diff --git a/application/bin.bootstrap.php b/application/bin.bootstrap.php new file mode 100644 index 00000000..1c2b51be --- /dev/null +++ b/application/bin.bootstrap.php @@ -0,0 +1,40 @@ +getOptions()); +Zend_Registry::set('config', $c); + +// Database - Zend Style +$db = Zend_Db::factory($c->profil->db->metier); +Zend_Db_Table_Abstract::setDefaultAdapter($db); + +// Database - Doctrine Style +$config = new \Doctrine\DBAL\Configuration(); +$connectionParams = array( + 'dbname' => $c->profil->db->metier->params->dbname, + 'user' => $c->profil->db->metier->params->username, + 'password' => $c->profil->db->metier->params->password, + 'host' => $c->profil->db->metier->params->host, + 'charset' => 'utf8', + 'driver' => 'pdo_mysql', +); + +try { + $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); + Zend_Registry::set('doctrine', $conn); +} catch (\Doctrine\DBAL\DBALException $e) { + echo "Connection Database impossible.\n"; + exit; +} \ No newline at end of file diff --git a/bin/buildCache.php b/bin/buildCache.php index 2a018f04..69919335 100644 --- a/bin/buildCache.php +++ b/bin/buildCache.php @@ -1,17 +1,5 @@ "Generate the specify cache.", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -62,25 +51,6 @@ if ( $opts->list ) { exit; } -// Database -$c = new Zend_Config($application->getOptions()); -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - /** * Cache des Tribunaux Bodacc */ diff --git a/bin/buildCodeRatios.php b/bin/buildCodeRatios.php index c42dfea8..38121107 100644 --- a/bin/buildCodeRatios.php +++ b/bin/buildCodeRatios.php @@ -1,17 +1,5 @@ "Tab in cache", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -44,27 +33,6 @@ if ($displayUsage) { exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -// Database -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - // Fichier MRatios if (isset($opts->ratios)) { diff --git a/bin/buildCodeSfr.php b/bin/buildCodeSfr.php index f831e046..cd16d087 100644 --- a/bin/buildCodeSfr.php +++ b/bin/buildCodeSfr.php @@ -1,17 +1,5 @@ "Version des régles", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -38,23 +27,6 @@ if ($displayUsage) { exit; } -// Doctrine conn -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $application->profil->db->metier->params->dbname, - 'user' => $application->profil->db->metier->params->username, - 'password' => $application->profil->db->metier->params->password, - 'host' => $application->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - exit; -} - $types = array('VORD', 'VORP', 'PO'); if ( $opts->compile!='' && in_array($opts->compile, $types) ) { diff --git a/bin/buildLog.php b/bin/buildLog.php index 9fa1a730..32bba05b 100644 --- a/bin/buildLog.php +++ b/bin/buildLog.php @@ -1,17 +1,5 @@ "", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -38,25 +27,6 @@ if ($displayUsage) { } if ($opts->log) { - // Database - $c = new Zend_Config($application->getOptions()); - $config = new \Doctrine\DBAL\Configuration(); - $connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', - ); - - try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); - } catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; - } - $sql = "SELECT * FROM sdv1.logs_item"; $stmt = $conn->prepare($sql); $stmt->execute(); diff --git a/bin/buildTypes.php b/bin/buildTypes.php index f535126f..0d6b443f 100644 --- a/bin/buildTypes.php +++ b/bin/buildTypes.php @@ -1,17 +1,5 @@ "{Service Name}/{version}", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } diff --git a/bin/cleanTemp.php b/bin/cleanTemp.php index 6723b269..8a88b598 100644 --- a/bin/cleanTemp.php +++ b/bin/cleanTemp.php @@ -1,26 +1,8 @@ getOptions()); -Zend_Registry::set('config', $c); - -require_once 'WsScore/Configure.php'; -$oldconfig = new Configure(); - $typesFichier = array('csv', 'fichiers', 'clients', 'kbis'); // --- Options @@ -32,12 +14,13 @@ try { 'type=w' => 'Supprime uniquement les fichiers indiqués.', )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } diff --git a/bin/greffe.php b/bin/greffe.php index 1cebe695..e9dffd37 100644 --- a/bin/greffe.php +++ b/bin/greffe.php @@ -1,17 +1,5 @@ "Control", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -43,32 +32,6 @@ if ($displayUsage) { exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -// Doctrine conn -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - if (APPLICATION_ENV == 'development') { - echo '
'; print_r($e); echo ''; - } else { - echo "Le service rencontre actuellement un problème technique."; - } - exit; -} -Zend_Registry::set('doctrine', $conn); - $testMail = false; $test = false; diff --git a/bin/kbis.php b/bin/kbis.php index 9f639fb4..d46552ca 100644 --- a/bin/kbis.php +++ b/bin/kbis.php @@ -1,18 +1,6 @@ #!/usr/bin/php parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -46,9 +35,6 @@ if ($displayUsage) { exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - if ( isset($opts->debug) ) { define('DEBUG', true); } else { diff --git a/bin/kbis2.php b/bin/kbis2.php index 07a1b639..3feb0aec 100644 --- a/bin/kbis2.php +++ b/bin/kbis2.php @@ -1,4 +1,6 @@ parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { echo $e->getUsageMessage(); exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -if ( isset($opts->debug) ) { - define('DEBUG', true); -} else { - define('DEBUG', false); +// --- Aide / Options +if ($optionsNb == 0 || isset($opts->help)) { + $displayUsage = true; } -//Usage -if(count($opts->getOptions())==0 || isset($opts->help)) -{ +// --- Usage +if ($displayUsage) { echo "Telecharge le kbis chez infogreffe."; echo "\n\n"; echo $opts->getUsageMessage(); @@ -57,6 +41,12 @@ if(count($opts->getOptions())==0 || isset($opts->help)) exit; } +if ( isset($opts->debug) ) { + define('DEBUG', true); +} else { + define('DEBUG', false); +} + /* 338 437 189 diff --git a/bin/loadCodeRatios.php b/bin/loadCodeRatios.php index 08843120..0c09032c 100644 --- a/bin/loadCodeRatios.php +++ b/bin/loadCodeRatios.php @@ -1,17 +1,5 @@ "Affiche resultat traitement " )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { + $displayUsage = true; +} + +// --- Aide / Options +if ($optionsNb == 0 || isset($opts->help)) { + $displayUsage = true; +} + +// --- Usage +if ($displayUsage) { + echo "Charge les commentaires ratios à partir de CSV."; + echo "\n\n"; echo $opts->getUsageMessage(); + echo "\n"; exit; } - //Usage - if( count($opts->getOptions())==0 || isset($opts->help)) - { - echo $opts->getUsageMessage(); - exit; - } - ######################################################### + ######################################################### ##### Presence te taille du fichier ##### ######################################################### diff --git a/bin/sql2csv.php b/bin/sql2csv.php index 924f009b..6254848d 100644 --- a/bin/sql2csv.php +++ b/bin/sql2csv.php @@ -1,17 +1,5 @@ "", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } @@ -40,25 +29,6 @@ if ($displayUsage) { use League\Csv\Writer; -// Database -$c = new Zend_Config($application->getOptions()); -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => 'sdv1', - 'user' => 'wsuser', - 'password' => 'wspass2012', - 'host' => '195.154.170.169', - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - $sql = file_get_contents($opts->sqlfile); //we fetch the info from a DB using a PDO object diff --git a/library/WsScore/Gestion/v0.3/Service.php b/library/WsScore/Gestion/v0.3/Service.php index 03d329af..084c3f15 100644 --- a/library/WsScore/Gestion/v0.3/Service.php +++ b/library/WsScore/Gestion/v0.3/Service.php @@ -940,7 +940,7 @@ class Gestion extends Scores_Ws_Server AND l.login=u.login AND u.idClient=c.id ORDER BY l.login ASC, l.dateHeure ASC"; file_put_contents($c->profil->path->shared."/files/logs-$annee-$mois-$detail-$idClient-$login-$all.sql", $sql); - exec("php ".APPLICATION_PATH."/../scripts/jobs/sql2csv.php --sqlfile ".$c->profil->path->shared."/files/logs-$annee-$mois-$detail-$idClient-$login-$all.sql --csvfile $fichierCsv > /dev/null &"); + exec("php ".APPLICATION_PATH."/../bin/sql2csv.php --sqlfile ".$c->profil->path->shared."/files/logs-$annee-$mois-$detail-$idClient-$login-$all.sql --csvfile $fichierCsv > /dev/null &"); $size = $cache = 0; } diff --git a/library/WsScore/Interne/v0.6/Service.php b/library/WsScore/Interne/v0.6/Service.php index 4e3a4c0b..d97da90a 100644 --- a/library/WsScore/Interne/v0.6/Service.php +++ b/library/WsScore/Interne/v0.6/Service.php @@ -1338,7 +1338,7 @@ class Interne extends Scores_Ws_Server $c = Zend_Registry::get('config'); $path = $c->profil->path->shared.'/files'; file_put_contents($path."/listesurv-$source-$login-$idClient.sql", $sql); - exec("php ".APPLICATION_PATH."/../scripts/jobs/sql2csv.php --sqlfile ".$path."/listesurv-$source-$login-$idClient.sql --csvfile $fichierCsv > /dev/null &"); + exec("php ".APPLICATION_PATH."/../bin/sql2csv.php --sqlfile ".$path."/listesurv-$source-$login-$idClient.sql --csvfile $fichierCsv > /dev/null &"); $size=$cache=0; } diff --git a/library/WsScore/Pieces/v0.1/Service.php b/library/WsScore/Pieces/v0.1/Service.php index 7e478b24..055faf1d 100644 --- a/library/WsScore/Pieces/v0.1/Service.php +++ b/library/WsScore/Pieces/v0.1/Service.php @@ -115,7 +115,7 @@ class Pieces extends Scores_Ws_Server //Téléchargement du KBIS $result = array(); - exec('php '.APPLICATION_PATH.'/../scripts/jobs/getKbis.php --siren '.$siren, $result); + exec('php '.APPLICATION_PATH.'/../bin/kbis.php --siren '.$siren, $result); $result = end($result); if (substr($result,-5) == '.html') { $file = $dir.'/'.$result; diff --git a/scripts/build/genCache.php b/scripts/build/genCache.php deleted file mode 100644 index 2a018f04..00000000 --- a/scripts/build/genCache.php +++ /dev/null @@ -1,421 +0,0 @@ - "Aide.", - 'list' => "List item.", - 'generate|g=s' => "Generate the specify cache.", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "\nGénération Table Static Metier\n\n"; - echo $opts->getUsageMessage(); - exit; -} - -if ( $opts->list ) { - $tabItems = array( - 'Tribunaux' => "Tribunaux", - 'FctDir' => "Fonctions de direction", - 'Evenements' => "Table des evenements bodacc", - 'Devises' => "Table des devises bodacc", - 'RncsTribunaux' => "Table des tribunaux", - 'DevisesInpi' => "Devises Inpi", - 'Jugements' => "Jugements", - 'PaysInpi' => "PaysInpi", - 'CodesNaf' => "Codes Naf", - 'CodesNace' => "Codes Nace", - 'CodesNafa' => "Codes Nafa", - 'CodesFJ' => "Codes Formes Juridiques", - 'AffairesTypes' => "Codes natures des contentieux", - 'ProcolDelete' => "Codes effacement de procol", - ); - echo "\n"; - foreach ( $tabItems as $code => $label ) { - echo "\t" . $code . " => ". $label . PHP_EOL; - } - exit; -} - -// Database -$c = new Zend_Config($application->getOptions()); -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - -/** - * Cache des Tribunaux Bodacc - */ -if( $opts->generate == 'Tribunaux' ) { - - $sql = "SELECT triCode, triNom, LPAD(triCP,5,0) AS triCP, triSiret FROM jo.tribunaux WHERE triCode IS NOT NULL"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/BodaccTribunaux.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - $dep = substr($item->triCP, 0, 2); - if ($dep == 97 || $dep == 98) { - $dep = substr($item->triCP, 0, 3); - } - fwrite($fp, "\t'" . $item->triCode . "' => array("); - fwrite($fp, "'nom'=>\"" . $item->triNom . "\", 'siret'=>\"".$item->triSiret."\", 'dep'=>\"".$dep."\""); - fwrite($fp, "),\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache Fonctions de Direction - */ -if ( $opts->generate == 'FctDir' ) { - - $sql = "SELECT codeFct, libelle FROM jo.bodacc_fonctions"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp=fopen(APPLICATION_PATH . '/../library/Metier/Table/FctDir.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . intval($item->codeFct) . "' => \"". $item->libelle . "\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache Evenements - */ -if ( $opts->generate == 'Evenements' ) { - - $sql = "SELECT codEven, libEven, Bodacc_Code, Rubrique, version, lienEtab FROM jo.tabEvenements"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/Evenements.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . intval($item->codEven) . "' => array(\n"); - - fwrite($fp, "\t\t'libEven' => \"" . $item->libEven . "\",\n"); - fwrite($fp, "\t\t'Bodacc_Code' => \"" . $item->Bodacc_Code . "\",\n"); - fwrite($fp, "\t\t'Rubrique' => \"" . $item->Rubrique . "\",\n"); - fwrite($fp, "\t\t'Version' => " . $item->version . ",\n"); - fwrite($fp, "\t\t'LienEtab' => " . $item->lienEtab . ",\n"); - - fwrite($fp, "\t),\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache des devises Bodacc - */ -if ( $opts->generate == 'Devises' ) { - - $sql = "SELECT libDeviseBodacc, devIso FROM jo.bodacc_devises"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/Devises.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t\"" . $item->libDeviseBodacc . "\" => \"" . $item->devIso ."\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache Tribunaux RNCS - */ -if ( $opts->generate == 'RncsTribunaux' ) { - - $sql = "SELECT triNumGreffe, triNom, triId, triCode FROM jo.tribunaux WHERE triNumGreffe IS NOT NULL"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/RncsTribunaux.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t" . intval($item->triNumGreffe) . " => array("); - fwrite($fp, "'Id'=>\"" . intval($item->triId) . "\", 'Nom'=>\"".$item->triNom."\", 'Code'=>\"".$item->triCode."\""); - fwrite($fp, "),\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache Devises Inpi - */ -if ( $opts->generate == 'DevisesInpi' ) { - - $sql = "SELECT devInpi, devIso FROM jo.tabDevises WHERE devInpi>0 ORDER BY devInpi ASC"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/DevisesInpi.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t" . intval($item->devInpi) . " => \"" . $item->devIso . "\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache Jugements - */ -if ( $opts->generate == 'Jugements' ) { - - $sql = "SELECT codJugement, codEven FROM jo.tabJugeRncs"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/Jugements.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t" . intval($item->codJugement) . " => " . $item->codEven . ",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache PaysInpi - */ -if ( $opts->generate == 'PaysInpi' ) { - - $sql = "SELECT codePaysInpi, codPays FROM jo.tabPays WHERE codePaysInpi>0 ORDER BY codePaysInpi ASC"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/PaysInpi.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t" . intval($item->codePaysInpi) . " => \"" . $item->codPays . "\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache CodesNaf - */ -if ( $opts->generate == 'CodesNaf' ) { - - $sql = "SELECT codNaf700 AS naf, libNaf700 AS LibNaf FROM jo.tabNaf4"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/CodesNaf.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . $item->naf . "' => \"" . $item->LibNaf . "\",\n"); - } - } - - $sql = "SELECT codNaf5 AS naf, libNaf5 AS LibNaf FROM jo.tabNaf5"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - if ($stmt->rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . $item->naf . "' => \"" . $item->LibNaf. "\",\n"); - } - } - - fwrite($fp, ");\n"); -} - -/** - * Cache CodesNace - */ -if ( $opts->generate == 'CodesNace' ) { - - $sql = "SELECT codNaf5 AS naf, libNaf5 AS LibNaf, codNaf1 FROM jo.tabNaf5"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/CodesNace.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . $item->naf . "' => \"" . $item->codNaf1 . preg_replace('/^0/','',substr($item->naf,0,4)) . "\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache CodesNafa - */ -if ( $opts->generate == 'CodesNafa' ) { - - $sql = "SELECT codNafa AS nafa, libNafa FROM jo.tabNafa"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/CodesNafa.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . $item->nafa . "' => \"" . $item->libNafa ."\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache CodesFJ - */ -if ( $opts->generate == 'CodesFJ' ) { - - $sql = "SELECT code AS FJ, libelle AS libFJ FROM jo.tabFJur WHERE code>=1000"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/CodesFJ.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t" . $item->FJ . " => \"" . str_replace('"','\"',$item->libFJ) ."\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Cache AffairesTypes - * Code Nature des contentieux - */ -if ( $opts->generate == 'AffairesTypes' ) { - - $sql = "SELECT code, label FROM jo.greffes_affaires_nature"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Table/AffairesTypes.php','w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t'" . $item->code . "' => \"" . $item->label ."\",\n"); - } - } - fwrite($fp, ");\n"); -} - -/** - * Procol Delete - */ -if ( $opts->generate == 'ProcolDelete' ) { - - $sql = "SELECT codEven, affProcol, libEven FROM jo.tabEvenements WHERE affProcol>0"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - - $fp = fopen(APPLICATION_PATH . '/../library/Metier/Defaillance/ProcolDelete.php', 'w'); - fwrite($fp, "rowCount() > 0) { - foreach($result as $item) { - fwrite($fp, "\t" . $item->codEven . " => " . $item->affProcol .", //".$item->libEven." \n"); - } - } - fwrite($fp, ");\n"); -} - - diff --git a/scripts/build/genCodeRatios.php b/scripts/build/genCodeRatios.php deleted file mode 100644 index c42dfea8..00000000 --- a/scripts/build/genCodeRatios.php +++ /dev/null @@ -1,1102 +0,0 @@ - "Aide.", - 'ratios' => "Génére la class des ratios (classMRatios.php)", - 'type-s' => "Choix du type d'indiScore : score 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) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "\nRatios et Formules\n\n"; - echo $opts->getUsageMessage(); - exit; -} - -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -// Database -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - -// Fichier MRatios -if (isset($opts->ratios)) { - - $configFile = APPLICATION_PATH.'/../library/Metier/Scores/MRatios.php'; - - $fp = fopen($configFile, 'w'); - fwrite($fp, ''R[801]', - 'R01b'=>'Rh[801]', - 'R01c'=>'Rs[801]', - 'R02a'=>'R[802]', - 'R02b'=>'Rh[802]', - 'R02c'=>'Rs[802]', - 'R02d'=>'Rq[802]', - 'R02e'=>'Rt[802]', - 'R03a'=>'R[803]', - 'R03b'=>'Rh[803]', - 'R03c'=>'Rs[803]', - 'R03d'=>'Rq[803]', - 'R03e'=>'Rt[803]', - 'R04a'=>'R[804]', - 'R04b'=>'Rh[804]', - 'R04c'=>'Rs[804]', - 'R04d'=>'Rq[804]', - 'R04e'=>'Rt[804]', - 'R05a'=>'R[805]', - 'R05b'=>'Rh[805]', - 'R05c'=>'Rs[805]', - 'R06a'=>'R[806]', - 'R06b'=>'Rh[806]', - 'R06c'=>'Rs[806]', - 'R06d'=>'Rq[806]', - 'R06e'=>'Rt[806]', - 'R07a'=>'R[807]', - 'R07b'=>'Rh[807]', - 'R07c'=>'Rs[807]', - 'R07d'=>'Rq[807]', - 'R07e'=>'Rt[807]', - 'R08a'=>'R[808]', - 'R08b'=>'Rh[808]', - 'R08c'=>'Rs[808]', - 'R08d'=>'Rq[808]', - 'R08e'=>'Rt[808]', - 'R09a'=>'R[809]', - 'R09b'=>'Rh[809]', - 'R09c'=>'Rs[809]', - 'R09d'=>'Rq[809]', - 'R09e'=>'Rt[809]', - 'R10a'=>'R[810]', - 'R10b'=>'Rh[810]', - 'R10c'=>'Rs[810]', - 'R10d'=>'Rq[810]', - 'R10e'=>'Rt[810]', - 'R11a'=>'R[811]', - 'R11b'=>'Rh[811]', - 'R11c'=>'Rs[811]', - 'R12a'=>'R[812]', - 'R12b'=>'Rh[812]', - 'R12c'=>'Rs[812]', - 'R13a'=>'R[813]', - 'R13b'=>'Rh[813]', - 'R13c'=>'Rs[813]', - 'R13d'=>'Rq[813]', - 'R13e'=>'Rt[813]', - 'R14a'=>'R[814]', - 'R14b'=>'Rh[814]', - 'R14c'=>'Rs[814]', - 'R14d'=>'Rq[814]', - 'R14e'=>'Rt[814]', - 'R15a'=>'R[815]', - 'R15b'=>'Rh[815]', - 'R15c'=>'Rs[815]', - 'R15d'=>'Rq[815]', - 'R15e'=>'Rt[815]', - 'R16a'=>'R[816]', - 'R16b'=>'Rh[816]', - 'R16c'=>'Rs[816]', - 'R16d'=>'Rq[816]', - 'R16e'=>'Rt[816]', - 'R17a'=>'R[817]', - 'R17b'=>'Rh[817]', - 'R17c'=>'Rs[817]', - 'R18a'=>'R[818]', - 'R18b'=>'Rh[818]', - 'R18c'=>'Rs[818]', - 'R18d'=>'Rq[818]', - 'R18e'=>'Rt[818]', - 'R19a'=>'R[819]', - 'R19b'=>'Rh[819]', - 'R19c'=>'Rs[819]', - 'R19d'=>'Rq[819]', - 'R19e'=>'Rt[819]', - 'R20a'=>'R[820]', - 'R20b'=>'Rh[820]', - 'R20c'=>'Rs[820]', - 'R20d'=>'Rq[820]', - 'R20e'=>'Rt[820]', - 'R21a'=>'R[821]', - 'R21b'=>'Rh[821]', - 'R21c'=>'Rs[821]', - 'R21d'=>'Rq[821]', - 'R21e'=>'Rt[821]', - 'R22a'=>'R[822]', - 'R22b'=>'Rh[822]', - 'R22c'=>'Rs[822]', - 'R23a'=>'R[823]', - 'R23b'=>'Rh[823]', - 'R23c'=>'Rs[823]', - 'R24a'=>'R[824]', - 'R24b'=>'Rh[824]', - 'R24c'=>'Rs[824]', - 'R25a'=>'R[825]', - 'R25b'=>'Rh[825]', - 'R25c'=>'Rs[825]', - 'R26a'=>'R[826]', - 'R26b'=>'Rh[826]', - 'R26c'=>'Rs[826]', - 'R26d'=>'Rq[826]', - 'R26e'=>'Rt[826]', - 'R27a'=>'R[827]', - 'R27b'=>'Rh[827]', - 'R27c'=>'Rs[827]', - 'R27d'=>'Rq[827]', - 'R27e'=>'Rt[827]', - 'R28a'=>'R[828]', - 'R28b'=>'Rh[828]', - 'R28c'=>'Rs[828]', - 'R28d'=>'Rq[828]', - 'R28e'=>'Rt[828]', - 'R29a'=>'R[829]', - 'R29b'=>'Rh[829]', - 'R29c'=>'Rs[829]', - 'R29d'=>'Rq[829]', - 'R29e'=>'Rt[829]', - 'R30a'=>'R[830]', - 'R30b'=>'Rh[830]', - 'R30c'=>'Rs[830]', - 'R30d'=>'Rq[830]', - 'R30e'=>'Rt[830]', - 'R31a'=>'R[843]', - 'R31b'=>'Rh[843]', - 'R31c'=>'Rs[843]', - 'R31d'=>'Rq[843]', - 'R31e'=>'Rt[843]', - 'R32a'=>'R[831]', - 'R32b'=>'Rh[831]', - 'R32c'=>'Rs[831]', - 'R33a'=>'R[832]', - 'R33b'=>'Rh[832]', - 'R33c'=>'Rs[832]', - 'R33d'=>'R[845]', - 'R33e'=>'Rh[845]', - 'R33f'=>'Rs[845]', - 'R34a'=>'R[833]', - 'R34b'=>'Rh[833]', - 'R34c'=>'Rs[833]', - 'R34d'=>'R[846]', - 'R34e'=>'Rh[846]', - 'R34f'=>'Rs[846]', - 'R35a'=>'R[834]', - 'R35b'=>'Rh[834]', - 'R35c'=>'Rs[834]', - 'R35d'=>'R[847]', - 'R35e'=>'Rh[847]', - 'R35f'=>'Rs[847]', - 'R36a'=>'R[835]', - 'R36b'=>'Rh[835]', - 'R36c'=>'Rs[835]', - 'R36d'=>'R[849]', - 'R36e'=>'Rh[849]', - 'R36f'=>'Rs[849]', - 'R37a'=>'R[844]', - 'R37b'=>'Rh[844]', - 'R37c'=>'Rs[844]', - 'R37d'=>'R[848]', - 'R37e'=>'Rh[848]', - 'R37f'=>'Rs[848]', - 'R38a'=>'R[836]', - 'R38b'=>'Rh[836]', - 'R38c'=>'Rs[836]', - 'R38d'=>'Rq[836]', - 'R38e'=>'Rt[836]', - 'R39a'=>'R[837]', - 'R39b'=>'Rh[837]', - 'R39c'=>'Rs[837]', - 'R39d'=>'Rq[837]', - 'R39e'=>'Rt[837]', - 'R40a'=>'R[838]', - 'R40b'=>'Rh[838]', - 'R40c'=>'Rs[838]', - 'R40d'=>'Rq[838]', - 'R40e'=>'Rt[838]', - 'R41a'=>'R[842]', - 'R41b'=>'Rh[842]', - 'R41c'=>'Rs[842]', - 'R41d'=>'Rq[842]', - 'R41e'=>'Rt[842]', - 'R42a'=>'R[839]', - 'R42b'=>'Rh[839]', - 'R42c'=>'Rs[839]', - 'R42d'=>'Rq[839]', - 'R42e'=>'Rt[839]', - 'R43a'=>'R[840]', - 'R43b'=>'Rh[840]', - 'R43c'=>'Rs[840]', - 'R43d'=>'Rq[840]', - 'R43e'=>'Rt[840]', - 'R44a'=>'R[841]', - 'R44b'=>'Rh[841]', - 'R44c'=>'Rs[841]', - ); - - public function __construct() - { - } - - /** - * Conversion des zones pour les collectivités - * @param unknown \$codeR - * @param unknown \$zonesDB - * @return array - */ - public function convertZones(\$codeR, \$zonesDB) - { - foreach(\$this->tabZones2Ratios as \$oldR=>\$newR) { - if (preg_match('/(\D+)\[(\d+)\]/Uis', \$newR, \$matches) && \$matches[1]==\$codeR) { - \$iRatio=\$matches[2]; - if (\$codeR=='R') - \$ret[\$iRatio]=\$zonesDB[\$oldR]*1000; - else - \$ret[\$iRatio]=\$zonesDB[\$oldR]; - } - } - return \$ret; - } - - /** - * 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]; - } - } - - /** - * Taux de tva - * @param string \$date AAAAMM - * @return double - */ - public function getTxTva(\$date) - { - \$tabTxTva = include __DIR__ . '/Data/Tva.php'; - foreach (\$tabTxTva as \$ym => \$v) { - if (\$ym > \$date) { - break; - } - \$tva = \$v; - } - return \$tva; - } - - /** - * 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['DATE_CLOTURE']; - \$tva = \$this->getTxTva(substr(\$millesime,0,6)); - - // --- 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"); - - $stmt = $conn->executeQuery("SELECT id, libelle, formule, unite, commentaires, borneMin, - borneMax, calcul, deleted FROM jo.ratios_formules WHERE deleted=0"); - - $tabMoy = array(); - while ($formule = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $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; -} - -// --- Formules -if (isset($opts->formules)) { - - if ( isset($opts->type) && in_array($opts->type, array('score', 'valo')) ) { - $type = $opts->type; - } else { - $type = 'score'; - } - - $cycle = 2; - $version = $opts->formules; - - // Select the right table in database in function of type - switch ($type) { - case 'score': - $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 - $stmt = $conn->executeQuery("SELECT code, langue, cycle, ligne, commentaire, tri, deleted - FROM $tableComment - WHERE deleted=0 AND cycle=$cycle AND ligne NOT LIKE '%*%' AND commentaire NOT LIKE '.*%' - ORDER BY langue ASC, cycle ASC, code ASC, ligne ASC"); - $tabCommentaires = $tabTri = $tabTriAff = array(); - while ($commentaire = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $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; - } - } - - // Read formulas - $stmt = $conn->executeQuery("SELECT code, ligne, remarque, operande, ope1, operation, valeur - FROM $tableFormu - WHERE deleted=0 AND code>1 AND ligne NOT LIKE '%*%' ORDER BY code ASC, ligne ASC"); - $idPre = $strFormule = false; - $debugFormule = ''; - $fp = fopen($file,'w'); - fwrite($fp,'fetch(\PDO::FETCH_ASSOC)) { - $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('/\$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); - - fwrite($fp, $remarque."\n"); - // Remplace "$" par "$this->" - fwrite($fp, str_replace('$', '$this->', $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"=>' ')); - } - $ligne = $formule['ligne']*1; - - $operande = trim(strtr(strtoupper($formule['operande']),array(':'=>''))); - $ope1 = trim($formule['ope1']); - - // PROJECTAUX PROJECCOEF PROJEC - if (preg_match("/(PROJECTAUX|PROJECCOEF|PROJEC)\((.*)\)/Ui", $ope1, $matches)) { - $ope1 = $matches[1].'($'.preg_replace('/R\[0+/', 'regR[', str_replace('+', '', $matches[2])).')'; - } - // Gestion du mot clef LONG - elseif (preg_match('/^LONG\(([A-Z0-9\_]{1,30})\)$/i', $ope1, $matches)) { - $ope1 = preg_replace('/^LONG\(([A-Z0-9\_]{1,30})\)$/i','strlen(\$$1)', $ope1); - } - // Gestion du substr - else { - $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('"'=>"'"))); - - 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,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); - } - - 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)) { - $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: - echo 'Indiscore '.$id.' OPERANDE INCONNUE '.$operande."\n"; - break; - } - $idPre = $id; - //echo $strFormule."\n"; - } - - // --- Gestion de la dernière ligne de commentaire - $debugFormule.= $strFormule.') ) $C['.$idPre.']=true;'."\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('/\$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); - - eval ($strFormule.') $C['.$idPre.']=true;'); - - // Remplace "$" par "$this->" - fwrite($fp, str_replace('$', '$this->', $strFormule.') $C['.$idPre.']=true;')."\n"); - fwrite($fp, str_replace('$', '$this->', $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"; - - $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); - } -} - -// --- Commentaires -if ( isset($opts->comments) ) { - if ( isset($opts->type) && in_array($opts->type, array('score', 'valo')) ) { - $type = $opts->type; - } else { - $type = 'score'; - } - - $cycle = 2; - if (isset($opts->niveau)) { - $cycle = $opts->niveau; - } - $version = $opts->comments; - - // Select the right table in database in function of type - switch ($type) { - case 'score': - $tableComment = 'jo.scores_commentaires_'.$version; - break; - case 'valo': - $tableComment = 'jo.valo_commentaires_'.$version; - break; - } - $path = APPLICATION_PATH.'/../library/Metier/Scores/Comment'; - - // Read comments text - $stmt = $conn->executeQuery("SELECT code, langue, cycle, ligne, commentaire, tri, deleted - FROM $tableComment - WHERE deleted=0 AND cycle=$cycle AND ligne NOT LIKE '%*%' AND commentaire NOT LIKE '.*%' - ORDER BY langue ASC, cycle ASC, code ASC, ligne ASC"); - $tabCommentaires = $tabTri = $tabTriAff = array(); - while ($commentaire = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $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 Tri Aff - $fp = fopen($path.'/'.ucfirst($type).'Tri'.$version.'N'.$cycle.'.php', 'w'); - fwrite($fp, ' $idVal) { - fwrite($fp, "\t" . $id." => ".$idVal."," . "\n"); - } - fwrite($fp, ");" . "\n"); - fclose($fp); - - // Table commentaires - $fp = fopen($path.'/'.ucfirst($type).'Txt'.$version.'N'.$cycle.'.php', 'w'); - fwrite($fp, ' $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"); - fclose($fp); - - echo "Code généré. \n"; -} - -// --- Gestion des éléments de cache -if ( $opts->tabcache) { - - $pathCache = APPLICATION_PATH . '/../library/Metier/Scores/Data'; - - // Variables - $fp = fopen($pathCache . '/Variables.php','w'); - fwrite($fp, "executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='TU'"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'TU' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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 */ - $stmt = $conn->executeQuery("SELECT REGION AS code, 'int' AS type, NCCENR AS libelle FROM insee.regions"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'REGIMP' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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"); - $stmt->closeCursor(); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - fwrite($fp, "\t\t'".$item->code."' => array("); - fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); - fwrite($fp, "),\n"); - } - fwrite($fp, "\t),\n"); - } - - /** ZEMET */ - $stmt = $conn->executeQuery("SELECT codZEMET AS code, libZEMET AS libelle, article FROM insee.insee_tabZemet WHERE anneeZemet='1994'"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'ZEMET1994' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - if( in_array(strtoupper(substr($item->libelle,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"); - } - $stmt = $conn->executeQuery("SELECT codZEMET AS code, libZEMET AS libelle, article FROM insee.insee_tabZemet WHERE anneeZemet='2010'"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'ZEMET2010' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - if( in_array(strtoupper(substr($item->libelle,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 */ - $stmt = $conn->executeQuery("SELECT numdep AS code, libdep AS libelle FROM insee.departements"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'DEPSIE' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - fwrite($fp, "\t\t'".$item->code."' => array("); - fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); - fwrite($fp, "),\n"); - } - fwrite($fp, "\t),\n"); - } - - /** LIEUACT */ - $stmt = $conn->executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='LIEUACT'"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'LIEUACT' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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 */ - $stmt = $conn->executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='ACTISURF'"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'ACTISURF' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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 */ - $stmt = $conn->executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='ACTIVNAT'"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'ACTIVNAT' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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*/ - $stmt = $conn->executeQuery("SELECT code, libelle FROM jo.tabFJur"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'FJUR' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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 */ - $stmt = $conn->executeQuery("SELECT codNaf700 AS code, libNaf700 AS libelle FROM jo.tabNaf4 UNION SELECT codNaf5 AS code, libNaf5 AS libelle FROM jo.tabNaf5"); - if ($stmt->rowCount() > 0 ) { - fwrite($fp, "\t'APEENT' => array(\n"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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"); - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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 . '/Infla.php','w'); - fwrite($fp, "executeQuery("SELECT annee, infla FROM sdv1.inflation WHERE annee>1990 ORDER BY annee"); - if ($stmt->rowCount() > 0 ) { - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - fwrite($fp, "\t" . $item->annee . " => " . $item->infla . ",\n"); - } - } - - fwrite($fp, ");\n"); - fclose($fp); - - /** Taux de rendement des actions **/ - $fp = fopen($pathCache . '/RendObli.php','w'); - fwrite($fp, "executeQuery("SELECT annee, txMoinsInfla FROM sdv1.txRendObli WHERE annee>1990 ORDER BY annee ASC"); - if ($stmt->rowCount() > 0 ) { - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - fwrite($fp, "\t" . $item->annee . " => " . $item->txMoinsInfla . ",\n"); - } - } - fwrite($fp, ");\n"); - fclose($fp); - - /** Formules **/ - $fp = fopen($pathCache . '/Formules.php','w'); - fwrite($fp, "executeQuery("SELECT id, libelle, formule, unite, commentaires, borneMin, borneMax, calcul, deleted FROM jo.ratios_formules WHERE deleted=0"); - if ($stmt->rowCount() > 0 ) { - $i = 0; - while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { - 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); -} diff --git a/scripts/build/genCodeSfr.php b/scripts/build/genCodeSfr.php deleted file mode 100644 index f831e046..00000000 --- a/scripts/build/genCodeSfr.php +++ /dev/null @@ -1,75 +0,0 @@ - "Aide.", - 'compile-s' => "Génére le cache des règles, sans paramètres (tout), avec paramètres (VORD, VORP, PO)", - 'version=s' => "Version des régles", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "\nRegles SFR\n\n"; - echo $opts->getUsageMessage(); - exit; -} - -// Doctrine conn -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $application->profil->db->metier->params->dbname, - 'user' => $application->profil->db->metier->params->username, - 'password' => $application->profil->db->metier->params->password, - 'host' => $application->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - exit; -} - -$types = array('VORD', 'VORP', 'PO'); - -if ( $opts->compile!='' && in_array($opts->compile, $types) ) { - $types = array($opts->compile); -} - -if ( count($types) > 0 ) { - - foreach ( $types as $type ) { - $ruleSfrM = new Metier_Sfr_Compile($conn); - $ruleSfrM->setVersion($opts->version); - $ruleSfrM->construct($type); - } - -} - - - diff --git a/scripts/build/genLog.php b/scripts/build/genLog.php deleted file mode 100644 index 9fa1a730..00000000 --- a/scripts/build/genLog.php +++ /dev/null @@ -1,87 +0,0 @@ - "Aide.", - 'log' => "", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "\nLog\n\n"; - echo $opts->getUsageMessage(); - exit; -} - -if ($opts->log) { - // Database - $c = new Zend_Config($application->getOptions()); - $config = new \Doctrine\DBAL\Configuration(); - $connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', - ); - - try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); - } catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; - } - - $sql = "SELECT * FROM sdv1.logs_item"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - - $outPath = APPLICATION_PATH . '/../library/Scores/Account/Log/List.php'; - $outFile = $outPath . '/Config.php'; - if ($stmt->rowCount() > 0) { - $result = $stmt->fetchAll(\PDO::FETCH_OBJ); - file_put_contents($outFile, "Code . "' => array(,\n", FILE_APPEND); - file_put_contents($outFile, "\t\t'Label' => ". $c->Label . ",\n", FILE_APPEND); - file_put_contents($outFile, "\t\'Description' => ". $c->Description . ",\n", FILE_APPEND); - file_put_contents($outFile, "\t\t'Category' => ". $c->Category . ",\n", FILE_APPEND); - file_put_contents($outFile, "\t),\n", FILE_APPEND); - } - file_put_contents($outFile, ");\n", FILE_APPEND); - } -} - - - - - - - diff --git a/scripts/build/genTypes.php b/scripts/build/genTypes.php deleted file mode 100644 index f535126f..00000000 --- a/scripts/build/genTypes.php +++ /dev/null @@ -1,61 +0,0 @@ - "Aide.", - 'path=s' => "{Service Name}/{version}", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "\nType Service\n\n"; - echo $opts->getUsageMessage(); - exit; -} - -$wsPath = APPLICATION_PATH . '/../library/WsScore/'; - -require_once $wsPath . $opts->path . '/Types.php'; -$detect = new Zend_Reflection_File($wsPath . $opts->path . '/Types.php'); -$result = $detect->getClasses(); - -$outPath = dirname($wsPath . $opts->path . '/Types.php'); -$outFile = $outPath . '/Config.php'; - -if (count($result) > 0) { - file_put_contents($outFile, "name . "' => '" . $c->name ."',\n", FILE_APPEND); - } - file_put_contents($outFile, ");\n", FILE_APPEND); -} - - - - - diff --git a/scripts/build/loadCodeRatios.php b/scripts/build/loadCodeRatios.php deleted file mode 100644 index 08843120..00000000 --- a/scripts/build/loadCodeRatios.php +++ /dev/null @@ -1,636 +0,0 @@ - "Aide.", - 'fichier=s' => "Nom du fichier complet : version ", - 'affiche=s' => "Affiche resultat traitement " - )); - $opts->parse(); -} -catch (Zend_Console_Getopt_Exception $e) -{ - echo $opts->getUsageMessage(); - exit; -} - - //Usage - if( count($opts->getOptions())==0 || isset($opts->help)) - { - echo $opts->getUsageMessage(); - exit; - } - - ######################################################### - ##### Presence te taille du fichier ##### - ######################################################### - - $fichier = $opts->fichier; // $fichier contient chemin/qqchose.csv - $nomfichier = basename($fichier); // $nomfichier contient qqchose.csv, basename retourne un array donc un tableau ayant comme valeur chacun des - - // fichiers (chemain absolu) contenu dans le repertoir $directory, ici le repertoir contient normalement une seul fichier a la fois , donc $fichier[] - $fic = $fichier ; // On definti notre variable $fic comme etant notre fichier. - - ######################################################### - ##### Teste de validité du nom du fichier ##### - ######################################################### - - $detect1 = strstr($nomfichier, 'valo_commentaires_'); - $detect2 = strstr($nomfichier, 'valo_formules_'); - $detect3 = strstr($nomfichier, 'scores_formules_'); - $detect4 = strstr($nomfichier, 'scores_commentaires_'); - - - if ($detect1 !== false or $detect2 !== false or $detect3 !== false or $detect4 !== false) - { - echo "\n"." Nom du fichier ok"."\n" ; - } - else - { - echo "\n" . "le nom du fichier est incorrect" . "\n"; - echo "\n" . "le nom du fichier doit obliqatoirement etre compose de la sorte :" . "\n"; - echo "\n" . 'valo_commentaires_' . "\n"; - echo "\n" ."ou"."\n"; - echo "\n" . 'valo_formules_' . "\n"; - echo "\n" ."ou"."\n"; - echo "\n" . 'scores_formules_' . "\n"; - echo "\n" ."ou"."\n"; - echo "\n" . 'scores_commentaires_' . "\n"; - - Exit; - } - - - ######################################################### - ##### On indique si le fichier est present ou non ##### - ######################################################### - - if ((file_exists($fichier))) - { - echo "\n Fichier $nomfichier au format csv trouve a l'emplacement prevu : \n"; - echo "\n"." La taille du fichier est de :".filesize($fic)." octets"."\n"; - $file = true; - } - else - { - echo "\n". "Pas de fichier .csv present a l'endroit indique"."\n"; - $file = false; - exit; - } - - ######################################################### - ##### taille du contenu du fichier ##### - ######################################################### - - # déclaration variables : - - $fileopen = fopen($fic, 'r'); - $contenufichier = fgetcsv($fileopen); - $nblignes=0; - $cnbl = count($nblignes); - $fific = file($fic); // retourner le contenu du fichier dans une chaîne de caractères. - - - foreach ($fific as $line_num => $line) - { - $nblignes++; - } - echo "\n"." le fichier contient " . $nblignes . " lignes."."\n" ; - - - ######################################################### - ##### Routage vers commentaires ou formules ##### - ######################################################### - - #variables : - - $doublon = 0; // On initialise la variable doublon. - $row = 0 ; // On initialise les lignes. - $verif = array() ; // creation d'un tableau - $nom_fic = basename($fic) ; - $col3= 0; - - ######################################################### - ##### Identification du type de fichier ##### - ######################################################### - - //On commance rechercher si le nom du fichier contient "COMMENTAIRE" pour 4 colonnes sinon 2 colonnes - if (strstr($nom_fic, 'commentaires')) - { - $nbcol_cle = 4; - } - else - { - $nbcol_cle = 2; - } - - // Si $fic est bien ouvert on commence le traitement. - if ($file = true ) - { - $fileopen2 = fopen($fic, "r+"); - - if($fileopen2) - { - $contenufichier=fgetcsv($fileopen2); - $nblignes = file($fic); - - // Tant qu'il y a des lignes, lis les et fait en un tableau. - while (($data = fgetcsv($fileopen2,0,';','"')) !== FALSE) - { - $num = count($row); //compte nombre de partits dans la phrase - $row++; - - // On fait une concatenation des colonnes de $fic dans un nouveau tableau nomme $cle. - // Cela nous permettera de dedoublonner par la suite. - - if ($nbcol_cle == 4) // si nbcol = 4 alors notre clé sera composée de 4 colonnes sinon 3 - { - $cle = $data[0].$data[1].$data[2].$data[3]; - } - else - { - $cle = $data[0].$data[1].$data[2]; - } - - ######################################################### - ##### Dédoublonnage ##### - ######################################################### - - // On regarde si on retrouve les valeurs de $verif dans $cle - if (in_array($cle, $verif, TRUE)) - { - $doublon = $doublon + 1; // On définit un compteur qui nous indiquera le nombre de doublons - echo "\n"."Attention vous avez $doublon doublon(s) dans votre fichier !\n"; - echo "\n"."il semblerait qu'il soit present a la ligne $row contenant $cle "."\n"; - } - else - { - // Ajout de la cle au tableau indexe numeriquement - $verif[] = $cle ; - } - ######################################################### - ##### Routage commentaires ou formules ##### - ##### et verification des champs ##### - ######################################################### - if (strstr ($nom_fic , 'commentaires'))// le nom du fichier contient 'commentaires' alors ... - { - // On teste les champs vide - if (strlen($data[0])== 0 or strlen($data[1]) == 0 - or strlen($data[2]) == 0 or strlen($data[3]) == 0) - { - echo "\n"."Erreur ! Vous avez des champs vides commentaires , sur la ligne $num"."\n"."contenant $data[1].$data[2].$data[3].$data[4].$data[5].$data[6].$data[7]"; - } - - if ($data[0] == 0) - { - echo "\n"."erreur code commentaire ". $data[0] ." null"."\n"; - exit; - } - - if($data[2] < 0) - { - echo "\n"."erreur code ligne " . $data[2] . "null"."\n"; - exit; - } - } - elseif (strstr ($nom_fic , 'formules')) - { - if (strlen($data[0]) == 0 or strlen($data[1]) == 0 ) - { - echo "\n"." Erreur vous avez des champs vides formules , sur la ligne $row"."\n"."contenant $data[0].$data[1]. . "; - exit; - } - - if ($data[0] == 0) - { - echo "\n"."erreur code commentaire " . $data[0] . " null"."\n"; - exit; - } - - if($data[1] < 0) - { - echo "\n"."erreur code code ligne". $data[1] ."null"."\n"; - exit; - } - } - } - } - } - if ($doublon >= 1) - { - $ok = false; - echo "\n"." $doublon Doublons détectés dans le fichier."."\n"; - // Quitte avec un code d'erreur: doublon détecté. - exit(1); - - } - elseif ($doublon == 0 && !file_exists($fic)) - { - $ok = false; - exit; - } - else - { - - // le script appelant continue. - $ok = true; // petit marqueur de fonctionnement du script jusqu'a présent - echo "\n Le fichier ne comporte pas de doublon. \n"; - } - - fclose($fileopen); - - - echo "\n Bon, maintenant on va passer a la base de donnee \n"; - - ######################################################### - ##### ________ ____ ____ ##### - ### | __ \ | \ | \ ### - # | / | |\ \ | |\ \ # - ### | __ \ | |/ / | |/ / ### - ##### |_______/ |___/ |___/ ##### - ######################################################### - - // si notre scripte est bon on passe a la suite - $c = new Zend_Config($application->getOptions()); - try { - $db = Zend_Db::factory($c->profil->db->metier); - $db->getConnection(); - // print_r (get_class_methods($db)); - } - catch (Zend_Exception $e) - { - echo $e->getMessage(); - } - -if ($db->isConnected()) - { - echo "\n***********************************************\n"; - echo "\n Connection a la BDD ok \n"; - echo "\n***********************************************\n"; - } -else - { - echo "\n***********************************************\n"; - echo "\n !!!! Erreur / ! Pas connecte a la BDD !!!! \n"; - echo "\n***********************************************\n"; - } - - $pathCache = APPLICATION_PATH . '/../library/Metier/Scores/Variables'; - $copy_fic = $nomfichier; - - if($nomfichier) // Si le nom du fichier comprend 'scores' ou 'valo'... - { - // On découpe la chaine de caractère à chaque "/" et on fait un array. - $token = basename($copy_fic); - - // On prend ce qui se trouve avant le point - $token1 = strtok($token, "."); - - // On effece '_utf8' et '.csv' - $nomtabletemp =(str_replace('_utf8', '', $token)); - $nomtable =(str_replace('.csv','', $nomtabletemp)); - - // Affichage du nom de la table - echo "\n Le nom de la table est : $nomtable . \n"; - } - - #################################################### - ##### // Création de la Table Ccmmentaires \\ ##### - #################################################### - - if (strstr($nomtable,"commentaires")) - { - - try - { - // Création d'une table "TEXTE" - $sql_ctc_query = $db->query("CREATE TABLE $nomtable - ( - code int(8) NOT NULL, - langue char(2) NOT NULL, - cycle smallint(3) NOT NULL, - ligne char(4) NOT NULL, - commentaire longtext, - tri varchar(5) DEFAULT NULL, - deleted varchar(2) DEFAULT NULL, - idUser varchar(0) DEFAULT NULL, - dateInsert varchar(15) DEFAULT NULL, - dateUpdate varchar(0) DEFAULT NULL, - PRIMARY KEY (code,langue,cycle,ligne) - ) - ENGINE = MyISAM DEFAULT CHARSET=latin1 COMMENT= 'Commentaires Valorisation - Liste des commentaires';"); - } - catch (Zend_Exception $e) - { - echo $e->getMessage()."\n"; - echo "\n"."!!!!! ERREUR ! / CHARGEMENT ARRETE !!!!!"."\n"."\n"; - - } - echo "\n" . " Table $nomtable cree." ."\n"; - } - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - $fileopen2 = fopen($fic, "r+"); - $nbr=0; - - if($fileopen2) - { - $contenufichier=fgetcsv($fileopen2); - $nblignes = file($fic); - $vide = ""; - $null = null; - $zero = 0; - } - else - { - exit; - echo "\n"."Erreur a l'ouverture du fichier"."\n"; - } - - if(strstr($nomtable,"commentaires")) - { - // Tant qu'il y a des lignes, lis les et fait en un tableau. - while (($data = fgetcsv($fileopen2,0,';','"')) !== FALSE) - { - - #################################################### - ##### encodage et remplacement du contenu ##### - #################################################### - - $data[4] = str_replace(chr(93), "]", $data[4]); // crochet fermant - $data[4] = str_replace(chr(92), "\\" , $data[4]); // anti slash - $data[4] = str_replace(chr(128), '€', $data[4]); // devise euros - $data[4] = str_replace(chr(130), ',', $data[4]); // baseline single quote - $data[4] = str_replace(chr(132), '"', $data[4]); // baseline double quote - $data[4] = str_replace(chr(133), '...', $data[4]); // ellipsis - $data[4] = str_replace(chr(145), "'", $data[4]); // left single quote - $data[4] = str_replace(chr(146), "'", $data[4]); // right single quote - $data[4] = str_replace(chr(147), '"', $data[4]); // left double quote - $data[4] = str_replace(chr(148), '"', $data[4]); // right double quote - $data[4] = str_replace(chr(150), '–', $data[4]); // tiret du 6 - - - $data[5] = str_replace(chr(93), "]", $data[5]); // crochet fermant - $data[5] = str_replace(chr(92), "\\" , $data[5]); // anti slash - $data[5] = str_replace(chr(128), '€', $data[5]); // devise euros - $data[5] = str_replace(chr(130), ',', $data[5]); // baseline single quote - $data[5] = str_replace(chr(132), '"', $data[5]); // baseline double quote - $data[5] = str_replace(chr(133), '...', $data[5]); // ellipsis - $data[5] = str_replace(chr(145), "'", $data[5]); // left single quote - $data[5] = str_replace(chr(146), "'", $data[5]); // right single quote - $data[5] = str_replace(chr(147), '"', $data[5]); // left double quote - $data[5] = str_replace(chr(148), '"', $data[5]); // right double quote - $data[5] = str_replace(chr(150), '–', $data[5]); // tiret du 6 - - $encode = mb_detect_encoding($data[4]); // detection de l'encodage. - $encode = mb_detect_encoding($data[5]); // detection de l'encodage. - $data[4] = mb_convert_encoding($data[4], $encode, 'UTF-8'); - $data[5] = mb_convert_encoding($data[5], $encode, 'UTF-8'); - - // $Zdata4 = '"'.$db->->real_escape_string($data[4]); - // $Zdata4 = $db->quote($data[4]); - - //$Zdata4 = mysqli_real_escape_string($db, $data[4]); - - if ($data[5] == null) - { - $data[5] = 0; - } - - $zdata4= $db->quote($data[4]); - $nbr++; - - // ESSAI 1 - $sql_insert = array - ( - 'code' => "$data[0]", - 'langue' => "$data[1]", - 'cycle' => "$data[2]", - 'ligne' => "$data[3]", - 'commentaire' => "$data[4]", - 'tri' => "$data[5]", - 'deleted' => "$null", - 'idUser' => "$null", - 'dateInsert' => "$null", - 'dateUpdate' => "$null" - ); - - try - { - # $num = count($row); // On compte nombre de parti dans la phrase - # $row++; // à chaques tour de boucle j'ajoute 1 à $row - - - // ESSAI 2 - /* - $sql_itc = $db->query("INSERT INTO $nomtable - ( - code, langue, cycle, ligne, commentaire, tri, deleted, idUser, dateInsert, dateUpdate) - VALUES - ( - ".$data[0].",".$data[1].",".$data[2].",".$data[3].",".$Zdata4.",".$data[5].",'','','',) - "); - */ - - $db->insert($nomtable, $sql_insert); - - //` - // Astuce !! La structure de $data[0] étant un int on retire les " - // Astuce !! La colonne 5 contenant des apostrophs étant interprété par le sql comme un nouveau champ il est necessaire de protéger ce champs, du coup in ajoute la fonction mysql_real_escape_string() pour insérer un antislash devant les caractères " NULL, \x00, \n, \r, \, ', " et \x1a. " - } - - // Renseignement sur les erreurs possibles - #echo ("$sql_itt"); - catch(Zend_Exception $e) - { - echo "\n" . $e->getMessage()."\n"; - - //echo "\n"."!!!!!!!!!!!!!!!!!!!!! Import de la table $nomtable echouee. !!!!!!!!!!!!!!!!!!!!!"."\n"."\n"; - //$sql_erase = $db->query("DROP TABLE $nomtable;"); - //echo "La table $nomtable a ete effacee !! \n "; - } - } - - echo "\n"."Import de la table $nomtable . ok". "\n"; - - // comptage sql - $comptage = count($sql_itc_query); - echo "\n"."Nombre de lignes importees : "."$nbr"."\n"; - - exit; - } - - - - elseif(strstr($nomtable,"formules")) - { - #################################################### - // Création de la Table formules \\ - #################################################### - try{ - $sql_ctf_query = $db->query("CREATE TABLE $nomtable - ( - code int(8) NOT NULL DEFAULT '0', - ligne char(4) NOT NULL DEFAULT '', - remarque varchar(120) DEFAULT NULL, - operande varchar(7) DEFAULT NULL, - ope1 varchar(255) DEFAULT NULL, - operation varchar(9) DEFAULT NULL, - valeur varchar(255) DEFAULT NULL, - tri varchar(0) DEFAULT NULL, - deleted varchar(0) DEFAULT NULL, - idUser varchar(0) DEFAULT NULL, - dateInsert varchar(0) DEFAULT NULL, - dateUpdate varchar(0) DEFAULT NULL, - PRIMARY KEY (code,ligne) - ) - ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Criteres Valorisation - Formules de calculs' ;"); - - } - catch (Zend_Exception $e) - { - echo $e->getMessage()."\n"; - echo "\n"."!!!!!!!!!!!!!!!!!!!!! CHARGEMENT ARRETE !!!!!!!!!!!!!!!!!!!!!"."\n"."\n"; - } - echo "\n Table $nomtable cree.\n"; - - - // Tant qu'il y a des lignes, lis les et fait en un tableau. - while (($data = fgetcsv($fileopen2,0,';','"')) !== FALSE) - { - - - #################################################### - ##### encodage et remplacement du contenu ##### - #################################################### - - $data[2] = str_replace(chr(93), "]", $data[2]); // crochet fermant - $data[2] = str_replace(chr(92), "\\" , $data[2]); // anti slash - $data[2] = str_replace(chr(128), '€', $data[2]); // devise euros - $data[2] = str_replace(chr(130), ',', $data[2]); // baseline single quote - $data[2] = str_replace(chr(132), '"', $data[2]); // baseline double quote - $data[2] = str_replace(chr(133), '...', $data[2]); // ellipsis - $data[2] = str_replace(chr(145), "'", $data[2]); // left single quote - $data[2] = str_replace(chr(146), "'", $data[2]); // right single quote - $data[2] = str_replace(chr(147), '"', $data[2]); // left double quote - $data[2] = str_replace(chr(148), '"', $data[2]); // right double quote - $data[2] = str_replace(chr(150), '–', $data[2]); // tiret du 6 - - - $data[4] = str_replace(chr(93), "]", $data[4]); // crochet fermant - $data[4] = str_replace(chr(92), "\\" , $data[4]); // anti slash - $data[4] = str_replace(chr(128), '€', $data[4]); // devise euros - $data[4] = str_replace(chr(130), ',', $data[4]); // baseline single quote - $data[4] = str_replace(chr(132), '"', $data[4]); // baseline double quote - $data[4] = str_replace(chr(133), '...', $data[4]); // ellipsis - $data[4] = str_replace(chr(145), "'", $data[4]); // left single quote - $data[4] = str_replace(chr(146), "'", $data[4]); // right single quote - $data[4] = str_replace(chr(147), '"', $data[4]); // left double quote - $data[4] = str_replace(chr(148), '"', $data[4]); // right double quote - $data[4] = str_replace(chr(150), '–', $data[4]); // tiret du 6 - - - $data[5] = str_replace(chr(93), "]", $data[5]); // crochet fermant - $data[5] = str_replace(chr(92), "\\" , $data[5]); // anti slash - $data[5] = str_replace(chr(128), '€', $data[5]); // devise euros - $data[5] = str_replace(chr(130), ',', $data[5]); // baseline single quote - $data[5] = str_replace(chr(132), '"', $data[5]); // baseline double quote - $data[5] = str_replace(chr(133), '...', $data[5]); // ellipsis - $data[5] = str_replace(chr(145), "'", $data[5]); // left single quote - $data[5] = str_replace(chr(146), "'", $data[5]); // right single quote - $data[5] = str_replace(chr(147), '"', $data[5]); // left double quote - $data[5] = str_replace(chr(148), '"', $data[5]); // right double quote - $data[5] = str_replace(chr(150), '–', $data[5]); // tiret du 6 - - $data[6] = str_replace(chr(93), "]", $data[6]); // crochet fermant - $data[6] = str_replace(chr(92), "\\" , $data[6]); // anti slash - $data[6] = str_replace(chr(128), '€', $data[6]); // devise euros - $data[6] = str_replace(chr(130), ',', $data[6]); // baseline single quote - $data[6] = str_replace(chr(132), '"', $data[6]); // baseline double quote - $data[6] = str_replace(chr(133), '...', $data[6]); // ellipsis - $data[6] = str_replace(chr(145), "'", $data[6]); // left single quote - $data[6] = str_replace(chr(146), "'", $data[6]); // right single quote - $data[6] = str_replace(chr(147), '"', $data[6]); // left double quote - $data[6] = str_replace(chr(148), '"', $data[6]); // right double quote - $data[6] = str_replace(chr(150), '–', $data[6]); // tiret du 6 - - $encode = mb_detect_encoding($data[2]); // detection de l'encodage. - $encode = mb_detect_encoding($data[5]); // detection de l'encodage. - $encode = mb_detect_encoding($data[4]); // detection de l'encodage. - $encode = mb_detect_encoding($data[6]); // detection de l'encodage. - - $data[2] = mb_convert_encoding($data[2], $encode, 'UTF-8'); - $data[4] = mb_convert_encoding($data[4], $encode, 'UTF-8'); - $data[5] = mb_convert_encoding($data[5], $encode, 'UTF-8'); - $data[6] = mb_convert_encoding($data[6], $encode, 'UTF-8'); - - -$sql_insert = array( - 'code' => "$data[0]", - 'ligne' => "$data[1]", - 'remarque' => "$data[2]", - 'operande' => "$data[3]", - 'ope1' => "$data[4]", - 'operation' => "$data[5]", - 'valeur' => "$data[6]", - 'tri' => "$null", - 'deleted' => "$null", - 'idUser' => "$null", - 'dateInsert' => "$null", - 'dateUpdate' => "$null" - ); - $nbr++; - try{ - $db->insert($nomtable, $sql_insert); - } - catch (Zend_Exception $e) - { - echo $e->getMessage()."\n"; - echo "\n"."!!!!! ERREUR ! / CHARGEMENT ARRETE !!!!!"."\n"."\n"; - } - } - - echo "\n"." Import de la table $nomtable ok."."\n"; - - // comptage sql - $comptage = count($sql_insert); - echo "\n"." Nombre de lignes importees : "."$nbr"."\n"; - fclose($fileopen2); - exit; - } - - - // Exécution de la requête - //$result = $db->query($sql_ctt); - // Renseignement sur les erreurs possibles - - - - - -// echo "" . $Erreur . "
'; print_r($e); echo ''; - } else { - echo "Le service rencontre actuellement un problème technique."; - } - exit; -} -Zend_Registry::set('doctrine', $conn); - -/** - * Connexion à la base de données - */ -$db = Zend_Db::factory($c->profil->db->metier); -Zend_Db_Table_Abstract::setDefaultAdapter($db); - -// Bilans -if ($opts->bilan) { - - if ($opts->files) { - - $nbBilans = 0; - - //Type de bilan - $types = array('consolides', 'sociaux'); - foreach ( $types as $type ) { - - $path = $c->profil->infogreffe->storage->path . '/' . 'bilans'; - - echo "Bilans ".$type.PHP_EOL; - - //AAAA - echo "Liste des années...".PHP_EOL; - $dirYears = array(); - $path = $path . '/' . $type; - if ($handle = opendir($path)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' && is_dir($path . '/' . $file)) { - $dirYears[] = $file; - } - } - sort($dirYears); - } - - //Fichier - foreach ($dirYears as $year) { - echo "Traitement des fichiers $type $year".PHP_EOL; - $pathFile = $path . '/' . $year; - if ($handle = opendir($pathFile)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' ) { - //'bilan-' . $this->siren . '-' . $type . '-' . $dateCloture . '.pdf'; - if (preg_match('/^bilan-([0-9]{9})-(sociaux|consolides)-([0-9]{8})\.pdf/', $file, $matches)) { - - echo "Fichier ".$file; - - $siren = $matches[1]; - $typeComptes = $matches[2]; - $dateCloture = substr($matches[3],0,4).'-'.substr($matches[3],4,2).'-'.substr($matches[3],6,2); - - //Recherche dans la bdd - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->where('siren=?',$siren) - ->where('date_cloture=?', $dateCloture); - if ($typeComptes=='sociaux') { - $sql->where('type_comptes="" OR type_comptes="sociaux"'); - } else { - $sql->where('type_comptes="consolides"'); - } - $sql->where('actif=1'); - $sql->order('dateInsert DESC')->order('num_depot DESC')->limit(1); - $item = $bilanM->fetchRow($sql); - - if ($item === null) { - //If not find write the database - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infogreffe->getList(); - //And get again the item in database - $item = $bilanM->fetchRow($sql); - } - - if ($item === null) { - echo " = non trouvé."; - } else { - if ($item->pdfDate == '0000-00-00') { - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infos = $infogreffe->pdfInfos($pathFile . '/' . $file); - - if (false !== $infos) { - $data = array( - 'pdfLink' => $file, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $bilanM->update($data, 'id='.$item->id); - echo " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - - } else { - echo " = présent."; - } - - } - echo PHP_EOL; - } - $nbBilans++; - } - } - } - } - } - echo "Nombre de fichier : ".$nbBilans.PHP_EOL; - } - - /** - * Lecture des fichiers depuis un répertoire - * siren_YYYY_NUMDEPOT_BilanComplet.pdf - */ - elseif ($opts->numdepot) { - - echo $opts->numdepot."\n"; - - if( !is_dir($opts->numdepot) ) { - echo "Répertoire inexistant !\n"; exit; - } - - if ($handle = opendir($opts->numdepot)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' ) { - if (preg_match('/^([0-9]{9})_([0-9]{4})_([0-9]{1,})_(.*)\.pdf/', $file, $matches)) { - - echo $file; - - $siren = $matches[1]; - $millesime = $matches[2]; - $depot = $matches[3]; - - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->from($bilanM, array('id','siren','millesime', 'date_cloture','type_comptes', 'pdfDate')) - ->where('siren=?', $siren) - ->where('millesime=?', $millesime) - ->where('num_depot=?', $depot); - $item = $bilanM->fetchRow($sql); - - if ($item === null) { - //If not find write the database - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infogreffe->getList(); - //And get again the item in database - $item = $bilanM->fetchRow($sql); - } - - if ($item === null) { - echo " = non trouvé."; - } else { - if ($item->pdfDate == '0000-00-00') { - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - - $type = "sociaux"; - if ( !empty($item->type_comptes) ) { - $type = $item->type_comptes; - } - - //File path - 2012_sociaux-20121231-7501-55-B-14450-0035567 - $newfile = $infogreffe->getFileName($type, $item->date_cloture); - $filepath = $c->profil->infogreffe->storage->path . '/' . - $infogreffe->getFilePath($type, $item->date_cloture) . '/' . $newfile; - - if (copy($opts->numdepot . '/' .$file, $filepath)) { - $infos = $infogreffe->pdfInfos($filepath); - - if (false !== $infos) { - $data = array( - 'pdfLink' => $file, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $bilanM->update($data, 'id='.$item->id); - echo " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - } else { - echo " = copie du fichier impossible."; - } - - } else { - echo " = présent."; - } - } - echo PHP_EOL; - } - } - } - } - - } - - //Lecture de toute la base de données - else { - - //Lire la base de données - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->from($bilanM, array('siren','millesime', 'date_cloture','type_comptes')) - ->order('millesime DESC'); - - if ( is_numeric($opts->bilan) ){ - $sql->where('millesime=?', $opts->bilan); - } - - if ( $opts->total ) { - $nbTotal = $bilanM->fetchAll($sql)->count(); - echo "Total : ".$nbTotal.PHP_EOL; - exit; - } - - if ( $opts->max && $opts->part ) { - $sql->limit($opts->max, $opts->part); - } elseif ($opts->max) { - $sql->limit($opts->max); - } - - //$nbTotal = $bilanM->fetchAll($sql)->count(); - - if ( $opts->siren ) { - $sql->where('siren=?',$opts->siren); - } else { - $sql->where('pdfDate=?','0000-00-00'); - } - - $sql->where('actif=1'); - - $result = $bilanM->fetchAll($sql); - - $NbLignes = $result->count(); - - echo "Nb Lignes à traiter : ".$NbLignes.PHP_EOL; - - if ( $NbLignes > 0 ) { - $cpt = 1; - foreach ( $result as $item ) { - $siren = str_pad($item->siren, 9, '0', STR_PAD_LEFT); - - echo "Ligne ".$cpt."/".$NbLignes." - siren = ".$siren." , millesime = ".$item->millesime; - - // Lire les informations du fichier - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $type = 'sociaux'; - if ( !empty($item->type_comptes) ) { - $type = $item->type_comptes; - } - - //File path - 2012_sociaux-20121231-7501-55-B-14450-0035567 - $file = $infogreffe->getFileName($type, $item->date_cloture); - $filepath = $c->profil->infogreffe->storage->path . '/' . - $infogreffe->getFilePath($type, $item->date_cloture) . '/' . $file; - - echo " Fichier : ".$filepath; - - if ( file_exists($filepath) ) { - echo " lecture."; - //Analyser le fichier - Nombre de page et taille - $infos = $infogreffe->pdfInfos($filepath); - - //Enregistrer les infos du fichier dans la base de données - if (false !== $infos) { - $infogreffe->type_comptes = $item->type_comptes; - $infogreffe->date_cloture = $item->date_cloture; - $infogreffe->dbSetFile($file, $infos['size'], $infos['pages'], $infos['version']); - } - } else { - echo " non trouvé."; - } - - echo PHP_EOL; - $cpt++; - } - } else { - echo "Aucun enregistrement !".PHP_EOL; - } - - } - - exit; -} - -// Actes -if ($opts->acte) { - - if ($opts->files) { - - $path = $c->profil->infogreffe->storage->path . '/' . 'actes'; - $months = array('01','02','03','04','05','06','07','08','09','10','11','12'); - - $nbActes = 0; - - //AAAA - echo "Liste des années...".PHP_EOL; - $dirYears = array(); - if ($handle = opendir($path)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' && is_dir($path . '/' . $file)) { - $dirYears[] = $file; - } - } - sort($dirYears); - } - - //Fichier - foreach ($dirYears as $year) { - foreach ($months as $month) { - $pathFile = $path . '/' . $year . '/' . $month; - echo "Traitement des fichiers $year/$month".PHP_EOL; - if ( is_dir($pathFile) ) { - if ($handle = opendir($pathFile)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' ) { - - //acte-347614984-TB-2012-03-15-1402-00-D-50625-4-1.pdf - if (preg_match('/^acte-([0-9]{9})-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)\.pdf/', $file, $matches)) { - $outfile = 'acte-'.$matches[1].'-'.$matches[2].'-'. - $matches[3].$matches[4].$matches[5].'-'. - $matches[6].'-'.$matches[7].'-'.$matches[8].'-'.$matches[9].'-'.$matches[10].'-'.$matches[11].'.pdf'; - echo "Fichier ".$file; - if ( rename($pathFile.'/'.$file, $pathFile.'/'.$outfile) ) { - $data = array( - 'pdfLink' => $outfile, - ); - try { - $acteM = new Application_Model_JoGreffesActes(); - $result = $acteM->update($data, array( - 'pdfLink="'.$file.'"', - 'siren='.$matches[1], - )); - echo " = " . $outfile . " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - echo "\n"; - continue; - } - - //'acte-' . $this->siren . '-' . $type . '-' . $date . '-' . $options . '-' . $num . '.pdf'; - //with options = NumGreffe - NumRC - NumRC - NumRC - NumDepot - //acte-876580325-XB-20120427-5602-65-B-00032-18-01.pdf - if (preg_match('/^acte-([0-9]{9})-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)\.pdf/', $file, $matches)) { - - echo "Fichier ".$file; - - $siren = $matches[1]; - $type = $matches[2]; - $date = substr($matches[3],0,4).'-'.substr($matches[3],4,2).'-'.substr($matches[3],6,2); - $depot = $matches[8]; - $num = $matches[9]; - - $acteM = new Application_Model_JoGreffesActes(); - $sql = $acteM->select() - ->where('siren=?', $siren) - ->where('num_depot=?', $depot) - ->where('date_acte=?', $date) - ->where('num_acte=?', intval($num)); - //->where('type_acte=?', $type); - //GROUP BY type_acte_libelle - - $sql->where('actif=1'); - - $items = $acteM->fetchAll($sql); - - if (count($items)==0) { - //If not find write the database - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infogreffe->getList(); - //And get again the item in database - $items = $acteM->fetchAll($sql); - } - - if (count($items)==0) { - echo " = non trouvé."; - } else { - foreach($items as $item) { - if ($item->pdfDate == '0000-00-00') { - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infos = $infogreffe->pdfInfos($pathFile . '/' . $file); - - if (false !== $infos) { - $data = array( - 'pdfLink' => $file, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $acteM->update($data, 'id='.$item->id); - echo " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - - } else { - echo " = présent."; - } - } - - } - echo PHP_EOL; - } - $nbActes++; - } - } - } - } - } - - - } - echo "Nombre de fichier : ".$nbActes.PHP_EOL; - - } else { - - //Lire la base de données - $acteM = new Application_Model_JoGreffesActes(); - $sql = $acteM->select() - ->from($actesM, array( - 'siren', - 'numRC', - 'LPAD(numGreffe,4,0) AS numGreffe', - 'pdfLink', - 'pdfSize', - 'pdfPage', - 'num_depot', - 'date_depot', - 'date_acte', - 'LPAD(num_acte,2,0) AS num_acte', - 'type_acte', - 'type_acte_libelle', - 'nbpages_acte', - 'decision_nature', - 'decision_libelle', - 'mode_diffusion' - )) - ->order('date_depot ASC'); - if ( $opts->siren ) { - $sql->where('siren=?',$opts->siren); - } else { - $sql->where('pdfLink=?',''); - } - - $result = $acteM->fetchAll($sql); - - if ( $result->count() > 0 ) { - $cpt = 1; - foreach ( $result as $item ) { - - $date = $item->date_acte; - $num = $item->num_acte; - $type = $item->type_acte; - - $infogreffe = new Metier_Infogreffe_DocAC(); - $infogreffe->setSiren($siren); - - $options = $item->numGreffe . '-' . substr($item->numRC,0,2) . '-' . substr($item->numRC,2,1) . '-' . substr($item->numRC,3) . '-' . $item->num_depot; - $file = $infogreffe->getFileName($date, $num, $type, $options); - $path = $c->profil->path->shared . '/datafile/' . $infogreffe->getFilePath($date) . '/' . $file; - - if ( file_exists($filepath) ) { - //Analyser le fichier - Nombre de page et taille - $infos = $infogreffe->pdfInfos($filepath); - - //Enregistrer les infos du fichier dans la base de données - if (false !== $infos) { - $infogreffe->dbSetFile($file, $infos['size'], $infos['pages'], $infos['version']); - } - } - - } - } else { - echo "Aucun enregistrement !\n"; - } - } -} \ No newline at end of file diff --git a/scripts/jobs/getGreffe.php b/scripts/jobs/getGreffe.php deleted file mode 100644 index 1cebe695..00000000 --- a/scripts/jobs/getGreffe.php +++ /dev/null @@ -1,580 +0,0 @@ - "Affiche l'aide.", - 'list' => "Liste les actes en attente disponible sur le FTP et affiche les informations", - 'get-s' => "Recupère seulement les actes du FTP (un seul document si la référence est spécifier G
'; print_r($e); echo ''; - } else { - echo "Le service rencontre actuellement un problème technique."; - } - exit; -} -Zend_Registry::set('doctrine', $conn); - -$testMail = false; - -$test = false; -if (isset($opts->list)){ - $test = true; -} - -$types = array('bi', 'ac'); - -//Configuration FTP -define ('ACTES_IGNUM_FTP_URL', '192.168.3.202'); -define ('ACTES_IGNUM_FTP_USER', 'mpc2500'); -define ('ACTES_IGNUM_FTP_PASS', 'passmpc78'); -define ('ACTES_IGNUM_LOCAL_DIR', $c->profil->path->shared.'/files/'); - -define ('PATH_DATA', $c->profil->infogreffe->storage->path); - -$report_email = $c->profil->mail->email->support; -$report_subject = 'Traitement des actes '.date('Y-m-d H:i:s'); -$report_txt = ''; - -function sendMail($commande, $type){ - $subject = "Actes ou Statuts disponible pour ".$commande->raisonSociale.' ('.$commande->siren.')'; - $message = "Bonjour,\n\n"; - $message.= "Le document commandé pour ".$commande->raisonSociale." (siren ".$commande->siren.") est disponible en téléchargement sur le site de Scores & Décisions.\r\n\r\n"; - if ($commande->refClient!='') { - $message = "Votre référence : ".$commande->refClient."\r\n\r\n"; - } - switch ( $type ) { - case 'BI': - $dateBilan = substr($commande->bilanCloture,8,2).'/'.substr($commande->bilanCloture,5,2).'/'.substr($commande->bilanCloture,0,4); - $message.= "Bilan cloturé le ".$dateBilan; - break; - case 'AC': - $dateActe = substr($commande->acteDate,8,2).'/'.substr($commande->acteDate,5,2).'/'.substr($commande->acteDate,0,4); - $dateDepot = substr($commande->depotDate,8,2).'/'.substr($commande->depotDate,5,2).'/'.substr($commande->depotDate,0,4); - $message.= "Acte n°".$commande->acteNum." du ".$dateActe." (Dépot n°".$commande->depotNum." du ".$dateDepot.") "; - break; - } - $message.= "\n\n"; - - $message.= "Consulter la fiche identité http://extranet.scores-decisions.com/identite/fiche/siret/".$commande->siren.", puis rubrique \"Pieces Officielles\"\n"; - - $message.= "ou directement depuis la page suivante http://extranet.scores-decisions.com/pieces"; - switch ( $type ) { - case 'BI': - $message.= "/bilans/siret/".$commande->siren; - break; - case 'AC': - $message.= "/actes/siret/".$commande->siren; - break; - } - $message.= "\n\n"; - - $message.= "Bien cordialement, \n"; - $message.= "Le service support.\n"; - $message.= "\n"; - - $message.= "--"; - - $message.= "\n\n"; - - $message.= "SCORES & DECISIONS"; - $message.= "\n"; - $message.= "Service support"; - $message.= "\n"; - $message.= "1, rue de Clairefontaine - 78120 RAMBOUILLET"; - $message.= "\n"; - $message.= "tél : 0 811 261 216"; - $message.= "\n"; - $message.= "fax : 33 (0)1 75 43 85 74"; - $message.= "\n"; - $message.= "support@scores-decisions.com"; - $message.= "\n"; - $message.= "http://www.scores-decisions.com/"; - $message.= "\n"; - $message.= "Scores & Décisions est l'acteur nouvelle génération de l'information et de l'évaluation des entreprises"; - - $message.= "\n\n"; - - $message.= "Pensez à l'environnement avant d'imprimer ce message !"; - $message.= "\n"; - $message.= "Save paper - think before you print"; - $message.= "\n"; - - $headers = 'From: infoslegales@scores-decisions.com' . "\r\n" . - 'Reply-To: infoslegales@scores-decisions.com'; - - if ( mail(strtolower($commande->email), $subject, utf8_decode($message), $headers) ){ - echo date ('Y/m/d - H:i:s').' - Un email a été envoyé à '.$commande->email." pour la commande ".$commande->id.".\n"; - return true; - } else { - echo date ('Y/m/d - H:i:s').' - ERREUR : Impossible d\'envoyer l\'email à '.$commande->email." pour la commande ".$commande->id.".\n"; - return false; - } -} - -/** - * Connexion à la base de données - */ -$db = Zend_Db::factory($c->profil->db->metier); -Zend_Db_Table_Abstract::setDefaultAdapter($db); - -/** - * List actes files and check if an entry exist in the database - * greffes/actes/AAAA/MM - * preg_match('/^acte-([0-9]{9})-(ST)-([0-9]{8})-.*\.pdf/', $fichier, $matches) - * preg_match('/^acte-([0-9]{9})-([0-9a-zA-Z]{1,})-([0-9]{8})-.*-([0-9]{2})\.pdf/', $fichier, $matches) - */ -if ($opts->control) { - - $dir = PATH_DATA.'/greffes/actes'; - if (is_dir($dir)) { - if ($dh = opendir($dir)) { - //Annee - while (($anneeDir = readdir($dh)) !== false) { - if ($anneeDir != '.' || $anneeDir != '..') { - echo "Dir ".$dir . DIRECTORY_SEPARATOR . $anneeDir."\n"; - if ($dhAnneeDir = opendir($dir . DIRECTORY_SEPARATOR . $anneeDir)) { - //Mois - while (($moisDir = readdir($dhAnneeDir)) !== false) { - echo "Dir ".$dir . DIRECTORY_SEPARATOR . $anneeDir . DIRECTORY_SEPARATOR . $moisDir."\n"; - if ($moisDir != '.' || $moisDir != '..') { - //Fichier - if ($dhFile = opendir($dir . DIRECTORY_SEPARATOR . $anneeDir . DIRECTORY_SEPARATOR . $moisDir)) { - while (($file = readdir($dhFile)) !== false) { - if ($file != '.' || $file != '..') { - - if (preg_match('/^acte-([0-9]{9})-([0-9a-zA-Z]{1,})-([0-9]{8})-.*-([0-9]{2})\.pdf/', $file, $matches)) { - $siren = $matches[1]; - $type = $matches[2]; - $date = $matches[3]; - $num = $matches[4]; - $actesM = new Application_Model_ActesFiles(); - $sql = $actesM->select() - ->where('siren=?', $siren) - ->where('type=?', $type) - ->where('date=?', $date) - ->where('num=?', $num); - $result = $actesM->fetchRow($sql); - if ( null === $result ) { - echo "Insert $file\n"; - $actesM->insert(array( - 'siren' => $siren, - 'type' => $type, - 'date' => $date, - 'num' => $num, - 'file' => $file, - )); - } - } - - } - } - closedir($dhFile); - } - } - } - closedir($dhAnneeDir); - } - } - } - closedir($dh); - } - } - exit; -} - -/** - * Liste des commandes non traités depuis la base de données - */ -$acM = new Application_Model_Sdv1GreffeCommandesAc(); -$biM = new Application_Model_Sdv1GreffeCommandesBi(); -$tabCommandes = array(); -if (in_array('ac', $types)) { - $sql = $acM->select() - ->where('mode=?','C') - ->where('dateCommande!=?', '0000-00-00 00:00:00') - ->where('dateEnvoi=?', '0000-00-00 00:00:00'); - $rows = $acM->fetchAll($sql); - if (count($rows)>0) { - foreach ($rows as $row) { - $tabCommandes['G-AC-'.$row->id] = $row; - } - } -} -if (in_array('bi', $types)) { - $sql = $biM->select() - ->where('mode=?','C') - ->where('dateCommande!=?', '0000-00-00 00:00:00') - ->where('dateEnvoi=?', '0000-00-00 00:00:00'); - $rows = $biM->fetchAll($sql); - if (count($rows)>0) { - foreach ($rows as $row) { - $tabCommandes['G-BI-'.$row->id] = $row; - } - } -} -$nbCommandes = count($tabCommandes); -echo date('Y/m/d - H:i:s') ." - Il y a $nbCommandes commandes en attente de réception courrier ou numérisation !\n"; - -/** - * Connexion au site FTP pour la récupération de la liste des fichiers au format pdf - */ -$conn_id = ftp_connect(ACTES_IGNUM_FTP_URL); -if (!$conn_id) { - echo date ('Y/m/d - H:i:s')." - ERREUR : Impossible de se connecter au serveur FTP (".ACTES_IGNUM_FTP_URL.") !\n"; - exit; -} -$login_result = ftp_login($conn_id, ACTES_IGNUM_FTP_USER, ACTES_IGNUM_FTP_PASS); -if (!$login_result) { - echo date ('Y/m/d - H:i:s')." - ERREUR : Impossible de s'authentifier sur le serveur FTP (".ACTES_IGNUM_FTP_URL.")!\n"; - exit; -} -$contents = ftp_nlist($conn_id, "*.pdf"); - -/** - * Liste de tout les fichiers disponible dans le repertoire - * et associe une clé pour faciliter le tri - */ -$tabFichiersFtp = array(); -foreach ($contents as $filename){ - $indice = 0; - $f = strtolower($filename); - if (preg_match('/g-(ac|bi)-[0-9]+\.pdf/', $f) - || preg_match('/g-(ac|bi)-[0-9]+-[0-9]{1,2}\.pdf/', $f)){ - - $part = substr(str_replace('.pdf', '', $f), 5); - $p = strpos($part, '-'); - if ( $p === false ) { - $ref = substr($f, 0, 5) . $part; - $indice = 0; - } else { - $ref = substr($f, 0, 5) . substr($part, 0, $p); - $indice = substr($part, $p+1); - } - $tabFichiersFtp[strtoupper($ref).'-'.$indice] = $filename; - - // Fichiers en anomalies - } else { - if ($test){ - echo "Erreur : Anomalie fichier numérisé $filename\n"; - } else { - $subject = "Erreur : Anomalie fichier numérisé"; - $message = "Le fichier $filename a été trouvé et ne correspond pas au format attendu"; - $headers = 'From: supportdev@scores-decisions.com' . "\r\n" . - 'Reply-To: supportdev@scores-decisions.com'; - mail('supportdev@scores-decisions.com', $subject, $message, $headers); - } - } -} - -/** - * Tri des fichiers par ordre décroissant - * Les noms des fichiers sont incrémenté par 1 - */ -krsort($tabFichiersFtp); - -/** - * Dans le cas ou il y a eu une erreur de scan, la production passe a nouveau le - * document dans le scanner et le fichier est envoyé sur le ftp - * Le document est nommé G[ref],G[ref]-1,G[ref]-2,.....pdf. - * On garde donc le dernier document scanné. - */ -$lastRef = ''; -$tabFichiersTemp = array(); -foreach($tabFichiersFtp as $k => $val) -{ - - $part = substr($k, 5); - $p = strpos($part, '-'); - if ( $p === false ) { - $ref = substr($k, 0, 5) . $part; - } else { - $ref = substr($k, 0, 5) . substr($part, 0, $p); - } - - if( $lastRef != $ref ) { - $tabFichiersTemp[$ref] = $val; - } - $lastRef = $ref; - -} -$tabFichiers = $tabFichiersTemp; -unset($tabFichiersTemp); - -/** - * Pour chaque commande, test de la présence d'un fichier associé - * Si le fichier correspond téléchargement du fichier - */ -foreach ( $tabCommandes as $ref => $commande ) { - foreach ( $tabFichiers as $refAssocie => $fichier ) { - - if ( $ref == $refAssocie ) { - - echo date ('Y/m/d - H:i:s')." - Traitement de la commande $ref\n"; - - if ( $test ) { - - echo date ('Y/m/d - H:i:s')." - Fichier $fichier \n"; - - } else { - - // Récupération du fichier depuis le FTP (s'il n'existe pas déjà) - if ( !file_exists(ACTES_IGNUM_LOCAL_DIR.$fichier) ) { - if (ftp_get($conn_id, ACTES_IGNUM_LOCAL_DIR.$fichier, $fichier, FTP_BINARY, 0)) { - echo date ('Y/m/d - H:i:s')." - Fichier $fichier téléchargé depuis le serveur FTP.\n"; - } else { - echo date ('Y/m/d - H:i:s')." - ERREUR : Impossible de télécharger le fichier $fichier !\n"; - } - } - - switch ( substr($ref,2,2) ) { - - case 'BI': - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($commande->siren); - //Format date cloture - $dateCloture = substr($commande->bilanCloture,0,4) . '-' . - substr($commande->bilanCloture,5,2) . '-' . - substr($commande->bilanCloture,8,2); - $path = $infogreffe->getFilePath($commande->bilanType, $dateCloture); - $nomCible = $infogreffe->getFileName($commande->bilanType, $dateCloture); - - $fileOut = PATH_DATA.'/'.$path.'/'.$nomCible; - - $isFileOnStorage = false; - - if ( file_exists($fileOut) ) { - $isFileOnStorage = true; - echo date ('Y/m/d - H:i:s')." - Fichier ".ACTES_IGNUM_LOCAL_DIR.$fichier." déjà présent en ".$fileOut.".\n"; - } else { - if ( copy(ACTES_IGNUM_LOCAL_DIR.$fichier, $fileOut) ) { - $isFileOnStorage = true; - echo date ('Y/m/d - H:i:s')." - Fichier ".ACTES_IGNUM_LOCAL_DIR.$fichier." déplacé en ".$fileOut.".\n"; - } else { - echo date ('Y/m/d - H:i:s')." ERREUR - Impossible de déplacer ".ACTES_IGNUM_LOCAL_DIR.$fichier." en ".$fileOut." !\n"; - } - } - - // --- Lecture présence référence bilan - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->where('siren=?',$commande->siren) - ->where('date_cloture=?', $dateCloture); - if ($commande->bilanType=='sociaux') { - $sql->where('type_comptes="" OR type_comptes="sociaux"'); - } else { - $sql->where('type_comptes="consolides"'); - } - $item = $bilanM->fetchRow($sql); - - // --- Enregistrement - if ( $isFileOnStorage && $item->pdfDate == '0000-00-00' ) { - $infos = $infogreffe->pdfInfos($fileOut); - if (false !== $infos) { - $data = array( - 'pdfLink' => $nomCible, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $bilanM->update($data, 'id='.$item->id); - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - } - break; - - case 'AC': - - $acteM = new Application_Model_JoGreffesActes(); - $sql = $acteM->select() - ->from($acteM, array( - 'id', - 'siren', - 'numRC', - 'LPAD(numGreffe,4,0) AS numGreffe', - 'pdfLink', - 'pdfSize', - 'pdfPage', - 'pdfDate', - 'num_depot', - 'date_depot', - 'date_acte', - 'LPAD(num_acte,2,0) AS num_acte', - 'type_acte', - 'type_acte_libelle', - 'nbpages_acte', - 'decision_nature', - 'decision_libelle', - 'mode_diffusion' - )) - ->where('siren=?', $commande->siren) - ->where('num_depot=?', $commande->depotNum) - ->where('num_acte=?', $commande->acteNum) - ->where('type_acte=?',$commande->acteType); - $item = $acteM->fetchRow($sql); - - $infogreffe = new Metier_Infogreffe_DocAC(); - $infogreffe->setSiren($commande->siren); - $date = $commande->acteDate; - if ( $date == '0000-00-00' ) { - $date = $commande->depotDate; - } - - $path = $infogreffe->getFilePath($date); - //(Numéro du Greffe)-(dossier_millesime)-(dossier_statut)-(dossier_chrono)-(num_depot) - $options = $item->numGreffe . '-' . substr($item->numRC,0,2) . '-' . substr($item->numRC,2,1) . '-' . substr($item->numRC,3) . '-' . $item->num_depot; - $nomCible = $infogreffe->getFileName($date, $commande->acteNum, $commande->acteType, $options); - - $fileOut = PATH_DATA.'/'.$path.'/'.$nomCible; - - $isFileOnStorage = false; - - if ( file_exists($fileOut) ) { - $isFileOnStorage = true; - echo date ('Y/m/d - H:i:s')." - Fichier ".ACTES_IGNUM_LOCAL_DIR.$fichier." déjà présent en ".$fileOut.".\n"; - } else { - if ( copy(ACTES_IGNUM_LOCAL_DIR.$fichier, $fileOut) ) { - $isFileOnStorage = true; - echo date ('Y/m/d - H:i:s')." - Fichier ".ACTES_IGNUM_LOCAL_DIR.$fichier." déplacé en ".$fileOut.".\n"; - } else { - echo date ('Y/m/d - H:i:s')." ERREUR - Impossible de déplacer ".ACTES_IGNUM_LOCAL_DIR.$fichier." en ".$fileOut." !\n"; - } - } - - if ( $isFileOnStorage && $item->pdfDate == '0000-00-00' ) { - $infos = $infogreffe->pdfInfos($fileOut); - if ( false !== $infos ) { - $data = array( - 'pdfLink' => $nomCible, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $acteM->update($data, 'id='.$item->id); - echo " = enregistrement.\n"; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - } - - break; - } - - //Envoi du mail et Mise à jour de la commande - if ( file_exists($fileOut) ) { - if ( $testMail ) { - echo "Envoi fichier $nomCible ($ref) à ".$commande->email; - } else { - $report_txt.= "$ref intégré à l'extranet"; - $isMailSent = false; - if (trim($commande->email)!=''){ - $isMailSent = sendMail($commande, substr($ref,2,2)); - } else { - $isMailSent = true; - } - if ( $isMailSent ) { - $data = array( 'dateEnvoi' => date('YmdHis')); - switch ( substr($ref,2,2) ) { - case 'BI': - $commandesM = new Application_Model_Sdv1GreffeCommandesBi(); - break; - case 'AC': - $commandesM = new Application_Model_Sdv1GreffeCommandesAc(); - break; - } - $commandesM->update($data, 'id='.$commande->id); - echo date ('Y/m/d - H:i:s')." - Commande $ref mise à jour\n"; - $report_txt.= ' - Email envoyé à '.$commande->email; - } else { - $report_txt.= ' - Email non envoyé !'; - echo date ('Y/m/d - H:i:s')." ERREUR - Email non envoyé et commande $ref non mise à jour\n"; - } - $report_txt.= "\n"; - } - } // Fin envoi mail - } - } // Fin condition ref - } -} -ftp_close($conn_id); - -if (empty($report_txt)) { - $report_txt = "Aucun envoi."; -} - -//Envoi du mail de rapport -if (!$test && !$testMail){ - if (mail($report_email, $report_subject, utf8_decode($report_txt))){ - echo date ('Y/m/d - H:i:s')." - Rapport envoyé.\n"; - } else { - echo date ('Y/m/d - H:i:s')." - Erreur lors de l'envoir du rapport !\n"; - } -} - -?> \ No newline at end of file diff --git a/scripts/jobs/getKbis.php b/scripts/jobs/getKbis.php deleted file mode 100644 index 9f639fb4..00000000 --- a/scripts/jobs/getKbis.php +++ /dev/null @@ -1,613 +0,0 @@ -#!/usr/bin/php - "Affiche l'aide.", - 'siren=s' => "Commander un kbis", - 'commandes' => "Liste les commandes passees (Reference), si reference alors recupere le kbis", - 'visu=s' => "Telechargement du kbis avec une reference (--commandes obligatoire)", - 'debug' => "Mode debug", - ) - ); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "Telecharge le kbis chez infogreffe."; - echo "\n\n"; - echo $opts->getUsageMessage(); - echo "\n"; - exit; -} - -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -if ( isset($opts->debug) ) { - define('DEBUG', true); -} else { - define('DEBUG', false); -} - -function getPageHeader($start,$end,$header) -{ - $pattern = '/'. $start .'(.*)'. $end .'/'; - if (preg_match($pattern, $header, $result)) { - return $result[1]; - } else { - return false; - } -} - -function getPage($url, $curl_data = '', $override = null) -{ - global $ckfile; - - //$user_agent = 'Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1'; - //$user_agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'; - $user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)'; - - $verbose = false; - $post = false; - $fields = ''; - if (is_array($curl_data) && count($curl_data)>0) { - foreach($curl_data as $key=>$value) { - $fields .= $key.'='.$value.'&'; - } - rtrim($fields,'&'); - $post = true; - } - - $options = array( - CURLOPT_RETURNTRANSFER => true, // return web page - CURLOPT_HEADER => false, // don't return headers - CURLOPT_FOLLOWLOCATION => false, // follow redirects - CURLOPT_ENCODING => "", // handle all encodings - CURLOPT_USERAGENT => $user_agent, // who am i - CURLOPT_AUTOREFERER => true, // set referer on redirect - CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect - CURLOPT_TIMEOUT => 120, // timeout on response - CURLOPT_MAXREDIRS => 10, // stop after 10 redirects - CURLOPT_POST => $post, // i am sending post data - CURLOPT_POSTFIELDS => $fields, // this are my post vars - CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl - CURLOPT_SSL_VERIFYPEER => false, // - CURLOPT_VERBOSE => $verbose , // - //CURLOPT_COOKIESESSION => true, - CURLOPT_COOKIEFILE => $ckfile, - CURLOPT_COOKIEJAR => $ckfile, // Stockage du cookie de session - ); - - //Override define CURL option - if (is_array($override) && count($override)>0 ) { - $options = $override + $options; - } - - $ch = curl_init($url); - curl_setopt_array($ch,$options); - $content = curl_exec($ch); - $err = curl_errno($ch); - $errmsg = curl_error($ch) ; - $header = curl_getinfo($ch); - curl_close($ch); - - //Rewrite encoding to UTF-8 - //text/html; charset=ISO-8859-1 - //$encoding = getPageHeader('text\/html; charset=', '', $header['content_type']); - //$encoding = 'ISO-8859-1'; - //$content = iconv($encoding, 'UTF-8//TRANSLIT', $content); - - // $header['errno'] = $err; - // $header['errmsg'] = $errmsg; - // $header['content'] = $content; - return array('header'=>$header, 'content'=>$content); -} - - -/** - * Retourne l'url après une page 302 - * @param string $content - * @return string|boolean - */ -function getUrl302($content) -{ - $url = false; - preg_match('/\