work.lib.php 65 KB

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