index.php 9.6 KB

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