1 |
<?php |
2 |
/** |
3 |
* Ce script permet de creer un duplicata d'un enregistrement |
4 |
* et des ses enregistrements liés |
5 |
* |
6 |
* @package openfoncier |
7 |
* @version SVN : $Id$ |
8 |
* |
9 |
* @todo Il faut gerer ce script d'une maniere differente : |
10 |
* il faudrait integrer la duplication d'enregistrement dans |
11 |
* om_dbform.class.php pour le gerer grace a la meme interface que |
12 |
* form.php. |
13 |
*/ |
14 |
|
15 |
// Fichier requis |
16 |
require_once "../obj/utils.class.php"; |
17 |
require_once '../obj/om_formulaire.class.php'; |
18 |
|
19 |
// Instance de la classe utils |
20 |
$f = new utils(NULL, "copie", _("Copie")); |
21 |
|
22 |
// Identifiant de l'objet metier a copier |
23 |
(isset($_GET['idx']) ? $idx = $_GET['idx'] : $idx = ""); |
24 |
// Nom de l'objet metier |
25 |
(isset($_GET['obj']) ? $obj = $_GET['obj'] : $obj = ""); |
26 |
// Nom de l'objet metier associe |
27 |
(isset($_GET['objsf']) ? $objsf = $_GET['objsf'] : $objsf = ""); |
28 |
// Paramètres pour le bouton retour |
29 |
(isset($_GET['premier']) ? $premier = $_GET['premier'] : $premier = 0); |
30 |
(isset($_GET['tricol']) ? $tricol = $_GET['tricol'] : $tricol = ""); |
31 |
(isset($_GET['recherche']) ? $recherche = $_GET['recherche'] : $recherche = ""); |
32 |
(isset($_GET['selectioncol']) ? $selectioncol = $_GET['selectioncol'] : $selectioncol = ""); |
33 |
(isset($_GET['advs_id']) ? $advs_id = $_GET['advs_id'] : $advs_id = ""); |
34 |
|
35 |
// Description de la page |
36 |
$description = _("Cette page permet de dupliquer un enregistrement et ses enregistrements associes."); |
37 |
$f->displayDescription($description); |
38 |
|
39 |
// Bouton retour |
40 |
$bouton_retour = "<a class=\"retour\" href=". |
41 |
"\"../scr/tab.php?obj=%s&premier=%s&tricol=%s". |
42 |
"&recherche=%s&selectioncol=%s&advs_id=%s\">". |
43 |
_("Retour"). |
44 |
"</a>"; |
45 |
|
46 |
// Si des données sont envoyées par le formulaire |
47 |
if (!empty($_POST['idx']) |
48 |
&& !empty($_POST['obj'])) { |
49 |
|
50 |
// Identifiant de l'objet metier a copier |
51 |
(isset($_POST['idx']) ? $idx = $_POST['idx'] : $idx = ""); |
52 |
// Nom de l'objet metier |
53 |
(isset($_POST['obj']) ? $obj = $_POST['obj'] : $obj = ""); |
54 |
// Nom des objets metier associés |
55 |
(isset($_POST['objsf']) ? $objsf = $_POST['objsf'] : $objsf = ""); |
56 |
|
57 |
// Liste des objets associés |
58 |
$listObjsf = explode(",", $objsf); |
59 |
foreach ($listObjsf as $key => $value) { |
60 |
// Si l'objet n'est pas checké |
61 |
if (!array_key_exists($value, $_POST)) { |
62 |
// Supprime l'objet de la liste |
63 |
unset($listObjsf[$key]); |
64 |
} |
65 |
} |
66 |
|
67 |
// Liste des objets associés choisis |
68 |
$objsf_checked = implode(",", $listObjsf); |
69 |
|
70 |
// Utilisation de la fonction copie |
71 |
$return = $f->copier($idx, $obj, $objsf_checked); |
72 |
|
73 |
// Message affiché à l'utilisateur |
74 |
$message = $return['message']; |
75 |
// Type du message |
76 |
$message_type = $return['message_type']; |
77 |
|
78 |
// Affiche le message |
79 |
$f->displayMessage($message_type, $message); |
80 |
|
81 |
// Permet de faire une recherche sur l'identifiant du duplicata |
82 |
$recherche = (isset($return[$obj.'_'.$idx])) ? $return[$obj.'_'.$idx] : ""; |
83 |
// Permet que la recherche se fasse seulement sur l'identifiant |
84 |
$selectioncol = 0; |
85 |
|
86 |
// Affiche le bouton de retour |
87 |
printf("<div class=\"formControls\">"); |
88 |
printf($bouton_retour, $obj, $premier, $tricol, $recherche, $selectioncol, $advs_id); |
89 |
printf("</div>"); |
90 |
|
91 |
// Sinon |
92 |
} else { |
93 |
|
94 |
// Champs du formulaire = objet métier associés |
95 |
if ($objsf != '') { |
96 |
$champs = explode(",", $objsf); |
97 |
} |
98 |
$champs[] = "idx"; |
99 |
$champs[] = "obj"; |
100 |
$champs[] = "objsf"; |
101 |
|
102 |
// Création d'un nouvel objet de type formulaire |
103 |
$form = new formulaire(NULL, 0, 0, $champs); |
104 |
|
105 |
// Type des champs |
106 |
foreach ($champs as $key) { |
107 |
$form->setType($key, 'checkbox'); |
108 |
} |
109 |
$form->setType("idx", 'hidden'); |
110 |
$form->setType("obj", 'hidden'); |
111 |
$form->setType("objsf", 'hidden'); |
112 |
|
113 |
// Libellés des champs |
114 |
foreach ($champs as $key) { |
115 |
$form->setLib($key, _($key)); |
116 |
} |
117 |
|
118 |
// Valeur des champs |
119 |
foreach ($champs as $key) { |
120 |
$form->setVal($key, 'f'); |
121 |
} |
122 |
$form->setVal("idx", $idx); |
123 |
$form->setVal("obj", $obj); |
124 |
$form->setVal("objsf", $objsf); |
125 |
|
126 |
// Affichage des champs |
127 |
$i = 0; |
128 |
$lastKey = ""; |
129 |
foreach ($champs as $key) { |
130 |
if ($i == 0) { |
131 |
$form->setFieldset($key, 'D', _("Liste des objets associes"), ""); |
132 |
} |
133 |
$form->setBloc($key, 'DF', "", ""); |
134 |
$lastKey = $key; |
135 |
$i++; |
136 |
} |
137 |
$form->setFieldset($lastKey, 'F'); |
138 |
|
139 |
// Ouverture du formulaire |
140 |
printf("<form method=\"POST\" action=\"valid_copie.php?obj=".$obj."&objsf=bible,lien_dossier_instruction_type_evenement,transition&idx=".$idx."&premier=".$premier."&tricol=".$tricol."&recherche=".$recherche."&selectioncol=".$selectioncol."&advs_id=".$advs_id."\" name=\"f2\">"); |
141 |
|
142 |
// Champs du formulaire |
143 |
$form->entete(); |
144 |
$form->afficher($champs, 0, false, false); |
145 |
if ($objsf == '') { |
146 |
printf(_("Aucun objet associe existant.")); |
147 |
} |
148 |
$form->enpied(); |
149 |
|
150 |
// Bouton "Copier" et "Retour" |
151 |
printf("<div class=\"formControls\">"); |
152 |
printf('<input id="button-%1$s" type="submit" class="om-button ui-button ui-widget ui-state-default ui-corner-all" value="%1$s" role="button" aria-disabled="false">', _("Copier")); |
153 |
printf($bouton_retour, $obj, $premier, $tricol, $recherche, $selectioncol, $advs_id); |
154 |
printf("</div>"); |
155 |
|
156 |
// Fermeture du formulaire |
157 |
printf("</form>"); |
158 |
} |
159 |
|
160 |
?> |