userlogCSV.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. /* INIT SECTION */
  9. $uInfo = $_REQUEST['uInfo'];
  10. $view = $_REQUEST['view'];
  11. // name of the language file that needs to be included
  12. $language_file = 'tracking';
  13. require_once '../inc/global.inc.php';
  14. // Roles and rights system
  15. $user_id = api_get_user_id();
  16. $course_id = api_get_course_id();
  17. /*
  18. $role_id = RolesRights::get_local_user_role_id($user_id, $course_id);
  19. $location_id = RolesRights::get_course_tool_location_id($course_id, TOOL_TRACKING);
  20. $is_allowed = RolesRights::is_allowed_which_rights($role_id, $location_id);
  21. //block users without view right
  22. RolesRights::protect_location($role_id, $location_id);
  23. */
  24. //YW Hack security to quick fix RolesRights bug
  25. $is_allowed = true;
  26. /* Libraries */
  27. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  28. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  29. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  30. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  31. /* Header */
  32. /*
  33. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  34. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  35. */
  36. if($uInfo)
  37. {
  38. $interbreadcrumb[]= array ("url"=>"../user/userInfo.php?uInfo=$uInfo", "name"=> get_lang('BredCrumpUsers'));
  39. }
  40. $nameTools = get_lang('ToolName');
  41. /* Constants and variables */
  42. $is_allowedToTrack = $is_courseAdmin;
  43. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  44. // Database Table Definitions
  45. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  46. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  47. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  48. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  49. $TABLETRACK_ACCESS = $_configuration['statistics_database']."`.`track_e_access";
  50. $TABLETRACK_LINKS = $_configuration['statistics_database']."`.`track_e_links";
  51. $TABLETRACK_LOGIN = $_configuration['statistics_database']."`.`track_e_login";
  52. $TABLETRACK_DOWNLOADS = $_configuration['statistics_database']."`.`track_e_downloads";
  53. $TABLETRACK_UPLOADS = $_configuration['statistics_database']."`.`track_e_uploads";
  54. $TABLETRACK_EXERCICES = $_configuration['statistics_database']."`.`track_e_exercices";
  55. $TABLETRACK_HOTPOTATOES = $_configuration['statistics_database']."`.`track_e_hotpotatoes";
  56. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  57. $TABLECOURSE_WORK = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  58. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  59. $TABLECOURSE_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  60. //$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  61. if(api_get_setting('use_session_mode') == "true") {
  62. $sql = "SELECT 1
  63. FROM $tbl_session_course_user AS session_course_user
  64. INNER JOIN $tbl_session AS session
  65. ON session_course_user.id_session = session.id
  66. AND ((date_start<=NOW()
  67. AND date_end>=NOW())
  68. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  69. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  70. //echo $sql;
  71. $result=Database::query($sql);
  72. if(!Database::num_rows($result)){
  73. $disabled = true;
  74. }
  75. }
  76. $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
  77. $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
  78. $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
  79. $tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  80. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  81. // The variables for the days and the months
  82. $DaysShort = api_get_week_days_short();
  83. $DaysLong = api_get_week_days_long();
  84. $MonthsLong = api_get_months_long();
  85. $MonthsShort = api_get_months_short();
  86. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  87. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  88. //YW hack security to fix RolesRights bug
  89. $is_allowedToTrack = true; // allowed to track only user of one group
  90. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  91. /* MAIN SECTION */
  92. $title[0]='';
  93. $title[1]='';
  94. $line='';
  95. $title_line='';
  96. // check if uid is tutor of this group
  97. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $_configuration['tracking_enabled'] )
  98. {
  99. if(!$uInfo && !isset($uInfo) )
  100. {
  101. /*
  102. * Display list of user of this group
  103. */
  104. if( $is_allowedToTrackEverybodyInCourse )
  105. {
  106. // if user can track everybody : list user of course
  107. if(api_get_setting('use_session_mode')) {
  108. $sql = "SELECT count(user_id)
  109. FROM $TABLECOURSUSER
  110. WHERE `course_code` = '$_cid' AND relation_type<>".COURSE_RELATION_TYPE_RRHH."";
  111. }
  112. else {
  113. $sql = "SELECT count(id_user)
  114. FROM $tbl_session_course_user
  115. WHERE `course_code` = '$_cid'";
  116. }
  117. }
  118. else
  119. {
  120. // if user can only track one group : list users of this group
  121. $sql = "SELECT count(user)
  122. FROM $TABLECOURSE_GROUPSUSER
  123. WHERE `group_id` = '$_gid'";
  124. }
  125. $userGroupNb = getOneResult($sql);
  126. $step = 25; // number of student per page
  127. if ($userGroupNb > $step)
  128. {
  129. if(!isset($offset))
  130. {
  131. $offset=0;
  132. }
  133. $next = $offset + $step;
  134. $previous = $offset - $step;
  135. $navLink = "";
  136. if ($previous >= 0)
  137. {
  138. }
  139. if ($next < $userGroupNb)
  140. {
  141. }
  142. }
  143. else
  144. {
  145. $offset = 0;
  146. }
  147. echo $navLink;
  148. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  149. if( $is_allowedToTrackEverybodyInCourse )
  150. {
  151. // list of users in this course
  152. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  153. FROM $TABLECOURSUSER cu , $TABLEUSER u
  154. WHERE `cu`.`user_id` = `u`.`user_id` AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  155. AND `cu`.`course_code` = '$_cid'
  156. LIMIT $offset,$step";
  157. }
  158. else
  159. {
  160. // list of users of this group
  161. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  162. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  163. WHERE `gu`.`user_id` = `u`.`user_id`
  164. AND `gu`.`group_id` = '$_gid'
  165. LIMIT $offset,$step";
  166. }
  167. $list_users = getManyResults3Col($sql);
  168. for($i = 0 ; $i < sizeof($list_users) ; $i++)
  169. {
  170. }
  171. }
  172. else // if uInfo is set
  173. {
  174. /*
  175. * Informations about student uInfo
  176. */
  177. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  178. // another course, or group
  179. if( $is_allowedToTrackEverybodyInCourse )
  180. {
  181. // check if user is in this course
  182. $tracking_is_accepted = $is_course_member;
  183. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  184. $title[0]=$tracked_user_info[1].'_'.$tracked_user_info[2];
  185. }
  186. else
  187. {
  188. // check if user is in the group of this tutor
  189. $sql = "SELECT `u`.`firstname`,`u`.`lastname`, `u`.`email`
  190. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  191. WHERE `gu`.`user_id` = `u`.`user_id`
  192. AND `gu`.`group_id` = '$_gid'
  193. AND `u`.`user_id` = '$uInfo'";
  194. $query = Database::query($sql);
  195. $tracked_user_info = @Database::fetch_assoc($query);
  196. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  197. $title[0] = $tracked_user_info['firstname'].'_'.$tracked_user_info['lastname'];
  198. }
  199. if ($tracking_is_accepted)
  200. {
  201. $tracked_user_info['email'] == '' ? $mail_link = get_lang('NoEmail') : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  202. if(!isset($view))
  203. {
  204. $view ='0000000';
  205. }
  206. //Logins
  207. list($title_line1, $line1) = TrackingUserLogCSV::display_login_tracking_info($view, $uInfo, $_cid);
  208. //Exercise results
  209. list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info($view, $uInfo, $_cid);
  210. //Student publications uploaded
  211. list($title_line3, $line3) = TrackingUserLogCSV::display_student_publications_tracking_info($view, $uInfo, $_cid);
  212. //Links usage
  213. list($title_line4, $line4) = TrackingUserLogCSV::display_links_tracking_info($view, $uInfo, $_cid);
  214. //Documents downloaded
  215. list($title_line5, $line5) = TrackingUserLogCSV::display_document_tracking_info($view, $uInfo, $_cid);
  216. $title_line = $title_line1.$title_line2.$title_line3.$title_line4.$title_line5;
  217. $line= $line1.$line2.$line3.$line4.$line5;
  218. }
  219. else
  220. {
  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(str_replace(":","",str_replace(" ","_", $title[0].'_'.$title[1].'.csv')));
  288. $filename = replace_dangerous_char($filename);
  289. if(preg_match("/MSIE 5.5/",$_SERVER['HTTP_USER_AGENT']))
  290. {
  291. header('Content-Disposition: filename= '.$filename);
  292. }
  293. else
  294. {
  295. header('Content-Disposition: attachment; filename= '.$filename);
  296. }
  297. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  298. {
  299. header('Pragma: ');
  300. header('Cache-Control: ');
  301. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  302. }
  303. header('Content-Description: '.$filename);
  304. header('Content-transfer-encoding: binary');
  305. echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
  306. echo api_html_entity_decode($line, ENT_QUOTES, $charset);
  307. exit;
  308. }
  309. // not allowed
  310. else
  311. {
  312. if(!$_configuration['tracking_enabled'])
  313. {
  314. echo get_lang('TrackingDisabled');
  315. }
  316. else
  317. {
  318. api_not_allowed();
  319. }
  320. }