Code

Added remove multiple entries to macro list
[gosa.git] / plugins / gofon / conference / class_phoneConferenceManagment.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_conference.inc";
22 class phoneConferenceManagment extends plugin
23 {
24   /* Definitions */
25   var $plHeadline                                 = "Phone conferences";
26   var $plDescription                    = "Management";
28   /* CLI vars */
29   var $cli_summary                        = "Handling of LDAP subtrees";
30   var $cli_description          = "Some longer text\nfor help";
31   var $cli_parameters                   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33   /* attribute list for save action */
34   var $attributes                                 = array();
35   var $objectclasses                    = array();
37   var $conferences                        = array();
38   var $conftab            = false;
39   var $ui                 = NULL;
40   var $DivListConference  = NULL;
42   /* Initialise Class */
43   function phoneConferenceManagment ($config, $ui)
44   {
45     $this->ui                     = $ui;
46     $this->dn                     = "";
47     $this->config               = $config;
48     $this->DivListConference = new divListConference($this->config,$this);
49   }
52   /* Execute class and display something */
53   function execute()
54   {
55     /* Call parent execute */
56     plugin::execute();
58     $_SESSION['LOCK_VARS_TO_USE'] = array("/^id$/","/^act$/","/^conference_/");
60     /***************
61       Variable initialisation
62      ***************/
63   
64     /* Reload departments */
65     $smarty                                                       = get_smarty();
66     $display                                              = "";
67     $s_action                                           = "";  // Will contain an action, like del or edit
68     $s_entry                                            = "";  // The entry name for edit delete -...
71     /***************
72       Check posts  
73      ***************/
74   
75     foreach($_POST as $key => $post){
76       if(preg_match("/^conference_new.*/i",$key)){
77         $s_action = "new";
78         // Post for delete
79       }elseif(preg_match("/^conference_del.*/",$key)){
80         $s_action = "del";
81         $s_entry  = preg_replace("/^conference_del_/i","",$key);
82         $s_entry  = preg_replace("/_.*$/","",$s_entry);
83         // Post for edit
84       }elseif(preg_match("/conference_edit_.*/",$key)){
85         $s_action="edit";
86         $s_entry  = preg_replace("/conference_edit_/i","",$key);
87         $s_entry  = preg_replace("/_.*$/","",$s_entry);
88       } 
89     }
91     /* Edit Entry */
92     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
93       $s_action = "edit";
94       $s_entry  = $_GET['id'];
95     }
98     /***************
99       Cancel dialogs 
100      ***************/
101   
102     /* Reset requested? */
103     if (isset($_POST['edit_cancel'])){
104       if (isset($this->conftab)){
105         del_lock ($this->conftab->dn);
106         unset ($this->conftab);
107       }
108       $this->conftab= NULL;
109       $this->lognames= array();;
110       $this->cn= "";
111       unset ($_SESSION['objectinfo']);
112     }
115     /***************
116       Delete 
117      ***************/
118   
119     /* Delete Entry if Posted action (s_action) == del
120      * The entry which will be deleted is defined in $s_entry
121      */
122     if ($s_action =="del"){
124       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
125       if(preg_match("/d/",$acl)){
126         $this->dn= $this->conferences[$s_entry]['dn'];
128         /* Check locking */
129         if (($conf= get_lock($this->dn)) != ""){
130           $_SESSION['dn']= $this->dn;
131           return(gen_locked_message($conf, $this->dn));
132         } else {
133           add_lock ($this->dn, $this->ui->dn);
134           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
135           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
136           return ($display);
137         }
138       }
139     }
142     /***************
143       Delete confirmed  
144      ***************/
145   
146     /* If department deletion is accepted ...
147      * Finally delete department
148      */
149     if (isset($_POST['delete_department_confirm'])){
150       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
151       if(preg_match("/d/",$acl)){
152         $this->remove_from_parent();
153         gosa_log ("Department object'".$this->dn."' has been removed");
154       } else {
155         print_red (_("You have no permission to remove this department."));
156       }
157     }
160     /***************
161       Edit
162      ***************/
163   
164     /* Edit Entry if Posted action (s_action) == edit
165      * The entry which will be edited is defined in $s_entry
166      */
167     if (($s_action=="edit") && (!isset($this->conftab->config))){
169       $this->dn= $this->conferences[$s_entry]['dn'];
171       if (($conf= get_lock($this->dn)) != ""){
172         return(gen_locked_message ($conf, $this->dn));
173       }
175       /* Lock the current entry, so everyone will get the  above dialog */
176       add_lock ($this->dn, $this->ui->dn);
178       /* Register conftab to trigger edit dialog */
179       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
180       $this->conftab->set_acl_base($this->dn);
181       $_SESSION['objectinfo']= $this->dn;
182     }
185     /***************
186       Create new  
187      ***************/
188   
189     /* Insert new entry*/    
190     if($s_action == "new" ){
192       $dummy_dn = "cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;      
193       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
194       if(preg_match("/c/",$acl)){
195         /* Set up the users ACL's for this 'dn' */
196         $this->dn= "new";
197         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
198         $this->conftab->set_acl_base($dummy_dn);
199         unset($_SESSION['objectinfo']);
200       }
201     }
204     /***************
205       Save entry  
206      ***************/
207   
208     /* Edit finished, check and save changes */
209     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
210       /* Check tabs, will feed message array */
211       $this->conftab->last= $this->conftab->current;
212       $this->conftab->save_object();
213       $message= $this->conftab->check();
215       if (count($message) == 0){
216         if($this->conftab->save() == 1){
217           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
218           return;
219         }
220         gosa_log ("goFonConference object '".$this->dn."' has been saved");
222         if (!isset($_POST['edit_apply'])){
223           if ($this->dn != "new"){
224             del_lock ($this->dn);
225           }
226         }
228         $this->conftab->save ();
229         del_lock ($this->conftab->dn);;
230         unset ($this->conftab);
231         $this->conftab= NULL;
232         unset ($_SESSION['objectinfo']);
233       } else {
234         show_errors($message);
235       }
236     }
239     /***************
240       Display dialogs   
241      ***************/
242   
243     /* if edit or new, show dialog */
244     if(($this->conftab) && (isset($this->conftab->config))){
245       $display= $this->conftab->execute();
247       /* Don't show buttons if tab dialog requests this */
248       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
249         $display.= "<p style=\"text-align:right\">\n";
250         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
251         $display.= "&nbsp;\n";
252         if ($this->dn != "new"){
253           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
254           $display.= "&nbsp;\n";
255         }
256         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
257         $display.= "</p>";
258       }
259       return ($display);
260     }
263     /***************
264       display divlist
265      ***************/
267     /* Check if there is a snapshot dialog open */
268     $base = $this->DivListConference->selectedBase;
269     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
270       return($str);
271     }
273     /* Return rendered main page */
274     /* Display dialog with system list */
275     $this->DivListConference->parent = $this;
276     $this->DivListConference->execute();
278     /* Add departments if subsearch is disabled */
279     if(!$this->DivListConference->SubSearch){
280       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5);
281     }
282     $this->reload();
283     $this->DivListConference->setEntries($this->conferences);
284     return($this->DivListConference->Draw());
285   }
288   /* Return departments, that will be included within snapshot detection */
289   function get_used_snapshot_bases()
290   {
291     return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
292   }
295   /* Reload entries for divlist.
296    * reload all conferences for the current base, with the given regex
297    */
298   function reload()
299   {
300     $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
301     $SubSearch        = $this->DivListConference->SubSearch;
302     $Regex            = $this->DivListConference->Regex;
303     $Flags            = GL_SIZELIMIT ; 
304     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
305     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
306  
307     if($SubSearch){
308       $Flags |= GL_SUBSEARCH;
309     }
311     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
312   }
314   function remove_from_parent()
315   {
316     /* Ehm what are we doinf here ? */
317   
318     $cfg = new conference($this->config, $this->dn);
319     $cfg->set_acl_category("gofonconference");
320     $cfg->set_acl_base($this->dn);
322     $cfg->remove_from_parent();
323     $ldap= $this->config->get_ldap_link();
324     $ldap->cd ($this->dn);
325     $ldap->recursive_remove();
327     /* Optionally execute a command after we're done */
328     $this->postremove();
330     /* Delete references to object groups */
331     $ldap->cd ($this->config->current['BASE']);
332     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
333     while ($ldap->fetch()){
334       $og= new conftab($this->config, $ldap->getDN());
335       unset($og->member[$this->dn]);
336       $og->save ();
337     }
339   }
341   function save_object()
342   {
343     $this->DivListConference->save_object();
344   }
346   function remove_lock()
347   {
348     if (isset($this->dn)){
349       del_lock ($this->dn);
350     }
351   }
354 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
355 ?>