<?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: report.php 573 2006-08-23 09:38:54Z fabio $
 * @author	 Fabio Pirovano <fabio [at] docebo [dot] com>
 */

if($GLOBALS['current_user']->isAnonymous()) die("You can't access");

function reportlist() {

	require_once($GLOBALS['where_framework'].'/lib/lib.form.php');

	$lang =& DoceboLanguage::createInstance('report');

	$GLOBALS['page']->add('' .
		'<script type="text/javascript">' .
		'function report_disableCustom(drop, start_time, end_time) {' .
		'	var s_id = document.getElementById(start_time);' .
		'	var e_id = document.getElementById(end_time);' .
		'	var drop_id = document.getElementById(drop);' .
		'	if(drop_id.selectedIndex == 0) {' .
		'		s_id.disabled = false;'.
		'		e_id.disabled = false;'.
		'	} else {' .
		'		s_id.disabled = true;'.
		'		e_id.disabled = true;'.
		'	}' .
		'}' .
		'</script>' .
		'', 'page_head');
	

	$query_report = "
	SELECT id_report, report_name, class_name, file_name 
	FROM ".$GLOBALS['prefix_lms']."_report ";
	$re_report = mysql_query($query_report);
	
	$GLOBALS['page']->add(
		getTitleArea($lang->def('_REPORT'), 'report', $lang->def('_ALT_REPORT'))
		.'<div class="std_block">'
		.'<span class="text_bold">'.$lang->def('_REPORT_LIST_CAPTION').'</span><br />', 'content');
	while(list($id_report, $report_name, $class_name, $file_name) = mysql_fetch_row($re_report)) {

		require_once($GLOBALS['where_lms'].'/admin/modules/report/'.$file_name);
		
		$obj_report = new $class_name( $id_report, $report_name );
		$GLOBALS['page']->add($obj_report->report_mask($report_name, $lang).'<br />', 'content');
	}
	$GLOBALS['page']->add('</div>', 'content');
}

function openreport() {

	$lang =& DoceboLanguage::createInstance('report');

	$id_report = importVar('id_report', true, 0);

	$query_report = "
	SELECT class_name, file_name, report_name
	FROM ".$GLOBALS['prefix_lms']."_report
	WHERE id_report = '".$id_report."'";
	$re_report = mysql_query($query_report);

	if(mysql_num_rows($re_report) == 0) {
		reportlist();
		return;
	}
	list($class_name, $file_name, $report_name) = mysql_fetch_row($re_report);

	require_once($GLOBALS['where_lms'].'/admin/modules/report/'.$file_name);
	$obj_report = new $class_name( $id_report );
	$obj_report->play(	'index.php?modname=report&op=openreport&id_report='.$id_report,
						'index.php?modname=report&op=reportlist');
	
}

function reportDispatch($op) {

	switch($op) {
		case "reportlist" : {
			reportlist();
		};break;
		case "openreport" : {
			openreport();
		};break;
	}

}

?>