tracking.lib.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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)) . '</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. $avg_progress += mysql_result($resultItem, 0, 0);
  162. }
  163. $avg_progress = round($avg_progress / $nb_lp, 1);
  164. }
  165. return $avg_progress;
  166. }
  167. function get_avg_student_score($student_id, $course_code) {
  168. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  169. $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  170. $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  171. $course = CourseManager :: get_course_information($course_code);
  172. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']);
  173. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']);
  174. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']);
  175. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']);
  176. $sql_course_lp = 'SELECT id FROM '.$lp_table;
  177. $sql_result_lp = api_sql_query($sql_course_lp, __FILE__, __LINE__);
  178. $lp_scorm_score_total = 0;
  179. $lp_scorm_weighting_total = 0;
  180. if(Database::num_rows($sql_result_lp)>0){
  181. //Scorm
  182. while($a_learnpath = mysql_fetch_array($sql_result_lp)){
  183. $sql = 'SELECT id, max_score
  184. FROM '.$lp_item_table.' AS lp_item
  185. WHERE lp_id='.$a_learnpath['id'].'
  186. AND item_type="sco" LIMIT 1';
  187. $rs_lp_item_id_scorm = api_sql_query($sql, __FILE__, __LINE__);
  188. if(Database::num_rows($rs_lp_item_id_scorm)>0){
  189. $lp_item_id = mysql_result($rs_lp_item_id_scorm,0,'id');
  190. $lp_item__max_score = mysql_result($rs_lp_item_id_scorm,0,'max_score');
  191. //We get the last view id of this LP
  192. $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"';
  193. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  194. $lp_view_id = mysql_result($rs_last_lp_view_id,0,'id');
  195. $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';
  196. $rs_score = api_sql_query($sql, __FILE__, __LINE__);
  197. $lp_scorm_score = mysql_result($rs_score,0,'score');
  198. $lp_scorm_score = ($lp_scorm_score / $lp_item__max_score) * 100;
  199. $lp_scorm_score_total+=$lp_scorm_score;
  200. $lp_scorm_weighting_total+=100;
  201. }
  202. }
  203. mysql_data_seek($sql_result_lp,0);
  204. //Quizz in LP
  205. while($a_learnpath = Database::fetch_array($sql_result_lp)){
  206. $sql = 'SELECT id as item_id, max_score
  207. FROM '.$lp_item_table.' AS lp_item
  208. WHERE lp_id='.$a_learnpath['id'].'
  209. AND item_type="quiz"';
  210. $rsItems = api_sql_query($sql, __FILE__, __LINE__);
  211. //We get the last view id of this LP
  212. $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"';
  213. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  214. $lp_view_id = mysql_result($rs_last_lp_view_id,0,'id');
  215. $total_score = $total_weighting = 0;
  216. while($item = Database :: fetch_array($rsItems, 'ASSOC'))
  217. {
  218. $sql = 'SELECT score as student_score
  219. FROM '.$lp_item_view_table.' as lp_view_item
  220. WHERE lp_view_item.lp_item_id = '.$item['item_id'].'
  221. AND lp_view_id = "'.$lp_view_id.'"
  222. ';
  223. $rsScores = api_sql_query($sql, __FILE__, __LINE__);
  224. $total_score += mysql_result($rsScores, 0, 0);
  225. $total_weighting += $item['max_score'];
  226. $lp_scorm_score_total += ($total_score/$total_weighting)*100;
  227. $lp_scorm_weighting_total+=100;
  228. }
  229. }
  230. }
  231. $totalScore = $lp_scorm_score_total;
  232. $totalWeighting = $lp_scorm_weighting_total + 100;
  233. $pourcentageScore = round(($totalScore * 100) / $totalWeighting);
  234. return $pourcentageScore;
  235. }
  236. /**
  237. * gets the list of students followed by coach
  238. * @param integer $coach_id the id of the coach
  239. * @return Array the list of students
  240. */
  241. function get_student_followed_by_coach($coach_id) {
  242. $coach_id = intval($coach_id);
  243. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  244. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  245. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  246. $a_students = array ();
  247. //////////////////////////////////////////////////////////////
  248. // At first, courses where $coach_id is coach of the course //
  249. //////////////////////////////////////////////////////////////
  250. $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  251. $result = api_sql_query($sql);
  252. while ($a_courses = mysql_fetch_array($result)) {
  253. $course_code = $a_courses["course_code"];
  254. $id_session = $a_courses["id_session"];
  255. $sql = "SELECT distinct srcru.id_user
  256. FROM $tbl_session_course_user AS srcru
  257. WHERE course_code='$course_code' AND id_session='$id_session'";
  258. $rs = api_sql_query($sql);
  259. while ($row = mysql_fetch_array($rs)) {
  260. $a_students[$row['id_user']] = $row['id_user'];
  261. }
  262. }
  263. //////////////////////////////////////////////////////////////
  264. // Then, courses where $coach_id is coach of the session //
  265. //////////////////////////////////////////////////////////////
  266. $sql = 'SELECT session_course_user.id_user
  267. FROM ' . $tbl_session_course_user . ' as session_course_user
  268. INNER JOIN ' . $tbl_session_course . ' as session_course
  269. ON session_course.course_code = session_course_user.course_code
  270. AND session_course_user.id_session = session_course.id_session
  271. INNER JOIN ' . $tbl_session . ' as session
  272. ON session.id = session_course.id_session
  273. AND session.id_coach = ' . $coach_id;
  274. $result = api_sql_query($sql);
  275. while ($row = mysql_fetch_array($result)) {
  276. $a_students[$row['id_user']] = $row['id_user'];
  277. }
  278. return $a_students;
  279. }
  280. function get_student_followed_by_coach_in_a_session($id_session, $coach_id) {
  281. $coach_id = intval($coach_id);
  282. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  283. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  284. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  285. $a_students = array ();
  286. //////////////////////////////////////////////////////////////
  287. // At first, courses where $coach_id is coach of the course //
  288. //////////////////////////////////////////////////////////////
  289. $sql = 'SELECT course_code FROM ' . $tbl_session_course . ' WHERE id_session="' . $id_session . '" AND id_coach=' . $coach_id;
  290. $result = api_sql_query($sql);
  291. while ($a_courses = mysql_fetch_array($result)) {
  292. $course_code = $a_courses["course_code"];
  293. $sql = "SELECT distinct srcru.id_user
  294. FROM $tbl_session_course_user AS srcru
  295. WHERE course_code='$course_code' and id_session = '" . $id_session . "'";
  296. $rs = api_sql_query($sql, __FILE__, __LINE__);
  297. while ($row = mysql_fetch_array($rs)) {
  298. $a_students[$row['id_user']] = $row['id_user'];
  299. }
  300. }
  301. //////////////////////////////////////////////////////////////
  302. // Then, courses where $coach_id is coach of the session //
  303. //////////////////////////////////////////////////////////////
  304. $dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
  305. $result = api_sql_query($dsl_session_coach, __FILE__, __LINE__);
  306. //He is the session_coach so we select all the users in the session
  307. if (mysql_num_rows($result) > 0) {
  308. $sql = 'SELECT DISTINCT srcru.id_user FROM ' . $tbl_session_course_user . ' AS srcru WHERE id_session="' . $id_session . '"';
  309. $result = api_sql_query($sql);
  310. while ($row = mysql_fetch_array($result)) {
  311. $a_students[$row['id_user']] = $row['id_user'];
  312. }
  313. }
  314. return $a_students;
  315. }
  316. function is_allowed_to_coach_student($coach_id, $student_id) {
  317. $coach_id = intval($coach_id);
  318. $student_id = intval($student_id);
  319. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  320. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  321. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  322. //////////////////////////////////////////////////////////////
  323. // At first, courses where $coach_id is coach of the course //
  324. //////////////////////////////////////////////////////////////
  325. $sql = 'SELECT 1
  326. FROM ' . $tbl_session_course_user . ' AS session_course_user
  327. INNER JOIN ' . $tbl_session_course . ' AS session_course
  328. ON session_course.course_code = session_course_user.course_code
  329. AND id_coach=' . $coach_id . '
  330. WHERE id_user=' . $student_id;
  331. $result = api_sql_query($sql, __FILE__, __LINE__);
  332. if (mysql_num_rows($result) > 0) {
  333. return true;
  334. }
  335. //////////////////////////////////////////////////////////////
  336. // Then, courses where $coach_id is coach of the session //
  337. //////////////////////////////////////////////////////////////
  338. $sql = 'SELECT session_course_user.id_user
  339. FROM ' . $tbl_session_course_user . ' as session_course_user
  340. INNER JOIN ' . $tbl_session_course . ' as session_course
  341. ON session_course.course_code = session_course_user.course_code
  342. INNER JOIN ' . $tbl_session . ' as session
  343. ON session.id = session_course.id_session
  344. AND session.id_coach = ' . $coach_id . '
  345. WHERE id_user = ' . $student_id;
  346. $result = api_sql_query($sql, __FILE__, __LINE__);
  347. if (mysql_num_rows($result) > 0) {
  348. return true;
  349. }
  350. return false;
  351. }
  352. function get_courses_followed_by_coach($coach_id, $id_session = '') {
  353. $coach_id = intval($coach_id);
  354. if (!empty ($id_session))
  355. $id_session = intval($id_session);
  356. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  357. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  358. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  359. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  360. //////////////////////////////////////////////////////////////
  361. // At first, courses where $coach_id is coach of the course //
  362. //////////////////////////////////////////////////////////////
  363. $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  364. if (!empty ($id_session))
  365. $sql .= ' AND id_session=' . $id_session;
  366. $result = api_sql_query($sql, __FILE__, __LINE__);
  367. while ($row = mysql_fetch_array($result)) {
  368. $a_courses[$row['course_code']] = $row['course_code'];
  369. }
  370. //////////////////////////////////////////////////////////////
  371. // Then, courses where $coach_id is coach of the session //
  372. //////////////////////////////////////////////////////////////
  373. $sql = 'SELECT DISTINCT session_course.course_code
  374. FROM ' . $tbl_session_course . ' as session_course
  375. INNER JOIN ' . $tbl_session . ' as session
  376. ON session.id = session_course.id_session
  377. AND session.id_coach = ' . $coach_id . '
  378. INNER JOIN ' . $tbl_course . ' as course
  379. ON course.code = session_course.course_code';
  380. if (!empty ($id_session))
  381. $sql .= ' WHERE session_course.id_session=' . $id_session;
  382. $result = api_sql_query($sql, __FILE__, __LINE__);
  383. while ($row = mysql_fetch_array($result)) {
  384. $a_courses[$row['course_code']] = $row['course_code'];
  385. }
  386. return $a_courses;
  387. }
  388. function get_sessions_coached_by_user($coach_id) {
  389. // table definition
  390. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  391. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  392. // protect datas
  393. $coach_id = intval($coach_id);
  394. // session where we are general coach
  395. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  396. FROM ' . $tbl_session . '
  397. WHERE id_coach=' . $coach_id;
  398. $rs = api_sql_query($sql);
  399. while ($row = mysql_fetch_array($rs)) {
  400. $a_sessions[$row["id"]] = $row;
  401. }
  402. // session where we are coach of a course
  403. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  404. FROM ' . $tbl_session . ' as session
  405. INNER JOIN ' . $tbl_session_course . ' as session_course
  406. ON session.id = session_course.id_session
  407. AND session_course.id_coach=' . $coach_id;
  408. $rs = api_sql_query($sql);
  409. while ($row = mysql_fetch_array($rs)) {
  410. $a_sessions[$row["id"]] = $row;
  411. }
  412. foreach ($a_sessions as & $session) {
  413. if ($session['date_start'] == '0000-00-00') {
  414. $session['status'] = get_lang('SessionActive');
  415. }
  416. else {
  417. $date_start = explode('-', $session['date_start']);
  418. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  419. $date_end = explode('-', $session['date_end']);
  420. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  421. if ($time_start < time() && time() < $time_end) {
  422. $session['status'] = get_lang('SessionActive');
  423. }
  424. else{
  425. if (time() < $time_start) {
  426. $session['status'] = get_lang('SessionFuture');
  427. }
  428. else{
  429. if (time() > $time_end) {
  430. $session['status'] = get_lang('SessionPast');
  431. }
  432. }
  433. }
  434. }
  435. }
  436. return $a_sessions;
  437. }
  438. function get_courses_list_from_session($session_id) {
  439. //protect datas
  440. $session_id = intval($session_id);
  441. // table definition
  442. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  443. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  444. $sql = 'SELECT DISTINCT course_code, id_coach
  445. FROM ' . $tbl_session_course . '
  446. WHERE id_session=' . $session_id;
  447. $rs = api_sql_query($sql, __FILE__, __LINE__);
  448. $a_courses = array ();
  449. while ($row = mysql_fetch_array($rs)) {
  450. $a_courses[$row['course_code']] = $row;
  451. }
  452. return $a_courses;
  453. }
  454. function count_student_assignments($student_id, $course_code) {
  455. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  456. // protect datas
  457. $student_id = intval($student_id);
  458. $course_code = addslashes($course_code);
  459. // get the informations of the course
  460. $a_course = CourseManager :: get_course_information($course_code);
  461. // table definition
  462. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']);
  463. $sql = 'SELECT 1
  464. FROM ' . $tbl_item_property . '
  465. WHERE insert_user_id=' . $student_id . '
  466. AND tool="work"';
  467. $rs = api_sql_query($sql, __LINE__, __FILE__);
  468. return mysql_num_rows($rs);
  469. }
  470. function count_student_messages($student_id, $course_code) {
  471. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  472. // protect datas
  473. $student_id = intval($student_id);
  474. $course_code = addslashes($course_code);
  475. // get the informations of the course
  476. $a_course = CourseManager :: get_course_information($course_code);
  477. // table definition
  478. $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  479. $sql = 'SELECT 1
  480. FROM ' . $tbl_messages . '
  481. WHERE poster_id=' . $student_id;
  482. $rs = api_sql_query($sql, __LINE__, __FILE__);
  483. return mysql_num_rows($rs);
  484. }
  485. function count_student_visited_links($student_id, $course_code) {
  486. // protect datas
  487. $student_id = intval($student_id);
  488. $course_code = addslashes($course_code);
  489. // table definition
  490. $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  491. $sql = 'SELECT 1
  492. FROM ' . $tbl_stats_links . '
  493. WHERE links_user_id=' . $student_id . '
  494. AND links_cours_id="' . $course_code . '"';
  495. $rs = api_sql_query($sql, __LINE__, __FILE__);
  496. return mysql_num_rows($rs);
  497. }
  498. function count_student_downloaded_documents($student_id, $course_code) {
  499. // protect datas
  500. $student_id = intval($student_id);
  501. $course_code = addslashes($course_code);
  502. // table definition
  503. $tbl_stats_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  504. $sql = 'SELECT 1
  505. FROM ' . $tbl_stats_documents . '
  506. WHERE down_user_id=' . $student_id . '
  507. AND down_cours_id="' . $course_code . '"';
  508. $rs = api_sql_query($sql, __LINE__, __FILE__);
  509. return mysql_num_rows($rs);
  510. }
  511. function get_course_list_in_session_from_student($user_id, $id_session) {
  512. $user_id = intval($user_id);
  513. $id_session = intval($id_session);
  514. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  515. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user="' . $user_id . '" AND id_session="' . $id_session . '"';
  516. $result = api_sql_query($sql, __LINE__, __FILE__);
  517. $a_courses = array ();
  518. while ($row = mysql_fetch_array($result)) {
  519. $a_courses[$row['course_code']] = $row['course_code'];
  520. }
  521. return $a_courses;
  522. }
  523. }
  524. ?>