work.lib.php 83 KB

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