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