Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Param.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  * Parameters values
9  *
10  * @author Anakeen 2000
11  * @version $Id: Class.Param.php,v 1.29 2008/11/13 16:43:11 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 include_once ('Class.Log.php');
20 include_once ('Class.DbObj.php');
21 include_once ('Class.ParamDef.php');
22 
23 define("PARAM_APP", "A");
24 define("PARAM_GLB", "G");
25 define("PARAM_USER", "U");
26 define("PARAM_STYLE", "S");
27 
28 class Param extends DbObj
29 {
30  var $fields = array(
31  "name",
32  "type",
33  "appid",
34  "val"
35  );
36 
37  var $id_fields = array(
38  "name",
39  "type",
40  "appid"
41  );
42 
43  var $dbtable = "paramv";
44 
45  var $sqlcreate = '
46  create table paramv (
47  name varchar(50) not null,
48  type varchar(21),
49  appid int4,
50  val text);
51  create index paramv_idx2 on paramv(name);
52  create unique index paramv_idx3 on paramv(name,type,appid);
53  ';
54 
55  var $buffer = array();
56 
57  function PreInsert()
58  {
59  if (strpos($this->name, " ") != 0) {
60  return _("Parameter name does not include spaces");
61  }
62  }
63  function PostInit()
64  {
65  $opd = new Paramdef();
66  $opd->create();
67  }
68  function PreUpdate()
69  {
70  $this->PreInsert();
71  }
72 
73  function SetKey($appid, $userid, $styleid = "0")
74  {
75  $this->appid = $appid;
76  $this->buffer = array_merge($this->buffer, $this->GetAll($appid, $userid, $styleid));
77  }
78 
79  function Set($name, $val, $type = PARAM_GLB, $appid = '')
80  {
81  global $action;
82  if ($action) {
83  $action->parent->session->unregister("sessparam" . $appid);
84  }
85  $this->name = $name;
86  $this->val = $val;
87  $this->type = $type;
88  $pdef = new paramdef($this->dbaccess, $name);
89 
90  if ($pdef->isAffected()) {
91  if ($pdef->isglob == 'Y') {
92  $appid = $pdef->appid;
93  if ($action) {
94  $action->parent->session->close(); // need to refresh all application parameters
95  $action->parent->session->set(); // reopen current session
96 
97  }
98  }
99  }
100  $this->appid = $appid;
101 
102  $paramt = new Param($this->dbaccess, array(
103  $name,
104  $type,
105  $appid
106  ));
107  if ($paramt->isAffected()) $this->Modify();
108  else $this->Add();
109 
110  $this->buffer[$name] = $val;
111  }
112 
113  function SetVolatile($name, $val)
114  {
115  $this->buffer[$name] = $val;
116  }
117 
118  function Get($name, $def = "")
119  {
120  if (isset($this->buffer[$name])) {
121  return ($this->buffer[$name]);
122  } else {
123  return ($def);
124  }
125  }
126 
127  function GetAll($appid = "", $userid, $styleid = "0")
128  {
129  if ($appid == "") $appid = $this->appid;
130  $psize = new Param($this->dbaccess, array(
131  "FONTSIZE",
132  PARAM_USER . $userid,
133  "1"
134  ));
135  if ($psize->val != '') $size = $psize->val;
136  else $size = 'normal';
137  $size = 'SIZE_' . strtoupper($size);
138  $query = new QueryDb($this->dbaccess, "Param");
139  if ($userid) {
140  $list = $query->Query(0, 0, "TABLE", "select distinct on(paramv.name) paramv.* from paramv left join paramdef on (paramv.name=paramdef.name) where " . "(paramv.type = '" . PARAM_GLB . "') " . " OR (paramv.type='" . PARAM_APP . "' and paramv.appid=$appid)" . " OR (paramv.type='" . PARAM_USER . $userid . "' and paramv.appid=$appid)" . " OR (paramv.type='" . PARAM_USER . $userid . "' and paramdef.isglob='Y')" . " OR (paramv.type='" . PARAM_STYLE . $styleid . "' and paramv.appid=$appid)" . " OR (paramv.type='" . PARAM_STYLE . $styleid . "' and paramdef.isglob='Y')" . " OR (paramv.type='" . PARAM_STYLE . $size . "')" . " order by paramv.name, paramv.type desc");
141  } else {
142  $list = $query->Query(0, 0, "TABLE", "SELECT * from paramv where type='G' or (type='A' and appid=$appid);");
143  }
144  $out = array();
145  if ($query->nb != 0) {
146  while (list($k, $v) = each($list)) {
147  $out[$v["name"]] = $v["val"];
148  }
149  } else {
150  $this->log->debug("$appid no constant define for this application");
151  }
152  return ($out);
153  }
154 
155  function GetUser($userid = ANONYMOUS_ID, $styleid = "")
156  {
157  $query = new QueryDb($this->dbaccess, "Param");
158 
159  $tlist = $query->Query(0, 0, "TABLE", "select distinct on(paramv.name, paramv.appid) paramv.*, paramdef.descr, paramdef.kind from paramv, paramdef where paramv.name = paramdef.name and paramdef.isuser='Y' and (" . " (type = '" . PARAM_GLB . "') " . " OR (type='" . PARAM_APP . "')" . " OR (type='" . PARAM_STYLE . $styleid . "' )" . " OR (type='" . PARAM_USER . $userid . "' ))" . " order by paramv.name, paramv.appid, paramv.type desc");
160 
161  return ($tlist);
162  }
163  /**
164  * get list of parameters for a style
165  * @param bool $onlystyle if false return all parameters excepts user parameters with style parameters
166  * if true return only parameters redifined by the style
167  * @return array of parameters values
168  */
169  function GetStyle($styleid, $onlystyle = false)
170  {
171  $query = new QueryDb($this->dbaccess, "Param");
172  if ($onlystyle) {
173  $query->AddQuery("type='" . PARAM_STYLE . $styleid . "'");
174  $tlist = $query->Query(0, 0, "TABLE");
175  } else {
176  $tlist = $query->Query(0, 0, "TABLE", "select distinct on(paramv.name, paramv.appid) paramv.*, paramdef.descr, paramdef.kind from paramv, paramdef where paramv.name = paramdef.name and paramdef.isstyle='Y' and (" . " (type = '" . PARAM_GLB . "') " . " OR (type='" . PARAM_APP . "')" . " OR (type='" . PARAM_STYLE . $styleid . "' ))" . " order by paramv.name, paramv.appid, paramv.type desc");
177  }
178  return ($tlist);
179  }
180 
181  function GetApps()
182  {
183  $query = new QueryDb($this->dbaccess, "Param");
184 
185  $tlist = $query->Query(0, 0, "TABLE", "select paramv.*, paramdef.descr, paramdef.kind from paramv, paramdef where paramv.name = paramdef.name and (" . " (type = '" . PARAM_GLB . "') " . " OR (type='" . PARAM_APP . "'))" . " order by paramv.appid, paramv.name, type desc");
186 
187  return ($tlist);
188  }
189 
190  function GetUParam($p, $u = ANONYMOUS_ID, $appid = "")
191  {
192  if ($appid == "") $appid = $this->appid;
193  $req = "select val from paramv where name='" . $p . "' and type='U" . $u . "' and appid=" . $appid . ";";
194  $query = new QueryDb($this->dbaccess, "Param");
195  $tlist = $query->Query(0, 0, "TABLE", $req);
196  if ($query->nb != 0) return $tlist[0]["val"];
197  return "";
198  }
199  // delete paramters that cannot be change after initialisation
200  function DelStatic($appid)
201  {
202 
203  $query = new QueryDb($this->dbaccess, "Param");
204  $list = $query->Query(0, 0, "LIST", "select paramv.* from paramv, paramdef where paramdef.name=paramv.name and paramdef.kind='static' and paramdef.isuser!='Y' and paramv.appid=$appid;");
205 
206  if ($query->nb != 0) {
207  reset($list);
208  while (list($k, $v) = each($list)) {
209  $v->Delete();
210  if (isset($this->buffer[$v->name])) unset($this->buffer[$v->name]);
211  }
212  }
213  }
214 
215  function PostDelete()
216  {
217  if (isset($this->buffer[$this->name])) unset($this->buffer[$this->name]);
218  }
219 
220  function DelAll($appid = "")
221  {
222  $query = new QueryDb($this->dbaccess, "Param");
223  // delete all parameters not used by application
224  $query->Query(0, 0, "TABLE", "delete from paramv where appid not in (select id from application) ");
225  return;
226  }
227  // FIN DE CLASSE
228 
229 }
230 ?>
← centre documentaire © anakeen - published under CC License - Dynacase