index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * @package dokeos.notebook
  5. * @author Christian Fasanando
  6. * Notebook tool's user interface
  7. */
  8. $language_file = array ('notebook');
  9. require_once('../inc/global.inc.php');
  10. api_protect_course_script(true);
  11. require_once('notebookfunction.inc.php');
  12. /*
  13. * Header
  14. */
  15. $htmlHeadXtra[] = to_javascript_notebook();
  16. $tool = TOOL_NOTEBOOK;
  17. Display::display_header(get_lang(ucfirst($tool)));
  18. $user_id = api_get_user_id();
  19. $course_id = api_get_course_id();
  20. $session_id = $_SESSION['id_session'];
  21. $ctok = $_SESSION['sec_token'];
  22. $stok = Security::get_token();
  23. $date = date('Y/m/d H:i:s');
  24. $icon_add = 'kwrite.gif';
  25. $icon_edit ='edit.gif';
  26. $icon_delete ='delete.gif';
  27. //---------------------------------------------------------
  28. echo '<a href="index.php?action=addnotebook">'.Display::return_icon($icon_add,get_lang('NewNote')).get_lang('NewNote').'</a>';
  29. if (isset($_REQUEST['action']) && $_REQUEST['action']=='addnotebook') {
  30. echo '<table class="notebook-add-form" id="notebook-add">';
  31. echo '<tr><td>';
  32. echo '<form name="frm_add_notebook" method="post">';
  33. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  34. echo '<input type="hidden" name="action" value="addnotebook">';
  35. echo '<div class="add-desc-notebook"><textarea class="style-add-textarea" rows="5" cols="80" name="description" maxlength="255" onfocus="this.value=\'\';document.getElementById(\'msg_add_error\').style.display=\'none\';"><<'.get_lang('WriteYourNoteHere').'>></textarea></div>';
  36. echo '<div class="action_notebook"><input type="button" value="'.get_lang('SaveNote').'" onclick="return add_notebook()"><input type="button" value="'.get_lang('Cancel').'" onclick="document.getElementById(\'notebook-add\').style.display = \'none\';document.getElementById(\'msg_add_error\').style.display=\'none\';"></div>';
  37. echo '<span class="msg_error" id="msg_add_error"></span>';
  38. echo '</form>';
  39. echo '</td></tr>';
  40. echo '</table>';
  41. }
  42. /*======================================
  43. Add Notebook Details
  44. ======================================*/
  45. if ($ctok==$_POST['sec_token']) {
  46. if ((isset($_REQUEST['action']) && $_REQUEST['action']=='addnotebook') && isset($_REQUEST['description'])) {
  47. $description = Security::remove_XSS($_REQUEST['description']);
  48. $add_notebook= add_notebook_details($user_id,$course_id,$session_id,$description,$date);
  49. if($add_notebook) {
  50. Display::display_confirmation_message(get_lang('NoteCreated'));
  51. }
  52. }
  53. }
  54. /*======================================
  55. Edit Notebook Details
  56. ======================================*/
  57. if ($ctok==$_POST['sec_token']) {
  58. if (isset($_REQUEST['upd_notebook_id']) && isset($_REQUEST['upd_description'])) {
  59. $notebook_id = Security::remove_XSS($_REQUEST['upd_notebook_id']);
  60. $description = Security::remove_XSS($_REQUEST['upd_description']);
  61. $edit_notebook= edit_notebook_details($notebook_id,$user_id,$course_id,$session_id,$description,$date);
  62. if($edit_notebook) {
  63. Display::display_confirmation_message(get_lang('NoteUpdated'));
  64. }
  65. }
  66. }
  67. /*======================================
  68. Delete Notebook Details
  69. ======================================*/
  70. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_notebook'){
  71. $notebook_id = Security::remove_XSS($_REQUEST['notebook_id']);
  72. $delete_notebook = delete_notebook_details($notebook_id);
  73. if($delete_notebook) {
  74. Display::display_confirmation_message(get_lang('NoteDeleted'));
  75. }
  76. }
  77. /*======================================
  78. Display Notebook Details
  79. ======================================*/
  80. $notebook_list=get_notebook_details($user_id);
  81. echo '<div>';
  82. $counter = 1;
  83. while ($row_notebook_list=Database::fetch_array($notebook_list)){
  84. $title= get_lang('Note').'&nbsp;'.$counter;
  85. $notebook_id = $_REQUEST['notebook_id'];
  86. echo '<div class="notebook-list">';
  87. echo '<div class="note-number">';
  88. echo '<span>'.$title.'</span>&nbsp;|&nbsp;';
  89. echo '<span class="date_information" >'.$row_notebook_list['start_date'].'</span>';
  90. echo '</div>';
  91. if ((isset($_REQUEST['action']) && $_REQUEST['action']=='edit_notebook') && ($row_notebook_list['notebook_id'] == $notebook_id)){
  92. echo '<div class="notebook-edit-form"><a name="note-'.$row_notebook_list['notebook_id'].'"></a>';
  93. echo '<form name="frm_edit_notebook" action="index.php" method="post"><input type="hidden" name="upd_notebook_id" value="'.$notebook_id.'" />';
  94. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  95. echo '<div class="upd-desc-notebook"><textarea class="style-edit-textarea" rows="4" cols="120" name="upd_description" maxlength="255" onfocus="this.select()">'.$row_notebook_list['description'].'</textarea></div>';
  96. echo '<div class="action_notebook"><input type="button" value="'.get_lang('SaveNote').'" onclick="edit_notebook()"><input type="button" value="'.get_lang('Cancel').'" onclick="edit_cancel_notebook()"></div>';
  97. echo '<span class="msg_error" id="msg_edit_error"></span>';
  98. echo '</form></div>';
  99. } else {
  100. echo '<div class="desc-notebook">'.$row_notebook_list['description'].'</div>';
  101. echo '<div class="notebook-term-action-links">';
  102. echo '<span><a href="index.php?action=edit_notebook&notebook_id='.$row_notebook_list['notebook_id'].'#note-'.$row_notebook_list['notebook_id'].'" >'.Display::return_icon($icon_edit,get_lang('Edit')).'</a>&nbsp;';
  103. echo '<a href="index.php?action=delete_notebook&notebook_id='.$row_notebook_list['notebook_id'].'" onclick="return confirmation(\''.$title.'\');">'.Display::return_icon($icon_delete,get_lang('Edit')).'</a></span>';
  104. if ( $row_notebook_list['status']==1 ) {
  105. echo '&nbsp;&nbsp;<span class="date_information">'.get_lang('LastUpdateDate').'&nbsp;:&nbsp;'.$row_notebook_list['end_date'].'</span>';
  106. }
  107. echo '</div>';
  108. }
  109. echo '</div>';
  110. $counter++;
  111. }
  112. echo '</div>';
  113. /*
  114. ==============================================================================
  115. FOOTER
  116. ==============================================================================
  117. */
  118. Display::display_footer();