Code

Updated share checks to allow umlauts
[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  */
21 class phoneConferenceManagment extends plugin
22 {
23   /* Definitions */
24   var $plHeadline                                 = "Phone conferences";
25   var $plDescription                    = "Management";
27   /* CLI vars */
28   var $cli_summary                        = "Handling of LDAP subtrees";
29   var $cli_description          = "Some longer text\nfor help";
30   var $cli_parameters                   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
32   /* attribute list for save action */
33   var $attributes                                 = array();
34   var $objectclasses                    = array();
36   var $conferences                        = array();
37   var $conftab            = false;
38   var $ui                 = NULL;
39   var $DivListConference  = NULL;
41   var $CopyPasteHandler = NULL;
42   var $start_pasting_copied_objects = FALSE;
44   /* Initialise Class */
45   function phoneConferenceManagment (&$config, $ui)
46   {
47     $this->ui                     = $ui;
48     $this->dn                     = "";
49     $this->config               = $config;
50     $this->DivListConference = new divListConference($this->config,$this);
52     /* Copy & Paste enabled ?*/
53     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
54       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
55     }
56   }
59   /* Execute class and display something */
60   function execute()
61   {
62     /* Call parent execute */
63     plugin::execute();
65     $_SESSION['LOCK_VARS_TO_USE'] = array("/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/");
67     /***************
68       Variable initialisation
69      ***************/
70   
71     /* Reload departments */
72     $smarty                                                       = get_smarty();
73     $display                                              = "";
74     $s_action                                           = "";  // Will contain an action, like del or edit
75     $s_entry                                            = "";  // The entry name for edit delete -...
78     /***************
79       Check posts  
80      ***************/
81   
82     foreach($_POST as $key => $post){
83       if(preg_match("/^conference_new.*/i",$key)){
84         $s_action = "new";
85         // Post for delete
86       }elseif(preg_match("/^conference_del.*/",$key)){
87         $s_action = "del";
88         $s_entry  = preg_replace("/^conference_del_/i","",$key);
89         $s_entry  = preg_replace("/_.*$/","",$s_entry);
90         // Post for edit
91       }elseif(preg_match("/conference_edit_.*/",$key)){
92         $s_action="edit";
93         $s_entry  = preg_replace("/conference_edit_/i","",$key);
94         $s_entry  = preg_replace("/_.*$/","",$s_entry);
95       }elseif(preg_match("/^remove_multiple_conferences/",$key)){
96         $s_action="del_multiple";
97       }elseif(preg_match("/^editPaste.*/i",$key)){
98         $s_action="editPaste";
99       }elseif(preg_match("/^copy_.*/",$key)){
100         $s_action="copy";
101         $s_entry  = preg_replace("/^copy_/i","",$key);
102         $s_entry  = preg_replace("/_.$/","",$s_entry);
103       }elseif(preg_match("/^cut_.*/",$key)){
104         $s_action="cut";
105         $s_entry  = preg_replace("/^cut_/i","",$key);
106         $s_entry  = preg_replace("/_.$/","",$s_entry);
107       }elseif(preg_match("/^multiple_copy_objects/",$key)){
108         $s_action = "copy_multiple";
109       }elseif(preg_match("/^multiple_cut_objects/",$key)){
110         $s_action = "cut_multiple";
111       } 
112     }
114     /* Edit Entry */
115     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
116       $s_action = "edit";
117       $s_entry  = $_GET['id'];
118     }
121     /***************
122       Cancel dialogs 
123      ***************/
124   
125     /* Reset requested? */
126     if (isset($_POST['edit_cancel'])){
127       if (isset($this->conftab)){
128         del_lock ($this->conftab->dn);
129         unset ($this->conftab);
130       }
131       $this->conftab= NULL;
132       $this->lognames= array();;
133       $this->cn= "";
134       unset ($_SESSION['objectinfo']);
135     }
138     /********************
139       Copy & Paste Handling  ...
140      ********************/
142     /* Display the copy & paste dialog, if it is currently open */
143     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
144     if($ret){
145       return($ret);
146     }
149     /********************
150       Delete MULTIPLE entries requested, display confirm dialog
151      ********************/
153     if ($s_action=="del_multiple"){
154       $ids = $this->list_get_selected_items();
156       if(count($ids)){
158         foreach($ids as $id){
159           $dn = $this->conferences[$id]['dn'];
160           if (($user= get_lock($dn)) != ""){
161             return(gen_locked_message ($user, $dn));
162           }
163           $this->dns[$id] = $dn;
164         }
166         $dns_names = "<br><pre>";
167         foreach($this->dns as $dn){
168           add_lock ($dn, $this->ui->dn);
169           $dns_names .= $dn."\n";
170         }
171         $dns_names .="</pre>";
173         /* Lock the current entry, so nobody will edit it during deletion */
174         $smarty->assign("info",     sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names)));
175         $smarty->assign("multiple", true);
176         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
177       }
178     }
181     /********************
182       Delete MULTIPLE entries confirmed
183      ********************/
185     /* Confirmation for deletion has been passed. Users should be deleted. */
186     if (isset($_POST['delete_multiple_conference_confirm'])){
188       /* Remove user by user and check acls before removeing them */
189       foreach($this->dns as $key => $dn){
190         $this->dn = $dn;
191         $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
192         if(preg_match("/d/",$acl)){
193           $this->remove_from_parent();
194         } else {
195           print_red (_("You have no permission to remove this department."));
196         }
197         /* Remove lock file after successfull deletion */
198         del_lock ($dn);
199         unset($this->dns[$key]);
200       }
201     }
204     /********************
205       Delete MULTIPLE entries Canceled
206      ********************/
208     /* Remove lock */
209     if(isset($_POST['delete_multiple_conference_cancel'])){
210       foreach($this->dns as $key => $dn){
211         del_lock ($dn);
212         unset($this->dns[$key]);
213       }
214     }
217     /***************
218       Delete 
219      ***************/
220   
221     /* Delete Entry if Posted action (s_action) == del
222      * The entry which will be deleted is defined in $s_entry
223      */
224     if ($s_action =="del"){
226       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
227       if(preg_match("/d/",$acl)){
228         $this->dn= $this->conferences[$s_entry]['dn'];
230         /* Check locking */
231         if (($conf= get_lock($this->dn)) != ""){
232           $_SESSION['dn']= $this->dn;
233           return(gen_locked_message($conf, $this->dn));
234         } else {
235           add_lock ($this->dn, $this->ui->dn);
236           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
237           $smarty->assign("multiple", false);
238           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
239           return ($display);
240         }
241       }
242     }
245     /***************
246       Delete confirmed  
247      ***************/
248   
249     /* If department deletion is accepted ...
250      * Finally delete department
251      */
252     if (isset($_POST['delete_department_confirm'])){
253       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
254       if(preg_match("/d/",$acl)){
255         $this->remove_from_parent();
256       } else {
257         print_red (_("You have no permission to remove this department."));
258       }
259     }
262     /***************
263       Edit
264      ***************/
265   
266     /* Edit Entry if Posted action (s_action) == edit
267      * The entry which will be edited is defined in $s_entry
268      */
269     if (($s_action=="edit") && (!isset($this->conftab->config))){
271       $this->dn= $this->conferences[$s_entry]['dn'];
273       if (($conf= get_lock($this->dn)) != ""){
274         return(gen_locked_message ($conf, $this->dn));
275       }
277       /* Lock the current entry, so everyone will get the  above dialog */
278       add_lock ($this->dn, $this->ui->dn);
280       /* Register conftab to trigger edit dialog */
281       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
282       $this->conftab->set_acl_base($this->dn);
283       $_SESSION['objectinfo']= $this->dn;
284     }
287     /***************
288       Create new  
289      ***************/
290   
291     /* Insert new entry*/    
292     if($s_action == "new" ){
294       $dummy_dn = "cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;      
295       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
296       if(preg_match("/c/",$acl)){
297         /* Set up the users ACL's for this 'dn' */
298         $this->dn= "new";
299         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
300         $this->conftab->set_acl_base($dummy_dn);
301         unset($_SESSION['objectinfo']);
302       }
303     }
306     /***************
307       Save entry  
308      ***************/
309   
310     /* Edit finished, check and save changes */
311     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
312       /* Check tabs, will feed message array */
313       $this->conftab->last= $this->conftab->current;
314       $this->conftab->save_object();
315       $message= $this->conftab->check();
317       if (count($message) == 0){
318         if($this->conftab->save() == 1){
319           return;
320         }
322         if (!isset($_POST['edit_apply'])){
323           if ($this->dn != "new"){
324             del_lock ($this->dn);
325           }
326         }
328         $this->conftab->save ();
329         del_lock ($this->conftab->dn);;
330         unset ($this->conftab);
331         $this->conftab= NULL;
332         unset ($_SESSION['objectinfo']);
333       } else {
334         show_errors($message);
335       }
336     }
339     /***************
340       Display dialogs   
341      ***************/
342   
343     /* if edit or new, show dialog */
344     if(($this->conftab) && (isset($this->conftab->config))){
345       $display= $this->conftab->execute();
347       /* Don't show buttons if tab dialog requests this */
348       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
349         $display.= "<p style=\"text-align:right\">\n";
350         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
351         $display.= "&nbsp;\n";
352         if ($this->dn != "new"){
353           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
354           $display.= "&nbsp;\n";
355         }
356         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
357         $display.= "</p>";
358       }
359       return ($display);
360     }
363     /***************
364       display divlist
365      ***************/
367     /* Check if there is a snapshot dialog open */
368     $base = $this->DivListConference->selectedBase;
369     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
370       return($str);
371     }
373     /* Return rendered main page */
374     /* Display dialog with system list */
375     $this->DivListConference->parent = $this;
376     $this->DivListConference->execute();
378     /* Add departments if subsearch is disabled */
379     if(!$this->DivListConference->SubSearch){
380       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
381     }
382     $this->reload();
383     $this->DivListConference->setEntries($this->conferences);
384     return($this->DivListConference->Draw());
385   }
388   /* Return departments, that will be included within snapshot detection */
389   function get_used_snapshot_bases()
390   {
391     return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
392   }
395   /* Reload entries for divlist.
396    * reload all conferences for the current base, with the given regex
397    */
398   function reload()
399   {
400     $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
401     $SubSearch        = $this->DivListConference->SubSearch;
402     $Regex            = $this->DivListConference->Regex;
403     $Flags            = GL_SIZELIMIT ; 
404     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
405     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
406  
407     if($SubSearch){
408       $Flags |= GL_SUBSEARCH;
409     }
411     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
412   }
414   function remove_from_parent()
415   {
416     /* Ehm what are we doinf here ? */
417   
418     $cfg = new conference($this->config, $this->dn);
419     $cfg->set_acl_category("gofonconference");
420     $cfg->set_acl_base($this->dn);
422     $cfg->remove_from_parent();
423     $ldap= $this->config->get_ldap_link();
424     $ldap->cd ($this->dn);
425     $ldap->recursive_remove();
427     /* Optionally execute a command after we're done */
428     $this->postremove();
430     /* Delete references to object groups */
431     $ldap->cd ($this->config->current['BASE']);
432     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
433     while ($ldap->fetch()){
434       $og= new conftab($this->config, $ldap->getDN());
435       unset($og->member[$this->dn]);
436       $og->save ();
437     }
439   }
442   function copyPasteHandling_from_queue($s_action,$s_entry)
443   {
444     /* Check if Copy & Paste is disabled */
445     if(!is_object($this->CopyPasteHandler)){
446       return("");
447     }
449     /* Add a single entry to queue */
450     if($s_action == "cut" || $s_action == "copy"){
452       /* Cleanup object queue */
453       $this->CopyPasteHandler->cleanup_queue();
454       $dn = $this->conferences[$s_entry]['dn'];
455       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
456     }
458     /* Add entries to queue */
459     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
461       /* Cleanup object queue */
462       $this->CopyPasteHandler->cleanup_queue();
464       /* Add new entries to CP queue */
465       foreach($this->list_get_selected_items() as $id){
466         $dn = $this->conferences[$id]['dn'];
468         if($s_action == "copy_multiple"){
469           $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
470         }
471         if($s_action == "cut_multiple"){
472           $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
473         }
474       }
475     }
477     /* Start pasting entries */
478     if($s_action == "editPaste"){
479       $this->start_pasting_copied_objects = TRUE;
480     }
481     /* Return C&P dialog */
482     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
484       /* Load entry from queue and set base */
485       $this->CopyPasteHandler->load_entry_from_queue();
486       $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
488       /* Get dialog */
489       $data = $this->CopyPasteHandler->execute();
491       /* Return dialog data */
492       if(!empty($data)){
493         return($data);
494       }
495     }
497     /* Automatically disable status for pasting */
498     if(!$this->CopyPasteHandler->entries_queued()){
499       $this->start_pasting_copied_objects = FALSE;
500     }
501     return("");
502   }
505   function save_object()
506   {
507     $this->DivListConference->save_object();
508   }
510   function remove_lock()
511   {
512     if (isset($this->dn)){
513       del_lock ($this->dn);
514     }
515   }
518   function list_get_selected_items()
519   {
520     $ids = array();
521     foreach($_POST as $name => $value){
522       if(preg_match("/^item_selected_[0-9]*$/",$name)){
523         $id   = preg_replace("/^item_selected_/","",$name);
524         $ids[$id] = $id;
525       }
526     }
527     return($ids);
528   }
532 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
533 ?>