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 }
151 } else {
152 /* Errors found, show message */
153 msg_dialog::displayChecks($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::set('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[] = array();
218 foreach($this->dns as $dn){
219 add_lock ($dn, $this->ui->dn);
220 $dns_names[]=@LDAP::fix( $dn);
221 }
223 /* Lock the current entry, so nobody will edit it during deletion */
224 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("blocklist")));
225 $smarty->assign("multiple", true);
226 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
227 }
228 }
231 /********************
232 Delete MULTIPLE entries confirmed
233 ********************/
235 /* Confirmation for deletion has been passed. */
236 if (isset($_POST['delete_multiple_blocklist_confirm'])){
238 /* Remove user by user and check acls before removeing them */
239 foreach($this->dns as $key => $dn){
240 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
241 $this->dn = $dn;
242 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
243 $this->dialog->delete();
244 $this->dialog = NULL;
245 } else {
246 msg_dialog::display(_("Permission error"), sprintf(_("You have not permission to delete '%s'!"), $dn), ERROR_DIALOG);
247 }
248 /* Remove lock file after successfull deletion */
249 del_lock ($dn);
250 unset($this->dns[$key]);
251 }
252 $this->reload();
253 }
256 /********************
257 Delete MULTIPLE entries Canceled
258 ********************/
260 /* Remove lock */
261 if(isset($_POST['delete_multiple_blocklist_cancel'])){
262 foreach($this->dns as $key => $dn){
263 del_lock ($dn);
264 unset($this->dns[$key]);
265 }
266 }
269 /***************
270 Remove blocklist
271 ***************/
273 /* Delete blocklist requested */
274 if ($s_action=="del"){
275 $this->dn=$this->blocklists[$s_entry]['dn'];
277 /* Check locking */
278 if (($user= get_lock($this->dn)) != ""){
279 session::set('dn',$this->dn);
280 return(gen_locked_message($user, $this->dn));
281 } else {
283 // Lock this dn for editing
284 add_lock ($this->dn, $this->ui->dn);
285 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("blocklist")));
286 $smarty->assign("multiple", false);
287 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
288 }
289 }
292 /***************
293 Remove blocklist confirmed
294 ***************/
296 /* Finally delete blocklist */
297 if (isset($_POST['delete_blocklist_confirm'])){
298 if (preg_match("/d/",$this->ui->get_permissions($this->dn,"gofaxlist/blocklistGeneric"))){
299 $this->dialog = new faxblocktabs($this->config,$this->config->data['TABS']['FAXBLOCKTABS'],$this->dn);
300 $this->dialog->delete();
301 $this->dialog = NULL;
302 del_lock ($this->dn);
303 } else {
304 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
305 }
306 }
308 /***************
309 Divlist dialog
310 ***************/
312 /* Check if there is a snapshot dialog open */
313 $base = $this->DivListBlocklist->selectedBase;
314 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
315 return($str);
316 }
318 /* Display dialog with system list */
319 $this->DivListBlocklist->parent = $this;
320 $this->DivListBlocklist->execute();
322 /* Add departments if subsearch is disabled */
323 if(!$this->DivListBlocklist->SubSearch){
324 $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase,3,1);
325 }
326 $this->reload();
327 $this->DivListBlocklist->setEntries($this->blocklists);
328 return($this->DivListBlocklist->Draw());
329 }
332 function list_get_selected_items()
333 {
334 $ids = array();
335 foreach($_POST as $name => $value){
336 if(preg_match("/^item_selected_[0-9]*$/",$name)){
337 $id = preg_replace("/^item_selected_/","",$name);
338 $ids[$id] = $id;
339 }
340 }
341 return($ids);
342 }
345 /* Return departments, that will be included within snapshot detection */
346 function get_used_snapshot_bases()
347 {
348 return(array(get_ou('blocklistou').$this->DivListBlocklist->selectedBase));
349 }
352 /* Reload the list of known blocklists */
353 function reload()
354 {
355 /* Init some vars */
356 $filter = $filter2 = "";
357 $base = $this->DivListBlocklist->selectedBase;
358 $Regex = $this->DivListBlocklist->Regex;
359 $SubSearch = $this->DivListBlocklist->SubSearch;
360 $ShowSendBocklists = $this->DivListBlocklist->ShowSendBocklists;
361 $ShowReceiveBlocklists = $this->DivListBlocklist->ShowReceiveBlocklists;
362 $Flags = GL_SIZELIMIT;
363 $res = $res2 = array();
365 /* Append subsearch to Flags */
366 if($SubSearch){
367 $Flags |= GL_SUBSEARCH;
368 }else{
369 $base = get_ou('blocklistou').$base;
370 }
372 /* Create filter */
373 if ($ShowSendBocklists){
374 $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))";
375 $res= get_list($filter, "gofaxlist", $base,array("*"), $Flags);
376 }
377 if ($ShowReceiveBlocklists){
378 $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))";
379 $res2= get_list($filter2, "gofaxlist", $base,array("*"), $Flags);
380 }
382 $this->blocklists = array_merge($res,$res2);
384 /* appen && sort */
385 $tmp=array();
386 foreach($this->blocklists as $tkey => $val ){
388 $acl = $this->ui ->get_permissions($base,"gofaxlist/blocklist");
389 if(preg_match("/r/",$acl)){
390 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
391 }
392 }
393 ksort($tmp);
394 $this->blocklists=array();
395 foreach($tmp as $val){
396 $this->blocklists[]=$val;
397 }
398 reset ($this->blocklists);
399 }
402 /* Save data to object */
403 function save_object()
404 {
405 $this->DivListBlocklist->save_object();
406 }
412 function copyPasteHandling_from_queue($s_action,$s_entry)
413 {
414 /* Check if Copy & Paste is disabled */
415 if(!is_object($this->CopyPasteHandler)){
416 return("");
417 }
419 /* Add a single entry to queue */
420 if($s_action == "cut" || $s_action == "copy"){
421 /* Cleanup object queue */
422 $this->CopyPasteHandler->cleanup_queue();
423 $dn = $this->blocklists[$s_entry]['dn'];
424 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"faxblocktabs","FAXBLOCKTABS","gofaxlist");
425 }
427 /* Add entries to queue */
428 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
430 /* Cleanup object queue */
431 $this->CopyPasteHandler->cleanup_queue();
433 /* Add new entries to CP queue */
434 foreach($this->list_get_selected_items() as $id){
435 $dn = $this->blocklists[$id]['dn'];
437 if($s_action == "copy_multiple"){
438 $this->CopyPasteHandler->add_to_queue($dn,"copy","faxblocktabs","FAXBLOCKTABS","gofaxlist");
439 }
440 if($s_action == "cut_multiple"){
441 $this->CopyPasteHandler->add_to_queue($dn,"cut","faxblocktabs","FAXBLOCKTABS","gofaxlist");
442 }
443 }
444 }
446 /* Start pasting entries */
447 if($s_action == "editPaste"){
448 $this->start_pasting_copied_objects = TRUE;
449 }
451 /* Return C&P dialog */
452 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
454 /* Get dialog */
455 $data = $this->CopyPasteHandler->execute();
456 $this->CopyPasteHandler->SetVar("base",$this->DivListBlocklist->selectedBase);
458 /* Return dialog data */
459 if(!empty($data)){
460 return($data);
461 }
462 }
464 /* Automatically disable status for pasting */
465 if(!$this->CopyPasteHandler->entries_queued()){
466 $this->start_pasting_copied_objects = FALSE;
467 }
468 return("");
469 }
471 }
472 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
473 ?>