userlogCSV.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2006 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
  9. Copyright (c) Sebastien Piraux <piraux_seb@hotmail.com>
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. // TODO: Is this file deprecated?
  21. /**
  22. ==============================================================================
  23. * @package dokeos.tracking
  24. * @todo clean code - structure is unclear and difficult to modify
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. INIT SECTION
  30. ==============================================================================
  31. */
  32. $uInfo = $_REQUEST['uInfo'];
  33. $view = $_REQUEST['view'];
  34. // name of the language file that needs to be included
  35. $language_file = 'tracking';
  36. include('../inc/global.inc.php');
  37. // Roles and rights system
  38. $user_id = api_get_user_id();
  39. $course_id = api_get_course_id();
  40. /*
  41. $role_id = RolesRights::get_local_user_role_id($user_id, $course_id);
  42. $location_id = RolesRights::get_course_tool_location_id($course_id, TOOL_TRACKING);
  43. $is_allowed = RolesRights::is_allowed_which_rights($role_id, $location_id);
  44. //block users without view right
  45. RolesRights::protect_location($role_id, $location_id);
  46. */
  47. //YW Hack security to quick fix RolesRights bug
  48. $is_allowed = true;
  49. /*
  50. -----------------------------------------------------------
  51. Libraries
  52. -----------------------------------------------------------
  53. */
  54. include(api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php');
  55. include(api_get_path(LIBRARY_PATH).'course.lib.php');
  56. include(api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php');
  57. require_once(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');
  58. /*
  59. -----------------------------------------------------------
  60. Header
  61. -----------------------------------------------------------
  62. */
  63. // charset determination
  64. if ($_GET['scormcontopen'])
  65. {
  66. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  67. $contopen = (int) $_GET['scormcontopen'];
  68. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$contopen;
  69. $res = Database::query($sql);
  70. $row = Database::fetch_array($res);
  71. $lp_charset = $row['default_encoding'];
  72. //header('Content-Type: text/html; charset='. $row['default_encoding']);
  73. }
  74. /*
  75. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  76. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  77. */
  78. if($uInfo)
  79. {
  80. $interbreadcrumb[]= array ("url"=>"../user/userInfo.php?uInfo=$uInfo", "name"=> get_lang('BredCrumpUsers'));
  81. }
  82. $nameTools = get_lang('ToolName');
  83. /*
  84. -----------------------------------------------------------
  85. Constants and variables
  86. -----------------------------------------------------------
  87. */
  88. $is_allowedToTrack = $is_courseAdmin;
  89. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  90. // Database Table Definitions
  91. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  92. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  93. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  94. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  95. $TABLETRACK_ACCESS = $_configuration['statistics_database']."`.`track_e_access";
  96. $TABLETRACK_LINKS = $_configuration['statistics_database']."`.`track_e_links";
  97. $TABLETRACK_LOGIN = $_configuration['statistics_database']."`.`track_e_login";
  98. $TABLETRACK_DOWNLOADS = $_configuration['statistics_database']."`.`track_e_downloads";
  99. $TABLETRACK_UPLOADS = $_configuration['statistics_database']."`.`track_e_uploads";
  100. $TABLETRACK_EXERCICES = $_configuration['statistics_database']."`.`track_e_exercices";
  101. $TABLETRACK_HOTPOTATOES = $_configuration['statistics_database']."`.`track_e_hotpotatoes";
  102. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  103. $TABLECOURSE_WORK = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  104. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  105. $TABLECOURSE_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  106. //$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  107. if(api_get_setting('use_session_mode') == "true") {
  108. $sql = "SELECT 1
  109. FROM $tbl_session_course_user AS session_course_user
  110. INNER JOIN $tbl_session AS session
  111. ON session_course_user.id_session = session.id
  112. AND ((date_start<=NOW()
  113. AND date_end>=NOW())
  114. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  115. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  116. //echo $sql;
  117. $result=Database::query($sql);
  118. if(!Database::num_rows($result)){
  119. $disabled = true;
  120. }
  121. }
  122. $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
  123. $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
  124. $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
  125. $tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  126. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  127. // The variables for the days and the months
  128. $DaysShort = api_get_week_days_short();
  129. $DaysLong = api_get_week_days_long();
  130. $MonthsLong = api_get_months_long();
  131. $MonthsShort = api_get_months_short();
  132. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  133. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  134. //YW hack security to fix RolesRights bug
  135. $is_allowedToTrack = true; // allowed to track only user of one group
  136. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  137. /*
  138. ==============================================================================
  139. MAIN SECTION
  140. ==============================================================================
  141. */
  142. $title[0]='';
  143. $title[1]='';
  144. $line='';
  145. $title_line='';
  146. // check if uid is tutor of this group
  147. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $_configuration['tracking_enabled'] )
  148. {
  149. if(!$uInfo && !isset($uInfo) )
  150. {
  151. /***************************************************************************
  152. *
  153. * Display list of user of this group
  154. *
  155. ***************************************************************************/
  156. if( $is_allowedToTrackEverybodyInCourse )
  157. {
  158. // if user can track everybody : list user of course
  159. if(api_get_setting('use_session_mode')) {
  160. $sql = "SELECT count(user_id)
  161. FROM $TABLECOURSUSER
  162. WHERE `course_code` = '$_cid' AND relation_type<>".COURSE_RELATION_TYPE_RRHH."";
  163. }
  164. else {
  165. $sql = "SELECT count(id_user)
  166. FROM $tbl_session_course_user
  167. WHERE `course_code` = '$_cid'";
  168. }
  169. }
  170. else
  171. {
  172. // if user can only track one group : list users of this group
  173. $sql = "SELECT count(user)
  174. FROM $TABLECOURSE_GROUPSUSER
  175. WHERE `group_id` = '$_gid'";
  176. }
  177. $userGroupNb = getOneResult($sql);
  178. $step = 25; // number of student per page
  179. if ($userGroupNb > $step)
  180. {
  181. if(!isset($offset))
  182. {
  183. $offset=0;
  184. }
  185. $next = $offset + $step;
  186. $previous = $offset - $step;
  187. $navLink = "";
  188. if ($previous >= 0)
  189. {
  190. }
  191. if ($next < $userGroupNb)
  192. {
  193. }
  194. }
  195. else
  196. {
  197. $offset = 0;
  198. }
  199. echo $navLink;
  200. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  201. if( $is_allowedToTrackEverybodyInCourse )
  202. {
  203. // list of users in this course
  204. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  205. FROM $TABLECOURSUSER cu , $TABLEUSER u
  206. WHERE `cu`.`user_id` = `u`.`user_id` AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  207. AND `cu`.`course_code` = '$_cid'
  208. LIMIT $offset,$step";
  209. }
  210. else
  211. {
  212. // list of users of this group
  213. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  214. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  215. WHERE `gu`.`user_id` = `u`.`user_id`
  216. AND `gu`.`group_id` = '$_gid'
  217. LIMIT $offset,$step";
  218. }
  219. $list_users = getManyResults3Col($sql);
  220. for($i = 0 ; $i < sizeof($list_users) ; $i++)
  221. {
  222. }
  223. }
  224. else // if uInfo is set
  225. {
  226. /***************************************************************************
  227. *
  228. * Informations about student uInfo
  229. *
  230. ***************************************************************************/
  231. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  232. // another course, or group
  233. if( $is_allowedToTrackEverybodyInCourse )
  234. {
  235. // check if user is in this course
  236. $tracking_is_accepted = $is_course_member;
  237. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  238. $title[0]=$tracked_user_info[1].'_'.$tracked_user_info[2];
  239. }
  240. else
  241. {
  242. // check if user is in the group of this tutor
  243. $sql = "SELECT `u`.`firstname`,`u`.`lastname`, `u`.`email`
  244. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  245. WHERE `gu`.`user_id` = `u`.`user_id`
  246. AND `gu`.`group_id` = '$_gid'
  247. AND `u`.`user_id` = '$uInfo'";
  248. $query = Database::query($sql);
  249. $tracked_user_info = @Database::fetch_assoc($query);
  250. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  251. $title[0] = $tracked_user_info['firstname'].'_'.$tracked_user_info['lastname'];
  252. }
  253. if ($tracking_is_accepted)
  254. {
  255. $tracked_user_info['email'] == '' ? $mail_link = get_lang('NoEmail') : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  256. if(!isset($view))
  257. {
  258. $view ='0000000';
  259. }
  260. //Logins
  261. list($title_line1, $line1) = TrackingUserLogCSV::display_login_tracking_info($view, $uInfo, $_cid);
  262. //Exercise results
  263. list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info($view, $uInfo, $_cid);
  264. //Student publications uploaded
  265. list($title_line3, $line3) = TrackingUserLogCSV::display_student_publications_tracking_info($view, $uInfo, $_cid);
  266. //Links usage
  267. list($title_line4, $line4) = TrackingUserLogCSV::display_links_tracking_info($view, $uInfo, $_cid);
  268. //Documents downloaded
  269. list($title_line5, $line5) = TrackingUserLogCSV::display_document_tracking_info($view, $uInfo, $_cid);
  270. $title_line = $title_line1.$title_line2.$title_line3.$title_line4.$title_line5;
  271. $line= $line1.$line2.$line3.$line4.$line5;
  272. }
  273. else
  274. {
  275. echo get_lang('ErrorUserNotInGroup');
  276. }
  277. /***************************************************************************
  278. *
  279. * Scorm contents and Learning Path
  280. *
  281. ***************************************************************************/
  282. //TODO: scorm tools is in work and the logs will change in few days...
  283. /*if(substr($view,5,1) == '1')
  284. {
  285. $new_view = substr_replace($view,'0',5,1);
  286. $title[1]=get_lang('ScormContentColumn');
  287. $line ='';
  288. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  289. $result=Database::query($sql);
  290. $ar=Database::fetch_array($result);
  291. if (is_array($ar))
  292. {
  293. while ($ar['id'] != '') {
  294. $lp_title = stripslashes($ar['name']);
  295. echo "<tr><td>";
  296. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
  297. echo "</td></tr>";
  298. if ($ar['id']==$scormcontopen) { //have to list the students here
  299. $contentId=$ar['id'];
  300. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  301. "FROM $tbl_learnpath_item i " .
  302. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  303. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  304. "WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
  305. $result3=Database::query($sql3);
  306. $ar3=Database::fetch_array($result3);
  307. if (is_array($ar3)) {
  308. $title_line=get_lang('ScormTitleColumn').";".get_lang('ScormStatusColumn').";".get_lang('ScormScoreColumn').";".get_lang('ScormTimeColumn')."\n";
  309. while ($ar3['status'] != '') {
  310. require_once('../newscorm/learnpathItem.class.php');
  311. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  312. $title = api_htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  313. $line .= $title.';'.$ar3['status'].';'.$ar3['score'].';'.$time."\n";
  314. $ar3=Database::fetch_array($result3);
  315. }
  316. } else {
  317. $line .= get_lang('ScormNeverOpened');
  318. }
  319. }
  320. $ar=Database::fetch_array($result);
  321. }
  322. }
  323. else
  324. {
  325. $noscorm=true;
  326. }
  327. if ($noscorm) {
  328. $line=get_lang('NoResult');
  329. }
  330. }
  331. else
  332. {
  333. $new_view = substr_replace($view,'1',5,1);
  334. }*/
  335. }
  336. /***************************************************************************
  337. *
  338. * Export to a CSV file
  339. * force the browser to save the file instead of opening it
  340. ***************************************************************************/
  341. $len = strlen($title_line.$line);
  342. header('Content-type: application/octet-stream');
  343. //header('Content-Type: application/force-download');
  344. header('Content-length: '.$len);
  345. $filename = html_entity_decode(str_replace(":","",str_replace(" ","_", $title[0].'_'.$title[1].'.csv')));
  346. if(preg_match("/MSIE 5.5/",$_SERVER['HTTP_USER_AGENT']))
  347. {
  348. header('Content-Disposition: filename= '.$filename);
  349. }
  350. else
  351. {
  352. header('Content-Disposition: attachment; filename= '.$filename);
  353. }
  354. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  355. {
  356. header('Pragma: ');
  357. header('Cache-Control: ');
  358. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  359. }
  360. header('Content-Description: '.$filename);
  361. header('Content-transfer-encoding: binary');
  362. echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
  363. echo api_html_entity_decode($line, ENT_QUOTES, $charset);
  364. exit;
  365. }
  366. // not allowed
  367. else
  368. {
  369. if(!$_configuration['tracking_enabled'])
  370. {
  371. echo get_lang('TrackingDisabled');
  372. }
  373. else
  374. {
  375. api_not_allowed();
  376. }
  377. }