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