work.php 58 KB

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