work.lib.php 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  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($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. foreach($dirs_list as $dir) {
  385. if ($my_sub_dir=='') {
  386. $mydir_temp = '/'.$dir;
  387. }else {
  388. $mydir_temp = '/'.$my_sub_dir.$dir;
  389. }
  390. $sql_select_directory= "SELECT prop.lastedit_date, id, author, has_properties, view_properties, description, qualification,weight,id FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE ";
  391. if (!empty($_SESSION['toolgroup'])) {
  392. $sql_select_directory.=" work.post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group
  393. } else {
  394. $sql_select_directory.=" work.post_group_id = '0' ";
  395. }
  396. $sql_select_directory.=" AND work.url LIKE BINARY '".$mydir_temp."' AND work.filetype = 'folder' AND prop.tool='work' $condition_session";
  397. $result=Database::query($sql_select_directory,__FILE__,__LINE__);
  398. $row=Database::fetch_array($result);
  399. if(!$row) {
  400. // the folder belongs to another session
  401. continue;
  402. }
  403. $direc_date= $row['lastedit_date']; //directory's date
  404. $author= $row['author']; //directory's author
  405. $view_properties=$row['view_properties'];
  406. $is_assignment = $row['has_properties'];
  407. $id2=$row['id'];
  408. $mydir = $my_sub_dir.$dir;
  409. if ($is_allowed_to_edit) {
  410. isset($_GET['edit_dir'])?$clean_edit_dir=Security :: remove_XSS(Database::escape_string($_GET['edit_dir'])):$clean_edit_dir='';
  411. // form edit directory
  412. if(isset($clean_edit_dir) && $clean_edit_dir==$mydir) {
  413. if(!empty($row['has_properties'])) {
  414. $sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE id = '."'".$row['has_properties']."'".' LIMIT 1',__FILE__,__LINE__);
  415. $homework = Database::fetch_array($sql);
  416. }
  417. $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?curdirpath='.$my_sub_dir.'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$mydir);
  418. $group_name[] = FormValidator :: createElement('text','dir_name');
  419. $form_folder -> addGroup($group_name,'my_group',get_lang('Title'));
  420. $form_folder -> addGroupRule('my_group',get_lang('ThisFieldIsRequired'),'required');
  421. $defaults = array('my_group[dir_name]'=>html_entity_decode($dir),'description'=>html_entity_decode($row['description']));
  422. $form_folder-> addElement('textarea','description',get_lang('Description'),array('rows'=>5,'cols'=>50));
  423. $qualification_input[] = FormValidator :: createElement('text','qualification');
  424. $form_folder -> addGroup($qualification_input,'qualification',get_lang('QualificationNumberOver'),'size="10"');
  425. if ($row['weight'] > 0) {
  426. $weight_input[] = FormValidator :: createElement('text','weight');
  427. $form_folder -> addGroup($weight_input,'weight',get_lang('WeightInTheGradebook'),'size="10"');
  428. }
  429. $there_is_a_end_date =false;
  430. if($row['view_properties']=='1') {
  431. if($homework['expires_on']!='0000-00-00 00:00:00'){
  432. $there_is_a_expire_date = true;
  433. $form_folder -> addGroup(create_group_date_select(),'expires',get_lang('ExpiresAt'));
  434. }
  435. if($homework['ends_on']!='0000-00-00 00:00:00') {
  436. $there_is_a_end_date = true;
  437. $form_folder -> addGroup(create_group_date_select(),'ends',get_lang('EndsAt'));
  438. }
  439. if ($there_is_a_expire_date && $there_is_a_end_date) {
  440. $form_folder -> addRule(array('expires','ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  441. }
  442. } else {
  443. $form_folder -> addElement('html','<div class="row">
  444. <div class="label">&nbsp;</div>
  445. <div class="formw">
  446. <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>
  447. </div>
  448. </div> ');
  449. $form_folder -> addElement('html','<div id="options" style="display: none;">');
  450. if(empty($default)) {
  451. $default = date('Y-m-d 12:00:00');
  452. }
  453. $parts = split(' ',$default);
  454. list($d_year,$d_month,$d_day) = split('-',$parts[0]);
  455. list($d_hour,$d_minute) = split(':',$parts[1]);
  456. if ((int)$row['weight'] == 0) {
  457. $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\';}"');
  458. $form_folder -> addElement('html','<div id=\'option3\' style="display:none">');
  459. $weight_input2[] = FormValidator :: createElement('text','weight');
  460. $form_folder -> addGroup($weight_input2,'weight',get_lang('WeightInTheGradebook'),'size="10"');
  461. $form_folder -> addElement('html','</div>');
  462. }
  463. if($homework['expires_on']='0000-00-00 00:00:00') {
  464. $homework['expires_on']=date("Y-m-d H:i:s");
  465. $there_is_a_expire_date = true;
  466. $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\';}"');
  467. $form_folder -> addElement('html','<div id=\'option1\' style="display:none">');
  468. $form_folder -> addGroup(create_group_date_select(),'expires',get_lang('ExpiresAt'));
  469. $form_folder -> addElement('html','</div>');
  470. }
  471. if($homework['ends_on']='0000-00-00 00:00:00') {
  472. $homework['ends_on']=date("Y-m-d H:i:s");
  473. $there_is_a_end_date = true;
  474. $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\';}"');
  475. $form_folder -> addElement('html','<div id=\'option2\' style="display:none">');
  476. $form_folder -> addGroup(create_group_date_select(),'ends',get_lang('EndsAt'));
  477. $form_folder -> addElement('html','</div>');
  478. }
  479. $form_folder -> addRule (array('expires','ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
  480. $form_folder -> addElement('html','</div>');
  481. }
  482. $form_folder -> addElement('style_submit_button','submit',get_lang('ModifyDirectory'),'class="save"');
  483. if($there_is_a_end_date == true) {
  484. $defaults = array_merge($defaults,convert_date_to_array($homework['ends_on'],'ends'));
  485. }
  486. if($there_is_a_expire_date == true) {
  487. $defaults = array_merge($defaults,convert_date_to_array($homework['expires_on'],'expires'));
  488. }
  489. if(!empty($row['qualification'])) {
  490. $defaults = array_merge($defaults,array('qualification[qualification]'=>$row['qualification']));
  491. }
  492. if(!empty($row['weight'])) {
  493. $defaults = array_merge($defaults,array('weight[weight]'=>$row['weight']));
  494. }
  495. $form_folder -> setDefaults($defaults);
  496. $display_edit_form=true;
  497. if($form_folder -> validate()) {
  498. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  499. if($there_is_a_end_date == true || $there_is_a_expire_date == true) {
  500. if($row['view_properties']=='1') {
  501. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
  502. Database::query($sql_add_publication, __FILE__, __LINE__);
  503. $expires_query= ' SET expires_on = '."'".(($there_is_a_expire_date == true)?get_date_from_group('expires'):'0000-00-00 00:00:00')."'".',';
  504. $ends_query = ' ends_on = '."'".(($there_is_a_end_date == true) ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
  505. Database::query('UPDATE '.$work_assigment.$expires_query.$ends_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__);
  506. } else if($row['view_properties']=='0') {
  507. if ($_POST['enableExpiryDate']=='1') {
  508. $expires_query= ' SET expires_on = '."'".(($there_is_a_expire_date == true)?get_date_from_group('expires'):'0000-00-00 00:00:00')."'";
  509. //$ends_query = ' ends_on = '."'".(($there_is_a_end_date == true) ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
  510. Database::query('UPDATE '.$work_assigment.$expires_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__);
  511. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
  512. Database::query($sql_add_publication, __FILE__, __LINE__);
  513. }
  514. if ($_POST['enableEndDate']=='1') {
  515. //$expires_query= ' SET expires_on = '."'".(($there_is_a_expire_date == true)?get_date_from_group('expires'):'0000-00-00 00:00:00')."'".',';
  516. $ends_query = ' SET ends_on = '."'".(($there_is_a_end_date == true) ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
  517. Database::query('UPDATE '.$work_assigment.$ends_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__);
  518. $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
  519. Database::query($sql_add_publication, __FILE__, __LINE__);
  520. }
  521. }
  522. }
  523. //if($_POST['qualification']['qualification']!='')
  524. 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__);
  525. 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__);
  526. //we are changing the current work and we want add them into gradebook
  527. if(isset($_POST['make_calification']) && $_POST['make_calification']==1) {
  528. require_once('../gradebook/lib/be/gradebookitem.class.php');
  529. require_once('../gradebook/lib/be/evaluation.class.php');
  530. require_once('../gradebook/lib/be/abstractlink.class.php');
  531. require_once('../gradebook/lib/gradebook_functions.inc.php');
  532. $resource_name = Security::remove_XSS($_POST['dir_name']);
  533. 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());
  534. }
  535. Display::display_confirmation_message(get_lang('FolderEdited'));
  536. $values = $form_folder -> exportValues();
  537. $values = $values['my_group'];
  538. $dir_name = replace_dangerous_char($values['dir_name']);
  539. $dir_name = disable_dangerous_file($dir_name);
  540. update_dir_name($mydir,$dir_name);
  541. $mydir = $my_sub_dir.$dir_name;
  542. $dir = $dir_name;
  543. $display_edit_form=false;
  544. // gets calendar_id from student_publication_assigment
  545. $sql = "SELECT add_to_calendar FROM $work_assigment WHERE publication_id ='".$row['id']."'";
  546. $res = Database::query($sql,__FILE__,__LINE__);
  547. $calendar_id = Database::fetch_row($res);
  548. // update from agenda if it exists
  549. if (!empty($calendar_id[0])) {
  550. $sql = "UPDATE ".$TABLEAGENDA."
  551. SET title='".$dir_name."',
  552. content = '".$dir_name."',
  553. end_date='".get_date_from_group('ends')."'
  554. WHERE id='".$calendar_id[0]."'";
  555. Database::query($sql,__FILE__,__LINE__);
  556. }
  557. }
  558. }
  559. }
  560. $action = '';
  561. $row = array();
  562. $class = '';
  563. $row[] = '<img src="../img/works.gif" border="0" hspace="5" align="middle" alt="'.get_lang('Assignment').'" title="'.get_lang('Assignment').'" />'; //image
  564. //$a_count_directory=count_dir($work_dir.'/'.$dir,false);
  565. $cant_files=0;
  566. $cant_dir = 0;
  567. if(api_is_allowed_to_edit()) {
  568. $sql_document = "SELECT count(*) FROM $work_table WHERE url NOT LIKE '".$sub_course_dir.$dir."/%/%' AND url LIKE '".$sub_course_dir.$dir."/%'";
  569. } else {
  570. // gets admin_course
  571. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  572. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  573. $sql = "SELECT course_user.user_id FROM $table_user user, $table_course_user course_user
  574. WHERE course_user.user_id=user.user_id AND course_user.course_code='".api_get_course_id()."' AND course_user.status='1'";
  575. $res = Database::query($sql,__FILE__,__LINE__);
  576. $admin_course = '';
  577. while($row_admin = Database::fetch_row($res)) {
  578. $admin_course .='\''.$row_admin[0].'\',';
  579. }
  580. $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."/%'";
  581. }
  582. //count documents
  583. $res_document = Database::query($sql_document,__FILE__,__LINE__);
  584. $count_document = Database::fetch_row($res_document);
  585. $cant_files = $count_document[0];
  586. //count directories
  587. $sql_directory = "SELECT count(*) FROM $work_table s WHERE url NOT LIKE '/".$mydir."/%/%' AND url LIKE '/".$mydir."/%'";
  588. $res_directory = Database::query($sql_directory,__FILE__,__LINE__);
  589. $count_directory = Database::fetch_row($res_directory);
  590. $cant_dir = $count_directory[0];
  591. $text_file=get_lang('FilesUpload');
  592. $text_dir=get_lang('Directories');
  593. if ($cant_files==1) {
  594. $text_file=api_strtolower(get_lang('FileUpload'));
  595. }
  596. if ($cant_dir==1) {
  597. $text_dir=get_lang('directory');
  598. }
  599. if ($cant_dir!=0) {
  600. $dirtext=' ('.$cant_dir.' '.$text_dir.')';
  601. } else {
  602. $dirtext='';
  603. }
  604. if (!empty($display_edit_form) && isset($clean_edit_dir) && $clean_edit_dir==$mydir) {
  605. $row[] = '<span class="invisible" style="display:none">'.$dir.'</span>'.$form_folder->toHtml(); // form to edit the directory's name
  606. } else {
  607. $tbl_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  608. $add_to_name = '';
  609. $sql = "SELECT weight FROM ". $tbl_gradebook_link ." WHERE type='3' AND ref_id= '".$id2."'";
  610. $result=Database::query($sql, __FILE__, __LINE__);
  611. $count = Database::num_rows($result);
  612. if($count>0) {
  613. $add_to_name = ' / <span style="color:blue">'.get_lang('Assignment').'</span>';
  614. } else {
  615. $add_to_name = '';
  616. }
  617. $show_as_icon = get_work_id($mydir); //true or false
  618. if ($show_as_icon){
  619. if (is_allowed_to_edit()) {
  620. $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>';
  621. }
  622. $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;
  623. } else {
  624. $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;
  625. }
  626. }
  627. if ($count_files!=0) {
  628. $row[] = "";
  629. }
  630. if ($direc_date!='' && $direc_date!='0000-00-00 00:00:00') {
  631. $my_direc_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($direc_date))).'&nbsp;&nbsp;&nbsp;&nbsp;';
  632. $my_direc_date .= ucfirst(strftime($timeNoSecFormat,strtotime($direc_date)));
  633. $row[]= date_to_str_ago($direc_date).'<br /><span class="dropbox_date">'.$my_direc_date.'</span>';
  634. } else {
  635. $row[]='';
  636. }
  637. if ($origin != 'learnpath') {
  638. if( $is_allowed_to_edit) {
  639. $action .= '<a href="'.api_get_self().'?cidReq='.api_get_course_id().
  640. '&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>';
  641. $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>';
  642. $row[] = $action;
  643. } else {
  644. $row[] = "";
  645. }
  646. }
  647. $table_data[] = $row;
  648. }
  649. while( $work = Database::fetch_object($sql_result)) {
  650. //Get the author ID for that document from the item_property table
  651. $is_author = false;
  652. $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND ref=".$work->id;
  653. $author_qry = Database::query($author_sql,__FILE__,__LINE__);
  654. $row2=Database::fetch_array($author_qry);
  655. if(Database::num_rows($author_qry)==1) {
  656. $is_author = true;
  657. }
  658. //display info depending on the permissions
  659. if( $work->accepted == '1' || $is_allowed_to_edit) {
  660. $row = array();
  661. if($work->accepted == '0')
  662. {
  663. $class='class="invisible"';
  664. } else {
  665. $class='';
  666. }
  667. $qualification_string = '';
  668. $add_string = '';
  669. if(defined('IS_ASSIGNMENT')):
  670. if($work->qualification=='') {
  671. $qualification_string = ' / <b style="color:orange">'.get_lang('NotRevised').'<b>';
  672. } else {
  673. $qualification_string = ' / <b style="color:blue">'.get_lang('Qualification').': '.$work->qualification.'<b>';
  674. }
  675. if(defined('ASSIGNMENT_EXPIRES') && (ASSIGNMENT_EXPIRES < convert_date_to_number($work->sent_date))) {
  676. $add_string = ' <b style="color:red">'.get_lang('Expired').'</b>';
  677. }
  678. endif;
  679. $url = implode("/", array_map("rawurlencode", explode("/", $work->url)));
  680. //$full_file_name = 'download.php?file='.$realname;
  681. $row[]= build_document_icon_tag('file',$work->url);
  682. $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;
  683. $row[]= display_user_link($row2['insert_user_id'],$work->author).$qualification_string;// $work->author;
  684. $sent_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($work->sent_date))).'&nbsp;&nbsp;&nbsp;&nbsp;';
  685. $sent_date .= ucfirst(strftime($timeNoSecFormat,strtotime($work->sent_date)));
  686. $row[]= date_to_str_ago($work->sent_date).$add_string.'<br><span class="dropbox_date">'.$sent_date.'</span>';
  687. if( $is_allowed_to_edit) {
  688. $action = '';
  689. $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>';
  690. $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>';
  691. $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>';
  692. if($work->accepted == '1') {
  693. $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>';
  694. } else {
  695. $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>';
  696. }
  697. $row[] = $action;
  698. // the user that is not course admin can only edit/delete own document
  699. } elseif($row2['insert_user_id'] == $_user['user_id']) {
  700. $action = '';
  701. $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>';
  702. if (api_get_course_setting('student_delete_own_publication')==1) {
  703. $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>';
  704. }
  705. $row[] = $action;
  706. } else {
  707. $row[] = " ";
  708. }
  709. $table_data[] = $row;
  710. }
  711. }
  712. $sorting_options=array();
  713. $sorting_options['column']=1;
  714. $paging_options=array();
  715. if (isset($_GET['curdirpath'])) {
  716. $my_params = array ('curdirpath' => Security::remove_XSS($_GET['curdirpath']));
  717. }
  718. if (isset($_GET['edit_dir'])) {
  719. $my_params = array ('edit_dir' => Security::remove_XSS($_GET['edit_dir']));
  720. }
  721. $my_params['origin'] = $origin;
  722. Display::display_sortable_config_table($table_header,$table_data,$sorting_options, $paging_options,$my_params,$column_show,$column_order);
  723. }
  724. /**
  725. * Returns a list of subdirectories found in the given directory.
  726. *
  727. * The list return starts from the given base directory.
  728. * If you require the subdirs of /var/www/ (or /var/www), you will get 'abc/', 'def/', but not '/var/www/abc/'...
  729. * @param string Base dir
  730. * @param integer 0 if we only want dirs from this level, 1 if we want to recurse into subdirs
  731. * @return strings_array The list of subdirs in 'abc/' form, -1 on error, and 0 if none found
  732. * @todo Add a session check to see if subdirs_list doesn't exist yet (cached copy)
  733. */
  734. function get_subdirs_list($basedir='',$recurse=0){
  735. //echo "Looking for subdirs of $basedir";
  736. if(empty($basedir) or !is_dir($basedir)) {
  737. return -1;
  738. }
  739. if(substr($basedir,-1,1)!='/') {
  740. $basedir = $basedir.'/';
  741. }
  742. $dirs_list = array();
  743. $dh = opendir($basedir);
  744. while($entry = readdir($dh)) {
  745. $entry = replace_dangerous_char($entry);
  746. $entry = disable_dangerous_file($entry);
  747. if(is_dir($basedir.$entry) && $entry!='..' && $entry!='.') {
  748. $dirs_list[] = $entry;
  749. if($recurse==1) {
  750. foreach(get_subdirs_list($basedir.$entry) as $subdir) {
  751. $dirs_list[] = $entry.'/'.$subdir;
  752. }
  753. }
  754. }
  755. }
  756. closedir($dh);
  757. return $dirs_list;
  758. }
  759. /**
  760. * Builds the form thats enables the user to
  761. * select a directory to browse/upload in
  762. * This function has been copied from the document/document.inc.php library
  763. *
  764. * @param array $folders
  765. * @param string $curdirpath
  766. * @param string $group_dir
  767. * @return string html form
  768. */
  769. function build_work_directory_selector($folders,$curdirpath,$group_dir='')
  770. {
  771. $form = '<form name="selector" action="'.api_get_self().'?'.api_get_cidreq().'" method="POST">'."\n";
  772. $form .= get_lang('CurrentDirectory').' <select name="curdirpath" onchange="javascript:document.selector.submit()">'."\n";
  773. //group documents cannot be uploaded in the root
  774. if ($group_dir=='') {
  775. $form .= '<option value="/">/ ('.get_lang('Root').')</option>';
  776. if (is_array($folders)) {
  777. foreach ($folders as $folder) {
  778. $selected = ($curdirpath==$folder)?' selected="selected"':'';
  779. $form .= '<option'.$selected.' value="'.$folder.'">'.$folder.'</option>'."\n";
  780. }
  781. }
  782. } else {
  783. foreach ($folders as $folder) {
  784. $selected = ($curdirpath==$folder)?' selected="selected"':'';
  785. $display_folder = substr($folder,strlen($group_dir));
  786. $display_folder = ($display_folder == '')?'/ ('.get_lang('Root').')':$display_folder;
  787. $form .= '<option'.$selected.' value="'.$folder.'">'.$display_folder.'</option>'."\n";
  788. }
  789. }
  790. $form .= '</select>'."\n";
  791. $form .= '<noscript><input type="submit" name="change_path" value="'.get_lang('Ok').'" /></noscript>'."\n";
  792. $form .= '</form>';
  793. return $form;
  794. }
  795. /**
  796. * Builds the form thats enables the user to
  797. * move a document from one directory to another
  798. * This function has been copied from the document/document.inc.php library
  799. *
  800. * @param array $folders
  801. * @param string $curdirpath
  802. * @param string $move_file
  803. * @return string html form
  804. */
  805. function build_work_move_to_selector($folders,$curdirpath,$move_file,$group_dir='')
  806. {
  807. //gets file title
  808. $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  809. $sql = "SELECT title FROM $tbl_work WHERE id ='".(int)$move_file."'";
  810. $result = Database::query($sql,__FILE__,__LINE__);
  811. $title = Database::fetch_row($result);
  812. global $gradebook;
  813. $form = '<form name="move_to" action="'.api_get_self().'?gradebook='.$gradebook.'" method="POST">'."\n";
  814. $form .= '<div class="row"><div class="form_header">'.get_lang('MoveFile').'</div></div>';
  815. $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />'."\n";
  816. $form .= '<div class="row">
  817. <div class="label">
  818. <span class="form_required">*</span>'.sprintf(get_lang('MoveXTo'),$title[0]).'
  819. </div>
  820. <div class="formw">';
  821. $form .= ' <select name="move_to">'."\n";
  822. //group documents cannot be uploaded in the root
  823. if($group_dir=='') {
  824. if($curdirpath!='/') {
  825. $form .= '<option value="/">/ ('.get_lang('Root').')</option>';
  826. }
  827. if (is_array($folders)) {
  828. foreach ($folders as $folder) {
  829. //you cannot move a file to:
  830. //1. current directory
  831. //2. inside the folder you want to move
  832. //3. inside a subfolder of the folder you want to move
  833. if(($curdirpath!=$folder) && ($folder!=$move_file) && (substr($folder,0,strlen($move_file)+1) != $move_file.'/')) {
  834. $form .= '<option value="'.$folder.'">'.$folder.'</option>'."\n";
  835. }
  836. }
  837. }
  838. } else {
  839. if ($curdirpath!='/') {
  840. $form .= '<option value="/">/ ('.get_lang('Root').')</option>';
  841. }
  842. foreach ($folders as $folder) {
  843. if (($curdirpath!=$folder) && ($folder!=$move_file) && (substr($folder,0,strlen($move_file)+1) != $move_file.'/')) {
  844. //cannot copy dir into his own subdir
  845. $display_folder = substr($folder,strlen($group_dir));
  846. $display_folder = ($display_folder == '')?'/ ('.get_lang('Root').')':$display_folder;
  847. $form .= '<option value="'.$folder.'">'.$display_folder.'</option>'."\n";
  848. }
  849. }
  850. }
  851. $form .= '</select>'."\n";
  852. $form .= ' </div>
  853. </div>';
  854. $form .= '<div class="row">
  855. <div class="label">
  856. </div>
  857. <div class="formw">
  858. <button type="submit" class="save" name="move_file_submit">'.get_lang('MoveFile').'</button>
  859. </div>
  860. </div>';
  861. $form .= '</form>';
  862. $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  863. return $form;
  864. }
  865. /**
  866. * Checks if the first given directory exists as a subdir of the second given directory
  867. * This function should now be deprecated by Security::check_abs_path()
  868. * @param string Subdir
  869. * @param string Base dir
  870. * @return integer -1 on error, 0 if not subdir, 1 if subdir
  871. */
  872. function is_subdir_of($subdir,$basedir)
  873. {
  874. if(empty($subdir) or empty($basedir)) {
  875. return -1;
  876. }
  877. if(substr($basedir,-1,1)!='/') {
  878. $basedir=$basedir.'/';
  879. }
  880. if(substr($subdir,0,1)=='/') {
  881. $subdir = substr($subdir,1);
  882. }
  883. if(is_dir($basedir.$subdir)) {
  884. return 1;
  885. } else {
  886. return 0;
  887. }
  888. }
  889. /**
  890. * creates a new directory trying to find a directory name
  891. * that doesn't already exist
  892. * (we could use unique_name() here...)
  893. *
  894. * @author Hugues Peeters <hugues.peeters@claroline.net>
  895. * @author Bert Vanderkimpen
  896. * @author Yannick Warnier <ywarnier@beeznest.org> Adaptation for work tool
  897. * @param string Base work dir (.../work)
  898. * @param string $desiredDirName complete path of the desired name
  899. * @return string actual directory name if it succeeds,
  900. * boolean false otherwise
  901. */
  902. function create_unexisting_work_directory($base_work_dir,$desired_dir_name)
  903. {
  904. $nb = '';
  905. $base_work_dir = (substr($base_work_dir,-1,1)=='/'?$base_work_dir:$base_work_dir.'/');
  906. while ( file_exists($base_work_dir.$desired_dir_name.$nb) ) {
  907. $nb += 1;
  908. }
  909. //echo "creating ".$base_work_dir.$desired_dir_name.$nb."#...";
  910. $perm = api_get_setting('permissions_for_new_directories');
  911. $perm = octdec(!empty($perm)?$perm:'0770');
  912. if ( mkdir($base_work_dir.$desired_dir_name.$nb, $perm)) {
  913. chmod($base_work_dir.$desired_dir_name.$nb, $perm);
  914. return $desired_dir_name.$nb;
  915. } else {
  916. return false;
  917. }
  918. }
  919. /**
  920. * Delete a work-tool directory
  921. * @param string Base "work" directory for this course as /var/www/dokeos/courses/ABCD/work/
  922. * @param string The directory name as the bit after "work/", without trailing slash
  923. * @return integer -1 on error
  924. */
  925. function del_dir($base_work_dir,$dir,$id) {
  926. if(empty($dir) or $dir=='/') {
  927. return -1;
  928. }
  929. $check = Security::check_abs_path($base_work_dir.$dir,$base_work_dir);
  930. if (!$check || !is_dir($base_work_dir.$dir)) {
  931. return -1;
  932. }
  933. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  934. $sql = "DELETE FROM $table WHERE url LIKE BINARY 'work/".$dir."/%'";
  935. $res = Database::query($sql,__FILE__,__LINE__);
  936. //delete from DB the directories
  937. $sql = "DELETE FROM $table WHERE filetype = 'folder' AND url LIKE BINARY '/".$dir."%'";
  938. $res = Database::query($sql,__FILE__,__LINE__);
  939. require_once(api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  940. $new_dir= $dir.'_DELETED_'.$id;
  941. if (api_get_setting('permanently_remove_deleted_files') == 'true'){
  942. my_delete($base_work_dir.$dir);
  943. } else {
  944. rename($base_work_dir.$dir, $base_work_dir.$new_dir);
  945. }
  946. }
  947. /**
  948. * Get the path of a document in the student_publication table (path relative to the course directory)
  949. * @param integer Element ID
  950. * @return string Path (or -1 on error)
  951. */
  952. function get_work_path($id)
  953. {
  954. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  955. $sql = "SELECT * FROM $table WHERE id=$id";
  956. $res = Database::query($sql);
  957. if(Database::num_rows($res)!=1) {
  958. return -1;
  959. } else {
  960. $row = Database::fetch_array($res);
  961. return $row['url'];
  962. }
  963. }
  964. /**
  965. * Update the url of a work in the student_publication table
  966. * @param integer ID of the work to update
  967. * @param string Destination directory where the work has been moved (must end with a '/')
  968. * @return -1 on error, sql query result on success
  969. */
  970. function update_work_url($id,$new_path)
  971. {
  972. if(empty($id)) return -1;
  973. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  974. $sql = "SELECT * FROM $table WHERE id=$id";
  975. $res = Database::query($sql);
  976. if(Database::num_rows($res)!=1) {
  977. return -1;
  978. } else {
  979. $row = Database::fetch_array($res);
  980. $filename = basename($row['url']);
  981. $new_url = $new_path.$filename;
  982. $sql2 = "UPDATE $table SET url = '$new_url' WHERE id=$id";
  983. $res2 = Database::query($sql2);
  984. return $res2;
  985. }
  986. }
  987. /**
  988. * Update the url of a dir in the student_publication table
  989. * @param string old path
  990. * @param string new path
  991. */
  992. function update_dir_name($path, $new_name) {
  993. if (!empty($new_name)){
  994. global $base_work_dir;
  995. include_once(api_get_path(LIBRARY_PATH) . "/fileManage.lib.php");
  996. include_once(api_get_path(LIBRARY_PATH) . "/fileUpload.lib.php");
  997. $path_to_dir = dirname($path);
  998. if($path_to_dir=='.') {
  999. $path_to_dir = '';
  1000. } else {
  1001. $path_to_dir .= '/';
  1002. }
  1003. $new_name = Security::remove_XSS($new_name);
  1004. $new_name = replace_dangerous_char($new_name);
  1005. $new_name = disable_dangerous_file($new_name);
  1006. my_rename($base_work_dir.'/'.$path,$new_name);
  1007. $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1008. //update all the files in the other directories according with the next query
  1009. $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "work/'.$path.'/%"'; // like binary (Case Sensitive)
  1010. $rs = Database::query($sql, __FILE__, __LINE__);
  1011. $work_len=strlen('work/'.$path);
  1012. while($work = Database :: fetch_array($rs)) {
  1013. $new_dir=$work['url'];
  1014. $name_with_directory=substr($new_dir,$work_len,strlen($new_dir));
  1015. $sql = 'UPDATE '.$table.' SET url="work/'.$path_to_dir.$new_name.$name_with_directory.'" WHERE id= '.$work['id'];
  1016. Database::query($sql, __FILE__, __LINE__);
  1017. }
  1018. //update all the directory's children according with the next query
  1019. $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "/'.$path.'%"';
  1020. $rs = Database::query($sql, __FILE__, __LINE__);
  1021. $work_len=strlen('/'.$path);
  1022. while($work = Database :: fetch_array($rs)) {
  1023. $new_dir=$work['url'];
  1024. $name_with_directory=substr($new_dir,$work_len,strlen($new_dir));
  1025. $url=$path_to_dir.$new_name.$name_with_directory;
  1026. $sql = 'UPDATE '.$table.' SET url="/'.$url.'" WHERE id= '.$work['id'];
  1027. Database::query($sql, __FILE__, __LINE__);
  1028. }
  1029. }
  1030. }
  1031. /**
  1032. * Return an array with all the folder's ids that are in the given path
  1033. * @param string Path of the directory
  1034. * @return array The list of ids of all the directories in the path
  1035. * @author Julio Montoya Dokeos
  1036. * @version April 2008
  1037. */
  1038. function get_parent_directories($my_cur_dir_path) {
  1039. $list_id = array();
  1040. if (!empty($my_cur_dir_path)) {
  1041. $list_parents = explode('/', $my_cur_dir_path);
  1042. $dir_acum = '';
  1043. global $work_table;
  1044. for ($i = 0; $i < count($list_parents) - 1; $i++) {
  1045. $item = Database::escape_string($list_parents[$i]);
  1046. $where_sentence = "url LIKE BINARY '" . $dir_acum . "/" . $item."'";
  1047. $dir_acum .= '/' . $list_parents[$i];
  1048. $sql = "SELECT id FROM ". $work_table . " WHERE ". $where_sentence;
  1049. $result = Database::query($sql, __FILE__, __LINE__);
  1050. $row= Database::fetch_array($result);
  1051. $list_id[]=$row['id'];
  1052. }
  1053. }
  1054. return $list_id;
  1055. }
  1056. /**
  1057. * Transform an all directory structure (only directories) in an array
  1058. * @param string path of the directory
  1059. * @return array the directory structure into an array
  1060. * @author Julio Montoya Dokeos
  1061. * @version April 2008
  1062. */
  1063. function directory_to_array($directory)
  1064. {
  1065. $array_items = array();
  1066. if ($handle = opendir($directory)) {
  1067. while (false !== ($file = readdir($handle))) {
  1068. if ($file != "." && $file != "..") {
  1069. if (is_dir($directory. "/" . $file)) {
  1070. $array_items = array_merge($array_items, directory_to_array($directory. "/" . $file));
  1071. $file = $directory . "/" . $file;
  1072. $array_items[] = preg_replace("/\/\//si", "/", $file);
  1073. }
  1074. }
  1075. }
  1076. closedir($handle);
  1077. }
  1078. return $array_items;
  1079. }
  1080. /**
  1081. * Insert into the DB of the course all the directories
  1082. * @param string path of the /work directory of the course
  1083. * @return -1 on error, sql query result on success
  1084. * @author Julio Montoya Dokeos
  1085. * @version April 2008
  1086. */
  1087. function insert_all_directory_in_course_table($base_work_dir) {
  1088. $dir_to_array =directory_to_array($base_work_dir,true);
  1089. $only_dir=array();
  1090. for($i=0;$i<count($dir_to_array);$i++) {
  1091. $only_dir[]=substr($dir_to_array[$i],strlen($base_work_dir), strlen($dir_to_array[$i]));
  1092. }
  1093. for($i=0;$i<count($only_dir);$i++) {
  1094. global $work_table;
  1095. $sql_insert_all= "INSERT INTO " . $work_table . " SET url = '" . $only_dir[$i] . "', " .
  1096. "title = '',
  1097. description = '',
  1098. author = '',
  1099. active = '0',
  1100. accepted = '1',
  1101. filetype = 'folder',
  1102. post_group_id = '".intval($_GET['toolgroup'])."',
  1103. sent_date = '0000-00-00 00:00:00' ";
  1104. Database::query($sql_insert_all, __FILE__, __LINE__);
  1105. }
  1106. }
  1107. /**
  1108. * This function displays the number of files contained in a directory
  1109. *
  1110. * @param string the path of the directory
  1111. * @param boolean true if we want the total quantity of files include in others child directorys , false only files in the directory
  1112. * @return array the first element is an integer with the number of files in the folder, the second element is the number of directories
  1113. * @author Julio Montoya Dokeos
  1114. * @version April 2008
  1115. */
  1116. function count_dir($path_dir, $recurse)
  1117. {
  1118. $count = 0;
  1119. $count_dir= 0;
  1120. $d = dir($path_dir);
  1121. while ($entry = $d->Read()) {
  1122. if (!(($entry == "..") || ($entry == "."))) {
  1123. if (is_dir($path_dir.'/'.$entry)) {
  1124. $count_dir++;
  1125. if ($recurse) {
  1126. $count += count_dir($path_dir . '/' . $entry, $recurse);
  1127. }
  1128. } else {
  1129. $count++;
  1130. }
  1131. }
  1132. }
  1133. $return_array=array();
  1134. $return_array[]=$count;
  1135. $return_array[]=$count_dir;
  1136. return $return_array;
  1137. }
  1138. /**
  1139. * returns all the javascript that is required for easily
  1140. * validation when you create a work
  1141. * this goes into the $htmlHeadXtra[] array
  1142. */
  1143. function to_javascript_work() {
  1144. return '<script>
  1145. function plus() {
  1146. if(document.getElementById(\'options\').style.display == \'none\') {
  1147. document.getElementById(\'options\').style.display = \'block\';
  1148. document.getElementById(\'plus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide', ''),array('style'=>'vertical-align:middle')).'&nbsp;'.addslashes(get_lang('AdvancedParameters', '')).'\';
  1149. } else {
  1150. document.getElementById(\'options\').style.display = \'none\';
  1151. document.getElementById(\'plus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show', ''),array('style'=>'vertical-align:middle')).'&nbsp;'.addslashes(get_lang('AdvancedParameters', '')).'\';
  1152. }
  1153. }
  1154. function updateDocumentTitle(value){
  1155. var temp = value.indexOf("/");
  1156. //linux path
  1157. if(temp!=-1){
  1158. var temp=value.split("/");
  1159. }
  1160. else{
  1161. var temp=value.split("\\\");
  1162. }
  1163. document.getElementById("file_upload").value=temp[temp.length-1];
  1164. }
  1165. function checkDate(month, day, year)
  1166. {
  1167. var monthLength =
  1168. new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  1169. if (!day || !month || !year)
  1170. return false;
  1171. // check for bisestile year
  1172. if (year/4 == parseInt(year/4))
  1173. monthLength[1] = 29;
  1174. if (month < 1 || month > 12)
  1175. return false;
  1176. if (day > monthLength[month-1])
  1177. return false;
  1178. return true;
  1179. }
  1180. function mktime() {
  1181. var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
  1182. d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  1183. var dateManip = {
  1184. 0: function(tt){ return d.setHours(tt); },
  1185. 1: function(tt){ return d.setMinutes(tt); },
  1186. 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
  1187. 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
  1188. 4: function(tt){ return d.setDate(tt+mb); },
  1189. 5: function(tt){ return d.setYear(tt+ma); }
  1190. };
  1191. for( i = 0; i < argc; i++ ){
  1192. no = parseInt(argv[i]*1);
  1193. if (isNaN(no)) {
  1194. return false;
  1195. } else {
  1196. // arg is number, lets manipulate date object
  1197. if(!dateManip[i](no)){
  1198. // failed
  1199. return false;
  1200. }
  1201. }
  1202. }
  1203. return Math.floor(d.getTime()/1000);
  1204. }
  1205. function validate(){
  1206. var expires_day = document.form1.expires_day.value;
  1207. var expires_month = document.form1.expires_month.value;
  1208. var expires_year = document.form1.expires_year.value;
  1209. var expires_hour = document.form1.expires_hour.value;
  1210. var expires_minute = document.form1.expires_minute.value;
  1211. var expires_date = mktime(expires_hour,expires_minute,0,expires_month,expires_day,expires_year)
  1212. var ends_day = document.form1.ends_day.value;
  1213. var ends_month = document.form1.ends_month.value;
  1214. var ends_year = document.form1.ends_year.value;
  1215. var ends_hour = document.form1.ends_hour.value;
  1216. var ends_minute = document.form1.ends_minute.value;
  1217. var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year)
  1218. var new_dir = document.form1.new_dir.value;
  1219. msg_id1 = document.getElementById("msg_error1");
  1220. msg_id2 = document.getElementById("msg_error2");
  1221. msg_id3 = document.getElementById("msg_error3");
  1222. msg_id4 = document.getElementById("msg_error4");
  1223. msg_id5 = document.getElementById("msg_error_weight");
  1224. if(new_dir==""){
  1225. msg_id1.style.display ="block";
  1226. msg_id1.innerHTML="'.get_lang('FieldRequired', '').'";
  1227. msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1228. }
  1229. else if(document.form1.type1.checked==true && document.form1.type2.checked==true && expires_date > ends_date) {
  1230. msg_id2.style.display ="block";
  1231. msg_id2.innerHTML="'.get_lang('EndDateCannotBeBeforeTheExpireDate', '').'";
  1232. msg_id1.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1233. }
  1234. else if (checkDate(expires_month,expires_day,expires_year) == false)
  1235. {
  1236. msg_id3.style.display ="block";
  1237. msg_id3.innerHTML="'.get_lang('InvalidDate', '').'";
  1238. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id4.innerHTML="";msg_id5.innerHTML="";
  1239. }
  1240. else if (checkDate(ends_month,ends_day,ends_year) == false)
  1241. {
  1242. msg_id4.style.display ="block";
  1243. msg_id4.innerHTML="'.get_lang('InvalidDate', '').'";
  1244. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id5.innerHTML="";
  1245. }
  1246. else
  1247. {
  1248. if (document.form1.make_calification.checked == true)
  1249. {
  1250. var weight = document.form1.weight.value;
  1251. if(weight==""){
  1252. msg_id5.style.display ="block";
  1253. msg_id5.innerHTML="'.get_lang('WeightNecessary', '').'";
  1254. msg_id1.innerHTML="";msg_id2.innerHTML="";msg_id3.innerHTML="";msg_id4.innerHTML="";
  1255. return false;
  1256. }
  1257. }
  1258. document.form1.action = "work.php?origin='.api_get_tools_lists($_REQUEST['origin']).'&gradebook='.(empty($_GET['gradebook'])?'':'view').'";
  1259. document.form1.submit();
  1260. }
  1261. }
  1262. </script>';
  1263. }
  1264. /**
  1265. * Gets the id of a student publication with a given path
  1266. * @param string $path
  1267. * @return true if is found / false if not found
  1268. */
  1269. function get_work_id($path) {
  1270. $TBL_STUDENT_PUBLICATION = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  1271. $TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1272. if (is_allowed_to_edit()) {
  1273. $sql = "SELECT 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'";
  1274. } else {
  1275. $sql = "SELECT 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()."'";
  1276. }
  1277. $result = Database::query($sql, __FILE__, __LINE__);
  1278. $num_rows = Database::num_rows($result);
  1279. if ($result && $num_rows > 0) {
  1280. return true;
  1281. } else {
  1282. return false;
  1283. }
  1284. }
  1285. /**
  1286. * Get list of users who have not given the task
  1287. * @param int
  1288. * @return array
  1289. * @author cvargas carlos.vargas@beeznest.com
  1290. */
  1291. function get_list_users_without_publication($task_id) {
  1292. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  1293. $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1294. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1295. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  1296. $session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1297. //condition for the session
  1298. $session_id = api_get_session_id();
  1299. if (!empty($session_id)){
  1300. $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."'";
  1301. } else {
  1302. $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()."'";
  1303. }
  1304. $result = Database::query($sql, __FILE__, __LINE__);
  1305. $users_with_tasks = array();
  1306. while($row = Database::fetch_array($result)) {
  1307. $users_with_tasks[] = $row['id'];
  1308. }
  1309. if (!empty($session_id)){
  1310. $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."'";
  1311. } else {
  1312. $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";
  1313. }
  1314. $result_users = Database::query($sql_users, __FILE__, __LINE__);
  1315. $users_without_tasks = array();
  1316. while ($row_users = Database::fetch_row($result_users)) {
  1317. if (in_array($row_users[0],$users_with_tasks)) continue;
  1318. $user_id = array_shift($row_users);
  1319. $row_users[3] = $row_users[2];
  1320. $row_users[2] = Display::encrypted_mailto_link($row_users[2],$row_users[2]);
  1321. $users_without_tasks[] = $row_users;
  1322. }
  1323. return $users_without_tasks;
  1324. }
  1325. /**
  1326. * Display list of users who have not given the task
  1327. *
  1328. * @param int task id
  1329. * @return array
  1330. * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
  1331. * @author Julio Montoya <gugli100@gmail.com> Fixes
  1332. */
  1333. function display_list_users_without_publication($task_id) {
  1334. global $origin;
  1335. $table_header[] = array(get_lang('FirstName'),true);
  1336. $table_header[] = array(get_lang('LastName'),true);
  1337. $table_header[] = array(get_lang('Email'),true);
  1338. // table_data
  1339. $table_data = get_list_users_without_publication($task_id);
  1340. $sorting_options=array();
  1341. $sorting_options['column']=1;
  1342. $paging_options=array();
  1343. $my_params = array();
  1344. if (isset($_GET['curdirpath'])) {
  1345. $my_params['curdirpath'] = Security::remove_XSS($_GET['curdirpath']);
  1346. }
  1347. if (isset($_GET['edit_dir'])) {
  1348. $my_params['edit_dir'] = Security::remove_XSS($_GET['edit_dir']);
  1349. }
  1350. if (isset($_GET['list'])) {
  1351. $my_params['list'] = Security::remove_XSS($_GET['list']);
  1352. }
  1353. $my_params['origin'] = $origin;
  1354. //$column_show
  1355. $column_show[]=1;
  1356. $column_show[]=1;
  1357. $column_show[]=1;
  1358. Display::display_sortable_config_table($table_header,$table_data,$sorting_options, $paging_options,$my_params,$column_show);
  1359. }
  1360. /**
  1361. * Send reminder to users who have not given the task
  1362. *
  1363. * @param int
  1364. * @return array
  1365. * @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
  1366. */
  1367. function send_reminder_users_without_publication($task_id) {
  1368. global $_course,$my_cur_dir_path,$currentUserFirstName,$currentUserLastName,$currentUserEmail;
  1369. $emailsubject = "[" . api_get_setting('siteName') . "] ";
  1370. $sender_name = $currentUserFirstName.' '.$currentUserLastName;
  1371. $email_admin = $currentUserEmail;
  1372. // The body can be as long as you wish, and any combination of text and variables
  1373. $emailbody_user .= get_lang('ReminderToSubmitPendingTask')."\n".get_lang('CourseName')." : ".$_course['name']."\n";
  1374. $emailbody_user .= get_lang('WorkName')." : ".substr($my_cur_dir_path, 0, -1)."\n\n".get_lang('Teacher')." : ".$currentUserFirstName.' '.$currentUserLastName."\n".get_lang('Email')." : ".$currentUserEmail;
  1375. $list_users= get_list_users_without_publication($task_id);
  1376. foreach ($list_users as $users) {
  1377. $name_user = $users[1].' '.$users[0];
  1378. @api_mail($name_user, $users[3], $emailsubject, $emailbody_user, $sender_name,$email_admin);
  1379. }
  1380. }