index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. // Including the global initialization file
  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['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->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  62. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  63. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  64. );
  65. $form->addButtonCreate(get_lang('AddNote'), 'SubmitNote');
  66. // Setting the rules
  67. $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
  68. // The validation or display
  69. if ($form->validate()) {
  70. $check = Security::check_token('post');
  71. if ($check) {
  72. $values = $form->exportValues();
  73. $res = NotebookManager::save_note($values);
  74. if ($res) {
  75. Display::display_confirmation_message(get_lang('NoteAdded'));
  76. }
  77. }
  78. Security::clear_token();
  79. NotebookManager::display_notes();
  80. } else {
  81. echo '<div class="actions">';
  82. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  83. echo '</div>';
  84. $token = Security::get_token();
  85. $form->addElement('hidden', 'sec_token');
  86. $form->setConstants(array('sec_token' => $token));
  87. $form->display();
  88. }
  89. } elseif (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id'])) {
  90. // Action handling: Editing a note
  91. if (!empty($_GET['isStudentView'])) {
  92. NotebookManager::display_notes();
  93. exit;
  94. }
  95. // Initialize the object
  96. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.Security::remove_XSS($_GET['notebook_id']));
  97. // Setting the form elements
  98. $form->addElement('header', '', get_lang('ModifyNote'));
  99. $form->addElement('hidden', 'notebook_id');
  100. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '100'));
  101. //$form->applyFilter('note_title', 'html_filter');
  102. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  103. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  104. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  105. );
  106. $form->addButtonUpdate(get_lang('ModifyNote'), 'SubmitNote');
  107. // Setting the defaults
  108. $defaults = NotebookManager::get_note_information(Security::remove_XSS($_GET['notebook_id']));
  109. $form->setDefaults($defaults);
  110. // Setting the rules
  111. $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
  112. // The validation or display
  113. if ($form->validate()) {
  114. $check = Security::check_token('post');
  115. if ($check) {
  116. $values = $form->exportValues();
  117. $res = NotebookManager::update_note($values);
  118. if ($res) {
  119. Display::display_confirmation_message(get_lang('NoteUpdated'));
  120. }
  121. }
  122. Security::clear_token();
  123. NotebookManager::display_notes();
  124. } else {
  125. echo '<div class="actions">';
  126. echo '<a href="index.php">'.
  127. Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  128. echo '</div>';
  129. $token = Security::get_token();
  130. $form->addElement('hidden', 'sec_token');
  131. $form->setConstants(array('sec_token' => $token));
  132. $form->display();
  133. }
  134. } elseif (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id'])) {
  135. // Action handling: deleting a note
  136. $res = NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id']));
  137. if ($res) {
  138. Display::display_confirmation_message(get_lang('NoteDeleted'));
  139. }
  140. NotebookManager::display_notes();
  141. } elseif (
  142. isset($_GET['action']) && $_GET['action'] == 'changeview' &&
  143. in_array($_GET['view'], array('creation_date', 'update_date', 'title'))
  144. ) {
  145. // Action handling: changing the view (sorting order)
  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();