userLog.php 16 KB

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