1016 lines
35 KiB
PHP
1016 lines
35 KiB
PHP
<?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(),
|
|
)));
|
|
|
|
//Use classmap autoloader - useful with opcode and realpath cache
|
|
require_once 'Zend/Loader/AutoloaderFactory.php';
|
|
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
|
Zend_Loader_AutoloaderFactory::factory(array(
|
|
'Zend_Loader_ClassMapAutoloader' => array(
|
|
__DIR__ . '/../../library/Zend/autoload_classmap.php',
|
|
__DIR__ . '/../../library/Application/autoload_classmap.php',
|
|
__DIR__ . '/../../application/autoload_classmap.php',
|
|
__DIR__ . '/../../library/Scores/autoload_classmap.php',
|
|
__DIR__ . '/../../library/SdMetier/autoload_classmap.php',
|
|
),
|
|
'Zend_Loader_StandardAutoloader' => array(
|
|
'prefixes' => array(
|
|
'Zend' => __DIR__ . '/../../library/Zend',
|
|
'Application' => __DIR__ . '/../../library/Application',
|
|
'Scores' => __DIR__ . '/../../library/Scores',
|
|
'SdMetier' => __DIR__ . '/../../library/SdMetier',
|
|
'Metier' => __DIR__ . '/../../library/Metier',
|
|
),
|
|
'fallback_autoloader' => true
|
|
)
|
|
));
|
|
|
|
// Zend_Application - Use it if you don't have autoloaders
|
|
//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.",
|
|
'ratios' => "Génére la class des ratios (classMRatios.php)",
|
|
'type-s' => "Choix du type d'indiScore : scores ou valo",
|
|
'formules-s' => "Génére le code Formules{type}{versions}.php",
|
|
'comments-s' => "Génére le cache des Comments{type}{versions}.php",
|
|
'niveau=s' => "Niveau de commentaire",
|
|
'tabcache' => "Tab in cache",
|
|
)
|
|
);
|
|
$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);
|
|
|
|
/**
|
|
* Connexion à la base de données
|
|
*/
|
|
$db = Zend_Db::factory($c->profil->db->metier);
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
|
|
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->formules) ) {
|
|
|
|
if ( isset($opts->type) && in_array($opts->type, array('scores', 'valo')) ) {
|
|
$type = $opts->type;
|
|
} else {
|
|
$type = 'scores';
|
|
}
|
|
|
|
if (generateFormule($opts->formules, $type) === true){
|
|
echo "Code généré. \n";
|
|
}
|
|
}
|
|
|
|
if ( isset($opts->comments) ) {
|
|
//@todo : Générer le fichier pour chaque niveau
|
|
if ( isset($opts->type) && in_array($opts->type, array('scores', 'valo')) ) {
|
|
$type = $opts->type;
|
|
} else {
|
|
$type = 'scores';
|
|
}
|
|
|
|
$cycle = 2;
|
|
if (isset($opts->niveau)) {
|
|
$cycle = $opts->niveau;
|
|
}
|
|
|
|
if (generateComment($opts->comments, $type, $cycle) === true){
|
|
echo "Code généré. \n";
|
|
}
|
|
}
|
|
|
|
if ( $opts->tabcache) {
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
$db = Zend_Db::factory($c->profil->db->metier);
|
|
|
|
$pathCache = APPLICATION_PATH . '/../library/Metier/scores/Data';
|
|
|
|
//Variables
|
|
$fp=fopen($pathCache . DIRECTORY_SEPARATOR . 'Variables.php','w');
|
|
fwrite($fp, "<?php\n");
|
|
fwrite($fp, "return array(\n");
|
|
|
|
/** TU */
|
|
$result = $db->query("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='TU'");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'TU' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"".str_replace('$', $item->libelle, $item->article)."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** REGIMP - RPEN */
|
|
$result = $db->query("SELECT REGION AS code, 'int' AS type, NCCENR AS libelle FROM insee.regions");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'REGIMP' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
fwrite($fp, "\t'RPEN' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** ZEMET */
|
|
$result = $db->query("SELECT codZEMET AS code, libZEMET AS libelle, article FROM insee.insee_tabZemet WHERE anneeZemet='1994'");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'ZEMET1994' => array(\n");
|
|
foreach($rows as $item) {
|
|
if( in_array(strtoupper(substr($val['lib'],0,1)),array('A','E','I','O','U')) ) {
|
|
$prefix = "d'";
|
|
} else {
|
|
$prefix = "de ";
|
|
}
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $prefix . $item->libelle."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
$result = $db->query("SELECT codZEMET AS code, libZEMET AS libelle, article FROM insee.insee_tabZemet WHERE anneeZemet='2010'");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'ZEMET2010' => array(\n");
|
|
foreach($rows as $item) {
|
|
if( in_array(strtoupper(substr($val['lib'],0,1)),array('A','E','I','O','U')) ) {
|
|
$prefix = "d'";
|
|
} else {
|
|
$prefix = "de ";
|
|
}
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $prefix . $item->libelle."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
|
|
/** DEPSIE */
|
|
$result = $db->query("SELECT numdep AS code, libdep AS libelle FROM insee.departements");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'DEPSIE' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** LIEUACT */
|
|
$result = $db->query("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='LIEUACT'");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'LIEUACT' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". preg_replace('/\$1?/', $item->libelle, $item->article) ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** ACTISURF */
|
|
$result = $db->query("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='ACTISURF'");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'ACTISURF' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". str_replace('$', $item->libelle, $item->article) ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** ACTIVNAT */
|
|
$result = $db->query("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='ACTIVNAT'");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'ACTIVNAT' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". str_replace('$', $item->libelle, $item->article) ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** FJUR - FJURINSEE - FJURRNCS*/
|
|
$result = $db->query("SELECT code, libelle FROM jo.tabFJur");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'FJUR' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . str_replace('"','\"',$item->libelle) . "\", 'art'=>\"". str_replace('"','\"',$item->libelle) ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
fwrite($fp, "\t'FJURINSEE' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . str_replace('"','\"',$item->libelle) . "\", 'art'=>\"". str_replace('"','\"',$item->libelle) ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
fwrite($fp, "\t'FJURRNCS' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . str_replace('"','\"',$item->libelle) . "\", 'art'=>\"". str_replace('"','\"',$item->libelle) ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
/** APEENT - APEINSEE - APERNCS */
|
|
$result = $db->query("SELECT codNaf700 AS code, libNaf700 AS libelle FROM jo.tabNaf4 UNION SELECT codNaf5 AS code, libNaf5 AS libelle FROM jo.tabNaf5");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
fwrite($fp, "\t'APEENT' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
fwrite($fp, "\t'APEINSEE' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
fwrite($fp, "\t'APERNCS' => array(\n");
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t\t'".$item->code."' => array(");
|
|
fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\"");
|
|
fwrite($fp, "),\n");
|
|
}
|
|
fwrite($fp, "\t),\n");
|
|
}
|
|
|
|
fwrite($fp, ");\n");
|
|
fclose($fp);
|
|
|
|
|
|
/** Taux d'inflation **/
|
|
$fp=fopen($pathCache . DIRECTORY_SEPARATOR . 'Infla.php','w');
|
|
fwrite($fp, "<?php\n");
|
|
fwrite($fp, "return array(\n");
|
|
|
|
$result = $db->query("SELECT annee, infla FROM sdv1.inflation WHERE annee>1990 ORDER BY annee");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t" . $item->annee . " => " . $item->infla . ",\n");
|
|
}
|
|
}
|
|
|
|
fwrite($fp, ");\n");
|
|
fclose($fp);
|
|
|
|
|
|
/** Taux de rendement des actions **/
|
|
$fp=fopen($pathCache . DIRECTORY_SEPARATOR . 'RendObli.php','w');
|
|
fwrite($fp, "<?php\n");
|
|
fwrite($fp, "return array(\n");
|
|
|
|
$result = $db->query("SELECT annee, txMoinsInfla FROM sdv1.txRendObli WHERE annee>1990 ORDER BY annee ASC");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
foreach($rows as $item) {
|
|
fwrite($fp, "\t" . $item->annee . " => " . $item->txMoinsInfla . ",\n");
|
|
}
|
|
}
|
|
|
|
fwrite($fp, ");\n");
|
|
fclose($fp);
|
|
|
|
|
|
/** Formules **/
|
|
$fp=fopen($pathCache . DIRECTORY_SEPARATOR . 'Formules.php','w');
|
|
fwrite($fp, "<?php\n");
|
|
fwrite($fp, "return array(\n");
|
|
|
|
$result = $db->query("SELECT id, libelle, formule, unite, commentaires, borneMin, borneMax, calcul, deleted FROM jo.ratios_formules WHERE deleted=0");
|
|
$result->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$rows = $result->fetchAll();
|
|
if ( count($rows) > 0 ) {
|
|
$i = 0;
|
|
foreach($rows as $item) {
|
|
|
|
fwrite($fp, "\t".$i." => array(\n");
|
|
fwrite($fp, "\t\t'id' => ".intval($item->id).",\n");
|
|
fwrite($fp, "\t\t'libelle' => \"".trim(str_replace('"','\"',$item->libelle))."\",\n");
|
|
fwrite($fp, "\t\t'commentaires' => \"".trim(str_replace('"','\"',$item->commentaires))."\",\n");
|
|
fwrite($fp, "\t\t'unite' => '".$item->unite."',\n");
|
|
fwrite($fp, "\t\t'borneMin' => '".$item->borneMin."',\n");
|
|
fwrite($fp, "\t\t'borneMax' => '".$item->borneMax."',\n");
|
|
fwrite($fp, "\t\t'formule' => '".$item->formule."',\n");
|
|
fwrite($fp, "\t),\n");
|
|
|
|
$i++;
|
|
}
|
|
}
|
|
|
|
fwrite($fp, ");\n");
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Make the static data file cache configMRatios.tmp.php
|
|
* Must be rename as configRatios.php
|
|
*/
|
|
function genereCacheRatios()
|
|
{
|
|
$tabMoy = array();
|
|
$iDb = new WDB();
|
|
|
|
$configFile = APPLICATION_PATH.'/../library/Metier/scores/classMRatios.php';
|
|
|
|
$fp=fopen($configFile, 'w');
|
|
fwrite($fp, '<?php'."\n");
|
|
fwrite($fp, "/** Auto generated class ".date('Y-m-d H:i:s')."*/" . "\n");
|
|
fwrite($fp, "class MRatios
|
|
{
|
|
public \$tva = 20.0;
|
|
|
|
public \$efftr = null;
|
|
|
|
/**
|
|
* Donne le taux d'inflation pour une année donnée
|
|
* @param unknown \$annee
|
|
* @return unknown
|
|
*/
|
|
public function getInflation(\$annee)
|
|
{
|
|
\$tabInfla = include __DIR__ . '/Data/Infla.php';
|
|
if ( isset(\$tabInfla[\$annee]) ) {
|
|
return \$tabInfla[\$annee];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Donne le taux de rendement des actions pour une année donnée
|
|
* @param unknown \$annee
|
|
* @return unknown
|
|
*/
|
|
public function getTxRendement(\$annee)
|
|
{
|
|
\$tabTxRendObli = include __DIR__ . '/Data/RendObli.php';
|
|
if ( isset(\$tabTxRendObli[\$annee]) ) {
|
|
return \$tabTxRendObli[\$annee];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Définit la tranche d'effectif
|
|
* @param int \$value
|
|
*/
|
|
public function setTrancheEffectif(\$value)
|
|
{
|
|
\$this->efftr = \$value;
|
|
}
|
|
|
|
/**
|
|
* Calcul les ratios
|
|
* @param array \$bilans
|
|
* Format des bilans à envoyer
|
|
*
|
|
* Les bilans doivent être envoyés trier
|
|
* @return array
|
|
*/
|
|
public function calcul(\$bilans)
|
|
{
|
|
\$numBil = 0;
|
|
foreach (\$bilans as \$k => \$p) {
|
|
|
|
\$millesime = \$p['CONSOLIDE'];
|
|
|
|
// --- Utilisation des bilans N ou S uniquement
|
|
if ( !in_array(substr(\$millesime, 0, 1), array('S', 'N')) ) {
|
|
continue;
|
|
}
|
|
|
|
// --- Calcul
|
|
" . "\n");
|
|
|
|
fwrite($fp, "\t\t\t" . "\$nm=\$p['DUREE_MOIS'];" ."\n");
|
|
fwrite($fp, "\t\t\t" . "\$nmp=\$p['DUREE_MOIS_PRE'];" ."\n");
|
|
fwrite($fp, "\t\t\t" . "\$R=array();" ."\n");
|
|
|
|
$tabFormules = $iDb->select(
|
|
'jo.ratios_formules',
|
|
'id, libelle, formule, unite, commentaires, borneMin, borneMax, calcul, deleted',
|
|
'deleted=0');
|
|
|
|
foreach ($tabFormules as $i=>$formule) {
|
|
$id=intval($formule['id']);
|
|
$libelle=$formule['libelle'];
|
|
$unite=$formule['unite'];
|
|
|
|
/** 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('/(tva|efftr|nm)/','\$this->$1', $formuleStr);
|
|
$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
|
|
$formule1 = preg_replace_callback('/\bR\[(.*)\]/U', function($match) {
|
|
return '$R['.intval($match[1]).']';
|
|
}, $formule1);
|
|
|
|
// 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', '$this->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.= "\t" . "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.= "\t" . "if (\$R[$id]<$bMin) { \$R[$id] = $bMin; }";
|
|
}
|
|
if (isset($tabBornes[1]) && trim(@$tabBornes[1])<>'') {
|
|
$bMax =trim($tabBornes[1])*1;
|
|
$formule1.= "\t" . "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.= "\t" . "if (\$R[$id]>$bMax) { \$R[$id] = $bMax; }";
|
|
}
|
|
$formule2 = $formule1;
|
|
|
|
fwrite($fp, "\t\t\t" . $formule2 . "\n");
|
|
fwrite($fp, "\t\t\t" . "if (!isset(\$R[".$id."])) { \$R[".$id."] = 'NS'; }" . "\n\n");
|
|
}
|
|
}
|
|
|
|
fwrite($fp, "\n");
|
|
fwrite($fp, "\t\t\t" . '$tabRatios[$numBil]=$R;'."\n");
|
|
fwrite($fp, "\t\t\t" . '$numBil++;'."\n");
|
|
fwrite($fp, "\t\t" . "}" ."\n\n");
|
|
|
|
foreach($tabMoy as $iRatio=>$tMoy) {
|
|
$irMoy=$tMoy['ratio'];
|
|
$nbExo=$tMoy['nbExo'];
|
|
fwrite($fp, "\t\t" . "for(\$i=0; \$i<\$numBil; \$i++) {" . "\n");
|
|
fwrite($fp, "\t\t\t" . "\$tabRatios[\$i][".$iRatio."]=(\$tabRatios[\$i][".$irMoy."]");
|
|
for($i=1; $i<$nbExo; $i++) {
|
|
fwrite($fp, '+$tabRatios[$i+'.$i.']['.$irMoy.']');
|
|
}
|
|
fwrite($fp, ")/".$nbExo.";" . "\n");
|
|
fwrite($fp, "\t\t" . "}" . "\n\n");
|
|
}
|
|
|
|
fwrite($fp, "\t\t" . "return \$tabRatios;" . "\n");
|
|
fwrite($fp, "\t" . "}" . "\n");
|
|
fwrite($fp, "}" . "\n");
|
|
fclose ($fp);
|
|
|
|
$strOutput=exec('php -l '.$configFile, $output);
|
|
if (preg_match('/^No syntax errors detected in /', $strOutput)) {
|
|
} else {
|
|
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 generateFormule($version, $type = 'scores')
|
|
{
|
|
$cycle = 2;
|
|
|
|
// Chargement des formules de commentaires
|
|
$tabFormulesScore=array();
|
|
|
|
$iDb = new WDB();
|
|
|
|
// Select the right table in database in function of type
|
|
switch ($type) {
|
|
case 'scores':
|
|
$file = APPLICATION_PATH.'/../library/Metier/scores/Formule/Score_'.$version.'.php';
|
|
$tableFormu = 'jo.scores_formules_'.$version;
|
|
$tableComment = 'jo.scores_commentaires_'.$version;
|
|
break;
|
|
|
|
case 'valo':
|
|
$file = APPLICATION_PATH.'/../library/Metier/scores/Formule/Valo_'.$version.'.php';
|
|
$tableFormu = 'jo.valo_formules_'.$version;
|
|
$tableComment = 'jo.valo_commentaires_'.$version;
|
|
break;
|
|
}
|
|
|
|
//Read comments
|
|
$tabTmp = $iDb->select(
|
|
$tableComment,
|
|
'code, langue, cycle, ligne, commentaire, tri, deleted',
|
|
"deleted=0 AND cycle=$cycle 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;
|
|
$debugFormule='';
|
|
|
|
$fp = fopen($file,'w');
|
|
fwrite($fp,'<?php'."\n");
|
|
fwrite($fp, "/** Auto generated class ".date('Y-m-d H:i:s')."*/" . "\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('/\|([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);
|
|
}
|
|
$strAction=preg_replace('/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui', 'abs($1)', $strAction);
|
|
$strAction=preg_replace('/\$R\[0+/', '$R[', $strAction);
|
|
$strAction=preg_replace('/\$Ra\[0+/', '$Ra[', $strAction);
|
|
$strAction=preg_replace('/\$Rap\[0+/', '$Rap[', $strAction);
|
|
$strAction=preg_replace('/\$Rp\[0+/', '$Rp[', $strAction);
|
|
$strAction=preg_replace('/\$Rs\[0+/', '$Rs[', $strAction);
|
|
$strAction=preg_replace('/\$Rsp\[0+/', '$Rsp[', $strAction);
|
|
$strAction=preg_replace('/\$Revol\[0+/', '$Revol[', $strAction);
|
|
$strAction=preg_replace('/\$Revolp\[0+/', '$Revolp[', $strAction);
|
|
$strAction=preg_replace('/\$Rdiff\[0+/', '$Rdiff[', $strAction);
|
|
|
|
debugLog('W', 'Indiscore '.$strFormule.') $C['.$idPre.']='.$C[$idPre], __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
fwrite($fp, $remarque."\n");
|
|
fwrite($fp, $strFormule.') { $C['.$idPre."]=true; $strAction } "."\n");
|
|
|
|
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.=' '.strtr($formule['remarque'],array("\r"=>' ',"\n"=>' '));
|
|
|
|
echo $formule['valeur'];
|
|
//if ($id == '264500') exit;
|
|
|
|
$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);
|
|
}
|
|
|
|
echo " = ".$valeur;
|
|
|
|
if ( !empty($valeur)
|
|
&& substr($valeur,0,1) != "'"
|
|
&& !preg_match('/\(.*;.*\)/', $valeur)
|
|
&& substr($valeur,0,6) != 'substr'
|
|
&& !in_array($valeur, array('vrai', 'faux')) ) {
|
|
//file_put_contents('test.log', $valeur, FILE_APPEND);
|
|
//$valeur = preg_replace('/([A-Z][A-Za-z0-9\_]{1,29}|[A-Za-z0-9]{1,30}\[[0-9]+\])/', '\$$1' , $valeur);
|
|
$valeur = preg_replace('/([A-Z][A-Za-z0-9\_]{0,29}|[A-Za-z0-9]{1,30}\[[0-9]+\])/', '\$$1' , $valeur);
|
|
//file_put_contents('test.log', " = ".$valeur."\n", FILE_APPEND);
|
|
}
|
|
echo " = ".$valeur ."\n";
|
|
|
|
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.']) ';
|
|
}
|
|
$tmpFormule='true';
|
|
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);
|
|
}
|
|
|
|
$strAction=preg_replace('/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui', 'abs($1)', $strAction);
|
|
$strAction=preg_replace('/\$R\[0+/', '$R[', $strAction);
|
|
$strAction=preg_replace('/\$Ra\[0+/', '$Ra[', $strAction);
|
|
$strAction=preg_replace('/\$Rap\[0+/', '$Rap[', $strAction);
|
|
$strAction=preg_replace('/\$Rp\[0+/', '$Rp[', $strAction);
|
|
$strAction=preg_replace('/\$Rs\[0+/', '$Rs[', $strAction);
|
|
$strAction=preg_replace('/\$Rsp\[0+/', '$Rsp[', $strAction);
|
|
$strAction=preg_replace('/\$Revol\[0+/', '$Revol[', $strAction);
|
|
$strAction=preg_replace('/\$Revolp\[0+/', '$Revolp[', $strAction);
|
|
$strAction=preg_replace('/\$Rdiff\[0+/', '$Rdiff[', $strAction);
|
|
|
|
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($fp, $strFormule.') $C['.$idPre.']=true;'."\n");
|
|
|
|
fwrite($fp, "\n".'$ECHANGE=\''.serialize($ECHANGE)."';"."\n");
|
|
|
|
fwrite($fp, "\n".'?>'."\n");
|
|
fclose($fp);
|
|
$debugFormule.='$C['.$idPre.']='.$C[$idPre]."\r\n";
|
|
//echo '</table>';
|
|
|
|
$strOutput=exec('php -l '.$file, $output);
|
|
if (preg_match('/^No syntax errors detected in /', $strOutput)) {
|
|
echo "Aucune erreur\n";
|
|
} else {
|
|
echo "Erreur : $strOutput\n";
|
|
print_r($output);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $type
|
|
* @param unknown $version
|
|
* @return boolean
|
|
*/
|
|
function generateComment($version, $type = 'scores', $cycle = 2)
|
|
{
|
|
$iDb = new WDB();
|
|
|
|
// Select the right table in database in function of type
|
|
switch ($type) {
|
|
case 'scores':
|
|
$name = 'Score_'.$version.'_'.$cycle;
|
|
$file = APPLICATION_PATH.'/../library/Metier/scores/Comment/Score_'.$version.'_'.$cycle.'.php';
|
|
$tableComment = 'jo.scores_commentaires_'.$version;
|
|
break;
|
|
|
|
case 'valo':
|
|
$name = 'Valo_'.$version.'_'.$cycle;
|
|
$file = APPLICATION_PATH.'/../library/Metier/scores/Comment/Valo_'.$version.'_'.$cycle.'.php';
|
|
$tableComment = 'jo.valo_commentaires_'.$version;
|
|
break;
|
|
}
|
|
|
|
// Read comments text
|
|
$tabTmp = $iDb->select(
|
|
$tableComment,
|
|
'code, langue, cycle, ligne, commentaire, tri, deleted',
|
|
"deleted=0 AND cycle=$cycle AND ligne NOT LIKE '%*%' AND commentaire NOT LIKE '.*%' ORDER BY langue ASC, cycle ASC, code ASC, ligne ASC",
|
|
false, MYSQL_ASSOC
|
|
);
|
|
|
|
$fp=fopen($file, 'w');
|
|
fwrite($fp, '<?php'."\n");
|
|
fwrite($fp, "/** Auto generated class ".date('Y-m-d H:i:s')."*/" . "\n");
|
|
|
|
$tabCommentaires = $tabTri = $tabTriAff = array();
|
|
foreach ($tabTmp as $i => $commentaire) {
|
|
$id = $commentaire['code']*1;
|
|
$ligne = $commentaire['ligne']*1;
|
|
$tabCommentaires[$id][$ligne] = str_replace('"','\"',$commentaire['commentaire']);
|
|
if ($commentaire['tri']) {
|
|
//$tabTri[$id] = $commentaire['tri'];
|
|
$tabTriAff[$id] = ($commentaire['tri'].'.'.(10000000+(1*$commentaire['code'])))*1;
|
|
}
|
|
}
|
|
|
|
//Table commentaires
|
|
fwrite($fp, "\$tabCommentaires = array(" . "\n");
|
|
foreach ($tabCommentaires as $id => $idVal) {
|
|
fwrite($fp, "\t" . $id." => array(" . "\n");
|
|
foreach ($idVal as $ligne => $ligneVal) {
|
|
fwrite($fp, "\t\t" . $ligne." => \"".$ligneVal."\"," . "\n");
|
|
}
|
|
fwrite($fp, "\t" . ")," . "\n");
|
|
}
|
|
fwrite($fp, ");" . "\n");
|
|
|
|
//Table Tri
|
|
/*fwrite($fp, "\t" . "protected \$tabTri = array(" . "\n");
|
|
foreach ($tabTri as $id => $idVal) {
|
|
fwrite($fp, "\t\t" . $id." => ".$idVal."," . "\n");
|
|
}
|
|
fwrite($fp, "\t" . ");" . "\n");*/
|
|
|
|
//Table Tri Aff
|
|
fwrite($fp, "\$tabTriAff = array(" . "\n");
|
|
foreach ($tabTriAff as $id => $idVal) {
|
|
fwrite($fp, "\t" . $id." => ".$idVal."," . "\n");
|
|
}
|
|
fwrite($fp, ");" . "\n");
|
|
|
|
$strOutput = exec('php -l '.$file, $output);
|
|
if (preg_match('/^No syntax errors detected in /', $strOutput)) {
|
|
//move($configFileTmp, $configFile);
|
|
} else {
|
|
print_r($output);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|