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");
10 var $objectclasses= array();
12 var $CopyPasteVars = array("option_name","option_value");
14 function applicationParameters (&$config, $dn= NULL, $parent= NULL)
15 {
16 plugin::plugin ($config, $dn, $parent);
18 $this->gosaApplicationParameter = array();
20 if (isset($this->attrs['gosaApplicationParameter'])){
21 $this->is_account= TRUE;
22 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
23 $option= preg_replace('/^[^:]+:/', '',
24 $this->attrs['gosaApplicationParameter'][$i]);
25 $name= preg_replace('/:.*$/', '',
26 $this->attrs['gosaApplicationParameter'][$i]);
27 $this->option_name[$i]= $name;
28 $this->option_value[$i]= $option;
29 }
30 } else {
31 $this->is_account= FALSE;
32 }
33 }
35 function execute()
36 {
37 /* Call parent execute */
38 plugin::execute();
40 /* Do we need to flip is_account state? */
41 if(isset($_POST['modify_state'])){
42 if($this->is_account && $this->acl_is_removeable()){
43 $this->is_account= FALSE;
44 }elseif(!$this->is_account && $this->acl_is_createable()){
45 $this->is_account= TRUE;
46 }
47 }
49 /* Show tab dialog headers */
50 $display= "";
51 if ($this->parent !== NULL){
52 if ($this->is_account){
53 $display= $this->show_disable_header(_("Remove options"),msgPool::featuresEnabled(_("parameter")));
54 } else {
55 $display= $this->show_enable_header(_("Create options"), msgPool::featuresDisabled(_("parameter")));
56 $this->parent->by_object['application']->generateTemplate();
57 return ($display);
58 }
59 }
61 if($this->acl_is_writeable("gosaApplicationParameter")){
63 /* Add option to list */
64 if (isset($_POST['add_option'])){
65 $i= count($this->option_name);
66 $this->option_name[$i]= "";
67 $this->option_value[$i]= "";
68 }
70 /* Remove value from list */
71 for ($i= 0; $i<count($this->option_name); $i++){
72 if (isset($_POST["remove$i"])){
73 $k= 0;
74 $on= array();
75 $ov= array();
76 for ($j= 0; $j<count($this->option_name); $j++){
77 if ($j != $i){
78 $on[$k]= $this->option_name[$j];
79 $ov[$k]= $this->option_value[$j];
80 $k++;
81 }
82 }
83 $this->option_name= $on;
84 $this->option_value= $ov;
85 break;
86 }
87 }
88 }
90 /* Generate list of attributes */
91 if (count($this->option_name) == 0){
92 $this->option_name[]= "";
93 $this->option_value[]= "";
94 }
98 $acl = $this->getacl("gosaApplicationParameter") ;
99 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
100 if (count ($this->option_name)){
102 for ($i= 0; $i < count($this->option_name); $i++){
103 $name = $this->option_name[$i];
104 $value= $this->option_value[$i];
106 $tag = "";
107 if(!preg_match("/w/",$acl)){
108 $tag = " disabled ";
109 }
111 if(!preg_match("/r/",$acl)){
112 $name = "";
113 $value= "";
114 }
116 $table.="<tr>".
117 " <td>".
118 " <input name=\"option$i\" size=25 maxlength=50 value=\"".$name."\" ".$tag.">".
119 " </td>".
120 " <td>".
121 " <input name=\"value$i\" size=60 maxlength=250 value=\"".$value."\" ".$tag.">".
122 " <br>".
123 " </td>".
124 " <td>".
125 " <input type=\"submit\" name=\"remove$i\" value=\""._("Remove")."\" ".$tag.">".
126 " </td>".
127 "</tr>";
128 }
129 }
130 $table.= "</table>";
131 $table.="<input type=\"submit\" name=\"add_option\" $tag value=\""._("Add option")."\">";
133 /* Show main page */
134 $smarty= get_smarty();
135 $tmp = $this->plInfo();
136 foreach($tmp['plProvidedAcls'] as $name => $translation){
137 $smarty->assign($name."ACL",$this->getacl($name));
138 }
140 $smarty->assign("table", $table);
141 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
142 $this->parent->by_object['application']->generateTemplate();
143 return ($display);
144 }
146 function remove_from_parent()
147 {
148 $ldap= $this->config->get_ldap_link();
150 /* Zero attributes */
151 $this->attrs= array();
152 $this->attrs['gosaApplicationParameter']= array();
154 $ldap->cd($this->dn);
155 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
156 $this->attributes, "Save");
157 $this->cleanup();
158 $ldap->modify ($this->attrs);
160 if (!$ldap->success()){
161 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
162 }
164 /* Optionally execute a command after we're done */
165 $this->handle_post_events('remove');
166 }
169 /* Save data to object */
170 function save_object()
171 {
172 if (isset($_POST['option0']) && $this->acl_is_writeable("gosaApplicationParameter")){
173 for ($i= 0; $i<count($this->option_name); $i++){
174 $this->option_name[$i]= $_POST["option$i"];
175 $this->option_value[$i]= "";
176 if ($_POST["value$i"] != ""){
177 $this->option_value[$i]= $_POST["value$i"];
178 }
179 }
180 }
181 }
184 /* Check values */
185 function check()
186 {
187 /* Call common method to give check the hook */
188 $message= plugin::check();
190 /* Check for valid option names */
191 for ($i= 0; $i<count($this->option_name); $i++){
192 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
193 $message[]= msgPool::invalid(_("Name"), $this->option_name[$i],"/^[a-z0-9_]+$/i");
194 }
195 }
197 return $message;
198 }
201 /* Save to LDAP */
202 function save()
203 {
204 /* Generate values */
205 $this->attrs= array();
206 if (count($this->option_name) == 0){
207 $this->attrs['gosaApplicationParameter']= array();
208 } else {
209 for ($i= 0; $i<count($this->option_name); $i++){
210 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
211 ":".$this->option_value[$i];
212 }
213 }
215 /* Write back to ldap */
216 $ldap= $this->config->get_ldap_link();
217 $ldap->cd($this->dn);
218 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
219 $this->attributes, "Save");
220 $this->cleanup();
221 $ldap->modify ($this->attrs);
223 if (!$ldap->success()){
224 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
225 }
227 /* Optionally execute a command after we're done */
228 $this->handle_post_events('modify');
229 }
231 /* Return plugin informations for acl handling
232 #FIXME FAIscript seams to ununsed within this class... */
233 static function plInfo()
234 {
235 return (array(
236 "plShortName" => _("Parameter"),
237 "plDescription" => _("Parameter configuration"),
238 "plSelfModify" => FALSE,
239 "plDepends" => array(),
240 "plPriority" => 0,
241 "plSection" => array("administration"),
242 "plCategory" => array("application"),
244 "plProvidedAcls"=> array(
245 "gosaApplicationParameter" => _("Application parameter settings"))
246 ));
247 }
250 }
251 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
252 ?>