work.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  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(null,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. Database::query($query, __FILE__, __LINE__);
  355. $_course['show_score'] = $uploadvisibledisabled;
  356. } else {
  357. $query = "SELECT * FROM " . $main_course_table . " WHERE code=\"" . $_course['sysCode'] . "\"";
  358. $result = Database::query($query, __FILE__, __LINE__);
  359. $row = Database::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(null,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 = Database::query($queryString1, __FILE__, __LINE__);
  387. $result2 = Database::query($queryString2, __FILE__, __LINE__);
  388. $result3 = Database::query($queryString3, __FILE__, __LINE__);
  389. }
  390. }
  391. /*-------------------------------------------
  392. EDIT COMMAND WORK COMMAND
  393. -----------------------------------------*/
  394. $qualification_number=0;
  395. if (!empty($edit)) {
  396. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  397. api_not_allowed();
  398. }
  399. $sql = "SELECT * FROM " . $work_table . " WHERE id='" . $edit . "'";
  400. $result = Database::query($sql, __FILE__, __LINE__);
  401. if (!empty($result)) {
  402. $row = Database::fetch_array($result);
  403. $workTitle = $row['title'];
  404. $workAuthor = $row['author'];
  405. $workDescription = $row['description'];
  406. $workUrl = $row['url'];
  407. $qualification_number = $row['qualification'];
  408. }
  409. }
  410. /*-------------------------------------------
  411. MAKE INVISIBLE WORK COMMAND
  412. -----------------------------------------*/
  413. if (!empty($make_invisible)) {
  414. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  415. api_not_allowed();
  416. }
  417. if (isset($make_invisible) && $make_invisible == "all") {
  418. $sql = "ALTER TABLE " . $work_table . "
  419. CHANGE accepted accepted TINYINT(1) DEFAULT '0'";
  420. Database::query($sql, __FILE__, __LINE__);
  421. $sql = "UPDATE " . $work_table . "
  422. SET accepted = 0";
  423. Database::query($sql, __FILE__, __LINE__);
  424. Display::display_confirmation_message(get_lang('AllFilesInvisible'));
  425. } else {
  426. $sql = "UPDATE " . $work_table . "
  427. SET accepted = 0
  428. WHERE id = '" . $make_invisible . "'";
  429. Database::query($sql, __FILE__, __LINE__);
  430. Display::display_confirmation_message(get_lang('FileInvisible'));
  431. }
  432. }
  433. /*-------------------------------------------
  434. MAKE VISIBLE WORK COMMAND
  435. -----------------------------------------*/
  436. if (!empty($make_visible)) {
  437. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  438. api_not_allowed();
  439. }
  440. if (isset($make_visible) && $make_visible == "all") {
  441. $sql = "ALTER TABLE " . $work_table . "
  442. CHANGE accepted accepted TINYINT(1) DEFAULT '1'";
  443. Database::query($sql, __FILE__, __LINE__);
  444. $sql = "UPDATE " . $work_table . "
  445. SET accepted = 1";
  446. Database::query($sql, __FILE__, __LINE__);
  447. Display::display_confirmation_message(get_lang('AllFilesVisible'));
  448. } else {
  449. $sql = "UPDATE " . $work_table . "
  450. SET accepted = 1
  451. WHERE id = '" . $make_visible . "'";
  452. Database::query($sql, __FILE__, __LINE__);
  453. Display::display_confirmation_message(get_lang('FileVisible'));
  454. }
  455. // update all the parents in the table item propery
  456. $list_id=get_parent_directories($my_cur_dir_path);
  457. for ($i = 0; $i < count($list_id); $i++) {
  458. api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
  459. }
  460. }
  461. /*--------------------
  462. * Create dir command
  463. ---------------------*/
  464. if (!empty ($_REQUEST['new_dir'])) {
  465. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  466. api_not_allowed();
  467. }
  468. function get_date_from_select($prefix) {
  469. 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';
  470. }
  471. $fexpire= get_date_from_select('expires');
  472. $fend = get_date_from_select('ends');
  473. include_once (api_get_path(LIBRARY_PATH) . "fileUpload.lib.php");
  474. $added_slash = (substr($cur_dir_path, -1, 1) == '/') ? '' : '/';
  475. $filter_directoy=Security::remove_XSS($_POST['new_dir']);
  476. $directory =disable_dangerous_file($filter_directoy);
  477. $directory =replace_accents($filter_directoy);
  478. $dir_name = $cur_dir_path . $added_slash . replace_dangerous_char($directory);
  479. $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
  480. // we insert here the directory in the table $work_table
  481. $dir_name_sql='';
  482. if ($ctok==$_POST['sec_token']) {
  483. if (!empty($created_dir)) {
  484. if ($cur_dir_path=='/') {
  485. $dir_name_sql = $created_dir;
  486. } else {
  487. $dir_name_sql = '/'.$created_dir;
  488. }
  489. //----------------inser into agenda----------------------//
  490. $agenda_id = 0;
  491. if(!empty($_POST['type2']) && isset($_POST['add_to_calendar']) && $_POST['add_to_calendar']==1):
  492. include_once('../calendar/agenda.inc.php');
  493. include_once('../resourcelinker/resourcelinker.inc.php');
  494. isset($course_info)?$course=$course_info:$course=null;
  495. $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);
  496. endif;
  497. $sql_add_publication = "INSERT INTO " . $work_table . " SET " .
  498. "url = '".Database::escape_string(Security::remove_XSS($dir_name_sql))."',
  499. title = '',
  500. description = '".Database::escape_string(Security::remove_XSS($_POST['description']))."',
  501. author = '',
  502. active = '0',
  503. accepted = '1',
  504. filetype = 'folder',
  505. post_group_id = '".$toolgroup."',
  506. sent_date = NOW(),
  507. qualification = '".(($_POST['qualification_value']!='') ? Database::escape_string($_POST['qualification_value']) : '') ."',
  508. parent_id = '',
  509. qualificator_id = '',
  510. date_of_qualification = '0000-00-00 00:00:00',
  511. session_id = ".intval($id_session);
  512. Database::query($sql_add_publication, __FILE__, __LINE__);
  513. // add the directory
  514. $id = Database::insert_id();
  515. //Folder created
  516. api_item_property_update($_course, 'work', $id, 'DirectoryCreated', $user_id);
  517. Display :: display_confirmation_message(get_lang('DirectoryCreated'), false);
  518. //Database :: escape_string($_REQUEST['make_visible']);
  519. //if($_POST['type1']==1)
  520. //$insert_limite
  521. //----------------inser into student_publication_assignment-------------------//
  522. //return something like this: 2008-02-45 00:00:00
  523. if(!empty($_POST['type1']) || !empty($_POST['type2'])) {
  524. isset($_POST['enable_calification'])?$enable_calification = (int)$_POST['enable_calification']:$enable_calification=null;
  525. $sql_add_homework = "INSERT INTO $TSTDPUBASG SET " .
  526. "expires_on = '".((isset($_POST['type1']) && $_POST['type1']==1) ? get_date_from_select('expires') : '0000-00-00 00:00:00'). "',
  527. ends_on = '".((isset($_POST['type2']) && $_POST['type2']==1) ? get_date_from_select('ends') : '0000-00-00 00:00:00')."',
  528. add_to_calendar = '$agenda_id',
  529. enable_qualification = '".$enable_calification."',
  530. publication_id = '".$id."'";
  531. Database::query($sql_add_homework, __FILE__, __LINE__);
  532. //Database::query($sql_add_publication, __FILE__, __LINE__);
  533. $sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".Database::insert_id().", view_properties = 1 ".' where id = '.$id;
  534. Database::query($sql_add_publication, __FILE__, __LINE__);
  535. } else {
  536. $sql_add_homework = "INSERT INTO $TSTDPUBASG SET " .
  537. "expires_on = '0000-00-00 00:00:00',
  538. ends_on = '0000-00-00 00:00:00',
  539. add_to_calendar = '$agenda_id',
  540. enable_qualification = '".(isset($_POST['enable_calification'])?(int)$_POST['enable_calification']:'')."',
  541. publication_id = '".$id."'";
  542. Database::query($sql_add_homework, __FILE__, __LINE__);
  543. //Database::query($sql_add_publication, __FILE__, __LINE__);
  544. $sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".Database::insert_id().", view_properties = 0 ".' where id = '.$id;
  545. Database::query($sql_add_publication, __FILE__, __LINE__);
  546. }
  547. if(isset($_POST['make_calification']) && $_POST['make_calification']==1) {
  548. require_once('../gradebook/lib/be/gradebookitem.class.php');
  549. require_once('../gradebook/lib/be/evaluation.class.php');
  550. require_once('../gradebook/lib/be/abstractlink.class.php');
  551. require_once('../gradebook/lib/gradebook_functions.inc.php');
  552. $resource_name = (empty($_POST['qualification_name'])) ? $_POST['new_dir'] : $_POST['qualification_name'];
  553. 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());
  554. }
  555. //-----------------end features---------------------------//
  556. // update all the parents in the table item propery
  557. $list_id=get_parent_directories($my_cur_dir_path);
  558. for ($i = 0; $i < count($list_id); $i++) {
  559. api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
  560. }
  561. //-------------------------------------------------------------------------------
  562. //uncomment if you want to enter the created dir
  563. //$curdirpath = $created_dir;
  564. //$curdirpathurl = urlencode($curdirpath);
  565. } else {
  566. Display :: display_error_message(get_lang('CannotCreateDir'));
  567. }
  568. }
  569. }
  570. /* -------------------
  571. * Delete dir command
  572. --------------------*/
  573. if (!empty ($_REQUEST['delete_dir'])) {
  574. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  575. api_not_allowed();
  576. }
  577. $delete_directory=$_REQUEST['delete_dir'];
  578. $id=$_REQUEST['delete2'];
  579. del_dir($base_work_dir . '/', $delete_directory,$id);
  580. Display :: display_confirmation_message(get_lang('DirDeleted') . ': '.$delete_directory);
  581. }
  582. if (!empty ($_REQUEST['delete2'])) {
  583. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  584. api_not_allowed();
  585. }
  586. $delete_2=$_REQUEST['delete2'];
  587. // gets calendar_id from student_publication_assigment
  588. $sql = "SELECT add_to_calendar FROM $TSTDPUBASG WHERE publication_id ='$delete_2'";
  589. $res = Database::query($sql,__FILE__,__LINE__);
  590. $calendar_id = Database::fetch_row($res);
  591. // delete from agenda if it exists
  592. if (!empty($calendar_id[0])) {
  593. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  594. $sql = "DELETE FROM $t_agenda WHERE id ='".$calendar_id[0]."'";
  595. Database::query($sql,__FILE__,__LINE__);
  596. }
  597. $sql2="DELETE FROM $TSTDPUBASG WHERE publication_id ='$delete_2'";
  598. $result2 = Database::query($sql2, __FILE__, __LINE__);
  599. $sql3="DELETE FROM $t_gradebook_link WHERE course_code='$course_code' AND ref_id='$delete_2'";
  600. $result3 = Database::query($sql3, __FILE__, __LINE__);
  601. }
  602. /* ----------------------
  603. * Move file form request
  604. ----------------------- */
  605. if (!empty ($_REQUEST['move'])) {
  606. $folders = array();
  607. $sql = "SELECT url FROM $work_table WHERE url LIKE '/%' AND post_group_id = '".(empty($_SESSION['toolgroup'])?0:$_SESSION['toolgroup'])."'";
  608. $res = Database::query($sql,__FILE__,__LINE__);
  609. while($folder = Database::fetch_array($res)) {
  610. $folders[] = substr($folder['url'],1,(strlen($folder['url'])-1));
  611. }
  612. echo build_work_move_to_selector($folders, $cur_dir_path, $_REQUEST['move']);
  613. }
  614. /* ------------------
  615. * Move file command
  616. ------------------- */
  617. if (isset ($_POST['move_to']) && isset ($_POST['move_file'])) {
  618. include_once (api_get_path(LIBRARY_PATH) . "/fileManage.lib.php");
  619. $move_to = $_POST['move_to'];
  620. if ($move_to == '/' or empty ($move_to)) {
  621. $move_to = '';
  622. } elseif (substr($move_to, -1, 1) != '/') {
  623. $move_to = $move_to . '/';
  624. }
  625. //security fix: make sure they can't move files that are not in the document table
  626. if ($path = get_work_path($_POST['move_file'])) {
  627. //echo "got path $path";
  628. //Display::display_normal_message('We want to move '.$_POST['move_file'].' to '.$_POST['move_to']);
  629. if (move($course_dir . '/' . $path, $base_work_dir . '/' . $move_to)) {
  630. //update db
  631. update_work_url(Security::remove_XSS($_POST['move_file']), 'work/' . $move_to);
  632. //set the current path
  633. $cur_dir_path = $move_to;
  634. $cur_dir_path_url = urlencode($move_to);
  635. // update all the parents in the table item propery
  636. $list_id=get_parent_directories($cur_dir_path);
  637. for ($i = 0; $i < count($list_id); $i++) {
  638. api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
  639. }
  640. Display :: display_confirmation_message(get_lang('DirMv'));
  641. } else {
  642. Display :: display_error_message(get_lang('Impossible'));
  643. }
  644. } else {
  645. Display :: display_error_message(get_lang('Impossible'));
  646. }
  647. }
  648. /*-----------------------------------------------------------
  649. COMMANDS SECTION (reserved for others - check they're authors each time)
  650. -----------------------------------------------------------
  651. */
  652. else {
  653. $iprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  654. $user_id = api_get_user_id();
  655. /*-------------------------------------------
  656. DELETE WORK COMMAND
  657. -----------------------------------------*/
  658. if ($delete) {
  659. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  660. api_not_allowed();
  661. }
  662. if ($delete == "all") {
  663. /*not authorized to this user */
  664. } else {
  665. //Get the author ID for that document from the item_property table
  666. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" .Database::escape_string($delete);
  667. $author_qry = Database::query($author_sql, __FILE__, __LINE__);
  668. if (Database :: num_rows($author_qry) == 1) {
  669. //we found the current user is the author
  670. $queryString1 = "SELECT url FROM " . $work_table . " WHERE id = '$delete'";
  671. $queryString2 = "DELETE FROM " . $work_table . " WHERE id='$delete'";
  672. $queryString3 = "DELETE FROM " . $TSTDPUBASG . " WHERE publication_id='$delete'";
  673. $result1 = Database::query($queryString1, __FILE__, __LINE__);
  674. $result2 = Database::query($queryString2, __FILE__, __LINE__);
  675. $result3 = Database::query($queryString3, __FILE__, __LINE__);
  676. if ($result1) {
  677. api_item_property_update($_course, 'work', $delete, 'DocumentDeleted', $user_id);
  678. while ($thisUrl = Database::fetch_array($result1)) {
  679. // check the url really points to a file in the work area
  680. // (some work links can come from groups area...)
  681. if (substr(dirname($thisUrl['url']), -4) == "work") {
  682. @ unlink($currentCourseRepositorySys . "work/" . $thisWork);
  683. }
  684. }
  685. }
  686. }
  687. }
  688. }
  689. /*-------------------------------------------
  690. EDIT COMMAND WORK COMMAND
  691. -----------------------------------------*/
  692. if ($edit) {
  693. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  694. api_not_allowed();
  695. }
  696. //Get the author ID for that document from the item_property table
  697. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . $edit;
  698. $author_qry = Database::query($author_sql, __FILE__, __LINE__);
  699. if (Database :: num_rows($author_qry) == 1) {
  700. //we found the current user is the author
  701. $sql = "SELECT * FROM " . $work_table . " WHERE id='" . $edit . "'";
  702. $result = Database::query($sql, __FILE__, __LINE__);
  703. if ($result ) {
  704. $row = Database::fetch_array($result);
  705. $workTitle = $row['title'];
  706. $workAuthor = $row['author'];
  707. $workDescription = $row['description'];
  708. $workUrl = $row['url'];
  709. $qualification_number = $row['qualification'];
  710. }
  711. }
  712. }
  713. }
  714. /*
  715. ==============================================================================
  716. FORM SUBMIT PROCEDURE
  717. ==============================================================================
  718. */
  719. $error_message = "";
  720. if ($ctok==$_POST['sec_token']) { //check the token inserted into the form
  721. if (!empty($_POST['submitWork']) && !empty($is_course_member)) {
  722. if (!empty($_FILES['file']['size'])) {
  723. $updir = $currentCourseRepositorySys . 'work/'; //directory path to upload
  724. // Try to add an extension to the file if it has'nt one
  725. $new_file_name = add_ext_on_mime(stripslashes($_FILES['file']['name']), $_FILES['file']['type']);
  726. // Replace dangerous characters
  727. $new_file_name = replace_dangerous_char($new_file_name, 'strict');
  728. // Transform any .php file in .phps fo security
  729. $new_file_name = php2phps($new_file_name);
  730. //filter extension
  731. if (!filter_extension($new_file_name)) {
  732. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  733. $succeed = false;
  734. } else {
  735. if (!$title) {
  736. $title = $_FILES['file']['name'];
  737. }
  738. //if (!$authors) {
  739. $authors = api_get_person_name($currentUserFirstName, $currentUserLastName);
  740. //}
  741. // compose a unique file name to avoid any conflict
  742. $new_file_name = uniqid('') . $new_file_name;
  743. if (isset ($_SESSION['toolgroup'])) {
  744. $post_group_id = $_SESSION['toolgroup'];
  745. } else {
  746. $post_group_id = '0';
  747. }
  748. //if we come from the group tools the groupid will be saved in $work_table
  749. @move_uploaded_file($_FILES['file']['tmp_name'], $updir . $my_cur_dir_path . $new_file_name);
  750. $url = "work/" . $my_cur_dir_path . $new_file_name;
  751. $result = Database::query("SHOW FIELDS FROM " . $work_table . " LIKE 'sent_date'", __FILE__, __LINE__);
  752. if (!Database::num_rows($result)) {
  753. Database::query("ALTER TABLE " . $work_table . " ADD sent_date DATETIME NOT NULL");
  754. }
  755. $current_date = date('Y-m-d H:i:s');
  756. $parent_id = '';
  757. $active = '';
  758. $sql = Database::query('SELECT id FROM '.Database::get_course_table(TABLE_STUDENT_PUBLICATION).' WHERE url = '."'/".Database::escape_string($_GET['curdirpath'])."' AND filetype='folder' LIMIT 1");
  759. if(Database::num_rows($sql) > 0 ) {
  760. $dir_row = Database::fetch_array($sql);
  761. $parent_id = $dir_row['id'];
  762. }
  763. $sql_add_publication = "INSERT INTO " . $work_table . " SET " .
  764. "url = '" . $url . "',
  765. title = '" . Database::escape_string(Security::remove_XSS($title)) . "',
  766. description = '" . Database::escape_string(Security::remove_XSS($description)) . "',
  767. author = '" . Database::escape_string($authors) . "',
  768. active = '" . $active . "',
  769. accepted = '" . (api_is_allowed_to_edit(null,true)?$uploadvisibledisabled:(!$uploadvisibledisabled)) . "',
  770. post_group_id = '" . $post_group_id . "',
  771. sent_date = '".$current_date ."',
  772. parent_id = '".$parent_id ."' ,
  773. session_id = ".intval($id_session);
  774. Database::query($sql_add_publication, __FILE__, __LINE__);
  775. $Id = Database::insert_id();
  776. api_item_property_update($_course, 'work', $Id, 'DocumentAdded', $user_id);
  777. $succeed = true;
  778. // update all the parents in the table item propery
  779. $list_id=get_parent_directories($my_cur_dir_path);
  780. for ($i = 0; $i < count($list_id); $i++) {
  781. api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
  782. }
  783. }
  784. } elseif ($newWorkUrl) {
  785. if (isset ($_SESSION['toolgroup'])) {
  786. $post_group_id = $_SESSION['toolgroup'];
  787. } else {
  788. $post_group_id = '0';
  789. }
  790. /*
  791. * SPECIAL CASE ! For a work coming from another area (i.e. groups)
  792. */
  793. $url = str_replace('../../' . $_course['path'] . '/', '', $newWorkUrl);
  794. if (!$title) {
  795. $title = basename($workUrl);
  796. }
  797. $result = Database::query("SHOW FIELDS FROM " . $work_table . " LIKE 'sent_date'", __FILE__, __LINE__);
  798. if (!Database::num_rows($result)) {
  799. Database::query("ALTER TABLE " . $work_table . " ADD sent_date DATETIME NOT NULL");
  800. }
  801. $current_date = date('Y-m-d H:i:s');
  802. $sql = "INSERT INTO " . $work_table . "
  803. SET url = '" . $url . "',
  804. title = '" . Database::escape_string(Security::remove_XSS($title)) . "',
  805. description = '" . Database::escape_string(Security::remove_XSS($description)) . "',
  806. author = '" . Database::escape_string($authors) . "',
  807. post_group_id = '".$post_group_id."',
  808. sent_date = '".$current_date."',
  809. session_id = ".intval($id_session);
  810. Database::query($sql, __FILE__, __LINE__);
  811. $insertId = Database::insert_id();
  812. api_item_property_update($_course, 'work', $insertId, 'DocumentAdded', $user_id);
  813. $succeed = true;
  814. // update all the parents in the table item propery
  815. $list_id=get_parent_directories($my_cur_dir_path);
  816. for ($i = 0; $i < count($list_id); $i++) {
  817. api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
  818. }
  819. }
  820. /*
  821. * SPECIAL CASE ! For a work edited
  822. */
  823. else {
  824. //Get the author ID for that document from the item_property table
  825. $is_author = false;
  826. if ($id<>'') {
  827. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . Database::escape_string($id);
  828. $author_qry = Database::query($author_sql, __FILE__, __LINE__);
  829. if (Database :: num_rows($author_qry) == 1) {
  830. $is_author = true;
  831. }
  832. } else {
  833. Display::display_error_message(get_lang('IsNotPosibleSaveTheDocument'));
  834. }
  835. if ($id && ($is_allowed_to_edit or $is_author)) {
  836. if (!$title) {
  837. $title = basename($newWorkUrl);
  838. }
  839. if($is_allowed_to_edit && ($_POST['qualification']!='')) {
  840. $add_to_update = ',qualificator_id ='."'".api_get_user_id()."',";
  841. $add_to_update .= 'qualification ='."'".Database::escape_string($_POST['qualification'])."',";
  842. $add_to_update .= 'date_of_qualification ='."'".date('Y-m-d H:i:s')."'";
  843. }
  844. if ((int)$_POST['qualification'] > (int)$_POST['qualification_over']) {
  845. Display::display_error_message(get_lang('QualificationMustNotBeMoreThanQualificationOver'));
  846. } else {
  847. $sql = "UPDATE " . $work_table . "
  848. SET title = '" . Database::escape_string(Security::remove_XSS($title)) . "',
  849. description = '" . Database::escape_string(Security::remove_XSS($description)) . "'
  850. ".$add_to_update."
  851. WHERE id = '$id'";
  852. Database::query($sql, __FILE__, __LINE__);
  853. }
  854. $insertId = $id;
  855. api_item_property_update($_course, 'work', $insertId, 'DocumentUpdated', $user_id);
  856. $succeed = true;
  857. } else {
  858. $error_message = get_lang('TooBig');
  859. }
  860. }
  861. }
  862. }
  863. if (!empty($_POST['submitWork']) && !empty($succeed) && !$id) {
  864. //last value is to check this is not "just" an edit
  865. //YW Tis part serve to send a e-mail to the tutors when a new file is sent
  866. $send = api_get_course_setting('email_alert_manager_on_new_doc');
  867. if ($send > 0) {
  868. // Lets predefine some variables. Be sure to change the from address!
  869. $emailto = array ();
  870. if (empty ($id_session)) {
  871. $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';
  872. $res_resp = Database::query($sql_resp, __FILE__, __LINE__);
  873. while ($row_email = Database :: fetch_array($res_resp)) {
  874. if (!empty ($row_email['myemail'])) {
  875. $emailto[$row_email['myemail']] = $row_email['myemail'];
  876. }
  877. }
  878. } else {
  879. // coachs of the session
  880. $sql_resp = 'SELECT user.email as myemail
  881. FROM ' . $table_session . ' session
  882. INNER JOIN ' . $table_user . ' user
  883. ON user.user_id = session.id_coach
  884. WHERE session.id = ' . intval($id_session);
  885. $res_resp = Database::query($sql_resp, __FILE__, __LINE__);
  886. while ($row_email = Database :: fetch_array($res_resp)) {
  887. if (!empty ($row_email['myemail'])) {
  888. $emailto[$row_email['myemail']] = $row_email['myemail'];
  889. }
  890. }
  891. //coach of the course
  892. $sql_resp = 'SELECT user.email as myemail
  893. FROM ' . $table_session_course . ' session_course
  894. INNER JOIN ' . $table_user . ' user
  895. ON user.user_id = session_course.id_coach
  896. WHERE session_course.id_session = ' . intval($id_session);
  897. $res_resp = Database::query($sql_resp, __FILE__, __LINE__);
  898. while ($row_email = Database :: fetch_array($res_resp)) {
  899. if (!empty ($row_email['myemail'])) {
  900. $emailto[$row_email['myemail']] = $row_email['myemail'];
  901. }
  902. }
  903. }
  904. if (count($emailto) > 0) {
  905. $emailto = implode(',', $emailto);
  906. $emailfromaddr = api_get_setting('emailAdministrator');
  907. $emailfromname = api_get_setting('siteName');
  908. $emailsubject = "[" . api_get_setting('siteName') . "] ";
  909. $sender_name = api_get_setting('administratorName').' '.api_get_setting('administratorSurname');
  910. $email_admin = api_get_setting('emailAdministrator');
  911. // The body can be as long as you wish, and any combination of text and variables
  912. $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');
  913. // Here we are forming one large header line
  914. // Every header must be followed by a \n except the last
  915. @api_mail('', $emailto, $emailsubject, $emailbody, $sender_name,$email_admin);
  916. }
  917. }
  918. $message = get_lang('DocAdd');
  919. if ($uploadvisibledisabled && !$is_allowed_to_edit) {
  920. $message .= "<br />" . get_lang('_doc_unvisible') . "<br />";
  921. }
  922. //stats
  923. if (!$Id) {
  924. $Id = $insertId;
  925. }
  926. event_upload($Id);
  927. $submit_success_message = $message . "<br />\n";
  928. Display :: display_confirmation_message($submit_success_message, false);
  929. }
  930. /*=======================================
  931. Display links to upload form and tool options
  932. =======================================
  933. */
  934. $has_expired = false;
  935. $has_ended = false;
  936. isset($_GET['curdirpath'])?$curdirpath=Database::escape_string($_GET['curdirpath']):$curdirpath='';
  937. $sql = Database::query('SELECT description,id FROM '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION).' WHERE filetype = '."'folder'".' and has_properties != '."''".' and url = '."'/".$curdirpath."'".' LIMIT 1',__FILE__,__LINE__);
  938. $is_special = Database::num_rows($sql);
  939. if($is_special > 0):
  940. $is_special = true;
  941. define('IS_ASSIGNMENT',1);
  942. $publication = Database::fetch_array($sql);
  943. $sql = Database::query('SELECT * FROM '.$TSTDPUBASG.' WHERE publication_id = '.(string)$publication['id'].' LIMIT 1',__FILE__,__LINE__);
  944. $homework = Database::fetch_array($sql);
  945. if($homework['expires_on']!='0000-00-00 00:00:00' || $homework['ends_on']!='0000-00-00 00:00:00'):
  946. $time_now = convert_date_to_number(date('Y-m-d H:i:s'));
  947. $time_expires = convert_date_to_number($homework['expires_on']);
  948. $time_ends = convert_date_to_number($homework['ends_on']);
  949. $difference = $time_expires - $time_now;
  950. $difference2 = $time_ends - $time_now;
  951. if($homework['expires_on']!='0000-00-00 00:00:00' && $difference < 0) $has_expired = true;
  952. if($homework['ends_on']!='0000-00-00 00:00:00' && $difference2 < 0) $has_ended = true;
  953. if($homework['expires_on']=='0000-00-00 00:00:00'){ $not_ends_on=true; }
  954. if (!$not_ends_on) {
  955. define('ASSIGNMENT_EXPIRES',$time_expires);
  956. }
  957. if(!empty($publication['description'])){
  958. Display :: display_normal_message($publication['description']);
  959. }
  960. $ends_on = api_ucfirst(format_locale_date($dateFormatLong,strtotime($homework['ends_on']))).' ';
  961. $ends_on .= ucfirst(strftime($timeNoSecFormat,strtotime($homework['ends_on'])));
  962. $expires_on = api_ucfirst(format_locale_date($dateFormatLong,strtotime($homework['expires_on']))).' ';
  963. $expires_on .= ucfirst(strftime($timeNoSecFormat,strtotime($homework['expires_on'])));
  964. if($has_ended) {
  965. Display :: display_error_message(get_lang('EndDateAlreadyPassed').' '.$ends_on);
  966. display_action_links($cur_dir_path, $always_show_tool_options,true);
  967. } elseif($has_expired) {
  968. Display :: display_warning_message(get_lang('ExpiryDateAlreadyPassed').' '.$expires_on);
  969. display_action_links($cur_dir_path, $always_show_tool_options,$always_show_upload_form);
  970. } else {
  971. if (!$not_ends_on) {
  972. Display :: display_normal_message(get_lang('ExpiryDateToSendWorkIs').' '.$expires_on);
  973. }
  974. display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form);
  975. }
  976. else:
  977. display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form);
  978. endif;
  979. else:
  980. display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form);
  981. endif;
  982. /*=======================================
  983. Display form to upload document
  984. =======================================*/
  985. if ($is_course_member) {
  986. if (($display_upload_form || $edit)&&!$has_ended) {
  987. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  988. api_not_allowed();
  989. }
  990. if ($edit) {
  991. //Get the author ID for that document from the item_property table
  992. $is_author = false;
  993. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . $edit;
  994. $author_qry = Database::query($author_sql, __FILE__, __LINE__);
  995. if (Database :: num_rows($author_qry) == 1) {
  996. $is_author = true;
  997. }
  998. }
  999. //require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  1000. require_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  1001. $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"');
  1002. // form title
  1003. if ($edit)
  1004. {
  1005. $form_title = get_lang('EditMedia');
  1006. }
  1007. else
  1008. {
  1009. $form_title = get_lang('UploadADocument');
  1010. }
  1011. $form->addElement('header', '', $form_title);
  1012. if (!empty ($error_message)) {
  1013. Display :: display_error_message($error_message);
  1014. }
  1015. if ($submitGroupWorkUrl) {
  1016. // For user comming from group space to publish his work
  1017. $realUrl = str_replace($_configuration['root_sys'], $_configuration['root_web'], str_replace("\\", "/", realpath($submitGroupWorkUrl)));
  1018. $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl);
  1019. $text_document = & $form->addElement('text', 'document', get_lang("Document"));
  1020. $defaults["document"] = '<a href="' . format_url($submitGroupWorkUrl) . '">' . $realUrl . '</a>';
  1021. $text_document->freeze();
  1022. } elseif ($edit && ($is_allowed_to_edit or $is_author)) {
  1023. $workUrl = $currentCourseRepositoryWeb . $workUrl;
  1024. $form->addElement('hidden', 'id', $edit);
  1025. $html = '<div class="row">
  1026. <div class="label">' . get_lang("Document") . '
  1027. </div>
  1028. <div class="formw">
  1029. <a href="' . $workUrl . '">' . get_lang("ClickHereToDownloadTheFile") . '</a>
  1030. </div>
  1031. </div>';
  1032. $form->addElement('html', $html);
  1033. } else {
  1034. // else standard upload option
  1035. $form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
  1036. }
  1037. $titleWork = $form->addElement('text', 'title', get_lang("TitleWork"), 'id="file_upload" style="width: 350px;"');
  1038. $defaults["title"] = ($edit ? stripslashes($workTitle) : stripslashes($title));
  1039. //Removed to avoid incoherences
  1040. //$titleAuthors = $form->addElement('text', 'authors', get_lang("Authors"), 'style="width: 350px;"');
  1041. //if (empty ($authors)) {
  1042. $authors = api_get_person_name($_user['firstName'], $_user['lastName']);
  1043. //}
  1044. //$defaults["authors"] = ($edit ? stripslashes($workAuthor) : stripslashes($authors));
  1045. $titleAuthors = $form->addElement('textarea', 'description', get_lang("Description"), 'style="width: 350px; height: 60px;"');
  1046. $defaults["description"] = ($edit ? stripslashes($workDescription) : stripslashes($description));
  1047. if($is_allowed_to_edit && !empty($edit) && !empty($parent_id)) {
  1048. // Get qualification from parent_id that'll allow the validation qualification over
  1049. $sql = "SELECT qualification FROM $work_table WHERE id='$parent_id'";
  1050. $result = Database::query($sql,__FILE__,__LINE__);
  1051. $row = Database::fetch_array($result);
  1052. $qualification_over = $row['qualification'];
  1053. $form->addElement('text', 'qualification', get_lang('Qualification'),'size="10"');
  1054. $form->addElement('html','<div style="margin-left:20%">'.get_lang('QualificationOver').'&nbsp;:&nbsp;'.$qualification_over.'</div>');
  1055. $form->addElement('hidden', 'qualification_over', $qualification_over);
  1056. }
  1057. $defaults['qualification'] = $qualification_number;//($edit ? stripslashes($qualification_number) : stripslashes($qualification_number));
  1058. $form->addElement('hidden', 'active', 1);
  1059. $form->addElement('hidden', 'accepted', 1);
  1060. $form->addElement('hidden', 'sec_token', $stok);
  1061. if (isset($_GET['edit'])) {
  1062. $text=get_lang('UpdateWork');
  1063. $class='save';
  1064. } else {
  1065. $text=get_lang('SendWork');
  1066. $class='upload';
  1067. }
  1068. // fix the Ok button when we see the tool in the learn path
  1069. if ($origin== 'learnpath') {
  1070. $form->addElement('html', '<div style="margin-left:137px">');
  1071. $form->addElement('style_submit_button','submitWork', $text, array('class="'.$class.'"','value="submitWork"'));
  1072. $form->addElement('html', '</div>');
  1073. } else {
  1074. //$form->addElement('submit','submitWork', get_lang('SendFile'));
  1075. $form->addElement('style_submit_button', 'submitWork', $text, array('class="'.$class.'"','value="submitWork"'));
  1076. }
  1077. if (!empty($_POST['submitWork']) || $edit) {
  1078. $form->addElement('style_submit_button', 'cancelForm', get_lang('Cancel'),'class="cancel"');
  1079. }
  1080. $form->add_real_progress_bar('uploadWork', 'DownloadFile');
  1081. $form->setDefaults($defaults);
  1082. $form->addRule('file', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  1083. $form->display();
  1084. }
  1085. function make_select($name,$values,$checked='') {
  1086. $output = '<select name="'.$name.'" id="'.$name.'">';
  1087. foreach($values as $key => $value) {
  1088. $output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
  1089. }
  1090. $output .= '</select>';
  1091. return $output;
  1092. }
  1093. function make_checkbox($name,$checked='') {
  1094. return '' .
  1095. '<input type="checkbox" value="1" name="'.$name.'" '.((!empty($checked))?'checked="checked"':'').'/>';
  1096. }
  1097. function draw_date_picker($prefix,$default='') {
  1098. //$default = 2008-10-01 10:00:00
  1099. if(empty($default)) {
  1100. $default = date('Y-m-d H:i:s');
  1101. }
  1102. $parts = split(' ',$default);
  1103. list($d_year,$d_month,$d_day) = split('-',$parts[0]);
  1104. list($d_hour,$d_minute) = split(':',$parts[1]);
  1105. $month_list = array(
  1106. 1=>get_lang('JanuaryLong'),
  1107. 2=>get_lang('FebruaryLong'),
  1108. 3=>get_lang('MarchLong'),
  1109. 4=>get_lang('AprilLong'),
  1110. 5=>get_lang('MayLong'),
  1111. 6=>get_lang('JuneLong'),
  1112. 7=>get_lang('JulyLong'),
  1113. 8=>get_lang('AugustLong'),
  1114. 9=>get_lang('SeptemberLong'),
  1115. 10=>get_lang('OctoberLong'),
  1116. 11=>get_lang('NovemberLong'),
  1117. 12=>get_lang('DecemberLong')
  1118. );
  1119. $minute = range(10,59);
  1120. array_unshift($minute,'00','01','02','03','04','05','06','07','08','09');
  1121. $date_form = make_select($prefix.'_day', array_combine(range(1,31),range(1,31)), $d_day);
  1122. $date_form .= make_select($prefix.'_month', $month_list, $d_month);
  1123. $date_form .= make_select($prefix.'_year', array( $d_year=> $d_year, $d_year+1=>$d_year+1), $d_year).'&nbsp;&nbsp;&nbsp;&nbsp;';
  1124. $date_form .= make_select($prefix.'_hour', array_combine(range(0,23),range(0,23)), $d_hour).' : ';
  1125. $date_form .= make_select($prefix.'_minute', $minute, $d_minute);
  1126. return $date_form;
  1127. }
  1128. //show them the form for the directory name
  1129. if (isset ($_REQUEST['createdir']) && $is_allowed_to_edit) {
  1130. //create the form that asks for the directory name
  1131. $new_folder_text = '<form name="form1" method="POST">';
  1132. $new_folder_text .= '<div class="row"><div class="form_header">'.get_lang('CreateAssignment').'</div></div>';
  1133. $new_folder_text .= '<input type="hidden" name="curdirpath" value="' . Security :: remove_XSS($cur_dir_path) . '"/>';
  1134. $new_folder_text .= '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  1135. $new_folder_text .= '<div class="row">
  1136. <div class="label">
  1137. <span class="form_required">*</span> '.get_lang('AssignmentName').'
  1138. </div>
  1139. <div class="formw">
  1140. <div id="msg_error1" style="display:none;color:red"></div>
  1141. <input type="text" name="new_dir" onfocus="document.getElementById(\'msg_error1\').style.display=\'none\';"/>
  1142. </div>
  1143. </div>';
  1144. //$new_folder_text .= '<button type="button" name="create_dir" class="add" onClick="validate();" value="' . get_lang('Ok') . '"/>'.get_lang('CreateDirectory').'</button>';
  1145. //new additional fields inside the "if condition" just to agroup
  1146. if(true):
  1147. $new_folder_text .= '<div class="row">
  1148. <div class="label">
  1149. '.get_lang('Description').'
  1150. </div>
  1151. <div class="formw">
  1152. <textarea name="description" rows="4" cols="70"></textarea>
  1153. </div>
  1154. </div>';
  1155. // Advanced parameters
  1156. $addtext .='<div id="options" style="display: none;">';
  1157. $addtext .= '<div style="padding:10px">';
  1158. $addtext .= '<b>'.get_lang('QualificationOfAssignment').'</b>';
  1159. $addtext .= '<table cellspacing="0" cellpading="0" border="0"><tr>';
  1160. $addtext .= '<td colspan="2">&nbsp;&nbsp;'.get_lang('QualificationNumberOver').'&nbsp;';
  1161. $addtext .= '<input type="text" name="qualification_value" value="" size="5"/></td><tr><td colspan="2">';
  1162. $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>';
  1163. $addtext .= '<td colspan="2"><div id="option1" style="display:none">';
  1164. $addtext .= '<div id="msg_error_weight" style="display:none;color:red"></div>';
  1165. $addtext .= '&nbsp;&nbsp;'.get_lang('WeightInTheGradebook').'&nbsp;';
  1166. $addtext .= '<input type="text" name="weight" value="" size="5" onfocus="document.getElementById(\'msg_error_weight\').style.display=\'none\';"/></div></td></tr>';
  1167. $addtext .= '</tr></table>';
  1168. $addtext .= '<br />';
  1169. $addtext .= '<b>'.get_lang('DatesAvailables').'</b><br>';
  1170. $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').'';
  1171. $addtext .= '&nbsp;&nbsp;&nbsp;<span id="msg_error2" style="display:none;color:red"></span>';
  1172. $addtext .= '&nbsp;&nbsp;&nbsp;<span id="msg_error3" style="display:none;color:red"></span>';
  1173. $addtext .= '<div id="option2" style="padding:4px;display:none">&nbsp;&nbsp;';
  1174. $addtext .= draw_date_picker('expires').'</div>';
  1175. $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').'';
  1176. $addtext .= '<div id="option3" style="padding:4px;display:none">';
  1177. $addtext .= '&nbsp;&nbsp;&nbsp;<div id="msg_error4" style="display:none;color:red"></div>';
  1178. $addtext .= draw_date_picker('ends').'<br />';
  1179. $addtext .= '&nbsp;&nbsp;'.make_checkbox('add_to_calendar').get_lang('AddToCalendar').'</div>';
  1180. $addtext .= '</div>';
  1181. $addtext .= '</div>';
  1182. $new_folder_text .= '<div class="row">
  1183. <div class="label">
  1184. <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 />
  1185. </div>
  1186. <div class="formw">
  1187. '.$addtext.'
  1188. </div>
  1189. </div>';
  1190. endif;
  1191. $new_folder_text .= '<div class="row">
  1192. <div class="label">
  1193. </div>
  1194. <div class="formw">
  1195. <button type="button" class="add" name="create_dir" onClick="validate();" value="' . addslashes(get_lang('CreateDirectory')) . '"/>' . addslashes(get_lang('ButtonCreateAssignment')) . '</button>
  1196. </div>
  1197. </div>';
  1198. $new_folder_text .= '</form>';
  1199. //show the form
  1200. echo $new_folder_text;
  1201. }
  1202. } else {
  1203. //the user is not registered in this course
  1204. echo "<p style=\"font-weight:bold\">" . get_lang("MustBeRegisteredUser") . "</p>";
  1205. }
  1206. /*
  1207. ==============================================================================
  1208. Display of tool options
  1209. ==============================================================================
  1210. */
  1211. if ($display_tool_options) {
  1212. display_tool_options($uploadvisibledisabled, $origin, $base_work_dir, $cur_dir_path, $cur_dir_path_url);
  1213. }
  1214. /*
  1215. ==============================================================================
  1216. Display list of student publications
  1217. ==============================================================================
  1218. */
  1219. if ($cur_dir_path == '/') {
  1220. $my_cur_dir_path = '';
  1221. } else {
  1222. $my_cur_dir_path = $cur_dir_path;
  1223. }
  1224. if (!$display_upload_form && !$display_tool_options) {
  1225. $add_query = '';
  1226. $sql = "SELECT user.firstname, user.lastname FROM $table_user user, $table_course_user course_user
  1227. WHERE course_user.user_id=user.user_id AND course_user.course_code='".api_get_course_id()."' AND course_user.status='1'";
  1228. $res = Database::query($sql,__FILE__,__LINE__);
  1229. $admin_course = '';
  1230. while($row = Database::fetch_row($res)) {
  1231. $admin_course .='\''.api_get_person_name($row[0], $row[1]).'\',';
  1232. }
  1233. if(!$is_allowed_to_edit && $is_special==true) {
  1234. $add_query = ' AND author IN('.$admin_course.'\''.api_get_person_name($_user['firstName'], $_user['lastName']).'\')';
  1235. }
  1236. if($is_allowed_to_edit && $is_special==true) {
  1237. if (!empty($_REQUEST['filter'])) {
  1238. switch($_REQUEST['filter']) {
  1239. case 1:
  1240. $add_query = ' AND qualification = '."''";
  1241. break;
  1242. case 2:
  1243. $add_query = ' AND qualification != '."''";
  1244. break;
  1245. case 3:
  1246. $add_query = ' AND sent_date < '."'".$homework['expires_on']."'";
  1247. break;
  1248. default:
  1249. $add_query = '';
  1250. }
  1251. }
  1252. isset($_GET['cidreq'])?$cidreq = Security::Remove_XSS($_GET['cidreq']):$cidreq='';
  1253. isset($_GET['curdirpath'])?$curdirpath = Security::Remove_XSS($_GET['curdirpath']):$curdirpath='';
  1254. isset($_REQUEST['filter'])?$filter = (int)$_REQUEST['filter']:$filter='';
  1255. if ($origin != 'learnpath') {
  1256. $form_filter = '<form method="post" action="'.api_get_self().'?cidReq='.$cidreq.'&curdirpath='.$curdirpath.'&gradebook='.$gradebook.'">';
  1257. $form_filter .= make_select('filter',array(0=>get_lang('SelectAFilter'),1=>get_lang('FilterByNotRevised'),2=>get_lang('FilterByRevised'),3=>get_lang('FilterByNotExpired')),$filter);
  1258. $form_filter .= '<input type="submit" value="'.get_lang('FilterAssignments').'"</form>';
  1259. echo $form_filter;
  1260. }
  1261. }
  1262. display_student_publications_list($base_work_dir . '/' . $my_cur_dir_path, 'work/' . $my_cur_dir_path, $currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin,$add_query);
  1263. }
  1264. /*
  1265. ==============================================================================
  1266. Footer
  1267. ==============================================================================
  1268. */
  1269. if ($origin != 'learnpath') {
  1270. //we are not in the learning path tool
  1271. Display :: display_footer();
  1272. }