3 require_once 'Pman.php';
5 class Pman_Core_MessagePreview extends Pman
7 var $masterTemplate = 'mail/MessagePreview.html';
15 if (HTML_FlexyFramework::get()->cli) {
18 $this->authUser = $this->getAuthUser();
19 if (!$this->authUser) {
25 function get($v, $opts=array())
28 if((empty($_REQUEST['_id']) && empty($_REQUEST['template_name']) )|| empty($_REQUEST['_table'])){
29 $this->jerr('Missing Options');
32 $mlq = DB_DataObject::factory($_REQUEST['_table']);
33 if (!empty($_REQUEST['template_name'])) {
34 $res = $mlq->get('name', $_REQUEST['template_name']);
36 $res = $mlq->get($_REQUEST['_id']);
39 $this->jerr("invalid id/name");
42 $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
45 if (isset($_REQUEST['ontable']) && !empty($_REQUEST['onid']) && !empty($_REQUEST['evtype'])) {
46 $tn = preg_replace('/[^a-z_]+/i', '', $_REQUEST['ontable']);
48 $t = DB_DataObject::factory($tn);
49 if (!is_a($t, 'DB_DataObject') && !is_a($t, 'PDO_DataObject')) {
50 $this->jerr("invalid URL");
52 if (!$t->get($_REQUEST['onid'])) {
53 $this->jerr("invalid id");
55 if (!method_exists($t,'notify'.$_REQUEST['evtype'])) {
56 $this->jerr("invalid evtype");
59 $m = 'notify'.$_REQUEST['evtype'];
60 $this->msg = (object)$t->$m('test@test.com', false, false, false);
61 // print_R($this->msg->mailer );
62 $this->msg->subject = $this->msg->headers['Subject'];
63 $this->msg->from_email = $mlq->from_email;
64 $this->msg->from_name = $mlq->from_name;
65 $this->msg->plaintext = $this->msg->mailer->textbody ;
66 $this->msg->bodytext = $this->msg->mailer->htmlbody;
67 $this->msg->rcpts = $this->msg->mailer->rcpts;
70 //$data->subject = $data['Subject;
79 $this->msg->rcpts = "send to <these@people>";
86 if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
87 $this->jerr('Missing Options');
90 if($_REQUEST['_table'] == 'core_email'){
91 $this->coreEmailSendTest();
94 $cn = DB_DataObject::factory('core_notify');
96 'evtype' => "{$_REQUEST['_table']}::SendPreviewEmail",
97 'onid' => $_REQUEST['_id'],
98 'ontable' => $_REQUEST['_table'],
99 'person_id' => $this->authUser->id,
100 'person_table' => 'Person',
101 'act_when' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE"),
102 'act_start' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE")
107 $sent = $cn->sendManual();
109 if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
110 $this->jerr($sent->getMessage());
113 $this->jok("SUCCESS");
116 $mid = $_REQUEST['_id'];
118 $mlq = DB_DataObject::factory($_REQUEST['_table']);
120 $mlq->get($_REQUEST['_id']);
123 'template' => $mlq->name,
124 'person' => $this->authUser
127 $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content);
129 if(!is_object($sent)){
130 $this->jok('SUCCESS');
133 $this->jerr('error!!:' . $sent->toString());
137 function coreEmailSendTest()
139 $core_email = DB_DataObject::factory('core_email');
141 if(!$core_email->get($_REQUEST['_id'])){
142 $this->jerr('Invalid Message ID');
145 if(empty($core_email->test_class)){
146 $this->jerr("[{$core_email->name}] does not has test class");
149 require_once "{$core_email->test_class}.php";
151 $cls = str_replace('/', '_', $core_email->test_class);
155 $method = "test_{$core_email->name}";
157 if(!method_exists($x, $method)){
158 $this->jerr("{$method} does not exists in {$cls}");
161 $content = $x->{$method}($this, $this->authUser);
163 $content['bcc'] = array();
167 $cn = DB_DataObject::factory('core_notify');
169 'evtype' => 'Core_email::testData',
170 'onid' => $_REQUEST['_id'],
171 'ontable' => $_REQUEST['_table'],
172 'person_id' => $this->authUser->id,
173 'person_table' => 'Person',
174 'act_when' => $cn->sqlValue("NOW()"),
175 'act_start' => $cn->sqlValue("NOW()")
180 $sent = $cn->sendManual();
182 if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
183 $this->jerr($sent->getMessage());
186 $this->jok("SUCCESS");
192 $sent = $core_email->send($content);
194 if(is_object($sent)){
195 $this->jerr("Error sending email - " . $sent->toString());
198 $this->jok('SUCCESS');