userLog.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // TODO: Is this file deprecated?
  4. /**
  5. * @package chamilo.tracking
  6. * @todo clean code - structure is unclear and difficult to modify
  7. */
  8. /* INIT SECTION */
  9. $uInfo = $_REQUEST['uInfo'];
  10. $view = $_REQUEST['view'];
  11. // name of the language file that needs to be included
  12. $language_file = 'tracking';
  13. // Including the global initialization file
  14. require_once '../inc/global.inc.php';
  15. // the section (for the tabs)
  16. $this_section = "session_my_space";
  17. // variables
  18. $user_id = api_get_user_id();
  19. $course_id = api_get_course_id();
  20. //YW Hack security to quick fix RolesRights bug
  21. $is_allowed = true;
  22. /* Libraries */
  23. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  24. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  25. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  26. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  27. /* Header */
  28. /*
  29. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  30. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  31. */
  32. if(isset($uInfo)) {
  33. $interbreadcrumb[]= array ('url'=>'../user/userInfo.php?uInfo='.Security::remove_XSS($uInfo), "name"=> api_ucfirst(get_lang('Users')));
  34. }
  35. $nameTools = get_lang('ToolName');
  36. $htmlHeadXtra[] = "<style type='text/css'>
  37. /*<![CDATA[*/
  38. .secLine {background-color : #E6E6E6;}
  39. .content {padding-left : 15px;padding-right : 15px; }
  40. .specialLink{color : #0000FF;}
  41. /*]]>*/
  42. </style>
  43. <style media='print' type='text/css'>
  44. /*<![CDATA[*/
  45. td {border-bottom: thin dashed gray;}
  46. /*]]>*/
  47. </style>";
  48. Display::display_header($nameTools,"Tracking");
  49. /* Constants and variables */
  50. $is_allowedToTrack = $is_courseAdmin;
  51. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  52. // Database Table Definitions
  53. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  54. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  55. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  56. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  57. $TABLETRACK_ACCESS = $_configuration['statistics_database'].".track_e_access";
  58. $TABLETRACK_LINKS = $_configuration['statistics_database'].".track_e_links";
  59. $TABLETRACK_LOGIN = $_configuration['statistics_database'].".track_e_login";
  60. $TABLETRACK_DOWNLOADS = $_configuration['statistics_database'].".track_e_downloads";
  61. $TABLETRACK_UPLOADS = $_configuration['statistics_database'].".track_e_uploads";
  62. $TABLETRACK_EXERCICES = $_configuration['statistics_database'].".track_e_exercices";
  63. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  64. $TABLECOURSE_WORK = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  65. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  66. $TABLECOURSE_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  67. $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  68. if(api_get_setting('use_session_mode') == "true") {
  69. $sql = "SELECT 1
  70. FROM $tbl_session_course_user AS session_course_user
  71. INNER JOIN $tbl_session AS session
  72. ON session_course_user.id_session = session.id
  73. AND ((date_start<=NOW()
  74. AND date_end>=NOW())
  75. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  76. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  77. //echo $sql;
  78. $result=Database::query($sql);
  79. if(!Database::num_rows($result)){
  80. $disabled = true;
  81. }
  82. }
  83. $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
  84. $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
  85. $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
  86. $tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  87. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  88. // The variables for the days and the months
  89. $DaysShort = api_get_week_days_short();
  90. $DaysLong = api_get_week_days_long();
  91. $MonthsLong = api_get_months_long();
  92. $MonthsShort = api_get_months_short();
  93. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  94. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  95. //YW hack security to fix RolesRights bug
  96. $is_allowedToTrack = true; // allowed to track only user of one group
  97. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  98. /* MAIN SECTION */
  99. ?>
  100. <h3>
  101. <?php echo $nameTools ?>
  102. </h3>
  103. <h4>
  104. <?php echo get_lang('StatsOfUser'); ?>
  105. </h4>
  106. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  107. <?php
  108. // check if uid is tutor of this group
  109. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
  110. if(!$uInfo && !isset($uInfo) ) {
  111. /*
  112. * Display list of user of this group
  113. */
  114. echo "<h4>".get_lang('ListStudents')."</h4>";
  115. if( $is_allowedToTrackEverybodyInCourse ) {
  116. // if user can track everybody : list user of course
  117. if(api_get_setting('use_session_mode')) {
  118. $sql = "SELECT count(user_id)
  119. FROM $TABLECOURSUSER
  120. WHERE course_code = '".Database::escape_string($_cid)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH."";
  121. } else {
  122. $sql = "SELECT count(id_user)
  123. FROM $tbl_session_course_user
  124. WHERE course_code = '".Database::escape_string($_cid)."'";
  125. }
  126. } else {
  127. // if user can only track one group : list users of this group
  128. $sql = "SELECT count(user)
  129. FROM $TABLECOURSE_GROUPSUSER
  130. WHERE group_id = '".Database::escape_string($_gid)."'";
  131. }
  132. $userGroupNb = getOneResult($sql);
  133. $step = 25; // number of student per page
  134. if ($userGroupNb > $step) {
  135. if(!isset($offset)) {
  136. $offset=0;
  137. }
  138. $next = $offset + $step;
  139. $previous = $offset - $step;
  140. $navLink = "<table width='100%' border='0'>\n"
  141. ."<tr>\n"
  142. ."<td align='left'>";
  143. if ($previous >= 0) {
  144. $navLink .= "<a href='".api_get_self()."?offset=$previous'>&lt;&lt; ".get_lang('PreviousPage')."</a>";
  145. }
  146. $navLink .= "</td>\n"
  147. ."<td align='right'>";
  148. if ($next < $userGroupNb) {
  149. $navLink .= "<a href='".api_get_self()."?offset=$next'>".get_lang('NextPage')." &gt;&gt;</a>";
  150. }
  151. $navLink .= "</td>\n"
  152. ."</tr>\n"
  153. ."</table>\n";
  154. } else {
  155. $offset = 0;
  156. }
  157. echo $navLink;
  158. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  159. if( $is_allowedToTrackEverybodyInCourse ) {
  160. // list of users in this course
  161. $sql = "SELECT u.user_id, u.firstname,u.lastname
  162. FROM $TABLECOURSUSER cu , $TABLEUSER u
  163. WHERE cu.user_id = u.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  164. AND cu.course_code = '".Database::escape_string($_cid)."'
  165. LIMIT $offset,$step";
  166. }
  167. else
  168. {
  169. // list of users of this group
  170. $sql = "SELECT u.user_id, u.firstname,u.lastname
  171. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  172. WHERE gu.user_id = u.user_id
  173. AND gu.group_id = '".Database::escape_string($_gid)."'
  174. LIMIT $offset,$step";
  175. }
  176. $list_users = getManyResults3Col($sql);
  177. echo "<table width='100%' cellpadding='2' cellspacing='1' border='0'>\n"
  178. ."<tr align='center' valign='top' bgcolor='#E6E6E6'>\n"
  179. ."<td align='left'>",get_lang('UserName'),"</td>\n"
  180. ."</tr>\n";
  181. for($i = 0 ; $i < sizeof($list_users) ; $i++) {
  182. echo "<tr valign='top' align='center'>\n"
  183. ."<td align='left'>"
  184. ."<a href='".api_get_self()."?uInfo=",$list_users[$i][0],"'>"
  185. .$list_users[$i][1]," ",$list_users[$i][2]
  186. ."</a>".
  187. "</td>\n";
  188. }
  189. echo "</table>\n";
  190. echo $navLink;
  191. } else {
  192. // if uInfo is set
  193. /*
  194. * Informations about student uInfo
  195. */
  196. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  197. // another course, or group
  198. if( $is_allowedToTrackEverybodyInCourse ) {
  199. // check if user is in this course
  200. $tracking_is_accepted = $is_course_member;
  201. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  202. } else {
  203. // check if user is in the group of this tutor
  204. $sql = "SELECT u.firstname,u.lastname, u.email
  205. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  206. WHERE gu.user_id = u.user_id
  207. AND gu.group_id = '".Database::escape_string($_gid)."'
  208. AND u.user_id = '".Database::escape_string($uInfo)."'";
  209. $query = Database::query($sql);
  210. $tracked_user_info = @Database::fetch_assoc($query);
  211. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  212. }
  213. if ($tracking_is_accepted) {
  214. $tracked_user_info['email'] == '' ? $mail_link = get_lang('NoEmail') : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  215. echo "<tr><td>";
  216. echo get_lang('informationsAbout').' :';
  217. echo "<ul>\n"
  218. ."<li>".get_lang('FirstName')." : ".$tracked_user_info['firstname']."</li>\n"
  219. ."<li>".get_lang('LastName')." : ".$tracked_user_info['lastname']."</li>\n"
  220. ."<li>".get_lang('Email')." : ".$mail_link."</li>\n"
  221. ."</ul>";
  222. echo "</td></tr>\n";
  223. // show all : number of 1 is equal to or bigger than number of categories
  224. // show none : number of 0 is equal to or bigger than number of categories
  225. echo "<tr>
  226. <td>
  227. [<a href='".api_get_self()."?uInfo=".Security::remove_XSS($uInfo)."&view=1111111'>".get_lang('ShowAll')."</a>]
  228. [<a href='".api_get_self()."?uInfo=".Security::remove_XSS($uInfo)."&view=0000000'>".get_lang('ShowNone')."</a>]".
  229. //"||[<a href='".api_get_self()."'>".get_lang('BackToList')."</a>]".
  230. "</td>
  231. </tr>
  232. ";
  233. if(!isset($view))
  234. {
  235. $view ='0000000';
  236. }
  237. //Logins
  238. TrackingUserLog::display_login_tracking_info($view, $uInfo, $_cid);
  239. //Exercise results
  240. TrackingUserLog::display_exercise_tracking_info($view, $uInfo, $_cid);
  241. //Student publications uploaded
  242. TrackingUserLog::display_student_publications_tracking_info($view, $uInfo, $_cid);
  243. //Links usage
  244. TrackingUserLog::display_links_tracking_info($view, $uInfo, $_cid);
  245. //Documents downloaded
  246. TrackingUserLog::display_document_tracking_info($view, $uInfo, $_cid);
  247. } else {
  248. echo get_lang('ErrorUserNotInGroup');
  249. }
  250. /*
  251. * Scorm contents and Learning Path
  252. */
  253. if(substr($view,5,1) == '1') {
  254. $new_view = substr_replace($view,'0',5,1);
  255. echo "<tr>
  256. <td valign='top'>
  257. <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>]
  258. </td>
  259. </tr>";
  260. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  261. $result=Database::query($sql);
  262. $ar=Database::fetch_array($result);
  263. echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
  264. echo "<table cellpadding='2' cellspacing='1' border='0' align='center'><tr>
  265. <td class='secLine'>
  266. &nbsp;".get_lang('ScormContentColumn')."&nbsp;
  267. </td>
  268. </tr>";
  269. if (is_array($ar)) {
  270. while ($ar['id'] != '') {
  271. $lp_title = stripslashes($ar['name']);
  272. echo "<tr><td>";
  273. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=".Security::remove_XSS($uInfo)."' class='specialLink'>$lp_title</a>";
  274. echo "</td></tr>";
  275. if ($ar['id']==$scormcontopen) { //have to list the students here
  276. $contentId=$ar['id'];
  277. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  278. "FROM $tbl_learnpath_item i " .
  279. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  280. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  281. "WHERE (v.user_id=".Database::escape_string($uInfo)." and v.lp_id=$contentId) ORDER BY v.id, i.id";
  282. $result3=Database::query($sql3);
  283. $ar3=Database::fetch_array($result3);
  284. if (is_array($ar3)) {
  285. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td>
  286. <td class='secLine'>
  287. &nbsp;".get_lang('ScormTitleColumn')."&nbsp;
  288. </td>
  289. <td class='secLine'>
  290. &nbsp;".get_lang('ScormStatusColumn')."&nbsp;
  291. </td>
  292. <td class='secLine'>
  293. &nbsp;".get_lang('ScormScoreColumn')."&nbsp;
  294. </td>
  295. <td class='secLine'>
  296. &nbsp;".get_lang('ScormTimeColumn')."&nbsp;
  297. </td>
  298. </tr>";
  299. while ($ar3['status'] != '') {
  300. require_once '../newscorm/learnpathItem.class.php';
  301. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  302. echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
  303. echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
  304. echo "</tr>";
  305. $ar3=Database::fetch_array($result3);
  306. }
  307. } else {
  308. echo "<tr>";
  309. echo "<td colspan='3'><center>".get_lang('ScormNeverOpened')."</center></td>";
  310. echo"</tr>";
  311. }
  312. }
  313. $ar=Database::fetch_array($result);
  314. }
  315. } else {
  316. $noscorm=true;
  317. }
  318. if ($noscorm) {
  319. echo "<tr>";
  320. echo "<td colspan='3'><center>".get_lang('NoResult')."</center></td>";
  321. echo "</tr>";
  322. }
  323. echo "</table>";
  324. echo "</td></tr>";
  325. } else {
  326. $new_view = substr_replace($view,'1',5,1);
  327. echo "
  328. <tr>
  329. <td valign='top'>
  330. +<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>
  331. </td>
  332. </tr>
  333. ";
  334. }
  335. }
  336. } else {
  337. // not allowed
  338. api_not_allowed();
  339. }
  340. ?>
  341. </table>
  342. <?php
  343. Display::display_footer();