Code

Fixed macro visible flag
[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                                    = "";
33   var $DivListMacro     = NULL;
35   function gofonMacro($config, $ui)
36   {
37     /* Save configuration for internal use */
38     $this->config= $config;
39     $this->ui= $ui;
41     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
42     $this->acl= get_module_permission($acl, "goFonMacro", $ui->dn);
44     $this->DivListMacro = new divListMacro($this->config,$this);
45   }
47   function execute()
48   {
49     /* Call parent execute */
50     plugin::execute();
52     /*****************
53       Variable initialisation
54      *****************/
56     $s_action     = "";                       // Contains the action to proceed
57     $s_entry      = "";                       // The value for s_action
58     $base_back    = "";                       // The Link for Backbutton
59     $smarty= get_smarty();
62     /*****************
63       Check Posts 
64      *****************/
66     /* Test Posts */
67     foreach($_POST as $key => $val){
68       // Post for delete
69       if(preg_match("/user_del.*/",$key)){
70         $s_action = "del";
71         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
72         // Post for edit
73       }elseif(preg_match("/user_edit_.*/",$key)){
74         $s_action="edit";
75         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
76         // Post for new
77       }elseif(preg_match("/user_new.*/",$key)){
78         $s_action="new";
79       }elseif(preg_match("/user_chgpw.*/i",$key)){
80         $s_action="change_pw";
81         $s_entry  = preg_replace("/user_chgpw_/i","",$key);
82       }
83     }
84     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
85       $s_action ="edit";
86       $s_entry  = $_GET['id'];
87     }
88     $s_entry  = preg_replace("/_.$/","",$s_entry);
91     /*****************
92       Create a new Macro 
93      *****************/
95     /* New macro? */
96     if ($s_action=="new"){
98       /* By default we set 'dn' to 'new', all relevant plugins will
99          react on this. */
100       $this->dn= "new";
102       /* Create new usertab object */
103       $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
104     }
107     /*****************
108       Edit || Password canceled  
109      *****************/
111     /* Cancel dialogs */
112     if (isset($_POST['edit_cancel']) || isset($_POST['delete_cancel'])){
113       del_lock ($this->macrotabs->dn);
114       unset ($this->macrotabs);
115       $this->macrotabs= NULL;
116       unset ($_SESSION['objectinfo']);
117     }
120     /*****************
121       Edit finised
122      *****************/
124     /* Finish mac edit is triggered by the tabulator dialog, so
125        the user wants to save edited data. Check and save at this
126        point. */
127     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->macrotabs->config))){
129       /* Check tabs, will feed message array */
130       $this->macrotabs->last= $this->macrotabs->current;
131       $this->macrotabs->save_object();
132       $message= $this->macrotabs->check();
134       /* Save, or display error message? */
135       if (count($message) == 0){
137         /* Save data data to ldap */
138         $this->macrotabs->save();
139         gosa_log ("Macro object'".$this->dn."' has been saved");
141         if (!isset($_POST['edit_apply'])){
142           /* macro has been saved successfully, remove lock from
143              LDAP. */
144           if ($this->dn != "new"){
145             del_lock ($this->dn);
146           }
148           unset ($this->macrotabs);
149           $this->macrotabs= NULL;
150           unset ($_SESSION['objectinfo']);
151         }
152       } else {
153         /* Ok. There seem to be errors regarding to the tab data,
154            show message and continue as usual. */
155         show_errors($message);
156       }
157     }
160     /*****************
161       Edit macro 
162      *****************/
164     /* User wants to edit data */
165     if (($s_action=="edit") && (!isset($this->macrotabs->config))){
167       /* Get 'dn' from posted 'macrolists', must be unique */
168       $this->dn= $this->macros[$s_entry]['dn']; 
170       /* Check locking, save current plugin in 'back_plugin', so
171          the dialog knows where to return. */
172       if (($user= get_lock($this->dn)) != ""){
173         return(gen_locked_message ($user, $this->dn));
174       }
176       /* Lock the current entry, so everyone will get the
177          above dialog */
178       add_lock ($this->dn, $this->ui->dn);
179       /* Register macrotabs to trigger edit dialog */
180       $this->macrotabs= new macrotabs($this->config,
181           $this->config->data['TABS']['MACROTABS'], $this->dn);
182       $_SESSION['objectinfo']= $this->dn;
183     }
186     /*****************
187       Remove marco
188      *****************/
190     /* Remove user was requested */
191     if ($s_action=="del"){
193       /* Get 'dn' from posted 'uid' */
194       $this->dn= $this->macros[$s_entry]['dn'];
196       /* Load permissions for selected 'dn' and check if
197          we're allowed to remove this 'dn' */
198       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
199       $this->acl= get_module_permission($acl, "goFonMacro", $this->dn);
200       if (chkacl($this->acl, "delete") == ""){
202         /* Check locking, save current plugin in 'back_plugin', so
203            the dialog knows where to return. */
204         if (($user= get_lock($this->dn)) != ""){
205           return (gen_locked_message ($user, $this->dn));
206         }
208         /* Lock the current entry, so nobody will edit it during deletion */
209         add_lock ($this->dn, $this->ui->dn);
210         $smarty= get_smarty();
211         $smarty->assign("intro", sprintf(_("You're about to delete the macro '%s'."), $this->dn));
212         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
213       } else {
215         /* Obviously the user isn't allowed to delete. Show message and
216            clean session. */
217         print_red (_("You are not allowed to delete this macro!"));
218       }
219     }
222     /*****************
223       Remove macro
224      *****************/
226     /* Confirmation for deletion has been passed. Macro should be deleted. */
227     if (isset($_POST['delete_macro_confirm'])){
229       /* Some nice guy may send this as POST, so we've to check
230          for the permissions again. */
231       if (chkacl($this->acl, "delete") == ""){
233         /* Delete request is permitted, perform LDAP action */
234         $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
235         $this->macrotabs->set_acl(array($this->acl));
237         $this->macrotabs->delete ();
238         gosa_log ("macro object'".$this->dn."' has been removed");
239         unset ($this->macrotabs);
240         $this->macrotabs= NULL;
241       } else {
242         /* Normally this shouldn't be reached, send some extra
243            logs to notify the administrator */
244         print_red (_("You are not allowed to delete this macro!"));
245         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
246       }
247       /* Remove lock file after successfull deletion */
248       del_lock ($this->dn);
249     }
252     /*****************
253       Display open dialogs  
254      *****************/
256     /* Show tab dialog if object is present */
257     if (($this->macrotabs) && (isset($this->macrotabs->config))){
258       $display= $this->macrotabs->execute();
260       /* Don't show buttons if tab dialog requests this */
261       if (!$this->macrotabs->by_object[$this->macrotabs->current]->dialog){
262         $display.= "<p style=\"text-align:right\">\n";
263         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
264         $display.= "&nbsp;\n";
265         if ($this->dn != "new"){
266           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
267           $display.= "&nbsp;\n";
268         }
269         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
270         $display.= "</p>";
271       }
272       return ($display);
273     }
276     /*****************
277       Display entry list 
278      *****************/
280     /* Return rendered main page */
281     /* Display dialog with system list */
282     $this->DivListMacro->parent = $this;
283     $this->DivListMacro->execute();
285     /* Add departments if subsearch is disabled */
286     if(!$this->DivListMacro->SubSearch){
287       $this->DivListMacro->AddDepartments($this->DivListMacro->selectedBase,4);
288     }
289     $this->reload();
290     $this->DivListMacro->setEntries($this->macros);
291     return($this->DivListMacro->Draw());
292   }
295   function reload()
296   {
297     /* Set base for all searches */
298     $base       = $this->DivListMacro->selectedBase;
299     $SubSearch  = $this->DivListMacro->SubSearch;
300     $Regex      = $this->DivListMacro->Regex;
301     $Filter     = "(&(cn=".$Regex.")(objectClass=goFonMacro))";
302     $Flags      = GL_SIZELIMIT;
303     $Attrs      = array("cn","description","displayName","goFonMacroVisible");
305     /* Prepare for ls or search*/        
306     if($SubSearch){
307       $Flags |= GL_SUBSEARCH;
308     }else{
309       $base = "ou=macros,ou=asterisk,ou=configs,ou=systems,".$base;
310     }
312     /* Generate macro list */
313     $res= get_list($Filter, $this->ui->subtreeACL,$base, $Attrs, $Flags);
315     $tmp=array();
316     foreach($res as $tkey => $val ){
317       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
318     }
319     ksort($tmp);
320     $this->macros=array();
321     foreach($tmp as $val){
322       $this->macros[]=$val;
323     }
325     reset ($this->macros);
326   }
329   /* Save data to object */
330   function save_object()
331   {
332     $this->DivListMacro->save_object();
333   }
336   function adapt_from_template($dn)  { }
337   function check() { }
339 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
340 ?>