work.php 56 KB

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