54 include_once (
'Class.Out.php');
55 include_once (
'Class.Table.php');
56 include_once (
'Class.Log.php');
73 "lib" =>
"Commence par",
75 "param" =>
"SEMIPERCENT"
83 "lib" =>
"Ne Contient Pas",
88 "lib" =>
"Est égal à",
93 "lib" =>
"Est différent de",
98 "lib" =>
"Est Supérieur à",
103 "lib" =>
"Est Inférieur à",
108 "lib" =>
"N'est pas Vide",
109 "oper" =>
"is not null",
129 $this->log =
new Log(
"",
"Query",
"$class");
130 $this->log->debug(
"Nouveau QueryObj $dbaccess/$class");
135 $this->
init(
"string",
"");
136 $this->
init(
"operator",
"none");
137 $this->
init(
"criteria",
"");
138 $this->
init(
"case",
"");
139 $this->
init(
"order_by",
"");
140 $this->
init(
"casse",
"NON");
141 $this->
init(
"alpha_criteria",
"");
142 $this->
init(
"desc",
"down");
143 $this->
init(
"start", 0);
144 $this->
init(
"slice", 20);
146 $this->table =
new Table();
158 if ($p_query ==
'') {
161 reset($this->basic_elem->fields);
162 while (list($k, $v) = each($this->basic_elem->fields)) {
163 $select =
$select .
" " . $this->basic_elem->dbtable .
"." . $v .
",";
166 reset($this->basic_elem->sup_fields);
167 while (list($k, $v) = each($this->basic_elem->sup_fields)) {
172 $from = $this->basic_elem->dbtable;
173 reset($this->basic_elem->sup_tables);
174 while (list($k, $v) = each($this->basic_elem->sup_tables)) {
178 $query =
"select " . $this->distinct .
" {$select}
183 if ($where[$nb_where] !=
"") {
187 if ($where[$nb_where] !=
"") {
191 if ($where[$nb_where] !=
"") {
199 while (list($k, $v) = each($where)) {
213 if ($this->desc ==
"up") {
222 $this->dbid = pg_connect(
"{$this->dbaccess}");
223 ### echo $this->dbaccess;
224 $chrono = microtime();
225 ###$this->log->debug("Requète : $query / $chrono");
226 $this->LastQuery =
$query;
227 ### echo "<br>$query";
228 $res = pg_exec($this->dbid,
$query);
230 if (!$res)
return FALSE;
232 $this->nb = pg_numrows($res);
234 if ($this->nb == 0)
return FALSE;
235 $chrono = microtime();
236 $this->log->debug(
"Résultats : {$this->nb} / $chrono");
238 if (
$start >= $this->nb) {
250 $this->log->debug(
"Extraction de " .
$start .
" à " . $end);
253 $result = pg_fetch_array($res,
$c);
254 $this->log->debug(
"Affectation de " .
$c);
255 if (($res_type ==
"LIST") || ($res_type ==
"LISTC")) {
258 while (list($k, $v) = each($result)) {
259 $this->list[
$c][$k] = $v;
263 $this->list[
$c] =
"";
266 $chrono = microtime();
267 $this->log->debug(
"Affectation du tableau : $chrono");
268 return ($this->list);
274 if (($this->criteria !=
"") && ($this->
operator !=
"none")) {
275 if ($this->casse ==
"NON") {
276 $out =
$out .
" upper(" . $this->criteria .
") " . $this->operators[$this->operator][
"oper"];
278 $out =
$out . $this->criteria .
" " . $this->operators[$this->operator][
"oper"];
281 switch ($this->operators[$this->
operator][
"param"]) {
283 $string =
" '{$this->string}'";
287 $string =
" '%{$this->string}%'";
291 $string =
" '{$this->string}%'";
293 if (($this->
operator !=
'null') && ($this->
operator !=
'notn')) {
294 if ($this->casse ==
"NON") {
295 $out.=
" upper({$string})";
307 if (($this->display_alpha ==
"TRUE") && ($this->alpha !=
"ALL") && ($this->alpha !=
"NONE")) {
308 $out =
" upper({$this->alpha_criteria}) like upper('{$this->alpha}%') ";
316 $this->log->debug(
"Supplementaires");
317 if (
sizeof($this->basic_elem->sup_where) > 0) {
318 reset($this->basic_elem->sup_where);
320 while (list($k, $v) = each($this->basic_elem->sup_where)) {
339 function GenPage($url, $nores, $complete =
"FALSE", $display_form =
"YES")
342 $this->
init(
"alpha", $this->alpha_default);
349 $o->cat($this->
GenForm($url, $display_form));
351 if (($this->display_alpha ==
"TRUE") && ($this->alpha ==
"NONE")) {
352 return (
$o->flush());
355 if ($complete ==
"FALSE") {
356 $this->table->array = $this->
Query($this->
start, $this->
slice,
"TABLE");
358 $this->table->array = $this->
Query($this->
start, $this->
slice,
"LISTC");
359 $this->table->arrayobj =
"TRUE";
362 $this->table->sort_link =
"javascript:void(0)\\\" onClick=\\\"SortPage(
363 document.QueryObj,'%s');return false";
364 $this->table->page_link =
"javascript:void(0)\\\" onclick=\\\"GoPage(
365 document.QueryObj,%s,%s);return false";
367 if (!isset($this->table->headcontent[
"$this->order_by"])) {
368 $this->table->headcontent[
"$this->order_by"] = $this->order_by;
371 $this->table->headcontent[
"$this->order_by"].= $this->$desc;
373 if ($this->nb == 0) {
376 $o->cat($this->table->get());
379 $o->cat(
'<table border=0 cellspacing=0 cellpadding=0 width="100%">
380 <tr><td class="textinv2">Total : ' . $this->nb .
'</td></tr>
383 return (
$o->flush());
389 if (
sizeof($this->basic_elem->criterias) == 0)
return (
"");
390 $this->log->debug(
"Nouvelle forme");
395 <script language="javascript">
396 function selFiltre(form_cour, champ) {
397 var oper_sel=form_cour.p_operator[form_cour.p_operator.selectedIndex].value;
398 var crit_sel=form_cour.p_criteria[form_cour.p_criteria.selectedIndex].value;
399 var crit_idx=form_cour.p_criteria.selectedIndex;
400 tab_types = new Array();');
404 reset($this->basic_elem->criterias);
405 while (list($k, $v) = each($this->basic_elem->criterias)) {
406 $o->cat(
"tab_types[{$ind}]=\"" . $v[
"type"] .
"\";");
411 if ((tab_types[crit_idx]=="NUM") && (oper_sel=="nlike")) {
412 alert ("Un champ numérique ne peut-être recherché avec \'Ne Contient Pas\'!!");
413 form_cour.p_operator.options[0].selected=true;
415 if ((tab_types[crit_idx]=="NUM") && (oper_sel=="like")) {
416 alert ("Un champ numérique ne peut-être recherché avec \'Contient\'!!");
417 form_cour.p_operator.options[0].selected=true;
419 if ((crit_sel=="") && (champ.name=="p_criteria")) {
420 form_cour.p_string.value = "";
421 form_cour.p_operator.options[0].selected=true;
426 function checkFiltre(form_cour) {
428 if ($display_form ==
'YES') {
431 var oper_sel=form_cour.p_operator[form_cour.p_operator.selectedIndex].value;
432 var crit_sel=form_cour.p_criteria[form_cour.p_criteria.selectedIndex].value;
433 var casse=form_cour.chk_casse.checked;
435 form_cour.p_casse.value="NON";
437 form_cour.p_casse.value="OUI";
439 if ((crit_sel=="") && (oper_sel!="")) {
441 alert ("Vous devez choisir un critere!!"); }
442 if ((crit_sel!="") && (oper_sel=="")) {
444 alert ("Vous devez choisir un operator!!"); }
449 $o->cat(
' var ok=true; return(ok); }');
453 function queryFiltre(form_cour) {
455 ok = checkFiltre(form_cour);
457 form_cour.p_start.value=0;
462 function resetFiltre(form_cour) {
463 form_cour.p_criteria.selectedIndex=0;
464 form_cour.p_operator.selectedIndex=0;
465 form_cour.p_start.value=0;
466 form_cour.p_string.value="";
470 function GoPage(form_cour,start,slice) {
471 form_cour.p_start.value = start;
472 form_cour.p_slice.value = slice;
473 ok=checkFiltre(form_cour);
474 if (ok) {form_cour.submit();}
477 function SortPage(form_cour,order) {
478 if (form_cour.p_order_by.value == order) {
479 if (form_cour.p_desc.value == "down") {
480 form_cour.p_desc.value = "up";
482 form_cour.p_desc.value = "down";
485 form_cour.p_order_by.value = order;
486 form_cour.p_desc.value = "down";
488 ok=checkFiltre(form_cour);
489 if (ok) {form_cour.submit();}
492 function setAlpha(form_cour,car) {
493 form_cour.p_alpha.value = car;
494 form_cour.p_start.value = 0;
495 ok=checkFiltre(form_cour);
496 if (ok) {form_cour.submit();}
502 <form name="QueryObj" method="POST" action="' . $url .
'">');
503 if ($display_form ==
"YES") {
504 $o->cat(
'<table bgcolor="#F2F2F2" border="0" cellspacing="0" cellpadding="2" >
507 if ($this->display_alpha ==
"TRUE") {
508 $o->cat(
'<td><small><select name="p_alpha_criteria">\n');
509 reset($this->basic_elem->criterias);
510 while (list($k, $v) = each($this->basic_elem->criterias)) {
511 if ($v[
"type"] ==
"TXT") {
512 if ($this->alpha_criteria == $k) {
513 $o->cat(
"<OPTION SELECTED VALUE=\"{$k}\">" . $v[
"libelle"] .
"\n");
515 $o->cat(
"<OPTION VALUE=\"{$k}\">" . $v[
"libelle"] .
"\n");
519 $o->cat(
'</select></small></td>');
520 $o->cat(
'<td nowrap colspan="3">');
521 for ($i = ord(
"A"); $i <= ord(
"Z"); $i++) {
524 if ($this->alpha ==
$c) {
527 $o->cat(
"<a href=\"javascript:void(0)\"
528 onClick=\"setAlpha(document.QueryObj,'" .
$c .
"');return false\">");
529 $o->cat(
'<font size="-1">' .
$c .
'</font></a>');
530 if ($this->alpha ==
$c) {
534 $o->cat(
"</td><td align=\"center\">");
535 if ($this->alpha ==
"ALL")
$o->cat(
'<b>[');
536 $o->cat(
"<a href=\"javascript:void(0)\"
537 onClick=\"setAlpha(document.QueryObj,'ALL');return false\">");
538 $o->cat(
'<font size="-1">Tout</font></a>');
539 if ($this->alpha ==
"ALL")
$o->cat(
']</b>');
541 if ($this->alpha ==
"NONE") {
544 $o->cat(
"<a href=\"javascript:void(0)\"
545 onClick=\"setAlpha(document.QueryObj,'NONE');return false\">");
546 $o->cat(
"<font size=\"-1\">Rien</font></a>");
547 if ($this->alpha ==
"NONE") {
554 <TD><SMALL><SELECT NAME=\"p_criteria\"
555 onChange=\"selFiltre(document.QueryObj,this);\">\n");
556 reset($this->basic_elem->criterias);
557 while (list($k, $v) = each($this->basic_elem->criterias)) {
558 if ($this->criteria == $k) {
559 $o->cat(
"<OPTION SELECTED VALUE=\"{$k}\">" . $v[
"libelle"] .
"\n");
561 $o->cat(
"<OPTION VALUE=\"{$k}\">" . $v[
"libelle"] .
"\n");
564 $o->cat(
"</SELECT></SMALL></TD>\n");
567 <TD><SMALL><SELECT NAME=\"p_operator\"
568 onChange=\"selFiltre(document.QueryObj,this);\">\n");
569 while (list($k, $v) = each($this->operators)) {
570 if ($this->
operator == $k) {
571 $o->cat(
"<OPTION SELECTED VALUE=\"{$k}\">" . $v[
"lib"] .
"\n");
573 $o->cat(
"<OPTION VALUE=\"{$k}\">" . $v[
"lib"] .
"\n");
576 $o->cat(
"</SELECT></SMALL></TD>\n");
579 <td><small><input name="p_string" maxlength=15 size=10 class="finput"
580 value="' . $this->
string .
'">
584 <td><a href="javascript:void(0)"
585 onClick="queryFiltre(document.QueryObj);return false">
586 <font size="-1">Recherche</font></a>
587 <a href="javascript:void(0)"
588 onClick="resetFiltre(document.QueryObj);return false">
589 <font size="-1">Réinitialiser</font></a>
593 <td nowrap><input type="checkbox"');
594 if ($this->casse ==
"OUI") {
595 $o->cat(
' checked ');
597 $o->cat(
'name="chk_casse"><font size="-1">Respecter la casse</font></td>');
603 $o->cat(
'<input type="hidden" name="p_slice" value="' . $this->
slice .
'">
604 <input type="hidden" name="p_start" value="' . $this->
start .
'">
605 <input type="hidden" name="p_order_by" value="' . $this->
order_by .
'">
606 <input type="hidden" name="p_casse" value="' . $this->casse .
'">
607 <input type="hidden" name="p_desc" value="' . $this->desc .
'">
608 <input type="hidden" name="p_alpha" value="' . $this->alpha .
'">
611 return (
$o->flush());
616 global $HTTP_POST_VARS;
617 if (is_array($HTTP_POST_VARS) && isset($HTTP_POST_VARS[
"p_$attr"])) {
618 $this->$attr = $HTTP_POST_VARS[
"p_$attr"];
620 if (isset($this->basic_elem->def[$attr])) {
621 $this->$attr = $this->basic_elem->def[$attr];
623 $this->$attr = $default;