work.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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>
  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. $_course = api_get_course_info();
  76. /* Constants and variables */
  77. $tool_name = get_lang('StudentPublications');
  78. $course_code = api_get_course_id();
  79. $session_id = api_get_session_id();
  80. $currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/';
  81. $currentCourseRepositoryWeb = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/';
  82. $currentUserFirstName = $_user['firstName'];
  83. $currentUserLastName = $_user['lastName'];
  84. $currentUserEmail = $_user['mail'];
  85. $item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
  86. $parent_id = isset($_REQUEST['parent_id']) ? Database::escape_string($_REQUEST['parent_id']) : '';
  87. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
  88. $submitGroupWorkUrl = isset($_REQUEST['submitGroupWorkUrl']) ? Security::remove_XSS($_REQUEST['submitGroupWorkUrl']) : '';
  89. $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
  90. $description = isset($_REQUEST['description']) ? $_REQUEST['description'] : '';
  91. $uploadvisibledisabled = isset($_REQUEST['uploadvisibledisabled']) ? Database::escape_string($_REQUEST['uploadvisibledisabled']) : $course_info['show_score'];
  92. //directories management
  93. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  94. $course_dir = $sys_course_path . $_course['path'];
  95. $base_work_dir = $course_dir . '/work';
  96. $link_target_parameter = ""; // e.g. "target=\"_blank\"";
  97. $display_list_users_without_publication = isset($_GET['list']) && Security::remove_XSS($_GET['list']) == 'without' ? true : false;
  98. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
  99. //Download folder
  100. if ($action == 'downloadfolder') {
  101. require 'downloadfolder.inc.php';
  102. }
  103. /* More init stuff */
  104. if (isset ($_POST['cancelForm']) && !empty ($_POST['cancelForm'])) {
  105. header('Location: '.api_get_self().'?origin='.$origin.'&amp;gradebook='.$gradebook);
  106. exit;
  107. }
  108. // If the POST's size exceeds 8M (default value in php.ini) the $_POST array is emptied
  109. // If that case happens, we set $submitWork to 1 to allow displaying of the error message
  110. // The redirection with header() is needed to avoid apache to show an error page on the next request
  111. if ($_SERVER['REQUEST_METHOD'] == 'POST' && !sizeof($_POST)) {
  112. if (strstr($_SERVER['REQUEST_URI'], '?')) {
  113. header('Location: ' . $_SERVER['REQUEST_URI'] . '&submitWork=1');
  114. exit();
  115. } else {
  116. header('Location: ' . $_SERVER['REQUEST_URI'] . '?submitWork=1');
  117. exit();
  118. }
  119. }
  120. $group_id = api_get_group_id();
  121. $display_upload_form = false;
  122. if ($action == 'upload_form') {
  123. $display_upload_form = true;
  124. }
  125. /* Header */
  126. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  127. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  128. $gradebook = $_SESSION['gradebook'];
  129. } elseif (empty($_GET['gradebook'])) {
  130. unset($_SESSION['gradebook']);
  131. $gradebook = '';
  132. }
  133. if (!empty($gradebook) && $gradebook == 'view') {
  134. $interbreadcrumb[] = array ('url' => '../gradebook/' . $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  135. }
  136. if (!empty($group_id)) {
  137. $group_properties = GroupManager::get_group_properties($group_id);
  138. $show_work = false;
  139. if (api_is_allowed_to_edit(false, true)) {
  140. $show_work = true;
  141. } else {
  142. // you are not a teacher
  143. $show_work = GroupManager::user_has_access($user_id, $group_id, GroupManager::GROUP_TOOL_WORK);
  144. }
  145. if (!$show_work) {
  146. api_not_allowed();
  147. }
  148. $interbreadcrumb[] = array ('url' => '../group/group.php', 'name' => get_lang('Groups'));
  149. $interbreadcrumb[] = array ('url' => '../group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  150. $url_dir ='';
  151. $interbreadcrumb[] = array ('url' =>'work.php?gidReq='.$group_id,'name' => get_lang('StudentPublications'));
  152. $url_dir = 'work.php?&id=' . $work_id;
  153. $interbreadcrumb[] = array ('url' => $url_dir,'name' => $my_folder_data['title']);
  154. if ($action == 'upload_form') {
  155. $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('UploadADocument'));
  156. }
  157. if ($action == 'create_dir') {
  158. $interbreadcrumb[] = array ('url' => 'work.php','name' => get_lang('CreateAssignment'));
  159. }
  160. Display :: display_header(null);
  161. } else {
  162. if (isset($origin) && $origin != 'learnpath') {
  163. if (isset($_GET['id']) && !empty($_GET['id']) || $display_upload_form || $action == 'settings' || $action == 'create_dir') {
  164. $interbreadcrumb[] = array ('url' => 'work.php', 'name' => get_lang('StudentPublications'));
  165. } else {
  166. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('StudentPublications'));
  167. }
  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' => '#', 'name' => get_lang('UploadADocument'));
  172. }
  173. if ($action == 'settings') {
  174. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('EditToolOptions'));
  175. }
  176. if ($action == 'create_dir') {
  177. $interbreadcrumb[] = array ('url' => '#','name' => get_lang('CreateAssignment'));
  178. }
  179. Display :: display_header(null);
  180. } else {
  181. //we are in the learnpath tool
  182. Display::display_reduced_header();
  183. }
  184. }
  185. //stats
  186. event_access_tool(TOOL_STUDENTPUBLICATION);
  187. $is_allowed_to_edit = api_is_allowed_to_edit();
  188. $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
  189. Display::display_introduction_section(TOOL_STUDENTPUBLICATION);
  190. // introduction section
  191. if ($origin == 'learnpath') {
  192. echo '<div style="height:15px">&nbsp;</div>';
  193. }
  194. /* Display links to upload form and tool options */
  195. if (!in_array($action, array('add','create_dir'))) {
  196. $token = Security::get_token();
  197. }
  198. display_action_links($work_id, $curdirpath, $action);
  199. // for teachers
  200. switch ($action) {
  201. case 'settings':
  202. //if posts
  203. if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
  204. // Changing the tool setting: default visibility of an uploaded document
  205. // @todo
  206. $query = "UPDATE ".$main_course_table." SET show_score='" . $uploadvisibledisabled . "' WHERE code='" . api_get_course_id() . "'";
  207. $res = Database::query($query);
  208. /**
  209. * Course data are cached in session so we need to update both the database
  210. * and the session data
  211. */
  212. $_course['show_score'] = $uploadvisibledisabled;
  213. Session::write('_course', $course);
  214. // changing the tool setting: is a student allowed to delete his/her own document
  215. // database table definition
  216. $table_course_setting = Database :: get_course_table(TOOL_COURSE_SETTING);
  217. // counting the number of occurrences of this setting (if 0 => add, if 1 => update)
  218. $query = "SELECT * FROM " . $table_course_setting . " WHERE c_id = $course_id AND variable = 'student_delete_own_publication'";
  219. $result = Database::query($query);
  220. $number_of_setting = Database::num_rows($result);
  221. if ($number_of_setting == 1) {
  222. $query = "UPDATE " . $table_course_setting . " SET value='" . Database::escape_string($_POST['student_delete_own_publication']) . "'
  223. WHERE variable='student_delete_own_publication' AND c_id = $course_id";
  224. Database::query($query);
  225. } else {
  226. $query = "INSERT INTO " . $table_course_setting . " (c_id, variable, value, category) VALUES
  227. ($course_id, 'student_delete_own_publication','" . Database::escape_string($_POST['student_delete_own_publication']) . "','work')";
  228. Database::query($query);
  229. }
  230. Display::display_confirmation_message(get_lang('Saved'));
  231. }
  232. /* Display of tool options */
  233. display_tool_options($uploadvisibledisabled, $origin);
  234. break;
  235. case 'mark_work':
  236. if (!api_is_allowed_to_edit()) {
  237. echo Display::return_message(get_lang('ActionNotAllowed'), 'error');
  238. Display::display_footer();
  239. }
  240. break;
  241. case 'create_dir':
  242. case 'add':
  243. //$check = Security::check_token('post');
  244. //show them the form for the directory name
  245. if ($is_allowed_to_edit && in_array($action, array('create_dir','add'))) {
  246. //create the form that asks for the directory name
  247. $form = new FormValidator('form1', 'post', api_get_self().'?action=create_dir&'. api_get_cidreq());
  248. $form->addElement('header', get_lang('CreateAssignment').$token);
  249. $form->addElement('hidden', 'action', 'add');
  250. $form->addElement('hidden', 'curdirpath', Security :: remove_XSS($curdirpath));
  251. // $form->addElement('hidden', 'sec_token', $token);
  252. $form->addElement('text', 'new_dir', get_lang('AssignmentName'));
  253. $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required');
  254. $form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
  255. $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>');
  256. $form->addElement('html', '<div id="options" style="display: none;">');
  257. //QualificationOfAssignment
  258. $form->addElement('text', 'qualification_value', get_lang('QualificationNumeric'));
  259. if (Gradebook::is_active()) {
  260. $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';}"));
  261. } else {
  262. //QualificationOfAssignment
  263. //$form->addElement('hidden', 'qualification_value',0);
  264. $form->addElement('hidden', 'make_calification', false);
  265. }
  266. $form->addElement('html', '<div id="option1" style="display: none;">');
  267. //Loading gradebook select
  268. load_gradebook_select_in_tool($form);
  269. $form->addElement('text', 'weight', get_lang('WeightInTheGradebook'));
  270. $form->addElement('html', '</div>');
  271. $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';}"));
  272. $form->addElement('html', '<div id="option2" style="display: none;">');
  273. $form->addElement('advanced_settings',draw_date_picker('expires'));
  274. $form->addElement('html', '</div>');
  275. $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';}"));
  276. $form->addElement('html', '<div id="option3" style="display: none;">');
  277. $form->addElement('advanced_settings', draw_date_picker('ends'));
  278. $form->addElement('html', '</div>');
  279. $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
  280. $form->addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
  281. $form->addElement('html', '</div>');
  282. $form->addElement('style_submit_button', 'submit', get_lang('CreateDirectory'));
  283. if ($form->validate()) {
  284. $directory = Security::remove_XSS($_POST['new_dir']);
  285. $directory = replace_dangerous_char($directory);
  286. $directory = disable_dangerous_file($directory);
  287. $dir_name = $curdirpath.$directory;
  288. $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
  289. // we insert here the directory in the table $work_table
  290. $dir_name_sql = '';
  291. if (!empty($created_dir)) {
  292. if ($curdirpath == '/') {
  293. $dir_name_sql = $created_dir;
  294. } else {
  295. $dir_name_sql = '/'.$created_dir;
  296. }
  297. $time = time();
  298. $today = api_get_utc_datetime($time);
  299. $sql_add_publication = "INSERT INTO " . $work_table . " SET
  300. c_id = $course_id,
  301. url = '".Database::escape_string($dir_name_sql)."',
  302. title = '".Database::escape_string($_POST['new_dir'])."',
  303. description = '".Database::escape_string($_POST['description'])."',
  304. author = '',
  305. active = '1',
  306. accepted = '1',
  307. filetype = 'folder',
  308. post_group_id = '".$group_id."',
  309. sent_date = '".$today."',
  310. qualification = '".(($_POST['qualification_value']!='') ? Database::escape_string($_POST['qualification_value']) : '') ."',
  311. parent_id = '',
  312. qualificator_id = '',
  313. date_of_qualification = '0000-00-00 00:00:00',
  314. weight = '".Database::escape_string($_POST['weight'])."',
  315. session_id = '".intval($id_session)."',
  316. allow_text_assignment = '".Database::escape_string($_POST['allow_text_assignment'])."',
  317. contains_file = 0,
  318. user_id = '".$user_id."'";
  319. Database::query($sql_add_publication);
  320. // add the directory
  321. $id = Database::insert_id();
  322. if ($id) {
  323. // Insert into agenda
  324. $agenda_id = 0;
  325. $end_date = '';
  326. if (isset($_POST['add_to_calendar']) && $_POST['add_to_calendar'] == 1) {
  327. require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
  328. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  329. // Setting today date
  330. $date = $end_date = $time;
  331. $title = sprintf(get_lang('HandingOverOfTaskX'), $_POST['new_dir']);
  332. if (!empty($_POST['type1'])) {
  333. $end_date = get_date_from_select('expires');
  334. $date = $end_date;
  335. }
  336. $description = isset($_POST['description']) ? $_POST['description'] : '';
  337. $content = '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.api_substr($dir_name_sql, 1).'" >'.$_POST['new_dir'].'</a>'.$description;
  338. $agenda_id = agenda_add_item($course_info, $title, $content, $date, $end_date, array('GROUP:'.$group_id), 0);
  339. }
  340. }
  341. //Folder created
  342. api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', $user_id, $group_id);
  343. Display :: display_confirmation_message(get_lang('DirectoryCreated'), false);
  344. // insert into student_publication_assignment
  345. //return something like this: 2008-02-45 00:00:00
  346. $enable_calification = isset($_POST['qualification_value']) && !empty($_POST['qualification_value']) ? 1 : 0;
  347. if (!empty($_POST['type1']) || !empty($_POST['type2'])) {
  348. $sql_add_homework = "INSERT INTO $TSTDPUBASG SET
  349. c_id = $course_id ,
  350. expires_on = '".((isset($_POST['type1']) && $_POST['type1']==1) ? api_get_utc_datetime(get_date_from_select('expires')) : '0000-00-00 00:00:00'). "',
  351. ends_on = '".((isset($_POST['type2']) && $_POST['type2']==1) ? api_get_utc_datetime(get_date_from_select('ends')) : '0000-00-00 00:00:00')."',
  352. add_to_calendar = '$agenda_id',
  353. enable_qualification = '$enable_calification',
  354. publication_id = '$id'";
  355. Database::query($sql_add_homework);
  356. $my_last_id = Database::insert_id();
  357. $sql_add_publication = "UPDATE $work_table SET has_properties = $my_last_id , view_properties = 1 WHERE c_id = $course_id AND id = $id";
  358. Database::query($sql_add_publication);
  359. } else {
  360. $sql_add_homework = "INSERT INTO $TSTDPUBASG SET
  361. c_id = $course_id ,
  362. expires_on = '0000-00-00 00:00:00',
  363. ends_on = '0000-00-00 00:00:00',
  364. add_to_calendar = '$agenda_id',
  365. enable_qualification = '".$enable_calification."',
  366. publication_id = '".$id."'";
  367. Database::query($sql_add_homework);
  368. $inserted_id = Database::insert_id();
  369. $sql_add_publication = "UPDATE $work_table SET has_properties = $inserted_id, view_properties = 0 WHERE c_id = $course_id AND id = $id";
  370. Database::query($sql_add_publication);
  371. }
  372. if (!empty($_POST['category_id'])) {
  373. if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1) {
  374. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  375. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  376. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
  377. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  378. $resource_name = $_POST['new_dir'];
  379. add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), 3, $id, $resource_name, $_POST['weight'], $_POST['qualification_value'], $_POST['description'], 1, api_get_session_id());
  380. }
  381. }
  382. if (api_get_course_setting('email_alert_students_on_new_homework') == 1) {
  383. send_email_on_homework_creation(api_get_course_id());
  384. }
  385. } else {
  386. Display :: display_error_message(get_lang('CannotCreateDir'));
  387. }
  388. } else {
  389. $form->display();
  390. }
  391. }
  392. case 'make_visible':
  393. case 'delete':
  394. case 'make_invisible':
  395. case 'move':
  396. case 'move_to':
  397. case 'list':
  398. /* Move file command */
  399. if ($is_allowed_to_edit && $action == 'move_to') {
  400. $move_to_path = get_work_path($_REQUEST['move_to_id']);
  401. if ($move_to_path==-1) {
  402. $move_to_path = '/';
  403. } elseif (substr($move_to_path, -1, 1) != '/') {
  404. $move_to_path = $move_to_path .'/';
  405. }
  406. //security fix: make sure they can't move files that are not in the document table
  407. if ($path = get_work_path($item_id)) {
  408. if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
  409. // Update db
  410. update_work_url($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']);
  411. api_item_property_update($_course, 'work', $_REQUEST['move_to_id'], 'FolderUpdated', $user_id);
  412. Display :: display_confirmation_message(get_lang('DirMv'));
  413. } else {
  414. Display :: display_error_message(get_lang('Impossible'));
  415. }
  416. } else {
  417. Display :: display_error_message(get_lang('Impossible'));
  418. }
  419. }
  420. /* Move file form request */
  421. if ($is_allowed_to_edit && $action == 'move') {
  422. if (!empty($item_id)) {
  423. $folders = array();
  424. $session_id = api_get_session_id();
  425. $session_id == 0 ? $withsession = " AND session_id = 0 " : $withsession = " AND session_id='".$session_id."'";
  426. $sql = "SELECT id, url, title FROM $work_table
  427. WHERE c_id = $course_id AND active IN (0, 1) AND url LIKE '/%' AND post_group_id = '".$group_id."'".$withsession;
  428. $res = Database::query($sql);
  429. while ($folder = Database::fetch_array($res)) {
  430. $folders[$folder['id']] = $folder['title'];
  431. }
  432. echo build_work_move_to_selector($folders, $curdirpath, $item_id);
  433. }
  434. }
  435. /* MAKE VISIBLE WORK COMMAND */
  436. if ($is_allowed_to_edit && $action == 'make_visible') {
  437. if (!empty($item_id)) {
  438. if (isset($item_id) && $item_id == 'all') {
  439. } else {
  440. $sql = "UPDATE " . $work_table . " SET accepted = 1 WHERE c_id = $course_id AND id = '" . $item_id . "'";
  441. Database::query($sql);
  442. api_item_property_update($course_info, 'work', $item_id, 'visible', api_get_user_id());
  443. Display::display_confirmation_message(get_lang('FileVisible'));
  444. }
  445. }
  446. }
  447. if ($is_allowed_to_edit && $action == 'make_invisible') {
  448. /* MAKE INVISIBLE WORK COMMAND */
  449. if (!empty($item_id)) {
  450. if (isset($item_id) && $item_id == 'all') {
  451. } else {
  452. $sql = "UPDATE " . $work_table . " SET accepted = 0
  453. WHERE c_id = $course_id AND id = '" . $item_id . "'";
  454. Database::query($sql);
  455. api_item_property_update($course_info, 'work', $item_id, 'invisible', api_get_user_id());
  456. Display::display_confirmation_message(get_lang('FileInvisible'));
  457. }
  458. }
  459. }
  460. /* Delete dir command */
  461. if ($is_allowed_to_edit && !empty($_REQUEST['delete_dir'])) {
  462. $delete_dir_id = intval($_REQUEST['delete_dir']);
  463. $locked = api_resource_is_locked_by_gradebook($delete_dir_id, LINK_STUDENTPUBLICATION);
  464. if ($locked == false) {
  465. $work_to_delete = get_work_data_by_id($delete_dir_id);
  466. del_dir($delete_dir_id);
  467. // gets calendar_id from student_publication_assigment
  468. $sql = "SELECT add_to_calendar FROM $TSTDPUBASG WHERE c_id = $course_id AND publication_id ='$delete_dir_id'";
  469. $res = Database::query($sql);
  470. $calendar_id = Database::fetch_row($res);
  471. // delete from agenda if it exists
  472. if (!empty($calendar_id[0])) {
  473. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  474. $sql = "DELETE FROM $t_agenda WHERE c_id = $course_id AND id ='".$calendar_id[0]."'";
  475. Database::query($sql);
  476. }
  477. $sql = "DELETE FROM $TSTDPUBASG WHERE c_id = $course_id AND publication_id ='$delete_dir_id'";
  478. Database::query($sql);
  479. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $delete_dir_id, api_get_session_id());
  480. $link_id = $link_info['id'];
  481. if ($link_info !== false) {
  482. remove_resource_from_course_gradebook($link_id);
  483. }
  484. Display :: display_confirmation_message(get_lang('DirDeleted') . ': '.$work_to_delete['title']);
  485. } else {
  486. Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
  487. }
  488. }
  489. /* DELETE WORK COMMAND */
  490. if ($action == 'delete' && $item_id) {
  491. $file_deleted = false;
  492. $is_author = user_is_author($item_id);
  493. $work_data = get_work_data_by_id($item_id);
  494. $locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION);
  495. if (($is_allowed_to_edit && $locked == false) || ($locked == false AND $is_author && api_get_course_setting('student_delete_own_publication') == 1 && $work_data['qualificator_id'] == 0)) {
  496. //we found the current user is the author
  497. $queryString1 = "SELECT url, contains_file FROM ".$work_table." WHERE c_id = $course_id AND id = $item_id";
  498. $result1 = Database::query($queryString1);
  499. $row = Database::fetch_array($result1);
  500. if (Database::num_rows($result1) > 0) {
  501. $queryString2 = "UPDATE " . $work_table . " SET active = 2 WHERE c_id = $course_id AND id = $item_id";
  502. $queryString3 = "DELETE FROM ".$TSTDPUBASG ." WHERE c_id = $course_id AND publication_id = $item_id";
  503. Database::query($queryString2);
  504. Database::query($queryString3);
  505. api_item_property_update($_course, 'work', $item_id, 'DocumentDeleted', $user_id);
  506. $work = $row['url'];
  507. if ($row['contains_file'] == 1) {
  508. if (!empty($work)) {
  509. if (api_get_setting('permanently_remove_deleted_files') == 'true') {
  510. my_delete($currentCourseRepositorySys.'/'.$work);
  511. Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
  512. $file_deleted = true;
  513. } else {
  514. $extension = pathinfo($work, PATHINFO_EXTENSION);
  515. $new_dir = $work.'_DELETED_'.$item_id.'.'.$extension;
  516. if (file_exists($currentCourseRepositorySys.'/'.$work)) {
  517. rename($currentCourseRepositorySys.'/'.$work, $currentCourseRepositorySys.'/'.$new_dir);
  518. Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
  519. $file_deleted = true;
  520. }
  521. }
  522. }
  523. } else {
  524. $file_deleted = true;
  525. }
  526. }
  527. }
  528. if (!$file_deleted) {
  529. Display::display_error_message(get_lang('YouAreNotAllowedToDeleteThisDocument'));
  530. }
  531. }
  532. /* Display list of student publications */
  533. if (!empty($my_folder_data['description'])) {
  534. echo '<p><div><strong>'.get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description'], STUDENT).'</p></div></p>';
  535. }
  536. $my_folder_data = get_work_data_by_id($work_id);
  537. $work_parents = array();
  538. if (empty($my_folder_data)) {
  539. $work_parents = getWorkList($work_id, $my_folder_data, $add_query);
  540. }
  541. if (api_is_allowed_to_edit()) {
  542. // Work list
  543. echo '<div class="row">';
  544. echo '<div class="span9">';
  545. if (!empty($group_id)) {
  546. $userList = GroupManager::get_users($group_id);
  547. } else {
  548. if (empty($session_id)) {
  549. $userList = CourseManager::get_user_list_from_course_code($course_code, $session_id, null, null, STUDENT);
  550. } else {
  551. $userList = CourseManager::get_user_list_from_course_code($course_code, $session_id, null, null, 0);
  552. }
  553. $userList = array_keys($userList);
  554. }
  555. display_student_publications_list($work_id, $my_folder_data, $work_parents, $origin, $add_query, $userList);
  556. echo '</div>';
  557. echo '<div class="span3">';
  558. $table = new HTML_Table(array('class' => 'data_table'));
  559. $column = 0;
  560. $row = 0;
  561. $headers = array(get_lang('Students'), get_lang('Works'));
  562. foreach ($headers as $header) {
  563. $table->setHeaderContents($row, $column, $header);
  564. $column++;
  565. }
  566. $row++;
  567. $column = 0;
  568. foreach ($userList as $userId) {
  569. $user = api_get_user_info($userId);
  570. $link = api_get_path(WEB_CODE_PATH).'work/student_work.php?'.api_get_cidreq().'&studentId='.$user['user_id'];
  571. $url = Display::url(api_get_person_name($user['firstname'], $user['lastname']), $link);
  572. $table->setCellContents($row, $column, $url);
  573. $column++;
  574. $userWorks = 0;
  575. foreach ($work_parents as $work) {
  576. $userWorks += getUniqueStudentAttempts($work->id, $group_id, $course_id, $session_id, $user['user_id']);
  577. }
  578. $cell = $userWorks." / ".count($work_parents);
  579. $table->setCellContents($row, $column, $cell);
  580. $row++;
  581. $column = 0;
  582. }
  583. echo $table->toHtml();
  584. echo '</div>';
  585. } else {
  586. display_student_publications_list($work_id, $my_folder_data, $work_parents, $origin, $add_query, null);
  587. }
  588. break;
  589. }
  590. if ($origin != 'learnpath') {
  591. //we are not in the learning path tool
  592. Display :: display_footer();
  593. }