courseLogCSV.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. Author: Frederic Vauthier (frederic.vauthier@dokeos.com)
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @author Thomas Depraetere
  23. * @author Hugues Peeters
  24. * @author Christophe Gesche
  25. * @author Sebastien Piraux
  26. * @author Toon Keppens (Vi-Host.net)
  27. *
  28. * @package dokeos.tracking
  29. ==============================================================================
  30. */
  31. // TODO: Is this file deprecated?
  32. /*
  33. ==============================================================================
  34. INIT SECTION
  35. ==============================================================================
  36. */
  37. $pathopen = isset($_REQUEST['pathopen']) ? $_REQUEST['pathopen'] : null;
  38. // name of the language file that needs to be included
  39. $language_file = "tracking";
  40. include('../inc/global.inc.php');
  41. //includes for SCORM and LP
  42. require_once('../newscorm/learnpath.class.php');
  43. require_once('../newscorm/learnpathItem.class.php');
  44. require_once('../newscorm/scorm.class.php');
  45. require_once('../newscorm/scormItem.class.php');
  46. // charset determination
  47. if ($_GET['scormcontopen'])
  48. {
  49. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  50. $contopen = (int) $_GET['scormcontopen'];
  51. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$contopen;
  52. $res = api_sql_query($sql,__FILE__,__LINE__);
  53. $row = Database::fetch_array($res);
  54. $lp_charset = $row['default_encoding'];
  55. //header('Content-Type: text/html; charset='. $row['default_encoding']);
  56. }
  57. /*
  58. -----------------------------------------------------------
  59. Constants and variables
  60. -----------------------------------------------------------
  61. */
  62. // regroup table names for maintenance purpose
  63. $TABLETRACK_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  64. $TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  65. $TABLETRACK_DOWNLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  66. $TABLETRACK_ACCESS_2 = Database::get_statistic_table("track_e_access");
  67. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  68. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  69. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  70. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  71. //$table_scormdata = Database::get_scorm_table(TABLE_SCORM_SCO_DATA);
  72. //$table_scormmain = Database::get_scorm_table(TABLE_SCORM_MAIN);
  73. //$tbl_learnpath_main = Database::get_course_table(TABLE_LEARNPATH_MAIN);
  74. //$tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM);
  75. //$tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER);
  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. $view = $_REQUEST['view'];
  81. if($view=="0000001") $nameTools=get_lang('SynthesisView');
  82. if($view=="1000000") $nameTools=get_lang('CourseStats');
  83. if($view=="0100000") $nameTools=get_lang('CourseAccess');
  84. if($view=="0010000") $nameTools=get_lang('ToolsAccess');
  85. if($view=="0001000") $nameTools=get_lang('LinksAccess');
  86. if($view=="0000100") $nameTools=get_lang('DocumentsAccess');
  87. if($view=="00000010") $nameTools=get_lang('ScormAccess');
  88. $interbreadcrumb[] = array ("url" => api_get_self()."?view=0000000", "name" => get_lang('ToolName'));
  89. include(api_get_path(LIBRARY_PATH)."statsUtils.lib.inc.php");
  90. include("../resourcelinker/resourcelinker.inc.php");
  91. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin;
  92. /*
  93. ==============================================================================
  94. MAIN CODE
  95. ==============================================================================
  96. */
  97. $title[0]=get_lang('StatsOfCourse')." : ".$_course['official_code'];
  98. // check if uid is prof of this group
  99. if($is_allowedToTrack && $_configuration['tracking_enabled'])
  100. {
  101. // show all : view must be equal to the sum of all view values (1024+512+...+64)
  102. // show none : less than the tiniest value
  103. /*echo "<div>
  104. [<a href='".api_get_self()."?view=1111111'>".get_lang('ShowAll')."</a>]
  105. [<a href='".api_get_self()."?view=0000000'>".get_lang('ShowNone')."</a>]
  106. </div><br>
  107. ";*/
  108. if(!isset($view)) $view ="0000000";
  109. /***************************************************************************
  110. *
  111. * Reporting
  112. *
  113. ***************************************************************************/
  114. $tempView = $view;
  115. if($view[6] == '1'){
  116. $tempView[6] = '0';
  117. //--------------------------------BEGIN users in this course
  118. $sql = "SELECT $TABLECOURSUSER.`user_id`, $table_user.`lastname`, $table_user.`firstname`
  119. FROM $TABLECOURSUSER, $table_user
  120. WHERE $TABLECOURSUSER.course_code = '".$_cid."' AND $TABLECOURSUSER.`user_id` = $table_user.`user_id`
  121. ORDER BY $table_user.`lastname`";
  122. $results = getManyResults3Col($sql);
  123. //BUGFIX: get visual code instead of real course code. Scormpaths use the visual code... (should be fixed in future versions)
  124. $sql = "SELECT visual_code FROM $TABLECOURSE WHERE code = '".$_cid."'";
  125. $_course['visual_code'] = getOneResult($sql);
  126. if (is_array($results))
  127. {
  128. $line='';
  129. $title_line = get_lang('Name').";".get_lang('FirstAccess').";".get_lang('LastAccess').";".get_lang('Visited')."\n";
  130. for($j = 0 ; $j < count($results) ; $j++)
  131. {
  132. //--------------------------------BEGIN % visited
  133. // sum of all items (= multiple learningpaths + SCORM imported paths)
  134. $sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) " .
  135. "FROM $tbl_learnpath_item_view iv " .
  136. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id = v.id " .
  137. "WHERE v.user_id = ".$results[$j][0];
  138. $total_lpath_items = getOneResult($sql);
  139. // sum of all completed items (= multiple learningpaths + SCORM imported paths)
  140. $sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) " .
  141. "FROM $tbl_learnpath_item_view iv " .
  142. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id = v.id " .
  143. "WHERE v.user_id = ".$results[$j][0]." " .
  144. "AND (status = 'completed' OR status='passed')";
  145. $total_lpath_items_completed = getOneResult($sql);
  146. // calculation & bgcolor setting
  147. $lpath_pct_completed = empty($total_lpath_items) ? "-" : round(($total_lpath_items_completed / $total_lpath_items) * 100);
  148. //--------------------------------END % visited
  149. //--------------------------------BEGIN first/last access
  150. // first access
  151. $sql = "SELECT access_date FROM $TABLETRACK_ACCESS_2 WHERE `access_user_id` = '".$results[$j][0]."' AND `access_cours_code` = '".$_course['official_code']."' AND `access_tool` = 'learnpath' ORDER BY access_id ASC LIMIT 1";
  152. $first_access = getOneResult($sql);
  153. $first_access = empty($first_access) ? "-" : date('d.m.y',strtotime($first_access));
  154. // last access
  155. $sql = "SELECT access_date FROM $TABLETRACK_ACCESS WHERE `access_user_id` = '".$results[$j][0]."' AND `access_cours_code` = '".$_course['official_code']."' AND `access_tool` = 'learnpath'";
  156. $last_access = getOneResult($sql);
  157. $last_access = empty($last_access) ? "-" : date('d.m.y',strtotime($last_access));
  158. //--------------------------------END first/last access
  159. //--------------------------------BEGIN presentation of data
  160. $line .= $results[$j][1]." ".$results[$j][2].";".$first_access.";".$last_access.";".$lpath_pct_completed."\n";
  161. //--------------------------------END presentation of data
  162. }
  163. }
  164. else
  165. {
  166. $line = get_lang('NoResult')."\n";
  167. }
  168. }
  169. /***************************************************************************
  170. *
  171. * Main
  172. *
  173. ***************************************************************************/
  174. $tempView = $view;
  175. if($view[0] == '1')
  176. {
  177. $title[1]= $nameTools;
  178. $tempView[0] = '0';
  179. $sql = "SELECT count(*)
  180. FROM $TABLECOURSUSER
  181. WHERE course_code = '".$_cid."'";
  182. $count = getOneResult($sql);
  183. $title_line = get_lang('CountUsers')." ; ".$count."\n";
  184. }
  185. /***************************************************************************
  186. *
  187. * Access to this course
  188. *
  189. ***************************************************************************/
  190. $tempView = $view;
  191. if($view[1] == '1'){
  192. $tempView[1] = '0';
  193. $title[1]=get_lang('ConnectionsToThisCourse');
  194. $title_line = '';
  195. $line = '';
  196. //Total
  197. $sql = "SELECT count(*)
  198. FROM $TABLETRACK_ACCESS
  199. WHERE access_cours_code = '".$_cid."'
  200. AND access_tool IS NULL";
  201. $count = getOneResult($sql);
  202. $line .= get_lang('CountToolAccess')." ; ".$count."\n";
  203. // last 31 days
  204. $sql = "SELECT count(*)
  205. FROM $TABLETRACK_ACCESS
  206. WHERE `access_cours_code` = '$_cid'
  207. AND (access_date > DATE_ADD(CURDATE(), INTERVAL -31 DAY))
  208. AND access_tool IS NULL";
  209. $count = getOneResult($sql);
  210. $line .= get_lang('Last31days')." ; ".$count."\n";
  211. // last 7 days
  212. $sql = "SELECT count(*)
  213. FROM $TABLETRACK_ACCESS
  214. WHERE `access_cours_code` = '$_cid'
  215. AND (access_date > DATE_ADD(CURDATE(), INTERVAL -7 DAY))
  216. AND access_tool IS NULL";
  217. $count = getOneResult($sql);
  218. $line .= get_lang('Last7days')." ; ".$count."\n";
  219. // today
  220. $sql = "SELECT count(*)
  221. FROM $TABLETRACK_ACCESS
  222. WHERE `access_cours_code` = '$_cid'
  223. AND ( access_date > CURDATE() )
  224. AND access_tool IS NULL";
  225. $count = getOneResult($sql);
  226. $line .= get_lang('Thisday')." ; ".$count."\n";
  227. }
  228. /***************************************************************************
  229. *
  230. * Tools
  231. *
  232. ***************************************************************************/
  233. $tempView = $view;
  234. if($view[2] == '1'){
  235. $tempView[2] = '0';
  236. $title[1]= $nameTools;
  237. $line ='';
  238. $title_line = get_lang('ToolTitleToolnameColumn').";".get_lang('ToolTitleUsersColumn').";".get_lang('ToolTitleCountColumn')."\n";
  239. $sql = "SELECT `access_tool`, COUNT(DISTINCT `access_user_id`),count( `access_tool` )
  240. FROM $TABLETRACK_ACCESS
  241. WHERE `access_tool` IS NOT NULL
  242. AND `access_cours_code` = '$_cid'
  243. GROUP BY `access_tool`";
  244. $results = getManyResults3Col($sql);
  245. if (is_array($results))
  246. {
  247. for($j = 0 ; $j < count($results) ; $j++)
  248. {
  249. $line .= $results[$j][0]."/".get_lang($results[$j][0]).";".$results[$j][1].";".$results[$j][2]."\n";
  250. }
  251. }
  252. else
  253. {
  254. $line = get_lang('NoResult')."\n";
  255. }
  256. }
  257. /***************************************************************************
  258. *
  259. * Links
  260. *
  261. ***************************************************************************/
  262. $tempView = $view;
  263. if($view[3] == '1'){
  264. $tempView[3] = '0';
  265. $sql = "SELECT `cl`.`title`, `cl`.`url`,count(DISTINCT `sl`.`links_user_id`), count(`cl`.`title`)
  266. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  267. WHERE `sl`.`links_link_id` = `cl`.`id`
  268. AND `sl`.`links_cours_id` = '$_cid'
  269. GROUP BY `cl`.`title`, `cl`.`url`";
  270. $results = getManyResultsXCol($sql,4);
  271. $title[1]= $nameTools;
  272. $line='';
  273. $title_line = get_lang('LinksTitleLinkColumn').";".get_lang('LinksTitleUsersColumn').";".get_lang('LinksTitleCountColumn')."\n";
  274. if (is_array($results))
  275. {
  276. for($j = 0 ; $j < count($results) ; $j++)
  277. {
  278. $line .= $results[$j][1]."'>".$results[$j][0].";".$results[$j][2].";".$results[$j][3]."\n";
  279. }
  280. }
  281. else
  282. {
  283. $line = get_lang('NoResult')."\n";
  284. }
  285. }
  286. /***************************************************************************
  287. *
  288. * Documents
  289. *
  290. ***************************************************************************/
  291. $tempView = $view;
  292. if($view[4] == '1'){
  293. $tempView[4] = '0';
  294. $sql = "SELECT `down_doc_path`, COUNT(DISTINCT `down_user_id`), COUNT(`down_doc_path`)
  295. FROM $TABLETRACK_DOWNLOADS
  296. WHERE `down_cours_id` = '$_cid'
  297. GROUP BY `down_doc_path`";
  298. $results = getManyResults3Col($sql);
  299. $title[1]= $nameTools;
  300. $line='';
  301. $title_line = get_lang('DocumentsTitleDocumentColumn').";".get_lang('DocumentsTitleUsersColumn').";".get_lang('DocumentsTitleCountColumn')."\n";
  302. if (is_array($results))
  303. {
  304. for($j = 0 ; $j < count($results) ; $j++)
  305. {
  306. $line .= $results[$j][0].";".$results[$j][1].";".$results[$j][2]."\n";
  307. }
  308. }
  309. else
  310. {
  311. $line=get_lang('NoResult')."\n";
  312. }
  313. }
  314. /***************************************************************************
  315. *
  316. * Scorm contents and Learning Path
  317. *
  318. ***************************************************************************/
  319. $tempView = $view;
  320. if($view[5] == '1'){
  321. $tempView[5] = '0';
  322. $sql = "SELECT id, name
  323. FROM $tbl_learnpath_main";
  324. //WHERE dokeosCourse='$_cid'"; we are using a table inside the course now, so no need for course id
  325. $result=api_sql_query($sql,__FILE__,__LINE__);
  326. $ar=Database::fetch_array($result);
  327. $title[1]= $nameTools;
  328. $line='';
  329. $title_line = get_lang('ScormContentColumn');
  330. $scormcontopen=$_REQUEST["scormcontopen"];
  331. $scormstudentopen=$_REQUEST["scormstudentopen"];
  332. if (is_array($ar)){
  333. while ($ar['id'] != '') {
  334. $lp_title = stripslashes($ar['name']);
  335. //echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."' class='specialLink'>$lp_title</a>";
  336. if ($ar['id']==$scormcontopen) { //have to list the students here
  337. $contentId=$ar['id'];
  338. $sql2 = "SELECT u.user_id, u.lastname, u.firstname " .
  339. "FROM $tbl_learnpath_view sd " .
  340. "INNER JOIN $table_user u " .
  341. "ON u.user_id = sd.user_id " .
  342. "WHERE sd.lp_id=$contentId group by u.user_id";
  343. //error_log($sql2,0);
  344. $result2=api_sql_query($sql2,__FILE__,__LINE__);
  345. if(mysql_num_rows($result2)>0){
  346. $ar2=Database::fetch_array($result2);
  347. while ($ar2 != '') {
  348. if (isset($_REQUEST["scormstudentopen"]) && $ar2['user_id']==$scormstudentopen) {
  349. $line .= $ar['id']." ".$ar2['user_id']." ".$ar2['lastname']." ".$ar2['firstname'];
  350. }
  351. else{
  352. $line .= $ar['id']." ".$ar2['user_id']." ".$ar2['lastname']." ".$ar2['firstname'];
  353. }
  354. if ($ar2['user_id']==$scormstudentopen) { //have to list the student's results
  355. $studentId=$ar2['user_id'];
  356. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  357. "FROM $tbl_learnpath_item i " .
  358. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  359. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  360. "WHERE (v.user_id=$studentId and v.lp_id=$contentId) ORDER BY v.id, i.id";
  361. $result3=api_sql_query($sql3,__FILE__,__LINE__);
  362. $ar3=Database::fetch_array($result3);
  363. $title_line .= get_lang('ScormTitleColumn').";".get_lang('ScormStatusColumn').";".get_lang('ScormScoreColumn').";".get_lang('ScormTimeColumn');
  364. while ($ar3['status'] != '') {
  365. require_once('../newscorm/learnpathItem.class.php');
  366. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  367. $title = api_htmlentities($ar3['title'],ENT_QUOTES,$lp_charset);
  368. $line .= $title.";".$ar3['status'].";".$ar3['score'].";".$time;
  369. $ar3=Database::fetch_array($result3);
  370. }
  371. }
  372. $line .= "\n";
  373. $ar2=Database::fetch_array($result2);
  374. }
  375. $title_line .= "\n";
  376. }
  377. }
  378. $ar=Database::fetch_array($result);
  379. }
  380. }
  381. }
  382. /***************************************************************************
  383. *
  384. * Export to a CSV file
  385. * force the browser to save the file instead of opening it
  386. ***************************************************************************/
  387. $len = strlen($title_line.$line);
  388. header('Content-type: application/octet-stream');
  389. //header('Content-Type: application/force-download');
  390. header('Content-length: '.$len);
  391. $filename = html_entity_decode(str_replace(":","",str_replace(" ","_", $title[0].'_'.$title[1].'.csv')));
  392. if(preg_match("/MSIE 5.5/",$_SERVER['HTTP_USER_AGENT']))
  393. {
  394. header('Content-Disposition: filename= '.$filename);
  395. }
  396. else
  397. {
  398. header('Content-Disposition: attachment; filename= '.$filename);
  399. }
  400. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  401. {
  402. header('Pragma: ');
  403. header('Cache-Control: ');
  404. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  405. }
  406. header('Content-Description: '.$filename);
  407. header('Content-transfer-encoding: binary');
  408. echo api_html_entity_decode($title_line, ENT_COMPAT, $charset);
  409. echo api_html_entity_decode($line, ENT_COMPAT, $charset);
  410. exit;
  411. }
  412. // not allowed
  413. else
  414. {
  415. if(!$_configuration['tracking_enabled'])
  416. {
  417. echo get_lang('TrackingDisabled');
  418. }
  419. else
  420. {
  421. api_not_allowed();
  422. }
  423. }
  424. ?>