Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.ParameterManager.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Manage application parameters
8  * Set and get application parameters
9  * @class ParameterManager
10  *
11  * @see ApplicationParameterManager
12  *
13  * @deprecated use { @link ApplicationParameterManager } instead
14  *
15  * @code
16  * $v=ParameterManager::getParameter("CORE_CLIENT");
17  * @endcode
18  */
20 {
21  private static $cache = array();
22  /**
23  * @return Action|null
24  */
25  private static function &getAction()
26  {
27  global $action;
28  return $action;
29  }
30  /**
31  * for internal purpose only
32  * @deprecated use { @link ApplicationParameterManager } instead
33  */
34  public static function resetCache()
35  {
37  self::$cache = array();
38  }
39  /**
40  * return current value for a parameter
41  * these values can depend of current user when it is a user parameter
42  * @deprecated use { @link ApplicationParameterManager } instead
43  *
44  * @param string $name paramter name
45  * @return string|null value of parameter (null if parameter not exists)
46  */
47  public static function getParameter($name)
48  {
50  return getParam($name);
51  }
52  /**
53  * get a specific value for an application
54  * get user value for current user if it is a user parameter
55  * @deprecated use { @link ApplicationParameterManager } instead
56  * @param string $appName application name
57  * @param string $name paramter
58  * @return string|null value of parameter (null if parameter not exists)
59  */
60  public static function getApplicationParameter($appName, $name)
61  {
63  self::getParameter('a');
64  if (!isset(self::$cache[$appName])) {
65  $sql = sprintf("select paramv.name,paramv.val from paramv, application where application.name='%s' and application.id=paramv.appid and paramv.type !~ '^U';", pg_escape_string($appName));
66  simpleQuery('', $sql, $r);
67  $t = array();
68  foreach ($r as $values) {
69  $t[$values["name"]] = $values["val"];
70  }
71  $uid = getCurrentUser()->id;
72  $sql = sprintf("select paramv.name,paramv.val from paramv, application where application.name='%s' and application.id=paramv.appid and paramv.type = 'U%d';", pg_escape_string($appName) , $uid);
73 
74  simpleQuery('', $sql, $r);
75  foreach ($r as $values) {
76  $t[$values["name"]] = $values["val"];
77  }
78  self::$cache[$appName] = $t;
79  }
80  return isset(self::$cache[$appName][$name]) ? self::$cache[$appName][$name] : null;
81  }
82  /**
83  * set new Value for a global application parameter
84  * @deprecated use { @link ApplicationParameterManager } instead
85  * @param string $name parameter name
86  * @param string $value new value to set
87  * @throws Dcp\PMGT\Exception
88  */
89  public static function setGlobalParameter($name, $value)
90  {
92  // verify parameter exists
93  $sql = sprintf("select paramdef.*, application.name as appname from paramdef, application where paramdef.isglob='Y' and application.id=paramdef.appid and paramdef.name='%s';", pg_escape_string($name));
94  simpleQuery('', $sql, $r, false, true);
95  if (empty($r)) {
96  throw new \Dcp\PMGT\Exception("PMGT0003", $name);
97  }
98  self::setApplicationTypeParameter($r["isglob"] == "Y" ? PARAM_GLB : PARAM_APP, $r["appname"], $r["appid"], $r["name"], $value);
99  }
100  /**
101  * set new Value for an application parameter
102  * @deprecated use { @link ApplicationParameterManager } instead
103  * @param string $appName application name
104  * @param string $name parameter name
105  * @param string $value new value to set
106  * @throws Dcp\PMGT\Exception
107  */
108  public static function setApplicationParameter($appName, $name, $value)
109  {
111  // verify if parameter exists
112  $sql = sprintf("select paramdef.*, application.name as appname from paramdef, application where application.id = paramdef.appid and paramdef.name='%s';", pg_escape_string($name));
113  simpleQuery('', $sql, $r, false, true);
114 
115  if (empty($r)) {
116  throw new \Dcp\PMGT\Exception("PMGT0001", $name, $appName);
117  }
118  if ($r["appname"] == $appName) {
119  $appId = $r["appid"];
120  } else {
121  $sql = sprintf("select application.id from application where application.name='%s'", pg_escape_string($appName));
122  simpleQuery('', $sql, $appId, true, true);
123  if (empty($appId)) {
124  throw new \Dcp\PMGT\Exception("PMGT0006", $name, $appName);
125  }
126  }
127  self::setApplicationTypeParameter($r["isglob"] == "Y" ? PARAM_GLB : PARAM_APP, $appName, $appId, $r["name"], $value);
128  }
129  /**
130  * Update a user parameter value
131  * @deprecated use { @link ApplicationParameterManager } instead
132  * @param string $appName application name
133  * @param string $name parameter name (must be declared as user)
134  * @param string $value new value to set
135  * @param int $userId user account identificator (if null use current user)
136  * @throws Dcp\PMGT\Exception
137  */
138  public static function setUserApplicationParameter($appName, $name, $value, $userId = null)
139  {
141  // verify if parameter exists
142  $sql = sprintf("select paramdef.*, application.name as appname from paramdef, application where application.name in ('%s',(select childof from application where name='%s')) and application.id=paramdef.appid and paramdef.name = '%s' and isuser='Y';", pg_escape_string($appName) , pg_escape_string($appName) , pg_escape_string($name));
143  simpleQuery('', $sql, $r, false, true);
144  if (empty($r)) {
145  throw new \Dcp\PMGT\Exception("PMGT0004", $name, $appName);
146  }
147  if ($r["appname"] == $appName) {
148  $appId = $r["appid"];
149  } else {
150  $sql = sprintf("select application.id from application where application.name='%s'", pg_escape_string($appName));
151  simpleQuery('', $sql, $appId, true, true);
152  if (empty($appId)) {
153  throw new \Dcp\PMGT\Exception("PMGT0006", $name, $appName);
154  }
155  }
156  if ($userId === null) $userId = getCurrentUser()->id;
157  self::setUserApplicationTypeParameter($userId, $appName, $appId, $r["name"], $value);
158  }
159  /**
160  * Update a global user parameter value
161  * @deprecated use { @link ApplicationParameterManager } instead
162  * @param string $name parameter name (must be declared as user and global)
163  * @param string $value new value to set
164  * @param int $userId user account identificator (if null use current user)
165  * @throws Dcp\PMGT\Exception
166  */
167  public static function setGlobalUserParameter($name, $value, $userId = null)
168  {
170  // verify if parameter exists
171  $sql = sprintf("select paramdef.*, application.name as appname from paramdef, application where application.id=paramdef.appid and paramdef.name = '%s' and isuser='Y' and isglob='Y';", pg_escape_string($name));
172  simpleQuery('', $sql, $r, false, true);
173  if (empty($r)) {
174  throw new \Dcp\PMGT\Exception("PMGT0007", $name);
175  }
176 
177  if ($userId === null) $userId = getCurrentUser()->id;
178  self::setUserApplicationTypeParameter($userId, $r["appname"], $r["appid"], $r["name"], $value);
179  }
180  private static function setApplicationTypeParameter($type, $appName, $appId, $name, $value)
181  {
182  $a = self::getAction();
183  if ($a) {
184  $p = $a->parent->param;
185  } else {
186  $p = new Param(getDbAccess());
187  }
188 
189  $err = $p->set($name, $value, $type, $appId);
190 
191  if ($err) {
192  throw new \Dcp\PMGT\Exception("PMGT0002", $name, $appName, $err);
193  }
194  if (isset(self::$cache[$appName][$name])) self::$cache[$appName][$name] = $value;
195 
196  $a = self::getAction();
197  }
198  private static function setUserApplicationTypeParameter($userId, $appName, $appId, $name, $value)
199  {
200  $a = self::getAction();
201  if ($a) {
202  $p = $a->parent->param;
203  } else {
204  $p = new Param(getDbAccess());
205  }
206 
207  simpleQuery('', sprintf("select id from users where id=%d and accounttype='U'", $userId) , $uid, true, true);
208  if (!$uid) {
209  throw new \Dcp\PMGT\Exception("PMGT0008", $name, $appName, $userId);
210  }
211 
212  $err = $p->set($name, $value, PARAM_USER . $userId, $appId);
213  if ($err) {
214  throw new \Dcp\PMGT\Exception("PMGT0005", $name, $appName, $err);
215  }
216  if (isset(self::$cache[$appName][$name])) self::$cache[$appName][$name] = $value;
217  }
218 }
static setUserApplicationParameter($appName, $name, $value, $userId=null)
const PARAM_APP
Definition: Class.Param.php:21
global $action
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
const PARAM_USER
Definition: Class.Param.php:25
static setGlobalParameter($name, $value)
static getApplicationParameter($appName, $name)
static setGlobalUserParameter($name, $value, $userId=null)
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
const PARAM_GLB
Definition: Class.Param.php:23
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
getCurrentUser()
Definition: Lib.Common.php:250
static setApplicationParameter($appName, $name, $value)
getDbAccess()
Definition: Lib.Common.php:368
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
$value
← centre documentaire © anakeen