Code

Added a first set of reference changes - nearly untested
[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   var $CopyPasteHandler = NULL;
43   var $start_pasting_copied_objects = FALSE;
45   /* Initialise Class */
46   function phoneConferenceManagment (&$config, $ui)
47   {
48     $this->ui                     = $ui;
49     $this->dn                     = "";
50     $this->config               = $config;
51     $this->DivListConference = new divListConference($this->config,$this);
53     /* Copy & Paste enabled ?*/
54     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
55       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
56     }
57   }
60   /* Execute class and display something */
61   function execute()
62   {
63     /* Call parent execute */
64     plugin::execute();
66     $_SESSION['LOCK_VARS_TO_USE'] = array("/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/");
68     /***************
69       Variable initialisation
70      ***************/
71   
72     /* Reload departments */
73     $smarty                                                       = get_smarty();
74     $display                                              = "";
75     $s_action                                           = "";  // Will contain an action, like del or edit
76     $s_entry                                            = "";  // The entry name for edit delete -...
79     /***************
80       Check posts  
81      ***************/
82   
83     foreach($_POST as $key => $post){
84       if(preg_match("/^conference_new.*/i",$key)){
85         $s_action = "new";
86         // Post for delete
87       }elseif(preg_match("/^conference_del.*/",$key)){
88         $s_action = "del";
89         $s_entry  = preg_replace("/^conference_del_/i","",$key);
90         $s_entry  = preg_replace("/_.*$/","",$s_entry);
91         // Post for edit
92       }elseif(preg_match("/conference_edit_.*/",$key)){
93         $s_action="edit";
94         $s_entry  = preg_replace("/conference_edit_/i","",$key);
95         $s_entry  = preg_replace("/_.*$/","",$s_entry);
96       }elseif(preg_match("/^remove_multiple_conferences/",$key)){
97         $s_action="del_multiple";
98       }elseif(preg_match("/^editPaste.*/i",$key)){
99         $s_action="editPaste";
100       }elseif(preg_match("/^copy_.*/",$key)){
101         $s_action="copy";
102         $s_entry  = preg_replace("/^copy_/i","",$key);
103         $s_entry  = preg_replace("/_.$/","",$s_entry);
104       }elseif(preg_match("/^cut_.*/",$key)){
105         $s_action="cut";
106         $s_entry  = preg_replace("/^cut_/i","",$key);
107         $s_entry  = preg_replace("/_.$/","",$s_entry);
108       }elseif(preg_match("/^multiple_copy_objects/",$key)){
109         $s_action = "copy_multiple";
110       }elseif(preg_match("/^multiple_cut_objects/",$key)){
111         $s_action = "cut_multiple";
112       } 
113     }
115     /* Edit Entry */
116     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
117       $s_action = "edit";
118       $s_entry  = $_GET['id'];
119     }
122     /***************
123       Cancel dialogs 
124      ***************/
125   
126     /* Reset requested? */
127     if (isset($_POST['edit_cancel'])){
128       if (isset($this->conftab)){
129         del_lock ($this->conftab->dn);
130         unset ($this->conftab);
131       }
132       $this->conftab= NULL;
133       $this->lognames= array();;
134       $this->cn= "";
135       unset ($_SESSION['objectinfo']);
136     }
139     /********************
140       Copy & Paste Handling  ...
141      ********************/
143     /* Display the copy & paste dialog, if it is currently open */
144     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
145     if($ret){
146       return($ret);
147     }
150     /********************
151       Delete MULTIPLE entries requested, display confirm dialog
152      ********************/
154     if ($s_action=="del_multiple"){
155       $ids = $this->list_get_selected_items();
157       if(count($ids)){
159         foreach($ids as $id){
160           $dn = $this->conferences[$id]['dn'];
161           if (($user= get_lock($dn)) != ""){
162             return(gen_locked_message ($user, $dn));
163           }
164           $this->dns[$id] = $dn;
165         }
167         $dns_names = "<br><pre>";
168         foreach($this->dns as $dn){
169           add_lock ($dn, $this->ui->dn);
170           $dns_names .= $dn."\n";
171         }
172         $dns_names .="</pre>";
174         /* Lock the current entry, so nobody will edit it during deletion */
175         $smarty->assign("info",     sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names)));
176         $smarty->assign("multiple", true);
177         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
178       }
179     }
182     /********************
183       Delete MULTIPLE entries confirmed
184      ********************/
186     /* Confirmation for deletion has been passed. Users should be deleted. */
187     if (isset($_POST['delete_multiple_conference_confirm'])){
189       /* Remove user by user and check acls before removeing them */
190       foreach($this->dns as $key => $dn){
191         $this->dn = $dn;
192         $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
193         if(preg_match("/d/",$acl)){
194           $this->remove_from_parent();
195         } else {
196           print_red (_("You have no permission to remove this department."));
197         }
198         /* Remove lock file after successfull deletion */
199         del_lock ($dn);
200         unset($this->dns[$key]);
201       }
202     }
205     /********************
206       Delete MULTIPLE entries Canceled
207      ********************/
209     /* Remove lock */
210     if(isset($_POST['delete_multiple_conference_cancel'])){
211       foreach($this->dns as $key => $dn){
212         del_lock ($dn);
213         unset($this->dns[$key]);
214       }
215     }
218     /***************
219       Delete 
220      ***************/
221   
222     /* Delete Entry if Posted action (s_action) == del
223      * The entry which will be deleted is defined in $s_entry
224      */
225     if ($s_action =="del"){
227       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
228       if(preg_match("/d/",$acl)){
229         $this->dn= $this->conferences[$s_entry]['dn'];
231         /* Check locking */
232         if (($conf= get_lock($this->dn)) != ""){
233           $_SESSION['dn']= $this->dn;
234           return(gen_locked_message($conf, $this->dn));
235         } else {
236           add_lock ($this->dn, $this->ui->dn);
237           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
238           $smarty->assign("multiple", false);
239           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
240           return ($display);
241         }
242       }
243     }
246     /***************
247       Delete confirmed  
248      ***************/
249   
250     /* If department deletion is accepted ...
251      * Finally delete department
252      */
253     if (isset($_POST['delete_department_confirm'])){
254       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
255       if(preg_match("/d/",$acl)){
256         $this->remove_from_parent();
257       } else {
258         print_red (_("You have no permission to remove this department."));
259       }
260     }
263     /***************
264       Edit
265      ***************/
266   
267     /* Edit Entry if Posted action (s_action) == edit
268      * The entry which will be edited is defined in $s_entry
269      */
270     if (($s_action=="edit") && (!isset($this->conftab->config))){
272       $this->dn= $this->conferences[$s_entry]['dn'];
274       if (($conf= get_lock($this->dn)) != ""){
275         return(gen_locked_message ($conf, $this->dn));
276       }
278       /* Lock the current entry, so everyone will get the  above dialog */
279       add_lock ($this->dn, $this->ui->dn);
281       /* Register conftab to trigger edit dialog */
282       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
283       $this->conftab->set_acl_base($this->dn);
284       $_SESSION['objectinfo']= $this->dn;
285     }
288     /***************
289       Create new  
290      ***************/
291   
292     /* Insert new entry*/    
293     if($s_action == "new" ){
295       $dummy_dn = "cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;      
296       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
297       if(preg_match("/c/",$acl)){
298         /* Set up the users ACL's for this 'dn' */
299         $this->dn= "new";
300         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
301         $this->conftab->set_acl_base($dummy_dn);
302         unset($_SESSION['objectinfo']);
303       }
304     }
307     /***************
308       Save entry  
309      ***************/
310   
311     /* Edit finished, check and save changes */
312     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
313       /* Check tabs, will feed message array */
314       $this->conftab->last= $this->conftab->current;
315       $this->conftab->save_object();
316       $message= $this->conftab->check();
318       if (count($message) == 0){
319         if($this->conftab->save() == 1){
320           return;
321         }
323         if (!isset($_POST['edit_apply'])){
324           if ($this->dn != "new"){
325             del_lock ($this->dn);
326           }
327         }
329         $this->conftab->save ();
330         del_lock ($this->conftab->dn);;
331         unset ($this->conftab);
332         $this->conftab= NULL;
333         unset ($_SESSION['objectinfo']);
334       } else {
335         show_errors($message);
336       }
337     }
340     /***************
341       Display dialogs   
342      ***************/
343   
344     /* if edit or new, show dialog */
345     if(($this->conftab) && (isset($this->conftab->config))){
346       $display= $this->conftab->execute();
348       /* Don't show buttons if tab dialog requests this */
349       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
350         $display.= "<p style=\"text-align:right\">\n";
351         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
352         $display.= "&nbsp;\n";
353         if ($this->dn != "new"){
354           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
355           $display.= "&nbsp;\n";
356         }
357         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
358         $display.= "</p>";
359       }
360       return ($display);
361     }
364     /***************
365       display divlist
366      ***************/
368     /* Check if there is a snapshot dialog open */
369     $base = $this->DivListConference->selectedBase;
370     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
371       return($str);
372     }
374     /* Return rendered main page */
375     /* Display dialog with system list */
376     $this->DivListConference->parent = $this;
377     $this->DivListConference->execute();
379     /* Add departments if subsearch is disabled */
380     if(!$this->DivListConference->SubSearch){
381       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
382     }
383     $this->reload();
384     $this->DivListConference->setEntries($this->conferences);
385     return($this->DivListConference->Draw());
386   }
389   /* Return departments, that will be included within snapshot detection */
390   function get_used_snapshot_bases()
391   {
392     return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
393   }
396   /* Reload entries for divlist.
397    * reload all conferences for the current base, with the given regex
398    */
399   function reload()
400   {
401     $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
402     $SubSearch        = $this->DivListConference->SubSearch;
403     $Regex            = $this->DivListConference->Regex;
404     $Flags            = GL_SIZELIMIT ; 
405     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
406     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
407  
408     if($SubSearch){
409       $Flags |= GL_SUBSEARCH;
410     }
412     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
413   }
415   function remove_from_parent()
416   {
417     /* Ehm what are we doinf here ? */
418   
419     $cfg = new conference($this->config, $this->dn);
420     $cfg->set_acl_category("gofonconference");
421     $cfg->set_acl_base($this->dn);
423     $cfg->remove_from_parent();
424     $ldap= $this->config->get_ldap_link();
425     $ldap->cd ($this->dn);
426     $ldap->recursive_remove();
428     /* Optionally execute a command after we're done */
429     $this->postremove();
431     /* Delete references to object groups */
432     $ldap->cd ($this->config->current['BASE']);
433     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
434     while ($ldap->fetch()){
435       $og= new conftab($this->config, $ldap->getDN());
436       unset($og->member[$this->dn]);
437       $og->save ();
438     }
440   }
443   function copyPasteHandling_from_queue($s_action,$s_entry)
444   {
445     /* Check if Copy & Paste is disabled */
446     if(!is_object($this->CopyPasteHandler)){
447       return("");
448     }
450     /* Add a single entry to queue */
451     if($s_action == "cut" || $s_action == "copy"){
453       /* Cleanup object queue */
454       $this->CopyPasteHandler->cleanup_queue();
455       $dn = $this->conferences[$s_entry]['dn'];
456       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
457     }
459     /* Add entries to queue */
460     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
462       /* Cleanup object queue */
463       $this->CopyPasteHandler->cleanup_queue();
465       /* Add new entries to CP queue */
466       foreach($this->list_get_selected_items() as $id){
467         $dn = $this->conferences[$id]['dn'];
469         if($s_action == "copy_multiple"){
470           $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
471         }
472         if($s_action == "cut_multiple"){
473           $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
474         }
475       }
476     }
478     /* Start pasting entries */
479     if($s_action == "editPaste"){
480       $this->start_pasting_copied_objects = TRUE;
481     }
482     /* Return C&P dialog */
483     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
485       /* Load entry from queue and set base */
486       $this->CopyPasteHandler->load_entry_from_queue();
487       $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
489       /* Get dialog */
490       $data = $this->CopyPasteHandler->execute();
492       /* Return dialog data */
493       if(!empty($data)){
494         return($data);
495       }
496     }
498     /* Automatically disable status for pasting */
499     if(!$this->CopyPasteHandler->entries_queued()){
500       $this->start_pasting_copied_objects = FALSE;
501     }
502     return("");
503   }
506   function save_object()
507   {
508     $this->DivListConference->save_object();
509   }
511   function remove_lock()
512   {
513     if (isset($this->dn)){
514       del_lock ($this->dn);
515     }
516   }
519   function list_get_selected_items()
520   {
521     $ids = array();
522     foreach($_POST as $name => $value){
523       if(preg_match("/^item_selected_[0-9]*$/",$name)){
524         $id   = preg_replace("/^item_selected_/","",$name);
525         $ids[$id] = $id;
526       }
527     }
528     return($ids);
529   }
533 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
534 ?>