'.get_lang('ThisFieldIsRequired'), 'required');
+
+ // The validation or display
+ if ( $form->validate() )
+ {
+ $check = Security::check_token('post');
+ if ($check)
+ {
+ $values = $form->exportValues();
+ save_note($values);
+
+ }
+ Security::clear_token();
+ display_notes();
+ }
+ else
+ {
+ echo '
';
+ $token = Security::get_token();
+ $form->addElement('hidden','sec_token');
+ $form->setConstants(array('sec_token' => $token));
+ $form->display();
+ }
+}
+
+// Action handling: Editing a note
+else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id']))
+{
+
+ if (!empty($_GET['isStudentView'])) {
+ display_notes();
+ exit;
+ }
+
+ // initiate the object
+ $form = new FormValidator('note','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'¬ebook_id='.Security::remove_XSS($_GET['notebook_id']));
+ // settting the form elements
+ $form->addElement('header', '', get_lang('ModifyNote'));
+ $form->addElement('hidden', 'notebook_id');
+ $form->addElement('text', 'note_title', get_lang('NoteTitle'),array('size'=>'100'));
+ //$form->applyFilter('note_title', 'html_filter');
+ $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
+ ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
+ : array('ToolbarSet' => 'Notebook_Student', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
+ );
+ $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyNote'), 'class="save"');
+
+ // setting the defaults
+ $defaults = get_note_information(Security::remove_XSS($_GET['notebook_id']));
+ $form->setDefaults($defaults);
+
+ // setting the rules
+ $form->addRule('note_title', '
'.get_lang('ThisFieldIsRequired'), 'required');
+
+ // The validation or display
+ if ( $form->validate() )
+ {
+ $check = Security::check_token('post');
+ if ($check)
+ {
+ $values = $form->exportValues();
+ update_note($values);
+ }
+ Security::clear_token();
+ display_notes();
+ }
+ else
+ {
+ echo '
';
+ $token = Security::get_token();
+ $form->addElement('hidden','sec_token');
+ $form->setConstants(array('sec_token' => $token));
+ $form->display();
+ }
+}
+
+// Action handling: deleting a note
+else if (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id']))
+{
+ delete_note(Security::remove_XSS($_GET['notebook_id']));
+ display_notes();
+}
+
+// Action handling: changing the view (sorting order)
+else if ($_GET['action'] == 'changeview' AND in_array($_GET['view'],array('creation_date','update_date', 'title')))
+{
+ switch ($_GET['view'])
+ {
+ case 'creation_date':
+ if (!$_GET['direction'] OR $_GET['direction'] == 'ASC')
+ {
+ Display::display_confirmation_message(get_lang('NotesSortedByCreationDateAsc'));
+ }
+ else
+ {
+ Display::display_confirmation_message(get_lang('NotesSortedByCreationDateDESC'));
+ }
+ break;
+ case 'update_date':
+ if (!$_GET['direction'] OR $_GET['direction'] == 'ASC')
+ {
+ Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateAsc'));
+ }
+ else
+ {
+ Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateDESC'));
+ }
+ break;
+ case 'title':
+ if (!$_GET['direction'] OR $_GET['direction'] == 'ASC')
+ {
+ Display::display_confirmation_message(get_lang('NotesSortedByTitleAsc'));
+ }
+ else
+ {
+ Display::display_confirmation_message(get_lang('NotesSortedByTitleDESC'));
+ }
+ break;
+ }
+ $_SESSION['notebook_view'] = $_GET['view'];
+ display_notes();
+} else {
+ display_notes();
+}
+
+
+// footer
+Display::display_footer();
+
+/**
+ * a little bit of javascript to display a prettier warning when deleting a note
+ *
+ * @return unknown
+ *
+ * @author Patrick Cool
, Ghent University, Belgium
+ * @version januari 2009, dokeos 1.8.6
+ */
+function javascript_notebook()
+{
+ return "";
+}
+
+/**
+ * This functions stores the note in the database
+ *
+ * @param array $values
+ *
+ * @author Christian Fasanando
+ * @author Patrick Cool , Ghent University, Belgium
+ * @version januari 2009, dokeos 1.8.6
+ */
+function save_note($values) {
+ // Database table definition
+ $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
+
+ $sql = "INSERT INTO $t_notebook (user_id, course, session_id, title, description, creation_date,update_date,status)
+ VALUES(
+ '".Database::escape_string(api_get_user_id())."',
+ '".Database::escape_string(api_get_course_id())."',
+ '".Database::escape_string($_SESSION['id_session'])."',
+ '".Database::escape_string(Security::remove_XSS($values['note_title']))."',
+ '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['note_comment'])),COURSEMANAGERLOWSECURITY))."',
+ '".Database::escape_string(date('Y-m-d H:i:s'))."',
+ '".Database::escape_string(date('Y-m-d H:i:s'))."',
+ '0')";
+ $result = api_sql_query($sql, __FILE__, __LINE__);
+ // display the feedback message
+ Display::display_confirmation_message(get_lang('NoteAdded'));
+}
+
+function get_note_information($notebook_id) {
+ // Database table definition
+ $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
+
+ $sql = "SELECT notebook_id AS notebook_id,
+ title AS note_title,
+ description AS note_comment
+ FROM $t_notebook
+ WHERE notebook_id = '".Database::escape_string($notebook_id)."' ";
+ $result = api_sql_query($sql, __FILE__, __LINE__);
+ return Database::fetch_array($result);
+}
+
+/**
+ * This functions updates the note in the database
+ *
+ * @param array $values
+ *
+ * @author Christian Fasanando
+ * @author Patrick Cool , Ghent University, Belgium
+ * @version januari 2009, dokeos 1.8.6
+ */
+function update_note($values) {
+ // Database table definition
+ $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
+
+ $sql = "UPDATE $t_notebook SET
+ user_id = '".Database::escape_string(api_get_user_id())."',
+ course = '".Database::escape_string(api_get_course_id())."',
+ session_id = '".Database::escape_string($_SESSION['id_session'])."',
+ title = '".Database::escape_string(Security::remove_XSS($values['note_title']))."',
+ description = '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['note_comment'])),COURSEMANAGERLOWSECURITY))."',
+ update_date = '".Database::escape_string(date('Y-m-d H:i:s'))."'
+ WHERE notebook_id = '".Database::escape_string($values['notebook_id'])."'";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ // display the feedback message
+ Display::display_confirmation_message(get_lang('NoteUpdated'));
+}
+
+function delete_note($notebook_id) {
+ // Database table definition
+ $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
+
+ $sql = "DELETE FROM $t_notebook WHERE notebook_id='".Database::escape_string($notebook_id)."' AND user_id = '".Database::escape_string(api_get_user_id())."'";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ Display::display_confirmation_message(get_lang('NoteDeleted'));
+}
+
+function display_notes() {
+
+ if (!$_GET['direction'])
+ {
+ $sort_direction = 'ASC';
+ $link_sort_direction = 'DESC';
+ }
+ elseif ($_GET['direction'] == 'ASC')
+ {
+ $sort_direction = 'ASC';
+ $link_sort_direction = 'DESC';
+ }
+ else
+ {
+ $sort_direction = 'DESC';
+ $link_sort_direction = 'ASC';
+ }
+
+
+ // action links
+ echo '';
+
+ if (!in_array($_SESSION['notebook_view'],array('creation_date','update_date', 'title'))) {
+ $_SESSION['notebook_view'] = 'creation_date';
+ }
+
+ // Database table definition
+ $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
+ $order_by = "";
+ if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') {
+ $order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction ";
+ } else {
+ $order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction ";
+ }
+
+ $cond_extra = ($_SESSION['notebook_view']== 'update_date')?" AND update_date <> '0000-00-00 00:00:00'":" ";
+
+ $sql = "SELECT * FROM $t_notebook WHERE user_id = '".Database::escape_string(api_get_user_id())."' $cond_extra $order_by";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ while ($row = Database::fetch_array($result)) {
+ echo '';
+ echo ' ('.get_lang('CreationDate').': '.date_to_str_ago($row['creation_date']).' '.$row['creation_date'].'';
+ if ($row['update_date'] <> $row['creation_date']) {
+ echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($row['update_date']).' '.$row['update_date'].'';
+ }
+ echo ')';
+ echo $row['title'];
+ echo '
';
+ echo '';
+ echo '';
+ }
+ return $return;
+}
+?>