userlogCSV.php 13 KB

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