work.php 55 KB

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