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;
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("/^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 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 del_lock ($this->dn);
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 foreach($ids as $id){
216 $dn = $this->blocklists[$id]['dn'];
217 if (($user= get_lock($dn)) != ""){
218 return(gen_locked_message ($user, $dn));
219 }
220 $this->dns[$id] = $dn;
221 }
223 $dns_names[] = array();
224 foreach($this->dns as $dn){
225 add_lock ($dn, $this->ui->dn);
226 $dns_names[]=@LDAP::fix( $dn);
227 }
229 /* Lock the current entry, so nobody will edit it during deletion */
230 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("blocklist")));
231 $smarty->assign("multiple", true);
232 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
233 }
234 }
237 /********************
238 Delete MULTIPLE entries confirmed
239 ********************/
241 /* Confirmation for deletion has been passed. */
242 if (isset($_POST['delete_multiple_blocklist_confirm'])){
244 /* Remove user by user and check acls before removeing them */
245 foreach($this->dns as $key => $dn){
246 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
247 $this->dn = $dn;
248 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
249 $this->dialog->delete();
250 $this->dialog = NULL;
251 } else {
252 msg_dialog::display(_("Permission error"), msgPool::permDelete($dn), ERROR_DIALOG);
253 }
254 /* Remove lock file after successfull deletion */
255 del_lock ($dn);
256 unset($this->dns[$key]);
257 }
258 $this->reload();
259 }
262 /********************
263 Delete MULTIPLE entries Canceled
264 ********************/
266 /* Remove lock */
267 if(isset($_POST['delete_multiple_blocklist_cancel'])){
268 foreach($this->dns as $key => $dn){
269 del_lock ($dn);
270 unset($this->dns[$key]);
271 }
272 }
275 /***************
276 Remove blocklist
277 ***************/
279 /* Delete blocklist requested */
280 if ($s_action=="del"){
281 $this->dn=$this->blocklists[$s_entry]['dn'];
283 /* Check locking */
284 if (($user= get_lock($this->dn)) != ""){
285 session::set('dn',$this->dn);
286 return(gen_locked_message($user, $this->dn));
287 } else {
289 // Lock this dn for editing
290 add_lock ($this->dn, $this->ui->dn);
291 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("blocklist")));
292 $smarty->assign("multiple", false);
293 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
294 }
295 }
298 /***************
299 Remove blocklist confirmed
300 ***************/
302 /* Finally delete blocklist */
303 if (isset($_POST['delete_blocklist_confirm'])){
304 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
305 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
306 $this->dialog->delete();
307 $this->dialog = NULL;
308 del_lock ($this->dn);
309 } else {
310 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
311 }
312 }
314 /***************
315 Divlist dialog
316 ***************/
318 /* Check if there is a snapshot dialog open */
319 $base = $this->DivListBlocklist->selectedBase;
320 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
321 return($str);
322 }
324 /* Display dialog with system list */
325 $this->DivListBlocklist->parent = $this;
326 $this->DivListBlocklist->execute();
328 /* Add departments if subsearch is disabled */
329 if(!$this->DivListBlocklist->SubSearch){
330 $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase,3,1);
331 }
332 $this->reload();
333 $this->DivListBlocklist->setEntries($this->blocklists);
334 return($this->DivListBlocklist->Draw());
335 }
338 function list_get_selected_items()
339 {
340 $ids = array();
341 foreach($_POST as $name => $value){
342 if(preg_match("/^item_selected_[0-9]*$/",$name)){
343 $id = preg_replace("/^item_selected_/","",$name);
344 $ids[$id] = $id;
345 }
346 }
347 return($ids);
348 }
351 /* Return departments, that will be included within snapshot detection */
352 function get_used_snapshot_bases()
353 {
354 return(array(get_ou('blocklistou').$this->DivListBlocklist->selectedBase));
355 }
358 /* Reload the list of known blocklists */
359 function reload()
360 {
361 /* Init some vars */
362 $filter = $filter2 = "";
363 $base = $this->DivListBlocklist->selectedBase;
364 $Regex = $this->DivListBlocklist->Regex;
365 $SubSearch = $this->DivListBlocklist->SubSearch;
366 $ShowSendBocklists = $this->DivListBlocklist->ShowSendBocklists;
367 $ShowReceiveBlocklists = $this->DivListBlocklist->ShowReceiveBlocklists;
368 $Flags = GL_SIZELIMIT;
369 $res = $res2 = array();
371 /* Append subsearch to Flags */
372 if($SubSearch){
373 $Flags |= GL_SUBSEARCH;
374 }else{
375 $base = get_ou('blocklistou').$base;
376 }
378 /* Create filter */
379 if ($ShowSendBocklists){
380 $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))";
381 $res= get_list($filter, "gofaxlist", $base,array("*"), $Flags);
382 }
383 if ($ShowReceiveBlocklists){
384 $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))";
385 $res2= get_list($filter2, "gofaxlist", $base,array("*"), $Flags);
386 }
388 $this->blocklists = array_merge($res,$res2);
390 /* appen && sort */
391 $tmp=array();
392 foreach($this->blocklists as $tkey => $val ){
394 $acl = $this->ui ->get_permissions($base,"gofaxlist/blocklist");
395 if(preg_match("/r/",$acl)){
396 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
397 }
398 }
399 ksort($tmp);
400 $this->blocklists=array();
401 foreach($tmp as $val){
402 $this->blocklists[]=$val;
403 }
404 reset ($this->blocklists);
405 }
408 /* Save data to object */
409 function save_object()
410 {
411 $this->DivListBlocklist->save_object();
412 if(is_object($this->CopyPasteHandler)){
413 $this->CopyPasteHandler->save_object();
414 }
415 }
421 function copyPasteHandling_from_queue($s_action,$s_entry)
422 {
423 /* Check if Copy & Paste is disabled */
424 if(!is_object($this->CopyPasteHandler)){
425 return("");
426 }
428 /* Add a single entry to queue */
429 if($s_action == "cut" || $s_action == "copy"){
430 /* Cleanup object queue */
431 $this->CopyPasteHandler->cleanup_queue();
432 $dn = $this->blocklists[$s_entry]['dn'];
433 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
434 }
436 /* Add entries to queue */
437 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
439 /* Cleanup object queue */
440 $this->CopyPasteHandler->cleanup_queue();
442 /* Add new entries to CP queue */
443 foreach($this->list_get_selected_items() as $id){
444 $dn = $this->blocklists[$id]['dn'];
446 if($s_action == "copy_multiple"){
447 $this->CopyPasteHandler->add_to_queue($dn,"copy","faxblocktabs","FAXBLOCKTABS","gofaxlist");
448 }
449 if($s_action == "cut_multiple"){
450 $this->CopyPasteHandler->add_to_queue($dn,"cut","faxblocktabs","FAXBLOCKTABS","gofaxlist");
451 }
452 }
453 }
455 /* Start pasting entries */
456 if($s_action == "editPaste"){
457 $this->start_pasting_copied_objects = TRUE;
458 }
460 /* Return C&P dialog */
461 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
463 /* Get dialog */
464 $data = $this->CopyPasteHandler->execute();
465 $this->CopyPasteHandler->SetVar("base",$this->DivListBlocklist->selectedBase);
467 /* Return dialog data */
468 if(!empty($data)){
469 return($data);
470 }
471 }
473 /* Automatically disable status for pasting */
474 if(!$this->CopyPasteHandler->entries_queued()){
475 $this->start_pasting_copied_objects = FALSE;
476 }
477 return("");
478 }
480 }
481 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
482 ?>