dokeos-tracking
[ class tree: dokeos-tracking ] [ index: dokeos-tracking ] [ all elements ]

Source for file courseLogCSV.php

Documentation is available at courseLogCSV.php

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

Documentation generated on Thu, 12 Jun 2008 13:12:14 -0500 by phpDocumentor 1.4.1