userLog.php 15 KB

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