work.php 61 KB

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