<?php
/**
 * @package linea21.modules
 * @subpackage dashboard
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

/***********************
* paramétrage du fichier XML
* 
* *************************/

/*********************
* contenu du fichier XML 
* valeurs posssibles : 
* P (format public) 
* A (format admin)
************************/
$format="P";

/*********************
* liste des indicateurs 
* valeurs posssibles : 
* R (statut<>'E') 
* P (statut='P')
************************/
if ($format=="A")$filter_sdi="R";
else $filter_sdi="P";
/*********************
* liste des valeurs
* valeurs posssibles : 
* D (statut<>'E') 
* SCP (statut='P') sdiv_date_published ASC
* SCD (statut='P') sdiv_date_published DESC
* SCA (statut<>'E') sdiv_date_published DESC
************************/

if ($format=="A") $filter_value="D";
else $filter_value="SCD";

define('TAB_LINE2',"");
define('END_LINE2',"");
include_once("../config/define.php");
include_once("../config/server.php");
include_once("../lib/no_cache.php");
include_once("../lib/functions_auth.php");
include_once('../lib/lang.php'); 
IncludeAdminLang("dashboard");
include_once("../lib/lib_common.php");
include_once("../class/system/class.".SQL.".php");
include_once(SQL.'.inc.php');
include_once('../class/class.sdi.php');
$sql_entity=SQL;
$sql_object = new $sql_entity;
$sql_object -> DBInitialise();
$sql_object -> DBConnexion();


$sdi_object= new sdi;
$result=$sql_object->DBSelect($req_list_theme);

$req_sdi=SQL_getListSdi($filter_sdi, $valueparam=0);
$result_sdi = $sql_object -> DBSelect($req_sdi);
header('Content-Type: text/xml');
$listing="<?xml version=\"1.0\" encoding=\"".CHARSET."\"?>".END_LINE2."<dashboard>" . END_LINE2;

