work.lib.php 65 KB

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