c21919f95655912cdb1ebe5f4001641b66a65905
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 */
10 var $CopyPasteVars = array("option_name","option_value");
11 var $attributes= array("gosaApplicationParameter");
12 var $objectclasses= array();
13 var $ui;
15 function applicationParameters ($config, $dn= NULL, $parent= NULL)
16 {
17 plugin::plugin ($config, $dn, $parent);
19 $this->gosaApplicationParameter = array();
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 $this->ui = get_userinfo();
35 }
37 function execute()
38 {
39 /* Call parent execute */
40 plugin::execute();
42 /* Do we need to flip is_account state? */
43 if (isset($_POST['modify_state']) && chkacl($this->acl,"gotoLogonScript")==""){
44 $this->is_account= !$this->is_account;
45 }
47 /* Show tab dialog headers */
48 $display= "";
49 if ($this->parent != NULL){
50 if ($this->is_account){
51 $display= $this->show_header(_("Remove options"),
52 _("This application has options. You can disable them by clicking below."));
53 } else {
54 $display= $this->show_header(_("Create options"),
55 _("This application has options disabled. You can enable them by clicking below."));
56 $this->parent->by_object['application']->generateTemplate();
57 return ($display);
58 }
59 }
61 /* Add option to list */
62 if (isset($_POST['add_option'])){
63 $i= count($this->option_name);
64 $this->option_name[$i]= "";
65 $this->option_value[$i]= "";
66 }
68 if(chkacl($this->acl,"gotoLogonScript") == ""){
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 }
96 $mode= "";
97 if (chkacl($this->acl, "create") != ""){
98 $mode= "disabled";
99 }
101 $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
102 if (count ($this->option_name)){
103 for ($i= 0; $i < count($this->option_name); $i++){
104 $table.="<tr><td><input name=\"option$i\" size=25 maxlength=50 ".
105 "value=\"".$this->option_name[$i]."\" $mode></td><td><input name=\"value$i\" ".
106 "size=60 maxlength=250 value=\"".$this->option_value[$i]."\" $mode><br></td><td>".
107 "<input type=\"submit\" name=\"remove$i\" value=\"".
108 _("Remove")."\" $mode></td></tr>";
109 }
110 }
111 $table.= "</table>";
113 if ($mode == ""){
114 $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
115 }
117 /* Show main page */
118 $smarty= get_smarty();
119 $smarty->assign("table", $table);
120 $display.= $smarty->fetch(get_template_path('parameters.tpl', TRUE));
121 $this->parent->by_object['application']->generateTemplate();
122 return ($display);
123 }
125 function remove_from_parent()
126 {
127 $ldap= $this->config->get_ldap_link();
129 /* Zero attributes */
130 $this->attrs= array();
131 $this->attrs['gosaApplicationParameter']= array();
133 $ldap->cd($this->dn);
134 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
135 $this->attributes, "Save");
136 $this->cleanup();
137 $ldap->modify ($this->attrs);
139 show_ldap_error($ldap->get_error(), _("Removing application parameters failed"));
141 /* Optionally execute a command after we're done */
142 $this->handle_post_events('remove');
143 }
146 /* Save data to object */
147 function save_object()
148 {
149 if(chkacl($this->acl,"gotoLogonScript") == ""){
150 if (isset($_POST['option0'])){
151 for ($i= 0; $i<count($this->option_name); $i++){
152 $this->option_name[$i]= $_POST["option$i"];
153 $this->option_value[$i]= "";
154 if ($_POST["value$i"] != ""){
155 $this->option_value[$i]= $_POST["value$i"];
156 }
157 }
158 }
159 }
160 }
163 /* Check values */
164 function check()
165 {
166 /* Call common method to give check the hook */
167 $message= plugin::check();
169 /* Check for valid option names */
170 for ($i= 0; $i<count($this->option_name); $i++){
171 if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
172 $message[]= sprintf(_("Value '%s' specified as option name is not valid."),
173 $this->option_name[$i]);
174 }
175 }
177 return $message;
178 }
181 /* Save to LDAP */
182 function save()
183 {
184 /* Generate values */
185 $this->attrs= array();
186 if (count($this->option_name) == 0){
187 $this->attrs['gosaApplicationParameter']= array();
188 } else {
189 for ($i= 0; $i<count($this->option_name); $i++){
190 $this->attrs['gosaApplicationParameter'][]= $this->option_name[$i].
191 ":".$this->option_value[$i];
192 }
193 }
195 /* Write back to ldap */
196 $ldap= $this->config->get_ldap_link();
197 $ldap->cd($this->dn);
198 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
199 $this->attributes, "Save");
200 $this->cleanup();
201 $ldap->modify ($this->attrs);
203 show_ldap_error($ldap->get_error(), _("Saving applications parameters failed"));
205 /* Optionally execute a command after we're done */
206 $this->handle_post_events('modify');
207 }
209 }
211 ?>