Code

Fix script update
[gosa.git] / plugins / admin / applications / class_applicationParameters.inc
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();
15   var $objectclasses= array();
17   function applicationParameters ($config, $dn= NULL)
18   {
19         plugin::plugin ($config, $dn);
21         if (isset($this->attrs['gosaApplicationParameter'])){
22                 $this->is_account= TRUE;
23                 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
24                         $option= preg_replace('/^[^:]+:/', '',
25                                         $this->attrs['gosaApplicationParameter'][$i]);
26                         $name= preg_replace('/:.*$/', '',
27                                         $this->attrs['gosaApplicationParameter'][$i]);
28                         $this->option_name[$i]= $name;
29                         $this->option_value[$i]= $option;
30                 }
31         } else {
32                 $this->is_account= FALSE;
33         }
34   }
36   function execute()
37   {
38         /* Call parent execute */
39         plugin::execute();
41         /* Do we need to flip is_account state? */
42         if (isset($_POST['modify_state'])){
43                 $this->is_account= !$this->is_account;
44         }
46         /* Show tab dialog headers */
47         $display= "";
48         if ($this->parent != NULL){
49                 if ($this->is_account){
50                         $display= $this->show_header(_("Remove options"),
51                                 _("This application has options. You can disable them by clicking below."));
52                 } else {
53                         $display= $this->show_header(_("Create options"),
54                                 _("This application has options disabled. You can enable them by clicking below."));
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         }
90         $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
91         if (count ($this->option_name)){
92                 for ($i= 0; $i < count($this->option_name); $i++){
93                         $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
94                                 "value=\"".$this->option_name[$i]."\"></td><td><input name=\"value$i\" ".
95                                 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\"><br></td><td>".
96                                 "<input type=\"submit\" name=\"remove$i\" value=\"".
97                                 _("Remove")."\"></td></tr>";
98                 }
99         }
100         $table.= "</table>";
101         $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
103         /* Show main page */
104         $smarty= get_smarty();
105         $smarty->assign("table", $table);
106         $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
107         return ($display);
108   }
110   function remove_from_parent()
111   {
112         $ldap= $this->config->get_ldap_link();
114         /* Zero attributes */
115         $this->attrs= array();
116         $this->attrs['gosaApplicationParameter']= array();
118         $ldap->cd($this->dn);
119         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
120                 $this->attributes, "Save");
121         $ldap->modify($this->attrs);
122         show_ldap_error($ldap->get_error());
124         /* Optionally execute a command after we're done */
125         $this->handle_post_events('remove');
126   }
129   /* Save data to object */
130   function save_object()
131   {
132         if (isset($_POST['option0'])){
133                 for ($i= 0; $i<count($this->option_name); $i++){
134                         $this->option_name[$i]= $_POST["option$i"];
135                         $this->option_value[$i]= "";
136                         if ($_POST["value$i"] != ""){
137                                 $this->option_value[$i]= $_POST["value$i"];
138                         }
139                 }
140         }
141   }
144   /* Check values */
145   function check()
146   {
147         $message= array();
149         /* Check for valid option names */
150         for ($i= 0; $i<count($this->option_name); $i++){
151                 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
152                         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
153                                         $this->option_name[$i]);
154                 }
155         }
156         
157         return $message;
158   }
161   /* Save to LDAP */
162   function save()
163   {
164         /* Generate values */
165         $this->attrs= array();
166         if (count($this->option_name) == 0){
167                 $this->attrs['gosaApplicationParameter']= array();
168         } else {
169                 for ($i= 0; $i<count($this->option_name); $i++){
170                         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
171                                 ":".$this->option_value[$i];
172                 }
173         }
175         /* Write back to ldap */
176         $ldap= $this->config->get_ldap_link();
177         $ldap->cd($this->dn);
178         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
179                 $this->attributes, "Save");
180         $ldap->modify($this->attrs);
181         show_ldap_error($ldap->get_error());
183         /* Optionally execute a command after we're done */
184         $this->handle_post_events('modify');
185   }
189 ?>