notebook.lib.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. ==============================================================================
  5. * This class provides methods for the notebook management.
  6. * Include/require it in your code to use its features.
  7. * @author Carlos Vargas <litox84@gmail.com>, move code of main/notebook up here
  8. * @package chamilo.library
  9. ==============================================================================
  10. */
  11. class NotebookManager
  12. {
  13. private function __construct() {
  14. }
  15. /**
  16. * a little bit of javascript to display a prettier warning when deleting a note
  17. *
  18. * @return unknown
  19. *
  20. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  21. * @version januari 2009, dokeos 1.8.6
  22. */
  23. function javascript_notebook()
  24. {
  25. return "<script type=\"text/javascript\">
  26. function confirmation (name)
  27. {
  28. if (confirm(\" ". get_lang("NoteConfirmDelete") ." \"+ name + \" ?\"))
  29. {return true;}
  30. else
  31. {return false;}
  32. }
  33. </script>";
  34. }
  35. /**
  36. * This functions stores the note in the database
  37. *
  38. * @param array $values
  39. *
  40. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  41. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  42. * @version januari 2009, dokeos 1.8.6
  43. */
  44. function save_note($values) {
  45. // Database table definition
  46. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  47. $sql = "INSERT INTO $t_notebook (user_id, course, session_id, title, description, creation_date,update_date,status)
  48. VALUES(
  49. '".Database::escape_string(api_get_user_id())."',
  50. '".Database::escape_string(api_get_course_id())."',
  51. '".Database::escape_string($_SESSION['id_session'])."',
  52. '".Database::escape_string(Security::remove_XSS($values['note_title']))."',
  53. '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['note_comment'])),COURSEMANAGERLOWSECURITY))."',
  54. '".Database::escape_string(date('Y-m-d H:i:s'))."',
  55. '".Database::escape_string(date('Y-m-d H:i:s'))."',
  56. '0')";
  57. $result = Database::query($sql, __FILE__, __LINE__);
  58. $id = Database::insert_id();
  59. if ($id > 0) {
  60. //insert into item_property
  61. api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, $id, 'NotebookAdded', api_get_user_id());
  62. }
  63. // display the feedback message
  64. Display::display_confirmation_message(get_lang('NoteAdded'));
  65. }
  66. function get_note_information($notebook_id) {
  67. // Database table definition
  68. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  69. $sql = "SELECT notebook_id AS notebook_id,
  70. title AS note_title,
  71. description AS note_comment,
  72. session_id AS session_id
  73. FROM $t_notebook
  74. WHERE notebook_id = '".Database::escape_string($notebook_id)."' ";
  75. $result = Database::query($sql, __FILE__, __LINE__);
  76. return Database::fetch_array($result);
  77. }
  78. /**
  79. * This functions updates the note in the database
  80. *
  81. * @param array $values
  82. *
  83. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  84. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  85. * @version januari 2009, dokeos 1.8.6
  86. */
  87. function update_note($values) {
  88. // Database table definition
  89. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  90. $sql = "UPDATE $t_notebook SET
  91. user_id = '".Database::escape_string(api_get_user_id())."',
  92. course = '".Database::escape_string(api_get_course_id())."',
  93. session_id = '".Database::escape_string($_SESSION['id_session'])."',
  94. title = '".Database::escape_string(Security::remove_XSS($values['note_title']))."',
  95. description = '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['note_comment'])),COURSEMANAGERLOWSECURITY))."',
  96. update_date = '".Database::escape_string(date('Y-m-d H:i:s'))."'
  97. WHERE notebook_id = '".Database::escape_string($values['notebook_id'])."'";
  98. $result = Database::query($sql, __FILE__, __LINE__);
  99. //update item_property (update)
  100. api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($values['notebook_id']), 'NotebookUpdated', api_get_user_id());
  101. // display the feedback message
  102. Display::display_confirmation_message(get_lang('NoteUpdated'));
  103. }
  104. function delete_note($notebook_id) {
  105. // Database table definition
  106. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  107. $sql = "DELETE FROM $t_notebook WHERE notebook_id='".Database::escape_string($notebook_id)."' AND user_id = '".Database::escape_string(api_get_user_id())."'";
  108. $result = Database::query($sql, __FILE__, __LINE__);
  109. //update item_property (delete)
  110. api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($notebook_id), 'delete', api_get_user_id());
  111. Display::display_confirmation_message(get_lang('NoteDeleted'));
  112. }
  113. function display_notes() {
  114. global $_user;
  115. if (!$_GET['direction'])
  116. {
  117. $sort_direction = 'ASC';
  118. $link_sort_direction = 'DESC';
  119. }
  120. elseif ($_GET['direction'] == 'ASC')
  121. {
  122. $sort_direction = 'ASC';
  123. $link_sort_direction = 'DESC';
  124. }
  125. else
  126. {
  127. $sort_direction = 'DESC';
  128. $link_sort_direction = 'ASC';
  129. }
  130. // action links
  131. echo '<div class="actions" style="margin-bottom:20px">';
  132. //if (api_is_allowed_to_edit())
  133. //{
  134. if (!api_is_anonymous()) {
  135. if (api_get_session_id()==0)
  136. echo '<a href="index.php?'.api_get_cidreq().'&amp;action=addnote">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
  137. elseif(api_is_allowed_to_session_edit(false,true)){
  138. echo '<a href="index.php?'.api_get_cidreq().'&amp;action=addnote">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
  139. }
  140. } else {
  141. echo '<a href="javascript:void(0)">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
  142. }
  143. //}
  144. echo '<a href="index.php?'.api_get_cidreq().'&amp;action=changeview&amp;view=creation_date&amp;direction='.$link_sort_direction.'">'.Display::return_icon('calendar_select.gif',get_lang('OrderByCreationDate')).get_lang('OrderByCreationDate').'</a>';
  145. echo '<a href="index.php?'.api_get_cidreq().'&amp;action=changeview&amp;view=update_date&amp;direction='.$link_sort_direction.'">'.Display::return_icon('calendar_select.gif',get_lang('OrderByModificationDate')).get_lang('OrderByModificationDate').'</a>';
  146. echo '<a href="index.php?'.api_get_cidreq().'&amp;action=changeview&amp;view=title&amp;direction='.$link_sort_direction.'">'.Display::return_icon('comment.gif',get_lang('OrderByTitle')).get_lang('OrderByTitle').'</a>';
  147. echo '</div>';
  148. if (!in_array($_SESSION['notebook_view'],array('creation_date','update_date', 'title'))) {
  149. $_SESSION['notebook_view'] = 'creation_date';
  150. }
  151. // Database table definition
  152. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  153. $order_by = "";
  154. if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') {
  155. $order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction ";
  156. } else {
  157. $order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction ";
  158. }
  159. //condition for the session
  160. $session_id = api_get_session_id();
  161. $condition_session = api_get_session_condition($session_id);
  162. $cond_extra = ($_SESSION['notebook_view']== 'update_date')?" AND update_date <> '0000-00-00 00:00:00'":" ";
  163. $sql = "SELECT * FROM $t_notebook WHERE user_id = '".Database::escape_string(api_get_user_id())."' $condition_session $cond_extra $order_by";
  164. $result = Database::query($sql, __FILE__, __LINE__);
  165. while ($row = Database::fetch_array($result)) {
  166. //validacion when belongs to a session
  167. $session_img = api_get_session_image($row['session_id'], $_user['status']);
  168. echo '<div class="sectiontitle">';
  169. 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>';
  170. if ($row['update_date'] <> $row['creation_date']) {
  171. echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($row['update_date']).'&nbsp;&nbsp;<span class="dropbox_date">'.$row['update_date'].'</span>';
  172. }
  173. echo ')</span>';
  174. echo $row['title'] . $session_img;
  175. echo '</div>';
  176. echo '<div class="sectioncomment">'.$row['description'].'</div>';
  177. echo '<div>';
  178. echo '<a href="'.api_get_self().'?action=editnote&amp;notebook_id='.$row['notebook_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  179. 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>';
  180. echo '</div>';
  181. }
  182. //return $return;
  183. }
  184. }
  185. ?>