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;
11 var $dns = array();
12 var $start_pasting_copied_objects = FALSE;
14 function blocklist (&$config, $ui)
15 {
16 $this->ui = $ui;
17 $this->dn = "";
18 $this->config = &$config;
19 $this->base = session::get('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::set('LOCK_VARS_TO_USE',array("/^menu_action/","/^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 $this->remove_lock();
126 $this->dialog = NULL;
127 session::un_set('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 $this->remove_lock();
147 $this->dn= "";
148 $this->dialog = NULL;
149 session::un_set('objectinfo');
150 }else{
152 /* Reinitialize tab */
153 if($this->dialog instanceof tabs){
154 $this->dialog->re_init();
155 }
156 }
157 } else {
158 /* Errors found, show message */
159 msg_dialog::displayChecks($message);
160 }
161 }
164 /***************
165 Create a new blocklist (dialog)
166 ***************/
168 /* Create new blocklist? */
169 if ($s_action=="new"){
170 $this->dn= "new";
171 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
172 $this->dialog->set_acl_base($this->base);
173 }
176 /***************
177 Edit blocklist
178 ***************/
180 if ($s_action=="edit" && !is_object($this->dialog)){
182 $this->dn=$this->blocklists[$s_entry]['dn'];
184 if (($user= get_lock($this->dn)) != ""){
185 return(gen_locked_message($user, $this->dn));
186 }else{
187 add_lock ($this->dn, $this->ui->dn);
188 }
189 session::set('objectinfo',trim($this->dn));
190 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
191 $this->dialog->set_acl_base($this->dn);
192 }
195 /***************
196 Display dialog
197 ***************/
199 if(is_object($this->dialog) && ($this->dialog instanceof faxblocktabs)){
200 $this->dialog->save_object();
201 return($this->dialog->execute());
202 }
205 /********************
206 Delete MULTIPLE entries requested, display confirm dialog
207 ********************/
209 if ($s_action=="del_multiple"){
211 $this->dns = array();
212 $ids = $this->list_get_selected_items();
214 if(count($ids)){
215 $disallowed = array();
216 foreach($ids as $id){
217 $dn = $this->blocklists[$id]['dn'];
218 $acl = $this->ui->get_permissions($dn, "gofaxlist/blocklistGeneric");
219 if(preg_match("/d/",$acl)){
220 $this->dns[$id] = $dn;
221 }else{
222 $disallowed[] = $dn;
223 }
224 }
226 if(count($disallowed)){
227 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
228 }
230 if(count($this->dns)){
232 if ($user= get_multiple_locks($this->dns)){
233 return(gen_locked_message($user,$this->dns));
234 }
236 $dns_names = array();
237 foreach($this->dns as $dn){
238 $dns_names[]=@LDAP::fix( $dn);
239 }
240 add_lock ($this->dns, $this->ui->dn);
242 /* Lock the current entry, so nobody will edit it during deletion */
243 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("blocklist")));
244 $smarty->assign("multiple", true);
245 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
246 }
247 }
248 }
251 /********************
252 Delete MULTIPLE entries confirmed
253 ********************/
255 /* Confirmation for deletion has been passed. */
256 if (isset($_POST['delete_multiple_blocklist_confirm'])){
258 /* Remove user by user and check acls before removeing them */
259 foreach($this->dns as $key => $dn){
260 $this->dn = $dn;
261 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
262 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
263 $this->dialog->delete();
264 $this->dialog = NULL;
265 } else {
266 msg_dialog::display(_("Permission error"), msgPool::permDelete($dn), ERROR_DIALOG);
267 }
268 /* Remove lock file after successfull deletion */
269 }
270 $this->remove_lock();
271 $this->dns = array();
272 $this->reload();
273 }
276 /********************
277 Delete MULTIPLE entries Canceled
278 ********************/
280 /* Remove lock */
281 if(isset($_POST['delete_multiple_blocklist_cancel'])){
282 foreach($this->dns as $key => $dn){
283 $this->remove_lock();
284 unset($this->dns[$key]);
285 }
286 }
289 /***************
290 Remove blocklist
291 ***************/
293 /* Delete blocklist requested */
294 if ($s_action=="del"){
295 $this->dn=$this->blocklists[$s_entry]['dn'];
297 /* Check locking */
298 if (($user= get_lock($this->dn)) != ""){
299 session::set('dn',$this->dn);
300 return(gen_locked_message($user, $this->dn));
301 } else {
303 // Lock this dn for editing
304 add_lock ($this->dn, $this->ui->dn);
305 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("blocklist")));
306 $smarty->assign("multiple", false);
307 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
308 }
309 }
312 /***************
313 Remove blocklist confirmed
314 ***************/
316 /* Finally delete blocklist */
317 if (isset($_POST['delete_blocklist_confirm'])){
318 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
319 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
320 $this->dialog->delete();
321 $this->dialog = NULL;
322 $this->remove_lock();
323 } else {
324 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
325 }
326 }
328 /***************
329 Divlist dialog
330 ***************/
332 /* Check if there is a snapshot dialog open */
333 $base = $this->DivListBlocklist->selectedBase;
334 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
335 return($str);
336 }
338 /* Display dialog with system list */
339 $this->DivListBlocklist->parent = $this;
340 $this->DivListBlocklist->execute();
342 /* Add departments if subsearch is disabled */
343 if(!$this->DivListBlocklist->SubSearch){
344 $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase,3,1);
345 }
346 $this->reload();
347 $this->DivListBlocklist->setEntries($this->blocklists);
348 return($this->DivListBlocklist->Draw());
349 }
352 function list_get_selected_items()
353 {
354 $ids = array();
355 foreach($_POST as $name => $value){
356 if(preg_match("/^item_selected_[0-9]*$/",$name)){
357 $id = preg_replace("/^item_selected_/","",$name);
358 $ids[$id] = $id;
359 }
360 }
361 return($ids);
362 }
365 /* Return departments, that will be included within snapshot detection */
366 function get_used_snapshot_bases()
367 {
368 return(array(get_ou('blocklistou').$this->DivListBlocklist->selectedBase));
369 }
372 /* Reload the list of known blocklists */
373 function reload()
374 {
375 /* Init some vars */
376 $filter = $filter2 = "";
377 $base = $this->DivListBlocklist->selectedBase;
378 $Regex = $this->DivListBlocklist->Regex;
379 $SubSearch = $this->DivListBlocklist->SubSearch;
380 $ShowSendBocklists = $this->DivListBlocklist->ShowSendBocklists;
381 $ShowReceiveBlocklists = $this->DivListBlocklist->ShowReceiveBlocklists;
382 $Flags = GL_SIZELIMIT;
383 $res = $res2 = array();
385 /* Append subsearch to Flags */
386 if($SubSearch){
387 $Flags |= GL_SUBSEARCH;
388 }else{
389 $base = get_ou('blocklistou').$base;
390 }
392 /* Create filter */
393 if ($ShowSendBocklists){
394 $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))";
395 $res= get_list($filter, "gofaxlist", $base,array("*"), $Flags);
396 }
397 if ($ShowReceiveBlocklists){
398 $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))";
399 $res2= get_list($filter2, "gofaxlist", $base,array("*"), $Flags);
400 }
402 $this->blocklists = array_merge($res,$res2);
404 /* appen && sort */
405 $tmp=array();
406 foreach($this->blocklists as $tkey => $val ){
408 $acl = $this->ui ->get_permissions($base,"gofaxlist/blocklist");
409 if(preg_match("/r/",$acl)){
410 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
411 }
412 }
413 ksort($tmp);
414 $this->blocklists=array();
415 foreach($tmp as $val){
416 $this->blocklists[]=$val;
417 }
418 reset ($this->blocklists);
419 }
422 /* Save data to object */
423 function save_object()
424 {
425 $this->DivListBlocklist->save_object();
426 if(is_object($this->CopyPasteHandler)){
427 $this->CopyPasteHandler->save_object();
428 }
429 }
435 function copyPasteHandling_from_queue($s_action,$s_entry)
436 {
437 /* Check if Copy & Paste is disabled */
438 if(!is_object($this->CopyPasteHandler)){
439 return("");
440 }
442 $ui = get_userinfo();
444 /* Add a single entry to queue */
445 if($s_action == "cut" || $s_action == "copy"){
446 /* Cleanup object queue */
447 $this->CopyPasteHandler->cleanup_queue();
448 $dn = $this->blocklists[$s_entry]['dn'];
449 if($s_action == "copy" && $ui->is_copyable($dn,"gofaxlist","blocklistGeneric")){
450 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
451 }
452 if($s_action == "cut" && $ui->is_cutable($dn,"gofaxlist","blocklistGeneric")){
453 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
454 }
455 }
457 /* Add entries to queue */
458 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
460 /* Cleanup object queue */
461 $this->CopyPasteHandler->cleanup_queue();
463 /* Add new entries to CP queue */
464 foreach($this->list_get_selected_items() as $id){
465 $dn = $this->blocklists[$id]['dn'];
467 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"gofaxlist","blocklistGeneric")){
468 $this->CopyPasteHandler->add_to_queue($dn,"copy","faxblocktabs","FAXBLOCKTABS","gofaxlist");
469 }
470 if($s_action == "cut_multiple" && $ui->is_cutable($dn,"gofaxlist","blocklistGeneric")){
471 $this->CopyPasteHandler->add_to_queue($dn,"cut","faxblocktabs","FAXBLOCKTABS","gofaxlist");
472 }
473 }
474 }
476 /* Start pasting entries */
477 if($s_action == "editPaste"){
478 $this->start_pasting_copied_objects = TRUE;
479 }
481 /* Return C&P dialog */
482 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
484 /* Get dialog */
485 $this->CopyPasteHandler->SetVar("base",$this->DivListBlocklist->selectedBase);
486 $data = $this->CopyPasteHandler->execute();
488 /* Return dialog data */
489 if(!empty($data)){
490 return($data);
491 }
492 }
494 /* Automatically disable status for pasting */
495 if(!$this->CopyPasteHandler->entries_queued()){
496 $this->start_pasting_copied_objects = FALSE;
497 }
498 return("");
499 }
502 /*! \brief Remove entry locks if the plugin was aborted.
503 */
504 function remove_lock()
505 {
506 if($this->dn) del_lock($this->dn);
507 if(is_array($this->dns) && count($this->dns)) del_lock($this->dns);
508 }
509 }
510 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
511 ?>