Core  3.2
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  * @package FDL
5 */
6 /**
7  * Parameters values
8  *
9  * @author Anakeen
10  * @version $Id: Class.Param.php,v 1.29 2008/11/13 16:43:11 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 /**
15  */
16 
17 include_once ('Class.Log.php');
18 include_once ('Class.DbObj.php');
19 include_once ('Class.ParamDef.php');
20 /** @deprecated use Param::PARAM_APP instead */
21 define("PARAM_APP", "A");
22 /** @deprecated use Param::PARAM_GLB instead */
23 define("PARAM_GLB", "G");
24 /** @deprecated use Param::PARAM_USER instead */
25 define("PARAM_USER", "U");
26 /** @deprecated use Param::PARAM_STYLE instead */
27 define("PARAM_STYLE", "S");
28 
29 class Param extends DbObj
30 {
31 
32  const PARAM_APP = "A";
33  const PARAM_GLB = "G";
34  const PARAM_USER = "U";
35  const PARAM_STYLE = "S";
36 
37  var $fields = array(
38  "name",
39  "type",
40  "appid",
41  "val"
42  );
43 
44  var $id_fields = array(
45  "name",
46  "type",
47  "appid"
48  );
49 
50  public $name;
51  public $type;
52  public $appid;
53  public $val;
54  var $dbtable = "paramv";
55 
56  var $sqlcreate = '
57  create table paramv (
58  name varchar(50) not null,
59  type varchar(21),
60  appid int4,
61  val text);
62  create index paramv_idx2 on paramv(name);
63  create unique index paramv_idx3 on paramv(name,type,appid);
64  ';
65 
66  var $buffer = array();
67 
68  function PreInsert()
69  {
70  if (strpos($this->name, " ") != 0) {
71  return _("Parameter name does not include spaces");
72  }
73  return '';
74  }
75  function PostInit()
76  {
77  $opd = new Paramdef();
78  $opd->create();
79  }
80  function PreUpdate()
81  {
82  $this->PreInsert();
83  }
84 
85  function SetKey($appid, $userid, $styleid = "0")
86  {
87  $this->appid = $appid;
88  $this->buffer = array_merge($this->buffer, $this->GetAll($appid, $userid, $styleid));
89  }
90 
91  function Set($name, $val, $type = self::PARAM_GLB, $appid = '')
92  {
93  global $action;
94  if ($action) {
95  $action->parent->session->unregister("sessparam" . $appid);
96  }
97  $this->name = $name;
98  $this->val = $val;
99  $this->type = $type;
100 
102 
103  if ($pdef && $pdef->isAffected()) {
104  if ($pdef->isglob == 'Y') {
105  $appid = $pdef->appid;
106  }
107  }
108  $this->appid = $appid;
109 
110  $paramt = new Param($this->dbaccess, array(
111  $name,
112  $type,
113  $appid
114  ));
115  if ($paramt->isAffected()) $err = $this->Modify();
116  else $err = $this->Add();
117 
118  $otype = '';
119  if ($type == self::PARAM_GLB) $otype = self::PARAM_APP;
120  elseif ($type == self::PARAM_APP) $otype = self::PARAM_GLB;
121  if ($otype) {
122  // delete incompatible parameter
123  $paramo = new Param($this->dbaccess, array(
124  $name,
125  $otype,
126  $appid
127  ));
128  if ($paramo->isAffected()) $paramo->delete();
129  }
130 
131  $this->buffer[$name] = $val;
132  return $err;
133  }
134 
135  function SetVolatile($name, $val)
136  {
137  if ($val !== null) $this->buffer[$name] = $val;
138  else unset($this->buffer[$name]);
139  }
140 
141  function Get($name, $def = "")
142  {
143  require_once ('WHAT/Class.ApplicationParameterManager.php');
144 
146  return $value;
147  }
148  if (isset($this->buffer[$name])) {
149  return ($this->buffer[$name]);
150  } else {
151  return ($def);
152  }
153  }
154 
155  function GetAll($appid = "", $userid, $styleid = "0")
156  {
157  if ($appid == "") $appid = $this->appid;
158  $psize = new Param($this->dbaccess, array(
159  "FONTSIZE",
160  self::PARAM_USER . $userid,
161  "1"
162  ));
163  $out = array();
164  if ($psize->val != '') $size = $psize->val;
165  else $size = 'normal';
166  $size = 'SIZE_' . strtoupper($size);
167 
168  if ($appid) {
169  if ($userid) {
170  $styleIdPG = pg_escape_string($styleid);
171  $sql = sprintf("select distinct on(paramv.name) paramv.* from paramv left join paramdef on (paramv.name=paramdef.name) where
172 (paramv.type = '%s') OR (paramv.appid=%d and (paramv.type='%s' or paramv.type='%s%d' or paramv.type='%s%s')) OR (paramdef.isglob='Y' and (paramv.type='%s%d' or paramv.type='%s%s')) OR
173 (paramv.type='%s%s') order by paramv.name, paramv.type desc", self::PARAM_GLB, $appid, self::PARAM_APP, self::PARAM_USER, $userid, self::PARAM_STYLE, $styleIdPG, self::PARAM_USER, $userid, self::PARAM_STYLE, $styleIdPG, self::PARAM_STYLE, pg_escape_string($size));
174  } else {
175  $sql = sprintf("SELECT * from paramv where type='G' or (type='A' and appid=%d);", $appid);
176  }
177  simpleQuery($this->dbaccess, $sql, $list);
178 
179  foreach ($list as $v) {
180  $out[$v["name"]] = $v["val"];
181  }
182  } else {
183  $this->log->debug("$appid no constant define for this application");
184  }
185  return ($out);
186  }
187 
188  function GetUser($userid = Account::ANONYMOUS_ID, $styleid = "")
189  {
190  $query = new QueryDb($this->dbaccess, "Param");
191 
192  $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 = '" . self::PARAM_GLB . "') " . " OR (type='" . self::PARAM_APP . "')" . " OR (type='" . self::PARAM_STYLE . $styleid . "' )" . " OR (type='" . self::PARAM_USER . $userid . "' ))" . " order by paramv.name, paramv.appid, paramv.type desc");
193 
194  return ($tlist);
195  }
196  /**
197  * get list of parameters for a style
198  * @param bool $onlystyle if false return all parameters excepts user parameters with style parameters
199  * if true return only parameters redifined by the style
200  * @return array of parameters values
201  */
202  function GetStyle($styleid, $onlystyle = false)
203  {
204  $query = new QueryDb($this->dbaccess, "Param");
205  if ($onlystyle) {
206  $query->AddQuery("type='" . self::PARAM_STYLE . $styleid . "'");
207  $tlist = $query->Query(0, 0, "TABLE");
208  } else {
209  $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 = '" . self::PARAM_GLB . "') " . " OR (type='" . self::PARAM_APP . "')" . " OR (type='" . self::PARAM_STYLE . $styleid . "' ))" . " order by paramv.name, paramv.appid, paramv.type desc");
210  }
211  return ($tlist);
212  }
213 
214  function GetApps()
215  {
216  $query = new QueryDb($this->dbaccess, "Param");
217 
218  $tlist = $query->Query(0, 0, "TABLE", "select paramv.*, paramdef.descr, paramdef.kind from paramv, paramdef where paramv.name = paramdef.name and (" . " (type = '" . self::PARAM_GLB . "') " . " OR (type='" . self::PARAM_APP . "'))" . " order by paramv.appid, paramv.name, type desc");
219 
220  return ($tlist);
221  }
222 
223  function GetUParam($p, $u = Account::ANONYMOUS_ID, $appid = "")
224  {
225  if ($appid == "") $appid = $this->appid;
226  $req = "select val from paramv where name='" . $p . "' and type='U" . $u . "' and appid=" . $appid . ";";
227  $query = new QueryDb($this->dbaccess, "Param");
228  $tlist = $query->Query(0, 0, "TABLE", $req);
229  if ($query->nb != 0) return $tlist[0]["val"];
230  return "";
231  }
232  // delete paramters that cannot be change after initialisation
233  function DelStatic($appid)
234  {
235 
236  $query = new QueryDb($this->dbaccess, "Param");
237  $sql = sprintf("select paramv.* from paramv, paramdef where paramdef.name=paramv.name and paramdef.kind='static' and paramdef.isuser!='Y' and paramv.appid=%d", $appid);
238  $list = $query->Query(0, 0, "LIST", $sql);
239 
240  if ($query->nb != 0) {
241  reset($list);
242  /*
243  * @var Param $v
244  */
245  foreach ($list as $k => $v) {
246  $v->Delete();
247  if (isset($this->buffer[$v->name])) unset($this->buffer[$v->name]);
248  }
249  }
250  }
251 
252  function PostDelete()
253  {
254  if (isset($this->buffer[$this->name])) unset($this->buffer[$this->name]);
255  }
256 
257  function DelAll($appid = "")
258  {
259  $query = new QueryDb($this->dbaccess, "Param");
260  // delete all parameters not used by application
261  $query->Query(0, 0, "TABLE", "delete from paramv where appid not in (select id from application) ");
262  return;
263  }
264  // FIN DE CLASSE
265 
266 }
267 ?>
$s type
Definition: dav.php:73
const PARAM_APP
Definition: Class.Param.php:21
global $action
print $fam getTitle() $fam name
const PARAM_USER
Definition: Class.Param.php:25
Add($nopost=false, $nopre=false)
GetStyle($styleid, $onlystyle=false)
$size
Definition: resizeimg.php:110
PostDelete()
const ANONYMOUS_ID
DelStatic($appid)
PreInsert()
Definition: Class.Param.php:68
GetAll($appid="", $userid, $styleid="0")
SetVolatile($name, $val)
static getParamDef($name, $appid=null)
const PARAM_USER
Definition: Class.Param.php:34
DelAll($appid="")
Set($name, $val, $type=self::PARAM_GLB, $appid= '')
Definition: Class.Param.php:91
PostInit()
Definition: Class.Param.php:75
const PARAM_STYLE
Definition: Class.Param.php:35
const PARAM_APP
Definition: Class.Param.php:32
SetKey($appid, $userid, $styleid="0")
Definition: Class.Param.php:85
const PARAM_GLB
Definition: Class.Param.php:23
Get($name, $def="")
const PARAM_GLB
Definition: Class.Param.php:33
const PARAM_STYLE
Definition: Class.Param.php:27
PreUpdate()
Definition: Class.Param.php:80
GetUParam($p, $u=Account::ANONYMOUS_ID, $appid="")
if(($docid!==0)&&(!is_numeric($docid))) $query
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
GetUser($userid=Account::ANONYMOUS_ID, $styleid="")
$value
← centre documentaire © anakeen