tracking.lib.php 82 KB

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