Code

* Fixed undefined index for "All"
[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           gosa_log ("Department object'".$this->dn."' has been removed");
164         } else {
165           print_red (_("You have no permission to remove this department."));
166         }
167         /* Remove lock file after successfull deletion */
168         del_lock ($dn);
169         unset($this->dns[$key]);
170       }
171     }
174     /********************
175       Delete MULTIPLE entries Canceled
176      ********************/
178     /* Remove lock */
179     if(isset($_POST['delete_multiple_conference_cancel'])){
180       foreach($this->dns as $key => $dn){
181         del_lock ($dn);
182         unset($this->dns[$key]);
183       }
184     }
187     /***************
188       Delete 
189      ***************/
190   
191     /* Delete Entry if Posted action (s_action) == del
192      * The entry which will be deleted is defined in $s_entry
193      */
194     if ($s_action =="del"){
196       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
197       if(preg_match("/d/",$acl)){
198         $this->dn= $this->conferences[$s_entry]['dn'];
200         /* Check locking */
201         if (($conf= get_lock($this->dn)) != ""){
202           $_SESSION['dn']= $this->dn;
203           return(gen_locked_message($conf, $this->dn));
204         } else {
205           add_lock ($this->dn, $this->ui->dn);
206           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
207           $smarty->assign("multiple", false);
208           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
209           return ($display);
210         }
211       }
212     }
215     /***************
216       Delete confirmed  
217      ***************/
218   
219     /* If department deletion is accepted ...
220      * Finally delete department
221      */
222     if (isset($_POST['delete_department_confirm'])){
223       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
224       if(preg_match("/d/",$acl)){
225         $this->remove_from_parent();
226         gosa_log ("Department object'".$this->dn."' has been removed");
227       } else {
228         print_red (_("You have no permission to remove this department."));
229       }
230     }
233     /***************
234       Edit
235      ***************/
236   
237     /* Edit Entry if Posted action (s_action) == edit
238      * The entry which will be edited is defined in $s_entry
239      */
240     if (($s_action=="edit") && (!isset($this->conftab->config))){
242       $this->dn= $this->conferences[$s_entry]['dn'];
244       if (($conf= get_lock($this->dn)) != ""){
245         return(gen_locked_message ($conf, $this->dn));
246       }
248       /* Lock the current entry, so everyone will get the  above dialog */
249       add_lock ($this->dn, $this->ui->dn);
251       /* Register conftab to trigger edit dialog */
252       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
253       $this->conftab->set_acl_base($this->dn);
254       $_SESSION['objectinfo']= $this->dn;
255     }
258     /***************
259       Create new  
260      ***************/
261   
262     /* Insert new entry*/    
263     if($s_action == "new" ){
265       $dummy_dn = "cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;      
266       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
267       if(preg_match("/c/",$acl)){
268         /* Set up the users ACL's for this 'dn' */
269         $this->dn= "new";
270         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
271         $this->conftab->set_acl_base($dummy_dn);
272         unset($_SESSION['objectinfo']);
273       }
274     }
277     /***************
278       Save entry  
279      ***************/
280   
281     /* Edit finished, check and save changes */
282     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
283       /* Check tabs, will feed message array */
284       $this->conftab->last= $this->conftab->current;
285       $this->conftab->save_object();
286       $message= $this->conftab->check();
288       if (count($message) == 0){
289         if($this->conftab->save() == 1){
290           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
291           return;
292         }
293         gosa_log ("goFonConference object '".$this->dn."' has been saved");
295         if (!isset($_POST['edit_apply'])){
296           if ($this->dn != "new"){
297             del_lock ($this->dn);
298           }
299         }
301         $this->conftab->save ();
302         del_lock ($this->conftab->dn);;
303         unset ($this->conftab);
304         $this->conftab= NULL;
305         unset ($_SESSION['objectinfo']);
306       } else {
307         show_errors($message);
308       }
309     }
312     /***************
313       Display dialogs   
314      ***************/
315   
316     /* if edit or new, show dialog */
317     if(($this->conftab) && (isset($this->conftab->config))){
318       $display= $this->conftab->execute();
320       /* Don't show buttons if tab dialog requests this */
321       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
322         $display.= "<p style=\"text-align:right\">\n";
323         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
324         $display.= "&nbsp;\n";
325         if ($this->dn != "new"){
326           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
327           $display.= "&nbsp;\n";
328         }
329         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
330         $display.= "</p>";
331       }
332       return ($display);
333     }
336     /***************
337       display divlist
338      ***************/
340     /* Check if there is a snapshot dialog open */
341     $base = $this->DivListConference->selectedBase;
342     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
343       return($str);
344     }
346     /* Return rendered main page */
347     /* Display dialog with system list */
348     $this->DivListConference->parent = $this;
349     $this->DivListConference->execute();
351     /* Add departments if subsearch is disabled */
352     if(!$this->DivListConference->SubSearch){
353       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
354     }
355     $this->reload();
356     $this->DivListConference->setEntries($this->conferences);
357     return($this->DivListConference->Draw());
358   }
361   /* Return departments, that will be included within snapshot detection */
362   function get_used_snapshot_bases()
363   {
364     return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
365   }
368   /* Reload entries for divlist.
369    * reload all conferences for the current base, with the given regex
370    */
371   function reload()
372   {
373     $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
374     $SubSearch        = $this->DivListConference->SubSearch;
375     $Regex            = $this->DivListConference->Regex;
376     $Flags            = GL_SIZELIMIT ; 
377     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
378     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
379  
380     if($SubSearch){
381       $Flags |= GL_SUBSEARCH;
382     }
384     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
385   }
387   function remove_from_parent()
388   {
389     /* Ehm what are we doinf here ? */
390   
391     $cfg = new conference($this->config, $this->dn);
392     $cfg->set_acl_category("gofonconference");
393     $cfg->set_acl_base($this->dn);
395     $cfg->remove_from_parent();
396     $ldap= $this->config->get_ldap_link();
397     $ldap->cd ($this->dn);
398     $ldap->recursive_remove();
400     /* Optionally execute a command after we're done */
401     $this->postremove();
403     /* Delete references to object groups */
404     $ldap->cd ($this->config->current['BASE']);
405     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
406     while ($ldap->fetch()){
407       $og= new conftab($this->config, $ldap->getDN());
408       unset($og->member[$this->dn]);
409       $og->save ();
410     }
412   }
414   function save_object()
415   {
416     $this->DivListConference->save_object();
417   }
419   function remove_lock()
420   {
421     if (isset($this->dn)){
422       del_lock ($this->dn);
423     }
424   }
427   function list_get_selected_items()
428   {
429     $ids = array();
430     foreach($_POST as $name => $value){
431       if(preg_match("/^item_selected_[0-9]*$/",$name)){
432         $id   = preg_replace("/^item_selected_/","",$name);
433         $ids[$id] = $id;
434       }
435     }
436     return($ids);
437   }
441 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
442 ?>