<?php

/************************************************************************/
/* DOCEBO LMS - Learning managment system									*/
/* ============================================							*/
/*																			*/
/* Copyright (c) 2005														*/
/* http://www.docebo.com													*/
/*																			*/
/* This program is free software. You can redistribute it and/or modify	*/
/* it under the terms of the GNU General Public License as published by	*/
/* the Free Software Foundation; either version 2 of the License.		*/
/************************************************************************/

if(!defined('IN_DOCEBO')) die('You cannot access this file directly');

/**
 * @version  $Id: class.report_performance.php 573 2006-08-23 09:38:54Z fabio $
 * @author	 Fabio Pirovano <fabio [at] docebo [dot] com>
 */

require_once($GLOBALS['where_lms'].'/admin/modules/report/class.report.php');
require_once($GLOBALS['where_lms'].'/lib/lib.course.php');

class Report_Performance extends Report {
	
	var $lang;
	
	function Report_Performance($id_report) {
		$this->lang =& DoceboLanguage::createInstance('ru_report');
		parent::Report($id_report);
	}
	
	function play($jump_url, $back_url, $alluser, $org_chart_subdivision, $start_time, $end_time) {
		
		require_once($GLOBALS['where_framework'].'/lib/lib.form.php');
		require_once($GLOBALS['where_framework'].'/lib/lib.directory.php');
		require_once($GLOBALS['where_framework'].'/class.module/class.directory.php');
		require_once($GLOBALS['where_lms'].'/lib/lib.course.php');
		
		$lang =& DoceboLanguage::createInstance('report');
		
		$page_title = getTitleArea(array(
			str_replace('&', '&amp;', $back_url) => $lang->def('_REPORT'),
			$this->report_name
		), 'report', $lang->def('_ALT_REPORT'));
		
		if($alluser == 1) {
			
			$GLOBALS['page']->add(
				$page_title
				.'<div class="std_block">'
				.getBackUi(str_replace('&', '&amp;', $back_url), $lang->def('_BACK')), 'content');
			$this->show_report($jump_url, true, $org_chart_subdivision, $start_time, $end_time);
			$GLOBALS['page']->add('</div>', 'content');
			return;
		}
		if(isset($_POST['cancelselector'])) {
			
			jumpTo($back_url);
		} elseif(isset($_POST['okselector'])) {
			
			$GLOBALS['page']->add(
				$page_title
				.'<div class="std_block">'
				.getBackUi(str_replace('&', '&amp;', $back_url), $lang->def('_BACK')), 'content');
			$this->show_report($jump_url, false, $org_chart_subdivision, $start_time, $end_time);
			$GLOBALS['page']->add('</div>', 'content');
			return;
		} elseif(isset($_POST['export_cvs'])) {
			
			$this->exportAsCvs($org_chart_subdivision, $start_time, $end_time);
		} else {
			
			// first step load selector 
			require_once($GLOBALS['where_framework'].'/class.module/class.directory.php');
			
			$aclManager = new DoceboACLManager();
			$user_select = new Module_Directory();
			
			if($org_chart_subdivision == 0) {
				
				$user_select->show_user_selector = TRUE;
				$user_select->show_group_selector = TRUE;
			} else {
				
				$user_select->show_user_selector = FALSE;
				$user_select->show_group_selector = FALSE;
			}
			$user_select->show_orgchart_selector = TRUE;
			$user_select->show_orgchart_simple_selector = FALSE;
			$user_select->multi_choice = TRUE;
			
			$user_select->addFormInfo(
				Form::getHidden('start_time', 'start_time', $start_time)
				.Form::getHidden('end_time', 'end_time', $end_time)
				.Form::getHidden('org_chart_subdivision', 'org_chart_subdivision', $org_chart_subdivision)
				.Form::getHidden('alluser', 'alluser', $alluser)
			);
			$user_select->setPageTitle($page_title);
			$user_select->loadSelector(str_replace('&', '&amp;', $jump_url), 
					false, 
					$lang->def('_CHOOSE_USER_FOR_REPORT'), 
					true, 
					true );
		}
		
	}
	
