f72339f9618ba2806f4a0a11a2949c6537f1e7c0
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 */
15 var $CopyPasteVars = array("option_name","option_value");
16 var $attributes= array("gosaApplicationParameter");
17 var $objectclasses= array();
18 var $ui;
20 function applicationParameters ($config, $dn= NULL, $parent= NULL)
21 {
22 plugin::plugin ($config, $dn, $parent);
24 $this->gosaApplicationParameter = array();
26 if (isset($this->attrs['gosaApplicationParameter'])){
27 $this->is_account= TRUE;
28 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
29 $option= preg_replace('/^[^:]+:/', '',
30 $this->attrs['gosaApplicationParameter'][$i]);
31 $name= preg_replace('/:.*$/', '',
32 $this->attrs['gosaApplicationParameter'][$i]);
33 $this->option_name[$i]= $name;
34 $this->option_value[$i]= $option;
35 }
36 } else {
37 $this->is_account= FALSE;
38 }
39 $this->ui = get_userinfo();
40 }
42 function execute()
43 {
44 /* Call parent execute */
45 plugin::execute();
47 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
48 $this->acl= get_module_permission($acl, "application", $this->dn);
50 /* Do we need to flip is_account state? */
51 if (isset($_POST['modify_state']) && chkacl($this->acl,"gotoLogonScript")==""){
52 $this->is_account= !$this->is_account;
53 }
55 /* Show tab dialog headers */
56 $display= "";
57 if ($this->parent != NULL){
58 if ($this->is_account){
59 $display= $this->show_header(_("Remove options"),
60 _("This application has options. You can disable them by clicking below."));
61 } else {
62 $display= $this->show_header(_("Create options"),
63 _("This application has options disabled. You can enable them by clicking below."));
64 $this->parent->by_object['application']->generateTemplate();
65 return ($display);
66 }
67 }
69 /* Add option to list */
70 if (isset($_POST['add_option'])){
71 $i= count($this->option_name);
72 $this->option_name[$i]= "";
73 $this->option_value[$i]= "";
74 }
76 if(chkacl($this->acl,"gotoLogonScript") == ""){
78 /* Remove value from list */
79 for ($i= 0; $i<count($this->option_name); $i++){
80 if (isset($_POST["remove$i"])){
81 $k= 0;
82 $on= array();
83 $ov= array();
84 for ($j= 0; $j<count($this->option_name); $j++){
85 if ($j != $i){
86 $on[$k]= $this->option_name[$j];
87 $ov[$k]= $this->option_value[$j];
88 $k++;
89 }
90 }
91 $this->option_name= $on;
92 $this->option_value= $ov;
93 break;
94 }
95 }
96 }
98 /* Generate list of attributes */
99 if (count($this->option_name) == 0){
100 $this->option_name[]= "";
101 $this->option_value[]= "";
102 }
104 $mode= "";
105 if (chkacl($this->acl, "create") != ""){
106 $mode= "disabled";
107 }
109 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
110 if (count ($this->option_name)){
111 for ($i= 0; $i < count($this->option_name); $i++){
112 $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
113 "value=\"".$this->option_name[$i]."\" $mode></td><td><input name=\"value$i\" ".
114 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\" $mode><br></td><td>".
115 "<input type=\"submit\" name=\"remove$i\" value=\"".
116 _("Remove")."\" $mode></td></tr>";
117 }
118 }
119 $table.= "</table>";
121 if ($mode == ""){
122 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
123 }
125 /* Show main page */
126 $smarty= get_smarty();
127 $smarty->assign("table", $table);
128 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
129 $this->parent->by_object['application']->generateTemplate();
130 return ($display);
131 }
133 function remove_from_parent()
134 {
135 $ldap= $this->config->get_ldap_link();
137 /* Zero attributes */
138 $this->attrs= array();
139 $this->attrs['gosaApplicationParameter']= array();
141 $ldap->cd($this->dn);
142 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
143 $this->attributes, "Save");
144 $this->cleanup();
145 $ldap->modify ($this->attrs);
147 show_ldap_error($ldap->get_error(), _("Removing application parameters failed"));
149 /* Optionally execute a command after we're done */
150 $this->handle_post_events('remove');
151 }
154 /* Save data to object */
155 function save_object()
156 {
157 if(chkacl($this->acl,"gotoLogonScript") == ""){
158 if (isset($_POST['option0'])){
159 for ($i= 0; $i<count($this->option_name); $i++){
160 $this->option_name[$i]= $_POST["option$i"];
161 $this->option_value[$i]= "";
162 if ($_POST["value$i"] != ""){
163 $this->option_value[$i]= $_POST["value$i"];
164 }
165 }
166 }
167 }
168 }
171 /* Check values */
172 function check()
173 {
174 /* Call common method to give check the hook */
175 $message= plugin::check();
177 /* Check for valid option names */
178 for ($i= 0; $i<count($this->option_name); $i++){
179 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
180 $message[]= sprintf(_("Value '%s' specified as option name is not valid."),
181 $this->option_name[$i]);
182 }
183 }
185 return $message;
186 }
189 /* Save to LDAP */
190 function save()
191 {
192 /* Generate values */
193 $this->attrs= array();
194 if (count($this->option_name) == 0){
195 $this->attrs['gosaApplicationParameter']= array();
196 } else {
197 for ($i= 0; $i<count($this->option_name); $i++){
198 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
199 ":".$this->option_value[$i];
200 }
201 }
203 /* Write back to ldap */
204 $ldap= $this->config->get_ldap_link();
205 $ldap->cd($this->dn);
206 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
207 $this->attributes, "Save");
208 $this->cleanup();
209 $ldap->modify ($this->attrs);
211 show_ldap_error($ldap->get_error(), _("Saving applications parameters failed"));
213 /* Optionally execute a command after we're done */
214 $this->handle_post_events('modify');
215 }
217 }
219 ?>