22 private static $cache = array();
29 self::$cache = array();
46 if ($userId === null) {
49 $applicationId = self::getApplicationId($application, $parameterName);
50 if (isset(self::$cache[$applicationId .
' ' . $parameterName .
' ' . $userId])) {
51 return self::$cache[$applicationId .
' ' . $parameterName .
' ' . $userId];
53 $sql = sprintf(
"select val from paramv where appid=%d and type='U%d' and name='%s';", $applicationId, $userId, pg_escape_string($parameterName));
56 if ($return !==
false) {
57 self::$cache[$applicationId .
' ' . $parameterName .
' ' . $userId] = $return;
78 return self::getCommonParameterValue($application, $parameterName);
93 $applicationId = self::getApplicationId($application, $parameterName);
94 if (isset(self::$cache[$applicationId .
' ' . $parameterName])) {
95 return self::$cache[$applicationId .
' ' . $parameterName];
97 $sql = sprintf(
"select val from paramv where appid=%d and type !~ '^U' and name='%s';", $applicationId, $parameterName, pg_escape_string($parameterName));
100 if ($return !==
false) {
101 self::$cache[$applicationId .
' ' . $parameterName] = $return;
128 $applicationId = self::getApplicationId($application, $parameterName);
132 $parameter =
$action->parent->param;
137 if ($userId === null) {
143 $type = self::getParameter($applicationId, $parameterName);
145 if (empty(
$type) ||
$type[
"isuser"] ===
"N") {
146 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0006", $applicationId, $parameterName);
150 simpleQuery(
'', sprintf(
"select true from users where id=%d and accounttype='U'", $userId) , $uid,
true,
true,
true);
152 if ($uid ===
false) {
153 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0007", $applicationId, $parameterName, $userId);
158 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0006", $applicationId, $parameterName,
$err);
160 self::$cache[$applicationId .
' ' . $parameterName .
' ' . $userId] =
$value;
176 self::setCommonParameterValue($application, $parameterName,
$value);
192 $applicationId = self::getApplicationId($application, $parameterName);
195 $sql = sprintf(
"select type from paramv where (name='%s' and appid = %d);", pg_escape_string($parameterName) , $applicationId);
198 if ($isGlobal ===
false) {
200 $sql = sprintf(
"select isglob from paramdef where (name='%s' and appid = %d);", pg_escape_string($parameterName) , $applicationId);
202 if ($isGlobal ===
false) {
203 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0011", $parameterName);
205 if ($isGlobal ==
'Y') {
212 $parameter =
$action->parent->param;
222 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0009", $parameterName, $applicationId,
$err);
224 self::$cache[$applicationId .
' ' . $parameterName] =
$value;
238 if ((
$value = self::_catchDeprecatedGlobalParameter($parameterName)) !== null) {
242 $applicationId = self::getApplicationId($application, $parameterName);
243 $type = self::getParameter($applicationId, $parameterName);
246 if (
$type[
"isuser"] ===
"Y") {
247 $return = self::getUserParameterValue($applicationId, $parameterName);
248 if ($return === null) {
249 $return = self::getUserParameterDefaultValue($applicationId, $parameterName);
252 $return = self::getCommonParameterValue($applicationId, $parameterName);
277 $applicationId = self::getApplicationId($application, $parameterName);
279 $type = self::getParameter($applicationId, $parameterName);
283 if (
$type[
"isuser"] ===
"Y") {
284 self::setUserParameterValue($applicationId, $parameterName,
$value, null,
false);
286 self::setCommonParameterValue($applicationId, $parameterName,
$value);
315 $applicationId = self::getApplicationId($application, $parameterName);
318 $sql = sprintf(
"SELECT
321 application AS app LEFT OUTER JOIN application AS parent ON (app.childof = parent.name),
324 (paramdef.appid = app.id OR paramdef.appid = parent.id or paramdef.appid = 1)
325 and paramdef.name = '%s'
326 and app.id = %d;", pg_escape_string($parameterName) , $applicationId);
328 if (empty($result)) {
329 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0008", $parameterName, $applicationId);
345 $applicationId = self::getApplicationId($application);
348 $sql = sprintf(
"SELECT
350 app.name as applicationName
352 application AS app LEFT OUTER JOIN application AS parent ON (app.childof = parent.name),
355 (paramdef.appid = app.id OR paramdef.appid = parent.id or paramdef.appid = 1)
356 and app.id = %d;", $applicationId);
358 if (empty($result)) {
359 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0003", $applicationId);
372 private static function getApplicationId($application, $parameter =
"")
374 $applicationName =
"";
378 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0010");
380 $applicationId = self::getGlobalParameterApplicationName($parameter);
381 if ($applicationId ===
false) {
382 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0002", $parameter);
386 if ($action instanceof
Action) {
387 $applicationName = $action->parent->name;
388 $applicationId = $action->parent->id;
390 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0004");
393 $applicationName = $application->name;
394 } elseif ((!is_int($application) ? (ctype_digit($application)) :
true)) {
395 $applicationId = $application;
396 } elseif (is_string($application)) {
397 $applicationName = $application;
399 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0004");
402 if ($applicationName && empty($applicationId)) {
403 $applicationId = self::convertApplicationNameToId($applicationName);
404 if ($applicationId ===
false) {
405 throw new \Dcp\ApplicationParameterManager\Exception(
"APM0003", $application);
409 return $applicationId;
418 private static function getGlobalParameterApplicationName($parameterName)
420 if ((
$value = self::_catchDeprecatedGlobalParameter($parameterName)) !== null) {
423 $sql = sprintf(
"select paramv.appid from paramv, application where paramv.type='G' and application.id=paramv.appid and paramv.name='%s';", pg_escape_string($parameterName));
435 private static function convertApplicationNameToId($applicationName)
437 $sql = sprintf(
"select id from application where name = '%s';", pg_escape_string($applicationName));
438 $applicationId = null;
440 return $applicationId;
447 private static function getAction()
464 switch ($parameterName) {
468 $msg = sprintf(
"Application parameter '%s' is deprecated: use \"getDbAccess()\", \"\$action->dbaccess\", \"\$application->dbaccess\", or \"\$doc->dbaccess\" instead.", $parameterName);
473 $msg = sprintf(
"Application parameter '%s' is deprecated: use DEFAULT_PUBDIR constant instead.", $parameterName);
478 $action = self::getAction();
479 if (isset($action->log)) {
480 $action->log->deprecated($msg);
482 error_log(__METHOD__ .
" " . $msg);
static _catchDeprecatedGlobalParameter($parameterName)
static setUserParameterDefaultValue($application, $parameterName, $value)
static getParameterValue($application, $parameterName)
static getScopedParameterValue($parameter)
static setParameterValue($application, $parameterName, $value)
static getParameters($application)
static setCommonParameterValue($application, $parameterName, $value)
const CURRENT_APPLICATION
getParam($name, $def="")
must be in core or global type
static getUserParameterDefaultValue($application, $parameterName)
static setUserParameterValue($application, $parameterName, $value, $userId=null, $check=true)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
static getCommonParameterValue($application, $parameterName)
if($file) if($subject==""&&$file) if($subject=="") $err
static getParameter($application, $parameterName)
static getUserParameterValue($application, $parameterName, $userId=null)