work.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. $courseInfo = api_get_course_info();
  12. $course_id = $courseInfo['real_id'];
  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. $session_id = api_get_session_id();
  26. $group_id = api_get_group_id();
  27. $item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
  28. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
  29. $course_dir = api_get_path(SYS_COURSE_PATH).$_course['path'];
  30. $base_work_dir = $course_dir . '/work';
  31. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
  32. //Download folder
  33. if ($action == 'downloadfolder') {
  34. require 'downloadfolder.inc.php';
  35. }
  36. $display_upload_form = false;
  37. if ($action == 'upload_form') {
  38. $display_upload_form = true;
  39. }
  40. /* Header */
  41. if (api_is_in_gradebook()) {
  42. $interbreadcrumb[]= array(
  43. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  44. 'name' => get_lang('ToolGradebook')
  45. );
  46. }
  47. if (!empty($group_id)) {
  48. api_protect_course_group(GroupManager::GROUP_TOOL_WORK);
  49. $group_properties = GroupManager::get_group_properties($group_id);
  50. $interbreadcrumb[] = array(
  51. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  52. 'name' => get_lang('Groups'),
  53. );
  54. $interbreadcrumb[] = array(
  55. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  56. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  57. );
  58. $interbreadcrumb[] = array(
  59. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  60. 'name' => get_lang('StudentPublications'),
  61. );
  62. $url_dir = api_get_path(WEB_CODE_PATH).'work/work.php?&id=' . $work_id.'&'.api_get_cidreq();
  63. if (!empty($my_folder_data)) {
  64. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
  65. }
  66. if ($action == 'upload_form') {
  67. $interbreadcrumb[] = array(
  68. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  69. 'name' => get_lang('UploadADocument'),
  70. );
  71. }
  72. if ($action == 'create_dir') {
  73. $interbreadcrumb[] = array(
  74. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  75. 'name' => get_lang('CreateAssignment'),
  76. );
  77. }
  78. } else {
  79. if ($origin != 'learnpath') {
  80. if (isset($_GET['id']) && !empty($_GET['id']) || $display_upload_form || $action == 'settings' || $action == 'create_dir') {
  81. $interbreadcrumb[] = array(
  82. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  83. 'name' => get_lang('StudentPublications'),
  84. );
  85. } else {
  86. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('StudentPublications'));
  87. }
  88. if (!empty($my_folder_data)) {
  89. $interbreadcrumb[] = array(
  90. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?id='.$work_id.'&'.api_get_cidreq(),
  91. 'name' => $my_folder_data['title'],
  92. );
  93. }
  94. if ($action == 'upload_form') {
  95. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('UploadADocument'));
  96. }
  97. if ($action == 'settings') {
  98. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditToolOptions'));
  99. }
  100. if ($action == 'create_dir') {
  101. $interbreadcrumb[] = array('url' => '#','name' => get_lang('CreateAssignment'));
  102. }
  103. }
  104. }
  105. // Stats
  106. Event::event_access_tool(TOOL_STUDENTPUBLICATION);
  107. $is_allowed_to_edit = api_is_allowed_to_edit();
  108. $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
  109. /* Display links to upload form and tool options */
  110. if (!in_array($action, array('add', 'create_dir'))) {
  111. $token = Security::get_token();
  112. }
  113. $currentUrl = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
  114. $content = null;
  115. // For teachers
  116. switch ($action) {
  117. case 'settings':
  118. //if posts
  119. if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
  120. updateSettings(
  121. $courseInfo,
  122. $_POST['show_score'],
  123. $_POST['student_delete_own_publication']
  124. );
  125. Display::return_message(get_lang('Saved'));
  126. header('Location: '.$currentUrl);
  127. exit;
  128. }
  129. $studentDeleteOwnPublication = api_get_course_setting('student_delete_own_publication') == 1 ? 1 : 0;
  130. /* Display of tool options */
  131. $content = settingsForm(
  132. array(
  133. 'show_score' => $courseInfo['show_score'],
  134. 'student_delete_own_publication' => $studentDeleteOwnPublication
  135. )
  136. );
  137. break;
  138. case 'add':
  139. case 'create_dir':
  140. if (!$is_allowed_to_edit) {
  141. api_not_allowed();
  142. }
  143. $form = new FormValidator(
  144. 'form1',
  145. 'post',
  146. api_get_path(WEB_CODE_PATH) . 'work/work.php?action=create_dir&' . api_get_cidreq()
  147. );
  148. $form->addElement('header', get_lang('CreateAssignment'));
  149. $form->addElement('hidden', 'action', 'add');
  150. $defaults = isset($_POST) ? $_POST : array();
  151. $form = getFormWork($form, $defaults);
  152. $form->addButtonCreate(get_lang('CreateDirectory'));
  153. if ($form->validate()) {
  154. $result = addDir(
  155. $_POST,
  156. $user_id,
  157. $_course,
  158. $group_id,
  159. $id_session
  160. );
  161. if ($result) {
  162. Display::return_message(get_lang('DirectoryCreated'), 'success');
  163. } else {
  164. Display::return_message(get_lang('CannotCreateDir'), 'error');
  165. }
  166. header('Location: '.$currentUrl);
  167. exit;
  168. } else {
  169. $content = $form->return_form();
  170. }
  171. break;
  172. case 'delete_dir':
  173. if ($is_allowed_to_edit) {
  174. $work_to_delete = get_work_data_by_id($_REQUEST['id']);
  175. $result = deleteDirWork($_REQUEST['id']);
  176. if ($result) {
  177. Display::return_message(
  178. get_lang('DirDeleted') . ': ' . $work_to_delete['title'],
  179. 'success'
  180. );
  181. }
  182. header('Location: '.$currentUrl);
  183. exit;
  184. }
  185. break;
  186. case 'move':
  187. /* Move file form request */
  188. if ($is_allowed_to_edit) {
  189. if (!empty($item_id)) {
  190. $content = generateMoveForm(
  191. $item_id,
  192. $curdirpath,
  193. $courseInfo,
  194. $group_id,
  195. $session_id
  196. );
  197. }
  198. }
  199. break;
  200. case 'move_to':
  201. /* Move file command */
  202. if ($is_allowed_to_edit) {
  203. $move_to_path = get_work_path($_REQUEST['move_to_id']);
  204. if ($move_to_path==-1) {
  205. $move_to_path = '/';
  206. } elseif (substr($move_to_path, -1, 1) != '/') {
  207. $move_to_path = $move_to_path .'/';
  208. }
  209. // Security fix: make sure they can't move files that are not in the document table
  210. if ($path = get_work_path($item_id)) {
  211. if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
  212. // Update db
  213. updateWorkUrl(
  214. $item_id,
  215. 'work' . $move_to_path,
  216. $_REQUEST['move_to_id']
  217. );
  218. api_item_property_update(
  219. $_course,
  220. 'work',
  221. $_REQUEST['move_to_id'],
  222. 'FolderUpdated',
  223. $user_id
  224. );
  225. Display::return_message(get_lang('DirMv'), 'success');
  226. } else {
  227. Display::return_message(get_lang('Impossible'), 'error');
  228. }
  229. } else {
  230. Display::return_message(get_lang('Impossible'), 'error');
  231. }
  232. header('Location: '.$currentUrl);
  233. exit;
  234. }
  235. break;
  236. case 'visible':
  237. if (!$is_allowed_to_edit) {
  238. api_not_allowed();
  239. }
  240. api_item_property_update(
  241. $courseInfo,
  242. 'work',
  243. $work_id,
  244. 'visible',
  245. api_get_user_id(),
  246. null,
  247. null,
  248. null,
  249. null,
  250. $session_id
  251. );
  252. Display::return_message(
  253. get_lang('VisibilityChanged'),
  254. 'confirmation'
  255. );
  256. header('Location: '.$currentUrl);
  257. exit;
  258. break;
  259. case 'invisible':
  260. if (!$is_allowed_to_edit) {
  261. api_not_allowed();
  262. }
  263. api_item_property_update(
  264. $courseInfo,
  265. 'work',
  266. $work_id,
  267. 'invisible',
  268. api_get_user_id(),
  269. null,
  270. null,
  271. null,
  272. null,
  273. $session_id
  274. );
  275. Display::return_message(
  276. get_lang('VisibilityChanged'),
  277. 'confirmation'
  278. );
  279. header('Location: '.$currentUrl);
  280. exit;
  281. break;
  282. case 'list':
  283. /* Display list of student publications */
  284. if (!empty($my_folder_data['description'])) {
  285. $content = '<div>'.
  286. get_lang('Description').':'.Security::remove_XSS($my_folder_data['description'], STUDENT).
  287. '</div>';
  288. }
  289. if (api_is_allowed_to_edit() || api_is_coach()) {
  290. // Work list
  291. $content .= '<div class="row">';
  292. $content .= '<div class="col-md-12">';
  293. $content .= '<div class="table-responsive">';
  294. $content .= Display::panel(showTeacherWorkGrid());
  295. $content .= '</div>';
  296. $content .= '</div>';
  297. $content .= '<div id="student-list-work" style="display: none" class="table-responsive">';
  298. $content .= '<div class="toolbar"><a id="closed-view-list" href="#"><em class="fa fa-times-circle"></em> ' .get_lang('Close'). '</a></div>';
  299. $content .= showStudentList($work_id);
  300. $content .= '</div>';
  301. $content .= '</div>';
  302. } else {
  303. $content .= Display::panel(showStudentWorkGrid());
  304. }
  305. break;
  306. }
  307. Display::display_introduction_section(TOOL_STUDENTPUBLICATION);
  308. if ($origin == 'learnpath') {
  309. echo '<div style="height:15px">&nbsp;</div>';
  310. }
  311. display_action_links($work_id, $curdirpath, $action);
  312. echo $content;