	function show_report($jump_url, $alluser, $org_chart_subdivision, $start_time, $end_time) {
		
		$lang =& DoceboLanguage::createInstance('rp_report');
		
		$acl_man 		= new DoceboACLManager();
		$course_man 	= new Man_Course();
		
		if($alluser == 0) {
			$user_select 	= new Module_Directory();
			$elem_selected 	= $user_select->getSelection($_POST);
			$user_selected 	=& $acl_man->getAllUsersFromIdst($elem_selected);
			
		} else {
			
			$user_selected =& $this->getAllUserIdst();
		}
		if($org_chart_subdivision == 1) {
			
			require_once($GLOBALS['where_framework'].'/lib/lib.orgchart.php');
			$org_man 	= new OrgChartManager();
			if($alluser == 1) {
				$elem_selected = $org_man->getAllGroupIdFolder();
			}
			$org_name = $org_man->getFolderFormIdst($elem_selected);
		} else {
			
			$elem_selected = array();
		}
		
		if(empty($user_selected)) {
			
			$GLOBALS['page']->add($lang->def('_NULL_SELECTION'), 'content');
			return;
		}
		$users_info =& $acl_man->getUsers($user_selected);
		
		// Retrive all the course
		$course =& $course_man->getAllCoursesWithMoreInfo();
		if(empty($course)) {
			
			$GLOBALS['page']->add($lang->def('_NULL_COURSE_SELECTION'), 'content');
			return;
		}
		
		// css
		$GLOBALS['page']->add(
			"\n".'<link href="'.getPathTemplate('lms').'style/report/style_report_performance.css" rel="stylesheet" type="text/css" />'."\n"
		, 'page_head');
		
		// Export as cvs
		$GLOBALS['page']->add(
			Form::openForm('export', $jump_url)
			.Form::openElementSpace('')
			.Form::getHidden('org_chart_subdivision', 'org_chart_subdivision', ( $org_chart_subdivision ?  1 : 0 ))
			.Form::getHidden('start_time', 'start_time', $start_time)
			.Form::getHidden('end_time', 'end_time', $end_time)
			.Form::getHidden('elem_selected', 'elem_selected', urlencode(serialize($elem_selected)))
			.Form::getHidden('user_selected', 'user_selected', urlencode(serialize($user_selected)))
			.form::getButton('export_cvs', 'export_cvs', $lang->def('_CSVEXPORT'), 'export_cvs')
			.Form::closeElementSpace()
			.Form::closeForm()
		, 'content');
		
		if($org_chart_subdivision === 0) {
			
			$date_now = $GLOBALS['regset']->databaseToRegional(date("Y-m-d H:i:s")); 
			
			$GLOBALS['page']->add('<div class="datasummary">', 'content');
			if($start_time != '' || $end_time != '') {
				
				$GLOBALS['page']->add('<b>'.$lang->def('_TIME_BELT_2').' :</b> '
					.( $start_time != '' 	? ' <b>'.$lang->def('_START_TIME').' </b>'.$GLOBALS['regset']->databaseToRegional($start_time, 'date') 	: '' )
					.( $end_time != '' 		? ' <b>'.$lang->def('_END_TIME').' </b>'.$GLOBALS['regset']->databaseToRegional($end_time, 'date') 		: '' )
					.'<br />'
					, 'content');
			}
			$GLOBALS['page']->add( '<b>'.$lang->def('_ANALYSIS_DATE').' :</b> '.$date_now.'<br />'
			.'</div>', 'content');
				
			$now = time();
			$num_comple = array();
			$time_comple = array();
			
			$query_time = "
			SELECT idCourse, status, UNIX_TIMESTAMP(date_inscr), UNIX_TIMESTAMP(date_first_access), UNIX_TIMESTAMP(date_complete)
			FROM ".$GLOBALS['prefix_lms']."_courseuser 
			WHERE idUser IN (".implode(',', $user_selected).") ";
			if($start_time != '') $query_time .= " AND date_inscr >= '".$start_time."' ";
			if($end_time != '') $query_time .= " AND date_inscr <= '".$end_time."' ";
			$re_time = mysql_query($query_time);
			
			while(list($id_cp, $status, $d_iscr, $d_first, $d_complete) = mysql_fetch_row($re_time)) {
				
				if($d_complete != NULL) {
					//not complete
					//late is difference between iscr and now
					$day_compl = (int)(($d_complete - $d_iscr) / 86400);
					
					if(isset($num_comple[$id_cp])) ++$num_comple[$id_cp];
					else $num_comple[$id_cp] = 1;
					if(isset($time_comple[$id_cp])) $time_comple[$id_cp] += $day_compl;
					else $time_comple[$id_cp] = $day_compl;
				}
			}
			$this->_printTable($course, $num_comple, $time_comple);
		} else {
			
			$date_now = $GLOBALS['regset']->databaseToRegional(date("Y-m-d H:i:s")); 
			
			reset($org_name);
			while(list($idst_group, $folder_name) = each($org_name)) {
				
				$GLOBALS['page']->add('<div class="datasummary">'
					.'<b>'.$lang->def('_FOLDER_NAME').' :</b> '.$folder_name['name']
						.( $folder_name['type_of_folder'] == ORG_CHART_WITH_DESCENDANTS ? ' ('.$lang->def('_WITH_DESCENDANTS').')' : '' ).'<br />'
					, 'content');
				if($start_time != '' || $end_time != '') {
					
					$GLOBALS['page']->add('<b>'.$lang->def('_TIME_BELT_2').' :</b> '
						.( $start_time != '' 	? ' <b>'.$lang->def('_START_TIME').' </b>'.$GLOBALS['regset']->databaseToRegional($start_time, 'date') 	: '' )
						.( $end_time != '' 		? ' <b>'.$lang->def('_END_TIME').' </b>'.$GLOBALS['regset']->databaseToRegional($end_time, 'date') 		: '' )
						.'<br />'
						, 'content');
				}
				$GLOBALS['page']->add( '<b>'.$lang->def('_ANALYSIS_DATE').' :</b> '.$date_now.'<br />'
				.'</div>', 'content');
				
				$group_user = $acl_man->getGroupAllUser($idst_group);
				
				$now = time();
				$num_comple = array();
				$time_comple = array();
				
				$query_time = "
				SELECT idCourse, status, UNIX_TIMESTAMP(date_inscr), UNIX_TIMESTAMP(date_first_access), UNIX_TIMESTAMP(date_complete)
				FROM ".$GLOBALS['prefix_lms']."_courseuser 
				WHERE idUser IN (".implode(',', $group_user).") ";
				if($start_time != '') $query_time .= " AND date_inscr >= '".$start_time."' ";
				if($end_time != '') $query_time .= " AND date_inscr <= '".$end_time."' ";
				$re_time = mysql_query($query_time);
			
				while(list($id_cp, $status, $d_iscr, $d_first, $d_complete) = mysql_fetch_row($re_time)) {
					
					if($d_complete != NULL) {
						//not complete
						//late is difference between iscr and now
						$day_compl = (int)(($d_complete - $d_iscr) / 86400);
						
						if(isset($num_comple[$id_cp])) ++$num_comple[$id_cp];
						else $num_comple[$id_cp] = 1;
						if(isset($time_comple[$id_cp])) $time_comple[$id_cp] += $day_compl;
						else $time_comple[$id_cp] = $day_compl;
					}
				}
				$this->_printTable($course, $num_comple, $time_comple);	
			}
		}
	}
	
