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