index.php 6.8 KB

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