Code

abf3a2b4b1ff10057829f6f5c3be146bbc3ef4ea
[gosa.git] / gosa-plugins / gofon / 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  */
21 class phoneConferenceManagment extends plugin
22 {
23   /* Definitions */
24   var $plHeadline                                 = "Phone conferences";
25   var $plDescription                    = "Management";
27   /* attribute list for save action */
28   var $attributes                                 = array();
29   var $objectclasses                    = array();
31   var $conferences                        = array();
32   var $conftab            = false;
33   var $ui                 = NULL;
34   var $DivListConference  = NULL;
36   var $CopyPasteHandler = NULL;
37   var $start_pasting_copied_objects = FALSE;
39   /* Initialise Class */
40   function phoneConferenceManagment (&$config, $ui)
41   {
42     $this->ui                     = $ui;
43     $this->dn                     = "";
44     $this->config               = $config;
45     $this->DivListConference = new divListConference($this->config,$this);
47     /* Copy & Paste enabled ?*/
48     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
49       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
50     }
51   }
54   /* Execute class and display something */
55   function execute()
56   {
57     /* Call parent execute */
58     plugin::execute();
60     session::set('LOCK_VARS_TO_USE',array("/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/"));
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("/^conference_new.*/i",$key)){
79         $s_action = "new";
80         // Post for delete
81       }elseif(preg_match("/^conference_del.*/",$key)){
82         $s_action = "del";
83         $s_entry  = preg_replace("/^conference_del_/i","",$key);
84         $s_entry  = preg_replace("/_.*$/","",$s_entry);
85         // Post for edit
86       }elseif(preg_match("/conference_edit_.*/",$key)){
87         $s_action="edit";
88         $s_entry  = preg_replace("/conference_edit_/i","",$key);
89         $s_entry  = preg_replace("/_.*$/","",$s_entry);
90       }elseif(preg_match("/^remove_multiple_conferences/",$key)){
91         $s_action="del_multiple";
92       }elseif(preg_match("/^editPaste.*/i",$key)){
93         $s_action="editPaste";
94       }elseif(preg_match("/^copy_.*/",$key)){
95         $s_action="copy";
96         $s_entry  = preg_replace("/^copy_/i","",$key);
97         $s_entry  = preg_replace("/_.$/","",$s_entry);
98       }elseif(preg_match("/^cut_.*/",$key)){
99         $s_action="cut";
100         $s_entry  = preg_replace("/^cut_/i","",$key);
101         $s_entry  = preg_replace("/_.$/","",$s_entry);
102       }elseif(preg_match("/^multiple_copy_objects/",$key)){
103         $s_action = "copy_multiple";
104       }elseif(preg_match("/^multiple_cut_objects/",$key)){
105         $s_action = "cut_multiple";
106       } 
107     }
109     /* Edit Entry */
110     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
111       $s_action = "edit";
112       $s_entry  = $_GET['id'];
113     }
115     /* handle C&P from layers menu */
116     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
117       $s_action = "copy_multiple";
118     }
119     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
120       $s_action = "cut_multiple";
121     }
122     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
123       $s_action = "editPaste";
124     }
126     /* Create options */
127     if(isset($_POST['menu_action']) && $_POST['menu_action'] == "conference_new"){
128       $s_action = "new";
129     }
131     /* handle remove from layers menu */
132     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
133       $s_action = "del_multiple";
134     }
137     /***************
138       Cancel dialogs 
139      ***************/
140   
141     /* Reset requested? */
142     if (isset($_POST['edit_cancel'])){
143       if (isset($this->conftab)){
144         del_lock ($this->conftab->dn);
145         unset ($this->conftab);
146       }
147       $this->conftab= NULL;
148       $this->lognames= array();;
149       $this->cn= "";
150       session::un_set('objectinfo');
151     }
154     /********************
155       Copy & Paste Handling  ...
156      ********************/
158     /* Display the copy & paste dialog, if it is currently open */
159     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
160     if($ret){
161       return($ret);
162     }
165     /********************
166       Delete MULTIPLE entries requested, display confirm dialog
167      ********************/
169     if ($s_action=="del_multiple"){
170       $ids = $this->list_get_selected_items();
172       if(count($ids)){
174         foreach($ids as $id){
175           $dn = $this->conferences[$id]['dn'];
176           if (($user= get_lock($dn)) != ""){
177             return(gen_locked_message ($user, $dn));
178           }
179           $this->dns[$id] = $dn;
180         }
182         $dns_names = array();
183         foreach($this->dns as $dn){
184           add_lock ($dn, $this->ui->dn);
185           $dns_names[] = @LDAP::fix($dn);
186         }
188         /* Lock the current entry, so nobody will edit it during deletion */
189         $smarty->assign("info", msgPool::deleteInfo($dns_names,_("conference")));
190         $smarty->assign("multiple", true);
191         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
192       }
193     }
196     /********************
197       Delete MULTIPLE entries confirmed
198      ********************/
200     /* Confirmation for deletion has been passed. Users should be deleted. */
201     if (isset($_POST['delete_multiple_conference_confirm'])){
203       /* Remove user by user and check acls before removeing them */
204       foreach($this->dns as $key => $dn){
205         $this->dn = $dn;
206         $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
207         if(preg_match("/d/",$acl)){
208           $this->remove_from_parent();
209         } else {
210           msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
211         }
212         /* Remove lock file after successfull deletion */
213         del_lock ($dn);
214         unset($this->dns[$key]);
215       }
216     }
219     /********************
220       Delete MULTIPLE entries Canceled
221      ********************/
223     /* Remove lock */
224     if(isset($_POST['delete_multiple_conference_cancel'])){
225       foreach($this->dns as $key => $dn){
226         del_lock ($dn);
227         unset($this->dns[$key]);
228       }
229     }
232     /***************
233       Delete 
234      ***************/
235   
236     /* Delete Entry if Posted action (s_action) == del
237      * The entry which will be deleted is defined in $s_entry
238      */
239     if ($s_action =="del"){
241       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
242       if(preg_match("/d/",$acl)){
243         $this->dn= $this->conferences[$s_entry]['dn'];
245         /* Check locking */
246         if (($conf= get_lock($this->dn)) != ""){
247           session::set('dn',$this->dn);
248           return(gen_locked_message($conf, $this->dn));
249         } else {
250           add_lock ($this->dn, $this->ui->dn);
251           $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("conference")));
252           $smarty->assign("multiple", false);
253           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
254           return ($display);
255         }
256       }
257     }
260     /***************
261       Delete confirmed  
262      ***************/
263   
264     /* If department deletion is accepted ...
265      * Finally delete department
266      */
267     if (isset($_POST['delete_department_confirm'])){
268       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
269       if(preg_match("/d/",$acl)){
270         $this->remove_from_parent();
271       } else {
272         msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
273       }
274     }
277     /***************
278       Edit
279      ***************/
280   
281     /* Edit Entry if Posted action (s_action) == edit
282      * The entry which will be edited is defined in $s_entry
283      */
284     if (($s_action=="edit") && (!isset($this->conftab->config))){
286       $this->dn= $this->conferences[$s_entry]['dn'];
288       if (($conf= get_lock($this->dn)) != ""){
289         return(gen_locked_message ($conf, $this->dn));
290       }
292       /* Lock the current entry, so everyone will get the  above dialog */
293       add_lock ($this->dn, $this->ui->dn);
295       /* Register conftab to trigger edit dialog */
296       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
297       $this->conftab->set_acl_base($this->dn);
298       session::set('objectinfo',$this->dn);
299     }
302     /***************
303       Create new  
304      ***************/
305   
306     /* Insert new entry*/    
307     if($s_action == "new" ){
309       $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase;      
310       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
311       if(preg_match("/c/",$acl)){
312         /* Set up the users ACL's for this 'dn' */
313         $this->dn= "new";
314         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
315         $this->conftab->set_acl_base($dummy_dn);
316         session::un_set('objectinfo');
317       }
318     }
321     /***************
322       Save entry  
323      ***************/
324   
325     /* Edit finished, check and save changes */
326     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
327       /* Check tabs, will feed message array */
328       $this->conftab->last= $this->conftab->current;
329       $this->conftab->save_object();
330       $message= $this->conftab->check();
332       if (count($message) == 0){
333         if($this->conftab->save() == 1){
334           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
335           return;
336         }
337         gosa_log ("goFonConference object '".$this->dn."' has been saved");
339         if (!isset($_POST['edit_apply'])){
340           if ($this->dn != "new"){
341             del_lock ($this->dn);
342           }
343         }
345         del_lock ($this->conftab->dn);;
346         unset ($this->conftab);
347         $this->conftab= NULL;
348         session::un_set('objectinfo');
349       } else {
350         msg_dialog::displayChecks($message);
351       }
352     }
355     /***************
356       Display dialogs   
357      ***************/
358   
359     /* if edit or new, show dialog */
360     if(($this->conftab) && (isset($this->conftab->config))){
361       $display= $this->conftab->execute();
363       /* Don't show buttons if tab dialog requests this */
364       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
365         $display.= "<p style=\"text-align:right\">\n";
366         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
367         $display.= "&nbsp;\n";
368         if ($this->dn != "new"){
369           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
370           $display.= "&nbsp;\n";
371         }
372         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
373         $display.= "</p>";
374       }
375       return ($display);
376     }
379     /***************
380       display divlist
381      ***************/
383     /* Check if there is a snapshot dialog open */
384     $base = $this->DivListConference->selectedBase;
385     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
386       return($str);
387     }
389     /* Return rendered main page */
390     /* Display dialog with system list */
391     $this->DivListConference->parent = $this;
392     $this->DivListConference->execute();
394     /* Add departments if subsearch is disabled */
395     if(!$this->DivListConference->SubSearch){
396       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
397     }
398     $this->reload();
399     $this->DivListConference->setEntries($this->conferences);
400     return($this->DivListConference->Draw());
401   }
404   /* Return departments, that will be included within snapshot detection */
405   function get_used_snapshot_bases()
406   {
407     return(array(get_ou('conferenceou').$this->DivListConference->selectedBase));
408   }
411   /* Reload entries for divlist.
412    * reload all conferences for the current base, with the given regex
413    */
414   function reload()
415   {
416     $Base             = get_ou('conferenceou').$this->DivListConference->selectedBase;
417     $SubSearch        = $this->DivListConference->SubSearch;
418     $Regex            = $this->DivListConference->Regex;
419     $Flags            = GL_SIZELIMIT ; 
420     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
421     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
422  
423     if($SubSearch){
424       $Flags |= GL_SUBSEARCH;
425     }
427     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
428   }
430   function remove_from_parent()
431   {
432     /* Ehm what are we doinf here ? */
433   
434     $cfg = new conference($this->config, $this->dn);
435     $cfg->set_acl_category("gofonconference");
436     $cfg->set_acl_base($this->dn);
438     $cfg->remove_from_parent();
439     $ldap= $this->config->get_ldap_link();
440     $ldap->cd ($this->dn);
441     $ldap->recursive_remove();
443     /* Optionally execute a command after we're done */
444     $this->postremove();
446     /* Delete references to object groups */
447     $ldap->cd ($this->config->current['BASE']);
448     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
449     while ($ldap->fetch()){
450       $og= new conftab($this->config, $ldap->getDN());
451       unset($og->member[$this->dn]);
452       $og->save ();
453     }
455   }
458   function copyPasteHandling_from_queue($s_action,$s_entry)
459   {
460     /* Check if Copy & Paste is disabled */
461     if(!is_object($this->CopyPasteHandler)){
462       return("");
463     }
465     /* Add a single entry to queue */
466     if($s_action == "cut" || $s_action == "copy"){
468       /* Cleanup object queue */
469       $this->CopyPasteHandler->cleanup_queue();
470       $dn = $this->conferences[$s_entry]['dn'];
471       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
472     }
474     /* Add entries to queue */
475     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
477       /* Cleanup object queue */
478       $this->CopyPasteHandler->cleanup_queue();
480       /* Add new entries to CP queue */
481       foreach($this->list_get_selected_items() as $id){
482         $dn = $this->conferences[$id]['dn'];
484         if($s_action == "copy_multiple"){
485           $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
486         }
487         if($s_action == "cut_multiple"){
488           $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
489         }
490       }
491     }
493     /* Start pasting entries */
494     if($s_action == "editPaste"){
495       $this->start_pasting_copied_objects = TRUE;
496     }
497     /* Return C&P dialog */
498     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
500       /* Get dialog */
501       $data = $this->CopyPasteHandler->execute();
502       $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
504       /* Return dialog data */
505       if(!empty($data)){
506         return($data);
507       }
508     }
510     /* Automatically disable status for pasting */
511     if(!$this->CopyPasteHandler->entries_queued()){
512       $this->start_pasting_copied_objects = FALSE;
513     }
514     return("");
515   }
518   function save_object()
519   {
520     $this->DivListConference->save_object();
521   }
523   function remove_lock()
524   {
525     if (isset($this->dn)){
526       del_lock ($this->dn);
527     }
528   }
531   function list_get_selected_items()
532   {
533     $ids = array();
534     foreach($_POST as $name => $value){
535       if(preg_match("/^item_selected_[0-9]*$/",$name)){
536         $id   = preg_replace("/^item_selected_/","",$name);
537         $ids[$id] = $id;
538       }
539     }
540     return($ids);
541   }
545 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
546 ?>