work.lib.php 65 KB

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