work.php 54 KB

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