Code

Removed CLI
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationParameters.inc
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");
10   var $objectclasses= array();
12   var $CopyPasteVars = array("option_name","option_value");
14   function applicationParameters (&$config, $dn= NULL, $parent= NULL)
15   {
16     plugin::plugin ($config, $dn, $parent);
18     $this->gosaApplicationParameter = array();
20     if (isset($this->attrs['gosaApplicationParameter'])){
21       $this->is_account= TRUE;
22       for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
23         $option= preg_replace('/^[^:]+:/', '',
24             $this->attrs['gosaApplicationParameter'][$i]);
25         $name= preg_replace('/:.*$/', '',
26             $this->attrs['gosaApplicationParameter'][$i]);
27         $this->option_name[$i]= $name;
28         $this->option_value[$i]= $option;
29       }
30     } else {
31       $this->is_account= FALSE;
32     }
33   }
35   function execute()
36   {
37     /* Call parent execute */
38     plugin::execute();
40     /* Do we need to flip is_account state? */
41     if (isset($_POST['modify_state'])){
42       $this->is_account= !$this->is_account;
43     }
45     /* Show tab dialog headers */
46     $display= "";
47     if ($this->parent !== NULL){
48       if ($this->is_account){
49         $display= $this->show_disable_header(_("Remove options"),
50             _("This application has options. You can disable them by clicking below."));
51       } else {
52         $display= $this->show_enable_header(_("Create options"),
53             _("This application has options disabled. You can enable them by clicking below."));
54         $this->parent->by_object['application']->generateTemplate();
55         return ($display);
56       }
57     }
59     /* Add option to list */
60     if (isset($_POST['add_option'])){
61       $i= count($this->option_name);
62       $this->option_name[$i]= "";
63       $this->option_value[$i]= "";
64     }
66     /* Remove value from list */
67     for ($i= 0; $i<count($this->option_name); $i++){
68       if (isset($_POST["remove$i"])){
69         $k= 0;
70         $on= array();
71         $ov= array();
72         for ($j= 0; $j<count($this->option_name); $j++){
73           if ($j != $i){
74             $on[$k]= $this->option_name[$j];
75             $ov[$k]= $this->option_value[$j];
76             $k++;
77           }
78         }
79         $this->option_name= $on;
80         $this->option_value= $ov;
81         break;
82       }
83     }
85     /* Generate list of attributes */
86     if (count($this->option_name) == 0){
87       $this->option_name[]= "";
88       $this->option_value[]= "";
89     }
92     $acl = $this->getacl("gosaApplicationParameter")    ;
93     $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
94     if (count ($this->option_name)){
96       for ($i= 0; $i < count($this->option_name); $i++){
97         $name = $this->option_name[$i];
98         $value= $this->option_value[$i];
100         $tag = "";
101         if(!preg_match("/w/",$acl)){
102           $tag = " disabled ";
103         }
105         if(!preg_match("/r/",$acl)){
106           $name = "";
107           $value= "";
108         }
110         $table.="<tr>".
111           " <td>".
112           "  <input name=\"option$i\" size=25 maxlength=50 value=\"".$name."\" ".$tag.">".
113           " </td>".
114           " <td>".
115           "  <input name=\"value$i\" size=60 maxlength=250 value=\"".$value."\" ".$tag.">".
116           "  <br>".
117           " </td>".
118           " <td>".
119           "  <input type=\"submit\" name=\"remove$i\" value=\""._("Remove")."\" ".$tag.">".
120           " </td>".
121           "</tr>";
122       }
123     }
124     $table.= "</table>";
125     $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
127     /* Show main page */
128     $smarty= get_smarty();
129     $tmp = $this->plInfo();
130     foreach($tmp['plProvidedAcls'] as $name => $translation){
131       $smarty->assign($name."ACL",$this->getacl($name));
132     }
134     $smarty->assign("table", $table);
135     $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
136     $this->parent->by_object['application']->generateTemplate();
137     return ($display);
138   }
140   function remove_from_parent()
141   {
142     $ldap= $this->config->get_ldap_link();
144     /* Zero attributes */
145     $this->attrs= array();
146     $this->attrs['gosaApplicationParameter']= array();
148     $ldap->cd($this->dn);
149     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
150         $this->attributes, "Save");
151     $this->cleanup();
152     $ldap->modify ($this->attrs); 
154     show_ldap_error($ldap->get_error(), sprintf(_("Removing of application parameters with dn '%s' failed."),$this->dn));
156     /* Optionally execute a command after we're done */
157     $this->handle_post_events('remove');
158   }
161   /* Save data to object */
162   function save_object()
163   {
164     if (isset($_POST['option0'])){
165       for ($i= 0; $i<count($this->option_name); $i++){
166         $this->option_name[$i]= $_POST["option$i"];
167         $this->option_value[$i]= "";
168         if ($_POST["value$i"] != ""){
169           $this->option_value[$i]= $_POST["value$i"];
170         }
171       }
172     }
173   }
176   /* Check values */
177   function check()
178   {
179     /* Call common method to give check the hook */
180     $message= plugin::check();
182     /* Check for valid option names */
183     for ($i= 0; $i<count($this->option_name); $i++){
184       if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
185         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
186             $this->option_name[$i]);
187       }
188     }
190     return $message;
191   }
194   /* Save to LDAP */
195   function save()
196   {
197     /* Generate values */
198     $this->attrs= array();
199     if (count($this->option_name) == 0){
200       $this->attrs['gosaApplicationParameter']= array();
201     } else {
202       for ($i= 0; $i<count($this->option_name); $i++){
203         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
204           ":".$this->option_value[$i];
205       }
206     }
208     /* Write back to ldap */
209     $ldap= $this->config->get_ldap_link();
210     $ldap->cd($this->dn);
211     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
212         $this->attributes, "Save");
213     $this->cleanup();
214     $ldap->modify ($this->attrs); 
216     show_ldap_error($ldap->get_error(), sprintf(_("Saving of application parameters with dn '%s' failed."),$this->dn));
218     /* Optionally execute a command after we're done */
219     $this->handle_post_events('modify');
220   }
222   /* Return plugin informations for acl handling
223 #FIXME FAIscript seams to ununsed within this class... */
224   static function plInfo()
225   {
226     return (array(
227           "plShortName"   => _("Parameter"),
228           "plDescription" => _("Parameter configuration"),
229           "plSelfModify"  => FALSE,
230           "plDepends"     => array(),
231           "plPriority"    => 0,
232           "plSection"     => array("administration"),
233           "plCategory"    => array("application"),
235           "plProvidedAcls"=> array(
236             "gosaApplicationParameter"      => _("Application parameter settings"))  
237           ));
238   }
242 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
243 ?>