SimpleExcel.php
[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         if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
24             $this->jerr('Missing Options');
25         }
26         
27         $mlq = DB_DataObject::factory($_REQUEST['_table']);
28         
29         $mlq->get($_REQUEST['_id']);
30         
31         $this->msg = $mlq;
32
33         $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
34         
35     }
36     
37     function post($v)
38     {
39         if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
40             $this->jerr('Missing Options');
41         }
42         
43         if($_REQUEST['_table'] == 'core_email'){
44             $this->coreEmailSendTest();
45         }
46         
47         $cn = DB_DataObject::factory('core_notify');
48         $cn->setFrom(array(
49             'evtype'        => "{$_REQUEST['_table']}::SendPreviewEmail",
50             'onid'          => $_REQUEST['_id'],
51             'ontable'       => $_REQUEST['_table'],
52             'person_id'     => $this->authUser->id,
53             'person_table'  => 'Person',
54             'act_when'      => $cn->sqlValue("NOW()"),
55             'act_start'     => $cn->sqlValue("NOW()")
56         ));
57         
58         $cn->insert();
59         
60         $sent = $cn->sendManual();
61         
62         if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
63             $this->jerr($sent->getMessage());
64         }
65         
66         $this->jok("SUCCESS");
67         
68         /*
69         $mid = $_REQUEST['_id'];
70         
71         $mlq = DB_DataObject::factory($_REQUEST['_table']);
72         
73         $mlq->get($_REQUEST['_id']);
74         
75         $content = array(
76             'template' => $mlq->name,
77             'person' => $this->authUser
78         );
79         
80         $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content);
81         
82         if(!is_object($sent)){
83             $this->jok('SUCCESS');
84         }
85         
86         $this->jerr('error!!:' . $sent->toString());
87         */
88     }
89     
90     function coreEmailSendTest()
91     {
92         $core_email = DB_DataObject::factory('core_email');
93         
94         if(!$core_email->get($_REQUEST['_id'])){
95             $this->jerr('Invalid Message ID');
96         }
97         
98         if(empty($core_email->test_class)){
99             $this->jerr("[{$core_email->name}] does not has test class");
100         }
101         
102         require_once "{$core_email->test_class}.php";
103         
104         $cls = str_replace('/', '_', $core_email->test_class);
105         
106         $x = new $cls;
107         
108         $method = "test_{$core_email->name}";
109         
110         if(!method_exists($x, $method)){
111             $this->jerr("{$method} does not exists in {$cls}");
112         }
113
114         $content = $x->{$method}($this, $this->authUser);
115         
116         $content['bcc'] = array();
117         
118         $sent = $core_email->send($content);
119         
120         if(is_object($sent)){
121             $this->jerr("Error sending email - " . $sent->toString());
122         }
123         
124         $this->jok('SUCCESS');
125     }
126 }