tracking.lib.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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).'linphone.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. $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. $pourcentageScore = round(($totalScore * 100) / $lp_scorm_weighting_total);
  233. return $pourcentageScore;
  234. }
  235. /**
  236. * gets the list of students followed by coach
  237. * @param integer $coach_id the id of the coach
  238. * @return Array the list of students
  239. */
  240. function get_student_followed_by_coach($coach_id) {
  241. $coach_id = intval($coach_id);
  242. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  243. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  244. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  245. $a_students = array ();
  246. //////////////////////////////////////////////////////////////
  247. // At first, courses where $coach_id is coach of the course //
  248. //////////////////////////////////////////////////////////////
  249. $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  250. $result = api_sql_query($sql);
  251. while ($a_courses = mysql_fetch_array($result)) {
  252. $course_code = $a_courses["course_code"];
  253. $id_session = $a_courses["id_session"];
  254. $sql = "SELECT distinct srcru.id_user
  255. FROM $tbl_session_course_user AS srcru
  256. WHERE course_code='$course_code' AND id_session='$id_session'";
  257. $rs = api_sql_query($sql);
  258. while ($row = mysql_fetch_array($rs)) {
  259. $a_students[$row['id_user']] = $row['id_user'];
  260. }
  261. }
  262. //////////////////////////////////////////////////////////////
  263. // Then, courses where $coach_id is coach of the session //
  264. //////////////////////////////////////////////////////////////
  265. $sql = 'SELECT session_course_user.id_user
  266. FROM ' . $tbl_session_course_user . ' as session_course_user
  267. INNER JOIN ' . $tbl_session_course . ' as session_course
  268. ON session_course.course_code = session_course_user.course_code
  269. AND session_course_user.id_session = session_course.id_session
  270. INNER JOIN ' . $tbl_session . ' as session
  271. ON session.id = session_course.id_session
  272. AND session.id_coach = ' . $coach_id;
  273. $result = api_sql_query($sql);
  274. while ($row = mysql_fetch_array($result)) {
  275. $a_students[$row['id_user']] = $row['id_user'];
  276. }
  277. return $a_students;
  278. }
  279. function get_student_followed_by_coach_in_a_session($id_session, $coach_id) {
  280. $coach_id = intval($coach_id);
  281. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  282. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  283. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  284. $a_students = array ();
  285. //////////////////////////////////////////////////////////////
  286. // At first, courses where $coach_id is coach of the course //
  287. //////////////////////////////////////////////////////////////
  288. $sql = 'SELECT course_code FROM ' . $tbl_session_course . ' WHERE id_session="' . $id_session . '" AND id_coach=' . $coach_id;
  289. $result = api_sql_query($sql);
  290. while ($a_courses = mysql_fetch_array($result)) {
  291. $course_code = $a_courses["course_code"];
  292. $sql = "SELECT distinct srcru.id_user
  293. FROM $tbl_session_course_user AS srcru
  294. WHERE course_code='$course_code' and id_session = '" . $id_session . "'";
  295. $rs = api_sql_query($sql, __FILE__, __LINE__);
  296. while ($row = mysql_fetch_array($rs)) {
  297. $a_students[$row['id_user']] = $row['id_user'];
  298. }
  299. }
  300. //////////////////////////////////////////////////////////////
  301. // Then, courses where $coach_id is coach of the session //
  302. //////////////////////////////////////////////////////////////
  303. $dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
  304. $result = api_sql_query($dsl_session_coach, __FILE__, __LINE__);
  305. //He is the session_coach so we select all the users in the session
  306. if (mysql_num_rows($result) > 0) {
  307. $sql = 'SELECT DISTINCT srcru.id_user FROM ' . $tbl_session_course_user . ' AS srcru WHERE id_session="' . $id_session . '"';
  308. $result = api_sql_query($sql);
  309. while ($row = mysql_fetch_array($result)) {
  310. $a_students[$row['id_user']] = $row['id_user'];
  311. }
  312. }
  313. return $a_students;
  314. }
  315. function is_allowed_to_coach_student($coach_id, $student_id) {
  316. $coach_id = intval($coach_id);
  317. $student_id = intval($student_id);
  318. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  319. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  320. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  321. //////////////////////////////////////////////////////////////
  322. // At first, courses where $coach_id is coach of the course //
  323. //////////////////////////////////////////////////////////////
  324. $sql = 'SELECT 1
  325. FROM ' . $tbl_session_course_user . ' AS session_course_user
  326. INNER JOIN ' . $tbl_session_course . ' AS session_course
  327. ON session_course.course_code = session_course_user.course_code
  328. AND id_coach=' . $coach_id . '
  329. WHERE id_user=' . $student_id;
  330. $result = api_sql_query($sql, __FILE__, __LINE__);
  331. if (mysql_num_rows($result) > 0) {
  332. return true;
  333. }
  334. //////////////////////////////////////////////////////////////
  335. // Then, courses where $coach_id is coach of the session //
  336. //////////////////////////////////////////////////////////////
  337. $sql = 'SELECT session_course_user.id_user
  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. INNER JOIN ' . $tbl_session . ' as session
  342. ON session.id = session_course.id_session
  343. AND session.id_coach = ' . $coach_id . '
  344. WHERE id_user = ' . $student_id;
  345. $result = api_sql_query($sql, __FILE__, __LINE__);
  346. if (mysql_num_rows($result) > 0) {
  347. return true;
  348. }
  349. return false;
  350. }
  351. function get_courses_followed_by_coach($coach_id, $id_session = '') {
  352. $coach_id = intval($coach_id);
  353. if (!empty ($id_session))
  354. $id_session = intval($id_session);
  355. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  356. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  357. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  358. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  359. //////////////////////////////////////////////////////////////
  360. // At first, courses where $coach_id is coach of the course //
  361. //////////////////////////////////////////////////////////////
  362. $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  363. if (!empty ($id_session))
  364. $sql .= ' AND id_session=' . $id_session;
  365. $result = api_sql_query($sql, __FILE__, __LINE__);
  366. while ($row = mysql_fetch_array($result)) {
  367. $a_courses[$row['course_code']] = $row['course_code'];
  368. }
  369. //////////////////////////////////////////////////////////////
  370. // Then, courses where $coach_id is coach of the session //
  371. //////////////////////////////////////////////////////////////
  372. $sql = 'SELECT DISTINCT session_course.course_code
  373. FROM ' . $tbl_session_course . ' as session_course
  374. INNER JOIN ' . $tbl_session . ' as session
  375. ON session.id = session_course.id_session
  376. AND session.id_coach = ' . $coach_id . '
  377. INNER JOIN ' . $tbl_course . ' as course
  378. ON course.code = session_course.course_code';
  379. if (!empty ($id_session))
  380. $sql .= ' WHERE session_course.id_session=' . $id_session;
  381. $result = api_sql_query($sql, __FILE__, __LINE__);
  382. while ($row = mysql_fetch_array($result)) {
  383. $a_courses[$row['course_code']] = $row['course_code'];
  384. }
  385. return $a_courses;
  386. }
  387. function get_sessions_coached_by_user($coach_id) {
  388. // table definition
  389. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  390. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  391. // protect datas
  392. $coach_id = intval($coach_id);
  393. // session where we are general coach
  394. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  395. FROM ' . $tbl_session . '
  396. WHERE id_coach=' . $coach_id;
  397. $rs = api_sql_query($sql);
  398. while ($row = mysql_fetch_array($rs)) {
  399. $a_sessions[$row["id"]] = $row;
  400. }
  401. // session where we are coach of a course
  402. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  403. FROM ' . $tbl_session . ' as session
  404. INNER JOIN ' . $tbl_session_course . ' as session_course
  405. ON session.id = session_course.id_session
  406. AND session_course.id_coach=' . $coach_id;
  407. $rs = api_sql_query($sql);
  408. while ($row = mysql_fetch_array($rs)) {
  409. $a_sessions[$row["id"]] = $row;
  410. }
  411. foreach ($a_sessions as & $session) {
  412. if ($session['date_start'] == '0000-00-00') {
  413. $session['status'] = get_lang('SessionActive');
  414. }
  415. else {
  416. $date_start = explode('-', $session['date_start']);
  417. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  418. $date_end = explode('-', $session['date_end']);
  419. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  420. if ($time_start < time() && time() < $time_end) {
  421. $session['status'] = get_lang('SessionActive');
  422. }
  423. else{
  424. if (time() < $time_start) {
  425. $session['status'] = get_lang('SessionFuture');
  426. }
  427. else{
  428. if (time() > $time_end) {
  429. $session['status'] = get_lang('SessionPast');
  430. }
  431. }
  432. }
  433. }
  434. }
  435. return $a_sessions;
  436. }
  437. function get_courses_list_from_session($session_id) {
  438. //protect datas
  439. $session_id = intval($session_id);
  440. // table definition
  441. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  442. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  443. $sql = 'SELECT DISTINCT course_code, id_coach
  444. FROM ' . $tbl_session_course . '
  445. WHERE id_session=' . $session_id;
  446. $rs = api_sql_query($sql, __FILE__, __LINE__);
  447. $a_courses = array ();
  448. while ($row = mysql_fetch_array($rs)) {
  449. $a_courses[$row['course_code']] = $row;
  450. }
  451. return $a_courses;
  452. }
  453. function count_student_assignments($student_id, $course_code) {
  454. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  455. // protect datas
  456. $student_id = intval($student_id);
  457. $course_code = addslashes($course_code);
  458. // get the informations of the course
  459. $a_course = CourseManager :: get_course_information($course_code);
  460. // table definition
  461. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']);
  462. $sql = 'SELECT 1
  463. FROM ' . $tbl_item_property . '
  464. WHERE insert_user_id=' . $student_id . '
  465. AND tool="work"';
  466. $rs = api_sql_query($sql, __LINE__, __FILE__);
  467. return mysql_num_rows($rs);
  468. }
  469. function count_student_messages($student_id, $course_code) {
  470. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  471. // protect datas
  472. $student_id = intval($student_id);
  473. $course_code = addslashes($course_code);
  474. // get the informations of the course
  475. $a_course = CourseManager :: get_course_information($course_code);
  476. // table definition
  477. $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  478. $sql = 'SELECT 1
  479. FROM ' . $tbl_messages . '
  480. WHERE poster_id=' . $student_id;
  481. $rs = api_sql_query($sql, __LINE__, __FILE__);
  482. return mysql_num_rows($rs);
  483. }
  484. function count_student_visited_links($student_id, $course_code) {
  485. // protect datas
  486. $student_id = intval($student_id);
  487. $course_code = addslashes($course_code);
  488. // table definition
  489. $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  490. $sql = 'SELECT 1
  491. FROM ' . $tbl_stats_links . '
  492. WHERE links_user_id=' . $student_id . '
  493. AND links_cours_id="' . $course_code . '"';
  494. $rs = api_sql_query($sql, __LINE__, __FILE__);
  495. return mysql_num_rows($rs);
  496. }
  497. function count_student_downloaded_documents($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_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  503. $sql = 'SELECT 1
  504. FROM ' . $tbl_stats_documents . '
  505. WHERE down_user_id=' . $student_id . '
  506. AND down_cours_id="' . $course_code . '"';
  507. $rs = api_sql_query($sql, __LINE__, __FILE__);
  508. return mysql_num_rows($rs);
  509. }
  510. function get_course_list_in_session_from_student($user_id, $id_session) {
  511. $user_id = intval($user_id);
  512. $id_session = intval($id_session);
  513. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  514. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user="' . $user_id . '" AND id_session="' . $id_session . '"';
  515. $result = api_sql_query($sql, __LINE__, __FILE__);
  516. $a_courses = array ();
  517. while ($row = mysql_fetch_array($result)) {
  518. $a_courses[$row['course_code']] = $row['course_code'];
  519. }
  520. return $a_courses;
  521. }
  522. }
  523. ?>