work.php 11 KB

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