work.php 12 KB

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