Fichier télétransmission
This commit is contained in:
parent
ee1e16fc2f
commit
f5a8d55d0f
@ -1480,144 +1480,100 @@ class Interne extends Scores_Ws_Server
|
||||
$this->authenticate();
|
||||
$c = Zend_Registry::get('config');
|
||||
$path = "/mnt/clients/oldcrm";
|
||||
|
||||
if (empty($ref)) $ref = '*';
|
||||
if (empty($nomFic)) $nomFic = '';
|
||||
$error = new ErrorType();
|
||||
$tabFichier=$tabDates=array();
|
||||
$numAbo=substr($ref, 0,5);
|
||||
$tabFichier = $tabDates = array();
|
||||
$numAbo = substr($ref, 0,5);
|
||||
if (strtolower($login)=='vwbank') {
|
||||
$ficClient='surveillanceBodacc_SURBODPRDCFTVWBANK';
|
||||
$numAbo=$ref='19300';
|
||||
$numAbo = $ref = '19300';
|
||||
} elseif (substr($login,0,6)=='apicil') {
|
||||
$ficClient='surveillanceBodacc_SURBODPRDCFTAPICIL';
|
||||
$numAbo=$ref='';
|
||||
$numAbo = $ref = '';
|
||||
} elseif (strtolower($login)=='omni04') {
|
||||
$ficClient='surveillanceBodacc_SURBODPRDFTSOMNIREP';
|
||||
$numAbo=$ref='';
|
||||
} elseif (strtolower($login)=='bodacca3m') {
|
||||
$numAbo = $ref = '';
|
||||
} elseif (strtolower($login)=='bodacca3m' /*|| strtolower($login)=='mricois'*/) {
|
||||
$ficClient='surveillanceBodacc_SURBODPRDFTSMEDERIC';
|
||||
$numAbo=$ref='';
|
||||
$numAbo = $ref = '';
|
||||
} elseif (strtolower($login)=='bodaccomni') {
|
||||
$ficClient='surveillanceBodacc_SURBODPRDFTSOMNIREP';
|
||||
$numAbo=$ref='';
|
||||
$numAbo = $ref = '';
|
||||
} elseif (strtolower($login)=='bodacccrr') {
|
||||
$ficClient='surveillanceBodacc_SURBODPRDFTSCRR';
|
||||
$numAbo=$ref='';
|
||||
} elseif (strtolower($login)=='cpcambr13' || strtolower($login)=='cpcambr14') {
|
||||
$numAbo = $ref = '';
|
||||
} elseif (strtolower($login)=='cpcambr13' || strtolower($login)=='cpcambr14' /*|| strtolower($login)=='mricois'*/) {
|
||||
$ficClient='diffusionBodacc_DIFBODPRDMAICPCAM13';
|
||||
$numAbo=$ref='';
|
||||
$numAbo = $ref = '';
|
||||
} elseif (strtolower($login)=='frbsurveillance'){
|
||||
$ficClient='surveillanceBodacc_SURBODPRDFTPFBOISSON';
|
||||
$numAbo = $ref = '';
|
||||
} else {
|
||||
$ficClient='surveillanceBodacc_SURBODTSTFTSCNASEA';
|
||||
$numAbo = $ref = '';
|
||||
}
|
||||
|
||||
// --- Lecture du repertoire
|
||||
$dh = opendir($path."/");
|
||||
if (!$dh) {
|
||||
$error->errnum = 1;
|
||||
$error->errmsg = "Impossible d'ouvrir le dossier client";
|
||||
// --- Livraison fichier
|
||||
if ($nomFic!='') {
|
||||
$directory = $c->profil->path->files;
|
||||
$ficLength = strlen($ficClient . $numAbo);
|
||||
if (file_exists($path.'/'.$nomFic) && substr($nomFic, 0, $ficLength) == $ficClient . $numAbo) {
|
||||
if (!file_exists($directory."/$nomFic.bz2") || filesize($directory."/$nomFic.bz2") <= 14) {
|
||||
$string = file_get_contents($path."/$nomFic");
|
||||
$bz = bzopen($directory."/$nomFic.bz2",'w');
|
||||
if ($bz) {
|
||||
bzwrite($bz, $string, strlen($string));
|
||||
bzclose($bz);
|
||||
}
|
||||
}
|
||||
$tabFichier[] = $nomFic;
|
||||
} else {
|
||||
$error->errnum = 1;
|
||||
$error->errmsg = "Impossible d'ouvrir le fichier client";
|
||||
}
|
||||
} else {
|
||||
while (false !== ($filename = readdir($dh))) {
|
||||
if($filename=='.' && $filename=='..')
|
||||
continue;
|
||||
if (substr($filename, -4)=='.csv' && substr($filename,0,42)==$ficClient.$numAbo) {
|
||||
$tabFichier[] = $filename;
|
||||
$tabDates[]=substr($filename,43,8);
|
||||
$tabClients[]=substr($filename,0,42);
|
||||
}
|
||||
elseif ($ref=='*' && substr($filename, -4)=='.csv' && substr($filename,0,37)==$ficClient && substr($filename,37,1)<>'_') {
|
||||
$tabFichier[] = $filename;
|
||||
$tabDates[]=substr($filename,43,8);
|
||||
$tabClients[]=substr($filename,0,42);
|
||||
}
|
||||
elseif (substr($filename, -4)=='.csv' && substr($filename,0,37)==$ficClient && substr($filename,37,1)=='_') {
|
||||
$tabFichier[] = $filename;
|
||||
$tabDates[]=substr($filename,38,8);
|
||||
$tabClients[]=substr($filename,0,37);
|
||||
}
|
||||
elseif (substr($filename, -4)=='.csv' && substr($filename,0,38)==$ficClient && substr($filename,38,1)=='_') {
|
||||
$tabFichier[] = $filename;
|
||||
$tabDates[]=substr($filename,39,8);
|
||||
$tabClients[]=substr($filename,0,38);
|
||||
}
|
||||
}
|
||||
/** Tableau des noms de fichier **/
|
||||
sort($tabFichier);
|
||||
/** Tableau des dates de livraisons **/
|
||||
$tabDates=array_unique($tabDates);
|
||||
sort($tabDates);
|
||||
/** Tableau des Clients **/
|
||||
$tabClients=array_unique($tabClients);
|
||||
sort($tabClients);
|
||||
// --- Lecture du repertoire
|
||||
$dh = opendir($path."/");
|
||||
if ($dh) {
|
||||
while (false !== ($filename = readdir($dh))) {
|
||||
if ($filename == '.' && $filename =='..') continue;
|
||||
if (substr($filename, -4) != '.csv') continue;
|
||||
$ficLength = strlen($ficClient . $numAbo);
|
||||
if (substr($filename, 0, $ficLength) == $ficClient . $numAbo) {
|
||||
$tabFichier[] = $filename;
|
||||
$tabDates[] = substr($filename, $ficLength + 1, 8);
|
||||
$tabClients[] = substr($filename, 0, $ficLength);
|
||||
}
|
||||
}
|
||||
|
||||
if ($ref=='*') {
|
||||
$tabFichier = array();
|
||||
// Boucle sur les dates de livraison
|
||||
foreach ($tabDates as $dateFic) {
|
||||
if (strlen($dateFic)<>8) continue;
|
||||
if (!file_exists($path."/$ficClient".'_'."$dateFic.csv")
|
||||
|| filesize($path."/$ficClient".'_'."$dateFic.csv")==0) {
|
||||
// Tableau des noms de fichier
|
||||
sort($tabFichier);
|
||||
// Tableau des dates de livraisons
|
||||
$tabDates = array_unique($tabDates);
|
||||
sort($tabDates);
|
||||
// Tableau des Clients
|
||||
$tabClients = array_unique($tabClients);
|
||||
sort($tabClients);
|
||||
rsort($tabFichier);
|
||||
} else {
|
||||
$error->errnum = 1;
|
||||
$error->errmsg = "Impossible d'ouvrir le dossier client";
|
||||
}
|
||||
}
|
||||
|
||||
$fpW=fopen($path."/$ficClient".'_'."$dateFic.csv",'w');
|
||||
$entete=true;
|
||||
// Boucle afin de vérifier si on est sur le bon client
|
||||
foreach ($tabClients as $nomClient) {
|
||||
$dh = opendir($path."/");
|
||||
while (false !== ($filename = readdir($dh))) {
|
||||
if (substr($filename,0,51)==$nomClient.'_'.$dateFic && substr($filename,-4)=='.csv') {
|
||||
$fichier=$filename;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
$fpR=fopen($path."/".$fichier,'r');
|
||||
//return array('error'=>array('errnum'=>0, 'errmsg'=>''), 'results'=>array(($fichier)));//die;
|
||||
if ($fpR) {
|
||||
while (!feof($fpR)) {
|
||||
$ligne=trim(fgets($fpR));
|
||||
if (substr($ligne,0,5)=='Siren' && $entete==true) {
|
||||
fwrite($fpW, 'SITE;'.$ligne.EOL);
|
||||
$entete=false;
|
||||
}
|
||||
elseif (substr($ligne,0,5)<>'Siren' && trim($ligne)<>'') {
|
||||
fwrite($fpW, strtr($nomClient, array(
|
||||
'surveillanceBodacc_SURBODTSTFTS'=>'',
|
||||
'surveillanceBodacc_SURBODPRDCFT'=>'')).';'.$ligne.EOL);
|
||||
}
|
||||
}
|
||||
fclose($fpR);
|
||||
}
|
||||
}
|
||||
fclose($fpW);
|
||||
}
|
||||
if (strlen($dateFic)==8)
|
||||
$tabFichier[]=$ficClient.'_'.$dateFic.'.csv';
|
||||
}
|
||||
}
|
||||
rsort($tabFichier);
|
||||
|
||||
if ($nomFic!='') {
|
||||
$directory = $c->profil->path->files;
|
||||
if (!file_exists($directory."/$nomFic.bz2") || filesize($directory."/$nomFic.bz2")<=14) {
|
||||
$string = file_get_contents($path."/$nomFic");
|
||||
$bz = bzopen($directory."/$nomFic.bz2",'w');
|
||||
if ($bz) {
|
||||
bzwrite($bz, $string, strlen($string));
|
||||
bzclose($bz);
|
||||
}
|
||||
}
|
||||
}
|
||||
debugLog('I',"getListeFichierSurv pour $login, $ref, $nomFic : nb fichiers=".count($tabFichier),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
||||
if ($_SERVER['SERVER_PORT']!='80'){
|
||||
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
||||
}
|
||||
$result = array();
|
||||
foreach($tabFichier as $fichier){
|
||||
$retFichier = new ListeFichierSurv();
|
||||
$retFichier->UrlFichier = $hostname.'/fichier/crm/'.$fichier;
|
||||
$result[] = $retFichier;
|
||||
}
|
||||
$result = array();
|
||||
if (count($tabFichier) > 0) {
|
||||
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
||||
if ($_SERVER['SERVER_PORT'] != '80'){
|
||||
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
||||
}
|
||||
foreach($tabFichier as $fichier) {
|
||||
$retFichier = new ListeFichierSurv();
|
||||
$retFichier->UrlFichier = $hostname.'/fichier/crm/'.$fichier;
|
||||
$result[] = $retFichier;
|
||||
}
|
||||
}
|
||||
$output = new ListeFichierSurvReturn();
|
||||
$output->error = $error;
|
||||
|
Loading…
Reference in New Issue
Block a user