index.php 7.8 KB

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