Code

Updated filtering again
[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   /* attribute list for save action */
29   var $attributes                                 = array();
30   var $objectclasses                    = array();
32   var $conferences                        = array();
33   var $conftab            = false;
35   var $DivListConference  = NULL;
37   /* Initialise Class */
38   function phoneConferenceManagment ($config, $ui)
39   {
40     $this->ui                   = $ui;
41     $this->dn                   = "";
42     $this->config               = $config;
44     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
45     $this->acl= get_module_permission($acl, "conference", $ui->dn);
47     $this->DivListConference = new divListConference($this->config,$this);
48   }
51   /* Execute class and display something */
52   function execute()
53   {
54     /* Call parent execute */
55     plugin::execute();
57     /***************
58       Variable initialisation
59      ***************/
60   
61     /* Reload departments */
62     $smarty                                                       = get_smarty();
63     $display                                              = "";
64     $s_action                                           = "";  // Will contain an action, like del or edit
65     $s_entry                                            = "";  // The entry name for edit delete -...
68     /***************
69       Check posts  
70      ***************/
71   
72     foreach($_POST as $key => $post){
73       if(preg_match("/.*new.*/i",$key)){
74         $s_action = "new";
75         // Post for delete
76       }elseif(preg_match("/conf_del.*/",$key)){
77         $s_action = "del";
78         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
79         $s_entry  = preg_replace("/_.*$/","",$s_entry);
80         // Post for edit
81       }elseif(preg_match("/conf_edit_.*/",$key)){
82         $s_action="edit";
83         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
84         $s_entry  = preg_replace("/_.*$/","",$s_entry);
85       } 
86     }
88     /* Edit Entry */
89     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
90       $s_action = "edit";
91       $s_entry  = $_GET['id'];
92     }
95     /***************
96       Cancel dialogs 
97      ***************/
98   
99     /* Reset requested? */
100     if (isset($_POST['edit_cancel'])){
101       if (isset($this->conftab)){
102         del_lock ($this->conftab->dn);
103         unset ($this->conftab);
104       }
105       $this->conftab= NULL;
106       $this->lognames= array();;
107       $this->cn= "";
108       unset ($_SESSION['objectinfo']);
109     }
112     /***************
113       Delete 
114      ***************/
115   
116     /* Delete Entry if Posted action (s_action) == del
117      * The entry which will be deleted is defined in $s_entry
118      */
119     if ($s_action =="del"){
120       $this->dn= $this->conferences[$s_entry]['dn'];
122       /* Check locking */
123       if (($conf= get_lock($this->dn)) != ""){
124         $_SESSION['dn']= $this->dn;
125         return(gen_locked_message($conf, $this->dn));
126       } else {
127         add_lock ($this->dn, $this->ui->dn);
128         $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
129         $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
130         return ($display);
131       }
132     }
135     /***************
136       Delete confirmed  
137      ***************/
138   
139     /* If department deletion is accepted ...
140      * Finally delete department
141      */
142     if (isset($_POST['delete_department_confirm'])){
143       if (chkacl($this->acl, "delete") == ""){
144         $this->remove_from_parent();
145         gosa_log ("Department object'".$this->dn."' has been removed");
146       } else {
147         print_red (_("You have no permission to remove this department."));
148       }
149     }
152     /***************
153       Edit
154      ***************/
155   
156     /* Edit Entry if Posted action (s_action) == edit
157      * The entry which will be edited is defined in $s_entry
158      */
159     if (($s_action=="edit") && (!isset($this->conftab->config))){
161       $this->dn= $this->conferences[$s_entry]['dn'];
163       if (($conf= get_lock($this->dn)) != ""){
164         return(gen_locked_message ($conf, $this->dn));
165       }
167       /* Lock the current entry, so everyone will get the  above dialog */
168       add_lock ($this->dn, $this->ui->dn);
170       /* Register conftab to trigger edit dialog */
171       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
172       $_SESSION['objectinfo']= $this->dn;
173     }
176     /***************
177       Create new  
178      ***************/
179   
180     /* Insert new entry*/    
181     if($s_action == "new"){
182       
183       /* Set up the users ACL's for this 'dn' */
184       $this->dn= "new";
185       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
186       unset($_SESSION['objectinfo']);
187     }
190     /***************
191       Save entry  
192      ***************/
193   
194     /* Edit finished, check and save changes */
195     if ((isset($_POST['edit_finish'])) && (isset($this->conftab->config))){
196       /* Check tabs, will feed message array */
197       $this->conftab->last= $this->conftab->current;
198       $this->conftab->save_object();
199       $message= $this->conftab->check();
201       if (count($message) == 0){
202         if($this->conftab->save() == 1){
203           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
204           return;
205         }
206         gosa_log ("goFonConference object '".$this->dn."' has been saved");
208         if ($this->dn != "new"){
209           del_lock ($this->dn);
210         }
212         del_lock ($this->conftab->dn);;
213         unset ($this->conftab);
214         $this->conftab= NULL;
215         unset ($_SESSION['objectinfo']);
216       } else {
217         show_errors($message);
218       }
219     }
222     /***************
223       Display dialogs   
224      ***************/
225   
226     /* if edit or new, show dialog */
227     if(($this->conftab) && (isset($this->conftab->config))){
228       $display= $this->conftab->execute();
230       /* Don't show buttons if tab dialog requests this */
231       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
232         $display.= "<p style=\"text-align:right\">\n";
233         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
234         $display.= "&nbsp;\n";
235         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
236         $display.= "</p>";
237       }
238       return ($display);
239     }
242     /***************
243       display divlist
244      ***************/
246     /* Return rendered main page */
247     /* Display dialog with system list */
248     $this->DivListConference->parent = $this;
249     $this->DivListConference->execute();
251     /* Add departments if subsearch is disabled */
252     if(!$this->DivListConference->SubSearch){
253       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5);
254     }
255     $this->reload();
256     $this->DivListConference->setEntries($this->conferences);
257     return($this->DivListConference->Draw());
258   }
261   /* Reload entries for divlist.
262    * reload all conferences for the current base, with the given regex
263    */
264   function reload()
265   {
266     $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
267     $SubSearch        = $this->DivListConference->SubSearch;
268     $Regex            = $this->DivListConference->Regex;
269     $Flags            = GL_SIZELIMIT ; 
270     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
271     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber","description");
272  
273     if($SubSearch){
274       $Flags |= GL_SUBSEARCH;
275     }
277     $this->conferences= get_list($Filter,  $this->ui->subtreeACL, $Base, $Attrs, $Flags);
278   }
280   function remove_from_parent()
281   {
282     $cfg = new conference($this->config, $this->dn);
284     $cfg->remove_from_parent();
285     $ldap= $this->config->get_ldap_link();
286     $ldap->cd ($this->dn);
287     $ldap->recursive_remove();
289     /* Optionally execute a command after we're done */
290     $this->postremove();
292     /* Delete references to object groups */
293     $ldap->cd ($this->config->current['BASE']);
294     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
295     while ($ldap->fetch()){
296       $og= new conftab($this->config, $ldap->getDN());
297       unset($og->member[$this->dn]);
298       $og->save ();
299     }
301   }
303   function save_object()
304   {
305     $this->DivListConference->save_object();
306   }
308   function remove_lock()
309   {
310     if (isset($this->dn)){
311       del_lock ($this->dn);
312     }
313   }
316 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
317 ?>