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

class Report {
	
	var $id_report;
	
	var $report_name = '';
	
	var $report_descr = '';
	
	function Report($id_report, $report_name = false) {
		
		$this->id_report = $id_report;
		if($report_name == false) {
			$this->_load();
		} else {
			$lang =& DoceboLanguage::createInstance('report');
			$this->report_name 	= $lang->def('_'.$report_name);
			$this->report_descr = $lang->def('_'.$report_name.'_DESCRIPTION');
		} 
	}
	
	/**
	 * load the report info into the class variables
	 */
	function _load() {
		
		$lang =& DoceboLanguage::createInstance('report');
		
		$query_report = "
		SELECT report_name 
		FROM ".$GLOBALS['prefix_lms']."_report 
		WHERE id_report = '".$this->id_report."'";
		$re_report = mysql_query($query_report);
		list($report_name) = mysql_fetch_row($re_report);
		
		$this->report_name 		= $lang->def('_'.$report_name);
		$this->report_descr 	= $lang->def('_'.$report_name.'_DESCRIPTION');
	}
	
	function report_mask($report_name, &$lang) {
		
		$time_belt = array(
			0 		=> $lang->def('_CUSTOM_BELT'),
			7 		=> $lang->def('_LAST_WEEK'),
			31		=> $lang->def('_LAST_MONTH'),
			93 		=> $lang->def('_LAST_THREE_MONTH'),
			186 	=> $lang->def('_LAST_SIX_MONTH'),
			365 	=> $lang->def('_LAST_YEAR'),
		);
		
		$html = '<div class="report_box">'
			.'<h2>'.$this->report_name.'</h2>'
			.'<p class="descr">'
				.'<span>'.$lang->def('_REPORT_DESCRIPTION').' : </span>'.$this->report_descr
			.'</p>'
			.Form::openForm('report_'.$this->id_report, 'index.php?modname=report&amp;op=openreport&amp;id_report='.$this->id_report)

			.Form::openElementSpace()
			.Form::getDropdown($lang->def('_TIME_BELT'), 'time_belt_'.$this->id_report, 'time_belt', $time_belt, '', '', '' ,
				' onchange="report_disableCustom( \'time_belt_'.$this->id_report.'\', \'start_time_'.$this->id_report.'\', \'end_time_'.$this->id_report.'\' )"')

			.Form::getOpenFieldset($lang->def('_CUSTOM_BELT'), 'fieldset_'.$this->id_report)
			.Form::getDatefield($lang->def('_START_TIME'), 'start_time_'.$this->id_report, 'start_time', '')
			.Form::getDatefield($lang->def('_END_TIME'), 'end_time_'.$this->id_report, 'end_time', '')
			.Form::getCloseFieldset()
	
			.Form::getCheckbox(	$lang->def('ORG_CHART_SUBDIVISION'),
								'org_chart_subdivision_'.$this->id_report,
								'org_chart_subdivision',
								1 )
			.Form::closeButtonSpace()
	
			.Form::openButtonSpace()
			.Form::getButton('report_alluser_'.$this->id_report, 'report_alluser', $lang->def('_REPORT_FOR_ALL'), 'report_alluser')
			.Form::getButton('report_seluser_'.$this->id_report, 'report_seluser', $lang->def('_REPORT_FOR_SEL'), 'report_seluser')
			.Form::closeButtonSpace()
			.Form::closeForm()
			.'</div>';
		return $html;
	} 
	
	function play($jump_url, $back_url, $alluser, $org_chart_subdivision, $start_rime, $end_time) {
	
	}
	
	function &getAllUserIdst() {
		
		$p_dr 	= new PeopleDataRetriever($GLOBALS['dbConn'], $GLOBALS['prefix_fw']);
		
		$userlevelid = $GLOBALS['current_user']->getUserLevelId();
		if( $userlevelid != ADMIN_GROUP_GODADMIN ) {
			require_once($GLOBALS['where_framework'].'/lib/lib.adminmanager.php');
			$adminManager = new AdminManager();
			$p_dr->intersectGroupFilter(
				$adminManager->getAdminTree($GLOBALS['current_user']->getIdSt())
			);
		}
				
		$re_people = $p_dr->getAllRowsIdst();
		
		$user_selected = array();
		if(!$re_people) return $user_selected;
		
		while(list($idst) = mysql_fetch_row($re_people)) {
			
			$user_selected[$idst] = $idst; 
		}
		
		return $user_selected;
	}
	
	
	/**
	 * function used for debug 
	 * @param string	$back_url	the url of the main page
	 */
	function hello($back_url) {
		
		$lang =& DoceboLanguage::createInstance('report');
		
		$page_title = array(
			str_replace('&', '&amp;', $back_url) => $lang->def('_REPORT'),
			$this->report_name
		);
		$GLOBALS['page']->add(
			getTitleArea($page_title, 'report', $lang->def('_ALT_REPORT'))
			.'<div class="std_block">'
			.'Hello i\'m '.$this->report_name.' with id : '.$this->id_report.' and i do this: <br />'
			.$this->report_descr
			.'</div>', 'content');
	}
	
}

?>