work.php 58 KB

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