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