663068805656905a94c79e6305adeabcb9611ac2
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();
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_header(_("Remove options"),
50 _("This application has options. You can disable them by clicking below."));
51 } else {
52 $display= $this->show_header(_("Create options"),
53 _("This application has options disabled. You can enable them by clicking below."));
54 return ($display);
55 }
56 }
58 /* Add option to list */
59 if (isset($_POST['add_option'])){
60 $i= count($this->option_name);
61 $this->option_name[$i]= "";
62 $this->option_value[$i]= "";
63 }
65 /* Remove value from list */
66 for ($i= 0; $i<count($this->option_name); $i++){
67 if (isset($_POST["remove$i"])){
68 $k= 0;
69 $on= array();
70 $ov= array();
71 for ($j= 0; $j<count($this->option_name); $j++){
72 if ($j != $i){
73 $on[$k]= $this->option_name[$j];
74 $ov[$k]= $this->option_value[$j];
75 $k++;
76 }
77 }
78 $this->option_name= $on;
79 $this->option_value= $ov;
80 break;
81 }
82 }
84 /* Generate list of attributes */
85 if (count($this->option_name) == 0){
86 $this->option_name[]= "";
87 $this->option_value[]= "";
88 }
89 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
90 if (count ($this->option_name)){
91 for ($i= 0; $i < count($this->option_name); $i++){
92 $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
93 "value=\"".$this->option_name[$i]."\"></td><td><input name=\"value$i\" ".
94 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\"><br></td><td>".
95 "<input type=\"submit\" name=\"remove$i\" value=\"".
96 _("Remove")."\"></td></tr>";
97 }
98 }
99 $table.= "</table>";
100 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
102 /* Show main page */
103 $smarty= get_smarty();
104 $smarty->assign("table", $table);
105 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
106 return ($display);
107 }
109 function remove_from_parent()
110 {
111 $ldap= $this->config->get_ldap_link();
113 /* Zero attributes */
114 $this->attrs= array();
115 $this->attrs['gosaApplicationParameter']= array();
117 $ldap->cd($this->dn);
118 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
119 $this->attributes, "Save");
120 $ldap->modify($this->attrs);
121 show_ldap_error($ldap->get_error());
123 /* Optionally execute a command after we're done */
124 $this->handle_post_events('remove');
125 }
128 /* Save data to object */
129 function save_object()
130 {
131 if (isset($_POST['option0'])){
132 for ($i= 0; $i<count($this->option_name); $i++){
133 $this->option_name[$i]= $_POST["option$i"];
134 $this->option_value[$i]= "";
135 if ($_POST["value$i"] != ""){
136 $this->option_value[$i]= $_POST["value$i"];
137 }
138 }
139 }
140 }
143 /* Check values */
144 function check()
145 {
146 $message= array();
148 /* Check for valid option names */
149 for ($i= 0; $i<count($this->option_name); $i++){
150 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
151 $message[]= sprintf(_("Value '%s' specified as option name is not valid."),
152 $this->option_name[$i]);
153 }
154 }
156 return $message;
157 }
160 /* Save to LDAP */
161 function save()
162 {
163 /* Generate values */
164 $this->attrs= array();
165 if (count($this->option_name) == 0){
166 $this->attrs['gosaApplicationParameter']= array();
167 } else {
168 for ($i= 0; $i<count($this->option_name); $i++){
169 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
170 ":".$this->option_value[$i];
171 }
172 }
174 /* Write back to ldap */
175 $ldap= $this->config->get_ldap_link();
176 $ldap->cd($this->dn);
177 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
178 $this->attributes, "Save");
179 $ldap->modify($this->attrs);
180 show_ldap_error($ldap->get_error());
182 /* Optionally execute a command after we're done */
183 $this->handle_post_events('modify');
184 }
186 }
188 ?>