notebookfunction.inc.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * @package dokeos.notebook
  5. * @author Christian Fasanando
  6. * This library enables maintenance of the notebook tool
  7. */
  8. /**
  9. * This function retrieves notebook details by users
  10. * @return array Array of type ([notebook_id=>a,user_id=>b,course=>c,session_id=>d,description=>e,start_date=>f,end_date=>g,status=>h],[])
  11. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  12. * @version octubre 2008, dokeos 1.8.6
  13. */
  14. function get_notebook_details($user_id) {
  15. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  16. $safe_user_id = Database::escape_string($user_id);
  17. $sql = "SELECT note.notebook_id,note.user_id,note.course,note.session_id,
  18. note.description,DATE_FORMAT(note.start_date,'%d/%m/%Y %H:%i:%s') as start_date,DATE_FORMAT(note.end_date,'%d/%m/%Y %H:%i:%s') as end_date,note.status
  19. FROM $t_notebook note where note.user_id='$safe_user_id' ORDER BY note.start_date";
  20. $result = api_sql_query($sql, __FILE__, __LINE__);
  21. return $result;
  22. }
  23. /**
  24. * This function add notebook details by users
  25. * @param user_id type int
  26. * @param course type String
  27. * @param session_id type int
  28. * @param description type String
  29. * @param start_date type Date
  30. * @return boolean
  31. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  32. * @version octubre 2008, dokeos 1.8
  33. */
  34. function add_notebook_details($user_id,$course,$session_id,$description,$start_date) {
  35. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  36. $safe_course = Database::escape_string($course);
  37. $safe_description = Database::escape_string($description);
  38. $safe_start_date = Database::escape_string($start_date);
  39. if (empty($safe_description) || empty($safe_start_date)) {
  40. return false;
  41. }
  42. $sql = "INSERT INTO $t_notebook(user_id,course,session_id,description,start_date,status)
  43. VALUES('$user_id' , '$safe_course','$session_id','$safe_description','$safe_start_date',0)";
  44. $result = api_sql_query($sql, __FILE__, __LINE__);
  45. return $result;
  46. }
  47. /**
  48. * This function modify notebook details by users
  49. * @param notebook_id type int
  50. * @param user_id type int
  51. * @param course type String
  52. * @param session_id type int
  53. * @param description type String
  54. * @param end_date type Date
  55. * @return boolean
  56. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  57. * @version octubre 2008, dokeos 1.8
  58. */
  59. function edit_notebook_details($notebook_id,$user_id,$course,$session_id,$description,$end_date) {
  60. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  61. if ($notebook_id !== strval(intval($notebook_id))) { return false;}
  62. $safe_notebook_id = (int)$notebook_id;
  63. $safe_course = Database::escape_string($course);
  64. $safe_description = Database::escape_string($description);
  65. $safe_end_date = Database::escape_string($end_date);
  66. if (empty($description) || empty($end_date)) {
  67. return false;
  68. }
  69. $sql = "UPDATE $t_notebook SET user_id='$user_id' , course='$safe_course',session_id='$session_id',description='$safe_description',end_date='$end_date',status='1' WHERE notebook_id='$notebook_id'";
  70. $result = api_sql_query($sql, __FILE__, __LINE__);
  71. return $result;
  72. }
  73. /**
  74. * This function delete notebook details by users
  75. * @param notebook_id type int
  76. * @return boolean
  77. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  78. * @version octubre 2008, dokeos 1.8
  79. */
  80. function delete_notebook_details($notebook_id) {
  81. $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK);
  82. if ($notebook_id !== strval(intval($notebook_id))) { return false;}
  83. $safe_notebook_id = (int)$notebook_id;
  84. $sql = "DELETE FROM $t_notebook WHERE notebook_id=$safe_notebook_id";
  85. $result = api_sql_query($sql, __FILE__, __LINE__);
  86. return $result;
  87. }
  88. /**
  89. * returns all the javascript that is required in notebook/index.php
  90. * this goes into the $htmlHeadXtra[] array
  91. */
  92. function to_javascript_notebook() {
  93. return "<script type=\"text/javascript\">
  94. function confirmation (name)
  95. {
  96. if (confirm(\" ". get_lang('AreYouSureToDelete') ." \"+ name + \" ?\"))
  97. {return true;}
  98. else
  99. {return false;}
  100. }
  101. function add_notebook() {
  102. msg_error='".get_lang('YouMustWriteANote')."';
  103. msg='<<".get_lang('WriteYourNoteHere').">>';
  104. if(document.frm_add_notebook.description.value=='' || document.frm_add_notebook.description.value==msg) {
  105. document.getElementById('msg_add_error').style.display='block';
  106. document.getElementById('msg_add_error').innerHTML=msg_error;
  107. } else {
  108. document.frm_add_notebook.submit();
  109. }
  110. }
  111. function edit_cancel_notebook() {
  112. document.frm_edit_notebook.upd_notebook_id.value = '';
  113. document.frm_edit_notebook.upd_description.value = '';
  114. document.frm_edit_notebook.submit();
  115. }
  116. function edit_notebook() {
  117. msg_error='".get_lang('YouMustWriteANote')."';
  118. if(document.frm_edit_notebook.upd_description.value=='') {
  119. document.getElementById('msg_edit_error').style.display='block';
  120. document.getElementById('msg_edit_error').innerHTML=msg_error;
  121. } else {
  122. document.frm_edit_notebook.submit();
  123. }
  124. }
  125. </script>";
  126. }