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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.305  
changed lines
  Added in v.616

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26