Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.QueryObj.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generated Header (not documented yet)
8  *
9  * @author Anakeen
10  * @version $Id: Class.QueryObj.php,v 1.3 2004/03/22 15:21:40 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 /**
15  */
16 // ---------------------------------------------------------------------------
17 // anakeen 2000 - Yannick Le Briquer
18 // ---------------------------------------------------------------------------
19 // This program is free software; you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation; either version 2 of the License, or (at
22 // your option) any later version.
23 //
24 // This program is distributed in the hope that it will be useful, but
25 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 // for more details.
28 //
29 // You should have received a copy of the GNU General Public License along
30 // with this program; if not, write to the Free Software Foundation, Inc.,
31 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 // ---------------------------------------------------------------------------
33 // $Id: Class.QueryObj.php,v 1.3 2004/03/22 15:21:40 eric Exp $
34 // $Log: Class.QueryObj.php,v $
35 // Revision 1.3 2004/03/22 15:21:40 eric
36 // change HTTP variable name to put register_globals = Off
37 //
38 // Revision 1.2 2003/08/18 15:46:42 eric
39 // phpdoc
40 //
41 // Revision 1.1 2002/01/08 12:41:34 eric
42 // first
43 //
44 // Revision 1.1.1.1 2000/10/05 17:29:10 yannick
45 // Importation
46 //
47 // Revision 1.17 2000/09/15 07:48:23 marianne
48 // Modif libelle N'est pad Vide
49 //
50 // Revision 1.16 2000/09/15 07:47:27 marianne
51 // Correction bug sur 'null' et 'not null'
52 //
53 // Revision 1.15 2000/09/04 14:50:24 marianne
54 // Ajout booleen dans GenPage pour ne pas afficher le filtre
55 //
56 // Revision 1.14 2000/09/01 12:37:45 marianne
57 // suppression d'un /input en trop et modif classe Total
58 //
59 // Revision 1.13 2000/09/01 12:35:58 marianne
60 // celspacing=>cellspacing
61 //
62 // Revision 1.12 2000/08/03 14:11:55 marianne
63 // initialisation de dtart et slice
64 //
65 // Revision 1.11 2000/07/29 08:39:10 marc
66 // Mise en forme formulaire de recherche
67 //
68 // Revision 1.10 2000/07/09 08:00:55 yannick
69 // Mise au point V2.0
70 //
71 // Revision 1.9 2000/07/07 10:11:08 yannick
72 // Mise au point
73 //
74 // Revision 1.8 2000/07/03 13:30:35 yannick
75 // Ajout Last Query
76 //
77 // Revision 1.7 2000/06/30 12:45:46 yannick
78 // Retourne faux si le DbId n'existe pas
79 //
80 // Revision 1.6 2000/06/16 16:04:36 yannick
81 // mise au point
82 //
83 // Revision 1.5 2000/06/07 14:33:54 yannick
84 // RAZ num page sur changement de lettre
85 //
86 // Revision 1.4 2000/06/07 14:17:55 yannick
87 // QueryObj
88 //
89 // Revision 1.3 2000/06/05 16:13:55 yannick
90 // Fonction tournepage OK
91 //
92 // Revision 1.2 2000/06/05 13:58:27 yannick
93 // Mise au point
94 //
95 // Revision 1.1 2000/05/30 15:03:32 yannick
96 // Nouveau
97 //
98 // Revision 1.4 2000/05/30 09:33:50 xavier
99 // mise à jour du 05 30
100 //
101 // Revision 1.1 2000/05/19 09:56:15 admin
102 // init
103 //
104 // ---------------------------------------------------------------------------
105 // This class is designed to perform query constructs on objects
106 // It returns a table of objects that match the query
107 //
108 // It gives the HTML/JScript element for the gui
109 // and it gives the result of the query
110 $CLASS_QUERYOBJ_PHP = '$Id: Class.QueryObj.php,v 1.3 2004/03/22 15:21:40 eric Exp $';
111 
112 include_once ('Class.Out.php');
113 include_once ('Class.Table.php');
114 include_once ('Class.Log.php');
115 include_once ('Class.QueryDb.php');
116 
117 class QueryObj extends QueryDb
118 {
119 
120  var $down = "&nbsp;v";
121  var $up = "&nbsp;^";
122 
123  var $display_alpha = "FALSE";
124  var $alpha_default = "NONE";
125 
127  {
128  //
129  $this->init("string", "");
130  $this->init("operator", "none");
131  $this->init("criteria", "");
132  $this->init("case", "");
133  $this->init("order_by", "");
134  $this->init("casse", "NON");
135  $this->init("alpha_criteria", "");
136  $this->init("desc", "down");
137  $this->init("start", 0);
138  $this->init("slice", 20);
139 
140  $this->table = new Table();
141  $this->table->start = $this->start;
142  $this->table->slice = $this->slice;
143  $this->Query($dbaccess, $class);
144  }
145 
146  function AlphaClause()
147  {
148  $out = "";
149  if (($this->display_alpha == "TRUE") && ($this->alpha != "ALL") && ($this->alpha != "NONE")) {
150  $out = " upper({$this->alpha_criteria}) like upper('{$this->alpha}%') ";
151  }
152  return ($out);
153  }
154  // Create a complete page with the form, the table, the links...
155  // url = url called back on next/prev/start/end button (the calling page)
156  // nores = HTML message displayed when the query result is empty
157  // complete = boolean : say TRUE if you need that the object list is completely
158  // initiated (means that some attributes of the object are checked out from
159  // different tables). say FALSE if all the fields you need are checked out in
160  // the query. If you use complete on large results, it may take a while and
161  // a lot of memory.
162  function GenPage($url, $nores, $complete = "FALSE", $display_form = "YES")
163  {
164 
165  $this->init("alpha", $this->alpha_default);
166 
167  $this->table->start = $this->start;
168  $this->table->slice = $this->slice;
169 
170  $o = new Out();
171 
172  $o->cat($this->GenForm($url, $display_form));
173 
174  if (($this->display_alpha == "TRUE") && ($this->alpha == "NONE")) {
175  return ($o->flush());
176  }
177 
178  if ($complete == "FALSE") {
179  $this->table->array = $this->Query($this->start, $this->slice, "TABLE");
180  } else {
181  $this->table->array = $this->Query($this->start, $this->slice, "LISTC");
182  $this->table->arrayobj = "TRUE";
183  }
184 
185  $this->table->sort_link = "javascript:void(0)\\\" onClick=\\\"SortPage(
186  document.QueryObj,'%s');return false";
187  $this->table->page_link = "javascript:void(0)\\\" onclick=\\\"GoPage(
188  document.QueryObj,%s,%s);return false";
189 
190  if (!isset($this->table->headcontent["$this->order_by"])) {
191  $this->table->headcontent["$this->order_by"] = $this->order_by;
192  }
193  $desc = $this->desc;
194  $this->table->headcontent["$this->order_by"].= $this->$desc;
195 
196  if ($this->nb == 0) {
197  $o->cat($nores);
198  } else {
199  $o->cat($this->table->get());
200  }
201 
202  $o->cat('<table border=0 cellspacing=0 cellpadding=0 width="100%">
203  <tr><td class="textinv2">Total : ' . $this->nb . '</td></tr>
204  </table>');
205 
206  return ($o->flush());
207  }
208  // Generate the Query Form
209  function GenForm($url, $display_form = "YES")
210  {
211 
212  if (sizeof($this->basic_elem->criterias) == 0) return ("");
213  $this->log->debug("Nouvelle forme");
214 
215  $o = new Out();
216  // JavaScript Construct
217  $o->cat('
218  <script language="javascript">
219  function selFiltre(form_cour, champ) {
220  var oper_sel=form_cour.p_operator[form_cour.p_operator.selectedIndex].value;
221  var crit_sel=form_cour.p_criteria[form_cour.p_criteria.selectedIndex].value;
222  var crit_idx=form_cour.p_criteria.selectedIndex;
223  tab_types = new Array();');
224 
225  $ind = 0;
226  // table of types
227  reset($this->basic_elem->criterias);
228  foreach ($this->basic_elem->criterias as $k => $v) {
229  $o->cat("tab_types[{$ind}]=\"" . $v["type"] . "\";");
230  $ind++;
231  }
232 
233  $o->cat('
234  if ((tab_types[crit_idx]=="NUM") && (oper_sel=="nlike")) {
235  alert ("Un champ numérique ne peut-être recherché avec \'Ne Contient Pas\'!!");
236  form_cour.p_operator.options[0].selected=true;
237  }
238  if ((tab_types[crit_idx]=="NUM") && (oper_sel=="like")) {
239  alert ("Un champ numérique ne peut-être recherché avec \'Contient\'!!");
240  form_cour.p_operator.options[0].selected=true;
241  }
242  if ((crit_sel=="") && (champ.name=="p_criteria")) {
243  form_cour.p_string.value = "";
244  form_cour.p_operator.options[0].selected=true;
245  }
246  }');
247 
248  $o->cat('
249  function checkFiltre(form_cour) {
250  ');
251  if ($display_form == 'YES') {
252  $o->cat('
253  var ok=true;
254  var oper_sel=form_cour.p_operator[form_cour.p_operator.selectedIndex].value;
255  var crit_sel=form_cour.p_criteria[form_cour.p_criteria.selectedIndex].value;
256  var casse=form_cour.chk_casse.checked;
257  if (!casse) {
258  form_cour.p_casse.value="NON";
259  } else {
260  form_cour.p_casse.value="OUI";
261  }
262  if ((crit_sel=="") && (oper_sel!="")) {
263  ok=false;
264  alert ("Vous devez choisir un critere!!"); }
265  if ((crit_sel!="") && (oper_sel=="")) {
266  ok=false;
267  alert ("Vous devez choisir un operator!!"); }
268  return(ok);
269  }
270  ');
271  } else {
272  $o->cat(' var ok=true; return(ok); }');
273  }
274  $o->cat('
275 
276  function queryFiltre(form_cour) {
277 
278  ok = checkFiltre(form_cour);
279  if (ok) {
280  form_cour.p_start.value=0;
281  form_cour.submit();
282  }
283  }
284 
285  function resetFiltre(form_cour) {
286  form_cour.p_criteria.selectedIndex=0;
287  form_cour.p_operator.selectedIndex=0;
288  form_cour.p_start.value=0;
289  form_cour.p_string.value="";
290  form_cour.submit();
291  }
292 
293  function GoPage(form_cour,start,slice) {
294  form_cour.p_start.value = start;
295  form_cour.p_slice.value = slice;
296  ok=checkFiltre(form_cour);
297  if (ok) {form_cour.submit();}
298  }
299 
300  function SortPage(form_cour,order) {
301  if (form_cour.p_order_by.value == order) {
302  if (form_cour.p_desc.value == "down") {
303  form_cour.p_desc.value = "up";
304  } else {
305  form_cour.p_desc.value = "down";
306  }
307  } else {
308  form_cour.p_order_by.value = order;
309  form_cour.p_desc.value = "down";
310  }
311  ok=checkFiltre(form_cour);
312  if (ok) {form_cour.submit();}
313  }
314 
315  function setAlpha(form_cour,car) {
316  form_cour.p_alpha.value = car;
317  form_cour.p_start.value = 0;
318  ok=checkFiltre(form_cour);
319  if (ok) {form_cour.submit();}
320  }
321 
322  </script>');
323  // Form Construct
324  $o->cat('
325  <form name="QueryObj" method="POST" action="' . $url . '">');
326  if ($display_form == "YES") {
327  $o->cat('<table bgcolor="#F2F2F2" border="0" cellspacing="0" cellpadding="2" >
328  <tr>');
329  // Alpha Index
330  if ($this->display_alpha == "TRUE") {
331  $o->cat('<td><small><select name="p_alpha_criteria">\n');
332  reset($this->basic_elem->criterias);
333  foreach ($this->basic_elem->criterias as $k => $v) {
334  if ($v["type"] == "TXT") {
335  if ($this->alpha_criteria == $k) {
336  $o->cat("<OPTION SELECTED VALUE=\"{$k}\">" . $v["libelle"] . "\n");
337  } else {
338  $o->cat("<OPTION VALUE=\"{$k}\">" . $v["libelle"] . "\n");
339  }
340  }
341  }
342  $o->cat('</select></small></td>');
343  $o->cat('<td nowrap colspan="3">');
344  for ($i = ord("A"); $i <= ord("Z"); $i++) {
345  $c = chr($i);
346  $o->cat(' ');
347  if ($this->alpha == $c) {
348  $o->cat('<b>[');
349  }
350  $o->cat("<a href=\"javascript:void(0)\"
351  onClick=\"setAlpha(document.QueryObj,'" . $c . "');return false\">");
352  $o->cat('<font size="-1">' . $c . '</font></a>');
353  if ($this->alpha == $c) {
354  $o->cat(']</b>');
355  }
356  }
357  $o->cat("</td><td align=\"center\">");
358  if ($this->alpha == "ALL") $o->cat('<b>[');
359  $o->cat("<a href=\"javascript:void(0)\"
360  onClick=\"setAlpha(document.QueryObj,'ALL');return false\">");
361  $o->cat('<font size="-1">Tout</font></a>');
362  if ($this->alpha == "ALL") $o->cat(']</b>');
363  $o->cat("<br>");
364  if ($this->alpha == "NONE") {
365  $o->cat('<b>[');
366  }
367  $o->cat("<a href=\"javascript:void(0)\"
368  onClick=\"setAlpha(document.QueryObj,'NONE');return false\">");
369  $o->cat("<font size=\"-1\">Rien</font></a>");
370  if ($this->alpha == "NONE") {
371  $o->cat(']</b>');
372  }
373  $o->cat("</tr>");
374  }
375  // Criteria
376  $o->cat("<tr>
377  <TD><SMALL><SELECT NAME=\"p_criteria\"
378  onChange=\"selFiltre(document.QueryObj,this);\">\n");
379  reset($this->basic_elem->criterias);
380  foreach ($this->basic_elem->criterias as $k => $v) {
381  if ($this->criteria == $k) {
382  $o->cat("<OPTION SELECTED VALUE=\"{$k}\">" . $v["libelle"] . "\n");
383  } else {
384  $o->cat("<OPTION VALUE=\"{$k}\">" . $v["libelle"] . "\n");
385  }
386  }
387  $o->cat("</SELECT></SMALL></TD>\n");
388  // Operator
389  $o->cat("
390  <TD><SMALL><SELECT NAME=\"p_operator\"
391  onChange=\"selFiltre(document.QueryObj,this);\">\n");
392  foreach ($this->operators as $k => $v) {
393  if ($this->operator == $k) {
394  $o->cat("<OPTION SELECTED VALUE=\"{$k}\">" . $v["lib"] . "\n");
395  } else {
396  $o->cat("<OPTION VALUE=\"{$k}\">" . $v["lib"] . "\n");
397  }
398  }
399  $o->cat("</SELECT></SMALL></TD>\n");
400  // String (value)
401  $o->cat('
402  <td><small><input name="p_string" maxlength=15 size=10 class="finput"
403  value="' . $this->string . '">
404  </td>');
405  // Query buttons
406  $o->cat('
407  <td><a href="javascript:void(0)"
408  onClick="queryFiltre(document.QueryObj);return false">
409  <font size="-1">Recherche</font></a>
410  <a href="javascript:void(0)"
411  onClick="resetFiltre(document.QueryObj);return false">
412  <font size="-1">Réinitialiser</font></a>
413  </td>');
414  // Case sensitivity
415  $o->cat('
416  <td nowrap><input type="checkbox"');
417  if ($this->casse == "OUI") {
418  $o->cat(' checked ');
419  }
420  $o->cat('name="chk_casse"><font size="-1">Respecter la casse</font></td>');
421  // TODO
422  // Form end
423  $o->cat('
424  </tr></table>');
425  }
426  $o->cat('<input type="hidden" name="p_slice" value="' . $this->slice . '">
427  <input type="hidden" name="p_start" value="' . $this->start . '">
428  <input type="hidden" name="p_order_by" value="' . $this->order_by . '">
429  <input type="hidden" name="p_casse" value="' . $this->casse . '">
430  <input type="hidden" name="p_desc" value="' . $this->desc . '">
431  <input type="hidden" name="p_alpha" value="' . $this->alpha . '">
432  </form>');
433 
434  return ($o->flush());
435  }
436 
437  function init($attr, $default)
438  {
439  global $_POST;
440  if (is_array($_POST) && isset($_POST["p_$attr"])) {
441  $this->$attr = $_POST["p_$attr"];
442  } else {
443  if (isset($this->basic_elem->def[$attr])) {
444  $this->$attr = $this->basic_elem->def[$attr];
445  } else {
446  $this->$attr = $default;
447  }
448  }
449  }
450 }
451 ?>
global $_POST
Definition: chgpasswd.php:17
$s slice
Query($start=0, $slice=0, $res_type="LIST", $p_query="")
GenForm($url, $display_form="YES")
$s start
if($dbaccess=="") $o
$query order_by
GenPage($url, $nores, $complete="FALSE", $display_form="YES")
$dbaccess
Definition: checkVault.php:17
init($attr, $default)
QueryObj($dbaccess, $class)
$class
Definition: updateclass.php:38
$CLASS_QUERYOBJ_PHP
← centre documentaire © anakeen