tracking.lib.php 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. ==============================================================================
  5. * This is the tracking library for Dokeos.
  6. * Include/require it in your code to use its functionality.
  7. *
  8. * @package dokeos.library
  9. * @author Julio Montoya <gugli100@gmail.com> (Score average fixes)
  10. ==============================================================================
  11. */
  12. class Tracking {
  13. /**
  14. * Calculates the time spent on the platform by a user
  15. * @param int User id
  16. * @param bool True for calculating only time spent last week (optional)
  17. * @param int Timestamp for filtering by Day (optional, default = 0)
  18. * @return timestamp $nb_seconds
  19. */
  20. public static function get_time_spent_on_the_platform($user_id, $last_week = false, $by_day = 0) {
  21. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  22. $condition_time = '';
  23. if ($last_week) {
  24. $a_last_week = get_last_week();
  25. $fday_last_week = date('Y-m-d H:i:s',$a_last_week[0]);
  26. $lday_last_week = date('Y-m-d H:i:s',$a_last_week[6]);
  27. $condition_time = ' AND (login_date >= "'.$fday_last_week.'" AND logout_date <= "'.$lday_last_week.'") ';
  28. } else if (!empty($by_day)) {
  29. $fdate_time = date('Y-m-d',$by_day).' 00:00:00';
  30. $ldate_time = date('Y-m-d',$by_day).' 23:59:59';
  31. $condition_time = ' AND (login_date >= "'.$fdate_time.'" AND logout_date <= "'.$ldate_time.'" ) ';
  32. }
  33. $sql = 'SELECT login_date, logout_date FROM '.$tbl_track_login.'
  34. WHERE login_user_id = '.intval($user_id).$condition_time;
  35. $rs = Database::query($sql);
  36. $nb_seconds = 0;
  37. $wrong_logout_dates = false;
  38. while ($a_connections = Database::fetch_array($rs)) {
  39. $s_login_date = $a_connections["login_date"];
  40. $s_logout_date = $a_connections["logout_date"];
  41. $i_timestamp_login_date = strtotime($s_login_date);
  42. $i_timestamp_logout_date = strtotime($s_logout_date);
  43. if($i_timestamp_logout_date>0)
  44. {
  45. $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date);
  46. }
  47. else
  48. { // there are wrong datas in db, then we can't give a wrong time
  49. $wrong_logout_dates = true;
  50. }
  51. }
  52. if($nb_seconds>0 || !$wrong_logout_dates)
  53. {
  54. return $nb_seconds;
  55. }
  56. else
  57. {
  58. return -1; //-1 means we have wrong datas in the db
  59. }
  60. }
  61. /**
  62. * Calculates the time spent on the course
  63. * @param integer User id
  64. * @param string Course code
  65. * @param int Session id (optional)
  66. * @return timestamp Time in seconds
  67. */
  68. public static function get_time_spent_on_the_course($user_id, $course_code, $session_id = 0) {
  69. // protect datas
  70. $course_code = Database::escape_string($course_code);
  71. $session_id = intval($session_id);
  72. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  73. $condition_user = "";
  74. if (is_array($user_id)) {
  75. $condition_user = " AND user_id IN (".implode(',',$user_id).") ";
  76. } else {
  77. $user_id = intval($user_id);
  78. $condition_user = " AND user_id = '$user_id' ";
  79. }
  80. $sql = " SELECT SUM(UNIX_TIMESTAMP(logout_course_date)-UNIX_TIMESTAMP(login_course_date)) as nb_seconds
  81. FROM $tbl_track_course
  82. WHERE course_code='$course_code' AND session_id = '$session_id' $condition_user";
  83. $rs = Database::query($sql);
  84. $row = Database::fetch_array($rs);
  85. return $row['nb_seconds'];
  86. }
  87. /**
  88. * Get first connection date for a student
  89. * @param int Student id
  90. * @return string|bool Date format long without day or false if there are no connections
  91. */
  92. public static function get_first_connection_date($student_id) {
  93. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  94. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  95. WHERE login_user_id = ' . intval($student_id) . '
  96. ORDER BY login_date ASC LIMIT 0,1';
  97. $rs = Database::query($sql);
  98. if(Database::num_rows($rs)>0)
  99. {
  100. if ($first_login_date = Database::result($rs, 0, 0)) {
  101. return api_convert_and_format_date($first_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  102. }
  103. }
  104. return false;
  105. }
  106. /**
  107. * Get las connection date for a student
  108. * @param int Student id
  109. * @param bool Show a warning message (optional)
  110. * @param bool True for returning results in timestamp (optional)
  111. * @return string|int|bool Date format long without day, false if there are no connections or timestamp if parameter $return_timestamp is true
  112. */
  113. public static function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false) {
  114. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  115. $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
  116. WHERE login_user_id = ' . intval($student_id) . '
  117. ORDER BY login_date DESC LIMIT 0,1';
  118. $rs = Database::query($sql);
  119. if(Database::num_rows($rs)>0)
  120. {
  121. if ($last_login_date = Database::result($rs, 0, 0))
  122. {
  123. $last_login_date = api_get_local_time($last_login_date, null, date_default_timezone_get());
  124. if ($return_timestamp)
  125. {
  126. return api_strtotime($last_login_date);
  127. }
  128. else
  129. {
  130. if (!$warning_message)
  131. {
  132. return api_format_date($last_login_date, DATE_FORMAT_SHORT);
  133. }
  134. else
  135. {
  136. $timestamp = api_strtotime($last_login_date);
  137. $currentTimestamp = time();
  138. //If the last connection is > than 7 days, the text is red
  139. //345600 = 7 days in seconds
  140. if ($currentTimestamp - $timestamp > 604800)
  141. {
  142. return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . '</span>';
  143. }
  144. else
  145. {
  146. return api_format_date($last_login_date, DATE_FORMAT_SHORT);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. return false;
  153. }
  154. /**
  155. * Get first user's connection date on the course
  156. * @param int User id
  157. * @param string Course code
  158. * @param int Session id (optional, default=0)
  159. * @return string|bool Date with format long without day or false if there is no date
  160. */
  161. public static function get_first_connection_date_on_the_course($student_id, $course_code, $session_id = 0) {
  162. // protect data
  163. $student_id = intval($student_id);
  164. $course_code = Database::escape_string($course_code);
  165. $session_id = intval($session_id);
  166. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  167. $sql = 'SELECT login_course_date FROM '.$tbl_track_login.'
  168. WHERE user_id = '.$student_id.'
  169. AND course_code = "'.$course_code.'"
  170. AND session_id = '.$session_id.'
  171. ORDER BY login_course_date ASC LIMIT 0,1';
  172. $rs = Database::query($sql);
  173. if (Database::num_rows($rs)>0) {
  174. if ($first_login_date = Database::result($rs, 0, 0)) {
  175. return api_convert_and_format_date($first_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  176. }
  177. }
  178. return false;
  179. }
  180. /**
  181. * Get last user's connection date on the course
  182. * @param int User id
  183. * @param string Course code
  184. * @param int Session id (optional, default=0)
  185. * @return string|bool Date with format long without day or false if there is no date
  186. */
  187. public static function get_last_connection_date_on_the_course($student_id, $course_code, $session_id = 0) {
  188. // protect data
  189. $student_id = intval($student_id);
  190. $course_code = Database::escape_string($course_code);
  191. $session_id = intval($session_id);
  192. $tbl_track_e_course_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  193. $sql = 'SELECT login_course_date FROM '.$tbl_track_e_course_access.'
  194. WHERE user_id = '.$student_id.'
  195. AND course_code = "'.$course_code.'"
  196. AND session_id = '.$session_id.'
  197. ORDER BY login_course_date DESC LIMIT 0,1';
  198. $rs = Database::query($sql);
  199. if (Database::num_rows($rs)>0) {
  200. if ($last_login_date = Database::result($rs, 0, 0)) {
  201. $last_login_date = api_get_local_time($last_login_date, null, date_default_timezone_get());
  202. $timestamp = api_strtotime($last_login_date);
  203. $currentTimestamp = time();
  204. //If the last connection is > than 7 days, the text is red
  205. //345600 = 7 days in seconds
  206. if ($currentTimestamp - $timestamp > 604800) {
  207. return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . (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>';
  208. } else {
  209. return api_format_date($last_login_date, DATE_FORMAT_SHORT);
  210. }
  211. }
  212. }
  213. return false;
  214. }
  215. /**
  216. * Get count courses per student
  217. * @param int Student id
  218. * @param bool Include sessions (optional)
  219. * @return int count courses
  220. */
  221. public static function count_course_per_student($user_id, $include_sessions = true) {
  222. $user_id = intval($user_id);
  223. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  224. $tbl_session_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  225. $sql = 'SELECT DISTINCT course_code
  226. FROM ' . $tbl_course_rel_user . '
  227. WHERE user_id = ' . $user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH;
  228. $rs = Database::query($sql);
  229. $nb_courses = Database::num_rows($rs);
  230. if ($include_sessions) {
  231. $sql = 'SELECT DISTINCT course_code
  232. FROM ' . $tbl_session_course_rel_user . '
  233. WHERE id_user = ' . $user_id;
  234. $rs = Database::query($sql);
  235. $nb_courses += Database::num_rows($rs);
  236. }
  237. return $nb_courses;
  238. }
  239. /**
  240. * This function gets the score average from all tests in a course by student
  241. * @param int|array Student(s) id
  242. * @param string Course code
  243. * @param int Exercise id (optional), filtered by exercise
  244. * @param int Session id (optional), if param $session_id is null it'll return results including sessions, 0 = session is not filtered
  245. * @return string value (number %) Which represents a round integer about the score average.
  246. */
  247. public static function get_avg_student_exercise_score($student_id, $course_code, $exercise_id = 0, $session_id = null) {
  248. // protect datas
  249. $course_code = Database::escape_string($course_code);
  250. // get the informations of the course
  251. $a_course = CourseManager :: get_course_information($course_code);
  252. if(!empty($a_course['db_name'])) {
  253. // table definition
  254. $tbl_course_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$a_course['db_name']);
  255. $tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  256. // Compose a filter based on optional exercise given
  257. $condition_quiz = "";
  258. if(!empty($exercise_id)) {
  259. $exercise_id = intval($exercise_id);
  260. $condition_lp =" AND id = $exercise_id ";
  261. }
  262. // Compose a filter based on optional session id given
  263. $condition_session = "";
  264. if (isset($session_id)) {
  265. $session_id = intval($session_id);
  266. $condition_session = " AND session_id = $session_id ";
  267. }
  268. $count_quiz = Database::fetch_row(Database::query("SELECT count(id) FROM $tbl_course_quiz WHERE active <> -1 $condition_quiz $condition_session"));
  269. $quiz_avg_total_score = 0;
  270. if (!empty($count_quiz[0]) && !empty($student_id)) {
  271. $condition_user = "";
  272. if (is_array($student_id)) {
  273. $condition_user = " AND exe_user_id IN (".implode(',',$student_id).") ";
  274. } else {
  275. $condition_user = " AND exe_user_id = '$student_id' ";
  276. }
  277. $sql = "SELECT SUM(exe_result/exe_weighting*100) as avg_score
  278. FROM $tbl_stats_exercise
  279. WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1 $condition_quiz $condition_session)
  280. $condition_user
  281. AND orig_lp_id = 0
  282. AND exe_cours_id = '$course_code'
  283. AND orig_lp_item_id = 0
  284. ORDER BY exe_date DESC";
  285. $res = Database::query($sql);
  286. $row = Database::fetch_array($res);
  287. $quiz_avg_score = 0;
  288. if (!empty($row['avg_score'])) {
  289. $quiz_avg_score = round($row['avg_score'],2);
  290. }
  291. $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_quiz $condition_session) $condition_user AND orig_lp_id = 0 AND exe_cours_id = '$course_code' AND orig_lp_item_id = 0 ORDER BY exe_date DESC"));
  292. if(!empty($count_attempt[0])) {
  293. $quiz_avg_score = $quiz_avg_score / $count_attempt[0];
  294. }
  295. $quiz_avg_total_score = $quiz_avg_score;
  296. return $quiz_avg_total_score/$count_quiz[0];
  297. }
  298. }
  299. return null;
  300. }
  301. /**
  302. * Get count student's exercise attempts
  303. * @param int Student id
  304. * @param string Course code
  305. * @param int Exercise id
  306. * @param int Learning path id (optional), for showing attempts inside a learning path $lp_id and $lp_item_id params are required.
  307. * @param int Learning path item id (optional), for showing attempts inside a learning path $lp_id and $lp_item_id params are required.
  308. * @return int count of attempts
  309. */
  310. public function count_student_exercise_attempts($student_id, $course_code, $exercise_id, $lp_id = 0, $lp_item_id = 0) {
  311. $course_code = Database::escape_string($course_code);
  312. $course_info = CourseManager :: get_course_information($course_code);
  313. $student_id = intval($student_id);
  314. $exercise_id = intval($exercise_id);
  315. $count_attempts = 0;
  316. if (!empty($lp_id)) $lp_id = intval($lp_id);
  317. if (!empty($lp_item_id)) $lp_id = intval($lp_item_id);
  318. if (!empty($course_info['db_name'])) {
  319. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES, $course_info['db_name']);
  320. $sql = "SELECT COUNT(ex.exe_id) as essais
  321. FROM $tbl_stats_exercices AS ex
  322. WHERE ex.exe_cours_id = '$course_code'
  323. AND ex.exe_exo_id = $exercise_id
  324. AND orig_lp_id = $lp_id
  325. AND orig_lp_item_id = $lp_item_id
  326. AND exe_user_id= $student_id ";
  327. $rs = Database::query($sql);
  328. $row = Database::fetch_row($rs);
  329. $count_attempts = $row[0];
  330. }
  331. return $count_attempts;
  332. }
  333. /**
  334. * Returns the average student progress in the learning paths of the given
  335. * course.
  336. * @param int/array Student id(s)
  337. * @param string Course code
  338. * @param array Limit average to listed lp ids
  339. * @param int Session id (optional), if parameter $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  340. * @return double Average progress of the user in this course
  341. */
  342. public static function get_avg_student_progress($student_id, $course_code, $lp_ids = array(), $session_id = null) {
  343. // get the informations of the course
  344. $a_course = CourseManager :: get_course_information($course_code);
  345. if (!empty($a_course['db_name'])) {
  346. // table definition
  347. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']);
  348. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']);
  349. // Compose a filter based on optional learning paths list given
  350. $condition_lp = "";
  351. if(count($lp_ids) > 0) {
  352. $condition_lp =" WHERE id IN(".implode(',',$lp_ids).") ";
  353. }
  354. // Compose a filter based on optional session id
  355. $condition_session = "";
  356. if (isset($session_id)) {
  357. $session_id = intval($session_id);
  358. if (count($lp_ids) > 0) {
  359. $condition_session = " AND session_id = $session_id ";
  360. } else {
  361. $condition_session = " WHERE session_id = $session_id ";
  362. }
  363. }
  364. $res_count_lp = Database::query("SELECT id FROM $tbl_course_lp lp $condition_lp $condition_session");
  365. // count the number of learning paths
  366. $count_lp = Database::num_rows($res_count_lp);
  367. $lp_id = array();
  368. while ($row_lp = Database::fetch_array($res_count_lp)) {
  369. $lp_id[] = $row_lp[0];
  370. }
  371. $avg_progress = 0;
  372. //if there is at least one learning path and one student
  373. if ($count_lp>0 && !empty($student_id)) {
  374. $condition_user = "";
  375. if (is_array($student_id)) {
  376. $$r = array_walk($student_id,'intval');
  377. $condition_user = " lp_view.user_id IN (".implode(',',$student_id).") AND ";
  378. } else {
  379. $student_id = intval($student_id);
  380. $condition_user = " lp_view.user_id = '$student_id' AND ";
  381. }
  382. // Get last view for each student (in case of multi-attempt)
  383. // Also filter on LPs of this session
  384. $sql_maxes = "SELECT MAX(view_count), progress ".
  385. "FROM $tbl_course_lp_view lp_view ".
  386. "WHERE $condition_user ".
  387. "lp_view.lp_id IN (".implode(',',$lp_id).") ".
  388. "GROUP BY lp_id, user_id";
  389. $res_maxes = Database::query($sql_maxes);
  390. $sum = $number_items = 0;
  391. while ($row_maxes = Database::fetch_array($res_maxes)) {
  392. $sum += $row_maxes[1];
  393. $number_items++;
  394. }
  395. if ($number_items == 0) {
  396. return 0; //not necessary to return something else if there is no view
  397. }
  398. // average progress = total sum divided by the number of views
  399. // summed up.
  400. $avg_progress = round($sum / $number_items, 1);
  401. return $avg_progress;
  402. }
  403. }
  404. return null;
  405. }
  406. /**
  407. * This function gets:
  408. * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max scores.
  409. * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max scores.
  410. * 3. And finally it will return the average between 1. and 2.
  411. * This function does not take the results of a Test out of a LP
  412. *
  413. * @param int|array Student id(s)
  414. * @param string Course code
  415. * @param array Limit average to listed lp ids
  416. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  417. * @return string Value (number %) Which represents a round integer explain in got in 3.
  418. */
  419. public static function get_avg_student_score($student_id, $course_code, $lp_ids=array(), $session_id = null) {
  420. // get global tables names
  421. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  422. $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  423. $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  424. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  425. $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  426. $course = CourseManager :: get_course_information($course_code);
  427. if (!empty($course['db_name'])) {
  428. // get course tables names
  429. $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']);
  430. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']);
  431. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']);
  432. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']);
  433. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']);
  434. // Compose a filter based on optional learning paths list given
  435. $condition_lp = "";
  436. if(count($lp_ids) > 0) {
  437. $condition_lp =" WHERE id IN(".implode(',',$lp_ids).") ";
  438. }
  439. // Compose a filter based on optional session id
  440. $condition_session = "";
  441. if (isset($session_id)) {
  442. $session_id = intval($session_id);
  443. if (count($lp_ids) > 0) {
  444. $condition_session = " AND session_id = $session_id ";
  445. } else {
  446. $condition_session = " WHERE session_id = $session_id ";
  447. }
  448. }
  449. // Check the real number of LPs corresponding to the filter in the
  450. // database (and if no list was given, get them all)
  451. $res_row_lp = Database::query("SELECT DISTINCT(id) FROM $lp_table $condition_lp $condition_session");
  452. $count_row_lp = Database::num_rows($res_row_lp);
  453. $lp_list = array();
  454. while ($row_lp = Database::fetch_array($res_row_lp)) {
  455. $lp_list[] = $row_lp[0];
  456. }
  457. // Init local variables that will be used through the calculation
  458. $lp_scorm_score_total = 0;
  459. $lp_scorm_result_score_total = 0;
  460. $lp_scorm_loop=0;
  461. $lp_count = 0;
  462. $progress = 0;
  463. // prepare filter on users
  464. $condition_user1 = "";
  465. if (is_array($student_id)) {
  466. array_walk($student_id,'intval');
  467. $condition_user1 =" AND user_id IN (".implode(',',$student_id).") ";
  468. } else {
  469. $condition_user1 =" AND user_id = '$student_id' ";
  470. }
  471. if ($count_row_lp>0 && !empty($student_id)) {
  472. // Get all views through learning paths filter
  473. $sql = "SELECT MAX(view_count) as vc, id, progress, lp_id, user_id ".
  474. "FROM $lp_view_table ".
  475. "WHERE lp_id IN (".implode(',',$lp_list).") ".
  476. "$condition_user1 GROUP BY lp_id,user_id";
  477. $rs_last_lp_view_id = Database::query($sql);
  478. $count_views = 0;
  479. $score_of_scorm_calculate = 0;
  480. if (Database::num_rows($rs_last_lp_view_id) > 0) {
  481. // Cycle through each line of the results (grouped by lp_id, user_id)
  482. while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) {
  483. $lp_view_id = $row_lp_view['id'];
  484. $progress = $row_lp_view['progress'];
  485. $lp_id = $row_lp_view['lp_id'];
  486. $user_id = $row_lp_view['user_id'];
  487. // For the currently analysed view, get the score and
  488. // max_score of each item if it is a sco or a TOOL_QUIZ
  489. $sql_max_score = "SELECT lp_iv.score as score,lp_i.max_score, lp_i.path, lp_i.item_type , lp_i.id as iid".
  490. " FROM $lp_item_view_table as lp_iv ".
  491. " INNER JOIN $lp_item_table as lp_i ".
  492. " ON lp_i.id = lp_iv.lp_item_id ".
  493. " AND (lp_i.item_type='sco' ".
  494. " OR lp_i.item_type='".TOOL_QUIZ."') ".
  495. " WHERE lp_view_id='$lp_view_id'";
  496. $res_max_score = Database::query($sql_max_score);
  497. $count_total_loop = 0;
  498. $num_rows_max_score = Database::num_rows($res_max_score);
  499. // Go through each scorable element of this view
  500. $count_items = 0;
  501. while ($row_max_score = Database::fetch_array($res_max_score)) {
  502. $max_score = $row_max_score['max_score'];
  503. $score = $row_max_score['score'];
  504. if ($row_max_score['item_type'] == 'sco') {
  505. // Check if it is sco (easier to get max_score)
  506. //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.
  507. if ($max_score==0) {
  508. $max_score = 100;
  509. }
  510. $lp_scorm_result_score_total += ($score/$max_score);
  511. $current_value = $score/$max_score;
  512. } else {
  513. // Case of a TOOL_QUIZ element
  514. $item_id = $row_max_score['iid'];
  515. $item_path = $row_max_score['path'];
  516. // Get last attempt to this exercise through
  517. // the current lp for the current user
  518. $sql_last_attempt = "SELECT exe_id FROM $tbl_stats_exercices ".
  519. " WHERE exe_exo_id = '$item_path' ".
  520. " AND exe_user_id = '$user_id' ".
  521. // " AND orig_lp_id = '$lp_id' ". //lp_id is already defined by the item_id
  522. " AND orig_lp_item_id = '$item_id' ".
  523. " AND exe_cours_id = '$course_code' ".
  524. " ORDER BY exe_date DESC limit 1";
  525. $result_last_attempt = Database::query($sql_last_attempt);
  526. $num = Database :: num_rows($result_last_attempt);
  527. if ($num > 0 ) {
  528. $id_last_attempt = Database :: result($result_last_attempt, 0, 0);
  529. // Within the last attempt number tracking, get the sum of
  530. // the max_scores of all questions that it was
  531. // made of (we need to make this call dynamic
  532. // because of random questions selection)
  533. $sql = "SELECT SUM(t.ponderation) as maxscore ".
  534. " FROM ( SELECT distinct question_id, marks, ponderation ".
  535. " FROM $tbl_stats_attempts AS at " .
  536. " INNER JOIN $tbl_quiz_questions AS q ".
  537. " ON (q.id = at.question_id) ".
  538. " WHERE exe_id ='$id_last_attempt' ) AS t";
  539. $res_max_score_bis = Database::query($sql);
  540. $row_max_score_bis = Database :: fetch_array($res_max_score_bis);
  541. if (!empty($row_max_score_bis['maxscore'])) {
  542. $max_score = $row_max_score_bis['maxscore'];
  543. }
  544. $lp_scorm_result_score_total += ($score/$max_score);
  545. $current_value = $score/$max_score;
  546. } else {
  547. //$lp_scorm_result_score_total += 0;
  548. }
  549. }
  550. $count_items++;
  551. }
  552. $score_of_scorm_calculate += $count_items?round((($lp_scorm_result_score_total/$count_items)*100),2):0;
  553. $count_views++;
  554. }
  555. }
  556. if ( $count_views > 0 ) {
  557. $score_of_scorm_calculate = round(($score_of_scorm_calculate/$count_views),2);
  558. }
  559. return $score_of_scorm_calculate;
  560. }
  561. }
  562. return null;
  563. }
  564. /**
  565. * This function gets time spent in learning path for a student inside a course
  566. * @param int|array Student id(s)
  567. * @param string Course code
  568. * @param array Limit average to listed lp ids
  569. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  570. * @return int Total time
  571. */
  572. public static function get_time_spent_in_lp($student_id, $course_code, $lp_ids = array(), $session_id = null) {
  573. $course = CourseManager :: get_course_information($course_code);
  574. $student_id = intval($student_id);
  575. $total_time = 0;
  576. if (!empty($course['db_name'])) {
  577. $lp_table = Database :: get_course_table(TABLE_LP_MAIN, $course['db_name']);
  578. $t_lpv = Database :: get_course_table(TABLE_LP_VIEW, $course['db_name']);
  579. $t_lpiv = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course['db_name']);
  580. // Compose a filter based on optional learning paths list given
  581. $condition_lp = "";
  582. if(count($lp_ids) > 0) {
  583. $condition_lp =" WHERE id IN(".implode(',',$lp_ids).") ";
  584. }
  585. // Compose a filter based on optional session id
  586. $condition_session = "";
  587. if (isset($session_id)) {
  588. $session_id = intval($session_id);
  589. if (count($lp_ids) > 0) {
  590. $condition_session = " AND session_id = $session_id ";
  591. } else {
  592. $condition_session = " WHERE session_id = $session_id ";
  593. }
  594. }
  595. // Check the real number of LPs corresponding to the filter in the
  596. // database (and if no list was given, get them all)
  597. $res_row_lp = Database::query("SELECT DISTINCT(id) FROM $lp_table $condition_lp $condition_session");
  598. $count_row_lp = Database::num_rows($res_row_lp);
  599. // calculates time
  600. if ($count_row_lp > 0) {
  601. while ($row_lp = Database::fetch_array($res_row_lp)) {
  602. $lp_id = intval($row_lp['id']);
  603. $sql = 'SELECT SUM(total_time)
  604. FROM '.$t_lpiv.' AS item_view
  605. INNER JOIN '.$t_lpv.' AS view
  606. ON item_view.lp_view_id = view.id
  607. AND view.lp_id = '.$lp_id.'
  608. AND view.user_id = '.$student_id;
  609. $rs = Database::query($sql);
  610. if (Database :: num_rows($rs) > 0) {
  611. $total_time += Database :: result($rs, 0, 0);
  612. }
  613. }
  614. }
  615. }
  616. return $total_time;
  617. }
  618. /**
  619. * This function gets last connection time to one learning path
  620. * @param int|array Student id(s)
  621. * @param string Course code
  622. * @param int Learning path id
  623. * @return int Total time
  624. */
  625. public static function get_last_connection_time_in_lp($student_id, $course_code, $lp_id) {
  626. $course = CourseManager :: get_course_information($course_code);
  627. $student_id = intval($student_id);
  628. $lp_id = intval($lp_id);
  629. $last_time = 0;
  630. if (!empty($course['db_name'])) {
  631. $lp_table = Database :: get_course_table(TABLE_LP_MAIN, $course['db_name']);
  632. $t_lpv = Database :: get_course_table(TABLE_LP_VIEW, $course['db_name']);
  633. $t_lpiv = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course['db_name']);
  634. // Check the real number of LPs corresponding to the filter in the
  635. // database (and if no list was given, get them all)
  636. $res_row_lp = Database::query("SELECT id FROM $lp_table WHERE id = $lp_id ");
  637. $count_row_lp = Database::num_rows($res_row_lp);
  638. // calculates last connection time
  639. if ($count_row_lp > 0) {
  640. $sql = 'SELECT MAX(start_time)
  641. FROM ' . $t_lpiv . ' AS item_view
  642. INNER JOIN ' . $t_lpv . ' AS view
  643. ON item_view.lp_view_id = view.id
  644. AND view.lp_id = '.$lp_id.'
  645. AND view.user_id = '.$student_id;
  646. $rs = Database::query($sql);
  647. if (Database :: num_rows($rs) > 0) {
  648. $last_time = Database :: result($rs, 0, 0);
  649. }
  650. }
  651. }
  652. return $last_time;
  653. }
  654. /**
  655. * gets the list of students followed by coach
  656. * @param int Coach id
  657. * @return array List of students
  658. */
  659. public static function get_student_followed_by_coach($coach_id) {
  660. $coach_id = intval($coach_id);
  661. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  662. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  663. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  664. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  665. $a_students = array ();
  666. //////////////////////////////////////////////////////////////
  667. // At first, courses where $coach_id is coach of the course //
  668. //////////////////////////////////////////////////////////////
  669. $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id.' AND status=2';
  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 scu.id_session, scu.course_code
  676. FROM ' . $tbl_session_course_user . ' scu INNER JOIN '.$tbl_session_rel_access_url.' sru
  677. ON (scu.id_session=sru.session_id)
  678. WHERE scu.id_user=' . $coach_id.' AND scu.status=2 AND sru.access_url_id = '.$access_url_id;
  679. }
  680. }
  681. $result = Database::query($sql);
  682. while ($a_courses = Database::fetch_array($result)) {
  683. $course_code = $a_courses["course_code"];
  684. $id_session = $a_courses["id_session"];
  685. $sql = "SELECT distinct srcru.id_user
  686. FROM $tbl_session_course_user AS srcru, $tbl_session_user sru
  687. WHERE srcru.id_user = sru.id_user AND sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND srcru.id_session = sru.id_session AND srcru.course_code='$course_code' AND srcru.id_session='$id_session'";
  688. $rs = Database::query($sql);
  689. while ($row = Database::fetch_array($rs)) {
  690. $a_students[$row['id_user']] = $row['id_user'];
  691. }
  692. }
  693. //////////////////////////////////////////////////////////////
  694. // Then, courses where $coach_id is coach of the session //
  695. //////////////////////////////////////////////////////////////
  696. $sql = 'SELECT session_course_user.id_user
  697. FROM ' . $tbl_session_course_user . ' as session_course_user
  698. INNER JOIN '.$tbl_session_user.' sru ON session_course_user.id_user = sru.id_user AND session_course_user.id_session = sru.id_session
  699. INNER JOIN ' . $tbl_session_course . ' as session_course
  700. ON session_course.course_code = session_course_user.course_code
  701. AND session_course_user.id_session = session_course.id_session
  702. INNER JOIN ' . $tbl_session . ' as session
  703. ON session.id = session_course.id_session
  704. AND session.id_coach = ' . $coach_id;
  705. if ($_configuration['multiple_access_urls']==true) {
  706. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  707. $access_url_id = api_get_current_access_url_id();
  708. if ($access_url_id != -1){
  709. $sql = 'SELECT session_course_user.id_user
  710. FROM ' . $tbl_session_course_user . ' as session_course_user
  711. INNER JOIN '.$tbl_session_user.' sru ON session_course_user.id_user = sru.id_user AND session_course_user.id_session = sru.id_session
  712. INNER JOIN ' . $tbl_session_course . ' as session_course
  713. ON session_course.course_code = session_course_user.course_code
  714. AND session_course_user.id_session = session_course.id_session
  715. INNER JOIN ' . $tbl_session . ' as session
  716. ON session.id = session_course.id_session
  717. AND session.id_coach = ' . $coach_id.'
  718. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  719. ON session.id = session_rel_url.session_id WHERE access_url_id = '.$access_url_id;
  720. }
  721. }
  722. $result = Database::query($sql);
  723. while ($row = Database::fetch_array($result)) {
  724. $a_students[$row['id_user']] = $row['id_user'];
  725. }
  726. return $a_students;
  727. }
  728. /**
  729. * Get student followed by a coach inside a session
  730. * @param int Session id
  731. * @param int Coach id
  732. * @return array students list
  733. */
  734. public static function get_student_followed_by_coach_in_a_session($id_session, $coach_id) {
  735. $coach_id = intval($coach_id);
  736. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  737. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  738. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  739. $a_students = array ();
  740. //////////////////////////////////////////////////////////////
  741. // At first, courses where $coach_id is coach of the course //
  742. //////////////////////////////////////////////////////////////
  743. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_session="' . $id_session . '" AND id_user=' . $coach_id.' AND status=2';
  744. $result = Database::query($sql);
  745. while ($a_courses = Database::fetch_array($result)) {
  746. $course_code = $a_courses["course_code"];
  747. $sql = "SELECT distinct srcru.id_user
  748. FROM $tbl_session_course_user AS srcru
  749. WHERE course_code='$course_code' and id_session = '" . $id_session . "'";
  750. $rs = Database::query($sql);
  751. while ($row = Database::fetch_array($rs)) {
  752. $a_students[$row['id_user']] = $row['id_user'];
  753. }
  754. }
  755. //////////////////////////////////////////////////////////////
  756. // Then, courses where $coach_id is coach of the session //
  757. //////////////////////////////////////////////////////////////
  758. $dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
  759. $result = Database::query($dsl_session_coach);
  760. //He is the session_coach so we select all the users in the session
  761. if (Database::num_rows($result) > 0) {
  762. $sql = 'SELECT DISTINCT srcru.id_user FROM ' . $tbl_session_course_user . ' AS srcru WHERE id_session="' . $id_session . '"';
  763. $result = Database::query($sql);
  764. while ($row = Database::fetch_array($result)) {
  765. $a_students[$row['id_user']] = $row['id_user'];
  766. }
  767. }
  768. return $a_students;
  769. }
  770. /**
  771. * Check if a coach is allowed to follow a student
  772. * @param int Coach id
  773. * @param int Student id
  774. * @return bool
  775. */
  776. public static function is_allowed_to_coach_student($coach_id, $student_id) {
  777. $coach_id = intval($coach_id);
  778. $student_id = intval($student_id);
  779. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  780. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  781. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  782. //////////////////////////////////////////////////////////////
  783. // At first, courses where $coach_id is coach of the course //
  784. //////////////////////////////////////////////////////////////
  785. /*$sql = 'SELECT 1
  786. FROM ' . $tbl_session_course_user . ' AS session_course_user
  787. INNER JOIN ' . $tbl_session_course . ' AS session_course
  788. ON session_course.course_code = session_course_user.course_code
  789. AND id_coach=' . $coach_id . '
  790. WHERE id_user=' . $student_id;*/
  791. $sql = 'SELECT 1 FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id .' AND status=2';
  792. $result = Database::query($sql);
  793. if (Database::num_rows($result) > 0) {
  794. return true;
  795. }
  796. //////////////////////////////////////////////////////////////
  797. // Then, courses where $coach_id is coach of the session //
  798. //////////////////////////////////////////////////////////////
  799. $sql = 'SELECT session_course_user.id_user
  800. FROM ' . $tbl_session_course_user . ' as session_course_user
  801. INNER JOIN ' . $tbl_session_course . ' as session_course
  802. ON session_course.course_code = session_course_user.course_code
  803. INNER JOIN ' . $tbl_session . ' as session
  804. ON session.id = session_course.id_session
  805. AND session.id_coach = ' . $coach_id . '
  806. WHERE id_user = ' . $student_id;
  807. $result = Database::query($sql);
  808. if (Database::num_rows($result) > 0) {
  809. return true;
  810. }
  811. return false;
  812. }
  813. /**
  814. * Get courses followed by coach
  815. * @param int Coach id
  816. * @param int Session id (optional)
  817. * @return array Courses list
  818. */
  819. public static function get_courses_followed_by_coach($coach_id, $id_session = '')
  820. {
  821. $coach_id = intval($coach_id);
  822. if (!empty ($id_session))
  823. $id_session = intval($id_session);
  824. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  825. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  826. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  827. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  828. //////////////////////////////////////////////////////////////
  829. // At first, courses where $coach_id is coach of the course //
  830. //////////////////////////////////////////////////////////////
  831. $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id.' AND status=2';
  832. global $_configuration;
  833. if ($_configuration['multiple_access_urls']==true) {
  834. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  835. $access_url_id = api_get_current_access_url_id();
  836. if ($access_url_id != -1){
  837. $sql = 'SELECT DISTINCT scu.course_code FROM ' . $tbl_session_course_user . ' scu INNER JOIN '.$tbl_course_rel_access_url.' cru
  838. ON (scu.course_code = cru.course_code)
  839. WHERE scu.id_user=' . $coach_id.' AND scu.status=2 AND cru.access_url_id = '.$access_url_id;
  840. }
  841. }
  842. if (!empty ($id_session))
  843. $sql .= ' AND id_session=' . $id_session;
  844. $result = Database::query($sql);
  845. while ($row = Database::fetch_array($result)) {
  846. $a_courses[$row['course_code']] = $row['course_code'];
  847. }
  848. //////////////////////////////////////////////////////////////
  849. // Then, courses where $coach_id is coach of the session //
  850. //////////////////////////////////////////////////////////////
  851. $sql = 'SELECT DISTINCT session_course.course_code
  852. FROM ' . $tbl_session_course . ' as session_course
  853. INNER JOIN ' . $tbl_session . ' as session
  854. ON session.id = session_course.id_session
  855. AND session.id_coach = ' . $coach_id . '
  856. INNER JOIN ' . $tbl_course . ' as course
  857. ON course.code = session_course.course_code';
  858. if ($_configuration['multiple_access_urls']==true) {
  859. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  860. $access_url_id = api_get_current_access_url_id();
  861. if ($access_url_id != -1){
  862. $sql = 'SELECT DISTINCT session_course.course_code
  863. FROM ' . $tbl_session_course . ' as session_course
  864. INNER JOIN ' . $tbl_session . ' as session
  865. ON session.id = session_course.id_session
  866. AND session.id_coach = ' . $coach_id . '
  867. INNER JOIN ' . $tbl_course . ' as course
  868. ON course.code = session_course.course_code
  869. INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url
  870. ON (session_course.course_code = course_rel_url.course_code)';
  871. }
  872. }
  873. if (!empty ($id_session)) {
  874. $sql .= ' WHERE session_course.id_session=' . $id_session;
  875. if ($_configuration['multiple_access_urls']==true)
  876. $sql .= ' AND access_url_id = '.$access_url_id;
  877. } else {
  878. if ($_configuration['multiple_access_urls']==true)
  879. $sql .= ' WHERE access_url_id = '.$access_url_id;
  880. }
  881. $result = Database::query($sql);
  882. while ($row = Database::fetch_array($result)) {
  883. $a_courses[$row['course_code']] = $row['course_code'];
  884. }
  885. return $a_courses;
  886. }
  887. /**
  888. * Get sessions coached by user
  889. * @param int Coach id
  890. * @return array Sessions list
  891. */
  892. public static function get_sessions_coached_by_user($coach_id) {
  893. // table definition
  894. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  895. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  896. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  897. // protect datas
  898. $coach_id = intval($coach_id);
  899. // session where we are general coach
  900. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  901. FROM ' . $tbl_session . '
  902. WHERE id_coach=' . $coach_id;
  903. global $_configuration;
  904. if ($_configuration['multiple_access_urls']==true) {
  905. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  906. $access_url_id = api_get_current_access_url_id();
  907. if ($access_url_id != -1){
  908. $sql = 'SELECT DISTINCT id, name, date_start, date_end
  909. FROM ' . $tbl_session . ' session INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  910. ON (session.id = session_rel_url.session_id)
  911. WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id;
  912. }
  913. }
  914. $rs = Database::query($sql);
  915. while ($row = Database::fetch_array($rs))
  916. {
  917. $a_sessions[$row["id"]] = $row;
  918. }
  919. // session where we are coach of a course
  920. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  921. FROM ' . $tbl_session . ' as session
  922. INNER JOIN ' . $tbl_session_course_user . ' as session_course_user
  923. ON session.id = session_course_user.id_session
  924. AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2';
  925. global $_configuration;
  926. if ($_configuration['multiple_access_urls']==true) {
  927. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  928. $access_url_id = api_get_current_access_url_id();
  929. if ($access_url_id != -1){
  930. $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
  931. FROM ' . $tbl_session . ' as session
  932. INNER JOIN ' . $tbl_session_course_user . ' as session_course_user
  933. ON session.id = session_course_user.id_session AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2
  934. INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
  935. ON (session.id = session_rel_url.session_id)
  936. WHERE access_url_id = '.$access_url_id;
  937. }
  938. }
  939. $rs = Database::query($sql);
  940. while ($row = Database::fetch_array($rs))
  941. {
  942. $a_sessions[$row["id"]] = $row;
  943. }
  944. if (is_array($a_sessions)) {
  945. foreach ($a_sessions as & $session) {
  946. if ($session['date_start'] == '0000-00-00') {
  947. $session['status'] = get_lang('SessionActive');
  948. }
  949. else {
  950. $date_start = explode('-', $session['date_start']);
  951. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  952. $date_end = explode('-', $session['date_end']);
  953. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  954. if ($time_start < time() && time() < $time_end) {
  955. $session['status'] = get_lang('SessionActive');
  956. }
  957. else{
  958. if (time() < $time_start) {
  959. $session['status'] = get_lang('SessionFuture');
  960. }
  961. else{
  962. if (time() > $time_end) {
  963. $session['status'] = get_lang('SessionPast');
  964. }
  965. }
  966. }
  967. }
  968. }
  969. }
  970. return $a_sessions;
  971. }
  972. /**
  973. * Get courses list from a session
  974. * @param int Session id
  975. * @return array Courses list
  976. */
  977. public static function get_courses_list_from_session($session_id) {
  978. //protect datas
  979. $session_id = intval($session_id);
  980. // table definition
  981. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  982. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  983. $sql = 'SELECT DISTINCT course_code
  984. FROM ' . $tbl_session_course . '
  985. WHERE id_session=' . $session_id;
  986. $rs = Database::query($sql);
  987. $a_courses = array ();
  988. while ($row = Database::fetch_array($rs)) {
  989. $a_courses[$row['course_code']] = $row;
  990. }
  991. return $a_courses;
  992. }
  993. /**
  994. * Count assignments per student
  995. * @param int|array Student id(s)
  996. * @param string Course code
  997. * @param int Session id (optional), if param $session_id is null(default) return count of assignments including sessions, 0 = session is not filtered
  998. * @return int Count of assignments
  999. */
  1000. public static function count_student_assignments($student_id, $course_code, $session_id = null) {
  1001. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  1002. // protect datas
  1003. $course_code = Database::escape_string($course_code);
  1004. // get the informations of the course
  1005. $a_course = CourseManager :: get_course_information($course_code);
  1006. if (!empty($a_course['db_name'])) {
  1007. // table definition
  1008. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']);
  1009. $tbl_student_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION, $a_course['db_name']);
  1010. $condition_user = "";
  1011. if (is_array($student_id)) {
  1012. $condition_user = " AND ip.insert_user_id IN (".implode(',',$student_id).") ";
  1013. } else {
  1014. $condition_user = " AND ip.insert_user_id = '$student_id' ";
  1015. }
  1016. $condition_session = "";
  1017. if (isset($session_id)) {
  1018. $session_id = intval($session_id);
  1019. $condition_session = " AND pub.session_id = $session_id ";
  1020. }
  1021. $sql = "SELECT count(ip.tool) FROM $tbl_item_property ip INNER JOIN $tbl_student_publication pub ON ip.ref = pub.id WHERE ip.tool='work' $condition_user $condition_session ";
  1022. $rs = Database::query($sql);
  1023. $row = Database::fetch_row($rs);
  1024. return $row[0];
  1025. }
  1026. return null;
  1027. }
  1028. /**
  1029. * Count messages per student inside forum tool
  1030. * @param int Student id
  1031. * @param string Course code
  1032. * @param int Session id (optional), if param $session_id is null(default) return count of messages including sessions, 0 = session is not filtered
  1033. * @return int Count of messages
  1034. */
  1035. function count_student_messages($student_id, $course_code, $session_id = null) {
  1036. require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');
  1037. // protect datas
  1038. $student_id = intval($student_id);
  1039. $course_code = addslashes($course_code);
  1040. // get the informations of the course
  1041. $a_course = CourseManager :: get_course_information($course_code);
  1042. if(!empty($a_course['db_name']))
  1043. {
  1044. // table definition
  1045. $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  1046. $tbl_forum = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
  1047. $condition_user = "";
  1048. if (is_array($student_id)) {
  1049. $condition_user = " WHERE post.poster_id IN (".implode(',',$student_id).") ";
  1050. } else {
  1051. $condition_user = " WHERE post.poster_id = '$student_id' ";
  1052. }
  1053. $condition_session = "";
  1054. if (isset($session_id)) {
  1055. $session_id = intval($session_id);
  1056. $condition_session = " AND forum.session_id = $session_id";
  1057. }
  1058. $sql = "SELECT 1 FROM $tbl_forum_post post INNER JOIN $tbl_forum forum ON forum.forum_id = post.forum_id $condition_user $condition_session ";
  1059. $rs = Database::query($sql);
  1060. return Database::num_rows($rs);
  1061. }
  1062. else
  1063. {
  1064. return null;
  1065. }
  1066. }
  1067. /**
  1068. * This function counts the number of post by course
  1069. * @param string Course code
  1070. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  1071. * @return int The number of post by course
  1072. */
  1073. public static function count_number_of_posts_by_course($course_code, $session_id = null) {
  1074. //protect data
  1075. $course_code = Database::escape_string($course_code);
  1076. // get the informations of the course
  1077. $a_course = CourseManager :: get_course_information($course_code);
  1078. $count = 0;
  1079. if (!empty($a_course['db_name'])) {
  1080. $tbl_posts = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']);
  1081. $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
  1082. $condition_session = '';
  1083. if (isset($session_id)) {
  1084. $session_id = intval($session_id);
  1085. $condition_session = ' WHERE f.session_id = '. $session_id;
  1086. }
  1087. $sql = "SELECT count(*) FROM $tbl_posts p INNER JOIN $tbl_forums f ON f.forum_id = p.forum_id $condition_session ";
  1088. $result = Database::query($sql);
  1089. $row = Database::fetch_row($result);
  1090. $count = $row[0];
  1091. return $count;
  1092. } else {
  1093. return null;
  1094. }
  1095. }
  1096. /**
  1097. * This function counts the number of threads by course
  1098. * @param string Course code
  1099. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  1100. * @return int The number of threads by course
  1101. */
  1102. public static function count_number_of_threads_by_course($course_code, $session_id = null) {
  1103. //protect data
  1104. $course_code = Database::escape_string($course_code);
  1105. // get the informations of the course
  1106. $a_course = CourseManager :: get_course_information($course_code);
  1107. $count = 0;
  1108. if (!empty($a_course['db_name'])) {
  1109. $tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $a_course['db_name']);
  1110. $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
  1111. $condition_session = '';
  1112. if (isset($session_id)) {
  1113. $session_id = intval($session_id);
  1114. $condition_session = ' WHERE f.session_id = '. $session_id;
  1115. }
  1116. $sql = "SELECT count(*) FROM $tbl_threads t INNER JOIN $tbl_forums f ON f.forum_id = t.forum_id $condition_session ";
  1117. $result = Database::query($sql);
  1118. $row = Database::fetch_row($result);
  1119. $count = $row[0];
  1120. return $count;
  1121. } else {
  1122. return null;
  1123. }
  1124. }
  1125. /**
  1126. * This function counts the number of forums by course
  1127. * @param string Course code
  1128. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  1129. * @return int The number of forums by course
  1130. */
  1131. public static function count_number_of_forums_by_course($course_code, $session_id = null) {
  1132. //protect data
  1133. $course_code = addslashes($course_code);
  1134. // get the informations of the course
  1135. $a_course = CourseManager :: get_course_information($course_code);
  1136. $count = 0;
  1137. if (!empty($a_course['db_name'])) {
  1138. $condition_session = '';
  1139. if (isset($session_id)) {
  1140. $session_id = intval($session_id);
  1141. $condition_session = ' WHERE session_id = '. $session_id;
  1142. }
  1143. $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']);
  1144. $sql = "SELECT count(*) FROM $tbl_forums $condition_session";
  1145. $result = Database::query($sql);
  1146. $row = Database::fetch_row($result);
  1147. $count = $row[0];
  1148. return $count;
  1149. } else {
  1150. return null;
  1151. }
  1152. }
  1153. /**
  1154. * This function counts the chat last connections by course in x days
  1155. * @param string Course code
  1156. * @param int Last x days
  1157. * @param int Session id (optional)
  1158. * @return int Chat last connections by course in x days
  1159. */
  1160. public static function chat_connections_during_last_x_days_by_course($course_code,$last_days, $session_id = 0) {
  1161. //protect data
  1162. $last_days = intval($last_days);
  1163. $course_code = Database::escape_string($course_code);
  1164. $session_id = intval($session_id);
  1165. // get the informations of the course
  1166. $a_course = CourseManager :: get_course_information($course_code);
  1167. $count = 0;
  1168. if (!empty($a_course['db_name'])) {
  1169. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']);
  1170. $sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date
  1171. AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."' AND access_session_id='$session_id' ";
  1172. $result = Database::query($sql);
  1173. $row = Database::fetch_row($result);
  1174. $count = $row[0];
  1175. return $count;
  1176. } else {
  1177. return null;
  1178. }
  1179. }
  1180. /**
  1181. * This function gets the last student's connection in chat
  1182. * @param int Student id
  1183. * @param string Course code
  1184. * @param int Session id (optional)
  1185. * @return string datetime formatted without day (e.g: February 23, 2010 10:20:50 )
  1186. */
  1187. public static function chat_last_connection($student_id, $course_code, $session_id = 0) {
  1188. //protect datas
  1189. $student_id = intval($student_id);
  1190. $course_code= Database::escape_string($course_code);
  1191. $session_id = intval($session_id);
  1192. $date_time = '';
  1193. // table definition
  1194. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  1195. $sql = "SELECT access_date FROM $tbl_stats_access
  1196. WHERE access_tool='".TOOL_CHAT."' AND access_user_id='$student_id' AND access_cours_code = '$course_code' AND access_session_id = '$session_id' ORDER BY access_date DESC limit 1";
  1197. $rs = Database::query($sql);
  1198. if (Database::num_rows($rs) > 0) {
  1199. $row = Database::fetch_array($rs);
  1200. $date_time = api_convert_and_format_date($row['access_date'], null, date_default_timezone_get());
  1201. }
  1202. return $date_time;
  1203. }
  1204. /**
  1205. * Get count student's visited links
  1206. * @param int Student id
  1207. * @param string Course code
  1208. * @param int Session id (optional)
  1209. * @return int count of visited links
  1210. */
  1211. public static function count_student_visited_links($student_id, $course_code, $session_id = 0) {
  1212. // protect datas
  1213. $student_id = intval($student_id);
  1214. $course_code = Database::escape_string($course_code);
  1215. $session_id = intval($session_id);
  1216. // table definition
  1217. $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  1218. $sql = 'SELECT 1
  1219. FROM '.$tbl_stats_links.'
  1220. WHERE links_user_id= '.$student_id.'
  1221. AND links_cours_id = "'.$course_code.'"
  1222. AND links_session_id = '.$session_id.' ';
  1223. $rs = Database::query($sql);
  1224. return Database::num_rows($rs);
  1225. }
  1226. /**
  1227. * Get count student downloaded documents
  1228. * @param int Student id
  1229. * @param string Course code
  1230. * @param int Session id (optional)
  1231. * @return int Count downloaded documents
  1232. */
  1233. public static function count_student_downloaded_documents($student_id, $course_code, $session_id = 0) {
  1234. // protect datas
  1235. $student_id = intval($student_id);
  1236. $course_code = Database::escape_string($course_code);
  1237. $session_id = intval($session_id);
  1238. // table definition
  1239. $tbl_stats_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  1240. $sql = 'SELECT 1
  1241. FROM ' . $tbl_stats_documents . '
  1242. WHERE down_user_id = '.$student_id.'
  1243. AND down_cours_id = "'.$course_code.'"
  1244. AND down_session_id = '.$session_id.' ';
  1245. $rs = Database::query($sql);
  1246. return Database::num_rows($rs);
  1247. }
  1248. /**
  1249. * Get course list inside a session from a student
  1250. * @param int Student id
  1251. * @param int Session id (optional)
  1252. * @return array Courses list
  1253. */
  1254. public static function get_course_list_in_session_from_student($user_id, $id_session = 0) {
  1255. $user_id = intval($user_id);
  1256. $id_session = intval($id_session);
  1257. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1258. $sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user="' . $user_id . '" AND id_session="' . $id_session . '"';
  1259. $result = Database::query($sql);
  1260. $a_courses = array ();
  1261. while ($row = Database::fetch_array($result)) {
  1262. $a_courses[$row['course_code']] = $row['course_code'];
  1263. }
  1264. return $a_courses;
  1265. }
  1266. /**
  1267. * Get inactives students in course
  1268. * @param string Course code
  1269. * @param string Since login course date (optional, default = 'never')
  1270. * @param int Session id (optional)
  1271. * @return array Inactives users
  1272. */
  1273. public static function get_inactives_students_in_course($course_code, $since = 'never', $session_id=0) {
  1274. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  1275. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1276. $table_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1277. $inner = '';
  1278. if($session_id!=0)
  1279. {
  1280. $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user
  1281. ON stats_login.course_code = session_course_user.course_code
  1282. AND session_course_user.id_session = '.intval($session_id).'
  1283. AND session_course_user.id_user = stats_login.user_id ';
  1284. }
  1285. $sql = 'SELECT user_id, MAX(login_course_date) max_date FROM'.$tbl_track_login.' stats_login'.$inner.'
  1286. GROUP BY user_id
  1287. HAVING DATE_SUB( NOW(), INTERVAL '.$since.' DAY) > max_date ';
  1288. //HAVING DATE_ADD(max_date, INTERVAL '.$since.' DAY) < NOW() ';
  1289. if ($since == 'never') {
  1290. $sql = 'SELECT course_user.user_id FROM '.$table_course_rel_user.' course_user
  1291. LEFT JOIN '. $tbl_track_login.' stats_login
  1292. ON course_user.user_id = stats_login.user_id AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' '.
  1293. $inner.'
  1294. WHERE course_user.course_code = \''.Database::escape_string($course_code).'\'
  1295. AND stats_login.login_course_date IS NULL
  1296. GROUP BY course_user.user_id';
  1297. }
  1298. $rs = api_sql_query($sql);
  1299. $inactive_users = array();
  1300. while($user = Database::fetch_array($rs))
  1301. {
  1302. $inactive_users[] = $user['user_id'];
  1303. }
  1304. return $inactive_users;
  1305. }
  1306. /**
  1307. * Get count login per student
  1308. * @param int Student id
  1309. * @param string Course code
  1310. * @param int Session id (optional)
  1311. * @return int count login
  1312. */
  1313. public static function count_login_per_student($student_id, $course_code, $session_id = 0) {
  1314. $student_id = intval($student_id);
  1315. $course_code = Database::escape_string($course_code);
  1316. $session_id = intval($session_id);
  1317. $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  1318. $sql = 'SELECT '.$student_id.'
  1319. FROM ' . $tbl_course_rel_user . '
  1320. WHERE access_user_id=' . $student_id . '
  1321. AND access_cours_code="' . $course_code . '" AND access_session_id = "'.$session_id.'" ';
  1322. $rs = Database::query($sql);
  1323. $nb_login = Database::num_rows($rs);
  1324. return $nb_login;
  1325. }
  1326. /**
  1327. * Get students followed by a human resources manager
  1328. * @param int Drh id
  1329. * @return array Student list
  1330. */
  1331. public static function get_student_followed_by_drh($hr_dept_id) {
  1332. $hr_dept_id = intval($hr_dept_id);
  1333. $a_students = array ();
  1334. $tbl_organism = Database :: get_main_table(TABLE_MAIN_ORGANISM);
  1335. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1336. $sql = 'SELECT DISTINCT user_id FROM '.$tbl_user.' as user
  1337. WHERE hr_dept_id='.$hr_dept_id;
  1338. $rs = Database::query($sql);
  1339. while($user = Database :: fetch_array($rs))
  1340. {
  1341. $a_students[$user['user_id']] = $user['user_id'];
  1342. }
  1343. return $a_students;
  1344. }
  1345. /**
  1346. * allow get average of test and scorm inside a learning path
  1347. * @param int User id
  1348. * @param string Course id
  1349. * @return float average of test
  1350. * @author isaac flores paz <florespaz@bidsoftperu.com>
  1351. */
  1352. public static function get_average_test_scorm_and_lp ($user_id,$course_id) {
  1353. //the score inside the Reporting table
  1354. $course_info=api_get_course_info($course_id);
  1355. $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']);
  1356. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_info['dbName']);
  1357. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course_info['dbName']);
  1358. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']);
  1359. $sql_type='SELECT id,lp_type FROM '.$lp_table;
  1360. $rs_type=Database::query($sql_type);
  1361. $average_data=0;
  1362. $count_loop=0;
  1363. while ($row_type=Database::fetch_array($rs_type)) {
  1364. if ($row_type['lp_type']==1) {//lp dokeos
  1365. $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
  1366. $rs_last_lp_view_id = Database::query($sql);
  1367. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  1368. $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
  1369. 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.'"';
  1370. $sum=0;
  1371. $tot=0;
  1372. $rs_list_view1=Database::query($sql_list_view);
  1373. while ($row_list_view=Database::fetch_array($rs_list_view1)) {
  1374. $sum=$sum+$row_list_view['sum_data'];
  1375. $tot++;
  1376. }
  1377. if ($tot==0) {
  1378. $tot=1;
  1379. }
  1380. $average_data1=$sum/$tot;
  1381. $sql_list_view='';
  1382. $rs_last_lp_view_id='';
  1383. } elseif ($row_type['lp_type']==2) {//lp scorm
  1384. $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'";
  1385. $rs_last_lp_view_id = Database::query($sql);
  1386. $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id'));
  1387. $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
  1388. 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.'"';
  1389. $tot=0;
  1390. $sum=0;
  1391. $rs_list_view2=Database::query($sql_list_view);
  1392. while ($row_list_view=Database::fetch_array($rs_list_view2)) {
  1393. $sum=$sum+$row_list_view['sum_data'];
  1394. $tot++;
  1395. }
  1396. if ($tot==0) {
  1397. $tot=1;
  1398. }
  1399. $average_data2=$sum/$tot;
  1400. }
  1401. $average_data_sum=$average_data_sum+$average_data1+$average_data2;
  1402. $average_data2=0;
  1403. $average_data1=0;
  1404. $count_loop++;
  1405. }
  1406. if ((int)$count_loop > 0) {
  1407. $avg_student_score = round(($average_data_sum / $count_loop * 100), 2);
  1408. }
  1409. return $avg_student_score;
  1410. }
  1411. /**
  1412. * get count clicks about tools most used by course
  1413. * @param string Course code
  1414. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  1415. * @return array tools data
  1416. */
  1417. public static function get_tools_most_used_by_course($course_code, $session_id = null) {
  1418. //protect data
  1419. $course_code = Database::escape_string($course_code);
  1420. $data = array();
  1421. $TABLETRACK_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  1422. $condition_session = '';
  1423. if (isset($session_id)) {
  1424. $session_id = intval($session_id);
  1425. $condition_session = ' AND access_session_id = '. $session_id;
  1426. }
  1427. $sql = "SELECT access_tool, COUNT(DISTINCT access_user_id),count( access_tool ) as count_access_tool
  1428. FROM $TABLETRACK_ACCESS
  1429. WHERE access_tool IS NOT NULL
  1430. AND access_cours_code = '$course_code'
  1431. $condition_session
  1432. GROUP BY access_tool
  1433. ORDER BY count_access_tool DESC
  1434. LIMIT 0, 3";
  1435. $rs = Database::query($sql);
  1436. if (Database::num_rows($rs) > 0) {
  1437. while ($row = Database::fetch_array($rs)) {
  1438. $data[] = $row;
  1439. }
  1440. }
  1441. return $data;
  1442. }
  1443. /**
  1444. * get documents most downloaded by course
  1445. * @param string Course code
  1446. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  1447. * @param int Limit (optional, default = 0, 0 = without limit)
  1448. * @return array documents downloaded
  1449. */
  1450. public static function get_documents_most_downloaded_by_course($course_code, $session_id = null, $limit = 0) {
  1451. //protect data
  1452. $course_code = Database::escape_string($course_code);
  1453. $data = array();
  1454. $TABLETRACK_DOWNLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  1455. $condition_session = '';
  1456. if (isset($session_id)) {
  1457. $session_id = intval($session_id);
  1458. $condition_session = ' AND down_session_id = '. $session_id;
  1459. }
  1460. $sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
  1461. FROM $TABLETRACK_DOWNLOADS
  1462. WHERE down_cours_id = '$course_code'
  1463. $condition_session
  1464. GROUP BY down_doc_path
  1465. ORDER BY count_down DESC
  1466. LIMIT 0, $limit";
  1467. $rs = Database::query($sql);
  1468. if (Database::num_rows($rs) > 0) {
  1469. while ($row = Database::fetch_array($rs)) {
  1470. $data[] = $row;
  1471. }
  1472. }
  1473. return $data;
  1474. }
  1475. /**
  1476. * get links most visited by course
  1477. * @param string Course code
  1478. * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
  1479. * @return array links most visited
  1480. */
  1481. public static function get_links_most_visited_by_course($course_code, $session_id = null) {
  1482. //protect data
  1483. $course_code = Database::escape_string($course_code);
  1484. $course_info=api_get_course_info($course_code);
  1485. $data = array();
  1486. $TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  1487. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK, $course_info['dbName']);
  1488. $condition_session = '';
  1489. if (isset($session_id)) {
  1490. $session_id = intval($session_id);
  1491. $condition_session = ' AND cl.session_id = '.$session_id;
  1492. }
  1493. $sql = "SELECT cl.title, cl.url,count(DISTINCT sl.links_user_id), count(cl.title) as count_visits
  1494. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  1495. WHERE sl.links_link_id = cl.id
  1496. AND sl.links_cours_id = '$_cid'
  1497. $condition_session
  1498. GROUP BY cl.title, cl.url
  1499. ORDER BY count_visits DESC
  1500. LIMIT 0, 3";
  1501. $rs = Database::query($sql);
  1502. if (Database::num_rows($rs) > 0) {
  1503. while ($row = Database::fetch_array($rs)) {
  1504. $data[] = $row;
  1505. }
  1506. }
  1507. return $data;
  1508. }
  1509. }
  1510. class TrackingCourseLog {
  1511. function count_item_resources() {
  1512. global $session_id;
  1513. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1514. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  1515. $sql = "SELECT count(tool) AS total_number_of_items FROM $table_item_property track_resource, $table_user user" .
  1516. " WHERE track_resource.insert_user_id = user.user_id AND id_session = $session_id ";
  1517. if (isset($_GET['keyword'])) {
  1518. $keyword = Database::escape_string(trim($_GET['keyword']));
  1519. $sql .= " AND (user.username LIKE '%".$keyword."%' OR lastedit_type LIKE '%".$keyword."%' OR tool LIKE '%".$keyword."%')";
  1520. }
  1521. $sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description')";
  1522. $res = Database::query($sql);
  1523. $obj = Database::fetch_object($res);
  1524. return $obj->total_number_of_items;
  1525. }
  1526. function get_item_resources_data($from, $number_of_items, $column, $direction) {
  1527. global $dateTimeFormatLong, $session_id;
  1528. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1529. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  1530. $table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  1531. $sql = "SELECT
  1532. tool as col0,
  1533. lastedit_type as col1,
  1534. ref as ref,
  1535. user.username as col3,
  1536. insert_date as col5,
  1537. visibility as col6
  1538. FROM $table_item_property track_resource, $table_user user
  1539. WHERE track_resource.insert_user_id = user.user_id AND id_session = $session_id ";
  1540. if (isset($_GET['keyword'])) {
  1541. $keyword = Database::escape_string(trim($_GET['keyword']));
  1542. $sql .= " AND (user.username LIKE '%".$keyword."%' OR lastedit_type LIKE '%".$keyword."%' OR tool LIKE '%".$keyword."%') ";
  1543. }
  1544. $sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description')";
  1545. if ($column == 0) { $column = '0'; }
  1546. if ($column != '' && $direction != '') {
  1547. if ($column != 2 && $column != 4) {
  1548. $sql .= " ORDER BY col$column $direction";
  1549. }
  1550. } else {
  1551. $sql .= " ORDER BY col5 DESC ";
  1552. }
  1553. $sql .= " LIMIT $from, $number_of_items ";
  1554. $res = Database::query($sql) or die(Database::error());
  1555. $resources = array ();
  1556. while ($row = Database::fetch_array($res)) {
  1557. $ref = $row['ref'];
  1558. $table_name = TrackingCourseLog::get_tool_name_table($row['col0']);
  1559. $table_tool = Database :: get_course_table($table_name['table_name']);
  1560. $id = $table_name['id_tool'];
  1561. $query = "SELECT session.id, session.name, user.username FROM $table_tool tool, $table_session session, $table_user user" .
  1562. " WHERE tool.session_id = session.id AND session.id_coach = user.user_id AND tool.$id = $ref";
  1563. $recorset = Database::query($query);
  1564. if (!empty($recorset)) {
  1565. $obj = Database::fetch_object($recorset);
  1566. $name_session = '';
  1567. $coach_name = '';
  1568. if (!empty($obj)) {
  1569. $name_session = $obj->name;
  1570. $coach_name = $obj->username;
  1571. }
  1572. $url_tool = api_get_path(WEB_CODE_PATH).$table_name['link_tool'];
  1573. $row[0] = '';
  1574. if ($row['col6'] != 2) {
  1575. $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'&'.$obj->id.'">'.api_ucfirst($row['col0']).'</a>';
  1576. } else {
  1577. $row[0] = api_ucfirst($row['col0']);
  1578. }
  1579. $row[1] = get_lang($row[1]);
  1580. $row[5] = api_convert_and_format_date($row['col5'], null, date_default_timezone_get());
  1581. $row[4] = '';
  1582. if ($table_name['table_name'] == 'document') {
  1583. $condition = 'tool.title as title';
  1584. $query_document = "SELECT $condition FROM $table_tool tool" .
  1585. " WHERE id = $ref";
  1586. $rs_document = Database::query($query_document) or die(Database::error());
  1587. $obj_document = Database::fetch_object($rs_document);
  1588. $row[4] = $obj_document->title;
  1589. }
  1590. $row2 = $name_session;
  1591. if (!empty($coach_name)) {
  1592. $row2 .= '<br />'.get_lang('Coach').': '.$coach_name;
  1593. }
  1594. $row[2] = $row2;
  1595. $resources[] = $row;
  1596. }
  1597. }
  1598. return $resources;
  1599. }
  1600. function get_tool_name_table($tool) {
  1601. switch ($tool) {
  1602. case 'document':
  1603. $table_name = TABLE_DOCUMENT;
  1604. $link_tool = 'document/document.php';
  1605. $id_tool = 'id';
  1606. break;
  1607. case 'learnpath':
  1608. $table_name = TABLE_LP_MAIN;
  1609. $link_tool = 'newscorm/lp_controller.php';
  1610. $id_tool = 'id';
  1611. break;
  1612. case 'quiz':
  1613. $table_name = TABLE_QUIZ_TEST;
  1614. $link_tool = 'exercice/exercice.php';
  1615. $id_tool = 'id';
  1616. break;
  1617. case 'glossary':
  1618. $table_name = TABLE_GLOSSARY;
  1619. $link_tool = 'glossary/index.php';
  1620. $id_tool = 'glossary_id';
  1621. break;
  1622. case 'link':
  1623. $table_name = TABLE_LINK;
  1624. $link_tool = 'link/link.php';
  1625. $id_tool = 'id';
  1626. break;
  1627. case 'course_description':
  1628. $table_name = TABLE_COURSE_DESCRIPTION;
  1629. $link_tool = 'course_description/';
  1630. $id_tool = 'id';
  1631. break;
  1632. default:
  1633. $table_name = $tool;
  1634. break;
  1635. }
  1636. return array('table_name' => $table_name,
  1637. 'link_tool' => $link_tool,
  1638. 'id_tool' => $id_tool);
  1639. }
  1640. function display_additional_profile_fields() {
  1641. // getting all the extra profile fields that are defined by the platform administrator
  1642. $extra_fields = UserManager :: get_extra_fields(0,50,5,'ASC');
  1643. // creating the form
  1644. $return = '<form action="courseLog.php" method="get" name="additional_profile_field_form" id="additional_profile_field_form">';
  1645. // the select field with the additional user profile fields (= this is where we select the field of which we want to see
  1646. // the information the users have entered or selected.
  1647. $return .= '<select name="additional_profile_field">';
  1648. $return .= '<option value="-">'.get_lang('SelectFieldToAdd').'</option>';
  1649. foreach ($extra_fields as $key=>$field) {
  1650. // show only extra fields that are visible, added by J.Montoya
  1651. if ($field[6]==1) {
  1652. if ($field[0] == $_GET['additional_profile_field'] ) {
  1653. $selected = 'selected="selected"';
  1654. } else {
  1655. $selected = '';
  1656. }
  1657. $return .= '<option value="'.$field[0].'" '.$selected.'>'.$field[3].'</option>';
  1658. }
  1659. }
  1660. $return .= '</select>';
  1661. // the form elements for the $_GET parameters (because the form is passed through GET
  1662. foreach ($_GET as $key=>$value){
  1663. if ($key <> 'additional_profile_field') {
  1664. $return .= '<input type="hidden" name="'.Security::remove_XSS($key).'" value="'.Security::remove_XSS($value).'" />';
  1665. }
  1666. }
  1667. // the submit button
  1668. $return .= '<button class="save" type="submit">'.get_lang('AddAdditionalProfileField').'</button>';
  1669. $return .= '</form>';
  1670. return $return;
  1671. }
  1672. /**
  1673. * This function gets all the information of a certrain ($field_id) additional profile field.
  1674. * 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
  1675. *
  1676. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1677. * @since October 2009
  1678. * @version 1.8.7
  1679. */
  1680. function get_addtional_profile_information_of_field($field_id){
  1681. // Database table definition
  1682. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  1683. $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  1684. $sql = "SELECT user.user_id, field.field_value FROM $table_user user, $table_user_field_values field
  1685. WHERE user.user_id = field.user_id
  1686. AND field.field_id='".intval($field_id)."'";
  1687. $result = api_sql_query($sql);
  1688. while($row = Database::fetch_array($result))
  1689. {
  1690. $return[$row['user_id']][] = $row['field_value'];
  1691. }
  1692. return $return;
  1693. }
  1694. /**
  1695. * 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
  1696. * 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
  1697. *
  1698. * @author Julio Montoya <gugli100@gmail.com>
  1699. * @param int field id
  1700. * @param array list of user ids
  1701. * @return array
  1702. * @since Nov 2009
  1703. * @version 1.8.6.2
  1704. */
  1705. function get_addtional_profile_information_of_field_by_user($field_id, $users) {
  1706. // Database table definition
  1707. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  1708. $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  1709. $result_extra_field = UserManager::get_extra_field_information($field_id);
  1710. if (!empty($users)) {
  1711. if ($result_extra_field['field_type'] == USER_FIELD_TYPE_TAG ) {
  1712. foreach($users as $user_id) {
  1713. $user_result = UserManager::get_user_tags($user_id, $field_id);
  1714. $tag_list = array();
  1715. foreach($user_result as $item) {
  1716. $tag_list[] = $item['tag'];
  1717. }
  1718. $return[$user_id][] = implode(', ',$tag_list);
  1719. }
  1720. } else {
  1721. $new_user_array = array();
  1722. foreach($users as $user_id) {
  1723. $new_user_array[]= "'".$user_id."'";
  1724. }
  1725. $users = implode(',',$new_user_array);
  1726. //selecting only the necessary information NOT ALL the user list
  1727. $sql = "SELECT user.user_id, field.field_value FROM $table_user user INNER JOIN $table_user_field_values field
  1728. ON (user.user_id = field.user_id)
  1729. WHERE field.field_id=".intval($field_id)." AND user.user_id IN ($users)";
  1730. $result = api_sql_query($sql);
  1731. while($row = Database::fetch_array($result)) {
  1732. // get option value for field type double select by id
  1733. if (!empty($row['field_value'])) {
  1734. if ($result_extra_field['field_type'] == USER_FIELD_TYPE_DOUBLE_SELECT) {
  1735. $id_double_select = explode(';',$row['field_value']);
  1736. if (is_array($id_double_select)) {
  1737. $value1 = $result_extra_field['options'][$id_double_select[0]]['option_value'];
  1738. $value2 = $result_extra_field['options'][$id_double_select[1]]['option_value'];
  1739. $row['field_value'] = ($value1.';'.$value2);
  1740. }
  1741. }
  1742. }
  1743. // get other value from extra field
  1744. $return[$row['user_id']][] = $row['field_value'];
  1745. }
  1746. }
  1747. }
  1748. return $return;
  1749. }
  1750. /**
  1751. * count the number of students in this course (used for SortableTable)
  1752. * Deprecated
  1753. */
  1754. function count_student_in_course() {
  1755. global $nbStudents;
  1756. return $nbStudents;
  1757. }
  1758. function sort_users($a, $b) {
  1759. return strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  1760. }
  1761. function sort_users_desc($a, $b) {
  1762. return strcmp( trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  1763. }
  1764. /**
  1765. * Get number of users for sortable with pagination
  1766. * @return int
  1767. */
  1768. function get_number_of_users() {
  1769. global $user_ids;
  1770. return count($user_ids);
  1771. }
  1772. /**
  1773. * Get data for users list in sortable with pagination
  1774. * @return array
  1775. */
  1776. function get_user_data($from, $number_of_items, $column, $direction) {
  1777. global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content, $session_id;
  1778. $course_code = Database::escape_string($course_code);
  1779. $course_info = CourseManager :: get_course_information($course_code);
  1780. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1781. // get all users data from a course for sortable with limit
  1782. $condition_user = "";
  1783. if (is_array($user_ids)) {
  1784. $condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") ";
  1785. } else {
  1786. $condition_user = " WHERE user.user_id = '$user_ids' ";
  1787. }
  1788. $sql = "SELECT user.user_id as col0,
  1789. user.official_code as col1,
  1790. user.lastname as col2,
  1791. user.firstname as col3
  1792. FROM $tbl_user as user
  1793. $condition_user ";
  1794. if (!in_array($direction, array('ASC','DESC'))) {
  1795. $direction = 'ASC';
  1796. }
  1797. $column = intval($column);
  1798. $from = intval($from);
  1799. $number_of_items = intval($number_of_items);
  1800. $sql .= " ORDER BY col$column $direction ";
  1801. $sql .= " LIMIT $from,$number_of_items";
  1802. $res = Database::query($sql);
  1803. $users = array ();
  1804. $t = time();
  1805. $row = array();
  1806. while ($user = Database::fetch_row($res)) {
  1807. $row[0] = $user[1];
  1808. if ($is_western_name_order) {
  1809. $row[1] = $user[3];
  1810. $row[2] = $user[2];
  1811. } else {
  1812. $row[1] = $user[2];
  1813. $row[2] = $user[3];
  1814. }
  1815. $row[3] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user[0], $course_code, $session_id));
  1816. $avg_student_score = Tracking::get_avg_student_score($user[0], $course_code, array(), $session_id);
  1817. $avg_student_progress = Tracking::get_avg_student_progress($user[0], $course_code, array(), $session_id);
  1818. if (empty($avg_student_score)) {$avg_student_score=0;}
  1819. if (empty($avg_student_progress)) {$avg_student_progress=0;}
  1820. $row[4] = $avg_student_progress.'%';
  1821. $row[5] = $avg_student_score.'%';
  1822. $row[6] = Tracking::count_student_assignments($user[0], $course_code, $session_id);
  1823. $row[7] = Tracking::count_student_messages($user[0], $course_code, $session_id);
  1824. $row[8] = Tracking::get_first_connection_date_on_the_course($user[0], $course_code, $session_id);
  1825. $row[9] = Tracking::get_last_connection_date_on_the_course($user[0], $course_code, $session_id);
  1826. // we need to display an additional profile field
  1827. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  1828. if (is_array($additional_user_profile_info[$user[0]])) {
  1829. $row[10]=implode(', ', $additional_user_profile_info[$user[0]]);
  1830. } else {
  1831. $row[10]='&nbsp;';
  1832. }
  1833. }
  1834. $row[11] = '<center><a href="../mySpace/myStudents.php?student='.$user[0].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  1835. if ($export_csv) {
  1836. $row[8] = strip_tags($row[8]);
  1837. $row[9] = strip_tags($row[9]);
  1838. unset($row[10]);
  1839. unset($row[11]);
  1840. $csv_content[] = $row;
  1841. }
  1842. // store columns in array $users
  1843. $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]);
  1844. }
  1845. return $users;
  1846. }
  1847. }
  1848. class TrackingUserLog {
  1849. /**
  1850. * Displays the number of logins every month for a specific user in a specific course.
  1851. */
  1852. function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
  1853. {
  1854. $MonthsLong = $GLOBALS['MonthsLong'];
  1855. // protected data
  1856. $user_id = intval($user_id);
  1857. $session_id = intval($session_id);
  1858. $course_id = Database::escape_string($course_id);
  1859. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  1860. $tempView = $view;
  1861. if(substr($view,0,1) == '1') {
  1862. $new_view = substr_replace($view,'0',0,1);
  1863. echo "
  1864. <tr>
  1865. <td valign='top'>
  1866. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font>" .
  1867. "<b>".get_lang('LoginsAndAccessTools')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".$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>]
  1868. </td>
  1869. </tr>
  1870. ";
  1871. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LoginsDetails')."<br>";
  1872. $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
  1873. FROM $track_access_table
  1874. WHERE access_user_id = '$user_id'
  1875. AND access_cours_code = '$course_id'
  1876. AND access_session_id = '$session_id'
  1877. GROUP BY YEAR(access_date),MONTH(access_date)
  1878. ORDER BY YEAR(access_date),MONTH(access_date) ASC";
  1879. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  1880. //$results = getManyResults2Col($sql);
  1881. $results = getManyResults3Col($sql);
  1882. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  1883. echo "<tr>
  1884. <td class='secLine'>
  1885. ".get_lang('LoginsTitleMonthColumn')."
  1886. </td>
  1887. <td class='secLine'>
  1888. ".get_lang('LoginsTitleCountColumn')."
  1889. </td>
  1890. </tr>";
  1891. $total = 0;
  1892. if (is_array($results)) {
  1893. for($j = 0 ; $j < count($results) ; $j++) {
  1894. echo "<tr>";
  1895. echo "<td class='content'><a href='logins_details.php?uInfo=".$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>";
  1896. echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
  1897. echo"</tr>";
  1898. $total = $total + $results[$j][1];
  1899. }
  1900. echo "<tr>";
  1901. echo "<td>".get_lang('Total')."</td>";
  1902. echo "<td align='right' class='content'>".$total."</td>";
  1903. echo"</tr>";
  1904. } else {
  1905. echo "<tr>";
  1906. echo "<td colspan='2'><center>".get_lang('NoResult')."</center></td>";
  1907. echo"</tr>";
  1908. }
  1909. echo "</table>";
  1910. echo "</td></tr>";
  1911. } else {
  1912. $new_view = substr_replace($view,'1',0,1);
  1913. echo "
  1914. <tr>
  1915. <td valign='top'>
  1916. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=".$user_id."&view=".Security::remove_XSS($new_view)."' class='specialLink'>".get_lang('LoginsAndAccessTools')."</a>
  1917. </td>
  1918. </tr>
  1919. ";
  1920. }
  1921. }
  1922. /**
  1923. * Displays the exercise results for a specific user in a specific course.
  1924. * @todo remove globals
  1925. */
  1926. function display_exercise_tracking_info($view, $user_id, $course_id)
  1927. {
  1928. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $dateTimeFormatLong;
  1929. if(substr($view,1,1) == '1')
  1930. {
  1931. $new_view = substr_replace($view,'0',1,1);
  1932. echo "<tr>
  1933. <td valign='top'>
  1934. <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>]
  1935. </td>
  1936. </tr>";
  1937. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('ExercicesDetails')."<br />";
  1938. $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  1939. FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
  1940. WHERE te.exe_cours_id = '".Database::escape_string($course_id)."'
  1941. AND te.exe_user_id = '".Database::escape_string($user_id)."'
  1942. AND te.exe_exo_id = ce.id
  1943. ORDER BY ce.title ASC, te.exe_date ASC";
  1944. $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  1945. FROM $TBL_TRACK_HOTPOTATOES AS te
  1946. WHERE te.exe_user_id = '".Database::escape_string($user_id)."' AND te.exe_cours_id = '".Database::escape_string($course_id)."'
  1947. ORDER BY te.exe_cours_id ASC, te.exe_date ASC";
  1948. $hpresults = getManyResultsXCol($hpsql, 4);
  1949. $NoTestRes = 0;
  1950. $NoHPTestRes = 0;
  1951. echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
  1952. $results = getManyResultsXCol($sql, 4);
  1953. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
  1954. echo "
  1955. <tr bgcolor='#E6E6E6'>
  1956. <td>
  1957. ".get_lang('ExercicesTitleExerciceColumn')."
  1958. </td>
  1959. <td>
  1960. ".get_lang('Date')."
  1961. </td>
  1962. <td>
  1963. ".get_lang('ExercicesTitleScoreColumn')."
  1964. </td>
  1965. </tr>";
  1966. if (is_array($results)) {
  1967. for($i = 0; $i < sizeof($results); $i++) {
  1968. $display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
  1969. echo "<tr>\n";
  1970. echo "<td class='content'>".$results[$i][0]."</td>\n";
  1971. echo "<td class='content'>".$display_date."</td>\n";
  1972. echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
  1973. echo "</tr>\n";
  1974. }
  1975. } else {
  1976. // istvan begin
  1977. $NoTestRes = 1;
  1978. }
  1979. // The Result of Tests
  1980. if(is_array($hpresults)) {
  1981. for($i = 0; $i < sizeof($hpresults); $i++) {
  1982. $title = GetQuizName($hpresults[$i][0],'');
  1983. if ($title == '')
  1984. $title = basename($hpresults[$i][0]);
  1985. $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
  1986. ?>
  1987. <tr>
  1988. <td class="content"><?php echo $title; ?></td>
  1989. <td class="content" align="center"><?php echo $display_date; ?></td>
  1990. <td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?></td>
  1991. </tr>
  1992. <?php }
  1993. } else {
  1994. $NoHPTestRes = 1;
  1995. }
  1996. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  1997. echo "<tr>\n";
  1998. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>\n";
  1999. echo "</tr>\n";
  2000. }
  2001. echo "</table>";
  2002. echo "</td>\n</tr>\n";
  2003. } else {
  2004. $new_view = substr_replace($view,'1',1,1);
  2005. echo "
  2006. <tr>
  2007. <td valign='top'>
  2008. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".get_lang('ExercicesResults')."</a>
  2009. </td>
  2010. </tr>";
  2011. }
  2012. }
  2013. /**
  2014. * Displays the student publications for a specific user in a specific course.
  2015. * @todo remove globals
  2016. */
  2017. function display_student_publications_tracking_info($view, $user_id, $course_id)
  2018. {
  2019. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong, $_course;
  2020. if(substr($view,2,1) == '1') {
  2021. $new_view = substr_replace($view,'0',2,1);
  2022. echo "<tr>
  2023. <td valign='top'>
  2024. <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>]
  2025. </td>
  2026. </tr>";
  2027. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('WorksDetails')."<br>";
  2028. $sql = "SELECT u.upload_date, w.title, w.author,w.url
  2029. FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
  2030. WHERE u.upload_work_id = w.id
  2031. AND u.upload_user_id = '".Database::escape_string($user_id)."'
  2032. AND u.upload_cours_id = '".Database::escape_string($course_id)."'
  2033. ORDER BY u.upload_date DESC";
  2034. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  2035. $results = getManyResultsXCol($sql,4);
  2036. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  2037. echo "<tr>
  2038. <td class='secLine' width='40%'>
  2039. ".get_lang('WorkTitle')."
  2040. </td>
  2041. <td class='secLine' width='30%'>
  2042. ".get_lang('WorkAuthors')."
  2043. </td>
  2044. <td class='secLine' width='30%'>
  2045. ".get_lang('Date')."
  2046. </td>
  2047. </tr>";
  2048. if (is_array($results)) {
  2049. for($j = 0 ; $j < count($results) ; $j++) {
  2050. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  2051. $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
  2052. echo "<tr>";
  2053. echo "<td class='content'>"
  2054. ."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
  2055. ."</td>";
  2056. echo "<td class='content'>".$results[$j][2]."</td>";
  2057. echo "<td class='content'>".$beautifulDate."</td>";
  2058. echo"</tr>";
  2059. }
  2060. } else {
  2061. echo "<tr>";
  2062. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
  2063. echo"</tr>";
  2064. }
  2065. echo "</table>";
  2066. echo "</td></tr>";
  2067. } else {
  2068. $new_view = substr_replace($view,'1',2,1);
  2069. echo "
  2070. <tr>
  2071. <td valign='top'>
  2072. +<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>
  2073. </td>
  2074. </tr>
  2075. ";
  2076. }
  2077. }
  2078. /**
  2079. * Displays the links followed for a specific user in a specific course.
  2080. * @todo remove globals
  2081. */
  2082. function display_links_tracking_info($view, $user_id, $course_id)
  2083. {
  2084. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  2085. if(substr($view,3,1) == '1') {
  2086. $new_view = substr_replace($view,'0',3,1);
  2087. echo "
  2088. <tr>
  2089. <td valign='top'>
  2090. <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>]
  2091. </td>
  2092. </tr>
  2093. ";
  2094. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('LinksDetails')."<br>";
  2095. $sql = "SELECT cl.title, cl.url
  2096. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  2097. WHERE sl.links_link_id = cl.id
  2098. AND sl.links_cours_id = '".Database::escape_string($course_id)."'
  2099. AND sl.links_user_id = '".Database::escape_string($user_id)."'
  2100. GROUP BY cl.title, cl.url";
  2101. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  2102. $results = getManyResults2Col($sql);
  2103. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  2104. echo "<tr>
  2105. <td class='secLine'>
  2106. ".get_lang('LinksTitleLinkColumn')."
  2107. </td>
  2108. </tr>";
  2109. if (is_array($results)) {
  2110. for($j = 0 ; $j < count($results) ; $j++) {
  2111. echo "<tr>";
  2112. echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
  2113. echo"</tr>";
  2114. }
  2115. } else {
  2116. echo "<tr>";
  2117. echo "<td ><center>".get_lang('NoResult')."</center></td>";
  2118. echo"</tr>";
  2119. }
  2120. echo "</table>";
  2121. echo "</td></tr>";
  2122. } else {
  2123. $new_view = substr_replace($view,'1',3,1);
  2124. echo "
  2125. <tr>
  2126. <td valign='top'>
  2127. +<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>
  2128. </td>
  2129. </tr>
  2130. ";
  2131. }
  2132. }
  2133. /**
  2134. * Displays the documents downloaded for a specific user in a specific course.
  2135. * @param string kind of view inside tracking info
  2136. * @param int User id
  2137. * @param string Course code
  2138. * @param int Session id (optional, default = 0)
  2139. * @return void
  2140. */
  2141. function display_document_tracking_info($view, $user_id, $course_id, $session_id = 0)
  2142. {
  2143. // protect data
  2144. $user_id = intval($user_id);
  2145. $course_id = Database::escape_string($course_id);
  2146. $session_id = intval($session_id);
  2147. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  2148. if(substr($view,4,1) == '1')
  2149. {
  2150. $new_view = substr_replace($view,'0',4,1);
  2151. echo "
  2152. <tr>
  2153. <td valign='top'>
  2154. <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>]
  2155. </td>
  2156. </tr>
  2157. ";
  2158. echo "<tr><td style='padding-left : 40px;' valign='top'>".get_lang('DocumentsDetails')."<br>";
  2159. $sql = "SELECT down_doc_path
  2160. FROM $downloads_table
  2161. WHERE down_cours_id = '".$course_id."'
  2162. AND down_user_id = '$user_id'
  2163. AND down_session_id = '$session_id'
  2164. GROUP BY down_doc_path";
  2165. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  2166. $results = getManyResults1Col($sql);
  2167. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
  2168. echo "<tr>
  2169. <td class='secLine'>
  2170. ".get_lang('DocumentsTitleDocumentColumn')."
  2171. </td>
  2172. </tr>";
  2173. if (is_array($results)) {
  2174. for($j = 0 ; $j < count($results) ; $j++) {
  2175. echo "<tr>";
  2176. echo "<td class='content'>".$results[$j]."</td>";
  2177. echo"</tr>";
  2178. }
  2179. } else {
  2180. echo "<tr>";
  2181. echo "<td><center>".get_lang('NoResult')."</center></td>";
  2182. echo"</tr>";
  2183. }
  2184. echo "</table>";
  2185. echo "</td></tr>";
  2186. } else {
  2187. $new_view = substr_replace($view,'1',4,1);
  2188. echo "
  2189. <tr>
  2190. <td valign='top'>
  2191. +<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>
  2192. </td>
  2193. </tr>
  2194. ";
  2195. }
  2196. }
  2197. }
  2198. class TrackingUserLogCSV {
  2199. /**
  2200. * Displays the number of logins every month for a specific user in a specific course.
  2201. */
  2202. function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
  2203. {
  2204. $MonthsLong = $GLOBALS['MonthsLong'];
  2205. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  2206. // protected data
  2207. $user_id = intval($user_id);
  2208. $session_id = intval($session_id);
  2209. $course_id = Database::escape_string($course_id);
  2210. $tempView = $view;
  2211. if(substr($view,0,1) == '1')
  2212. {
  2213. $new_view = substr_replace($view,'0',0,1);
  2214. $title[1]= get_lang('LoginsAndAccessTools').get_lang('LoginsDetails');
  2215. $sql = "SELECT UNIX_TIMESTAMP(`access_date`), count(`access_date`)
  2216. FROM $track_access_table
  2217. WHERE access_user_id = '$user_id'
  2218. AND access_cours_code = '".$course_id."'
  2219. AND access_session_id = '$session_id'
  2220. GROUP BY YEAR(`access_date`),MONTH(`access_date`)
  2221. ORDER BY YEAR(`access_date`),MONTH(`access_date`) ASC";
  2222. //$results = getManyResults2Col($sql);
  2223. $results = getManyResults3Col($sql);
  2224. $title_line= get_lang('LoginsTitleMonthColumn').';'.get_lang('LoginsTitleCountColumn')."\n";
  2225. $line='';
  2226. $total = 0;
  2227. if (is_array($results))
  2228. {
  2229. for($j = 0 ; $j < count($results) ; $j++)
  2230. {
  2231. $line .= $results[$j][0].';'.$results[$j][1]."\n";
  2232. $total = $total + $results[$j][1];
  2233. }
  2234. $line .= get_lang('Total').";".$total."\n";
  2235. }
  2236. else
  2237. {
  2238. $line= get_lang('NoResult')."</center></td>";
  2239. }
  2240. }
  2241. else
  2242. {
  2243. $new_view = substr_replace($view,'1',0,1);
  2244. }
  2245. return array($title_line, $line);
  2246. }
  2247. /**
  2248. * Displays the exercise results for a specific user in a specific course.
  2249. * @todo remove globals
  2250. */
  2251. function display_exercise_tracking_info($view, $user_id, $course_id)
  2252. {
  2253. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong;
  2254. if(substr($view,1,1) == '1')
  2255. {
  2256. $new_view = substr_replace($view,'0',1,1);
  2257. $title[1]= get_lang('ExercicesDetails');
  2258. $line='';
  2259. $sql = "SELECT `ce`.`title`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  2260. FROM $TABLECOURSE_EXERCICES AS ce , `$TABLETRACK_EXERCICES` AS `te`
  2261. WHERE `te`.`exe_cours_id` = '$course_id'
  2262. AND `te`.`exe_user_id` = '$user_id'
  2263. AND `te`.`exe_exo_id` = `ce`.`id`
  2264. ORDER BY `ce`.`title` ASC, `te`.`exe_date` ASC";
  2265. $hpsql = "SELECT `te`.`exe_name`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  2266. FROM `$TABLETRACK_HOTPOTATOES` AS te
  2267. WHERE `te`.`exe_user_id` = '$user_id' AND `te`.`exe_cours_id` = '$course_id'
  2268. ORDER BY `te`.`exe_cours_id` ASC, `te`.`exe_date` ASC";
  2269. $hpresults = getManyResultsXCol($hpsql, 4);
  2270. $NoTestRes = 0;
  2271. $NoHPTestRes = 0;
  2272. $results = getManyResultsXCol($sql, 4);
  2273. $title_line=get_lang('ExercicesTitleExerciceColumn').";".get_lang('Date').';'.get_lang('ExercicesTitleScoreColumn')."\n";
  2274. if (is_array($results))
  2275. {
  2276. for($i = 0; $i < sizeof($results); $i++)
  2277. {
  2278. $display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
  2279. $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
  2280. }
  2281. }
  2282. else // istvan begin
  2283. {
  2284. $NoTestRes = 1;
  2285. }
  2286. // The Result of Tests
  2287. if(is_array($hpresults))
  2288. {
  2289. for($i = 0; $i < sizeof($hpresults); $i++)
  2290. {
  2291. $title = GetQuizName($hpresults[$i][0],'');
  2292. if ($title == '')
  2293. $title = basename($hpresults[$i][0]);
  2294. $display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
  2295. $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
  2296. }
  2297. }
  2298. else
  2299. {
  2300. $NoHPTestRes = 1;
  2301. }
  2302. if ($NoTestRes == 1 && $NoHPTestRes == 1)
  2303. {
  2304. $line=get_lang('NoResult');
  2305. }
  2306. }
  2307. else
  2308. {
  2309. $new_view = substr_replace($view,'1',1,1);
  2310. }
  2311. return array($title_line, $line);
  2312. }
  2313. /**
  2314. * Displays the student publications for a specific user in a specific course.
  2315. * @todo remove globals
  2316. */
  2317. function display_student_publications_tracking_info($view, $user_id, $course_id)
  2318. {
  2319. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong;
  2320. if(substr($view,2,1) == '1')
  2321. {
  2322. $new_view = substr_replace($view,'0',2,1);
  2323. $sql = "SELECT `u`.`upload_date`, `w`.`title`, `w`.`author`,`w`.`url`
  2324. FROM `$TABLETRACK_UPLOADS` `u` , $TABLECOURSE_WORK `w`
  2325. WHERE `u`.`upload_work_id` = `w`.`id`
  2326. AND `u`.`upload_user_id` = '$user_id'
  2327. AND `u`.`upload_cours_id` = '$course_id'
  2328. ORDER BY `u`.`upload_date` DESC";
  2329. $results = getManyResultsXCol($sql,4);
  2330. $title[1]=get_lang('WorksDetails');
  2331. $line='';
  2332. $title_line=get_lang('WorkTitle').";".get_lang('WorkAuthors').";".get_lang('Date')."\n";
  2333. if (is_array($results))
  2334. {
  2335. for($j = 0 ; $j < count($results) ; $j++)
  2336. {
  2337. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  2338. $beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
  2339. $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
  2340. }
  2341. }
  2342. else
  2343. {
  2344. $line= get_lang('NoResult');
  2345. }
  2346. }
  2347. else
  2348. {
  2349. $new_view = substr_replace($view,'1',2,1);
  2350. }
  2351. return array($title_line, $line);
  2352. }
  2353. /**
  2354. * Displays the links followed for a specific user in a specific course.
  2355. * @todo remove globals
  2356. */
  2357. function display_links_tracking_info($view, $user_id, $course_id)
  2358. {
  2359. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  2360. if(substr($view,3,1) == '1')
  2361. {
  2362. $new_view = substr_replace($view,'0',3,1);
  2363. $title[1]=get_lang('LinksDetails');
  2364. $sql = "SELECT `cl`.`title`, `cl`.`url`
  2365. FROM `$TABLETRACK_LINKS` AS sl, $TABLECOURSE_LINKS AS cl
  2366. WHERE `sl`.`links_link_id` = `cl`.`id`
  2367. AND `sl`.`links_cours_id` = '$course_id'
  2368. AND `sl`.`links_user_id` = '$user_id'
  2369. GROUP BY `cl`.`title`, `cl`.`url`";
  2370. $results = getManyResults2Col($sql);
  2371. $title_line= get_lang('LinksTitleLinkColumn')."\n";
  2372. if (is_array($results))
  2373. {
  2374. for($j = 0 ; $j < count($results) ; $j++)
  2375. {
  2376. $line .= $results[$j][0]."\n";
  2377. }
  2378. }
  2379. else
  2380. {
  2381. $line=get_lang('NoResult');
  2382. }
  2383. }
  2384. else
  2385. {
  2386. $new_view = substr_replace($view,'1',3,1);
  2387. }
  2388. return array($title_line, $line);
  2389. }
  2390. /**
  2391. * Displays the documents downloaded for a specific user in a specific course.
  2392. * @param string kind of view inside tracking info
  2393. * @param int User id
  2394. * @param string Course code
  2395. * @param int Session id (optional, default = 0)
  2396. * @return void
  2397. */
  2398. function display_document_tracking_info($view, $user_id, $course_id, $session_id = 0)
  2399. {
  2400. // protect data
  2401. $user_id = intval($user_id);
  2402. $course_id = Database::escape_string($course_id);
  2403. $session_id = intval($session_id);
  2404. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  2405. if (substr($view,4,1) == '1') {
  2406. $new_view = substr_replace($view,'0',4,1);
  2407. $title[1]= get_lang('DocumentsDetails');
  2408. $sql = "SELECT down_doc_path
  2409. FROM $downloads_table
  2410. WHERE down_cours_id = '$course_id'
  2411. AND down_user_id = '$user_id'
  2412. AND down_session_id = '$session_id'
  2413. GROUP BY down_doc_path";
  2414. $results = getManyResults1Col($sql);
  2415. $title_line = get_lang('DocumentsTitleDocumentColumn')."\n";
  2416. if (is_array($results)) {
  2417. for($j = 0 ; $j < count($results) ; $j++) {
  2418. $line .= $results[$j]."\n";
  2419. }
  2420. } else {
  2421. $line=get_lang('NoResult');
  2422. }
  2423. } else {
  2424. $new_view = substr_replace($view,'1',4,1);
  2425. }
  2426. return array($title_line, $line);
  2427. }
  2428. }
  2429. ?>