index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.glossary
  5. * @author Christian Fasanando, initial version
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium, refactoring and tighter integration
  7. */
  8. // Name of the language file that needs to be included
  9. $language_file = array('notebook');
  10. // Including the global initialization file
  11. require_once '../inc/global.inc.php';
  12. require_once api_get_path(LIBRARY_PATH).'notebook.lib.php';
  13. // The section (tabs)
  14. $this_section = SECTION_COURSES;
  15. // Notice for unauthorized people.
  16. api_protect_course_script(true);
  17. // Including additional libraries
  18. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  19. // Additional javascript
  20. $htmlHeadXtra[] = NotebookManager::javascript_notebook();
  21. $htmlHeadXtra[] = '<script type="text/javascript">
  22. function setFocus(){
  23. $("#note_title").focus();
  24. }
  25. $(document).ready(function () {
  26. setFocus();
  27. });
  28. </script>';
  29. // Setting the tool constants
  30. $tool = TOOL_NOTEBOOK;
  31. // Tracking
  32. event_access_tool(TOOL_NOTEBOOK);
  33. // Tool name
  34. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  35. $tool = 'NoteAddNew';
  36. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  37. }
  38. if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
  39. $tool = 'ModifyNote';
  40. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  41. }
  42. // Displaying the header
  43. Display::display_header(get_lang(ucfirst($tool)));
  44. // Tool introduction
  45. Display::display_introduction_section(TOOL_NOTEBOOK);
  46. // Action handling: Adding a note
  47. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  48. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  49. api_not_allowed();
  50. }
  51. if (!empty($_GET['isStudentView'])) {
  52. NotebookManager::display_notes();
  53. exit;
  54. }
  55. $_SESSION['notebook_view'] = 'creation_date';
  56. // Initiate the object
  57. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  58. // Settting the form elements
  59. $form->addElement('header', '', get_lang('NoteAddNew'));
  60. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '95', 'id' => 'note_title'));
  61. //$form->applyFilter('note_title', 'html_filter');
  62. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  63. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  64. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  65. );
  66. $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddNote'), 'class="add"');
  67. // Setting the rules
  68. $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  69. // The validation or display
  70. if ($form->validate()) {
  71. $check = Security::check_token('post');
  72. if ($check) {
  73. $values = $form->exportValues();
  74. $res = NotebookManager::save_note($values);
  75. if ($res) {
  76. Display::display_confirmation_message(get_lang('NoteAdded'));
  77. }
  78. }
  79. Security::clear_token();
  80. NotebookManager::display_notes();
  81. } else {
  82. echo '<div class="actions">';
  83. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'','32').'</a>';
  84. echo '</div>';
  85. $token = Security::get_token();
  86. $form->addElement('hidden', 'sec_token');
  87. $form->setConstants(array('sec_token' => $token));
  88. $form->display();
  89. }
  90. }
  91. // Action handling: Editing a note
  92. elseif (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id'])) {
  93. if (!empty($_GET['isStudentView'])) {
  94. NotebookManager::display_notes();
  95. exit;
  96. }
  97. // Initialize the object
  98. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.Security::remove_XSS($_GET['notebook_id']));
  99. // Settting the form elements
  100. $form->addElement('header', '', get_lang('ModifyNote'));
  101. $form->addElement('hidden', 'notebook_id');
  102. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '100'));
  103. //$form->applyFilter('note_title', 'html_filter');
  104. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  105. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  106. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  107. );
  108. $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyNote'), 'class="save"');
  109. // Setting the defaults
  110. $defaults = NotebookManager::get_note_information(Security::remove_XSS($_GET['notebook_id']));
  111. $form->setDefaults($defaults);
  112. // Setting the rules
  113. $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  114. // The validation or display
  115. if ($form->validate()) {
  116. $check = Security::check_token('post');
  117. if ($check) {
  118. $values = $form->exportValues();
  119. $res = NotebookManager::update_note($values);
  120. if ($res) {
  121. Display::display_confirmation_message(get_lang('NoteUpdated'));
  122. }
  123. }
  124. Security::clear_token();
  125. NotebookManager::display_notes();
  126. } else {
  127. echo '<div class="actions">';
  128. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'','32').'</a>';
  129. echo '</div>';
  130. $token = Security::get_token();
  131. $form->addElement('hidden', 'sec_token');
  132. $form->setConstants(array('sec_token' => $token));
  133. $form->display();
  134. }
  135. }
  136. // Action handling: deleting a note
  137. elseif (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id'])) {
  138. $res = NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id']));
  139. if ($res) {
  140. Display::display_confirmation_message(get_lang('NoteDeleted'));
  141. }
  142. NotebookManager::display_notes();
  143. }
  144. // Action handling: changing the view (sorting order)
  145. elseif ($_GET['action'] == 'changeview' AND in_array($_GET['view'], array('creation_date', 'update_date', 'title'))) {
  146. switch ($_GET['view']) {
  147. case 'creation_date':
  148. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  149. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateAsc'));
  150. } else {
  151. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateDESC'));
  152. }
  153. break;
  154. case 'update_date':
  155. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  156. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateAsc'));
  157. } else {
  158. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateDESC'));
  159. }
  160. break;
  161. case 'title':
  162. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  163. Display::display_confirmation_message(get_lang('NotesSortedByTitleAsc'));
  164. } else {
  165. Display::display_confirmation_message(get_lang('NotesSortedByTitleDESC'));
  166. }
  167. break;
  168. }
  169. $_SESSION['notebook_view'] = $_GET['view'];
  170. NotebookManager::display_notes();
  171. } else {
  172. NotebookManager::display_notes();
  173. }
  174. // Footer
  175. Display::display_footer();