extranet/includes/commentaires/commentaires.php

295 lines
7.4 KiB
PHP
Raw Normal View History

<?php
2010-03-30 09:58:23 +00:00
function commentaires_siren($content){
2010-05-27 09:41:20 +00:00
$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';
2010-03-30 09:58:23 +00:00
$output = preg_replace($pattern, $replace, $content);
return $output;
}
2010-04-01 08:51:39 +00:00
function commentaires_liste($content){
2010-04-16 16:44:44 +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';
$replace = '$1<span class="'.$class.'">$3</span>';
2010-04-01 08:51:39 +00:00
break;
case '-':
$class = 'moins';
$replace = '$1<span class="'.$class.'">$3</span>';
2010-04-01 08:51:39 +00:00
break;
2010-04-16 16:00:15 +00:00
case '=':
2010-04-16 16:44:44 +00:00
$replace = '$1<image style="vertical-align:middle;" src="./img/li-egale.gif">$3';
2010-04-16 16:00:15 +00:00
break;
2010-04-01 08:51:39 +00:00
default:
$class = 'point';
$replace = '$1<span class="'.$class.'">$3</span>';
2010-04-01 08:51:39 +00:00
break;
}
}
$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);
2010-04-02 14:29:37 +00:00
$replace = '<img src="./img/commentaires/'.strtolower($matches[1]).'"/>';
2010-04-01 09:50:47 +00:00
$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-04-15 14:24:35 +00:00
'html' => '',
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],
2010-04-15 14:24:35 +00:00
"<a href='".$path['html'].$matches[1].".".
2010-03-30 13:58:13 +00:00
$matches[2]."' target='_blank'>".
$matches[3]."</a>",
$content);
break;
2010-03-30 09:58:23 +00:00
}
}
return $content;
}
function commentaires_graphique($content){
$pattern = '/\[GRAPHIQUE id=(.*?) titre=\'(.*?)\',(.*)]/';
if( preg_match($pattern, $content, $matches) ){
FB::log($matches,'graphique');
$image_id = $matches[1];
$titre = $matches[2];
//Génération id/nom fichier graphique
if (($siret*1)==0 || ($siren*1)<100){
$id = 'gcomment-'.$idEntreprise.'-'.$image_id;
}else{
$id = 'gcomment-'.$siret.'-'.$image_id;
}
//Determine le type du graphique
$type = '';
$typePattern = array(
'histo' => '/(Rs?\[.*]#H,?){1,}/',
'radar' => '/(R\[.*]#R,?){1,}/',
'stacked' => '/(R\[.*],?){1,};(R\[.*],?){1,}/',
);
foreach($typePattern as $type => $pattern){
if (preg_match($pattern,$matches[3], $match_type)>0){
FB::log($match_type, $type);
break;
}
}
switch($type){
case 'histo':
$image_file = commentaires_graph_histo($id, $titre, $matches[3]);
break;
case 'radar':
$image_file= commentaires_graph_radar($id, $titre, $matches[3]);
break;
case 'stacked':
$image_file = commentaires_graph_stacked($id, $titre, $matches[3]);
break;
default:
$content = str_replace(
$matches[0],
'Erreur génération graphique',
$content);
break;
}
//Le fichier image existe
if( file_exists(PATH_SITE.'/cache/imgcache/'.$image_file) ){
$content = str_replace(
$matches[0],
'<img src="./imgcache/'.$image_file.'" />',
$content);
}else{
$content = str_replace(
$matches[0],
'Erreur génération graphique',
$content);
}
}
return $content;
}
function commentaires_graph_histo($id, $titre, $strRatios){
$ratios = explode(',', $strRatios);
$data = array();
2010-04-01 16:33:24 +00:00
$pattern = '/(Rs?)\[(.*)]#(.{1})/';
foreach($ratios as $ratio){
if( preg_match($pattern, $ratio, $matches) ){
$typeRatio = $matches[1];
$numRatio = $matches[2];
$titreRatio = commentaires_graph_lib($numRatio);
switch($typeRatio){
case 'R' : $titreRatio.= ' - Entreprise'; break;
case 'Rs' : $titreRatio.= ' - Secteur'; break;
}
$data['y'][] = array(
'titre' => $titreRatio,
'data' => commentaires_graph_y($typeRatio, $numRatio),
);
}
}
2010-04-01 16:33:24 +00:00
$data['x'] = commentaires_graph_x();
//Graphique
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(548, 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(110, 90, 300, 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;
}
$layer = $c->addBarLayer2(Side);
$color = array(0xff8080, 0x80ff80, 0x8080ff);
$i = 0;
foreach($data['y'] as $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;
}
function commentaires_graph_radar($id, $titre, $strRatios){
$ratios = explode(',', $strRatios);
$data = array();
$pattern = '/(Rs?)\[(.*)]#(.{1})/';
foreach($ratios as $ratio){
if( preg_match($pattern, $ratio, $matches) ){
$typeRatio = $matches[1];
$numRatio = $matches[2];
$titreRatio = commentaires_graph_lib($numRatio);
$supPattern = '/\(.*?\)/';
$titreRatio = preg_replace($supPattern, '', $titreRatio);
$supPattern = '/[ ]/';
$titreRatio = preg_replace($supPattern, '<*br*>', $titreRatio);
$data['y'][] = array(
'titre' => $titreRatio,
'data' => commentaires_graph_y($typeRatio, $numRatio),
);
}
}
$data['x'] = commentaires_graph_x();
//Graphique
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']);
foreach($data['y'] as $val){
$num = count($val['data'])-1;
$gdata[] = $val['data'][$num];
$labels[] = $val['titre'];
}
}
$c = new PolarChart(548, 480);
$c->setPlotArea(270, 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_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;
switch($typeRatio){
case 'R' : $tabRatio = $ratiosEntrep; break;
case 'Rs' : $tabRatio = $ratiosSecteur; break;
}
$output = array();
foreach($tabRatio as $key => $val){
$output[$key] = $val['r'.$numRatio];
}
return $output;
}