userLog.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 = Database::query($sql);
  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=Database::query($sql);
  127. if(!Database::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. $DaysShort = api_get_week_days_short();
  138. $DaysLong = api_get_week_days_long();
  139. $MonthsLong = api_get_months_long();
  140. $MonthsShort = api_get_months_short();
  141. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  142. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  143. //YW hack security to fix RolesRights bug
  144. $is_allowedToTrack = true; // allowed to track only user of one group
  145. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  146. /*
  147. ==============================================================================
  148. MAIN SECTION
  149. ==============================================================================
  150. */
  151. ?>
  152. <h3>
  153. <?php echo $nameTools ?>
  154. </h3>
  155. <h4>
  156. <?php echo get_lang('StatsOfUser'); ?>
  157. </h4>
  158. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  159. <?php
  160. // check if uid is tutor of this group
  161. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $_configuration['tracking_enabled'] ) {
  162. if(!$uInfo && !isset($uInfo) ) {
  163. /***************************************************************************
  164. *
  165. * Display list of user of this group
  166. *
  167. ***************************************************************************/
  168. echo "<h4>".get_lang('ListStudents')."</h4>";
  169. if( $is_allowedToTrackEverybodyInCourse ) {
  170. // if user can track everybody : list user of course
  171. if(api_get_setting('use_session_mode')) {
  172. $sql = "SELECT count(user_id)
  173. FROM $TABLECOURSUSER
  174. WHERE course_code = '".Database::escape_string($_cid)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH."";
  175. } else {
  176. $sql = "SELECT count(id_user)
  177. FROM $tbl_session_course_user
  178. WHERE course_code = '".Database::escape_string($_cid)."'";
  179. }
  180. } else {
  181. // if user can only track one group : list users of this group
  182. $sql = "SELECT count(user)
  183. FROM $TABLECOURSE_GROUPSUSER
  184. WHERE group_id = '".Database::escape_string($_gid)."'";
  185. }
  186. $userGroupNb = getOneResult($sql);
  187. $step = 25; // number of student per page
  188. if ($userGroupNb > $step) {
  189. if(!isset($offset)) {
  190. $offset=0;
  191. }
  192. $next = $offset + $step;
  193. $previous = $offset - $step;
  194. $navLink = "<table width='100%' border='0'>\n"
  195. ."<tr>\n"
  196. ."<td align='left'>";
  197. if ($previous >= 0) {
  198. $navLink .= "<a href='".api_get_self()."?offset=$previous'>&lt;&lt; ".get_lang('PreviousPage')."</a>";
  199. }
  200. $navLink .= "</td>\n"
  201. ."<td align='right'>";
  202. if ($next < $userGroupNb) {
  203. $navLink .= "<a href='".api_get_self()."?offset=$next'>".get_lang('NextPage')." &gt;&gt;</a>";
  204. }
  205. $navLink .= "</td>\n"
  206. ."</tr>\n"
  207. ."</table>\n";
  208. } else {
  209. $offset = 0;
  210. }
  211. echo $navLink;
  212. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  213. if( $is_allowedToTrackEverybodyInCourse ) {
  214. // list of users in this course
  215. $sql = "SELECT u.user_id, u.firstname,u.lastname
  216. FROM $TABLECOURSUSER cu , $TABLEUSER u
  217. WHERE cu.user_id = u.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  218. AND cu.course_code = '".Database::escape_string($_cid)."'
  219. LIMIT $offset,$step";
  220. }
  221. else
  222. {
  223. // list of users of this group
  224. $sql = "SELECT u.user_id, u.firstname,u.lastname
  225. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  226. WHERE gu.user_id = u.user_id
  227. AND gu.group_id = '".Database::escape_string($_gid)."'
  228. LIMIT $offset,$step";
  229. }
  230. $list_users = getManyResults3Col($sql);
  231. echo "<table width='100%' cellpadding='2' cellspacing='1' border='0'>\n"
  232. ."<tr align='center' valign='top' bgcolor='#E6E6E6'>\n"
  233. ."<td align='left'>",get_lang('UserName'),"</td>\n"
  234. ."</tr>\n";
  235. for($i = 0 ; $i < sizeof($list_users) ; $i++) {
  236. echo "<tr valign='top' align='center'>\n"
  237. ."<td align='left'>"
  238. ."<a href='".api_get_self()."?uInfo=",$list_users[$i][0],"'>"
  239. .$list_users[$i][1]," ",$list_users[$i][2]
  240. ."</a>".
  241. "</td>\n";
  242. }
  243. echo "</table>\n";
  244. echo $navLink;
  245. } else {
  246. // if uInfo is set
  247. /***************************************************************************
  248. *
  249. * Informations about student uInfo
  250. *
  251. ***************************************************************************/
  252. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  253. // another course, or group
  254. if( $is_allowedToTrackEverybodyInCourse ) {
  255. // check if user is in this course
  256. $tracking_is_accepted = $is_course_member;
  257. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  258. } else {
  259. // check if user is in the group of this tutor
  260. $sql = "SELECT u.firstname,u.lastname, u.email
  261. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  262. WHERE gu.user_id = u.user_id`
  263. AND gu.group_id = '".Database::escape_string($_gid)."'
  264. AND u.user_id = '".Database::escape_string($uInfo)."'";
  265. $query = Database::query($sql);
  266. $tracked_user_info = @Database::fetch_assoc($query);
  267. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  268. }
  269. if ($tracking_is_accepted) {
  270. $tracked_user_info['email'] == '' ? $mail_link = get_lang('NoEmail') : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  271. echo "<tr><td>";
  272. echo get_lang('informationsAbout').' :';
  273. echo "<ul>\n"
  274. ."<li>".get_lang('FirstName')." : ".$tracked_user_info['firstname']."</li>\n"
  275. ."<li>".get_lang('LastName')." : ".$tracked_user_info['lastname']."</li>\n"
  276. ."<li>".get_lang('Email')." : ".$mail_link."</li>\n"
  277. ."</ul>";
  278. echo "</td></tr>\n";
  279. // show all : number of 1 is equal to or bigger than number of categories
  280. // show none : number of 0 is equal to or bigger than number of categories
  281. echo "<tr>
  282. <td>
  283. [<a href='".api_get_self()."?uInfo=".Security::remove_XSS($uInfo)."&view=1111111'>".get_lang('ShowAll')."</a>]
  284. [<a href='".api_get_self()."?uInfo=".Security::remove_XSS($uInfo)."&view=0000000'>".get_lang('ShowNone')."</a>]".
  285. //"||[<a href='".api_get_self()."'>".get_lang('BackToList')."</a>]".
  286. "</td>
  287. </tr>
  288. ";
  289. if(!isset($view))
  290. {
  291. $view ='0000000';
  292. }
  293. //Logins
  294. TrackingUserLog::display_login_tracking_info($view, $uInfo, $_cid);
  295. //Exercise results
  296. TrackingUserLog::display_exercise_tracking_info($view, $uInfo, $_cid);
  297. //Student publications uploaded
  298. TrackingUserLog::display_student_publications_tracking_info($view, $uInfo, $_cid);
  299. //Links usage
  300. TrackingUserLog::display_links_tracking_info($view, $uInfo, $_cid);
  301. //Documents downloaded
  302. TrackingUserLog::display_document_tracking_info($view, $uInfo, $_cid);
  303. } else {
  304. echo get_lang('ErrorUserNotInGroup');
  305. }
  306. /***************************************************************************
  307. *
  308. * Scorm contents and Learning Path
  309. *
  310. ***************************************************************************/
  311. if(substr($view,5,1) == '1') {
  312. $new_view = substr_replace($view,'0',5,1);
  313. echo "<tr>
  314. <td valign='top'>
  315. <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ScormAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?view=".Security::remove_XSS($new_view)."&uInfo=".Security::remove_XSS($uInfo)."'>".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>]
  316. </td>
  317. </tr>";
  318. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  319. $result=Database::query($sql);
  320. $ar=Database::fetch_array($result);
  321. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  322. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'><tr>
  323. <td class='secLine'>
  324. &nbsp;".get_lang('ScormContentColumn')."&nbsp;
  325. </td>
  326. </tr>";
  327. if (is_array($ar)) {
  328. while ($ar['id'] != '') {
  329. $lp_title = stripslashes($ar['name']);
  330. echo "<tr><td>";
  331. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=".Security::remove_XSS($uInfo)."' class='specialLink'>$lp_title</a>";
  332. echo "</td></tr>";
  333. if ($ar['id']==$scormcontopen) { //have to list the students here
  334. $contentId=$ar['id'];
  335. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  336. "FROM $tbl_learnpath_item i " .
  337. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  338. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  339. "WHERE (v.user_id=".Database::escape_string($uInfo)." and v.lp_id=$contentId) ORDER BY v.id, i.id";
  340. $result3=Database::query($sql3);
  341. $ar3=Database::fetch_array($result3);
  342. if (is_array($ar3)) {
  343. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td>
  344. <td class='secLine'>
  345. &nbsp;".get_lang('ScormTitleColumn')."&nbsp;
  346. </td>
  347. <td class='secLine'>
  348. &nbsp;".get_lang('ScormStatusColumn')."&nbsp;
  349. </td>
  350. <td class='secLine'>
  351. &nbsp;".get_lang('ScormScoreColumn')."&nbsp;
  352. </td>
  353. <td class='secLine'>
  354. &nbsp;".get_lang('ScormTimeColumn')."&nbsp;
  355. </td>
  356. </tr>";
  357. while ($ar3['status'] != '') {
  358. require_once('../newscorm/learnpathItem.class.php');
  359. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  360. $title = api_htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  361. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
  362. echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
  363. echo "</tr>";
  364. $ar3=Database::fetch_array($result3);
  365. }
  366. } else {
  367. echo "<tr>";
  368. echo "<td colspan='3'><center>".get_lang('ScormNeverOpened')."</center></td>";
  369. echo"</tr>";
  370. }
  371. }
  372. $ar=Database::fetch_array($result);
  373. }
  374. } else {
  375. $noscorm=true;
  376. }
  377. if ($noscorm) {
  378. echo "<tr>";
  379. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
  380. echo "</tr>";
  381. }
  382. echo "</table>";
  383. echo "</td></tr>";
  384. } else {
  385. $new_view = substr_replace($view,'1',5,1);
  386. echo "
  387. <tr>
  388. <td valign='top'>
  389. +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?view=".Security::remove_XSS($new_view)."&uInfo=".Security::remove_XSS($uInfo)."' class='specialLink'>".get_lang('ScormAccess')."</a>
  390. </td>
  391. </tr>
  392. ";
  393. }
  394. }
  395. } else {
  396. // not allowed
  397. if(!$_configuration['tracking_enabled'])
  398. {
  399. echo get_lang('TrackingDisabled');
  400. } else {
  401. api_not_allowed();
  402. }
  403. }
  404. ?>
  405. </table>
  406. <?php
  407. Display::display_footer();
  408. ?>