tracking.lib.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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-2008 Dokeos SPRL
  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 address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * This is the tracking library for Dokeos.
  24. * Include/require it in your code to use its functionality.
  25. *
  26. * @package dokeos.library
  27. * @author Julio Montoya <gugli100@gmail.com> (Score average fixes)
  28. ==============================================================================
  29. */
  30. class Tracking {
  31. /**
  32. * Calculates the time spent on the platform by a user
  33. * @param integer $user_id the user id
  34. * @return timestamp $nb_seconds
  35. */
  36. function get_time_spent_on_the_platform($user_id) {
  37. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  38. $sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . '
  39. WHERE login_user_id = ' . intval($user_id);;
  40. $rs = api_sql_query($sql,__FILE__,__LINE__);
  41. $nb_seconds = 0;
  42. $wrong_logout_dates = false;
  43. while ($a_connections = Database::fetch_array($rs)) {
  44. $s_login_date = $a_connections["login_date"];
  45. $s_logout_date = $a_connections["logout_date"];
  46. $i_timestamp_login_date = strtotime($s_login_date);
  47. $i_timestamp_logout_date = strtotime($s_logout_date);
  48. if($i_timestamp_logout_date>0)
  49. {
  50. $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date);
  51. }
  52. else
  53. { // there are wrong datas in db, then we can't give a wrong time
  54. $wrong_logout_dates = true;
  55. }
  56. }
  57. if($nb_seconds>0 || !$wrong_logout_dates)
  58. {
  59. return $nb_seconds;
  60. }
  61. else
  62. {
  63. return -1; //-1 means we have wrong datas in the db
  64. }
  65. }
  66. /**
  67. * Calculates the time spent on the course
  68. * @param integer $user_id the user id
  69. * @param string $course_code the course code
  70. * @return timestamp $nb_seconds
  71. */
  72. function get_time_spent_on_the_course($user_id, $course_code) {
  73. // protect datas
  74. $user_id = intval($user_id);
  75. $course_code = addslashes($course_code);
  76. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  77. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  78. WHERE user_id = ' . $user_id . '
  79. AND course_code="' . $course_code . '"';
  80. $rs = api_sql_query($sql,__FILE__,__LINE__);
  81. $nb_seconds = 0;
  82. while ($a_connections = Database::fetch_array($rs)) {
  83. $s_login_date = $a_connections["login_course_date"];
  84. $s_logout_date = $a_connections["logout_course_date"];
  85. $i_timestamp_login_date = strtotime($s_login_date);
  86. $i_timestamp_logout_date = strtotime($s_logout_date);
  87. $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date);
  88. }
  89. return $nb_seconds;
  90. }
  91. function get_first_connection_date($student_id) {
  92. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  93. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  94. WHERE login_user_id = ' . intval($student_id) . '
  95. ORDER BY login_date ASC LIMIT 0,1';
  96. $rs = api_sql_query($sql,__FILE__,__LINE__);
  97. if(Database::num_rows($rs)>0)
  98. {
  99. if ($first_login_date = Database::result($rs, 0, 0)) {
  100. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date));
  101. }
  102. }
  103. return false;
  104. }
  105. function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false) {
  106. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  107. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  108. WHERE login_user_id = ' . intval($student_id) . '
  109. ORDER BY login_date DESC LIMIT 0,1';
  110. $rs = api_sql_query($sql,__FILE__,__LINE__);
  111. if(Database::num_rows($rs)>0)
  112. {
  113. if ($last_login_date = Database::result($rs, 0, 0))
  114. {
  115. if ($return_timestamp)
  116. {
  117. return strtotime($last_login_date);
  118. }
  119. else
  120. {
  121. if (!$warning_message)
  122. {
  123. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  124. }
  125. else
  126. {
  127. $timestamp = strtotime($last_login_date);
  128. $currentTimestamp = mktime();
  129. //If the last connection is > than 7 days, the text is red
  130. //345600 = 7 days in seconds
  131. if ($currentTimestamp - $timestamp > 604800)
  132. {
  133. return '<span style="color: #F00;">' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . '</span>';
  134. }
  135. else
  136. {
  137. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  138. }
  139. }
  140. }
  141. }
  142. }
  143. return false;
  144. }
  145. function get_first_connection_date_on_the_course($student_id, $course_code) {
  146. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  147. $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . '
  148. WHERE user_id = ' . intval($student_id) . '
  149. AND course_code = "' . Database::escape_string($course_code) . '"
  150. ORDER BY login_course_date ASC LIMIT 0,1';
  151. $rs = api_sql_query($sql,__FILE__,__LINE__);
  152. if(Database::num_rows($rs)>0)
  153. {
  154. if ($first_login_date = Database::result($rs, 0, 0)) {
  155. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date));
  156. }
  157. }
  158. return false;
  159. }
  160. function get_last_connection_date_on_the_course($student_id, $course_code) {
  161. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  162. $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . '
  163. WHERE user_id = ' . intval($student_id) . '
  164. AND course_code = "' . Database::escape_string($course_code) . '"
  165. ORDER BY login_course_date DESC LIMIT 0,1';
  166. $rs = api_sql_query($sql,__FILE__,__LINE__);
  167. if(Database::num_rows($rs)>0)
  168. {
  169. if ($last_login_date = Database::result($rs, 0, 0)) {
  170. $timestamp = strtotime($last_login_date);
  171. $currentTimestamp = mktime();
  172. //If the last connection is > than 7 days, the text is red
  173. //345600 = 7 days in seconds
  174. if ($currentTimestamp - $timestamp > 604800) {
  175. return '<span style="color: #F00;">' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . ' <a href="'.api_get_path(REL_CODE_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>';
  176. } else {
  177. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  178. }
  179. }
  180. }
  181. return false;
  182. }
  183. function count_course_per_student($user_id) {
  184. $user_id = intval($user_id);
  185. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  186. $tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  187. $sql = 'SELECT DISTINCT course_code
  188. FROM ' . $tbl_course_rel_user . '
  189. WHERE user_id = ' . $user_id;
  190. $rs = api_sql_query($sql, __FILE__, __LINE__);
  191. $nb_courses = Database::num_rows($rs);
  192. $sql = 'SELECT DISTINCT course_code
  193. FROM ' . $tbl_session_course_rel_user . '
  194. WHERE id_user = ' . $user_id;
  195. $rs = api_sql_query($sql, __FILE__, __LINE__);
  196. $nb_courses += Database::num_rows($rs);
  197. return $nb_courses;
  198. }
  199. function get_avg_student_progress($student_id, $course_code) {
  200. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  201. // protect datas
  202. $student_id = intval($student_id);
  203. $course_code = addslashes($course_code);
  204. // get the informations of the course
  205. $a_course = CourseManager :: get_course_information($course_code);
  206. if(!empty($a_course['db_name']))
  207. {
  208. // table definition
  209. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']);
  210. $tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $a_course['db_name']);
  211. $tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $a_course['db_name']);
  212. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']);
  213. //get the list of learning paths
  214. $sql = 'SELECT id FROM ' . $tbl_course_lp;
  215. $rs = api_sql_query($sql, __FILE__, __LINE__);
  216. $nb_lp = Database::num_rows($rs);
  217. $avg_progress = 0;
  218. if ($nb_lp > 0) {
  219. while ($lp = Database :: fetch_array($rs)) {
  220. // get the progress in learning pathes
  221. $sqlProgress = "SELECT progress
  222. FROM " . $tbl_course_lp_view . " AS lp_view
  223. WHERE lp_view.user_id = " . $student_id . "
  224. AND lp_view.lp_id = " . $lp['id'] . "
  225. ";
  226. $resultItem = api_sql_query($sqlProgress, __FILE__, __LINE__);
  227. if(Database::num_rows($resultItem)>0)
  228. {
  229. $avg_progress += Database::result($resultItem, 0, 0);
  230. }
  231. }
  232. $avg_progress = round($avg_progress / $nb_lp, 1);
  233. }
  234. return $avg_progress;
  235. }
  236. else
  237. {
  238. return null;
  239. }
  240. }
  241. /**
  242. * This function gets:
  243. * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max score.
  244. * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max score.
  245. * 3. And finally it will return the average between 1. and 2.
  246. * This function does not take the results of a Test out of a LP
  247. *
  248. * @param User id
  249. * @param Course id
  250. * @param Array limit average to listed lp ids
  251. * @return string value (number %) Which represents a round integer explain in got in 3.
  252. */
  253. function get_avg_student_score($student_id, $course_code, $lp_ids=array()) {
  254. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  255. $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  256. $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  257. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  258. $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  259. $course = CourseManager :: get_course_information($course_code);
  260. if(!empty($course['db_name']))
  261. {
  262. $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']);
  263. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']);
  264. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']);
  265. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']);
  266. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']);
  267. $sql_course_lp = 'SELECT id FROM '.$lp_table;
  268. if(count($lp_ids)!=0)
  269. {
  270. $sql_course_lp.=' WHERE id IN ('.implode(',',$lp_ids).')';
  271. }
  272. $sql_result_lp = api_sql_query($sql_course_lp, __FILE__, __LINE__);
  273. $lp_scorm_score_total = 0;
  274. $lp_scorm_weighting_total = 0;
  275. if(Database::num_rows($sql_result_lp)>0){
  276. //Scorm test
  277. while($a_learnpath = Database::fetch_array($sql_result_lp)){
  278. //We get the last view id of this LP
  279. $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"';
  280. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  281. $lp_view_id = Database::result($rs_last_lp_view_id,0,'id');
  282. $sql='SELECT SUM(lp_iv.score)/count(lp_item_id) as score, SUM(lp_iv.max_score)/count(lp_item_id) as max_score
  283. FROM '.$lp_item_view_table.' as lp_iv
  284. INNER JOIN '.$lp_item_table.' as lp_i
  285. ON lp_i.id = lp_iv.lp_item_id
  286. AND lp_i.item_type="sco"
  287. WHERE lp_iv.max_score != ""
  288. AND lp_view_id="'.$lp_view_id.'"';
  289. $rs = api_sql_query($sql, __FILE__, __LINE__);
  290. $lp_scorm_score_total+=Database::result($rs, 0, 'score');
  291. $lp_scorm_weighting_total+=Database::result($rs, 0, 'max_score');
  292. }
  293. //The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row.
  294. mysql_data_seek($sql_result_lp,0);
  295. //Quizz in a LP
  296. while($a_learnpath = Database::fetch_array($sql_result_lp)){
  297. //we got the maxscore this is wrong
  298. /*
  299. echo $sql = 'SELECT id as item_id, max_score
  300. FROM '.$lp_item_table.' AS lp_item
  301. WHERE lp_id='.$a_learnpath['id'].'
  302. AND item_type="quiz"';
  303. */
  304. //Path is the exercise id
  305. $sql = 'SELECT path, id as item_id, max_score
  306. FROM '.$lp_item_table.' AS lp_item
  307. WHERE lp_id='.$a_learnpath['id'].'
  308. AND item_type="quiz"';
  309. $rsItems = api_sql_query($sql, __FILE__, __LINE__);
  310. //We get the last view id of this LP
  311. $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"';
  312. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  313. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  314. $total_score = $total_weighting = 0;
  315. if($lp_view_id!=0)
  316. {
  317. while($item = Database :: fetch_array($rsItems, 'ASSOC'))
  318. {
  319. // we take the score from a LP because we have lp_view_id
  320. $sql = 'SELECT score as student_score
  321. FROM '.$lp_item_view_table.' as lp_view_item
  322. WHERE lp_view_item.lp_item_id = '.$item['item_id'].'
  323. AND lp_view_id = "'.$lp_view_id.'"
  324. ';
  325. $rsScores = api_sql_query($sql, __FILE__, __LINE__);
  326. // Real max score - this was implemented because of the random exercises
  327. $sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
  328. 'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$a_learnpath['id'].'" AND orig_lp_item_id = "'.$item['item_id'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
  329. $resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
  330. $num = Database :: num_rows($resultLastAttempt);
  331. if ($num > 0){
  332. if ($num > 1){
  333. while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
  334. $id_last_attempt = $rowLA[0];
  335. }
  336. } else {
  337. $id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
  338. }
  339. }
  340. $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
  341. "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
  342. $result = api_sql_query($sql, __FILE__, __LINE__);
  343. $row_max_score = Database :: fetch_array($result);
  344. $maxscore = $row_max_score['maxscore'];
  345. if ($maxscore=='')
  346. {
  347. $maxscore = $item['max_score'];
  348. }
  349. if(Database::num_rows($rsScores)>0)
  350. {
  351. $total_score += Database::result($rsScores, 0, 0);
  352. //echo $total_weighting += $item['max_score'];
  353. $total_weighting += $maxscore;
  354. if($total_weighting>0)
  355. {
  356. $lp_scorm_score_total += ($total_score/$total_weighting)*100;
  357. $lp_scorm_weighting_total+=100;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. $totalScore = $lp_scorm_score_total;
  365. $pourcentageScore = 0;
  366. if($lp_scorm_weighting_total>0) {
  367. //i.e 10.52
  368. $pourcentageScore = round( (($totalScore * 100) / $lp_scorm_weighting_total),2);
  369. return $pourcentageScore;
  370. }
  371. else
  372. {
  373. return null;
  374. }
  375. }
  376. else
  377. {
  378. return null;
  379. }
  380. }
  381. /**
  382. * gets the list of students followed by coach
  383. * @param integer $coach_id the id of the coach
  384. * @return Array the list of students
  385. */
  386. function get_student_followed_by_coach($coach_id) {
  387. $coach_id = intval($coach_id);
  388. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  389. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  390. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  391. $a_students = array ();
  392. //////////////////////////////////////////////////////////////
  393. // At first, courses where $coach_id is coach of the course //
  394. //////////////////////////////////////////////////////////////
  395. $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  396. global $_configuration;
  397. if ($_configuration['multiple_access_urls']==true) {
  398. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  399. $access_url_id = api_get_current_access_url_id();
  400. if ($access_url_id != -1){
  401. $sql = 'SELECT id_session, course_code
  402. FROM ' . $tbl_session_course . ' session_course INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  403. ON (session_course.id_session=session_rel_url.session_id)
  404. WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id;
  405. }
  406. }
  407. $result = api_sql_query($sql,__FILE__,__LINE__);
  408. while ($a_courses = Database::fetch_array($result)) {
  409. $course_code = $a_courses["course_code"];
  410. $id_session = $a_courses["id_session"];
  411. $sql = "SELECT distinct srcru.id_user
  412. FROM $tbl_session_course_user AS srcru
  413. WHERE course_code='$course_code' AND id_session='$id_session'";
  414. $rs = api_sql_query($sql,__FILE__,__LINE__);
  415. while ($row = Database::fetch_array($rs)) {
  416. $a_students[$row['id_user']] = $row['id_user'];
  417. }
  418. }
  419. //////////////////////////////////////////////////////////////
  420. // Then, courses where $coach_id is coach of the session //
  421. //////////////////////////////////////////////////////////////
  422. $sql = 'SELECT session_course_user.id_user
  423. FROM ' . $tbl_session_course_user . ' as session_course_user
  424. INNER JOIN ' . $tbl_session_course . ' as session_course
  425. ON session_course.course_code = session_course_user.course_code
  426. AND session_course_user.id_session = session_course.id_session
  427. INNER JOIN ' . $tbl_session . ' as session
  428. ON session.id = session_course.id_session
  429. AND session.id_coach = ' . $coach_id;
  430. if ($_configuration['multiple_access_urls']==true) {
  431. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  432. $access_url_id = api_get_current_access_url_id();
  433. if ($access_url_id != -1){
  434. $sql = 'SELECT session_course_user.id_user
  435. FROM ' . $tbl_session_course_user . ' as session_course_user
  436. INNER JOIN ' . $tbl_session_course . ' as session_course
  437. ON session_course.course_code = session_course_user.course_code
  438. AND session_course_user.id_session = session_course.id_session
  439. INNER JOIN ' . $tbl_session . ' as session
  440. ON session.id = session_course.id_session
  441. AND session.id_coach = ' . $coach_id.'
  442. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  443. ON session.id = session_rel_url.session_id WHERE access_url_id = '.$access_url_id;
  444. }
  445. }
  446. $result = api_sql_query($sql,__FILE__,__LINE__);
  447. while ($row = Database::fetch_array($result)) {
  448. $a_students[$row['id_user']] = $row['id_user'];
  449. }
  450. return $a_students;
  451. }
  452. function get_student_followed_by_coach_in_a_session($id_session, $coach_id) {
  453. $coach_id = intval($coach_id);
  454. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  455. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  456. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  457. $a_students = array ();
  458. //////////////////////////////////////////////////////////////
  459. // At first, courses where $coach_id is coach of the course //
  460. //////////////////////////////////////////////////////////////
  461. $sql = 'SELECT course_code FROM ' . $tbl_session_course . ' WHERE id_session="' . $id_session . '" AND id_coach=' . $coach_id;
  462. $result = api_sql_query($sql,__FILE__,__LINE__);
  463. while ($a_courses = Database::fetch_array($result)) {
  464. $course_code = $a_courses["course_code"];
  465. $sql = "SELECT distinct srcru.id_user
  466. FROM $tbl_session_course_user AS srcru
  467. WHERE course_code='$course_code' and id_session = '" . $id_session . "'";
  468. $rs = api_sql_query($sql, __FILE__, __LINE__);
  469. while ($row = Database::fetch_array($rs)) {
  470. $a_students[$row['id_user']] = $row['id_user'];
  471. }
  472. }
  473. //////////////////////////////////////////////////////////////
  474. // Then, courses where $coach_id is coach of the session //
  475. //////////////////////////////////////////////////////////////
  476. $dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
  477. $result = api_sql_query($dsl_session_coach, __FILE__, __LINE__);
  478. //He is the session_coach so we select all the users in the session
  479. if (Database::num_rows($result) > 0) {
  480. $sql = 'SELECT DISTINCT srcru.id_user FROM ' . $tbl_session_course_user . ' AS srcru WHERE id_session="' . $id_session . '"';
  481. $result = api_sql_query($sql,__FILE__,__LINE__);
  482. while ($row = Database::fetch_array($result)) {
  483. $a_students[$row['id_user']] = $row['id_user'];
  484. }
  485. }
  486. return $a_students;
  487. }
  488. function is_allowed_to_coach_student($coach_id, $student_id) {
  489. $coach_id = intval($coach_id);
  490. $student_id = intval($student_id);
  491. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  492. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  493. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  494. //////////////////////////////////////////////////////////////
  495. // At first, courses where $coach_id is coach of the course //
  496. //////////////////////////////////////////////////////////////
  497. $sql = 'SELECT 1
  498. FROM ' . $tbl_session_course_user . ' AS session_course_user
  499. INNER JOIN ' . $tbl_session_course . ' AS session_course
  500. ON session_course.course_code = session_course_user.course_code
  501. AND id_coach=' . $coach_id . '
  502. WHERE id_user=' . $student_id;
  503. $result = api_sql_query($sql, __FILE__, __LINE__);
  504. if (Database::num_rows($result) > 0) {
  505. return true;
  506. }
  507. //////////////////////////////////////////////////////////////
  508. // Then, courses where $coach_id is coach of the session //
  509. //////////////////////////////////////////////////////////////
  510. $sql = 'SELECT session_course_user.id_user
  511. FROM ' . $tbl_session_course_user . ' as session_course_user
  512. INNER JOIN ' . $tbl_session_course . ' as session_course
  513. ON session_course.course_code = session_course_user.course_code
  514. INNER JOIN ' . $tbl_session . ' as session
  515. ON session.id = session_course.id_session
  516. AND session.id_coach = ' . $coach_id . '
  517. WHERE id_user = ' . $student_id;
  518. $result = api_sql_query($sql, __FILE__, __LINE__);
  519. if (Database::num_rows($result) > 0) {
  520. return true;
  521. }
  522. return false;
  523. }
  524. function get_courses_followed_by_coach($coach_id, $id_session = '')
  525. {
  526. $coach_id = intval($coach_id);
  527. if (!empty ($id_session))
  528. $id_session = intval($id_session);
  529. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  530. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  531. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  532. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  533. //////////////////////////////////////////////////////////////
  534. // At first, courses where $coach_id is coach of the course //
  535. //////////////////////////////////////////////////////////////
  536. $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id;
  537. global $_configuration;
  538. if ($_configuration['multiple_access_urls']==true) {
  539. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  540. $access_url_id = api_get_current_access_url_id();
  541. if ($access_url_id != -1){
  542. $sql = 'SELECT DISTINCT session_course.course_code FROM ' . $tbl_session_course . ' session_course INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url
  543. ON (session_course.course_code = course_rel_url.course_code)
  544. WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id;
  545. }
  546. }
  547. if (!empty ($id_session))
  548. $sql .= ' AND id_session=' . $id_session;
  549. $result = api_sql_query($sql, __FILE__, __LINE__);
  550. while ($row = Database::fetch_array($result)) {
  551. $a_courses[$row['course_code']] = $row['course_code'];
  552. }
  553. //////////////////////////////////////////////////////////////
  554. // Then, courses where $coach_id is coach of the session //
  555. //////////////////////////////////////////////////////////////
  556. $sql = 'SELECT DISTINCT session_course.course_code
  557. FROM ' . $tbl_session_course . ' as session_course
  558. INNER JOIN ' . $tbl_session . ' as session
  559. ON session.id = session_course.id_session
  560. AND session.id_coach = ' . $coach_id . '
  561. INNER JOIN ' . $tbl_course . ' as course
  562. ON course.code = session_course.course_code';
  563. if ($_configuration['multiple_access_urls']==true) {
  564. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  565. $access_url_id = api_get_current_access_url_id();
  566. if ($access_url_id != -1){
  567. $sql = 'SELECT DISTINCT session_course.course_code
  568. FROM ' . $tbl_session_course . ' as session_course
  569. INNER JOIN ' . $tbl_session . ' as session
  570. ON session.id = session_course.id_session
  571. AND session.id_coach = ' . $coach_id . '
  572. INNER JOIN ' . $tbl_course . ' as course
  573. ON course.code = session_course.course_code
  574. INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url
  575. ON (session_course.course_code = course_rel_url.course_code)';
  576. }
  577. }
  578. if (!empty ($id_session)) {
  579. $sql .= ' WHERE session_course.id_session=' . $id_session;
  580. $sql .= ' AND access_url_id = '.$access_url_id;
  581. } else {
  582. $sql .= ' WHERE access_url_id = '.$access_url_id;
  583. }
  584. $result = api_sql_query($sql, __FILE__, __LINE__);
  585. while ($row = Database::fetch_array($result)) {
  586. $a_courses[$row['course_code']] = $row['course_code'];
  587. }
  588. return $a_courses;
  589. }
  590. function get_sessions_coached_by_user($coach_id) {
  591. // table definition
  592. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  593. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  594. // protect datas
  595. $coach_id = intval($coach_id);
  596. // session where we are general coach
  597. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  598. FROM ' . $tbl_session . '
  599. WHERE id_coach=' . $coach_id;
  600. global $_configuration;
  601. if ($_configuration['multiple_access_urls']==true) {
  602. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  603. $access_url_id = api_get_current_access_url_id();
  604. if ($access_url_id != -1){
  605. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  606. FROM ' . $tbl_session . ' session INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  607. ON (session.id = session_rel_url.session_id)
  608. WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id;
  609. }
  610. }
  611. $rs = api_sql_query($sql,__FILE__,__LINE__);
  612. while ($row = Database::fetch_array($rs))
  613. {
  614. $a_sessions[$row["id"]] = $row;
  615. }
  616. // session where we are coach of a course
  617. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  618. FROM ' . $tbl_session . ' as session
  619. INNER JOIN ' . $tbl_session_course . ' as session_course
  620. ON session.id = session_course.id_session
  621. AND session_course.id_coach=' . $coach_id;
  622. global $_configuration;
  623. if ($_configuration['multiple_access_urls']==true) {
  624. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  625. $access_url_id = api_get_current_access_url_id();
  626. if ($access_url_id != -1){
  627. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  628. FROM ' . $tbl_session . ' as session
  629. INNER JOIN ' . $tbl_session_course . ' as session_course
  630. ON session.id = session_course.id_session AND session_course.id_coach=' . $coach_id.'
  631. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  632. ON (session.id = session_rel_url.session_id)
  633. WHERE access_url_id = '.$access_url_id;
  634. }
  635. }
  636. $rs = api_sql_query($sql,__FILE__,__LINE__);
  637. while ($row = Database::fetch_array($rs))
  638. {
  639. $a_sessions[$row["id"]] = $row;
  640. }
  641. if (is_array($a_sessions)) {
  642. foreach ($a_sessions as & $session) {
  643. if ($session['date_start'] == '0000-00-00') {
  644. $session['status'] = get_lang('SessionActive');
  645. }
  646. else {
  647. $date_start = explode('-', $session['date_start']);
  648. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  649. $date_end = explode('-', $session['date_end']);
  650. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  651. if ($time_start < time() && time() < $time_end) {
  652. $session['status'] = get_lang('SessionActive');
  653. }
  654. else{
  655. if (time() < $time_start) {
  656. $session['status'] = get_lang('SessionFuture');
  657. }
  658. else{
  659. if (time() > $time_end) {
  660. $session['status'] = get_lang('SessionPast');
  661. }
  662. }
  663. }
  664. }
  665. }
  666. }
  667. return $a_sessions;
  668. }
  669. function get_courses_list_from_session($session_id) {
  670. //protect datas
  671. $session_id = intval($session_id);
  672. // table definition
  673. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  674. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  675. $sql = 'SELECT DISTINCT course_code, id_coach
  676. FROM ' . $tbl_session_course . '
  677. WHERE id_session=' . $session_id;
  678. $rs = api_sql_query($sql, __FILE__, __LINE__);
  679. $a_courses = array ();
  680. while ($row = Database::fetch_array($rs)) {
  681. $a_courses[$row['course_code']] = $row;
  682. }
  683. return $a_courses;
  684. }
  685. function count_student_assignments($student_id, $course_code) {
  686. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  687. // protect datas
  688. $student_id = intval($student_id);
  689. $course_code = addslashes($course_code);
  690. // get the informations of the course
  691. $a_course = CourseManager :: get_course_information($course_code);
  692. if(!empty($a_course['db_name']))
  693. {
  694. // table definition
  695. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']);
  696. $sql = 'SELECT 1
  697. FROM ' . $tbl_item_property . '
  698. WHERE insert_user_id=' . $student_id . '
  699. AND tool="work"';
  700. $rs = api_sql_query($sql, __LINE__, __FILE__);
  701. return Database::num_rows($rs);
  702. }
  703. else
  704. {
  705. return null;
  706. }
  707. }
  708. function count_student_messages($student_id, $course_code) {
  709. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  710. // protect datas
  711. $student_id = intval($student_id);
  712. $course_code = addslashes($course_code);
  713. // get the informations of the course
  714. $a_course = CourseManager :: get_course_information($course_code);
  715. if(!empty($a_course['db_name']))
  716. {
  717. // table definition
  718. $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  719. $sql = 'SELECT 1
  720. FROM ' . $tbl_messages . '
  721. WHERE poster_id=' . $student_id;
  722. $rs = api_sql_query($sql, __LINE__, __FILE__);
  723. return Database::num_rows($rs);
  724. }
  725. else
  726. {
  727. return null;
  728. }
  729. }
  730. /**
  731. * This function counts the number of post by course
  732. * @param string $course_code - Course ID
  733. * @return int the number of post by course
  734. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  735. * @version enero 2009, dokeos 1.8.6
  736. */
  737. function count_number_of_posts_by_course($course_code) {
  738. //protect data
  739. $course_code = addslashes($course_code);
  740. // get the informations of the course
  741. $a_course = CourseManager :: get_course_information($course_code);
  742. $count = 0;
  743. if (!empty($a_course['db_name'])) {
  744. $tbl_posts = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  745. $sql = "SELECT count(*) FROM $tbl_posts";
  746. $result = api_sql_query($sql, __FILE__, __LINE__);
  747. $row = Database::fetch_row($result);
  748. $count = $row[0];
  749. return $count;
  750. } else {
  751. return null;
  752. }
  753. }
  754. /**
  755. * This function counts the number of threads by course
  756. * @param string $course_code - Course ID
  757. * @return int the number of threads by course
  758. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  759. * @version enero 2009, dokeos 1.8.6
  760. */
  761. function count_number_of_threads_by_course($course_code) {
  762. //protect data
  763. $course_code = addslashes($course_code);
  764. // get the informations of the course
  765. $a_course = CourseManager :: get_course_information($course_code);
  766. $count = 0;
  767. if (!empty($a_course['db_name'])) {
  768. $tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $a_course['db_name']);
  769. $sql = "SELECT count(*) FROM $tbl_threads";
  770. $result = api_sql_query($sql, __FILE__, __LINE__);
  771. $row = Database::fetch_row($result);
  772. $count = $row[0];
  773. return $count;
  774. } else {
  775. return null;
  776. }
  777. }
  778. /**
  779. * This function counts the number of forums by course
  780. * @param string $course_code - Course ID
  781. * @return int the number of forums by course
  782. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  783. * @version enero 2009, dokeos 1.8.6
  784. */
  785. function count_number_of_forums_by_course($course_code) {
  786. //protect data
  787. $course_code = addslashes($course_code);
  788. // get the informations of the course
  789. $a_course = CourseManager :: get_course_information($course_code);
  790. $count = 0;
  791. if (!empty($a_course['db_name'])) {
  792. $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
  793. $sql = "SELECT count(*) FROM $tbl_forums";
  794. $result = api_sql_query($sql, __FILE__, __LINE__);
  795. $row = Database::fetch_row($result);
  796. $count = $row[0];
  797. return $count;
  798. } else {
  799. return null;
  800. }
  801. }
  802. /**
  803. * This function counts the chat last connections by course in x days
  804. * @param string $course_code - Course ID
  805. * @param int $last_days - last x days
  806. * @return int the chat last connections by course in x days
  807. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  808. * @version enero 2009, dokeos 1.8.6
  809. */
  810. function chat_connections_during_last_x_days_by_course($course_code,$last_days) {
  811. //protect data
  812. $last_days = intval($last_days);
  813. $course_code = addslashes($course_code);
  814. // get the informations of the course
  815. $a_course = CourseManager :: get_course_information($course_code);
  816. $count = 0;
  817. if (!empty($a_course['db_name'])) {
  818. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']);
  819. $sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date
  820. AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."'";
  821. $result = api_sql_query($sql, __FILE__, __LINE__);
  822. $row = Database::fetch_row($result);
  823. $count = $row[0];
  824. return $count;
  825. } else {
  826. return null;
  827. }
  828. }
  829. /**
  830. * This function gets the last student's connection in chat
  831. * @param int $student_id - Student ID
  832. * @param string $course_code - Course ID
  833. * @return string the last connection
  834. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  835. * @version enero 2009, dokeos 1.8.6
  836. */
  837. function chat_last_connection($student_id,$course_code) {
  838. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  839. //protect datas
  840. $student_id = intval($student_id);
  841. $course_code = addslashes($course_code);
  842. // get the informations of the course
  843. $a_course = CourseManager :: get_course_information($course_code);
  844. $date_time = '';
  845. if (!empty($a_course['db_name'])) {
  846. // table definition
  847. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']);
  848. $sql = "SELECT access_date FROM $tbl_stats_access
  849. WHERE access_tool='".TOOL_CHAT."' AND access_user_id='$student_id' AND access_cours_code = '$course_code' ORDER BY access_date DESC limit 1";
  850. $rs = api_sql_query($sql, __LINE__, __FILE__);
  851. $row = Database::fetch_array($rs);
  852. $last_connection = $row['access_date'];
  853. if (!empty($last_connection)) {
  854. $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection));
  855. $time = explode(' ',$last_connection);
  856. $date_time = $date_format_long.' '.$time[1];
  857. }
  858. return $date_time;
  859. } else {
  860. return null;
  861. }
  862. }
  863. function count_student_visited_links($student_id, $course_code) {
  864. // protect datas
  865. $student_id = intval($student_id);
  866. $course_code = addslashes($course_code);
  867. // table definition
  868. $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  869. $sql = 'SELECT 1
  870. FROM ' . $tbl_stats_links . '
  871. WHERE links_user_id=' . $student_id . '
  872. AND links_cours_id="' . $course_code . '"';
  873. $rs = api_sql_query($sql, __LINE__, __FILE__);
  874. return Database::num_rows($rs);
  875. }
  876. function count_student_downloaded_documents($student_id, $course_code) {
  877. // protect datas
  878. $student_id = intval($student_id);
  879. $course_code = addslashes($course_code);
  880. // table definition
  881. $tbl_stats_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  882. $sql = 'SELECT 1
  883. FROM ' . $tbl_stats_documents . '
  884. WHERE down_user_id=' . $student_id . '
  885. AND down_cours_id="' . $course_code . '"';
  886. $rs = api_sql_query($sql, __LINE__, __FILE__);
  887. return Database::num_rows($rs);
  888. }
  889. function get_course_list_in_session_from_student($user_id, $id_session) {
  890. $user_id = intval($user_id);
  891. $id_session = intval($id_session);
  892. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  893. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user="' . $user_id . '" AND id_session="' . $id_session . '"';
  894. $result = api_sql_query($sql, __LINE__, __FILE__);
  895. $a_courses = array ();
  896. while ($row = Database::fetch_array($result)) {
  897. $a_courses[$row['course_code']] = $row['course_code'];
  898. }
  899. return $a_courses;
  900. }
  901. function get_inactives_students_in_course($course_code, $since, $session_id=0)
  902. {
  903. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  904. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  905. $inner = '';
  906. if($session_id!=0)
  907. {
  908. $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user
  909. ON stats_login.course_code = session_course_user.course_code
  910. AND session_course_user.id_session = '.intval($session_id).'
  911. AND session_course_user.id_user = stats_login.user_id ';
  912. }
  913. $sql = 'SELECT user_id, MAX(login_course_date) max_date FROM'.$tbl_track_login.' stats_login'.$inner.'
  914. GROUP BY user_id
  915. HAVING DATE_SUB( NOW(), INTERVAL '.$since.' DAY) > max_date ';
  916. //HAVING DATE_ADD(max_date, INTERVAL '.$since.' DAY) < NOW() ';
  917. $rs = api_sql_query($sql,__FILE__,__LINE__);
  918. $inactive_users = array();
  919. while($user = Database::fetch_array($rs))
  920. {
  921. $inactive_users[] = $user['user_id'];
  922. }
  923. return $inactive_users;
  924. }
  925. function count_login_per_student($student_id, $course_code) {
  926. $student_id = intval($student_id);
  927. $course_code = addslashes($course_code);
  928. $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  929. $sql = 'SELECT '.$student_id.'
  930. FROM ' . $tbl_course_rel_user . '
  931. WHERE access_user_id=' . $student_id . '
  932. AND access_cours_code="' . $course_code . '"';
  933. $rs = api_sql_query($sql, __FILE__, __LINE__);
  934. $nb_login = Database::num_rows($rs);
  935. return $nb_login;
  936. }
  937. function get_student_followed_by_drh($hr_dept_id) {
  938. $hr_dept_id = intval($hr_dept_id);
  939. $a_students = array ();
  940. $tbl_organism = Database :: get_main_table(TABLE_MAIN_ORGANISM);
  941. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  942. $sql = 'SELECT DISTINCT user_id FROM '.$tbl_user.' as user
  943. WHERE hr_dept_id='.$hr_dept_id;
  944. $rs = api_sql_query($sql, __FILE__, __LINE__);
  945. while($user = Database :: fetch_array($rs))
  946. {
  947. $a_students[$user['user_id']] = $user['user_id'];
  948. }
  949. return $a_students;
  950. }
  951. }
  952. ?>