work.lib.php 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  1. <?php
  2. /* For licensing terms, see /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.lib.php 22357 2009-07-24 17:44:17Z juliomontoya $
  10. */
  11. /**
  12. * Displays action links (for admins, authorized groups members and authorized students)
  13. * @param string Current dir
  14. * @param integer Whether to show tool options
  15. * @param integer Whether to show upload form option
  16. * @return void
  17. */
  18. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
  19. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  20. function display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form) {
  21. global $gradebook;
  22. $display_output = '';
  23. $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  24. $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : empty($curdirpath);
  25. ///why is that here?
  26. //$origin = api_get_tools_lists($origin);
  27. echo '<div class="actions">';
  28. if (strlen($cur_dir_path) > 0 && $cur_dir_path != '/') {
  29. $parent_dir = dirname($cur_dir_path);
  30. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&curdirpath='.$parent_dir.'">'.Display::return_icon('back.png', get_lang('BackToWorksList')).' '.get_lang('BackToWorksList').'</a>';
  31. } else {
  32. if ($_GET['display_tool_options'] == 'true' OR $_GET['display_upload_form'] == 'true') {
  33. if ($origin != 'learnpath') {
  34. echo '<a href="work.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToWorksList')).' '.get_lang('BackToWorksList').'</a>';
  35. }
  36. }
  37. }
  38. if (!$always_show_tool_options && api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
  39. // Create dir
  40. if ($cur_dir_path == '/') {
  41. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;toolgroup='.Security::remove_XSS($_GET['toolgroup']).'&amp;createdir=1&origin='.$origin.'&gradebook='.$gradebook.'">'.Display::return_icon('works_new.gif', get_lang('CreateAssignment')).' '.get_lang('CreateAssignment').' </a>';
  42. }
  43. // Options
  44. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;display_tool_options=true&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('acces_tool.gif', get_lang('EditToolOptions')).' '.get_lang('EditToolOptions').'</a>';
  45. }
  46. if (!$always_show_upload_form && api_is_allowed_to_session_edit(false, true)) {
  47. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$cur_dir_path.'&amp;display_upload_form=true&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('submit_file.gif', get_lang('UploadADocument')).' '.get_lang('UploadADocument').'</a>';
  48. }
  49. if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath' && api_is_allowed_to_session_edit(false, true)) {
  50. // delete all files
  51. if (api_get_setting('permanently_remove_deleted_files') == 'true'){
  52. $message = get_lang('ConfirmYourChoiceDeleteAllfiles');
  53. } else {
  54. $message = get_lang('ConfirmYourChoice');
  55. }
  56. if (empty($curdirpath) or $curdirpath != '.') {
  57. $display_output .= '<a href="#">'.Display::return_icon('delete_na.gif', get_lang('Delete')).get_lang('DeleteAllFiles').'</a>';
  58. } else {
  59. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;delete=all" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities($message, ENT_QUOTES)).'\')) return false;">'.
  60. Display::return_icon('delete.gif', get_lang('Delete')).' '.get_lang('DeleteAllFiles').'</a>';
  61. }
  62. // make all files visible or invisible
  63. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  64. $sql_query = "SHOW COLUMNS FROM ".$work_table." LIKE 'accepted'";
  65. $sql_result = Database::query($sql_query);
  66. if ($sql_result) {
  67. $columnStatus = Database::fetch_array($sql_result);
  68. if ($columnStatus['Default'] == 1) {
  69. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;make_invisible=all">'.
  70. Display::return_icon('visible.gif', get_lang('MakeAllPapersInvisible')).' '.get_lang('MakeAllPapersInvisible')."</a>\n";
  71. } else {
  72. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;make_visible=all">'.
  73. Display::return_icon('invisible.gif', get_lang('MakeAllPapersVisible')).' '.get_lang('MakeAllPapersVisible')."</a>\n";
  74. }
  75. }
  76. }
  77. if (api_is_allowed_to_edit(null, true)) {
  78. global $publication;
  79. if (empty($curdirpath) or $curdirpath != '.' or $cur_dir_path != '/') {
  80. if (empty($_GET['list']) or Security::remove_XSS($_GET['list']) == 'with') {
  81. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=without">'.
  82. Display::return_icon('un_check.gif', get_lang('ViewUsersWithoutTask')).' '.get_lang('ViewUsersWithoutTask')."</a>\n";
  83. } else {
  84. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=with">'.
  85. Display::return_icon('check.gif', get_lang('ViewUsersWithTask')).' '.get_lang('ViewUsersWithTask')."</a>\n";
  86. $_SESSION['token'] = time();
  87. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=without&amp;action=send_mail&amp;sec_token='.$_SESSION['token'].'">'.
  88. Display::return_icon('messagebox_warning.gif', get_lang('ReminderMessage')).' '.get_lang('ReminderMessage')."</a>\n";
  89. }
  90. }
  91. }
  92. if ($display_output != '') {
  93. echo $display_output;
  94. }
  95. echo '</div>';
  96. }
  97. /**
  98. * Displays all options for this tool.
  99. * These are
  100. * - make all files visible / invisible
  101. * - set the default visibility of uploaded files
  102. *
  103. * @param $uploadvisibledisabled
  104. * @param $origin
  105. * @param $base_work_dir Base working directory (up to '/work')
  106. * @param $cur_dir_path Current subdirectory of 'work/'
  107. * @param $cur_dir_path_url Current subdirectory of 'work/', url-encoded
  108. */
  109. function display_tool_options($uploadvisibledisabled, $origin, $base_work_dir, $cur_dir_path, $cur_dir_path_url) {
  110. global $group_properties, $gradebook;
  111. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  112. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  113. if (!$is_allowed_to_edit) {
  114. return;
  115. }
  116. echo '<form method="post" action="'.api_get_self().'?origin='.$origin.'&gradebook='.$gradebook.'&display_tool_options=true">';
  117. echo '<div class="row"><div class="form_header">'.get_lang('EditToolOptions').'</div></div>';
  118. display_default_visibility_form($uploadvisibledisabled);
  119. display_studentsdelete_form();
  120. echo '<div class="row">
  121. <div class="formw">
  122. <button type="submit" class="save" name="changeProperties" value="'.get_lang('Ok').'">'.get_lang('Ok').'</button>
  123. </div>
  124. </div>';
  125. echo '</form>';
  126. }
  127. /**
  128. * Displays the form where course admins can specify wether uploaded documents
  129. * are visible or invisible by default.
  130. *
  131. * @param $uploadvisibledisabled
  132. * @param $origin
  133. */
  134. function display_default_visibility_form($uploadvisibledisabled) {
  135. ?>
  136. <div class="row">
  137. <div class="label">
  138. <?php echo get_lang('_default_upload'); ?>
  139. </div>
  140. <div class="formw">
  141. <input class="checkbox" type="radio" name="uploadvisibledisabled" value="0" <?php if ($uploadvisibledisabled == 0) echo 'checked'; ?> />
  142. <?php echo get_lang('_new_visible'); ?><br />
  143. <input class="checkbox" type="radio" name="uploadvisibledisabled" value="1" <?php if ($uploadvisibledisabled == 1) echo 'checked'; ?> />
  144. <?php echo get_lang('_new_unvisible'); ?>
  145. </div>
  146. </div>
  147. <?php
  148. }
  149. /**
  150. * Display a part of the form to edit the settings of the tool
  151. * In this case weither the students are allowed to delete their own publication or not (by default not)
  152. *
  153. * @return html code
  154. * @since Dokeos 1.8.6.2
  155. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  156. */
  157. function display_studentsdelete_form() {
  158. // by default api_get_course_setting returns -1 and the code only expects 0 or 1 so anything tha
  159. // is different than 1 will be converted into 0
  160. $current_course_setting_value = api_get_course_setting('student_delete_own_publication');
  161. if ($current_course_setting_value != 1) {
  162. $current_course_setting_value = 0;
  163. }
  164. ?>
  165. <div class="row">
  166. <div class="label">
  167. <?php echo get_lang('StudentAllowedToDeleteOwnPublication'); ?>
  168. </div>
  169. <div class="formw">
  170. <input class="checkbox" type="radio" name="student_delete_own_publication" value="0" <?php if ($current_course_setting_value == 0) echo 'checked'; ?> />
  171. <?php echo get_lang('No'); ?><br />
  172. <input class="checkbox" type="radio" name="student_delete_own_publication" value="1" <?php if ($current_course_setting_value == 1) echo 'checked'; ?> />
  173. <?php echo get_lang('Yes'); ?>
  174. </div>
  175. </div>
  176. <?php
  177. }
  178. /**
  179. * This function displays the firstname and lastname of the user as a link to the user tool.
  180. *
  181. * @see this is the same function as in the new forum, so this probably has to move to a user library.
  182. *
  183. * @todo move this function to the user library
  184. *
  185. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  186. * @version march 2006
  187. */
  188. function display_user_link_work($user_id, $name = '') {
  189. global $_otherusers;
  190. $user_id = intval($user_id);
  191. if ($user_id != 0) {
  192. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  193. $sql = "SELECT user_id, firstname, lastname FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'";
  194. $result = Database::query($sql);
  195. $row = Database::fetch_array($result);
  196. if ($name == '') {
  197. return '<a href="../user/userInfo.php?cidReq='.api_get_course_id().'&amp;gradebook='.$gradebook.'&amp;origin=&amp;uInfo='.$row['user_id'].'">'.api_get_person_name($row['firstname'], $row['lastname']).'</a>';
  198. } else {
  199. return '<a href="../user/userInfo.php?cidReq='.api_get_course_id().'&amp;gradebook='.$gradebook.'&amp;origin=&amp;uInfo='.$user_id.'">'.$name.'</a>';
  200. }
  201. } else {
  202. return $name.' ('.get_lang('Anonymous').')';
  203. }
  204. }
  205. /**
  206. * converts 2008-10-06 12:45:00 to timestamp
  207. */
  208. function convert_date_to_number($default) {
  209. // 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
  210. $parts = split(' ', $default);
  211. list($d_year, $d_month, $d_day) = split('-', $parts[0]);
  212. list($d_hour, $d_minute, $d_second) = split(':', $parts[1]);
  213. return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
  214. }
  215. /**
  216. * converts 1-9 to 01-09
  217. */
  218. function two_digits($number) {
  219. $number = (int)$number;
  220. return ($number < 10) ? '0'.$number : $number;
  221. }
  222. /**
  223. * converts 2008-10-06 12:45:00 to -> array($data'year'=>2008,$data'month'=>10 etc...)
  224. */
  225. function convert_date_to_array($date, $group) {
  226. $parts = split(' ', $date);
  227. list($data[$group.'[year]'], $data[$group.'[month]'], $data[$group.'[day]']) = split('-', $parts[0]);
  228. list($data[$group.'[hour]'], $data[$group.'[minute]']) = split(':', $parts[1]);
  229. return $data;
  230. }
  231. /**
  232. * get date from a group of date
  233. */
  234. function get_date_from_group($group) {
  235. return $_POST[$group]['year'].'-'.two_digits($_POST[$group]['month']).'-'.two_digits($_POST[$group]['day']).' '.two_digits($_POST[$group]['hour']).':'.two_digits($_POST[$group]['minute']).':00';
  236. }
  237. /**
  238. * create a group of select from a date
  239. */
  240. function create_group_date_select($prefix = '') {
  241. $minute = range(10, 59);
  242. $d_year = date('Y');
  243. array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09');
  244. $group_name[] = FormValidator :: createElement('select', $prefix.'day', '', array_combine(range(1, 31), range(1, 31)));
  245. $group_name[] = FormValidator :: createElement('select', $prefix.'month', '', array_combine(range(1, 12), api_get_months_long()));
  246. $group_name[] = FormValidator :: createElement('select', $prefix.'year', '', array($d_year => $d_year, $d_year + 1 => $d_year + 1));
  247. $group_name[] = FormValidator :: createElement('select', $prefix.'hour', '', array_combine(range(0, 23), range(0, 23)));
  248. $group_name[] = FormValidator :: createElement('select', $prefix.'minute', '', $minute);
  249. return $group_name;
  250. }
  251. /**
  252. * Display the list of student publications, taking into account the user status
  253. *
  254. * @param $currentCourseRepositoryWeb, the web location of the course folder
  255. * @param $link_target_parameter - should there be a target parameter for the links
  256. * @param $dateFormatLong - date format
  257. * @param $origin - typically empty or 'learnpath'
  258. */
  259. function display_student_publications_list($work_dir, $sub_course_dir, $currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin, $add_in_where_query = '') {
  260. global $timeNoSecFormat, $dateFormatShort, $gradebook, $_user;
  261. // Database table names
  262. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  263. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  264. $work_assigment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  265. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  266. $user_id = api_get_user_id();
  267. $publications_list = array();
  268. $sort_params = array();
  269. if (isset($_GET['column'])) {
  270. $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
  271. }
  272. if (isset($_GET['page_nr'])) {
  273. $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
  274. }
  275. if (isset($_GET['per_page'])) {
  276. $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
  277. }
  278. if (isset($_GET['direction'])) {
  279. $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
  280. }
  281. $sort_params = implode('&amp;', $sort_params);
  282. $my_params = $sort_params;
  283. $origin = Security::remove_XSS($origin);
  284. if (substr($sub_course_dir, -1, 1) != '/' && !empty($sub_course_dir)) {
  285. $sub_course_dir = $sub_course_dir.'/';
  286. }
  287. if ($sub_course_dir == '/') {
  288. $sub_course_dir = '';
  289. }
  290. //condition for the session
  291. $session_id = api_get_session_id();
  292. $condition_session = api_get_session_condition($session_id);
  293. //Get list from database
  294. if ($is_allowed_to_edit) {
  295. $sql_get_publications_list = "SELECT * " .
  296. "FROM ".$work_table." " .
  297. "WHERE url LIKE BINARY '$sub_course_dir%' " .
  298. "AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query.
  299. $condition_session.
  300. " ORDER BY sent_date DESC";
  301. $sql_get_publications_num = "SELECT count(*) " .
  302. "FROM ".$work_table." " .
  303. "WHERE url LIKE BINARY '$sub_course_dir%' " .
  304. "AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query.
  305. $condition_session.
  306. " ORDER BY id";
  307. } else {
  308. if (!empty($_SESSION['toolgroup'])) {
  309. $group_query = " WHERE post_group_id = '".intval($_SESSION['toolgroup'])."' "; // set to select only messages posted by the user's group
  310. $subdirs_query = "AND url NOT LIKE BINARY '$sub_course_dir%/%' AND url LIKE BINARY '$sub_course_dir%'";
  311. } else {
  312. $group_query = " WHERE post_group_id = '0' ";
  313. $subdirs_query = "AND url NOT LIKE '$sub_course_dir%/%' AND url LIKE '$sub_course_dir%'";
  314. }
  315. $sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query ".$add_in_where_query." $condition_session ORDER BY id";
  316. $sql_get_publications_num = "SELECT count(url) " .
  317. "FROM ".$work_table." " .
  318. "WHERE url LIKE BINARY '$sub_course_dir%' " .
  319. "AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query.
  320. $condition_session.
  321. " ORDER BY id";
  322. }
  323. $sql_result = Database::query($sql_get_publications_list);
  324. $sql_result_num = Database::query($sql_get_publications_num);
  325. $row = Database::fetch_array($sql_result_num);
  326. $count_files = $row[0];
  327. $table_header[] = array(get_lang('Type'), true, 'style="width:40px"');
  328. $table_header[] = array(get_lang('Title'), true);
  329. if ($count_files != 0) {
  330. $table_header[] = array(get_lang('Authors'), true);
  331. }
  332. $table_header[] = array(get_lang('Date'), true);
  333. if ($origin != 'learnpath') {
  334. $table_header[] = array(get_lang('Modify'), true);
  335. $table_header[] = array('RealDate', true);
  336. }
  337. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  338. $column_show[] = 1; // type
  339. $column_show[] = 1; // title
  340. if ($count_files != 0) {
  341. $column_show[] = 1; // authors
  342. }
  343. $column_show[] = 1; //date
  344. $column_show[] = 1; // modify
  345. $column_show[] = 0; //real date in correct format
  346. // Here we change the way how the colums are going to be sort
  347. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  348. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  349. if ($count_files != 0) {
  350. $column_order[3] = 5;
  351. } else {
  352. $column_order[2] = 4;
  353. }
  354. $table_data = array();
  355. $dirs_list = get_subdirs_list($work_dir);
  356. $my_sub_dir = str_replace('work/', '', $sub_course_dir);
  357. // List of all folders
  358. if (is_array($dirs_list)) {
  359. foreach ($dirs_list as $dir) {
  360. if ($my_sub_dir == '') {
  361. $mydir_temp = '/'.$dir;
  362. } else {
  363. $mydir_temp = '/'.$my_sub_dir.$dir;
  364. }
  365. $sql_select_directory = "SELECT prop.lastedit_date, work.id, author, has_properties, view_properties, description, qualification, weight FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE ";
  366. if (!empty($_SESSION['toolgroup'])) {
  367. $sql_select_directory .= " work.post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group
  368. } else {
  369. $sql_select_directory .= " work.post_group_id = '0' ";
  370. }
  371. $sql_select_directory .= " AND work.url LIKE BINARY '".$mydir_temp."' AND work.filetype = 'folder' AND prop.tool='work' $condition_session";
  372. $result = Database::query($sql_select_directory);
  373. $row = Database::fetch_array($result);
  374. if (!$row) {
  375. // the folder belongs to another session
  376. continue;
  377. }
  378. $direc_date = $row['lastedit_date']; //directory's date
  379. $author = $row['author']; //directory's author
  380. $view_properties = $row['view_properties'];
  381. $is_assignment = $row['has_properties'];
  382. $id2 = $row['id'];
  383. $mydir = $my_sub_dir.$dir;
  384. if ($is_allowed_to_edit) {
  385. isset($_GET['edit_dir']) ? $clean_edit_dir = Security :: remove_XSS($_GET['edit_dir']) : $clean_edit_dir = '';
  386. // form edit directory
  387. if (isset($clean_edit_dir) && $clean_edit_dir == $mydir) {
  388. if (!empty($row['has_properties'])) {
  389. $sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE id = '."'".$row['has_properties']."'".' LIMIT 1');
  390. $homework = Database::fetch_array($sql);
  391. }
  392. $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?curdirpath='.$my_sub_dir.'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$mydir);
  393. $group_name[] = FormValidator :: createElement('text', 'dir_name');
  394. $form_folder -> addGroup($group_name, 'my_group', get_lang('Title'));
  395. $form_folder -> addGroupRule('my_group', get_lang('ThisFieldIsRequired'), 'required');
  396. $defaults = array('my_group[dir_name]' => html_entity_decode($dir), 'description' => api_html_entity_decode($row['description']));
  397. //$form_folder-> addElement('textarea', 'description', get_lang('Description'), array('rows' => 5, 'cols' => 50));
  398. $form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'profile', 'Width' => '100%', 'Height' => '200'));
  399. $qualification_input[] = FormValidator :: createElement('text','qualification');
  400. $form_folder -> addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'), 'size="10"');
  401. if ($row['weight'] > 0) {
  402. $weight_input[] = FormValidator :: createElement('text', 'weight');
  403. $form_folder -> addGroup($weight_input, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
  404. }
  405. $there_is_a_end_date = false;
  406. if ($row['view_properties'] == '1') {
  407. if ($homework['expires_on'] != '0000-00-00 00:00:00') {
  408. $there_is_a_expire_date = true;
  409. $form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
  410. }
  411. if ($homework['ends_on'] != '0000-00-00 00:00:00') {
  412. $there_is_a_end_date = true;
  413. $form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
  414. }
  415. if ($there_is_a_expire_date && $there_is_a_end_date) {
  416. $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  417. }
  418. } else {
  419. $form_folder -> addElement('html', '<div class="row">
  420. <div class="label">&nbsp;</div>
  421. <div class="formw">
  422. <a href="javascript://" onclick="javascript: return plus();" ><span id="plus">&nbsp;<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'</span></a>
  423. </div>
  424. </div> ');
  425. $form_folder -> addElement('html', '<div id="options" style="display: none;">');
  426. if (empty($default)) {
  427. $default = date('Y-m-d 12:00:00');
  428. }
  429. $parts = split(' ', $default);
  430. list($d_year, $d_month, $d_day) = split('-', $parts[0]);
  431. list($d_hour, $d_minute) = split(':', $parts[1]);
  432. if ((int)$row['weight'] == 0) {
  433. $form_folder -> addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked==true){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
  434. $form_folder -> addElement('html', '<div id=\'option3\' style="display:none">');
  435. $weight_input2[] = FormValidator :: createElement('text', 'weight');
  436. $form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
  437. $form_folder -> addElement('html', '</div>');
  438. }
  439. if ($homework['expires_on'] = '0000-00-00 00:00:00') {
  440. $homework['expires_on'] = date('Y-m-d H:i:s');
  441. $there_is_a_expire_date = true;
  442. $form_folder -> addElement('checkbox', 'enableExpiryDate',null,get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked==true){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
  443. $form_folder -> addElement('html', '<div id=\'option1\' style="display:none">');
  444. $form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
  445. $form_folder -> addElement('html', '</div>');
  446. }
  447. if ($homework['ends_on'] = '0000-00-00 00:00:00') {
  448. $homework['ends_on'] = date('Y-m-d H:i:s');
  449. $there_is_a_end_date = true;
  450. $form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked==true){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"');
  451. $form_folder -> addElement('html', '<div id=\'option2\' style="display:none">');
  452. $form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
  453. $form_folder -> addElement('html', '</div>');
  454. }
  455. $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  456. $form_folder -> addElement('html', '</div>');
  457. }
  458. $form_folder -> addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"');
  459. if ($there_is_a_end_date) {
  460. $defaults = array_merge($defaults, convert_date_to_array($homework['ends_on'], 'ends'));
  461. }
  462. if ($there_is_a_expire_date) {
  463. $defaults = array_merge($defaults, convert_date_to_array($homework['expires_on'], 'expires'));
  464. }
  465. if (!empty($row['qualification'])) {
  466. $defaults = array_merge($defaults, array('qualification[qualification]' => $row['qualification']));
  467. }
  468. if (!empty($row['weight'])) {
  469. $defaults = array_merge($defaults, array('weight[weight]' => $row['weight']));
  470. }
  471. $form_folder -> setDefaults($defaults);
  472. $display_edit_form = true;
  473. if ($form_folder -> validate()) {
  474. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  475. if ($there_is_a_end_date || $there_is_a_expire_date) {
  476. if ($row['view_properties'] == '1') {
  477. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
  478. Database::query($sql_add_publication);
  479. $expires_query = ' SET expires_on = '."'".($there_is_a_expire_date ? get_date_from_group('expires') : '0000-00-00 00:00:00')."'".',';
  480. $ends_query = ' ends_on = '."'".($there_is_a_end_date ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
  481. Database::query('UPDATE '.$work_assigment.$expires_query.$ends_query.' WHERE id = '."'".$row['has_properties']."'");
  482. } elseif ($row['view_properties'] == '0') {
  483. if ($_POST['enableExpiryDate'] == '1') {
  484. $expires_query = ' SET expires_on = '."'".($there_is_a_expire_date ? get_date_from_group('expires') : '0000-00-00 00:00:00')."'";
  485. //$ends_query = ' ends_on = '."'".($there_is_a_end_date ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
  486. Database::query('UPDATE '.$work_assigment.$expires_query.' WHERE id = '."'".$row['has_properties']."'");
  487. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
  488. Database::query($sql_add_publication);
  489. }
  490. if ($_POST['enableEndDate'] == '1') {
  491. //$expires_query = ' SET expires_on = '."'".($there_is_a_expire_date ? get_date_from_group('expires') : '0000-00-00 00:00:00')."'".',';
  492. $ends_query = ' SET ends_on = '."'".($there_is_a_end_date ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
  493. Database::query('UPDATE '.$work_assigment.$ends_query.' WHERE id = '."'".$row['has_properties']."'");
  494. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
  495. Database::query($sql_add_publication);
  496. }
  497. }
  498. }
  499. //if($_POST['qualification']['qualification']!='')
  500. Database::query('UPDATE '.$work_table.' SET description = '."'".Database::escape_string($_POST['description'])."'".', qualification = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".',weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".' WHERE id = '."'".$row['id']."'");
  501. Database::query('UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).' SET weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".' WHERE course_code = '."'".api_get_course_id()."'".' AND ref_id = '."'".$row['id']."'".'');
  502. //we are changing the current work and we want add them into gradebook
  503. if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1) {
  504. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  505. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  506. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
  507. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  508. $resource_name = $_POST['dir_name'];
  509. add_resource_to_course_gradebook(api_get_course_id(), 3, $row['id'], Database::escape_string($resource_name), (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], Database::escape_string($_POST['description']), time(), 1, api_get_session_id());
  510. }
  511. Display::display_confirmation_message(get_lang('FolderEdited'));
  512. $values = $form_folder -> exportValues();
  513. $values = $values['my_group'];
  514. $dir_name = replace_dangerous_char($values['dir_name']);
  515. $dir_name = disable_dangerous_file($dir_name);
  516. update_dir_name($mydir, $dir_name);
  517. $mydir = $my_sub_dir.$dir_name;
  518. $dir = $dir_name;
  519. $display_edit_form = false;
  520. // gets calendar_id from student_publication_assigment
  521. $sql = "SELECT add_to_calendar FROM $work_assigment WHERE publication_id ='".$row['id']."'";
  522. $res = Database::query($sql);
  523. $calendar_id = Database::fetch_row($res);
  524. // update from agenda if it exists
  525. if (!empty($calendar_id[0])) {
  526. $sql = "UPDATE ".$TABLEAGENDA."
  527. SET title='".$dir_name."',
  528. content = '".$dir_name."',
  529. end_date='".get_date_from_group('ends')."'
  530. WHERE id='".$calendar_id[0]."'";
  531. Database::query($sql);
  532. }
  533. }
  534. }
  535. }
  536. $action = '';
  537. $row = array();
  538. $class = '';
  539. //$a_count_directory = count_dir($work_dir.'/'.$dir, false);
  540. $cant_files = 0;
  541. $cant_dir = 0;
  542. if (api_is_allowed_to_edit()) {
  543. $sql_document = "SELECT count(*) FROM $work_table WHERE url NOT LIKE '".$sub_course_dir.$dir."/%/%' AND url LIKE '".$sub_course_dir.$dir."/%'";
  544. } else {
  545. // gets admin_course
  546. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  547. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  548. $sql = "SELECT course_user.user_id FROM $table_user user, $table_course_user course_user
  549. WHERE course_user.user_id=user.user_id AND course_user.course_code='".api_get_course_id()."' AND course_user.status='1'";
  550. $res = Database::query($sql);
  551. $admin_course = '';
  552. while($row_admin = Database::fetch_row($res)) {
  553. $admin_course .= '\''.$row_admin[0].'\',';
  554. }
  555. $sql_document = "SELECT count(*) FROM $work_table s, $iprop_table p WHERE s.id = p.ref AND p.tool='work' AND lastedit_user_id IN(".$admin_course.'\''.api_get_user_id().'\''.") AND s.accepted='1' AND url NOT LIKE '".$sub_course_dir.$dir."/%/%' AND url LIKE '".$sub_course_dir.$dir."/%'";
  556. }
  557. //count documents
  558. $res_document = Database::query($sql_document);
  559. $count_document = Database::fetch_row($res_document);
  560. $cant_files = $count_document[0];
  561. //count directories
  562. $sql_directory = "SELECT count(*) FROM $work_table s WHERE url NOT LIKE '/".$mydir."/%/%' AND url LIKE '/".$mydir."/%'";
  563. $res_directory = Database::query($sql_directory);
  564. $count_directory = Database::fetch_row($res_directory);
  565. $cant_dir = $count_directory[0];
  566. $text_file = get_lang('FilesUpload');
  567. $text_dir = get_lang('Directories');
  568. if ($cant_files == 1) {
  569. $text_file = api_strtolower(get_lang('FileUpload'));
  570. }
  571. if ($cant_dir == 1) {
  572. $text_dir = get_lang('directory');
  573. }
  574. if ($cant_dir != 0) {
  575. $dirtext = ' ('.$cant_dir.' '.$text_dir.')';
  576. } else {
  577. $dirtext = '';
  578. }
  579. $icon = '<img src="../img/works.gif" border="0" hspace="5" align="middle" alt="'.get_lang('Assignment').'" title="'.get_lang('Assignment').'" />';
  580. if (!empty($display_edit_form) && isset($clean_edit_dir) && $clean_edit_dir == $mydir) {
  581. $row[] = $icon;
  582. $row[] = '<span class="invisible" style="display:none">'.$dir.'</span>'.$form_folder->toHtml(); // form to edit the directory's name
  583. } else {
  584. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&curdirpath='.$mydir.'">'.$icon.'</a>';
  585. $tbl_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  586. $add_to_name = '';
  587. $sql = "SELECT weight FROM ". $tbl_gradebook_link ." WHERE type='3' AND ref_id= '".$id2."'";
  588. $result = Database::query($sql);
  589. $count = Database::num_rows($result);
  590. if ($count > 0) {
  591. $add_to_name = ' / <span style="color:blue">'.get_lang('Assignment').'</span>';
  592. } else {
  593. $add_to_name = '';
  594. }
  595. $show_as_icon = get_work_id($mydir); //true or false
  596. if ($show_as_icon) {
  597. if (is_allowed_to_edit()) {
  598. $zip='<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&gradebook='.$gradebook.'&action=downloadfolder&path=/'.$mydir.'"><img src="../img/zip_save.gif" style="float:right;" alt="'.get_lang('Save').'" title="'.get_lang('Save').'" width="17" height="17"/></a>';
  599. }
  600. $row[] = $zip.'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&curdirpath='.$mydir.'"'.$class.'>'.$dir.'</a>'.$add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
  601. } else {
  602. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&curdirpath='.$mydir.'"'.$class.'>'.$dir.'</a>'.$add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
  603. }
  604. }
  605. if ($count_files != 0) {
  606. $row[] = '';
  607. }
  608. if ($direc_date != '' && $direc_date != '0000-00-00 00:00:00') {
  609. $direc_date_local = api_get_local_time($direc_date, null, date_default_timezone_get());
  610. $row[] = date_to_str_ago($direc_date_local).'<br /><span class="dropbox_date">'.api_format_date($direc_date_local).'</span>';
  611. } else {
  612. $direc_date_local = '0000-00-00 00:00:00';
  613. $row[] = '';
  614. }
  615. if ($origin != 'learnpath') {
  616. if ($is_allowed_to_edit) {
  617. $action .= '<a href="'.api_get_self().'?cidReq='.api_get_course_id().
  618. '&curdirpath='.$my_sub_dir.'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$mydir.'"><img src="../img/edit.gif" alt="'.get_lang('Modify').'" title="'.get_lang('Modify').'"></a>';
  619. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&delete_dir='.$mydir.'&delete2='.$id2.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('DirDelete').'" >'.Display::return_icon('delete.gif',get_lang('DirDelete')).'</a>';
  620. $row[] = $action;
  621. } else {
  622. $row[] = '';
  623. }
  624. }
  625. $row[] = $direc_date_local;
  626. $table_data[] = $row;
  627. }
  628. }
  629. if (Database::num_rows($sql_result) > 0) {
  630. while ($work = Database::fetch_object($sql_result)) {
  631. //Get the author ID for that document from the item_property table
  632. $is_author = false;
  633. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND ref=".$work->id;
  634. $author_qry = Database::query($author_sql);
  635. $row2 = Database::fetch_array($author_qry);
  636. if (Database::num_rows($author_qry) == 1) {
  637. $is_author = true;
  638. }
  639. //display info depending on the permissions
  640. if ($work->accepted == '1' || $is_allowed_to_edit) {
  641. $row = array();
  642. if ($work->accepted == '0') {
  643. $class = 'class="invisible"';
  644. } else {
  645. $class = '';
  646. }
  647. $qualification_string = '';
  648. $add_string = '';
  649. if (defined('IS_ASSIGNMENT')) {
  650. if($work->qualification == '') {
  651. $qualification_string = ' / <b style="color:orange">'.get_lang('NotRevised').'</b>';
  652. } else {
  653. $qualification_string = ' / <b style="color:blue">'.get_lang('Qualification').': '.$work->qualification.'</b>';
  654. }
  655. if (defined('ASSIGNMENT_EXPIRES') && (ASSIGNMENT_EXPIRES < convert_date_to_number($work->sent_date))) {
  656. $add_string = ' <b style="color:red">'.get_lang('Expired').'</b>';
  657. }
  658. }
  659. $url = implode('/', array_map('rawurlencode', explode('/', $work->url)));
  660. $row[] = '<a href="download.php?file='.$url.'">'.build_document_icon_tag('file', substr(basename($work->url), 13)).'</a>';
  661. $row[] = '<a href="download.php?file='.$url.'"'.$class.'><img src="../img/filesave.gif" style="float:right;" alt="'.get_lang('Save').'" title="'.get_lang('Save').'" />'.$work->title.'</a><br />'.$work->description;
  662. $row[] = display_user_link_work($row2['insert_user_id'], $work->author).$qualification_string; // $work->author;
  663. $work_sent_date_local = api_get_local_time($work->sent_date, null, date_default_timezone_get());
  664. $row[] = date_to_str_ago($work_sent_date_local).$add_string.'<br /><span class="dropbox_date">'.api_format_date($work_sent_date_local).'</span>';
  665. if ($is_allowed_to_edit) {
  666. $action = '';
  667. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;edit='.$work->id.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&amp;parent_id='.$work->parent_id.'" title="'.get_lang('Modify').'" ><img src="../img/edit.gif" alt="'.get_lang('Modify').'" title="'.get_lang('Modify').'"></a>';
  668. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('WorkDelete').'" >'.Display::return_icon('delete.gif', get_lang('WorkDelete')).'</a>';
  669. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;move='.$work->id.'" title="'.get_lang('Move').'"><img src="../img/deplacer_fichier.gif" border="0" title="'.get_lang('Move').'" alt="'.get_lang('Move').'" /></a>';
  670. if ($work->accepted == '1') {
  671. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;make_invisible='.$work->id.'&amp;'.$sort_params.'" title="'.get_lang('Invisible').'" ><img src="../img/visible.gif" alt="'.get_lang('Invisible').'" title="'.get_lang('Invisible').'"></a>';
  672. } else {
  673. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;make_visible='.$work->id.'&amp;'.$sort_params.'" title="'.get_lang('Visible').'" ><img src="../img/invisible.gif" alt="'.get_lang('Visible').'" title="'.get_lang('Visible').'"></a>';
  674. }
  675. $row[] = $action;
  676. // the user that is not course admin can only edit/delete own document
  677. } elseif ($row2['insert_user_id'] == $_user['user_id']) {
  678. $action = '';
  679. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;edit='.$work->id.'" title="'.get_lang('Modify').'" ><img src="../img/edit.gif" alt="'.get_lang('Modify').'" title="'.get_lang('Modify').'"></a>';
  680. if (api_get_course_setting('student_delete_own_publication') == 1) {
  681. $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('WorkDelete').'" >'.Display::return_icon('delete.gif',get_lang('WorkDelete')).'</a>';
  682. }
  683. $row[] = $action;
  684. } else {
  685. $row[] = ' ';
  686. }
  687. $row[] = $work_sent_date_local;
  688. $table_data[] = $row;
  689. }
  690. }
  691. }
  692. $sorting_options = array();
  693. $sorting_options['column'] = 1;
  694. $paging_options = array();
  695. if (isset($_GET['curdirpath'])) {
  696. $my_params = array ('curdirpath' => Security::remove_XSS($_GET['curdirpath']));
  697. }
  698. if (isset($_GET['edit_dir'])) {
  699. $my_params = array ('edit_dir' => Security::remove_XSS($_GET['edit_dir']));
  700. }
  701. $my_params['origin'] = $origin;
  702. Display::display_sortable_config_table($table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order);
  703. }
  704. /**
  705. * Returns a list of subdirectories found in the given directory.
  706. *
  707. * The list return starts from the given base directory.
  708. * If you require the subdirs of /var/www/ (or /var/www), you will get 'abc/', 'def/', but not '/var/www/abc/'...
  709. * @param string Base dir
  710. * @param integer 0 if we only want dirs from this level, 1 if we want to recurse into subdirs
  711. * @return strings_array The list of subdirs in 'abc/' form, -1 on error, and 0 if none found
  712. * @todo Add a session check to see if subdirs_list doesn't exist yet (cached copy)
  713. */
  714. function get_subdirs_list($basedir = '', $recurse = 0) {
  715. //echo "Looking for subdirs of $basedir";
  716. if (empty($basedir) or !is_dir($basedir)) {
  717. return -1;
  718. }
  719. if (substr($basedir, -1, 1) != '/') {
  720. $basedir = $basedir.'/';
  721. }
  722. $dirs_list = array();
  723. $dh = opendir($basedir);
  724. while ($entry = readdir($dh)) {
  725. $entry = replace_dangerous_char($entry);
  726. $entry = disable_dangerous_file($entry);
  727. if (is_dir($basedir.$entry) && $entry != '..' && $entry != '.') {
  728. $dirs_list[] = $entry;
  729. if ($recurse == 1) {
  730. foreach (get_subdirs_list($basedir.$entry) as $subdir) {
  731. $dirs_list[] = $entry.'/'.$subdir;
  732. }
  733. }
  734. }
  735. }
  736. closedir($dh);
  737. return $dirs_list;
  738. }
  739. /**
  740. * Builds the form thats enables the user to
  741. * select a directory to browse/upload in
  742. * This function has been copied from the document/document.inc.php library
  743. *
  744. * @param array $folders
  745. * @param string $curdirpath
  746. * @param string $group_dir
  747. * @return string html form
  748. */
  749. // TODO: This function is a candidate for removal, it is not used anywhere.
  750. function build_work_directory_selector($folders, $curdirpath, $group_dir = '') {
  751. $form = '<form name="selector" action="'.api_get_self().'?'.api_get_cidreq().'" method="POST">'."\n";
  752. $form .= get_lang('CurrentDirectory').' <select name="curdirpath" onchange="javascript: document.selector.submit();">'."\n";
  753. //group documents cannot be uploaded in the root
  754. if ($group_dir == '') {
  755. $form .= '<option value="/">/ ('.get_lang('Root').')</option>';
  756. if (is_array($folders)) {
  757. foreach ($folders as $folder) {
  758. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  759. $form .= '<option'.$selected.' value="'.$folder.'">'.$folder.'</option>'."\n";
  760. }
  761. }
  762. } else {
  763. foreach ($folders as $folder) {
  764. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  765. $display_folder = substr($folder, strlen($group_dir));
  766. $display_folder = ($display_folder == '') ? '/ ('.get_lang('Root').')' : $display_folder;
  767. $form .= '<option'.$selected.' value="'.$folder.'">'.$display_folder.'</option>'."\n";
  768. }
  769. }
  770. $form .= '</select>'."\n";
  771. $form .= '<noscript><input type="submit" name="change_path" value="'.get_lang('Ok').'" /></noscript>'."\n";
  772. $form .= '</form>';
  773. return $form;
  774. }
  775. /**
  776. * Builds the form thats enables the user to
  777. * move a document from one directory to another
  778. * This function has been copied from the document/document.inc.php library
  779. *
  780. * @param array $folders
  781. * @param string $curdirpath
  782. * @param string $move_file
  783. * @return string html form
  784. */
  785. function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
  786. //gets file title
  787. $move_file = intval($move_file);
  788. $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  789. $sql = "SELECT title FROM $tbl_work WHERE id ='".$move_file."'";
  790. $result = Database::query($sql);
  791. $title = Database::fetch_row($result);
  792. global $gradebook;
  793. $form = '<form name="move_to" action="'.api_get_self().'?gradebook='.$gradebook.'" method="POST">'."\n";
  794. $form .= '<div class="row"><div class="form_header">'.get_lang('MoveFile').'</div></div>';
  795. $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />'."\n";
  796. $form .= '<div class="row">
  797. <div class="label">
  798. <span class="form_required">*</span>'.sprintf(get_lang('MoveXTo'), $title[0]).'
  799. </div>
  800. <div class="formw">';
  801. $form .= ' <select name="move_to">'."\n";
  802. //group documents cannot be uploaded in the root
  803. if ($group_dir == '') {
  804. if ($curdirpath != '/') {
  805. $form .= '<option value="0">/ ('.get_lang('Root').')</option>';
  806. }
  807. if (is_array($folders)) {
  808. foreach ($folders as $fid => $folder) {
  809. //you cannot move a file to:
  810. //1. current directory
  811. //2. inside the folder you want to move
  812. //3. inside a subfolder of the folder you want to move
  813. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  814. $form .= '<option value="'.$fid.'">'.$folder.'</option>'."\n";
  815. }
  816. }
  817. }
  818. } else {
  819. if ($curdirpath != '/') {
  820. $form .= '<option value="0">/ ('.get_lang('Root').')</option>';
  821. }
  822. foreach ($folders as $fid => $folder) {
  823. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  824. //cannot copy dir into his own subdir
  825. $display_folder = substr($folder, strlen($group_dir));
  826. $display_folder = ($display_folder == '') ? '/ ('.get_lang('Root').')' : $display_folder;
  827. $form .= '<option value="'.$fid.'">'.$display_folder.'</option>'."\n";
  828. }
  829. }
  830. }
  831. $form .= '</select>'."\n";
  832. $form .= ' </div>
  833. </div>';
  834. $form .= '<div class="row">
  835. <div class="label">
  836. </div>
  837. <div class="formw">
  838. <button type="submit" class="save" name="move_file_submit">'.get_lang('MoveFile').'</button>
  839. </div>
  840. </div>';
  841. $form .= '</form>';
  842. $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  843. return $form;
  844. }
  845. /**
  846. * Checks if the first given directory exists as a subdir of the second given directory
  847. * This function should now be deprecated by Security::check_abs_path()
  848. * @param string Subdir
  849. * @param string Base dir
  850. * @return integer -1 on error, 0 if not subdir, 1 if subdir
  851. */
  852. // TODO: This function is a candidate for removal, it is not used anywhere.
  853. function is_subdir_of($subdir, $basedir) {
  854. if (empty($subdir) or empty($basedir)) {
  855. return -1;
  856. }
  857. if (substr($basedir, -1, 1) != '/') {
  858. $basedir = $basedir.'/';
  859. }
  860. if (substr($subdir, 0, 1) == '/') {
  861. $subdir = substr($subdir, 1);
  862. }
  863. return is_dir($basedir.$subdir) ? 1 : 0;
  864. }
  865. /**
  866. * creates a new directory trying to find a directory name
  867. * that doesn't already exist
  868. * (we could use unique_name() here...)
  869. *
  870. * @author Hugues Peeters <hugues.peeters@claroline.net>
  871. * @author Bert Vanderkimpen
  872. * @author Yannick Warnier <ywarnier@beeznest.org> Adaptation for work tool
  873. * @param string Base work dir (.../work)
  874. * @param string $desiredDirName complete path of the desired name
  875. * @return string actual directory name if it succeeds, boolean false otherwise
  876. */
  877. function create_unexisting_work_directory($base_work_dir, $desired_dir_name) {
  878. $nb = '';
  879. $base_work_dir = (substr($base_work_dir, -1, 1) == '/' ? $base_work_dir : $base_work_dir.'/');
  880. while (file_exists($base_work_dir.$desired_dir_name.$nb)) {
  881. $nb += 1;
  882. }
  883. if (@mkdir($base_work_dir.$desired_dir_name.$nb, api_get_permissions_for_new_directories())) {
  884. return $desired_dir_name.$nb;
  885. } else {
  886. return false;
  887. }
  888. }
  889. /**
  890. * Delete a work-tool directory
  891. * @param string Base "work" directory for this course as /var/www/dokeos/courses/ABCD/work/
  892. * @param string The directory name as the bit after "work/", without trailing slash
  893. * @return integer -1 on error
  894. */
  895. function del_dir($base_work_dir, $dir, $id) {
  896. $id = intval($id);
  897. if (empty($dir) or $dir == '/') {
  898. return -1;
  899. }
  900. $check = Security::check_abs_path($base_work_dir.$dir, $base_work_dir);
  901. if (!$check || !is_dir($base_work_dir.$dir)) {
  902. return -1;
  903. }
  904. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  905. $sql = "DELETE FROM $table WHERE url BINARY 'work/".$dir."/%'";
  906. $res = Database::query($sql);
  907. //delete from DB the directories
  908. $sql = "DELETE FROM $table WHERE filetype = 'folder' AND url BINARY '/".$dir."%'";
  909. $res = Database::query($sql);
  910. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  911. $new_dir = $dir.'_DELETED_'.$id;
  912. if (api_get_setting('permanently_remove_deleted_files') == 'true'){
  913. my_delete($base_work_dir.$dir);
  914. } else {
  915. if (file_exists($base_work_dir.$dir)) {
  916. rename($base_work_dir.$dir, $base_work_dir.$new_dir);
  917. }
  918. }
  919. }
  920. /**
  921. * Get the path of a document in the student_publication table (path relative to the course directory)
  922. * @param integer Element ID
  923. * @return string Path (or -1 on error)
  924. */
  925. function get_work_path($id) {
  926. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  927. $sql = "SELECT * FROM $table WHERE id=$id";
  928. $res = Database::query($sql);
  929. if (Database::num_rows($res) != 1) {
  930. return -1;
  931. } else {
  932. $row = Database::fetch_array($res);
  933. return $row['url'];
  934. }
  935. }
  936. /**
  937. * Update the url of a work in the student_publication table
  938. * @param integer ID of the work to update
  939. * @param string Destination directory where the work has been moved (must end with a '/')
  940. * @return -1 on error, sql query result on success
  941. */
  942. function update_work_url($id, $new_path, $parent_id) {
  943. if (empty($id)) return -1;
  944. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  945. $sql = "SELECT * FROM $table WHERE id=$id";
  946. $res = Database::query($sql);
  947. if (Database::num_rows($res) != 1) {
  948. return -1;
  949. } else {
  950. $row = Database::fetch_array($res);
  951. $filename = basename($row['url']);
  952. $new_url = $new_path .$filename;
  953. $sql2 = "UPDATE $table SET url = '$new_url', parent_id = '$parent_id' WHERE id=$id";
  954. $res2 = Database::query($sql2);
  955. return $res2;
  956. }
  957. }
  958. /**
  959. * Update the url of a dir in the student_publication table
  960. * @param string old path
  961. * @param string new path
  962. */
  963. function update_dir_name($path, $new_name) {
  964. if (!empty($new_name)) {
  965. global $base_work_dir;
  966. include_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  967. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  968. $path_to_dir = dirname($path);
  969. if ($path_to_dir == '.') {
  970. $path_to_dir = '';
  971. } else {
  972. $path_to_dir .= '/';
  973. }
  974. $new_name = Security::remove_XSS($new_name);
  975. $new_name = replace_dangerous_char($new_name);
  976. $new_name = disable_dangerous_file($new_name);
  977. my_rename($base_work_dir.'/'.$path, $new_name);
  978. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  979. //update all the files in the other directories according with the next query
  980. $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "work/'.$path.'/%"'; // like binary (Case Sensitive)
  981. $rs = Database::query($sql);
  982. $work_len = strlen('work/'.$path);
  983. while ($work = Database :: fetch_array($rs)) {
  984. $new_dir = $work['url'];
  985. $name_with_directory = substr($new_dir, $work_len, strlen($new_dir));
  986. $sql = 'UPDATE '.$table.' SET url="work/'.$path_to_dir.$new_name.$name_with_directory.'" WHERE id= '.$work['id'];
  987. Database::query($sql);
  988. }
  989. //update all the directory's children according with the next query
  990. $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "/'.$path.'%"';
  991. $rs = Database::query($sql);
  992. $work_len = strlen('/'.$path);
  993. while ($work = Database :: fetch_array($rs)) {
  994. $new_dir = $work['url'];
  995. $name_with_directory = substr($new_dir, $work_len, strlen($new_dir));
  996. $url = $path_to_dir.$new_name.$name_with_directory;
  997. $sql = 'UPDATE '.$table.' SET url="/'.$url.'" WHERE id= '.$work['id'];
  998. Database::query($sql);
  999. }
  1000. }
  1001. }
  1002. /**
  1003. * Return an array with all the folder's ids that are in the given path
  1004. * @param string Path of the directory
  1005. * @return array The list of ids of all the directories in the path
  1006. * @author Julio Montoya Dokeos
  1007. * @version April 2008
  1008. */
  1009. function get_parent_directories($my_cur_dir_path) {
  1010. $list_id = array();
  1011. if (!empty($my_cur_dir_path)) {
  1012. $list_parents = explode('/', $my_cur_dir_path);
  1013. $dir_acum = '';
  1014. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1015. for ($i = 0; $i < count($list_parents) - 1; $i++) {
  1016. $item = Database::escape_string($list_parents[$i]);
  1017. $where_sentence = "url LIKE BINARY '" . $dir_acum . "/" . $item."'";
  1018. $dir_acum .= '/' . $list_parents[$i];
  1019. $sql = "SELECT id FROM ". $work_table . " WHERE ". $where_sentence;
  1020. $result = Database::query($sql);
  1021. $row = Database::fetch_array($result);
  1022. $list_id[] = $row['id'];
  1023. }
  1024. }
  1025. return $list_id;
  1026. }
  1027. /**
  1028. * Transform an all directory structure (only directories) in an array
  1029. * @param string path of the directory
  1030. * @return array the directory structure into an array
  1031. * @author Julio Montoya Dokeos
  1032. * @version April 2008
  1033. */
  1034. function directory_to_array($directory) {
  1035. $array_items = array();
  1036. if ($handle = @opendir($directory)) {
  1037. while (false !== ($file = readdir($handle))) {
  1038. if ($file != '.' && $file != '..') {
  1039. if (is_dir($directory. '/' . $file)) {
  1040. $array_items = array_merge($array_items, directory_to_array($directory. '/' . $file));
  1041. $file = $directory . '/' . $file;
  1042. $array_items[] = preg_replace("/\/\//si", '/', $file);
  1043. }
  1044. }
  1045. }
  1046. closedir($handle);
  1047. }
  1048. return $array_items;
  1049. }
  1050. /**
  1051. * Insert into the DB of the course all the directories
  1052. * @param string path of the /work directory of the course
  1053. * @return -1 on error, sql query result on success
  1054. * @author Julio Montoya Dokeos
  1055. * @version April 2008
  1056. */
  1057. function insert_all_directory_in_course_table($base_work_dir) {
  1058. $dir_to_array = directory_to_array($base_work_dir, true);
  1059. $only_dir = array();
  1060. for ($i = 0; $i < count($dir_to_array); $i++) {
  1061. $only_dir[] = substr($dir_to_array[$i], strlen($base_work_dir), strlen($dir_to_array[$i]));
  1062. }
  1063. for($i = 0; $i < count($only_dir); $i++) {
  1064. global $work_table;
  1065. $sql_insert_all= "INSERT INTO " . $work_table . " SET url = '" . $only_dir[$i] . "', " .
  1066. "title = '',
  1067. description = '',
  1068. author = '',
  1069. active = '0',
  1070. accepted = '1',
  1071. filetype = 'folder',
  1072. post_group_id = '".intval($_GET['toolgroup'])."',
  1073. sent_date = '0000-00-00 00:00:00' ";
  1074. Database::query($sql_insert_all);
  1075. }
  1076. }
  1077. /**
  1078. * This function displays the number of files contained in a directory
  1079. *
  1080. * @param string the path of the directory
  1081. * @param boolean true if we want the total quantity of files include in others child directorys , false only files in the directory
  1082. * @return array the first element is an integer with the number of files in the folder, the second element is the number of directories
  1083. * @author Julio Montoya Dokeos
  1084. * @version April 2008
  1085. */
  1086. function count_dir($path_dir, $recurse) {
  1087. $count = 0;
  1088. $count_dir = 0;
  1089. $d = dir($path_dir);
  1090. while ($entry = $d->Read()) {
  1091. if (!(($entry == '..') || ($entry == '.'))) {
  1092. if (is_dir($path_dir.'/'.$entry)) {
  1093. $count_dir++;
  1094. if ($recurse) {
  1095. $count += count_dir($path_dir . '/' . $entry, $recurse);
  1096. }
  1097. } else {
  1098. $count++;
  1099. }
  1100. }
  1101. }
  1102. $return_array = array();
  1103. $return_array[] = $count;
  1104. $return_array[] = $count_dir;
  1105. return $return_array;
  1106. }
  1107. /**
  1108. * returns all the javascript that is required for easily
  1109. * validation when you create a work
  1110. * this goes into the $htmlHeadXtra[] array
  1111. */
  1112. function to_javascript_work() {
  1113. return '<script>
  1114. function plus() {
  1115. if(document.getElementById(\'options\').style.display == \'none\') {
  1116. document.getElementById(\'options\').style.display = \'block\';
  1117. document.getElementById(\'plus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide', ''), array('style' => 'vertical-align:middle')).'&nbsp;'.addslashes(get_lang('AdvancedParameters', '')).'\';
  1118. } else {
  1119. document.getElementById(\'options\').style.display = \'none\';
  1120. document.getElementById(\'plus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show', ''), array('style' => 'vertical-align:middle')).'&nbsp;'.addslashes(get_lang('AdvancedParameters', '')).'\';
  1121. }
  1122. }
  1123. function updateDocumentTitle(value){
  1124. var temp = value.indexOf("/");
  1125. //linux path
  1126. if(temp!=-1){
  1127. var temp=value.split("/");
  1128. }
  1129. else{
  1130. var temp=value.split("\\\");
  1131. }
  1132. document.getElementById("file_upload").value=temp[temp.length-1];
  1133. }
  1134. function checkDate(month, day, year)
  1135. {
  1136. var monthLength =
  1137. new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  1138. if (!day || !month || !year)
  1139. return false;
  1140. // check for bisestile year
  1141. if (year/4 == parseInt(year/4))
  1142. monthLength[1] = 29;
  1143. if (month < 1 || month > 12)
  1144. return false;
  1145. if (day > monthLength[month-1])
  1146. return false;
  1147. return true;
  1148. }
  1149. function mktime() {
  1150. var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
  1151. d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  1152. var dateManip = {
  1153. 0: function(tt){ return d.setHours(tt); },
  1154. 1: function(tt){ return d.setMinutes(tt); },
  1155. 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
  1156. 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
  1157. 4: function(tt){ return d.setDate(tt+mb); },
  1158. 5: function(tt){ return d.setYear(tt+ma); }
  1159. };
  1160. for( i = 0; i < argc; i++ ){
  1161. no = parseInt(argv[i]*1);
  1162. if (isNaN(no)) {
  1163. return false;
  1164. } else {
  1165. // arg is number, lets manipulate date object
  1166. if(!dateManip[i](no)){
  1167. // failed
  1168. return false;
  1169. }
  1170. }
  1171. }
  1172. return Math.floor(d.getTime()/1000);
  1173. }
  1174. function validate(){
  1175. var expires_day = document.form1.expires_day.value;
  1176. var expires_month = document.form1.expires_month.value;
  1177. var expires_year = document.form1.expires_year.value;
  1178. var expires_hour = document.form1.expires_hour.value;
  1179. var expires_minute = document.form1.expires_minute.value;
  1180. var expires_date = mktime(expires_hour,expires_minute,0,expires_month,expires_day,expires_year)
  1181. var ends_day = document.form1.ends_day.value;
  1182. var ends_month = document.form1.ends_month.value;
  1183. var ends_year = document.form1.ends_year.value;
  1184. var ends_hour = document.form1.ends_hour.value;
  1185. var ends_minute = document.form1.ends_minute.value;
  1186. var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year)
  1187. var new_dir = document.form1.new_dir.value;
  1188. msg_id1 = document.getElementById("msg_error1");
  1189. msg_id2 = document.getElementById("msg_error2");
  1190. msg_id3 = document.getElementById("msg_error3");
  1191. msg_id4 = document.getElementById("msg_error4");
  1192. msg_id5 = document.getElementById("msg_error_weight");
  1193. if(new_dir==""){
  1194. msg_id1.style.display ="block";
  1195. msg_id1.innerHTML="'.get_lang('FieldRequired', '').'";
  1196. msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1197. }
  1198. else if(document.form1.type1.checked==true && document.form1.type2.checked==true && expires_date > ends_date) {
  1199. msg_id2.style.display ="block";
  1200. msg_id2.innerHTML="'.get_lang('EndDateCannotBeBeforeTheExpireDate', '').'";
  1201. msg_id1.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1202. }
  1203. else if (checkDate(expires_month,expires_day,expires_year) == false)
  1204. {
  1205. msg_id3.style.display ="block";
  1206. msg_id3.innerHTML="'.get_lang('InvalidDate', '').'";
  1207. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1208. }
  1209. else if (checkDate(ends_month,ends_day,ends_year) == false)
  1210. {
  1211. msg_id4.style.display ="block";
  1212. msg_id4.innerHTML="'.get_lang('InvalidDate', '').'";
  1213. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id5.innerHTML="";
  1214. }
  1215. else
  1216. {
  1217. if (document.form1.make_calification.checked == true)
  1218. {
  1219. var weight = document.form1.weight.value;
  1220. if(weight==""){
  1221. msg_id5.style.display ="block";
  1222. msg_id5.innerHTML="'.get_lang('WeightNecessary', '').'";
  1223. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";
  1224. return false;
  1225. }
  1226. }
  1227. document.form1.action = "work.php?origin='.api_get_tools_lists($_REQUEST['origin']).'&gradebook='.(empty($_GET['gradebook'])?'':'view').'";
  1228. document.form1.submit();
  1229. }
  1230. }
  1231. </script>';
  1232. }
  1233. /**
  1234. * Gets the id of a student publication with a given path
  1235. * @param string $path
  1236. * @return true if is found / false if not found
  1237. */
  1238. // TODO: The name of this function does not fit with the kind of information it returns. Maybe check_work_id() or is_work_id()?
  1239. function get_work_id($path) {
  1240. $TBL_STUDENT_PUBLICATION = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  1241. $TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1242. if (is_allowed_to_edit()) {
  1243. $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2'";
  1244. } else {
  1245. $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2' AND props.lastedit_user_id='".api_get_user_id()."'";
  1246. }
  1247. $result = Database::query($sql);
  1248. $num_rows = Database::num_rows($result);
  1249. if ($result && $num_rows > 0) {
  1250. return true;
  1251. } else {
  1252. return false;
  1253. }
  1254. }
  1255. /**
  1256. * Get list of users who have not given the task
  1257. * @param int
  1258. * @return array
  1259. * @author cvargas carlos.vargas@beeznest.com
  1260. */
  1261. function get_list_users_without_publication($task_id) {
  1262. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1263. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1264. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1265. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  1266. $session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1267. //condition for the session
  1268. $session_id = api_get_session_id();
  1269. if (!empty($session_id)){
  1270. $sql = "SELECT user_id as id FROM $work_table WHERE parent_id='$task_id' and session_id='".$session_id."'";
  1271. } else {
  1272. $sql = "SELECT user_id as id FROM $work_table WHERE parent_id='$task_id'";
  1273. }
  1274. $result = Database::query($sql);
  1275. $users_with_tasks = array();
  1276. while($row = Database::fetch_array($result)) {
  1277. $users_with_tasks[] = $row['id'];
  1278. }
  1279. if (!empty($session_id)){
  1280. $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u WHERE u.status!=1 and cu.course_code='".api_get_course_id()."' AND u.user_id=cu.id_user and cu.id_session='".$session_id."'";
  1281. } else {
  1282. $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u WHERE u.status!=1 and cu.course_code='".api_get_course_id()."' AND u.user_id=cu.user_id";
  1283. }
  1284. $result_users = Database::query($sql_users);
  1285. $users_without_tasks = array();
  1286. while ($row_users = Database::fetch_row($result_users)) {
  1287. if (in_array($row_users[0], $users_with_tasks)) continue;
  1288. $user_id = array_shift($row_users);
  1289. $row_users[3] = $row_users[2];
  1290. $row_users[2] = Display::encrypted_mailto_link($row_users[2], $row_users[2]);
  1291. $users_without_tasks[] = $row_users;
  1292. }
  1293. return $users_without_tasks;
  1294. }
  1295. /**
  1296. * Display list of users who have not given the task
  1297. *
  1298. * @param int task id
  1299. * @return array
  1300. * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
  1301. * @author Julio Montoya <gugli100@gmail.com> Fixes
  1302. */
  1303. function display_list_users_without_publication($task_id) {
  1304. global $origin;
  1305. $table_header[] = array(get_lang('FirstName'), true);
  1306. $table_header[] = array(get_lang('LastName'), true);
  1307. $table_header[] = array(get_lang('Email'), true);
  1308. // table_data
  1309. $table_data = get_list_users_without_publication($task_id);
  1310. $sorting_options = array();
  1311. $sorting_options['column'] = 1;
  1312. $paging_options = array();
  1313. $my_params = array();
  1314. if (isset($_GET['curdirpath'])) {
  1315. $my_params['curdirpath'] = Security::remove_XSS($_GET['curdirpath']);
  1316. }
  1317. if (isset($_GET['edit_dir'])) {
  1318. $my_params['edit_dir'] = Security::remove_XSS($_GET['edit_dir']);
  1319. }
  1320. if (isset($_GET['list'])) {
  1321. $my_params['list'] = Security::remove_XSS($_GET['list']);
  1322. }
  1323. $my_params['origin'] = $origin;
  1324. //$column_show
  1325. $column_show[] = 1;
  1326. $column_show[] = 1;
  1327. $column_show[] = 1;
  1328. Display::display_sortable_config_table($table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show);
  1329. }
  1330. /**
  1331. * Send reminder to users who have not given the task
  1332. *
  1333. * @param int
  1334. * @return array
  1335. * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
  1336. */
  1337. function send_reminder_users_without_publication($task_id) {
  1338. global $_course, $my_cur_dir_path, $currentUserFirstName, $currentUserLastName, $currentUserEmail;
  1339. $emailsubject = '[' . api_get_setting('siteName') . '] ';
  1340. $sender_name = api_get_person_name($currentUserFirstName, $currentUserLastName, null, PERSON_NAME_EMAIL_ADDRESS);
  1341. $email_admin = $currentUserEmail;
  1342. // The body can be as long as you wish, and any combination of text and variables
  1343. $emailbody_user .= get_lang('ReminderToSubmitPendingTask')."\n".get_lang('CourseName').' : '.$_course['name']."\n";
  1344. $emailbody_user .= get_lang('WorkName').' : '.substr($my_cur_dir_path, 0, -1)."\n\n".get_lang('Teacher').' : '.api_get_person_name($currentUserFirstName, $currentUserLastName)."\n".get_lang('Email').' : '.$currentUserEmail;
  1345. $list_users = get_list_users_without_publication($task_id);
  1346. foreach ($list_users as $user) {
  1347. $name_user = api_get_person_name($user[0], $user[1], null, PERSON_NAME_EMAIL_ADDRESS);
  1348. @api_mail($name_user, $user[3], $emailsubject, $emailbody_user, $sender_name, $email_admin);
  1349. }
  1350. }