hide popup message if failure is handled - not sure what knock on effect this may...
[Pman.Core] / VerifyAccess.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Core_VerifyAccess extends Pman
6 {
7     var $masterTemplate = 'master-verify-ip-access.html';
8     
9     /*
10      * This is a public page
11      */
12     function getAuth() 
13     {
14         return true;
15     }
16     
17     function get($id='', $opts = array())
18     {
19         @list($id, $key) = explode('/', $id);
20         
21         if(empty($id) || empty($key)){
22             $this->jerr('Invalid URL');
23         }
24         
25         $core_ip_access = DB_DataObject::factory('core_ip_access');
26         
27         if(!$core_ip_access->get($id) || $core_ip_access->authorized_key != $key){
28             $this->jerr('This URL is broken');
29         }
30         
31         $ff = HTML_FlexyFramework::get();
32         
33         if(empty($ff->Pman['ip_management']) || empty($ff->Pman['XMPP']) || empty($ff->Pman['XMPP']['to'])) {
34             $this->jerr('[System Error] This site does not using IP management');
35         }
36         
37 //        $ff->Pman['XMPP']['to'] = 'edward@roojs.com'; // testing...
38         
39         $core_person = DB_DataObject::factory('core_person');
40         
41         if(!$core_person->get('email', $ff->Pman['XMPP']['to'])) {
42             $this->jerr('[System Error] Please setup the XMPP correctly');
43         }
44         
45         return;
46         
47     }
48     
49     function post($base)
50     {
51         $core_ip_access = DB_DataObject::factory('core_ip_access');
52         
53         if(
54                 empty($_REQUEST['id']) || 
55                 empty($_REQUEST['authorized_key']) ||
56                 !$core_ip_access->get($_REQUEST['id']) ||
57                 $core_ip_access->authorized_key != $_REQUEST['authorized_key']
58         ){                 
59             $this->jerr('Invalid URL');
60         }
61         
62         if(!empty($_REQUEST['_to_data'])){
63             $this->jdata($core_ip_access->toArray());
64         }
65         
66         $ff = HTML_FlexyFramework::get();
67         
68         if(empty($ff->Pman['ip_management']) || empty($ff->Pman['XMPP']) || empty($ff->Pman['XMPP']['to'])) {
69             $this->jerr('[System Error] This site does not using IP management');
70         }
71         
72 //        $ff->Pman['XMPP']['to'] = 'edward@roojs.com'; // testing...
73         
74         $core_person = DB_DataObject::factory('core_person');
75         
76         if(!$core_person->get('email', $ff->Pman['XMPP']['to'])) {
77             $this->jerr('[System Error] Please setup the XMPP correctly');
78         }
79         
80         $o = clone($core_ip_access);
81         
82         $core_ip_access->setFrom(array(
83             'status' => empty($_REQUEST['status']) ? 0 : $_REQUEST['status'],
84             'expire_dt' => ($_REQUEST['status'] != -2 || empty($_REQUEST['expire_dt'])) ? '' : date('Y-m-d', strtotime($_REQUEST['expire_dt'])),
85             'authorized_by' => $core_person->id
86         ));
87         
88         $core_ip_access->update($o);
89         
90         $this->jok('OK');
91         
92     }
93     
94     
95 }