userlogCSV.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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,__FILE__,__LINE__);
  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,__FILE__,__LINE__);
  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. // Defining the shorts for the days
  129. // TODO: The function myEnc() should be eliminated. The following arrays should be constructed using the correspondent API-functions in the internationalization library.
  130. $DaysShort = array (myEnc(get_lang("SundayShort")), myEnc(get_lang("MondayShort")), myEnc(get_lang("TuesdayShort")), myEnc(get_lang("WednesdayShort")), myEnc(get_lang("ThursdayShort")), myEnc(get_lang("FridayShort")), myEnc(get_lang("SaturdayShort")));
  131. // Defining the days of the week to allow translation of the days
  132. $DaysLong = array (myEnc(get_lang("SundayLong")), myEnc(get_lang("MondayLong")), myEnc(get_lang("TuesdayLong")), myEnc(get_lang("WednesdayLong")), myEnc(get_lang("ThursdayLong")), myEnc(get_lang("FridayLong")), myEnc(get_lang("SaturdayLong")));
  133. // Defining the months of the year to allow translation of the months
  134. $MonthsLong = array (myEnc(get_lang("JanuaryLong")), myEnc(get_lang("FebruaryLong")), myEnc(get_lang("MarchLong")), myEnc(get_lang("AprilLong")), myEnc(get_lang("MayLong")), myEnc(get_lang("JuneLong")), myEnc(get_lang("JulyLong")), myEnc(get_lang("AugustLong")), myEnc(get_lang("SeptemberLong")), myEnc(get_lang("OctoberLong")), myEnc(get_lang("NovemberLong")), myEnc(get_lang("DecemberLong")));
  135. // Defining the months of the year to allow translation of the months
  136. $MonthsShort = array (myEnc(get_lang("JanuaryShort")), myEnc(get_lang("FebruaryShort")), myEnc(get_lang("MarchShort")), myEnc(get_lang("AprilShort")), myEnc(get_lang("MayShort")), myEnc(get_lang("JuneShort")), myEnc(get_lang("JulyShort")), myEnc(get_lang("AugustShort")), myEnc(get_lang("SeptemberShort")), myEnc(get_lang("OctoberShort")), myEnc(get_lang("NovemberShort")), myEnc(get_lang("DecemberShort")));
  137. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  138. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  139. //YW hack security to fix RolesRights bug
  140. $is_allowedToTrack = true; // allowed to track only user of one group
  141. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  142. /*
  143. ==============================================================================
  144. FUNCTIONS
  145. ==============================================================================
  146. */
  147. /**
  148. * Shortcut function to use htmlentities on many, many strings in this script
  149. * @param string String in a supposed encoding
  150. * @param string Supposed initial encoding (default: 'ISO-8859-15')
  151. * @return string HTML string (no encoding dependency)
  152. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  153. */
  154. function myEnc($isostring,$supposed_encoding='ISO-8859-15')
  155. {
  156. return api_htmlentities($isostring,ENT_QUOTES,$supposed_encoding);
  157. }
  158. /**
  159. * Displays the number of logins every month for a specific user in a specific course.
  160. */
  161. function display_login_tracking_info($view, $user_id, $course_id)
  162. {
  163. $MonthsLong = $GLOBALS['MonthsLong'];
  164. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  165. $tempView = $view;
  166. if(substr($view,0,1) == '1')
  167. {
  168. $new_view = substr_replace($view,'0',0,1);
  169. $title[1]= myEnc(get_lang('LoginsAndAccessTools')).myEnc(get_lang('LoginsDetails'));
  170. $sql = "SELECT UNIX_TIMESTAMP(`access_date`), count(`access_date`)
  171. FROM $track_access_table
  172. WHERE `access_user_id` = '$user_id'
  173. AND `access_cours_code` = '".$course_id."'
  174. GROUP BY YEAR(`access_date`),MONTH(`access_date`)
  175. ORDER BY YEAR(`access_date`),MONTH(`access_date`) ASC";
  176. //$results = getManyResults2Col($sql);
  177. $results = getManyResults3Col($sql);
  178. $title_line= myEnc(get_lang('LoginsTitleMonthColumn')).';'.myEnc(get_lang('LoginsTitleCountColumn'))."\n";
  179. $line='';
  180. $total = 0;
  181. if (is_array($results))
  182. {
  183. for($j = 0 ; $j < count($results) ; $j++)
  184. {
  185. $line .= $results[$j][0].';'.$results[$j][1]."\n";
  186. $total = $total + $results[$j][1];
  187. }
  188. $line .= myEnc(get_lang('Total')).";".$total."\n";
  189. }
  190. else
  191. {
  192. $line= myEnc(get_lang('NoResult'))."</center></td>";
  193. }
  194. }
  195. else
  196. {
  197. $new_view = substr_replace($view,'1',0,1);
  198. }
  199. return array($title_line, $line);
  200. }
  201. /**
  202. * Displays the exercise results for a specific user in a specific course.
  203. * @todo remove globals
  204. */
  205. function display_exercise_tracking_info($view, $user_id, $course_id)
  206. {
  207. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES;
  208. if(substr($view,1,1) == '1')
  209. {
  210. $new_view = substr_replace($view,'0',1,1);
  211. $title[1]= myEnc(get_lang('ExercicesDetails'));
  212. $line='';
  213. $sql = "SELECT `ce`.`title`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  214. FROM $TABLECOURSE_EXERCICES AS ce , `$TABLETRACK_EXERCICES` AS `te`
  215. WHERE `te`.`exe_cours_id` = '$course_id'
  216. AND `te`.`exe_user_id` = '$user_id'
  217. AND `te`.`exe_exo_id` = `ce`.`id`
  218. ORDER BY `ce`.`title` ASC, `te`.`exe_date` ASC";
  219. $hpsql = "SELECT `te`.`exe_name`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  220. FROM `$TABLETRACK_HOTPOTATOES` AS te
  221. WHERE `te`.`exe_user_id` = '$user_id' AND `te`.`exe_cours_id` = '$course_id'
  222. ORDER BY `te`.`exe_cours_id` ASC, `te`.`exe_date` ASC";
  223. $hpresults = getManyResultsXCol($hpsql, 4);
  224. $NoTestRes = 0;
  225. $NoHPTestRes = 0;
  226. $results = getManyResultsXCol($sql, 4);
  227. $title_line=myEnc(get_lang('ExercicesTitleExerciceColumn')).";".myEnc(get_lang('Date')).';'.myEnc(get_lang('ExercicesTitleScoreColumn'))."\n";
  228. if (is_array($results))
  229. {
  230. for($i = 0; $i < sizeof($results); $i++)
  231. {
  232. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]);
  233. $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
  234. }
  235. }
  236. else // istvan begin
  237. {
  238. $NoTestRes = 1;
  239. }
  240. // The Result of Tests
  241. if(is_array($hpresults))
  242. {
  243. for($i = 0; $i < sizeof($hpresults); $i++)
  244. {
  245. $title = GetQuizName($hpresults[$i][0],'');
  246. if ($title == '')
  247. $title = basename($hpresults[$i][0]);
  248. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]);
  249. $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
  250. }
  251. }
  252. else
  253. {
  254. $NoHPTestRes = 1;
  255. }
  256. if ($NoTestRes == 1 && $NoHPTestRes == 1)
  257. {
  258. $line=get_lang('NoResult');
  259. }
  260. }
  261. else
  262. {
  263. $new_view = substr_replace($view,'1',1,1);
  264. }
  265. return array($title_line, $line);
  266. }
  267. /**
  268. * Displays the student publications for a specific user in a specific course.
  269. * @todo remove globals
  270. */
  271. function display_student_publications_tracking_info($view, $user_id, $course_id)
  272. {
  273. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong;
  274. if(substr($view,2,1) == '1')
  275. {
  276. $new_view = substr_replace($view,'0',2,1);
  277. $sql = "SELECT `u`.`upload_date`, `w`.`title`, `w`.`author`,`w`.`url`
  278. FROM `$TABLETRACK_UPLOADS` `u` , $TABLECOURSE_WORK `w`
  279. WHERE `u`.`upload_work_id` = `w`.`id`
  280. AND `u`.`upload_user_id` = '$user_id'
  281. AND `u`.`upload_cours_id` = '$course_id'
  282. ORDER BY `u`.`upload_date` DESC";
  283. $results = getManyResultsXCol($sql,4);
  284. $title[1]=myEnc(get_lang('WorksDetails'));
  285. $line='';
  286. $title_line=myEnc(get_lang('WorkTitle')).";".myEnc(get_lang('WorkAuthors')).";".myEnc(get_lang('Date'))."\n";
  287. if (is_array($results))
  288. {
  289. for($j = 0 ; $j < count($results) ; $j++)
  290. {
  291. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  292. $timestamp = strtotime($results[$j][0]);
  293. $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp);
  294. $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
  295. }
  296. }
  297. else
  298. {
  299. $line= myEnc(get_lang('NoResult'));
  300. }
  301. }
  302. else
  303. {
  304. $new_view = substr_replace($view,'1',2,1);
  305. }
  306. return array($title_line, $line);
  307. }
  308. /**
  309. * Displays the links followed for a specific user in a specific course.
  310. * @todo remove globals
  311. */
  312. function display_links_tracking_info($view, $user_id, $course_id)
  313. {
  314. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  315. if(substr($view,3,1) == '1')
  316. {
  317. $new_view = substr_replace($view,'0',3,1);
  318. $title[1]=myEnc(get_lang('LinksDetails'));
  319. $sql = "SELECT `cl`.`title`, `cl`.`url`
  320. FROM `$TABLETRACK_LINKS` AS sl, $TABLECOURSE_LINKS AS cl
  321. WHERE `sl`.`links_link_id` = `cl`.`id`
  322. AND `sl`.`links_cours_id` = '$course_id'
  323. AND `sl`.`links_user_id` = '$user_id'
  324. GROUP BY `cl`.`title`, `cl`.`url`";
  325. $results = getManyResults2Col($sql);
  326. $title_line= myEnc(get_lang('LinksTitleLinkColumn'))."\n";
  327. if (is_array($results))
  328. {
  329. for($j = 0 ; $j < count($results) ; $j++)
  330. {
  331. $line .= $results[$j][0]."\n";
  332. }
  333. }
  334. else
  335. {
  336. $line=myEnc(get_lang('NoResult'));
  337. }
  338. }
  339. else
  340. {
  341. $new_view = substr_replace($view,'1',3,1);
  342. }
  343. return array($title_line, $line);
  344. }
  345. /**
  346. * Displays the documents downloaded for a specific user in a specific course.
  347. */
  348. function display_document_tracking_info($view, $user_id, $course_id)
  349. {
  350. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  351. if(substr($view,4,1) == '1')
  352. {
  353. $new_view = substr_replace($view,'0',4,1);
  354. $title[1]= myEnc(get_lang('DocumentsDetails'));
  355. $sql = "SELECT `down_doc_path`
  356. FROM $downloads_table
  357. WHERE `down_cours_id` = '$course_id'
  358. AND `down_user_id` = '$user_id'
  359. GROUP BY `down_doc_path`";
  360. $results = getManyResults1Col($sql);
  361. $title_line = myEnc(get_lang('DocumentsTitleDocumentColumn'))."\n";
  362. if (is_array($results))
  363. {
  364. for($j = 0 ; $j < count($results) ; $j++)
  365. {
  366. $line .= $results[$j]."\n";
  367. }
  368. }
  369. else
  370. {
  371. $line=myEnc(get_lang('NoResult'));
  372. }
  373. }
  374. else
  375. {
  376. $new_view = substr_replace($view,'1',4,1);
  377. }
  378. return array($title_line, $line);
  379. }
  380. /*
  381. ==============================================================================
  382. MAIN SECTION
  383. ==============================================================================
  384. */
  385. $title[0]='';
  386. $title[1]='';
  387. $line='';
  388. $title_line='';
  389. // check if uid is tutor of this group
  390. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $_configuration['tracking_enabled'] )
  391. {
  392. if(!$uInfo && !isset($uInfo) )
  393. {
  394. /***************************************************************************
  395. *
  396. * Display list of user of this group
  397. *
  398. ***************************************************************************/
  399. if( $is_allowedToTrackEverybodyInCourse )
  400. {
  401. // if user can track everybody : list user of course
  402. if(api_get_setting('use_session_mode')) {
  403. $sql = "SELECT count(user_id)
  404. FROM $TABLECOURSUSER
  405. WHERE `course_code` = '$_cid'";
  406. }
  407. else {
  408. $sql = "SELECT count(id_user)
  409. FROM $tbl_session_course_user
  410. WHERE `course_code` = '$_cid'";
  411. }
  412. }
  413. else
  414. {
  415. // if user can only track one group : list users of this group
  416. $sql = "SELECT count(user)
  417. FROM $TABLECOURSE_GROUPSUSER
  418. WHERE `group_id` = '$_gid'";
  419. }
  420. $userGroupNb = getOneResult($sql);
  421. $step = 25; // number of student per page
  422. if ($userGroupNb > $step)
  423. {
  424. if(!isset($offset))
  425. {
  426. $offset=0;
  427. }
  428. $next = $offset + $step;
  429. $previous = $offset - $step;
  430. $navLink = "";
  431. if ($previous >= 0)
  432. {
  433. }
  434. if ($next < $userGroupNb)
  435. {
  436. }
  437. }
  438. else
  439. {
  440. $offset = 0;
  441. }
  442. echo $navLink;
  443. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  444. if( $is_allowedToTrackEverybodyInCourse )
  445. {
  446. // list of users in this course
  447. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  448. FROM $TABLECOURSUSER cu , $TABLEUSER u
  449. WHERE `cu`.`user_id` = `u`.`user_id`
  450. AND `cu`.`course_code` = '$_cid'
  451. LIMIT $offset,$step";
  452. }
  453. else
  454. {
  455. // list of users of this group
  456. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  457. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  458. WHERE `gu`.`user_id` = `u`.`user_id`
  459. AND `gu`.`group_id` = '$_gid'
  460. LIMIT $offset,$step";
  461. }
  462. $list_users = getManyResults3Col($sql);
  463. for($i = 0 ; $i < sizeof($list_users) ; $i++)
  464. {
  465. }
  466. }
  467. else // if uInfo is set
  468. {
  469. /***************************************************************************
  470. *
  471. * Informations about student uInfo
  472. *
  473. ***************************************************************************/
  474. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  475. // another course, or group
  476. if( $is_allowedToTrackEverybodyInCourse )
  477. {
  478. // check if user is in this course
  479. $tracking_is_accepted = $is_course_member;
  480. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  481. $title[0]=$tracked_user_info[1].'_'.$tracked_user_info[2];
  482. }
  483. else
  484. {
  485. // check if user is in the group of this tutor
  486. $sql = "SELECT `u`.`firstname`,`u`.`lastname`, `u`.`email`
  487. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  488. WHERE `gu`.`user_id` = `u`.`user_id`
  489. AND `gu`.`group_id` = '$_gid'
  490. AND `u`.`user_id` = '$uInfo'";
  491. $query = Database::query($sql,__FILE__,__LINE__);
  492. $tracked_user_info = @mysql_fetch_assoc($query);
  493. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  494. $title[0] = $tracked_user_info['firstname'].'_'.$tracked_user_info['lastname'];
  495. }
  496. if ($tracking_is_accepted)
  497. {
  498. $tracked_user_info['email'] == '' ? $mail_link = myEnc(get_lang('NoEmail')) : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  499. if(!isset($view))
  500. {
  501. $view ='0000000';
  502. }
  503. //Logins
  504. list($title_line1, $line1) = display_login_tracking_info($view, $uInfo, $_cid);
  505. //Exercise results
  506. list($title_line2, $line2) = display_exercise_tracking_info($view, $uInfo, $_cid);
  507. //Student publications uploaded
  508. list($title_line3, $line3) = display_student_publications_tracking_info($view, $uInfo, $_cid);
  509. //Links usage
  510. list($title_line4, $line4) = display_links_tracking_info($view, $uInfo, $_cid);
  511. //Documents downloaded
  512. list($title_line5, $line5) = display_document_tracking_info($view, $uInfo, $_cid);
  513. $title_line = $title_line1.$title_line2.$title_line3.$title_line4.$title_line5;
  514. $line= $line1.$line2.$line3.$line4.$line5;
  515. }
  516. else
  517. {
  518. echo myEnc(get_lang('ErrorUserNotInGroup'));
  519. }
  520. /***************************************************************************
  521. *
  522. * Scorm contents and Learning Path
  523. *
  524. ***************************************************************************/
  525. //TODO: scorm tools is in work and the logs will change in few days...
  526. /*if(substr($view,5,1) == '1')
  527. {
  528. $new_view = substr_replace($view,'0',5,1);
  529. $title[1]=myEnc(get_lang('ScormContentColumn'));
  530. $line ='';
  531. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  532. $result=Database::query($sql,__FILE__,__LINE__);
  533. $ar=Database::fetch_array($result);
  534. if (is_array($ar))
  535. {
  536. while ($ar['id'] != '') {
  537. $lp_title = stripslashes($ar['name']);
  538. echo "<tr><td>";
  539. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
  540. echo "</td></tr>";
  541. if ($ar['id']==$scormcontopen) { //have to list the students here
  542. $contentId=$ar['id'];
  543. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  544. "FROM $tbl_learnpath_item i " .
  545. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  546. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  547. "WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
  548. $result3=Database::query($sql3,__FILE__,__LINE__);
  549. $ar3=Database::fetch_array($result3);
  550. if (is_array($ar3)) {
  551. $title_line=myEnc(get_lang('ScormTitleColumn')).";".myEnc(get_lang('ScormStatusColumn')).";".myEnc(get_lang('ScormScoreColumn')).";".myEnc(get_lang('ScormTimeColumn'))."\n";
  552. while ($ar3['status'] != '') {
  553. require_once('../newscorm/learnpathItem.class.php');
  554. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  555. $title = api_htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  556. $line .= $title.';'.$ar3['status'].';'.$ar3['score'].';'.$time."\n";
  557. $ar3=Database::fetch_array($result3);
  558. }
  559. } else {
  560. $line .= myEnc(get_lang('ScormNeverOpened'));
  561. }
  562. }
  563. $ar=Database::fetch_array($result);
  564. }
  565. }
  566. else
  567. {
  568. $noscorm=true;
  569. }
  570. if ($noscorm) {
  571. $line=myEnc(get_lang('NoResult'));
  572. }
  573. }
  574. else
  575. {
  576. $new_view = substr_replace($view,'1',5,1);
  577. }*/
  578. }
  579. /***************************************************************************
  580. *
  581. * Export to a CSV file
  582. * force the browser to save the file instead of opening it
  583. ***************************************************************************/
  584. $len = strlen($title_line.$line);
  585. header('Content-type: application/octet-stream');
  586. //header('Content-Type: application/force-download');
  587. header('Content-length: '.$len);
  588. $filename = html_entity_decode(str_replace(":","",str_replace(" ","_", $title[0].'_'.$title[1].'.csv')));
  589. if(preg_match("/MSIE 5.5/",$_SERVER['HTTP_USER_AGENT']))
  590. {
  591. header('Content-Disposition: filename= '.$filename);
  592. }
  593. else
  594. {
  595. header('Content-Disposition: attachment; filename= '.$filename);
  596. }
  597. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  598. {
  599. header('Pragma: ');
  600. header('Cache-Control: ');
  601. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  602. }
  603. header('Content-Description: '.$filename);
  604. header('Content-transfer-encoding: binary');
  605. echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
  606. echo api_html_entity_decode($line, ENT_QUOTES, $charset);
  607. exit;
  608. }
  609. // not allowed
  610. else
  611. {
  612. if(!$_configuration['tracking_enabled'])
  613. {
  614. echo myEnc(get_lang('TrackingDisabled'));
  615. }
  616. else
  617. {
  618. api_not_allowed();
  619. }
  620. }