Code

Updated print_red stuff
[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   /* 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::set('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     }
120     /* handle C&P from layers menu */
121     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
122       $s_action = "copy_multiple";
123     }
124     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
125       $s_action = "cut_multiple";
126     }
127     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
128       $s_action = "editPaste";
129     }
131     /* Create options */
132     if(isset($_POST['menu_action']) && $_POST['menu_action'] == "conference_new"){
133       $s_action = "new";
134     }
136     /* handle remove from layers menu */
137     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
138       $s_action = "del_multiple";
139     }
142     /***************
143       Cancel dialogs 
144      ***************/
145   
146     /* Reset requested? */
147     if (isset($_POST['edit_cancel'])){
148       if (isset($this->conftab)){
149         del_lock ($this->conftab->dn);
150         unset ($this->conftab);
151       }
152       $this->conftab= NULL;
153       $this->lognames= array();;
154       $this->cn= "";
155       session::un_set('objectinfo');
156     }
159     /********************
160       Copy & Paste Handling  ...
161      ********************/
163     /* Display the copy & paste dialog, if it is currently open */
164     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
165     if($ret){
166       return($ret);
167     }
170     /********************
171       Delete MULTIPLE entries requested, display confirm dialog
172      ********************/
174     if ($s_action=="del_multiple"){
175       $ids = $this->list_get_selected_items();
177       if(count($ids)){
179         foreach($ids as $id){
180           $dn = $this->conferences[$id]['dn'];
181           if (($user= get_lock($dn)) != ""){
182             return(gen_locked_message ($user, $dn));
183           }
184           $this->dns[$id] = $dn;
185         }
187         $dns_names = "<br><pre>";
188         foreach($this->dns as $dn){
189           add_lock ($dn, $this->ui->dn);
190           $dns_names .= $dn."\n";
191         }
192         $dns_names .="</pre>";
194         /* Lock the current entry, so nobody will edit it during deletion */
195         $smarty->assign("info",     sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names)));
196         $smarty->assign("multiple", true);
197         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
198       }
199     }
202     /********************
203       Delete MULTIPLE entries confirmed
204      ********************/
206     /* Confirmation for deletion has been passed. Users should be deleted. */
207     if (isset($_POST['delete_multiple_conference_confirm'])){
209       /* Remove user by user and check acls before removeing them */
210       foreach($this->dns as $key => $dn){
211         $this->dn = $dn;
212         $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
213         if(preg_match("/d/",$acl)){
214           $this->remove_from_parent();
215         } else {
216           msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
217         }
218         /* Remove lock file after successfull deletion */
219         del_lock ($dn);
220         unset($this->dns[$key]);
221       }
222     }
225     /********************
226       Delete MULTIPLE entries Canceled
227      ********************/
229     /* Remove lock */
230     if(isset($_POST['delete_multiple_conference_cancel'])){
231       foreach($this->dns as $key => $dn){
232         del_lock ($dn);
233         unset($this->dns[$key]);
234       }
235     }
238     /***************
239       Delete 
240      ***************/
241   
242     /* Delete Entry if Posted action (s_action) == del
243      * The entry which will be deleted is defined in $s_entry
244      */
245     if ($s_action =="del"){
247       $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); 
248       if(preg_match("/d/",$acl)){
249         $this->dn= $this->conferences[$s_entry]['dn'];
251         /* Check locking */
252         if (($conf= get_lock($this->dn)) != ""){
253           session::set('dn',$this->dn);
254           return(gen_locked_message($conf, $this->dn));
255         } else {
256           add_lock ($this->dn, $this->ui->dn);
257           $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
258           $smarty->assign("multiple", false);
259           $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
260           return ($display);
261         }
262       }
263     }
266     /***************
267       Delete confirmed  
268      ***************/
269   
270     /* If department deletion is accepted ...
271      * Finally delete department
272      */
273     if (isset($_POST['delete_department_confirm'])){
274       $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); 
275       if(preg_match("/d/",$acl)){
276         $this->remove_from_parent();
277       } else {
278         msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
279       }
280     }
283     /***************
284       Edit
285      ***************/
286   
287     /* Edit Entry if Posted action (s_action) == edit
288      * The entry which will be edited is defined in $s_entry
289      */
290     if (($s_action=="edit") && (!isset($this->conftab->config))){
292       $this->dn= $this->conferences[$s_entry]['dn'];
294       if (($conf= get_lock($this->dn)) != ""){
295         return(gen_locked_message ($conf, $this->dn));
296       }
298       /* Lock the current entry, so everyone will get the  above dialog */
299       add_lock ($this->dn, $this->ui->dn);
301       /* Register conftab to trigger edit dialog */
302       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
303       $this->conftab->set_acl_base($this->dn);
304       session::set('objectinfo',$this->dn);
305     }
308     /***************
309       Create new  
310      ***************/
311   
312     /* Insert new entry*/    
313     if($s_action == "new" ){
315       $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase;      
316       $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); 
317       if(preg_match("/c/",$acl)){
318         /* Set up the users ACL's for this 'dn' */
319         $this->dn= "new";
320         $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
321         $this->conftab->set_acl_base($dummy_dn);
322         session::un_set('objectinfo');
323       }
324     }
327     /***************
328       Save entry  
329      ***************/
330   
331     /* Edit finished, check and save changes */
332     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
333       /* Check tabs, will feed message array */
334       $this->conftab->last= $this->conftab->current;
335       $this->conftab->save_object();
336       $message= $this->conftab->check();
338       if (count($message) == 0){
339         if($this->conftab->save() == 1){
340           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
341           return;
342         }
343         gosa_log ("goFonConference object '".$this->dn."' has been saved");
345         if (!isset($_POST['edit_apply'])){
346           if ($this->dn != "new"){
347             del_lock ($this->dn);
348           }
349         }
351         del_lock ($this->conftab->dn);;
352         unset ($this->conftab);
353         $this->conftab= NULL;
354         session::un_set('objectinfo');
355       } else {
356         show_errors($message);
357       }
358     }
361     /***************
362       Display dialogs   
363      ***************/
364   
365     /* if edit or new, show dialog */
366     if(($this->conftab) && (isset($this->conftab->config))){
367       $display= $this->conftab->execute();
369       /* Don't show buttons if tab dialog requests this */
370       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
371         $display.= "<p style=\"text-align:right\">\n";
372         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
373         $display.= "&nbsp;\n";
374         if ($this->dn != "new"){
375           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
376           $display.= "&nbsp;\n";
377         }
378         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
379         $display.= "</p>";
380       }
381       return ($display);
382     }
385     /***************
386       display divlist
387      ***************/
389     /* Check if there is a snapshot dialog open */
390     $base = $this->DivListConference->selectedBase;
391     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
392       return($str);
393     }
395     /* Return rendered main page */
396     /* Display dialog with system list */
397     $this->DivListConference->parent = $this;
398     $this->DivListConference->execute();
400     /* Add departments if subsearch is disabled */
401     if(!$this->DivListConference->SubSearch){
402       $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
403     }
404     $this->reload();
405     $this->DivListConference->setEntries($this->conferences);
406     return($this->DivListConference->Draw());
407   }
410   /* Return departments, that will be included within snapshot detection */
411   function get_used_snapshot_bases()
412   {
413     return(array(get_ou('conferenceou').$this->DivListConference->selectedBase));
414   }
417   /* Reload entries for divlist.
418    * reload all conferences for the current base, with the given regex
419    */
420   function reload()
421   {
422     $Base             = get_ou('conferenceou').$this->DivListConference->selectedBase;
423     $SubSearch        = $this->DivListConference->SubSearch;
424     $Regex            = $this->DivListConference->Regex;
425     $Flags            = GL_SIZELIMIT ; 
426     $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
427     $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
428  
429     if($SubSearch){
430       $Flags |= GL_SUBSEARCH;
431     }
433     $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
434   }
436   function remove_from_parent()
437   {
438     /* Ehm what are we doinf here ? */
439   
440     $cfg = new conference($this->config, $this->dn);
441     $cfg->set_acl_category("gofonconference");
442     $cfg->set_acl_base($this->dn);
444     $cfg->remove_from_parent();
445     $ldap= $this->config->get_ldap_link();
446     $ldap->cd ($this->dn);
447     $ldap->recursive_remove();
449     /* Optionally execute a command after we're done */
450     $this->postremove();
452     /* Delete references to object groups */
453     $ldap->cd ($this->config->current['BASE']);
454     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
455     while ($ldap->fetch()){
456       $og= new conftab($this->config, $ldap->getDN());
457       unset($og->member[$this->dn]);
458       $og->save ();
459     }
461   }
464   function copyPasteHandling_from_queue($s_action,$s_entry)
465   {
466     /* Check if Copy & Paste is disabled */
467     if(!is_object($this->CopyPasteHandler)){
468       return("");
469     }
471     /* Add a single entry to queue */
472     if($s_action == "cut" || $s_action == "copy"){
474       /* Cleanup object queue */
475       $this->CopyPasteHandler->cleanup_queue();
476       $dn = $this->conferences[$s_entry]['dn'];
477       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
478     }
480     /* Add entries to queue */
481     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
483       /* Cleanup object queue */
484       $this->CopyPasteHandler->cleanup_queue();
486       /* Add new entries to CP queue */
487       foreach($this->list_get_selected_items() as $id){
488         $dn = $this->conferences[$id]['dn'];
490         if($s_action == "copy_multiple"){
491           $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
492         }
493         if($s_action == "cut_multiple"){
494           $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
495         }
496       }
497     }
499     /* Start pasting entries */
500     if($s_action == "editPaste"){
501       $this->start_pasting_copied_objects = TRUE;
502     }
503     /* Return C&P dialog */
504     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
506       /* Load entry from queue and set base */
507       $this->CopyPasteHandler->load_entry_from_queue();
508       $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
510       /* Get dialog */
511       $data = $this->CopyPasteHandler->execute();
513       /* Return dialog data */
514       if(!empty($data)){
515         return($data);
516       }
517     }
519     /* Automatically disable status for pasting */
520     if(!$this->CopyPasteHandler->entries_queued()){
521       $this->start_pasting_copied_objects = FALSE;
522     }
523     return("");
524   }
527   function save_object()
528   {
529     $this->DivListConference->save_object();
530   }
532   function remove_lock()
533   {
534     if (isset($this->dn)){
535       del_lock ($this->dn);
536     }
537   }
540   function list_get_selected_items()
541   {
542     $ids = array();
543     foreach($_POST as $name => $value){
544       if(preg_match("/^item_selected_[0-9]*$/",$name)){
545         $id   = preg_replace("/^item_selected_/","",$name);
546         $ids[$id] = $id;
547       }
548     }
549     return($ids);
550   }
554 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
555 ?>