2012-11-30 13:51:48 +00:00
< ? php
// Define path to application directory
defined ( 'APPLICATION_PATH' )
|| define ( 'APPLICATION_PATH' , realpath ( dirname ( __FILE__ ) . '/../../application' ));
// Define application environment
defined ( 'APPLICATION_ENV' )
|| define ( 'APPLICATION_ENV' , ( getenv ( 'APPLICATION_ENV' ) ? getenv ( 'APPLICATION_ENV' ) : 'development' ));
// Ensure library/ is on include_path
set_include_path ( implode ( PATH_SEPARATOR , array (
realpath ( APPLICATION_PATH . '/../library' ),
get_include_path (),
)));
/** Zend_Application */
require_once 'Zend/Application.php' ;
// Create application, bootstrap, and run
$application = new Zend_Application (
APPLICATION_ENV ,
APPLICATION_PATH . '/configs/application.ini'
);
try {
$opts = new Zend_Console_Getopt (
//Options
array (
'help|?' => " Aide. " ,
'indiscore-s' => " Génére le code tmp/indiscore_ \$ versions.php " ,
'type-s' => " Choix du type d'indiScore : scores ou valo " ,
'ratios' => " Génére le cache des ratios (tmp/configMRatios.php) "
)
);
$opts -> parse ();
} catch ( Zend_Console_Getopt_Exception $e ) {
echo $e -> getUsageMessage ();
exit ;
}
//Usage
if ( count ( $opts -> getOptions ()) == 0 || isset ( $opts -> help ))
{
echo $opts -> getUsageMessage ();
exit ;
}
$c = new Zend_Config ( $application -> getOptions ());
Zend_Registry :: set ( 'config' , $c );
require_once 'WsScore/Configure.php' ;
$oldconfig = new Configure ();
require_once 'framework/fwk.php' ;
require_once 'framework/common/chiffres.php' ;
require_once 'framework/common/dates.php' ;
require_once 'framework/mail/sendMail.php' ;
require_once 'Metier/insee/classMInsee.php' ;
require_once 'Metier/partenaires/classMGreffes.php' ;
require_once 'Metier/partenaires/classMBilans.php' ;
if ( isset ( $opts -> ratios )){
genereCacheRatios ();
}
if ( isset ( $opts -> indiscore ) ) {
if ( isset ( $opts -> type ) && in_array ( $opts -> type , array ( 'scores' , 'valo' )) ) {
$type = $opts -> type ;
} else {
$type = 'scores' ;
}
if ( genereCacheIndiscore ( $opts -> indiscore , $type ) === true ){
echo " Code généré. \n " ;
}
}
/**
* Make the static data file cache configMRatios . tmp . php
* Must be rename as configRatios . php
*/
function genereCacheRatios ()
{
$tabMoy = array ();
$iDb = new WDB ( " jo " );
$tabTmp = $iDb -> select ( " sdv1.inflation " , " annee, infla " , " annee>1990 ORDER BY annee " , false , MYSQL_ASSOC );
$strFonctions = " \$ tabInfla=array(); \n " ;
foreach ( $tabTmp as $tabTmp2 ) {
$strFonctions .= '$tabInfla[' . $tabTmp2 [ 'annee' ] . ']=' . $tabTmp2 [ 'infla' ] . " ; \n " ;
}
$strFonctions .= '
/** Donne le taux d\'inflation pour une année donnée **/
function getInflation ( $annee ) {
global $tabInfla ;
if ( ! isset ( $tabInfla [ $annee ]))
sendMail ( " production@scores-decisions.com " , " ylenaour@scores-decisions.com " , " ERREUR, il manque le taux d \ 'inflation pour l \ 'année $annee " , " il manque le taux d \ 'inflation pour l \ 'année $annee dans la table sdv1.inflation " );
return $tabInfla [ $annee ];
} ' ;
$configFileTmp = APPLICATION_PATH . '/../library/Metier/tmp/configMRatios.tmp.php' ;
$configFile = APPLICATION_PATH . '/../library/Metier/tmp/configMRatios.php' ;
$fp = fopen ( $configFileTmp , 'w' );
fwrite ( $fp , '<?php' . " \n " );
fwrite ( $fp , 'error_reporting(E_ALL ^ E_NOTICE);' . " \n " );
fwrite ( $fp , '$tva=19.6;' . " \n " );
fwrite ( $fp , $strFonctions . " \n " );
fwrite ( $fp , '$tabFormules=array();' . " \n " . " \n " );
$tabFormules = $iDb -> select (
'ratios_formules' ,
2012-12-17 16:35:12 +00:00
'id, libelle, formule, unite, commentaires, borneMin, borneMax, calcul, deleted' ,
2012-11-30 13:51:48 +00:00
'deleted=0' );
foreach ( $tabFormules as $i => $formule ) {
$id = $formule [ 'id' ] * 1 ;
fwrite ( $fp , '$tabFormules[' . $i . '][\'id\']=' . $id . ';' . " \n " );
fwrite ( $fp , '$tabFormules[' . $i . '][\'libelle\']="' . trim ( str_replace ( '"' , '\"' , $formule [ 'libelle' ])) . '";' . " \n " );
fwrite ( $fp , '$tabFormules[' . $i . '][\'commentaires\']="' . trim ( str_replace ( '"' , '\"' , $formule [ 'commentaires' ])) . '";' . " \n " );
fwrite ( $fp , '$tabFormules[' . $i . '][\'unite\']=\'' . $formule [ 'unite' ] . '\';' . " \n " );
fwrite ( $fp , '$tabFormules[' . $i . '][\'borneMin\']=\'' . $formule [ 'borneMin' ] . '\';' . " \n " );
fwrite ( $fp , '$tabFormules[' . $i . '][\'borneMax\']=\'' . $formule [ 'borneMax' ] . '\';' . " \n " );
fwrite ( $fp , '$tabFormules[' . $i . '][\'formule\']=\'' . $formule [ 'formule' ] . '\';' . " \n " );
}
fwrite ( $fp , " \n " . 'function calculRatios($tabBilans, $tabIdentite, $accesPartenaire) {' . " \n " );
fwrite ( $fp , ' global $tva, $tabFormules, $mBil, $tabBilan, $efftr;' . " \n " );
fwrite ( $fp , ' $numBil=0;' . " \n " );
fwrite ( $fp , ' $numBilType=array();' . " \n " );
fwrite ( $fp , ' foreach ($tabBilans as $millesime=>$bil) {' . " \n " );
2012-12-17 16:35:12 +00:00
fwrite ( $fp , ' $tabTmp=@$mBil->getBilan(substr($millesime,-10), substr($millesime,0,1), @$bil[\'ref\'], $accesPartenaire, $nbRatiosMax=5);' . " \n " );
2012-11-30 13:51:48 +00:00
fwrite ( $fp , ' $numBilType[substr($millesime,0,1)]++;' . " \n " );
fwrite ( $fp , ' if (substr($millesime,0,1)==\'S\') {' . " \n " );
2012-12-17 16:35:12 +00:00
fwrite ( $fp , ' if ($numBilType[\'S\']>$nbRatiosMax) continue;' . " \n " );
2012-11-30 13:51:48 +00:00
fwrite ( $fp , ' $tabTmp2=$mBil->bilanSimplifie2Normal($tabTmp);' . " \n " );
fwrite ( $fp , ' $tabBilan[$numBil]=array_merge($tabTmp2, $tabTmp);' . " \n " );
fwrite ( $fp , ' } elseif (substr($millesime,0,1)==\'N\') {' . " \n " );
2012-12-17 16:35:12 +00:00
fwrite ( $fp , ' if ($numBilType[\'N\']>$nbRatiosMax) continue;' . " \n " );
2012-11-30 13:51:48 +00:00
fwrite ( $fp , ' $tabBilan[$numBil]=$tabTmp;' . " \n " );
fwrite ( $fp , ' } elseif (substr($millesime,0,1)==\'C\') {' . " \n " );
2012-12-17 16:35:12 +00:00
fwrite ( $fp , ' if ($numBilType[\'C\']>$nbRatiosMax) continue;' . " \n " );
2012-11-30 13:51:48 +00:00
fwrite ( $fp , ' $tabBilan[$numBil]=$tabTmp;' . " \n " );
fwrite ( $fp , ' } elseif (substr($millesime,0,1)==\'A\') {' . " \n " );
2012-12-17 16:35:12 +00:00
fwrite ( $fp , ' if ($numBilType[\'A\']>$nbRatiosMax) continue;' . " \n " );
2012-11-30 13:51:48 +00:00
fwrite ( $fp , ' $tabBilan[$numBil]=$tabTmp;' . " \n " );
fwrite ( $fp , ' //return(array());' . " \n " );
fwrite ( $fp , ' } elseif (substr($millesime,0,1)==\'B\') {' . " \n " );
2012-12-17 16:35:12 +00:00
fwrite ( $fp , ' if ($numBilType[\'B\']>$nbRatiosMax) continue;' . " \n " );
2012-11-30 13:51:48 +00:00
fwrite ( $fp , ' $tabBilan[$numBil]=$tabTmp;' . " \n " );
fwrite ( $fp , ' //return(array());' . " \n " );
fwrite ( $fp , ' }' . " \n " );
fwrite ( $fp , ' unset($tabTmp); unset($tabTmp2);' . " \n " );
fwrite ( $fp , ' if ($numBil>10) break;' . " \n " );
fwrite ( $fp , ' $p=$tabBilan[$numBil];' . " \n " );
fwrite ( $fp , ' $nm=$p[\'DUREE_MOIS\'];' . " \n " );
fwrite ( $fp , ' $nmp=$p[\'DUREE_MOIS_PRE\'];' . " \n " );
fwrite ( $fp , ' $R=array();' . " \n " . " \n " );
foreach ( $tabFormules as $i => $formule ) {
$id = $formule [ 'id' ] * 1 ;
$libelle = $formule [ 'libelle' ];
$unite = $formule [ 'unite' ];
2012-12-17 16:35:12 +00:00
/** Ratios avec formules à calculer **/
if ( $formule [ 'calcul' ]) {
$formuleStr = $formule [ 'formule' ];
if ( preg_match ( " /^MOY \ (R \ [(.*) \ ],(.*) \ )/Ui " , $formuleStr , $matches )) {
$tabMoy [ $id ] = array (
'ratio' => $matches [ 1 ] * 1 ,
'nbExo' => $matches [ 2 ] * 1 ,
);
continue ;
}
// Gestion des variables minuscules de 1 à 8 caractères alphanumériques
$formule1 = preg_replace ( '/([a-z]{1,8})/' , '\$$1' , $formuleStr );
// Gestion des postes du BILAN AX, BX, YP, FL1, etc...
$formule1 = preg_replace ( '/\b([A-Z]{2,2}[1-9]{0,1})\b/' , '\$p[\'$1\']' , $formule1 );
// Gestion des ratios précédent
2012-12-26 10:05:24 +00:00
$formule1 = preg_replace ( '/\bR\[(.*)\]/U' , '\$R[\\1]' , $formule1 );
2012-12-17 16:35:12 +00:00
// Gestion des valeurs Absolues
$formule1 = preg_replace ( '/\|(.*)\|/U' , 'abs($1)' , $formule1 );
// Gestion de l'inflation pour l'année du bilan
$formule1 = preg_replace ( '/\INFLATION/U' , 'getInflation(substr($millesime,-4))' , $formule1 );
// Ecriture de la formule
$formule1 = " \$ R[ $id ]= " . $formule1 . ';' ;
/** fonction ou **/
if ( preg_match ( '/ \$ou (.*)/' , $formule1 , $matches )) {
$formule1 = preg_replace ( '/ \$ou (.*)/' , ';' , $formule1 );
$alternative = $matches [ 1 ];
$formule1 .= " if ( \$ R[ $id ]==0) \$ R[ $id ]= $alternative " ;
}
/** Bornage des résultats en cas de dépassement **/
if ( preg_match ( '/;BORN\((.*)\)/U' , $formule1 , $matches )) {
$formule1 = preg_replace ( '/(;BORN\(.*\))/U' , '' , $formule1 );
$tabBornes = explode ( ':' , $matches [ 1 ]);
if ( trim ( $tabBornes [ 0 ]) <> '' ) {
$bMin = trim ( $tabBornes [ 0 ]) * 1 ;
$formule1 .= " if ( \$ R[ $id ]< $bMin ) \$ R[ $id ]= $bMin ; " ;
}
if ( isset ( $tabBornes [ 1 ]) && trim ( @ $tabBornes [ 1 ]) <> '' ) {
$bMax = trim ( $tabBornes [ 1 ]) * 1 ;
$formule1 .= " if ( \$ R[ $id ]> $bMax ) \$ R[ $id ]= $bMax ; " ;
}
}
/** Bornage des résultats en cas de dépassement **/
if ( preg_match ( '/;LIM\((.*)\)/U' , $formule1 , $matches )) {
$formule1 = preg_replace ( '/(;LIM\(.*\))/U' , '' , $formule1 );
$bMax = trim ( $matches [ 1 ]) * 1 ;
$formule1 .= " if ( \$ R[ $id ]> $bMax ) \$ R[ $id ]= $bMax ; " ;
}
$formule2 = $formule1 ;
fwrite ( $fp , " \t \t " . $formule2 . " \n " );
//@eval($formule2);
fwrite ( $fp , " \t \t " . 'if (!isset($R[' . $id . '])) $R[' . $id . ']=\'NS\';' . " \n " );
if ( ! isset ( $R [ $id ])) $R [ $id ] = 'NS' ;
}
2012-11-30 13:51:48 +00:00
}
fwrite ( $fp , " \n \t \t " . '$tabRatios[$numBil]=$R;' . " \n " );
fwrite ( $fp , " \t \t " . '$numBil++;' . " \n " );
fwrite ( $fp , " \t \t " . '}' . " \n \n " );
foreach ( $tabMoy as $iRatio => $tMoy ) {
$irMoy = $tMoy [ 'ratio' ];
$nbExo = $tMoy [ 'nbExo' ];
fwrite ( $fp , ' for($i=0; $i<$numBil; $i++) {' . " \n " );
fwrite ( $fp , ' $tabRatios[$i][' . $iRatio . ']=($tabRatios[$i][' . $irMoy . ']' );
for ( $i = 1 ; $i < $nbExo ; $i ++ )
fwrite ( $fp , '+$tabRatios[$i+' . $i . '][' . $irMoy . ']' );
fwrite ( $fp , ')/' . $nbExo . ';' );
fwrite ( $fp , ' }' . " \n " . " \n " );
}
fwrite ( $fp , " \t " . 'return $tabRatios;' . " \n " );
fwrite ( $fp , '}' . " \n " );
fclose ( $fp );
$strOutput = exec ( 'php -l ' . $configFileTmp , $output );
if ( preg_match ( '/^No syntax errors detected in /' , $strOutput )) {
//move($configFileTmp, $configFile);
} else {
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "classMRatios sur $siren : Erreur de compilation '$strOutput'", print_r($output, true)."\n");
print_r ( $output );
return false ;
}
return true ;
}
/**
* Make the static file cache for indIscore
* ( indiscore . tmp . php , must be rename as indiscore $version . php )
* @ param string $version ex : " _XXX " where XXX is the number version to select the right table in
* database
* @ param string $type
* scores : Comments for the score version , valo : Comments for the " valorisation " version
* @ return string
*/
function genereCacheIndiscore ( $version , $type = 'scores' )
{
$cycleClient = 2 ;
// Chargement des formules de commentaires
$tabFormulesScore = array ();
$iDb = new WDB ( " jo " );
// Select the right table in database in function of type
switch ( $type ) {
case 'scores' :
$fileIndiscore = APPLICATION_PATH . '/../library/Metier/tmp/indiscore' . $version . '.php' ;
$fileIndiscoreTmp = APPLICATION_PATH . '/../library/Metier/tmp/indiscore.tmp.php' ;
$tableComments = 'scores_commentaires' . $version ;
$tableFormu = 'scores_formules' . $version ;
break ;
case 'valo' :
$fileIndiscore = APPLICATION_PATH . '/../library/Metier/tmp/indiscorevalo' . $version . '.php' ;
$fileIndiscoreTmp = APPLICATION_PATH . '/../library/Metier/tmp/indiscorevalo.tmp.php' ;
$tableComments = 'valo_commentaires' . $version ;
$tableFormu = 'valo_formules' . $version ;
break ;
}
// Read comments text
$tabTmp = $iDb -> select (
$tableComments ,
'code, langue, cycle, ligne, commentaire, tri, deleted' ,
" deleted=0 AND cycle= $cycleClient AND ligne NOT LIKE '%*%' AND commentaire NOT LIKE '.*%' ORDER BY langue ASC, cycle ASC, code ASC, ligne ASC " ,
false , MYSQL_ASSOC
);
foreach ( $tabTmp as $i => $commentaire ) {
$id = $commentaire [ 'code' ] * 1 ;
$cycle = $commentaire [ 'cycle' ] * 1 ;
$ligne = $commentaire [ 'ligne' ] * 1 ;
$tabCommentaires [ $id ][ $cycle ][ $ligne ] = $commentaire [ 'commentaire' ];
if ( $commentaire [ 'tri' ]) {
$tabTri [ $id ] = $commentaire [ 'tri' ];
$tabTriAff [ $id ] = ( $commentaire [ 'tri' ] . '.' . ( 10000000 + ( 1 * $commentaire [ 'code' ]))) * 1 ;
}
}
// Read formulas
$tabTmp = $iDb -> select (
$tableFormu ,
'code, ligne, remarque, operande, ope1, operation, valeur' ,
" deleted=0 AND ligne NOT LIKE '%*%' ORDER BY code ASC, ligne ASC " ,
false , MYSQL_ASSOC
);
$idPre = $strFormule = false ;
//echo '<table border="1">';
$debugFormule = '' ;
$fp2 = fopen ( $fileIndiscoreTmp , 'w' );
fwrite ( $fp2 , '<?php' . " \n " );
$ECHANGE = array ();
foreach ( $tabTmp as $i => $formule ) {
$id = $formule [ 'code' ] * 1 ;
if ( $idPre != $id && $idPre != false ) {
$debugFormule .= $strFormule . ') { $C[' . $idPre . " ]=true; $strAction } \t " ;
//$strFormule=preg_replace('/\|(.+)\|/U', 'abs($1)', $strFormule);
$strFormule = preg_replace ( '/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui' , 'abs($1)' , $strFormule );
$strFormule = preg_replace ( '/\$R\[0+/' , '$R[' , $strFormule );
$strFormule = preg_replace ( '/\$Ra\[0+/' , '$Ra[' , $strFormule );
$strFormule = preg_replace ( '/\$Rap\[0+/' , '$Rap[' , $strFormule );
$strFormule = preg_replace ( '/\$Rp\[0+/' , '$Rp[' , $strFormule );
$strFormule = preg_replace ( '/\$Rs\[0+/' , '$Rs[' , $strFormule );
$strFormule = preg_replace ( '/\$Rsp\[0+/' , '$Rsp[' , $strFormule );
$strFormule = preg_replace ( '/\$Revol\[0+/' , '$Revol[' , $strFormule );
$strFormule = preg_replace ( '/\$Revolp\[0+/' , '$Revolp[' , $strFormule );
$strFormule = preg_replace ( '/\$Rdiff\[0+/' , '$Rdiff[' , $strFormule );
for ( $j = 2 ; $j < 5 ; $j ++ ) {
$strFormule = preg_replace ( '/\$Rp' . $j . '\[0+/' , '$Rp' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Rs' . $j . '\[0+/' , '$Rs' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Rsp' . $j . '\[0+/' , '$Rsp' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Revol' . $j . '\[0+/' , '$Revol' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Revolp' . $j . '\[0+/' , '$Revolp' . $j . '[' , $strFormule );
}
debugLog ( 'W' , 'Indiscore ' . $strFormule . ') $C[' . $idPre . ']=' . $C [ $idPre ], __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
//$fp2=fopen('/var/www/html/ws2/indiscore.tmp.php','a');
// Cas particulier de la première lignde de commentaire
//if ($i<=1) $remarque="// $id-".$formule['ligne'].' : '.trim($formule['remarque'].' '.$remarque);
fwrite ( $fp2 , $remarque . " \n " );
fwrite ( $fp2 , $strFormule . ') { $C[' . $idPre . " ]=true; $strAction } " . " \n " );
//fclose($fp2);
eval ( $strFormule . ') { $C[' . $idPre . " ]=true; $strAction } " );
$debugFormule .= '$C[' . $idPre . ']=' . $C [ $idPre ] . " \r \n " ;
$remarque = " // $id - " . $formule [ 'ligne' ] . ' : ' . $formule [ 'remarque' ];
$strAction = '' ;
} elseif ( ! $idPre )
$remarque = " // $id - " . $formule [ 'ligne' ];
else
$remarque .= ' ' . $formule [ 'remarque' ];
$ligne = $formule [ 'ligne' ] * 1 ;
$operande = trim ( strtr ( strtoupper ( $formule [ 'operande' ]), array ( ':' => '' )));
$ope1 = trim ( $formule [ 'ope1' ]);
/* P [ xxx , + n ] valeur Projection linéaire du ratio xxx sur n années Valeur du ratio au terme de l ' année N + n années
Pc [ xxx , + n ] ou Pc [ xxx ] Valeur du coefficient de corrélation de la régression linéaire Coef de 0 à 1 à transformer en % Pertinence de la corélation pour qu ' elle soit bonne le coef doit > 0 , 75
Pevol [ xxx , n ] Valeur du taux de progression au terme des N années Projection linéaire du ratio xxx sur N années Taux de progression entre la valeur du ratio en année N et sa valeur à + n années ( même principe que Revol [ xxx ] pour les ratios )
*/
if ( preg_match ( " /(PROJECTAUX|PROJECCOEF|PROJEC) \ ((.*) \ )/Ui " , $ope1 , $matches ))
{
$ope1 = $matches [ 1 ] . '($' . preg_replace ( '/R\[0+/' , 'regR[' , $matches [ 2 ]) . ')' ;
}
elseif ( preg_match ( '/^LONG\(([A-Z0-9\_]{1,30})\)$/i' , $ope1 , $matches ))
{
// Gestion du mot clef LONG
$ope1 = preg_replace ( '/^LONG\(([A-Z0-9\_]{1,30})\)$/i' , 'strlen(\$$1)' , $ope1 );
}
else
{
// Gestion du substr
$ope1 = preg_replace ( '/([A-Z0-9\_]{1,30})\((.*)\)$/i' , 'substr(\$$1,$2)' , $ope1 );
}
$operation = trim ( $formule [ 'operation' ]);
if ( $operation == '=' ) $operation = '==' ;
$valeur = trim ( strtr ( $formule [ 'valeur' ], array ( '"' => " ' " )));
$tabFormulesScore [ $id ][ $ligne ][ 'operande' ] = $operande ;
$tabFormulesScore [ $id ][ $ligne ][ 'ope1' ] = $ope1 ;
$tabFormulesScore [ $id ][ $ligne ][ 'operation' ] = $operation ;
$tabFormulesScore [ $id ][ $ligne ][ 'valeur' ] = $valeur ;
if ( preg_match ( " /^MOY \ (R(.*),(.*) \ )/Ui " , $valeur , $matches )) {
$valeur = '( (R' . $matches [ 1 ];
for ( $iMoy = 0 ; $iMoy < $matches [ 2 ]; $iMoy ++ ) {
if ( $iMoy == 1 )
$valeur .= '+Rp' . $matches [ 1 ];
else
$valeur .= '+Rp' . $iMoy . $matches [ 1 ];
}
$valeur .= ')/' . $matches [ 2 ] . ')' ;
}
else
{
$valeur = preg_replace ( '/([A-Z\_]{1,30})\((.*)\)$/i' , 'substr(\$$1,$2)' , $valeur );
}
if ( ! empty ( $valeur )
|| substr ( $valeur , 0 , 6 ) != 'substr' && substr ( $valeur , 0 , 1 ) != " ' "
|| ! in_array ( $valeur , array ( 'vrai' , 'faux' ))
) {
//file_put_contents('test.log', $valeur, FILE_APPEND);
$valeur = preg_replace ( '/([A-Z][A-Z0-9\_]{1,29}|[A-Za-z0-9]{1,30}\[[0-9]+\])/' , '\$$1' , $valeur );
//file_put_contents('test.log', " = ".$valeur."\n", FILE_APPEND);
}
if ( preg_match ( " /^substr|^projec|^strlen|^ \ ||^'/i " , $ope1 )) {
$ope1deb = '' ;
$ope1 = strtr ( $ope1 , array ( '|R[' => '|$R[' ,
'|Rp[' => '|$Rp[' ,
'|Rp2[' => '|$Rp2[' ,
'|Rp3[' => '|$Rp3[' ,
'|Rs[' => '|$Rs[' ,
'|Rsp[' => '|$Rsp[' ,
'|Revol[' => '|$Revol[' ,
'|Revolp[' => '|$Revolp[' ,
'|Revols[' => '|$Revols[' ,
'|Rdiff[' => '|$Rdiff[' ,
));
}
else {
$ope1deb = '$' ;
$ope1 = strtr ( $ope1 , array ( '/R[' => '/$R[' ,
'/Rp[' => '/$Rp[' ,
'/Rp2[' => '/$Rp2[' ,
'/Rp3[' => '/$Rp3[' ,
'/Rs[' => '/$Rs[' ,
'/Rsp[' => '/$Rsp[' ,
'/Revol[' => '/$Revol[' ,
'/Revolp[' => '/$Revolp[' ,
'/Revols[' => '/$Revols[' ,
'/Rdiff[' => '/$Rdiff[' ,
));
}
//(C[5000100]àC[5000998])
if ( preg_match ( '/^C\[(.*)\]àC\[(.*)\]$/' , $ope1 , $matches )) {
/** On veut savoir si des commentaires Cxx à Cyy sont chargés **/
$tabTmp4 = array ();
foreach ( $tabTri as $idxC => $t ) {
if ( $idxC >= $matches [ 1 ] && $idxC <= $matches [ 2 ])
$tabTmp4 [] = ' isset($C[' . $idxC . ']) ' ;
}
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Indiscore sur $siren : Debug Code=$id, ligne=$ligne", print_r($matches, true).print_r($tabTmp4, true)."\n");
$tmpFormule = 'true' ;
// if (count($tabTmp4)>0 && preg_match('/NON/i',$operande))
// $tmpFormule=' ('.implode(' && ', $tabTmp4).') ';
//else
if ( count ( $tabTmp4 ) > 0 )
$tmpFormule = ' (' . implode ( ' || ' , $tabTmp4 ) . ') ' ;
} elseif ( preg_match_all ( '/^\((C\[(.*)\];?)+\)$/' , $ope1 , $matches )) {
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Indiscore sur $siren : Debug", print_r($matches, true)."\n");
$tabTmp5 = explode ( ';' , $matches [ 1 ][ 0 ]); // C[3255000];C[3260000];C[3265000]
$tabTmp4 = array ();
foreach ( $tabTmp5 as $t )
$tabTmp4 [] = ' isset($' . $t . ') ' ;
$tmpFormule = 'true' ;
if ( count ( $tabTmp4 ) > 0 && preg_match ( '/NON/i' , $operande ))
$tmpFormule = ' (' . implode ( ' && ' , $tabTmp4 ) . ') ' ;
elseif ( count ( $tabTmp4 ) > 0 )
$tmpFormule = ' (' . implode ( ' || ' , $tabTmp4 ) . ') ' ;
} elseif (( $operation == '==' || $operation == '<>' ) && preg_match ( '/\(.*;.*\)/' , $valeur )) {
/** Gestion du point-virgule (correspond à un IN dans WHERE sql **/
$tabTmp3 = explode ( ';' , $valeur );
$tabTmp4 = array ();
foreach ( $tabTmp3 as $i3 => $svaleur )
$tabTmp4 [] = $ope1deb . $ope1 . $operation . strtr ( $svaleur , array ( '(' => '' , ')' => '' , ',' => '.' ));
if ( $operation == '==' ) $tmpFormule = ' (' . implode ( ' || ' , $tabTmp4 ) . ') ' ;
else $tmpFormule = implode ( ' && ' , $tabTmp4 );
} elseif ( $operande == 'ET' && preg_match ( '/\(.*;.*\)/' , $ope1 )) {
/** Gestion du point-virgule (correspond à un IN dans WHERE sql **/
$tabTmp3 = explode ( ';' , $ope1 );
$tabTmp4 = array ();
foreach ( $tabTmp3 as $i3 => $ope1val )
$tabTmp4 [] = $ope1deb . strtr ( $ope1val , array ( '(' => '' , ')' => '' , ',' => '.' ));
$tmpFormule = ' (' . implode ( ' && ' , $tabTmp4 ) . ') ' ;
} elseif ( preg_match ( '/(.*)à(.*)/' , $valeur , $matches )) {
/** Gestion du 'à' (correspond à min < xxx < max **/
$tmpFormule = ' (' . $ope1deb . $ope1 . ' >= ' . $matches [ 1 ] . ' && ' . $ope1deb . $ope1 . ' <= ' . $matches [ 2 ] . ') ' ;
} else {
if ( ! preg_match ( " /^substr/ " , $valeur ))
$valeur = strtr ( $valeur , array ( ',' => '.' ));
if ( $operation == '' && $valeur == '' )
$tmpFormule = $ope1deb . $ope1 ;
elseif ( $operation <> '' && $valeur == '' )
$tmpFormule = $ope1deb . $ope1 . $operation . " '' " ;
elseif ( strtoupper ( $valeur ) == strtolower ( $valeur ) && $valeur <> '' )
$tmpFormule = $ope1deb . $ope1 . $operation . $valeur ;
elseif ( strtolower ( $valeur ) == 'vrai' )
$tmpFormule = $ope1deb . $ope1 . $operation . 'true' ;
elseif ( strtolower ( $valeur ) == 'faux' )
$tmpFormule = $ope1deb . $ope1 . $operation . 'false' ;
elseif ( strtolower ( $valeur ) == 'nmp' )
$tmpFormule = $ope1deb . $ope1 . $operation . '$nmp' ;
else
$tmpFormule = $ope1deb . $ope1 . $operation . $valeur ;
}
$strParentDeb = $strParentFin = '' ;
if ( preg_match_all ( '/(\()/' , $operande , $matches )) {
$strParentDeb = implode ( ' ' , $matches [ 1 ]);
$operande = trim ( strtr ( $operande , array ( '(' => '' )));
} elseif ( preg_match_all ( '/(\))/' , $operande , $matches )) {
$strParentFin = implode ( ' ' , $matches [ 1 ]);
$operande = trim ( strtr ( $operande , array ( ')' => '' )));
}
switch ( $operande ) {
case 'SI' : $strFormule = " if ( $strParentDeb $tmpFormule $strParentFin " ; break ;
case 'SI NON' : $strFormule = " if ( $strParentDeb !( $tmpFormule ) $strParentFin " ; break ;
case 'ET' : $strFormule .= " && $strParentDeb $tmpFormule $strParentFin " ; break ;
case 'ET NON' : $strFormule .= " && $strParentDeb !( $tmpFormule ) $strParentFin " ; break ;
case 'OU' : $strFormule .= " || $strParentDeb $tmpFormule $strParentFin " ; break ;
case 'OU NON' : $strFormule .= " || $strParentDeb !( $tmpFormule ) $strParentFin " ; break ;
case 'ACTION' : $strAction .= str_replace ( '==' , '=' , " $tmpFormule ; " ); break ;
case 'ECHANGE' : $ECHANGE [] = $tmpFormule ; break ;
default :
debugLog ( 'W' , 'Indiscore ' . $id . ' OPERANDE INCONNUE ' . $operande , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
break ;
}
$idPre = $id ;
debugLog ( 'W' , 'Indiscore ' . $id . ' ' . $strFormule , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
}
/** Gestion de la dernière ligne de commentaire **/
$debugFormule .= $strFormule . ') ) $C[' . $idPre . ']=true;' . " \t " ;
$strFormule = preg_replace ( '/\|(.{1,12})\|/U' , 'abs($1)' , $strFormule );
$strFormule = preg_replace ( '/\$R\[0+/' , '$R[' , $strFormule );
$strFormule = preg_replace ( '/\$Ra\[0+/' , '$Ra[' , $strFormule );
$strFormule = preg_replace ( '/\$Rap\[0+/' , '$Rap[' , $strFormule );
$strFormule = preg_replace ( '/\$Rp\[0+/' , '$Rp[' , $strFormule );
$strFormule = preg_replace ( '/\$Rs\[0+/' , '$Rs[' , $strFormule );
$strFormule = preg_replace ( '/\$Rsp\[0+/' , '$Rsp[' , $strFormule );
$strFormule = preg_replace ( '/\$Revol\[0+/' , '$Revol[' , $strFormule );
$strFormule = preg_replace ( '/\$Revolp\[0+/' , '$Revolp[' , $strFormule );
$strFormule = preg_replace ( '/\$Revols\[0+/' , '$Revols[' , $strFormule );
$strFormule = preg_replace ( '/\$Rdiff\[0+/' , '$Rdiff[' , $strFormule );
for ( $j = 2 ; $j < 5 ; $j ++ ) {
$strFormule = preg_replace ( '/\$Rp' . $j . '\[0+/' , '$Rp' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Rs' . $j . '\[0+/' , '$Rs' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Rsp' . $j . '\[0+/' , '$Rsp' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Revol' . $j . '\[0+/' , '$Revol' . $j . '[' , $strFormule );
$strFormule = preg_replace ( '/\$Revolp' . $j . '\[0+/' , '$Revolp' . $j . '[' , $strFormule );
}
debugLog ( 'W' , 'Indiscore ' . $strFormule . ') $C[' . $idPre . ']=' . $C [ $idPre ], __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
eval ( $strFormule . ') $C[' . $idPre . ']=true;' );
//$fp2=fopen('/var/www/html/ws2/indiscore.tmp.php','a');
fwrite ( $fp2 , $strFormule . ') $C[' . $idPre . ']=true;' . " \n " );
fwrite ( $fp2 , " \n " . '$ECHANGE=\'' . serialize ( $ECHANGE ) . " '; " . " \n " );
fwrite ( $fp2 , " \n " . '?>' . " \n " );
fclose ( $fp2 );
$debugFormule .= '$C[' . $idPre . ']=' . $C [ $idPre ] . " \r \n " ;
//echo '</table>';
$strOutput = exec ( 'php -l ' . $fileIndiscoreTmp , $output );
if ( preg_match ( '/^No syntax errors detected in /' , $strOutput )) {
echo " Aucune erreur \n " ;
//move($fileIndiscoreTmp, $fileIndiscore);
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Indiscore sur $siren : Compilation OK '$strOutput'", print_r($output, true)."\n");
} else {
echo " Erreur : $strOutput\n " ;
print_r ( $output );
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Indiscore sur $siren : Erreur de compilation '$strOutput'", print_r($output, true)."\n");
}
}