work.lib.php 71 KB

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