1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_macros.inc";
22 class gofonMacro extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Phone macros";
26 var $plDescription = "This does something";
28 /* Dialog attributes */
29 var $macrotabs = NULL;
30 var $applications = array();
31 var $ui = NULL;
32 var $acl = "";
34 function gofonMacro($config, $ui)
35 {
36 /* Save configuration for internal use */
37 $this->config= $config;
38 $this->ui= $ui;
40 /* Get global filter config */
41 if (!is_global("macrofilter")){
42 $base= get_base_from_people($ui->dn);
43 $macrofilter= array("depselect" => $base, "regex" => "*");
44 register_global("macrofilter", $macrofilter);
45 }
46 }
48 function execute()
49 {
50 /* Save data */
51 $macrofilter= get_global("macrofilter");
52 foreach( array("depselect", "regex") as $type){
53 if (isset($_POST[$type])){
54 $macrofilter[$type]= $_POST[$type];
55 }
56 }
57 if (isset($_GET['search'])){
58 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
59 if ($s == "**"){
60 $s= "*";
61 }
62 $macrofilter['regex']= $s;
63 }
64 /* Save (new) Filter */
65 register_global("macrofilter", $macrofilter);
67 /* Check sorting variable */
68 if (!isset($this->macrotabs) &&
69 !isset($_POST['new_app']) &&
70 !isset($_POST['delete_app']) &&
71 !isset($_POST['select_app'])){
72 $this->reload();
73 }
76 $smarty= get_smarty();
78 /* Check for exeeded sizelimit */
79 if (($message= check_sizelimit()) != ""){
80 return($message);
81 }
83 /* New application? */
84 if (isset($_POST['new_app'])){
86 /* By default we set 'dn' to 'new', all relevant plugins will
87 react on this. */
88 $this->dn= "new";
90 /* Create new usertab object */
91 $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
92 $this->macrotabs->set_acl(array(':all'));
93 }
95 /* Cancel dialogs */
96 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
97 del_lock ($this->macrotabs->dn);
98 unset ($this->macrotabs);
99 $this->macrotabs= NULL;
100 unset ($_SESSION['objectinfo']);
101 }
103 /* Finish apps edit is triggered by the tabulator dialog, so
104 the user wants to save edited data. Check and save at this
105 point. */
106 if (isset($_POST['edit_finish'])){
108 /* Check tabs, will feed message array */
109 $this->macrotabs->last= $this->macrotabs->current;
110 $this->macrotabs->save_object();
111 $message= $this->macrotabs->check();
113 /* Save, or display error message? */
114 if (count($message) == 0){
116 /* Save data data to ldap */
117 $this->macrotabs->save();
118 gosa_log ("Macro object'".$this->dn."' has been saved");
120 /* Application has been saved successfully, remove lock from
121 LDAP. */
122 if ($this->dn != "new"){
123 del_lock ($this->dn);
124 }
126 /* There's no page reload so we have to read new apps at
127 this point. */
128 $this->reload ();
129 unset ($this->macrotabs);
130 $this->macrotabs= NULL;
131 unset ($_SESSION['objectinfo']);
132 } else {
133 /* Ok. There seem to be errors regarding to the tab data,
134 show message and continue as usual. */
135 show_errors($message);
136 }
137 }
139 /* User wants to edit data? */
140 if ((isset($_POST['select_app']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['macrolists']) && $_POST['macrolists'] != ""){
142 /* Get 'dn' from posted 'macrolists', must be unique */
143 $this->dn= trim($_POST['macrolists']);
145 /* Check locking, save current plugin in 'back_plugin', so
146 the dialog knows where to return. */
147 if (($user= get_lock($this->dn)) != ""){
148 return(gen_locked_message ($user, $this->dn));
149 }
151 /* Lock the current entry, so everyone will get the
152 above dialog */
153 add_lock ($this->dn, $this->ui->dn);
155 /* Set up the users ACL's for this 'dn' */
156 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
158 /* Register macrotabs to trigger edit dialog */
159 $this->macrotabs= new macrotabs($this->config,
160 $this->config->data['TABS']['MACROTABS'], $this->dn);
161 $this->macrotabs->set_acl($acl);
162 $_SESSION['objectinfo']= $this->dn;
163 }
165 /* Remove user was requested */
166 if (isset($_POST['delete_app']) && isset($_POST['macrolists'])){
168 /* Get 'dn' from posted 'uid' */
169 $this->dn= trim($_POST['macrolists']);
171 /* Load permissions for selected 'dn' and check if
172 we're allowed to remove this 'dn' */
173 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
174 $this->acl= get_module_permission($acl, "application", $this->dn);
175 if (chkacl($this->acl, "delete") == ""){
177 /* Check locking, save current plugin in 'back_plugin', so
178 the dialog knows where to return. */
179 if (($user= get_lock($this->dn)) != ""){
180 return (gen_locked_message ($user, $this->dn));
181 }
183 /* Lock the current entry, so nobody will edit it during deletion */
184 add_lock ($this->dn, $this->ui->dn);
185 $smarty= get_smarty();
186 $smarty->assign("intro", sprintf(_("You're about to delete the macro '%s'."), $this->dn));
187 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
188 } else {
190 /* Obviously the user isn't allowed to delete. Show message and
191 clean session. */
192 print_red (_("You are not allowed to delete this, macro!"));
193 }
194 }
196 /* Confirmation for deletion has been passed. Group should be deleted. */
197 if (isset($_POST['delete_app_confirm'])){
199 /* Some nice guy may send this as POST, so we've to check
200 for the permissions again. */
201 if (chkacl($this->acl, "delete") == ""){
203 /* Delete request is permitted, perform LDAP action */
204 $this->macrotabs= new macrotabs($this->config,
205 $this->config->data['TABS']['MACROTABS'], $this->dn);
206 $this->macrotabs->set_acl(array($this->acl));
207 $this->macrotabs->delete ();
208 gosa_log ("Application object'".$this->dn."' has been removed");
209 unset ($this->macrotabs);
210 $this->macrotabs= NULL;
212 /* Group list has changed, reload it. */
213 $this->reload ();
214 } else {
216 /* Normally this shouldn't be reached, send some extra
217 logs to notify the administrator */
218 print_red (_("You are not allowed to delete this application!"));
219 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
220 }
222 /* Remove lock file after successfull deletion */
223 del_lock ($this->dn);
224 }
227 /* Delete application canceled? */
228 if (isset($_POST['delete_cancel'])){
229 del_lock ($this->dn);
230 unset($_SESSION['objectinfo']);
231 }
233 /* Show tab dialog if object is present */
234 if ($this->macrotabs){
235 $display= $this->macrotabs->execute();
237 /* Don't show buttons if tab dialog requests this */
238 if (!$this->macrotabs->by_object[$this->macrotabs->current]->dialog){
239 $display.= "<p style=\"text-align:right\">\n";
240 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
241 $display.= " \n";
242 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
243 $display.= "</p>";
244 }
245 return ($display);
246 }
248 /* Show main page */
249 $smarty->assign("applications", $this->applications);
250 $smarty->assign("search_image", get_template_path('images/search.png'));
251 $smarty->assign("tree_image", get_template_path('images/tree.png'));
252 $smarty->assign("infoimage", get_template_path('images/info.png'));
253 $smarty->assign("launchimage", get_template_path('images/launch.png'));
254 $smarty->assign("deplist", $this->config->idepartments);
255 foreach( array("depselect", "regex") as $type){
256 $smarty->assign("$type", $macrofilter[$type]);
257 }
259 /* Extend if we are not using javascript */
260 $smarty->assign("apply", apply_filter());
261 $smarty->assign("alphabet", generate_alphabet());
262 $smarty->assign("hint", print_sizelimit_warning());
264 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
265 }
268 function reload()
269 {
270 /* Get config */
271 $macrofilter= get_global('macrofilter');
273 /* Set base for all searches */
274 $base= $macrofilter['depselect'];
276 /* Regex filter? */
277 if ($macrofilter['regex'] != ""){
278 $regex= $macrofilter['regex'];
279 } else {
280 $regex= "*";
281 }
283 /* Generate application list */
284 $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=goFonMacro))", TRUE, $base, array("cn", "description"), TRUE);
285 $this->applications= array();
286 foreach ($res as $value){
287 $this->applications[$value["dn"]]= $value["cn"][0];
288 if (isset($value["description"][0])){
289 $this->applications[$value["dn"]]= $value["cn"][0]." (".
290 $value["description"][0].")";
291 }
292 }
293 natcasesort ($this->applications);
294 reset ($this->applications);
295 }
297 function remove_from_parent()
298 {
299 /* Optionally execute a command after we're done */
300 $this->postremove();
301 }
304 /* Save data to object */
305 function save_object()
306 {
307 }
310 /* Check values */
311 function check()
312 {
313 }
316 /* Save to LDAP */
317 function save()
318 {
319 /* Optionally execute a command after we're done */
320 $this->postcreate();
321 }
323 function adapt_from_template($dn)
324 {
325 }
327 function password_change_needed()
328 {
329 }
331 function show_header($button_text, $text, $disabled= FALSE)
332 {
333 }
335 function remove_lock()
336 {
337 if (isset($this->macrotabs->dn)){
338 del_lock ($this->macrotabs->dn);
339 }
340 }
342 }
343 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
344 ?>