Code

Moved folder image
[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"),msgPool::featuresEnabled(_("parameter")));
50       } else {
51         $display= $this->show_enable_header(_("Create options"), msgPool::featuresDisabled(_("parameter")));
52         $this->parent->by_object['application']->generateTemplate();
53         return ($display);
54       }
55     }
57     /* Add option to list */
58     if (isset($_POST['add_option'])){
59       $i= count($this->option_name);
60       $this->option_name[$i]= "";
61       $this->option_value[$i]= "";
62     }
64     /* Remove value from list */
65     for ($i= 0; $i<count($this->option_name); $i++){
66       if (isset($_POST["remove$i"])){
67         $k= 0;
68         $on= array();
69         $ov= array();
70         for ($j= 0; $j<count($this->option_name); $j++){
71           if ($j != $i){
72             $on[$k]= $this->option_name[$j];
73             $ov[$k]= $this->option_value[$j];
74             $k++;
75           }
76         }
77         $this->option_name= $on;
78         $this->option_value= $ov;
79         break;
80       }
81     }
83     /* Generate list of attributes */
84     if (count($this->option_name) == 0){
85       $this->option_name[]= "";
86       $this->option_value[]= "";
87     }
90     $acl = $this->getacl("gosaApplicationParameter")    ;
91     $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
92     if (count ($this->option_name)){
94       for ($i= 0; $i < count($this->option_name); $i++){
95         $name = $this->option_name[$i];
96         $value= $this->option_value[$i];
98         $tag = "";
99         if(!preg_match("/w/",$acl)){
100           $tag = " disabled ";
101         }
103         if(!preg_match("/r/",$acl)){
104           $name = "";
105           $value= "";
106         }
108         $table.="<tr>".
109           " <td>".
110           "  <input name=\"option$i\" size=25 maxlength=50 value=\"".$name."\" ".$tag.">".
111           " </td>".
112           " <td>".
113           "  <input name=\"value$i\" size=60 maxlength=250 value=\"".$value."\" ".$tag.">".
114           "  <br>".
115           " </td>".
116           " <td>".
117           "  <input type=\"submit\" name=\"remove$i\" value=\""._("Remove")."\" ".$tag.">".
118           " </td>".
119           "</tr>";
120       }
121     }
122     $table.= "</table>";
123     $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
125     /* Show main page */
126     $smarty= get_smarty();
127     $tmp = $this->plInfo();
128     foreach($tmp['plProvidedAcls'] as $name => $translation){
129       $smarty->assign($name."ACL",$this->getacl($name));
130     }
132     $smarty->assign("table", $table);
133     $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
134     $this->parent->by_object['application']->generateTemplate();
135     return ($display);
136   }
138   function remove_from_parent()
139   {
140     $ldap= $this->config->get_ldap_link();
142     /* Zero attributes */
143     $this->attrs= array();
144     $this->attrs['gosaApplicationParameter']= array();
146     $ldap->cd($this->dn);
147     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
148         $this->attributes, "Save");
149     $this->cleanup();
150     $ldap->modify ($this->attrs); 
152     if (!$ldap->success()){
153       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
154     }
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[]= msgPool::invalid(_("Name"), $this->option_name[$i],"/^[a-z0-9_]+$/i");
186       }
187     }
189     return $message;
190   }
193   /* Save to LDAP */
194   function save()
195   {
196     /* Generate values */
197     $this->attrs= array();
198     if (count($this->option_name) == 0){
199       $this->attrs['gosaApplicationParameter']= array();
200     } else {
201       for ($i= 0; $i<count($this->option_name); $i++){
202         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
203           ":".$this->option_value[$i];
204       }
205     }
207     /* Write back to ldap */
208     $ldap= $this->config->get_ldap_link();
209     $ldap->cd($this->dn);
210     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
211         $this->attributes, "Save");
212     $this->cleanup();
213     $ldap->modify ($this->attrs); 
215     if (!$ldap->success()){
216       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
217     }
219     /* Optionally execute a command after we're done */
220     $this->handle_post_events('modify');
221   }
223   /* Return plugin informations for acl handling
224 #FIXME FAIscript seams to ununsed within this class... */
225   static function plInfo()
226   {
227     return (array(
228           "plShortName"   => _("Parameter"),
229           "plDescription" => _("Parameter configuration"),
230           "plSelfModify"  => FALSE,
231           "plDepends"     => array(),
232           "plPriority"    => 0,
233           "plSection"     => array("administration"),
234           "plCategory"    => array("application"),
236           "plProvidedAcls"=> array(
237             "gosaApplicationParameter"      => _("Application parameter settings"))  
238           ));
239   }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>