index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. $course_plugin = 'notebookteacher';
  5. require_once __DIR__.'/../config.php';
  6. // Notice for unauthorized people.
  7. api_protect_course_script(true);
  8. $_setting['student_view_enabled'] = 'false';
  9. $plugin = NotebookTeacherPlugin::create();
  10. $enable = $plugin->get('enable_plugin_notebookteacher') == 'true';
  11. if (!$enable) {
  12. api_not_allowed(true, $plugin->get_lang('ToolDisabled'));
  13. }
  14. $allow = api_is_teacher() || api_is_drh();
  15. if (!$allow) {
  16. api_not_allowed(true);
  17. }
  18. $current_course_tool = $plugin->get_lang('NotebookTeacher');
  19. $notebookId = isset($_GET['notebook_id']) ? (int) $_GET['notebook_id'] : 0;
  20. $studentId = isset($_GET['student_id']) ? $_GET['student_id'] : 0;
  21. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  22. $currentUrl = api_get_self().'?'.api_get_cidreq().'&student_id='.$studentId;
  23. // The section (tabs)
  24. $this_section = SECTION_COURSES;
  25. $location = api_get_self().'?'.api_get_cidreq();
  26. // Additional javascript
  27. $htmlHeadXtra[] = NotebookTeacher::javascriptNotebook();
  28. $htmlHeadXtra[] = '<script>
  29. function setFocus(){
  30. $("#note_title").focus();
  31. }
  32. $(document).ready(function () {
  33. setFocus();
  34. });
  35. function studentFilter() {
  36. var student_id = $("#student_filter").val();
  37. location.href ="'.$location.'&student_id="+student_id;
  38. }
  39. </script>';
  40. // Tracking
  41. Event::event_access_tool('notebookteacher');
  42. $noteBookTeacher = $tool = $plugin->get_lang('NotebookTeacher');
  43. switch ($action) {
  44. case 'addnote':
  45. $tool = 'NoteAddNew';
  46. $interbreadcrumb[] = [
  47. 'url' => 'index.php?'.api_get_cidreq(),
  48. 'name' => $noteBookTeacher,
  49. ];
  50. if ((api_get_session_id() != 0 &&
  51. !api_is_allowed_to_session_edit(false, true) || api_is_drh())) {
  52. api_not_allowed();
  53. }
  54. Session::write('notebook_view', 'creation_date');
  55. $form = new FormValidator(
  56. 'note',
  57. 'post',
  58. $currentUrl.'&action=addnote'
  59. );
  60. $form->addHeader(get_lang('NoteAddNew'));
  61. $form = NotebookTeacher::getForm($form, $studentId);
  62. $form->setDefaults(['student_id' => $studentId]);
  63. // The validation or display
  64. if ($form->validate()) {
  65. $check = Security::check_token('post');
  66. if ($check) {
  67. $values = $form->exportValues();
  68. $res = NotebookTeacher::saveNote($values);
  69. if ($res) {
  70. Display::addFlash(Display::return_message(get_lang('NoteAdded'), 'confirmation'));
  71. }
  72. }
  73. header('Location: '.$currentUrl);
  74. exit;
  75. } else {
  76. // Displaying the header
  77. Display::display_header(get_lang(ucfirst($tool)));
  78. // Tool introduction
  79. Display::display_introduction_section($noteBookTeacher);
  80. echo '<div class="actions">';
  81. echo '<a href="index.php">'.
  82. Display::return_icon('back.png', get_lang('BackToNotesList'), '', ICON_SIZE_MEDIUM).
  83. '</a>';
  84. echo '</div>';
  85. $token = Security::get_token();
  86. $form->addElement('hidden', 'sec_token');
  87. $form->setConstants(['sec_token' => $token]);
  88. $form->display();
  89. }
  90. break;
  91. case 'editnote':
  92. $tool = 'ModifyNote';
  93. $interbreadcrumb[] = [
  94. 'url' => 'index.php?'.api_get_cidreq(),
  95. 'name' => $noteBookTeacher,
  96. ];
  97. if (empty($notebookId)) {
  98. api_not_allowed(true);
  99. }
  100. $defaults = NotebookTeacher::getNoteInformation($notebookId);
  101. if (empty($defaults)) {
  102. api_not_allowed(true);
  103. }
  104. $form = new FormValidator(
  105. 'note',
  106. 'post',
  107. $currentUrl.'&action='.$action.'&notebook_id='.$notebookId
  108. );
  109. // Setting the form elements
  110. $form->addHeader(get_lang('ModifyNote'));
  111. $form->addHidden('notebook_id', $notebookId);
  112. $form = NotebookTeacher::getForm($form, $defaults['student_id']);
  113. // Setting the defaults
  114. $form->setDefaults($defaults);
  115. // The validation or display
  116. if ($form->validate()) {
  117. $check = Security::check_token('post');
  118. if ($check) {
  119. $values = $form->exportValues();
  120. $res = NotebookTeacher::updateNote($values);
  121. if ($res) {
  122. Display::addFlash(Display::return_message(get_lang('NoteUpdated'), 'confirmation'));
  123. }
  124. }
  125. header('Location: '.$currentUrl);
  126. exit;
  127. } else {
  128. // Displaying the header
  129. Display::display_header(get_lang(ucfirst($tool)));
  130. // Tool introduction
  131. Display::display_introduction_section($noteBookTeacher);
  132. echo '<div class="actions">';
  133. echo '<a href="index.php">'.
  134. Display::return_icon('back.png', get_lang('BackToNotesList'), '', ICON_SIZE_MEDIUM).'</a>';
  135. echo '</div>';
  136. $token = Security::get_token();
  137. $form->addElement('hidden', 'sec_token');
  138. $form->setConstants(['sec_token' => $token]);
  139. $form->display();
  140. }
  141. break;
  142. case 'deletenote':
  143. $res = NotebookTeacher::deleteNote($notebookId);
  144. if ($res) {
  145. Display::addFlash(Display::return_message(get_lang('NoteDeleted'), 'confirmation'));
  146. }
  147. header('Location: '.$currentUrl);
  148. exit;
  149. break;
  150. case 'changeview':
  151. if (in_array($_GET['view'], ['creation_date', 'update_date', 'title'])) {
  152. switch ($_GET['view']) {
  153. case 'creation_date':
  154. if (!$_GET['direction'] || $_GET['direction'] == 'ASC') {
  155. Display::addFlash(
  156. Display::return_message(get_lang('NotesSortedByCreationDateAsc'), 'confirmation')
  157. );
  158. } else {
  159. Display::addFlash(
  160. Display::return_message(get_lang('NotesSortedByCreationDateDESC'), 'confirmation')
  161. );
  162. }
  163. break;
  164. case 'update_date':
  165. if (!$_GET['direction'] || $_GET['direction'] == 'ASC') {
  166. Display::addFlash(
  167. Display::return_message(get_lang('NotesSortedByUpdateDateAsc'), 'confirmation')
  168. );
  169. } else {
  170. Display::addFlash(
  171. Display::return_message(get_lang('NotesSortedByUpdateDateDESC'), 'confirmation')
  172. );
  173. }
  174. break;
  175. case 'title':
  176. if (!$_GET['direction'] || $_GET['direction'] == 'ASC') {
  177. Display::addFlash(Display::return_message(get_lang('NotesSortedByTitleAsc'), 'confirmation'));
  178. } else {
  179. Display::addFlash(Display::return_message(get_lang('NotesSortedByTitleDESC'), 'confirmation'));
  180. }
  181. break;
  182. }
  183. Session::write('notebook_view', Security::remove_XSS($_GET['view']));
  184. header('Location: '.$currentUrl);
  185. exit;
  186. }
  187. break;
  188. default:
  189. // Displaying the header
  190. Display::display_header(get_lang(ucfirst($tool)));
  191. // Tool introduction
  192. Display::display_introduction_section($noteBookTeacher);
  193. NotebookTeacher::displayNotes();
  194. break;
  195. }
  196. Display::display_footer();