extranet/includes/commentaires/commentaires.php

265 lines
6.6 KiB
PHP

<?php
function commentaires_siren($content){
$pattern = '/(.*?)<siren>([0-9]{3}) ([0-9]{3}) ([0-9]{3})<\/siren>(.*?)/i';
$replace = '$1<a href=/?page=identite&siret=$2$3$4>$2 $3 $4</a>$5';
$output = preg_replace($pattern, $replace, $content);
return $output;
}
function commentaires_liste($content){
$pattern = '/(.*?)<li([\=|\+|-]?)>(.*)/i';
if(preg_match($pattern, $content, $matches)){
switch($matches[2]){
case '+':
$class = 'plus';
$replace = '$1<span class="'.$class.'">$3</span>';
break;
case '-':
$class = 'moins';
$replace = '$1<span class="'.$class.'">$3</span>';
break;
case '=':
$replace = '$1<image style="vertical-align:middle;" src="./img/li-egale.gif">$3';
break;
default:
$class = 'point';
$replace = '$1<span class="'.$class.'">$3</span>';
break;
}
}
$output = preg_replace($pattern, $replace, $content);
return $output;
}
function commentaires_image($content){
$pattern = '/IMAGE\((.*?)\)/i';
preg_match($pattern, $content, $matches);
$replace = '<img src="./img/commentaires/'.strtolower($matches[1]).'"/>';
$output = str_replace($matches[0], $replace, $content);
return $output;
}
function commentaires_lien($content){
$path = array(
'pdf' => '/datafile.php?q=commentaires',
'html' => '',
);
$pattern = "/<lien='(.*?).(pdf|html|htm)'>(.*?)<\/lien>/i";
preg_match($pattern, $content, $matches);
if(count($matches)>0){
switch($matches[2]){
case 'pdf':
$content = str_replace(
$matches[0],
"<a href='".$path['pdf']."/".$matches[1].".".
$matches[2]."' target='_blank'>".
$matches[3]."</a>",
$content);
break;
case 'htm':
case 'html':
$content = str_replace(
$matches[0],
"<a href='".$path['html'].$matches[1].".".
$matches[2]."' target='_blank'>".
$matches[3]."</a>",
$content);
break;
}
}
return $content;
}
function commentaires_graph($id, $titre, $ratios = array() ){
$data = array();
$pattern = '/(Rs?)\[(.*)]#(.{1})/';
foreach($ratios as $ratio){
//FB::log($ratio, 'ratio');
if( preg_match($pattern, $ratio, $matches) ){
$typeRatio = $matches[1];
$numRatio = $matches[2];
$typeElement = $matches[3];
$titreRatio = commentaires_graph_lib($numRatio);
if ($typeElement != 'R'){
switch($typeRatio){
case 'R' : $titreRatio.= ' - Entreprise'; break;
case 'Rs' : $titreRatio.= ' - Secteur'; break;
}
}else{
$supPattern = '/\(.*?\)/';
$titreRatio = preg_replace($supPattern, '', $titreRatio);
$supPattern = '/[ ]/';
$titreRatio = preg_replace($supPattern, '<*br*>', $titreRatio);
}
$data['y'][] = array(
'titre' => $titreRatio,
'data' => commentaires_graph_y($typeRatio, $numRatio),
'style' => $typeElement,
);
//FB::log($data['y'], 'data');
}
}
$data['x'] = commentaires_graph_x();
if ($typeElement == 'R'){
$output = commentaires_graph_radar($id, $titre, $data);
} else {
$output = commentaires_graph_xy($id, $titre, $data);
}
return $output;
}
function commentaires_graph_lib($numRatio){
global $ratiosInfos;
return htmlspecialchars_decode(
$ratiosInfos['r'.$numRatio]['libelle'],
ENT_QUOTES);
}
function commentaires_graph_x(){
global $bilansInfos;
$output = array();
foreach($bilansInfos as $bilan){
$output[] = $bilan['dateCloture'];
}
return $output;
}
function commentaires_graph_y($typeRatio, $numRatio){
global $ratiosEntrep, $ratiosSecteur;
//FB::log($typeRatio, 'typeRatio');
switch($typeRatio){
case 'R' : $tabRatio = $ratiosEntrep; break;
case 'Rs' : $tabRatio = $ratiosSecteur; break;
}
$output = array();
foreach($tabRatio as $key => $val){
//FB::log($val['r'.$numRatio], 'val');
$output[$key] = $val['r'.$numRatio];
}
return $output;
}
function commentaires_graph_radar($id, $titre, $data){
require_once 'phpchartdir/phpchartdir.php';
$path = PATH_SITE.'/cache/imgcache/';
$file = $id.'.png';
if(count($data)<=1){
$output = 0;
}else{
FB::log($data, 'data');
//Tri des données
foreach($data['y'] as $yKey => $y){
$i = 0;
foreach($y['data'] as $val){
$dataTri[$data['x'][$i]] = $val;
$i++;
}
ksort($dataTri);
$data['y'][$yKey]['data'] = array_values($dataTri);
}
sort($data['x']);
FB::log($data, 'data');
foreach($data['y'] as $val){
$num = count($val['data'])-1;
$gdata[] = $val['data'][$num];
$labels[] = $val['titre'];
}
}
FB::log($gdata, 'gdata');
$c = new PolarChart(530, 480);
$c->setPlotArea(275, 240, 150);
$c->addAreaLayer($gdata, 0x9999ff);
$c->angularAxis->setLabels($labels);
if( $c->makeChart($path.$file) === true ){
$output = $file;
}else{
$output = false;
}
return $output;
}
function commentaires_graph_xy($id, $titre, $data){
require_once 'phpchartdir/phpchartdir.php';
$path = PATH_SITE.'/cache/imgcache/';
$file = $id.'.png';
if(count($data)<=1){
$output = 0;
}else{
//Tri des données
foreach($data['y'] as $yKey => $y){
$i = 0;
foreach($y['data'] as $val){
$dataTri[$data['x'][$i]] = $val;
$i++;
}
ksort($dataTri);
$data['y'][$yKey]['data'] = array_values($dataTri);
}
sort($data['x']);
//Génération du graphique
$c = new XYChart(500, 350);
$c->addTitle($titre, 'times.ttf', 10);
$c->yAxis->setTitle('EUR');
$c->yAxis->setWidth(2);
$c->xAxis->setTitle('Années');
$c->xAxis->setWidth(2);
$legendObj = $c->addLegend2(25, 25, -2, "times.ttf", 9);
$legendObj->setBackground(Transparent, Transparent);
$c->setPlotArea(50, 90, 280, 200);
//Génération des labels
$labelsX = array();
foreach($data['x'] as $x){
$annee = substr($x, 0, 4);
$mois = substr($x, 4, 2);
$jour = substr($x, 6, 2);
$labelsX[] = $annee;
}
//Détection multi-bar
$graphStyleMH = false;
$precStyle = '';
foreach($data['y'] as $ydata){
if($ydata['style']=='H' && $precStyle == 'H'){
$graphStyleMH = true;
}
$precStyle = $ydata['style'];
}
//Affichage standard
if(!$graphStyleMH){
foreach($data['y'] as $ydata){
switch($ydata['style']){
case 'L':
$lineLayer = $c->addLineLayer(
$ydata['data'], -1, $ydata['titre']);
$lineLayer->setLineWidth(2);
break;
case 'H':
$c->addBarLayer(
$ydata['data'], -1, $ydata['titre']);
break;
}
}
//Affichage multibar
}else{
$layer = $c->addBarLayer2(Side);
$color = array(0xff8080, 0x80ff80);
$i = 0;
foreach($data['y'] as $ydata){
FB::log($ydata['data'], 'ydata');
$layer->addDataSet($ydata['data'], $color[$i], $ydata['titre']);
$i++;
}
}
$c->xAxis->setLabels($labelsX);
if( $c->makeChart($path.$file) === true ){
$output = $file;
}
else{
$output = false;
}
}
return $output;
}