extranet/application/controllers/RechercheController.php

433 lines
14 KiB
PHP
Raw Normal View History

2011-01-06 08:37:20 +00:00
<?php
class RechercheController extends Zend_Controller_Action
{
public function init()
2011-04-11 14:19:14 +00:00
{
2011-04-29 15:47:38 +00:00
/** Pour Giant **/
if(isset($_SESSION['recherche']['giant']))
unset($_SESSION['recherche']['giant']);
require_once 'Scores/RechercheHistorique.php';
2011-04-11 14:19:14 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/styles/recherche.css', 'all');
}
2011-01-06 08:37:20 +00:00
public function indexAction()
{
$this->_forward('entreprise');
}
/**
* Affiche le formulaire de recherche entreprise
*/
2011-01-07 17:16:07 +00:00
public function entrepriseAction()
{
2011-05-19 13:55:35 +00:00
$request = $this->getRequest();
2011-01-07 17:16:07 +00:00
$this->view->headTitle()->append('Recherche Entreprise');
2011-04-11 14:32:37 +00:00
require_once 'Web/Forms/RechercheEntreprise.php';
2011-01-07 17:16:07 +00:00
$form = new Form_RechercheEntreprise();
if ( $request->isPost() || $request->isGet() ){
$form->populate($request->getParams());
}
2011-01-07 17:16:07 +00:00
$this->view->form = $form;
}
2011-02-16 15:47:05 +00:00
/**
* Affiche le formulaire de recherche dirigeants
*/
2011-04-11 15:51:41 +00:00
public function dirigeantAction()
{
2011-04-11 14:19:14 +00:00
$this->view->headTitle()->append('Recherche Dirigeant');
2011-04-13 12:53:09 +00:00
require_once 'Web/Forms/RechercheDirigeant.php';
$form = new Form_RechercheDirigeant();
2011-04-13 12:53:09 +00:00
$this->view->assign('form', $form);
2011-04-11 14:19:14 +00:00
}
/**
* Affiche le formulaire de recherche annonces
* Enter description here ...
*/
2011-04-11 15:51:41 +00:00
public function annonceAction()
{
2011-04-11 14:19:14 +00:00
$this->view->headTitle()->append('Recherche Annonce');
}
2011-02-16 15:47:05 +00:00
public function internationaleAction(){}
2011-04-11 14:19:14 +00:00
public function lastAction()
{
$this->view->headTitle()->append('Liste des dernières recherches');
$session = new Zend_Session_Namespace('Historique');
$this->view->assign('historique', $session->historique['entreprise']);
}
2011-01-06 08:37:20 +00:00
public function listAction()
{
$this->view->headTitle()->append('Liste des dernières recherches');
$rechercheSession = new RechercheHistorique();
$this->view->assign('historique', $rechercheSession->liste());
2011-04-11 14:19:14 +00:00
}
public function enqueteAction()
{
$this->view->headTitle()->append('Enquête');
require_once 'Scores/Utilisateur.php';
2011-05-19 13:55:35 +00:00
require_once 'Web/Forms/RechercheEnquete.php';
2011-04-11 14:19:14 +00:00
$user = new Utilisateur();
if (!$user->checkPerm('INVESTIG')){
2011-04-11 15:51:41 +00:00
$this->renderScript('error/error-perms.phtml');
}
$form = new Form_RechercheEnquete();
2011-05-19 13:55:35 +00:00
$user = new Utilisateur();
2011-04-11 14:19:14 +00:00
2011-05-19 13:55:35 +00:00
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getParams())) {
Zend_Registry::get('firebug')->info($form->getValues());
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'path');
$path = realpath($config->data).'/'.$config->log;
$fp = fopen($path.'/enquetes.csv', 'a');
fwrite($fp, date('Y/m/d H:i:s').' - '.print_r($form->getValues(),true)."\n");
2011-05-19 13:55:35 +00:00
fclose($fp);
$message = "Détail de la demande d'investigation<br/>";
foreach($form->getValues() as $key => $value) {
$message.= ucwords($key)." : ".$value."<br/>";
}
$message.= "<br/>";
$message.= "Identité du demandeur<br/>";
$message.= "Login : ".$user->getLogin()."<br/>";
$message.= "Email : ".$user->getEmail()."<br/>";
$message.= "Nom : ".$user->getNom()."<br/>";
$message.= "Prénom : ".$user->getPrenom()."<br/>";
$objet = "Demande d'investigation";
require_once 'Scores/Mail.php';
$mail = new Mail();
$mail->setFrom('contact');
$mail->addToKey('production');
$mail->setSubject($objet);
$mail->setBodyHtml($message);
$mail->send();
} else {
//Affichage formulaire
$data = array( 'email' => $user->getEmail() );
if ($request->isPost()){
$data = $form->getValues();
}
$form->populate($data);
$this->view->assign('form', $form);
}
2011-04-11 14:19:14 +00:00
}
/**
* Affiche les résultats d'une recherche
*/
2011-04-11 14:19:14 +00:00
public function listeAction()
{
$request = $this->getRequest();
2011-04-11 14:32:37 +00:00
$params = $request->getParams();
$type = $request->getParam('type', '');
$rechercheParams = new RechercheHistorique();
//Si le formulaire a été soumis alors on enregistre en session et on redirige
if ( !empty($type) ) {
$rechercheParams->save($type, $params);
$this->_redirect('recherche/liste');
}
//On selectionne en session
if (count($rechercheParams->liste())>0){
$recherche = $rechercheParams->item(0);
$type = $recherche['type'];
$params = $recherche['params'];
}
2011-04-15 12:40:29 +00:00
//Giant
2011-06-29 14:39:16 +00:00
if( !empty($params['pays']) ){
$this->_forward('search', 'giant');
}
2011-06-30 12:14:14 +00:00
$page = $request->getParam('page', 1);
if ($page==0) $page = 1;
2011-04-11 14:19:14 +00:00
//Criteres recherche entreprise
if ($type=='ent'){
2011-05-09 12:39:39 +00:00
Zend_Registry::get('firebug')->info('RECHERCHE ENTREPRISE');
// Type de recherche = entreprises
2011-05-09 12:39:39 +00:00
$telFax = trim(preg_replace('/[^0-9]/', '', $params['telFax']));
$naf = trim(preg_replace('/[^0-9A-Z]/i', '', $params['naf']));
// Traitement des données formulaire
$raisonSociale = preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['raisonSociale']));
$numVoie = preg_replace('/[^0-9]/', '', $params['numero']);
if ($numVoie > 9999) {
die('Numéro de voie incorrecte !');
}
$libVoie = preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['voie']));
$cpVille = preg_replace('/ +/',' ',
preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['cpVille'])));
2011-05-09 12:39:39 +00:00
if (preg_match("/^([0-9]{2,5})([\D]*)/i", $cpVille, $matches)) {
$cp = trim($matches[1]);
$ville = trim($matches[2]);
} else {
$cp = '';
$ville = trim($cpVille);
}
$criteres = array();
2011-05-09 12:39:39 +00:00
$criteres['identifiant'] = $params['siret'];
$criteres['raisonSociale'] = $raisonSociale;
$criteres['adresse'] = $numVoie.' '.$libVoie;
$criteres['codePostal']= $cp;
$criteres['ville'] = $ville;
$criteres['telFax'] = $telFax;
$criteres['naf'] = $naf;
2011-04-11 14:19:14 +00:00
$criteres['siege'] = false;
$criteres['actif'] = false;
2011-05-09 12:39:39 +00:00
2011-04-11 14:19:14 +00:00
//Criteres recherche dirigeants
} else if ($type=='dir') {
Zend_Registry::get('firebug')->info('RECHERCHE DIRIGEANT');
2011-05-09 12:39:39 +00:00
// Type de recherche = dirigeants
$dirNom = preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['dirNom']));
$dirPrenom = preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['dirPrenom']));
$dirDateNaissJJ = preg_replace('/[^0-9]/', '', $params['dirDateNaissJJ']);
if (intval($dirDateNaissJJ)<0 || intval($dirDateNaissJJ>31)){
//die('Jour de naissance incorrect !');
}
$dirDateNaissMM = preg_replace('/[^0-9]/', '', $params['dirDateNaissMM']);
if (intval($dirDateNaissMM)<0 || intval($dirDateNaissMM>31)){
//die('Mois de naissance incorrect !');
}
$dirDateNaissAAAA = preg_replace('/[^0-9]/', '', $params['dirDateNaissAAAA']);
$year = date('Y')-18;
if (intval($dirDateNaissAAAA)<0 || intval($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);
}
2011-04-11 14:19:14 +00:00
2011-05-09 12:39:39 +00:00
$criteres = array();
$criteres['dirNom'] = $dirNom;
$criteres['dirPrenom'] = $dirPrenom;
$criteres['dirDateNaiss'] = $dirDateNaiss;
$criteres['lieuNaiss'] = $dirVille;
2011-04-11 14:19:14 +00:00
}
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$position = $page-1;
if ($type=='ent') {
$reponse = $ws->rechercheEntreprise($type, $criteres, $position);
$criteresTexte = '';
//@todo : selection des critères à afficher
foreach ($reponse->criteres as $value){
if (!empty($value)) $criteresTexte.= $value.' ';
}
} elseif ($type=='dir') {
$reponse = $ws->searchDir($dirNom, $dirPrenom, $dirDateNaiss, $dirVille, $position);
$criteresTexte = '';
//@todo : selection des critères à afficher
foreach ($criteres as $value){
if (!empty($value)) $criteresTexte.= $value.' ';
}
}
2011-04-11 14:19:14 +00:00
if ($reponse !== false) {
$etabs = $reponse->result->item;
2011-04-11 14:19:14 +00:00
$criteresTexte = trim($criteresTexte);
$criteresLien = $this->view->url($params);
$info = $reponse->info;
$nbReponses = $reponse->nbReponses;
$nbReponsesTotal = $reponse->nbReponsesTotal;
2011-04-11 14:19:14 +00:00
if ($nbReponses < $nbReponsesTotal) {
$totPage = ceil($nbReponsesTotal/$nbReponses);
2011-06-30 12:14:14 +00:00
$curPage = $position+1;
2011-04-11 14:19:14 +00:00
} else {
$totPage = $curPage = 1;
}
2011-06-30 12:14:14 +00:00
2011-04-11 14:19:14 +00:00
$liste = array();
2011-06-30 12:14:14 +00:00
if (count($etabs)>0) {
foreach($etabs as $i => $etab) {
Zend_Registry::get('firebug')->info($etabs);
$item = array();
$item['position'] = ($position*$nbReponses)+$i+1;
$item['id'] = $etab->id;
$item['siren'] = $etab->Siren;
$item['siret'] = $etab->Siren.$etab->Nic;
$item['InfoSiret'] = $etab->Siren.' '.$etab->Nic;
$item['InfoNom'] = $etab->Nom;
$nomDetail = '';
if ($etab->Nom2<>'' || $etab->Enseigne<>'' || $etab->Sigle<>'') {
$nomDetail.= '<i>';
if ($etab->Nom2!='') $nomDetail.= $etab->Nom2.'<br/>';
if ($etab->Enseigne<>'') $nomDetail.= 'Enseigne : '.$etab->Enseigne.'&nbsp;&nbsp;&nbsp;&nbsp;';
if ($etab->Sigle<>'') $nomDetail.= 'Sigle : '.$etab->Sigle;
$nomDetail.= '</i><br/>';
}
$item['InfoNomDetail'] = $nomDetail;
$item['InfoSiret'] = substr($etab->Siren,0,3).' '.
substr($etab->Siren,3,3).' '.
substr($etab->Siren,6,3).' '.
$etab->Nic;
$infoEtab = '';
if ($etab->Siege==1){
$infoEtab.= '&Eacute;tablissement si&egrave;ge ';
} else {
$infoEtab.= '&Eacute;tablissement secondaire ';
}
if ($etab->Actif==1){
$infoEtab.= 'actif';
} else {
$infoEtab.= 'inactif';
}
if (intval($etab->Nic)==0 || intval($item->Nic)>=99990) {
$infoEtab.=' provisoire';
}
if ($etab->Siege!=1 || ($etab->Siege==1 && $etab->Actif!=1)) {
$url = $this->view->url(array(
'controller'=>'identite',
'action'=>'fiche',
'id' => $etab->id,
'siren' => $etab->Siren,
));
$infoEtab.= ' <a title="Voir la fiche d\'identité du siège de cette entreprise"'.
' href="'.$url.'">(Accès siège)</a>';
}
$item['InfoEtab'] = $infoEtab;
$adresse = $etab->Adresse.'<br/>';
if (isset($etab->Adresse2) && $etab->Adresse2 != '') {
$adresse.= $etab->Adresse2.'<br/>';
}
$adresse.= "<b>".$etab->CP." ".$etab->Ville."</b>";
$item['InfoAdresse'] = $adresse;
$forme = '';
if (trim($etab->FJ)!='')
{
$forme = '<i>Forme : '.$etab->FJLib.' ('.$etab->FJ.')</i><br/>';
}
$item['InfoForme'] = $forme;
$activite = '';
if (trim($etab->NafEnt)!='')
{
$activite = '<i>Activit&eacute; : '.$etab->NafEntLib.' ('.$etab->NafEnt.')</i><br/>';
}
$item['InfoActivite'] = $activite;
if ($type=='dir') {
$item['InfoDirigeant'] = '<u>Dirigeant recherch&eacute; :</u> ';
if ($etab->DirRs!='') {
$item['InfoDirigeant'].= '<b>'.$etab->DirRs.'</b>, repr&eacute;sent&eacute; par ';
}
$item['InfoDirigeant'].= $etab->DirNom .' '. $etab->DirPrenom;
if ($etab->DirNomUsage<>'' && $etab->DirNomUsage<>$etab->DirNom) {
$item['InfoDirigeant'].= ' ('. $etab->DirNomUsage . ')';
}
$item['InfoDirigeant'].= '<i>, '.$etab->DirFonction.'</i><br/>';
}
2011-06-30 12:14:14 +00:00
$liste[] = $item;
}
2011-04-11 14:19:14 +00:00
}
}
require_once 'Scores/Utilisateur.php';
$user = new Utilisateur();
$this->view->assign('blockInvestig', $user->checkPerm('INVESTIG'));
if ($type=='dir') {
$this->view->assign('blockDirToEntreprise', true);
$this->view->assign('searchDirToEntrepriseTxt', trim($critere['nom'].' '.$criteres['prenom']));
$this->view->assign('searchDirToEntrepriseLien', $this->view->url(array(
'action' => 'list',
'type' => 'ent',
'raisonSociale' => trim($critere['nom'].' '.$criteres['prenom'])
)));
} else {
$this->view->assign('blockDirToEntreprise', false);
}
2011-04-11 14:19:14 +00:00
$this->view->assign('liste', $liste);
$this->view->assign('totPage', $totPage);
$this->view->assign('curPage', $curPage);
$this->view->assign('nbReponses', $nbReponses);
$this->view->assign('nbReponsesTotal', $nbReponsesTotal);
$this->view->assign('criteresTexte', $criteresTexte);
$this->view->assign('criteresLien', $criteresLien);
$this->view->assign('info', $info);
}
public function ipariAction()
{
}
public function nafAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$q = strtolower($this->getRequest()->getParam('q', ''));
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH.'/configs/databases.ini');
$db = Zend_Db::factory($dbConfig->db->sdv1);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$naf = new Application_Model_Naf5();
$rowset = $naf->select('codNaf5, libNaf5')
->where("codNaf5 LIKE '%$q%' OR libNaf5 LIKE '%$q%'")
->order('poids DESC');
$rows = $naf->fetchAll($rowset);
$output = array();
if (count($rows)>0){
$separator = " , ";
foreach ($rows as $item) {
if (strpos(strtolower($item->codNaf5), $q) !== false ||
strpos(strtolower($item->libNaf5), $q) !== false )
{
$output[] = array(
'label' => $item->codNaf5 . $separator . $item->libNaf5,
'value' => $item->codNaf5,
);
}
}
}
echo json_encode($output);
}
2011-01-06 08:37:20 +00:00
}