index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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('../inc/lib/events.lib.inc.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[] = javascript_notebook();
  21. // setting the tool constants
  22. $tool = TOOL_NOTEBOOK;
  23. // tracking
  24. event_access_tool(TOOL_NOTEBOOK);
  25. if ( isset($_GET['action']) && ($_GET['action'] == 'addnote' || $_GET['action'] == 'editnote')) {
  26. $tool=get_lang('NotebookManagement');
  27. $interbreadcrumb[] = array ("url"=>"index.php", "name"=> ucfirst(get_lang(TOOL_NOTEBOOK)));
  28. }
  29. // displaying the header
  30. Display::display_header(get_lang(ucfirst($tool)));
  31. // Tool introduction
  32. $fck_attribute['Width'] = '100%';
  33. $fck_attribute['Height'] = '300';
  34. $fck_attribute['ToolbarSet'] = 'Introduction';
  35. Display::display_introduction_section(TOOL_NOTEBOOK,'left');
  36. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  37. // Config notebook FckEditor buttons bar
  38. $fck_attribute['Width'] = '100%';
  39. $fck_attribute['Height'] = '300';
  40. if(!api_is_allowed_to_edit())
  41. {
  42. $fck_attribute['Config']['UserStatus'] = 'student';
  43. $fck_attribute['ToolbarSet'] = 'Notebook_Student';
  44. }
  45. else
  46. {
  47. $fck_attribute['ToolbarSet'] = 'Notebook';
  48. }
  49. // Action handling: Adding a note
  50. if (isset($_GET['action']) && $_GET['action'] == 'addnote')
  51. {
  52. if (!empty($_GET['isStudentView'])) {
  53. 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'));
  62. $form->applyFilter('note_title', 'html_filter');
  63. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'));
  64. $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddNote'), 'class="add"');
  65. // setting the rules
  66. $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  67. // The validation or display
  68. if ( $form->validate() )
  69. {
  70. $check = Security::check_token('post');
  71. if ($check)
  72. {
  73. $values = $form->exportValues();
  74. save_note($values);
  75. }
  76. Security::clear_token();
  77. display_notes();
  78. }
  79. else
  80. {
  81. $token = Security::get_token();
  82. $form->addElement('hidden','sec_token');
  83. $form->setConstants(array('sec_token' => $token));
  84. $form->display();
  85. }
  86. }
  87. // Action handling: Editing a note
  88. else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id']))
  89. {
  90. if (!empty($_GET['isStudentView'])) {
  91. display_notes();
  92. exit;
  93. }
  94. // initiate the object
  95. $form = new FormValidator('note','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&notebook_id='.Security::remove_XSS($_GET['notebook_id']));
  96. // settting the form elements
  97. $form->addElement('header', '', get_lang('ModifyNote'));
  98. $form->addElement('hidden', 'notebook_id');
  99. $form->addElement('text', 'note_title', get_lang('NoteTitle'),array('size'=>'100'));
  100. $form->applyFilter('note_title', 'html_filter');
  101. $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'));
  102. $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyNote'), 'class="save"');
  103. // setting the defaults
  104. $defaults = get_note_information(Security::remove_XSS($_GET['notebook_id']));
  105. $form->setDefaults($defaults);
  106. // setting the rules
  107. $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  108. // The validation or display
  109. if ( $form->validate() )
  110. {
  111. $check = Security::check_token('post');
  112. if ($check)
  113. {
  114. $values = $form->exportValues();
  115. update_note($values);
  116. }
  117. Security::clear_token();
  118. display_notes();
  119. }
  120. else
  121. {
  122. $token = Security::get_token();
  123. $form->addElement('hidden','sec_token');
  124. $form->setConstants(array('sec_token' => $token));
  125. $form->display();
  126. }
  127. }
  128. // Action handling: deleting a note
  129. else if (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id']))
  130. {
  131. delete_note(Security::remove_XSS($_GET['notebook_id']));
  132. display_notes();
  133. }
  134. // Action handling: changing the view (sorting order)
  135. else if ($_GET['action'] == 'changeview' AND in_array($_GET['view'],array('creation_date','update_date', 'title')))
  136. {
  137. $_SESSION['notebook_view'] = $_GET['view'];
  138. display_notes();
  139. } else {
  140. display_notes();
  141. }
  142. // footer
  143. Display::display_footer();
  144. /**
  145. * a little bit of javascript to display a prettier warning when deleting a note
  146. *
  147. * @return unknown
  148. *
  149. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  150. * @version januari 2009, dokeos 1.8.6
  151. */
  152. function javascript_notebook()
  153. {
  154. return "<script type=\"text/javascript\">
  155. function confirmation (name)
  156. {
  157. if (confirm(\" ". get_lang("NoteConfirmDelete") ." \"+ name + \" ?\"))
  158. {return true;}
  159. else
  160. {return false;}
  161. }
  162. </script>";
  163. }
  164. /**
  165. * This functions stores the note in the database
  166. *
  167. * @param array $values
  168. *
  169. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  170. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  171. * @version januari 2009, dokeos 1.8.6
  172. */
  173. function save_note($values)
  174. {
  175. // Database table definition
  176. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  177. $sql = "INSERT INTO $t_notebook (user_id, course, session_id, title, description, creation_date,update_date,status)
  178. VALUES(
  179. '".Database::escape_string(api_get_user_id())."',
  180. '".Database::escape_string(api_get_course_id())."',
  181. '".Database::escape_string($_SESSION['id_session'])."',
  182. '".Database::escape_string($values['note_title'])."',
  183. '".Database::escape_string($values['note_comment'])."',
  184. '".Database::escape_string(date('Y-m-d H:i:s'))."',
  185. '".Database::escape_string(date('Y-m-d H:i:s'))."',
  186. '0')";
  187. $result = api_sql_query($sql, __FILE__, __LINE__);
  188. // display the feedback message
  189. Display::display_confirmation_message(get_lang('NoteAdded'));
  190. }
  191. function get_note_information($notebook_id)
  192. {
  193. // Database table definition
  194. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  195. $sql = "SELECT notebook_id AS notebook_id,
  196. title AS note_title,
  197. description AS note_comment
  198. FROM $t_notebook
  199. WHERE notebook_id = '".Database::escape_string($notebook_id)."' ";
  200. $result = api_sql_query($sql, __FILE__, __LINE__);
  201. return Database::fetch_array($result);
  202. }
  203. /**
  204. * This functions updates the note in the database
  205. *
  206. * @param array $values
  207. *
  208. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  209. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  210. * @version januari 2009, dokeos 1.8.6
  211. */
  212. function update_note($values)
  213. {
  214. // Database table definition
  215. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  216. $sql = "UPDATE $t_notebook SET
  217. user_id = '".Database::escape_string(api_get_user_id())."',
  218. course = '".Database::escape_string(api_get_course_id())."',
  219. session_id = '".Database::escape_string($_SESSION['id_session'])."',
  220. title = '".Database::escape_string($values['note_title'])."',
  221. description = '".Database::escape_string($values['note_comment'])."',
  222. update_date = '".Database::escape_string(date('Y-m-d H:i:s'))."'
  223. WHERE notebook_id = '".Database::escape_string($values['notebook_id'])."'";
  224. $result = api_sql_query($sql, __FILE__, __LINE__);
  225. // display the feedback message
  226. Display::display_confirmation_message(get_lang('NoteUpdated'));
  227. }
  228. function delete_note($notebook_id)
  229. {
  230. // Database table definition
  231. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  232. $sql = "DELETE FROM $t_notebook WHERE notebook_id='".Database::escape_string($notebook_id)."' AND user_id = '".Database::escape_string(api_get_user_id())."'";
  233. $result = api_sql_query($sql, __FILE__, __LINE__);
  234. Display::display_confirmation_message(get_lang('NoteDeleted'));
  235. }
  236. function display_notes()
  237. {
  238. // action links
  239. echo '<div class="actions" style="margin-bottom:20px">';
  240. //if (api_is_allowed_to_edit())
  241. //{
  242. echo '<a href="index.php?'.api_get_cidreq().'&action=addnote">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
  243. //}
  244. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=creation_date">'.Display::return_icon('calendar_select.gif',get_lang('OrderByCreationDate')).get_lang('OrderByCreationDate').'</a>';
  245. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=update_date">'.Display::return_icon('calendar_select.gif',get_lang('OrderByModificationDate')).get_lang('OrderByModificationDate').'</a>';
  246. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=title">'.Display::return_icon('comment.gif',get_lang('OrderByTitle')).get_lang('OrderByTitle').'</a>';
  247. echo '</div>';
  248. if (!in_array($_SESSION['notebook_view'],array('creation_date','update_date', 'title')))
  249. {
  250. $_SESSION['notebook_view'] = 'creation_date';
  251. }
  252. // Database table definition
  253. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  254. $order_by = "";
  255. if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') {
  256. $order_by = " ORDER BY ".$_SESSION['notebook_view']." DESC ";
  257. } else {
  258. $order_by = " ORDER BY ".$_SESSION['notebook_view']." ASC ";
  259. }
  260. $cond_extra = ($_SESSION['notebook_view']== 'update_date')?" AND update_date <> '0000-00-00 00:00:00'":" ";
  261. $sql = "SELECT * FROM $t_notebook WHERE user_id = '".Database::escape_string(api_get_user_id())."' $cond_extra $order_by";
  262. $result = api_sql_query($sql, __FILE__, __LINE__);
  263. while ($row = Database::fetch_array($result))
  264. {
  265. echo '<div class="sectiontitle">';
  266. echo '<span style="float: right;"> ('.get_lang('CreationDate').': '.date_to_str_ago($row['creation_date']).'&nbsp;&nbsp;<span class="dropbox_date">'.$row['creation_date'].'</span>';
  267. if ($row['update_date'] <> $row['creation_date'])
  268. {
  269. echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($row['update_date']).'&nbsp;&nbsp;<span class="dropbox_date">'.$row['update_date'].'</span>';
  270. }
  271. echo ')</span>';
  272. echo $row['title'];
  273. echo '</div>';
  274. echo '<div class="sectioncomment">'.$row['description'].'</div>';
  275. echo '<div>';
  276. echo '<a href="'.api_get_self().'?action=editnote&amp;notebook_id='.$row['notebook_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  277. echo '<a href="'.api_get_self().'?action=deletenote&amp;notebook_id='.$row['notebook_id'].'" onclick="return confirmation(\''.$row['title'].'\');">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  278. echo '</div>';
  279. }
  280. return $return;
  281. }
  282. ?>