Code

Some additional hardcoded department links moved to get_ou()
[gosa.git] / gosa-plugins / gofax / gofax / blocklists / class_blocklistManagement.inc
1 <?php
2 class blocklist extends plugin
3 {
4   /* Definitions */
5   var $plHeadline= "FAX Blocklists";
6   var $plDescription= "This does something";
8   var $blocklists       = array();
9   var $DivListBlocklist = NULL;
10   var $CopyPasteHandler = NULL;
12   var $start_pasting_copied_objects = FALSE;
13   
14   function blocklist (&$config, $ui)
15   {
16     $this->ui     = $ui;
17     $this->dn     = "";
18     $this->config = &$config;
19     $this->base = $_SESSION['CurrentMainBase']; 
20     $this->DivListBlocklist = new divListBlocklist($this->config,$this);
22     /* Initialize copy&paste queue */
23     if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
24       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
25     }
26   }
29   function execute()
30   {
31     /* Call parent execute */
32     plugin::execute();
34     $_SESSION['LOCK_VARS_TO_USE'] = array("/^goFaxBlocklist_/","/^act$/","/^id$/","/^remove_multiple_blocklists/","/^item_selected/");
36     /***************
37       Init vars 
38      ***************/
40     /* Get global smarty instance */
41     $smarty       = get_smarty();
42     $s_action     = "";                       // Contains the action to proceed
43     $s_entry      = "";                       // The value for s_action
44     $base_back    = "";                       // The Link for Backbutton
47     /***************
48       Fetch posts 
49      ***************/
51     /* Test Posts */
52     foreach($_POST as $key => $val){
53       // Post for delete
54       if(preg_match("/^goFaxBlocklist_del.*/",$key)){
55         $s_action = "del";
56         $s_entry  = preg_replace("/^goFaxBlocklist_del_/i","",$key);
57         // Post for edit
58       }elseif(preg_match("/^goFaxBlocklist_edit_.*/",$key)){
59         $s_action="edit";
60         $s_entry  = preg_replace("/^goFaxBlocklist_edit_/i","",$key);
61         // Post for new
62       }elseif(preg_match("/^goFaxBlocklist_new.*/",$key)){
63         $s_action="new";
64       }elseif(preg_match("/^remove_multiple_blocklists/",$key)){
65         $s_action="del_multiple";
66       }elseif(preg_match("/^copy/",$key)){
67         $s_action = "copy";
68         $s_entry= preg_replace("/^copy_/i", "", $key);
69       }elseif(preg_match("/^cut/",$key)){
70         $s_action = "cut";
71         $s_entry= preg_replace("/^cut_/i", "", $key);
72       }
74     }
75     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
76       $s_action ="edit";
77       $s_entry  = $_GET['id'];
78     }
80     $s_entry  = preg_replace("/_.$/","",$s_entry);
83     /* handle C&P from layers menu */
84     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
85       $s_action = "copy_multiple";
86     }
87     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
88       $s_action = "cut_multiple";
89     }
90     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
91       $s_action = "editPaste";
92     }
95     /* Create options */
96     if(isset($_POST['menu_action']) && $_POST['menu_action'] == "goFaxBlocklist_new"){
97       $s_action = "new";
98     }
100     /* handle remove from layers menu */
101     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
102       $s_action = "del_multiple";
103     }
106     /***************
107       Handle copy & paste  
108      ***************/
110     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
111     if($ret){
112       return($ret);
113     }
116     /***************
117       Cancel some dialogs  
118      ***************/
120     /* Cancel dialog */
121     if (isset($_POST['edit_cancel']) || 
122         isset($_POST['delete_blocklist_cancel']) ||
123         isset($_POST['delete_lock'])){
125       del_lock ($this->dn);
126       $this->dialog = NULL;
127       unset($_SESSION['objectinfo']);
128     }
131     /***************
132       Save blocklist 
133      ***************/
135     /* What about finish? */
136     if (isset($_POST['edit_finish']) || isset($_POST['edit_apply'])){
138       /* No errors, save object */
139       $this->dialog->save_object();
140       $message= $this->check();
141       if (count ($message) == 0){
143         $this->dialog->save ();
145         if (!isset($_POST['edit_apply'])){
146           del_lock ($this->dn);
147           $this->dn= "";
148           $this->dialog = NULL;
149           unset($_SESSION['objectinfo']);
150         }
151       } else {
152         /* Errors found, show message */
153         show_errors ($message);
154       }
155     }
158     /***************
159       Create a new blocklist (dialog)
160      ***************/
162     /* Create new blocklist? */
163     if ($s_action=="new"){
164       $this->dn= "new";
165       $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
166       $this->dialog->set_acl_base($this->base);
167     }
170     /***************
171       Edit blocklist 
172      ***************/
174     if ($s_action=="edit" && !is_object($this->dialog)){
176       $this->dn=$this->blocklists[$s_entry]['dn'];
178       if (($user= get_lock($this->dn)) != ""){
179         return(gen_locked_message($user, $this->dn));
180       }else{
181         add_lock ($this->dn, $this->ui->dn);
182       }
183       $_SESSION['objectinfo']= trim($this->dn);
184       $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
185       $this->dialog->set_acl_base($this->dn);
186     }    
189     /***************
190       Display dialog  
191      ***************/
193     if(is_object($this->dialog) && ($this->dialog instanceof faxblocktabs)){
194       $this->dialog->save_object();
195       return($this->dialog->execute());
196     }
199     /********************
200       Delete MULTIPLE entries requested, display confirm dialog
201      ********************/
203     if ($s_action=="del_multiple"){
205       $this->dns = array();
206       $ids = $this->list_get_selected_items();
208       if(count($ids)){
209         foreach($ids as $id){
210           $dn = $this->blocklists[$id]['dn'];
211           if (($user= get_lock($dn)) != ""){
212             return(gen_locked_message ($user, $dn));
213           }
214           $this->dns[$id] = $dn;
215         }
217         $dns_names = "<br><pre>";
218         foreach($this->dns as $dn){
219           add_lock ($dn, $this->ui->dn);
220           $dns_names .= $dn."\n";
221         }
222         $dns_names .="</pre>";
224         /* Lock the current entry, so nobody will edit it during deletion */
225         $smarty->assign("info",     sprintf(_("You're about to delete the following blocklists(s) %s"), @LDAP::fix($dns_names)));
226         $smarty->assign("multiple", true);
227         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
228       }
229     }
232     /********************
233       Delete MULTIPLE entries confirmed
234      ********************/
236     /* Confirmation for deletion has been passed. */
237     if (isset($_POST['delete_multiple_blocklist_confirm'])){
239       /* Remove user by user and check acls before removeing them */
240       foreach($this->dns as $key => $dn){
241         if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
242           $this->dn = $dn;
243           $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
244           $this->dialog->delete();
245           $this->dialog = NULL;
246         } else {
247           print_red (sprintf(_("You are not allowed to delete the blocklist '%s'!"),$dn));
248         }
249         /* Remove lock file after successfull deletion */
250         del_lock ($dn);
251         unset($this->dns[$key]);
252       }
253       $this->reload();
254     }
257     /********************
258       Delete MULTIPLE entries Canceled
259      ********************/
261     /* Remove lock */
262     if(isset($_POST['delete_multiple_blocklist_cancel'])){
263       foreach($this->dns as $key => $dn){
264         del_lock ($dn);
265         unset($this->dns[$key]);
266       }
267     }
270     /***************
271       Remove blocklist
272      ***************/
274     /* Delete blocklist requested */
275     if ($s_action=="del"){
276       $this->dn=$this->blocklists[$s_entry]['dn'];
278       /* Check locking */
279       if (($user= get_lock($this->dn)) != ""){
280         $_SESSION['dn']= $this->dn;
281         return(gen_locked_message($user, $this->dn));
282       } else {
284         // Lock this dn for editing
285         add_lock ($this->dn, $this->ui->dn);
286         $smarty->assign("info", sprintf(_("You're about to delete the blocklist '%s'."), $this->dn));
287         $smarty->assign("multiple", false);
288         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
289       }
290     }
293     /***************
294       Remove blocklist confirmed
295      ***************/
297     /* Finally delete blocklist */
298     if (isset($_POST['delete_blocklist_confirm'])){
299       if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
300         $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
301         $this->dialog->delete();
302         $this->dialog = NULL;
303         del_lock ($this->dn);
304       } else {
305         print_red (_("You have no permission to remove this blocklist."));
306       }
307     }
309     /***************
310       Divlist dialog 
311      ***************/
313     /* Check if there is a snapshot dialog open */
314     $base = $this->DivListBlocklist->selectedBase;
315     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
316       return($str);
317     }
319     /* Display dialog with system list */
320     $this->DivListBlocklist->parent = $this;
321     $this->DivListBlocklist->execute();
323     /* Add departments if subsearch is disabled */
324     if(!$this->DivListBlocklist->SubSearch){
325       $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase,3,1);
326     }
327     $this->reload();
328     $this->DivListBlocklist->setEntries($this->blocklists);
329     return($this->DivListBlocklist->Draw());
330   }
333   function list_get_selected_items()
334   {
335     $ids = array();
336     foreach($_POST as $name => $value){
337       if(preg_match("/^item_selected_[0-9]*$/",$name)){
338         $id   = preg_replace("/^item_selected_/","",$name);
339         $ids[$id] = $id;
340       }
341     }
342     return($ids);
343   }
346   /* Return departments, that will be included within snapshot detection */
347   function get_used_snapshot_bases()
348   {
349     return(array(get_ou('blocklistou').$this->DivListBlocklist->selectedBase));
350   }
353   /* Reload the list of known blocklists */
354   function reload()
355   {
356     /* Init some vars */
357     $filter = $filter2      = "";
358     $base                   = $this->DivListBlocklist->selectedBase;
359     $Regex                  = $this->DivListBlocklist->Regex;
360     $SubSearch              = $this->DivListBlocklist->SubSearch;
361     $ShowSendBocklists      = $this->DivListBlocklist->ShowSendBocklists;
362     $ShowReceiveBlocklists  = $this->DivListBlocklist->ShowReceiveBlocklists;
363     $Flags                  = GL_SIZELIMIT;
364     $res = $res2            = array();
366     /* Append subsearch to Flags */
367     if($SubSearch){
368       $Flags |= GL_SUBSEARCH;
369     }else{
370       $base = get_ou('blocklistou').$base;
371     }  
373     /* Create filter */
374     if ($ShowSendBocklists){
375       $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))";
376       $res= get_list($filter, "gofaxlist", $base,array("*"), $Flags);
377     }
378     if ($ShowReceiveBlocklists){
379       $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))";
380       $res2= get_list($filter2, "gofaxlist", $base,array("*"), $Flags);
381     }
383     $this->blocklists = array_merge($res,$res2);
385     /* appen && sort */
386     $tmp=array();
387     foreach($this->blocklists as $tkey => $val ){
389       $acl = $this->ui ->get_permissions($base,"gofaxlist/blocklist");
390       if(preg_match("/r/",$acl)){
391         $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
392       }
393     }
394     ksort($tmp);
395     $this->blocklists=array();
396     foreach($tmp as $val){
397       $this->blocklists[]=$val;
398     }
399     reset ($this->blocklists);
400   }
403   /* Save data to object */
404   function save_object()
405   {
406     $this->DivListBlocklist->save_object();
407   }
413   function copyPasteHandling_from_queue($s_action,$s_entry)
414   {
415     /* Check if Copy & Paste is disabled */
416     if(!is_object($this->CopyPasteHandler)){
417       return("");
418     }
420     /* Add a single entry to queue */
421     if($s_action == "cut" || $s_action == "copy"){
422       /* Cleanup object queue */
423       $this->CopyPasteHandler->cleanup_queue();
424       $dn = $this->blocklists[$s_entry]['dn'];
425       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
426     }
428     /* Add entries to queue */
429     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
431       /* Cleanup object queue */
432       $this->CopyPasteHandler->cleanup_queue();
434       /* Add new entries to CP queue */
435       foreach($this->list_get_selected_items() as $id){
436         $dn = $this->blocklists[$id]['dn'];
438         if($s_action == "copy_multiple"){
439           $this->CopyPasteHandler->add_to_queue($dn,"copy","faxblocktabs","FAXBLOCKTABS","gofaxlist");
440         }
441         if($s_action == "cut_multiple"){
442           $this->CopyPasteHandler->add_to_queue($dn,"cut","faxblocktabs","FAXBLOCKTABS","gofaxlist");
443         }
444       }
445     }
447     /* Start pasting entries */
448     if($s_action == "editPaste"){
449       $this->start_pasting_copied_objects = TRUE;
450     }
452     /* Return C&P dialog */
453     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
455       /* Load entry from queue and set base */
456       $this->CopyPasteHandler->load_entry_from_queue();
457       $this->CopyPasteHandler->SetVar("base",$this->DivListBlocklist->selectedBase);
459       /* Get dialog */
460       $data = $this->CopyPasteHandler->execute();
462       /* Return dialog data */
463       if(!empty($data)){
464         return($data);
465       }
466     }
468     /* Automatically disable status for pasting */
469     if(!$this->CopyPasteHandler->entries_queued()){
470       $this->start_pasting_copied_objects = FALSE;
471     }
472     return("");
473   }
476 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
477 ?>