Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
editapplicationparameter.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 include_once ("FDL/Class.Dir.php");
8 include_once ("FDL/editutil.php");
9 /**
10  * Edit application parameters
11  * @param Action $action
12  * @return bool
13  */
15 {
16 
17  $usage = new ActionUsage($action);
18  $parameterid = $usage->addRequiredParameter("parameterId", _("Parameter's id"));
19  $appid = $usage->addOptionalParameter("appId", _("Application Id"));
20  $default = $usage->addOptionalParameter("emptyValue", _("value for empty field"));
21  $value = $usage->addOptionalParameter("value", _("value in field"));
22  $onChange = $usage->addOptionalParameter("submitOnChange", _("Sending input on change?"));
23  $localSubmit = $usage->addOptionalParameter("localSubmit", _("Adding button to submit")) == "yes" ? true : false;
24  $submitLabel = $usage->addOptionalParameter("submitLabel", _("Label of submit button") , array() , _("Submit"));
25  $usage->setStrictMode();
26  $usage->verify();
27 
28  $action->lay->eset("parameterid", $parameterid);
29 
30  $paramdef = array();
31  $err = simpleQuery($action->dbaccess, sprintf("SELECT * from paramdef where name='%s'", pg_escape_string($parameterid)) , $paramdef);
32  if ($err) {
33  $action->AddWarningMsg(sprintf(_("Parameter [%s] not found. Error message: [%s]") , $parameterid, $err));
34  $action->lay->template = htmlspecialchars(sprintf(_("Parameter [%s] not found. Error message: [%s]") , $parameterid, $err) , ENT_QUOTES);
35  $action->lay->noparse = true;
36  return false;
37  }
38  $action->lay->set("type_text", ($paramdef[0]["kind"] == "text"));
39  $enum = substr($paramdef[0]["kind"], 0, 4) == "enum";
40  $action->lay->set("type_enum", $enum);
41 
42  $type = ($paramdef[0]["isglob"] == "Y") ? Param::PARAM_GLB : Param::PARAM_APP;
43  $action->lay->set("type", $type);
44 
45  if (!$appid) {
46  if ($type !== Param::PARAM_GLB) {
47  $action->AddWarningMsg(sprintf(_("Parameter [%s] is not global, an apllication muste be given") , $parameterid));
48  $action->lay->template = htmlspecialchars(sprintf(_("Parameter [%s] is not global, an apllication muste be given") , $parameterid) , ENT_QUOTES);
49  $action->lay->noparse = true;
50  return false;
51  }
52  $appid = $paramdef[0]["appid"];
53  } else {
54  $app = new Application();
55  $null = null;
56  $err = $app->set($appid, $null);
57  if ($err) {
58  $action->AddWarningMsg(sprintf(_("Application [%s] not found. Error message: [%s]") , $appid, $err));
59  $action->lay->template = htmlspecialchars(sprintf(_("Application [%s] not found. Error message: [%s]") , $appid, $err) , ENT_QUOTES);
60  $action->lay->noparse = true;
61  return false;
62  }
63  $appid = $app->id;
64  }
65  $action->lay->set("appid", getApplicationNameFromId($action->dbaccess, $appid));
66 
67  $val = array();
68  $query = sprintf("SELECT * from paramv where name='%s' and appid='%s' and type='%s'", pg_escape_string($parameterid) , pg_escape_string($appid) , pg_escape_string($type));
69  $err = simpleQuery($action->dbaccess, $query, $val);
70  if ($err) {
71  $action->AddWarningMsg(sprintf(_("Parameter [%s] not found. Error message: [%s]") , $parameterid, $err));
72  $action->lay->template = htmlspecialchars(sprintf(_("Parameter [%s] not found. Error message: [%s]") , $parameterid, $err));
73  $action->lay->noparse = true;
74  return false;
75  }
76  if (!$value) {
77  if ($default !== null) {
78  $value = $default;
79  } else {
80  $value = $val[0]["val"];
81  }
82  }
83 
84  if ($onChange == "no") {
85  $onChange = "";
86  } elseif ($onChange == "yes" || (!$onChange && !$localSubmit)) {
87  $onChange = "yes";
88  }
89 
90  $action->lay->set("local_submit", (bool)$localSubmit);
91  $action->lay->eset("submit_label", $submitLabel);
92  $action->lay->set("on_change", "");
93  $action->lay->set("change", ($onChange != ""));
94  if ($enum) {
95  $matches = array();
96  preg_match('/enum\(([^.]*)\)/', $paramdef[0]["kind"], $matches);
97  $valuestmp = explode("|", $matches[1]);
98  $values = array();
99  foreach ($valuestmp as $v) {
100  if ($v == $value) {
101  $values[] = array(
102  "selected" => 'selected="selected"',
103  "value" => $v
104  );
105  } else {
106  $values[] = array(
107  "selected" => '',
108  "value" => $v
109  );
110  }
111  }
112  $action->lay->eSetBlockData("options", $values);
113  } else {
114  $action->lay->eset("value", $value);
115  }
116  $label = $paramdef[0]["descr"] ? _($paramdef[0]["descr"]) : "";
117  $action->lay->set("label", $label);
118 
119  $action->parent->addJsRef("lib/jquery/jquery.js");
120  $action->parent->addJsRef("FDL/Layout/editparameter.js");
121  return true;
122 }
123 
124 function getApplicationNameFromId($dbaccess, $id, &$cache = null)
125 {
126  if (is_array($cache) && array_key_exists('app', $cache)) {
127  if (array_key_exists($id, $cache['app'])) {
128  return $cache['app'][$id];
129  }
130  }
131 
132  $query = new QueryDb($dbaccess, "application");
133  $query->addQuery(sprintf("id = %s", pg_escape_string($id)));
134  $res = $query->query(0, 0, "TABLE");
135  if (!is_array($res)) {
136  return null;
137  }
138 
139  $name = $res[0]['name'];
140  if (is_array($cache) && array_key_exists('app', $cache)) {
141  $cache['app'][$id] = $name;
142  }
143 
144  return $name;
145 }
global $action
getApplicationNameFromId($dbaccess, $id, &$cache=null)
$app
const PARAM_APP
Definition: Class.Param.php:32
Verify arguments for action function.
editapplicationparameter(Action &$action)
const PARAM_GLB
Definition: Class.Param.php:33
$dbaccess
Definition: checkVault.php:17
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
$null
$usage
$value
← centre documentaire © anakeen