userlogCSV.php 12 KB

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