userLog.php 33 KB

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