index.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. // Including the global initialization file
  9. require_once '../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 type="text/javascript">
  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. // Tool name
  30. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  31. $tool = 'NoteAddNew';
  32. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  33. }
  34. if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
  35. $tool = 'ModifyNote';
  36. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  37. }
  38. // Displaying the header
  39. Display::display_header(get_lang(ucfirst($tool)));
  40. // Tool introduction
  41. Display::display_introduction_section(TOOL_NOTEBOOK);
  42. // Action handling: Adding a note
  43. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  44. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  45. api_not_allowed();
  46. }
  47. if (!empty($_GET['isStudentView'])) {
  48. NotebookManager::display_notes();
  49. exit;
  50. }
  51. $_SESSION['notebook_view'] = 'creation_date';
  52. // Initiate the object
  53. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  54. // Setting the form elements
  55. $form->addElement('header', '', get_lang('NoteAddNew'));
  56. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '95', 'id' => 'note_title'));
  57. //$form->applyFilter('note_title', 'html_filter');
  58. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  59. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  60. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  61. );
  62. $form->addButtonCreate(get_lang('AddNote'), 'SubmitNote');
  63. // Setting the rules
  64. $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
  65. // The validation or display
  66. if ($form->validate()) {
  67. $check = Security::check_token('post');
  68. if ($check) {
  69. $values = $form->exportValues();
  70. $res = NotebookManager::save_note($values);
  71. if ($res) {
  72. Display::display_confirmation_message(get_lang('NoteAdded'));
  73. }
  74. }
  75. Security::clear_token();
  76. NotebookManager::display_notes();
  77. } else {
  78. echo '<div class="actions">';
  79. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  80. echo '</div>';
  81. $token = Security::get_token();
  82. $form->addElement('hidden', 'sec_token');
  83. $form->setConstants(array('sec_token' => $token));
  84. $form->display();
  85. }
  86. } elseif (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id'])) {
  87. // Action handling: Editing a note
  88. if (!empty($_GET['isStudentView'])) {
  89. NotebookManager::display_notes();
  90. exit;
  91. }
  92. // Initialize the object
  93. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.Security::remove_XSS($_GET['notebook_id']));
  94. // Setting the form elements
  95. $form->addElement('header', '', get_lang('ModifyNote'));
  96. $form->addElement('hidden', 'notebook_id');
  97. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '100'));
  98. //$form->applyFilter('note_title', 'html_filter');
  99. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  100. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  101. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  102. );
  103. $form->addButtonUpdate(get_lang('ModifyNote'), 'SubmitNote');
  104. // Setting the defaults
  105. $defaults = NotebookManager::get_note_information(Security::remove_XSS($_GET['notebook_id']));
  106. $form->setDefaults($defaults);
  107. // Setting the rules
  108. $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
  109. // The validation or display
  110. if ($form->validate()) {
  111. $check = Security::check_token('post');
  112. if ($check) {
  113. $values = $form->exportValues();
  114. $res = NotebookManager::update_note($values);
  115. if ($res) {
  116. Display::display_confirmation_message(get_lang('NoteUpdated'));
  117. }
  118. }
  119. Security::clear_token();
  120. NotebookManager::display_notes();
  121. } else {
  122. echo '<div class="actions">';
  123. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  124. echo '</div>';
  125. $token = Security::get_token();
  126. $form->addElement('hidden', 'sec_token');
  127. $form->setConstants(array('sec_token' => $token));
  128. $form->display();
  129. }
  130. }
  131. // Action handling: deleting a note
  132. elseif (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id'])) {
  133. $res = NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id']));
  134. if ($res) {
  135. Display::display_confirmation_message(get_lang('NoteDeleted'));
  136. }
  137. NotebookManager::display_notes();
  138. } elseif (
  139. isset($_GET['action']) && $_GET['action'] == 'changeview' &&
  140. in_array($_GET['view'], array('creation_date', 'update_date', 'title'))
  141. ) {
  142. // Action handling: changing the view (sorting order)
  143. switch ($_GET['view']) {
  144. case 'creation_date':
  145. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  146. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateAsc'));
  147. } else {
  148. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateDESC'));
  149. }
  150. break;
  151. case 'update_date':
  152. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  153. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateAsc'));
  154. } else {
  155. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateDESC'));
  156. }
  157. break;
  158. case 'title':
  159. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC') {
  160. Display::display_confirmation_message(get_lang('NotesSortedByTitleAsc'));
  161. } else {
  162. Display::display_confirmation_message(get_lang('NotesSortedByTitleDESC'));
  163. }
  164. break;
  165. }
  166. $_SESSION['notebook_view'] = $_GET['view'];
  167. NotebookManager::display_notes();
  168. } else {
  169. NotebookManager::display_notes();
  170. }
  171. // Footer
  172. Display::display_footer();