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");
58 $m = 'notify'.$_REQUEST['evtype'];
59 $this->msg = (object)$t->$m('test@test.com', false, false, false);
60 // print_R($this->msg->mailer );
61 $this->msg->subject = $this->msg->headers['Subject'];
62 $this->msg->from_email = $mlq->from_email;
63 $this->msg->from_name = $mlq->from_name;
64 $this->msg->plaintext = $this->msg->mailer->textbody ;
65 $this->msg->bodytext = $this->msg->mailer->htmlbody;
66 $this->msg->rcpts = $this->msg->mailer->rcpts;
69 //$data->subject = $data['Subject;
78 $this->msg->rcpts = "send to <these@people>";
85 if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
86 $this->jerr('Missing Options');
89 if($_REQUEST['_table'] == 'core_email'){
90 $this->coreEmailSendTest();
93 $cn = DB_DataObject::factory('core_notify');
95 'evtype' => "{$_REQUEST['_table']}::SendPreviewEmail",
96 'onid' => $_REQUEST['_id'],
97 'ontable' => $_REQUEST['_table'],
98 'person_id' => $this->authUser->id,
99 'person_table' => 'Person',
100 'act_when' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE"),
101 'act_start' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE")
106 $sent = $cn->sendManual();
108 if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
109 $this->jerr($sent->getMessage());
112 $this->jok("SUCCESS");
115 $mid = $_REQUEST['_id'];
117 $mlq = DB_DataObject::factory($_REQUEST['_table']);
119 $mlq->get($_REQUEST['_id']);
122 'template' => $mlq->name,
123 'person' => $this->authUser
126 $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content);
128 if(!is_object($sent)){
129 $this->jok('SUCCESS');
132 $this->jerr('error!!:' . $sent->toString());
136 function coreEmailSendTest()
138 $core_email = DB_DataObject::factory('core_email');
140 if(!$core_email->get($_REQUEST['_id'])){
141 $this->jerr('Invalid Message ID');
144 if(empty($core_email->test_class)){
145 $this->jerr("[{$core_email->name}] does not has test class");
148 require_once "{$core_email->test_class}.php";
150 $cls = str_replace('/', '_', $core_email->test_class);
154 $method = "test_{$core_email->name}";
156 if(!method_exists($x, $method)){
157 $this->jerr("{$method} does not exists in {$cls}");
160 $content = $x->{$method}($this, $this->authUser);
162 $content['bcc'] = array();
166 $cn = DB_DataObject::factory('core_notify');
168 'evtype' => 'Core_email::testData',
169 'onid' => $_REQUEST['_id'],
170 'ontable' => $_REQUEST['_table'],
171 'person_id' => $this->authUser->id,
172 'person_table' => 'Person',
173 'act_when' => $cn->sqlValue("NOW()"),
174 'act_start' => $cn->sqlValue("NOW()")
179 $sent = $cn->sendManual();
181 if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
182 $this->jerr($sent->getMessage());
185 $this->jok("SUCCESS");
191 $sent = $core_email->send($content);
193 if(is_object($sent)){
194 $this->jerr("Error sending email - " . $sent->toString());
197 $this->jok('SUCCESS');