Code

Page position will be saved in Lists now
[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();
15   var $objectclasses= array();
17   function applicationParameters ($config, $dn= NULL)
18   {
19         plugin::plugin ($config, $dn);
21         if (isset($this->attrs['gosaApplicationParameter'])){
22                 $this->is_account= TRUE;
23                 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
24                         $option= preg_replace('/^[^:]+:/', '',
25                                         $this->attrs['gosaApplicationParameter'][$i]);
26                         $name= preg_replace('/:.*$/', '',
27                                         $this->attrs['gosaApplicationParameter'][$i]);
28                         $this->option_name[$i]= $name;
29                         $this->option_value[$i]= $option;
30                 }
31         } else {
32                 $this->is_account= FALSE;
33         }
34   }
36   function execute()
37   {
38         /* Do we need to flip is_account state? */
39         if (isset($_POST['modify_state'])){
40                 $this->is_account= !$this->is_account;
41         }
43         /* Show tab dialog headers */
44         $display= "";
45         if ($this->parent != NULL){
46                 if ($this->is_account){
47                         $display= $this->show_header(_("Remove options"),
48                                 _("This application has options. You can disable them by clicking below."));
49                 } else {
50                         $display= $this->show_header(_("Create options"),
51                                 _("This application has options disabled. You can enable them by clicking below."));
52                         return ($display);
53                 }
54         }
56         /* Add option to list */
57         if (isset($_POST['add_option'])){
58                 $i= count($this->option_name);
59                 $this->option_name[$i]= "";
60                 $this->option_value[$i]= "";
61         }
63         /* Remove value from list */
64         for ($i= 0; $i<count($this->option_name); $i++){
65                 if (isset($_POST["remove$i"])){
66                         $k= 0;
67                         $on= array();
68                         $ov= array();
69                         for ($j= 0; $j<count($this->option_name); $j++){
70                                 if ($j != $i){
71                                         $on[$k]= $this->option_name[$j];
72                                         $ov[$k]= $this->option_value[$j];
73                                         $k++;
74                                 }
75                         }
76                         $this->option_name= $on;
77                         $this->option_value= $ov;
78                         break;
79                 }
80         }
82         /* Generate list of attributes */
83         if (count($this->option_name) == 0){
84                 $this->option_name[]= "";
85                 $this->option_value[]= "";
86         }
87         $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
88         if (count ($this->option_name)){
89                 for ($i= 0; $i < count($this->option_name); $i++){
90                         $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
91                                 "value=\"".$this->option_name[$i]."\"></td><td><input name=\"value$i\" ".
92                                 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\"><br></td><td>".
93                                 "<input type=\"submit\" name=\"remove$i\" value=\"".
94                                 _("Remove")."\"></td></tr>";
95                 }
96         }
97         $table.= "</table>";
98         $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
100         /* Show main page */
101         $smarty= get_smarty();
102         $smarty->assign("table", $table);
103         $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
104         return ($display);
105   }
107   function remove_from_parent()
108   {
109         $ldap= $this->config->get_ldap_link();
111         /* Zero attributes */
112         $this->attrs= array();
113         $this->attrs['gosaApplicationParameter']= array();
115         $ldap->cd($this->dn);
116         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
117                 $this->attributes, "Save");
118         $ldap->modify($this->attrs);
119         show_ldap_error($ldap->get_error());
121         /* Optionally execute a command after we're done */
122         $this->handle_post_events('remove');
123   }
126   /* Save data to object */
127   function save_object()
128   {
129         if (isset($_POST['option0'])){
130                 for ($i= 0; $i<count($this->option_name); $i++){
131                         $this->option_name[$i]= $_POST["option$i"];
132                         $this->option_value[$i]= "";
133                         if ($_POST["value$i"] != ""){
134                                 $this->option_value[$i]= $_POST["value$i"];
135                         }
136                 }
137         }
138   }
141   /* Check values */
142   function check()
143   {
144         $message= array();
146         /* Check for valid option names */
147         for ($i= 0; $i<count($this->option_name); $i++){
148                 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
149                         $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
150                                         $this->option_name[$i]);
151                 }
152         }
153         
154         return $message;
155   }
158   /* Save to LDAP */
159   function save()
160   {
161         /* Generate values */
162         $this->attrs= array();
163         if (count($this->option_name) == 0){
164                 $this->attrs['gosaApplicationParameter']= array();
165         } else {
166                 for ($i= 0; $i<count($this->option_name); $i++){
167                         $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
168                                 ":".$this->option_value[$i];
169                 }
170         }
172         /* Write back to ldap */
173         $ldap= $this->config->get_ldap_link();
174         $ldap->cd($this->dn);
175         @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
176                 $this->attributes, "Save");
177         $ldap->modify($this->attrs);
178         show_ldap_error($ldap->get_error());
180         /* Optionally execute a command after we're done */
181         $this->handle_post_events('modify');
182   }
186 ?>