1 <?php
2 class blocklist extends plugin
3 {
4 /* Definitions */
5 var $plHeadline= "FAX blocklists";
6 var $plDescription= "This does something";
7 var $plIcon = "plugins/gofax/images/blocklists.png";
9 var $blocklists = array();
10 var $DivListBlocklist = NULL;
11 var $CopyPasteHandler = NULL;
12 var $dns = array();
13 var $start_pasting_copied_objects = FALSE;
15 var $acl_module = array("gofaxlist");
17 function blocklist (&$config, $ui)
18 {
19 $this->ui = $ui;
20 $this->dn = "";
21 $this->config = &$config;
22 $this->base = session::get('CurrentMainBase');
23 $this->DivListBlocklist = new divListBlocklist($this->config,$this);
25 /* Initialize copy&paste queue */
26 if ($this->config->boolValueIsTrue("main", "copyPaste")){
27 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
28 }
29 }
32 function execute()
33 {
34 /* Call parent execute */
35 plugin::execute();
37 session::set('LOCK_VARS_TO_USE',array("/^menu_action/","/^goFaxBlocklist_/","/^act$/","/^id$/","/^remove_multiple_blocklists/","/^item_selected/"));
39 /***************
40 Init vars
41 ***************/
43 /* Get global smarty instance */
44 $smarty = get_smarty();
45 $s_action = ""; // Contains the action to proceed
46 $s_entry = ""; // The value for s_action
47 $base_back = ""; // The Link for Backbutton
50 /***************
51 Fetch posts
52 ***************/
54 /* Test Posts */
55 foreach($_POST as $key => $val){
56 // Post for delete
57 if(preg_match("/^goFaxBlocklist_del.*/",$key)){
58 $s_action = "del";
59 $s_entry = preg_replace("/^goFaxBlocklist_del_/i","",$key);
60 // Post for edit
61 }elseif(preg_match("/^goFaxBlocklist_edit_.*/",$key)){
62 $s_action="edit";
63 $s_entry = preg_replace("/^goFaxBlocklist_edit_/i","",$key);
64 // Post for new
65 }elseif(preg_match("/^goFaxBlocklist_new.*/",$key)){
66 $s_action="new";
67 }elseif(preg_match("/^remove_multiple_blocklists/",$key)){
68 $s_action="del_multiple";
69 }elseif(preg_match("/^copy/",$key)){
70 $s_action = "copy";
71 $s_entry= preg_replace("/^copy_/i", "", $key);
72 }elseif(preg_match("/^cut/",$key)){
73 $s_action = "cut";
74 $s_entry= preg_replace("/^cut_/i", "", $key);
75 }
77 }
78 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
79 $s_action ="edit";
80 $s_entry = $_GET['id'];
81 }
83 $s_entry = preg_replace("/_.$/","",$s_entry);
86 /* handle C&P from layers menu */
87 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
88 $s_action = "copy_multiple";
89 }
90 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
91 $s_action = "cut_multiple";
92 }
93 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
94 $s_action = "editPaste";
95 }
98 /* Create options */
99 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "goFaxBlocklist_new"){
100 $s_action = "new";
101 }
103 /* handle remove from layers menu */
104 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
105 $s_action = "del_multiple";
106 }
109 /***************
110 Handle copy & paste
111 ***************/
113 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
114 if($ret){
115 return($ret);
116 }
119 /***************
120 Cancel some dialogs
121 ***************/
123 /* Cancel dialog */
124 if (isset($_POST['edit_cancel']) ||
125 isset($_POST['delete_blocklist_cancel']) ||
126 isset($_POST['delete_lock'])){
128 $this->remove_lock();
129 $this->dialog = NULL;
130 set_object_info();
131 }
134 /***************
135 Save blocklist
136 ***************/
138 /* What about finish? */
139 if (isset($_POST['edit_finish']) || isset($_POST['edit_apply'])){
141 /* No errors, save object */
142 $this->dialog->save_object();
143 $message= $this->check();
144 if (count ($message) == 0){
146 $this->dialog->save ();
148 if (!isset($_POST['edit_apply'])){
149 $this->remove_lock();
150 $this->dn= "";
151 $this->dialog = NULL;
152 set_object_info();
153 }else{
155 /* Reinitialize tab */
156 if($this->dialog instanceof tabs){
157 $this->dialog->re_init();
158 }
159 }
160 } else {
161 /* Errors found, show message */
162 msg_dialog::displayChecks($message);
163 }
164 }
167 /***************
168 Create a new blocklist (dialog)
169 ***************/
171 /* Create new blocklist? */
172 if ($s_action=="new"){
173 $this->dn= "new";
174 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
175 $this->dialog->set_acl_base($this->base);
176 }
179 /***************
180 Edit blocklist
181 ***************/
183 if ($s_action=="edit" && !is_object($this->dialog)){
185 $this->dn=$this->blocklists[$s_entry]['dn'];
187 if (($user= get_lock($this->dn)) != ""){
188 return(gen_locked_message($user, $this->dn,TRUE));
189 }else{
190 add_lock ($this->dn, $this->ui->dn);
191 }
192 set_object_info(trim($this->dn));
193 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
194 $this->dialog->set_acl_base($this->dn);
195 }
198 /***************
199 Display dialog
200 ***************/
202 if(is_object($this->dialog) && ($this->dialog instanceof faxblocktabs)){
203 $this->dialog->save_object();
204 return($this->dialog->execute());
205 }
208 /********************
209 Delete MULTIPLE entries requested, display confirm dialog
210 ********************/
212 if ($s_action=="del_multiple"){
214 $this->dns = array();
215 $ids = $this->list_get_selected_items();
217 if(count($ids)){
218 $disallowed = array();
219 foreach($ids as $id){
220 $dn = $this->blocklists[$id]['dn'];
221 $acl = $this->ui->get_permissions($dn, "gofaxlist/blocklistGeneric");
222 if(preg_match("/d/",$acl)){
223 $this->dns[$id] = $dn;
224 }else{
225 $disallowed[] = $dn;
226 }
227 }
229 if(count($disallowed)){
230 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
231 }
233 if(count($this->dns)){
235 if ($user= get_multiple_locks($this->dns)){
236 return(gen_locked_message($user,$this->dns));
237 }
239 $dns_names = array();
240 foreach($this->dns as $dn){
241 $dns_names[]=LDAP::fix( $dn);
242 }
243 add_lock ($this->dns, $this->ui->dn);
245 /* Lock the current entry, so nobody will edit it during deletion */
246 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("blocklist")));
247 $smarty->assign("multiple", true);
248 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
249 }
250 }
251 }
254 /********************
255 Delete MULTIPLE entries confirmed
256 ********************/
258 /* Confirmation for deletion has been passed. */
259 if (isset($_POST['delete_multiple_blocklist_confirm'])){
261 /* Remove user by user and check acls before removeing them */
262 foreach($this->dns as $key => $dn){
263 $this->dn = $dn;
264 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
265 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
266 $this->dialog->delete();
267 $this->dialog = NULL;
268 } else {
269 msg_dialog::display(_("Permission error"), msgPool::permDelete($dn), ERROR_DIALOG);
270 }
271 /* Remove lock file after successfull deletion */
272 }
273 $this->remove_lock();
274 $this->dns = array();
275 $this->reload();
276 }
279 /********************
280 Delete MULTIPLE entries Canceled
281 ********************/
283 /* Remove lock */
284 if(isset($_POST['delete_multiple_blocklist_cancel'])){
285 foreach($this->dns as $key => $dn){
286 $this->remove_lock();
287 unset($this->dns[$key]);
288 }
289 }
292 /***************
293 Remove blocklist
294 ***************/
296 /* Delete blocklist requested */
297 if ($s_action=="del"){
298 $this->dn=$this->blocklists[$s_entry]['dn'];
300 /* Check locking */
301 if (($user= get_lock($this->dn)) != ""){
302 return(gen_locked_message($user, $this->dn));
303 } else {
305 // Lock this dn for editing
306 add_lock ($this->dn, $this->ui->dn);
307 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->dn),_("blocklist")));
308 $smarty->assign("multiple", false);
309 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
310 }
311 }
314 /***************
315 Remove blocklist confirmed
316 ***************/
318 /* Finally delete blocklist */
319 if (isset($_POST['delete_blocklist_confirm'])){
320 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
321 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
322 $this->dialog->delete();
323 $this->dialog = NULL;
324 $this->remove_lock();
325 } else {
326 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
327 }
328 }
330 /***************
331 Divlist dialog
332 ***************/
334 /* Check if there is a snapshot dialog open */
335 $base = $this->DivListBlocklist->selectedBase;
336 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
337 return($str);
338 }
340 /* Display dialog with system list */
341 $this->DivListBlocklist->parent = $this;
342 $this->DivListBlocklist->execute();
344 /* Add departments if subsearch is disabled */
345 if(!$this->DivListBlocklist->SubSearch){
346 $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase,3,1);
347 }
348 $this->reload();
349 $this->DivListBlocklist->setEntries($this->blocklists);
350 return($this->DivListBlocklist->Draw());
351 }
354 function list_get_selected_items()
355 {
356 $ids = array();
357 foreach($_POST as $name => $value){
358 if(preg_match("/^item_selected_[0-9]*$/",$name)){
359 $id = preg_replace("/^item_selected_/","",$name);
360 $ids[$id] = $id;
361 }
362 }
363 return($ids);
364 }
367 /* Return departments, that will be included within snapshot detection */
368 function get_used_snapshot_bases()
369 {
370 return(array(get_ou('faxBlocklistRDN').$this->DivListBlocklist->selectedBase));
371 }
374 /* Reload the list of known blocklists */
375 function reload()
376 {
377 /* Init some vars */
378 $filter = $filter2 = "";
379 $base = $this->DivListBlocklist->selectedBase;
380 $Regex = $this->DivListBlocklist->Regex;
381 $SubSearch = $this->DivListBlocklist->SubSearch;
382 $ShowSendBocklists = $this->DivListBlocklist->ShowSendBocklists;
383 $ShowReceiveBlocklists = $this->DivListBlocklist->ShowReceiveBlocklists;
384 $Flags = GL_SIZELIMIT;
385 $res = $res2 = array();
387 /* Append subsearch to Flags */
388 if($SubSearch){
389 $Flags |= GL_SUBSEARCH;
390 }else{
391 $base = get_ou('faxBlocklistRDN').$base;
392 }
394 /* Create filter */
395 if ($ShowSendBocklists){
396 $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))";
397 $res= get_list($filter, "gofaxlist", $base,array("*"), $Flags);
398 }
399 if ($ShowReceiveBlocklists){
400 $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))";
401 $res2= get_list($filter2, "gofaxlist", $base,array("*"), $Flags);
402 }
404 $this->blocklists = array_merge($res,$res2);
406 /* appen && sort */
407 $tmp=array();
408 foreach($this->blocklists as $tkey => $val ){
410 $acl = $this->ui ->get_permissions($base,"gofaxlist/blocklistGeneric");
411 if(preg_match("/r/",$acl)){
412 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
413 }
414 }
415 ksort($tmp);
416 $this->blocklists=array();
417 foreach($tmp as $val){
418 $this->blocklists[]=$val;
419 }
420 reset ($this->blocklists);
421 }
424 /* Save data to object */
425 function save_object()
426 {
427 $this->DivListBlocklist->save_object();
428 if(is_object($this->CopyPasteHandler)){
429 $this->CopyPasteHandler->save_object();
430 }
431 }
437 function copyPasteHandling_from_queue($s_action,$s_entry)
438 {
439 /* Check if Copy & Paste is disabled */
440 if(!is_object($this->CopyPasteHandler)){
441 return("");
442 }
444 $ui = get_userinfo();
446 /* Add a single entry to queue */
447 if($s_action == "cut" || $s_action == "copy"){
448 /* Cleanup object queue */
449 $this->CopyPasteHandler->cleanup_queue();
450 $dn = $this->blocklists[$s_entry]['dn'];
451 if($s_action == "copy" && $ui->is_copyable($dn,"gofaxlist","blocklistGeneric")){
452 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
453 }
454 if($s_action == "cut" && $ui->is_cutable($dn,"gofaxlist","blocklistGeneric")){
455 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
456 }
457 }
459 /* Add entries to queue */
460 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
462 /* Cleanup object queue */
463 $this->CopyPasteHandler->cleanup_queue();
465 /* Add new entries to CP queue */
466 foreach($this->list_get_selected_items() as $id){
467 $dn = $this->blocklists[$id]['dn'];
469 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"gofaxlist","blocklistGeneric")){
470 $this->CopyPasteHandler->add_to_queue($dn,"copy","faxblocktabs","FAXBLOCKTABS","gofaxlist");
471 }
472 if($s_action == "cut_multiple" && $ui->is_cutable($dn,"gofaxlist","blocklistGeneric")){
473 $this->CopyPasteHandler->add_to_queue($dn,"cut","faxblocktabs","FAXBLOCKTABS","gofaxlist");
474 }
475 }
476 }
478 /* Start pasting entries */
479 if($s_action == "editPaste"){
480 $this->start_pasting_copied_objects = TRUE;
481 }
483 /* Return C&P dialog */
484 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
486 /* Get dialog */
487 $this->CopyPasteHandler->SetVar("base",$this->DivListBlocklist->selectedBase);
488 $data = $this->CopyPasteHandler->execute();
490 /* Return dialog data */
491 if(!empty($data)){
492 return($data);
493 }
494 }
496 /* Automatically disable status for pasting */
497 if(!$this->CopyPasteHandler->entries_queued()){
498 $this->start_pasting_copied_objects = FALSE;
499 }
500 return("");
501 }
504 /*! \brief Remove entry locks if the plugin was aborted.
505 */
506 function remove_lock()
507 {
508 if($this->dn) del_lock($this->dn);
509 if(is_array($this->dns) && count($this->dns)) del_lock($this->dns);
510 }
511 }
512 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
513 ?>