index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 '../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 type="text/javascript">
  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. // Tool name
  31. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  32. $tool = 'NoteAddNew';
  33. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  34. }
  35. if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
  36. $tool = 'ModifyNote';
  37. $interbreadcrumb[] = array('url' => 'index.php', '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 (isset($_GET['action']) && $_GET['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::write('notebook_view', 'creation_date');
  53. $form = new FormValidator(
  54. 'note',
  55. 'post',
  56. api_get_self().'?action='.Security::remove_XSS($_GET['action'])
  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->addHtmlEditor('note_comment', get_lang('NoteComment'), false,
  62. false, 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->addButtonCreate(get_lang('AddNote'), 'SubmitNote');
  67. // Setting the rules
  68. $form->addRule('note_title', 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'),'',ICON_SIZE_MEDIUM).'</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. } elseif (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id'])) {
  91. // Action handling: Editing a note
  92. if (!empty($_GET['isStudentView'])) {
  93. NotebookManager::display_notes();
  94. exit;
  95. }
  96. // Initialize the object
  97. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.Security::remove_XSS($_GET['notebook_id']));
  98. // Setting the form elements
  99. $form->addElement('header', '', get_lang('ModifyNote'));
  100. $form->addElement('hidden', 'notebook_id');
  101. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '100'));
  102. //$form->applyFilter('note_title', 'html_filter');
  103. $form->addHtmlEditor('note_comment', get_lang('NoteComment'), false,
  104. false, 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->addButtonUpdate(get_lang('ModifyNote'), 'SubmitNote');
  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', 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">'.
  129. Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  130. echo '</div>';
  131. $token = Security::get_token();
  132. $form->addElement('hidden', 'sec_token');
  133. $form->setConstants(array('sec_token' => $token));
  134. $form->display();
  135. }
  136. } elseif (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id'])) {
  137. // Action handling: deleting a note
  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. } elseif (
  144. isset($_GET['action']) && $_GET['action'] == 'changeview' &&
  145. in_array($_GET['view'], array('creation_date', 'update_date', 'title'))
  146. ) {
  147. // Action handling: changing the view (sorting order)
  148. switch ($_GET['view']) {
  149. case 'creation_date':
  150. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  151. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateAsc'));
  152. } else {
  153. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateDESC'));
  154. }
  155. break;
  156. case 'update_date':
  157. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  158. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateAsc'));
  159. } else {
  160. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateDESC'));
  161. }
  162. break;
  163. case 'title':
  164. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  165. Display::display_confirmation_message(get_lang('NotesSortedByTitleAsc'));
  166. } else {
  167. Display::display_confirmation_message(get_lang('NotesSortedByTitleDESC'));
  168. }
  169. break;
  170. }
  171. Session::write('notebook_view', $_GET['view']);
  172. NotebookManager::display_notes();
  173. } else {
  174. NotebookManager::display_notes();
  175. }
  176. // Footer
  177. Display::display_footer();