/[openfoncier]/trunk/obj/om_table.class.php
ViewVC logotype

Annotation of /trunk/obj/om_table.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 618 - (hide annotations)
Wed Nov 7 12:10:49 2012 UTC (12 years, 2 months ago) by nhaye
File size: 12580 byte(s)
Correction d'erreurs lorsque l'option d'export n'est pas activé.

1 atreal 305 <?php
2     /**
3     * Ce fichier est destine a permettre la surcharge de certaines methodes de
4     * la classe om_table pour des besoins specifiques de l'application
5     *
6     * @package openmairie_exemple
7     * @version SVN : $Id$
8     */
9    
10     /**
11     *
12     */
13     require_once PATH_OPENMAIRIE."om_table.class.php";
14    
15     /**
16     *
17     */
18     class om_table extends table {
19 nhaye 616
20     /**
21     * Tableau des type d'export possible pour le resultat de la recherche avancee
22     **/
23     var $advs_export = NULL;
24    
25     /**
26     * Retourne true si la recherche avancee est activee, false sinon.
27     *
28     * Configure la recherche au premier appel si celle ci est activee.
29     *
30     * @return bool etat de la recherche avancee: activee/desactivee
31     */
32     function isAdvancedSearchEnabled() {
33    
34     /* Si letat est deja defini, on le retourne */
35     if ($this->_etatRechercheAv != null) {
36     return $this->_etatRechercheAv;
37     }
38    
39     /* Sinon on cherche une option de type search */
40     foreach ($this->options as $option) {
41    
42     /* SI loption search est defini
43     ET quelle dispose d'un parametre advanced
44     ET que ce parametre nest pas NULL
45     ALORS la recherche avancee est defini a la valeur du parametre
46     SINON elle est desactivee */
47    
48     if ($option['type'] == 'search' and
49     key_exists('advanced', $option) and
50     !empty($option['advanced']) and
51     is_array($option['advanced'])) {
52    
53     // configuration de la liste des champs de recherche
54     $this->paramChampRechercheAv = $option['advanced'];
55    
56     // configuration du formulaire ouvert par defaut
57     if (key_exists("default_form", $option)) {
58     $this->advs_default_form = $option["default_form"];
59     }
60    
61     // configuration du nom de la table en base de donnees de l'objet
62     $this->absolute_object = $option['absolute_object'];
63    
64     // Types d'exports possible
65 nhaye 618 if (key_exists("export", $option)) {
66     $this->advs_export = $option['export'];
67     }
68 nhaye 616
69     $this->_etatRechercheAv = true;
70     return $this->_etatRechercheAv;
71     }
72     }
73    
74     $this->_etatRechercheAv = false;
75     return $this->_etatRechercheAv;
76     }
77     /**
78     * Affiche le formulaire de recherche avancee
79     * avec lien pour export
80     *
81     * @access public
82     * @return void
83     */
84     function displayAdvancedSearch() {
85    
86     /* Recuperation du nom de l'objet sur lequel la recherche seffectue */
87    
88     require_once PATH_OPENMAIRIE."formulairedyn.class.php";
89     require_once "../obj/".$this->absolute_object.".class.php";
90    
91     $form = new formulaire(NULL, 0, 0, $this->htmlChampRechercheAv);
92    
93     /* Creation dun objet vide pour pouvoir creer facilement les champs de
94     type select */
95    
96     $object = new $this->absolute_object("]", $this->db, 0);
97     $object->setSelect($form, 0, $this->db, false);
98    
99     $paramChamp = $this->paramChampRechercheAv;
100     /* Affichage du formulaire */
101     echo "\t<form action=\"";
102     $params = array("validation" => 0, "premier" => 0, "advs_id"=>$this->gen_advs_id());
103     $params_export = array("validation" => 0, "premier" => 0, "advs_id"=>$this->_advs_id);
104     echo $this->composeURL($params);
105    
106     echo "\" method=\"post\" id=\"advanced-form\">\n";
107     echo "\t\t<fieldset class=\"cadre ui-corner-all ui-widget-content adv-search-fieldset\">\n";
108     echo "\t\t<legend id=\"toggle-advanced-display\" class=\"ui-corner-all ui-widget-content ui-state-active\">";
109     echo _("Recherche");
110     echo "\t\t</legend>";
111    
112     // construction du message d'aide
113     $help_text = _('Utilisation de * pour zones de saisie').':';
114    
115     if ($this->wildcard['left'] == '') {
116     $help_text .= " "._("*ABC finit par 'ABC'.");
117     }
118    
119     if ($this->wildcard['right'] == '') {
120     $help_text .= " "._("ABC* commence par 'ABC'.");
121     }
122    
123     if ($this->wildcard['left'] == '' and $this->wildcard['right'] == '') {
124     $help_text .= " "._("*ABC* contient 'ABC'.");
125     }
126    
127     $help_text .= " "._("A*D peut correspondre a 'ABCD'.");
128    
129     if ($this->wildcard['left'] != '' and $this->wildcard['right'] != '') {
130     $help_text .= " "._("Par defaut * est ajoute au debut et a la fin des recherches.");
131     } else {
132     if ($this->wildcard['left'] != '') {
133     $help_text .= " "._("Par defaut * est toujours ajoute au debut des recherches.");
134     }
135 atreal 305
136 nhaye 616 if ($this->wildcard['right'] != '') {
137     $help_text .= " "._("Par defaut * est toujours ajoute a la fin des recherches.");
138     }
139     }
140    
141     /* Affichage du widget de recherche multicriteres classique */
142    
143     echo "\t\t\t<div id=\"adv-search-classic-fields\">";
144    
145     echo "\t\t\t\t<div class=\"adv-search-widget\">\n";
146     echo "\t\t\t\t\t<label>"._("Rechercher")."&nbsp;<input type=\"text\" name=\"recherche\" ";
147     echo "value=\"".$this->getParam("recherche")."\" ";
148     echo "class=\"champFormulaire\" /></label>\n";
149     echo "\t\t\t\t</div>\n";
150    
151     echo "\t\t\t<p class=\"adv-search-helptext\">".$help_text."</p>";
152    
153     echo "\t\t\t</div>";
154    
155     /* Affichage des widgets de recherche avancee */
156    
157     echo "\t\t\t<div id=\"adv-search-adv-fields\">";
158    
159     foreach ($this->dbChampRechercheAv as $champ) {
160    
161     /* Gestion de l'affichage de deux champs HTML date pour pouvoir
162     soumettre un intervalle. Les deux champs sont crees avec
163     deux attributs "name" differents: le premier avec le suffixe
164     "_min" et le second "_max", representant respectivement la date
165     minimale et la date maximale. */
166    
167     $champs_html = array($champ);
168    
169     if ($paramChamp[$champ]["type"] == "date" AND
170     key_exists("where", $paramChamp[$champ]) AND
171     $paramChamp[$champ]["where"] == "intervaldate") {
172    
173     $champs_html = array($champ."_min", $champ."_max");
174    
175     /* Gestion de l'affichage de deux champs HTML checkbox pour pouvoir
176     soumettre des valeurs booleennes. Les deux champs sont crees avec
177     deux attributs "name" differents: le premier avec le suffixe
178     "_true" et le second "_false". */
179    
180     } elseif ($paramChamp[$champ]["type"] == "checkbox" AND
181     key_exists("where", $paramChamp[$champ]) AND
182     ($paramChamp[$champ]["where"] == "boolean")) {
183    
184     $champs_html = array($champ."_true", $champ."_false");
185     }
186    
187     foreach ($champs_html as $champ_html) {
188    
189     $form->setType($champ_html, $paramChamp[$champ]["type"]);
190    
191     // libelle des intervales de date
192     if ($paramChamp[$champ]['type'] == 'date' and
193     isset($paramChamp[$champ]['where']) and
194     $paramChamp[$champ]['where'] == 'intervaldate') {
195    
196     // premier champ
197     if ($champ_html == $champ.'_min') {
198    
199     $form->setBloc($champ_html, 'D',
200     $paramChamp[$champ]['libelle'],
201     'intervaldate');
202    
203     // si lib1 n'existe pas, on utilise `du`
204     if (isset($paramChamp[$champ]['lib1'])) {
205     $form->setLib($champ_html,
206     $paramChamp[$champ]['lib1']);
207     } else {
208     $form->setLib($champ_html, _('du'));
209     }
210     }
211    
212     // second champ
213     if ($champ_html == $champ.'_max') {
214    
215     $form->setBloc($champ_html, 'F');
216    
217     // si lib2 n'existe pas, on utilise `au`
218     if (isset($paramChamp[$champ]['lib2'])) {
219     $form->setLib($champ_html,
220     $paramChamp[$champ]['lib2']);
221     } else {
222     $form->setLib($champ_html, _('au'));
223     }
224     }
225    
226     } else {
227     $form->setLib($champ_html, $paramChamp[$champ]["libelle"]);
228     }
229    
230     if (isset($paramChamp[$champ]["taille"])) {
231     $form->setTaille($champ_html, $paramChamp[$champ]["taille"]);
232     }
233    
234     if (isset($paramChamp[$champ]["max"])) {
235     $form->setMax($champ_html, $paramChamp[$champ]["max"]);
236     }
237    
238     if ($paramChamp[$champ]["type"] == "select" AND
239     key_exists("subtype", $paramChamp[$champ]) AND
240     $paramChamp[$champ]["subtype"] == "manualselect") {
241     $form->setSelect($champ_html, $paramChamp[$champ]["args"]);
242     }
243    
244     if ($paramChamp[$champ]["type"] == "date") {
245     $form->setOnchange($champ_html,"fdate(this)");
246     }
247    
248     if (isset($_POST[$champ_html]) AND $_POST[$champ_html] != "") {
249     $form->setVal($champ_html, $_POST[$champ_html]);
250     }
251     }
252    
253     }
254    
255     $form->entete();
256     $form->afficher($this->htmlChampRechercheAv, 0, false, false);
257    
258    
259    
260     $form->enpied();
261    
262     /* Message d'aide */
263    
264     echo "<div class=\"visualClear\"></div>";
265     echo "<p class=\"adv-search-helptext\">".$help_text."</p>";
266    
267    
268     echo "\t\t\t</div>";
269    
270     /* Fin du fieldset recherche avancee */
271    
272     echo "\t\t</fieldset>\n";
273    
274     /* Affichage des boutons de controle du formulaire */
275    
276     // si une recherche avancee est faite
277     if (isset($_POST["advanced-search-submit"])) {
278     // on affiche la recherche avancee
279     echo "\t\t<button type=\"submit\" id=\"adv-search-submit\" name=\"advanced-search-submit\">";
280    
281     // si une recherche simple est faite
282     } elseif (isset($_POST["classic-search-submit"])) {
283     // on affiche la recherche simple
284     echo "\t\t<button type=\"submit\" id=\"adv-search-submit\" name=\"classic-search-submit\">";
285    
286     // si aucune recherche n'est faite, on affiche le formulaire configure par defaut
287     } else {
288     if ($this->advs_default_form == "advanced") {
289     echo "\t\t<button type=\"submit\" id=\"adv-search-submit\" name=\"advanced-search-submit\">";
290     } else {
291     echo "\t\t<button type=\"submit\" id=\"adv-search-submit\" name=\"classic-search-submit\">";
292     }
293     }
294    
295     echo _("Recherche");
296     echo "</button>\n";
297    
298     echo "\t\t<a href=\"#\" class=\"raz_advs\" onclick=\"clear_form($('#advanced-form'));\">";
299     echo _("Vider le formulaire");
300     echo "</a>";
301 nhaye 618 if(isset($this->advs_export) AND !empty($this->advs_export)) {
302     echo "<div id=\"advs_export\">";
303     echo _("Exporter au format")." : ";
304     foreach($this->advs_export as $format) {
305     echo "<a href=\"../app/advs_export_".$format.".php?".$this->composeExportUrl($params_export)."\" >$format</a>";
306     }
307     echo "</div>";
308 nhaye 616 }
309     echo "\t</form>\n";
310     }
311    
312     function gen_advs_id() {
313     return str_replace(array('.',','), '', microtime(true));
314     }
315    
316     /**
317     *
318     */
319     function composeExportUrl($params = array()) {
320    
321     // aff correspond au fichier vers lesquels tous les liens vont pointer
322     // (exemple : ../scr/tab.php ou ../scr/soustab.php)
323     $return = "";
324     //
325     foreach ($params as $param => $value) {
326     if (!array_key_exists($param, $this->params)) {
327     $return .= $param."=".$params[$param]."&amp;";
328     }
329     }
330     foreach ($this->params as $param => $value) {
331     if (isset($params[$param])) {
332     $return .= $param."=".$params[$param]."&amp;";
333     } else {
334     $return .= $param."=".$value."&amp;";
335     }
336     }
337     if ($return != "") {
338     substr($return, 0, strlen($return)-5);
339     }
340    
341     //
342     return $return;
343    
344     }
345    
346 atreal 305 }
347    
348     ?>

Properties

Name Value
svn:keywords Id

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26