	function _printTable(&$course, &$num_comple, &$time_comple) {
	
		$lang =& DoceboLanguage::createInstance('rp_report');
	
		// Table
		$GLOBALS['page']->add(
			'<table class="report_table" summary="'.$lang->def('_RD_SUMMAMRY_MANAGMENT').'">'
			.'<caption>'.$lang->def('_RD_CAPTION').'</caption>'
			.'<thead>'
			.'<tr>'."\n\t"
				.'<th colspan="2">'.$lang->def('_TH_COURSE').'</th>'."\n\t"
				.'<th colspan="5">'.$lang->def('_TH_USER').'</th>'."\n"
			.'</tr>'
			.'<tr>'."\n\t"
				.'<th rowspan="2">'.$lang->def('_TH_CODE_COURSE').'</th>'."\n\t"
				.'<th rowspan="2">'.$lang->def('_TH_NAME_COURSE').'</th>'."\n\t"
				.'<th>'.$lang->def('_COMPLETE_COURSE').'</th>'."\n\t"
				.'<th>'.$lang->def('_STDTIME_COMPLETE').'</th>'."\n\t"
				.'<th>'.$lang->def('_EFFTIME_COMPLETE').'</th>'."\n\t"
				.'<th colspan="2">'.$lang->def('_INITINERE').'</th>'."\n\t"
			.'</tr>'
			.'<tr>'."\n\t"
				.'<th class="image">'.$lang->def('_TH_NUM').'</th>'."\n\t"
				.'<th class="image">'.$lang->def('_TH_WEEK').'</th>'."\n\t"
				.'<th class="image">'.$lang->def('_TH_WEEK').'</th>'."\n\t"
				.'<th class="image">'.$lang->def('_TH_PERC').'</th>'."\n\t"
				.'<th class="image">'.$lang->def('_TH_PERM_LEVEL').'</th>'."\n\t"
			.'</tr>'
			.'</thead>'."\n\n"
			.'<tbody>'
		, 'content');
		
		// find some information
		
		$i = $eff = 0;
		$tot_comple = $avg_mediumTime = $avg_real_time = $avg_perc_time = $avg_lv = 0;
		
		while(list($id, $data) =  each($course) ) {
			
			$row = '<tr class="row'.( (++$i)%2 ? '' : '_col' ).'">'
				.'<td>'.$data['code'].'</td>'."\n\t"
				.'<td>'.$data['name'].'</td>'."\n\t";
			if(isset($num_comple[$id])) { 
				$row .= '<td class="image">'.$num_comple[$id].'</td>'."\n\t"
					.'<td class="image">'.number_format( ($course[$id]['mediumTime'] / 7), 2, '.', '').'</td>'."\n\t";
					
				$tot_comple += $num_comple[$id];
				$avg_mediumTime += $course[$id]['mediumTime'];
				
				if( $num_comple[$id] != 0 ) {
					$day_comple = ( $time_comple[$id] / $num_comple[$id] ); // medium time of course complete
					if($course[$id]['mediumTime'] != 0) $perc_comple = $day_comple / $course[$id]['mediumTime'];
					else $perc_comple = '0';
					$row .= '<td class="image">'.number_format( ($day_comple / 7), 2, '.', '').'</td>'."\n\t"
						.'<td class="image">'.number_format( $perc_comple*100, 2, '.', '').'%</td>'."\n\t";
					if($perc_comple < 0.70) {
						$row .= '<td class="image">1</td>';
						$avg_lv += 1;
					}
					elseif( ($perc_comple >= 0.70) && ($perc_comple < 0.90) ) {
						$row .= '<td class="image">2</td>';
						$avg_lv += 2;
					}
					else {
						$row .= '<td class="image">3</td>';
						$avg_lv += 3;
					}
					$eff++;
					$avg_real_time += $day_comple;
					$avg_perc_time += $perc_comple;
				}
				else {
					$row .= '<td class="image">&nbsp;</td>'."\n\t"
						.'<td class="image">&nbsp;</td>'."\n\t"
						.'<td class="image">&nbsp;</td>'."\n\t";
				}
				
			} else {
				$row .= '<td class="image">&nbsp;</td>'."\n\t"
					.'<td class="image">'.number_format( ($course[$id]['mediumTime'] / 7), 2, '.', '').'</td>'."\n\t"
					.'<td class="image">&nbsp;</td>'."\n\t"
					.'<td class="image">&nbsp;</td>'."\n\t"
					.'<td class="image">&nbsp;</td>'."\n\t";
					
				$avg_mediumTime += $course[$id]['mediumTime'];
			}
			$row .= '</tr>';
			$GLOBALS['page']->add( $row, 'content');
		}
		$GLOBALS['page']->add( '<tr class="total">'
			.'<td colspan="2"><b>'.$lang->def('_TOTAL').'</b></td>'
			.'<td class="image">'.$tot_comple.'</td>'
			.'<td class="image">'.( $i ? number_format( ( $avg_mediumTime / $i ) / 7, 2, '.', '') : '&nbsp;' ).'</td>'
			.'<td class="image">'.( $i ? number_format( ( ( $avg_real_time / $i ) / 7 ), 2, '.', '') : '&nbsp;' ).'</td>'
			.'<td class="image">'.( $i ? number_format( ( $avg_perc_time*100 / $i ), 2, '.', '').'%' : '&nbsp;' ).'</td>'
			.'<td class="image">'.( $eff ? number_format( ( $avg_lv / $eff ), 2, '.', '') : '&nbsp;' ).'</td>'
		.'</tr>', 'content');
		$GLOBALS['page']->add( 
			'</tbody>'
			.'</table>', 'content');
	}
	
