index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * @package dokeos.glossary
  5. * @author Christian Fasanando, initial version
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium, refactoring and tighter integration in Dokeos
  7. */
  8. // name of the language file that needs to be included
  9. $language_file = array('notebook');
  10. // including the global dokeos fileç
  11. require_once '../inc/global.inc.php';
  12. require_once api_get_path(LIBRARY_PATH).'notebook.lib.php';
  13. // the section (tabs)
  14. $this_section=SECTION_COURSES;
  15. // notice for unauthorized people.
  16. api_protect_course_script(true);
  17. // including additional libraries
  18. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  19. // additional javascript
  20. $htmlHeadXtra[] = NotebookManager::javascript_notebook();
  21. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  22. $htmlHeadXtra[] = '<script type="text/javascript">
  23. function setFocus(){
  24. $("#note_title").focus();
  25. }
  26. $(document).ready(function () {
  27. setFocus();
  28. });
  29. </script>';
  30. // setting the tool constants
  31. $tool = TOOL_NOTEBOOK;
  32. // tracking
  33. event_access_tool(TOOL_NOTEBOOK);
  34. // tool name
  35. if ( isset($_GET['action']) && $_GET['action'] == 'addnote') {
  36. $tool = 'NoteAddNew';
  37. $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('Notebook'));
  38. }
  39. if ( isset($_GET['action']) && $_GET['action'] == 'editnote') {
  40. $tool = 'ModifyNote';
  41. $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('Notebook'));
  42. }
  43. // displaying the header
  44. Display::display_header(get_lang(ucfirst($tool)));
  45. // Tool introduction
  46. Display::display_introduction_section(TOOL_NOTEBOOK);
  47. // Action handling: Adding a note
  48. if (isset($_GET['action']) && $_GET['action'] == 'addnote') {
  49. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  50. api_not_allowed();
  51. }
  52. if (!empty($_GET['isStudentView'])) {
  53. NotebookManager::display_notes();
  54. exit;
  55. }
  56. $_SESSION['notebook_view'] = 'creation_date';
  57. // initiate the object
  58. $form = new FormValidator('note','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  59. // settting the form elements
  60. $form->addElement('header', '', get_lang('NoteAddNew'));
  61. $form->addElement('text', 'note_title', get_lang('NoteTitle'),array('size'=>'95', 'id'=> 'note_title'));
  62. //$form->applyFilter('note_title', 'html_filter');
  63. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit()
  64. ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300')
  65. : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')
  66. );
  67. $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddNote'), 'class="add"');
  68. // setting the rules
  69. $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  70. // The validation or display
  71. if ($form->validate()) {
  72. $check = Security::check_token('post');
  73. if ($check) {
  74. $values = $form->exportValues();
  75. $res = NotebookManager::save_note($values);
  76. if ($res == true){
  77. Display::display_confirmation_message(get_lang('NoteAdded'));
  78. }
  79. }
  80. Security::clear_token();
  81. NotebookManager::display_notes();
  82. } else {
  83. echo '<div class="actions">';
  84. echo '<a href="index.php">'.Display::return_icon('back.png').' '.get_lang('BackToNotesList').'</a>';
  85. echo '</div>';
  86. $token = Security::get_token();
  87. $form->addElement('hidden','sec_token');
  88. $form->setConstants(array('sec_token' => $token));
  89. $form->display();
  90. }
  91. }
  92. // Action handling: Editing a note
  93. else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id']))
  94. {
  95. if (!empty($_GET['isStudentView'])) {
  96. NotebookManager::display_notes();
  97. exit;
  98. }
  99. // initiate 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. // settting 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', '<div class="required">'.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==true){
  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').'</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. else if (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id']))
  140. {
  141. $res=NotebookManager::delete_note(Security::remove_XSS($_GET['notebook_id']));
  142. if ($res==true){
  143. Display::display_confirmation_message(get_lang('NoteDeleted'));
  144. }
  145. NotebookManager::display_notes();
  146. }
  147. // Action handling: changing the view (sorting order)
  148. else if ($_GET['action'] == 'changeview' AND in_array($_GET['view'],array('creation_date','update_date', 'title')))
  149. {
  150. switch ($_GET['view'])
  151. {
  152. case 'creation_date':
  153. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC')
  154. {
  155. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateAsc'));
  156. }
  157. else
  158. {
  159. Display::display_confirmation_message(get_lang('NotesSortedByCreationDateDESC'));
  160. }
  161. break;
  162. case 'update_date':
  163. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC')
  164. {
  165. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateAsc'));
  166. }
  167. else
  168. {
  169. Display::display_confirmation_message(get_lang('NotesSortedByUpdateDateDESC'));
  170. }
  171. break;
  172. case 'title':
  173. if (!$_GET['direction'] OR $_GET['direction'] == 'ASC')
  174. {
  175. Display::display_confirmation_message(get_lang('NotesSortedByTitleAsc'));
  176. }
  177. else
  178. {
  179. Display::display_confirmation_message(get_lang('NotesSortedByTitleDESC'));
  180. }
  181. break;
  182. }
  183. $_SESSION['notebook_view'] = $_GET['view'];
  184. NotebookManager::display_notes();
  185. } else {
  186. NotebookManager::display_notes();
  187. }
  188. // footer
  189. Display::display_footer();
  190. ?>