Code

Added copy & paste to gofon Macros
[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_/","/^item_selected/","/^remove_multiple_conferences/");
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       }elseif(preg_match("/^remove_multiple_conferences/",$key)){
89         $s_action="del_multiple";
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     }
118     /********************
119       Delete MULTIPLE entries requested, display confirm dialog
120      ********************/
122     if ($s_action=="del_multiple"){
123       $ids = $this->list_get_selected_items();
125       if(count($ids)){
127         foreach($ids as $id){
128           $dn = $this->conferences[$id]['dn'];
129           if (($user= get_lock($dn)) != ""){
130             return(gen_locked_message ($user, $dn));
131           }
132           $this->dns[$id] = $dn;
133         }
135         $dns_names = "<br><pre>";
136         foreach($this->dns as $dn){
137           add_lock ($dn, $this->ui->dn);
138           $dns_names .= $dn."\n";
139         }
140         $dns_names .="</pre>";
142         /* Lock the current entry, so nobody will edit it during deletion */
143         $smarty->assign("info",     sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names)));
144         $smarty->assign("multiple", true);
145         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
146       }
147     }
150     /********************
151       Delete MULTIPLE entries confirmed
152      ********************/
154     /* Confirmation for deletion has been passed. Users should be deleted. */
155     if (isset($_POST['delete_multiple_conference_confirm'])){
157       /* Remove user by user and check acls before removeing them */
158       foreach($this->dns as $key => $dn){
159         $this->dn = $dn;
160         $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
161         if(preg_match("/d/",$acl)){
162           $this->remove_from_parent();
163         } else {
164           print_red (_("You have no permission to remove this department."));
165         }
166         /* Remove lock file after successfull deletion */
167         del_lock ($dn);
168         unset($this->dns[$key]);
169       }
170     }
173     /********************
174       Delete MULTIPLE entries Canceled
175      ********************/
177     /* Remove lock */
178     if(isset($_POST['delete_multiple_conference_cancel'])){
179       foreach($this->dns as $key => $dn){
180         del_lock ($dn);
181         unset($this->dns[$key]);
182       }
183     }
186     /***************
187       Delete 
188      ***************/
189   
190     /* Delete Entry if Posted action (s_action) == del
191      * The entry which will be deleted is defined in $s_entry
192      */
193     if ($s_action =="del"){
195       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
196       if(preg_match("/d/",$acl)){
197         $this->dn= $this->conferences[$s_entry]['dn'];
199         /* Check locking */
200         if (($conf= get_lock($this->dn)) != ""){
201           $_SESSION['dn']= $this->dn;
202           return(gen_locked_message($conf, $this->dn));
203         } else {
204           add_lock ($this->dn, $this->ui->dn);
205           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
206           $smarty->assign("multiple", false);
207           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
208           return ($display);
209         }
210       }
211     }
214     /***************
215       Delete confirmed  
216      ***************/
217   
218     /* If department deletion is accepted ...
219      * Finally delete department
220      */
221     if (isset($_POST['delete_department_confirm'])){
222       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
223       if(preg_match("/d/",$acl)){
224         $this->remove_from_parent();
225       } else {
226         print_red (_("You have no permission to remove this department."));
227       }
228     }
231     /***************
232       Edit
233      ***************/
234   
235     /* Edit Entry if Posted action (s_action) == edit
236      * The entry which will be edited is defined in $s_entry
237      */
238     if (($s_action=="edit") && (!isset($this->conftab->config))){
240       $this->dn= $this->conferences[$s_entry]['dn'];
242       if (($conf= get_lock($this->dn)) != ""){
243         return(gen_locked_message ($conf, $this->dn));
244       }
246       /* Lock the current entry, so everyone will get the  above dialog */
247       add_lock ($this->dn, $this->ui->dn);
249       /* Register conftab to trigger edit dialog */
250       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
251       $this->conftab->set_acl_base($this->dn);
252       $_SESSION['objectinfo']= $this->dn;
253     }
256     /***************
257       Create new  
258      ***************/
259   
260     /* Insert new entry*/    
261     if($s_action == "new" ){
263       $dummy_dn = "cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;      
264       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
265       if(preg_match("/c/",$acl)){
266         /* Set up the users ACL's for this 'dn' */
267         $this->dn= "new";
268         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
269         $this->conftab->set_acl_base($dummy_dn);
270         unset($_SESSION['objectinfo']);
271       }
272     }
275     /***************
276       Save entry  
277      ***************/
278   
279     /* Edit finished, check and save changes */
280     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
281       /* Check tabs, will feed message array */
282       $this->conftab->last= $this->conftab->current;
283       $this->conftab->save_object();
284       $message= $this->conftab->check();
286       if (count($message) == 0){
287         if($this->conftab->save() == 1){
288           return;
289         }
291         if (!isset($_POST['edit_apply'])){
292           if ($this->dn != "new"){
293             del_lock ($this->dn);
294           }
295         }
297         $this->conftab->save ();
298         del_lock ($this->conftab->dn);;
299         unset ($this->conftab);
300         $this->conftab= NULL;
301         unset ($_SESSION['objectinfo']);
302       } else {
303         show_errors($message);
304       }
305     }
308     /***************
309       Display dialogs   
310      ***************/
311   
312     /* if edit or new, show dialog */
313     if(($this->conftab) && (isset($this->conftab->config))){
314       $display= $this->conftab->execute();
316       /* Don't show buttons if tab dialog requests this */
317       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
318         $display.= "<p style=\"text-align:right\">\n";
319         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
320         $display.= "&nbsp;\n";
321         if ($this->dn != "new"){
322           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
323           $display.= "&nbsp;\n";
324         }
325         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
326         $display.= "</p>";
327       }
328       return ($display);
329     }
332     /***************
333       display divlist
334      ***************/
336     /* Check if there is a snapshot dialog open */
337     $base = $this->DivListConference->selectedBase;
338     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
339       return($str);
340     }
342     /* Return rendered main page */
343     /* Display dialog with system list */
344     $this->DivListConference->parent = $this;
345     $this->DivListConference->execute();
347     /* Add departments if subsearch is disabled */
348     if(!$this->DivListConference->SubSearch){
349       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
350     }
351     $this->reload();
352     $this->DivListConference->setEntries($this->conferences);
353     return($this->DivListConference->Draw());
354   }
357   /* Return departments, that will be included within snapshot detection */
358   function get_used_snapshot_bases()
359   {
360     return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
361   }
364   /* Reload entries for divlist.
365    * reload all conferences for the current base, with the given regex
366    */
367   function reload()
368   {
369     $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
370     $SubSearch        = $this->DivListConference->SubSearch;
371     $Regex            = $this->DivListConference->Regex;
372     $Flags            = GL_SIZELIMIT ; 
373     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
374     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
375  
376     if($SubSearch){
377       $Flags |= GL_SUBSEARCH;
378     }
380     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
381   }
383   function remove_from_parent()
384   {
385     /* Ehm what are we doinf here ? */
386   
387     $cfg = new conference($this->config, $this->dn);
388     $cfg->set_acl_category("gofonconference");
389     $cfg->set_acl_base($this->dn);
391     $cfg->remove_from_parent();
392     $ldap= $this->config->get_ldap_link();
393     $ldap->cd ($this->dn);
394     $ldap->recursive_remove();
396     /* Optionally execute a command after we're done */
397     $this->postremove();
399     /* Delete references to object groups */
400     $ldap->cd ($this->config->current['BASE']);
401     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
402     while ($ldap->fetch()){
403       $og= new conftab($this->config, $ldap->getDN());
404       unset($og->member[$this->dn]);
405       $og->save ();
406     }
408   }
410   function save_object()
411   {
412     $this->DivListConference->save_object();
413   }
415   function remove_lock()
416   {
417     if (isset($this->dn)){
418       del_lock ($this->dn);
419     }
420   }
423   function list_get_selected_items()
424   {
425     $ids = array();
426     foreach($_POST as $name => $value){
427       if(preg_match("/^item_selected_[0-9]*$/",$name)){
428         $id   = preg_replace("/^item_selected_/","",$name);
429         $ids[$id] = $id;
430       }
431     }
432     return($ids);
433   }
437 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
438 ?>