From 124ce7050760947e65e3d4b4069efe02266a3812 Mon Sep 17 00:00:00 2001 From: Carlos Vargas Date: Thu, 4 Feb 2010 17:38:30 -0500 Subject: [PATCH] improve returns of functions CT#191 --- main/inc/lib/notebook.lib.php | 23 ++++++++++------- main/notebook/index.php | 48 +++++++++++++++++------------------ 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/main/inc/lib/notebook.lib.php b/main/inc/lib/notebook.lib.php index ed19de7c41..3162801329 100644 --- a/main/inc/lib/notebook.lib.php +++ b/main/inc/lib/notebook.lib.php @@ -40,10 +40,11 @@ class NotebookManager * This functions stores the note in the database * * @param array $values - * + * @return bool * @author Christian Fasanando * @author Patrick Cool , Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 + * */ function save_note($values) { // Database table definition @@ -65,9 +66,10 @@ class NotebookManager //insert into item_property api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, $id, 'NotebookAdded', api_get_user_id()); } - - // display the feedback message - Display::display_confirmation_message(get_lang('NoteAdded')); + $affected_rows = Database::affected_rows(); + if (!empty($affected_rows)){ + return true; + } } function get_note_information($notebook_id) { @@ -109,9 +111,10 @@ class NotebookManager //update item_property (update) api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($values['notebook_id']), 'NotebookUpdated', api_get_user_id()); - - // display the feedback message - Display::display_confirmation_message(get_lang('NoteUpdated')); + $affected_rows = Database::affected_rows(); + if (!empty($affected_rows)){ + return true; + } } function delete_note($notebook_id) { @@ -123,8 +126,10 @@ class NotebookManager //update item_property (delete) api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($notebook_id), 'delete', api_get_user_id()); - - Display::display_confirmation_message(get_lang('NoteDeleted')); + $affected_rows = Database::affected_rows(); + if (!empty($affected_rows)){ + return true; + } } function display_notes() { diff --git a/main/notebook/index.php b/main/notebook/index.php index 0d2f371258..90d6f47c67 100755 --- a/main/notebook/index.php +++ b/main/notebook/index.php @@ -45,13 +45,11 @@ $tool = TOOL_NOTEBOOK; event_access_tool(TOOL_NOTEBOOK); // tool name -if ( isset($_GET['action']) && $_GET['action'] == 'addnote') -{ +if ( isset($_GET['action']) && $_GET['action'] == 'addnote') { $tool = 'NoteAddNew'; $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('Notebook')); } -if ( isset($_GET['action']) && $_GET['action'] == 'editnote') -{ +if ( isset($_GET['action']) && $_GET['action'] == 'editnote') { $tool = 'ModifyNote'; $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('Notebook')); } @@ -64,8 +62,7 @@ Display::display_introduction_section(TOOL_NOTEBOOK); // Action handling: Adding a note -if (isset($_GET['action']) && $_GET['action'] == 'addnote') -{ +if (isset($_GET['action']) && $_GET['action'] == 'addnote') { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { api_not_allowed(); } @@ -93,20 +90,18 @@ if (isset($_GET['action']) && $_GET['action'] == 'addnote') $form->addRule('note_title', '
'.get_lang('ThisFieldIsRequired'), 'required'); // The validation or display - if ( $form->validate() ) - { + if ($form->validate()) { $check = Security::check_token('post'); - if ($check) - { + if ($check) { $values = $form->exportValues(); - NotebookManager::save_note($values); - + $res = NotebookManager::save_note($values); + if ($res == true){ + Display::display_confirmation_message(get_lang('NoteAdded')); + } } Security::clear_token(); NotebookManager::display_notes(); - } - else - { + } else { echo ''; @@ -116,7 +111,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'addnote') $form->display(); } } - // Action handling: Editing a note else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id'])) { @@ -147,19 +141,19 @@ else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($ $form->addRule('note_title', '
'.get_lang('ThisFieldIsRequired'), 'required'); // The validation or display - if ( $form->validate() ) - { + if ($form->validate()) { $check = Security::check_token('post'); - if ($check) - { + if ($check) { $values = $form->exportValues(); - NotebookManager::update_note($values); + $res=NotebookManager::update_note($values); + if ($res==true){ + Display::display_confirmation_message(get_lang('NoteUpdated')); + } + } Security::clear_token(); NotebookManager::display_notes(); - } - else - { + } else { echo ''; @@ -173,7 +167,11 @@ else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($ // Action handling: deleting a note else if (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id'])) { - NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id'])); + $res=NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id'])); + if ($res==true){ + Display::display_confirmation_message(get_lang('NoteDeleted')); + } + NotebookManager::display_notes(); }