userLog.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. <?php // $Id: userLog.php 9718 2006-10-25 08:16:19Z bmol $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
  9. Copyright (c) Sebastien Piraux <piraux_seb@hotmail.com>
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @package dokeos.tracking
  23. * @todo clean code - structure is unclear and difficult to modify
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. $uInfo = $_REQUEST['uInfo'];
  32. $view = $_REQUEST['view'];
  33. $langFile = 'tracking';
  34. include('../inc/global.inc.php');
  35. // Roles and rights system
  36. $user_id = api_get_user_id();
  37. $course_id = api_get_course_id();
  38. /*
  39. $role_id = RolesRights::get_local_user_role_id($user_id, $course_id);
  40. $location_id = RolesRights::get_course_tool_location_id($course_id, TOOL_TRACKING);
  41. $is_allowed = RolesRights::is_allowed_which_rights($role_id, $location_id);
  42. //block users without view right
  43. RolesRights::protect_location($role_id, $location_id);
  44. */
  45. //YW Hack security to quick fix RolesRights bug
  46. $is_allowed = true;
  47. /*
  48. -----------------------------------------------------------
  49. Libraries
  50. -----------------------------------------------------------
  51. */
  52. include(api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php');
  53. include(api_get_path(LIBRARY_PATH).'course.lib.php');
  54. include(api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php');
  55. require_once(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');
  56. /*
  57. -----------------------------------------------------------
  58. Header
  59. -----------------------------------------------------------
  60. */
  61. // charset determination
  62. if ($_GET['scormcontopen'])
  63. {
  64. $tbl_lp = Database::get_course_table('lp');
  65. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$_GET['scormcontopen'];
  66. $res = api_sql_query($sql,__FILE__,__LINE__);
  67. $row = Database::fetch_array($res);
  68. $lp_charset = $row['default_encoding'];
  69. //header('Content-Type: text/html; charset='. $row['default_encoding']);
  70. }
  71. /*
  72. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  73. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  74. */
  75. if($uInfo)
  76. {
  77. $interbreadcrumb[]= array ("url"=>"../user/userInfo.php?uInfo=$uInfo", "name"=> get_lang('BredCrumpUsers'));
  78. }
  79. $nameTools = get_lang('ToolName');
  80. $htmlHeadXtra[] = "<style type='text/css'>
  81. /*<![CDATA[*/
  82. .secLine {background-color : #E6E6E6;}
  83. .content {padding-left : 15px;padding-right : 15px; }
  84. .specialLink{color : #0000FF;}
  85. /*]]>*/
  86. </style>
  87. <style media='print' type='text/css'>
  88. /*<![CDATA[*/
  89. td {border-bottom: thin dashed gray;}
  90. /*]]>*/
  91. </style>";
  92. Display::display_header($nameTools,"Tracking");
  93. /*
  94. -----------------------------------------------------------
  95. Constants and variables
  96. -----------------------------------------------------------
  97. */
  98. //$is_allowed_to_track = $is_allowed[EDIT_RIGHT] && $is_trackingEnabled;
  99. //YW hack security to quick fix RolesRights bug
  100. $is_allowedToTrack = $is_courseAdmin;
  101. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  102. // regroup table names for maintenance purpose
  103. $TABLECOURSUSER = Database::get_main_table(MAIN_COURSE_USER_TABLE);
  104. $TABLEUSER = Database::get_main_table(MAIN_USER_TABLE);
  105. $tbl_session_course_user = Database::get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  106. $tbl_session = Database::get_main_table(MAIN_SESSION_TABLE);
  107. $TABLETRACK_ACCESS = $statsDbName."`.`track_e_access";
  108. $TABLETRACK_LINKS = $statsDbName."`.`track_e_links";
  109. $TABLETRACK_LOGIN = $statsDbName."`.`track_e_login";
  110. $TABLETRACK_DOWNLOADS = $statsDbName."`.`track_e_downloads";
  111. $TABLETRACK_UPLOADS = $statsDbName."`.`track_e_uploads";
  112. $TABLETRACK_EXERCICES = $statsDbName."`.`track_e_exercices";
  113. $TABLECOURSE_LINKS = Database::get_course_table(LINK_TABLE);
  114. $TABLECOURSE_WORK = Database::get_course_table(STUDENT_PUBLICATION_TABLE);
  115. $TABLECOURSE_GROUPSUSER = Database::get_course_table(GROUP_USER_TABLE);
  116. $TABLECOURSE_EXERCICES = Database::get_course_table(QUIZ_TEST_TABLE);
  117. $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(STATISTIC_TRACK_E_HOTPOTATOES_TABLE);
  118. /*
  119. $tbl_learnpath_main = Database::get_course_table(LEARNPATH_MAIN_TABLE);
  120. $tbl_learnpath_item = Database::get_course_table(LEARNPATH_ITEM_TABLE);
  121. $tbl_learnpath_chapter = Database::get_course_table(LEARNPATH_CHAPTER_TABLE);
  122. $tbl_learnpath_user = Database::get_course_table(LEARNPATH_USER_TABLE);
  123. */
  124. if(api_get_setting('use_session_mode') == "true") {
  125. $sql = "SELECT 1
  126. FROM $tbl_session_course_user AS session_course_user
  127. INNER JOIN $tbl_session AS session
  128. ON session_course_user.id_session = session.id
  129. AND ((date_start<=NOW()
  130. AND date_end>=NOW())
  131. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  132. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  133. //echo $sql;
  134. $result=api_sql_query($sql,__FILE__,__LINE__);
  135. if(!mysql_num_rows($result)){
  136. $disabled = true;
  137. }
  138. }
  139. $tbl_learnpath_main = Database::get_course_table('lp');
  140. $tbl_learnpath_item = Database::get_course_table('lp_item');
  141. $tbl_learnpath_view = Database::get_course_table('lp_view');
  142. $tbl_learnpath_item_view = Database::get_course_table('lp_item_view');
  143. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  144. // the variables for the days and the months
  145. // Defining the shorts for the days
  146. $DaysShort = array (myEnc(get_lang("SundayShort")), myEnc(get_lang("MondayShort")), myEnc(get_lang("TuesdayShort")), myEnc(get_lang("WednesdayShort")), myEnc(get_lang("ThursdayShort")), myEnc(get_lang("FridayShort")), myEnc(get_lang("SaturdayShort")));
  147. // Defining the days of the week to allow translation of the days
  148. $DaysLong = array (myEnc(get_lang("SundayLong")), myEnc(get_lang("MondayLong")), myEnc(get_lang("TuesdayLong")), myEnc(get_lang("WednesdayLong")), myEnc(get_lang("ThursdayLong")), myEnc(get_lang("FridayLong")), myEnc(get_lang("SaturdayLong")));
  149. // Defining the months of the year to allow translation of the months
  150. $MonthsLong = array (myEnc(get_lang("JanuaryLong")), myEnc(get_lang("FebruaryLong")), myEnc(get_lang("MarchLong")), myEnc(get_lang("AprilLong")), myEnc(get_lang("MayLong")), myEnc(get_lang("JuneLong")), myEnc(get_lang("JulyLong")), myEnc(get_lang("AugustLong")), myEnc(get_lang("SeptemberLong")), myEnc(get_lang("OctoberLong")), myEnc(get_lang("NovemberLong")), myEnc(get_lang("DecemberLong")));
  151. // Defining the months of the year to allow translation of the months
  152. $MonthsShort = array (myEnc(get_lang("JanuaryShort")), myEnc(get_lang("FebruaryShort")), myEnc(get_lang("MarchShort")), myEnc(get_lang("AprilShort")), myEnc(get_lang("MayShort")), myEnc(get_lang("JuneShort")), myEnc(get_lang("JulyShort")), myEnc(get_lang("AugustShort")), myEnc(get_lang("SeptemberShort")), myEnc(get_lang("OctoberShort")), myEnc(get_lang("NovemberShort")), myEnc(get_lang("DecemberShort")));
  153. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  154. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  155. //YW hack security to fix RolesRights bug
  156. $is_allowedToTrack = true; // allowed to track only user of one group
  157. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  158. /*
  159. ==============================================================================
  160. FUNCTIONS
  161. ==============================================================================
  162. */
  163. /**
  164. * Shortcut function to use htmlentities on many, many strings in this script
  165. * @param string String in a supposed encoding
  166. * @param string Supposed initial encoding (default: 'ISO-8859-15')
  167. * @return string HTML string (no encoding dependency)
  168. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  169. */
  170. function myEnc($isostring,$supposed_encoding='ISO-8859-15')
  171. {
  172. return htmlentities($isostring,ENT_QUOTES,$supposed_encoding);
  173. }
  174. /**
  175. * Displays the number of logins every month for a specific user in a specific course.
  176. */
  177. function display_login_tracking_info($view, $user_id, $course_id)
  178. {
  179. $MonthsLong = $GLOBALS['MonthsLong'];
  180. $track_access_table = Database::get_statistic_table(STATISTIC_TRACK_E_ACCESS_TABLE);
  181. $tempView = $view;
  182. if(substr($view,0,1) == '1')
  183. {
  184. $new_view = substr_replace($view,'0',0,1);
  185. echo "
  186. <tr>
  187. <td valign='top'>
  188. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('LoginsAndAccessTools'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."'>".myEnc(get_lang('Close'))."</a>]
  189. </td>
  190. </tr>
  191. ";
  192. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('LoginsDetails'))."<br>";
  193. $sql = "SELECT UNIX_TIMESTAMP(`access_date`), count(`access_date`)
  194. FROM $track_access_table
  195. WHERE `access_user_id` = '$user_id'
  196. AND `access_cours_code` = '".$course_id."'
  197. GROUP BY YEAR(`access_date`),MONTH(`access_date`)
  198. ORDER BY YEAR(`access_date`),MONTH(`access_date`) ASC";
  199. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  200. //$results = getManyResults2Col($sql);
  201. $results = getManyResults3Col($sql);
  202. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  203. echo "<tr>
  204. <td class='secLine'>
  205. ".myEnc(get_lang('LoginsTitleMonthColumn'))."
  206. </td>
  207. <td class='secLine'>
  208. ".myEnc(get_lang('LoginsTitleCountColumn'))."
  209. </td>
  210. </tr>";
  211. $total = 0;
  212. if (is_array($results))
  213. {
  214. for($j = 0 ; $j < count($results) ; $j++)
  215. {
  216. echo "<tr>";
  217. //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>";
  218. echo "<td class='content'><a href='logins_details.php?uInfo=$user_id&reqdate=".$results[$j][0]."&view=$view'>".$MonthsLong[date('n', $results[$j][0])-1].' '.date('Y', $results[$j][0])."</a></td>";
  219. echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
  220. echo"</tr>";
  221. $total = $total + $results[$j][1];
  222. }
  223. echo "<tr>";
  224. echo "<td>".myEnc(get_lang('Total'))."</td>";
  225. echo "<td align='right' class='content'>".$total."</td>";
  226. echo"</tr>";
  227. }
  228. else
  229. {
  230. echo "<tr>";
  231. echo "<td colspan='2'><center>".myEnc(get_lang('NoResult'))."</center></td>";
  232. echo"</tr>";
  233. }
  234. echo "</table>";
  235. echo "</td></tr>";
  236. }
  237. else
  238. {
  239. $new_view = substr_replace($view,'1',0,1);
  240. echo "
  241. <tr>
  242. <td valign='top'>
  243. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".myEnc(get_lang('LoginsAndAccessTools'))."</a>
  244. </td>
  245. </tr>
  246. ";
  247. }
  248. }
  249. /**
  250. * Displays the exercise results for a specific user in a specific course.
  251. * @todo remove globals
  252. */
  253. function display_exercise_tracking_info($view, $user_id, $course_id)
  254. {
  255. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES;
  256. if(substr($view,1,1) == '1')
  257. {
  258. $new_view = substr_replace($view,'0',1,1);
  259. echo "
  260. <tr>
  261. <td valign='top'>
  262. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('ExercicesResults'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."'>".myEnc(get_lang('Close'))."</a>]
  263. </td>
  264. </tr>
  265. ";
  266. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('ExercicesDetails'))."<br />";
  267. $sql = "SELECT `ce`.`title`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  268. FROM $TABLECOURSE_EXERCICES AS ce , `$TABLETRACK_EXERCICES` AS te
  269. WHERE `te`.`exe_cours_id` = '$course_id'
  270. AND `te`.`exe_user_id` = '$user_id'
  271. AND `te`.`exe_exo_id` = `ce`.`id`
  272. ORDER BY `ce`.`title` ASC, `te`.`exe_date` ASC";
  273. $hpsql = "SELECT `te`.`exe_name`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  274. FROM $TBL_TRACK_HOTPOTATOES AS te
  275. WHERE `te`.`exe_user_id` = '$user_id' AND `te`.`exe_cours_id` = '$course_id'
  276. ORDER BY `te`.`exe_cours_id` ASC, `te`.`exe_date` ASC";
  277. $hpresults = getManyResultsXCol($hpsql, 4);
  278. $NoTestRes = 0;
  279. $NoHPTestRes = 0;
  280. echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
  281. $results = getManyResultsXCol($sql, 4);
  282. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
  283. echo "
  284. <tr bgcolor='#E6E6E6'>
  285. <td>
  286. ".myEnc(get_lang('ExercicesTitleExerciceColumn'))."
  287. </td>
  288. <td>
  289. ".myEnc(get_lang('Date'))."
  290. </td>
  291. <td>
  292. ".myEnc(get_lang('ExercicesTitleScoreColumn'))."
  293. </td>
  294. </tr>";
  295. if (is_array($results))
  296. {
  297. for($i = 0; $i < sizeof($results); $i++)
  298. {
  299. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]);
  300. echo "<tr>\n";
  301. echo "<td class='content'>".$results[$i][0]."</td>\n";
  302. echo "<td class='content'>".$display_date."</td>\n";
  303. echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
  304. echo "</tr>\n";
  305. }
  306. }
  307. else // istvan begin
  308. {
  309. $NoTestRes = 1;
  310. }
  311. // The Result of Tests
  312. if(is_array($hpresults))
  313. {
  314. for($i = 0; $i < sizeof($hpresults); $i++)
  315. {
  316. $title = GetQuizName($hpresults[$i][0], $documentPath);
  317. if ($title == '')
  318. $title = GetFileName($hpresults[$i][0]);
  319. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]);
  320. ?>
  321. <tr>
  322. <td class="content"><?php echo $title; ?></td>
  323. <td class="content" align="center"><?php echo $display_date; ?></td>
  324. <td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?></td>
  325. </tr>
  326. <?php }
  327. }
  328. else
  329. {
  330. $NoHPTestRes = 1;
  331. }
  332. if ($NoTestRes == 1 && $NoHPTestRes == 1)
  333. {
  334. echo "<tr>\n";
  335. echo "<td colspan='3'><center>".myEnc(get_lang('NoResult'))."</center></td>\n";
  336. echo "</tr>\n";
  337. }
  338. echo "</table>";
  339. echo "</td>\n</tr>\n";
  340. }
  341. else
  342. {
  343. $new_view = substr_replace($view,'1',1,1);
  344. echo "
  345. <tr>
  346. <td valign='top'>
  347. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".myEnc(get_lang('ExercicesResults'))."</a>
  348. </td>
  349. </tr>
  350. ";
  351. }
  352. }
  353. /**
  354. * Displays the student publications for a specific user in a specific course.
  355. * @todo remove globals
  356. */
  357. function display_student_publications_tracking_info($view, $user_id, $course_id)
  358. {
  359. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong;
  360. if(substr($view,2,1) == '1')
  361. {
  362. $new_view = substr_replace($view,'0',2,1);
  363. echo "
  364. <tr>
  365. <td valign='top'>
  366. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('WorkUploads'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."'>".myEnc(get_lang('Close'))."</a>]
  367. </td>
  368. </tr>
  369. ";
  370. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('WorksDetails'))."<br>";
  371. $sql = "SELECT `u`.`upload_date`, `w`.`title`, `w`.`author`,`w`.`url`
  372. FROM `$TABLETRACK_UPLOADS` `u` , $TABLECOURSE_WORK `w`
  373. WHERE `u`.`upload_work_id` = `w`.`id`
  374. AND `u`.`upload_user_id` = '$user_id'
  375. AND `u`.`upload_cours_id` = '$course_id'
  376. ORDER BY `u`.`upload_date` DESC";
  377. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  378. $results = getManyResultsXCol($sql,4);
  379. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  380. echo "<tr>
  381. <td class='secLine' width='40%'>
  382. ".myEnc(get_lang('WorkTitle'))."
  383. </td>
  384. <td class='secLine' width='30%'>
  385. ".myEnc(get_lang('WorkAuthors'))."
  386. </td>
  387. <td class='secLine' width='30%'>
  388. ".myEnc(get_lang('Date'))."
  389. </td>
  390. </tr>";
  391. if (is_array($results))
  392. {
  393. for($j = 0 ; $j < count($results) ; $j++)
  394. {
  395. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  396. $timestamp = strtotime($results[$j][0]);
  397. $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp);
  398. echo "<tr>";
  399. echo "<td class='content'>"
  400. ."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
  401. ."</td>";
  402. echo "<td class='content'>".$results[$j][2]."</td>";
  403. echo "<td class='content'>".$beautifulDate."</td>";
  404. echo"</tr>";
  405. }
  406. }
  407. else
  408. {
  409. echo "<tr>";
  410. echo "<td colspan='3'><center>".myEnc(get_lang('NoResult'))."</center></td>";
  411. echo"</tr>";
  412. }
  413. echo "</table>";
  414. echo "</td></tr>";
  415. }
  416. else
  417. {
  418. $new_view = substr_replace($view,'1',2,1);
  419. echo "
  420. <tr>
  421. <td valign='top'>
  422. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".myEnc(get_lang('WorkUploads'))."</a>
  423. </td>
  424. </tr>
  425. ";
  426. }
  427. }
  428. /**
  429. * Displays the links followed for a specific user in a specific course.
  430. * @todo remove globals
  431. */
  432. function display_links_tracking_info($view, $user_id, $course_id)
  433. {
  434. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  435. if(substr($view,3,1) == '1')
  436. {
  437. $new_view = substr_replace($view,'0',3,1);
  438. echo "
  439. <tr>
  440. <td valign='top'>
  441. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('LinksAccess'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."'>".myEnc(get_lang('Close'))."</a>]
  442. </td>
  443. </tr>
  444. ";
  445. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('LinksDetails'))."<br>";
  446. $sql = "SELECT `cl`.`title`, `cl`.`url`
  447. FROM `$TABLETRACK_LINKS` AS sl, $TABLECOURSE_LINKS AS cl
  448. WHERE `sl`.`links_link_id` = `cl`.`id`
  449. AND `sl`.`links_cours_id` = '$course_id'
  450. AND `sl`.`links_user_id` = '$user_id'
  451. GROUP BY `cl`.`title`, `cl`.`url`";
  452. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  453. $results = getManyResults2Col($sql);
  454. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  455. echo "<tr>
  456. <td class='secLine'>
  457. ".myEnc(get_lang('LinksTitleLinkColumn'))."
  458. </td>
  459. </tr>";
  460. if (is_array($results))
  461. {
  462. for($j = 0 ; $j < count($results) ; $j++)
  463. {
  464. echo "<tr>";
  465. echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
  466. echo"</tr>";
  467. }
  468. }
  469. else
  470. {
  471. echo "<tr>";
  472. echo "<td ><center>".myEnc(get_lang('NoResult'))."</center></td>";
  473. echo"</tr>";
  474. }
  475. echo "</table>";
  476. echo "</td></tr>";
  477. }
  478. else
  479. {
  480. $new_view = substr_replace($view,'1',3,1);
  481. echo "
  482. <tr>
  483. <td valign='top'>
  484. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".myEnc(get_lang('LinksAccess'))."</a>
  485. </td>
  486. </tr>
  487. ";
  488. }
  489. }
  490. /**
  491. * Displays the documents downloaded for a specific user in a specific course.
  492. */
  493. function display_document_tracking_info($view, $user_id, $course_id)
  494. {
  495. $downloads_table = Database::get_statistic_table(STATISTIC_TRACK_E_DOWNLOADS_TABLE);
  496. if(substr($view,4,1) == '1')
  497. {
  498. $new_view = substr_replace($view,'0',4,1);
  499. echo "
  500. <tr>
  501. <td valign='top'>
  502. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('DocumentsAccess'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."'>".myEnc(get_lang('Close'))."</a>]
  503. </td>
  504. </tr>
  505. ";
  506. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('DocumentsDetails'))."<br>";
  507. $sql = "SELECT `down_doc_path`
  508. FROM $downloads_table
  509. WHERE `down_cours_id` = '$course_id'
  510. AND `down_user_id` = '$user_id'
  511. GROUP BY `down_doc_path`";
  512. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  513. $results = getManyResults1Col($sql);
  514. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
  515. echo "<tr>
  516. <td class='secLine'>
  517. ".myEnc(get_lang('DocumentsTitleDocumentColumn'))."
  518. </td>
  519. </tr>";
  520. if (is_array($results))
  521. {
  522. for($j = 0 ; $j < count($results) ; $j++)
  523. {
  524. echo "<tr>";
  525. echo "<td class='content'>".$results[$j]."</td>";
  526. echo"</tr>";
  527. }
  528. }
  529. else
  530. {
  531. echo "<tr>";
  532. echo "<td><center>".myEnc(get_lang('NoResult'))."</center></td>";
  533. echo"</tr>";
  534. }
  535. echo "</table>";
  536. echo "</td></tr>";
  537. }
  538. else
  539. {
  540. $new_view = substr_replace($view,'1',4,1);
  541. echo "
  542. <tr>
  543. <td valign='top'>
  544. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".$_SERVER['PHP_SELF']."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".myEnc(get_lang('DocumentsAccess'))."</a>
  545. </td>
  546. </tr>
  547. ";
  548. }
  549. }
  550. /*
  551. ==============================================================================
  552. MAIN SECTION
  553. ==============================================================================
  554. */
  555. ?>
  556. <h3>
  557. <?php echo $nameTools ?>
  558. </h3>
  559. <h4>
  560. <?php echo myEnc(get_lang('StatsOfUser')); ?>
  561. </h4>
  562. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  563. <?php
  564. // check if uid is tutor of this group
  565. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $is_trackingEnabled )
  566. {
  567. if(!$uInfo && !isset($uInfo) )
  568. {
  569. /***************************************************************************
  570. *
  571. * Display list of user of this group
  572. *
  573. ***************************************************************************/
  574. echo "<h4>".myEnc(get_lang('ListStudents'))."</h4>";
  575. if( $is_allowedToTrackEverybodyInCourse )
  576. {
  577. // if user can track everybody : list user of course
  578. if(api_get_setting('use_session_mode')) {
  579. $sql = "SELECT count(user_id)
  580. FROM $TABLECOURSUSER
  581. WHERE `course_code` = '$_cid'";
  582. }
  583. else {
  584. $sql = "SELECT count(id_user)
  585. FROM $tbl_session_course_user
  586. WHERE `course_code` = '$_cid'";
  587. }
  588. }
  589. else
  590. {
  591. // if user can only track one group : list users of this group
  592. $sql = "SELECT count(user)
  593. FROM $TABLECOURSE_GROUPSUSER
  594. WHERE `group_id` = '$_gid'";
  595. }
  596. $userGroupNb = getOneResult($sql);
  597. $step = 25; // number of student per page
  598. if ($userGroupNb > $step)
  599. {
  600. if(!isset($offset))
  601. {
  602. $offset=0;
  603. }
  604. $next = $offset + $step;
  605. $previous = $offset - $step;
  606. $navLink = "<table width='100%' border='0'>\n"
  607. ."<tr>\n"
  608. ."<td align='left'>";
  609. if ($previous >= 0)
  610. {
  611. $navLink .= "<a href='".$_SERVER['PHP_SELF']."?offset=$previous'>&lt;&lt; ".myEnc(get_lang('PreviousPage'))."</a>";
  612. }
  613. $navLink .= "</td>\n"
  614. ."<td align='right'>";
  615. if ($next < $userGroupNb)
  616. {
  617. $navLink .= "<a href='".$_SERVER['PHP_SELF']."?offset=$next'>".myEnc(get_lang('NextPage'))." &gt;&gt;</a>";
  618. }
  619. $navLink .= "</td>\n"
  620. ."</tr>\n"
  621. ."</table>\n";
  622. }
  623. else
  624. {
  625. $offset = 0;
  626. }
  627. echo $navLink;
  628. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  629. if( $is_allowedToTrackEverybodyInCourse )
  630. {
  631. // list of users in this course
  632. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  633. FROM $TABLECOURSUSER cu , $TABLEUSER u
  634. WHERE `cu`.`user_id` = `u`.`user_id`
  635. AND `cu`.`course_code` = '$_cid'
  636. LIMIT $offset,$step";
  637. }
  638. else
  639. {
  640. // list of users of this group
  641. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  642. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  643. WHERE `gu`.`user_id` = `u`.`user_id`
  644. AND `gu`.`group_id` = '$_gid'
  645. LIMIT $offset,$step";
  646. }
  647. $list_users = getManyResults3Col($sql);
  648. echo "<table width='100%' cellpadding='2' cellspacing='1' border='0'>\n"
  649. ."<tr align='center' valign='top' bgcolor='#E6E6E6'>\n"
  650. ."<td align='left'>",myEnc(get_lang('UserName')),"</td>\n"
  651. ."</tr>\n";
  652. for($i = 0 ; $i < sizeof($list_users) ; $i++)
  653. {
  654. echo "<tr valign='top' align='center'>\n"
  655. ."<td align='left'>"
  656. ."<a href='".$_SERVER['PHP_SELF']."?uInfo=",$list_users[$i][0],"'>"
  657. .$list_users[$i][1]," ",$list_users[$i][2]
  658. ."</a>".
  659. "</td>\n";
  660. }
  661. echo "</table>\n";
  662. echo $navLink;
  663. }
  664. else // if uInfo is set
  665. {
  666. /***************************************************************************
  667. *
  668. * Informations about student uInfo
  669. *
  670. ***************************************************************************/
  671. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  672. // another course, or group
  673. if( $is_allowedToTrackEverybodyInCourse )
  674. {
  675. // check if user is in this course
  676. $tracking_is_accepted = $is_course_member;
  677. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  678. }
  679. else
  680. {
  681. // check if user is in the group of this tutor
  682. $sql = "SELECT `u`.`firstname`,`u`.`lastname`, `u`.`email`
  683. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  684. WHERE `gu`.`user_id` = `u`.`user_id`
  685. AND `gu`.`group_id` = '$_gid'
  686. AND `u`.`user_id` = '$uInfo'";
  687. $query = api_sql_query($sql,__FILE__,__LINE__);
  688. $tracked_user_info = @mysql_fetch_assoc($query);
  689. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  690. }
  691. if ($tracking_is_accepted)
  692. {
  693. $tracked_user_info['email'] == '' ? $mail_link = myEnc(get_lang('NoEmail')) : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  694. echo "<tr><td>";
  695. echo get_lang('informationsAbout').' :';
  696. echo "<ul>\n"
  697. ."<li>".myEnc(get_lang('FirstName'))." : ".$tracked_user_info['firstname']."</li>\n"
  698. ."<li>".myEnc(get_lang('LastName'))." : ".$tracked_user_info['lastname']."</li>\n"
  699. ."<li>".myEnc(get_lang('Email'))." : ".$mail_link."</li>\n"
  700. ."</ul>";
  701. echo "</td></tr>\n";
  702. // show all : number of 1 is equal to or bigger than number of categories
  703. // show none : number of 0 is equal to or bigger than number of categories
  704. echo "<tr>
  705. <td>
  706. [<a href='".$_SERVER['PHP_SELF']."?uInfo=$uInfo&view=1111111'>".myEnc(get_lang('ShowAll'))."</a>]
  707. [<a href='".$_SERVER['PHP_SELF']."?uInfo=$uInfo&view=0000000'>".myEnc(get_lang('ShowNone'))."</a>]".
  708. //"||[<a href='".$_SERVER['PHP_SELF']."'>".myEnc(get_lang('BackToList'))."</a>]".
  709. "</td>
  710. </tr>
  711. ";
  712. if(!isset($view))
  713. {
  714. $view ='0000000';
  715. }
  716. //Logins
  717. display_login_tracking_info($view, $uInfo, $_cid);
  718. //Exercise results
  719. display_exercise_tracking_info($view, $uInfo, $_cid);
  720. //Student publications uploaded
  721. display_student_publications_tracking_info($view, $uInfo, $_cid);
  722. //Links usage
  723. display_links_tracking_info($view, $uInfo, $_cid);
  724. //Documents downloaded
  725. display_document_tracking_info($view, $uInfo, $_cid);
  726. }
  727. else
  728. {
  729. echo myEnc(get_lang('ErrorUserNotInGroup'));
  730. }
  731. /***************************************************************************
  732. *
  733. * Scorm contents and Learning Path
  734. *
  735. ***************************************************************************/
  736. if(substr($view,5,1) == '1')
  737. {
  738. $new_view = substr_replace($view,'0',5,1);
  739. echo "
  740. <tr>
  741. <td valign='top'>
  742. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('ScormAccess'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".$_SERVER['PHP_SELF']."?view=$new_view&uInfo=$uInfo'>".myEnc(get_lang('Close'))."</a>]
  743. </td>
  744. </tr>
  745. ";
  746. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  747. $result=api_sql_query($sql,__FILE__,__LINE__);
  748. $ar=Database::fetch_array($result);
  749. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  750. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'><tr>
  751. <td class='secLine'>
  752. &nbsp;".myEnc(get_lang('ScormContentColumn'))."&nbsp;
  753. </td>
  754. </tr>";
  755. if (is_array($ar))
  756. {
  757. while ($ar['id'] != '') {
  758. $lp_title = stripslashes($ar['name']);
  759. echo "<tr><td>";
  760. echo "<a href='".$_SERVER['PHP_SELF']."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
  761. echo "</td></tr>";
  762. if ($ar['id']==$scormcontopen) { //have to list the students here
  763. $contentId=$ar['id'];
  764. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  765. "FROM $tbl_learnpath_item i " .
  766. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  767. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  768. "WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
  769. $result3=api_sql_query($sql3,__FILE__,__LINE__);
  770. $ar3=Database::fetch_array($result3);
  771. if (is_array($ar3)) {
  772. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td>
  773. <td class='secLine'>
  774. &nbsp;".myEnc(get_lang('ScormTitleColumn'))."&nbsp;
  775. </td>
  776. <td class='secLine'>
  777. &nbsp;".myEnc(get_lang('ScormStatusColumn'))."&nbsp;
  778. </td>
  779. <td class='secLine'>
  780. &nbsp;".myEnc(get_lang('ScormScoreColumn'))."&nbsp;
  781. </td>
  782. <td class='secLine'>
  783. &nbsp;".myEnc(get_lang('ScormTimeColumn'))."&nbsp;
  784. </td>
  785. </tr>";
  786. while ($ar3['status'] != '') {
  787. require_once('../newscorm/learnpathItem.class.php');
  788. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  789. $title = htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  790. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
  791. echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
  792. echo "</tr>";
  793. $ar3=Database::fetch_array($result3);
  794. }
  795. } else {
  796. echo "<tr>";
  797. echo "<td colspan='3'><center>".myEnc(get_lang('ScormNeverOpened'))."</center></td>";
  798. echo"</tr>";
  799. }
  800. }
  801. $ar=Database::fetch_array($result);
  802. }
  803. }
  804. else
  805. {
  806. $noscorm=true;
  807. }
  808. if ($noscorm) {
  809. echo "<tr>";
  810. echo "<td colspan='3'><center>".myEnc(get_lang('NoResult'))."</center></td>";
  811. echo "</tr>";
  812. }
  813. echo "</table>";
  814. echo "</td></tr>";
  815. }
  816. else
  817. {
  818. $new_view = substr_replace($view,'1',5,1);
  819. echo "
  820. <tr>
  821. <td valign='top'>
  822. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".$_SERVER['PHP_SELF']."?view=$new_view&uInfo=$uInfo' class='specialLink'>".myEnc(get_lang('ScormAccess'))."</a>
  823. </td>
  824. </tr>
  825. ";
  826. }
  827. }
  828. }
  829. // not allowed
  830. else
  831. {
  832. if(!$is_trackingEnabled)
  833. {
  834. echo myEnc(get_lang('TrackingDisabled'));
  835. }
  836. else
  837. {
  838. api_not_allowed();
  839. }
  840. }
  841. ?>
  842. </table>
  843. <?php
  844. Display::display_footer();
  845. ?>