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 $ldap->modify($this->attrs);
124 show_ldap_error($ldap->get_error());
126 /* Optionally execute a command after we're done */
127 $this->handle_post_events('remove');
128 }
131 /* Save data to object */
132 function save_object()
133 {
134 if (isset($_POST['option0'])){
135 for ($i= 0; $i<count($this->option_name); $i++){
136 $this->option_name[$i]= $_POST["option$i"];
137 $this->option_value[$i]= "";
138 if ($_POST["value$i"] != ""){
139 $this->option_value[$i]= $_POST["value$i"];
140 }
141 }
142 }
143 }
146 /* Check values */
147 function check()
148 {
149 $message= array();
151 /* Check for valid option names */
152 for ($i= 0; $i<count($this->option_name); $i++){
153 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
154 $message[]= sprintf(_("Value '%s' specified as option name is not valid."),
155 $this->option_name[$i]);
156 }
157 }
159 return $message;
160 }
163 /* Save to LDAP */
164 function save()
165 {
166 /* Generate values */
167 $this->attrs= array();
168 if (count($this->option_name) == 0){
169 $this->attrs['gosaApplicationParameter']= array();
170 } else {
171 for ($i= 0; $i<count($this->option_name); $i++){
172 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
173 ":".$this->option_value[$i];
174 }
175 }
177 /* Write back to ldap */
178 $ldap= $this->config->get_ldap_link();
179 $ldap->cd($this->dn);
180 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
181 $this->attributes, "Save");
182 $ldap->modify($this->attrs);
183 show_ldap_error($ldap->get_error());
185 /* Optionally execute a command after we're done */
186 $this->handle_post_events('modify');
187 }
189 }
191 ?>