extranet/includes/commentaires/commentaires.php

260 lines
6.4 KiB
PHP
Raw Normal View History

<?php
2010-03-30 09:58:23 +00:00
function commentaires_siren($content){
$pattern = '@<siren>([0-9]{3}) ([0-9]{3}) ([0-9]{3})</siren>@si';
$replace = '<a href=/?page=identite&siret=$1$2$3>$1 $2 $3</a>';
$output = preg_replace($pattern, $replace, $content);
return $output;
}
2010-04-01 08:51:39 +00:00
function commentaires_liste($content){
2010-04-01 09:50:47 +00:00
$pattern = '/(.*?)<li([\+|-]?)>(.+?)/i';
2010-04-01 08:51:39 +00:00
if(preg_match($pattern, $content, $matches)){
switch($matches[2]){
case '+':
$class = 'plus';
break;
case '-':
$class = 'moins';
break;
default:
$class = 'point';
break;
}
$replace = '$1<span class="'.$class.'">$3</span>';
}
$output = preg_replace($pattern, $replace, $content);
return $output;
}
function commentaires_image($content){
2010-04-01 09:50:47 +00:00
$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;
2010-04-01 08:51:39 +00:00
}
2010-03-30 09:58:23 +00:00
function commentaires_lien($content){
$path = array(
'pdf' => '/datafile.php?q=commentaires',
2010-03-31 15:53:14 +00:00
'html' => '/rouerelance',
2010-03-30 09:58:23 +00:00
);
2010-03-30 13:58:13 +00:00
$pattern = "/<lien='(.*?).(pdf|html|htm)'>(.*?)<\/lien>/i";
2010-03-30 09:58:23 +00:00
preg_match($pattern, $content, $matches);
if(count($matches)>0){
switch($matches[2]){
case 'pdf':
2010-03-30 10:17:20 +00:00
$content = str_replace(
$matches[0],
"<a href='".$path['pdf']."/".$matches[1].".".
$matches[2]."' target='_blank'>".
$matches[3]."</a>",
$content);
2010-03-30 09:58:23 +00:00
break;
2010-03-30 13:58:13 +00:00
case 'htm':
case 'html':
$content = str_replace(
$matches[0],
"<a href='".$path['html']."/".$matches[1].".".
$matches[2]."' target='_blank'>".
$matches[3]."</a>",
$content);
break;
2010-03-30 09:58:23 +00:00
}
}
return $content;
}
function commentaires_graph($id, $titre, $ratios = array() ){
$data = array();
2010-04-01 16:33:24 +00:00
$pattern = '/(Rs?)\[(.*)]#(.{1})/';
foreach($ratios as $ratio){
2010-04-01 16:33:24 +00:00
//FB::log($ratio, 'ratio');
if( preg_match($pattern, $ratio, $matches) ){
$typeRatio = $matches[1];
$numRatio = $matches[2];
$typeElement = $matches[3];
$titreRatio = commentaires_graph_lib($numRatio);
2010-04-01 16:33:24 +00:00
if ($typeElement != 'R'){
switch($typeRatio){
case 'R' : $titreRatio.= ' - Entreprise'; break;
case 'Rs' : $titreRatio.= ' - Secteur'; break;
}
}else{
$supPattern = '/\(.*?\)/';
$titreRatio = preg_replace($supPattern, '', $titreRatio);
2010-04-01 16:48:13 +00:00
$supPattern = '/[ ]/';
$titreRatio = preg_replace($supPattern, '<*br*>', $titreRatio);
}
$data['y'][] = array(
'titre' => $titreRatio,
'data' => commentaires_graph_y($typeRatio, $numRatio),
'style' => $typeElement,
);
2010-04-01 16:33:24 +00:00
//FB::log($data['y'], 'data');
}
}
2010-04-01 16:33:24 +00:00
$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;
2010-04-01 16:33:24 +00:00
//FB::log($typeRatio, 'typeRatio');
switch($typeRatio){
case 'R' : $tabRatio = $ratiosEntrep; break;
case 'Rs' : $tabRatio = $ratiosSecteur; break;
}
$output = array();
foreach($tabRatio as $key => $val){
2010-04-01 16:33:24 +00:00
//FB::log($val['r'.$numRatio], 'val');
$output[$key] = $val['r'.$numRatio];
}
return $output;
2010-04-01 16:33:24 +00:00
}
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');
2010-04-01 16:48:13 +00:00
$c = new PolarChart(530, 480);
$c->setPlotArea(275, 240, 150);
2010-04-01 16:33:24 +00:00
$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;
}