<?php
/*
 * Created on 26 mars 07 by Eric Marguin
 *
 * Script to display the tracking of the students in the learning paths.
 */
 
$language_file = array ('registration', 'index', 'tracking', 'exercice', 'scorm');
$cidReset = true;
include ('../inc/global.inc.php');
include_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
include_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
include_once('../newscorm/learnpath.class.php');
include_once('../newscorm/learnpathItem.class.php');
require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');

$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
if($export_csv)
{
	ob_start();
}
$csv_content = array();

// hgz 20070724 users can see themself course process
//if(!CourseManager :: is_course_teacher($_user['user_id'], $_GET['course']) && !Tracking :: is_allowed_to_coach_student($_user['user_id'],$_GET['student_id']))
if(!CourseManager :: is_course_teacher($_user['user_id'], $_GET['course']) && !Tracking :: is_allowed_to_coach_student($_user['user_id'],$_GET['student_id']) && $_user['user_id'] != $_GET['student_id'])
{
	Display::display_header('');
	api_not_allowed();
	Display::display_footer();
}

$_course = CourseManager :: get_course_information($_GET['course']);
$_course['dbNameGlu'] = $_configuration['table_prefix'] . $_course['db_name'] . $_configuration['db_glue'];
$cidReq = $_GET['course'];

if(!empty($_GET['origin']) && $_GET['origin'] == 'user_course')
{
	$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
	$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".$_GET['course'], "name" => get_lang("Users"));
}
else if(!empty($_GET['origin']) && $_GET['origin'] == 'tracking_course')
{
	$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
	$interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$_GET['course'].'&studentlist=true', "name" => get_lang("Tracking"));
}
else
{
	$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
	$interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang("MyStudents"));
 	$interbreadcrumb[] = array ("url" => "myStudents.php?student=".$_GET['student_id'], "name" => get_lang("StudentDetails"));
 	$nameTools=get_lang("DetailsStudentInCourse");
}

$interbreadcrumb[] = array("url" => "myStudents.php?student=".$_GET['student_id']."&course=".$_GET['course']."&details=true&origin=".$_GET['origin'] , "name" => get_lang("DetailsStudentInCourse"));

$nameTools = get_lang('Learnpath');

$css_url = api_get_path(WEB_CODE_PATH) . 'css/' . api_get_setting('stylesheets') . '/scorm.css';
$htmlHeadXtra[] = ''.'<style type="text/css" media="screen, projection">
		/*<![CDATA[*/
		@import "' . $css_url . '";
		/*]]>*/
	</style>';

$htmlHeadXtra[] = get_table_style_ie6();

Display :: display_header($nameTools);

$user_id = intval($_GET['student_id']);
$lp_id = intval($_GET['lp_id']);

$sql = 'SELECT name 
		FROM '.Database::get_course_table(TABLE_LP_MAIN, $_course['db_name']).'
		WHERE id='.$lp_id;
$rs = api_sql_query($sql, __FILE__, __LINE__);
$lp_title = mysql_result($rs, 0, 0);

$sql = 'SELECT lastname, firstname 
		FROM '.Database::get_main_table(TABLE_MAIN_USER).'
		WHERE user_id='.$user_id;
$rs = api_sql_query($sql, __FILE__, __LINE__);
$name = mysql_result($rs, 0, 0).' '.mysql_result($rs, 0, 1);

echo '
	  <div align="right">
			<a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
			<a href="'.$_SERVER['PHP_SELF'].'?export=csv&'.$_SERVER['QUERY_STRING'].'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
		 </div>
	<div class="clear"></div>';

$list = learnpath :: get_flat_ordered_items_list($lp_id);

$origin = 'tracking';

include_once('../newscorm/lp_stats.php');

Display :: display_footer();
?>

