([0-9]{3})(?: )?([0-9]{3})(?: )?([0-9]{3})<\/siren>(.*?)/i'; $replace = '$1$2 $3 $4$5'; $output = preg_replace($pattern, $replace, $content); return $output; } function commentaires_liste($content){ $pattern = '/(.*?)(.*)/i'; if(preg_match($pattern, $content, $matches)){ switch($matches[2]){ case '+': $class = 'plus'; $replace = '$1$3'; break; case '-': $class = 'moins'; $replace = '$1$3'; break; case '=': $replace = '$1$3'; break; default: $class = 'point'; $replace = '$1$3'; break; } } $output = preg_replace($pattern, $replace, $content); return $output; } function commentaires_image($content){ $pattern = '/IMAGE\((.*?)\)/i'; preg_match($pattern, $content, $matches); $replace = ''; $output = str_replace($matches[0], $replace, $content); return $output; } function commentaires_lien($content){ $path = array( 'pdf' => '/datafile.php?q=commentaires', 'html' => '', ); $pattern = "/(.*?)<\/lien>/i"; preg_match($pattern, $content, $matches); if(count($matches)>0){ switch($matches[2]){ case 'pdf': $content = str_replace( $matches[0], "". $matches[3]."", $content); break; case 'htm': case 'html': $content = str_replace( $matches[0], "". $matches[3]."", $content); break; } } return $content; } function commentaires_graphique_couleur($content){ $graphCouleurs = array(); //Association des couleurs Nom => code Hexa $assocNomCouleurs = array( 'BLA' => 0xFFFFFF, 'BLA1' => 0xFFFAFA, 'BLA2' => 0xF0FFFF, 'BLA3' => 0xFFFFF0, 'BLE' => 0x0000FF, 'BLE1' => 0x00BFFF, 'BLE2' => 0x00008B, 'BLE3' => 0x87F0FA, 'JAU' => 0xFFFF00, 'JAU1' => 0xFFEFD5, 'JAU2' => 0xFFA500, 'JAU3' => 0xFFFFE0, 'LUM' => 0xADFF2F, 'LUM1' => 0x00FFFF, 'LUM2' => 0xFF00FF, 'LUM3' => 0xF0FFF0, 'MAR' => 0xD2691E, 'MAR1' => 0xF4A460, 'MAR2' => 0x8B4513, 'MAR3' => 0xF5DEB3, 'MET' => 0xFFD700, 'MET1' => 0xFFF8DC, 'MET2' => 0xC0C0C0, 'MET3' => 0xFDF5E6, 'NOI' => 0x000000, 'NOI1' => 0x808080, 'NOI2' => 0x2F4F4F, 'NOI3' => 0xDCDCDC, 'ROU' => 0xFF0000, 'ROU1' => 0xFF7F50, 'ROU2' => 0xB22222, 'ROU3' => 0xFFDAB9, 'VER' => 0x228B22, 'VER1' => 0x66CDAA, 'VER2' => 0x066400, 'VER3' => 0x98FB98, 'VIO' => 0xC71585, 'VIO1' => 0xEE82EE, 'VIO2' => 0x8B008B, 'VIO3' => 0xFFF0F5, ); $pattern = '/COULEUR\((.*)\)/i'; ///Detection couleur if ( preg_match($pattern, $content, $matches) ) { $listeCouleurs = $matches[1]; //Récupération des couleurs $pattern = '/([a-z0-9]{3,4})/i'; if ( preg_match_all($pattern, $listeCouleurs, $matches) ) { FB::log($matches, 'matches'); $nbCouleurs = count($matches[1]); for($i=1;$i<$nbCouleurs;$i++){ $graphCouleurs[] = $assocNomCouleurs[$matches[1][$i]]; } } } FB::log($graphCouleurs,' DETECTION : graphCouleurs'); return $graphCouleurs; } function commentaires_graphique($content){ global $siret, $siren, $idEntreprise; $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( 'stacked' => '/(R\[.*]#HS,?){1,};(R\[.*]#HS,?){1,}/', 'histo' => '/(Rs?\[.*]#[H|L],?){1,}/', 'radar' => '/(R\[.*]#R,?){1,}/', 'projection' => '/(Rs?\[.*]#[H]),(R[.*]_Y)/' ); 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; case 'projection': $image_file = 'Erreur'; break; default: $image_file = 'Erreur'; break; } //Le fichier image existe if( file_exists(PATH_SITE.'/cache/imgcache/'.$image_file) ){ $content = str_replace( $matches[0], '', $content); }else{ $content = str_replace( $matches[0], 'Erreur génération graphique', $content); } } return $content; } function commentaires_graph_stacked($id, $titre, $strRatios) { global $bilansInfos, $ratiosEntrep, $ratiosSecteur, $ratiosInfos, $graphCouleurs; if(count($graphCouleurs)>0){ $couleurs = $graphCouleurs; } else { $couleurs = array( 0xaaaaff, 0x6666ff, 0x3cb371, /*medium sea green*/ 0xff8080, 0x000000, /*noir*/ /*0x80ff80,*/ 0xffe4c4, /*abricot*/ 0xbc8f8f, /*rosy brown*/ 0xc0c0c0, /*silver*/ 0xfffff0, /*ivoire*/ /*0xf0ffff, /*azure*/ 0xff7f50, /*coral*/ 0xa0522d, /*marron*/ 0xffd700, /*gold*/ 0x8866ff, 0x0000cd, /*blue*/ 0xee82e2, /*violet*/ ); } $ratios = explode(';', $strRatios); $stackRatiosL = explode(',', $ratios[0]); $stackRatiosR = explode(',', $ratios[1]); foreach ($bilansInfos as $key => $row) { $bilansInfos[$key]['cle'] = $key; $date[$key] = $row['dateCloture']; $duree[$key] = $row['duree']; $devise[$key] = $row['devise']; $unite[$key] = $row['unite']; $cle[$key] = $row['cle']; } array_multisort( $date, SORT_DESC, $duree, SORT_DESC, $devise, SORT_DESC, $unite, SORT_DESC, $cle, SORT_DESC, $bilansInfos); $index = $bilansInfos[0]['cle']; $dateCloture = substr($bilansInfos[0]['dateCloture'],0,4); //Génération du graphique require_once('phpchartdir/phpchartdir.php'); $path = PATH_SITE.'/cache/imgcache/'; $file = $id.'.png'; $c = new XYChart(548, 300); $c->addTitle($titre, 'times.ttf', 10); $c->setPlotArea(60, 30, 200, 200); $legendObj = $c->addLegend2(300, 50, -2, "times.ttf", 9); $legendObj->setBackground(Transparent, Transparent); $labels = array($dateCloture); $c->xAxis->setLabels($labels); $layer = $c->addBarLayer2(Stack); $layer->setBorderColor(Transparent, softLighting(Left)); $cpt_couleur = 0; $pattern = '/(Rs?)\[(.*)]#.{1}/'; $layer->addDataGroup("Actif"); foreach($stackRatiosL as $ratio){ preg_match($pattern, $ratio, $matches); $value = $ratiosEntrep[$index]['r'.$matches[2]]; $titre = htmlspecialchars_decode( $ratiosInfos['r'.$matches[2]]['libelle'],ENT_QUOTES); FB::log($ratio, $titre); FB::log($value,'value'); $layer->addDataSet(array($value), $couleurs[$cpt_couleur], $titre); $cpt_couleur++; if($cpt_couleur>=count($couleurs)) { $cpt_couleur=0; } } $layer->addDataGroup("Passif"); foreach($stackRatiosR as $ratio){ preg_match($pattern, $ratio, $matches); $value = $ratiosEntrep[$index]['r'.$matches[2]]; $titre = htmlspecialchars_decode( $ratiosInfos['r'.$matches[2]]['libelle'],ENT_QUOTES); FB::log($ratio, $titre); FB::log($value,'value'); $layer->addDataSet(array($value), $couleurs[$cpt_couleur], $titre); $cpt_couleur++; if($cpt_couleur>=count($couleurs)) { $cpt_couleur=0; } } $layer->setBarGap(0.2, 0); $c->yAxis->setAutoScale(0.2); if( $c->makeChart($path.$file) === true ) { $output = $file; } else { $output = false; } return $output; } function commentaires_graph_histo($id, $titre, $strRatios){ global $graphCouleurs; FB::log($graphCouleurs, 'HISTO : graphCouleurs'); if(count($graphCouleurs)>0){ $couleurs = $graphCouleurs; } else { $couleurs = array(0xff8080, 0x80ff80, 0x8080ff); } $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); switch($typeRatio){ case 'R' : $titreRatio.= ' - Entreprise'; break; case 'Rs' : $titreRatio.= ' - Secteur'; break; } $data['y'][] = array( 'titre' => $titreRatio, 'data' => commentaires_graph_y($typeRatio, $numRatio), 'style' => $matches[3], ); } } $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; } //Application layer pour bar $barLayer = $c->addBarLayer2(Side); $barLayer->setBorderColor(Transparent, softLighting(Left)); //Application layer pour line $lineLayer = $c->addLineLayer2(Side); $lineLayer->setBorderColor(Transparent, softLighting(Left)); $lineLayer->setLineWidth(2); FB::log($data,'histo-Data'); $i = 0; foreach($data['y'] as $ydata){ FB::log($couleurs[$i], 'Couleur'); if ( $ydata['style'] == 'H' ){ $barLayer->addDataSet($ydata['data'], $couleurs[$i], $ydata['titre']); } else if ( $ydata['style'] == 'L' ){ $lineLayer->addDataSet($ydata['data'], $couleurs[$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) { global $graphCouleurs; if(count($graphCouleurs)>0){ $couleurs = $graphCouleurs; } else { $couleurs = array(0x9999ff); } FB::log($couleurs, 'RADAR-couleur'); $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, $couleurs[0]); $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; }