userlogCSV.php 12 KB

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