work.php 53 KB

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