work.php 61 KB

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