work.php 52 KB

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