Code

Updated strings
[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 = "<br><pre>";
183         foreach($this->dns as $dn){
184           add_lock ($dn, $this->ui->dn);
185           $dns_names .= $dn."\n";
186         }
187         $dns_names .="</pre>";
189         /* Lock the current entry, so nobody will edit it during deletion */
190         $smarty->assign("info",     sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names)));
191         $smarty->assign("multiple", true);
192         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
193       }
194     }
197     /********************
198       Delete MULTIPLE entries confirmed
199      ********************/
201     /* Confirmation for deletion has been passed. Users should be deleted. */
202     if (isset($_POST['delete_multiple_conference_confirm'])){
204       /* Remove user by user and check acls before removeing them */
205       foreach($this->dns as $key => $dn){
206         $this->dn = $dn;
207         $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
208         if(preg_match("/d/",$acl)){
209           $this->remove_from_parent();
210         } else {
211           msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
212         }
213         /* Remove lock file after successfull deletion */
214         del_lock ($dn);
215         unset($this->dns[$key]);
216       }
217     }
220     /********************
221       Delete MULTIPLE entries Canceled
222      ********************/
224     /* Remove lock */
225     if(isset($_POST['delete_multiple_conference_cancel'])){
226       foreach($this->dns as $key => $dn){
227         del_lock ($dn);
228         unset($this->dns[$key]);
229       }
230     }
233     /***************
234       Delete 
235      ***************/
236   
237     /* Delete Entry if Posted action (s_action) == del
238      * The entry which will be deleted is defined in $s_entry
239      */
240     if ($s_action =="del"){
242       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
243       if(preg_match("/d/",$acl)){
244         $this->dn= $this->conferences[$s_entry]['dn'];
246         /* Check locking */
247         if (($conf= get_lock($this->dn)) != ""){
248           session::set('dn',$this->dn);
249           return(gen_locked_message($conf, $this->dn));
250         } else {
251           add_lock ($this->dn, $this->ui->dn);
252           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
253           $smarty->assign("multiple", false);
254           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
255           return ($display);
256         }
257       }
258     }
261     /***************
262       Delete confirmed  
263      ***************/
264   
265     /* If department deletion is accepted ...
266      * Finally delete department
267      */
268     if (isset($_POST['delete_department_confirm'])){
269       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
270       if(preg_match("/d/",$acl)){
271         $this->remove_from_parent();
272       } else {
273         msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
274       }
275     }
278     /***************
279       Edit
280      ***************/
281   
282     /* Edit Entry if Posted action (s_action) == edit
283      * The entry which will be edited is defined in $s_entry
284      */
285     if (($s_action=="edit") && (!isset($this->conftab->config))){
287       $this->dn= $this->conferences[$s_entry]['dn'];
289       if (($conf= get_lock($this->dn)) != ""){
290         return(gen_locked_message ($conf, $this->dn));
291       }
293       /* Lock the current entry, so everyone will get the  above dialog */
294       add_lock ($this->dn, $this->ui->dn);
296       /* Register conftab to trigger edit dialog */
297       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
298       $this->conftab->set_acl_base($this->dn);
299       session::set('objectinfo',$this->dn);
300     }
303     /***************
304       Create new  
305      ***************/
306   
307     /* Insert new entry*/    
308     if($s_action == "new" ){
310       $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase;      
311       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
312       if(preg_match("/c/",$acl)){
313         /* Set up the users ACL's for this 'dn' */
314         $this->dn= "new";
315         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
316         $this->conftab->set_acl_base($dummy_dn);
317         session::un_set('objectinfo');
318       }
319     }
322     /***************
323       Save entry  
324      ***************/
325   
326     /* Edit finished, check and save changes */
327     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
328       /* Check tabs, will feed message array */
329       $this->conftab->last= $this->conftab->current;
330       $this->conftab->save_object();
331       $message= $this->conftab->check();
333       if (count($message) == 0){
334         if($this->conftab->save() == 1){
335           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
336           return;
337         }
338         gosa_log ("goFonConference object '".$this->dn."' has been saved");
340         if (!isset($_POST['edit_apply'])){
341           if ($this->dn != "new"){
342             del_lock ($this->dn);
343           }
344         }
346         del_lock ($this->conftab->dn);;
347         unset ($this->conftab);
348         $this->conftab= NULL;
349         session::un_set('objectinfo');
350       } else {
351         msgDialog::displayChecks($message);
352       }
353     }
356     /***************
357       Display dialogs   
358      ***************/
359   
360     /* if edit or new, show dialog */
361     if(($this->conftab) && (isset($this->conftab->config))){
362       $display= $this->conftab->execute();
364       /* Don't show buttons if tab dialog requests this */
365       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
366         $display.= "<p style=\"text-align:right\">\n";
367         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
368         $display.= "&nbsp;\n";
369         if ($this->dn != "new"){
370           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
371           $display.= "&nbsp;\n";
372         }
373         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
374         $display.= "</p>";
375       }
376       return ($display);
377     }
380     /***************
381       display divlist
382      ***************/
384     /* Check if there is a snapshot dialog open */
385     $base = $this->DivListConference->selectedBase;
386     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
387       return($str);
388     }
390     /* Return rendered main page */
391     /* Display dialog with system list */
392     $this->DivListConference->parent = $this;
393     $this->DivListConference->execute();
395     /* Add departments if subsearch is disabled */
396     if(!$this->DivListConference->SubSearch){
397       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
398     }
399     $this->reload();
400     $this->DivListConference->setEntries($this->conferences);
401     return($this->DivListConference->Draw());
402   }
405   /* Return departments, that will be included within snapshot detection */
406   function get_used_snapshot_bases()
407   {
408     return(array(get_ou('conferenceou').$this->DivListConference->selectedBase));
409   }
412   /* Reload entries for divlist.
413    * reload all conferences for the current base, with the given regex
414    */
415   function reload()
416   {
417     $Base             = get_ou('conferenceou').$this->DivListConference->selectedBase;
418     $SubSearch        = $this->DivListConference->SubSearch;
419     $Regex            = $this->DivListConference->Regex;
420     $Flags            = GL_SIZELIMIT ; 
421     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
422     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
423  
424     if($SubSearch){
425       $Flags |= GL_SUBSEARCH;
426     }
428     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
429   }
431   function remove_from_parent()
432   {
433     /* Ehm what are we doinf here ? */
434   
435     $cfg = new conference($this->config, $this->dn);
436     $cfg->set_acl_category("gofonconference");
437     $cfg->set_acl_base($this->dn);
439     $cfg->remove_from_parent();
440     $ldap= $this->config->get_ldap_link();
441     $ldap->cd ($this->dn);
442     $ldap->recursive_remove();
444     /* Optionally execute a command after we're done */
445     $this->postremove();
447     /* Delete references to object groups */
448     $ldap->cd ($this->config->current['BASE']);
449     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
450     while ($ldap->fetch()){
451       $og= new conftab($this->config, $ldap->getDN());
452       unset($og->member[$this->dn]);
453       $og->save ();
454     }
456   }
459   function copyPasteHandling_from_queue($s_action,$s_entry)
460   {
461     /* Check if Copy & Paste is disabled */
462     if(!is_object($this->CopyPasteHandler)){
463       return("");
464     }
466     /* Add a single entry to queue */
467     if($s_action == "cut" || $s_action == "copy"){
469       /* Cleanup object queue */
470       $this->CopyPasteHandler->cleanup_queue();
471       $dn = $this->conferences[$s_entry]['dn'];
472       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
473     }
475     /* Add entries to queue */
476     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
478       /* Cleanup object queue */
479       $this->CopyPasteHandler->cleanup_queue();
481       /* Add new entries to CP queue */
482       foreach($this->list_get_selected_items() as $id){
483         $dn = $this->conferences[$id]['dn'];
485         if($s_action == "copy_multiple"){
486           $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
487         }
488         if($s_action == "cut_multiple"){
489           $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
490         }
491       }
492     }
494     /* Start pasting entries */
495     if($s_action == "editPaste"){
496       $this->start_pasting_copied_objects = TRUE;
497     }
498     /* Return C&P dialog */
499     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
501       /* Get dialog */
502       $data = $this->CopyPasteHandler->execute();
503       $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
505       /* Return dialog data */
506       if(!empty($data)){
507         return($data);
508       }
509     }
511     /* Automatically disable status for pasting */
512     if(!$this->CopyPasteHandler->entries_queued()){
513       $this->start_pasting_copied_objects = FALSE;
514     }
515     return("");
516   }
519   function save_object()
520   {
521     $this->DivListConference->save_object();
522   }
524   function remove_lock()
525   {
526     if (isset($this->dn)){
527       del_lock ($this->dn);
528     }
529   }
532   function list_get_selected_items()
533   {
534     $ids = array();
535     foreach($_POST as $name => $value){
536       if(preg_match("/^item_selected_[0-9]*$/",$name)){
537         $id   = preg_replace("/^item_selected_/","",$name);
538         $ids[$id] = $id;
539       }
540     }
541     return($ids);
542   }
546 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
547 ?>