work.lib.php 59 KB

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