work.php 12 KB

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