work.php 54 KB

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