work.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.work
  5. **/
  6. /* INIT SECTION */
  7. $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
  8. require_once '../inc/global.inc.php';
  9. $current_course_tool = TOOL_STUDENTPUBLICATION;
  10. api_protect_course_script(true);
  11. require_once 'work.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  16. $course_id = api_get_course_int_id();
  17. $course_info = api_get_course_info();
  18. $user_id = api_get_user_id();
  19. $id_session = api_get_session_id();
  20. // Section (for the tabs)
  21. $this_section = SECTION_COURSES;
  22. $work_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  23. $my_folder_data = get_work_data_by_id($work_id);
  24. $curdirpath = '';
  25. $htmlHeadXtra[] = api_get_jqgrid_js();
  26. $htmlHeadXtra[] = to_javascript_work();
  27. $htmlHeadXtra[] = '<script>
  28. function setFocus() {
  29. $("#work_title").focus();
  30. }
  31. $(document).ready(function () {
  32. setFocus();
  33. });
  34. </script>';
  35. $_course = api_get_course_info();
  36. /* Constants and variables */
  37. $tool_name = get_lang('StudentPublications');
  38. $course_code = api_get_course_id();
  39. $session_id = api_get_session_id();
  40. $group_id = api_get_group_id();
  41. $item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
  42. $parent_id = isset($_REQUEST['parent_id']) ? Database::escape_string($_REQUEST['parent_id']) : '';
  43. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
  44. $submitGroupWorkUrl = isset($_REQUEST['submitGroupWorkUrl']) ? Security::remove_XSS($_REQUEST['submitGroupWorkUrl']) : '';
  45. $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
  46. $description = isset($_REQUEST['description']) ? $_REQUEST['description'] : '';
  47. $uploadvisibledisabled = isset($_REQUEST['uploadvisibledisabled']) ? Database::escape_string($_REQUEST['uploadvisibledisabled']) : $course_info['show_score'];
  48. $course_dir = api_get_path(SYS_COURSE_PATH).$_course['path'];
  49. $base_work_dir = $course_dir . '/work';
  50. $link_target_parameter = ""; // e.g. "target=\"_blank\"";
  51. $display_list_users_without_publication = isset($_GET['list']) && Security::remove_XSS($_GET['list']) == 'without' ? true : false;
  52. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
  53. //Download folder
  54. if ($action == 'downloadfolder') {
  55. require 'downloadfolder.inc.php';
  56. }
  57. $display_upload_form = false;
  58. if ($action == 'upload_form') {
  59. $display_upload_form = true;
  60. }
  61. /* Header */
  62. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  63. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  64. $gradebook = $_SESSION['gradebook'];
  65. } elseif (empty($_GET['gradebook'])) {
  66. unset($_SESSION['gradebook']);
  67. $gradebook = '';
  68. }
  69. if (!empty($gradebook) && $gradebook == 'view') {
  70. $interbreadcrumb[] = array ('url' => '../gradebook/' . $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  71. }
  72. if (!empty($group_id)) {
  73. $group_properties = GroupManager::get_group_properties($group_id);
  74. $show_work = false;
  75. if (api_is_allowed_to_edit(false, true)) {
  76. $show_work = true;
  77. } else {
  78. // you are not a teacher
  79. $show_work = GroupManager::user_has_access($user_id, $group_id, GroupManager::GROUP_TOOL_WORK);
  80. }
  81. if (!$show_work) {
  82. api_not_allowed();
  83. }
  84. $interbreadcrumb[] = array ('url' => '../group/group.php', 'name' => get_lang('Groups'));
  85. $interbreadcrumb[] = array ('url' => '../group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  86. $interbreadcrumb[] = array ('url' =>'work.php?gidReq='.$group_id,'name' => get_lang('StudentPublications'));
  87. $url_dir = 'work.php?&id=' . $work_id;
  88. $interbreadcrumb[] = array ('url' => $url_dir, 'name' => $my_folder_data['title']);
  89. if ($action == 'upload_form') {
  90. $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('UploadADocument'));
  91. }
  92. if ($action == 'create_dir') {
  93. $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('CreateAssignment'));
  94. }
  95. Display::display_header(null);
  96. } else {
  97. if (isset($origin) && $origin != 'learnpath') {
  98. if (isset($_GET['id']) && !empty($_GET['id']) || $display_upload_form || $action == 'settings' || $action == 'create_dir') {
  99. $interbreadcrumb[] = array ('url' => 'work.php', 'name' => get_lang('StudentPublications'));
  100. } else {
  101. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('StudentPublications'));
  102. }
  103. $url_dir = 'work.php?id=' . $work_id;
  104. $interbreadcrumb[] = array ('url' => $url_dir,'name' => $my_folder_data['title']);
  105. if ($action == 'upload_form') {
  106. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('UploadADocument'));
  107. }
  108. if ($action == 'settings') {
  109. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('EditToolOptions'));
  110. }
  111. if ($action == 'create_dir') {
  112. $interbreadcrumb[] = array ('url' => '#','name' => get_lang('CreateAssignment'));
  113. }
  114. Display :: display_header(null);
  115. } else {
  116. //we are in the learnpath tool
  117. Display::display_reduced_header();
  118. }
  119. }
  120. // Stats
  121. event_access_tool(TOOL_STUDENTPUBLICATION);
  122. $is_allowed_to_edit = api_is_allowed_to_edit();
  123. $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
  124. Display::display_introduction_section(TOOL_STUDENTPUBLICATION);
  125. if ($origin == 'learnpath') {
  126. echo '<div style="height:15px">&nbsp;</div>';
  127. }
  128. /* Display links to upload form and tool options */
  129. if (!in_array($action, array('add', 'create_dir'))) {
  130. $token = Security::get_token();
  131. }
  132. $courseInfo = api_get_course_info();
  133. display_action_links($work_id, $curdirpath, $action);
  134. // For teachers
  135. switch ($action) {
  136. case 'settings':
  137. //if posts
  138. if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
  139. updateSettings($course, $_POST['show_score'], $_POST['student_delete_own_publication']);
  140. Display::display_confirmation_message(get_lang('Saved'));
  141. }
  142. $studentDeleteOwnPublication = api_get_course_setting('student_delete_own_publication') == 1 ? 1 : 0;
  143. /* Display of tool options */
  144. settingsForm(
  145. array(
  146. 'show_score' => $course_info['show_score'],
  147. 'student_delete_own_publication' => $studentDeleteOwnPublication
  148. )
  149. );
  150. break;
  151. case 'mark_work':
  152. if (!api_is_allowed_to_edit()) {
  153. echo Display::return_message(get_lang('ActionNotAllowed'), 'error');
  154. Display::display_footer();
  155. }
  156. break;
  157. case 'create_dir':
  158. case 'add':
  159. // Show them the form for the directory name
  160. if ($is_allowed_to_edit && in_array($action, array('create_dir', 'add'))) {
  161. $form = new FormValidator('form1', 'post', api_get_path(WEB_CODE_PATH).'work/work.php?action=create_dir&'. api_get_cidreq());
  162. $form->addElement('header', get_lang('CreateAssignment'));
  163. $form->addElement('hidden', 'action', 'add');
  164. $form = getFormWork($form, array());
  165. $form->addElement('style_submit_button', 'submit', get_lang('CreateDirectory'));
  166. if ($form->validate()) {
  167. $result = addDir($_POST, $user_id, $_course, $group_id, $id_session);
  168. if ($result) {
  169. Display::display_confirmation_message(get_lang('DirectoryCreated'), false);
  170. } else {
  171. Display::display_error_message(get_lang('CannotCreateDir'));
  172. }
  173. } else {
  174. $form->display();
  175. }
  176. }
  177. case 'delete_dir':
  178. case 'move':
  179. case 'move_to':
  180. case 'list':
  181. /* Move file command */
  182. if ($is_allowed_to_edit && $action == 'move_to') {
  183. $move_to_path = get_work_path($_REQUEST['move_to_id']);
  184. if ($move_to_path==-1) {
  185. $move_to_path = '/';
  186. } elseif (substr($move_to_path, -1, 1) != '/') {
  187. $move_to_path = $move_to_path .'/';
  188. }
  189. //security fix: make sure they can't move files that are not in the document table
  190. if ($path = get_work_path($item_id)) {
  191. if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
  192. // Update db
  193. updateWorkUrl($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']);
  194. api_item_property_update($_course, 'work', $_REQUEST['move_to_id'], 'FolderUpdated', $user_id);
  195. Display::display_confirmation_message(get_lang('DirMv'));
  196. } else {
  197. Display::display_error_message(get_lang('Impossible'));
  198. }
  199. } else {
  200. Display :: display_error_message(get_lang('Impossible'));
  201. }
  202. }
  203. /* Move file form request */
  204. if ($is_allowed_to_edit && $action == 'move') {
  205. if (!empty($item_id)) {
  206. echo generateMoveForm($item_id, $curdirpath, $course_info, $group_id, $session_id);
  207. }
  208. }
  209. /* Delete dir */
  210. if ($is_allowed_to_edit && $action == 'delete_dir') {
  211. $work_to_delete = get_work_data_by_id($_REQUEST['id']);
  212. $result = deleteDirWork($_REQUEST['id']);
  213. if ($result) {
  214. Display::display_confirmation_message(get_lang('DirDeleted') . ': '.$work_to_delete['title']);
  215. }
  216. }
  217. /* Display list of student publications */
  218. if (!empty($my_folder_data['description'])) {
  219. echo '<p><div><strong>'.
  220. get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description'], STUDENT).
  221. '</p></div></p>';
  222. }
  223. $my_folder_data = get_work_data_by_id($work_id);
  224. $work_parents = array();
  225. if (empty($my_folder_data)) {
  226. $work_parents = getWorkList($work_id, $my_folder_data, $add_query);
  227. }
  228. if (api_is_allowed_to_edit()) {
  229. $userList = getWorkUserList($course_code, $session_id);
  230. // Work list
  231. echo '<div class="row">';
  232. echo '<div class="span9">';
  233. $grid = showTeacherWorkGrid();
  234. echo $grid ;
  235. echo '</div>';
  236. echo '<div class="span3">';
  237. echo showStudentList($userList, $work_parents, $group_id, $course_id, $session_id);
  238. echo '</div>';
  239. } else {
  240. echo showStudentWorkGrid();
  241. }
  242. break;
  243. }
  244. if ($origin != 'learnpath') {
  245. //we are not in the learning path tool
  246. Display :: display_footer();
  247. }