work.php 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.work
  6. * @author Thomas, Hugues, Christophe - original version
  7. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - ability for course admins to specify wether uploaded documents are visible or invisible by default.
  8. * @author Roan Embrechts, code refactoring and virtual course support
  9. * @author Frederic Vauthier, directories management
  10. * @author Julio Montoya <gugli100@gmail.com> BeezNest 2011 LOTS of bug fixes
  11. *
  12. * @todo refactor more code into functions, use quickforms, coding standards, ... jm
  13. */
  14. /**
  15. * STUDENT PUBLICATIONS MODULE
  16. *
  17. * Note: for a more advanced module, see the dropbox tool.
  18. * This one is easier with less options.
  19. * This tool is better used for publishing things,
  20. * sending in assignments is better in the dropbox.
  21. *
  22. * GOALS
  23. * *****
  24. * Allow student to quickly send documents immediately visible on the Course
  25. *
  26. * The script does 5 things:
  27. *
  28. * 1. Upload documents
  29. * 2. Give them a name
  30. * 3. Modify data about documents
  31. * 4. Delete link to documents and simultaneously remove them
  32. * 5. Show documents list to students and visitors
  33. *
  34. * On the long run, the idea is to allow sending realvideo . Which means only
  35. * establish a correspondence between RealServer Content Path and the user's
  36. * documents path.
  37. *
  38. *
  39. */
  40. /* INIT SECTION */
  41. $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
  42. require_once '../inc/global.inc.php';
  43. $current_course_tool = TOOL_STUDENTPUBLICATION;
  44. /* Configuration settings */
  45. api_protect_course_script(true);
  46. // Including necessary files
  47. require_once 'work.lib.php';
  48. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  49. include_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  50. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  51. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  52. $course_id = api_get_course_int_id();
  53. $course_info = api_get_course_info();
  54. $user_id = api_get_user_id();
  55. $id_session = api_get_session_id();
  56. // Section (for the tabs)
  57. $this_section = SECTION_COURSES;
  58. $work_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  59. $my_folder_data = get_work_data_by_id($work_id);
  60. $curdirpath = '';
  61. $htmlHeadXtra[] = api_get_jqgrid_js();
  62. $htmlHeadXtra[] = to_javascript_work();
  63. $htmlHeadXtra[] = '<script type="text/javascript">
  64. function setFocus(){
  65. $("#work_title").focus();
  66. }
  67. $(document).ready(function () {
  68. setFocus();
  69. });
  70. </script>';
  71. // Table definitions
  72. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  73. $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  74. $TSTDPUBASG = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  75. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  76. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  77. $table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  78. $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  79. /* Constants and variables */
  80. $tool_name = get_lang('StudentPublications');
  81. $course_code = api_get_course_id();
  82. $session_id = api_get_session_id();
  83. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code,$session_id);
  84. $is_course_member = $is_course_member || api_is_platform_admin();
  85. $currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/';
  86. $currentCourseRepositoryWeb = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/';
  87. $currentUserFirstName = $_user['firstName'];
  88. $currentUserLastName = $_user['lastName'];
  89. $currentUserEmail = $_user['mail'];
  90. $item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
  91. $parent_id = isset($_REQUEST['parent_id']) ? Database::escape_string($_REQUEST['parent_id']) : '';
  92. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
  93. $submitGroupWorkUrl = isset($_REQUEST['submitGroupWorkUrl']) ? Security::remove_XSS($_REQUEST['submitGroupWorkUrl']) : '';
  94. $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
  95. $description = isset($_REQUEST['description']) ? $_REQUEST['description'] : '';
  96. $uploadvisibledisabled = isset($_REQUEST['uploadvisibledisabled']) ? Database::escape_string($_REQUEST['uploadvisibledisabled']) : $course_info['show_score'];
  97. // get data for publication assignment
  98. $has_expired = false;
  99. $has_ended = false;
  100. //directories management
  101. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  102. $course_dir = $sys_course_path . $_course['path'];
  103. $base_work_dir = $course_dir . '/work';
  104. $link_target_parameter = ""; // e.g. "target=\"_blank\"";
  105. $display_list_users_without_publication = isset($_GET['list']) && Security::remove_XSS($_GET['list']) == 'without' ? true : false;
  106. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
  107. //Download folder
  108. if ($action == 'downloadfolder') {
  109. require 'downloadfolder.inc.php';
  110. }
  111. /* More init stuff */
  112. if (isset ($_POST['cancelForm']) && !empty ($_POST['cancelForm'])) {
  113. header('Location: ' . api_get_self() . '?origin='.$origin.'&amp;gradebook='.$gradebook);
  114. exit;
  115. }
  116. // If the POST's size exceeds 8M (default value in php.ini) the $_POST array is emptied
  117. // If that case happens, we set $submitWork to 1 to allow displaying of the error message
  118. // The redirection with header() is needed to avoid apache to show an error page on the next request
  119. if ($_SERVER['REQUEST_METHOD'] == 'POST' && !sizeof($_POST)) {
  120. if (strstr($_SERVER['REQUEST_URI'], '?')) {
  121. header('Location: ' . $_SERVER['REQUEST_URI'] . '&submitWork=1');
  122. exit ();
  123. } else {
  124. header('Location: ' . $_SERVER['REQUEST_URI'] . '?submitWork=1');
  125. exit ();
  126. }
  127. }
  128. $group_id = api_get_group_id();
  129. $display_upload_form = false;
  130. if ($action == 'upload_form') {
  131. $display_upload_form = true;
  132. }
  133. /* Header */
  134. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  135. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  136. $gradebook = $_SESSION['gradebook'];
  137. } elseif (empty($_GET['gradebook'])) {
  138. unset($_SESSION['gradebook']);
  139. $gradebook = '';
  140. }
  141. if (!empty($gradebook) && $gradebook == 'view') {
  142. $interbreadcrumb[] = array ('url' => '../gradebook/' . $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  143. }
  144. if (!empty($group_id)) {
  145. $group_properties = GroupManager :: get_group_properties($group_id);
  146. $show_work = false;
  147. if (api_is_allowed_to_edit(false, true)) {
  148. $show_work = true;
  149. } else {
  150. // you are not a teacher
  151. $show_work = GroupManager::user_has_access($user_id, $group_id, GroupManager::GROUP_TOOL_WORK);
  152. }
  153. if (!$show_work) {
  154. api_not_allowed();
  155. }
  156. $interbreadcrumb[] = array ('url' => '../group/group.php', 'name' => get_lang('Groups'));
  157. $interbreadcrumb[] = array ('url' => '../group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  158. $url_dir ='';
  159. $interbreadcrumb[] = array ('url' =>'work.php?gidReq='.$group_id,'name' => get_lang('StudentPublications'));
  160. $url_dir = 'work.php?&id=' . $work_id;
  161. $interbreadcrumb[] = array ('url' => $url_dir,'name' => $my_folder_data['title']);
  162. if ($action == 'upload_form') {
  163. $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('UploadADocument'));
  164. }
  165. if ($action == 'create_dir') {
  166. $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('CreateAssignment'));
  167. }
  168. Display :: display_header(null);
  169. } else {
  170. if (isset($origin) && $origin != 'learnpath') {
  171. if (isset($_GET['id']) && !empty($_GET['id']) || $display_upload_form || $action == 'settings' || $action == 'create_dir') {
  172. $interbreadcrumb[] = array ('url' => 'work.php', 'name' => get_lang('StudentPublications'));
  173. } else {
  174. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('StudentPublications'));
  175. }
  176. $url_dir = 'work.php?id=' . $work_id;
  177. $interbreadcrumb[] = array ('url' => $url_dir,'name' => $my_folder_data['title']);
  178. if ($action == 'upload_form') {
  179. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('UploadADocument'));
  180. }
  181. if ($action == 'settings') {
  182. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('EditToolOptions'));
  183. }
  184. if ($action == 'create_dir') {
  185. $interbreadcrumb[] = array ('url' => '#','name' => get_lang('CreateAssignment'));
  186. }
  187. Display :: display_header(null);
  188. } else {
  189. //we are in the learnpath tool
  190. Display::display_reduced_header();
  191. }
  192. }
  193. //stats
  194. event_access_tool(TOOL_STUDENTPUBLICATION);
  195. $is_allowed_to_edit = api_is_allowed_to_edit(); //has to come after display_tool_view_option();
  196. $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
  197. Display :: display_introduction_section(TOOL_STUDENTPUBLICATION);
  198. // introduction section
  199. if ($origin == 'learnpath') {
  200. echo '<div style="height:15px">&nbsp;</div>';
  201. }
  202. /* Display links to upload form and tool options */
  203. if (!in_array($action, array('send_mail','add','create_dir','upload'))) {
  204. $token = Security::get_token();
  205. }
  206. $show_tool_options = (in_array($action, array('list', 'add'))) ? true : false;
  207. $display_upload_link = $action == 'upload_form' ? false : true;
  208. if (!empty($my_folder_data)) {
  209. $homework = get_work_assignment_by_id($my_folder_data['id']);
  210. if ($homework['expires_on'] != '0000-00-00 00:00:00' || $homework['ends_on'] != '0000-00-00 00:00:00') {
  211. $time_now = time();
  212. if (!empty($homework['expires_on']) && $homework['expires_on'] != '0000-00-00 00:00:00') {
  213. $time_expires = api_strtotime($homework['expires_on'], 'UTC');
  214. $difference = $time_expires - $time_now;
  215. if ($difference < 0) {
  216. $has_expired = true;
  217. }
  218. }
  219. if (empty($homework['expires_on']) || $homework['expires_on'] == '0000-00-00 00:00:00') {
  220. $has_expired = false;
  221. }
  222. if (!empty($homework['ends_on']) && $homework['ends_on'] != '0000-00-00 00:00:00') {
  223. $time_ends = api_strtotime($homework['ends_on'], 'UTC');
  224. $difference2 = $time_ends - $time_now;
  225. if ($difference2 < 0) {
  226. $has_ended = true;
  227. }
  228. }
  229. $ends_on = api_convert_and_format_date($homework['ends_on']);
  230. $expires_on = api_convert_and_format_date($homework['expires_on']);
  231. if ($has_ended) {
  232. //if (!api_is_allowed_to_edit()) {
  233. $display_upload_link = false;
  234. //}
  235. $message = Display::return_message(get_lang('EndDateAlreadyPassed').' '.$ends_on, 'error');
  236. } elseif ($has_expired) {
  237. $display_upload_link = true;
  238. $message = Display::return_message(get_lang('ExpiryDateAlreadyPassed').' '.$expires_on, 'warning');
  239. } else {
  240. if ($has_expired) {
  241. $message = Display::return_message(get_lang('ExpiryDateToSendWorkIs').' '.$expires_on);
  242. }
  243. }
  244. }
  245. }
  246. display_action_links($work_id, $curdirpath, $show_tool_options, $display_upload_link, $action);
  247. echo $message;
  248. //for teachers
  249. switch ($action) {
  250. case 'send_mail':
  251. if (Security::check_token('get')) {
  252. $mails_sent_to = send_reminder_users_without_publication($my_folder_data);
  253. if (empty($mails_sent_to)) {
  254. Display::display_warning_message(get_lang('NoResults'));
  255. } else {
  256. Display::display_confirmation_message(get_lang('MessageHasBeenSent').' '.implode(', ', $mails_sent_to));
  257. }
  258. Security::clear_token();
  259. }
  260. break;
  261. case 'settings':
  262. //if posts
  263. if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
  264. // changing the tool setting: default visibility of an uploaded document
  265. $query = "UPDATE " . $main_course_table . " SET show_score='" . $uploadvisibledisabled . "' WHERE code='" . api_get_course_id() . "'";
  266. $res = Database::query($query);
  267. /**
  268. * Course data are cached in session so we need to update both the database
  269. * and the session data
  270. */
  271. $_course['show_score'] = $uploadvisibledisabled;
  272. Session::write('_course', $course);
  273. // changing the tool setting: is a student allowed to delete his/her own document
  274. // database table definition
  275. $table_course_setting = Database :: get_course_table(TOOL_COURSE_SETTING);
  276. // counting the number of occurrences of this setting (if 0 => add, if 1 => update)
  277. $query = "SELECT * FROM " . $table_course_setting . " WHERE c_id = $course_id AND variable = 'student_delete_own_publication'";
  278. $result = Database::query($query);
  279. $number_of_setting = Database::num_rows($result);
  280. if ($number_of_setting == 1) {
  281. $query = "UPDATE " . $table_course_setting . " SET value='" . Database::escape_string($_POST['student_delete_own_publication']) . "'
  282. WHERE variable='student_delete_own_publication' AND c_id = $course_id";
  283. Database::query($query);
  284. } else {
  285. $query = "INSERT INTO " . $table_course_setting . " (c_id, variable, value, category) VALUES
  286. ($course_id, 'student_delete_own_publication','" . Database::escape_string($_POST['student_delete_own_publication']) . "','work')";
  287. Database::query($query);
  288. }
  289. Display::display_confirmation_message(get_lang('Saved'));
  290. }
  291. /* Display of tool options */
  292. display_tool_options($uploadvisibledisabled, $origin);
  293. break;
  294. case 'mark_work':
  295. if (!api_is_allowed_to_edit()) {
  296. echo Display::return_message(get_lang('ActionNotAllowed'), 'error');
  297. Display::display_footer();
  298. }
  299. break;
  300. case 'edit':
  301. case 'upload_form': //can be add or edit work
  302. $is_author = false;
  303. if (empty($item_id)) {
  304. $parent_data = get_work_data_by_id($work_id);
  305. $parent_data['qualification'] = intval($parent_data['qualification']);
  306. if (!empty($parent_data) && !empty($parent_data['qualification'])) {
  307. $count = get_work_count_by_student($user_id, $work_id);
  308. if ($count >= 1 ) {
  309. if (api_get_course_setting('student_delete_own_publication') == '1') {
  310. Display::display_warning_message(get_lang('CantUploadDeleteYourPaperFirst'));
  311. } else {
  312. Display::display_warning_message(get_lang('YouAlreadySentAPaperYouCantUpload'));
  313. }
  314. Display::display_footer();
  315. exit;
  316. }
  317. }
  318. } else {
  319. //we found the current user is the author
  320. $sql = "SELECT * FROM $work_table WHERE c_id = $course_id AND id = $item_id";
  321. $result = Database::query($sql);
  322. $work_item = array();
  323. if ($result) {
  324. $work_item = Database::fetch_array($result);
  325. }
  326. //Get the author ID for that document from the item_property table
  327. $is_author = user_is_author($item_id);
  328. if (!$is_author) {
  329. Display::display_warning_message(get_lang('NotAllowed'));
  330. Display::display_footer();
  331. }
  332. }
  333. $form = new FormValidator('form', 'POST', api_get_self() . "?action=upload&id=".$work_id."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&origin=$origin", '', array('enctype' => "multipart/form-data"));
  334. // form title
  335. if ($item_id) {
  336. $form_title = get_lang('Edit');
  337. } else {
  338. $form_title = get_lang('UploadADocument');
  339. }
  340. $form->addElement('header', $form_title);
  341. if (!empty ($error_message)) {
  342. Display :: display_error_message($error_message);
  343. }
  344. $show_progress_bar = false;
  345. if ($submitGroupWorkUrl) {
  346. // For user comming from group space to publish his work
  347. $realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl)));
  348. $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl);
  349. $text_document = $form->addElement('text', 'document', get_lang('Document'));
  350. $defaults['document'] = '<a href="' . format_url($submitGroupWorkUrl) . '">' . $realUrl . '</a>';
  351. $text_document->freeze();
  352. } elseif ($item_id && ($is_allowed_to_edit or $is_author)) {
  353. $workUrl = $currentCourseRepositoryWeb . $workUrl;
  354. } else {
  355. // else standard upload option
  356. $form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
  357. $show_progress_bar = true;
  358. }
  359. $form->addElement('hidden', 'id', $work_id);
  360. if (empty($item_id)) {
  361. $form->addElement('hidden', 'contains_file', 0, array('id'=>'contains_file_id'));
  362. } else {
  363. $form->addElement('hidden', 'item_id', $item_id);
  364. }
  365. $form->addElement('text', 'title', get_lang('Title'), array('id' => 'file_upload', 'class' => 'span4'));
  366. //$form->addElement('html_editor', 'description', get_lang("Description"));
  367. $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200'));
  368. if ($item_id && !empty($work_item)) {
  369. $defaults['title'] = $work_item['title'];
  370. $defaults["description"] = $work_item['description'];
  371. $defaults['qualification'] = $work_item['qualification'];
  372. }
  373. if ($is_allowed_to_edit && !empty($item_id)) {
  374. // Get qualification from parent_id that'll allow the validation qualification over
  375. $sql = "SELECT qualification FROM $work_table WHERE c_id = $course_id AND id ='$parent_id' ";
  376. $result = Database::query($sql);
  377. $row = Database::fetch_array($result);
  378. $qualification_over = $row['qualification'];
  379. if (!empty($qualification_over) && intval($qualification_over) > 0) {
  380. $form->addElement('text', 'qualification', array(get_lang('Qualification'), null, " / ".$qualification_over), 'size="10"');
  381. $form->addElement('hidden', 'qualification_over', $qualification_over);
  382. }
  383. }
  384. $form->addElement('hidden', 'active', 1);
  385. $form->addElement('hidden', 'accepted', 1);
  386. $form->addElement('hidden', 'item_to_edit', $item_id);
  387. $token = Security::get_token();
  388. $form->addElement('hidden', 'sec_token', $token);
  389. if ($item_id) {
  390. $text = get_lang('UpdateWork');
  391. $class = 'save';
  392. } else {
  393. $text = get_lang('Send');
  394. $class = 'upload';
  395. }
  396. // fix the Ok button when we see the tool in the learn path
  397. if ($origin == 'learnpath') {
  398. $form->addElement('html', '<div style="margin-left:137px">');
  399. $form->addElement('style_submit_button', 'submitWork', $text, array('class'=> $class, 'value' => "submitWork"));
  400. $form->addElement('html', '</div>');
  401. } else {
  402. if ($item_id) {
  403. $form->addElement('style_submit_button', 'editWork', $text, array('class'=> $class, 'value' => "editWork"));
  404. } else {
  405. $form->addElement('style_submit_button', 'submitWork', $text, array('class'=> $class, 'value' => "submitWork"));
  406. }
  407. }
  408. if (!empty($_POST['submitWork']) || $item_id) {
  409. $form->addElement('style_submit_button', 'cancelForm', get_lang('Cancel'), 'class="cancel"');
  410. }
  411. if ($show_progress_bar) {
  412. $form->add_real_progress_bar('uploadWork', 'file');
  413. }
  414. $form->setDefaults($defaults);
  415. //fixes bug when showing modification form
  416. if (!empty($work_id)) {
  417. if ($is_allowed_to_edit) {
  418. if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) {
  419. echo Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
  420. } else {
  421. $form->display();
  422. }
  423. } elseif ($is_author) {
  424. if (empty($work_item['qualificator_id']) || $work_item['qualificator_id'] == 0) {
  425. $form->display();
  426. } else {
  427. Display::display_error_message(get_lang('ActionNotAllowed'));
  428. }
  429. } elseif ($student_can_edit_in_session && $has_ended == false) {
  430. $form->display();
  431. } else {
  432. Display::display_error_message(get_lang('ActionNotAllowed'));
  433. }
  434. } else {
  435. Display::display_error_message(get_lang('ActionNotAllowed'));
  436. }
  437. break;
  438. case 'upload':
  439. $check = Security::check_token('post');
  440. if ($student_can_edit_in_session && $check) {
  441. //check the token inserted into the form
  442. if (isset($_POST['submitWork']) && !empty($is_course_member)) {
  443. $authors = api_get_person_name($currentUserFirstName, $currentUserLastName);
  444. $url = null;
  445. $contains_file = 0;
  446. if ($_POST['contains_file'] && !empty($_FILES['file']['size'])) {
  447. $updir = $currentCourseRepositorySys . 'work/'; //directory path to upload
  448. // Try to add an extension to the file if it has'nt one
  449. $new_file_name = add_ext_on_mime(stripslashes($_FILES['file']['name']), $_FILES['file']['type']);
  450. // Replace dangerous characters
  451. $new_file_name = replace_dangerous_char($new_file_name, 'strict');
  452. // Transform any .php file in .phps fo security
  453. $new_file_name = php2phps($new_file_name);
  454. $filesize = filesize($_FILES['file']['tmp_name']);
  455. if (empty($filesize)) {
  456. Display :: display_error_message(get_lang('UplUploadFailedSizeIsZero'));
  457. $succeed = false;
  458. } elseif (!filter_extension($new_file_name)) {
  459. //filter extension
  460. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  461. $succeed = false;
  462. }
  463. if (!$title) {
  464. $title = $_FILES['file']['name'];
  465. }
  466. // Compose a unique file name to avoid any conflict
  467. $new_file_name = api_get_unique_id();
  468. $curdirpath = basename($my_folder_data['url']);
  469. //if we come from the group tools the groupid will be saved in $work_table
  470. $result = @move_uploaded_file($_FILES['file']['tmp_name'], $updir.$curdirpath.'/'.$new_file_name);
  471. if ($result) {
  472. $url = 'work/'.$curdirpath.'/'.$new_file_name;
  473. $contains_file = 1;
  474. }
  475. }
  476. if (empty($title)) {
  477. $title = get_lang('Untitled');
  478. }
  479. $documents_total_space = DocumentManager::documents_total_space();
  480. $course_max_space = DocumentManager::get_course_quota();
  481. $total_size = $filesize + $documents_total_space;
  482. if ($total_size > $course_max_space) {
  483. $error_message = get_lang('NoSpace');
  484. } else {
  485. $active = '1';
  486. $sql_add_publication = "INSERT INTO " . $work_table . " SET
  487. c_id = $course_id ,
  488. url = '" . $url . "',
  489. title = '" . Database::escape_string($title) . "',
  490. description = '" . Database::escape_string($description) . "',
  491. author = '" . Database::escape_string($authors) . "',
  492. contains_file = '".$contains_file."',
  493. active = '" . $active . "',
  494. accepted = '1',
  495. post_group_id = '".$group_id."',
  496. sent_date = '".api_get_utc_datetime()."',
  497. parent_id = '".$work_id."' ,
  498. session_id = '".intval($id_session)."' ,
  499. user_id = '".$user_id."'";
  500. //var_dump($sql_add_publication);exit;
  501. Database::query($sql_add_publication);
  502. $id = Database::insert_id();
  503. }
  504. if ($id) {
  505. api_item_property_update($course_info, 'work', $id, 'DocumentAdded', $user_id, api_get_group_id());
  506. /*
  507. * See task #5145
  508. if($uploadvisibledisabled){
  509. $sql = "UPDATE $work_table SET accepted = 0 WHERE c_id = $course_id AND id = $id";
  510. Database::query($sql);
  511. api_item_property_update($course_info, 'work', $id, 'invisible', api_get_user_id());
  512. }else{
  513. //api_item_property_update($course_info, 'work', $id, 'visible', api_get_user_id());
  514. }*/
  515. $succeed = true;
  516. }
  517. } elseif ($newWorkUrl) {
  518. // SPECIAL CASE ! For a work coming from another area (i.e. groups)
  519. /*
  520. $url = str_replace('../../' . $_course['path'] . '/', '', $newWorkUrl);
  521. if (!$title) {
  522. $title = basename($workUrl);
  523. }
  524. $sql = "INSERT INTO " . $work_table . " SET
  525. c_id = $course_id,
  526. url = '" . $url . "',
  527. title = '" . Database::escape_string($title) . "',
  528. description = '" . Database::escape_string($description) . "',
  529. author = '" . Database::escape_string($authors) . "',
  530. post_group_id = '".$group_id."',
  531. sent_date = '".api_get_utc_datetime()."',
  532. session_id = '".intval($id_session)."',
  533. user_id = '".$user_id."'";
  534. Database::query($sql);
  535. $insertId = Database::insert_id();
  536. api_item_property_update($_course, 'work', $insertId, 'DocumentAdded', $user_id, $group_id);
  537. $succeed = true;*/
  538. } elseif (isset($_POST['editWork'])) {
  539. /*
  540. * SPECIAL CASE ! For a work edited
  541. */
  542. //Get the author ID for that document from the item_property table
  543. $item_to_edit_id = intval($_POST['item_to_edit']);
  544. $is_author = user_is_author($item_to_edit_id);
  545. if ($is_author) {
  546. $work_data = get_work_data_by_id($item_to_edit_id);
  547. if (!empty($_POST['title']))
  548. $title = isset($_POST['title']) ? $_POST['title'] : $work_data['title'];
  549. $description = isset($_POST['description']) ? $_POST['description'] : $work_data['description'];
  550. if ($is_allowed_to_edit && ($_POST['qualification'] !='' )) {
  551. $add_to_update = ', qualificator_id ='."'".api_get_user_id()."',";
  552. $add_to_update .= ' qualification = '."'".Database::escape_string($_POST['qualification'])."',";
  553. $add_to_update .= ' date_of_qualification ='."'".api_get_utc_datetime()."'";
  554. }
  555. if ((int)$_POST['qualification'] > (int)$_POST['qualification_over']) {
  556. Display::display_error_message(get_lang('QualificationMustNotBeMoreThanQualificationOver'));
  557. } else {
  558. $sql = "UPDATE " . $work_table . "
  559. SET title = '" . Database::escape_string($title) . "',
  560. description = '" . Database::escape_string($description) . "'
  561. ".$add_to_update."
  562. WHERE c_id = $course_id AND id = $item_to_edit_id";
  563. Database::query($sql);
  564. }
  565. api_item_property_update($_course, 'work', $item_to_edit_id, 'DocumentUpdated', $user_id);
  566. $succeed = true;
  567. Display :: display_confirmation_message(get_lang('ItemUpdated'), false);
  568. } else {
  569. $error_message = get_lang('IsNotPosibleSaveTheDocument');
  570. }
  571. } else {
  572. $error_message = get_lang('IsNotPosibleSaveTheDocument');
  573. }
  574. Security::clear_token();
  575. } else {
  576. //Bad token or can't add works
  577. $error_message = get_lang('IsNotPosibleSaveTheDocument');
  578. }
  579. if (!empty($succeed) && !empty($id)) {
  580. //last value is to check this is not "just" an edit
  581. //YW Tis part serve to send a e-mail to the tutors when a new file is sent
  582. $send = api_get_course_setting('email_alert_manager_on_new_doc');
  583. if ($send > 0) {
  584. // Lets predefine some variables. Be sure to change the from address!
  585. if (empty($id_session)) {
  586. //Teachers
  587. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), null, null, null, COURSEMANAGER);
  588. } else {
  589. //Coaches
  590. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, 2);
  591. }
  592. $emailsubject = "[" . api_get_setting('siteName') . "] ".get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$_course['name']." ";
  593. foreach ($user_list as $user_data) {
  594. $user_id = $user_data;
  595. $emailbody = get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$_course['name']."\n";
  596. //$emailbody .= get_lang('WorkName')." : ".substr($my_cur_dir_path, 0, -1)."\n";
  597. $emailbody .= get_lang('UserName')." : ".api_get_person_name($user_data['firstname'], $user_data['lastname'])."\n";
  598. $emailbody .= get_lang('DateSent')." : ".api_format_date(api_get_local_time())."\n";
  599. $emailbody .= get_lang('WorkName')." : ".$title."\n\n".get_lang('DownloadLink')."\n";
  600. $url = api_get_path(WEB_CODE_PATH)."work/work.php?".api_get_cidreq()."&amp;id=".$work_id;
  601. $emailbody .= Display::url($url, $url)." \n\n" . api_get_setting('administratorName') . " " . api_get_setting('administratorSurname') . "\n" . get_lang('Manager') . " " . api_get_setting('siteName') . "\n" . get_lang('Email') . " : " . api_get_setting('emailAdministrator');
  602. MessageManager::send_message_simple($user_id, $emailsubject, $emailbody);
  603. }
  604. }
  605. $message = get_lang('DocAdd');
  606. event_upload($id);
  607. Display :: display_confirmation_message(get_lang('DocAdd'), false);
  608. } else {
  609. if (!empty($error_message)) {
  610. Display :: display_warning_message($error_message, false);
  611. }
  612. }
  613. case 'create_dir':
  614. case 'add':
  615. //$check = Security::check_token('post');
  616. //show them the form for the directory name
  617. if ($is_allowed_to_edit && in_array($action, array('create_dir','add'))) {
  618. //create the form that asks for the directory name
  619. $form = new FormValidator('form1', 'post', api_get_self().'?action=create_dir&'. api_get_cidreq());
  620. $form->addElement('header', get_lang('CreateAssignment').$token);
  621. $form->addElement('hidden', 'action', 'add');
  622. $form->addElement('hidden', 'curdirpath', Security :: remove_XSS($curdirpath));
  623. // $form->addElement('hidden', 'sec_token', $token);
  624. $form->addElement('text', 'new_dir', get_lang('AssignmentName'));
  625. $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required');
  626. //$form->addElement('html_editor', 'description', get_lang('Description'));
  627. $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200'));
  628. $form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();"><span id="plus">'.Display::return_icon('div_show.gif',get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')).' '.get_lang('AdvancedParameters').'</span></a>');
  629. $form->addElement('html', '<div id="options" style="display: none;">');
  630. //QualificationOfAssignment
  631. $form->addElement('text', 'qualification_value', get_lang('QualificationNumeric'));
  632. if (Gradebook::is_active()) {
  633. $form->addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}"));
  634. } else {
  635. //QualificationOfAssignment
  636. //$form->addElement('hidden', 'qualification_value',0);
  637. $form->addElement('hidden', 'make_calification', false);
  638. }
  639. $form->addElement('html', '<div id="option1" style="display: none;">');
  640. //Loading gradebook select
  641. load_gradebook_select_in_tool($form);
  642. $form->addElement('text', 'weight', get_lang('WeightInTheGradebook'));
  643. $form->addElement('html', '</div>');
  644. $form->addElement('checkbox', 'type1', null, get_lang('EnableExpiryDate'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option2').style.display='block';}else{document.getElementById('option2').style.display='none';}"));
  645. $form->addElement('html', '<div id="option2" style="display: none;">');
  646. $form->addElement('advanced_settings',draw_date_picker('expires'));
  647. $form->addElement('html', '</div>');
  648. $form->addElement('checkbox', 'type2', null, get_lang('EnableEndDate'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option3').style.display='block';}else{document.getElementById('option3').style.display='none';}"));
  649. $form->addElement('html', '<div id="option3" style="display: none;">');
  650. $form->addElement('advanced_settings', draw_date_picker('ends'));
  651. $form->addElement('html', '</div>');
  652. $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
  653. $form->addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
  654. $form->addElement('html', '</div>');
  655. $form->addElement('style_submit_button', 'submit', get_lang('CreateDirectory'));
  656. if ($form->validate()) {
  657. $directory = Security::remove_XSS($_POST['new_dir']);
  658. $directory = replace_dangerous_char($directory);
  659. $directory = disable_dangerous_file($directory);
  660. $dir_name = $curdirpath.$directory;
  661. $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
  662. // we insert here the directory in the table $work_table
  663. $dir_name_sql = '';
  664. if (!empty($created_dir)) {
  665. if ($curdirpath == '/') {
  666. $dir_name_sql = $created_dir;
  667. } else {
  668. $dir_name_sql = '/'.$created_dir;
  669. }
  670. $time = time();
  671. $today = api_get_utc_datetime($time);
  672. $sql_add_publication = "INSERT INTO " . $work_table . " SET
  673. c_id = $course_id,
  674. url = '".Database::escape_string($dir_name_sql)."',
  675. title = '".Database::escape_string($_POST['new_dir'])."',
  676. description = '".Database::escape_string($_POST['description'])."',
  677. author = '',
  678. active = '1',
  679. accepted = '1',
  680. filetype = 'folder',
  681. post_group_id = '".$group_id."',
  682. sent_date = '".$today."',
  683. qualification = '".(($_POST['qualification_value']!='') ? Database::escape_string($_POST['qualification_value']) : '') ."',
  684. parent_id = '',
  685. qualificator_id = '',
  686. date_of_qualification = '0000-00-00 00:00:00',
  687. weight = '".Database::escape_string($_POST['weight'])."',
  688. session_id = '".intval($id_session)."',
  689. allow_text_assignment = '".Database::escape_string($_POST['allow_text_assignment'])."',
  690. contains_file = 0,
  691. user_id = '".$user_id."'";
  692. Database::query($sql_add_publication);
  693. // add the directory
  694. $id = Database::insert_id();
  695. if ($id) {
  696. // Insert into agenda
  697. $agenda_id = 0;
  698. $end_date = '';
  699. if (isset($_POST['add_to_calendar']) && $_POST['add_to_calendar'] == 1) {
  700. require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
  701. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  702. // Setting today date
  703. $date = $end_date = $time;
  704. $title = sprintf(get_lang('HandingOverOfTaskX'), $_POST['new_dir']);
  705. if (!empty($_POST['type1'])) {
  706. $end_date = get_date_from_select('expires');
  707. $date = $end_date;
  708. }
  709. $description = isset($_POST['description']) ? $_POST['description'] : '';
  710. $content = '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.api_substr($dir_name_sql, 1).'" >'.$_POST['new_dir'].'</a>'.$description;
  711. $agenda_id = agenda_add_item($course_info, $title, $content, $date, $end_date, array('GROUP:'.$group_id), 0);
  712. }
  713. }
  714. //Folder created
  715. api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', $user_id, $group_id);
  716. Display :: display_confirmation_message(get_lang('DirectoryCreated'), false);
  717. // insert into student_publication_assignment
  718. //return something like this: 2008-02-45 00:00:00
  719. $enable_calification = isset($_POST['qualification_value']) && !empty($_POST['qualification_value']) ? 1 : 0;
  720. if (!empty($_POST['type1']) || !empty($_POST['type2'])) {
  721. $sql_add_homework = "INSERT INTO $TSTDPUBASG SET
  722. c_id = $course_id ,
  723. expires_on = '".((isset($_POST['type1']) && $_POST['type1']==1) ? api_get_utc_datetime(get_date_from_select('expires')) : '0000-00-00 00:00:00'). "',
  724. ends_on = '".((isset($_POST['type2']) && $_POST['type2']==1) ? api_get_utc_datetime(get_date_from_select('ends')) : '0000-00-00 00:00:00')."',
  725. add_to_calendar = '$agenda_id',
  726. enable_qualification = '$enable_calification',
  727. publication_id = '$id'";
  728. Database::query($sql_add_homework);
  729. $my_last_id = Database::insert_id();
  730. $sql_add_publication = "UPDATE $work_table SET has_properties = $my_last_id , view_properties = 1 WHERE c_id = $course_id AND id = $id";
  731. Database::query($sql_add_publication);
  732. } else {
  733. $sql_add_homework = "INSERT INTO $TSTDPUBASG SET
  734. c_id = $course_id ,
  735. expires_on = '0000-00-00 00:00:00',
  736. ends_on = '0000-00-00 00:00:00',
  737. add_to_calendar = '$agenda_id',
  738. enable_qualification = '".$enable_calification."',
  739. publication_id = '".$id."'";
  740. Database::query($sql_add_homework);
  741. $inserted_id = Database::insert_id();
  742. $sql_add_publication = "UPDATE $work_table SET has_properties = $inserted_id, view_properties = 0 WHERE c_id = $course_id AND id = $id";
  743. Database::query($sql_add_publication);
  744. }
  745. if (!empty($_POST['category_id'])) {
  746. if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1) {
  747. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  748. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  749. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
  750. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  751. $resource_name = $_POST['new_dir'];
  752. add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), 3, $id, $resource_name, $_POST['weight'], $_POST['qualification_value'], $_POST['description'], 1, api_get_session_id());
  753. }
  754. }
  755. if (api_get_course_setting('email_alert_students_on_new_homework') == 1) {
  756. send_email_on_homework_creation(api_get_course_id());
  757. }
  758. } else {
  759. Display :: display_error_message(get_lang('CannotCreateDir'));
  760. }
  761. } else {
  762. $form->display();
  763. }
  764. }
  765. case 'make_visible':
  766. case 'delete':
  767. case 'make_invisible':
  768. case 'move':
  769. case 'move_to':
  770. case 'list':
  771. /* Move file command */
  772. if ($is_allowed_to_edit && $action == 'move_to') {
  773. $move_to_path = get_work_path($_REQUEST['move_to_id']);
  774. if ($move_to_path==-1) {
  775. $move_to_path = '/';
  776. } elseif (substr($move_to_path, -1, 1) != '/') {
  777. $move_to_path = $move_to_path .'/';
  778. }
  779. //security fix: make sure they can't move files that are not in the document table
  780. if ($path = get_work_path($item_id)) {
  781. if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
  782. //update db
  783. update_work_url($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']);
  784. api_item_property_update($_course, 'work', $_REQUEST['move_to_id'], 'FolderUpdated', $user_id);
  785. /*
  786. // update all the parents in the table item propery
  787. $list_id = get_parent_directories($move_to_path);
  788. for ($i = 0; $i < count($list_id); $i++) {
  789. api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
  790. }*/
  791. Display :: display_confirmation_message(get_lang('DirMv'));
  792. } else {
  793. Display :: display_error_message(get_lang('Impossible'));
  794. }
  795. } else {
  796. Display :: display_error_message(get_lang('Impossible'));
  797. }
  798. }
  799. /* Move file form request */
  800. if ($is_allowed_to_edit && $action == 'move') {
  801. if (!empty($item_id)) {
  802. $folders = array();
  803. $session_id = api_get_session_id();
  804. $session_id == 0 ? $withsession = " AND session_id = 0 " : $withsession = " AND session_id='".$session_id."'";
  805. $sql = "SELECT id, url, title FROM $work_table
  806. WHERE c_id = $course_id AND active IN (0, 1) AND url LIKE '/%' AND post_group_id = '".$group_id."'".$withsession;
  807. $res = Database::query($sql);
  808. while($folder = Database::fetch_array($res)) {
  809. $folders[$folder['id']] = $folder['title'];
  810. }
  811. echo build_work_move_to_selector($folders, $curdirpath, $item_id);
  812. }
  813. }
  814. /* MAKE VISIBLE WORK COMMAND */
  815. if ($is_allowed_to_edit && $action == 'make_visible') {
  816. if (!empty($item_id)) {
  817. if (isset($item_id) && $item_id == 'all') {
  818. //never happens
  819. /*
  820. $sql = "ALTER TABLE " . $work_table . " CHANGE accepted accepted TINYINT(1) DEFAULT '1'";
  821. Database::query($sql);
  822. $sql = "UPDATE " . $work_table . " SET accepted = 1";
  823. Database::query($sql);
  824. Display::display_confirmation_message(get_lang('AllFilesVisible'));*/
  825. } else {
  826. $sql = "UPDATE " . $work_table . " SET accepted = 1 WHERE c_id = $course_id AND id = '" . $item_id . "'";
  827. Database::query($sql);
  828. api_item_property_update($course_info, 'work', $item_id, 'visible', api_get_user_id());
  829. Display::display_confirmation_message(get_lang('FileVisible'));
  830. }
  831. }
  832. }
  833. if ($is_allowed_to_edit && $action == 'make_invisible') {
  834. /* MAKE INVISIBLE WORK COMMAND */
  835. if (!empty($item_id)) {
  836. if (isset($item_id) && $item_id == 'all') {
  837. /*
  838. $sql = "ALTER TABLE " . $work_table . "
  839. CHANGE accepted accepted TINYINT(1) DEFAULT '0'";
  840. Database::query($sql);
  841. $sql = "UPDATE " . $work_table . " SET accepted = 0";
  842. Database::query($sql);
  843. Display::display_confirmation_message(get_lang('AllFilesInvisible'));*/
  844. } else {
  845. $sql = "UPDATE " . $work_table . " SET accepted = 0
  846. WHERE c_id = $course_id AND id = '" . $item_id . "'";
  847. Database::query($sql);
  848. api_item_property_update($course_info, 'work', $item_id, 'invisible', api_get_user_id());
  849. Display::display_confirmation_message(get_lang('FileInvisible'));
  850. }
  851. }
  852. }
  853. /* Delete dir command */
  854. if ($is_allowed_to_edit && !empty($_REQUEST['delete_dir'])) {
  855. $delete_dir_id = intval($_REQUEST['delete_dir']);
  856. $locked = api_resource_is_locked_by_gradebook($delete_dir_id, LINK_STUDENTPUBLICATION);
  857. if ($locked == false) {
  858. $work_to_delete = get_work_data_by_id($delete_dir_id);
  859. del_dir($delete_dir_id);
  860. // gets calendar_id from student_publication_assigment
  861. $sql = "SELECT add_to_calendar FROM $TSTDPUBASG WHERE c_id = $course_id AND publication_id ='$delete_dir_id'";
  862. $res = Database::query($sql);
  863. $calendar_id = Database::fetch_row($res);
  864. // delete from agenda if it exists
  865. if (!empty($calendar_id[0])) {
  866. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  867. $sql = "DELETE FROM $t_agenda WHERE c_id = $course_id AND id ='".$calendar_id[0]."'";
  868. Database::query($sql);
  869. }
  870. $sql = "DELETE FROM $TSTDPUBASG WHERE c_id = $course_id AND publication_id ='$delete_dir_id'";
  871. Database::query($sql);
  872. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $delete_dir_id, api_get_session_id());
  873. $link_id = $link_info['id'];
  874. if ($link_info !== false) {
  875. remove_resource_from_course_gradebook($link_id);
  876. }
  877. Display :: display_confirmation_message(get_lang('DirDeleted') . ': '.$work_to_delete['title']);
  878. } else {
  879. Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
  880. }
  881. }
  882. /* DELETE WORK COMMAND */
  883. if ($action == 'delete' && $item_id) {
  884. $file_deleted = false;
  885. $is_author = user_is_author($item_id);
  886. $work_data = get_work_data_by_id($item_id);
  887. $locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION);
  888. if ( ($is_allowed_to_edit && $locked == false) || ($locked == false AND $is_author && api_get_course_setting('student_delete_own_publication') == 1 && $work_data['qualificator_id'] == 0)) {
  889. //we found the current user is the author
  890. $queryString1 = "SELECT url, contains_file FROM " . $work_table . " WHERE c_id = $course_id AND id = $item_id";
  891. $result1 = Database::query($queryString1);
  892. $row = Database::fetch_array($result1);
  893. if (Database::num_rows($result1) > 0) {
  894. $queryString2 = "UPDATE " . $work_table . " SET active = 2 WHERE c_id = $course_id AND id = $item_id";
  895. $queryString3 = "DELETE FROM " . $TSTDPUBASG . " WHERE c_id = $course_id AND publication_id = $item_id";
  896. Database::query($queryString2);
  897. Database::query($queryString3);
  898. api_item_property_update($_course, 'work', $item_id, 'DocumentDeleted', $user_id);
  899. $work = $row['url'];
  900. if ($row['contains_file'] == 1) {
  901. if (!empty($work)) {
  902. if (api_get_setting('permanently_remove_deleted_files') == 'true') {
  903. my_delete($currentCourseRepositorySys.'/'.$work);
  904. Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
  905. $file_deleted = true;
  906. } else {
  907. $extension = pathinfo($work, PATHINFO_EXTENSION);
  908. $new_dir = $work.'_DELETED_'.$item_id.'.'.$extension;
  909. if (file_exists($currentCourseRepositorySys.'/'.$work)) {
  910. rename($currentCourseRepositorySys.'/'.$work, $currentCourseRepositorySys.'/'.$new_dir);
  911. Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
  912. $file_deleted = true;
  913. }
  914. }
  915. }
  916. } else {
  917. $file_deleted = true;
  918. }
  919. }
  920. }
  921. if (!$file_deleted) {
  922. Display::display_error_message(get_lang('YouAreNotAllowedToDeleteThisDocument'));
  923. }
  924. }
  925. /* Display list of student publications */
  926. if ($curdirpath == '/') {
  927. $my_cur_dir_path = '';
  928. } else {
  929. $my_cur_dir_path = $curdirpath;
  930. }
  931. if (!empty($my_folder_data['description'])) {
  932. echo '<p><div><strong>'.get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description'], STUDENT).'</p></div></p>';
  933. }
  934. //User works
  935. if (isset($work_id) && !empty($work_id) && !$display_list_users_without_publication) {
  936. $work_data = get_work_assignment_by_id($work_id);
  937. $check_qualification = intval($my_folder_data['qualification']);
  938. if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
  939. $type = 'simple';
  940. $columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'),
  941. get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions'));
  942. $column_model = array (
  943. array('name'=>'type', 'index'=>'file', 'width'=>'12', 'align'=>'left', 'search' => 'false'),
  944. array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
  945. array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
  946. array('name'=>'username', 'index'=>'username', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  947. array('name'=>'title', 'index'=>'title', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'wrap_cell' => 'true'),
  948. // array('name'=>'file', 'index'=>'file', 'width'=>'20', 'align'=>'left', 'search' => 'false'),
  949. array('name'=>'qualification', 'index'=>'qualification', 'width'=>'20', 'align'=>'left', 'search' => 'true'),
  950. array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'50', 'align'=>'left', 'search' => 'true'),
  951. array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  952. array('name'=>'actions', 'index'=>'actions', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'sortable'=>'false')
  953. );
  954. } else {
  955. $type = 'complex';
  956. $columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'),
  957. get_lang('Date'), get_lang('Actions'));
  958. $column_model = array (
  959. array('name'=>'type', 'index'=>'file', 'width'=>'12', 'align'=>'left', 'search' => 'false'),
  960. array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
  961. array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
  962. array('name'=>'username', 'index'=>'username', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  963. array('name'=>'title', 'index'=>'title', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"),
  964. // array('name'=>'file', 'index'=>'file', 'width'=>'20', 'align'=>'left', 'search' => 'false'),
  965. //array('name'=>'qualification', 'index'=>'qualification', 'width'=>'20', 'align'=>'left', 'search' => 'true'),
  966. array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'50', 'align'=>'left', 'search' => 'true'),
  967. //array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  968. array('name'=>'actions', 'index'=>'actions', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'sortable'=>'false')
  969. );
  970. }
  971. $extra_params = array();
  972. //Autowidth
  973. $extra_params['autowidth'] = 'true';
  974. //height auto
  975. $extra_params['height'] = 'auto';
  976. //$extra_params['excel'] = 'excel';
  977. //$extra_params['rowList'] = array(10, 20 ,30);
  978. $extra_params['sortname'] = 'firstname';
  979. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_user_list&work_id='.$work_id.'&type='.$type;
  980. ?>
  981. <script>
  982. $(function() {
  983. <?php
  984. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params);
  985. ?>
  986. });
  987. </script>
  988. <?php
  989. echo Display::grid_html('results');
  990. } elseif (isset($_GET['list']) && $_GET['list'] == 'without') {
  991. //User with no works
  992. display_list_users_without_publication($work_id);
  993. } else {
  994. //Work list
  995. display_student_publications_list($work_id, $link_target_parameter, $dateFormatLong, $origin, $add_query);
  996. }
  997. break;
  998. }
  999. if ($origin != 'learnpath') {
  1000. //we are not in the learning path tool
  1001. Display :: display_footer();
  1002. }