work.php 53 KB

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