Code

Removed old CLI stuff - cleanup
[gosa.git] / plugins / 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 */
10   var $CopyPasteVars = array("option_name","option_value");
11   var $attributes= array("gosaApplicationParameter");
12   var $objectclasses= array();
13 var $ui;
15   function applicationParameters ($config, $dn= NULL, $parent= NULL)
16   {
17         plugin::plugin ($config, $dn, $parent);
19         $this->gosaApplicationParameter = array();
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         $this->ui = get_userinfo();
35   }
37   function execute()
38   {
39         /* Call parent execute */
40         plugin::execute();
42         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
43         $this->acl= get_module_permission($acl, "application", $this->dn);
45         /* Do we need to flip is_account state? */
46         if (isset($_POST['modify_state']) && chkacl($this->acl,"gotoLogonScript")==""){
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_header(_("Remove options"),
55                                 _("This application has options. You can disable them by clicking below."));
56                 } else {
57                         $display= $this->show_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         if(chkacl($this->acl,"gotoLogonScript") == ""){
73                 /* Remove value from list */
74                 for ($i= 0; $i<count($this->option_name); $i++){
75                         if (isset($_POST["remove$i"])){
76                                 $k= 0;
77                                 $on= array();
78                                 $ov= array();
79                                 for ($j= 0; $j<count($this->option_name); $j++){
80                                         if ($j != $i){
81                                                 $on[$k]= $this->option_name[$j];
82                                                 $ov[$k]= $this->option_value[$j];
83                                                 $k++;
84                                         }
85                                 }
86                                 $this->option_name= $on;
87                                 $this->option_value= $ov;
88                                 break;
89                         }
90                 }
91         }
93         /* Generate list of attributes */
94         if (count($this->option_name) == 0){
95                 $this->option_name[]= "";
96                 $this->option_value[]= "";
97         }
99         $mode= "";
100         if (chkacl($this->acl, "create") != ""){
101                 $mode= "disabled";
102         }
104         $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
105         if (count ($this->option_name)){
106                 for ($i= 0; $i < count($this->option_name); $i++){
107                         $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
108                                 "value=\"".$this->option_name[$i]."\" $mode></td><td><input name=\"value$i\" ".
109                                 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\" $mode><br></td><td>".
110                                 "<input type=\"submit\" name=\"remove$i\" value=\"".
111                                 _("Remove")."\" $mode></td></tr>";
112                 }
113         }
114         $table.= "</table>";
116         if ($mode == ""){
117                 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
118         }
120         /* Show main page */
121         $smarty= get_smarty();
122         $smarty->assign("table", $table);
123         $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
124         $this->parent->by_object['application']->generateTemplate();
125         return ($display);
126   }
128   function remove_from_parent()
129   {
130         $ldap= $this->config->get_ldap_link();
132         /* Zero attributes */
133         $this->attrs= array();
134         $this->attrs['gosaApplicationParameter']= array();
136         $ldap->cd($this->dn);
137         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
138                 $this->attributes, "Save");
139         $this->cleanup();
140         $ldap->modify ($this->attrs); 
142         show_ldap_error($ldap->get_error(), _("Removing application parameters failed"));
144         /* Optionally execute a command after we're done */
145         $this->handle_post_events('remove');
146   }
149   /* Save data to object */
150   function save_object()
151   {
152           if(chkacl($this->acl,"gotoLogonScript") == ""){
153                   if (isset($_POST['option0'])){
154                           for ($i= 0; $i<count($this->option_name); $i++){
155                                   $this->option_name[$i]= $_POST["option$i"];
156                                   $this->option_value[$i]= "";
157                                   if ($_POST["value$i"] != ""){
158                                           $this->option_value[$i]= $_POST["value$i"];
159                                   }
160                           }
161                   }
162           }
163   }
166   /* Check values */
167   function check()
168   {
169         /* Call common method to give check the hook */
170         $message= plugin::check();
172         /* Check for valid option names */
173         for ($i= 0; $i<count($this->option_name); $i++){
174                 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
175                         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
176                                         $this->option_name[$i]);
177                 }
178         }
179         
180         return $message;
181   }
184   /* Save to LDAP */
185   function save()
186   {
187         /* Generate values */
188         $this->attrs= array();
189         if (count($this->option_name) == 0){
190                 $this->attrs['gosaApplicationParameter']= array();
191         } else {
192                 for ($i= 0; $i<count($this->option_name); $i++){
193                         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
194                                 ":".$this->option_value[$i];
195                 }
196         }
198         /* Write back to ldap */
199         $ldap= $this->config->get_ldap_link();
200         $ldap->cd($this->dn);
201         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
202                 $this->attributes, "Save");
203         $this->cleanup();
204         $ldap->modify ($this->attrs); 
206         show_ldap_error($ldap->get_error(), _("Saving applications parameters failed"));
208         /* Optionally execute a command after we're done */
209         $this->handle_post_events('modify');
210   }
214 ?>