work.php 11 KB

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