1 <?php
2 class applicationParameters extends plugin
3 {
4 /* Parameters */
5 var $option_name= array();
6 var $option_value= array();
8 /* attribute list for save action */
9 var $attributes= array("gosaApplicationParameter");
11 function applicationParameters (&$config, $dn= NULL, $parent= NULL)
12 {
13 plugin::plugin ($config, $dn, $parent);
15 $this->gosaApplicationParameter = array();
17 if (isset($this->attrs['gosaApplicationParameter'])){
18 $this->is_account= TRUE;
19 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
20 $option= preg_replace('/^[^:]+:/', '',
21 $this->attrs['gosaApplicationParameter'][$i]);
22 $name= preg_replace('/:.*$/', '',
23 $this->attrs['gosaApplicationParameter'][$i]);
24 $this->option_name[$i]= $name;
25 $this->option_value[$i]= $option;
26 }
27 } else {
28 $this->is_account= FALSE;
29 }
30 }
32 function execute()
33 {
34 /* Call parent execute */
35 plugin::execute();
37 /* Do we need to flip is_account state? */
38 if(isset($_POST['modify_state'])){
39 if($this->is_account && $this->acl_is_removeable()){
40 $this->is_account= FALSE;
41 }elseif(!$this->is_account && $this->acl_is_createable()){
42 $this->is_account= TRUE;
43 }
44 }
46 /* Show tab dialog headers */
47 $display= "";
48 if ($this->parent !== NULL){
49 if ($this->is_account){
50 $display= $this->show_disable_header(_("Remove options"),msgPool::featuresEnabled(_("parameter")));
51 } else {
52 $display= $this->show_enable_header(_("Create options"), msgPool::featuresDisabled(_("parameter")));
53 $this->parent->by_object['application']->generateTemplate();
54 return ($display);
55 }
56 }
58 if($this->acl_is_writeable("gosaApplicationParameter")){
60 /* Add option to list */
61 if (isset($_POST['add_option'])){
62 $i= count($this->option_name);
63 $this->option_name[$i]= "";
64 $this->option_value[$i]= "";
65 }
67 /* Remove value from list */
68 for ($i= 0; $i<count($this->option_name); $i++){
69 if (isset($_POST["remove$i"])){
70 $k= 0;
71 $on= array();
72 $ov= array();
73 for ($j= 0; $j<count($this->option_name); $j++){
74 if ($j != $i){
75 $on[$k]= $this->option_name[$j];
76 $ov[$k]= $this->option_value[$j];
77 $k++;
78 }
79 }
80 $this->option_name= $on;
81 $this->option_value= $ov;
82 break;
83 }
84 }
85 }
87 /* Generate list of attributes */
88 if (count($this->option_name) == 0){
89 $this->option_name[]= "";
90 $this->option_value[]= "";
91 }
95 $acl = $this->getacl("gosaApplicationParameter") ;
96 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
97 if (count ($this->option_name)){
99 for ($i= 0; $i < count($this->option_name); $i++){
100 $name = $this->option_name[$i];
101 $value= $this->option_value[$i];
103 $tag = "";
104 if(!preg_match("/w/",$acl)){
105 $tag = " disabled ";
106 }
108 if(!preg_match("/r/",$acl)){
109 $name = "";
110 $value= "";
111 }
113 $table.="<tr>".
114 " <td>".
115 " <input name=\"option$i\" size=25 maxlength=50 value=\"".$name."\" ".$tag.">".
116 " </td>".
117 " <td>".
118 " <input name=\"value$i\" size=60 maxlength=250 value=\"".$value."\" ".$tag.">".
119 " <br>".
120 " </td>".
121 " <td>".
122 " <input type=\"submit\" name=\"remove$i\" value=\""._("Remove")."\" ".$tag.">".
123 " </td>".
124 "</tr>";
125 }
126 }
127 $table.= "</table>";
128 $table.="<input type=\"submit\" name=\"add_option\" $tag value=\""._("Add option")."\">";
130 /* Show main page */
131 $smarty= get_smarty();
132 $tmp = $this->plInfo();
133 foreach($tmp['plProvidedAcls'] as $name => $translation){
134 $smarty->assign($name."ACL",$this->getacl($name));
135 }
137 $smarty->assign("table", $table);
138 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
139 $this->parent->by_object['application']->generateTemplate();
140 return ($display);
141 }
143 function remove_from_parent()
144 {
145 $ldap= $this->config->get_ldap_link();
147 /* Zero attributes */
148 $this->attrs= array();
149 $this->attrs['gosaApplicationParameter']= array();
151 $ldap->cd($this->dn);
152 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
153 $this->attributes, "Save");
154 $this->cleanup();
155 $ldap->modify ($this->attrs);
157 if (!$ldap->success()){
158 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
159 }
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']) && $this->acl_is_writeable("gosaApplicationParameter")){
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 /* Check for empty option names */
190 if (!$this->option_name[$i]) {
191 $message[]= msgPool::required(_("Name"));
192 }
193 /* Check for valid option names */
194 elseif (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
195 $message[]= msgPool::invalid(_("Name"), $this->option_name[$i],"/^[a-z0-9_]+$/i");
196 }
197 }
199 return $message;
200 }
203 /* Save to LDAP */
204 function save()
205 {
206 /* Generate values */
207 $this->attrs= array();
208 if (count($this->option_name) == 0){
209 $this->attrs['gosaApplicationParameter']= array();
210 } else {
211 for ($i= 0; $i<count($this->option_name); $i++){
212 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
213 ":".$this->option_value[$i];
214 }
215 }
217 /* Write back to ldap */
218 $ldap= $this->config->get_ldap_link();
219 $ldap->cd($this->dn);
220 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
221 $this->attributes, "Save");
222 $this->cleanup();
223 $ldap->modify ($this->attrs);
225 if (!$ldap->success()){
226 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
227 }
229 /* Optionally execute a command after we're done */
230 $this->handle_post_events('modify');
231 }
233 function PrepareForCopyPaste($source)
234 {
235 plugin::PrepareForCopyPaste($source);
237 $source_o = new applicationParameters($this->config,$source['dn']);
238 $this->option_name = $source_o->option_name;
239 $this->option_value = $source_o->option_value;
241 /* Set is_account state so that the save function is called properly */
242 $this->is_account = TRUE;
243 }
245 /* Return plugin informations for acl handling
246 #FIXME FAIscript seams to ununsed within this class... */
247 static function plInfo()
248 {
249 return (array(
250 "plShortName" => _("Parameter"),
251 "plDescription" => _("Parameter configuration"),
252 "plSelfModify" => FALSE,
253 "plDepends" => array(),
254 "plPriority" => 0,
255 "plSection" => array("administration"),
256 "plCategory" => array("application"),
258 "plProvidedAcls"=> array(
259 "gosaApplicationParameter" => _("Application parameter settings"))
260 ));
261 }
264 }
265 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
266 ?>