work.php 11 KB

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