	function exportAsCvs($org_chart_subdivision, $start_time, $end_time) {
		
		ob_end_clean();
		//content type forcing dowlad
		header("Content-type: application/download\n");
		//cache control
		header("Cache-control: private");
		//sending creation time
		header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
		//content type
		header('Content-Disposition: attachment; filename="report_performance '.gmdate('d-m-Y H i s').'.csv"');
		
		$lang =& DoceboLanguage::createInstance('rp_report');
		
		$acl_man 		= new DoceboACLManager();
		$course_man 	= new Man_Course();
		
		$elem_selected = unserialize(urldecode($_POST['elem_selected']));
		$user_selected = unserialize(urldecode($_POST['user_selected']));
		
		if(empty($user_selected)) exit;

		if($org_chart_subdivision == 1) {
			
			require_once($GLOBALS['where_framework'].'/lib/lib.orgchart.php');
			$org_man 	= new OrgChartManager();
			$org_name = $org_man->getFolderFormIdst($elem_selected);
		}
		
		// Retrive all the course
		$course =& $course_man->getAllCoursesWithMoreInfo();
		if(empty($course)) exit;
		
		if($org_chart_subdivision === 0) {
			
			$date_now = $GLOBALS['regset']->databaseToRegional(date("Y-m-d H:i:s")); 
			
			echo "\r\n";
			if($start_time != '' || $end_time != '') {
				
				echo ''.$lang->def('_TIME_BELT_2').' : '
					.( $start_time != '' 	? ' '.$lang->def('_START_TIME').' '.$GLOBALS['regset']->databaseToRegional($start_time, 'date') 	: '' )
					.( $end_time != '' 		? ' '.$lang->def('_END_TIME').' '.$GLOBALS['regset']->databaseToRegional($end_time, 'date') 		: '' )
					."\r\n";
			}
			echo ''.$lang->def('_ANALYSIS_DATE').' : '.$date_now."\r\n";
			
			$now = time();
			$num_comple = array();
			$time_comple = array();
			
			$query_time = "
			SELECT idCourse, status, UNIX_TIMESTAMP(date_inscr), UNIX_TIMESTAMP(date_first_access), UNIX_TIMESTAMP(date_complete)
			FROM ".$GLOBALS['prefix_lms']."_courseuser 
			WHERE idUser IN (".implode(',', $user_selected).") ";
			if($start_time != '') $query_time .= " AND cu.date_inscr >= '".$start_time."' ";
			if($end_time != '') $query_time .= " AND cu.date_inscr <= '".$end_time."' ";
			$re_time = mysql_query($query_time);
				
			while(list($id_cp, $status, $d_iscr, $d_first, $d_complete) = mysql_fetch_row($re_time)) {
				
				if($d_complete != NULL) {
					//not complete
					//late is difference between iscr and now
					$day_compl = (int)(($d_complete - $d_iscr) / 86400);
					
					if(isset($num_comple[$id_cp])) ++$num_comple[$id_cp];
					else $num_comple[$id_cp] = 1;
					if(isset($time_comple[$id_cp])) $time_comple[$id_cp] += $day_compl;
					else $time_comple[$id_cp] = $day_compl;
				}
			}
			$this->_printCsvTable($course, $num_comple, $time_comple);
		} else {
			
			$date_now = $GLOBALS['regset']->databaseToRegional(date("Y-m-d H:i:s")); 
			
			reset($org_name);
			while(list($idst_group, $folder_name) = each($org_name)) {
				
				
				echo "\r\n"
					.''.$lang->def('_FOLDER_NAME').' : '.$folder_name['name']
						.( $folder_name['type_of_folder'] == ORG_CHART_WITH_DESCENDANTS ? ' ('.$lang->def('_WITH_DESCENDANTS').')' : '' )."\r\n";
				if($start_time != '' || $end_time != '') {
					
					echo ''.$lang->def('_TIME_BELT_2').' : '
						.( $start_time != '' 	? ' '.$lang->def('_START_TIME').' '.$GLOBALS['regset']->databaseToRegional($start_time, 'date') 	: '' )
						.( $end_time != '' 		? ' '.$lang->def('_END_TIME').' '.$GLOBALS['regset']->databaseToRegional($end_time, 'date') 		: '' )
						."\r\n";
				}
				echo ''.$lang->def('_ANALYSIS_DATE').' : '.$date_now."\r\n";
				
				
				$group_user = $acl_man->getGroupAllUser($idst_group);
				
				$now = time();
				$num_comple = array();
				$time_comple = array();
				
				$query_time = "
				SELECT idCourse, status, UNIX_TIMESTAMP(date_inscr), UNIX_TIMESTAMP(date_first_access), UNIX_TIMESTAMP(date_complete)
				FROM ".$GLOBALS['prefix_lms']."_courseuser 
				WHERE idUser IN (".implode(',', $group_user).") ";
				if($start_time != '') $query_time .= " AND cu.date_inscr >= '".$start_time."' ";
				if($end_time != '') $query_time .= " AND cu.date_inscr <= '".$end_time."' ";
				$re_time = mysql_query($query_time);
				
				while(list($id_cp, $status, $d_iscr, $d_first, $d_complete) = mysql_fetch_row($re_time)) {
					
					if($d_complete != NULL) {
						//not complete
						//late is difference between iscr and now
						$day_compl = (int)(($d_complete - $d_iscr) / 86400);
						
						if(isset($num_comple[$id_cp])) ++$num_comple[$id_cp];
						else $num_comple[$id_cp] = 1;
						if(isset($time_comple[$id_cp])) $time_comple[$id_cp] += $day_compl;
						else $time_comple[$id_cp] = $day_compl;
					}
				}
				$this->_printCsvTable($course, $num_comple, $time_comple);	
			}
		}
		exit();
	}
	
