Code

Fixed acl's for app options
[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("gosaApplicationParameter");
15   var $objectclasses= array();
17   function applicationParameters ($config, $dn= NULL)
18   {
19         plugin::plugin ($config, $dn);
21         $this->gosaApplicationParameter = array();
23         if (isset($this->attrs['gosaApplicationParameter'])){
24                 $this->is_account= TRUE;
25                 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
26                         $option= preg_replace('/^[^:]+:/', '',
27                                         $this->attrs['gosaApplicationParameter'][$i]);
28                         $name= preg_replace('/:.*$/', '',
29                                         $this->attrs['gosaApplicationParameter'][$i]);
30                         $this->option_name[$i]= $name;
31                         $this->option_value[$i]= $option;
32                 }
33         } else {
34                 $this->is_account= FALSE;
35         }
36   }
38   function execute()
39   {
40         /* Call parent execute */
41         plugin::execute();
43         /* Do we need to flip is_account state? */
44         if (isset($_POST['modify_state'])){
45                 $this->is_account= !$this->is_account;
46         }
48         /* Show tab dialog headers */
49         $display= "";
50         if ($this->parent != NULL){
51                 if ($this->is_account){
52                         $display= $this->show_header(_("Remove options"),
53                                 _("This application has options. You can disable them by clicking below."));
54                 } else {
55                         $display= $this->show_header(_("Create options"),
56                                 _("This application has options disabled. You can enable them by clicking below."));
57                         $this->parent->by_object['application']->generateTemplate();
58                         return ($display);
59                 }
60         }
62         /* Add option to list */
63         if (isset($_POST['add_option'])){
64                 $i= count($this->option_name);
65                 $this->option_name[$i]= "";
66                 $this->option_value[$i]= "";
67         }
69         /* Remove value from list */
70         for ($i= 0; $i<count($this->option_name); $i++){
71                 if (isset($_POST["remove$i"])){
72                         $k= 0;
73                         $on= array();
74                         $ov= array();
75                         for ($j= 0; $j<count($this->option_name); $j++){
76                                 if ($j != $i){
77                                         $on[$k]= $this->option_name[$j];
78                                         $ov[$k]= $this->option_value[$j];
79                                         $k++;
80                                 }
81                         }
82                         $this->option_name= $on;
83                         $this->option_value= $ov;
84                         break;
85                 }
86         }
88         /* Generate list of attributes */
89         if (count($this->option_name) == 0){
90                 $this->option_name[]= "";
91                 $this->option_value[]= "";
92         }
94         $mode= "";
95         if (chkacl($this->acl, "create") != ""){
96                 $mode= "disabled";
97         }
99         $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
100         if (count ($this->option_name)){
101                 for ($i= 0; $i < count($this->option_name); $i++){
102                         $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
103                                 "value=\"".$this->option_name[$i]."\" $mode></td><td><input name=\"value$i\" ".
104                                 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\" $mode><br></td><td>".
105                                 "<input type=\"submit\" name=\"remove$i\" value=\"".
106                                 _("Remove")."\" $mode></td></tr>";
107                 }
108         }
109         $table.= "</table>";
111         if ($mode == ""){
112                 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
113         }
115         /* Show main page */
116         $smarty= get_smarty();
117         $smarty->assign("table", $table);
118         $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
119         $this->parent->by_object['application']->generateTemplate();
120         return ($display);
121   }
123   function remove_from_parent()
124   {
125         $ldap= $this->config->get_ldap_link();
127         /* Zero attributes */
128         $this->attrs= array();
129         $this->attrs['gosaApplicationParameter']= array();
131         $ldap->cd($this->dn);
132         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
133                 $this->attributes, "Save");
134         $this->cleanup();
135         $ldap->modify ($this->attrs); 
137         show_ldap_error($ldap->get_error(), _("Removing application parameters failed"));
139         /* Optionally execute a command after we're done */
140         $this->handle_post_events('remove');
141   }
144   /* Save data to object */
145   function save_object()
146   {
147         if (isset($_POST['option0'])){
148                 for ($i= 0; $i<count($this->option_name); $i++){
149                         $this->option_name[$i]= $_POST["option$i"];
150                         $this->option_value[$i]= "";
151                         if ($_POST["value$i"] != ""){
152                                 $this->option_value[$i]= $_POST["value$i"];
153                         }
154                 }
155         }
156   }
159   /* Check values */
160   function check()
161   {
162         /* Call common method to give check the hook */
163         $message= plugin::check();
165         /* Check for valid option names */
166         for ($i= 0; $i<count($this->option_name); $i++){
167                 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
168                         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
169                                         $this->option_name[$i]);
170                 }
171         }
172         
173         return $message;
174   }
177   /* Save to LDAP */
178   function save()
179   {
180         /* Generate values */
181         $this->attrs= array();
182         if (count($this->option_name) == 0){
183                 $this->attrs['gosaApplicationParameter']= array();
184         } else {
185                 for ($i= 0; $i<count($this->option_name); $i++){
186                         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
187                                 ":".$this->option_value[$i];
188                 }
189         }
191         /* Write back to ldap */
192         $ldap= $this->config->get_ldap_link();
193         $ldap->cd($this->dn);
194         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
195                 $this->attributes, "Save");
196         $this->cleanup();
197         $ldap->modify ($this->attrs); 
199         show_ldap_error($ldap->get_error(), _("Saving applications parameters failed"));
201         /* Optionally execute a command after we're done */
202         $this->handle_post_events('modify');
203   }
207 ?>