index.php 7.1 KB

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