work.lib.php 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.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. * @author Julio Montoya <gugli100@gmail.com> BeezNest 2011 LOTS of bug fixes
  10. * @todo this lib should be convert in a static class and moved to main/inc/lib
  11. */
  12. /**
  13. * Initialization
  14. */
  15. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
  16. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  17. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  18. /**
  19. * Displays action links (for admins, authorized groups members and authorized students)
  20. * @param string Current dir
  21. * @param integer Whether to show tool options
  22. * @param integer Whether to show upload form option
  23. * @return void
  24. */
  25. function display_action_links($id, $cur_dir_path, $show_tool_options, $display_upload_link, $action) {
  26. global $gradebook;
  27. $id = $my_back_id = intval($id);
  28. if ($action == 'list') {
  29. $my_back_id = 0;
  30. }
  31. $display_output = '';
  32. $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  33. if (!empty($id)) {
  34. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&id='.$my_back_id.'">'.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'</a>';
  35. }
  36. if ($show_tool_options && api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
  37. // Create dir
  38. if (empty($id)) {
  39. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=create_dir&origin='.$origin.'&gradebook='.$gradebook.'">';
  40. $display_output .= Display::return_icon('new_work.png', get_lang('CreateAssignment'),'',ICON_SIZE_MEDIUM).'</a>';
  41. }
  42. if (empty($id)) {
  43. // Options
  44. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=settings&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'">';
  45. $display_output .= Display::return_icon('settings.png', get_lang('EditToolOptions'),'',ICON_SIZE_MEDIUM).'</a>';
  46. }
  47. }
  48. if ($display_upload_link && api_is_allowed_to_session_edit(false, true) && !empty($id)) {
  49. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$id.'&action=upload_form&origin='.$origin.'&gradebook='.$gradebook.'">';
  50. $display_output .= Display::return_icon('upload_file.png', get_lang('UploadADocument'),'',ICON_SIZE_MEDIUM).'</a>';
  51. }
  52. if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath' && api_is_allowed_to_session_edit(false, true)) {
  53. // Delete all files
  54. if (api_get_setting('permanently_remove_deleted_files') == 'true'){
  55. $message = get_lang('ConfirmYourChoiceDeleteAllfiles');
  56. } else {
  57. $message = get_lang('ConfirmYourChoice');
  58. }
  59. }
  60. if (api_is_allowed_to_edit(null, true)) {
  61. global $token;
  62. if (!empty($id)) {
  63. if (empty($_GET['list']) or Security::remove_XSS($_GET['list']) == 'with') {
  64. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$id.'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=without">'.
  65. Display::return_icon('exercice_uncheck.png', get_lang('ViewUsersWithoutTask'),'',ICON_SIZE_MEDIUM)."</a>\n";
  66. } else {
  67. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$id.'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=with">'.
  68. Display::return_icon('exercice_check.png', get_lang('ViewUsersWithTask'),'',ICON_SIZE_MEDIUM)."</a>\n";
  69. if (!isset($_GET['action']) || (isset($_GET['action']) && $_GET['action'] != 'send_mail')) {
  70. $display_output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$id.'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=without&amp;action=send_mail&amp;sec_token='.$token.'">'.
  71. Display::return_icon('mail_send.png', get_lang('ReminderMessage'),'',ICON_SIZE_MEDIUM)."</a>";
  72. } else {
  73. $display_output .= Display::return_icon('mail_send_na.png', get_lang('ReminderMessage'),'',ICON_SIZE_MEDIUM);
  74. }
  75. }
  76. }
  77. }
  78. if ($display_output != '') {
  79. echo '<div class="actions">';
  80. echo $display_output;
  81. echo '</div>';
  82. }
  83. }
  84. /**
  85. * Displays all options for this tool.
  86. * These are
  87. * - make all files visible / invisible
  88. * - set the default visibility of uploaded files
  89. *
  90. * @param $uploadvisibledisabled
  91. * @param $origin
  92. */
  93. function display_tool_options($uploadvisibledisabled, $origin) {
  94. global $gradebook;
  95. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  96. if (!$is_allowed_to_edit) {
  97. return;
  98. }
  99. echo '<form class="form-horizontal" method="post" action="'.api_get_self().'?origin='.$origin.'&gradebook='.$gradebook.'&action=settings">';
  100. echo '<legend>'.get_lang('EditToolOptions').'</legend>';
  101. display_default_visibility_form($uploadvisibledisabled);
  102. display_studentsdelete_form();
  103. echo '<div class="row">
  104. <div class="formw">
  105. <button type="submit" class="save" name="changeProperties" value="'.get_lang('Ok').'">'.get_lang('Ok').'</button>
  106. </div>
  107. </div>';
  108. echo '</form>';
  109. }
  110. /**
  111. * Displays the form where course admins can specify wether uploaded documents
  112. * are visible or invisible by default.
  113. *
  114. * @param $uploadvisibledisabled
  115. * @param $origin
  116. */
  117. function display_default_visibility_form($uploadvisibledisabled) {
  118. ?>
  119. <div class="control-group">
  120. <label class="control-label">
  121. <?php echo get_lang('_default_upload'); ?>
  122. </label>
  123. <div class="controls">
  124. <label class="radio" for="uploadvisibledisabled_1">
  125. <input id="uploadvisibledisabled_1" class="checkbox" type="radio" name="uploadvisibledisabled" value="0" <?php if ($uploadvisibledisabled == 0) echo 'checked'; ?> />
  126. <?php echo get_lang('_new_visible'); ?>
  127. </label>
  128. <label class="radio" for="uploadvisibledisabled_2">
  129. <input id="uploadvisibledisabled_2" class="checkbox" type="radio" name="uploadvisibledisabled" value="1" <?php if ($uploadvisibledisabled == 1) echo 'checked'; ?> />
  130. <?php echo get_lang('_new_unvisible'); ?>
  131. </label>
  132. </div>
  133. </div>
  134. <?php
  135. }
  136. /**
  137. * Display a part of the form to edit the settings of the tool
  138. * In this case weither the students are allowed to delete their own publication or not (by default not)
  139. *
  140. * @return html code
  141. * @since Dokeos 1.8.6.2
  142. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  143. */
  144. function display_studentsdelete_form() {
  145. // by default api_get_course_setting returns -1 and the code only expects 0 or 1 so anything tha
  146. // is different than 1 will be converted into 0
  147. $current_course_setting_value = api_get_course_setting('student_delete_own_publication');
  148. if ($current_course_setting_value != 1) {
  149. $current_course_setting_value = 0;
  150. }
  151. ?>
  152. <div class="control-group">
  153. <label class="control-label"><?php echo get_lang('StudentAllowedToDeleteOwnPublication'); ?></label>
  154. <div class="controls">
  155. <label class="radio" for="student_delete_own_publication_2">
  156. <input id="student_delete_own_publication_2" class="checkbox" type="radio" name="student_delete_own_publication" value="1" <?php if ($current_course_setting_value == 1) echo 'checked'; ?> />
  157. <?php echo get_lang('Yes'); ?>
  158. </label>
  159. <label class="radio" for="student_delete_own_publication_1">
  160. <input id="student_delete_own_publication_1" class="checkbox" type="radio" name="student_delete_own_publication" value="0"
  161. <?php if ($current_course_setting_value == 0) echo 'checked'; ?> />
  162. <?php echo get_lang('No'); ?>
  163. </label>
  164. </div>
  165. </div>
  166. <?php
  167. }
  168. /**
  169. * converts 2008-10-06 12:45:00 to timestamp
  170. * @deprecated any calls found
  171. */
  172. function convert_date_to_number($default) {
  173. // 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
  174. $parts = split(' ', $default);
  175. list($d_year, $d_month, $d_day) = split('-', $parts[0]);
  176. list($d_hour, $d_minute, $d_second) = split(':', $parts[1]);
  177. return mktime((int)$d_hour, (int)$d_minute, (int)$d_second, (int)$d_month, (int)$d_day, (int)$d_year);
  178. }
  179. /**
  180. * converts 1-9 to 01-09
  181. */
  182. function two_digits($number) {
  183. $number = (int)$number;
  184. return ($number < 10) ? '0'.$number : $number;
  185. }
  186. /**
  187. * converts 2008-10-06 12:45:00 to -> array($data'year'=>2008,$data'month'=>10 etc...)
  188. */
  189. function convert_date_to_array($date, $group) {
  190. $parts = split(' ', $date);
  191. $date_parts = split('-', $parts[0]);
  192. $date_parts_tmp = array();
  193. foreach ($date_parts as $item) {
  194. $date_parts_tmp[] = intval($item);
  195. }
  196. $time_parts = split(':', $parts[1]);
  197. $time_parts_tmp = array();
  198. foreach ($time_parts as $item) {
  199. $time_parts_tmp[] = intval($item);
  200. }
  201. list($data[$group.'[year]'], $data[$group.'[month]'], $data[$group.'[day]']) = $date_parts_tmp;
  202. list($data[$group.'[hour]'], $data[$group.'[minute]']) = $time_parts_tmp;
  203. return $data;
  204. }
  205. /**
  206. * get date from a group of date
  207. */
  208. function get_date_from_group($group) {
  209. 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';
  210. }
  211. /**
  212. * create a group of select from a date
  213. */
  214. function create_group_date_select($prefix = '') {
  215. $minute = range(10, 59);
  216. $d_year = date('Y');
  217. array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09');
  218. $group_name[] = FormValidator :: createElement('select', $prefix.'day', '', array_combine(range(1, 31), range(1, 31)));
  219. $group_name[] = FormValidator :: createElement('select', $prefix.'month', '', array_combine(range(1, 12), api_get_months_long()));
  220. $group_name[] = FormValidator :: createElement('select', $prefix.'year', '', array($d_year => $d_year, $d_year + 1 => $d_year + 1));
  221. $group_name[] = FormValidator :: createElement('select', $prefix.'hour', '', array_combine(range(0, 23), range(0, 23)));
  222. $group_name[] = FormValidator :: createElement('select', $prefix.'minute', '', $minute);
  223. return $group_name;
  224. }
  225. function get_work_data_by_path($path) {
  226. $path = Database::escape_string($path);
  227. $course_id = api_get_course_int_id();
  228. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  229. $sql = "SELECT * FROM ".$work_table." WHERE url = '$path' AND c_id = $course_id ";
  230. $result = Database::query($sql);
  231. $return = array();
  232. if (Database::num_rows($result)) {
  233. $return = Database::fetch_array($result,'ASSOC');
  234. }
  235. return $return;
  236. }
  237. function get_work_data_by_id($id) {
  238. $id = intval($id);
  239. $course_id = api_get_course_int_id();
  240. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  241. $sql = "SELECT * FROM $work_table WHERE id = $id AND c_id = $course_id";
  242. $result = Database::query($sql);
  243. $return = array();
  244. if (Database::num_rows($result)) {
  245. $return = Database::fetch_array($result,'ASSOC');
  246. }
  247. return $return;
  248. }
  249. function get_work_count_by_student($user_id, $work_id) {
  250. $user_id = intval($user_id);
  251. $work_id = intval($work_id);
  252. $course_id = api_get_course_int_id();
  253. $session_id = api_get_session_id();
  254. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  255. $sql = "SELECT COUNT(*) as count FROM $work_table
  256. WHERE c_id = $course_id AND parent_id = $work_id AND user_id = $user_id AND active = 1 AND session_id = $session_id ";
  257. $result = Database::query($sql);
  258. $return = 0;
  259. if (Database::num_rows($result)) {
  260. $return = Database::fetch_row($result,'ASSOC');
  261. $return = intval($return[0]);
  262. }
  263. return $return;
  264. }
  265. function get_work_assignment_by_id($id) {
  266. $id = intval($id);
  267. $course_id = api_get_course_int_id();
  268. $table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  269. $sql = "SELECT * FROM $table WHERE c_id = $course_id AND publication_id = $id";
  270. $result = Database::query($sql);
  271. $return = array();
  272. if (Database::num_rows($result)) {
  273. $return = Database::fetch_array($result,'ASSOC');
  274. }
  275. return $return;
  276. }
  277. /**
  278. * Display the list of student publications, taking into account the user status
  279. *
  280. * @param $link_target_parameter - should there be a target parameter for the links
  281. * @param $dateFormatLong - date format
  282. * @param $origin - typically empty or 'learnpath'
  283. */
  284. function display_student_publications_list($id, $link_target_parameter, $dateFormatLong, $origin, $add_in_where_query = '') {
  285. global $timeNoSecFormat, $dateFormatShort, $gradebook, $_course;
  286. // Database table names
  287. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  288. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  289. $work_assigment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  290. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  291. $user_id = api_get_user_id();
  292. $session_id = api_get_session_id();
  293. $condition_session = api_get_session_condition($session_id);
  294. $course_id = api_get_course_int_id();
  295. $group_id = api_get_group_id();
  296. $course_info = api_get_course_info(api_get_course_id());
  297. $sort_params = array();
  298. if (isset($_GET['column'])) {
  299. $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
  300. }
  301. if (isset($_GET['page_nr'])) {
  302. $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
  303. }
  304. if (isset($_GET['per_page'])) {
  305. $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
  306. }
  307. if (isset($_GET['direction'])) {
  308. $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
  309. }
  310. $sort_params = implode('&amp;', $sort_params);
  311. $my_params = $sort_params;
  312. $origin = Security::remove_XSS($origin);
  313. // Getting the work data
  314. $my_folder_data = get_work_data_by_id($id);
  315. $qualification_exists = false;
  316. if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) {
  317. $qualification_exists = true;
  318. }
  319. $work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work';
  320. if (!empty($my_folder_data)) {
  321. $work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work'.$my_folder_data['url'];
  322. }
  323. if (empty($my_folder_data)) {
  324. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $id, api_get_session_id());
  325. $work_in_gradebook_link_id = $link_info['id'];
  326. if ($work_in_gradebook_link_id) {
  327. if ($is_allowed_to_edit)
  328. if (intval($my_folder_data['qualification']) == 0) {
  329. Display::display_warning_message(get_lang('MaxWeightNeedToBeProvided'));
  330. }
  331. }
  332. $contains_file_query = '';
  333. //Get list from database
  334. if ($is_allowed_to_edit) {
  335. $active_condition = ' active IN (0, 1)';
  336. $sql_get_publications_list = "SELECT * FROM $work_table
  337. WHERE c_id = $course_id $add_in_where_query $condition_session AND $active_condition AND
  338. ( parent_id = 0)
  339. $contains_file_query
  340. ORDER BY sent_date DESC";
  341. } else {
  342. if (!empty($group_id)) {
  343. $group_query = " WHERE c_id = $course_id AND post_group_id = '".$group_id."' "; // set to select only messages posted by the user's group
  344. $subdirs_query = "AND parent_id = 0";
  345. } else {
  346. $group_query = " WHERE c_id = $course_id AND post_group_id = '0' ";
  347. $subdirs_query = "AND parent_id = 0";
  348. }
  349. //@todo how we can active or not an assignment?
  350. $active_condition = ' AND active IN (1,0)';
  351. $sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session ORDER BY title";
  352. }
  353. $work_parents = array();
  354. $sql_result = Database::query($sql_get_publications_list);
  355. if (Database::num_rows($sql_result)) {
  356. while ($work = Database::fetch_object($sql_result)) {
  357. if ($work->parent_id == 0) {
  358. $work_parents[] = $work;
  359. }
  360. }
  361. }
  362. }
  363. $edit_dir = isset($_GET['edit_dir']) ? $_GET['edit_dir'] : '';
  364. $table_header = array();
  365. $table_has_actions_column = false;
  366. $table_header[] = array(get_lang('Type'), false, 'style="width:40px"');
  367. $table_header[] = array(get_lang('Title'), true);
  368. if (!empty($id)) {
  369. $table_header[] = array(get_lang('FirstName'), true);
  370. $table_header[] = array(get_lang('LastName'), true);
  371. if ($qualification_exists) {
  372. $table_header[] = array(get_lang('Qualification'), true);
  373. }
  374. }
  375. $table_header[] = array(get_lang('Date'), true, 'style="width:200px"');
  376. if ($is_allowed_to_edit) {
  377. $table_header[] = array(get_lang('Actions'), false, 'style="width:90px"', array('class'=>'td_actions'));
  378. $table_has_actions_column = true;
  379. }
  380. // the following column name seems both undefined and unused
  381. //$table_header[] = array('RealDate', true);
  382. $table_data = array();
  383. // List of all folders if no id was provided
  384. $group_id = api_get_group_id();
  385. if (is_array($work_parents)) {
  386. foreach ($work_parents as $work_parent) {
  387. $sql_select_directory = "SELECT title, url, prop.insert_date, prop.lastedit_date, work.id, author, has_properties, view_properties, description, qualification, weight, allow_text_assignment
  388. FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id AND prop.c_id = $course_id )
  389. WHERE active IN (0, 1) AND ";
  390. if (!empty($group_id)) {
  391. $sql_select_directory .= " work.post_group_id = '".$group_id."' "; // set to select only messages posted by the user's group
  392. } else {
  393. $sql_select_directory .= " work.post_group_id = '0' ";
  394. }
  395. $sql_select_directory .= " AND
  396. work.c_id = $course_id AND
  397. work.id = ".$work_parent->id." AND
  398. work.filetype = 'folder' AND
  399. prop.tool='work' $condition_session";
  400. $result = Database::query($sql_select_directory);
  401. $row = Database::fetch_array($result, 'ASSOC');
  402. if (!$row) {
  403. // the folder belongs to another session
  404. continue;
  405. }
  406. $direc_date = $row['lastedit_date']; //directory's date
  407. $author = $row['author']; //directory's author
  408. $view_properties = $row['view_properties'];
  409. $is_assignment = $row['has_properties'];
  410. $id2 = $row['id']; //work id
  411. $locked = api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION);
  412. if ($is_allowed_to_edit && $locked == false) {
  413. // form edit directory
  414. if (!empty($edit_dir) && $edit_dir == $id2) {
  415. if (!empty($row['has_properties'])) {
  416. $sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE c_id = '.$course_id.' AND id = "'.$row['has_properties'].'" LIMIT 1');
  417. $homework = Database::fetch_array($sql);
  418. }
  419. $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2);
  420. $form_folder->addElement('text', 'dir_name', get_lang('Title'));
  421. $form_folder->addElement('hidden', 'work_id', $id2);
  422. $form_folder -> addRule('dir_name', get_lang('ThisFieldIsRequired'), 'required');
  423. $my_title = !empty($row['title']) ? $row['title'] : basename($row['url']);
  424. $defaults = array('dir_name' => Security::remove_XSS($my_title), 'description' => Security::remove_XSS($row['description']));
  425. $form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'work', 'Width' => '80%', 'Height' => '200'));
  426. $there_is_a_end_date = false;
  427. $form_folder -> addElement('advanced_settings', '<a href="javascript://" onclick="javascript: return plus();" >
  428. <span id="plus">&nbsp;<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />
  429. &nbsp;'.get_lang('AdvancedParameters').'
  430. </span>
  431. </a>');
  432. $form_folder->addElement('html', '<div id="options" style="display: none;">');
  433. if (empty($default)) {
  434. $default = api_get_local_time();
  435. }
  436. $parts = explode(' ', $default);
  437. list($d_year, $d_month, $d_day) = explode('-', $parts[0]);
  438. list($d_hour, $d_minute) = explode(':', $parts[1]);
  439. if(Gradebook::is_active()){
  440. $qualification_input[] = FormValidator :: createElement('text', 'qualification');
  441. $form_folder -> addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'));
  442. if ((int)$row['weight'] == 0) {
  443. $form_folder -> addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
  444. $form_folder -> addElement('html', '<div id=\'option3\' style="display:none">');
  445. //Loading gradebook select
  446. load_gradebook_select_in_tool($form_folder);
  447. $weight_input2[] = FormValidator :: createElement('text', 'weight');
  448. $form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
  449. $form_folder -> addElement('html', '</div>');
  450. } else {
  451. $weight_input[] = FormValidator :: createElement('text', 'weight');
  452. //Loading gradebook select
  453. load_gradebook_select_in_tool($form_folder);
  454. $form_folder -> addGroup($weight_input, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
  455. }
  456. $link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $id2);
  457. $defaults['category_id'] = $link_info['category_id'];
  458. }else{
  459. $defaults['category_id'] = '';
  460. }
  461. if ($homework['expires_on'] != '0000-00-00 00:00:00') {
  462. $homework['expires_on'] = api_get_local_time($homework['expires_on']);
  463. $there_is_a_expire_date = true;
  464. $defaults['enableExpiryDate'] = true;
  465. $form_folder -> addElement('checkbox', 'enableExpiryDate',null,get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
  466. $form_folder -> addElement('html', '<div id=\'option1\' style="display:block">');
  467. $form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
  468. $form_folder -> addElement('html', '</div>');
  469. } else {
  470. $homework['expires_on'] = api_get_local_time();
  471. $expires_date_array = convert_date_to_array(api_get_local_time(), 'expires');
  472. $defaults = array_merge($defaults, $expires_date_array);
  473. $there_is_a_expire_date = false;
  474. $form_folder -> addElement('checkbox', 'enableExpiryDate',null,get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
  475. $form_folder -> addElement('html', '<div id=\'option1\' style="display:none">');
  476. $form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
  477. $form_folder -> addElement('html', '</div>');
  478. }
  479. if ($homework['ends_on'] != '0000-00-00 00:00:00') {
  480. $homework['ends_on'] = api_get_local_time($homework['ends_on']);
  481. $there_is_a_end_date = true;
  482. $defaults['enableEndDate'] = true;
  483. $form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"');
  484. $form_folder -> addElement('html', '<div id=\'option2\' style="display:block">');
  485. $form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
  486. $form_folder -> addElement('html', '</div>');
  487. $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  488. } else {
  489. $homework['ends_on'] = api_get_local_time();
  490. $expires_date_array = convert_date_to_array(api_get_local_time(), 'ends');
  491. $defaults = array_merge($defaults, $expires_date_array);
  492. $there_is_a_end_date = false;
  493. $form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"');
  494. $form_folder -> addElement('html', '<div id=\'option2\' style="display:none">');
  495. $form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
  496. $form_folder -> addElement('html', '</div>');
  497. $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  498. }
  499. if ($there_is_a_expire_date && $there_is_a_end_date) {
  500. $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  501. }
  502. $form_folder -> addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
  503. $form_folder -> addElement('html', '</div>');
  504. $form_folder -> addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"');
  505. if ($there_is_a_end_date) {
  506. $end_date_array = convert_date_to_array($homework['ends_on'], 'ends');
  507. $defaults = array_merge($defaults, $end_date_array);
  508. }
  509. if ($there_is_a_expire_date) {
  510. $expires_date_array = convert_date_to_array($homework['expires_on'], 'expires');
  511. $defaults = array_merge($defaults, $expires_date_array);
  512. }
  513. if (!empty($row['qualification'])) {
  514. $defaults = array_merge($defaults, array('qualification[qualification]' => $row['qualification']));
  515. }
  516. if (!empty($row['weight'])) {
  517. $defaults = array_merge($defaults, array('weight[weight]' => $row['weight']));
  518. }
  519. $defaults['allow_text_assignment'] = $row['allow_text_assignment'];
  520. $form_folder -> setDefaults($defaults);
  521. $display_edit_form = true;
  522. if ($form_folder->validate()) {
  523. if ($_POST['enableExpiryDate'] == '1') {
  524. $there_is_a_expire_date = true;
  525. } else {
  526. $there_is_a_expire_date = false;
  527. }
  528. if ($_POST['enableEndDate'] == '1') {
  529. $there_is_a_end_date = true;
  530. } else {
  531. $there_is_a_end_date = false;
  532. }
  533. $values = $form_folder->exportValues();
  534. $work_id = $values['work_id'];
  535. $dir_name = replace_dangerous_char($values['dir_name']);
  536. $dir_name = disable_dangerous_file($dir_name);
  537. $edit_check = false;
  538. $work_data = get_work_data_by_id($work_id);
  539. if (!empty($work_data)) {
  540. $edit_check = true;
  541. } else {
  542. $edit_check = true;
  543. }
  544. if ($edit_check) {
  545. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  546. $expires_query = ' SET expires_on = '."'".($there_is_a_expire_date ? api_get_utc_datetime(get_date_from_group('expires')) : '0000-00-00 00:00:00')."'";
  547. Database::query('UPDATE '.$work_assigment.$expires_query.' WHERE c_id = '.$course_id.' AND id = '."'".$row['has_properties']."'");
  548. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 WHERE c_id = $course_id AND id ='".$row['id']."'";
  549. Database::query($sql_add_publication);
  550. $ends_query = ' SET ends_on = '."'".($there_is_a_end_date ? api_get_utc_datetime(get_date_from_group('ends')) : '0000-00-00 00:00:00')."'";
  551. Database::query('UPDATE '.$work_assigment.$ends_query.' WHERE c_id = '.$course_id.' AND id = '."'".$row['has_properties']."'");
  552. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 WHERE c_id = $course_id AND id ='".$row['id']."'";
  553. Database::query($sql_add_publication);
  554. $qualification_value = isset($_POST['qualification']['qualification']) && !empty($_POST['qualification']['qualification']) ? intval($_POST['qualification']['qualification']) : 0;
  555. $enable_qualification = !empty($qualification_value) ? 1 : 0;
  556. $sql_add_publication = "UPDATE ".$work_assigment." SET enable_qualification = '".$enable_qualification. "' WHERE c_id = $course_id AND publication_id ='".$row['id']."'";
  557. Database::query($sql_add_publication);
  558. $sql = 'UPDATE '.$work_table.' SET
  559. allow_text_assignment = '."'".intval($_POST['allow_text_assignment'])."'".' ,
  560. title = '."'".Database::escape_string($_POST['dir_name'])."'".',
  561. description = '."'".Database::escape_string($_POST['description'])."'".',
  562. qualification = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".',
  563. weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".'
  564. WHERE c_id = '.$course_id.' AND id = '.$row['id'];
  565. Database::query($sql);
  566. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  567. if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1 && !empty($_POST['category_id'])) {
  568. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $row['id'], api_get_session_id());
  569. $link_id = $link_info['id'];
  570. if ($link_info !== false) {
  571. $course_code = api_get_course_id();
  572. Database::query('UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).' SET weight = '."'".Database::escape_string((float)$_POST['weight']['weight'])."'".'
  573. WHERE course_code = "'.$course_code.'" AND id = '.$link_id);
  574. }
  575. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  576. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  577. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
  578. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  579. $resource_name = $_POST['dir_name'];
  580. add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), 3, $row['id'], $resource_name, (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], $_POST['description'], 1, api_get_session_id());
  581. }
  582. update_dir_name($work_data, $dir_name, $values['dir_name']);
  583. $dir = $dir_name;
  584. $display_edit_form = false;
  585. // gets calendar_id from student_publication_assigment
  586. $sql = "SELECT add_to_calendar FROM $work_assigment WHERE c_id = $course_id AND publication_id ='".$row['id']."'";
  587. $res = Database::query($sql);
  588. $calendar_id = Database::fetch_row($res);
  589. $dir_name = sprintf(get_lang('HandingOverOfTaskX'), $dir_name);
  590. $end_date = $row['insert_date'];
  591. if ($_POST['enableExpiryDate'] == '1') {
  592. $end_date = Database::escape_string(api_get_utc_datetime(get_date_from_group('expires')));
  593. }
  594. // update from agenda if it exists
  595. if (!empty($calendar_id[0])) {
  596. $sql = "UPDATE ".$TABLEAGENDA."
  597. SET title='".$values['dir_name']."',
  598. content = '".Database::escape_string($_POST['description'])."',
  599. start_date = '".$end_date."',
  600. end_date = '".$end_date."'
  601. WHERE c_id = $course_id AND id='".$calendar_id[0]."'";
  602. Database::query($sql);
  603. }
  604. Display::display_confirmation_message(get_lang('FolderEdited'));
  605. } else {
  606. Display::display_warning_message(get_lang('FileExists'));
  607. }
  608. }
  609. }
  610. }
  611. $work_data = get_work_data_by_id($work_parent->id);
  612. $action = '';
  613. $row = array();
  614. $class = '';
  615. $cant_files = 0;
  616. $course_id = api_get_course_int_id();
  617. $session_id = api_get_session_id();
  618. if (api_is_allowed_to_edit()) {
  619. $sql_document = "SELECT count(*) FROM $work_table WHERE c_id = $course_id AND parent_id = ".$work_data['id']." AND active IN (0, 1) ";
  620. } else {
  621. $user_filter = "user_id = ".api_get_user_id()." AND ";
  622. if ($course_info['show_score'] == 0) {
  623. $user_filter = null;
  624. }
  625. $sql_document = "SELECT count(*) FROM $work_table s, $iprop_table p
  626. WHERE s.c_id = $course_id AND
  627. p.c_id = $course_id AND
  628. s.id = p.ref AND
  629. p.tool='work' AND
  630. s.accepted='1' AND
  631. $user_filter
  632. parent_id = ".$work_data['id']." AND
  633. active = 1 AND
  634. parent_id = ".$work_parent->id."";
  635. }
  636. //count documents
  637. $res_document = Database::query($sql_document);
  638. $count_document = Database::fetch_row($res_document);
  639. $cant_files = $count_document[0];
  640. $text_file = get_lang('FilesUpload');
  641. if ($cant_files == 1) {
  642. $text_file = api_strtolower(get_lang('FileUpload'));
  643. }
  644. $icon = Display::return_icon('work.png', get_lang('Assignment'), array(), ICON_SIZE_SMALL);
  645. if (!empty($display_edit_form) && !empty($edit_dir) && $edit_dir == $id2) {
  646. $row[] = $icon;
  647. $row[] = '<span class="invisible" style="display:none">'.$dir.'</span>'.$form_folder->toHtml(); // form to edit the directory's name
  648. } else {
  649. $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'">'.$icon.'</a>';
  650. $add_to_name = '';
  651. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  652. $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $id2 , api_get_session_id());
  653. $link_id = $link_info['id'];
  654. $count = 0;
  655. if ($link_info !== false) {
  656. $gradebook_data = get_resource_from_course_gradebook($link_id);
  657. $count = $gradebook_data['weight'];
  658. }
  659. if ($count > 0) {
  660. $add_to_name = Display::label(get_lang('IncludedInEvaluation'), 'info');
  661. } else {
  662. $add_to_name = '';
  663. }
  664. $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']);
  665. //Work name
  666. //if (api_is_allowed_to_edit()) {
  667. if ($cant_files > 0 ) {
  668. $zip = '<a href="downloadfolder.inc.php?id='.$work_data['id'].'">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL).'</a>';
  669. }
  670. //}
  671. $url = $zip.'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&id='.$work_data['id'].'"'.$class.'>'.
  672. $work_title.'</a> '.$add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
  673. $row[] = $url;
  674. }
  675. if ($count_files != 0) {
  676. $row[] = '';
  677. }
  678. if ($direc_date != '' && $direc_date != '0000-00-00 00:00:00') {
  679. $direc_date_local = api_get_local_time($direc_date);
  680. $row[] = date_to_str_ago($direc_date_local).'<br /><span class="dropbox_date">'.api_format_date($direc_date_local).'</span>';
  681. } else {
  682. $direc_date_local = '0000-00-00 00:00:00';
  683. $row[] = '';
  684. }
  685. if ($origin != 'learnpath') {
  686. if ($is_allowed_to_edit) {
  687. if (api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION)) {
  688. $action .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL);
  689. $action .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL);
  690. } else {
  691. $action .= '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2.'">'.Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
  692. $action .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&delete_dir='.$id2.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('DirDelete').'" >'.Display::return_icon('delete.png',get_lang('DirDelete'),'',ICON_SIZE_SMALL).'</a>';
  693. }
  694. $row[] = $action;
  695. } else {
  696. $row[] = '';
  697. }
  698. }
  699. $row[] = $direc_date_local;
  700. $row[] = $work_data['title'];
  701. $table_data[] = $row;
  702. }
  703. }
  704. $sorting_options = array();
  705. $sorting_options['column'] = 1;
  706. // Here we change the way how the colums are going to be sorted
  707. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  708. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  709. $column_order = array();
  710. $i=0;
  711. foreach($table_header as $item) {
  712. $column_order[$i] = $i;
  713. $i++;
  714. }
  715. if (empty($my_folder_data)) {
  716. $column_order[1] = 5;
  717. } else {
  718. $column_order[2] = 2;
  719. }
  720. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  721. $column_show = array();
  722. $column_show[] = 1; // type 0
  723. $column_show[] = 1; // title 1
  724. if (!empty($my_folder_data)) {
  725. $column_show[] = 1; // 2
  726. $column_show[] = 1; // 3
  727. if ($qualification_exists) {
  728. $column_show[] = 1; // 4
  729. }
  730. }
  731. $column_show[] = 1; //date
  732. if ($table_has_actions_column) {
  733. $column_show[] = 1; // modify
  734. }
  735. $column_show[] = 0; //real date in correct format
  736. $paging_options = array();
  737. if (isset($_GET['curdirpath'])) {
  738. $my_params = array ('curdirpath' => Security::remove_XSS($_GET['curdirpath']));
  739. }
  740. $my_params = array ('id' => isset($_GET['id']) ? $_GET['id'] : null);
  741. if (isset($_GET['edit_dir'])) {
  742. $my_params = array ('edit_dir' => intval($_GET['edit_dir']));
  743. }
  744. $my_params['origin'] = $origin;
  745. Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order);
  746. }
  747. /**
  748. * Returns a list of subdirectories found in the given directory.
  749. *
  750. * The list return starts from the given base directory.
  751. * If you require the subdirs of /var/www/ (or /var/www), you will get 'abc/', 'def/', but not '/var/www/abc/'...
  752. * @param string Base dir
  753. * @param integer 0 if we only want dirs from this level, 1 if we want to recurse into subdirs
  754. * @return strings_array The list of subdirs in 'abc/' form, -1 on error, and 0 if none found
  755. * @todo Add a session check to see if subdirs_list doesn't exist yet (cached copy)
  756. */
  757. function get_subdirs_list($basedir = '', $recurse = 0) {
  758. //echo "Looking for subdirs of $basedir";
  759. if (empty($basedir) or !is_dir($basedir)) {
  760. return -1;
  761. }
  762. if (substr($basedir, -1, 1) != '/') {
  763. $basedir = $basedir.'/';
  764. }
  765. $dirs_list = array();
  766. $dh = opendir($basedir);
  767. while ($entry = readdir($dh)) {
  768. $entry = replace_dangerous_char($entry);
  769. $entry = disable_dangerous_file($entry);
  770. if (is_dir($basedir.$entry) && $entry != '..' && $entry != '.') {
  771. $dirs_list[] = $entry;
  772. if ($recurse == 1) {
  773. foreach (get_subdirs_list($basedir.$entry) as $subdir) {
  774. $dirs_list[] = $entry.'/'.$subdir;
  775. }
  776. }
  777. }
  778. }
  779. closedir($dh);
  780. return $dirs_list;
  781. }
  782. /**
  783. * Builds the form thats enables the user to
  784. * select a directory to browse/upload in
  785. * This function has been copied from the document/document.inc.php library
  786. *
  787. * @param array $folders
  788. * @param string $curdirpath
  789. * @param string $group_dir
  790. * @return string html form
  791. */
  792. // TODO: This function is a candidate for removal, it is not used anywhere.
  793. function build_work_directory_selector($folders, $curdirpath, $group_dir = '') {
  794. $form = '<form name="selector" action="'.api_get_self().'?'.api_get_cidreq().'" method="POST">'."\n";
  795. $form .= get_lang('CurrentDirectory').' <select name="curdirpath" onchange="javascript: document.selector.submit();">'."\n";
  796. //group documents cannot be uploaded in the root
  797. if ($group_dir == '') {
  798. $form .= '<option value="/">/ ('.get_lang('Root').')</option>';
  799. if (is_array($folders)) {
  800. foreach ($folders as $folder) {
  801. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  802. $form .= '<option'.$selected.' value="'.$folder.'">'.$folder.'</option>'."\n";
  803. }
  804. }
  805. } else {
  806. foreach ($folders as $folder) {
  807. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  808. $display_folder = substr($folder, strlen($group_dir));
  809. $display_folder = ($display_folder == '') ? '/ ('.get_lang('Root').')' : $display_folder;
  810. $form .= '<option'.$selected.' value="'.$folder.'">'.$display_folder.'</option>'."\n";
  811. }
  812. }
  813. $form .= '</select>'."\n";
  814. $form .= '<noscript><input type="submit" name="change_path" value="'.get_lang('Ok').'" /></noscript>'."\n";
  815. $form .= '</form>';
  816. return $form;
  817. }
  818. /**
  819. * Builds the form thats enables the user to
  820. * move a document from one directory to another
  821. * This function has been copied from the document/document.inc.php library
  822. *
  823. * @param array $folders
  824. * @param string $curdirpath
  825. * @param string $move_file
  826. * @return string html form
  827. */
  828. function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
  829. $course_id = api_get_course_int_id();
  830. $move_file = intval($move_file);
  831. $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  832. $sql = "SELECT title FROM $tbl_work WHERE c_id = $course_id AND id ='".$move_file."'";
  833. $result = Database::query($sql);
  834. $title = Database::fetch_row($result);
  835. global $gradebook;
  836. //@todo use formvalidator please!
  837. $form = '<form class="form-horizontal" name="move_to_form" action="'.api_get_self().'?gradebook='.$gradebook.'&curdirpath='.Security::remove_XSS($curdirpath).'" method="POST">';
  838. $form .= '<legend>'.get_lang('MoveFile').' - '.Security::remove_XSS($title[0]).'</legend>';
  839. $form .= '<input type="hidden" name="item_id" value="'.$move_file.'" />';
  840. $form .= '<input type="hidden" name="action" value="move_to" />';
  841. $form .= '<div class="control-group">
  842. <label>
  843. <span class="form_required">*</span>'.get_lang('Select').'
  844. </label>
  845. <div class="controls">';
  846. $form .= ' <select name="move_to_id">';
  847. //group documents cannot be uploaded in the root
  848. if ($group_dir == '') {
  849. if ($curdirpath != '/') {
  850. //$form .= '<option value="0">/ ('.get_lang('Root').')</option>';
  851. }
  852. if (is_array($folders)) {
  853. foreach ($folders as $fid => $folder) {
  854. //you cannot move a file to:
  855. //1. current directory
  856. //2. inside the folder you want to move
  857. //3. inside a subfolder of the folder you want to move
  858. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  859. $form .= '<option value="'.$fid.'">'.$folder.'</option>';
  860. }
  861. }
  862. }
  863. } else {
  864. if ($curdirpath != '/') {
  865. $form .= '<option value="0">/ ('.get_lang('Root').')</option>';
  866. }
  867. foreach ($folders as $fid => $folder) {
  868. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  869. //cannot copy dir into his own subdir
  870. $display_folder = substr($folder, strlen($group_dir));
  871. $display_folder = ($display_folder == '') ? '/ ('.get_lang('Root').')' : $display_folder;
  872. $form .= '<option value="'.$fid.'">'.$display_folder.'</option>'."\n";
  873. }
  874. }
  875. }
  876. $form .= '</select>';
  877. $form .= ' </div>
  878. </div>';
  879. $form .= '<div class="control-group">
  880. <div class="controls">
  881. <button type="submit" class="save" name="move_file_submit">'.get_lang('MoveFile').'</button>
  882. </div>
  883. </div>';
  884. $form .= '</form>';
  885. $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  886. return $form;
  887. }
  888. /**
  889. * Checks if the first given directory exists as a subdir of the second given directory
  890. * This function should now be deprecated by Security::check_abs_path()
  891. * @param string Subdir
  892. * @param string Base dir
  893. * @return integer -1 on error, 0 if not subdir, 1 if subdir
  894. */
  895. // TODO: This function is a candidate for removal, it is not used anywhere.
  896. function is_subdir_of($subdir, $basedir) {
  897. if (empty($subdir) or empty($basedir)) {
  898. return -1;
  899. }
  900. if (substr($basedir, -1, 1) != '/') {
  901. $basedir = $basedir.'/';
  902. }
  903. if (substr($subdir, 0, 1) == '/') {
  904. $subdir = substr($subdir, 1);
  905. }
  906. return is_dir($basedir.$subdir) ? 1 : 0;
  907. }
  908. /**
  909. * creates a new directory trying to find a directory name
  910. * that doesn't already exist
  911. * (we could use unique_name() here...)
  912. *
  913. * @author Hugues Peeters <hugues.peeters@claroline.net>
  914. * @author Bert Vanderkimpen
  915. * @author Yannick Warnier <ywarnier@beeznest.org> Adaptation for work tool
  916. * @param string Base work dir (.../work)
  917. * @param string $desiredDirName complete path of the desired name
  918. * @return string actual directory name if it succeeds, boolean false otherwise
  919. */
  920. function create_unexisting_work_directory($base_work_dir, $desired_dir_name) {
  921. $nb = '';
  922. $base_work_dir = (substr($base_work_dir, -1, 1) == '/' ? $base_work_dir : $base_work_dir.'/');
  923. while (file_exists($base_work_dir.$desired_dir_name.$nb)) {
  924. $nb += 1;
  925. }
  926. if (@mkdir($base_work_dir.$desired_dir_name.$nb, api_get_permissions_for_new_directories())) {
  927. return $desired_dir_name.$nb;
  928. } else {
  929. return false;
  930. }
  931. }
  932. /**
  933. * Delete a work-tool directory
  934. * @param string Base "work" directory for this course as /var/www/chamilo/courses/ABCD/work/
  935. * @param string The directory name as the bit after "work/", without trailing slash
  936. * @return integer -1 on error
  937. */
  938. function del_dir($id) {
  939. global $_course;
  940. $id = intval($id);
  941. $work_data = get_work_data_by_id($id);
  942. if (empty($work_data)) {
  943. return false;
  944. }
  945. $base_work_dir = api_get_path(SYS_COURSE_PATH) .$_course['path'].'/work';
  946. $work_data_url = $base_work_dir.$work_data['url'];
  947. $check = Security::check_abs_path($work_data_url.'/', $base_work_dir.'/');
  948. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  949. $course_id = api_get_course_int_id();
  950. if (!empty($work_data['url'])) {
  951. //Deleting all contents inside the folder
  952. //@todo replace to parent_id
  953. $sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND filetype = 'folder' AND id = $id";
  954. $res = Database::query($sql);
  955. $sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND parent_id = $id";
  956. $res = Database::query($sql);
  957. if ($check) {
  958. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  959. $new_dir = $work_data_url.'_DELETED_'.$id;
  960. if (api_get_setting('permanently_remove_deleted_files') == 'true'){
  961. my_delete($work_data_url);
  962. } else {
  963. if (file_exists($work_data_url)) {
  964. rename($work_data_url, $new_dir);
  965. }
  966. }
  967. }
  968. }
  969. }
  970. /**
  971. * Get the path of a document in the student_publication table (path relative to the course directory)
  972. * @param integer Element ID
  973. * @return string Path (or -1 on error)
  974. */
  975. function get_work_path($id) {
  976. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  977. $course_id = api_get_course_int_id();
  978. $sql = 'SELECT url FROM '.$table.' WHERE c_id = '.$course_id.' AND id='.intval($id);
  979. $res = Database::query($sql);
  980. if (Database::num_rows($res)) {
  981. $row = Database::fetch_array($res);
  982. return $row['url'];
  983. }
  984. return -1;
  985. }
  986. /**
  987. * Update the url of a work in the student_publication table
  988. * @param integer ID of the work to update
  989. * @param string Destination directory where the work has been moved (must end with a '/')
  990. * @return -1 on error, sql query result on success
  991. */
  992. function update_work_url($id, $new_path, $parent_id) {
  993. if (empty($id)) return -1;
  994. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  995. $course_id = api_get_course_int_id();
  996. $id = intval($id);
  997. $parent_id = intval($parent_id);
  998. $sql = "SELECT * FROM $table WHERE c_id = $course_id AND id = $id";
  999. $res = Database::query($sql);
  1000. if (Database::num_rows($res) != 1) {
  1001. return -1;
  1002. } else {
  1003. $row = Database::fetch_array($res);
  1004. $filename = basename($row['url']);
  1005. $new_url = $new_path .$filename;
  1006. $sql2 = "UPDATE $table SET url = '$new_url', parent_id = '$parent_id' WHERE c_id = $course_id AND id = $id";
  1007. $res2 = Database::query($sql2);
  1008. return $res2;
  1009. }
  1010. }
  1011. /**
  1012. * Update the url of a dir in the student_publication table
  1013. * @param string old path
  1014. * @param string new path
  1015. */
  1016. function update_dir_name($work_data, $new_name, $title) {
  1017. $course_id = api_get_course_int_id();
  1018. $work_id = intval($work_data['id']);
  1019. $path = $work_data['url'];
  1020. if ($work_data['title'] == $title) {
  1021. return true;
  1022. }
  1023. $title = Database::escape_string($title);
  1024. if (!empty($new_name)) {
  1025. global $base_work_dir;
  1026. $new_name = Security::remove_XSS($new_name);
  1027. $new_name = replace_dangerous_char($new_name);
  1028. $new_name = disable_dangerous_file($new_name);
  1029. my_rename($base_work_dir.'/'.$path, $new_name);
  1030. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1031. //update all the files in the other directories according with the next query
  1032. $sql = "SELECT id, url FROM $table WHERE c_id = $course_id AND parent_id = $work_id"; // like binary (Case Sensitive)
  1033. $rs = Database::query($sql);
  1034. $work_len = strlen('work/'.$path);
  1035. while ($work = Database :: fetch_array($rs)) {
  1036. $new_dir = $work['url'];
  1037. $name_with_directory = substr($new_dir, $work_len, strlen($new_dir));
  1038. $name = Database::escape_string('work/'.$new_name.'/'.$name_with_directory);
  1039. $sql = 'UPDATE '.$table.' SET url= "'.$name.'" WHERE c_id = '.$course_id.' AND id= '.$work['id'];
  1040. Database::query($sql);
  1041. }
  1042. $sql = "UPDATE $table SET url= '/".$new_name."' , title = '".$title."' WHERE c_id = $course_id AND id = $work_id";
  1043. Database::query($sql);
  1044. }
  1045. }
  1046. /**
  1047. * Return an array with all the folder's ids that are in the given path
  1048. * @param string Path of the directory
  1049. * @return array The list of ids of all the directories in the path
  1050. * @author Julio Montoya Dokeos
  1051. * @version April 2008
  1052. */
  1053. function get_parent_directories($id) {
  1054. $course_id = api_get_course_int_id();
  1055. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1056. $id = intval($id);
  1057. $sql = "SELECT id FROM $work_table WHERE c_id = $course_id AND parent_id = $id";
  1058. $result = Database::query($sql);
  1059. $list_id = array();
  1060. if (Database::num_rows($result)) {
  1061. while ($row = Database::fetch_array($result)) {
  1062. $list_id[] = $row['id'];
  1063. }
  1064. }
  1065. return $list_id;
  1066. }
  1067. /**
  1068. * Transform an all directory structure (only directories) in an array
  1069. * @param string path of the directory
  1070. * @return array the directory structure into an array
  1071. * @author Julio Montoya Dokeos
  1072. * @version April 2008
  1073. */
  1074. function directory_to_array($directory) {
  1075. $array_items = array();
  1076. if ($handle = @opendir($directory)) {
  1077. while (false !== ($file = readdir($handle))) {
  1078. if ($file != '.' && $file != '..') {
  1079. if (is_dir($directory. '/' . $file)) {
  1080. $array_items = array_merge($array_items, directory_to_array($directory. '/' . $file));
  1081. $file = $directory . '/' . $file;
  1082. $array_items[] = preg_replace("/\/\//si", '/', $file);
  1083. }
  1084. }
  1085. }
  1086. closedir($handle);
  1087. }
  1088. return $array_items;
  1089. }
  1090. /**
  1091. * Insert into the DB of the course all the directories
  1092. * @param string path of the /work directory of the course
  1093. * @return -1 on error, sql query result on success
  1094. * @author Julio Montoya Dokeos
  1095. * @version April 2008
  1096. */
  1097. function insert_all_directory_in_course_table($base_work_dir) {
  1098. $dir_to_array = directory_to_array($base_work_dir, true);
  1099. $only_dir = array();
  1100. for ($i = 0; $i < count($dir_to_array); $i++) {
  1101. $only_dir[] = substr($dir_to_array[$i], strlen($base_work_dir), strlen($dir_to_array[$i]));
  1102. }
  1103. $course_id = api_get_course_int_id();
  1104. $group_id = api_get_group_id();
  1105. for($i = 0; $i < count($only_dir); $i++) {
  1106. global $work_table;
  1107. $sql_insert_all= "INSERT INTO " . $work_table . " SET
  1108. c_id = '$course_id',
  1109. url = '" . $only_dir[$i] . "',
  1110. title = '',
  1111. description = '',
  1112. author = '',
  1113. active = '0',
  1114. accepted = '1',
  1115. filetype = 'folder',
  1116. post_group_id = '".$group_id."',
  1117. sent_date = '0000-00-00 00:00:00' ";
  1118. Database::query($sql_insert_all);
  1119. }
  1120. }
  1121. /**
  1122. * This function displays the number of files contained in a directory
  1123. *
  1124. * @param string the path of the directory
  1125. * @param boolean true if we want the total quantity of files include in others child directorys , false only files in the directory
  1126. * @return array the first element is an integer with the number of files in the folder, the second element is the number of directories
  1127. * @author Julio Montoya Dokeos
  1128. * @version April 2008
  1129. */
  1130. function count_dir($path_dir, $recurse) {
  1131. $count = 0;
  1132. $count_dir = 0;
  1133. $d = dir($path_dir);
  1134. while ($entry = $d->Read()) {
  1135. if (!(($entry == '..') || ($entry == '.'))) {
  1136. if (is_dir($path_dir.'/'.$entry)) {
  1137. $count_dir++;
  1138. if ($recurse) {
  1139. $count += count_dir($path_dir . '/' . $entry, $recurse);
  1140. }
  1141. } else {
  1142. $count++;
  1143. }
  1144. }
  1145. }
  1146. $return_array = array();
  1147. $return_array[] = $count;
  1148. $return_array[] = $count_dir;
  1149. return $return_array;
  1150. }
  1151. /**
  1152. * returns all the javascript that is required for easily
  1153. * validation when you create a work
  1154. * this goes into the $htmlHeadXtra[] array
  1155. */
  1156. function to_javascript_work() {
  1157. $origin = isset($_REQUEST['origin']) && !empty($_REQUEST['origin']) ? api_get_tools_lists($_REQUEST['origin']) : '';
  1158. $js = '<script>
  1159. function plus() {
  1160. if(document.getElementById(\'options\').style.display == \'none\') {
  1161. document.getElementById(\'options\').style.display = \'block\';
  1162. document.getElementById(\'plus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide', ''), array('style' => 'vertical-align:middle')).'&nbsp;'.addslashes(get_lang('AdvancedParameters', '')).'\';
  1163. } else {
  1164. document.getElementById(\'options\').style.display = \'none\';
  1165. document.getElementById(\'plus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show', ''), array('style' => 'vertical-align:middle')).'&nbsp;'.addslashes(get_lang('AdvancedParameters', '')).'\';
  1166. }
  1167. }
  1168. function updateDocumentTitle(value) {
  1169. var temp = value.indexOf("/");
  1170. //linux path
  1171. if(temp!=-1){
  1172. var temp=value.split("/");
  1173. } else {
  1174. var temp=value.split("\\\");
  1175. }
  1176. document.getElementById("file_upload").value=temp[temp.length-1];
  1177. $("#contains_file_id").attr("checked", true);
  1178. }
  1179. function checkDate(month, day, year) {
  1180. var monthLength =
  1181. new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  1182. if (!day || !month || !year)
  1183. return false;
  1184. // check for bisestile year
  1185. if (year/4 == parseInt(year/4))
  1186. monthLength[1] = 29;
  1187. if (month < 1 || month > 12)
  1188. return false;
  1189. if (day > monthLength[month-1])
  1190. return false;
  1191. return true;
  1192. }
  1193. function mktime() {
  1194. var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
  1195. d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  1196. var dateManip = {
  1197. 0: function(tt){ return d.setHours(tt); },
  1198. 1: function(tt){ return d.setMinutes(tt); },
  1199. 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
  1200. 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
  1201. 4: function(tt){ return d.setDate(tt+mb); },
  1202. 5: function(tt){ return d.setYear(tt+ma); }
  1203. };
  1204. for( i = 0; i < argc; i++ ){
  1205. no = parseInt(argv[i]*1);
  1206. if (isNaN(no)) {
  1207. return false;
  1208. } else {
  1209. // arg is number, lets manipulate date object
  1210. if(!dateManip[i](no)){
  1211. // failed
  1212. return false;
  1213. }
  1214. }
  1215. }
  1216. return Math.floor(d.getTime()/1000);
  1217. }
  1218. function validate() {
  1219. var expires_day = document.form1.expires_day.value;
  1220. var expires_month = document.form1.expires_month.value;
  1221. var expires_year = document.form1.expires_year.value;
  1222. var expires_hour = document.form1.expires_hour.value;
  1223. var expires_minute = document.form1.expires_minute.value;
  1224. var expires_date = mktime(expires_hour,expires_minute,0,expires_month,expires_day,expires_year)
  1225. var ends_day = document.form1.ends_day.value;
  1226. var ends_month = document.form1.ends_month.value;
  1227. var ends_year = document.form1.ends_year.value;
  1228. var ends_hour = document.form1.ends_hour.value;
  1229. var ends_minute = document.form1.ends_minute.value;
  1230. var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year);
  1231. var new_dir = document.form1.new_dir.value;
  1232. msg_id1 = document.getElementById("msg_error1");
  1233. msg_id2 = document.getElementById("msg_error2");
  1234. msg_id3 = document.getElementById("msg_error3");
  1235. msg_id4 = document.getElementById("msg_error4");
  1236. msg_id5 = document.getElementById("msg_error_weight");
  1237. if(new_dir=="") {
  1238. msg_id1.style.display ="block";
  1239. msg_id1.innerHTML="'.get_lang('FieldRequired', '').'";
  1240. msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1241. } else if(document.form1.type1.checked && document.form1.type2.checked && expires_date > ends_date) {
  1242. msg_id2.style.display ="block";
  1243. msg_id2.innerHTML="'.get_lang('EndDateCannotBeBeforeTheExpireDate', '').'";
  1244. msg_id1.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1245. } else if (!checkDate(expires_month,expires_day,expires_year)) {
  1246. msg_id3.style.display ="block";
  1247. msg_id3.innerHTML="'.get_lang('InvalidDate', '').'";
  1248. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1249. } else if (!checkDate(ends_month,ends_day,ends_year)) {
  1250. msg_id4.style.display ="block";
  1251. msg_id4.innerHTML="'.get_lang('InvalidDate', '').'";
  1252. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id5.innerHTML="";
  1253. } else {
  1254. if (document.form1.make_calification.checked) {
  1255. var weight = document.form1.weight.value;
  1256. if(weight=="") {
  1257. msg_id5.style.display ="block";
  1258. msg_id5.innerHTML="'.get_lang('WeightNecessary', '').'";
  1259. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";
  1260. return false;
  1261. }
  1262. }
  1263. document.form1.action = "work.php?'. api_get_cidreq().'&origin='.$origin.'&gradebook='.(empty($_GET['gradebook'])?'':'view').'";
  1264. document.form1.submit();
  1265. }
  1266. }
  1267. </script>';
  1268. return $js;
  1269. }
  1270. /**
  1271. * Gets the id of a student publication with a given path
  1272. * @param string $path
  1273. * @return true if is found / false if not found
  1274. */
  1275. // TODO: The name of this function does not fit with the kind of information it returns. Maybe check_work_id() or is_work_id()?
  1276. function get_work_id($path) {
  1277. $TBL_STUDENT_PUBLICATION = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  1278. $TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1279. $course_id = api_get_course_int_id();
  1280. if (api_is_allowed_to_edit()) {
  1281. $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work, $TBL_PROP_TABLE AS props
  1282. WHERE props.c_id = $course_id AND work.c_id = $course_id AND props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2'";
  1283. } else {
  1284. $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props
  1285. WHERE props.c_id = $course_id AND work.c_id = $course_id AND 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()."'";
  1286. }
  1287. $result = Database::query($sql);
  1288. $num_rows = Database::num_rows($result);
  1289. if ($result && $num_rows > 0) {
  1290. return true;
  1291. } else {
  1292. return false;
  1293. }
  1294. }
  1295. function get_count_work($work_id) {
  1296. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1297. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1298. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  1299. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  1300. $session_id = api_get_session_id();
  1301. $condition_session = api_get_session_condition($session_id);
  1302. $course_id = api_get_course_int_id();
  1303. $group_id = api_get_group_id();
  1304. $course_info = api_get_course_info(api_get_course_id());
  1305. $work_id = intval($work_id);
  1306. if (!empty($group_id)) {
  1307. $extra_conditions = " work.post_group_id = '".intval($group_id)."' "; // set to select only messages posted by the user's group
  1308. } else {
  1309. $extra_conditions = " work.post_group_id = '0' ";
  1310. }
  1311. if ($is_allowed_to_edit) {
  1312. $extra_conditions .= ' AND work.active IN (0, 1) ';
  1313. } else {
  1314. $extra_conditions .= ' AND work.active = 1 AND accepted = 1';
  1315. if (isset($course_info['show_score']) && $course_info['show_score'] == 1) {
  1316. $extra_conditions .= " AND work.user_id = ".api_get_user_id()." ";
  1317. } else {
  1318. $extra_conditions .= '';
  1319. }
  1320. }
  1321. $extra_conditions .= " AND parent_id = ".$work_id." ";
  1322. $sql = "SELECT count(*) as count
  1323. FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id AND prop.c_id = $course_id AND work.c_id = $course_id )
  1324. INNER JOIN $user_table u ON (work.user_id = u.user_id)
  1325. WHERE $extra_conditions $where_condition $condition_session ";
  1326. $result = Database::query($sql);
  1327. $users_with_work = 0;
  1328. if (Database::num_rows($result)) {
  1329. $result = Database::fetch_array($result);
  1330. $users_with_work = $result['count'];
  1331. }
  1332. return $users_with_work;
  1333. }
  1334. function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition) {
  1335. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1336. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1337. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  1338. $session_id = api_get_session_id();
  1339. $course_id = api_get_course_int_id();
  1340. $group_id = api_get_group_id();
  1341. $course_info = api_get_course_info(api_get_course_id());
  1342. $work_id = intval($work_id);
  1343. $column = empty($column) ? : Database::escape_string($column);
  1344. $start = intval($start);
  1345. $limit = intval($limit);
  1346. if (!in_array($direction, array('asc','desc'))) {
  1347. $direction = 'desc';
  1348. }
  1349. $work_data = get_work_data_by_id($work_id);
  1350. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  1351. $condition_session = api_get_session_condition($session_id);
  1352. $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION);
  1353. if (!empty($work_data)) {
  1354. if (!empty($group_id)) {
  1355. $extra_conditions = " work.post_group_id = '".intval($group_id)."' "; // set to select only messages posted by the user's group
  1356. } else {
  1357. $extra_conditions = " work.post_group_id = '0' ";
  1358. }
  1359. if ($is_allowed_to_edit) {
  1360. $extra_conditions .= ' AND work.active IN (0, 1) ';
  1361. } else {
  1362. $extra_conditions .= ' AND work.active IN (1) ';
  1363. if (isset($course_info['show_score']) && $course_info['show_score'] == 1) {
  1364. $extra_conditions .= " AND u.user_id = ".api_get_user_id()." ";
  1365. } else {
  1366. $extra_conditions .= '';
  1367. }
  1368. }
  1369. $extra_conditions .= " AND parent_id = ".$work_id." ";
  1370. $select = 'DISTINCT work.id as id, title as file, url, sent_date, contains_file, has_properties, view_properties,
  1371. qualification, weight, allow_text_assignment, u.firstname, u.lastname, u.username, parent_id, accepted, qualificator_id';
  1372. $user_condition = "INNER JOIN $user_table u ON (work.user_id = u.user_id) ";
  1373. $work_condition = "$iprop_table prop INNER JOIN $work_table work ON (prop.ref = work.id AND prop.c_id = $course_id AND work.c_id = $course_id ) ";
  1374. $work_assignment = get_work_assignment_by_id($work_id);
  1375. $sql = "SELECT $select
  1376. FROM $work_condition $user_condition $course_conditions
  1377. WHERE $extra_conditions $where_condition $condition_session ";
  1378. $sql .= " ORDER BY $column $direction ";
  1379. $sql .= " LIMIT $start, $limit";
  1380. $result = Database::query($sql);
  1381. $works = array();
  1382. while ($work = Database::fetch_array($result, 'ASSOC')) {
  1383. //var_dump($work);
  1384. $item_id = $work['id'];
  1385. //Get the author ID for that document from the item_property table
  1386. $is_author = false;
  1387. $can_read = false;
  1388. $item_property_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_id, api_get_session_id());
  1389. if (!$is_allowed_to_edit && $item_property_data['insert_user_id'] == api_get_user_id()) {
  1390. $is_author = true;
  1391. }
  1392. if ($course_info['show_score'] == 0 ) {
  1393. $can_read = true;
  1394. }
  1395. if ($work['accepted'] == '0') {
  1396. $class = 'invisible';
  1397. } else {
  1398. $class = '';
  1399. }
  1400. $qualification_exists = false;
  1401. if (!empty($work_data['qualification']) && intval($work_data['qualification']) > 0) {
  1402. $qualification_exists = true;
  1403. }
  1404. $qualification_string = '';
  1405. if ($qualification_exists) {
  1406. if ($work['qualification'] == '') {
  1407. $qualification_string = Display::label('-');
  1408. } else {
  1409. $qualification_string = Display::label($work['qualification'], 'info');
  1410. }
  1411. }
  1412. $add_string = '';
  1413. $time_expires = api_strtotime($work['expires_on'], 'UTC');
  1414. if (!empty($work_assignment['expires_on']) && $work_assignment['expires_on'] != '0000-00-00 00:00:00' && $time_expires && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) {
  1415. $add_string = Display::label(get_lang('Expired'),'important');
  1416. }
  1417. if (($can_read && $work['accepted'] == '1') || ($is_author && $work['accepted'] == '1') || $is_allowed_to_edit) {
  1418. //Firstname, lastname, username
  1419. $work['firstname'] = Display::div($work['firstname'], array('class' => $class));
  1420. $work['lastname'] = Display::div($work['lastname'], array('class' => $class));
  1421. $work['username'] = Display::div($work['username'], array('class' => $class));
  1422. //Type
  1423. $work['type'] = build_document_icon_tag('file', $work['file']);
  1424. //File name
  1425. $link_to_download = null;
  1426. if ($work['contains_file']) {
  1427. $link_to_download = '<a href="download.php?id='.$item_id.'">'.Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> ';
  1428. } else {
  1429. $link_to_download = '<a href="view.php?id='.$item_id.'">'.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';
  1430. }
  1431. $send_to = Portfolio::share('work', $work['id'], array('style' => 'white-space:nowrap;'));
  1432. $work['qualification'] = $qualification_string;
  1433. //Date
  1434. $work_date = api_convert_and_format_date($work['sent_date']);
  1435. $work['sent_date'] = date_to_str_ago(api_get_local_time($work['sent_date'])).' '.$add_string.'<br />'.$work_date;
  1436. //Actions
  1437. $url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&id='.$work_id.'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']);
  1438. $action = '';
  1439. if ($is_allowed_to_edit) {
  1440. if ($locked) {
  1441. if ($qualification_exists) {
  1442. $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'),array(), ICON_SIZE_SMALL);
  1443. } else {
  1444. $action .= Display::return_icon('edit_na.png', get_lang('Comment'),array(), ICON_SIZE_SMALL);
  1445. }
  1446. } else {
  1447. if ($qualification_exists) {
  1448. $action .= '<a href="'.$url.'&amp;action=edit&item_id='.$item_id.'&amp;parent_id='.$work['parent_id'].'" title="'.get_lang('Modify').'" >'.
  1449. Display::return_icon('rate_work.png', get_lang('CorrectAndRate'),array(), ICON_SIZE_SMALL).'</a>';
  1450. } else {
  1451. $action .= '<a href="'.$url.'&amp;action=edit&item_id='.$item_id.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&amp;parent_id='.$work['parent_id'].'" title="'.get_lang('Modify').'" >'.
  1452. Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).'</a>';
  1453. }
  1454. }
  1455. if ($work['contains_file']) {
  1456. if ($locked) {
  1457. $action .= Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL);
  1458. } else {
  1459. $action .= '<a href="'.$url.'&amp;action=move&item_id='.$item_id.'" title="'.get_lang('Move').'">'.Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
  1460. }
  1461. }
  1462. if ($work['accepted'] == '1') {
  1463. $action .= '<a href="'.$url.'&amp;action=make_invisible&item_id='.$item_id.'&amp;'.$sort_params.'" title="'.get_lang('Invisible').'" >'.Display::return_icon('visible.png', get_lang('Invisible'),array(), ICON_SIZE_SMALL).'</a>';
  1464. } else {
  1465. $action .= '<a href="'.$url.'&amp;action=make_visible&item_id='.$item_id.'&amp;'.$sort_params.'" title="'.get_lang('Visible').'" >'.Display::return_icon('invisible.png', get_lang('Visible'),array(), ICON_SIZE_SMALL).'</a> ';
  1466. }
  1467. if ($locked) {
  1468. $action .= Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
  1469. } else {
  1470. $action .= '<a href="'.$url.'&amp;action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'" >'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  1471. }
  1472. } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) {
  1473. if (api_is_allowed_to_session_edit(false, true)) {
  1474. $action .= '<a href="'.$url.'&amp;action=edit&item_id='.$item_id.'" title="'.get_lang('Modify').'" >'.Display::return_icon('edit.png', get_lang('Modify'),array(), ICON_SIZE_SMALL).'</a>';
  1475. } else {
  1476. $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
  1477. }
  1478. if (api_get_course_setting('student_delete_own_publication') == 1) {
  1479. $action .= '<a href="'.$url.'&amp;action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'" >'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  1480. }
  1481. } else {
  1482. $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
  1483. }
  1484. //Status
  1485. if (empty($work['qualificator_id'])) {
  1486. $qualificator_id = Display::label(get_lang('NotRevised'), 'warning');
  1487. } else {
  1488. $qualificator_id = Display::label(get_lang('Revised'), 'success');
  1489. }
  1490. $work['qualificator_id'] = $qualificator_id;
  1491. $work['actions'] = $send_to.$link_to_download.$action;
  1492. $works[] = $work;
  1493. }
  1494. }
  1495. return $works;
  1496. }
  1497. }
  1498. /**
  1499. * Send reminder to users who have not given the task
  1500. *
  1501. * @param int
  1502. * @return array
  1503. * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
  1504. */
  1505. function send_reminder_users_without_publication($task_data) {
  1506. global $_course;
  1507. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1508. $task_id = $task_data['id'];
  1509. $task_title = !empty($task_data['title']) ? $task_data['title'] : basename($task_data['url']);
  1510. $subject = '[' . api_get_setting('siteName') . '] ';
  1511. // The body can be as long as you wish, and any combination of text and variables
  1512. $content = get_lang('ReminderToSubmitPendingTask')."\n".get_lang('CourseName').' : '.$_course['name']."\n";
  1513. $content .= get_lang('WorkName').' : '.$task_title."\n";
  1514. $list_users = get_list_users_without_publication($task_id);
  1515. $mails_sent_to = array();
  1516. foreach ($list_users as $user) {
  1517. $name_user = api_get_person_name($user[1], $user[0], null, PERSON_NAME_EMAIL_ADDRESS);
  1518. $dear_line = get_lang('Dear')." ".api_get_person_name($user[1], $user[0]) .", \n\n";
  1519. $body = $dear_line.$content;
  1520. api_mail($name_user, $user[3], $subject, $body, $sender_name, $email_admin);
  1521. $mails_sent_to[] = $name_user;
  1522. }
  1523. return $mails_sent_to;
  1524. }
  1525. /**
  1526. * Sends an email to the students of a course when a homework is created
  1527. *
  1528. * @param string course_id
  1529. *
  1530. * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
  1531. * @author Julio Montoya <gugli100@gmail.com> Adding session support - 2011
  1532. */
  1533. function send_email_on_homework_creation($course_id) {
  1534. // Get the students of the course
  1535. $session_id = api_get_session_id();
  1536. if (empty($session_id)) {
  1537. $students = CourseManager::get_student_list_from_course_code($course_id);
  1538. } else {
  1539. $students = CourseManager::get_student_list_from_course_code($course_id, true, $session_id);
  1540. }
  1541. $emailsubject = '[' . api_get_setting('siteName') . '] '.get_lang('HomeworkCreated');
  1542. $currentUser = api_get_user_info(api_get_user_id());
  1543. if (!empty($students)) {
  1544. foreach($students as $student) {
  1545. $user_info = api_get_user_info($student["user_id"]);
  1546. if(!empty($user_info["mail"])) {
  1547. $name_user = api_get_person_name($user_info["firstname"], $user_info["lastname"], null, PERSON_NAME_EMAIL_ADDRESS);
  1548. $emailbody = get_lang('Dear')." ".$name_user.",\n\n";
  1549. $emailbody .= get_lang('HomeworkHasBeenCreatedForTheCourse')." ".$course_id.". "."\n\n".get_lang('PleaseCheckHomeworkPage');
  1550. $emailbody .= "\n\n".api_get_person_name($currentUser["firstname"], $currentUser["lastname"]);
  1551. @api_mail($name_user, $user_info["mail"], $emailsubject, $emailbody, api_get_person_name($currentUser["firstname"], $currentUser["lastname"], null, PERSON_NAME_EMAIL_ADDRESS), $currentUser["mail"]);
  1552. }
  1553. }
  1554. }
  1555. }
  1556. function is_work_exist_by_url($url) {
  1557. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1558. $url = Database::escape_string($url);
  1559. $sql = "SELECT id FROM $work_table WHERE url='$url'";
  1560. $result = Database::query($sql);
  1561. if (Database::num_rows($result)> 0) {
  1562. $row = Database::fetch_row($result);
  1563. if (empty($row)) {
  1564. return false;
  1565. } else {
  1566. return true;
  1567. }
  1568. } else {
  1569. return false;
  1570. }
  1571. }
  1572. function make_select($name, $values, $checked = '') {
  1573. $output = '<select name="'.$name.'" id="'.$name.'">';
  1574. foreach($values as $key => $value) {
  1575. $output .= '<option value="'.$key.'" '.(($checked==$key) ? 'selected="selected"' : '').'>'.$value.'</option>';
  1576. }
  1577. $output .= '</select>';
  1578. return $output;
  1579. }
  1580. function make_checkbox($name, $checked = '', $label = null) {
  1581. $check = '<input id ="'.$name.'" type="checkbox" value="1" name="'.$name.'" '.((!empty($checked))?'checked="checked"':'').'/>';
  1582. if (!empty($label)) {
  1583. $check .="<label for ='$name'>$label</label>";
  1584. }
  1585. return $check;
  1586. }
  1587. function draw_date_picker($prefix, $default = '') {
  1588. if (empty($default)) {
  1589. $default = api_get_local_time();
  1590. }
  1591. $parts = explode(' ', $default);
  1592. list($d_year, $d_month, $d_day) = explode('-', $parts[0]);
  1593. list($d_hour, $d_minute) = explode(':', $parts[1]);
  1594. $minute = range(10, 59);
  1595. array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09');
  1596. $date_form = make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day);
  1597. $date_form .= make_select($prefix.'_month', array_combine(range(1, 12), api_get_months_long()), $d_month);
  1598. $date_form .= make_select($prefix.'_year', array($d_year => $d_year, $d_year + 1 => $d_year + 1), $d_year).'&nbsp;&nbsp;&nbsp;&nbsp;';
  1599. $date_form .= make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : ';
  1600. $date_form .= make_select($prefix.'_minute', $minute, $d_minute);
  1601. return $date_form;
  1602. }
  1603. function get_date_from_select($prefix) {
  1604. 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';
  1605. }
  1606. /* Check if a user is the author of the item */
  1607. function user_is_author($item_id, $user_id = null) {
  1608. if (empty($item_id)) {
  1609. return false;
  1610. }
  1611. if (empty($user_id)) {
  1612. $user_id = api_get_user_id();
  1613. }
  1614. $is_author = false;
  1615. $item_to_edit_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_id, api_get_session_id());
  1616. $is_allowed_to_edit = api_is_allowed_to_edit();
  1617. if ($is_allowed_to_edit) {
  1618. $is_author = true;
  1619. } else {
  1620. if ($item_to_edit_data['insert_user_id'] == $user_id) {
  1621. $is_author = true;
  1622. }
  1623. }
  1624. if (!$is_author) {
  1625. //api_not_allowed();
  1626. return false;
  1627. }
  1628. return $is_author;
  1629. }
  1630. /**
  1631. * Get list of users who have not given the task
  1632. * @param int
  1633. * @return array
  1634. * @author cvargas
  1635. * @author Julio Montoya <gugli100@gmail.com> Fixing query
  1636. */
  1637. function get_list_users_without_publication($task_id) {
  1638. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1639. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  1640. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  1641. $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1642. //condition for the session
  1643. $session_id = api_get_session_id();
  1644. $course_id = api_get_course_int_id();
  1645. $task_id = intval($task_id);
  1646. if ($session_id == 0) {
  1647. $sql = "SELECT user_id as id FROM $work_table WHERE c_id = $course_id AND parent_id='$task_id'";
  1648. } else {
  1649. $sql = "SELECT user_id as id FROM $work_table WHERE c_id = $course_id AND parent_id='$task_id' and session_id='".$session_id."'";
  1650. }
  1651. $result = Database::query($sql);
  1652. $users_with_tasks = array();
  1653. while($row = Database::fetch_array($result)) {
  1654. $users_with_tasks[] = $row['id'];
  1655. }
  1656. if ($session_id == 0){
  1657. $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u
  1658. WHERE u.status!=1 and cu.course_code='".api_get_course_id()."' AND u.user_id=cu.user_id";
  1659. } else {
  1660. $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u
  1661. 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."'";
  1662. }
  1663. $group_id = api_get_group_id();
  1664. $new_group_user_list = array();
  1665. if ($group_id) {
  1666. $group_user_list = GroupManager::get_subscribed_users($group_id);
  1667. if (!empty($group_user_list)) {
  1668. foreach($group_user_list as $group_user) {
  1669. $new_group_user_list[] = $group_user['user_id'];
  1670. }
  1671. }
  1672. }
  1673. $result_users = Database::query($sql_users);
  1674. $users_without_tasks = array();
  1675. while ($row_users = Database::fetch_row($result_users)) {
  1676. if (in_array($row_users[0], $users_with_tasks)) continue;
  1677. if ($group_id && !in_array($row_users[0], $new_group_user_list)) {
  1678. continue;
  1679. }
  1680. //$user_id = array_shift($row_users);
  1681. $row_users[0] = $row_users[1];
  1682. $row_users[1] = $row_users[2];
  1683. $row_users[2] = Display::encrypted_mailto_link($row_users[3]);
  1684. $users_without_tasks[] = $row_users;
  1685. }
  1686. return $users_without_tasks;
  1687. }
  1688. /**
  1689. * Display list of users who have not given the task
  1690. *
  1691. * @param int task id
  1692. * @return array
  1693. * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
  1694. * @author Julio Montoya <gugli100@gmail.com> Fixes
  1695. */
  1696. function display_list_users_without_publication($task_id) {
  1697. global $origin;
  1698. $table_header[] = array(get_lang('LastName'), true);
  1699. $table_header[] = array(get_lang('FirstName'), true);
  1700. $table_header[] = array(get_lang('Email'), true);
  1701. // table_data
  1702. $table_data = get_list_users_without_publication($task_id);
  1703. $sorting_options = array();
  1704. $sorting_options['column'] = 1;
  1705. $paging_options = array();
  1706. $my_params = array();
  1707. if (isset($_GET['curdirpath'])) {
  1708. $my_params['curdirpath'] = Security::remove_XSS($_GET['curdirpath']);
  1709. }
  1710. if (isset($_GET['edit_dir'])) {
  1711. $my_params['edit_dir'] = Security::remove_XSS($_GET['edit_dir']);
  1712. }
  1713. if (isset($_GET['list'])) {
  1714. $my_params['list'] = Security::remove_XSS($_GET['list']);
  1715. }
  1716. $my_params['origin'] = $origin;
  1717. $my_params['id'] = intval($_GET['id']);
  1718. //$column_show
  1719. $column_show[] = 1;
  1720. $column_show[] = 1;
  1721. $column_show[] = 1;
  1722. Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show);
  1723. }