userLog.php 15 KB

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