69ccc8f03dbd1b48749addefecbd0e981e8f6d28
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 /* Call parent execute */
39 plugin::execute();
41 /* Do we need to flip is_account state? */
42 if (isset($_POST['modify_state'])){
43 $this->is_account= !$this->is_account;
44 }
46 /* Show tab dialog headers */
47 $display= "";
48 if ($this->parent != NULL){
49 if ($this->is_account){
50 $display= $this->show_header(_("Remove options"),
51 _("This application has options. You can disable them by clicking below."));
52 } else {
53 $display= $this->show_header(_("Create options"),
54 _("This application has options disabled. You can enable them by clicking below."));
55 $this->parent->by_object['application']->generateTemplate();
56 return ($display);
57 }
58 }
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 }
86 /* Generate list of attributes */
87 if (count($this->option_name) == 0){
88 $this->option_name[]= "";
89 $this->option_value[]= "";
90 }
91 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
92 if (count ($this->option_name)){
93 for ($i= 0; $i < count($this->option_name); $i++){
94 $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
95 "value=\"".$this->option_name[$i]."\"></td><td><input name=\"value$i\" ".
96 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\"><br></td><td>".
97 "<input type=\"submit\" name=\"remove$i\" value=\"".
98 _("Remove")."\"></td></tr>";
99 }
100 }
101 $table.= "</table>";
102 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
104 /* Show main page */
105 $smarty= get_smarty();
106 $smarty->assign("table", $table);
107 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
108 $this->parent->by_object['application']->generateTemplate();
109 return ($display);
110 }
112 function remove_from_parent()
113 {
114 $ldap= $this->config->get_ldap_link();
116 /* Zero attributes */
117 $this->attrs= array();
118 $this->attrs['gosaApplicationParameter']= array();
120 $ldap->cd($this->dn);
121 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
122 $this->attributes, "Save");
123 $this->cleanup();
124 $ldap->modify ($this->attrs);
126 show_ldap_error($ldap->get_error());
128 /* Optionally execute a command after we're done */
129 $this->handle_post_events('remove');
130 }
133 /* Save data to object */
134 function save_object()
135 {
136 if (isset($_POST['option0'])){
137 for ($i= 0; $i<count($this->option_name); $i++){
138 $this->option_name[$i]= $_POST["option$i"];
139 $this->option_value[$i]= "";
140 if ($_POST["value$i"] != ""){
141 $this->option_value[$i]= $_POST["value$i"];
142 }
143 }
144 }
145 }
148 /* Check values */
149 function check()
150 {
151 $message= array();
153 /* Check for valid option names */
154 for ($i= 0; $i<count($this->option_name); $i++){
155 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
156 $message[]= sprintf(_("Value '%s' specified as option name is not valid."),
157 $this->option_name[$i]);
158 }
159 }
161 return $message;
162 }
165 /* Save to LDAP */
166 function save()
167 {
168 /* Generate values */
169 $this->attrs= array();
170 if (count($this->option_name) == 0){
171 $this->attrs['gosaApplicationParameter']= array();
172 } else {
173 for ($i= 0; $i<count($this->option_name); $i++){
174 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
175 ":".$this->option_value[$i];
176 }
177 }
179 /* Write back to ldap */
180 $ldap= $this->config->get_ldap_link();
181 $ldap->cd($this->dn);
182 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
183 $this->attributes, "Save");
184 $this->cleanup();
185 $ldap->modify ($this->attrs);
187 show_ldap_error($ldap->get_error());
189 /* Optionally execute a command after we're done */
190 $this->handle_post_events('modify');
191 }
193 }
195 ?>