Răsfoiți Sursa

improve returns of functions CT#191

Carlos Vargas 15 ani în urmă
părinte
comite
124ce70507
2 a modificat fișierele cu 37 adăugiri și 34 ștergeri
  1. 14 9
      main/inc/lib/notebook.lib.php
  2. 23 25
      main/notebook/index.php

+ 14 - 9
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 <christian.fasanando@dokeos.com>
 	 * @author Patrick Cool <patrick.cool@ugent.be>, 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() {

+ 23 - 25
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', '<div class="required">'.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 '<div class="actions">';
 		echo '<a href="index.php">'.Display::return_icon('back.png').' '.get_lang('BackToNotesList').'</a>';
 		echo '</div>';
@@ -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', '<div class="required">'.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 '<div class="actions">';
 		echo '<a href="index.php">'.Display::return_icon('back.png').' '.get_lang('BackToNotesList').'</a>';
 		echo '</div>';
@@ -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();
 }