work.lib.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php // $Id$
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) Dokeos S.A.
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  14. ==============================================================================
  15. */
  16. function display_action_links($always_show_tool_options, $always_show_upload_form)
  17. {
  18. $display_output = "";
  19. if (! $always_show_upload_form )
  20. {
  21. $display_output .= "<li><strong>" . "<a href=\"".$_SERVER['PHP_SELF']."?display_upload_form=true\">". get_lang("UploadADocument") . "</strong></a></li>";
  22. }
  23. if (! $always_show_tool_options && api_is_allowed_to_edit() )
  24. {
  25. $display_output .= "<li><strong>" . "<a href=\"".$_SERVER['PHP_SELF']."?display_tool_options=true\">" . get_lang("EditToolOptions") . "</a>" . "</strong></a></li>";
  26. }
  27. if ($display_output != "") echo "<ul>$display_output</ul>";
  28. }
  29. /**
  30. * Displays all options for this tool.
  31. * These are
  32. * - make all files visible / invisible
  33. * - set the default visibility of uploaded files
  34. *
  35. * @param $uploadvisibledisabled
  36. * @param $origin
  37. */
  38. function display_tool_options($uploadvisibledisabled, $origin)
  39. {
  40. $is_allowed_to_edit = api_is_allowed_to_edit();
  41. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  42. if (! $is_allowed_to_edit) return;
  43. echo "<table cellpadding=\"5\" cellspacing=\"2\" border=\"0\">\n";
  44. echo "<tr>\n",
  45. "<td colspan=\"2\">\n",
  46. "<table cellspacing=\"0\" cellpadding=\"5\" border=\"1\" bordercolor\"gray\">\n",
  47. "<tr>\n",
  48. "<td>",
  49. get_lang('AllFiles')." : ",
  50. "<a href=\"".$_SERVER['PHP_SELF']."?origin=$origin&delete=all\" ",
  51. "onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."')) return false;\">",
  52. "<img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang('Delete')."\" align=\"absmiddle\">",
  53. "</a>",
  54. "&nbsp;";
  55. $sql_query = "SHOW COLUMNS FROM ".$work_table." LIKE 'accepted'";
  56. $sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
  57. if ($sql_result)
  58. {
  59. $columnStatus = mysql_fetch_array($sql_result);
  60. if ($columnStatus['Default'] == 1)
  61. {
  62. echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=$origin&make_invisible=all\">",
  63. "<img src=\"../img/visible.gif\" border=\"0\" alt=\"".get_lang('Invisible')."\" align=\"absmiddle\">",
  64. "</a>\n";
  65. }
  66. else
  67. {
  68. echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=$origin&make_visible=all\">",
  69. "<img src=\"../img/invisible.gif\" border=\"0\" alt=\"".get_lang('Visible')."\" align=\"absmiddle\">",
  70. "</a>\n";
  71. }
  72. }
  73. echo "</td></tr>";
  74. display_default_visibility_form($uploadvisibledisabled, $origin);
  75. echo "</table>";
  76. echo "</td></tr>";
  77. echo "</table>";
  78. }
  79. /**
  80. * Displays the form where course admins can specify wether uploaded documents
  81. * are visible or invisible by default.
  82. *
  83. * @param $uploadvisibledisabled
  84. * @param $origin
  85. */
  86. function display_default_visibility_form($uploadvisibledisabled, $origin)
  87. {
  88. ?>
  89. <form method="post" action="<?php echo $_SERVER['PHP_SELF']."?origin=$origin"; ?>">
  90. <tr><td align="left">
  91. <strong><?php echo get_lang("_default_upload"); ?><br></strong>
  92. <input class="checkbox" type="radio" name="uploadvisibledisabled" value="0"
  93. <?php if($uploadvisibledisabled==0) echo "checked"; ?>>
  94. <?php echo get_lang("_new_visible");?><br>
  95. <input class="checkbox" type="radio" name="uploadvisibledisabled" value="1"
  96. <?php if($uploadvisibledisabled==1) echo "checked"; ?>>
  97. <?php echo get_lang("_new_unvisible"); ?><br>
  98. <input type="submit" name="changeProperties" value="<?php echo get_lang("Ok"); ?>">
  99. </td></tr>
  100. </form>
  101. <?php
  102. }
  103. /**
  104. * Display the list of student publications, taking into account the user status
  105. *
  106. * @param $currentCourseRepositoryWeb, the web location of the course folder
  107. * @param $link_target_parameter - should there be a target parameter for the links
  108. * @param $dateFormatLong - date format
  109. * @param $origin - typically empty or 'learnpath'
  110. */
  111. function display_student_publications_list($currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin)
  112. {
  113. //init
  114. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  115. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  116. $is_allowed_to_edit = api_is_allowed_to_edit();
  117. $user_id = api_get_user_id();
  118. $publications_list = array();
  119. $sort_params = array();
  120. if( isset($_GET['column']))
  121. {
  122. $sort_params[] = 'column='.$_GET['column'];
  123. }
  124. if( isset($_GET['page_nr']))
  125. {
  126. $sort_params[] = 'page_nr='.$_GET['page_nr'];
  127. }
  128. if( isset($_GET['per_page']))
  129. {
  130. $sort_params[] = 'per_page='.$_GET['per_page'];
  131. }
  132. if( isset($_GET['direction']))
  133. {
  134. $sort_params[] = 'direction='.$_GET['direction'];
  135. }
  136. $sort_params = implode('&amp;',$sort_params);
  137. //Get list from database
  138. if (!empty($_SESSION['toolgroup'])){
  139. $group_query = " WHERE post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group
  140. }
  141. else {
  142. $group_query = '';
  143. }
  144. $sql_get_publications_list = "SELECT * " .
  145. "FROM ".$work_table." " .
  146. $group_query.
  147. "ORDER BY id";
  148. //echo $sql_get_publications_list;
  149. $sql_result = api_sql_query($sql_get_publications_list,__FILE__,__LINE__);
  150. $table_header[] = array(get_lang('Title'),true);
  151. $table_header[] = array(get_lang('Description'),true);
  152. $table_header[] = array(get_lang('Authors'),true);
  153. $table_header[] = array(get_lang('Date'),true);
  154. if( $is_allowed_to_edit)
  155. {
  156. $table_header[] = array(get_lang('Modify'),true);
  157. }
  158. $table_data = array();
  159. while( $work = mysql_fetch_object($sql_result))
  160. {
  161. //Get the author ID for that document from the item_property table
  162. $is_author = false;
  163. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=".$work->id;
  164. $author_qry = api_sql_query($author_sql,__FILE__,__LINE__);
  165. if(Database::num_rows($author_qry)==1){
  166. $is_author = true;
  167. }
  168. //display info depending on the permissions
  169. if( $work->accepted == '1' || $is_allowed_to_edit)
  170. {
  171. $row = array();
  172. if($work->accepted == '0')
  173. {
  174. $class='class="invisible"';
  175. }
  176. else
  177. {
  178. $class='';
  179. }
  180. $url = implode("/", array_map("rawurlencode", explode("/", $work->url)));
  181. $row[] = '<a href="'.$currentCourseRepositoryWeb.$url.'"'.$class.'>'.$work->title.'</a>';
  182. $row[] = $work->description;
  183. $row[] = $work->author;
  184. $row[] = $work->sent_date;
  185. if( $is_allowed_to_edit)
  186. {
  187. if($work->accepted == '1')
  188. {
  189. $action = '<a href="'.$_SERVER['PHP_SELF'].'?origin='.$origin.'&make_invisible='.$work->id.'&amp;'.$sort_params.'"><img src="../img/visible.gif" alt="'.get_lang('Invisible').'"></a>';
  190. }
  191. else
  192. {
  193. $action = '<a href="'.$_SERVER['PHP_SELF'].'?origin='.$origin.'&make_visible='.$work->id.'&amp;'.$sort_params.'"><img src="../img/invisible.gif" alt="'.get_lang('Visible').'"></a>';
  194. }
  195. $action .= '<a href="'.$_SERVER['PHP_SELF'].'?origin='.$origin.'&edit='.$work->id.'"><img src="../img/edit.gif" alt="'.get_lang('Modify').'"></a>';
  196. $action .= '<a href="'.$_SERVER['PHP_SELF'].'?origin='.$origin.'&delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;"><img src="../img/delete.gif" alt="'.get_lang('WorkDelete').'"></a>';
  197. $row[] = $action;
  198. }elseif($is_author){
  199. $action = '';
  200. $action .= '<a href="'.$_SERVER['PHP_SELF'].'?&origin='.$origin.'&edit='.$work->id.'"><img src="../img/edit.gif" alt="'.get_lang('Modify').'"></a>';
  201. $action .= '<a href="'.$_SERVER['PHP_SELF'].'?&origin='.$origin.'&delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;"><img src="../img/delete.gif" alt="'.get_lang('WorkDelete').'"></a>';
  202. $row[] = $action;
  203. }else{
  204. $row[] = " ";
  205. }
  206. $table_data[] = $row;
  207. }
  208. }
  209. if( count($table_data) > 0)
  210. {
  211. Display::display_sortable_table($table_header,$table_data);
  212. }
  213. }