	function _printCsvTable(&$course, &$num_comple, &$time_comple) {
		
		$lang =& DoceboLanguage::createInstance('rp_report');
		
		// Table
		echo $lang->def('_RD_CAPTION')."\n\n";
		
		echo $lang->def('_TH_COURSE').';;'
			.$lang->def('_TH_USER').';;;;;'."\n"
				.$lang->def('_TH_CODE_COURSE').';'
				.$lang->def('_TH_NAME_COURSE').';'
				.$lang->def('_COMPLETE_COURSE').';'
				.$lang->def('_STDTIME_COMPLETE').';'
				.$lang->def('_EFFTIME_COMPLETE').';'
				.$lang->def('_INITINERE').';'
			."\n"
				.';;'
				.$lang->def('_TH_NUM').';'
				.$lang->def('_TH_WEEK').';'
				.$lang->def('_TH_WEEK').';'
				.$lang->def('_TH_PERC').';'
				.$lang->def('_TH_PERM_LEVEL').''
			."\n";
		
		// find some information
		
		$i = $eff = 0;
		$tot_comple = $avg_mediumTime = $avg_real_time = $avg_perc_time = $avg_lv = 0;
		
		while(list($id, $data) =  each($course) ) {
			$i++;
			$row = ereg_replace(';', '', $data['code']).';'
				.ereg_replace(';', '', $data['name']).';';
			if(isset($num_comple[$id])) { 
				$row .= $num_comple[$id].';'
					.number_format( ($course[$id]['mediumTime'] / 7), 2, '.', '').';';
					
				$tot_comple += $num_comple[$id];
				$avg_mediumTime += $course[$id]['mediumTime'];
				
				if( $num_comple[$id] != 0 ) {
					$day_comple = ( $time_comple[$id] / $num_comple[$id] );
					if($course[$id]['mediumTime'] != 0) $perc_comple = $day_comple / $course[$id]['mediumTime'];
					else $perc_comple = '0';
					$row .= number_format( ($day_comple / 7), 2, '.', '').';'
						.number_format( $perc_comple*100, 2, '.', '').'%;';
					if($perc_comple < 0.70) {
						$row .= 1;
						$avg_lv += 1;
					}
					elseif( ($perc_comple >= 0.70) && ($perc_comple < 0.90) ) {
						$row .= 2;
						$avg_lv += 2;
					}
					else {
						$row .= 3;
						$avg_lv += 3;
					}
					$eff++;
					$avg_real_time += $day_comple;
					$avg_perc_time += $perc_comple;
				}else {
					$row .= ';'.number_format( ($course[$id]['mediumTime'] / 7), 2, '.', '').';;;';
					$avg_mediumTime += $course[$id]['mediumTime'];
				}
				
			} else {
				$row .= ';'.number_format( ($course[$id]['mediumTime'] / 7), 2, '.', '').';;;';
			}
			$row .= "\n";
			echo $row;
		}
		echo $lang->def('_TOTAL').';;'
			.$tot_comple.';'
			.( $i ? number_format( ( $avg_mediumTime / $i ) / 7, 2, '.', '') : '' ).';'
			.( $i ? number_format( ( ( $avg_real_time / $i ) / 7 ), 2, '.', '') : '' ).';'
			.( $i ? number_format( ( $avg_perc_time*100 / $i ), 2, '.', '').'%' : '' ).';'
			.( $eff ? number_format( ( $avg_lv / $eff ), 2, '.', '') : '' );
	}
}

?>