$current_sdtheme='';
$current_theme='';
for ($i=0;$i<count($result);$i++){
	if ($result[$i]['sdtheme_id']!=$current_sdtheme) {
		$current_sdtheme=$result[$i]['sdtheme_id'];
		$aff_theme=false;
		if ($i!=0)$listing.=TAB_LINE2."</theme>".END_LINE2."</sdtheme>" . END_LINE2;
		$listing.="<sdtheme id=\"".$result[$i]['sdtheme_id']."\" title=\"".formatText($result[$i]['sdtheme_name'], '2XML')."\">" . END_LINE2;
		
	}
	else $aff_theme=true;
	
	if ($result[$i]['theme_id']!=$current_theme) {
		$current_theme=$result[$i]['theme_id'];
		if ($aff_theme==true) $listing.=TAB_LINE2."</theme>" . END_LINE2;
		$listing.= TAB_LINE2."<theme id=\"".$result[$i]['theme_id']."\" title=\"".formatText($result[$i]['theme_name'], '2XML')."\">" . END_LINE2;		
	}		

	
	for ($j=0;$j<count($result_sdi);$j++){
	if ($result[$i]['theme_id']==$result_sdi[$j]['sdii_theme']) {
	
	
	$req_sdii=SQL_getInfoSdi($result_sdi[$j]['sdii_id']);
$result_sdii = $sql_object -> DBSelect($req_sdii);

$req_sdir=SQL_getRules( $result_sdi[$j]['sdii_id'], $sql_object, -1);
$result_r = $sql_object -> DBSelect($req_sdir);

$req_sdie=SQL_getEvaluation( $result_sdi[$j]['sdii_id'], $sql_object,-1);
$result_e = $sql_object -> DBSelect($req_sdie);

$req_sdip=SQL_getProvider( $result_sdi[$j]['sdii_id'], $sql_object,-1);
$result_p = $sql_object -> DBSelect($req_sdip);

$req_scale=SQL_getlistscale(0);
$resultscale = $sql_object -> DBSelect($req_scale);

	//formattage des infos générales
	$listing.=TAB_LINE2.TAB_LINE2."<indicator id=\"".$result_sdi[$j]['sdii_id']."\">" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<title>".formatText($result_sdi[$j]['sdii_name'], '2XML')."</title>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<description>".formatText($result_sdii[0]['sdii_description'], '2XML')."</description>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<comment>".formatText($result_sdii[0]['sdii_comment'], '2XML')."</comment>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<range>".formatText($result_sdii[0]['sdii_range'], '2XML')."</range>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<goal>".formatText($result_sdii[0]['sdii_goal'], '2XML')."</goal>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<consulting>".formatText($result_sdii[0]['sdii_consulting'], '2XML')."</consulting>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<unit>".formatText($result_sdii[0]['sdii_unit'], '2XML')."</unit>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<max_value>".formatText($result_sdii[0]['sdii_max_value'], '2XML')."</max_value>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<min_value>".formatText($result_sdii[0]['sdii_min_value'], '2XML')."</min_value>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<threshold_value>".formatText($result_sdii[0]['sdii_threshold_value'], '2XML')."</threshold_value>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<threshold_relative>".formatText($result_sdii[0]['sdii_threshold_relative'], '2XML')."</threshold_relative>" . END_LINE2;
	
	if ($format=="A"){
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<frequency>".formatText($result_sdii[0]['sdii_frequency'], '2XML')."</frequency>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<date_crea>".formatText($result_sdii[0]['sdii_date_crea'], '2XML')."</date_crea>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<last_modify>".formatText($result_sdii[0]['sdii_last_modify'], '2XML')."</last_modify>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<statut>".formatText($result_sdii[0]['sdii_statut'], '2XML')."</statut>" . END_LINE2;
	//formattage des infos du fournisseur
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<provider id=\"".$result_p[0]['sdip_id']."\">". END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<title>".formatText($result_p[0]['sdip_name'], '2XML')."</title>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<service>".formatText($result_p[0]['sdip_service'], '2XML')."</service>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<description>".formatText($result_p[0]['sdip_description'], '2XML')."</description>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<incharge>".formatText($result_p[0]['sdip_incharge'], '2XML')."</incharge>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<address>".formatText($result_p[0]['sdip_address'], '2XML')."</address>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<phone>".formatText($result_p[0]['sdip_phone'], '2XML')."</phone>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<fax>".formatText($result_p[0]['sdip_fax'], '2XML')."</fax>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<email>".formatText($result_p[0]['sdip_email'], '2XML')."</email>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<date_crea>".formatText($result_p[0]['date_c'], '2XML')."</date_crea>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<last_modify>".formatText($result_p[0]['date_m'], '2XML')."</last_modify>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."</provider>". END_LINE2;
		
	//formattage des infos de réglementation
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<reglementation id=\"".$result_r[0]['sdir_id']."\">". END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<title>".formatText($result_r[0]['sdir_title'], '2XML')."</title>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<body>".formatText($result_r[0]['sdir_body'], '2XML')."</body>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<referer_uri>".formatText($result_r[0]['sdir_referer_uri'], '2XML')."</referer_uri>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<mask_uri>".formatText($result_r[0]['sdir_mask_uri'], '2XML')."</mask_uri>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<date_crea>".formatText($result_p[0]['date_c'], '2XML')."</date_crea>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<last_modify>".formatText($result_p[0]['date_m'], '2XML')."</last_modify>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."</reglementation>". END_LINE2;
	
	//formattage des infos d'évaluation
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."<evaluation id=\"".$result_e[0]['sdie_id']."\">". END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<scale_compare>".formatText($result_e[0]['sdie_scale_compare'], '2XML')."</scale_compare>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<fiability>".formatText($result_e[0]['sdie_fiability'], '2XML')."</fiability>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<accessibility>".formatText($result_e[0]['sdie_accessibility'], '2XML')."</accessibility>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<lisibility>".formatText($result_e[0]['sdie_lisibility'], '2XML')."</lisibility>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<relevance>".formatText($result_e[0]['sdie_relevance'], '2XML')."</relevance>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<global_performance>".formatText($result_e[0]['sdie_global_performance'], '2XML')."</global_performance>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<date_crea>".formatText($result_p[0]['date_c'], '2XML')."</date_crea>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<last_modify>".formatText($result_p[0]['date_m'], '2XML')."</last_modify>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2."</evaluation>". END_LINE2;
	}
	//formattage des valeurs
	for ($z=0;$z<count($resultscale);$z++){
	
	$req_sdiav=SQL_getAllValue($filter_value, $resultscale[$z]['scale_id'], $result_sdi[$j]['sdii_id']);	
	$result_value = $sql_object -> DBSelect($req_sdiav);
	if ($result_value[0]['sdiv_value']<>""){
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<scale id=\"".$resultscale[$z]['scale_id']."\">". END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<title>".formatText($resultscale[$z]['scale_denomination'], '2XML')."</title>" . END_LINE2;
	for ($h=0;$h<count($result_value);$h++){
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<value id=\"".$result_value[$h]['sdiv_id']."\">". END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<num_value>".formatText($result_value[$h]['sdiv_value'], '2XML')."</num_value>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<date_published>".formatText($result_value[$h]['date_p'], '2XML')."</date_published>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<date_crea>".formatText($result_value[$h]['date_c'], '2XML')."</date_crea>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<last_modify>".formatText($result_value[$h]['date_m'], '2XML')."</last_modify>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."<statut>".formatText($result_value[$h]['sdiv_statut'], '2XML')."</statut>" . END_LINE2;
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."</value>". END_LINE2;
	}
	$listing.=TAB_LINE2.TAB_LINE2.TAB_LINE2.TAB_LINE2."</scale>". END_LINE2;
	}
	}	
	
	$listing.=TAB_LINE2.TAB_LINE2."</indicator>" . END_LINE2; 
	}
	}

}
$listing.=TAB_LINE2."</theme>".END_LINE2."</sdtheme>" . END_LINE2."</dashboard>" . END_LINE2;

echo $listing;

?>