extranet/www/pages/recherchescsv.php

161 lines
5.0 KiB
PHP
Raw Normal View History

2011-11-22 07:55:06 +00:00
<?php
require_once 'export/ExportCSV.php';
if (isset($_SESSION['formR'])) {
$formR = $_SESSION['formR'];
} else {
echo "Erreur : les paramètres de recherche n'ont pas pu être récupérer !";
}
if ($typeRech == 'ent') {
// Type de recherche = entreprises
$telFax = trim(preg_replace('/[^0-9]/', '', $formR['telFax']));
$naf = trim(preg_replace('/[^0-9A-Z]/i', '', $formR['naf']));
//if ($telFax<>'') $typeId='T';
// Traitement des données formulaire
$raisonSociale =
preg_replace('/[^0-9A-Z]/', ' ',
strtoupper(cleanstring($formR['raisonSociale'])));
$numVoie = preg_replace('/[^0-9]/', '', $formR['numVoie']);
if ($numVoie > 9999) {
die('Numéro de voie incorrecte !');
}
$libVoie = preg_replace('/[^0-9A-Z]/', ' ',
strtoupper(cleanstring($formR['voie'])));
$cpVille =
preg_replace('/ +/',' ',
preg_replace('/[^0-9A-Z]/', ' ',
strtoupper(cleanstring($formR['cpVille']))));
if (preg_match("/^([0-9]{2,5})([\D]*)/i", $cpVille, $matches)) {
$cp = trim($matches[1]);
$ville = trim($matches[2]);
} else {
$cp = '';
$ville = trim($cpVille);
}
} else if ($typeRech == 'dir') {
// Type de recherche = dirigeants
$dirNom = preg_replace('/[^0-9A-Z]/', ' ',
strtoupper(trimAccent($formR['dirNom']))
);
$dirPrenom = preg_replace('/[^0-9A-Z]/', ' ',
strtoupper(trimAccent($formR['dirPrenom']))
);
$dirDateNaissJJ = preg_replace('/[^0-9]/', '',
$formR['dirDateNaissJJ'])*1;
if ($dirDateNaissJJ<0 || $dirDateNaissJJ>31)
die('Jour de naissance incorrect !');
$dirDateNaissMM = preg_replace('/[^0-9]/', '',
$formR['dirDateNaissMM'])*1;
if ($dirDateNaissMM<0 || $dirDateNaissMM>12)
die('Mois de naissance incorrect !');
$dirDateNaissAAAA = preg_replace('/[^0-9]/', '',
$formR['dirDateNaissAAAA'])*1;
$year = date('Y')-18;
if ($dirDateNaissAAAA<0 || $dirDateNaissAAAA>$year)
die('Année de naissance incorrecte !');
$dirDateNaiss = $dirDateNaissJJ.'/'.$dirDateNaissMM.'/'.$dirDateNaissAAAA;
$dirCpVille = preg_replace('/ +/',' ', preg_replace('/[^0-9A-Z]/', ' ',
strtoupper($formR['dirCpVille']))
);
if (preg_match('/^([0-9]{2,5})([\D]+)/i', $dirCpVille, $matches))
{
$dirCp = trim($matches[1]);
$dirVille = trim($matches[2]);
}
else {
$dirVille = trim($dirCpVille);
}
} elseif ($typeRech == 'act') {
$actNomRs = trim($formR['actNomRs']);
$pays = $formR['pays'];
$pctMin = preg_replace('/[^0-9]/', '', trim($formR['pctMin']));
$pctMax = preg_replace('/[^0-9]/', '', trim($formR['pctMax']));
$cpVille = preg_replace('/ +/',' ', preg_replace('/[^0-9A-Z]/', ' ',strtoupper(cleanstring($formR['cpVille']))));
}
//Type de recherche = entreprise
if ($typeRech=='ent' && $siret<>'') {
try {
$O = $client->searchSiren($siret, $position, $tabInfo['nbReponses'], 200, $cp);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
}
} elseif ($typeRech=='ent' && $telFax<>'') {
try {
$O = $client->searchTelFax($telFax, $position, $tabInfo['nbReponses'], 200);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
}
} elseif ($typeRech=='ent' && ($typeId=='R' || $typeId=='W' || $typeId=='I') ) {
try {
$O = $client->searchAutreId($typeId, $autreId, $position, $tabInfo['nbReponses'], 200, $cp);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
}
} elseif ($typeRech=='ent' && $siret=='') {
try {
$O = $client->searchNomAdr(
$raisonSociale, $numVoie.' '.$libVoie, $cp, $ville, false, false,
$position, $tabInfo['nbReponses'], 200, false, false,
$naf
);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
}
} elseif ($typeRech=='dir') {
try {
$O = $client->searchDir(
$dirNom, $dirPrenom, $dirDateNaiss, $dirVille,
$position, $tabInfo['nbReponses'], 200, false
);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
}
} elseif ($typeRech=='act') {
try {
$O = $client->searchAct(
$actNomRs, $cpVille, $siret, $pays, $pctMin, $pctMax,
$position, $tabInfo['nbReponses'], 200, false
);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
}
}
$etabs = $O['results']['reponses'];
2011-11-24 11:34:15 +00:00
$file = PATH_DATA . '/../cache/pages/'.$_SESSION['tabInfo']['idClient'].'-'.$_SESSION['tabInfo']['login'].'-'.date('YmdHis').'.csv';
2011-11-22 07:55:06 +00:00
$export = new ExportCSV($etabs, 'rechercheEntreprise');
2011-11-24 11:34:15 +00:00
$export->writeFile($file);
$content_type = 'application/csv-tab-delimited-table';
//Envoi du fichier sur la sortie standard
if ( file_exists($file) ) {
header('Content-Transfer-Encoding: none');
header('Content-type: ' . $content_type.'');
header('Content-Length: ' . filesize($file));
header('Content-MD5: ' . base64_encode(md5_file($file)));
header('Content-Disposition: filename="' . basename($file) . '"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression', '0');
echo file_get_contents($file);
} else {
echo 'Impossible de charger le fichier.';
}