userlogCSV.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. require_once '../inc/global.inc.php';
  15. // Roles and rights system
  16. $user_id = api_get_user_id();
  17. $course_id = api_get_course_id();
  18. $courseId = api_get_course_int_id();
  19. //YW Hack security to quick fix RolesRights bug
  20. $is_allowed = true;
  21. /* Libraries */
  22. require_once api_get_path(SYS_CODE_PATH) . 'resourcelinker/resourcelinker.inc.php';
  23. require_once api_get_path(SYS_CODE_PATH) . 'exercice/hotpotatoes.lib.php';
  24. /* Header */
  25. /*
  26. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  27. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  28. */
  29. if ($uInfo) {
  30. $interbreadcrumb[] = array(
  31. "url" => "../user/userInfo.php?uInfo=$uInfo",
  32. "name" => get_lang('BredCrumpUsers')
  33. );
  34. }
  35. $nameTools = get_lang('ToolName');
  36. /* Constants and variables */
  37. $is_allowedToTrack = $is_courseAdmin;
  38. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course(
  39. $user_id,
  40. $courseId
  41. );
  42. // Database Table Definitions
  43. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  44. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  45. $tbl_session_course_user = Database::get_main_table(
  46. TABLE_MAIN_SESSION_COURSE_USER
  47. );
  48. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  49. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  50. $now = api_get_utc_datetime();
  51. $sql = "SELECT 1
  52. FROM $tbl_session_course_user AS session_course_user
  53. INNER JOIN $tbl_session AS session
  54. ON session_course_user.session_id = session.id
  55. AND ((access_start_date <= '$now'
  56. AND access_end_date >= '$now')
  57. OR (access_start_date='0000-00-00' AND access_end_date='0000-00-00'))
  58. WHERE session_id='" . $_SESSION['id_session'] . "' AND c_id = $courseId";
  59. //echo $sql;
  60. $result = Database::query($sql);
  61. if (!Database::num_rows($result)) {
  62. $disabled = true;
  63. }
  64. $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
  65. $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
  66. $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
  67. $tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  68. $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  69. // The variables for the days and the months
  70. $DaysShort = api_get_week_days_short();
  71. $DaysLong = api_get_week_days_long();
  72. $MonthsLong = api_get_months_long();
  73. $MonthsShort = api_get_months_short();
  74. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  75. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  76. //YW hack security to fix RolesRights bug
  77. $is_allowedToTrack = true; // allowed to track only user of one group
  78. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  79. /* MAIN SECTION */
  80. $title[0] = '';
  81. $title[1] = '';
  82. $line = '';
  83. $title_line = '';
  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. if ($is_allowedToTrackEverybodyInCourse) {
  91. // if user can track everybody : list user of course
  92. $sql = "SELECT count(user_id)
  93. FROM $TABLECOURSUSER
  94. WHERE c_id = '$courseId' AND relation_type<>" . COURSE_RELATION_TYPE_RRHH . "";
  95. } else {
  96. // if user can only track one group : list users of this group
  97. $sql = "SELECT count(user)
  98. FROM $TABLECOURSE_GROUPSUSER
  99. WHERE group_id = '$_gid'";
  100. }
  101. $userGroupNb = StatsUtils::getOneResult($sql);
  102. $step = 25; // number of student per page
  103. if ($userGroupNb > $step) {
  104. if (!isset($offset)) {
  105. $offset = 0;
  106. }
  107. $next = $offset + $step;
  108. $previous = $offset - $step;
  109. $navLink = "";
  110. if ($previous >= 0) {
  111. }
  112. if ($next < $userGroupNb) {
  113. }
  114. } else {
  115. $offset = 0;
  116. }
  117. echo $navLink;
  118. if (!settype($offset, 'integer') || !settype($step, 'integer')) {
  119. die('Offset or step variables are not integers.');
  120. } //sanity check of integer vars
  121. if ($is_allowedToTrackEverybodyInCourse) {
  122. // list of users in this course
  123. $sql = "SELECT u.user_id, u.firstname,u.lastname
  124. FROM $TABLECOURSUSER cu , $TABLEUSER u
  125. WHERE cu.user_id = u.user_id AND cu.relation_type<>" . COURSE_RELATION_TYPE_RRHH . "
  126. AND cu.c_id = '$courseId'
  127. LIMIT $offset,$step";
  128. } else {
  129. // list of users of this group
  130. $sql = "SELECT u.user_id, u.firstname,u.lastname
  131. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  132. WHERE gu.user_id = u.user_id
  133. AND gu.group_id = '$_gid'
  134. LIMIT $offset,$step";
  135. }
  136. $list_users = getManyResults3Col($sql);
  137. for ($i = 0; $i < sizeof($list_users); $i++) {
  138. // just sum $i up
  139. }
  140. } else { // if uInfo is set
  141. /*
  142. * Informations about student uInfo
  143. */
  144. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  145. // another course, or group
  146. if ($is_allowedToTrackEverybodyInCourse) {
  147. // check if user is in this course
  148. $tracking_is_accepted = $is_course_member;
  149. $tracked_user_info = api_get_user_info($uInfo);
  150. $title[0] = $tracked_user_info[1] . '_' . $tracked_user_info[2];
  151. } else {
  152. // check if user is in the group of this tutor
  153. $sql = "SELECT u.firstname,u.lastname, u.email
  154. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  155. WHERE gu.user_id = u.user_id
  156. AND gu.group_id = '$_gid'
  157. AND u.user_id = '$uInfo'";
  158. $query = Database::query($sql);
  159. $tracked_user_info = @Database::fetch_assoc($query);
  160. if (is_array($tracked_user_info)) {
  161. $tracking_is_accepted = true;
  162. }
  163. $title[0] = $tracked_user_info['firstname'] . '_' . $tracked_user_info['lastname'];
  164. }
  165. if ($tracking_is_accepted) {
  166. $tracked_user_info['email'] == '' ? $mail_link = get_lang(
  167. 'NoEmail'
  168. ) : $mail_link = Display::encrypted_mailto_link(
  169. $tracked_user_info['email']
  170. );
  171. if (!isset($view)) {
  172. $view = '0000000';
  173. }
  174. //Logins
  175. list($title_line1, $line1) = TrackingUserLogCSV::display_login_tracking_info(
  176. $view,
  177. $uInfo,
  178. $courseId
  179. );
  180. //Exercise results
  181. list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info(
  182. $view,
  183. $uInfo,
  184. $_cid
  185. );
  186. //Student publications uploaded
  187. list($title_line3, $line3) = TrackingUserLogCSV::display_student_publications_tracking_info(
  188. $view,
  189. $uInfo,
  190. $courseId
  191. );
  192. //Links usage
  193. list($title_line4, $line4) = TrackingUserLogCSV::display_links_tracking_info(
  194. $view,
  195. $uInfo,
  196. $_cid
  197. );
  198. //Documents downloaded
  199. list($title_line5, $line5) = TrackingUserLogCSV::display_document_tracking_info(
  200. $view,
  201. $uInfo,
  202. $_cid
  203. );
  204. $title_line = $title_line1 . $title_line2 . $title_line3 . $title_line4 . $title_line5;
  205. $line = $line1 . $line2 . $line3 . $line4 . $line5;
  206. } else {
  207. echo get_lang('ErrorUserNotInGroup');
  208. }
  209. /*
  210. * Scorm contents and Learning Path
  211. */
  212. //TODO: scorm tools is in work and the logs will change in few days...
  213. /*if(substr($view,5,1) == '1')
  214. {
  215. $new_view = substr_replace($view,'0',5,1);
  216. $title[1]=get_lang('ScormContentColumn');
  217. $line ='';
  218. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  219. $result=Database::query($sql);
  220. $ar=Database::fetch_array($result);
  221. if (is_array($ar))
  222. {
  223. while ($ar['id'] != '') {
  224. $lp_title = stripslashes($ar['name']);
  225. echo "<tr><td>";
  226. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
  227. echo "</td></tr>";
  228. if ($ar['id']==$scormcontopen) { //have to list the students here
  229. $contentId=$ar['id'];
  230. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  231. "FROM $tbl_learnpath_item i " .
  232. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  233. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  234. "WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
  235. $result3=Database::query($sql3);
  236. $ar3=Database::fetch_array($result3);
  237. if (is_array($ar3)) {
  238. $title_line=get_lang('ScormTitleColumn').";".get_lang('ScormStatusColumn').";".get_lang('ScormScoreColumn').";".get_lang('ScormTimeColumn')."\n";
  239. while ($ar3['status'] != '') {
  240. require_once('../newscorm/learnpathItem.class.php');
  241. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  242. $line .= $title.';'.$ar3['status'].';'.$ar3['score'].';'.$time."\n";
  243. $ar3=Database::fetch_array($result3);
  244. }
  245. } else {
  246. $line .= get_lang('ScormNeverOpened');
  247. }
  248. }
  249. $ar=Database::fetch_array($result);
  250. }
  251. } else {
  252. $noscorm=true;
  253. }
  254. if ($noscorm) {
  255. $line=get_lang('NoResult');
  256. }
  257. } else {
  258. $new_view = substr_replace($view,'1',5,1);
  259. }*/
  260. }
  261. /*
  262. * Export to a CSV file
  263. * force the browser to save the file instead of opening it
  264. */
  265. $len = strlen($title_line . $line);
  266. header('Content-type: application/octet-stream');
  267. //header('Content-Type: application/force-download');
  268. header('Content-length: ' . $len);
  269. $filename = html_entity_decode(
  270. str_replace(
  271. ":",
  272. "",
  273. str_replace(" ", "_", $title[0] . '_' . $title[1] . '.csv')
  274. )
  275. );
  276. $filename = api_replace_dangerous_char($filename);
  277. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  278. header('Content-Disposition: filename= ' . $filename);
  279. } else {
  280. header('Content-Disposition: attachment; filename= ' . $filename);
  281. }
  282. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  283. header('Pragma: ');
  284. header('Cache-Control: ');
  285. header(
  286. 'Cache-Control: public'
  287. ); // IE cannot download from sessions without a cache
  288. }
  289. header('Content-Description: ' . $filename);
  290. header('Content-transfer-encoding: binary');
  291. echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
  292. echo api_html_entity_decode($line, ENT_QUOTES, $charset);
  293. exit;
  294. } else { // not allowed
  295. api_not_allowed();
  296. }