Code

Removed show_ldap_error() calls
[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"),
50             _("This application has options. You can disable them by clicking below."));
51       } else {
52         $display= $this->show_enable_header(_("Create options"),
53             _("This application has options disabled. You can enable them by clicking below."));
54         $this->parent->by_object['application']->generateTemplate();
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     }
92     $acl = $this->getacl("gosaApplicationParameter")    ;
93     $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
94     if (count ($this->option_name)){
96       for ($i= 0; $i < count($this->option_name); $i++){
97         $name = $this->option_name[$i];
98         $value= $this->option_value[$i];
100         $tag = "";
101         if(!preg_match("/w/",$acl)){
102           $tag = " disabled ";
103         }
105         if(!preg_match("/r/",$acl)){
106           $name = "";
107           $value= "";
108         }
110         $table.="<tr>".
111           " <td>".
112           "  <input name=\"option$i\" size=25 maxlength=50 value=\"".$name."\" ".$tag.">".
113           " </td>".
114           " <td>".
115           "  <input name=\"value$i\" size=60 maxlength=250 value=\"".$value."\" ".$tag.">".
116           "  <br>".
117           " </td>".
118           " <td>".
119           "  <input type=\"submit\" name=\"remove$i\" value=\""._("Remove")."\" ".$tag.">".
120           " </td>".
121           "</tr>";
122       }
123     }
124     $table.= "</table>";
125     $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
127     /* Show main page */
128     $smarty= get_smarty();
129     $tmp = $this->plInfo();
130     foreach($tmp['plProvidedAcls'] as $name => $translation){
131       $smarty->assign($name."ACL",$this->getacl($name));
132     }
134     $smarty->assign("table", $table);
135     $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
136     $this->parent->by_object['application']->generateTemplate();
137     return ($display);
138   }
140   function remove_from_parent()
141   {
142     $ldap= $this->config->get_ldap_link();
144     /* Zero attributes */
145     $this->attrs= array();
146     $this->attrs['gosaApplicationParameter']= array();
148     $ldap->cd($this->dn);
149     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
150         $this->attributes, "Save");
151     $this->cleanup();
152     $ldap->modify ($this->attrs); 
154     if (!$ldap->success()){
155       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
156     }
158     /* Optionally execute a command after we're done */
159     $this->handle_post_events('remove');
160   }
163   /* Save data to object */
164   function save_object()
165   {
166     if (isset($_POST['option0'])){
167       for ($i= 0; $i<count($this->option_name); $i++){
168         $this->option_name[$i]= $_POST["option$i"];
169         $this->option_value[$i]= "";
170         if ($_POST["value$i"] != ""){
171           $this->option_value[$i]= $_POST["value$i"];
172         }
173       }
174     }
175   }
178   /* Check values */
179   function check()
180   {
181     /* Call common method to give check the hook */
182     $message= plugin::check();
184     /* Check for valid option names */
185     for ($i= 0; $i<count($this->option_name); $i++){
186       if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
187         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
188             $this->option_name[$i]);
189       }
190     }
192     return $message;
193   }
196   /* Save to LDAP */
197   function save()
198   {
199     /* Generate values */
200     $this->attrs= array();
201     if (count($this->option_name) == 0){
202       $this->attrs['gosaApplicationParameter']= array();
203     } else {
204       for ($i= 0; $i<count($this->option_name); $i++){
205         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
206           ":".$this->option_value[$i];
207       }
208     }
210     /* Write back to ldap */
211     $ldap= $this->config->get_ldap_link();
212     $ldap->cd($this->dn);
213     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
214         $this->attributes, "Save");
215     $this->cleanup();
216     $ldap->modify ($this->attrs); 
218     if (!$ldap->success()){
219       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
220     }
222     /* Optionally execute a command after we're done */
223     $this->handle_post_events('modify');
224   }
226   /* Return plugin informations for acl handling
227 #FIXME FAIscript seams to ununsed within this class... */
228   static function plInfo()
229   {
230     return (array(
231           "plShortName"   => _("Parameter"),
232           "plDescription" => _("Parameter configuration"),
233           "plSelfModify"  => FALSE,
234           "plDepends"     => array(),
235           "plPriority"    => 0,
236           "plSection"     => array("administration"),
237           "plCategory"    => array("application"),
239           "plProvidedAcls"=> array(
240             "gosaApplicationParameter"      => _("Application parameter settings"))  
241           ));
242   }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>