work.php 63 KB

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