userlogCSV.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. /**
  21. ==============================================================================
  22. * @package dokeos.tracking
  23. * @todo clean code - structure is unclear and difficult to modify
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. $uInfo = $_REQUEST['uInfo'];
  32. $view = $_REQUEST['view'];
  33. // name of the language file that needs to be included
  34. $language_file = 'tracking';
  35. include('../inc/global.inc.php');
  36. // Roles and rights system
  37. $user_id = api_get_user_id();
  38. $course_id = api_get_course_id();
  39. /*
  40. $role_id = RolesRights::get_local_user_role_id($user_id, $course_id);
  41. $location_id = RolesRights::get_course_tool_location_id($course_id, TOOL_TRACKING);
  42. $is_allowed = RolesRights::is_allowed_which_rights($role_id, $location_id);
  43. //block users without view right
  44. RolesRights::protect_location($role_id, $location_id);
  45. */
  46. //YW Hack security to quick fix RolesRights bug
  47. $is_allowed = true;
  48. /*
  49. -----------------------------------------------------------
  50. Libraries
  51. -----------------------------------------------------------
  52. */
  53. include(api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php');
  54. include(api_get_path(LIBRARY_PATH).'course.lib.php');
  55. include(api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php');
  56. require_once(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');
  57. /*
  58. -----------------------------------------------------------
  59. Header
  60. -----------------------------------------------------------
  61. */
  62. // charset determination
  63. if ($_GET['scormcontopen'])
  64. {
  65. $tbl_lp = Database::get_course_table('lp');
  66. $contopen = (int) $_GET['scormcontopen'];
  67. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$contopen;
  68. $res = api_sql_query($sql,__FILE__,__LINE__);
  69. $row = Database::fetch_array($res);
  70. $lp_charset = $row['default_encoding'];
  71. //header('Content-Type: text/html; charset='. $row['default_encoding']);
  72. }
  73. /*
  74. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  75. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  76. */
  77. if($uInfo)
  78. {
  79. $interbreadcrumb[]= array ("url"=>"../user/userInfo.php?uInfo=$uInfo", "name"=> get_lang('BredCrumpUsers'));
  80. }
  81. $nameTools = get_lang('ToolName');
  82. /*
  83. -----------------------------------------------------------
  84. Constants and variables
  85. -----------------------------------------------------------
  86. */
  87. $is_allowedToTrack = $is_courseAdmin;
  88. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  89. // Database Table Definitions
  90. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  91. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  92. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  93. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  94. $TABLETRACK_ACCESS = $_configuration['statistics_database']."`.`track_e_access";
  95. $TABLETRACK_LINKS = $_configuration['statistics_database']."`.`track_e_links";
  96. $TABLETRACK_LOGIN = $_configuration['statistics_database']."`.`track_e_login";
  97. $TABLETRACK_DOWNLOADS = $_configuration['statistics_database']."`.`track_e_downloads";
  98. $TABLETRACK_UPLOADS = $_configuration['statistics_database']."`.`track_e_uploads";
  99. $TABLETRACK_EXERCICES = $_configuration['statistics_database']."`.`track_e_exercices";
  100. $TABLETRACK_HOTPOTATOES = $_configuration['statistics_database']."`.`track_e_hotpotatoes";
  101. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  102. $TABLECOURSE_WORK = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  103. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  104. $TABLECOURSE_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  105. //$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  106. if(api_get_setting('use_session_mode') == "true") {
  107. $sql = "SELECT 1
  108. FROM $tbl_session_course_user AS session_course_user
  109. INNER JOIN $tbl_session AS session
  110. ON session_course_user.id_session = session.id
  111. AND ((date_start<=NOW()
  112. AND date_end>=NOW())
  113. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  114. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  115. //echo $sql;
  116. $result=api_sql_query($sql,__FILE__,__LINE__);
  117. if(!mysql_num_rows($result)){
  118. $disabled = true;
  119. }
  120. }
  121. $tbl_learnpath_main = Database::get_course_table('lp');
  122. $tbl_learnpath_item = Database::get_course_table('lp_item');
  123. $tbl_learnpath_view = Database::get_course_table('lp_view');
  124. $tbl_learnpath_item_view = Database::get_course_table('lp_item_view');
  125. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  126. // the variables for the days and the months
  127. // Defining the shorts for the days
  128. $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")));
  129. // Defining the days of the week to allow translation of the days
  130. $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")));
  131. // Defining the months of the year to allow translation of the months
  132. $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")));
  133. // Defining the months of the year to allow translation of the months
  134. $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")));
  135. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  136. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  137. //YW hack security to fix RolesRights bug
  138. $is_allowedToTrack = true; // allowed to track only user of one group
  139. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  140. /*
  141. ==============================================================================
  142. FUNCTIONS
  143. ==============================================================================
  144. */
  145. /**
  146. * Shortcut function to use htmlentities on many, many strings in this script
  147. * @param string String in a supposed encoding
  148. * @param string Supposed initial encoding (default: 'ISO-8859-15')
  149. * @return string HTML string (no encoding dependency)
  150. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  151. */
  152. function myEnc($isostring,$supposed_encoding='ISO-8859-15')
  153. {
  154. return api_htmlentities($isostring,ENT_QUOTES,$supposed_encoding);
  155. }
  156. /**
  157. * Displays the number of logins every month for a specific user in a specific course.
  158. */
  159. function display_login_tracking_info($view, $user_id, $course_id)
  160. {
  161. $MonthsLong = $GLOBALS['MonthsLong'];
  162. $track_access_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  163. $tempView = $view;
  164. if(substr($view,0,1) == '1')
  165. {
  166. $new_view = substr_replace($view,'0',0,1);
  167. $title[1]= myEnc(get_lang('LoginsAndAccessTools')).myEnc(get_lang('LoginsDetails'));
  168. $sql = "SELECT UNIX_TIMESTAMP(`access_date`), count(`access_date`)
  169. FROM $track_access_table
  170. WHERE `access_user_id` = '$user_id'
  171. AND `access_cours_code` = '".$course_id."'
  172. GROUP BY YEAR(`access_date`),MONTH(`access_date`)
  173. ORDER BY YEAR(`access_date`),MONTH(`access_date`) ASC";
  174. //$results = getManyResults2Col($sql);
  175. $results = getManyResults3Col($sql);
  176. $title_line= myEnc(get_lang('LoginsTitleMonthColumn')).';'.myEnc(get_lang('LoginsTitleCountColumn'))."\n";
  177. $line='';
  178. $total = 0;
  179. if (is_array($results))
  180. {
  181. for($j = 0 ; $j < count($results) ; $j++)
  182. {
  183. $line .= $results[$j][0].';'.$results[$j][1]."\n";
  184. $total = $total + $results[$j][1];
  185. }
  186. $line .= myEnc(get_lang('Total')).";".$total."\n";
  187. }
  188. else
  189. {
  190. $line= myEnc(get_lang('NoResult'))."</center></td>";
  191. }
  192. }
  193. else
  194. {
  195. $new_view = substr_replace($view,'1',0,1);
  196. }
  197. return array($title_line, $line);
  198. }
  199. /**
  200. * Displays the exercise results for a specific user in a specific course.
  201. * @todo remove globals
  202. */
  203. function display_exercise_tracking_info($view, $user_id, $course_id)
  204. {
  205. global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES;
  206. if(substr($view,1,1) == '1')
  207. {
  208. $new_view = substr_replace($view,'0',1,1);
  209. $title[1]= myEnc(get_lang('ExercicesDetails'));
  210. $line='';
  211. $sql = "SELECT `ce`.`title`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  212. FROM $TABLECOURSE_EXERCICES AS ce , `$TABLETRACK_EXERCICES` AS `te`
  213. WHERE `te`.`exe_cours_id` = '$course_id'
  214. AND `te`.`exe_user_id` = '$user_id'
  215. AND `te`.`exe_exo_id` = `ce`.`id`
  216. ORDER BY `ce`.`title` ASC, `te`.`exe_date` ASC";
  217. $hpsql = "SELECT `te`.`exe_name`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`)
  218. FROM `$TABLETRACK_HOTPOTATOES` AS te
  219. WHERE `te`.`exe_user_id` = '$user_id' AND `te`.`exe_cours_id` = '$course_id'
  220. ORDER BY `te`.`exe_cours_id` ASC, `te`.`exe_date` ASC";
  221. $hpresults = getManyResultsXCol($hpsql, 4);
  222. $NoTestRes = 0;
  223. $NoHPTestRes = 0;
  224. $results = getManyResultsXCol($sql, 4);
  225. $title_line=myEnc(get_lang('ExercicesTitleExerciceColumn')).";".myEnc(get_lang('Date')).';'.myEnc(get_lang('ExercicesTitleScoreColumn'))."\n";
  226. if (is_array($results))
  227. {
  228. for($i = 0; $i < sizeof($results); $i++)
  229. {
  230. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]);
  231. $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
  232. }
  233. }
  234. else // istvan begin
  235. {
  236. $NoTestRes = 1;
  237. }
  238. // The Result of Tests
  239. if(is_array($hpresults))
  240. {
  241. for($i = 0; $i < sizeof($hpresults); $i++)
  242. {
  243. $title = GetQuizName($hpresults[$i][0],'');
  244. if ($title == '')
  245. $title = basename($hpresults[$i][0]);
  246. $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]);
  247. $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
  248. }
  249. }
  250. else
  251. {
  252. $NoHPTestRes = 1;
  253. }
  254. if ($NoTestRes == 1 && $NoHPTestRes == 1)
  255. {
  256. $line=get_lang('NoResult');
  257. }
  258. }
  259. else
  260. {
  261. $new_view = substr_replace($view,'1',1,1);
  262. }
  263. return array($title_line, $line);
  264. }
  265. /**
  266. * Displays the student publications for a specific user in a specific course.
  267. * @todo remove globals
  268. */
  269. function display_student_publications_tracking_info($view, $user_id, $course_id)
  270. {
  271. global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK, $dateTimeFormatLong;
  272. if(substr($view,2,1) == '1')
  273. {
  274. $new_view = substr_replace($view,'0',2,1);
  275. $sql = "SELECT `u`.`upload_date`, `w`.`title`, `w`.`author`,`w`.`url`
  276. FROM `$TABLETRACK_UPLOADS` `u` , $TABLECOURSE_WORK `w`
  277. WHERE `u`.`upload_work_id` = `w`.`id`
  278. AND `u`.`upload_user_id` = '$user_id'
  279. AND `u`.`upload_cours_id` = '$course_id'
  280. ORDER BY `u`.`upload_date` DESC";
  281. $results = getManyResultsXCol($sql,4);
  282. $title[1]=myEnc(get_lang('WorksDetails'));
  283. $line='';
  284. $title_line=myEnc(get_lang('WorkTitle')).";".myEnc(get_lang('WorkAuthors')).";".myEnc(get_lang('Date'))."\n";
  285. if (is_array($results))
  286. {
  287. for($j = 0 ; $j < count($results) ; $j++)
  288. {
  289. $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
  290. $timestamp = strtotime($results[$j][0]);
  291. $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp);
  292. $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
  293. }
  294. }
  295. else
  296. {
  297. $line= myEnc(get_lang('NoResult'));
  298. }
  299. }
  300. else
  301. {
  302. $new_view = substr_replace($view,'1',2,1);
  303. }
  304. return array($title_line, $line);
  305. }
  306. /**
  307. * Displays the links followed for a specific user in a specific course.
  308. * @todo remove globals
  309. */
  310. function display_links_tracking_info($view, $user_id, $course_id)
  311. {
  312. global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
  313. if(substr($view,3,1) == '1')
  314. {
  315. $new_view = substr_replace($view,'0',3,1);
  316. $title[1]=myEnc(get_lang('LinksDetails'));
  317. $sql = "SELECT `cl`.`title`, `cl`.`url`
  318. FROM `$TABLETRACK_LINKS` AS sl, $TABLECOURSE_LINKS AS cl
  319. WHERE `sl`.`links_link_id` = `cl`.`id`
  320. AND `sl`.`links_cours_id` = '$course_id'
  321. AND `sl`.`links_user_id` = '$user_id'
  322. GROUP BY `cl`.`title`, `cl`.`url`";
  323. $results = getManyResults2Col($sql);
  324. $title_line= myEnc(get_lang('LinksTitleLinkColumn'))."\n";
  325. if (is_array($results))
  326. {
  327. for($j = 0 ; $j < count($results) ; $j++)
  328. {
  329. $line .= $results[$j][0]."\n";
  330. }
  331. }
  332. else
  333. {
  334. $line=myEnc(get_lang('NoResult'));
  335. }
  336. }
  337. else
  338. {
  339. $new_view = substr_replace($view,'1',3,1);
  340. }
  341. return array($title_line, $line);
  342. }
  343. /**
  344. * Displays the documents downloaded for a specific user in a specific course.
  345. */
  346. function display_document_tracking_info($view, $user_id, $course_id)
  347. {
  348. $downloads_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  349. if(substr($view,4,1) == '1')
  350. {
  351. $new_view = substr_replace($view,'0',4,1);
  352. $title[1]= myEnc(get_lang('DocumentsDetails'));
  353. $sql = "SELECT `down_doc_path`
  354. FROM $downloads_table
  355. WHERE `down_cours_id` = '$course_id'
  356. AND `down_user_id` = '$user_id'
  357. GROUP BY `down_doc_path`";
  358. $results = getManyResults1Col($sql);
  359. $title_line = myEnc(get_lang('DocumentsTitleDocumentColumn'))."\n";
  360. if (is_array($results))
  361. {
  362. for($j = 0 ; $j < count($results) ; $j++)
  363. {
  364. $line .= $results[$j]."\n";
  365. }
  366. }
  367. else
  368. {
  369. $line=myEnc(get_lang('NoResult'));
  370. }
  371. }
  372. else
  373. {
  374. $new_view = substr_replace($view,'1',4,1);
  375. }
  376. return array($title_line, $line);
  377. }
  378. /*
  379. ==============================================================================
  380. MAIN SECTION
  381. ==============================================================================
  382. */
  383. $title[0]='';
  384. $title[1]='';
  385. $line='';
  386. $title_line='';
  387. // check if uid is tutor of this group
  388. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse ) && $_configuration['tracking_enabled'] )
  389. {
  390. if(!$uInfo && !isset($uInfo) )
  391. {
  392. /***************************************************************************
  393. *
  394. * Display list of user of this group
  395. *
  396. ***************************************************************************/
  397. if( $is_allowedToTrackEverybodyInCourse )
  398. {
  399. // if user can track everybody : list user of course
  400. if(api_get_setting('use_session_mode')) {
  401. $sql = "SELECT count(user_id)
  402. FROM $TABLECOURSUSER
  403. WHERE `course_code` = '$_cid'";
  404. }
  405. else {
  406. $sql = "SELECT count(id_user)
  407. FROM $tbl_session_course_user
  408. WHERE `course_code` = '$_cid'";
  409. }
  410. }
  411. else
  412. {
  413. // if user can only track one group : list users of this group
  414. $sql = "SELECT count(user)
  415. FROM $TABLECOURSE_GROUPSUSER
  416. WHERE `group_id` = '$_gid'";
  417. }
  418. $userGroupNb = getOneResult($sql);
  419. $step = 25; // number of student per page
  420. if ($userGroupNb > $step)
  421. {
  422. if(!isset($offset))
  423. {
  424. $offset=0;
  425. }
  426. $next = $offset + $step;
  427. $previous = $offset - $step;
  428. $navLink = "";
  429. if ($previous >= 0)
  430. {
  431. }
  432. if ($next < $userGroupNb)
  433. {
  434. }
  435. }
  436. else
  437. {
  438. $offset = 0;
  439. }
  440. echo $navLink;
  441. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  442. if( $is_allowedToTrackEverybodyInCourse )
  443. {
  444. // list of users in this course
  445. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  446. FROM $TABLECOURSUSER cu , $TABLEUSER u
  447. WHERE `cu`.`user_id` = `u`.`user_id`
  448. AND `cu`.`course_code` = '$_cid'
  449. LIMIT $offset,$step";
  450. }
  451. else
  452. {
  453. // list of users of this group
  454. $sql = "SELECT `u`.`user_id`, `u`.`firstname`,`u`.`lastname`
  455. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  456. WHERE `gu`.`user_id` = `u`.`user_id`
  457. AND `gu`.`group_id` = '$_gid'
  458. LIMIT $offset,$step";
  459. }
  460. $list_users = getManyResults3Col($sql);
  461. for($i = 0 ; $i < sizeof($list_users) ; $i++)
  462. {
  463. }
  464. }
  465. else // if uInfo is set
  466. {
  467. /***************************************************************************
  468. *
  469. * Informations about student uInfo
  470. *
  471. ***************************************************************************/
  472. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  473. // another course, or group
  474. if( $is_allowedToTrackEverybodyInCourse )
  475. {
  476. // check if user is in this course
  477. $tracking_is_accepted = $is_course_member;
  478. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  479. $title[0]=$tracked_user_info[1].'_'.$tracked_user_info[2];
  480. }
  481. else
  482. {
  483. // check if user is in the group of this tutor
  484. $sql = "SELECT `u`.`firstname`,`u`.`lastname`, `u`.`email`
  485. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  486. WHERE `gu`.`user_id` = `u`.`user_id`
  487. AND `gu`.`group_id` = '$_gid'
  488. AND `u`.`user_id` = '$uInfo'";
  489. $query = api_sql_query($sql,__FILE__,__LINE__);
  490. $tracked_user_info = @mysql_fetch_assoc($query);
  491. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  492. $title[0] = $tracked_user_info['firstname'].'_'.$tracked_user_info['lastname'];
  493. }
  494. if ($tracking_is_accepted)
  495. {
  496. $tracked_user_info['email'] == '' ? $mail_link = myEnc(get_lang('NoEmail')) : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  497. if(!isset($view))
  498. {
  499. $view ='0000000';
  500. }
  501. //Logins
  502. list($title_line1, $line1) = display_login_tracking_info($view, $uInfo, $_cid);
  503. //Exercise results
  504. list($title_line2, $line2) = display_exercise_tracking_info($view, $uInfo, $_cid);
  505. //Student publications uploaded
  506. list($title_line3, $line3) = display_student_publications_tracking_info($view, $uInfo, $_cid);
  507. //Links usage
  508. list($title_line4, $line4) = display_links_tracking_info($view, $uInfo, $_cid);
  509. //Documents downloaded
  510. list($title_line5, $line5) = display_document_tracking_info($view, $uInfo, $_cid);
  511. $title_line = $title_line1.$title_line2.$title_line3.$title_line4.$title_line5;
  512. $line= $line1.$line2.$line3.$line4.$line5;
  513. }
  514. else
  515. {
  516. echo myEnc(get_lang('ErrorUserNotInGroup'));
  517. }
  518. /***************************************************************************
  519. *
  520. * Scorm contents and Learning Path
  521. *
  522. ***************************************************************************/
  523. //TODO: scorm tools is in work and the logs will change in few days...
  524. /*if(substr($view,5,1) == '1')
  525. {
  526. $new_view = substr_replace($view,'0',5,1);
  527. $title[1]=myEnc(get_lang('ScormContentColumn'));
  528. $line ='';
  529. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  530. $result=api_sql_query($sql,__FILE__,__LINE__);
  531. $ar=Database::fetch_array($result);
  532. if (is_array($ar))
  533. {
  534. while ($ar['id'] != '') {
  535. $lp_title = stripslashes($ar['name']);
  536. echo "<tr><td>";
  537. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
  538. echo "</td></tr>";
  539. if ($ar['id']==$scormcontopen) { //have to list the students here
  540. $contentId=$ar['id'];
  541. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  542. "FROM $tbl_learnpath_item i " .
  543. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  544. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  545. "WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
  546. $result3=api_sql_query($sql3,__FILE__,__LINE__);
  547. $ar3=Database::fetch_array($result3);
  548. if (is_array($ar3)) {
  549. $title_line=myEnc(get_lang('ScormTitleColumn')).";".myEnc(get_lang('ScormStatusColumn')).";".myEnc(get_lang('ScormScoreColumn')).";".myEnc(get_lang('ScormTimeColumn'))."\n";
  550. while ($ar3['status'] != '') {
  551. require_once('../newscorm/learnpathItem.class.php');
  552. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  553. $title = htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  554. $line .= $title.';'.$ar3['status'].';'.$ar3['score'].';'.$time."\n";
  555. $ar3=Database::fetch_array($result3);
  556. }
  557. } else {
  558. $line .= myEnc(get_lang('ScormNeverOpened'));
  559. }
  560. }
  561. $ar=Database::fetch_array($result);
  562. }
  563. }
  564. else
  565. {
  566. $noscorm=true;
  567. }
  568. if ($noscorm) {
  569. $line=myEnc(get_lang('NoResult'));
  570. }
  571. }
  572. else
  573. {
  574. $new_view = substr_replace($view,'1',5,1);
  575. }*/
  576. }
  577. /***************************************************************************
  578. *
  579. * Export to a CSV file
  580. * force the browser to save the file instead of opening it
  581. ***************************************************************************/
  582. $len = strlen($title_line.$line);
  583. header('Content-type: application/octet-stream');
  584. //header('Content-Type: application/force-download');
  585. header('Content-length: '.$len);
  586. $filename = html_entity_decode(str_replace(":","",str_replace(" ","_", $title[0].'_'.$title[1].'.csv')));
  587. if(preg_match("/MSIE 5.5/",$_SERVER['HTTP_USER_AGENT']))
  588. {
  589. header('Content-Disposition: filename= '.$filename);
  590. }
  591. else
  592. {
  593. header('Content-Disposition: attachment; filename= '.$filename);
  594. }
  595. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  596. {
  597. header('Pragma: ');
  598. header('Cache-Control: ');
  599. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  600. }
  601. header('Content-Description: '.$filename);
  602. header('Content-transfer-encoding: binary');
  603. echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
  604. echo api_html_entity_decode($line, ENT_QUOTES, $charset);
  605. exit;
  606. }
  607. // not allowed
  608. else
  609. {
  610. if(!$_configuration['tracking_enabled'])
  611. {
  612. echo myEnc(get_lang('TrackingDisabled'));
  613. }
  614. else
  615. {
  616. api_not_allowed();
  617. }
  618. }