userLog.php 15 KB

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