hide popup message if failure is handled - not sure what knock on effect this may...
[Pman.Core] / MessagePreview.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Core_MessagePreview extends Pman
6 {
7     var $masterTemplate = 'mail/MessagePreview.html';
8     
9     function getAuth()
10     {
11         if (HTML_FlexyFramework::get()->cli) {
12             return true;
13         }
14         $this->authUser = $this->getAuthUser();
15         if (!$this->authUser) {
16             return false;
17         }
18         return true;
19     }
20     
21     function get($v, $opts=array())
22     {
23  
24         if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
25             $this->jerr('Missing Options');
26         }
27         
28         $mlq = DB_DataObject::factory($_REQUEST['_table']);
29         
30         $mlq->get($_REQUEST['_id']);
31         
32         $this->msg = $mlq;
33
34         $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
35         
36     }
37     
38     function post($v)
39     {
40         if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
41             $this->jerr('Missing Options');
42         }
43         
44         if($_REQUEST['_table'] == 'core_email'){
45             $this->coreEmailSendTest();
46         }
47         
48         $cn = DB_DataObject::factory('core_notify');
49         $cn->setFrom(array(
50             'evtype'        => "{$_REQUEST['_table']}::SendPreviewEmail",
51             'onid'          => $_REQUEST['_id'],
52             'ontable'       => $_REQUEST['_table'],
53             'person_id'     => $this->authUser->id,
54             'person_table'  => 'Person',
55             'act_when'      => $cn->sqlValue("NOW()"),
56             'act_start'     => $cn->sqlValue("NOW()")
57         ));
58         
59         $cn->insert();
60         
61         $sent = $cn->sendManual();
62         
63         if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
64             $this->jerr($sent->getMessage());
65         }
66         
67         $this->jok("SUCCESS");
68         
69         /*
70         $mid = $_REQUEST['_id'];
71         
72         $mlq = DB_DataObject::factory($_REQUEST['_table']);
73         
74         $mlq->get($_REQUEST['_id']);
75         
76         $content = array(
77             'template' => $mlq->name,
78             'person' => $this->authUser
79         );
80         
81         $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content);
82         
83         if(!is_object($sent)){
84             $this->jok('SUCCESS');
85         }
86         
87         $this->jerr('error!!:' . $sent->toString());
88         */
89     }
90     
91     function coreEmailSendTest()
92     {
93         $core_email = DB_DataObject::factory('core_email');
94         
95         if(!$core_email->get($_REQUEST['_id'])){
96             $this->jerr('Invalid Message ID');
97         }
98         
99         if(empty($core_email->test_class)){
100             $this->jerr("[{$core_email->name}] does not has test class");
101         }
102         
103         require_once "{$core_email->test_class}.php";
104         
105         $cls = str_replace('/', '_', $core_email->test_class);
106         
107         $x = new $cls;
108         
109         $method = "test_{$core_email->name}";
110         
111         if(!method_exists($x, $method)){
112             $this->jerr("{$method} does not exists in {$cls}");
113         }
114
115         $content = $x->{$method}($this, $this->authUser);
116         
117         $content['bcc'] = array();
118         
119         $sent = $core_email->send($content);
120         
121         if(is_object($sent)){
122             $this->jerr("Error sending email - " . $sent->toString());
123         }
124         
125         $this->jok('SUCCESS');
126     }
127 }