group_space_tracking.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once '../inc/global.inc.php';
  4. $allow = api_get_configuration_value('extra');
  5. if (empty($allow)) {
  6. exit;
  7. }
  8. $current_course_tool = TOOL_GROUP;
  9. // Notice for unauthorized people.
  10. api_protect_course_script(true);
  11. /* Libraries & config files */
  12. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  13. /* MAIN CODE */
  14. $group_id = api_get_group_id();
  15. $user_id = api_get_user_id();
  16. $current_group = GroupManager:: get_group_properties($group_id);
  17. // regroup table names for maintenance purpose
  18. if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
  19. api_not_allowed(true);
  20. }
  21. $tbl_stats_exercices_temp = Database:: get_main_table(track_e_exercices_temp);
  22. //on vide la table temp qui recoit les examen complétés
  23. $query = "TRUNCATE TABLE $tbl_stats_exercices_temp ";
  24. $result = Database::query($query);
  25. if (empty($current_group)) {
  26. api_not_allowed(true);
  27. }
  28. $this_section = SECTION_COURSES;
  29. $nameTools = get_lang('suivi_de');
  30. $interbreadcrumb[] = ['url' => 'group.php', 'name' => get_lang('Groups')];
  31. $forums_of_groups = get_forums_of_group($current_group['id']);
  32. $forum_state_public = 0;
  33. if (is_array($forums_of_groups)) {
  34. foreach ($forums_of_groups as $key => $value) {
  35. if ($value['forum_group_public_private'] == 'public') {
  36. $forum_state_public = 1;
  37. }
  38. }
  39. }
  40. if ($current_group['doc_state'] != 1 &&
  41. $current_group['calendar_state'] != 1 &&
  42. $current_group['work_state'] != 1 &&
  43. $current_group['announcements_state'] != 1 &&
  44. $current_group['wiki_state'] != 1 &&
  45. $current_group['chat_state'] != 1 &&
  46. $forum_state_public != 1
  47. ) {
  48. if (!api_is_allowed_to_edit(null, true) &&
  49. !GroupManager::is_user_in_group($user_id, $group_id)) {
  50. api_not_allowed($print_headers);
  51. }
  52. }
  53. /* Header */
  54. Display::display_header($nameTools.' '.Security::remove_XSS($current_group['name']), 'Group');
  55. Display::display_introduction_section(TOOL_GROUP);
  56. $course_code = api_get_course_id();
  57. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course(
  58. api_get_user_id(),
  59. $course_code
  60. );
  61. /*
  62. * List all the tutors of the current group
  63. */
  64. $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
  65. $tutor_info = '';
  66. if (count($tutors) == 0) {
  67. $tutor_info = get_lang('GroupNoneMasc');
  68. } else {
  69. isset($origin) ? $my_origin = $origin : $my_origin = '';
  70. $tutor_info .= '<ul class="thumbnails">';
  71. foreach ($tutors as $index => $tutor) {
  72. $tab_user_info = api_get_user_info($tutor['user_id']);
  73. $username = api_htmlentities(sprintf(get_lang('LoginX'), $tab_user_info['username']), ENT_QUOTES);
  74. $image_path = UserManager::get_user_picture_path_by_id($tutor['user_id'], 'web', false, true);
  75. $image_repository = $image_path['dir'];
  76. $existing_image = $image_path['file'];
  77. $completeName = api_get_person_name($tutor['firstname'], $tutor['lastname']);
  78. $photo = '<img src="'.$image_repository.$existing_image.'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
  79. $tutor_info .= '<li><a href="'.api_get_path(
  80. WEB_CODE_PATH
  81. ).'user/userInfo.php?origin='.$my_origin.'&amp;uInfo='.$tutor['user_id'].'">'.
  82. $photo.'&nbsp;'.$completeName.'</a></li>';
  83. }
  84. $tutor_info .= '</ul>';
  85. }
  86. echo Display::page_subheader(get_lang('GroupTutors'));
  87. if (!empty($tutor_info)) {
  88. echo $tutor_info;
  89. }
  90. /*
  91. * List all the members of the current group
  92. */
  93. echo '<div class="actions">';
  94. $now = date('Y-m-d');
  95. echo '&nbsp;Le '.$now.' <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang(
  96. 'Print'
  97. ).'</a>';
  98. echo '&nbsp; <a target="_blank" href="save_diff_all.php"><img src="'.api_get_path(
  99. WEB_IMG_PATH
  100. ).'addd.gif" border="0" />'.get_lang('save_diff_all').'</a>';
  101. echo '</div>';
  102. $table = new SortableTable(
  103. 'group_users',
  104. 'get_number_of_group_users',
  105. 'get_group_user_data',
  106. (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1
  107. );
  108. //$table -> display();
  109. $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  110. $my_origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  111. $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
  112. $parameters = ['cidReq' => $my_cidreq, 'origin' => $my_origin, 'gidReq' => $my_gidreq];
  113. $table->set_additional_parameters($parameters);
  114. $table->set_header(1, get_lang('OfficialCode'), false, 'align="center"');
  115. if (api_is_western_name_order()) {
  116. $table->set_header(2, get_lang('LastName'));
  117. $table->set_header(3, get_lang('FirstName'));
  118. } else {
  119. $table->set_header(2, get_lang('LastName'));
  120. $table->set_header(3, get_lang('FirstName'));
  121. }
  122. //the order of these calls is important
  123. $table->set_column_filter(2, 'user_name_filter');
  124. $table->set_column_filter(3, 'user_name_filter');
  125. $table->set_header(4, get_lang('Examen'), false);
  126. //the order of these calls is important
  127. $table->set_column_filter(2, 'user_name_filter');
  128. $table->set_column_filter(3, 'user_name_filter');
  129. $table->set_header(4, get_lang('Examen'), false);
  130. $table->set_header(5, get_lang('LatestLogin'), false, 'align="center"');
  131. $table->set_header(6, get_lang('time_tot'), false, 'align="center"');
  132. $table->set_header(7, get_lang('jours_complet'), false, 'align="center"');
  133. $table->set_header(8, get_lang('diff_horaire'), false, 'align="center"');
  134. $table->set_header(9, get_lang('save_diff'), false, 'align="center"');
  135. $table->set_header(10, get_lang('GroupCalendar'), false, 'align="center"');
  136. $table->set_header(11, get_lang('Details'), false);
  137. // Database table definition
  138. $table_group_user = Database:: get_course_table(TABLE_GROUP_USER);
  139. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  140. // $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  141. $tbl_personal_agenda = Database:: get_main_table(TABLE_PERSONAL_AGENDA);
  142. $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  143. $tbl_course_user = Database:: get_main_table(TABLE_MAIN_COURSE_USER);
  144. $tbl_stats_exercices = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  145. $tbl_stats_exercices_temp = Database:: get_main_table(track_e_exercices_temp);
  146. $tbl_group_course_info = Database:: get_course_table(TABLE_GROUP);
  147. $course_id = api_get_course_int_id();
  148. //on trouve le vrai groupID
  149. $sql = "SELECT iid FROM ".$tbl_group_course_info."
  150. WHERE c_id=".$course_id." and id=".$current_group['id'];
  151. $current_group_result = Database::query($sql);
  152. $current_group = Database::fetch_assoc($current_group_result)['iid'];
  153. //on trouve les user dans le groupe
  154. $sql = "SELECT *
  155. FROM ".$table_user." user, ".$table_group_user." group_rel_user
  156. WHERE group_rel_user.c_id = $course_id AND group_rel_user.user_id = user.user_id
  157. AND group_rel_user.group_id = ".$current_group." order by lastname
  158. ";
  159. $result = Database::query($sql);
  160. // Francois Belisle Kezber
  161. // Le TableDisplay contient une fonction qui set les headers... les headers sont plac�s dans la Row 0... Ce qui ecrase le contenue
  162. // le la vrai row 0... Il faut donc ajouter un empty record a la row 0 qui se fera ecras� par lesh headers plutot que le premier record
  163. // en ajoutant un empty record, ca fonctionne, mais il faut trouver pourquoi les headers ecrasent le premier record
  164. $row = [];
  165. $row[] = $student_datas['official_code'];
  166. $row[] = $student_datas['lastname'];
  167. $row[] = $student_datas['firstname'];
  168. $row[] = substr_replace($exampass, '', '0', '2');
  169. $row[] = $last_connection_date;
  170. $row[] = $time_tot;
  171. $row[] = $Total;
  172. $row[] = '<center>'.$sing.''.$diff.'&nbsp;'.$Days.''.$avertissement.'</font></b></center>';
  173. $row[] = '<center><a target="_blank" href="save_diff.php?student='.$user_in_groupe.'&diff='.$ajout.''.$diff.'"><img src="'.api_get_path(
  174. WEB_IMG_PATH
  175. ).'addd.gif" border="0" /></a></center>';
  176. $row[] = '<center><a target="_blank" href="suivi_myagenda.php?user_id='.$user_in_groupe.'&action=view&view=personal&firstname='.$student_datas['firstname'].'&name='.$student_datas['lastname'].'"><img src="'.api_get_path(
  177. WEB_IMG_PATH
  178. ).'calendar_week.gif" border="0" /></a></center>';
  179. $row[] = '<center><a target="_blank" href="../mySpace/myStudents.php?student='.$user_in_groupe.'"><img src="'.api_get_path(
  180. WEB_IMG_PATH
  181. ).'2rightarrow.gif" border="0" /></a></center>';
  182. $all_datas[] = $row;
  183. foreach ($all_datas as $row) {
  184. $table->addRow($row);
  185. }
  186. while ($resulta = Database::fetch_array($result)) {
  187. $user_in_groupe = $resulta['user_id'];
  188. unset($all_datas);
  189. //on cherche les examens
  190. $sqlexam = "SELECT mod_no
  191. FROM $tbl_stats_exercices
  192. WHERE exe_user_id = '$user_in_groupe'
  193. AND c_id = 0 AND (score_ex = 'SU' || score_rep1 = 'SU' || score_rep2 ='SU')
  194. ORDER BY mod_no ASC";
  195. $resultexam = Database::query($sqlexam);
  196. while ($a_exam = Database::fetch_array($resultexam)) {
  197. $exam = "$exam - $a_exam[0]";
  198. }
  199. Database::query(
  200. "INSERT INTO $tbl_stats_exercices_temp (id, exe_user_id, mod_passed) VALUES('', '$user_in_groupe', '$exam') "
  201. );
  202. //fin de exam
  203. //on compte le nombre de m% dans l'agenda pour chaque module
  204. /*
  205. $sqljtot = "SELECT COUNT( * ) AS TOT
  206. FROM $tbl_personal_agenda
  207. WHERE user = '$user_in_groupe'
  208. And title like 'm%'
  209. ";
  210. $resultjt = Database::query($sqljtot);
  211. while($jtot = mysql_fetch_array($resultjt))
  212. {
  213. $jour_realise_tot = ($jour_realise + $jtot['TOT'])/ 2;
  214. }
  215. //fin des jour de l'agenda
  216. */
  217. $course_code = $_course['id'];
  218. $student_datas = api_get_user_info($user_in_groupe);
  219. // affichage des jours complétés dans les parcours par chaque élève
  220. //on recherche les cours où sont inscrit les user
  221. $sql2 = "SELECT c_id, user_id
  222. FROM course_rel_user
  223. WHERE user_id = '$user_in_groupe'
  224. ";
  225. $result2 = Database::query($sql2);
  226. $Total = 0;
  227. while ($a_courses = Database::fetch_array($result2)) {
  228. $Courses_code = $a_courses['c_id'];
  229. $Courses_rel_user_id = $a_courses['user_id'];
  230. //on sort le temps passé dans chaque cours
  231. $sql = "SELECT SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds
  232. FROM track_e_course_access
  233. WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) AND c_id = $course_id AND user_id = '$user_in_groupe'
  234. ";
  235. //echo($sql);
  236. $rs = Database::query($sql);
  237. $row2 = Database::fetch_array($rs);
  238. $nb_secondes = $row2['nb_seconds'];
  239. $time_tot1 += $nb_secondes;
  240. //convertion secondes en temps
  241. $time_tot = api_time_to_hms($time_tot1);
  242. //on sort le c_id avec le code du cours
  243. //$sql8 = "SELECT *
  244. // FROM course
  245. // WHERE id = '$Courses_code'
  246. // ";
  247. // $result8 = Database::query($sql8);
  248. // $course_code_id = Database::fetch_array($result8) ;
  249. $c_id = $Courses_code;
  250. //pours chaque cours dans lequel il est inscrit, on cherche les jours complétés
  251. $Req3 = "SELECT *
  252. FROM c_lp_view
  253. WHERE user_id = '$Courses_rel_user_id'
  254. AND c_id = '$c_id'
  255. ";
  256. $res3 = Database::query($Req3);
  257. while ($result3 = Database::fetch_array($res3)) {
  258. $lp_id = $result3['lp_id'];
  259. $lp_id_view = $result3['id'];
  260. $c_id_view = $result3['c_id'];
  261. $Req4 = "SELECT id, lp_id ,title ,item_type
  262. FROM c_lp_item
  263. WHERE lp_id = '$lp_id'
  264. AND title LIKE '(+)%'
  265. AND c_id = '$c_id_view'
  266. AND item_type = 'document'
  267. ";
  268. $res4 = Database::query($Req4);
  269. while ($resulta4 = Database::fetch_array($res4)) {
  270. $lp_item_id = $resulta4['id'];
  271. $Req5 = " SELECT Max(id)
  272. FROM c_lp_item_view
  273. WHERE lp_item_id = '$lp_item_id'
  274. AND lp_view_id = '$lp_id_view'
  275. AND c_id = '$c_id_view'
  276. AND status = 'completed'
  277. ";
  278. $res5 = Database::query($Req5);
  279. while ($resul5 = Database::fetch_array($res5)) {
  280. $max = $resul5['0'];
  281. $Req6 = "SELECT COUNT( id )
  282. FROM c_lp_item_view
  283. WHERE id = '$max'
  284. AND c_id = '$c_id_view'
  285. ";
  286. $res6 = Database::query($Req6);
  287. while ($resultat6 = Database::fetch_array($res6)) {
  288. $Total = $Total + $resultat6[0];
  289. }
  290. }
  291. }
  292. }
  293. }
  294. // fin affichage des jours complétés dans les parcours par chaque élève
  295. // on recherche les exam sauvegardé dans la table temp
  296. $sqlexamtot = "SELECT mod_passed
  297. FROM $tbl_stats_exercices_temp
  298. WHERE exe_user_id = '$user_in_groupe'";
  299. $resultexamtot = Database::query($sqlexamtot);
  300. $a_examtot = Database::fetch_array($resultexamtot);
  301. $exampass = $a_examtot['mod_passed'];
  302. //on trouve le nombre dans l'agenda selon la date d'aujourdhui
  303. //si rien n'est inscrit cette journée dans l'agenda, recule de -1
  304. unset($jour_agenda);
  305. $tour = -1;
  306. while ($jour_agenda == '') {
  307. $tour++;
  308. $date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $tour, date("Y")));
  309. $sql4 = "SELECT * FROM $tbl_personal_agenda
  310. WHERE user = '$user_in_groupe' AND
  311. text='Pour le calendrier, ne pas effacer'
  312. AND date like '".$date." %:%'
  313. ";
  314. $result4 = Database::query($sql4);
  315. $res4 = Database::fetch_array($result4);
  316. $jour_agenda = $res4['title'];
  317. if ($tour > 300) {
  318. break;
  319. }
  320. }
  321. //on affiche la différence
  322. $diff = $jour_agenda - $Total;
  323. if ($diff > 0) {
  324. $sing = '<b><font color=#CC0000>';
  325. } else {
  326. $sing = '<b><font color=#008000>';
  327. }
  328. if ($diff > 0) {
  329. $avertissement = get_lang('retard');
  330. } else {
  331. $avertissement = get_lang('avance');
  332. }
  333. if ($diff > 0) {
  334. $ajout = '-';
  335. } else {
  336. $ajout = '';
  337. }
  338. $diff = abs($diff);
  339. $last_connection_date = Tracking:: get_last_connection_date($user_in_groupe, true);
  340. if ($last_connection_date == '') {
  341. $last_connection_date = get_lang('NoConnexion');
  342. }
  343. // on présente tous les résultats
  344. $row = [];
  345. $row[] = $student_datas['official_code'];
  346. $row[] = $student_datas['lastname'];
  347. $row[] = $student_datas['firstname'];
  348. $row[] = substr_replace($exampass, '', '0', '2');
  349. $row[] = $last_connection_date;
  350. $row[] = $time_tot;
  351. $row[] = $Total;
  352. $row[] = '<center>'.$sing.''.$diff.'&nbsp;'.$Days.''.$avertissement.'</font></b></center>';
  353. $row[] = '<center><a target="_blank" href="save_diff.php?student='.$user_in_groupe.'&diff='.$ajout.''.$diff.'"><img src="'.api_get_path(
  354. WEB_IMG_PATH
  355. ).'addd.gif" border="0" /></a></center>';
  356. $row[] = '<center><a target="_blank" href="suivi_myagenda.php?user_id='.$user_in_groupe.'&action=view&view=personal&firstname='.$student_datas['firstname'].'&name='.$student_datas['lastname'].'"><img src="'.api_get_path(
  357. WEB_IMG_PATH
  358. ).'calendar_week.gif" border="0" /></a></center>';
  359. $row[] = '<center><a target="_blank" href="../mySpace/myStudents.php?student='.$user_in_groupe.'"><img src="'.api_get_path(
  360. WEB_IMG_PATH
  361. ).'2rightarrow.gif" border="0" /></a></center>';
  362. $all_datas[] = $row;
  363. foreach ($all_datas as $row) {
  364. $table->addRow($row);
  365. }
  366. }
  367. $table->display();
  368. echo $precision_time;
  369. /**
  370. * Return user profile link around the given user name.
  371. *
  372. * The parameters use a trick of the sorteable table, where the first param is
  373. * the original value of the column
  374. *
  375. * @param string User name (value of the column at the time of calling)
  376. * @param string URL parameters
  377. * @param array Row of the "sortable table" as it is at the time of function call - we extract the user ID from
  378. * there
  379. *
  380. * @return string HTML link
  381. */
  382. function user_name_filter($name, $url_params, $row)
  383. {
  384. $tab_user_info = api_get_user_info($row[0]);
  385. $username = api_htmlentities(sprintf(get_lang('LoginX'), $tab_user_info['username']), ENT_QUOTES);
  386. return '<a href="../user/userInfo.php?uInfo='.$row[0].'&amp;'.$url_params.'" title="'.$username.'">'.$name.'</a>';
  387. }
  388. // Footer
  389. $orig = isset($origin) ? $origin : '';
  390. if ($orig != 'learnpath') {
  391. Display::display_footer();
  392. }