1 |
<?php |
2 |
/** |
3 |
* Ce script a pour objet de recuperer la liste des pétionnaires correspondant aux critères de recherche |
4 |
* |
5 |
* @package openfoncier |
6 |
* @version SVN : $Id: findPetitionnaire.php 5710 2016-01-05 17:41:54Z jymadier $ |
7 |
*/ |
8 |
|
9 |
require_once "../obj/utils.class.php"; |
10 |
$f = new utils("nohtml"); |
11 |
$f->isAccredited(array("demande","demande_modifier","demande_ajouter"), "OR"); |
12 |
//Récupération des valeurs envoyées |
13 |
$f->set_submitted_value(); |
14 |
$f->disableLog(); |
15 |
|
16 |
// Donnees |
17 |
$par_nom = ($f->get_submitted_post_value("particulier_nom") != null) ? $f->get_submitted_post_value("particulier_nom") : ""; |
18 |
$par_nom = str_replace('*', '', $par_nom); |
19 |
$par_nom = html_entity_decode($par_nom, ENT_QUOTES); |
20 |
$par_nom = $f->db->escapeSimple($par_nom); |
21 |
|
22 |
$par_prenom = ($f->get_submitted_post_value("particulier_prenom") != null) ? $f->get_submitted_post_value("particulier_prenom") : ""; |
23 |
$par_prenom = str_replace('*', '', $par_prenom); |
24 |
$par_prenom = html_entity_decode($par_prenom, ENT_QUOTES); |
25 |
$par_prenom = $f->db->escapeSimple($par_prenom); |
26 |
|
27 |
$mor_raison_sociale = ($f->get_submitted_post_value("personne_morale_raison_sociale") != null) ? $f->get_submitted_post_value("personne_morale_raison_sociale") : ""; |
28 |
$mor_raison_sociale = str_replace('*', '', $mor_raison_sociale); |
29 |
$mor_raison_sociale = html_entity_decode($mor_raison_sociale, ENT_QUOTES); |
30 |
$mor_raison_sociale = $f->db->escapeSimple($mor_raison_sociale); |
31 |
|
32 |
$mor_denomination = ($f->get_submitted_post_value("personne_morale_denomination") != null) ? $f->get_submitted_post_value("personne_morale_denomination") : ""; |
33 |
$mor_denomination = str_replace('*', '', $mor_denomination); |
34 |
$mor_denomination = html_entity_decode($mor_denomination, ENT_QUOTES); |
35 |
$mor_denomination = $f->db->escapeSimple($mor_denomination); |
36 |
|
37 |
$mor_siret = ($f->get_submitted_post_value("personne_morale_siret") != null) ? $f->get_submitted_post_value("personne_morale_siret") : ""; |
38 |
$mor_siret = str_replace('*', '', $mor_siret); |
39 |
$mor_siret = html_entity_decode($mor_siret, ENT_QUOTES); |
40 |
$mor_siret = $f->db->escapeSimple($mor_siret); |
41 |
|
42 |
$mor_cat_juridique = ($f->get_submitted_post_value("personne_morale_categorie_juridique") != null) ? $f->get_submitted_post_value("personne_morale_categorie_juridique") : ""; |
43 |
$mor_cat_juridique = str_replace('*', '', $mor_cat_juridique); |
44 |
$mor_cat_juridique = html_entity_decode($mor_cat_juridique, ENT_QUOTES); |
45 |
$mor_cat_juridique = $f->db->escapeSimple($mor_cat_juridique); |
46 |
|
47 |
$mor_nom = ($f->get_submitted_post_value("personne_morale_nom") != null) ? $f->get_submitted_post_value("personne_morale_nom") : ""; |
48 |
$mor_nom = str_replace('*', '', $mor_nom); |
49 |
$mor_nom = html_entity_decode($mor_nom, ENT_QUOTES); |
50 |
$mor_nom = $f->db->escapeSimple($mor_nom); |
51 |
|
52 |
$mor_prenom = ($f->get_submitted_post_value("personne_morale_prenom") != null) ? $f->get_submitted_post_value("personne_morale_prenom") : ""; |
53 |
$mor_prenom = str_replace('*', '', $mor_prenom); |
54 |
$mor_prenom = html_entity_decode($mor_prenom, ENT_QUOTES); |
55 |
$mor_prenom = $f->db->escapeSimple($mor_prenom); |
56 |
|
57 |
$om_collectivite = ($f->get_submitted_post_value("om_collectivite") != null) ? $f->get_submitted_post_value("om_collectivite") : $_SESSION['collectivite']; |
58 |
$listData = ""; |
59 |
|
60 |
$requete = "frequent is TRUE AND |
61 |
type_demandeur = 'petitionnaire' AND"; |
62 |
if($par_nom != "") { |
63 |
$requete .= " particulier_nom ILIKE '%$par_nom%'"; |
64 |
$requete .= " AND"; |
65 |
} |
66 |
if($par_prenom != "") { |
67 |
$requete .= " particulier_prenom ILIKE '%$par_prenom%'"; |
68 |
$requete .= " AND"; |
69 |
} |
70 |
|
71 |
if ($mor_raison_sociale != "") { |
72 |
$requete .= " personne_morale_raison_sociale ILIKE '%$mor_raison_sociale%'"; |
73 |
$requete .= " AND"; |
74 |
} |
75 |
|
76 |
if($mor_denomination != "") { |
77 |
$requete .= " personne_morale_denomination ILIKE '%$mor_denomination%'"; |
78 |
$requete .= " AND"; |
79 |
} |
80 |
|
81 |
if ($mor_siret != "") { |
82 |
$requete .= " personne_morale_siret ILIKE '%$mor_siret%'"; |
83 |
$requete .= " AND"; |
84 |
} |
85 |
|
86 |
if ($mor_cat_juridique != "") { |
87 |
$requete .= " personne_morale_categorie_juridique ILIKE '%$mor_cat_juridique%'"; |
88 |
$requete .= " AND"; |
89 |
} |
90 |
|
91 |
if($mor_nom != "") { |
92 |
$requete .= " personne_morale_nom ILIKE '%$mor_nom%'"; |
93 |
$requete .= " AND"; |
94 |
} |
95 |
|
96 |
if($mor_prenom != "") { |
97 |
$requete .= " personne_morale_prenom ILIKE '%$mor_prenom%'"; |
98 |
$requete .= " AND"; |
99 |
} |
100 |
|
101 |
// Ajoute une condition sur la collectivité de l'utilisateur, ou celle de niveau 2 |
102 |
$requete .= ' (om_collectivite = '.$om_collectivite; |
103 |
$requete .= ' OR om_collectivite = ( |
104 |
SELECT om_collectivite from '.DB_PREFIXE.'om_collectivite |
105 |
WHERE niveau=\'2\' |
106 |
))'; |
107 |
|
108 |
$sql = 'SELECT |
109 |
demandeur as value, |
110 |
trim(concat(particulier_nom,\' \', particulier_prenom, \' \', |
111 |
personne_morale_raison_sociale, \' \', personne_morale_denomination, |
112 |
\' \', personne_morale_categorie_juridique, \' \', personne_morale_siret, \' \', |
113 |
personne_morale_nom, \' \', personne_morale_prenom, \' \', |
114 |
code_postal, \' \', localite)) as content |
115 |
FROM '.DB_PREFIXE.'demandeur |
116 |
WHERE '.$requete; |
117 |
|
118 |
$res = $f->db->query($sql); |
119 |
$f->isDatabaseError($res); |
120 |
$listData=array(); |
121 |
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) { |
122 |
$listData[] = $row; |
123 |
} |
124 |
|
125 |
echo json_encode($listData); |
126 |
|
127 |
?> |