index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. require_once api_get_path(LIBRARY_PATH).'notebook.lib.php';
  17. // The section (tabs)
  18. $this_section = SECTION_COURSES;
  19. // Notice for unauthorized people.
  20. api_protect_course_script(true);
  21. // Additional javascript
  22. $htmlHeadXtra[] = NotebookManager::javascript_notebook();
  23. $htmlHeadXtra[] = '<script type="text/javascript">
  24. function setFocus(){
  25. $("#note_title").focus();
  26. }
  27. $(document).ready(function () {
  28. setFocus();
  29. });
  30. </script>';
  31. // Setting the tool constants
  32. $tool = TOOL_NOTEBOOK;
  33. // Tracking
  34. event_access_tool(TOOL_NOTEBOOK);
  35. // Tool name
  36. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  37. $tool = 'NoteAddNew';
  38. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  39. }
  40. if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
  41. $tool = 'ModifyNote';
  42. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('ToolNotebook'));
  43. }
  44. // Displaying the header
  45. Display::display_header(get_lang(ucfirst($tool)));
  46. // Tool introduction
  47. Display::display_introduction_section(TOOL_NOTEBOOK);
  48. // Action handling: Adding a note
  49. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  50. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  51. api_not_allowed();
  52. }
  53. if (!empty($_GET['isStudentView'])) {
  54. NotebookManager::display_notes();
  55. exit;
  56. }
  57. $_SESSION['notebook_view'] = 'creation_date';
  58. // Initiate the object
  59. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  60. // Setting the form elements
  61. $form->addElement('header', '', get_lang('NoteAddNew'));
  62. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '95', 'id' => 'note_title'));
  63. //$form->applyFilter('note_title', 'html_filter');
  64. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  65. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  66. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  67. );
  68. $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddNote'), 'class="add"');
  69. // Setting the rules
  70. $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
  71. // The validation or display
  72. if ($form->validate()) {
  73. $check = Security::check_token('post');
  74. if ($check) {
  75. $values = $form->exportValues();
  76. $res = NotebookManager::save_note($values);
  77. if ($res) {
  78. Display::display_confirmation_message(get_lang('NoteAdded'));
  79. }
  80. }
  81. Security::clear_token();
  82. NotebookManager::display_notes();
  83. } else {
  84. echo '<div class="actions">';
  85. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  86. echo '</div>';
  87. $token = Security::get_token();
  88. $form->addElement('hidden', 'sec_token');
  89. $form->setConstants(array('sec_token' => $token));
  90. $form->display();
  91. }
  92. }
  93. // Action handling: Editing a note
  94. elseif (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id'])) {
  95. if (!empty($_GET['isStudentView'])) {
  96. NotebookManager::display_notes();
  97. exit;
  98. }
  99. // Initialize the object
  100. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.Security::remove_XSS($_GET['notebook_id']));
  101. // Setting the form elements
  102. $form->addElement('header', '', get_lang('ModifyNote'));
  103. $form->addElement('hidden', 'notebook_id');
  104. $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '100'));
  105. //$form->applyFilter('note_title', 'html_filter');
  106. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  107. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  108. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  109. );
  110. $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyNote'), 'class="save"');
  111. // Setting the defaults
  112. $defaults = NotebookManager::get_note_information(Security::remove_XSS($_GET['notebook_id']));
  113. $form->setDefaults($defaults);
  114. // Setting the rules
  115. $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required');
  116. // The validation or display
  117. if ($form->validate()) {
  118. $check = Security::check_token('post');
  119. if ($check) {
  120. $values = $form->exportValues();
  121. $res = NotebookManager::update_note($values);
  122. if ($res) {
  123. Display::display_confirmation_message(get_lang('NoteUpdated'));
  124. }
  125. }
  126. Security::clear_token();
  127. NotebookManager::display_notes();
  128. } else {
  129. echo '<div class="actions">';
  130. echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToNotesList'),'',ICON_SIZE_MEDIUM).'</a>';
  131. echo '</div>';
  132. $token = Security::get_token();
  133. $form->addElement('hidden', 'sec_token');
  134. $form->setConstants(array('sec_token' => $token));
  135. $form->display();
  136. }
  137. }
  138. // Action handling: deleting a note
  139. elseif (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id'])) {
  140. $res = NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id']));
  141. if ($res) {
  142. Display::display_confirmation_message(get_lang('NoteDeleted'));
  143. }
  144. NotebookManager::display_notes();
  145. }
  146. // Action handling: changing the view (sorting order)
  147. elseif ($_GET['action'] == 'changeview' AND in_array($_GET['view'], array('creation_date', 'update_date', 'title'))) {
  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['notebook_view'] = $_GET['view'];
  172. NotebookManager::display_notes();
  173. } else {
  174. NotebookManager::display_notes();
  175. }
  176. // Footer
  177. Display::display_footer();