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

Source for file coaches.php

Documentation is available at coaches.php

  1. <?php
  2.  
  3. /*
  4.  * Created on 18 October 2006 by Elixir Interactive http://www.elixir-interactive.com
  5.  */
  6.  
  7.  
  8. // name of the language file that needs to be included 
  9. $language_file array ('registration''index''tracking''admin');
  10. $cidReset=true;
  11. require ('../inc/global.inc.php');
  12.  
  13. $this_section "session_my_space";
  14.  
  15. $nameToolsget_lang('Tutors');
  16.  
  17. $interbreadcrumb[array ("url" => "index.php""name" => get_lang('MySpace'));
  18.  
  19. if(isset($_GET["id_student"])){
  20.     $interbreadcrumb[array ("url" => "student.php""name" => get_lang('Students'));
  21. }
  22.  
  23. Display :: display_header($nameTools);
  24.  
  25.  
  26. // Database Table Definitions
  27. $tbl_course                         Database :: get_main_table(TABLE_MAIN_COURSE);
  28. $tbl_course_user                     Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  29. $tbl_user                             Database :: get_main_table(TABLE_MAIN_USER);
  30. $tbl_session                         Database :: get_main_table(TABLE_MAIN_SESSION);
  31. $tbl_session_rel_course             Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  32. $tbl_session_rel_course_rel_user     Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  33. $tbl_session_rel_user                 Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  34. $tbl_track_login                     Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  35.  
  36.  
  37. /*
  38.  ===============================================================================
  39.      FUNCTION
  40.  ===============================================================================  
  41.  */
  42.  
  43.  function exportCsv($a_header,$a_data)
  44.  {
  45.      global $archiveDirName;
  46.  
  47.     $fileName 'coaches.csv';
  48.     $archivePath api_get_path(SYS_PATH).$archiveDirName.'/';
  49.     $archiveURL api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  50.     
  51.     if(!$open fopen($archivePath.$fileName,'w+'))
  52.     {
  53.         $message get_lang('noOpen');
  54.     }
  55.     else
  56.     {
  57.         $info '';
  58.         
  59.         foreach($a_header as $header)
  60.         {
  61.             $info .= $header.';';
  62.         }
  63.         $info .= "\r\n";
  64.         
  65.         
  66.         foreach($a_data as $data)
  67.         {
  68.             foreach($data as $infos)
  69.             {
  70.                 $info .= $infos.';';
  71.             }
  72.             $info .= "\r\n";
  73.         }
  74.         
  75.         fwrite($open,$info);
  76.         fclose($open);
  77.         $perm api_get_setting('permissions_for_new_files');
  78.         $perm octdec(!empty($perm)?$perm:'0660');
  79.         chmod($fileName,$perm);
  80.         
  81.         header("Location:".$archiveURL.$fileName);
  82.     }
  83.     
  84.     return $message;
  85.  }
  86.  
  87.  function calculHours($seconds)
  88.     {
  89.       //combien d'heures ?
  90.       $hours floor($seconds 3600);
  91.     
  92.       //combien de minutes ?
  93.       $min floor(($seconds ($hours 3600)) 60);
  94.       if ($min 10)
  95.         $min "0".$min;
  96.     
  97.       //combien de secondes
  98.       $sec $seconds ($hours 3600($min 60);
  99.       if ($sec 10)
  100.         $sec "0".$sec;
  101.             
  102.       //echo $hours."h".$min."m".$sec."s";
  103.     
  104.         return $hours."h".$min."m".$sec."s" ;
  105.     
  106.     }
  107.  
  108. function is_coach(){
  109.       
  110.       global $tbl_session_course;
  111.       
  112.     $sql="SELECT course_code FROM $tbl_session_course WHERE id_coach='".$_SESSION["_uid"]."'";
  113.  
  114.     $result=api_sql_query($sql);
  115.       
  116.     if(mysql_num_rows($result)>0){
  117.         return true;        
  118.     }
  119.     else{
  120.         return false;
  121.     }
  122.   
  123. }
  124.  
  125.  
  126. /**
  127.  * MAIN PART
  128.  */
  129.  
  130. if(isset($_GET["id_student"])){
  131.     
  132.     $i_id_student=$_GET["id_student"];
  133.     $sqlCoachs "SELECT DISTINCT src.id_coach " .
  134.                     "FROM $tbl_session_rel_course as src, $tbl_session_rel_course_rel_user as srcru .
  135.                     "WHERE src.id_coach<>'0' AND src.course_code=srcru.course_code AND srcru.id_user='$i_id_student' AND srcru.id_session=src.id_session 
  136.                   ";
  137.  
  138. }
  139.  
  140. else{
  141.     if(api_is_platform_admin()){
  142.         $sqlCoachs "    SELECT DISTINCT id_coach, user_id, lastname, firstname
  143.                         FROM $tbl_user$tbl_session_rel_course
  144.                         WHERE id_coach=user_id
  145.                         ORDER BY lastname ASC
  146.                       ";
  147.     }
  148.     else{
  149.         
  150.         $sqlCoachs "    SELECT DISTINCT id_coach, $tbl_user.user_id, lastname, firstname
  151.                         FROM $tbl_user as user, $tbl_session_rel_course as session_rel_course, $tbl_course_user as course_rel_user  
  152.                         WHERE course_rel_user.course_code=session_rel_course.course_code AND course_rel_user.status='1' AND course_rel_user.user_id='".$_SESSION["_uid"]."' 
  153.                         AND session_rel_course.id_coach=user.user_id 
  154.                         ORDER BY lastname ASC
  155.                       ";
  156.     
  157.     }
  158. }
  159. $resultCoachs api_sql_query($sqlCoachs);
  160.  
  161. echo '<table class="data_table">
  162.          <tr>
  163.             <th>
  164.                 '.get_lang('FirstName').'
  165.             </th>
  166.             <th>
  167.                 '.get_lang('LastName').'
  168.             </th>
  169.             <th>
  170.                 '.get_lang('ConnectionTime').'
  171.             </th>
  172.             <th>
  173.                 '.get_lang('AdminCourses').'
  174.             </th>
  175.             <th>
  176.                 '.get_lang('Students').'
  177.             </th>
  178.         </tr>
  179.        ';
  180.  
  181. $a_header[]=get_lang('FirstName');
  182. $a_header[]=get_lang('LastName');
  183. $a_header[]=get_lang('ConnectionTime');
  184.  
  185. if(mysql_num_rows($resultCoachs)>0){
  186.     
  187.     while($a_coachs=mysql_fetch_array($resultCoachs)){
  188.         
  189.         $i_id_coach=$a_coachs["id_coach"];
  190.         
  191.         if(isset($_GET["id_student"])){
  192.             $sql_infos_coach="SELECT lastname, firstname FROM $tbl_user WHERE user_id='$i_id_coach'";
  193.             $resultCoachsInfos api_sql_query($sql_infos_coach);
  194.             $s_lastname=mysql_result($resultCoachsInfos,0,"lastname");
  195.             $s_firstname=mysql_result($resultCoachsInfos,0,"firstname");
  196.         }
  197.         
  198.         else{
  199.             $s_lastname=$a_coachs["lastname"];
  200.             $s_firstname=$a_coachs["firstname"];
  201.         }
  202.         
  203.         $s_sql_connection_time="SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$i_id_coach' AND logout_date <> 'null'";
  204.  
  205.         $q_result_connection_time=api_sql_query($s_sql_connection_time);
  206.         
  207.         $i_nb_seconds=0;
  208.         
  209.         while($a_connections=mysql_fetch_array($q_result_connection_time)){
  210.             
  211.             $s_login_date=$a_connections["login_date"];
  212.             $s_logout_date=$a_connections["logout_date"];
  213.             
  214.             $i_timestamp_login_date=strtotime($s_login_date);
  215.             $i_timestamp_logout_date=strtotime($s_logout_date);
  216.             
  217.             $i_nb_seconds+=($i_timestamp_logout_date-$i_timestamp_login_date);
  218.             
  219.         }
  220.         
  221.         $s_connection_time=calculHours($i_nb_seconds);
  222.         if($s_connection_time=="0h00m00s"){
  223.             $s_connection_time="";
  224.         }
  225.         
  226.         if($i%2==0){
  227.             $s_css_class="row_odd";
  228.             
  229.             if($i%20==&& $i!=0){
  230.                 echo '<tr>
  231.                     <th>
  232.                         '.get_lang('LastName').'
  233.                     </th>
  234.                     <th>
  235.                         '.get_lang('FirstName').'
  236.                     </th>
  237.                     <th>
  238.                         '.get_lang('ConnectionTime').'
  239.                     </th>
  240.                     <th>
  241.                         '.get_lang('AdminCourses').'
  242.                     </th>
  243.                     <th>
  244.                         '.get_lang('Students').'
  245.                     </th>
  246.                 </tr>';
  247.             }
  248.             
  249.         }
  250.         else{
  251.             $s_css_class="row_even";
  252.         }
  253.         
  254.         $i++;
  255.         
  256.         $a_data[$i_id_coach]["firstname"]=$s_firstname;
  257.         $a_data[$i_id_coach]["lastname"]=$s_lastname;
  258.         $a_data[$i_id_coach]["connection_time"]=$s_connection_time;
  259.             
  260.         echo '<tr class="'.$s_css_class.'"><td>'.$s_firstname.'</td><td>'.$s_lastname.'</td><td>'.$s_connection_time.'</td><td><a href="course.php?type=coach&user_id='.$i_id_coach.'">-></a></td><td><a href="student.php?type=coach&user_id='.$i_id_coach.'">-></a></td></tr>';
  261.         
  262.     }
  263.     
  264. }
  265.  
  266. //No results
  267. else{
  268.     
  269.     echo '<tr><td colspan="5" "align=center">'.get_lang("NoResult").'</td></tr>';
  270.     
  271. }
  272.  
  273. echo '</table>';
  274.  
  275. if(isset($_POST['export'])){
  276.     
  277.     exportCsv($a_header,$a_data);
  278.     
  279. }
  280.  
  281. echo "<br /><br />";
  282. echo "<form method='post' action='coaches.php'>
  283.         <input type='submit' name='export' value='".get_lang('exportExcel')."'/>
  284.       <form>";
  285.  
  286. /*
  287. ==============================================================================
  288.     FOOTER
  289. ==============================================================================
  290. */
  291.  
  292.  
  293. ?>

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