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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26