Code

skipping . .. when deleting smarty spool dir
[gosa.git] / plugins / gofon / macro / class_gofonMacroManagement.inc
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 $macros           = 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_mac']) &&
70         !isset($_POST['delete_mac']) &&
71         !isset($_POST['select_mac'])){
72       $this->reload();
73     }
74   
75     
76     $smarty= get_smarty();
78     /* Check for exeeded sizelimit */
79     if (($message= check_sizelimit()) != ""){
80       return($message);
81     }
83     /* New macro? */
84     if (isset($_POST['new_mac'])){
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 mac 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         /* macro 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 mac 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_mac']) || (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_mac']) && 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, "macro", $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_macro_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") == ""){
202       
203         /* Delete request is permitted, perform LDAP action */
204         $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
205         $this->macrotabs->set_acl(array($this->acl));
206       
207         $this->macrotabs->delete ();
208         gosa_log ("macro 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 {
215         /* Normally this shouldn't be reached, send some extra
216            logs to notify the administrator */
217         print_red (_("You are not allowed to delete this macro!"));
218         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
219       }
220       /* Remove lock file after successfull deletion */
221       del_lock ($this->dn);
222     }
225     /* Delete macro canceled? */
226     if (isset($_POST['delete_cancel'])){
227       del_lock ($this->dn);
228       unset($_SESSION['objectinfo']);
229     }
231     /* Show tab dialog if object is present */
232     if ($this->macrotabs){
233       $display= $this->macrotabs->execute();
235       /* Don't show buttons if tab dialog requests this */
236       if (!$this->macrotabs->by_object[$this->macrotabs->current]->dialog){
237         $display.= "<p style=\"text-align:right\">\n";
238         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
239         $display.= "&nbsp;\n";
240         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
241         $display.= "</p>";
242       }
243       return ($display);
244     }
246     /* Show main page */
247     $smarty->assign("macros", $this->macros);
248     $smarty->assign("search_image", get_template_path('images/search.png'));
249     $smarty->assign("tree_image", get_template_path('images/tree.png'));
250     $smarty->assign("infoimage", get_template_path('images/info.png'));
251     $smarty->assign("launchimage", get_template_path('images/launch.png'));
252     $smarty->assign("deplist", $this->config->idepartments);
253     foreach( array("depselect", "regex") as $type){
254       $smarty->assign("$type", $macrofilter[$type]);
255     }
257     /* Extend if we are not using javascript */
258     $smarty->assign("apply", apply_filter());
259     $smarty->assign("alphabet", generate_alphabet());
260     $smarty->assign("hint", print_sizelimit_warning());
262     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
263   }
266   function reload()
267   {
268     /* Get config */
269     $macrofilter= get_global('macrofilter');
271     /* Set base for all searches */
272     $base= $macrofilter['depselect'];
274     /* Regex filter? */
275     if ($macrofilter['regex'] != ""){
276       $regex= $macrofilter['regex'];
277     } else {
278       $regex= "*";
279     }
281     /* Generate macro list */
282     $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=goFonMacro))", TRUE, $base, array("cn", "description"), TRUE);
283     $this->macros= array();
284     foreach ($res as $value){
285       $this->macros[$value["dn"]]= $value["cn"][0];
286       if (isset($value["description"][0])){
287         $this->macros[$value["dn"]]= $value["cn"][0]." (".
288           $value["description"][0].")";
289       }
290     }
291     natcasesort ($this->macros);
292     reset ($this->macros);
293   }
295   function remove_from_parent()
296   {
297     /* Optionally execute a command after we're done */
298     $this->postremove();
299   }
302   /* Save data to object */
303   function save_object()
304   {
305   }
308   /* Check values */
309   function check()
310   {
311   }
314   /* Save to LDAP */
315   function save()
316   {
317     /* Optionally execute a command after we're done */
318     $this->postcreate();
319   }
321   function adapt_from_template($dn)
322   {
323   }
325   function password_change_needed()
326   {
327   }
329   function show_header($button_text, $text, $disabled= FALSE)
330   {
331   }
333   function remove_lock()
334   {
335     if (isset($this->macrotabs->dn)){
336       del_lock ($this->macrotabs->dn);
337     }
338   }
341 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
342 ?>