tracking.lib.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. // $Id: tracking.lib.php 2007-28-02 15:51:53
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) various contributors
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This is the tracking library for Dokeos.
  23. * Include/require it in your code to use its functionality.
  24. *
  25. * @package dokeos.library
  26. ==============================================================================
  27. */
  28. class Tracking {
  29. /**
  30. * Calculates the time spent on the platform by a user
  31. * @param integer $user_id the user id
  32. * @return timestamp $nb_seconds
  33. */
  34. function get_time_spent_on_the_platform($user_id) {
  35. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  36. $sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . '
  37. WHERE login_user_id = ' . intval($user_id).' AND logout_date IS NOT NULL';
  38. $rs = api_sql_query($sql);
  39. $nb_seconds = 0;
  40. while ($a_connections = mysql_fetch_array($rs)) {
  41. $s_login_date = $a_connections["login_date"];
  42. $s_logout_date = $a_connections["logout_date"];
  43. $i_timestamp_login_date = strtotime($s_login_date);
  44. $i_timestamp_logout_date = strtotime($s_logout_date);
  45. $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date);
  46. }
  47. return $nb_seconds;
  48. }
  49. /**
  50. * Calculates the time spent on the course
  51. * @param integer $user_id the user id
  52. * @param string $course_code the course code
  53. * @return timestamp $nb_seconds
  54. */
  55. function get_time_spent_on_the_course($user_id, $course_code) {
  56. // protect datas
  57. $student_id = intval($student_id);
  58. $course_code = addslashes($course_code);
  59. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  60. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  61. WHERE user_id = ' . intval($user_id) . '
  62. AND course_code="' . $course_code . '"';
  63. $rs = api_sql_query($sql);
  64. $nb_seconds = 0;
  65. while ($a_connections = mysql_fetch_array($rs)) {
  66. $s_login_date = $a_connections["login_course_date"];
  67. $s_logout_date = $a_connections["logout_course_date"];
  68. $i_timestamp_login_date = strtotime($s_login_date);
  69. $i_timestamp_logout_date = strtotime($s_logout_date);
  70. $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date);
  71. }
  72. return $nb_seconds;
  73. }
  74. function get_last_connection_date($student_id, $warning_message = false) {
  75. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  76. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  77. WHERE login_user_id = ' . intval($student_id) . '
  78. ORDER BY login_date DESC LIMIT 0,1';
  79. $rs = api_sql_query($sql);
  80. if ($last_login_date = mysql_result($rs, 0, 0)) {
  81. if (!$warning_message) {
  82. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  83. } else {
  84. $timestamp = strtotime($last_login_date);
  85. $currentTimestamp = mktime();
  86. //If the last connection is > than 7 days, the text is red
  87. //345600 = 7 days in seconds
  88. if ($currentTimestamp - $timestamp > 604800) {
  89. return '<span style="color: #F00;">' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . '</span>';
  90. } else {
  91. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  92. }
  93. }
  94. } else {
  95. return false;
  96. }
  97. }
  98. function get_last_connection_date_on_the_course($student_id, $course_code) {
  99. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  100. $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . '
  101. WHERE user_id = ' . intval($student_id) . '
  102. AND course_code = "' . mysql_real_escape_string($course_code) . '"
  103. ORDER BY login_course_date DESC LIMIT 0,1';
  104. $rs = api_sql_query($sql);
  105. if ($last_login_date = mysql_result($rs, 0, 0)) {
  106. $timestamp = strtotime($last_login_date);
  107. $currentTimestamp = mktime();
  108. //If the last connection is > than 7 days, the text is red
  109. //345600 = 7 days in seconds
  110. if ($currentTimestamp - $timestamp > 604800) {
  111. return '<span style="color: #F00;">' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . ' <a href="'.api_get_path(REL_CLARO_PATH).'announcements/announcements.php?action=add&remind_inactive='.$student_id.'" title="'.get_lang('RemindInactiveUser').'"><img align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" /></a></span>';
  112. } else {
  113. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  114. }
  115. } else {
  116. return false;
  117. }
  118. }
  119. function count_course_per_student($user_id) {
  120. $user_id = intval($user_id);
  121. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  122. $tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  123. $sql = 'SELECT DISTINCT course_code
  124. FROM ' . $tbl_course_rel_user . '
  125. WHERE user_id = ' . $user_id;
  126. $rs = api_sql_query($sql, __FILE__, __LINE__);
  127. $nb_courses = mysql_num_rows($rs);
  128. $sql = 'SELECT DISTINCT course_code
  129. FROM ' . $tbl_session_course_rel_user . '
  130. WHERE id_user = ' . $user_id;
  131. $rs = api_sql_query($sql, __FILE__, __LINE__);
  132. $nb_courses += mysql_num_rows($rs);
  133. return $nb_courses;
  134. }
  135. function get_avg_student_progress($student_id, $course_code) {
  136. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  137. // protect datas
  138. $student_id = intval($student_id);
  139. $course_code = addslashes($course_code);
  140. // get the informations of the course
  141. $a_course = CourseManager :: get_course_information($course_code);
  142. // table definition
  143. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']);
  144. $tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $a_course['db_name']);
  145. $tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $a_course['db_name']);
  146. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']);
  147. //get the list of learning paths
  148. $sql = 'SELECT id FROM ' . $tbl_course_lp;
  149. $rs = api_sql_query($sql, __FILE__, __LINE__);
  150. $nb_lp = mysql_num_rows($rs);
  151. $avg_progress = 0;
  152. if ($nb_lp > 0) {
  153. while ($lp = Database :: fetch_array($rs)) {
  154. // get the progress in learning pathes
  155. $sqlProgress = "SELECT progress
  156. FROM " . $tbl_course_lp_view . " AS lp_view
  157. WHERE lp_view.user_id = " . $student_id . "
  158. AND lp_view.lp_id = " . $lp['id'] . "
  159. ";
  160. $resultItem = api_sql_query($sqlProgress, __FILE__, __LINE__);
  161. if(Database::num_rows($resultItem)>0)
  162. {
  163. $avg_progress += mysql_result($resultItem, 0, 0);
  164. }
  165. }
  166. $avg_progress = round($avg_progress / $nb_lp, 1);
  167. }
  168. return $avg_progress;
  169. }
  170. function get_avg_student_score($student_id, $course_code) {
  171. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  172. $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  173. $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  174. $course = CourseManager :: get_course_information($course_code);
  175. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']);
  176. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']);
  177. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']);
  178. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']);
  179. $sql_course_lp = 'SELECT id FROM '.$lp_table;
  180. $sql_result_lp = api_sql_query($sql_course_lp, __FILE__, __LINE__);
  181. $lp_scorm_score_total = 0;
  182. $lp_scorm_weighting_total = 0;
  183. if(Database::num_rows($sql_result_lp)>0){
  184. //Scorm
  185. while($a_learnpath = mysql_fetch_array($sql_result_lp)){
  186. $sql = 'SELECT id, max_score
  187. FROM '.$lp_item_table.' AS lp_item
  188. WHERE lp_id='.$a_learnpath['id'].'
  189. AND item_type="sco" LIMIT 1';
  190. $rs_lp_item_id_scorm = api_sql_query($sql, __FILE__, __LINE__);
  191. if(Database::num_rows($rs_lp_item_id_scorm)>0){
  192. $lp_item_id = mysql_result($rs_lp_item_id_scorm,0,'id');
  193. $lp_item__max_score = mysql_result($rs_lp_item_id_scorm,0,'max_score');
  194. //We get the last view id of this LP
  195. $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"';
  196. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  197. $lp_view_id = mysql_result($rs_last_lp_view_id,0,'id');
  198. $sql='SELECT SUM(score)/count(lp_item_id) as score FROM '.$lp_item_view_table.' WHERE lp_view_id="'.$lp_view_id.'" GROUP BY lp_view_id';
  199. $rs_score = api_sql_query($sql, __FILE__, __LINE__);
  200. if(Database::num_rows($rs_score)>0)
  201. {
  202. $lp_scorm_score = mysql_result($rs_score,0,'score');
  203. $lp_scorm_score = ($lp_scorm_score / $lp_item__max_score) * 100;
  204. $lp_scorm_score_total+=$lp_scorm_score;
  205. $lp_scorm_weighting_total+=100;
  206. }
  207. }
  208. }
  209. mysql_data_seek($sql_result_lp,0);
  210. //Quizz in LP
  211. while($a_learnpath = Database::fetch_array($sql_result_lp)){
  212. $sql = 'SELECT id as item_id, max_score
  213. FROM '.$lp_item_table.' AS lp_item
  214. WHERE lp_id='.$a_learnpath['id'].'
  215. AND item_type="quiz"';
  216. $rsItems = api_sql_query($sql, __FILE__, __LINE__);
  217. //We get the last view id of this LP
  218. $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"';
  219. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  220. $lp_view_id = mysql_result($rs_last_lp_view_id,0,'id');
  221. $total_score = $total_weighting = 0;
  222. while($item = Database :: fetch_array($rsItems, 'ASSOC'))
  223. {
  224. $sql = 'SELECT score as student_score
  225. FROM '.$lp_item_view_table.' as lp_view_item
  226. WHERE lp_view_item.lp_item_id = '.$item['item_id'].'
  227. AND lp_view_id = "'.$lp_view_id.'"
  228. ';
  229. $rsScores = api_sql_query($sql, __FILE__, __LINE__);
  230. if(Database::num_rows($rsScores)>0)
  231. {
  232. $total_score += mysql_result($rsScores, 0, 0);
  233. $total_weighting += $item['max_score'];
  234. $lp_scorm_score_total += ($total_score/$total_weighting)*100;
  235. $lp_scorm_weighting_total+=100;
  236. }
  237. }
  238. }
  239. }
  240. $totalScore = $lp_scorm_score_total;
  241. $pourcentageScore = 0;
  242. if($lp_scorm_weighting_total>0)
  243. {
  244. $pourcentageScore = round(($totalScore * 100) / $lp_scorm_weighting_total);
  245. }
  246. return $pourcentageScore;
  247. }
  248. /**
  249. * gets the list of students followed by coach
  250. * @param integer $coach_id the id of the coach
  251. * @return Array the list of students
  252. */
  253. function get_student_followed_by_coach($coach_id) {
  254. $coach_id = intval($coach_id);
  255. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  256. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  257. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  258. $a_students = array ();
  259. //////////////////////////////////////////////////////////////
  260. // At first, courses where $coach_id is coach of the course //
  261. //////////////////////////////////////////////////////////////
  262. $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  263. $result = api_sql_query($sql);
  264. while ($a_courses = mysql_fetch_array($result)) {
  265. $course_code = $a_courses["course_code"];
  266. $id_session = $a_courses["id_session"];
  267. $sql = "SELECT distinct srcru.id_user
  268. FROM $tbl_session_course_user AS srcru
  269. WHERE course_code='$course_code' AND id_session='$id_session'";
  270. $rs = api_sql_query($sql);
  271. while ($row = mysql_fetch_array($rs)) {
  272. $a_students[$row['id_user']] = $row['id_user'];
  273. }
  274. }
  275. //////////////////////////////////////////////////////////////
  276. // Then, courses where $coach_id is coach of the session //
  277. //////////////////////////////////////////////////////////////
  278. $sql = 'SELECT session_course_user.id_user
  279. FROM ' . $tbl_session_course_user . ' as session_course_user
  280. INNER JOIN ' . $tbl_session_course . ' as session_course
  281. ON session_course.course_code = session_course_user.course_code
  282. AND session_course_user.id_session = session_course.id_session
  283. INNER JOIN ' . $tbl_session . ' as session
  284. ON session.id = session_course.id_session
  285. AND session.id_coach = ' . $coach_id;
  286. $result = api_sql_query($sql);
  287. while ($row = mysql_fetch_array($result)) {
  288. $a_students[$row['id_user']] = $row['id_user'];
  289. }
  290. return $a_students;
  291. }
  292. function get_student_followed_by_coach_in_a_session($id_session, $coach_id) {
  293. $coach_id = intval($coach_id);
  294. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  295. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  296. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  297. $a_students = array ();
  298. //////////////////////////////////////////////////////////////
  299. // At first, courses where $coach_id is coach of the course //
  300. //////////////////////////////////////////////////////////////
  301. $sql = 'SELECT course_code FROM ' . $tbl_session_course . ' WHERE id_session="' . $id_session . '" AND id_coach=' . $coach_id;
  302. $result = api_sql_query($sql);
  303. while ($a_courses = mysql_fetch_array($result)) {
  304. $course_code = $a_courses["course_code"];
  305. $sql = "SELECT distinct srcru.id_user
  306. FROM $tbl_session_course_user AS srcru
  307. WHERE course_code='$course_code' and id_session = '" . $id_session . "'";
  308. $rs = api_sql_query($sql, __FILE__, __LINE__);
  309. while ($row = mysql_fetch_array($rs)) {
  310. $a_students[$row['id_user']] = $row['id_user'];
  311. }
  312. }
  313. //////////////////////////////////////////////////////////////
  314. // Then, courses where $coach_id is coach of the session //
  315. //////////////////////////////////////////////////////////////
  316. $dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
  317. $result = api_sql_query($dsl_session_coach, __FILE__, __LINE__);
  318. //He is the session_coach so we select all the users in the session
  319. if (mysql_num_rows($result) > 0) {
  320. $sql = 'SELECT DISTINCT srcru.id_user FROM ' . $tbl_session_course_user . ' AS srcru WHERE id_session="' . $id_session . '"';
  321. $result = api_sql_query($sql);
  322. while ($row = mysql_fetch_array($result)) {
  323. $a_students[$row['id_user']] = $row['id_user'];
  324. }
  325. }
  326. return $a_students;
  327. }
  328. function is_allowed_to_coach_student($coach_id, $student_id) {
  329. $coach_id = intval($coach_id);
  330. $student_id = intval($student_id);
  331. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  332. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  333. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  334. //////////////////////////////////////////////////////////////
  335. // At first, courses where $coach_id is coach of the course //
  336. //////////////////////////////////////////////////////////////
  337. $sql = 'SELECT 1
  338. FROM ' . $tbl_session_course_user . ' AS session_course_user
  339. INNER JOIN ' . $tbl_session_course . ' AS session_course
  340. ON session_course.course_code = session_course_user.course_code
  341. AND id_coach=' . $coach_id . '
  342. WHERE id_user=' . $student_id;
  343. $result = api_sql_query($sql, __FILE__, __LINE__);
  344. if (mysql_num_rows($result) > 0) {
  345. return true;
  346. }
  347. //////////////////////////////////////////////////////////////
  348. // Then, courses where $coach_id is coach of the session //
  349. //////////////////////////////////////////////////////////////
  350. $sql = 'SELECT session_course_user.id_user
  351. FROM ' . $tbl_session_course_user . ' as session_course_user
  352. INNER JOIN ' . $tbl_session_course . ' as session_course
  353. ON session_course.course_code = session_course_user.course_code
  354. INNER JOIN ' . $tbl_session . ' as session
  355. ON session.id = session_course.id_session
  356. AND session.id_coach = ' . $coach_id . '
  357. WHERE id_user = ' . $student_id;
  358. $result = api_sql_query($sql, __FILE__, __LINE__);
  359. if (mysql_num_rows($result) > 0) {
  360. return true;
  361. }
  362. return false;
  363. }
  364. function get_courses_followed_by_coach($coach_id, $id_session = '') {
  365. $coach_id = intval($coach_id);
  366. if (!empty ($id_session))
  367. $id_session = intval($id_session);
  368. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  369. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  370. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  371. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  372. //////////////////////////////////////////////////////////////
  373. // At first, courses where $coach_id is coach of the course //
  374. //////////////////////////////////////////////////////////////
  375. $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  376. if (!empty ($id_session))
  377. $sql .= ' AND id_session=' . $id_session;
  378. $result = api_sql_query($sql, __FILE__, __LINE__);
  379. while ($row = mysql_fetch_array($result)) {
  380. $a_courses[$row['course_code']] = $row['course_code'];
  381. }
  382. //////////////////////////////////////////////////////////////
  383. // Then, courses where $coach_id is coach of the session //
  384. //////////////////////////////////////////////////////////////
  385. $sql = 'SELECT DISTINCT session_course.course_code
  386. FROM ' . $tbl_session_course . ' as session_course
  387. INNER JOIN ' . $tbl_session . ' as session
  388. ON session.id = session_course.id_session
  389. AND session.id_coach = ' . $coach_id . '
  390. INNER JOIN ' . $tbl_course . ' as course
  391. ON course.code = session_course.course_code';
  392. if (!empty ($id_session))
  393. $sql .= ' WHERE session_course.id_session=' . $id_session;
  394. $result = api_sql_query($sql, __FILE__, __LINE__);
  395. while ($row = mysql_fetch_array($result)) {
  396. $a_courses[$row['course_code']] = $row['course_code'];
  397. }
  398. return $a_courses;
  399. }
  400. function get_sessions_coached_by_user($coach_id) {
  401. // table definition
  402. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  403. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  404. // protect datas
  405. $coach_id = intval($coach_id);
  406. // session where we are general coach
  407. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  408. FROM ' . $tbl_session . '
  409. WHERE id_coach=' . $coach_id;
  410. $rs = api_sql_query($sql);
  411. while ($row = mysql_fetch_array($rs)) {
  412. $a_sessions[$row["id"]] = $row;
  413. }
  414. // session where we are coach of a course
  415. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  416. FROM ' . $tbl_session . ' as session
  417. INNER JOIN ' . $tbl_session_course . ' as session_course
  418. ON session.id = session_course.id_session
  419. AND session_course.id_coach=' . $coach_id;
  420. $rs = api_sql_query($sql);
  421. while ($row = mysql_fetch_array($rs)) {
  422. $a_sessions[$row["id"]] = $row;
  423. }
  424. foreach ($a_sessions as & $session) {
  425. if ($session['date_start'] == '0000-00-00') {
  426. $session['status'] = get_lang('SessionActive');
  427. }
  428. else {
  429. $date_start = explode('-', $session['date_start']);
  430. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  431. $date_end = explode('-', $session['date_end']);
  432. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  433. if ($time_start < time() && time() < $time_end) {
  434. $session['status'] = get_lang('SessionActive');
  435. }
  436. else{
  437. if (time() < $time_start) {
  438. $session['status'] = get_lang('SessionFuture');
  439. }
  440. else{
  441. if (time() > $time_end) {
  442. $session['status'] = get_lang('SessionPast');
  443. }
  444. }
  445. }
  446. }
  447. }
  448. return $a_sessions;
  449. }
  450. function get_courses_list_from_session($session_id) {
  451. //protect datas
  452. $session_id = intval($session_id);
  453. // table definition
  454. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  455. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  456. $sql = 'SELECT DISTINCT course_code, id_coach
  457. FROM ' . $tbl_session_course . '
  458. WHERE id_session=' . $session_id;
  459. $rs = api_sql_query($sql, __FILE__, __LINE__);
  460. $a_courses = array ();
  461. while ($row = mysql_fetch_array($rs)) {
  462. $a_courses[$row['course_code']] = $row;
  463. }
  464. return $a_courses;
  465. }
  466. function count_student_assignments($student_id, $course_code) {
  467. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  468. // protect datas
  469. $student_id = intval($student_id);
  470. $course_code = addslashes($course_code);
  471. // get the informations of the course
  472. $a_course = CourseManager :: get_course_information($course_code);
  473. // table definition
  474. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']);
  475. $sql = 'SELECT 1
  476. FROM ' . $tbl_item_property . '
  477. WHERE insert_user_id=' . $student_id . '
  478. AND tool="work"';
  479. $rs = api_sql_query($sql, __LINE__, __FILE__);
  480. return mysql_num_rows($rs);
  481. }
  482. function count_student_messages($student_id, $course_code) {
  483. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  484. // protect datas
  485. $student_id = intval($student_id);
  486. $course_code = addslashes($course_code);
  487. // get the informations of the course
  488. $a_course = CourseManager :: get_course_information($course_code);
  489. // table definition
  490. $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  491. $sql = 'SELECT 1
  492. FROM ' . $tbl_messages . '
  493. WHERE poster_id=' . $student_id;
  494. $rs = api_sql_query($sql, __LINE__, __FILE__);
  495. return mysql_num_rows($rs);
  496. }
  497. function count_student_visited_links($student_id, $course_code) {
  498. // protect datas
  499. $student_id = intval($student_id);
  500. $course_code = addslashes($course_code);
  501. // table definition
  502. $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  503. $sql = 'SELECT 1
  504. FROM ' . $tbl_stats_links . '
  505. WHERE links_user_id=' . $student_id . '
  506. AND links_cours_id="' . $course_code . '"';
  507. $rs = api_sql_query($sql, __LINE__, __FILE__);
  508. return mysql_num_rows($rs);
  509. }
  510. function count_student_downloaded_documents($student_id, $course_code) {
  511. // protect datas
  512. $student_id = intval($student_id);
  513. $course_code = addslashes($course_code);
  514. // table definition
  515. $tbl_stats_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  516. $sql = 'SELECT 1
  517. FROM ' . $tbl_stats_documents . '
  518. WHERE down_user_id=' . $student_id . '
  519. AND down_cours_id="' . $course_code . '"';
  520. $rs = api_sql_query($sql, __LINE__, __FILE__);
  521. return mysql_num_rows($rs);
  522. }
  523. function get_course_list_in_session_from_student($user_id, $id_session) {
  524. $user_id = intval($user_id);
  525. $id_session = intval($id_session);
  526. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  527. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user="' . $user_id . '" AND id_session="' . $id_session . '"';
  528. $result = api_sql_query($sql, __LINE__, __FILE__);
  529. $a_courses = array ();
  530. while ($row = mysql_fetch_array($result)) {
  531. $a_courses[$row['course_code']] = $row['course_code'];
  532. }
  533. return $a_courses;
  534. }
  535. function get_inactives_students_in_course($course_code, $since, $session_id=0)
  536. {
  537. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  538. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  539. $inner = '';
  540. if($session_id!=0)
  541. {
  542. $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user
  543. ON stats_login.course_code = session_course_user.course_code
  544. AND session_course_user.id_session = '.intval($session_id).'
  545. AND session_course_user.id_user = stats_login.user_id ';
  546. }
  547. $sql = 'SELECT user_id, MAX(login_course_date) max_date FROM'.$tbl_track_login.' stats_login'.$inner.'
  548. GROUP BY user_id
  549. HAVING DATE_ADD(max_date, INTERVAL '.$since.' DAY) < NOW() ';
  550. $rs = api_sql_query($sql,__FILE__,__LINE__);
  551. $inactive_users = array();
  552. while($user = Database::fetch_array($rs))
  553. {
  554. $inactive_users[] = $user['user_id'];
  555. }
  556. return $inactive_users;
  557. }
  558. function count_login_per_student($student_id, $course_code) {
  559. $student_id = intval($student_id);
  560. $course_code = addslashes($course_code);
  561. $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  562. $sql = 'SELECT '.$student_id.'
  563. FROM ' . $tbl_course_rel_user . '
  564. WHERE access_user_id=' . $student_id . '
  565. AND access_cours_code="' . $course_code . '"';
  566. $rs = api_sql_query($sql, __FILE__, __LINE__);
  567. $nb_login = mysql_num_rows($rs);
  568. return $nb_login;
  569. }
  570. }
  571. ?>