Code

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