Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.QueryGen.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.QueryGen.php,v 1.7 2007/05/09 15:44:27 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.QueryGen.php,v 1.7 2007/05/09 15:44:27 eric Exp $
34 //
35 // ---------------------------------------------------------------------------
36 // This class is designed to design easily pages with query/order elements
37 //
38 $CLASS_QUERYGEN_PHP = '$Id: Class.QueryGen.php,v 1.7 2007/05/09 15:44:27 eric Exp $';
39 
40 include_once ('Class.QueryDb.php');
41 include_once ('Class.TableLayout.php');
42 include_once ('Class.SubForm.php');
43 
44 class QueryGen
45 {
46 
47  var $table;
48  var $start;
49  var $slice;
50  var $order_by;
51  var $desc;
52  var $criteria = array();
53  var $operator;
54  var $value;
56  var $level;
57  var $fulltext = "";
58  var $fulltextfields = array();
59  var $freedata = "";
60  var $placeHolder = "";
61 
62  var $fulltextform = '
63 <form name="fulltext" method="post"
64  action="javascript:set_form_par(\'query\',\'fulltext\',self.document.fulltext.text.value,0);set_form_par(\'query\',\'start\',0,0);set_form_par(\'query\',\'all\',\'\',1);"
65  onreset="javascript:set_form_par(\'query\',\'fulltext\',\'\',0);set_form_par(\'query\',\'start\',0,0);set_form_par(\'query\',\'all\',\'\',1);">
66  <input name="text" type="text" value="%s" size="10" placeholder="%s">
67 </form>';
68 
69  var $up = "&nbsp;^";
70  var $down = "&nbsp;v";
71 
73  {
74  //
75  $this->log = new Log("", "QueryGen", "$class");
76  $this->query = new QueryDb($dbaccess, $class);
77 
78  $this->dbaccess = $dbaccess;
79 
80  $this->action = & $action;
81 
82  $this->action_name = GetHttpVars("sact", $action->name);
83  $this->app_name = GetHttpVars("sapp", $action->parent->name);
84 
85  if ($this->action_name != $action->name) {
86  $app = new Application($action->dbaccess);
87  $app->Set($this->app_name, $action->parent);
88  $this->action = new Action($action->dbaccess);
89  $this->action->Set($this->action_name, $app);
90  }
91  // Init all query params
92  $this->Init("order_by", $this->query->basic_elem->order_by);
93  $this->Init("desc", "down");
94  $this->Init("start", 0);
95  $this->Init("slice", 10);
96  $this->Init("fulltext", "");
97  $this->Init("freedata", "");
98  $this->fulltextfields = $this->query->basic_elem->fulltextfields;
99 
100  $i = 0;
101  while ($i < $this->slice) {
102  $this->Init("criteria", "", $i);
103  if (($this->criteria == "") || ($this->criteria[$i] == "")) break;
104 
105 
106  $this->Init("operator", "", $i);
107  $this->Init("value", "", $i);
108  $this->Init("connector", "", $i);
109  $this->Init("level", "", $i);
110  $i++;
111  }
112  // Init the query form (can be overlay by user)
113  $this->baseurl = $action->GetParam("CORE_BASEURL");
114  $this->action->lay->set("QUERY_FORM", $this->GenMainForm("query", 0, 0, $this->baseurl . "app=CORE&action=SETACTPAR&sole=Y"));
115  // Add Js Code that will be used to manage param modification
116  $this->action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/query_paging.js");
117  // Init a table layout (default. user can use its one)
118  $this->table = new TableLayout($this->action->lay);
119  $this->table->start = $this->start;
120  $this->table->slice = $this->slice;
121  }
122 
123  function SetFullTextForm($text)
124  {
125  $this->table->lay->set("FULLTEXTFORM", sprintf($this->fulltextform, $text, $this->placeHolder));
126  }
127 
128  function GenMainForm($name, $height, $width, $mainurl, $suburl = "")
129  {
130  $this->form = new SubForm($name, $height, $width, $mainurl, $suburl);
131 
132  $this->form->SetParam("key", "");
133  $this->form->SetParam("start", $this->start);
134  $this->form->SetParam("slice", $this->slice);
135  $this->form->SetParam("order_by", $this->order_by);
136  $this->form->SetParam("desc", $this->desc);
137  $this->form->SetParam("fulltext", $this->fulltext);
138  $this->form->SetParam("sapp", $this->action->parent->name);
139  $this->form->SetParam("sact", $this->action->name);
140  $this->form->SetParam("freedata", $this->freedata);
141 
142  $i = 0;
143  while ($i < $this->slice) {
144  if (!isset($this->criteria[$i]) || $this->criteria[$i] == "") break;
145 
146 
147  $this->form->SetParam("criteria_$i", $this->criteria[$i]);
148  $this->form->SetParam("operator_$i", $this->operator[$i]);
149  $this->form->SetParam("value_$i", $this->value[$i]);
150  $this->form->SetParam("connector_$i", $this->connector[$i]);
151  $this->form->SetParam("level_$i", $this->level[$i]);
152  $i++;
153  }
154  return ($this->form->GetMainForm());
155  }
156 
157  function Query($type = "TABLE")
158  {
159 
160  $this->query->order_by = $this->order_by;
161  $this->query->desc = $this->desc;
162  $this->AddFulltextQuery();
163  $this->table->array = $this->query->Query($this->start, $this->slice, $type);
164  $this->table->nb_tot = $this->query->count();
165  if ($this->table->nb_tot == 0) {
166  $this->table->array = array();
167  }
168  // Layout elements
169  $this->table->page_link = "javascript:set_form_par('query','start','%s',1);";
170  $this->table->sort_link = "javascript:set_form_par('query','order_by','%s',0);set_form_par('query','desc','%s',0);set_form_par('query','start','%s',0);set_form_par('query','all','',1);";
171  $this->table->desc = $this->desc;
172  $this->table->order_by = $this->order_by;
173  $this->table->slice = $this->slice;
174  $this->table->prev = $this->action->GetIcon("prev.png", "prev", 16);
175  $this->table->next = $this->action->GetIcon("next.png", "next", 16);
176  $this->table->first = $this->action->GetIcon("first.png", "first", 16);
177  $this->table->last = $this->action->GetIcon("last.png", "last", 16);
178  $this->up = $this->action->GetIcon("up.png", "up");
179  $this->down = $this->action->GetIcon("down.png", "down");
180  $this->SetFullTextForm($this->fulltext);
181  // color row table
182  $this->table->fields[] = "CLASS";
183  reset($this->table->array);
184  foreach ($this->table->array as $k => $v) {
185  $this->table->array[$k]["CLASS"] = ($k % 2) ? "TABOdd" : "";
186  }
187 
188  reset($this->table->array);
189  if (($this->order_by != "") && ($this->desc != "")) {
190  $desc = $this->desc;
191  if (is_array($this->table->headsortfields)) {
192  reset($this->table->headsortfields);
193  foreach ($this->table->headsortfields as $k => $v) {
194  if ($this->order_by == $v) {
195  $this->table->headcontent[$k].= $this->$desc;
196  }
197  }
198  }
199  }
200  }
201 
202  function AddFulltextQuery()
203  {
204  if (($this->fulltext != "") && (sizeof($this->fulltextfields) > 0)) {
205  reset($this->fulltextfields);
206  $sql = "(";
207  foreach ($this->fulltextfields as $k => $v) {
208  $sql.= " upper($v) like '%" . strtoupper($this->fulltext) . "%' OR";
209  }
210  $sql = substr($sql, 0, -2) . ")";
211  $this->AddQuery($sql);
212  }
213  }
214 
215  function Init($key, $defval, $ind = "")
216  {
217 
218  if ($ind == "") {
219  $this->$key = GetHttpVars("$key", $this->action->ActRead($key, $defval));
220  $this->action->ActRegister("$key", $this->$key);
221  } else {
222  $this->$key[$ind] = GetHttpVars("$key_$ind", $this->action->ActRead("$key_$ind", $defval));
223  $this->action->ActRegister("$key_$ind", $this->$key[$ind]);
224  }
225  }
226 
227  function AddQuery($contraint)
228  {
229  $this->query->AddQuery($contraint);
230  }
231 }
232 ?>
AddQuery($contraint)
GenMainForm($name, $height, $width, $mainurl, $suburl="")
Query($type="TABLE")
global $action
$s slice
SetFullTextForm($text)
$app
$CLASS_QUERYGEN_PHP
$s start
$query order_by
__construct($dbaccess, $class, &$action)
$dbaccess
Definition: checkVault.php:17
$class
Definition: updateclass.php:38
Init($key, $defval, $ind="")
← centre documentaire © anakeen