Code

Added acls to mimetype
[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_disable_header(_("Remove options"),
53                                 _("This application has options. You can disable them by clicking below."));
54                 } else {
55                         $display= $this->show_enable_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         
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)){
98                 
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\" 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         show_ldap_error($ldap->get_error(), sprintf(_("Removing of application parameters with dn '%s' failed."),$this->dn));
159         /* Optionally execute a command after we're done */
160         $this->handle_post_events('remove');
161   }
164   /* Save data to object */
165   function save_object()
166   {
167         if (isset($_POST['option0'])){
168                 for ($i= 0; $i<count($this->option_name); $i++){
169                         $this->option_name[$i]= $_POST["option$i"];
170                         $this->option_value[$i]= "";
171                         if ($_POST["value$i"] != ""){
172                                 $this->option_value[$i]= $_POST["value$i"];
173                         }
174                 }
175         }
176   }
179   /* Check values */
180   function check()
181   {
182         /* Call common method to give check the hook */
183         $message= plugin::check();
185         /* Check for valid option names */
186         for ($i= 0; $i<count($this->option_name); $i++){
187                 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
188                         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
189                                         $this->option_name[$i]);
190                 }
191         }
192         
193         return $message;
194   }
197   /* Save to LDAP */
198   function save()
199   {
200         /* Generate values */
201         $this->attrs= array();
202         if (count($this->option_name) == 0){
203                 $this->attrs['gosaApplicationParameter']= array();
204         } else {
205                 for ($i= 0; $i<count($this->option_name); $i++){
206                         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
207                                 ":".$this->option_value[$i];
208                 }
209         }
211         /* Write back to ldap */
212         $ldap= $this->config->get_ldap_link();
213         $ldap->cd($this->dn);
214         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
215                 $this->attributes, "Save");
216         $this->cleanup();
217         $ldap->modify ($this->attrs); 
219         show_ldap_error($ldap->get_error(), sprintf(_("Saving of application parameters with dn '%s' failed."),$this->dn));
221         /* Optionally execute a command after we're done */
222         $this->handle_post_events('modify');
223   }
225   /* Return plugin informations for acl handling
226       #FIXME FAIscript seams to ununsed within this class... */
227   function plInfo()
228   {
229     return (array(
230           "plShortName"   => _("Parameter"),
231           "plDescription" => _("Parameter configuration"),
232           "plSelfModify"  => FALSE,
233           "plDepends"     => array(),
234           "plPriority"    => 0,
235           "plSection"     => array("administration"),
236           "plCategory"    => array("application"),
238           "plProvidedAcls"=> array(
239             "gosaApplicationParameter"      => _("Application parameter settings"))  
240            ));
241   }
246 ?>