99a34440b7033e9038069d68debd57366f307003
1 <?php
4 class configViewer extends management
5 {
6 var $plHeadline= "Preferences";
7 var $plDescription= "Configure global and special GOsa settings like hooks and plugin parameters";
8 var $plIcon = "plugins/configViewer/images/plugin.png";
10 function __construct($config,$ui)
11 {
12 $this->config = $config;
13 $this->ui = $ui;
15 // Build filter
16 if (session::global_is_set(get_class($this)."_filter")){
17 $filter= session::global_get(get_class($this)."_filter");
18 } else {
19 $filter = new filter(get_template_path("property-filter.xml", true));
20 $filter->setObjectStorage($this->storagePoints);
21 }
22 $this->setFilter($filter);
24 // Build headpage
25 $headpage = new listing(get_template_path("property-list.xml", true));
26 $headpage->registerElementFilter("propertyName", "configViewer::propertyName");
27 $headpage->registerElementFilter("propertyGroup", "configViewer::propertyGroup");
28 $headpage->registerElementFilter("propertyClass", "configViewer::propertyClass");
29 $headpage->registerElementFilter("propertyValue", "configViewer::propertyValue");
30 $headpage->setFilter($filter);
31 parent::__construct($config, $ui, "property", $headpage);
33 $this->registerAction("saveProperties","saveProperties");
34 $this->registerAction("cancelProperties","cancelProperties");
35 }
38 function execute()
39 {
40 // Walk trough all properties and check if there posts for us.
41 $all = $this->config->configRegistry->getAllProperties();
42 foreach($all as $prop){
43 $post = "{$prop->getClass()}:{$prop->getName()}";
44 if(isset($_POST[$post]) && !in_array($prop->getStatus(),array('removed'))){
45 $prop->setValue(get_post($post));
46 }
47 }
48 return(management::execute());
49 }
51 function renderList()
52 {
53 // Walk trough all properties and check if there posts for us.
54 $all = $this->config->configRegistry->getAllProperties();
56 $htmlTooltips = "";
57 $jsTooltips = "";
58 foreach($all as $prop){
59 $modified = in_array($prop->getStatus(),array('modified','removed'));
60 if($modified) break;
61 }
63 $smarty = get_smarty();
64 $smarty->assign('is_modified', $modified);
65 $smarty->assign('htmlTooltips', $htmlTooltips);
66 $smarty->assign('jsTooltips', $jsTooltips);
67 return(management::renderList());
68 }
71 function cancelProperties()
72 {
73 $this->config->configRegistry->reload($force=TRUE);
74 }
76 function saveProperties()
77 {
78 $all = $this->config->configRegistry->getAllProperties();
79 $valid = TRUE;
80 foreach($all as $prop){
81 $valid &= $prop->check();
82 }
84 if($valid){
85 $this->config->configRegistry->saveChanges();
86 }
87 }
89 function detectPostActions()
90 {
91 $action = management::detectPostActions();
92 if(isset($_POST['saveProperties'])) $action['action'] = 'saveProperties';
93 if(isset($_POST['cancelProperties'])) $action['action'] = 'cancelProperties';
94 return($action);
95 }
97 protected function removeEntryRequested($action="",$target=array(),$all=array())
98 {
99 foreach($target as $dn){
100 list($class,$name) = preg_split("/:/", $dn);
101 if($this->config->configRegistry->propertyExists($class,$name)){
102 $prop = $this->config->configRegistry->getProperty($class,$name);
103 $prop->restoreDefault();
104 }
105 }
106 }
108 static function propertyGroup($group, $description = array())
109 {
110 return($group[0]);
111 }
112 static function propertyClass($class, $description = array())
113 {
114 global $config;
115 if(isset($config->configRegistry->classToName[$class[0]])){
116 $class = $config->configRegistry->classToName[$class[0]];
117 }else{
118 $class = $class[0];
119 }
120 return($class);
121 }
122 static function propertyName($class,$cn, $description,$mandatory)
123 {
124 $id = "{$class[0]}_{$cn[0]}";
126 $title = _("No description");
127 if(isset($description[0])) $title = htmlentities($description[0],ENT_COMPAT, 'UTF-8');
128 $title = preg_replace("/\n/", "<br>", $title);
129 $tooltip = "<div id='tooltip_{$id}' class='tooltip' style='display:none'>".$title."</div>";
131 $must = ($mandatory[0]) ? "<span class='required'>*</span>" : "";
133 return($tooltip."<span title='tooltip_{$id}'>{$cn[0]}{$must}</span>");
134 }
135 static function propertyValue($class,$cn,$value,$type,$default,$defaults,$check,$mandatory)
136 {
137 $ssize = "208px";
138 $isize = "200px";
139 $name = "{$class[0]}:{$cn[0]}";
140 $value = htmlentities($value[0],ENT_COMPAT,'UTF-8');
141 switch($type[0]){
142 case 'bool':
143 $res = "<select size=1 name=\"{$name}\" style='width:{$ssize}'>";
144 $false = (preg_match('/true/i', $value)) ? '' : "selected";
145 $true = (preg_match('/true/i', $value)) ? "selected" : '';
146 $res.= "<option {$false} value='false'>"._("FALSE")."</option>";
147 $res.= "<option {$true} value='true'>"._("TRUE")."</option>";
148 $res.= "</select>";
149 case 'switch':
150 if(!empty($defaults[0])){
151 $data = call_user_func(preg_split("/::/", $defaults[0]), $class[0],$cn[0],$value, $type[0]);
152 if(is_array($data)){
153 $res = "<select size=1 name=\"{$name}\" style='width:{$ssize}'>";
154 foreach($data as $oValue => $oDesc){
155 if($oValue == $value){
156 $res.="<option selected value=\"{$oValue}\">{$oDesc}</option>\n";
157 }else{
158 $res.="<option value=\"{$oValue}\">{$oDesc}</option>\n";
159 }
160 }
161 $res.= "</select>";
162 }
163 }
164 break;
165 case 'dn':
166 case 'rdn':
167 case 'uri':
168 case 'path':
169 case 'file':
170 case 'command':
171 case 'string':
172 case 'integer':
173 $res = "<input style='width:{$isize}' type='text' value=\"{$value}\" name=\"{$name}\">";
174 break;
175 default: echo $type[0].$name." ";$res = "";
176 }
178 // Check if it is a required value.
179 if($mandatory[0] && empty($value)){
180 $res.= "<rowClass:entry-error/>";
181 }
183 // Color row in red if the check methods returns false.
184 if(!empty($check[0]) && !empty($value)){
185 $check = call_user_func(preg_split("/::/", $check[0]),$displayMessage=FALSE, $class[0], $cn[0], $value, $type[0]);
186 if(!$check){
187 $res.= "<rowClass:entry-error/>";
188 }
189 }
191 return($res);
192 }
193 }
194 ?>