userLog.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. <?php // $Id: userLog.php 20202 2009-04-29 22:31:20Z juliomontoya $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  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. // name of the language file that needs to be included
  34. $language_file = 'tracking';
  35. include('../inc/global.inc.php');
  36. // Roles and rights system
  37. $user_id = api_get_user_id();
  38. $course_id = api_get_course_id();
  39. /*
  40. $role_id = RolesRights::get_local_user_role_id($user_id, $course_id);
  41. $location_id = RolesRights::get_course_tool_location_id($course_id, TOOL_TRACKING);
  42. $is_allowed = RolesRights::is_allowed_which_rights($role_id, $location_id);
  43. //block users without view right
  44. RolesRights::protect_location($role_id, $location_id);
  45. */
  46. //YW Hack security to quick fix RolesRights bug
  47. $is_allowed = true;
  48. /*
  49. -----------------------------------------------------------
  50. Libraries
  51. -----------------------------------------------------------
  52. */
  53. include(api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php');
  54. include(api_get_path(LIBRARY_PATH).'course.lib.php');
  55. include(api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php');
  56. require_once(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');
  57. /*
  58. -----------------------------------------------------------
  59. Header
  60. -----------------------------------------------------------
  61. */
  62. // charset determination
  63. if (isset($_GET['scormcontopen'])) {
  64. $tbl_lp = Database::get_course_table('lp');
  65. $contopen = Database::escape_string($_GET['scormcontopen']);
  66. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$contopen;
  67. $res = api_sql_query($sql,__FILE__,__LINE__);
  68. $row = Database::fetch_array($res);
  69. $lp_charset = $row['default_encoding'];
  70. //header('Content-Type: text/html; charset='. $row['default_encoding']);
  71. }
  72. /*
  73. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  74. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  75. */
  76. if(isset($uInfo)) {
  77. $interbreadcrumb[]= array ('url'=>'../user/userInfo.php?uInfo='.Security::remove_XSS($uInfo), "name"=> ucfirst(get_lang('Users')));
  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_allowedToTrack = $is_courseAdmin;
  99. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  100. // Database Table Definitions
  101. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  102. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  103. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  104. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  105. $TABLETRACK_ACCESS = $_configuration['statistics_database']."`.`track_e_access";
  106. $TABLETRACK_LINKS = $_configuration['statistics_database']."`.`track_e_links";
  107. $TABLETRACK_LOGIN = $_configuration['statistics_database']."`.`track_e_login";
  108. $TABLETRACK_DOWNLOADS = $_configuration['statistics_database']."`.`track_e_downloads";
  109. $TABLETRACK_UPLOADS = $_configuration['statistics_database']."`.`track_e_uploads";
  110. $TABLETRACK_EXERCICES = $_configuration['statistics_database']."`.`track_e_exercices";
  111. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  112. $TABLECOURSE_WORK = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  113. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  114. $TABLECOURSE_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  115. $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  116. if(api_get_setting('use_session_mode') == "true") {
  117. $sql = "SELECT 1
  118. FROM $tbl_session_course_user AS session_course_user
  119. INNER JOIN $tbl_session AS session
  120. ON session_course_user.id_session = session.id
  121. AND ((date_start<=NOW()
  122. AND date_end>=NOW())
  123. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  124. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  125. //echo $sql;
  126. $result=api_sql_query($sql,__FILE__,__LINE__);
  127. if(!mysql_num_rows($result)){
  128. $disabled = true;
  129. }
  130. }
  131. $tbl_learnpath_main = Database::get_course_table('lp');
  132. $tbl_learnpath_item = Database::get_course_table('lp_item');
  133. $tbl_learnpath_view = Database::get_course_table('lp_view');
  134. $tbl_learnpath_item_view = Database::get_course_table('lp_item_view');
  135. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  136. // the variables for the days and the months
  137. // Defining the shorts for the days
  138. $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")));
  139. // Defining the days of the week to allow translation of the days
  140. $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")));
  141. // Defining the months of the year to allow translation of the months
  142. $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")));
  143. // Defining the months of the year to allow translation of the months
  144. $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")));
  145. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  146. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  147. //YW hack security to fix RolesRights bug
  148. $is_allowedToTrack = true; // allowed to track only user of one group
  149. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  150. /*
  151. ==============================================================================
  152. FUNCTIONS
  153. ==============================================================================
  154. */
  155. /**
  156. * Shortcut function to use htmlentities on many, many strings in this script
  157. * @param string String in a supposed encoding
  158. * @param string Supposed initial encoding (default: 'ISO-8859-15')
  159. * @return string HTML string (no encoding dependency)
  160. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  161. */
  162. function myEnc($isostring,$supposed_encoding='ISO-8859-15')
  163. {
  164. return htmlentities($isostring,ENT_QUOTES,$supposed_encoding);
  165. }
  166. /**
  167. * Displays the number of logins every month for a specific user in a specific course.
  168. */
  169. function display_login_tracking_info($view, $user_id, $course_id)
  170. {
  171. $MonthsLong = $GLOBALS['MonthsLong'];
  172. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  173. $tempView = $view;
  174. if(substr($view,0,1) == '1') {
  175. $new_view = substr_replace($view,'0',0,1);
  176. echo "
  177. <tr>
  178. <td valign='top'>
  179. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font>" .
  180. "<b>".myEnc(get_lang('LoginsAndAccessTools'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".myEnc(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>]
  181. </td>
  182. </tr>
  183. ";
  184. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('LoginsDetails'))."<br>";
  185. $sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
  186. FROM $track_access_table
  187. WHERE access_user_id = '".Database::escape_string($user_id)."'
  188. AND access_cours_code = '".Database::escape_string($course_id)."'
  189. GROUP BY YEAR(access_date),MONTH(access_date)
  190. ORDER BY YEAR(access_date),MONTH(access_date) ASC";
  191. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  192. //$results = getManyResults2Col($sql);
  193. $results = getManyResults3Col($sql);
  194. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  195. echo "<tr>
  196. <td class='secLine'>
  197. ".myEnc(get_lang('LoginsTitleMonthColumn'))."
  198. </td>
  199. <td class='secLine'>
  200. ".myEnc(get_lang('LoginsTitleCountColumn'))."
  201. </td>
  202. </tr>";
  203. $total = 0;
  204. if (is_array($results)) {
  205. for($j = 0 ; $j < count($results) ; $j++) {
  206. echo "<tr>";
  207. //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>";
  208. 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>";
  209. echo "<td valign='top' align='right' class='content'>".$results[$j][1]."</td>";
  210. echo"</tr>";
  211. $total = $total + $results[$j][1];
  212. }
  213. echo "<tr>";
  214. echo "<td>".myEnc(get_lang('Total'))."</td>";
  215. echo "<td align='right' class='content'>".$total."</td>";
  216. echo"</tr>";
  217. } else {
  218. echo "<tr>";
  219. echo "<td colspan='2'><center>".myEnc(get_lang('NoResult'))."</center></td>";
  220. echo"</tr>";
  221. }
  222. echo "</table>";
  223. echo "</td></tr>";
  224. } else {
  225. $new_view = substr_replace($view,'1',0,1);
  226. echo "
  227. <tr>
  228. <td valign='top'>
  229. +<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'>".myEnc(get_lang('LoginsAndAccessTools'))."</a>
  230. </td>
  231. </tr>
  232. ";
  233. }
  234. }
  235. /**
  236. * Displays the exercise results for a specific user in a specific course.
  237. * @todo remove globals
  238. */
  239. function display_exercise_tracking_info($view, $user_id, $course_id)
  240. {
  241. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES;
  242. if(substr($view,1,1) == '1')
  243. {
  244. $new_view = substr_replace($view,'0',1,1);
  245. echo "<tr>
  246. <td valign='top'>
  247. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('ExercicesResults'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".myEnc(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>]
  248. </td>
  249. </tr>";
  250. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('ExercicesDetails'))."<br />";
  251. $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  252. FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
  253. WHERE te.exe_cours_id = '".Database::escape_string($course_id)."'
  254. AND te.exe_user_id = '".Database::escape_string($user_id)."'
  255. AND te.exe_exo_id = ce.id
  256. ORDER BY ce.title ASC, te.exe_date ASC";
  257. $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
  258. FROM $TBL_TRACK_HOTPOTATOES AS te
  259. WHERE te.exe_user_id = '".Database::escape_string($user_id)."' AND te.exe_cours_id = '".Database::escape_string($course_id)."'
  260. ORDER BY te.exe_cours_id ASC, te.exe_date ASC";
  261. $hpresults = getManyResultsXCol($hpsql, 4);
  262. $NoTestRes = 0;
  263. $NoHPTestRes = 0;
  264. echo "<tr>\n<td style='padding-left : 40px;padding-right : 40px;'>\n";
  265. $results = getManyResultsXCol($sql, 4);
  266. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>\n";
  267. echo "
  268. <tr bgcolor='#E6E6E6'>
  269. <td>
  270. ".myEnc(get_lang('ExercicesTitleExerciceColumn'))."
  271. </td>
  272. <td>
  273. ".myEnc(get_lang('Date'))."
  274. </td>
  275. <td>
  276. ".myEnc(get_lang('ExercicesTitleScoreColumn'))."
  277. </td>
  278. </tr>";
  279. if (is_array($results)) {
  280. for($i = 0; $i < sizeof($results); $i++) {
  281. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]);
  282. echo "<tr>\n";
  283. echo "<td class='content'>".$results[$i][0]."</td>\n";
  284. echo "<td class='content'>".$display_date."</td>\n";
  285. echo "<td valign='top' align='right' class='content'>".$results[$i][1]." / ".$results[$i][2]."</td>\n";
  286. echo "</tr>\n";
  287. }
  288. } else {
  289. // istvan begin
  290. $NoTestRes = 1;
  291. }
  292. // The Result of Tests
  293. if(is_array($hpresults)) {
  294. for($i = 0; $i < sizeof($hpresults); $i++) {
  295. $title = GetQuizName($hpresults[$i][0],'');
  296. if ($title == '')
  297. $title = GetFileName($hpresults[$i][0]);
  298. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]);
  299. ?>
  300. <tr>
  301. <td class="content"><?php echo $title; ?></td>
  302. <td class="content" align="center"><?php echo $display_date; ?></td>
  303. <td class="content" align="center"><?php echo $hpresults[$i][1]; ?> / <?php echo $hpresults[$i][2]; ?></td>
  304. </tr>
  305. <?php }
  306. } else {
  307. $NoHPTestRes = 1;
  308. }
  309. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  310. echo "<tr>\n";
  311. echo "<td colspan='3'><center>".myEnc(get_lang('NoResult'))."</center></td>\n";
  312. echo "</tr>\n";
  313. }
  314. echo "</table>";
  315. echo "</td>\n</tr>\n";
  316. } else {
  317. $new_view = substr_replace($view,'1',1,1);
  318. echo "
  319. <tr>
  320. <td valign='top'>
  321. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?uInfo=$user_id&view=".$new_view."' class='specialLink'>".myEnc(get_lang('ExercicesResults'))."</a>
  322. </td>
  323. </tr>";
  324. }
  325. }
  326. /**
  327. * Displays the student publications for a specific user in a specific course.
  328. * @todo remove globals
  329. */
  330. function display_student_publications_tracking_info($view, $user_id, $course_id)
  331. {
  332. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong, $_course;
  333. if(substr($view,2,1) == '1') {
  334. $new_view = substr_replace($view,'0',2,1);
  335. echo "<tr>
  336. <td valign='top'>
  337. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('WorkUploads'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".myEnc(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>]
  338. </td>
  339. </tr>";
  340. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('WorksDetails'))."<br>";
  341. $sql = "SELECT u.upload_date, w.title, w.author,w.url
  342. FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
  343. WHERE u.upload_work_id = w.id
  344. AND u.upload_user_id = '".Database::escape_string($user_id)."'
  345. AND u.upload_cours_id = '".Database::escape_string($course_id)."'
  346. ORDER BY u.upload_date DESC";
  347. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  348. $results = getManyResultsXCol($sql,4);
  349. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  350. echo "<tr>
  351. <td class='secLine' width='40%'>
  352. ".myEnc(get_lang('WorkTitle'))."
  353. </td>
  354. <td class='secLine' width='30%'>
  355. ".myEnc(get_lang('WorkAuthors'))."
  356. </td>
  357. <td class='secLine' width='30%'>
  358. ".myEnc(get_lang('Date'))."
  359. </td>
  360. </tr>";
  361. if (is_array($results)) {
  362. for($j = 0 ; $j < count($results) ; $j++) {
  363. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  364. $timestamp = strtotime($results[$j][0]);
  365. $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp);
  366. echo "<tr>";
  367. echo "<td class='content'>"
  368. ."<a href ='".$pathToFile."'>".$results[$j][1]."</a>"
  369. ."</td>";
  370. echo "<td class='content'>".$results[$j][2]."</td>";
  371. echo "<td class='content'>".$beautifulDate."</td>";
  372. echo"</tr>";
  373. }
  374. } else {
  375. echo "<tr>";
  376. echo "<td colspan='3'><center>".myEnc(get_lang('NoResult'))."</center></td>";
  377. echo"</tr>";
  378. }
  379. echo "</table>";
  380. echo "</td></tr>";
  381. } else {
  382. $new_view = substr_replace($view,'1',2,1);
  383. echo "
  384. <tr>
  385. <td valign='top'>
  386. +<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'>".myEnc(get_lang('WorkUploads'))."</a>
  387. </td>
  388. </tr>
  389. ";
  390. }
  391. }
  392. /**
  393. * Displays the links followed for a specific user in a specific course.
  394. * @todo remove globals
  395. */
  396. function display_links_tracking_info($view, $user_id, $course_id)
  397. {
  398. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  399. if(substr($view,3,1) == '1') {
  400. $new_view = substr_replace($view,'0',3,1);
  401. echo "
  402. <tr>
  403. <td valign='top'>
  404. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('LinksAccess'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".myEnc(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>]
  405. </td>
  406. </tr>
  407. ";
  408. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('LinksDetails'))."<br>";
  409. $sql = "SELECT cl.title, cl.url
  410. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  411. WHERE sl.links_link_id = cl.id
  412. AND sl.links_cours_id = '".Database::escape_string($course_id)."'
  413. AND sl.links_user_id = '".Database::escape_string($user_id)."'
  414. GROUP BY cl.title, cl.url";
  415. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  416. $results = getManyResults2Col($sql);
  417. echo "<table cellpadding='2' cellspacing='1' border='0' align=center>";
  418. echo "<tr>
  419. <td class='secLine'>
  420. ".myEnc(get_lang('LinksTitleLinkColumn'))."
  421. </td>
  422. </tr>";
  423. if (is_array($results)) {
  424. for($j = 0 ; $j < count($results) ; $j++) {
  425. echo "<tr>";
  426. echo "<td class='content'><a href='".$results[$j][1]."'>".$results[$j][0]."</a></td>";
  427. echo"</tr>";
  428. }
  429. } else {
  430. echo "<tr>";
  431. echo "<td ><center>".myEnc(get_lang('NoResult'))."</center></td>";
  432. echo"</tr>";
  433. }
  434. echo "</table>";
  435. echo "</td></tr>";
  436. } else {
  437. $new_view = substr_replace($view,'1',3,1);
  438. echo "
  439. <tr>
  440. <td valign='top'>
  441. +<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'>".myEnc(get_lang('LinksAccess'))."</a>
  442. </td>
  443. </tr>
  444. ";
  445. }
  446. }
  447. /**
  448. * Displays the documents downloaded for a specific user in a specific course.
  449. */
  450. function display_document_tracking_info($view, $user_id, $course_id)
  451. {
  452. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  453. if(substr($view,4,1) == '1')
  454. {
  455. $new_view = substr_replace($view,'0',4,1);
  456. echo "
  457. <tr>
  458. <td valign='top'>
  459. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('DocumentsAccess'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?uInfo=".Security::remove_XSS($user_id)."&view=".Security::remove_XSS($new_view)."'>".myEnc(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>]
  460. </td>
  461. </tr>
  462. ";
  463. echo "<tr><td style='padding-left : 40px;' valign='top'>".myEnc(get_lang('DocumentsDetails'))."<br>";
  464. $sql = "SELECT down_doc_path
  465. FROM $downloads_table
  466. WHERE down_cours_id = '".Database::escape_string($course_id)."'
  467. AND down_user_id = '".Database::escape_string($user_id)."'
  468. GROUP BY down_doc_path";
  469. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  470. $results = getManyResults1Col($sql);
  471. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
  472. echo "<tr>
  473. <td class='secLine'>
  474. ".myEnc(get_lang('DocumentsTitleDocumentColumn'))."
  475. </td>
  476. </tr>";
  477. if (is_array($results)) {
  478. for($j = 0 ; $j < count($results) ; $j++) {
  479. echo "<tr>";
  480. echo "<td class='content'>".$results[$j]."</td>";
  481. echo"</tr>";
  482. }
  483. } else {
  484. echo "<tr>";
  485. echo "<td><center>".myEnc(get_lang('NoResult'))."</center></td>";
  486. echo"</tr>";
  487. }
  488. echo "</table>";
  489. echo "</td></tr>";
  490. } else {
  491. $new_view = substr_replace($view,'1',4,1);
  492. echo "
  493. <tr>
  494. <td valign='top'>
  495. +<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'>".myEnc(get_lang('DocumentsAccess'))."</a>
  496. </td>
  497. </tr>
  498. ";
  499. }
  500. }
  501. /*
  502. ==============================================================================
  503. MAIN SECTION
  504. ==============================================================================
  505. */
  506. ?>
  507. <h3>
  508. <?php echo $nameTools ?>
  509. </h3>
  510. <h4>
  511. <?php echo myEnc(get_lang('StatsOfUser')); ?>
  512. </h4>
  513. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  514. <?php
  515. // check if uid is tutor of this group
  516. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $_configuration['tracking_enabled'] ) {
  517. if(!$uInfo && !isset($uInfo) ) {
  518. /***************************************************************************
  519. *
  520. * Display list of user of this group
  521. *
  522. ***************************************************************************/
  523. echo "<h4>".myEnc(get_lang('ListStudents'))."</h4>";
  524. if( $is_allowedToTrackEverybodyInCourse ) {
  525. // if user can track everybody : list user of course
  526. if(api_get_setting('use_session_mode')) {
  527. $sql = "SELECT count(user_id)
  528. FROM $TABLECOURSUSER
  529. WHERE course_code = '".Database::escape_string($_cid)."'";
  530. } else {
  531. $sql = "SELECT count(id_user)
  532. FROM $tbl_session_course_user
  533. WHERE course_code = '".Database::escape_string($_cid)."'";
  534. }
  535. } else {
  536. // if user can only track one group : list users of this group
  537. $sql = "SELECT count(user)
  538. FROM $TABLECOURSE_GROUPSUSER
  539. WHERE group_id = '".Database::escape_string($_gid)."'";
  540. }
  541. $userGroupNb = getOneResult($sql);
  542. $step = 25; // number of student per page
  543. if ($userGroupNb > $step) {
  544. if(!isset($offset)) {
  545. $offset=0;
  546. }
  547. $next = $offset + $step;
  548. $previous = $offset - $step;
  549. $navLink = "<table width='100%' border='0'>\n"
  550. ."<tr>\n"
  551. ."<td align='left'>";
  552. if ($previous >= 0) {
  553. $navLink .= "<a href='".api_get_self()."?offset=$previous'>&lt;&lt; ".myEnc(get_lang('PreviousPage'))."</a>";
  554. }
  555. $navLink .= "</td>\n"
  556. ."<td align='right'>";
  557. if ($next < $userGroupNb) {
  558. $navLink .= "<a href='".api_get_self()."?offset=$next'>".myEnc(get_lang('NextPage'))." &gt;&gt;</a>";
  559. }
  560. $navLink .= "</td>\n"
  561. ."</tr>\n"
  562. ."</table>\n";
  563. } else {
  564. $offset = 0;
  565. }
  566. echo $navLink;
  567. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  568. if( $is_allowedToTrackEverybodyInCourse ) {
  569. // list of users in this course
  570. $sql = "SELECT u.user_id, u.firstname,u.lastname
  571. FROM $TABLECOURSUSER cu , $TABLEUSER u
  572. WHERE cu.user_id = u.user_id
  573. AND cu.course_code = '".Database::escape_string($_cid)."'
  574. LIMIT $offset,$step";
  575. }
  576. else
  577. {
  578. // list of users of this group
  579. $sql = "SELECT u.user_id, u.firstname,u.lastname
  580. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  581. WHERE gu.user_id = u.user_id
  582. AND gu.group_id = '".Database::escape_string($_gid)."'
  583. LIMIT $offset,$step";
  584. }
  585. $list_users = getManyResults3Col($sql);
  586. echo "<table width='100%' cellpadding='2' cellspacing='1' border='0'>\n"
  587. ."<tr align='center' valign='top' bgcolor='#E6E6E6'>\n"
  588. ."<td align='left'>",myEnc(get_lang('UserName')),"</td>\n"
  589. ."</tr>\n";
  590. for($i = 0 ; $i < sizeof($list_users) ; $i++) {
  591. echo "<tr valign='top' align='center'>\n"
  592. ."<td align='left'>"
  593. ."<a href='".api_get_self()."?uInfo=",$list_users[$i][0],"'>"
  594. .$list_users[$i][1]," ",$list_users[$i][2]
  595. ."</a>".
  596. "</td>\n";
  597. }
  598. echo "</table>\n";
  599. echo $navLink;
  600. } else {
  601. // if uInfo is set
  602. /***************************************************************************
  603. *
  604. * Informations about student uInfo
  605. *
  606. ***************************************************************************/
  607. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  608. // another course, or group
  609. if( $is_allowedToTrackEverybodyInCourse ) {
  610. // check if user is in this course
  611. $tracking_is_accepted = $is_course_member;
  612. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  613. } else {
  614. // check if user is in the group of this tutor
  615. $sql = "SELECT u.firstname,u.lastname, u.email
  616. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  617. WHERE gu.user_id = u.user_id`
  618. AND gu.group_id = '".Database::escape_string($_gid)."'
  619. AND u.user_id = '".Database::escape_string($uInfo)."'";
  620. $query = api_sql_query($sql,__FILE__,__LINE__);
  621. $tracked_user_info = @mysql_fetch_assoc($query);
  622. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  623. }
  624. if ($tracking_is_accepted) {
  625. $tracked_user_info['email'] == '' ? $mail_link = myEnc(get_lang('NoEmail')) : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  626. echo "<tr><td>";
  627. echo get_lang('informationsAbout').' :';
  628. echo "<ul>\n"
  629. ."<li>".myEnc(get_lang('FirstName'))." : ".$tracked_user_info['firstname']."</li>\n"
  630. ."<li>".myEnc(get_lang('LastName'))." : ".$tracked_user_info['lastname']."</li>\n"
  631. ."<li>".myEnc(get_lang('Email'))." : ".$mail_link."</li>\n"
  632. ."</ul>";
  633. echo "</td></tr>\n";
  634. // show all : number of 1 is equal to or bigger than number of categories
  635. // show none : number of 0 is equal to or bigger than number of categories
  636. echo "<tr>
  637. <td>
  638. [<a href='".api_get_self()."?uInfo=".Security::remove_XSS($uInfo)."&view=1111111'>".myEnc(get_lang('ShowAll'))."</a>]
  639. [<a href='".api_get_self()."?uInfo=".Security::remove_XSS($uInfo)."&view=0000000'>".myEnc(get_lang('ShowNone'))."</a>]".
  640. //"||[<a href='".api_get_self()."'>".myEnc(get_lang('BackToList'))."</a>]".
  641. "</td>
  642. </tr>
  643. ";
  644. if(!isset($view))
  645. {
  646. $view ='0000000';
  647. }
  648. //Logins
  649. display_login_tracking_info($view, $uInfo, $_cid);
  650. //Exercise results
  651. display_exercise_tracking_info($view, $uInfo, $_cid);
  652. //Student publications uploaded
  653. display_student_publications_tracking_info($view, $uInfo, $_cid);
  654. //Links usage
  655. display_links_tracking_info($view, $uInfo, $_cid);
  656. //Documents downloaded
  657. display_document_tracking_info($view, $uInfo, $_cid);
  658. } else {
  659. echo myEnc(get_lang('ErrorUserNotInGroup'));
  660. }
  661. /***************************************************************************
  662. *
  663. * Scorm contents and Learning Path
  664. *
  665. ***************************************************************************/
  666. if(substr($view,5,1) == '1') {
  667. $new_view = substr_replace($view,'0',5,1);
  668. echo "<tr>
  669. <td valign='top'>
  670. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".myEnc(get_lang('ScormAccess'))."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?view=".Security::remove_XSS($new_view)."&uInfo=".Security::remove_XSS($uInfo)."'>".myEnc(get_lang('Close'))."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=000001'>".get_lang('ExportAsCSV')."</a>]
  671. </td>
  672. </tr>";
  673. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  674. $result=api_sql_query($sql,__FILE__,__LINE__);
  675. $ar=Database::fetch_array($result);
  676. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  677. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'><tr>
  678. <td class='secLine'>
  679. &nbsp;".myEnc(get_lang('ScormContentColumn'))."&nbsp;
  680. </td>
  681. </tr>";
  682. if (is_array($ar)) {
  683. while ($ar['id'] != '') {
  684. $lp_title = stripslashes($ar['name']);
  685. echo "<tr><td>";
  686. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=".Security::remove_XSS($uInfo)."' class='specialLink'>$lp_title</a>";
  687. echo "</td></tr>";
  688. if ($ar['id']==$scormcontopen) { //have to list the students here
  689. $contentId=$ar['id'];
  690. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  691. "FROM $tbl_learnpath_item i " .
  692. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  693. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  694. "WHERE (v.user_id=".Database::escape_string($uInfo)." and v.lp_id=$contentId) ORDER BY v.id, i.id";
  695. $result3=api_sql_query($sql3,__FILE__,__LINE__);
  696. $ar3=Database::fetch_array($result3);
  697. if (is_array($ar3)) {
  698. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td>
  699. <td class='secLine'>
  700. &nbsp;".myEnc(get_lang('ScormTitleColumn'))."&nbsp;
  701. </td>
  702. <td class='secLine'>
  703. &nbsp;".myEnc(get_lang('ScormStatusColumn'))."&nbsp;
  704. </td>
  705. <td class='secLine'>
  706. &nbsp;".myEnc(get_lang('ScormScoreColumn'))."&nbsp;
  707. </td>
  708. <td class='secLine'>
  709. &nbsp;".myEnc(get_lang('ScormTimeColumn'))."&nbsp;
  710. </td>
  711. </tr>";
  712. while ($ar3['status'] != '') {
  713. require_once('../newscorm/learnpathItem.class.php');
  714. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  715. $title = htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  716. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
  717. echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
  718. echo "</tr>";
  719. $ar3=Database::fetch_array($result3);
  720. }
  721. } else {
  722. echo "<tr>";
  723. echo "<td colspan='3'><center>".myEnc(get_lang('ScormNeverOpened'))."</center></td>";
  724. echo"</tr>";
  725. }
  726. }
  727. $ar=Database::fetch_array($result);
  728. }
  729. } else {
  730. $noscorm=true;
  731. }
  732. if ($noscorm) {
  733. echo "<tr>";
  734. echo "<td colspan='3'><center>".myEnc(get_lang('NoResult'))."</center></td>";
  735. echo "</tr>";
  736. }
  737. echo "</table>";
  738. echo "</td></tr>";
  739. } else {
  740. $new_view = substr_replace($view,'1',5,1);
  741. echo "
  742. <tr>
  743. <td valign='top'>
  744. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?view=".Security::remove_XSS($new_view)."&uInfo=".Security::remove_XSS($uInfo)."' class='specialLink'>".myEnc(get_lang('ScormAccess'))."</a>
  745. </td>
  746. </tr>
  747. ";
  748. }
  749. }
  750. } else {
  751. // not allowed
  752. if(!$_configuration['tracking_enabled'])
  753. {
  754. echo myEnc(get_lang('TrackingDisabled'));
  755. } else {
  756. api_not_allowed();
  757. }
  758. }
  759. ?>
  760. </table>
  761. <?php
  762. Display::display_footer();
  763. ?>