1 <?php
2 class applicationParameters extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage application class parameters";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Parameters */
10 var $option_name= array();
11 var $option_value= array();
13 /* attribute list for save action */
14 var $attributes= array("gosaApplicationParameter");
15 var $objectclasses= array();
17 var $CopyPasteVars = array("option_name","option_value");
19 function applicationParameters ($config, $dn= NULL, $parent= NULL)
20 {
21 plugin::plugin ($config, $dn, $parent);
23 $this->gosaApplicationParameter = array();
25 if (isset($this->attrs['gosaApplicationParameter'])){
26 $this->is_account= TRUE;
27 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
28 $option= preg_replace('/^[^:]+:/', '',
29 $this->attrs['gosaApplicationParameter'][$i]);
30 $name= preg_replace('/:.*$/', '',
31 $this->attrs['gosaApplicationParameter'][$i]);
32 $this->option_name[$i]= $name;
33 $this->option_value[$i]= $option;
34 }
35 } else {
36 $this->is_account= FALSE;
37 }
38 }
40 function execute()
41 {
42 /* Call parent execute */
43 plugin::execute();
45 /* Do we need to flip is_account state? */
46 if (isset($_POST['modify_state'])){
47 $this->is_account= !$this->is_account;
48 }
50 /* Show tab dialog headers */
51 $display= "";
52 if ($this->parent != NULL){
53 if ($this->is_account){
54 $display= $this->show_disable_header(_("Remove options"),
55 _("This application has options. You can disable them by clicking below."));
56 } else {
57 $display= $this->show_enable_header(_("Create options"),
58 _("This application has options disabled. You can enable them by clicking below."));
59 $this->parent->by_object['application']->generateTemplate();
60 return ($display);
61 }
62 }
64 /* Add option to list */
65 if (isset($_POST['add_option'])){
66 $i= count($this->option_name);
67 $this->option_name[$i]= "";
68 $this->option_value[$i]= "";
69 }
71 /* Remove value from list */
72 for ($i= 0; $i<count($this->option_name); $i++){
73 if (isset($_POST["remove$i"])){
74 $k= 0;
75 $on= array();
76 $ov= array();
77 for ($j= 0; $j<count($this->option_name); $j++){
78 if ($j != $i){
79 $on[$k]= $this->option_name[$j];
80 $ov[$k]= $this->option_value[$j];
81 $k++;
82 }
83 }
84 $this->option_name= $on;
85 $this->option_value= $ov;
86 break;
87 }
88 }
90 /* Generate list of attributes */
91 if (count($this->option_name) == 0){
92 $this->option_name[]= "";
93 $this->option_value[]= "";
94 }
97 $acl = $this->getacl("gosaApplicationParameter") ;
98 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
99 if (count ($this->option_name)){
101 for ($i= 0; $i < count($this->option_name); $i++){
102 $name = $this->option_name[$i];
103 $value= $this->option_value[$i];
105 $tag = "";
106 if(!preg_match("/w/",$acl)){
107 $tag = " disabled ";
108 }
110 if(!preg_match("/r/",$acl)){
111 $name = "";
112 $value= "";
113 }
115 $table.="<tr>".
116 " <td>".
117 " <input name=\"option$i\" size=25 maxlength=50 value=\"".$name."\" ".$tag.">".
118 " </td>".
119 " <td>".
120 " <input name=\"value$i\" size=60 maxlength=250 value=\"".$value."\" ".$tag.">".
121 " <br>".
122 " </td>".
123 " <td>".
124 " <input type=\"submit\" name=\"remove$i\" value=\""._("Remove")."\" ".$tag.">".
125 " </td>".
126 "</tr>";
127 }
128 }
129 $table.= "</table>";
130 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
132 /* Show main page */
133 $smarty= get_smarty();
134 $tmp = $this->plInfo();
135 foreach($tmp['plProvidedAcls'] as $name => $translation){
136 $smarty->assign($name."ACL",$this->getacl($name));
137 }
139 $smarty->assign("table", $table);
140 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
141 $this->parent->by_object['application']->generateTemplate();
142 return ($display);
143 }
145 function remove_from_parent()
146 {
147 $ldap= $this->config->get_ldap_link();
149 /* Zero attributes */
150 $this->attrs= array();
151 $this->attrs['gosaApplicationParameter']= array();
153 $ldap->cd($this->dn);
154 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
155 $this->attributes, "Save");
156 $this->cleanup();
157 $ldap->modify ($this->attrs);
159 show_ldap_error($ldap->get_error(), sprintf(_("Removing of application parameters with dn '%s' failed."),$this->dn));
161 /* Optionally execute a command after we're done */
162 $this->handle_post_events('remove');
163 }
166 /* Save data to object */
167 function save_object()
168 {
169 if (isset($_POST['option0'])){
170 for ($i= 0; $i<count($this->option_name); $i++){
171 $this->option_name[$i]= $_POST["option$i"];
172 $this->option_value[$i]= "";
173 if ($_POST["value$i"] != ""){
174 $this->option_value[$i]= $_POST["value$i"];
175 }
176 }
177 }
178 }
181 /* Check values */
182 function check()
183 {
184 /* Call common method to give check the hook */
185 $message= plugin::check();
187 /* Check for valid option names */
188 for ($i= 0; $i<count($this->option_name); $i++){
189 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
190 $message[]= sprintf(_("Value '%s' specified as option name is not valid."),
191 $this->option_name[$i]);
192 }
193 }
195 return $message;
196 }
199 /* Save to LDAP */
200 function save()
201 {
202 /* Generate values */
203 $this->attrs= array();
204 if (count($this->option_name) == 0){
205 $this->attrs['gosaApplicationParameter']= array();
206 } else {
207 for ($i= 0; $i<count($this->option_name); $i++){
208 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
209 ":".$this->option_value[$i];
210 }
211 }
213 /* Write back to ldap */
214 $ldap= $this->config->get_ldap_link();
215 $ldap->cd($this->dn);
216 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
217 $this->attributes, "Save");
218 $this->cleanup();
219 $ldap->modify ($this->attrs);
221 show_ldap_error($ldap->get_error(), sprintf(_("Saving of application parameters with dn '%s' failed."),$this->dn));
223 /* Optionally execute a command after we're done */
224 $this->handle_post_events('modify');
225 }
227 /* Return plugin informations for acl handling
228 #FIXME FAIscript seams to ununsed within this class... */
229 function plInfo()
230 {
231 return (array(
232 "plShortName" => _("Parameter"),
233 "plDescription" => _("Parameter configuration"),
234 "plSelfModify" => FALSE,
235 "plDepends" => array(),
236 "plPriority" => 0,
237 "plSection" => array("administration"),
238 "plCategory" => array("application"),
240 "plProvidedAcls"=> array(
241 "gosaApplicationParameter" => _("Application parameter settings"))
242 ));
243 }
246 }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>