tracking.lib.php 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  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. public static 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 = Database::query($sql);
  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. public static function get_time_spent_on_the_course($user_id, $course_code) {
  73. // protect datas
  74. $course_code = Database::escape_string($course_code);
  75. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  76. $condition_user = "";
  77. if (is_array($user_id)) {
  78. $condition_user = " AND user_id IN (".implode(',',$user_id).") ";
  79. } else {
  80. $user_id = intval($user_id);
  81. $condition_user = " AND user_id = '$user_id' ";
  82. }
  83. $sql = " SELECT SUM(UNIX_TIMESTAMP(logout_course_date)-UNIX_TIMESTAMP(login_course_date)) as nb_seconds
  84. FROM $tbl_track_course
  85. WHERE course_code='$course_code' $condition_user";
  86. $rs = Database::query($sql);
  87. $row = Database::fetch_array($rs);
  88. return $row['nb_seconds'];
  89. }
  90. public static function get_first_connection_date($student_id) {
  91. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  92. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  93. WHERE login_user_id = ' . intval($student_id) . '
  94. ORDER BY login_date ASC LIMIT 0,1';
  95. $rs = Database::query($sql);
  96. if(Database::num_rows($rs)>0)
  97. {
  98. if ($first_login_date = Database::result($rs, 0, 0)) {
  99. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date));
  100. }
  101. }
  102. return false;
  103. }
  104. public static function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false) {
  105. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  106. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  107. WHERE login_user_id = ' . intval($student_id) . '
  108. ORDER BY login_date DESC LIMIT 0,1';
  109. $rs = Database::query($sql);
  110. if(Database::num_rows($rs)>0)
  111. {
  112. if ($last_login_date = Database::result($rs, 0, 0))
  113. {
  114. if ($return_timestamp)
  115. {
  116. return strtotime($last_login_date);
  117. }
  118. else
  119. {
  120. if (!$warning_message)
  121. {
  122. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  123. }
  124. else
  125. {
  126. $timestamp = strtotime($last_login_date);
  127. $currentTimestamp = mktime();
  128. //If the last connection is > than 7 days, the text is red
  129. //345600 = 7 days in seconds
  130. if ($currentTimestamp - $timestamp > 604800)
  131. {
  132. return '<span style="color: #F00;">' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . '</span>';
  133. }
  134. else
  135. {
  136. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  137. }
  138. }
  139. }
  140. }
  141. }
  142. return false;
  143. }
  144. public static function get_first_connection_date_on_the_course($student_id, $course_code) {
  145. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  146. $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . '
  147. WHERE user_id = ' . intval($student_id) . '
  148. AND course_code = "' . Database::escape_string($course_code) . '"
  149. ORDER BY login_course_date ASC LIMIT 0,1';
  150. $rs = Database::query($sql);
  151. if(Database::num_rows($rs)>0)
  152. {
  153. if ($first_login_date = Database::result($rs, 0, 0)) {
  154. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date));
  155. }
  156. }
  157. return false;
  158. }
  159. public static function get_last_connection_date_on_the_course($student_id, $course_code) {
  160. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  161. $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . '
  162. WHERE user_id = ' . intval($student_id) . '
  163. AND course_code = "' . Database::escape_string($course_code) . '"
  164. ORDER BY login_course_date DESC LIMIT 0,1';
  165. $rs = Database::query($sql);
  166. if(Database::num_rows($rs)>0)
  167. {
  168. if ($last_login_date = Database::result($rs, 0, 0)) {
  169. $timestamp = strtotime($last_login_date);
  170. $currentTimestamp = mktime();
  171. //If the last connection is > than 7 days, the text is red
  172. //345600 = 7 days in seconds
  173. if ($currentTimestamp - $timestamp > 604800) {
  174. return '<span style="color: #F00;">' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . (api_is_allowed_to_edit()?' <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>';
  175. } else {
  176. return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date));
  177. }
  178. }
  179. }
  180. return false;
  181. }
  182. public static function count_course_per_student($user_id) {
  183. $user_id = intval($user_id);
  184. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  185. $tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  186. $sql = 'SELECT DISTINCT course_code
  187. FROM ' . $tbl_course_rel_user . '
  188. WHERE user_id = ' . $user_id;
  189. $rs = Database::query($sql);
  190. $nb_courses = Database::num_rows($rs);
  191. $sql = 'SELECT DISTINCT course_code
  192. FROM ' . $tbl_session_course_rel_user . '
  193. WHERE id_user = ' . $user_id;
  194. $rs = Database::query($sql);
  195. $nb_courses += Database::num_rows($rs);
  196. return $nb_courses;
  197. }
  198. /**
  199. * This function gets the score average from all tests in a course by student
  200. * @param int $student_id - or array for multiples User id (array(0=>1,1=>2))
  201. * @param string $course_code - Course id
  202. * @return string value (number %) Which represents a round integer about the score average.
  203. */
  204. public static function get_avg_student_exercise_score($student_id, $course_code) {
  205. // protect datas
  206. $course_code = Database::escape_string($course_code);
  207. // get the informations of the course
  208. $a_course = CourseManager :: get_course_information($course_code);
  209. if(!empty($a_course['db_name'])) {
  210. // table definition
  211. $tbl_course_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$a_course['db_name']);
  212. $tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  213. $count_quiz = Database::fetch_row(Database::query("SELECT count(id) FROM $tbl_course_quiz WHERE active <> -1"));
  214. $quiz_avg_total_score = 0;
  215. if (!empty($count_quiz[0]) && !empty($student_id)) {
  216. $condition_user = "";
  217. if (is_array($student_id)) {
  218. $condition_user = " AND exe_user_id IN (".implode(',',$student_id).") ";
  219. } else {
  220. $condition_user = " AND exe_user_id = '$student_id' ";
  221. }
  222. $sql = "SELECT SUM(exe_result/exe_weighting*100) as avg_score
  223. FROM $tbl_stats_exercise
  224. WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1)
  225. $condition_user
  226. AND orig_lp_id = 0
  227. AND exe_cours_id = '$course_code'
  228. AND orig_lp_item_id = 0
  229. ORDER BY exe_date DESC";
  230. $res = Database::query($sql);
  231. $row = Database::fetch_array($res);
  232. $quiz_avg_score = 0;
  233. if (!empty($row['avg_score'])) {
  234. $quiz_avg_score = round($row['avg_score'],2);
  235. }
  236. $count_attempt = Database::fetch_row(Database::query("SELECT count(*) FROM $tbl_stats_exercise WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1) $condition_user AND orig_lp_id = 0 AND exe_cours_id = '$course_code' AND orig_lp_item_id = 0 ORDER BY exe_date DESC"));
  237. if(!empty($count_attempt[0])) {
  238. $quiz_avg_score = $quiz_avg_score / $count_attempt[0];
  239. }
  240. $quiz_avg_total_score = $quiz_avg_score;
  241. return $quiz_avg_total_score/$count_quiz[0];
  242. }
  243. }
  244. return null;
  245. }
  246. public static function get_avg_student_progress($student_id, $course_code) {
  247. // protect datas
  248. $course_code = addslashes($course_code);
  249. // get the informations of the course
  250. $a_course = CourseManager :: get_course_information($course_code);
  251. if (!empty($a_course['db_name'])) {
  252. // table definition
  253. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']);
  254. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']);
  255. $count_lp = Database::fetch_row(Database::query("SELECT count(id) FROM $tbl_course_lp"));
  256. $avg_progress = 0;
  257. if (!empty($count_lp[0]) && !empty($student_id)) {
  258. $condition_user = "";
  259. if (is_array($student_id)) {
  260. $condition_user = " lp_view.user_id IN (".implode(',',$student_id).") AND ";
  261. } else {
  262. $condition_user = " lp_view.user_id = '$student_id' AND ";
  263. }
  264. $sqlProgress = "SELECT SUM(progress) FROM $tbl_course_lp_view AS lp_view WHERE $condition_user lp_view.lp_id IN (SELECT id FROM $tbl_course_lp)";
  265. $resultItem = Database::query($sqlProgress);
  266. $rowItem = Database::fetch_row($resultItem);
  267. $avg_progress = round($rowItem[0] / $count_lp[0], 1);
  268. return $avg_progress;
  269. }
  270. }
  271. return null;
  272. }
  273. /**
  274. * This function gets:
  275. * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max score.
  276. * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max score.
  277. * 3. And finally it will return the average between 1. and 2.
  278. * This function does not take the results of a Test out of a LP
  279. *
  280. * @param User id
  281. * @param Course id
  282. * @param Array limit average to listed lp ids
  283. * @return string value (number %) Which represents a round integer explain in got in 3.
  284. */
  285. public static function get_avg_student_score($student_id, $course_code, $lp_ids=array()) {
  286. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  287. $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  288. $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  289. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  290. $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  291. $course = CourseManager :: get_course_information($course_code);
  292. if (!empty($course['db_name'])) {
  293. $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']);
  294. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']);
  295. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']);
  296. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']);
  297. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']);
  298. $condition_lp = "";
  299. if(count($lp_ids) > 0) {
  300. $condition_lp =" WHERE id IN(".implode(',',$lp_ids).") ";
  301. }
  302. $count_row_lp = Database::fetch_row(Database::query("SELECT count(*) FROM $lp_table $condition_lp"));
  303. $lp_scorm_score_total = 0;
  304. $lp_scorm_weighting_total = 0;
  305. $lp_scorm_result_score_total = 0;
  306. $lp_scorm_loop=0;
  307. $lp_count = 0;
  308. $progress = 0;
  309. if (!empty($count_row_lp[0]) && !empty($student_id)) {
  310. $condition_user1 = "";
  311. if (is_array($student_id)) {
  312. $condition_user1 =" AND user_id IN (".implode(',',$student_id).") ";
  313. } else {
  314. $condition_user1 =" AND user_id = '$student_id' ";
  315. }
  316. $sql = "SELECT max(id) as id, lp_id, user_id FROM $lp_view_table WHERE lp_id IN (SELECT id FROM $lp_table $condition_lp) $condition_user1 GROUP BY lp_id,user_id";
  317. $rs_last_lp_view_id = Database::query($sql);
  318. $score_of_scorm_calculate = 0;
  319. if (Database::num_rows($rs_last_lp_view_id) > 0) {
  320. while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) {
  321. $lp_view_id = $row_lp_view['id'];
  322. // we get the progress
  323. $sql='SELECT progress FROM '.$lp_view_table.' WHERE id="'.$lp_view_id.'"';
  324. $rs = Database::query($sql);
  325. $progress = Database::result($rs,0,'progress');
  326. // item's list of an scorm
  327. $sql_max_score='SELECT lp_iv.score as score,lp_i.max_score
  328. FROM '.$lp_item_view_table.' as lp_iv
  329. INNER JOIN '.$lp_item_table.' as lp_i
  330. ON lp_i.id = lp_iv.lp_item_id
  331. AND lp_i.item_type="sco"
  332. WHERE lp_view_id="'.$lp_view_id.'"';
  333. $res_max_score=Database::query($sql_max_score);
  334. $count_total_loop=0;
  335. $num_rows_max_score=Database::num_rows($res_max_score);
  336. if ($num_rows_max_score==1) {
  337. while ($row_max_score=Database::fetch_array($res_max_score)) {
  338. if ($row_max_score['max_score']==0) {
  339. //when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100.
  340. $lp_scorm_result_score_total+=($row_max_score['score']/100);
  341. $current_value = $row_max_score['score']/100;
  342. } else {
  343. $lp_scorm_result_score_total+=($row_max_score['score']/$row_max_score['max_score']);
  344. $current_value = $row_max_score['score']/$row_max_score['max_score'];
  345. }
  346. $count_total_loop++;
  347. }
  348. } elseif ($num_rows_max_score > 1) {
  349. while ($row_max_score=Database::fetch_array($res_max_score)) {
  350. if ($row_max_score['max_score']==0) {
  351. $lp_scorm_result_score_total+=($row_max_score['score']/100);
  352. $current_value = $row_max_score['score']/100;
  353. } else {
  354. //when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100.
  355. $lp_scorm_result_score_total+=($row_max_score['score']/$row_max_score['max_score']);
  356. $current_value = $row_max_score['score']/$row_max_score['max_score'];
  357. }
  358. $count_total_loop++;
  359. }
  360. }
  361. if ($num_rows_max_score > 0 && ($progress > 0 || $current_value > 0 )) {
  362. $lp_count++;
  363. }
  364. if ($count_total_loop==0) {
  365. $count_total_loop=1;
  366. }
  367. $score_of_scorm_calculate=round((($lp_scorm_result_score_total/$count_total_loop)*100),2);
  368. }
  369. }
  370. if(count($lp_ids)==0 ) {
  371. $score_of_scorm_calculate=round((($score_of_scorm_calculate/$count_row_lp[0])),2);
  372. }
  373. $lp_scorm_score_total = $score_of_scorm_calculate;
  374. $condition_user2 = "";
  375. if (is_array($student_id)) {
  376. $condition_user2 =" lp_view.user_id IN (".implode(',',$student_id).") AND ";
  377. } else {
  378. $condition_user2 =" lp_view.user_id = '$student_id' AND ";
  379. }
  380. //Path is the exercise id
  381. $sql = "SELECT lp_view.id as lp_view_id, lp_view.lp_id as lp_id, lp_item.path, lp_item.id as item_id, lp_item.max_score, lp_view.user_id as user_id
  382. FROM $lp_view_table lp_view
  383. INNER JOIN $lp_item_table lp_item ON lp_item.lp_id = lp_view.lp_id AND item_type='".TOOL_QUIZ."'
  384. WHERE $condition_user2 lp_view.lp_id IN (SELECT id FROM $lp_table $condition_lp)";;
  385. $rsItems = Database::query($sql);
  386. $total_score = $total_weighting = 0;
  387. if (Database::num_rows($rsItems) > 0) {
  388. while ($item = Database::fetch_array($rsItems)) {
  389. $lp_view_id = $item['lp_view_id'];
  390. $lp_item_id = $item['item_id'];
  391. $lp_id = $item['lp_id'];
  392. $user_id = $item['user_id'];
  393. // we take the score from a LP because we have lp_view_id
  394. $sql = "SELECT score FROM $lp_item_view_table WHERE lp_item_id = '$lp_item_id' and lp_view_id = '$lp_view_id'
  395. ORDER BY view_count DESC limit 1";
  396. $rsScores = Database::query($sql);
  397. // Real max score - this was implemented because of the random exercises
  398. $sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
  399. 'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $user_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$lp_item_id.'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
  400. $resultLastAttempt = Database::query($sql_last_attempt);
  401. $num = Database :: num_rows($resultLastAttempt);
  402. if ($num > 0){
  403. if ($num > 1){
  404. while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
  405. $id_last_attempt = $rowLA[0];
  406. }
  407. } else {
  408. $id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
  409. }
  410. }
  411. $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
  412. "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
  413. $result = Database::query($sql);
  414. $row_max_score = Database :: fetch_array($result);
  415. $maxscore = $row_max_score['maxscore'];
  416. if ($maxscore=='') {
  417. $maxscore = $item['max_score'];
  418. }
  419. if(Database::num_rows($rsScores)>0) {
  420. $total_score = Database::result($rsScores, 0, 0);
  421. $total_weighting += $maxscore;
  422. if($total_weighting>0 && $maxscore>0) {
  423. $lp_scorm_score_total += ($total_score/$maxscore)*100;
  424. $lp_scorm_weighting_total+=100;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. $totalScore = $lp_scorm_score_total;
  431. $pourcentageScore = 0;
  432. if($lp_scorm_weighting_total>0) {
  433. //i.e 10.52
  434. $pourcentageScore = round( (($totalScore * 100) / $lp_scorm_weighting_total),2);
  435. return $pourcentageScore;
  436. } elseif ($score_of_scorm_calculate>0) {
  437. //echo '<br>'.$score_of_scorm_calculate;
  438. return $score_of_scorm_calculate;
  439. } else {
  440. return null;
  441. }
  442. }
  443. }
  444. /**
  445. * gets the list of students followed by coach
  446. * @param integer $coach_id the id of the coach
  447. * @return Array the list of students
  448. */
  449. public static function get_student_followed_by_coach($coach_id) {
  450. $coach_id = intval($coach_id);
  451. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  452. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  453. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  454. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  455. $a_students = array ();
  456. //////////////////////////////////////////////////////////////
  457. // At first, courses where $coach_id is coach of the course //
  458. //////////////////////////////////////////////////////////////
  459. $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id.' AND status=2';
  460. global $_configuration;
  461. if ($_configuration['multiple_access_urls']==true) {
  462. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  463. $access_url_id = api_get_current_access_url_id();
  464. if ($access_url_id != -1) {
  465. $sql = 'SELECT scu.id_session, scu.course_code
  466. FROM ' . $tbl_session_course_user . ' scu INNER JOIN '.$tbl_session_rel_access_url.' sru
  467. ON (scu.id_session=sru.session_id)
  468. WHERE scu.id_user=' . $coach_id.' AND scu.status=2 AND sru.access_url_id = '.$access_url_id;
  469. }
  470. }
  471. $result = Database::query($sql);
  472. while ($a_courses = Database::fetch_array($result)) {
  473. $course_code = $a_courses["course_code"];
  474. $id_session = $a_courses["id_session"];
  475. $sql = "SELECT distinct srcru.id_user
  476. FROM $tbl_session_course_user AS srcru, $tbl_session_user sru
  477. WHERE srcru.id_user = sru.id_user AND srcru.id_session = sru.id_session AND srcru.course_code='$course_code' AND srcru.id_session='$id_session'";
  478. $rs = Database::query($sql);
  479. while ($row = Database::fetch_array($rs)) {
  480. $a_students[$row['id_user']] = $row['id_user'];
  481. }
  482. }
  483. //////////////////////////////////////////////////////////////
  484. // Then, courses where $coach_id is coach of the session //
  485. //////////////////////////////////////////////////////////////
  486. $sql = 'SELECT session_course_user.id_user
  487. FROM ' . $tbl_session_course_user . ' as session_course_user
  488. INNER JOIN '.$tbl_session_user.' sru ON session_course_user.id_user = sru.id_user AND session_course_user.id_session = sru.id_session
  489. INNER JOIN ' . $tbl_session_course . ' as session_course
  490. ON session_course.course_code = session_course_user.course_code
  491. AND session_course_user.id_session = session_course.id_session
  492. INNER JOIN ' . $tbl_session . ' as session
  493. ON session.id = session_course.id_session
  494. AND session.id_coach = ' . $coach_id;
  495. if ($_configuration['multiple_access_urls']==true) {
  496. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  497. $access_url_id = api_get_current_access_url_id();
  498. if ($access_url_id != -1){
  499. $sql = 'SELECT session_course_user.id_user
  500. FROM ' . $tbl_session_course_user . ' as session_course_user
  501. INNER JOIN '.$tbl_session_user.' sru ON session_course_user.id_user = sru.id_user AND session_course_user.id_session = sru.id_session
  502. INNER JOIN ' . $tbl_session_course . ' as session_course
  503. ON session_course.course_code = session_course_user.course_code
  504. AND session_course_user.id_session = session_course.id_session
  505. INNER JOIN ' . $tbl_session . ' as session
  506. ON session.id = session_course.id_session
  507. AND session.id_coach = ' . $coach_id.'
  508. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  509. ON session.id = session_rel_url.session_id WHERE access_url_id = '.$access_url_id;
  510. }
  511. }
  512. $result = Database::query($sql);
  513. while ($row = Database::fetch_array($result)) {
  514. $a_students[$row['id_user']] = $row['id_user'];
  515. }
  516. return $a_students;
  517. }
  518. public static function get_student_followed_by_coach_in_a_session($id_session, $coach_id) {
  519. $coach_id = intval($coach_id);
  520. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  521. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  522. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  523. $a_students = array ();
  524. //////////////////////////////////////////////////////////////
  525. // At first, courses where $coach_id is coach of the course //
  526. //////////////////////////////////////////////////////////////
  527. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_session="' . $id_session . '" AND id_user=' . $coach_id.' AND status=2';
  528. $result = Database::query($sql);
  529. while ($a_courses = Database::fetch_array($result)) {
  530. $course_code = $a_courses["course_code"];
  531. $sql = "SELECT distinct srcru.id_user
  532. FROM $tbl_session_course_user AS srcru
  533. WHERE course_code='$course_code' and id_session = '" . $id_session . "'";
  534. $rs = Database::query($sql);
  535. while ($row = Database::fetch_array($rs)) {
  536. $a_students[$row['id_user']] = $row['id_user'];
  537. }
  538. }
  539. //////////////////////////////////////////////////////////////
  540. // Then, courses where $coach_id is coach of the session //
  541. //////////////////////////////////////////////////////////////
  542. $dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
  543. $result = Database::query($dsl_session_coach);
  544. //He is the session_coach so we select all the users in the session
  545. if (Database::num_rows($result) > 0) {
  546. $sql = 'SELECT DISTINCT srcru.id_user FROM ' . $tbl_session_course_user . ' AS srcru WHERE id_session="' . $id_session . '"';
  547. $result = Database::query($sql);
  548. while ($row = Database::fetch_array($result)) {
  549. $a_students[$row['id_user']] = $row['id_user'];
  550. }
  551. }
  552. return $a_students;
  553. }
  554. public static function is_allowed_to_coach_student($coach_id, $student_id) {
  555. $coach_id = intval($coach_id);
  556. $student_id = intval($student_id);
  557. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  558. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  559. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  560. //////////////////////////////////////////////////////////////
  561. // At first, courses where $coach_id is coach of the course //
  562. //////////////////////////////////////////////////////////////
  563. /*$sql = 'SELECT 1
  564. FROM ' . $tbl_session_course_user . ' AS session_course_user
  565. INNER JOIN ' . $tbl_session_course . ' AS session_course
  566. ON session_course.course_code = session_course_user.course_code
  567. AND id_coach=' . $coach_id . '
  568. WHERE id_user=' . $student_id;*/
  569. $sql = 'SELECT 1 FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id .' AND status=2';
  570. $result = Database::query($sql);
  571. if (Database::num_rows($result) > 0) {
  572. return true;
  573. }
  574. //////////////////////////////////////////////////////////////
  575. // Then, courses where $coach_id is coach of the session //
  576. //////////////////////////////////////////////////////////////
  577. $sql = 'SELECT session_course_user.id_user
  578. FROM ' . $tbl_session_course_user . ' as session_course_user
  579. INNER JOIN ' . $tbl_session_course . ' as session_course
  580. ON session_course.course_code = session_course_user.course_code
  581. INNER JOIN ' . $tbl_session . ' as session
  582. ON session.id = session_course.id_session
  583. AND session.id_coach = ' . $coach_id . '
  584. WHERE id_user = ' . $student_id;
  585. $result = Database::query($sql);
  586. if (Database::num_rows($result) > 0) {
  587. return true;
  588. }
  589. return false;
  590. }
  591. public static function get_courses_followed_by_coach($coach_id, $id_session = '')
  592. {
  593. $coach_id = intval($coach_id);
  594. if (!empty ($id_session))
  595. $id_session = intval($id_session);
  596. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  597. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  598. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  599. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  600. //////////////////////////////////////////////////////////////
  601. // At first, courses where $coach_id is coach of the course //
  602. //////////////////////////////////////////////////////////////
  603. $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id.' AND status=2';
  604. global $_configuration;
  605. if ($_configuration['multiple_access_urls']==true) {
  606. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  607. $access_url_id = api_get_current_access_url_id();
  608. if ($access_url_id != -1){
  609. $sql = 'SELECT DISTINCT scu.course_code FROM ' . $tbl_session_course_user . ' scu INNER JOIN '.$tbl_course_rel_access_url.' cru
  610. ON (scu.course_code = cru.course_code)
  611. WHERE scu.id_user=' . $coach_id.' AND scu.status=2 AND cru.access_url_id = '.$access_url_id;
  612. }
  613. }
  614. if (!empty ($id_session))
  615. $sql .= ' AND id_session=' . $id_session;
  616. $result = Database::query($sql);
  617. while ($row = Database::fetch_array($result)) {
  618. $a_courses[$row['course_code']] = $row['course_code'];
  619. }
  620. //////////////////////////////////////////////////////////////
  621. // Then, courses where $coach_id is coach of the session //
  622. //////////////////////////////////////////////////////////////
  623. $sql = 'SELECT DISTINCT session_course.course_code
  624. FROM ' . $tbl_session_course . ' as session_course
  625. INNER JOIN ' . $tbl_session . ' as session
  626. ON session.id = session_course.id_session
  627. AND session.id_coach = ' . $coach_id . '
  628. INNER JOIN ' . $tbl_course . ' as course
  629. ON course.code = session_course.course_code';
  630. if ($_configuration['multiple_access_urls']==true) {
  631. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  632. $access_url_id = api_get_current_access_url_id();
  633. if ($access_url_id != -1){
  634. $sql = 'SELECT DISTINCT session_course.course_code
  635. FROM ' . $tbl_session_course . ' as session_course
  636. INNER JOIN ' . $tbl_session . ' as session
  637. ON session.id = session_course.id_session
  638. AND session.id_coach = ' . $coach_id . '
  639. INNER JOIN ' . $tbl_course . ' as course
  640. ON course.code = session_course.course_code
  641. INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url
  642. ON (session_course.course_code = course_rel_url.course_code)';
  643. }
  644. }
  645. if (!empty ($id_session)) {
  646. $sql .= ' WHERE session_course.id_session=' . $id_session;
  647. if ($_configuration['multiple_access_urls']==true)
  648. $sql .= ' AND access_url_id = '.$access_url_id;
  649. } else {
  650. if ($_configuration['multiple_access_urls']==true)
  651. $sql .= ' WHERE access_url_id = '.$access_url_id;
  652. }
  653. $result = Database::query($sql);
  654. while ($row = Database::fetch_array($result)) {
  655. $a_courses[$row['course_code']] = $row['course_code'];
  656. }
  657. return $a_courses;
  658. }
  659. public static function get_sessions_coached_by_user($coach_id) {
  660. // table definition
  661. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  662. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  663. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  664. // protect datas
  665. $coach_id = intval($coach_id);
  666. // session where we are general coach
  667. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  668. FROM ' . $tbl_session . '
  669. WHERE id_coach=' . $coach_id;
  670. global $_configuration;
  671. if ($_configuration['multiple_access_urls']==true) {
  672. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  673. $access_url_id = api_get_current_access_url_id();
  674. if ($access_url_id != -1){
  675. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  676. FROM ' . $tbl_session . ' session INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  677. ON (session.id = session_rel_url.session_id)
  678. WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id;
  679. }
  680. }
  681. $rs = Database::query($sql);
  682. while ($row = Database::fetch_array($rs))
  683. {
  684. $a_sessions[$row["id"]] = $row;
  685. }
  686. // session where we are coach of a course
  687. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  688. FROM ' . $tbl_session . ' as session
  689. INNER JOIN ' . $tbl_session_course_user . ' as session_course_user
  690. ON session.id = session_course_user.id_session
  691. AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2';
  692. global $_configuration;
  693. if ($_configuration['multiple_access_urls']==true) {
  694. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  695. $access_url_id = api_get_current_access_url_id();
  696. if ($access_url_id != -1){
  697. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  698. FROM ' . $tbl_session . ' as session
  699. INNER JOIN ' . $tbl_session_course_user . ' as session_course_user
  700. ON session.id = session_course_user.id_session AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2
  701. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  702. ON (session.id = session_rel_url.session_id)
  703. WHERE access_url_id = '.$access_url_id;
  704. }
  705. }
  706. $rs = Database::query($sql);
  707. while ($row = Database::fetch_array($rs))
  708. {
  709. $a_sessions[$row["id"]] = $row;
  710. }
  711. if (is_array($a_sessions)) {
  712. foreach ($a_sessions as & $session) {
  713. if ($session['date_start'] == '0000-00-00') {
  714. $session['status'] = get_lang('SessionActive');
  715. }
  716. else {
  717. $date_start = explode('-', $session['date_start']);
  718. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  719. $date_end = explode('-', $session['date_end']);
  720. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  721. if ($time_start < time() && time() < $time_end) {
  722. $session['status'] = get_lang('SessionActive');
  723. }
  724. else{
  725. if (time() < $time_start) {
  726. $session['status'] = get_lang('SessionFuture');
  727. }
  728. else{
  729. if (time() > $time_end) {
  730. $session['status'] = get_lang('SessionPast');
  731. }
  732. }
  733. }
  734. }
  735. }
  736. }
  737. return $a_sessions;
  738. }
  739. public static function get_courses_list_from_session($session_id) {
  740. //protect datas
  741. $session_id = intval($session_id);
  742. // table definition
  743. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  744. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  745. $sql = 'SELECT DISTINCT course_code
  746. FROM ' . $tbl_session_course . '
  747. WHERE id_session=' . $session_id;
  748. $rs = Database::query($sql);
  749. $a_courses = array ();
  750. while ($row = Database::fetch_array($rs)) {
  751. $a_courses[$row['course_code']] = $row;
  752. }
  753. return $a_courses;
  754. }
  755. public static function count_student_assignments($student_id, $course_code) {
  756. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  757. // protect datas
  758. $course_code = Database::escape_string($course_code);
  759. // get the informations of the course
  760. $a_course = CourseManager :: get_course_information($course_code);
  761. if (!empty($a_course['db_name'])) {
  762. // table definition
  763. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']);
  764. $condition_user = "";
  765. if (is_array($student_id)) {
  766. $condition_user = " AND insert_user_id IN (".implode(',',$student_id).") ";
  767. } else {
  768. $condition_user = " AND insert_user_id = '$student_id' ";
  769. }
  770. $sql = "SELECT count(tool) FROM $tbl_item_property WHERE tool='work' $condition_user ";
  771. $rs = Database::query($sql);
  772. $row = Database::fetch_row($rs);
  773. return $row[0];
  774. }
  775. return null;
  776. }
  777. public static function count_student_messages($student_id, $course_code) {
  778. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  779. // protect datas
  780. $course_code = addslashes($course_code);
  781. // get the informations of the course
  782. $a_course = CourseManager :: get_course_information($course_code);
  783. if (!empty($a_course['db_name'])) {
  784. // table definition
  785. $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  786. $condition_user = "";
  787. if (is_array($student_id)) {
  788. $condition_user = " WHERE poster_id IN (".implode(',',$student_id).") ";
  789. } else {
  790. $condition_user = " WHERE poster_id = '$student_id' ";
  791. }
  792. $sql = "SELECT count(post_id) FROM $tbl_messages $condition_user ";
  793. $rs = Database::query($sql);
  794. $row = Database::fetch_row($rs);
  795. return $row[0];
  796. }
  797. return null;
  798. }
  799. /**
  800. * This function counts the number of post by course
  801. * @param string $course_code - Course ID
  802. * @return int the number of post by course
  803. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  804. * @version enero 2009, dokeos 1.8.6
  805. */
  806. public static function count_number_of_posts_by_course($course_code) {
  807. //protect data
  808. $course_code = addslashes($course_code);
  809. // get the informations of the course
  810. $a_course = CourseManager :: get_course_information($course_code);
  811. $count = 0;
  812. if (!empty($a_course['db_name'])) {
  813. $tbl_posts = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  814. $sql = "SELECT count(*) FROM $tbl_posts";
  815. $result = Database::query($sql);
  816. $row = Database::fetch_row($result);
  817. $count = $row[0];
  818. return $count;
  819. } else {
  820. return null;
  821. }
  822. }
  823. /**
  824. * This function counts the number of threads by course
  825. * @param string $course_code - Course ID
  826. * @return int the number of threads by course
  827. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  828. * @version enero 2009, dokeos 1.8.6
  829. */
  830. public static function count_number_of_threads_by_course($course_code) {
  831. //protect data
  832. $course_code = addslashes($course_code);
  833. // get the informations of the course
  834. $a_course = CourseManager :: get_course_information($course_code);
  835. $count = 0;
  836. if (!empty($a_course['db_name'])) {
  837. $tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $a_course['db_name']);
  838. $sql = "SELECT count(*) FROM $tbl_threads";
  839. $result = Database::query($sql);
  840. $row = Database::fetch_row($result);
  841. $count = $row[0];
  842. return $count;
  843. } else {
  844. return null;
  845. }
  846. }
  847. /**
  848. * This function counts the number of forums by course
  849. * @param string $course_code - Course ID
  850. * @return int the number of forums by course
  851. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  852. * @version enero 2009, dokeos 1.8.6
  853. */
  854. public static function count_number_of_forums_by_course($course_code) {
  855. //protect data
  856. $course_code = addslashes($course_code);
  857. // get the informations of the course
  858. $a_course = CourseManager :: get_course_information($course_code);
  859. $count = 0;
  860. if (!empty($a_course['db_name'])) {
  861. $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
  862. $sql = "SELECT count(*) FROM $tbl_forums";
  863. $result = Database::query($sql);
  864. $row = Database::fetch_row($result);
  865. $count = $row[0];
  866. return $count;
  867. } else {
  868. return null;
  869. }
  870. }
  871. /**
  872. * This function counts the chat last connections by course in x days
  873. * @param string $course_code - Course ID
  874. * @param int $last_days - last x days
  875. * @return int the chat last connections by course in x days
  876. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  877. * @version enero 2009, dokeos 1.8.6
  878. */
  879. public static function chat_connections_during_last_x_days_by_course($course_code,$last_days) {
  880. //protect data
  881. $last_days = intval($last_days);
  882. $course_code = addslashes($course_code);
  883. // get the informations of the course
  884. $a_course = CourseManager :: get_course_information($course_code);
  885. $count = 0;
  886. if (!empty($a_course['db_name'])) {
  887. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']);
  888. $sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date
  889. AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."'";
  890. $result = Database::query($sql);
  891. $row = Database::fetch_row($result);
  892. $count = $row[0];
  893. return $count;
  894. } else {
  895. return null;
  896. }
  897. }
  898. /**
  899. * This function gets the last student's connection in chat
  900. * @param int $student_id - Student ID
  901. * @param string $course_code - Course ID
  902. * @return string the last connection
  903. * @author Christian Fasanando <christian.fasanando@dokeos.com>,
  904. * @version enero 2009, dokeos 1.8.6
  905. */
  906. public static function chat_last_connection($student_id,$course_code) {
  907. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  908. //protect datas
  909. $student_id = intval($student_id);
  910. $course_code = addslashes($course_code);
  911. // get the informations of the course
  912. $a_course = CourseManager :: get_course_information($course_code);
  913. $date_time = '';
  914. if (!empty($a_course['db_name'])) {
  915. // table definition
  916. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']);
  917. $sql = "SELECT access_date FROM $tbl_stats_access
  918. WHERE access_tool='".TOOL_CHAT."' AND access_user_id='$student_id' AND access_cours_code = '$course_code' ORDER BY access_date DESC limit 1";
  919. $rs = Database::query($sql);
  920. $row = Database::fetch_array($rs);
  921. $last_connection = $row['access_date'];
  922. if (!empty($last_connection)) {
  923. $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection));
  924. $time = explode(' ',$last_connection);
  925. $date_time = $date_format_long.' '.$time[1];
  926. }
  927. return $date_time;
  928. } else {
  929. return null;
  930. }
  931. }
  932. public static function count_student_visited_links($student_id, $course_code) {
  933. // protect datas
  934. $student_id = intval($student_id);
  935. $course_code = addslashes($course_code);
  936. // table definition
  937. $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  938. $sql = 'SELECT 1
  939. FROM ' . $tbl_stats_links . '
  940. WHERE links_user_id=' . $student_id . '
  941. AND links_cours_id="' . $course_code . '"';
  942. $rs = Database::query($sql);
  943. return Database::num_rows($rs);
  944. }
  945. public static function count_student_downloaded_documents($student_id, $course_code) {
  946. // protect datas
  947. $student_id = intval($student_id);
  948. $course_code = addslashes($course_code);
  949. // table definition
  950. $tbl_stats_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  951. $sql = 'SELECT 1
  952. FROM ' . $tbl_stats_documents . '
  953. WHERE down_user_id=' . $student_id . '
  954. AND down_cours_id="' . $course_code . '"';
  955. $rs = Database::query($sql);
  956. return Database::num_rows($rs);
  957. }
  958. public static function get_course_list_in_session_from_student($user_id, $id_session) {
  959. $user_id = intval($user_id);
  960. $id_session = intval($id_session);
  961. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  962. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user="' . $user_id . '" AND id_session="' . $id_session . '"';
  963. $result = Database::query($sql);
  964. $a_courses = array ();
  965. while ($row = Database::fetch_array($result)) {
  966. $a_courses[$row['course_code']] = $row['course_code'];
  967. }
  968. return $a_courses;
  969. }
  970. public static function get_inactives_students_in_course($course_code, $since, $session_id=0)
  971. {
  972. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  973. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  974. $table_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  975. $inner = '';
  976. if($session_id!=0)
  977. {
  978. $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user
  979. ON stats_login.course_code = session_course_user.course_code
  980. AND session_course_user.id_session = '.intval($session_id).'
  981. AND session_course_user.id_user = stats_login.user_id ';
  982. }
  983. $sql = 'SELECT user_id, MAX(login_course_date) max_date FROM'.$tbl_track_login.' stats_login'.$inner.'
  984. GROUP BY user_id
  985. HAVING DATE_SUB( NOW(), INTERVAL '.$since.' DAY) > max_date ';
  986. //HAVING DATE_ADD(max_date, INTERVAL '.$since.' DAY) < NOW() ';
  987. if ($since == 'never') {
  988. $sql = 'SELECT course_user.user_id FROM '.$table_course_rel_user.' course_user
  989. LEFT JOIN '. $tbl_track_login.' stats_login
  990. ON course_user.user_id = stats_login.user_id'.
  991. $inner.'
  992. WHERE course_user.course_code = \''.Database::escape_string($course_code).'\'
  993. AND stats_login.login_course_date IS NULL
  994. GROUP BY course_user.user_id';
  995. }
  996. $rs = api_sql_query($sql);
  997. $inactive_users = array();
  998. while($user = Database::fetch_array($rs))
  999. {
  1000. $inactive_users[] = $user['user_id'];
  1001. }
  1002. return $inactive_users;
  1003. }
  1004. public static function count_login_per_student($student_id, $course_code) {
  1005. $student_id = intval($student_id);
  1006. $course_code = addslashes($course_code);
  1007. $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  1008. $sql = 'SELECT '.$student_id.'
  1009. FROM ' . $tbl_course_rel_user . '
  1010. WHERE access_user_id=' . $student_id . '
  1011. AND access_cours_code="' . $course_code . '"';
  1012. $rs = Database::query($sql);
  1013. $nb_login = Database::num_rows($rs);
  1014. return $nb_login;
  1015. }
  1016. public static function get_student_followed_by_drh($hr_dept_id) {
  1017. $hr_dept_id = intval($hr_dept_id);
  1018. $a_students = array ();
  1019. $tbl_organism = Database :: get_main_table(TABLE_MAIN_ORGANISM);
  1020. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1021. $sql = 'SELECT DISTINCT user_id FROM '.$tbl_user.' as user
  1022. WHERE hr_dept_id='.$hr_dept_id;
  1023. $rs = Database::query($sql);
  1024. while($user = Database :: fetch_array($rs))
  1025. {
  1026. $a_students[$user['user_id']] = $user['user_id'];
  1027. }
  1028. return $a_students;
  1029. }
  1030. /**
  1031. * allow get average of test of scorm and lp
  1032. * @author isaac flores paz <florespaz@bidsoftperu.com>
  1033. * @param int the user id
  1034. * @param string the course id
  1035. */
  1036. public static function get_average_test_scorm_and_lp ($user_id,$course_id) {
  1037. //the score inside the Reporting table
  1038. $course_info=api_get_course_info($course_id);
  1039. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']);
  1040. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_info['dbName']);
  1041. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course_info['dbName']);
  1042. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']);
  1043. $sql_type='SELECT id,lp_type FROM '.$lp_table;
  1044. $rs_type=Database::query($sql_type);
  1045. $average_data=0;
  1046. $count_loop=0;
  1047. while ($row_type=Database::fetch_array($rs_type)) {
  1048. if ($row_type['lp_type']==1) {//lp dokeos
  1049. $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
  1050. $rs_last_lp_view_id = Database::query($sql);
  1051. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  1052. $sql_list_view='SELECT li.max_score,lv.user_id,liw.score,(liw.score/li.max_score) as sum_data FROM '.$lp_item_table.' li INNER JOIN '.$lp_view_table.' lv
  1053. ON li.lp_id=lv.lp_id INNER JOIN '.$lp_item_view_table.' liw ON liw.lp_item_id=li.id WHERE lv.user_id="'.$user_id.'" AND li.item_type="quiz" AND liw.lp_view_id="'.$lp_view_id.'"';
  1054. $sum=0;
  1055. $tot=0;
  1056. $rs_list_view1=Database::query($sql_list_view);
  1057. while ($row_list_view=Database::fetch_array($rs_list_view1)) {
  1058. $sum=$sum+$row_list_view['sum_data'];
  1059. $tot++;
  1060. }
  1061. if ($tot==0) {
  1062. $tot=1;
  1063. }
  1064. $average_data1=$sum/$tot;
  1065. $sql_list_view='';
  1066. $rs_last_lp_view_id='';
  1067. } elseif ($row_type['lp_type']==2) {//lp scorm
  1068. $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
  1069. $rs_last_lp_view_id = Database::query($sql);
  1070. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  1071. $sql_list_view='SELECT li.max_score,lv.user_id,liw.score,((liw.score/li.max_score)*100) as sum_data FROM '.$lp_item_table.' li INNER JOIN '.$lp_view_table.' lv
  1072. ON li.lp_id=lv.lp_id INNER JOIN '.$lp_item_view_table.' liw ON liw.lp_item_id=li.id WHERE lv.user_id="'.$user_id.'" AND li.item_type="sco" AND liw.lp_view_id="'.$lp_view_id.'"';
  1073. $tot=0;
  1074. $sum=0;
  1075. $rs_list_view2=Database::query($sql_list_view);
  1076. while ($row_list_view=Database::fetch_array($rs_list_view2)) {
  1077. $sum=$sum+$row_list_view['sum_data'];
  1078. $tot++;
  1079. }
  1080. if ($tot==0) {
  1081. $tot=1;
  1082. }
  1083. $average_data2=$sum/$tot;
  1084. }
  1085. $average_data_sum=$average_data_sum+$average_data1+$average_data2;
  1086. $average_data2=0;
  1087. $average_data1=0;
  1088. $count_loop++;
  1089. }
  1090. if ((int)$count_loop > 0) {
  1091. $avg_student_score = round(($average_data_sum / $count_loop * 100), 2);
  1092. }
  1093. return $avg_student_score;
  1094. }
  1095. }
  1096. class TrackingCourseLog {
  1097. function count_item_resources() {
  1098. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1099. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  1100. $sql = "SELECT count(tool) AS total_number_of_items FROM $table_item_property track_resource, $table_user user" .
  1101. " WHERE track_resource.insert_user_id = user.user_id";
  1102. if (isset($_GET['keyword'])) {
  1103. $keyword = Database::escape_string(trim($_GET['keyword']));
  1104. $sql .= " AND (user.username LIKE '%".$keyword."%' OR lastedit_type LIKE '%".$keyword."%' OR tool LIKE '%".$keyword."%')";
  1105. }
  1106. $sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description')";
  1107. $res = Database::query($sql);
  1108. $obj = Database::fetch_object($res);
  1109. return $obj->total_number_of_items;
  1110. }
  1111. function get_item_resources_data($from, $number_of_items, $column, $direction) {
  1112. global $dateTimeFormatLong;
  1113. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1114. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  1115. $table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  1116. $sql = "SELECT
  1117. tool as col0,
  1118. lastedit_type as col1,
  1119. ref as ref,
  1120. user.username as col3,
  1121. insert_date as col5,
  1122. visibility as col6
  1123. FROM $table_item_property track_resource, $table_user user
  1124. WHERE track_resource.insert_user_id = user.user_id ";
  1125. if (isset($_GET['keyword'])) {
  1126. $keyword = Database::escape_string(trim($_GET['keyword']));
  1127. $sql .= " AND (user.username LIKE '%".$keyword."%' OR lastedit_type LIKE '%".$keyword."%' OR tool LIKE '%".$keyword."%') ";
  1128. }
  1129. $sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description')";
  1130. if ($column == 0) { $column = '0'; }
  1131. if ($column != '' && $direction != '') {
  1132. if ($column != 2 && $column != 4) {
  1133. $sql .= " ORDER BY col$column $direction";
  1134. }
  1135. } else {
  1136. $sql .= " ORDER BY col5 DESC ";
  1137. }
  1138. $sql .= " LIMIT $from, $number_of_items ";
  1139. $res = Database::query($sql) or die(Database::error());
  1140. $resources = array ();
  1141. while ($row = Database::fetch_array($res)) {
  1142. $ref = $row['ref'];
  1143. $table_name = TrackingCourseLog::get_tool_name_table($row['col0']);
  1144. $table_tool = Database :: get_course_table($table_name['table_name']);
  1145. $id = $table_name['id_tool'];
  1146. $query = "SELECT session.id, session.name, user.username FROM $table_tool tool, $table_session session, $table_user user" .
  1147. " WHERE tool.session_id = session.id AND session.id_coach = user.user_id AND tool.$id = $ref";
  1148. $recorset = Database::query($query);
  1149. if (!empty($recorset)) {
  1150. $obj = Database::fetch_object($recorset);
  1151. $name_session = '';
  1152. $coach_name = '';
  1153. if (!empty($obj)) {
  1154. $name_session = $obj->name;
  1155. $coach_name = $obj->username;
  1156. }
  1157. $url_tool = api_get_path(WEB_CODE_PATH).$table_name['link_tool'];
  1158. $row[0] = '';
  1159. if ($row['col6'] != 2) {
  1160. $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'&'.$obj->id.'">'.api_ucfirst($row['col0']).'</a>';
  1161. } else {
  1162. $row[0] = api_ucfirst($row['col0']);
  1163. }
  1164. $row[1] = get_lang($row[1]);
  1165. $row[5] = api_ucfirst(format_locale_date($dateTimeFormatLong, strtotime($row['col5'])));
  1166. $row[4] = '';
  1167. if ($table_name['table_name'] == 'document') {
  1168. $condition = 'tool.title as title';
  1169. $query_document = "SELECT $condition FROM $table_tool tool" .
  1170. " WHERE id = $ref";
  1171. $rs_document = Database::query($query_document) or die(Database::error());
  1172. $obj_document = Database::fetch_object($rs_document);
  1173. $row[4] = $obj_document->title;
  1174. }
  1175. $row2 = $name_session;
  1176. if (!empty($coach_name)) {
  1177. $row2 .= '<br />'.get_lang('Coach').': '.$coach_name;
  1178. }
  1179. $row[2] = $row2;
  1180. $resources[] = $row;
  1181. }
  1182. }
  1183. return $resources;
  1184. }
  1185. function get_tool_name_table($tool) {
  1186. switch ($tool) {
  1187. case 'document':
  1188. $table_name = TABLE_DOCUMENT;
  1189. $link_tool = 'document/document.php';
  1190. $id_tool = 'id';
  1191. break;
  1192. case 'learnpath':
  1193. $table_name = TABLE_LP_MAIN;
  1194. $link_tool = 'newscorm/lp_controller.php';
  1195. $id_tool = 'id';
  1196. break;
  1197. case 'quiz':
  1198. $table_name = TABLE_QUIZ_TEST;
  1199. $link_tool = 'exercice/exercice.php';
  1200. $id_tool = 'id';
  1201. break;
  1202. case 'glossary':
  1203. $table_name = TABLE_GLOSSARY;
  1204. $link_tool = 'glossary/index.php';
  1205. $id_tool = 'glossary_id';
  1206. break;
  1207. case 'link':
  1208. $table_name = TABLE_LINK;
  1209. $link_tool = 'link/link.php';
  1210. $id_tool = 'id';
  1211. break;
  1212. case 'course_description':
  1213. $table_name = TABLE_COURSE_DESCRIPTION;
  1214. $link_tool = 'course_description/';
  1215. $id_tool = 'id';
  1216. break;
  1217. default:
  1218. $table_name = $tool;
  1219. break;
  1220. }
  1221. return array('table_name' => $table_name,
  1222. 'link_tool' => $link_tool,
  1223. 'id_tool' => $id_tool);
  1224. }
  1225. function display_additional_profile_fields() {
  1226. // getting all the extra profile fields that are defined by the platform administrator
  1227. $extra_fields = UserManager :: get_extra_fields(0,50,5,'ASC');
  1228. // creating the form
  1229. $return = '<form action="courseLog.php" method="get" name="additional_profile_field_form" id="additional_profile_field_form">';
  1230. // the select field with the additional user profile fields (= this is where we select the field of which we want to see
  1231. // the information the users have entered or selected.
  1232. $return .= '<select name="additional_profile_field">';
  1233. $return .= '<option value="-">'.get_lang('SelectFieldToAdd').'</option>';
  1234. foreach ($extra_fields as $key=>$field) {
  1235. // show only extra fields that are visible, added by J.Montoya
  1236. if ($field[6]==1) {
  1237. if ($field[0] == $_GET['additional_profile_field'] ) {
  1238. $selected = 'selected="selected"';
  1239. } else {
  1240. $selected = '';
  1241. }
  1242. $return .= '<option value="'.$field[0].'" '.$selected.'>'.$field[3].'</option>';
  1243. }
  1244. }
  1245. $return .= '</select>';
  1246. // the form elements for the $_GET parameters (because the form is passed through GET
  1247. foreach ($_GET as $key=>$value){
  1248. if ($key <> 'additional_profile_field') {
  1249. $return .= '<input type="hidden" name="'.$key.'" value="'.Security::Remove_XSS($value).'" />';
  1250. }
  1251. }
  1252. // the submit button
  1253. $return .= '<button class="save" type="submit">'.get_lang('AddAdditionalProfileField').'</button>';
  1254. $return .= '</form>';
  1255. return $return;
  1256. }
  1257. /**
  1258. * This function gets all the information of a certrain ($field_id) additional profile field.
  1259. * It gets the information of all the users so that it can be displayed in the sortable table or in the csv or xls export
  1260. *
  1261. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1262. * @since October 2009
  1263. * @version 1.8.7
  1264. */
  1265. function get_addtional_profile_information_of_field($field_id){
  1266. // Database table definition
  1267. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  1268. $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  1269. $sql = "SELECT user.user_id, field.field_value FROM $table_user user, $table_user_field_values field
  1270. WHERE user.user_id = field.user_id
  1271. AND field.field_id='".intval($field_id)."'";
  1272. $result = api_sql_query($sql);
  1273. while($row = Database::fetch_array($result))
  1274. {
  1275. $return[$row['user_id']][] = $row['field_value'];
  1276. }
  1277. return $return;
  1278. }
  1279. /**
  1280. * This function gets all the information of a certrain ($field_id) additional profile field for a specific list of users is more efficent than get_addtional_profile_information_of_field() function
  1281. * It gets the information of all the users so that it can be displayed in the sortable table or in the csv or xls export
  1282. *
  1283. * @author Julio Montoya <gugli100@gmail.com>
  1284. * @param int field id
  1285. * @param array list of user ids
  1286. * @return array
  1287. * @since Nov 2009
  1288. * @version 1.8.6.2
  1289. */
  1290. function get_addtional_profile_information_of_field_by_user($field_id, $users) {
  1291. // Database table definition
  1292. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  1293. $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  1294. $result_extra_field = UserManager::get_extra_field_information($field_id);
  1295. if (!empty($users)) {
  1296. if ($result_extra_field['field_type'] == USER_FIELD_TYPE_TAG ) {
  1297. foreach($users as $user_id) {
  1298. $user_result = UserManager::get_user_tags($user_id, $field_id);
  1299. $tag_list = array();
  1300. foreach($user_result as $item) {
  1301. $tag_list[] = $item['tag'];
  1302. }
  1303. $return[$user_id][] = implode(', ',$tag_list);
  1304. }
  1305. } else {
  1306. $new_user_array = array();
  1307. foreach($users as $user_id) {
  1308. $new_user_array[]= "'".$user_id."'";
  1309. }
  1310. $users = implode(',',$new_user_array);
  1311. //selecting only the necessary information NOT ALL the user list
  1312. $sql = "SELECT user.user_id, field.field_value FROM $table_user user INNER JOIN $table_user_field_values field
  1313. ON (user.user_id = field.user_id)
  1314. WHERE field.field_id=".intval($field_id)." AND user.user_id IN ($users)";
  1315. $result = api_sql_query($sql);
  1316. while($row = Database::fetch_array($result)) {
  1317. // get option value for field type double select by id
  1318. if (!empty($row['field_value'])) {
  1319. if ($result_extra_field['field_type'] == USER_FIELD_TYPE_DOUBLE_SELECT) {
  1320. $id_double_select = explode(';',$row['field_value']);
  1321. if (is_array($id_double_select)) {
  1322. $value1 = $result_extra_field['options'][$id_double_select[0]]['option_value'];
  1323. $value2 = $result_extra_field['options'][$id_double_select[1]]['option_value'];
  1324. $row['field_value'] = ($value1.';'.$value2);
  1325. }
  1326. }
  1327. }
  1328. // get other value from extra field
  1329. $return[$row['user_id']][] = $row['field_value'];
  1330. }
  1331. }
  1332. }
  1333. return $return;
  1334. }
  1335. /**
  1336. * count the number of students in this course (used for SortableTable)
  1337. * Deprecated
  1338. */
  1339. function count_student_in_course() {
  1340. global $nbStudents;
  1341. return $nbStudents;
  1342. }
  1343. function sort_users($a, $b) {
  1344. return strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  1345. }
  1346. function sort_users_desc($a, $b) {
  1347. return strcmp( trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  1348. }
  1349. /**
  1350. * Get number of users for sortable with pagination
  1351. * @return int
  1352. */
  1353. function get_number_of_users() {
  1354. global $user_ids;
  1355. return count($user_ids);
  1356. }
  1357. /**
  1358. * Get data for users list in sortable with pagination
  1359. * @return array
  1360. */
  1361. function get_user_data($from, $number_of_items, $column, $direction) {
  1362. global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content;
  1363. $course_code = Database::escape_string($course_code);
  1364. $course_info = CourseManager :: get_course_information($course_code);
  1365. $tbl_track_cours_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  1366. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1367. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_info['db_name']);
  1368. $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST, $course_info['db_name']);
  1369. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['db_name']);
  1370. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['db_name']);
  1371. // get all users data from a course for sortable with limit
  1372. $condition_user = "";
  1373. if (is_array($user_ids)) {
  1374. $condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") ";
  1375. } else {
  1376. $condition_user = " WHERE user.user_id = '$user_ids' ";
  1377. }
  1378. $sql = "SELECT user.user_id as col0,
  1379. user.official_code as col1,
  1380. user.lastname as col2,
  1381. user.firstname as col3
  1382. FROM $tbl_user as user
  1383. $condition_user ";
  1384. if (!in_array($direction, array('ASC','DESC'))) {
  1385. $direction = 'ASC';
  1386. }
  1387. $column = intval($column);
  1388. $from = intval($from);
  1389. $number_of_items = intval($number_of_items);
  1390. $sql .= " ORDER BY col$column $direction ";
  1391. $sql .= " LIMIT $from,$number_of_items";
  1392. $res = Database::query($sql);
  1393. $users = array ();
  1394. $t = time();
  1395. $row = array();
  1396. while ($user = Database::fetch_row($res)) {
  1397. $row[0] = $user[1];
  1398. if ($is_western_name_order) {
  1399. $row[1] = $user[3];
  1400. $row[2] = $user[2];
  1401. } else {
  1402. $row[1] = $user[2];
  1403. $row[2] = $user[3];
  1404. }
  1405. $row[3] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user[0], $course_code));
  1406. $avg_student_score = Tracking::get_average_test_scorm_and_lp($user[0], $course_code);
  1407. $avg_student_progress = Tracking::get_avg_student_progress($user[0], $course_code);
  1408. if (empty($avg_student_score)) {$avg_student_score=0;}
  1409. if (empty($avg_student_progress)) {$avg_student_progress=0;}
  1410. $row[4] = $avg_student_progress.'%';
  1411. $row[5] = $avg_student_score.'%';
  1412. $row[6] = Tracking::count_student_assignments($user[0], $course_code);$user[4];
  1413. $row[7] = Tracking::count_student_messages($user[0], $course_code);//$user[5];
  1414. $row[8] = Tracking::get_first_connection_date_on_the_course($user[0], $course_code);
  1415. $row[9] = Tracking::get_last_connection_date_on_the_course($user[0], $course_code);
  1416. // we need to display an additional profile field
  1417. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  1418. if (is_array($additional_user_profile_info[$user[0]])) {
  1419. $row[10]=implode(', ', $additional_user_profile_info[$user[0]]);
  1420. } else {
  1421. $row[10]='&nbsp;';
  1422. }
  1423. }
  1424. $row[11] = '<center><a href="../mySpace/myStudents.php?student='.$user[0].'&details=true&course='.$course_code.'&origin=tracking_course"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  1425. if ($export_csv) {
  1426. $row[8] = strip_tags($row[8]);
  1427. $row[9] = strip_tags($row[9]);
  1428. unset($row[10]);
  1429. unset($row[11]);
  1430. $csv_content[] = $row;
  1431. }
  1432. // store columns in array $users
  1433. $users[] = array($row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11]);
  1434. }
  1435. return $users;
  1436. }
  1437. }
  1438. class TrackingUserLog {
  1439. /**
  1440. * Displays the number of logins every month for a specific user in a specific course.
  1441. */
  1442. function display_login_tracking_info($view, $user_id, $course_id)
  1443. {
  1444. $MonthsLong = $GLOBALS['MonthsLong'];
  1445. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  1446. $tempView = $view;
  1447. if(substr($view,0,1) == '1') {
  1448. $new_view = substr_replace($view,'0',0,1);
  1449. echo "
  1450. <tr>
  1451. <td valign='top'>
  1452. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font>" .
  1453. "<b>".get_lang('LoginsAndAccessTools')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=10000'>".get_lang('ExportAsCSV')."</a>]
  1454. </td>
  1455. </tr>
  1456. ";
  1457. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LoginsDetails')."<br>";
  1458. $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
  1459. FROM $track_access_table
  1460. WHERE access_user_id = '".Database::escape_string($user_id)."'
  1461. AND access_cours_code = '".Database::escape_string($course_id)."'
  1462. GROUP BY YEAR(access_date),MONTH(access_date)
  1463. ORDER BY YEAR(access_date),MONTH(access_date) ASC";
  1464. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  1465. //$results = getManyResults2Col($sql);
  1466. $results = getManyResults3Col($sql);
  1467. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  1468. echo "<tr>
  1469. <td class='secLine'>
  1470. ".get_lang('LoginsTitleMonthColumn')."
  1471. </td>
  1472. <td class='secLine'>
  1473. ".get_lang('LoginsTitleCountColumn')."
  1474. </td>
  1475. </tr>";
  1476. $total = 0;
  1477. if (is_array($results)) {
  1478. for($j = 0 ; $j < count($results) ; $j++) {
  1479. echo "<tr>";
  1480. //echo "<td class='content'><a href='logins_details.php?uInfo=$user_id&reqdate=".$results[$j][0]."'>".$langMonthNames['long'][date("n", $results[$j][0])-1]." ".date("Y", $results[$j][0])."</a></td>";
  1481. echo "<td class='content'><a href='logins_details.php?uInfo=".Security::remove_XSS($user_id)."&reqdate=".$results[$j][0]."&view=".Security::remove_XSS($view)."'>".$MonthsLong[date('n', $results[$j][0])-1].' '.date('Y', $results[$j][0])."</a></td>";
  1482. echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
  1483. echo"</tr>";
  1484. $total = $total + $results[$j][1];
  1485. }
  1486. echo "<tr>";
  1487. echo "<td>".get_lang('Total')."</td>";
  1488. echo "<td align='right' class='content'>".$total."</td>";
  1489. echo"</tr>";
  1490. } else {
  1491. echo "<tr>";
  1492. echo "<td colspan='2'><center>".get_lang('NoResult')."</center></td>";
  1493. echo"</tr>";
  1494. }
  1495. echo "</table>";
  1496. echo "</td></tr>";
  1497. } else {
  1498. $new_view = substr_replace($view,'1',0,1);
  1499. echo "
  1500. <tr>
  1501. <td valign='top'>
  1502. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LoginsAndAccessTools')."</a>
  1503. </td>
  1504. </tr>
  1505. ";
  1506. }
  1507. }
  1508. /**
  1509. * Displays the exercise results for a specific user in a specific course.
  1510. * @todo remove globals
  1511. */
  1512. function display_exercise_tracking_info($view, $user_id, $course_id)
  1513. {
  1514. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES;
  1515. if(substr($view,1,1) == '1')
  1516. {
  1517. $new_view = substr_replace($view,'0',1,1);
  1518. echo "<tr>
  1519. <td valign='top'>
  1520. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ExercicesResults')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=01000'>".get_lang('ExportAsCSV')."</a>]
  1521. </td>
  1522. </tr>";
  1523. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('ExercicesDetails')."<br />";
  1524. $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  1525. FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
  1526. WHERE te.exe_cours_id = '".Database::escape_string($course_id)."'
  1527. AND te.exe_user_id = '".Database::escape_string($user_id)."'
  1528. AND te.exe_exo_id = ce.id
  1529. ORDER BY ce.title ASC, te.exe_date ASC";
  1530. $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  1531. FROM $TBL_TRACK_HOTPOTATOES AS te
  1532. WHERE te.exe_user_id = '".Database::escape_string($user_id)."' AND te.exe_cours_id = '".Database::escape_string($course_id)."'
  1533. ORDER BY te.exe_cours_id ASC, te.exe_date ASC";
  1534. $hpresults = getManyResultsXCol($hpsql, 4);
  1535. $NoTestRes = 0;
  1536. $NoHPTestRes = 0;
  1537. echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
  1538. $results = getManyResultsXCol($sql, 4);
  1539. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
  1540. echo "
  1541. <tr bgcolor='#E6E6E6'>
  1542. <td>
  1543. ".get_lang('ExercicesTitleExerciceColumn')."
  1544. </td>
  1545. <td>
  1546. ".get_lang('Date')."
  1547. </td>
  1548. <td>
  1549. ".get_lang('ExercicesTitleScoreColumn')."
  1550. </td>
  1551. </tr>";
  1552. if (is_array($results)) {
  1553. for($i = 0; $i < sizeof($results); $i++) {
  1554. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]);
  1555. echo "<tr>\n";
  1556. echo "<td class='content'>".$results[$i][0]."</td>\n";
  1557. echo "<td class='content'>".$display_date."</td>\n";
  1558. echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
  1559. echo "</tr>\n";
  1560. }
  1561. } else {
  1562. // istvan begin
  1563. $NoTestRes = 1;
  1564. }
  1565. // The Result of Tests
  1566. if(is_array($hpresults)) {
  1567. for($i = 0; $i < sizeof($hpresults); $i++) {
  1568. $title = GetQuizName($hpresults[$i][0],'');
  1569. if ($title == '')
  1570. $title = basename($hpresults[$i][0]);
  1571. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]);
  1572. ?>
  1573. <tr>
  1574. <td class="content"><?php echo $title; ?></td>
  1575. <td class="content" align="center"><?php echo $display_date; ?></td>
  1576. <td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?></td>
  1577. </tr>
  1578. <?php }
  1579. } else {
  1580. $NoHPTestRes = 1;
  1581. }
  1582. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  1583. echo "<tr>\n";
  1584. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>\n";
  1585. echo "</tr>\n";
  1586. }
  1587. echo "</table>";
  1588. echo "</td>\n</tr>\n";
  1589. } else {
  1590. $new_view = substr_replace($view,'1',1,1);
  1591. echo "
  1592. <tr>
  1593. <td valign='top'>
  1594. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".get_lang('ExercicesResults')."</a>
  1595. </td>
  1596. </tr>";
  1597. }
  1598. }
  1599. /**
  1600. * Displays the student publications for a specific user in a specific course.
  1601. * @todo remove globals
  1602. */
  1603. function display_student_publications_tracking_info($view, $user_id, $course_id)
  1604. {
  1605. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong, $_course;
  1606. if(substr($view,2,1) == '1') {
  1607. $new_view = substr_replace($view,'0',2,1);
  1608. echo "<tr>
  1609. <td valign='top'>
  1610. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('WorkUploads')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00100'>".get_lang('ExportAsCSV')."</a>]
  1611. </td>
  1612. </tr>";
  1613. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('WorksDetails')."<br>";
  1614. $sql = "SELECT u.upload_date, w.title, w.author,w.url
  1615. FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
  1616. WHERE u.upload_work_id = w.id
  1617. AND u.upload_user_id = '".Database::escape_string($user_id)."'
  1618. AND u.upload_cours_id = '".Database::escape_string($course_id)."'
  1619. ORDER BY u.upload_date DESC";
  1620. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  1621. $results = getManyResultsXCol($sql,4);
  1622. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  1623. echo "<tr>
  1624. <td class='secLine' width='40%'>
  1625. ".get_lang('WorkTitle')."
  1626. </td>
  1627. <td class='secLine' width='30%'>
  1628. ".get_lang('WorkAuthors')."
  1629. </td>
  1630. <td class='secLine' width='30%'>
  1631. ".get_lang('Date')."
  1632. </td>
  1633. </tr>";
  1634. if (is_array($results)) {
  1635. for($j = 0 ; $j < count($results) ; $j++) {
  1636. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  1637. $timestamp = strtotime($results[$j][0]);
  1638. $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp);
  1639. echo "<tr>";
  1640. echo "<td class='content'>"
  1641. ."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
  1642. ."</td>";
  1643. echo "<td class='content'>".$results[$j][2]."</td>";
  1644. echo "<td class='content'>".$beautifulDate."</td>";
  1645. echo"</tr>";
  1646. }
  1647. } else {
  1648. echo "<tr>";
  1649. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
  1650. echo"</tr>";
  1651. }
  1652. echo "</table>";
  1653. echo "</td></tr>";
  1654. } else {
  1655. $new_view = substr_replace($view,'1',2,1);
  1656. echo "
  1657. <tr>
  1658. <td valign='top'>
  1659. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('WorkUploads')."</a>
  1660. </td>
  1661. </tr>
  1662. ";
  1663. }
  1664. }
  1665. /**
  1666. * Displays the links followed for a specific user in a specific course.
  1667. * @todo remove globals
  1668. */
  1669. function display_links_tracking_info($view, $user_id, $course_id)
  1670. {
  1671. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  1672. if(substr($view,3,1) == '1') {
  1673. $new_view = substr_replace($view,'0',3,1);
  1674. echo "
  1675. <tr>
  1676. <td valign='top'>
  1677. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('LinksAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00010'>".get_lang('ExportAsCSV')."</a>]
  1678. </td>
  1679. </tr>
  1680. ";
  1681. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LinksDetails')."<br>";
  1682. $sql = "SELECT cl.title, cl.url
  1683. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  1684. WHERE sl.links_link_id = cl.id
  1685. AND sl.links_cours_id = '".Database::escape_string($course_id)."'
  1686. AND sl.links_user_id = '".Database::escape_string($user_id)."'
  1687. GROUP BY cl.title, cl.url";
  1688. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  1689. $results = getManyResults2Col($sql);
  1690. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  1691. echo "<tr>
  1692. <td class='secLine'>
  1693. ".get_lang('LinksTitleLinkColumn')."
  1694. </td>
  1695. </tr>";
  1696. if (is_array($results)) {
  1697. for($j = 0 ; $j < count($results) ; $j++) {
  1698. echo "<tr>";
  1699. echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
  1700. echo"</tr>";
  1701. }
  1702. } else {
  1703. echo "<tr>";
  1704. echo "<td ><center>".get_lang('NoResult')."</center></td>";
  1705. echo"</tr>";
  1706. }
  1707. echo "</table>";
  1708. echo "</td></tr>";
  1709. } else {
  1710. $new_view = substr_replace($view,'1',3,1);
  1711. echo "
  1712. <tr>
  1713. <td valign='top'>
  1714. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LinksAccess')."</a>
  1715. </td>
  1716. </tr>
  1717. ";
  1718. }
  1719. }
  1720. /**
  1721. * Displays the documents downloaded for a specific user in a specific course.
  1722. */
  1723. function display_document_tracking_info($view, $user_id, $course_id)
  1724. {
  1725. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  1726. if(substr($view,4,1) == '1')
  1727. {
  1728. $new_view = substr_replace($view,'0',4,1);
  1729. echo "
  1730. <tr>
  1731. <td valign='top'>
  1732. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('DocumentsAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=00001'>".get_lang('ExportAsCSV')."</a>]
  1733. </td>
  1734. </tr>
  1735. ";
  1736. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('DocumentsDetails')."<br>";
  1737. $sql = "SELECT down_doc_path
  1738. FROM $downloads_table
  1739. WHERE down_cours_id = '".Database::escape_string($course_id)."'
  1740. AND down_user_id = '".Database::escape_string($user_id)."'
  1741. GROUP BY down_doc_path";
  1742. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  1743. $results = getManyResults1Col($sql);
  1744. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
  1745. echo "<tr>
  1746. <td class='secLine'>
  1747. ".get_lang('DocumentsTitleDocumentColumn')."
  1748. </td>
  1749. </tr>";
  1750. if (is_array($results)) {
  1751. for($j = 0 ; $j < count($results) ; $j++) {
  1752. echo "<tr>";
  1753. echo "<td class='content'>".$results[$j]."</td>";
  1754. echo"</tr>";
  1755. }
  1756. } else {
  1757. echo "<tr>";
  1758. echo "<td><center>".get_lang('NoResult')."</center></td>";
  1759. echo"</tr>";
  1760. }
  1761. echo "</table>";
  1762. echo "</td></tr>";
  1763. } else {
  1764. $new_view = substr_replace($view,'1',4,1);
  1765. echo "
  1766. <tr>
  1767. <td valign='top'>
  1768. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('DocumentsAccess')."</a>
  1769. </td>
  1770. </tr>
  1771. ";
  1772. }
  1773. }
  1774. }
  1775. class TrackingUserLogCSV {
  1776. /**
  1777. * Displays the number of logins every month for a specific user in a specific course.
  1778. */
  1779. function display_login_tracking_info($view, $user_id, $course_id)
  1780. {
  1781. $MonthsLong = $GLOBALS['MonthsLong'];
  1782. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  1783. $tempView = $view;
  1784. if(substr($view,0,1) == '1')
  1785. {
  1786. $new_view = substr_replace($view,'0',0,1);
  1787. $title[1]= get_lang('LoginsAndAccessTools').get_lang('LoginsDetails');
  1788. $sql = "SELECT UNIX_TIMESTAMP(`access_date`), count(`access_date`)
  1789. FROM $track_access_table
  1790. WHERE `access_user_id` = '$user_id'
  1791. AND `access_cours_code` = '".$course_id."'
  1792. GROUP BY YEAR(`access_date`),MONTH(`access_date`)
  1793. ORDER BY YEAR(`access_date`),MONTH(`access_date`) ASC";
  1794. //$results = getManyResults2Col($sql);
  1795. $results = getManyResults3Col($sql);
  1796. $title_line= get_lang('LoginsTitleMonthColumn').';'.get_lang('LoginsTitleCountColumn')."\n";
  1797. $line='';
  1798. $total = 0;
  1799. if (is_array($results))
  1800. {
  1801. for($j = 0 ; $j < count($results) ; $j++)
  1802. {
  1803. $line .= $results[$j][0].';'.$results[$j][1]."\n";
  1804. $total = $total + $results[$j][1];
  1805. }
  1806. $line .= get_lang('Total').";".$total."\n";
  1807. }
  1808. else
  1809. {
  1810. $line= get_lang('NoResult')."</center></td>";
  1811. }
  1812. }
  1813. else
  1814. {
  1815. $new_view = substr_replace($view,'1',0,1);
  1816. }
  1817. return array($title_line, $line);
  1818. }
  1819. /**
  1820. * Displays the exercise results for a specific user in a specific course.
  1821. * @todo remove globals
  1822. */
  1823. function display_exercise_tracking_info($view, $user_id, $course_id)
  1824. {
  1825. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES;
  1826. if(substr($view,1,1) == '1')
  1827. {
  1828. $new_view = substr_replace($view,'0',1,1);
  1829. $title[1]= get_lang('ExercicesDetails');
  1830. $line='';
  1831. $sql = "SELECT `ce`.`title`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  1832. FROM $TABLECOURSE_EXERCICES AS ce , `$TABLETRACK_EXERCICES` AS `te`
  1833. WHERE `te`.`exe_cours_id` = '$course_id'
  1834. AND `te`.`exe_user_id` = '$user_id'
  1835. AND `te`.`exe_exo_id` = `ce`.`id`
  1836. ORDER BY `ce`.`title` ASC, `te`.`exe_date` ASC";
  1837. $hpsql = "SELECT `te`.`exe_name`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  1838. FROM `$TABLETRACK_HOTPOTATOES` AS te
  1839. WHERE `te`.`exe_user_id` = '$user_id' AND `te`.`exe_cours_id` = '$course_id'
  1840. ORDER BY `te`.`exe_cours_id` ASC, `te`.`exe_date` ASC";
  1841. $hpresults = getManyResultsXCol($hpsql, 4);
  1842. $NoTestRes = 0;
  1843. $NoHPTestRes = 0;
  1844. $results = getManyResultsXCol($sql, 4);
  1845. $title_line=get_lang('ExercicesTitleExerciceColumn').";".get_lang('Date').';'.get_lang('ExercicesTitleScoreColumn')."\n";
  1846. if (is_array($results))
  1847. {
  1848. for($i = 0; $i < sizeof($results); $i++)
  1849. {
  1850. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]);
  1851. $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
  1852. }
  1853. }
  1854. else // istvan begin
  1855. {
  1856. $NoTestRes = 1;
  1857. }
  1858. // The Result of Tests
  1859. if(is_array($hpresults))
  1860. {
  1861. for($i = 0; $i < sizeof($hpresults); $i++)
  1862. {
  1863. $title = GetQuizName($hpresults[$i][0],'');
  1864. if ($title == '')
  1865. $title = basename($hpresults[$i][0]);
  1866. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]);
  1867. $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
  1868. }
  1869. }
  1870. else
  1871. {
  1872. $NoHPTestRes = 1;
  1873. }
  1874. if ($NoTestRes == 1 && $NoHPTestRes == 1)
  1875. {
  1876. $line=get_lang('NoResult');
  1877. }
  1878. }
  1879. else
  1880. {
  1881. $new_view = substr_replace($view,'1',1,1);
  1882. }
  1883. return array($title_line, $line);
  1884. }
  1885. /**
  1886. * Displays the student publications for a specific user in a specific course.
  1887. * @todo remove globals
  1888. */
  1889. function display_student_publications_tracking_info($view, $user_id, $course_id)
  1890. {
  1891. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong;
  1892. if(substr($view,2,1) == '1')
  1893. {
  1894. $new_view = substr_replace($view,'0',2,1);
  1895. $sql = "SELECT `u`.`upload_date`, `w`.`title`, `w`.`author`,`w`.`url`
  1896. FROM `$TABLETRACK_UPLOADS` `u` , $TABLECOURSE_WORK `w`
  1897. WHERE `u`.`upload_work_id` = `w`.`id`
  1898. AND `u`.`upload_user_id` = '$user_id'
  1899. AND `u`.`upload_cours_id` = '$course_id'
  1900. ORDER BY `u`.`upload_date` DESC";
  1901. $results = getManyResultsXCol($sql,4);
  1902. $title[1]=get_lang('WorksDetails');
  1903. $line='';
  1904. $title_line=get_lang('WorkTitle').";".get_lang('WorkAuthors').";".get_lang('Date')."\n";
  1905. if (is_array($results))
  1906. {
  1907. for($j = 0 ; $j < count($results) ; $j++)
  1908. {
  1909. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  1910. $timestamp = strtotime($results[$j][0]);
  1911. $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp);
  1912. $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
  1913. }
  1914. }
  1915. else
  1916. {
  1917. $line= get_lang('NoResult');
  1918. }
  1919. }
  1920. else
  1921. {
  1922. $new_view = substr_replace($view,'1',2,1);
  1923. }
  1924. return array($title_line, $line);
  1925. }
  1926. /**
  1927. * Displays the links followed for a specific user in a specific course.
  1928. * @todo remove globals
  1929. */
  1930. function display_links_tracking_info($view, $user_id, $course_id)
  1931. {
  1932. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  1933. if(substr($view,3,1) == '1')
  1934. {
  1935. $new_view = substr_replace($view,'0',3,1);
  1936. $title[1]=get_lang('LinksDetails');
  1937. $sql = "SELECT `cl`.`title`, `cl`.`url`
  1938. FROM `$TABLETRACK_LINKS` AS sl, $TABLECOURSE_LINKS AS cl
  1939. WHERE `sl`.`links_link_id` = `cl`.`id`
  1940. AND `sl`.`links_cours_id` = '$course_id'
  1941. AND `sl`.`links_user_id` = '$user_id'
  1942. GROUP BY `cl`.`title`, `cl`.`url`";
  1943. $results = getManyResults2Col($sql);
  1944. $title_line= get_lang('LinksTitleLinkColumn')."\n";
  1945. if (is_array($results))
  1946. {
  1947. for($j = 0 ; $j < count($results) ; $j++)
  1948. {
  1949. $line .= $results[$j][0]."\n";
  1950. }
  1951. }
  1952. else
  1953. {
  1954. $line=get_lang('NoResult');
  1955. }
  1956. }
  1957. else
  1958. {
  1959. $new_view = substr_replace($view,'1',3,1);
  1960. }
  1961. return array($title_line, $line);
  1962. }
  1963. /**
  1964. * Displays the documents downloaded for a specific user in a specific course.
  1965. */
  1966. function display_document_tracking_info($view, $user_id, $course_id)
  1967. {
  1968. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  1969. if(substr($view,4,1) == '1')
  1970. {
  1971. $new_view = substr_replace($view,'0',4,1);
  1972. $title[1]= get_lang('DocumentsDetails');
  1973. $sql = "SELECT `down_doc_path`
  1974. FROM $downloads_table
  1975. WHERE `down_cours_id` = '$course_id'
  1976. AND `down_user_id` = '$user_id'
  1977. GROUP BY `down_doc_path`";
  1978. $results = getManyResults1Col($sql);
  1979. $title_line = get_lang('DocumentsTitleDocumentColumn')."\n";
  1980. if (is_array($results))
  1981. {
  1982. for($j = 0 ; $j < count($results) ; $j++)
  1983. {
  1984. $line .= $results[$j]."\n";
  1985. }
  1986. }
  1987. else
  1988. {
  1989. $line=get_lang('NoResult');
  1990. }
  1991. }
  1992. else
  1993. {
  1994. $new_view = substr_replace($view,'1',4,1);
  1995. }
  1996. return array($title_line, $line);
  1997. }
  1998. }
  1999. ?>