1 |
mbroquet |
3730 |
<?php |
2 |
|
|
/** |
3 |
|
|
* Ce script permet de déclarer la classe import. |
4 |
|
|
* |
5 |
|
|
* @package openmairie_exemple |
6 |
|
|
* @version SVN : $Id: import_specific.class.php 6138 2016-03-09 10:53:39Z nhaye $ |
7 |
|
|
*/ |
8 |
|
|
require_once PATH_OPENMAIRIE."om_import.class.php"; |
9 |
|
|
|
10 |
|
|
require_once "../obj/dossier_autorisation.class.php"; |
11 |
|
|
require_once "../obj/dossier_parcelle.class.php"; |
12 |
|
|
|
13 |
|
|
/** |
14 |
|
|
* Définition de la classe import. |
15 |
|
|
* |
16 |
|
|
* Cette classe étend le module d'import du framework. Ce module permet |
17 |
|
|
* l'intégration de données dans l'applicatif depuis des fichiers CSV. |
18 |
|
|
*/ |
19 |
|
|
class import_specific extends import { |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* |
23 |
|
|
*/ |
24 |
|
|
var $script_path = "../app/import_specific.php"; |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* |
28 |
|
|
*/ |
29 |
|
|
var $script_extension = ".import_specific.inc.php"; |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* Ligne de travail du tableau en cours de formatage |
33 |
|
|
*/ |
34 |
|
|
var $line; |
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* Table de ligne rejetées à retiournées en csv |
38 |
|
|
*/ |
39 |
|
|
var $rejet = array(); |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* Table de ligne rejetées à retiournées en csv |
43 |
|
|
*/ |
44 |
|
|
var $line_error = array(); |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
/** |
49 |
|
|
* Liste des DA contenant chacun une liste de DI |
50 |
|
|
*/ |
51 |
|
|
var $dossier_autorisation; |
52 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* Vue principale du module import. |
55 |
|
|
* |
56 |
|
|
* Cette vue gère l'intégralité du module import : |
57 |
|
|
* - le listing des imports disponibles, |
58 |
|
|
* - le formulaire d'import d'un objet sélectionné, |
59 |
|
|
* - la validation du formulaire d'import, |
60 |
|
|
* - l'appel au traitement d'import, |
61 |
|
|
* - l'affichage du retour du traitement. |
62 |
|
|
* |
63 |
|
|
* @todo Il est nécessaire de gérer la récupération des $_GET et $_POST |
64 |
|
|
* dans des méthodes séparées afin de contrôler les données d'entrées |
65 |
|
|
* et de génériser le traitement d'import. |
66 |
|
|
* |
67 |
|
|
* @return void |
68 |
|
|
*/ |
69 |
|
|
function view_import_main() { |
70 |
|
|
// |
71 |
|
|
set_time_limit(3600); |
72 |
|
|
ini_set("memory_limit", "2048M"); |
73 |
|
|
// Nom de l'objet metier |
74 |
|
|
if(isset($_GET['obj'])) { |
75 |
|
|
$obj = $_GET['obj']; |
76 |
|
|
} else { |
77 |
|
|
$obj = ""; |
78 |
|
|
} |
79 |
|
|
// Vérification de l'existence de l'objet |
80 |
|
|
if ($obj != "" && !array_key_exists($obj, $this->get_import_list())) { |
81 |
|
|
$class = "error"; |
82 |
|
|
$message = _("L'objet est invalide."); |
83 |
|
|
$this->f->addToMessage($class, $message); |
84 |
|
|
$this->f->setFlag(null); |
85 |
|
|
$this->f->display(); |
86 |
|
|
die(); |
87 |
|
|
} |
88 |
|
|
// |
89 |
|
|
if ($obj == "") { |
90 |
|
|
// |
91 |
|
|
$this->display_import_list(); |
92 |
|
|
} else { |
93 |
|
|
// XXX Accesseur |
94 |
|
|
$this->f->displaySubTitle("-> ".$this->import_list[$obj]["title"]); |
95 |
|
|
// |
96 |
|
|
if (isset($_POST["submit-csv-import"])) { |
97 |
|
|
include $this->import_list[$obj]["path"]; |
98 |
|
|
|
99 |
|
|
if(isset($treatment) === false or empty($treatment) === true) { |
100 |
|
|
$this->treatment_import($obj); |
101 |
|
|
} else { |
102 |
|
|
$method = "treatment_import_".$treatment; |
103 |
|
|
if(method_exists($this, $method) === false) { |
104 |
|
|
$class = "error"; |
105 |
|
|
$message = _("La methode d'import n'est pas definie."); |
106 |
|
|
$this->f->addToMessage($class, $message); |
107 |
|
|
$this->f->setFlag(null); |
108 |
|
|
$this->f->display(); |
109 |
|
|
die(); |
110 |
|
|
} |
111 |
|
|
$this->$method($obj); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
} |
115 |
|
|
// |
116 |
|
|
$this->display_import_form($obj); |
117 |
|
|
// |
118 |
|
|
$this->display_import_helper($obj); |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
/** |
123 |
|
|
* Affichage du formulaire d'import. |
124 |
|
|
* |
125 |
|
|
* @param string $obj Identifiant de l'import. |
126 |
|
|
* |
127 |
|
|
* @return void |
128 |
|
|
*/ |
129 |
|
|
function display_import_form($obj) { |
130 |
|
|
// |
131 |
|
|
(defined("PATH_OPENMAIRIE") ? "" : define("PATH_OPENMAIRIE", "")); |
132 |
|
|
require_once PATH_OPENMAIRIE."om_formulaire.class.php"; |
133 |
|
|
// |
134 |
|
|
echo "\n<div id=\"form-csv-import\" class=\"formulaire\">\n"; |
135 |
|
|
echo "<form "; |
136 |
|
|
echo " action=\"".$this->script_path."?obj=".$obj."\" "; |
137 |
|
|
echo " method=\"post\" "; |
138 |
|
|
echo " name=\"f2\">\n"; |
139 |
|
|
// |
140 |
|
|
$champs = array("fic1", "separateur"); |
141 |
|
|
// |
142 |
|
|
$form = new formulaire(null, 0, 0, $champs); |
143 |
|
|
// |
144 |
|
|
$form->setLib("fic1", _("Fichier CSV")); |
145 |
|
|
$form->setType("fic1", "upload2"); |
146 |
|
|
$form->setTaille("fic1", 64); |
147 |
|
|
$form->setMax("fic1", 30); |
148 |
|
|
// Restriction sur le champ d'upload |
149 |
|
|
$params = array( |
150 |
|
|
"constraint" => array( |
151 |
|
|
"size_max" => 20, |
152 |
|
|
"extension" => ".csv;.txt" |
153 |
|
|
), |
154 |
|
|
); |
155 |
|
|
$form->setSelect("fic1", $params); |
156 |
|
|
// |
157 |
|
|
$form->setLib("separateur", _("Separateur")); |
158 |
|
|
$form->setType("separateur", "select"); |
159 |
|
|
$separator_list = array( |
160 |
|
|
0 => array(";", ",", ), |
161 |
|
|
1 => array("; "._("(point-virgule)"), ", "._("(virgule)")), |
162 |
|
|
); |
163 |
|
|
$form->setSelect("separateur", $separator_list); |
164 |
|
|
// |
165 |
|
|
$form->entete(); |
166 |
|
|
$form->afficher($champs, 0, false, false); |
167 |
|
|
$form->enpied(); |
168 |
|
|
// |
169 |
|
|
echo "\n<!-- ########## START FORMCONTROLS ########## -->\n"; |
170 |
|
|
echo "<div class=\"formControls\">\n"; |
171 |
|
|
echo "<input "; |
172 |
|
|
echo " type=\"submit\" "; |
173 |
|
|
echo " name=\"submit-csv-import\" "; |
174 |
|
|
echo " value=\""._("Importer")."\" "; |
175 |
|
|
echo " class=\"boutonFormulaire\" />\n"; |
176 |
|
|
// Lien retour |
177 |
|
|
$this->f->layout->display_lien_retour(array( |
178 |
|
|
"href" => $this->script_path, |
179 |
|
|
)); |
180 |
|
|
echo "</div>\n"; |
181 |
|
|
// |
182 |
|
|
echo "</form>\n"; |
183 |
|
|
echo "</div>\n"; |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
|
187 |
|
|
/** |
188 |
|
|
* Affichage de l'assistant d'import. |
189 |
|
|
* |
190 |
|
|
* @param string $obj Identifiant de l'import. |
191 |
|
|
* |
192 |
|
|
* @return void |
193 |
|
|
*/ |
194 |
|
|
function display_import_helper($obj) { |
195 |
|
|
// Récupération du fichier de paramétrage de l'import |
196 |
|
|
// XXX Faire un accesseur pour vérifier l'existence du fichier |
197 |
|
|
include $this->import_list[$obj]["path"]; |
198 |
|
|
// |
199 |
|
|
if (!isset($column)) { |
200 |
|
|
return; |
201 |
|
|
} |
202 |
|
|
// |
203 |
|
|
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
204 |
|
|
// |
205 |
|
|
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
206 |
|
|
echo _("Structure du fichier CSV"); |
207 |
|
|
echo "</legend>\n"; |
208 |
|
|
// Lien vers le téléchargement d'un fichier CSV modèle |
209 |
|
|
echo "<div>"; |
210 |
|
|
// $this->f->layout->display_link(array( |
211 |
|
|
// "href" => $this->script_path."?obj=".$obj."&action=template", |
212 |
|
|
// "title" => _("Télécharger le fichier CSV modèle"), |
213 |
|
|
// "class" => "om-prev-icon reqmo-16", |
214 |
|
|
// "target" => "_blank", |
215 |
|
|
// )); |
216 |
|
|
echo "</div>"; |
217 |
|
|
// Affichage des informations sur l'import |
218 |
|
|
echo "<table "; |
219 |
|
|
echo " class=\"table table-condensed table-bordered table-striped\" "; |
220 |
|
|
echo " id=\"structure_csv\">\n"; |
221 |
|
|
// |
222 |
|
|
echo "<thead>\n"; |
223 |
|
|
echo "<tr>"; |
224 |
|
|
echo "<th>"._("Ordre")."</th>"; |
225 |
|
|
echo "<th>"._("Champ")."</th>"; |
226 |
|
|
echo "<th>"._("Type")."</th>"; |
227 |
|
|
echo "<th>"._("Obligatoire")."</th>"; |
228 |
|
|
echo "<th>"._("Defaut")."</th>"; |
229 |
|
|
echo "<th>"._("Vocabulaire")."</th>"; |
230 |
|
|
echo "</tr>\n"; |
231 |
|
|
echo "</thead>\n"; |
232 |
|
|
// |
233 |
|
|
$i = 1; |
234 |
|
|
// |
235 |
|
|
echo "<tbody>\n"; |
236 |
|
|
foreach ($column as $key => $field) { |
237 |
|
|
// Gestion du caractère obligatoire du champ |
238 |
|
|
(isset($field["require"]) && $field["require"] == true) ? |
239 |
|
|
$needed = true : $needed = false; |
240 |
|
|
echo "<tr>"; |
241 |
|
|
// Ordre |
242 |
|
|
echo "<td><b>".$i."</b></td>"; |
243 |
|
|
// Champ |
244 |
|
|
echo "<td>".$field["header"]."</td>"; |
245 |
|
|
// Type |
246 |
|
|
echo "<td>"; |
247 |
|
|
if (isset($field["type"])) { |
248 |
|
|
switch ($field["type"]) { |
249 |
|
|
case 'blob': |
250 |
|
|
echo "text"; |
251 |
|
|
break; |
252 |
|
|
case 'string': |
253 |
|
|
echo "text"; |
254 |
|
|
break; |
255 |
|
|
default: |
256 |
|
|
echo $field["type"]; |
257 |
|
|
break; |
258 |
|
|
} |
259 |
|
|
} |
260 |
|
|
// Taille |
261 |
|
|
if (isset($field["len"])) { |
262 |
|
|
if (!in_array($field["type"], array("blob", "geom", ))) { |
263 |
|
|
echo " ("; |
264 |
|
|
echo $field["len"]; |
265 |
|
|
echo ")"; |
266 |
|
|
} |
267 |
|
|
} |
268 |
|
|
echo "</td>"; |
269 |
|
|
// Obligatoire si not null et si aucune valeur par défaut |
270 |
|
|
echo "<td>"; |
271 |
|
|
if ($needed == true && !isset($field["default"])) { |
272 |
|
|
echo "Oui"; |
273 |
|
|
} |
274 |
|
|
echo "</td>"; |
275 |
|
|
// Défaut |
276 |
|
|
echo "<td>"; |
277 |
|
|
if (isset($field["default"])) { |
278 |
|
|
echo "<i>".$field["default"]."</i>"; |
279 |
|
|
} |
280 |
|
|
echo "</td>"; |
281 |
|
|
// Vocabulaire |
282 |
|
|
echo "<td>"; |
283 |
|
|
// Clé étrangère |
284 |
|
|
if (isset($field["foreign_key"])) { |
285 |
|
|
echo _("Cle etrangere vers"). |
286 |
|
|
" : <a href=\"../scr/tab.php?obj=". |
287 |
|
|
$field["foreign_key"]["table"]."\">"; |
288 |
|
|
echo $field["foreign_key"]["table"].".".$field["foreign_key"]["field"]; |
289 |
|
|
echo "</a>"; |
290 |
|
|
if (isset($field["foreign_key"]["foreign_key_alias"]) |
291 |
|
|
&& isset($field["foreign_key"]["foreign_key_alias"]["fields_list"])) { |
292 |
|
|
if (count($field["foreign_key"]["foreign_key_alias"]["fields_list"]) > 1) { |
293 |
|
|
echo "<br/>=> "._("Valeurs alternatives possibles")." : "; |
294 |
|
|
} else { |
295 |
|
|
echo "<br/>=> "._("Valeur alternative possible")." : "; |
296 |
|
|
} |
297 |
|
|
echo implode( |
298 |
|
|
", ", |
299 |
|
|
$field["foreign_key"]["foreign_key_alias"]["fields_list"] |
300 |
|
|
); |
301 |
|
|
} |
302 |
|
|
} |
303 |
|
|
// Dates et booléens |
304 |
|
|
$field_info = ""; |
305 |
|
|
if (isset($field["type"])) { |
306 |
|
|
switch ($field["type"]) { |
307 |
|
|
case 'date': |
308 |
|
|
$field_info = _("Format")." : '"._("DD/MM/YYYY")."'"; |
309 |
|
|
break; |
310 |
|
|
case 'bool': |
311 |
|
|
$field_info = _("Format")." :<br/>"; |
312 |
|
|
if ($needed == false) { |
313 |
|
|
$field_info .= "'' "._("pour état null")."<br/>"; |
314 |
|
|
} |
315 |
|
|
$field_info .= "'t', 'true', '1', 'Oui' "._("pour oui"); |
316 |
|
|
$field_info .= "<br/>"; |
317 |
|
|
$field_info .= "'f', 'false', '0', 'Non' "._("pour non"); |
318 |
|
|
break; |
319 |
|
|
default: |
320 |
|
|
break; |
321 |
|
|
} |
322 |
|
|
} |
323 |
|
|
echo $field_info; |
324 |
|
|
echo "</td>"; |
325 |
|
|
// |
326 |
|
|
echo "</tr>\n"; |
327 |
|
|
$i++; |
328 |
|
|
} |
329 |
|
|
// |
330 |
|
|
echo "</tbody>\n"; |
331 |
|
|
// |
332 |
|
|
echo "</table>\n"; |
333 |
|
|
// |
334 |
|
|
echo "</fieldset>\n"; |
335 |
|
|
} |
336 |
|
|
|
337 |
|
|
|
338 |
|
|
/** |
339 |
|
|
* Traitement d'import pour csv provenant d'ads2007 |
340 |
|
|
* |
341 |
|
|
* @param string $obj Identifiant de l'import. |
342 |
|
|
* |
343 |
|
|
* @todo Modifier cette méthode pour la rendre générique et éventuellement |
344 |
|
|
* utilisable depuis d'autres contextes que celui de la vue principale |
345 |
|
|
* du module import. |
346 |
|
|
* |
347 |
|
|
* @return boolean false si erreur |
348 |
|
|
*/ |
349 |
|
|
function treatment_import_ads2007($obj) { |
350 |
|
|
|
351 |
|
|
// On vérifie que le formulaire a bien été validé |
352 |
|
|
if (!isset($_POST['submit-csv-import'])) { |
353 |
|
|
// |
354 |
|
|
return false; |
355 |
|
|
} |
356 |
|
|
|
357 |
|
|
// On récupère les paramètres du formulaire |
358 |
|
|
$separateur=$_POST['separateur']; |
359 |
|
|
|
360 |
|
|
// On vérifie que le fichier a bien été posté et qu'il n'est pas vide |
361 |
|
|
if (isset($_POST['fic1']) && $_POST['fic1'] == "") { |
362 |
|
|
// |
363 |
|
|
$class = "error"; |
364 |
|
|
$message = _("Vous n'avez pas selectionne de fichier a importer."); |
365 |
|
|
$this->f->displayMessage($class, $message); |
366 |
|
|
// |
367 |
|
|
return false; |
368 |
|
|
} |
369 |
|
|
|
370 |
|
|
// On enlève le préfixe du fichier temporaire |
371 |
|
|
$fichier_tmp = str_replace("tmp|", "", $_POST['fic1']); |
372 |
|
|
// On récupère le chemin vers le fichier |
373 |
|
|
$path = $this->f->storage->storage->temporary_storage->getPath($fichier_tmp); |
374 |
|
|
// On vérifie que le fichier peut être récupéré |
375 |
|
|
if (!file_exists($path)) { |
376 |
|
|
// |
377 |
|
|
$class = "error"; |
378 |
|
|
$message = _("Le fichier n'existe pas."); |
379 |
|
|
$this->f->displayMessage($class, $message); |
380 |
|
|
// |
381 |
|
|
return false; |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
// Configuration par défaut du fichier de paramétrage de l'import |
385 |
|
|
// |
386 |
|
|
$table = ""; |
387 |
|
|
// Clé primaire numérique automatique. Si la table dans laquelle les |
388 |
|
|
// données vont être importées possède une clé primaire numérique |
389 |
|
|
// associée à une séquence automatique, il faut positionner le nom du |
390 |
|
|
// champ de la clé primaire dans la variable $id. Attention il se peut |
391 |
|
|
// que ce paramètre se chevauche avec le critère OBLIGATOIRE. Si ce |
392 |
|
|
// champ est défini dans $zone et qu'il est obligatoire et qu'il est |
393 |
|
|
// en $id, les valeurs du fichier CSV seront ignorées. |
394 |
|
|
$id = ""; |
395 |
|
|
// |
396 |
|
|
$verrou = 1; // =0 pas de mise a jour de la base / =1 mise a jour |
397 |
|
|
// |
398 |
|
|
$fic_rejet = 1; // =0 pas de fichier pour relance / =1 fichier relance traitement |
399 |
|
|
// |
400 |
|
|
$ligne1 = 1; // = 1 : 1ere ligne contient nom des champs / o sinon |
401 |
|
|
|
402 |
|
|
// Récupération du fichier de paramétrage de l'import |
403 |
|
|
// XXX Faire un accesseur pour vérifier l'existence du fichier |
404 |
|
|
include $this->import_list[$obj]["path"]; |
405 |
|
|
|
406 |
|
|
$this->column = $column; |
407 |
|
|
|
408 |
|
|
$header = array(); |
409 |
|
|
foreach ($column as $key => $value) { |
410 |
|
|
$header[] = $column[$key]["header"]; |
411 |
|
|
} |
412 |
|
|
|
413 |
|
|
// On ouvre le fichier en lecture |
414 |
|
|
$fichier = fopen($path, "r"); |
415 |
|
|
|
416 |
|
|
// Initialisation des variables |
417 |
|
|
$cpt = array( |
418 |
|
|
"total" => 0, |
419 |
|
|
"rejet" => 0, |
420 |
|
|
"insert" => 0, |
421 |
|
|
"error" => 0, |
422 |
|
|
"firstline" => 0, |
423 |
|
|
"empty" => 0, |
424 |
|
|
); |
425 |
|
|
|
426 |
|
|
// Boucle sur chaque ligne du fichier |
427 |
|
|
while (!feof($fichier)) { |
428 |
|
|
// Incrementation du compteur de lignes |
429 |
|
|
$cpt['total']++; |
430 |
|
|
// Logger |
431 |
|
|
$this->f->addToLog(__METHOD__."(): LINE ".$cpt['total'], EXTRA_VERBOSE_MODE); |
432 |
|
|
// On définit si on se trouve sur la ligne titre |
433 |
|
|
$firstline = ($cpt['total'] == 1 && $ligne1 == 1 ? true : false); |
434 |
|
|
// |
435 |
|
|
$valF = array(); |
436 |
|
|
$this->line_error = array(); |
437 |
|
|
|
438 |
|
|
// Récupération de la ligne suivante dans le fichier |
439 |
|
|
$contenu = fgetcsv($fichier, 4096, $separateur); |
440 |
|
|
// |
441 |
|
|
$this->f->addToLog( |
442 |
|
|
__METHOD__."(): LINE ".$cpt['total']." - contenu = ".print_r($contenu, true), |
443 |
|
|
EXTRA_VERBOSE_MODE |
444 |
|
|
); |
445 |
|
|
// Si la ligne un champ ou moins et qu'il est vide on passe a la ligne |
446 |
|
|
// suivante |
447 |
|
|
if (count($contenu) == 1 && $contenu[0] == "") { // enregistrement vide |
448 |
|
|
$cpt["empty"]++; |
449 |
|
|
continue; |
450 |
|
|
} |
451 |
|
|
|
452 |
|
|
// Suppression des espaces superflus |
453 |
|
|
$contenu = array_map("trim", $contenu); |
454 |
|
|
array_walk( |
455 |
|
|
$contenu, |
456 |
|
|
function (&$entry) { |
457 |
|
|
$entry = iconv("ISO-8859-15", "UTF-8", $entry); |
458 |
|
|
} |
459 |
|
|
); |
460 |
|
|
// Suppression des colonnes de trop |
461 |
|
|
while(count($contenu) > 61) { |
462 |
|
|
unset($contenu[count($contenu)-1]); |
463 |
|
|
} |
464 |
|
|
|
465 |
|
|
// Si pas le bon nombre de colonnes on en ajoute pour ajouter le message |
466 |
|
|
// d'erreur |
467 |
|
|
if(count($contenu) != 61) { |
468 |
|
|
// Ajout des colonnes |
469 |
|
|
while(count($contenu) != 61) { |
470 |
|
|
$contenu[] = ""; |
471 |
|
|
} |
472 |
|
|
$contenu[] = _("Le format de la ligne n'est pas valide"); |
473 |
|
|
$this->rejet[] = $contenu; |
474 |
|
|
$cpt["rejet"]++; |
475 |
|
|
continue; |
476 |
|
|
} |
477 |
|
|
|
478 |
|
|
// Si la première ligne est entête |
479 |
|
|
if ($contenu[0] === "Type") { |
480 |
|
|
// |
481 |
|
|
$cpt['firstline']++; |
482 |
|
|
// Logger |
483 |
|
|
$this->f->addToLog( |
484 |
|
|
__METHOD__."(): LINE ".$cpt['total']." - firstline", |
485 |
|
|
EXTRA_VERBOSE_MODE |
486 |
|
|
); |
487 |
|
|
continue; |
488 |
|
|
} |
489 |
|
|
|
490 |
|
|
$contenu = array_combine(array_keys($this->column), $contenu); |
491 |
|
|
|
492 |
|
|
// Définition de la variable de travail |
493 |
|
|
$this->line = $contenu; |
494 |
|
|
|
495 |
|
|
// Traitement des lignes du csv |
496 |
|
|
|
497 |
|
|
// Si une date de decision est définie sans nature de decision alors |
498 |
|
|
// le dossier est implicitement accordé |
499 |
|
|
if(!empty($this->line["date_de_decision"]) and |
500 |
|
|
empty($this->line["nature_decision"])) { |
501 |
|
|
|
502 |
|
|
$this->line["nature_decision"] = "Favorable"; |
503 |
|
|
} |
504 |
|
|
// vérification de clôture du DI |
505 |
|
|
$this->is_cloture(); |
506 |
|
|
|
507 |
|
|
// définision de l'avis en fonction des date saisie |
508 |
|
|
$this->set_avis_decision_from_date($this->line); |
509 |
|
|
|
510 |
|
|
// reformatage du code INSEE |
511 |
|
|
$this->format_code_insee(); |
512 |
|
|
|
513 |
|
|
// Pour chaque champs vérifications définie dans la conf |
514 |
|
|
foreach ( $this->line as $key => $value ) { |
515 |
|
|
|
516 |
|
|
$this->line[$key] = trim($this->line[$key]); |
517 |
|
|
// Vérification du format des valeurs selon leurs type |
518 |
|
|
if($this->check_type($key) === false) { |
519 |
|
|
$this->line_error[] = sprintf( |
520 |
|
|
_("La colonne %s ne correspond pas au format requis"), |
521 |
|
|
$this->column[$key]["header"] |
522 |
|
|
); |
523 |
|
|
} |
524 |
|
|
// Mise en correspondance des valeurs de la base |
525 |
|
|
$this->set_linked_value($key); |
526 |
|
|
// Vérification de l'existance des clés etrangères |
527 |
|
|
if($this->get_foreign_key_id($key) === false) { |
528 |
|
|
$this->line_error[] = sprintf( |
529 |
|
|
_("Aucune correspondance pour la colonne %s"), |
530 |
|
|
$this->column[$key]["header"] |
531 |
|
|
); |
532 |
|
|
} |
533 |
|
|
|
534 |
|
|
// Vérification des champs obligatoires |
535 |
|
|
if($this->check_required($key) === false) { |
536 |
|
|
$this->line_error[] = sprintf( |
537 |
|
|
_("La colonne %s est obligatoire"), |
538 |
|
|
$this->column[$key]["header"] |
539 |
|
|
); |
540 |
|
|
} |
541 |
|
|
|
542 |
|
|
} |
543 |
|
|
|
544 |
|
|
// Définition de la collectivité du dossier |
545 |
|
|
$this->set_collectivite(); |
546 |
|
|
|
547 |
|
|
// Formatage (explode) de l'adresse du demandeur |
548 |
|
|
if($this->explode_address($this->line["adresse_demandeur"]) === false) { |
549 |
|
|
$this->line_error[] = |
550 |
|
|
_("Le format de l'adresse demandeur n'est pas correct"); |
551 |
|
|
} else { |
552 |
|
|
$this->line["adresse_demandeur"] = |
553 |
|
|
$this->explode_address($this->line["adresse_demandeur"]); |
554 |
|
|
} |
555 |
|
|
// Formatage (explode) de l'adresse du terrain |
556 |
|
|
if($this->explode_address($this->line["terrain"]) === false) { |
557 |
|
|
$this->line_error[] = |
558 |
|
|
_("Le format de l'adresse du terrain n'est pas correct"); |
559 |
|
|
} else { |
560 |
|
|
$this->line["terrain"] = |
561 |
|
|
$this->explode_address($this->line["terrain"]); |
562 |
|
|
} |
563 |
|
|
// Formatage des références cadastrales |
564 |
|
|
if($this->parse_reference_cadastrale("references_cadastrales") === false) { |
565 |
|
|
$this->line_error[] = |
566 |
|
|
_("Le format des references cadastrale n'est pas correct"); |
567 |
|
|
} |
568 |
|
|
// Définition du numéro de version du DI |
569 |
|
|
$this->set_version(); |
570 |
|
|
// Définition du prefixe des numéro DI et DA |
571 |
|
|
$this->set_prefix_di(); |
572 |
|
|
// On test l'existance ou non du DI |
573 |
|
|
$this->check_di_in_db(); |
574 |
|
|
|
575 |
|
|
if(!empty($this->line_error)) { |
576 |
|
|
$contenu[] = implode("\n", $this->line_error); |
577 |
|
|
$this->rejet[] = $contenu; |
578 |
|
|
$cpt["rejet"]++; |
579 |
|
|
continue; |
580 |
|
|
} else { |
581 |
|
|
$this->line['original_line'] = $contenu; |
582 |
|
|
} |
583 |
|
|
|
584 |
|
|
// Ajout de la ligne traitée au tableau final |
585 |
|
|
$this->dossier_autorisation[$this->line["initial"]][$this->line["version"]] = $this->line; |
586 |
|
|
|
587 |
|
|
} |
588 |
|
|
|
589 |
|
|
if(!empty($this->dossier_autorisation)) { |
590 |
|
|
|
591 |
|
|
// Vérification de l'intégrité de l'instruction |
592 |
|
|
foreach ($this->dossier_autorisation as $da_id => $list_di) { |
593 |
|
|
$this->f->db->autoCommit(false); |
594 |
|
|
|
595 |
|
|
if($this->is_da_exist($da_id) != true) { |
596 |
|
|
if($this->add_dossier_autorisation($da_id, $list_di) != true) { |
597 |
|
|
$cpt["error"]++; |
598 |
|
|
$this->f->db->rollback(); |
599 |
|
|
continue; |
600 |
|
|
} |
601 |
|
|
} |
602 |
|
|
// On boucle maintenant sur les di du da |
603 |
|
|
foreach ($list_di as $version => $data_di) { |
604 |
|
|
// Définition du suffixe des numéro DI |
605 |
|
|
$code = $this->get_dossier_instruction_type_code( |
606 |
|
|
$version, |
607 |
|
|
$this->dossier_autorisation[$da_id] |
608 |
|
|
); |
609 |
|
|
|
610 |
|
|
$data_di["dossier_instruction_type"] = |
611 |
|
|
$this->get_dossier_instruction_type($data_di["type"], $code); |
612 |
|
|
|
613 |
|
|
if($data_di["dossier_instruction_type"] === null) { |
614 |
|
|
$cpt["rejet"]++; |
615 |
|
|
$data_di['original_line'][] = sprintf( |
616 |
|
|
_("Aucun type de dossier d'instruction ne correspond (type = %s, code = %s)"), |
617 |
|
|
$data_di["type"], |
618 |
|
|
$code |
619 |
|
|
); |
620 |
|
|
$this->rejet[] = $data_di['original_line']; |
621 |
|
|
continue; |
622 |
|
|
} |
623 |
|
|
$data_di["numero"] .= $code.$version; |
624 |
|
|
|
625 |
|
|
|
626 |
|
|
if($this->is_di_exist($data_di["numero"]) === true) { |
627 |
|
|
$data_di["dossier_exist"] = true; |
628 |
|
|
} else { |
629 |
|
|
$data_di["dossier_exist"] = false; |
630 |
|
|
} |
631 |
|
|
|
632 |
|
|
if($this->add_dossier_instruction($data_di) === false) { |
633 |
|
|
$cpt["error"]++; |
634 |
|
|
$this->f->db->rollback(); |
635 |
|
|
continue; |
636 |
|
|
} |
637 |
|
|
|
638 |
|
|
if($this->add_donnees_techniques($data_di) === false) { |
639 |
|
|
$cpt["error"]++; |
640 |
|
|
$this->f->db->rollback(); |
641 |
|
|
continue; |
642 |
|
|
} |
643 |
|
|
|
644 |
|
|
if($data_di["dossier_exist"] == false) { |
645 |
|
|
if($this->add_demandeur($data_di) === false) { |
646 |
|
|
$cpt["error"]++; |
647 |
|
|
$this->f->db->rollback(); |
648 |
|
|
continue; |
649 |
|
|
} |
650 |
|
|
} |
651 |
|
|
|
652 |
|
|
$cpt["insert"]++; |
653 |
|
|
|
654 |
|
|
} |
655 |
|
|
|
656 |
|
|
$this->update_dossier_autorisation($da_id); |
657 |
|
|
|
658 |
|
|
$this->f->db->commit(); // Validation des transactions |
659 |
|
|
} |
660 |
|
|
} |
661 |
|
|
|
662 |
|
|
|
663 |
|
|
// Fermeture du fichier |
664 |
|
|
fclose($fichier); |
665 |
|
|
|
666 |
|
|
/** |
667 |
|
|
* Affichage du message de résultat de l'import |
668 |
|
|
*/ |
669 |
|
|
// Composition du message résultat |
670 |
|
|
$message = _("Resultat de l'import")."<br/>"; |
671 |
|
|
$message .= $cpt["total"]." "._("ligne(s) dans le fichier dont :")."<br/>"; |
672 |
|
|
$message .= " - ".$cpt["firstline"]." "._("ligne(s) d'entete")."<br/>"; |
673 |
|
|
$message .= " - ".$cpt["insert"]." "._("ligne(s) importee(s)")."<br/>"; |
674 |
|
|
$message .= " - ".$cpt["error"]." "._("ligne(s) en erreur")."<br/>"; |
675 |
|
|
$message .= " - ".$cpt["rejet"]." "._("ligne(s) rejetee(s)")."<br/>"; |
676 |
|
|
$message .= " - ".$cpt["empty"]." "._("ligne(s) vide(s)")."<br/>"; |
677 |
|
|
// |
678 |
|
|
if($cpt["error"] > 0 ) { |
679 |
|
|
// |
680 |
|
|
$class = "error"; |
681 |
|
|
$message .= |
682 |
|
|
_("Erreur de base de donnees. Contactez votre administrateur.")."<br/>"; |
683 |
|
|
|
684 |
|
|
} |
685 |
|
|
if ($fic_rejet == 1 && $cpt["rejet"] != 0) { |
686 |
|
|
// |
687 |
|
|
$class = "error"; |
688 |
|
|
$header[] = "Erreur (s)"; |
689 |
|
|
$header = array_map(array($this, "encodeFunc"), $header); |
690 |
|
|
$rejet = implode(";", $header)."\n"; |
691 |
|
|
// Composition du fichier de rejet |
692 |
|
|
foreach ($this->rejet as $line_rejet) { |
693 |
|
|
$line_rejet = array_map(array($this, "encodeFunc"), $line_rejet); |
694 |
|
|
$rejet .= implode(";", $line_rejet)."\n"; |
695 |
|
|
} |
696 |
|
|
$rejet = iconv("UTF-8", "ISO-8859-15", $rejet); |
697 |
|
|
$metadata = array( |
698 |
|
|
"filename" => "import_".$obj."_".date("Ymd_Gis")."_rejet.csv", |
699 |
|
|
"size" => strlen($rejet), |
700 |
|
|
"mimetype" => "application/vnd.ms-excel", |
701 |
|
|
); |
702 |
|
|
$uid = $this->f->storage->create_temporary($rejet, $metadata); |
703 |
|
|
// Enclenchement de la tamporisation de sortie |
704 |
|
|
ob_start(); |
705 |
|
|
// |
706 |
|
|
$this->f->layout->display_link( |
707 |
|
|
array( |
708 |
|
|
"href" => "../spg/file.php?uid=".$uid."&mode=temporary", |
709 |
|
|
"title" => _("Télécharger le fichier CSV rejet"), |
710 |
|
|
"class" => "om-prev-icon reqmo-16", |
711 |
|
|
"target" => "_blank", |
712 |
|
|
) |
713 |
|
|
); |
714 |
|
|
// Affecte le contenu courant du tampon de sortie au message puis l'efface |
715 |
|
|
$message .= ob_get_clean(); |
716 |
|
|
} else { |
717 |
|
|
// |
718 |
|
|
$class = "ok"; |
719 |
|
|
} |
720 |
|
|
// |
721 |
|
|
$this->f->displayMessage($class, $message); |
722 |
|
|
} |
723 |
|
|
|
724 |
|
|
/** |
725 |
|
|
* Formate le code insee fourni pas l'export ads2007. |
726 |
|
|
*/ |
727 |
|
|
function format_code_insee() { |
728 |
|
|
if(!isset($this->line["insee"]) or $this->line["insee"] == "") { |
729 |
|
|
return false; |
730 |
|
|
} |
731 |
|
|
$this->line["insee"] = |
732 |
|
|
str_pad( |
733 |
|
|
strval( |
734 |
|
|
intval($this->line["insee"]) |
735 |
|
|
), |
736 |
|
|
5, |
737 |
|
|
0, |
738 |
|
|
STR_PAD_LEFT |
739 |
|
|
); |
740 |
|
|
} |
741 |
|
|
|
742 |
|
|
/** |
743 |
|
|
* Permet d'échapper des quote autour de chaque valeur. |
744 |
|
|
* |
745 |
|
|
* @param string $value chaine à enquoter |
746 |
|
|
* |
747 |
|
|
* @return string m€me chaine avec quotes |
748 |
|
|
*/ |
749 |
|
|
function encodeFunc($value) { |
750 |
|
|
return "\"".$value."\""; |
751 |
|
|
} |
752 |
|
|
|
753 |
|
|
/** |
754 |
|
|
* [is_da_exist description] |
755 |
|
|
* |
756 |
|
|
* @param [type] $id [description] |
757 |
|
|
* |
758 |
|
|
* @return boolean [description] |
759 |
|
|
*/ |
760 |
|
|
function is_da_exist($id) { |
761 |
|
|
$sql = "SELECT count(*) FROM ". |
762 |
|
|
DB_PREFIXE."dossier_autorisation WHERE dossier_autorisation='".$id."'"; |
763 |
|
|
|
764 |
|
|
$count = $this->f->db->getone($sql); |
765 |
|
|
|
766 |
|
|
$this->f->isDatabaseError($id); |
767 |
|
|
|
768 |
|
|
if($count != "0") { |
769 |
|
|
return true; |
770 |
|
|
} |
771 |
|
|
|
772 |
|
|
return false; |
773 |
|
|
|
774 |
|
|
} |
775 |
|
|
|
776 |
|
|
/** |
777 |
|
|
* Vérifie si le di existe en BDD. |
778 |
|
|
* |
779 |
|
|
* @param string $id identifiant du dossier |
780 |
|
|
* |
781 |
|
|
* @return boolean true si existe false sinon |
782 |
|
|
*/ |
783 |
|
|
function is_di_exist($id) { |
784 |
|
|
$sql = "SELECT count(*) FROM ".DB_PREFIXE."dossier WHERE dossier='".$id."'"; |
785 |
|
|
|
786 |
|
|
$count = $this->f->db->getone($sql); |
787 |
|
|
|
788 |
|
|
$this->f->isDatabaseError($id); |
789 |
|
|
|
790 |
|
|
if($count != "0") { |
791 |
|
|
return true; |
792 |
|
|
} |
793 |
|
|
|
794 |
|
|
return false; |
795 |
|
|
|
796 |
|
|
} |
797 |
|
|
|
798 |
|
|
|
799 |
|
|
|
800 |
|
|
/** |
801 |
|
|
* Vérifie le contenu en fonction du paramétrage |
802 |
|
|
* |
803 |
|
|
* @param integer $key clé de la colonne |
804 |
|
|
* |
805 |
|
|
* @return string message d'erreur ou chaine vide |
806 |
|
|
*/ |
807 |
|
|
function check_required($key) { |
808 |
|
|
if($this->column[$key]["require"] === true and $this->line[$key] =="") { |
809 |
|
|
return false; |
810 |
|
|
} |
811 |
|
|
return true; |
812 |
|
|
} |
813 |
|
|
|
814 |
|
|
/** |
815 |
|
|
* Vérifie le contenu en fonction du paramétrage |
816 |
|
|
* |
817 |
|
|
* @param integer $key clé de la colonne |
818 |
|
|
* |
819 |
|
|
* @return string message d'erreur ou chaine vide |
820 |
|
|
*/ |
821 |
|
|
function check_type($key) { |
822 |
|
|
if($this->line[$key] === "") { |
823 |
|
|
return true; |
824 |
|
|
} |
825 |
|
|
$regex = ''; |
826 |
|
|
switch ($this->column[$key]["type"]) { |
827 |
|
|
|
828 |
|
|
case 'integer': |
829 |
|
|
$this->line[$key] = str_replace(' ', '', $this->line[$key]); |
830 |
|
|
$regex = '/^\d*$/'; |
831 |
|
|
break; |
832 |
|
|
case 'float': |
833 |
|
|
$this->line[$key] = str_replace(' ', '', $this->line[$key]); |
834 |
|
|
$regex = '/^(\d*[,|.])?\d*$/'; |
835 |
|
|
break; |
836 |
|
|
case 'boolean': |
837 |
|
|
$regex = '/^(Oui|Non)$/i'; |
838 |
|
|
break; |
839 |
|
|
case 'date': |
840 |
|
|
$regex = '/^\d{2}\/\d{2}\/\d{4}$/'; |
841 |
|
|
break; |
842 |
|
|
default: |
843 |
|
|
$regex = '/^.*$/m'; |
844 |
|
|
break; |
845 |
|
|
} |
846 |
|
|
if(preg_match ($regex, $this->line[$key])) { |
847 |
|
|
return true; |
848 |
|
|
} |
849 |
|
|
return false; |
850 |
|
|
} |
851 |
|
|
|
852 |
|
|
/** |
853 |
|
|
* Vérifie si une date de clôture ou une decision est présente. |
854 |
|
|
*/ |
855 |
|
|
function is_cloture() { |
856 |
|
|
if( |
857 |
|
|
empty($this->line["date_accord_tacite"]) and |
858 |
|
|
empty($this->line["date_de_rejet_tacite"]) and |
859 |
|
|
empty($this->line["date_de_refus_tacite"]) and |
860 |
|
|
(empty($this->line["date_de_decision"]) or |
861 |
|
|
empty($this->line["nature_decision"])) |
862 |
|
|
) { |
863 |
|
|
|
864 |
|
|
$this->line_error[] = _("Ce dossier n'est pas cloture"); |
865 |
|
|
} |
866 |
|
|
} |
867 |
|
|
|
868 |
|
|
/** |
869 |
|
|
* Positionne l'avis en fonction des dates de décision. |
870 |
|
|
*/ |
871 |
|
|
function set_avis_decision_from_date() { |
872 |
|
|
if(!isset($this->line["date_accord_tacite"]) or |
873 |
|
|
!isset($this->line["date_de_rejet_tacite"]) or |
874 |
|
|
!isset($this->line["date_de_refus_tacite"])) { |
875 |
|
|
return false; |
876 |
|
|
} |
877 |
|
|
$this->line["date_accord_tacite"] = trim($this->line["date_accord_tacite"]); |
878 |
|
|
$this->line["date_de_rejet_tacite"] = trim($this->line["date_de_rejet_tacite"]); |
879 |
|
|
$this->line["date_de_refus_tacite"] = trim($this->line["date_de_refus_tacite"]); |
880 |
|
|
|
881 |
|
|
if(!empty($this->line["date_accord_tacite"])) { |
882 |
|
|
$this->line["nature_decision"] = "Accord Tacite"; |
883 |
|
|
$this->line["date_de_decision"] = $this->line["date_accord_tacite"]; |
884 |
|
|
} |
885 |
|
|
if(!empty($this->line["date_de_rejet_tacite"])) { |
886 |
|
|
$this->line["nature_decision"] = "Rejet tacite"; |
887 |
|
|
$this->line["date_de_decision"] = $this->line["date_de_rejet_tacite"]; |
888 |
|
|
} |
889 |
|
|
if(!empty($this->line["date_de_refus_tacite"])) { |
890 |
|
|
$this->line["nature_decision"] = "Refus tacite"; |
891 |
|
|
$this->line["date_de_decision"] = $this->line["date_de_refus_tacite"]; |
892 |
|
|
} |
893 |
|
|
} |
894 |
|
|
|
895 |
|
|
/** |
896 |
|
|
* Récupération des clés étrangères. |
897 |
|
|
* |
898 |
|
|
* @param integer $key clé de la colonne |
899 |
|
|
* |
900 |
|
|
* @return string message d'erreur ou chaine vide |
901 |
|
|
*/ |
902 |
|
|
function get_foreign_key_id($key) { |
903 |
|
|
if(!isset($this->column[$key]["foreign_key"]) or $this->line[$key] ==="") { |
904 |
|
|
return true; |
905 |
|
|
} |
906 |
|
|
|
907 |
|
|
// Récupération de la clé étrangère avec la requète sql définie dans le |
908 |
|
|
// paramétrage du champ |
909 |
|
|
$sql = str_replace( |
910 |
|
|
'<value>', |
911 |
|
|
$this->f->db->escapeSimple($this->line[$key]), |
912 |
|
|
$this->column[$key]["foreign_key"]["sql"] |
913 |
|
|
); |
914 |
|
|
$id = $this->f->db->getOne($sql); |
915 |
|
|
|
916 |
|
|
$this->f->isDatabaseError($id); |
917 |
|
|
|
918 |
|
|
// si on trouve une valeur on remplace dans le tableau |
919 |
|
|
if ($id != "") { |
920 |
|
|
$this->line[$key] = $id; |
921 |
|
|
return true; |
922 |
|
|
} |
923 |
|
|
return false; |
924 |
|
|
} |
925 |
|
|
|
926 |
|
|
/** |
927 |
|
|
* Méthode de substition de valeurs du csv avec du paramétrage de la base. |
928 |
|
|
* |
929 |
|
|
* @param integer $key clé de la colonne |
930 |
|
|
*/ |
931 |
|
|
function set_linked_value($key) { |
932 |
|
|
if(isset($this->column[$key]["link"]) and |
933 |
|
|
$this->line[$key] != "" and |
934 |
|
|
array_key_exists($this->line[$key], $this->column[$key]["link"])) { |
935 |
|
|
|
936 |
|
|
$this->line[$key] = $this->column[$key]["link"][$this->line[$key]]; |
937 |
|
|
} |
938 |
|
|
} |
939 |
|
|
|
940 |
|
|
|
941 |
|
|
/** |
942 |
|
|
* Formate les references cadastrale. |
943 |
|
|
* |
944 |
|
|
* @param string $key clé de la colonne |
945 |
|
|
* |
946 |
|
|
* @return string vide |
947 |
|
|
*/ |
948 |
|
|
function parse_reference_cadastrale($key) { |
949 |
|
|
if($this->line[$key] == "") { |
950 |
|
|
return true; |
951 |
|
|
} |
952 |
|
|
$regex = "/^(\d{0,3})?-?(\D{1,2})-(\d{0,4})\w?$/i"; |
953 |
|
|
|
954 |
|
|
// Les ref sont sepparées par une virgule |
955 |
|
|
$reference = explode(',', $this->line[$key]); |
956 |
|
|
$ref_format = array(); |
957 |
|
|
|
958 |
|
|
foreach ($reference as $value) { |
959 |
|
|
if(trim($value) == "") { |
960 |
|
|
continue; |
961 |
|
|
} |
962 |
|
|
$array_ref = array(); |
963 |
|
|
|
964 |
|
|
// Pour chaque ref on vérifie le format |
965 |
|
|
if(!preg_match($regex, trim($value), $array_ref)) { |
966 |
|
|
|
967 |
|
|
return false; |
968 |
|
|
} |
969 |
|
|
// Et on les format pour openads |
970 |
|
|
$ref_format[] = sprintf( |
971 |
|
|
"%s%s%s", |
972 |
|
|
str_pad($array_ref[1], 3, "0", STR_PAD_LEFT), |
973 |
|
|
$array_ref[2], |
974 |
|
|
str_pad($array_ref[3], 4, "0", STR_PAD_LEFT) |
975 |
|
|
); |
976 |
|
|
} |
977 |
|
|
$this->line[$key] = implode(";", $ref_format); |
978 |
|
|
return true; |
979 |
|
|
} |
980 |
|
|
|
981 |
|
|
/** |
982 |
|
|
* Décompose une adresse postale complète en éléments distincts |
983 |
|
|
* |
984 |
|
|
* @param string $adresse_complete Adresse complète |
985 |
|
|
* |
986 |
|
|
* @return array Adresse triée |
987 |
|
|
*/ |
988 |
|
|
function explode_address($adresse_complete) { |
989 |
|
|
/** |
990 |
|
|
* Le script procède comme suit : |
991 |
|
|
* |
992 |
|
|
* - on supprime le pays |
993 |
|
|
* - Ã chaque extraction on supprime les espaces en début et fin de chaîne |
994 |
|
|
* - on récupère le numéro puis la ville puis le code postal |
995 |
|
|
* - on récupère la voie qui, si trop longue, est scindée en complément(s) |
996 |
|
|
*/ |
997 |
|
|
// Préparation du tableau de retour |
998 |
|
|
$adresse_triee = array( |
999 |
|
|
"numero" => "", |
1000 |
|
|
"voie" => "", |
1001 |
|
|
"complement1" => "", |
1002 |
|
|
"complement2" => "", |
1003 |
|
|
"cp" => "", |
1004 |
|
|
"ville" => "", |
1005 |
|
|
); |
1006 |
|
|
// Suppression du pays |
1007 |
|
|
$adresse_complete = preg_replace('/france/i', '', $adresse_complete); |
1008 |
|
|
// Suppression des espaces superflus |
1009 |
|
|
$adresse_complete = trim($adresse_complete); |
1010 |
|
|
// Récupération du numéro : NN(-NN) |
1011 |
|
|
$matches = array(); |
1012 |
|
|
// Récupération de la ville |
1013 |
|
|
$matches = array(); |
1014 |
|
|
// Si succès |
1015 |
|
|
if (preg_match('/[\D-\s]*(?:\d)*$/i', $adresse_complete, $matches)) { |
1016 |
|
|
$ville = $matches[0]; |
1017 |
|
|
// Suppression des espaces superflus |
1018 |
|
|
$ville = trim($ville); |
1019 |
|
|
$adresse_triee['ville'] = $ville; |
1020 |
|
|
// Suppression du numéro dans l'adresse complète |
1021 |
|
|
$adresse_complete = str_replace($ville, '', $adresse_complete); |
1022 |
|
|
// Suppression des espaces superflus |
1023 |
|
|
$adresse_complete = trim($adresse_complete); |
1024 |
|
|
} |
1025 |
|
|
// Récupération du code postal |
1026 |
|
|
$matches = array(); |
1027 |
|
|
// Si succès |
1028 |
|
|
if (preg_match('/[0-9]{5}$/', $adresse_complete, $matches)) { |
1029 |
|
|
$cp = $matches[0]; |
1030 |
|
|
$adresse_triee['cp'] = $cp; |
1031 |
|
|
// Suppression du numéro dans l'adresse complète |
1032 |
|
|
$adresse_complete = str_replace($cp, '', $adresse_complete); |
1033 |
|
|
// Suppression des espaces superflus |
1034 |
|
|
$adresse_complete = trim($adresse_complete); |
1035 |
|
|
} |
1036 |
|
|
// Si succès |
1037 |
|
|
if (preg_match('/^\d+(?:\s?[,-]?\s?\d{0,4})?/', $adresse_complete, $matches)) { |
1038 |
|
|
$numero = $matches[0]; |
1039 |
|
|
// Suppression des espaces superflus |
1040 |
|
|
$numero = str_replace(' ','',$numero); |
1041 |
|
|
$adresse_triee['numero'] = $numero; |
1042 |
|
|
// Suppression du numéro dans l'adresse complète |
1043 |
|
|
$adresse_complete = str_replace($numero, '', $adresse_complete); |
1044 |
|
|
// Suppression de la virgule qui suit le numéro |
1045 |
|
|
$adresse_complete = preg_replace('/^\s*,+/', '', $adresse_complete); |
1046 |
|
|
// Suppression des espaces superflus |
1047 |
|
|
$adresse_complete = trim($adresse_complete); |
1048 |
|
|
} |
1049 |
|
|
// Récupération de la voie en la divisant en deux voire trois parties |
1050 |
|
|
// si la chaîne de caractères est trop longue. |
1051 |
|
|
// Cela ne fractionne pas les mots. |
1052 |
|
|
$max_size = 30; // longueur maximum de la chaîne |
1053 |
|
|
if (strlen($adresse_complete) > $max_size ) { |
1054 |
|
|
$decoupe = explode( |
1055 |
|
|
'\n', |
1056 |
|
|
wordwrap($adresse_complete, $max_size , '\n') |
1057 |
|
|
); |
1058 |
|
|
// Première partie : la voie |
1059 |
|
|
$adresse_triee['voie'] = $decoupe[0]; |
1060 |
|
|
// Deuxième partie : le complément |
1061 |
|
|
$adresse_triee['complement1'] = $decoupe[1]; |
1062 |
|
|
// Eventuel second complément |
1063 |
|
|
if (isset($decoupe[2])) { |
1064 |
|
|
$adresse_triee['complement2'] = $decoupe[2]; |
1065 |
|
|
} |
1066 |
|
|
} else { |
1067 |
|
|
$adresse_triee['voie'] = $adresse_complete; |
1068 |
|
|
} |
1069 |
|
|
|
1070 |
|
|
foreach ($adresse_triee as $value) { |
1071 |
softime |
3856 |
if(strlen($value) > $max_size) { |
1072 |
mbroquet |
3730 |
return false; |
1073 |
|
|
} |
1074 |
|
|
} |
1075 |
|
|
|
1076 |
|
|
// Renvoi du tableau |
1077 |
|
|
return $adresse_triee; |
1078 |
|
|
} |
1079 |
|
|
|
1080 |
|
|
/** |
1081 |
|
|
* Permet de définir le numéro de version |
1082 |
|
|
*/ |
1083 |
|
|
function set_version() { |
1084 |
|
|
$regex = "/^(\w*)-?(\w*)?$/i"; |
1085 |
|
|
$dossier=array(); |
1086 |
|
|
|
1087 |
|
|
// On récupère les derniers chiffres après le possible '-' |
1088 |
|
|
preg_match($regex, $this->line["numero"], $dossier); |
1089 |
|
|
// Definition du numero de DA |
1090 |
|
|
$this->line["initial"] = $dossier[1]; |
1091 |
|
|
if($dossier[2] == '') { |
1092 |
|
|
// si pas de '-' demande initial |
1093 |
|
|
$this->line["version"] = 0; |
1094 |
|
|
} else { |
1095 |
|
|
// sinon on récupère les derniers chiffres |
1096 |
|
|
preg_match('/^(\D)?(\d*)$/', $dossier[2], $version); |
1097 |
|
|
|
1098 |
|
|
$this->line["version"] = intval($version[2]); |
1099 |
|
|
} |
1100 |
|
|
// On supprime l'extension |
1101 |
|
|
$this->line["numero"] = preg_replace ( $regex, '$1', $this->line["numero"]); |
1102 |
|
|
} |
1103 |
|
|
|
1104 |
|
|
/** |
1105 |
|
|
* Permet de définir la collectivité du dossier en fonction de son code INSEE |
1106 |
|
|
* |
1107 |
|
|
*/ |
1108 |
|
|
function set_collectivite() { |
1109 |
|
|
$sql = "SELECT om_collectivite FROM ".DB_PREFIXE."om_parametre WHERE libelle='insee' and valeur='".$this->line["insee"]."'"; |
1110 |
|
|
$om_collectivite = $this->f->db->getOne($sql); |
1111 |
|
|
|
1112 |
|
|
$this->f->isDatabaseError($om_collectivite); |
1113 |
|
|
if($om_collectivite != "") { |
1114 |
|
|
$this->line["om_collectivite"] = intval($om_collectivite); |
1115 |
|
|
return null; |
1116 |
|
|
} else { |
1117 |
|
|
$this->line_error[] = _("Le code INSEE de la commune n'est pas paramétré dans l'application"); |
1118 |
|
|
} |
1119 |
|
|
} |
1120 |
|
|
|
1121 |
|
|
/** |
1122 |
|
|
* Recupère le prefix du DI et DA en fonction du DATD |
1123 |
|
|
*/ |
1124 |
|
|
function set_prefix_di() { |
1125 |
|
|
if(!is_numeric($this->line["type"])) { |
1126 |
|
|
return; |
1127 |
|
|
} |
1128 |
|
|
$sql = "SELECT dossier_autorisation_type.code FROM " |
1129 |
|
|
.DB_PREFIXE."dossier_autorisation_type_detaille |
1130 |
|
|
JOIN ".DB_PREFIXE."dossier_autorisation_type ON |
1131 |
|
|
dossier_autorisation_type_detaille.dossier_autorisation_type=dossier_autorisation_type.dossier_autorisation_type |
1132 |
|
|
WHERE dossier_autorisation_type_detaille.dossier_autorisation_type_detaille=".$this->line["type"]; |
1133 |
|
|
|
1134 |
|
|
$prefix = $this->f->db->getOne($sql); |
1135 |
|
|
|
1136 |
|
|
$this->f->isDatabaseError($prefix); |
1137 |
|
|
|
1138 |
|
|
$this->line["initial"] = $prefix.$this->line["initial"]; |
1139 |
|
|
$this->line["numero"] = $prefix.$this->line["numero"]; |
1140 |
|
|
|
1141 |
|
|
} |
1142 |
|
|
|
1143 |
|
|
/** |
1144 |
|
|
* Vérifie si le dossier d'instruction existe en base |
1145 |
|
|
* |
1146 |
|
|
* @return boolean true si oui false sinon |
1147 |
|
|
*/ |
1148 |
|
|
function check_di_in_db() { |
1149 |
|
|
$sql = "SELECT count(*) FROM ".DB_PREFIXE."dossier WHERE dossier = '".$this->line["numero"]."'"; |
1150 |
|
|
$count = $this->f->db->getOne($sql); |
1151 |
|
|
$this->f->isDatabaseError($count); |
1152 |
|
|
if($count === "0") { |
1153 |
|
|
return null; |
1154 |
|
|
} |
1155 |
|
|
$this->line_error[] = _("Le dossier d'instruction est deja en base de donnees"); |
1156 |
|
|
} |
1157 |
|
|
|
1158 |
|
|
/** |
1159 |
|
|
* Ajout des DA. |
1160 |
|
|
* |
1161 |
|
|
* @param array $di_data données du DA |
1162 |
|
|
*/ |
1163 |
|
|
function add_dossier_autorisation($da_id, $list_di) { |
1164 |
|
|
|
1165 |
|
|
$da_valF["dossier_autorisation"] = $da_id; |
1166 |
|
|
$da_valF["exercice"] = substr($list_di[min(array_keys($list_di))]["depot_en_mairie"], -2); |
1167 |
|
|
$da_valF["insee"] = $list_di[min(array_keys($list_di))]["insee"]; |
1168 |
|
|
$da_valF["terrain_references_cadastrales"] = $list_di[min(array_keys($list_di))]["references_cadastrales"]; |
1169 |
|
|
$da_valF["terrain_adresse_voie_numero"] = $list_di[min(array_keys($list_di))]["terrain"]["numero"]; |
1170 |
|
|
$da_valF["terrain_adresse_voie"] = $list_di[min(array_keys($list_di))]["terrain"]["voie"]; |
1171 |
|
|
$da_valF["terrain_adresse_lieu_dit"] = $list_di[min(array_keys($list_di))]["terrain"]["complement1"]; |
1172 |
|
|
$da_valF["terrain_adresse_localite"] = $list_di[min(array_keys($list_di))]["terrain"]["ville"]; |
1173 |
|
|
$da_valF["terrain_adresse_code_postal"] = $list_di[min(array_keys($list_di))]["terrain"]["cp"]; |
1174 |
|
|
$surf = $this->get_surface($list_di[min(array_keys($list_di))]["surface_terrain"]); |
1175 |
|
|
$da_valF["terrain_superficie"] = (($surf===0)? null : $surf); |
1176 |
|
|
$da_valF["depot_initial"] = $list_di[min(array_keys($list_di))]["depot_en_mairie"]; |
1177 |
|
|
|
1178 |
|
|
$da_valF["om_collectivite"] = $list_di[min(array_keys($list_di))]["om_collectivite"]; |
1179 |
|
|
$da_valF["dossier_autorisation_type_detaille"] = $list_di[min(array_keys($list_di))]["type"]; |
1180 |
|
|
|
1181 |
|
|
$regex = "/^(.{2})(.{6})(.{2})(.{5})$/i"; |
1182 |
|
|
$dossier=array(); |
1183 |
|
|
// Préparation du libelle du dossier d'autorisation |
1184 |
|
|
preg_match($regex, $da_id, $dossier); |
1185 |
|
|
$da_valF["dossier_autorisation_libelle"] = $dossier[1].' '.$dossier[2].' '.$dossier[3].' '.$dossier[4]; |
1186 |
|
|
|
1187 |
|
|
// Execution de la requete d'insertion des donnees de l'attribut |
1188 |
|
|
// valF de l'objet dans l'attribut table de l'objet |
1189 |
|
|
$res = $this->f->db->autoExecute(DB_PREFIXE."dossier_autorisation", $da_valF, DB_AUTOQUERY_INSERT); |
1190 |
|
|
// Si une erreur survient |
1191 |
|
|
if ($this->f->isDatabaseError($res, true)) { |
1192 |
|
|
return false; |
1193 |
|
|
} |
1194 |
|
|
return true; |
1195 |
|
|
} |
1196 |
|
|
|
1197 |
|
|
/** |
1198 |
|
|
* Ajout des DI. |
1199 |
|
|
* |
1200 |
|
|
* @param array $di_data données du DI |
1201 |
|
|
*/ |
1202 |
|
|
function add_dossier_instruction($di_data) { |
1203 |
|
|
|
1204 |
|
|
$di_valF["dossier"] = $di_data["numero"]; |
1205 |
|
|
$regex = "/^(.{2})(.{6})(.{2})(.*)$/i"; |
1206 |
|
|
$dossier=array(); |
1207 |
|
|
// Préparation du libelle du dossier d'autorisation |
1208 |
|
|
preg_match($regex, $di_data["numero"], $dossier); |
1209 |
|
|
$di_valF["dossier_libelle"] = $dossier[1].' '.$dossier[2].' '.$dossier[3].' '.$dossier[4]; |
1210 |
|
|
$di_valF["etat"] = $di_data["etat"]; |
1211 |
|
|
|
1212 |
|
|
$di_valF["date_demande"] = $this->prepare_date($di_data["depot_en_mairie"]); |
1213 |
|
|
$di_valF["date_depot"] = $this->prepare_date($di_data["depot_en_mairie"]); |
1214 |
|
|
$di_valF["date_dernier_depot"] = $this->prepare_date($di_data["depot_en_mairie"]); |
1215 |
|
|
$di_valF["date_complet"] = $this->prepare_date($di_data["completude"]); |
1216 |
|
|
$di_valF["date_notification_delai"] = $this->prepare_date($di_data["notification_majoration"]); |
1217 |
|
|
$di_valF["date_limite"] = $this->prepare_date($di_data["dli"]); |
1218 |
|
|
$di_valF["date_decision"] = $this->prepare_date($di_data["date_de_decision"]); |
1219 |
|
|
$di_valF["date_chantier"] = $this->prepare_date($di_data["doc"]); |
1220 |
|
|
$di_valF["date_achevement"] = $this->prepare_date($di_data["daact"]); |
1221 |
|
|
$di_valF["avis_decision"] = $this->prepare_date($di_data["nature_decision"]); |
1222 |
|
|
|
1223 |
|
|
$di_valF["autorite_competente"] = $di_data["autorite"]; |
1224 |
|
|
|
1225 |
|
|
$di_valF["terrain_references_cadastrales"] = $di_data["references_cadastrales"]; |
1226 |
|
|
$di_valF["terrain_adresse_voie_numero"] = $di_data["terrain"]["numero"]; |
1227 |
|
|
$di_valF["terrain_adresse_voie"] = $di_data["terrain"]["voie"]; |
1228 |
|
|
$di_valF["terrain_adresse_lieu_dit"] = $di_data["terrain"]["complement1"]; |
1229 |
|
|
$di_valF["terrain_adresse_localite"] = $di_data["terrain"]["ville"]; |
1230 |
|
|
$di_valF["terrain_adresse_code_postal"] = $di_data["terrain"]["cp"]; |
1231 |
|
|
$surf = $this->get_surface($di_data["surface_terrain"]); |
1232 |
|
|
$di_valF["terrain_superficie"] = (($surf===0)? null : $surf); |
1233 |
|
|
|
1234 |
|
|
$di_valF["dossier_autorisation"] = $di_data["initial"]; |
1235 |
|
|
$di_valF["dossier_instruction_type"] = $di_data["dossier_instruction_type"]; |
1236 |
|
|
|
1237 |
|
|
$di_valF["version"] = $di_data["version"]; |
1238 |
|
|
|
1239 |
|
|
$di_valF["om_collectivite"] = $di_data["om_collectivite"]; |
1240 |
|
|
|
1241 |
|
|
// Si le dossier existe on le met à jour |
1242 |
|
|
if($di_data["dossier_exist"] == true) { |
1243 |
|
|
$mode = DB_AUTOQUERY_UPDATE; |
1244 |
|
|
} else { |
1245 |
|
|
$mode = DB_AUTOQUERY_INSERT; |
1246 |
|
|
} |
1247 |
|
|
|
1248 |
|
|
// Execution de la requete d'insertion des donnees de l'attribut |
1249 |
|
|
// valF de l'objet dans l'attribut table de l'objet |
1250 |
|
|
$res = $this->f->db->autoExecute( |
1251 |
|
|
DB_PREFIXE."dossier", |
1252 |
|
|
$di_valF, |
1253 |
|
|
$mode, |
1254 |
|
|
"dossier='".$di_data["numero"]."'"); |
1255 |
|
|
// Si une erreur survient |
1256 |
|
|
if ($this->f->isDatabaseError($res, true)) { |
1257 |
|
|
return false; |
1258 |
|
|
} |
1259 |
|
|
|
1260 |
|
|
// Si le champ des références cadastrales n'est pas vide |
1261 |
|
|
if ($di_valF['terrain_references_cadastrales'] != '') { |
1262 |
|
|
// Si le dossier existe, les references cadastrales peuvent êtres |
1263 |
|
|
// mise à jour on les supprimes donc pour insérer des parcelles à jour |
1264 |
|
|
$sql = "delete from ".DB_PREFIXE."dossier_parcelle where dossier='".$di_data["numero"]."'"; |
1265 |
|
|
// Execution de la requete de suppression de l'objet |
1266 |
|
|
$res = $this->f->db->query($sql); |
1267 |
|
|
// Si une erreur survient |
1268 |
|
|
if ($this->f->isDatabaseError($res, true)) { |
1269 |
|
|
return false; |
1270 |
|
|
} |
1271 |
|
|
// Parse les parcelles |
1272 |
|
|
$list_parcelles = $this->f->parseParcelles($di_valF['terrain_references_cadastrales']); |
1273 |
|
|
// A chaque parcelle une nouvelle ligne est créée dans la table |
1274 |
|
|
// dossier_parcelle |
1275 |
|
|
foreach ($list_parcelles as $parcelle) { |
1276 |
|
|
|
1277 |
|
|
// Instance de la classe dossier_parcelle |
1278 |
|
|
$dossier_parcelle = new dossier_parcelle("]", $this->db, DEBUG); |
1279 |
|
|
|
1280 |
|
|
// Valeurs à sauvegarder |
1281 |
|
|
$value = array( |
1282 |
|
|
'dossier_parcelle' => '', |
1283 |
|
|
'dossier' => $di_valF['dossier'], |
1284 |
|
|
'parcelle' => '', |
1285 |
|
|
'libelle' => $parcelle['quartier'] |
1286 |
|
|
.$parcelle['section'] |
1287 |
|
|
.$parcelle['parcelle'] |
1288 |
|
|
); |
1289 |
|
|
|
1290 |
|
|
// Ajout de la ligne |
1291 |
|
|
$dossier_parcelle->ajouter($value, $this->db, DEBUG); |
1292 |
|
|
} |
1293 |
|
|
|
1294 |
|
|
} |
1295 |
|
|
|
1296 |
|
|
return true; |
1297 |
|
|
} |
1298 |
|
|
|
1299 |
|
|
/** |
1300 |
|
|
* Mise en forme des dates. |
1301 |
|
|
* |
1302 |
|
|
* @param date $date format DD/MM/YYYY |
1303 |
|
|
* |
1304 |
|
|
* @return date format DD/MM/YYYY null si chaine vide |
1305 |
|
|
*/ |
1306 |
|
|
function prepare_date($date) { |
1307 |
|
|
if($date == '') { |
1308 |
|
|
return null; |
1309 |
|
|
} |
1310 |
|
|
return $date; |
1311 |
|
|
} |
1312 |
|
|
|
1313 |
|
|
/** |
1314 |
|
|
* Ajout des données techniques. |
1315 |
|
|
* |
1316 |
|
|
* @param array $di_data données du DI |
1317 |
|
|
*/ |
1318 |
|
|
function add_donnees_techniques($di_data) { |
1319 |
|
|
|
1320 |
|
|
$cerfa = $this->get_cerfa($di_data["type"]); |
1321 |
|
|
|
1322 |
|
|
$val_dt["donnees_techniques"] = $this->f->db->nextId(DB_PREFIXE.'donnees_techniques'); |
1323 |
|
|
$val_dt["cerfa"] = $cerfa; |
1324 |
|
|
$val_dt["dossier_instruction"] = $di_data["numero"]; |
1325 |
|
|
$val_dt["am_projet_desc"] = ""; |
1326 |
|
|
$val_dt["co_projet_desc"] = ""; |
1327 |
|
|
$val_dt["dm_projet_desc"] = ""; |
1328 |
|
|
if($di_data['type'] == 1 or $di_data['type'] == 2) { |
1329 |
|
|
$val_dt["co_projet_desc"] = $di_data["projet"]; |
1330 |
|
|
} |
1331 |
|
|
if($di_data['type'] == 4) { |
1332 |
|
|
$val_dt["am_projet_desc"] = $di_data["projet"]; |
1333 |
|
|
} |
1334 |
|
|
if($di_data['type'] == 3) { |
1335 |
|
|
$val_dt["dm_projet_desc"] = $di_data["projet"]; |
1336 |
|
|
} |
1337 |
|
|
|
1338 |
|
|
$val_dt["co_tot_log_nb"] = intval($di_data["nb_logements"]); |
1339 |
|
|
|
1340 |
|
|
$val_dt["am_terr_surf"] = $this->get_surface($di_data["surface_terrain"]); |
1341 |
|
|
|
1342 |
|
|
$val_dt["am_lotiss"] = $this->get_boolean($di_data["lotissement"]); |
1343 |
|
|
$val_dt["terr_juri_afu"] = $this->get_boolean($di_data["afu"]); |
1344 |
|
|
|
1345 |
|
|
$val_dt["code_cnil"] = $this->get_boolean($di_data["opposition_cnil"]); |
1346 |
|
|
|
1347 |
|
|
// Définition des surfaces selon destination |
1348 |
|
|
$destination = explode(',', $di_data["destination"]); |
1349 |
|
|
switch (trim($destination[0])) { |
1350 |
|
|
case 'Habitation': |
1351 |
|
|
$i = 1; |
1352 |
|
|
break; |
1353 |
|
|
case 'Hébergement hôtelier': |
1354 |
|
|
$i = 2; |
1355 |
|
|
break; |
1356 |
|
|
case 'Bureaux': |
1357 |
|
|
$i = 3; |
1358 |
|
|
break; |
1359 |
|
|
case 'Commerce': |
1360 |
|
|
$i = 4; |
1361 |
|
|
break; |
1362 |
|
|
case 'Artisanat': |
1363 |
|
|
$i = 5; |
1364 |
|
|
break; |
1365 |
|
|
case 'Industrie': |
1366 |
|
|
$i = 6; |
1367 |
|
|
break; |
1368 |
|
|
case 'Exploit. agricole ou forestière': |
1369 |
|
|
$i = 7; |
1370 |
|
|
break; |
1371 |
|
|
case 'Entrepôt': |
1372 |
|
|
$i = 8; |
1373 |
|
|
break; |
1374 |
|
|
case 'Service public ou d\'intérêt général': |
1375 |
|
|
$i = 9; |
1376 |
|
|
break; |
1377 |
|
|
|
1378 |
|
|
default: |
1379 |
|
|
$i = 1; |
1380 |
|
|
break; |
1381 |
|
|
} |
1382 |
|
|
// Tableau des surfaces |
1383 |
|
|
$val_dt["su_avt_shon".$i] = $this->get_surface($di_data["shon_existante"]); |
1384 |
|
|
$val_dt["su_cstr_shon".$i] = $this->get_surface($di_data["shon_construite"]); |
1385 |
|
|
$val_dt["su_trsf_shon".$i] = $this->get_surface($di_data["shon_transformation_shob"]); |
1386 |
|
|
$val_dt["su_chge_shon".$i] = $this->get_surface($di_data["shon_changement_destination"]); |
1387 |
|
|
$val_dt["su_demo_shon".$i] = $this->get_surface($di_data["shon_demolie"]); |
1388 |
|
|
$val_dt["su_sup_shon".$i] = $this->get_surface($di_data["shon_supprimee"]); |
1389 |
|
|
|
1390 |
|
|
// dates DOC/DAACT |
1391 |
|
|
$val_dt["doc_date"] = $this->prepare_date($di_data["doc"]); |
1392 |
|
|
$val_dt["daact_date"] = $this->prepare_date($di_data["daact"]); |
1393 |
|
|
|
1394 |
|
|
// Si les données techniques existe on les met à jour |
1395 |
|
|
if($di_data["dossier_exist"] == true) { |
1396 |
|
|
$mode = DB_AUTOQUERY_UPDATE; |
1397 |
|
|
} else { |
1398 |
|
|
$mode = DB_AUTOQUERY_INSERT; |
1399 |
|
|
} |
1400 |
|
|
// Execution de la requete d'insertion des donnees de l'attribut |
1401 |
|
|
// valF de l'objet dans l'attribut table de l'objet |
1402 |
|
|
$res = $this->f->db->autoExecute( |
1403 |
|
|
DB_PREFIXE."donnees_techniques", |
1404 |
|
|
$val_dt, |
1405 |
|
|
$mode, |
1406 |
|
|
"dossier_instruction='".$di_data["numero"]."'"); |
1407 |
|
|
|
1408 |
|
|
// On retourne l'inverse du resultat d'erreur |
1409 |
|
|
return !$this->f->isDatabaseError($res, true); |
1410 |
|
|
|
1411 |
|
|
} |
1412 |
|
|
|
1413 |
|
|
/** |
1414 |
|
|
* Ajout d'un demandeur. |
1415 |
|
|
* |
1416 |
|
|
* @param array $di_data liste des données du DI |
1417 |
|
|
*/ |
1418 |
|
|
function add_demandeur($di_data) { |
1419 |
|
|
|
1420 |
|
|
$val_demandeur["demandeur"] = $this->f->db->nextId(DB_PREFIXE.'demandeur'); |
1421 |
|
|
$val_demandeur["type_demandeur"] = 'petitionnaire'; |
1422 |
|
|
$val_demandeur["qualite"] = 'particulier'; |
1423 |
|
|
$val_demandeur["particulier_nom"] = $di_data["demandeur"]; |
1424 |
|
|
$val_demandeur["numero"] = $di_data["adresse_demandeur"]["numero"]; |
1425 |
|
|
$val_demandeur["voie"] = $di_data["adresse_demandeur"]["voie"]; |
1426 |
|
|
$val_demandeur["complement"] = $di_data["adresse_demandeur"]["complement1"]; |
1427 |
|
|
$val_demandeur["lieu_dit"] = $di_data["adresse_demandeur"]["complement2"]; |
1428 |
|
|
$val_demandeur["code_postal"] = $di_data["adresse_demandeur"]["cp"]; |
1429 |
|
|
$val_demandeur["localite"] = $di_data["adresse_demandeur"]["ville"]; |
1430 |
|
|
$val_demandeur["om_collectivite"] = $di_data["om_collectivite"]; |
1431 |
|
|
|
1432 |
|
|
// Execution de la requete d'insertion des donnees de l'attribut |
1433 |
|
|
// valF de l'objet dans l'attribut table de l'objet |
1434 |
|
|
$res = $this->f->db->autoExecute( |
1435 |
|
|
DB_PREFIXE."demandeur", |
1436 |
|
|
$val_demandeur, |
1437 |
|
|
DB_AUTOQUERY_INSERT |
1438 |
|
|
); |
1439 |
|
|
|
1440 |
|
|
if($this->f->isDatabaseError($res, true)) { |
1441 |
|
|
return false; |
1442 |
|
|
} |
1443 |
|
|
|
1444 |
|
|
$val_lien_dossier_demandeur = array( |
1445 |
|
|
'lien_dossier_demandeur' => $this->f->db->nextId(DB_PREFIXE.'lien_dossier_demandeur'), |
1446 |
|
|
'petitionnaire_principal' => "t", |
1447 |
|
|
'dossier' => $di_data["numero"], |
1448 |
|
|
'demandeur' => $val_demandeur["demandeur"] |
1449 |
|
|
); |
1450 |
|
|
// Execution de la requete d'insertion des donnees de l'attribut |
1451 |
|
|
// valF de l'objet dans l'attribut table de l'objet |
1452 |
|
|
$res = $this->f->db->autoExecute( |
1453 |
|
|
DB_PREFIXE."lien_dossier_demandeur", |
1454 |
|
|
$val_lien_dossier_demandeur, |
1455 |
|
|
DB_AUTOQUERY_INSERT |
1456 |
|
|
); |
1457 |
|
|
|
1458 |
|
|
if($this->f->isDatabaseError($res, true)) { |
1459 |
|
|
return false; |
1460 |
|
|
} |
1461 |
|
|
|
1462 |
|
|
return true; |
1463 |
|
|
} |
1464 |
|
|
|
1465 |
|
|
/** |
1466 |
|
|
* Retourne un float |
1467 |
|
|
* |
1468 |
|
|
* @param string $surf valeur à virgule |
1469 |
|
|
* |
1470 |
|
|
* @return float |
1471 |
|
|
*/ |
1472 |
|
|
function get_surface($surf) { |
1473 |
|
|
if($surf == '') { |
1474 |
|
|
return null; |
1475 |
|
|
} |
1476 |
|
|
return floatval(str_replace(',', '.', $surf)); |
1477 |
|
|
} |
1478 |
|
|
|
1479 |
|
|
/** |
1480 |
|
|
* Transforme Oui/Non en booleen interpretable par la base. |
1481 |
|
|
* |
1482 |
|
|
* @param String $bool Oui/Non |
1483 |
|
|
* |
1484 |
|
|
* @return string t/f |
1485 |
|
|
*/ |
1486 |
|
|
function get_boolean($bool) { |
1487 |
|
|
if($bool == '' or $bool == 'NULL') { |
1488 |
|
|
return null; |
1489 |
|
|
} |
1490 |
|
|
if($bool == 'Oui') { |
1491 |
|
|
return 't'; |
1492 |
|
|
} |
1493 |
|
|
if($bool == 'Non') { |
1494 |
|
|
return 'f'; |
1495 |
|
|
} |
1496 |
|
|
} |
1497 |
|
|
|
1498 |
|
|
/** |
1499 |
|
|
* Récupération du cerfa associé au DATD. |
1500 |
|
|
* |
1501 |
|
|
* @param integer $datd identifiant du DATD |
1502 |
|
|
* |
1503 |
|
|
* @return integer identifiant du cerfa |
1504 |
|
|
*/ |
1505 |
|
|
function get_cerfa($datd) { |
1506 |
|
|
$sql = "SELECT cerfa FROM ".DB_PREFIXE."dossier_autorisation_type_detaille |
1507 |
|
|
WHERE dossier_autorisation_type_detaille=".$datd; |
1508 |
|
|
$cerfa = $this->f->db->getOne($sql); |
1509 |
|
|
$this->f->isDatabaseError($cerfa); |
1510 |
|
|
return $cerfa; |
1511 |
|
|
} |
1512 |
|
|
|
1513 |
|
|
/** |
1514 |
|
|
* Méthode de mise à jour des données du DA passé en paramètre. |
1515 |
|
|
* |
1516 |
|
|
* @param string $id_da identifiant du DA |
1517 |
|
|
* |
1518 |
|
|
* @return boolean true/false |
1519 |
|
|
*/ |
1520 |
|
|
function update_dossier_autorisation($id_da) { |
1521 |
|
|
$da = new dossier_autorisation($id_da, $this->db, DEBUG); |
1522 |
|
|
return $da->majDossierAutorisation(); |
1523 |
|
|
} |
1524 |
|
|
|
1525 |
|
|
/** |
1526 |
|
|
* Récupération du code du type de dossier d'instruction. |
1527 |
|
|
* |
1528 |
|
|
* @param integer $version numero d'ordre du DI dans le DA |
1529 |
|
|
* @param array $list_di liste des DI avec leurs données |
1530 |
|
|
* |
1531 |
|
|
* @return string P/T/M |
1532 |
|
|
*/ |
1533 |
|
|
function get_dossier_instruction_type_code($version, $list_di) { |
1534 |
|
|
$list_di[$version]["demandeur"]; |
1535 |
|
|
|
1536 |
|
|
// Si version = 0 DI initial (P) |
1537 |
|
|
$type_demande = "P"; |
1538 |
|
|
if($version !== 0) { |
1539 |
|
|
// Sinon on verifie le nom du demandeur avec le DI précédent |
1540 |
|
|
// si il existe dans le tableau fourni en paramètre |
1541 |
|
|
if(isset($list_di[$version-1])) { |
1542 |
|
|
// Si different il s'agit d'un transfert |
1543 |
|
|
if($list_di[$version]["demandeur"] != $list_di[$version-1]["demandeur"]) { |
1544 |
|
|
$type_demande = "T"; |
1545 |
|
|
} else { |
1546 |
|
|
// Sinon modificatif |
1547 |
|
|
$type_demande = "M"; |
1548 |
|
|
} |
1549 |
|
|
} else { |
1550 |
|
|
// Si il n'existe pas dans le tableau on verifie en base |
1551 |
|
|
$sql_demandeur = "SELECT particulier_nom FROM ".DB_PREFIXE."demandeur |
1552 |
|
|
JOIN ".DB_PREFIXE."lien_dossier_demandeur ON lien_dossier_demandeur.demandeur=demandeur.demandeur |
1553 |
|
|
JOIN ".DB_PREFIXE."dossier ON lien_dossier_demandeur.dossier=dossier.dossier |
1554 |
|
|
WHERE lien_dossier_demandeur.dossier = '".$list_di[$version]["numero"]."' AND version<".$version." ORDER BY version DESC"; |
1555 |
|
|
$demandeur = $this->f->db->getOne($sql_demandeur); |
1556 |
|
|
$this->f->isDatabaseError($demandeur); |
1557 |
|
|
if($list_di[$version]["demandeur"] != $demandeur AND $demandeur != "") { |
1558 |
|
|
$type_demande = "T"; |
1559 |
|
|
} else { |
1560 |
|
|
$type_demande = "M"; |
1561 |
|
|
} |
1562 |
|
|
} |
1563 |
|
|
} |
1564 |
|
|
|
1565 |
|
|
return $type_demande; |
1566 |
|
|
} |
1567 |
|
|
|
1568 |
|
|
/** |
1569 |
|
|
* Récupération de l'identifiant du type de dossier d'instruction. |
1570 |
|
|
* |
1571 |
|
|
* @param integer $type dossier_autorisation_type_detaille |
1572 |
|
|
* @param string $code P/T/M |
1573 |
|
|
* |
1574 |
|
|
* @return integer identifiant du type de dossier d'instruction |
1575 |
|
|
*/ |
1576 |
|
|
function get_dossier_instruction_type($type, $code) { |
1577 |
|
|
$sql = "SELECT dossier_instruction_type FROM ".DB_PREFIXE."dossier_instruction_type WHERE dossier_autorisation_type_detaille=".$type." and code='".$code."'" ; |
1578 |
|
|
$dossier_instruction_type = $this->f->db->getOne($sql); |
1579 |
|
|
$this->f->isDatabaseError($dossier_instruction_type); |
1580 |
|
|
return $dossier_instruction_type; |
1581 |
|
|
} |
1582 |
|
|
} |
1583 |
|
|
|
1584 |
|
|
?> |