work.php 11 KB

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