Nettoyage
This commit is contained in:
parent
9fc9b4a1f5
commit
d1abec4736
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
class Application_Model_Aide extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'aide';
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
* @param array $keys
|
||||
*/
|
||||
public function texte($methode, $keys)
|
||||
{
|
||||
$sql = $this->select()
|
||||
->where('methode = ?', $methode)
|
||||
->where('champ IN ?', $keys);
|
||||
return $this->fetchAll($sql);
|
||||
}
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
class Application_Model_BilanSaisie extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'bilansaisie';
|
||||
|
||||
/**
|
||||
* Enregistre les informations nécessaire pour la saisie
|
||||
* @param unknown_type $email
|
||||
* @param unknown_type $method
|
||||
* @param unknown_type $confidentiel
|
||||
* @param unknown_type $siren
|
||||
* @param unknown_type $bilanCloture
|
||||
* @param unknown_type $format
|
||||
* @param unknown_type $bilanDuree
|
||||
*/
|
||||
public function setInformations($cliendId, $utilisateurId, $utilisateurLogin, $email, $method, $confidentiel, $siren, $bilanCloture, $format, $bilanDuree)
|
||||
{
|
||||
$env = 'PRD';
|
||||
$data = array(
|
||||
'clientId' => $cliendId,
|
||||
'utilisateurId' => $utilisateurId,
|
||||
'utilisateurLogin' => $utilisateurLogin,
|
||||
'utilisateurEmail' => $email,
|
||||
'method' => $method,
|
||||
'confidentiel' => $confidentiel,
|
||||
'siren' => $siren,
|
||||
'env' => $env,
|
||||
'fichier' => '',
|
||||
'bilanCloture' => $bilanCloture,
|
||||
'format' => $format,
|
||||
'bilanDuree' => $bilanDuree,
|
||||
'dateInsert' => date('Y-m-d H:i:s'),
|
||||
);
|
||||
return $this->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les informations
|
||||
* @param string $ref
|
||||
*/
|
||||
public function getInfosBilan($ref)
|
||||
{
|
||||
$sql = $this->select()->where(" ref='$ref'");
|
||||
$result = $this->fetchAll($sql)->toArray();
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistre le nom du fichier
|
||||
* @param string $ref
|
||||
* @param string $name
|
||||
*/
|
||||
public function setFilename($ref, $name)
|
||||
{
|
||||
$data = array( 'fichier' => $name );
|
||||
$this->update($data, "ref='$ref'");
|
||||
}
|
||||
|
||||
public function listBilans()
|
||||
{
|
||||
$sql = $this->select()
|
||||
->from($this, array('ref','utilisateurId','confidentiel','siren','bilanCloture','format','bilanDuree','fichier','env'))
|
||||
->where("dateEnvoi='0000-00-00 00:00:00' AND fichier!=''");
|
||||
$result = $this->fetchAll($sql)->toArray();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setDateEnvoi($ref)
|
||||
{
|
||||
$data = array( 'dateEnvoi' => date('Y-m-d H:m:s') );
|
||||
return $this->update($data, "ref='$ref'");
|
||||
}
|
||||
|
||||
}
|
@ -1,224 +0,0 @@
|
||||
<?php
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
//Use classmap autoloader - useful with opcode and realpath cache
|
||||
require_once 'Zend/Loader/AutoloaderFactory.php';
|
||||
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
||||
Zend_Loader_AutoloaderFactory::factory(array(
|
||||
'Zend_Loader_ClassMapAutoloader' => array(
|
||||
__DIR__ . '/../../library/Zend/autoload_classmap.php',
|
||||
__DIR__ . '/../../library/Application/autoload_classmap.php',
|
||||
__DIR__ . '/../../library/Scores/autoload_classmap.php',
|
||||
__DIR__ . '/../../application/autoload_classmap.php',
|
||||
),
|
||||
'Zend_Loader_StandardAutoloader' => array(
|
||||
'prefixes' => array(
|
||||
'Zend' => __DIR__ . '/../../library/Zend',
|
||||
'Application' => __DIR__ . '/../../library/Application',
|
||||
'Scores' => __DIR__ . '/../../library/Scores',
|
||||
'Metier' => __DIR__ . '/../../library/Metier',
|
||||
),
|
||||
'fallback_autoloader' => true
|
||||
)
|
||||
));
|
||||
|
||||
// Zend_Application - Use it if you don't have autoloaders
|
||||
//require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Affiche l'aide.",
|
||||
'list' => "Liste les bilans à saisir",
|
||||
'send' => "Envoi les fichiers par FTP.",
|
||||
'file=s' => "Specify a file to upload",
|
||||
));
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(count($opts->getOptions())==0 || isset($opts->help))
|
||||
{
|
||||
echo "Envoi les bilans saisie par les clients";
|
||||
echo "\n\n";
|
||||
echo $opts->getUsageMessage();
|
||||
echo "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$test = false;
|
||||
if ( isset($opts->list) ) {
|
||||
$test = true;
|
||||
}
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
Zend_Registry::set('config', $c);
|
||||
|
||||
$report_txt = '';
|
||||
|
||||
define ('PATH_DATA', $c->profil->path->data);
|
||||
|
||||
define('FTP_HOST', 'ftp.scores-decisions.com');
|
||||
define('FTP_USER', 'bilansext');
|
||||
define('FTP_PASS', 'j12azt78');
|
||||
define('FTP_DIR', 'send');
|
||||
|
||||
//==> Functions
|
||||
|
||||
function getRemoteFilename($infos)
|
||||
{
|
||||
Zend_Date::setOptions(array('extend_month' => true));
|
||||
$dateCloture = new Zend_Date($infos['bilanCloture'], 'dd/MM/yyyy');
|
||||
$date = $dateCloture->toString('yyyyMMdd');
|
||||
$file = $infos['siren'].'_'.
|
||||
$infos['format'].$date.'_'.
|
||||
$infos['bilanDuree'].'_'.
|
||||
$infos['confidentiel'].'_'.
|
||||
$infos['utilisateurId'].'_'.$infos['ref'];
|
||||
|
||||
if ($infos['env']=='PRD') {
|
||||
return $file;
|
||||
}
|
||||
return $file.'_'.$infos['env'];
|
||||
}
|
||||
|
||||
function sendToFtp($localFile, $remoteFile)
|
||||
{
|
||||
$conn_id = ftp_connect(FTP_HOST);
|
||||
$login_result = ftp_login($conn_id, FTP_USER, FTP_PASS);
|
||||
ftp_chdir($conn_id, FTP_DIR);
|
||||
if (ftp_put($conn_id, $remoteFile, $localFile, FTP_BINARY)) {
|
||||
return true;
|
||||
}
|
||||
ftp_close($conn_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
//==> Début programme
|
||||
/**
|
||||
* Connexion à la base de données
|
||||
*/
|
||||
$db = Zend_Db::factory($c->profil->db->sdv1);
|
||||
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
||||
|
||||
$tabFichier = array();
|
||||
|
||||
if ( $opts->send ) {
|
||||
|
||||
/**
|
||||
* Liste les fichiers qui peuvent être traités
|
||||
*/
|
||||
$bilans = new Application_Model_BilanSaisie();
|
||||
$listBilans = $bilans->listBilans();
|
||||
foreach ($listBilans as $infos)
|
||||
{
|
||||
$filename = $infos['ref'].'-'.$infos['siren'];
|
||||
$extValide = array('pdf', 'tiff');
|
||||
$fileExist = false;
|
||||
foreach ($extValide as $ext) {
|
||||
if (file_exists(PATH_DATA.'/bilanclient/'.$filename.'.'.$ext)) {
|
||||
$fileExist = true;
|
||||
$tabFichier[] = array(
|
||||
'ref' => $infos['ref'],
|
||||
'localFile' => $filename.'.'.$ext,
|
||||
'remoteFile' => getRemoteFilename($infos).'.'.$ext,
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Erreur fichier inexistant
|
||||
if (!$fileExist) {
|
||||
$txt = "Fichier manquant, Ref:".$infos['ref'];
|
||||
$report_txt.= $txt."\n";
|
||||
echo date('Y-m-d\TH:i:s')." - ".$txt."\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( !empty($opts->file) ) {
|
||||
|
||||
$bilans = new Application_Model_BilanSaisie();
|
||||
$sql = $bilans->select()->where('fichier=?', $opts->file);
|
||||
|
||||
$result = $bilans->fetchRow($sql);
|
||||
if ( $result !== null ) {
|
||||
|
||||
$infos = $result->toArray();
|
||||
$path_parts = pathinfo(PATH_DATA . '/' . $opts->file);
|
||||
$ext = $path_parts['extension'];
|
||||
$filename = $infos['ref'].'-'.$infos['siren'];
|
||||
$tabFichier[] = array(
|
||||
'ref' => $infos['ref'],
|
||||
'localFile' => $filename.'.'.$ext,
|
||||
'remoteFile' => getRemoteFilename($infos).'.'.$ext,
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($test) {
|
||||
print_r($tabFichier);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Envoi sur le FTP
|
||||
*/
|
||||
foreach ($tabFichier as $fichier)
|
||||
{
|
||||
$txt = "Envoi du fichier ".$fichier['localFile']." => ".$fichier['remoteFile']." (".$fichier['ref'].")";
|
||||
$report_txt.= $txt." - ";
|
||||
echo date('Y-m-d\TH:i:s')." - ".$txt." - ";
|
||||
if ( sendToFtp(PATH_DATA.'/bilanclient/'.$fichier['localFile'], $fichier['remoteFile']) ) {
|
||||
$bilans->setDateEnvoi($fichier['ref']);
|
||||
$txt = "Envoi terminé.";
|
||||
$report_txt.= $txt."\n";
|
||||
echo date('Y-m-d\TH:i:s')." - ".$txt."\n";
|
||||
} else {
|
||||
$txt = "Erreur d'envoi !";
|
||||
$report_txt.= $txt."\n";
|
||||
echo date('Y-m-d\TH:i:s')." - ".$txt."\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rapport
|
||||
*/
|
||||
if (empty($report_txt)) {
|
||||
$report_txt = "Aucun bilan client.";
|
||||
}
|
||||
|
||||
$report_email = $c->profil->mail->email->supportdev;
|
||||
$report_subject = 'Traitement Bilan Client '.date('Y-m-d H:i:s');
|
||||
$report_txt.= "\n".__FILE__;
|
||||
|
||||
if (mail($report_email, $report_subject, utf8_decode($report_txt))){
|
||||
echo date('Y-m-d\TH:i:s')." - Rapport envoyé.\n";
|
||||
} else {
|
||||
echo date('Y-m-d\TH:i:s')." - Erreur lors de l'envoi du rapport !\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user