Code

Added missing files
[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");
11   function applicationParameters (&$config, $dn= NULL, $parent= NULL)
12   {
13     plugin::plugin ($config, $dn, $parent);
15     $this->gosaApplicationParameter = array();
17     if (isset($this->attrs['gosaApplicationParameter'])){
18       $this->is_account= TRUE;
19       for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
20         $option= preg_replace('/^[^:]+:/', '',
21             $this->attrs['gosaApplicationParameter'][$i]);
22         $name= preg_replace('/:.*$/', '',
23             $this->attrs['gosaApplicationParameter'][$i]);
24         $this->option_name[$i]= $name;
25         $this->option_value[$i]= $option;
26       }
27     } else {
28       $this->is_account= FALSE;
29     }
30   }
32   function execute()
33   {
34     /* Call parent execute */
35     plugin::execute();
37     /* Do we need to flip is_account state? */
38     if(isset($_POST['modify_state'])){
39       if($this->is_account && $this->acl_is_removeable()){
40         $this->is_account= FALSE;
41       }elseif(!$this->is_account && $this->acl_is_createable()){
42         $this->is_account= TRUE;
43       }
44     }
46     /* Show tab dialog headers */
47     $display= "";
48     if ($this->parent !== NULL){
49       if ($this->is_account){
50         $display= $this->show_disable_header(_("Remove options"),msgPool::featuresEnabled(_("parameter")));
51       } else {
52         $display= $this->show_enable_header(_("Create options"), msgPool::featuresDisabled(_("parameter")));
53         $this->parent->by_object['application']->generateTemplate();
54         return ($display);
55       }
56     }
58     if($this->acl_is_writeable("gosaApplicationParameter")){
60       /* Add option to list */
61       if (isset($_POST['add_option'])){
62         $i= count($this->option_name);
63         $this->option_name[$i]= "";
64         $this->option_value[$i]= "";
65       }
67       /* Remove value from list */
68       for ($i= 0; $i<count($this->option_name); $i++){
69         if (isset($_POST["remove$i"])){
70           $k= 0;
71           $on= array();
72           $ov= array();
73           for ($j= 0; $j<count($this->option_name); $j++){
74             if ($j != $i){
75               $on[$k]= $this->option_name[$j];
76               $ov[$k]= $this->option_value[$j];
77               $k++;
78             }
79           }
80           $this->option_name= $on;
81           $this->option_value= $ov;
82           break;
83         }
84       }
85     }
87     /* Generate list of attributes */
88     if (count($this->option_name) == 0){
89       $this->option_name[]= "";
90       $this->option_value[]= "";
91     }
92     
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)){
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\" $tag 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     if (!$ldap->success()){
158       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
159     }
161     /* Optionally execute a command after we're done */
162     $this->handle_post_events('remove');
163   }
166   /* Save data to object */
167   function save_object()
168   {
169     if (isset($_POST['option0']) && $this->acl_is_writeable("gosaApplicationParameter")){
170       for ($i= 0; $i<count($this->option_name); $i++){
171         $this->option_name[$i]= $_POST["option$i"];
172         $this->option_value[$i]= "";
173         if ($_POST["value$i"] != ""){
174           $this->option_value[$i]= $_POST["value$i"];
175         }
176       }
177     }
178   }
181   /* Check values */
182   function check()
183   {
184     /* Call common method to give check the hook */
185     $message= plugin::check();
187     /* Check for valid option names */
188     for ($i= 0; $i<count($this->option_name); $i++){
189       if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
190         $message[]= msgPool::invalid(_("Name"), $this->option_name[$i],"/^[a-z0-9_]+$/i");
191       }
192     }
194     return $message;
195   }
198   /* Save to LDAP */
199   function save()
200   {
201     /* Generate values */
202     $this->attrs= array();
203     if (count($this->option_name) == 0){
204       $this->attrs['gosaApplicationParameter']= array();
205     } else {
206       for ($i= 0; $i<count($this->option_name); $i++){
207         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
208           ":".$this->option_value[$i];
209       }
210     }
212     /* Write back to ldap */
213     $ldap= $this->config->get_ldap_link();
214     $ldap->cd($this->dn);
215     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
216         $this->attributes, "Save");
217     $this->cleanup();
218     $ldap->modify ($this->attrs); 
220     if (!$ldap->success()){
221       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
222     }
224     /* Optionally execute a command after we're done */
225     $this->handle_post_events('modify');
226   }
228  
229   function PrepareForCopyPaste($source)
230   {
231     plugin::PrepareForCopyPaste($source);
233     $source_o = new applicationParameters($this->config,$source['dn']);
234     $this->option_name = $source_o->option_name;
235     $this->option_value = $source_o->option_value;
237     /* Set is_account state so that the save function is called properly */
238     $this->is_account = TRUE;
239   }
242   /* Return plugin informations for acl handling
243 #FIXME FAIscript seams to ununsed within this class... */
244   static function plInfo()
245   {
246     return (array(
247           "plShortName"   => _("Parameter"),
248           "plDescription" => _("Parameter configuration"),
249           "plSelfModify"  => FALSE,
250           "plDepends"     => array(),
251           "plPriority"    => 0,
252           "plSection"     => array("administration"),
253           "plCategory"    => array("application"),
255           "plProvidedAcls"=> array(
256             "gosaApplicationParameter"      => _("Application parameter settings"))  
257           ));
258   }
262 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
263 ?>