work.php 55 KB

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