work.php 57 KB

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