3 require_once 'Pman.php';
5 class Pman_Core_MessagePreview extends Pman
7 var $masterTemplate = 'mail/MessagePreview.html';
11 if (HTML_FlexyFramework::get()->cli) {
14 $this->authUser = $this->getAuthUser();
15 if (!$this->authUser) {
21 function get($v, $opts=array())
24 if((empty($_REQUEST['_id']) && empty($_REQUEST['template_name']) )|| empty($_REQUEST['_table'])){
25 $this->jerr('Missing Options');
28 $mlq = DB_DataObject::factory($_REQUEST['_table']);
29 if (!empty($_REQUEST['template_name'])) {
30 $res = $mlq->get('name', $_REQUEST['template_name']);
32 $res = $mlq->get($_REQUEST['_id']);
35 $this->jerr("invalid id/name");
38 $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
41 if (isset($_REQUEST['ontable']) && !empty($_REQUEST['onid']) && !empty($_REQUEST['evtype'])) {
42 $tn = preg_replace('/[^a-z_]+/i', '', $_REQUEST['ontable']);
44 $t = DB_DataObject::factory($tn);
45 if (!is_a($t, 'DB_DataObject') && !is_a($t, 'PDO_DataObject')) {
46 $this->jerr("invalid URL");
48 if (!$t->get($_REQUEST['onid'])) {
49 $this->jerr("invalid id");
51 if (!method_exists($t,'notify'.$_REQUEST['evtype'])) {
52 $this->jerr("invalid evtype");
54 $m = 'notify'.$_REQUEST['evtype'];
55 $this->msg = (object)$t->$m('test@test.com', false, false, false);
56 // print_R($this->msg->mailer );
57 $this->msg->subject = $this->msg->headers['Subject'];
58 $this->msg->from_email = $mlq->from_email;
59 $this->msg->from_name = $mlq->from_name;
60 $this->msg->plaintext = $this->msg->mailer->textbody ;
61 $this->msg->bodytext = $this->msg->mailer->htmlbody;
62 $this->msg->rcpts = $this->msg->mailer->rcpts;
65 //$data->subject = $data['Subject;
74 $this->msg->rcpts = "send to <these@people>";
81 if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
82 $this->jerr('Missing Options');
85 if($_REQUEST['_table'] == 'core_email'){
86 $this->coreEmailSendTest();
89 $cn = DB_DataObject::factory('core_notify');
91 'evtype' => "{$_REQUEST['_table']}::SendPreviewEmail",
92 'onid' => $_REQUEST['_id'],
93 'ontable' => $_REQUEST['_table'],
94 'person_id' => $this->authUser->id,
95 'person_table' => 'Person',
96 'act_when' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE"),
97 'act_start' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE")
102 $sent = $cn->sendManual();
104 if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
105 $this->jerr($sent->getMessage());
108 $this->jok("SUCCESS");
111 $mid = $_REQUEST['_id'];
113 $mlq = DB_DataObject::factory($_REQUEST['_table']);
115 $mlq->get($_REQUEST['_id']);
118 'template' => $mlq->name,
119 'person' => $this->authUser
122 $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content);
124 if(!is_object($sent)){
125 $this->jok('SUCCESS');
128 $this->jerr('error!!:' . $sent->toString());
132 function coreEmailSendTest()
134 $core_email = DB_DataObject::factory('core_email');
136 if(!$core_email->get($_REQUEST['_id'])){
137 $this->jerr('Invalid Message ID');
140 if(empty($core_email->test_class)){
141 $this->jerr("[{$core_email->name}] does not has test class");
144 require_once "{$core_email->test_class}.php";
146 $cls = str_replace('/', '_', $core_email->test_class);
150 $method = "test_{$core_email->name}";
152 if(!method_exists($x, $method)){
153 $this->jerr("{$method} does not exists in {$cls}");
156 $content = $x->{$method}($this, $this->authUser);
158 $content['bcc'] = array();
162 $cn = DB_DataObject::factory('core_notify');
164 'evtype' => 'Core_email::testData',
165 'onid' => $_REQUEST['_id'],
166 'ontable' => $_REQUEST['_table'],
167 'person_id' => $this->authUser->id,
168 'person_table' => 'Person',
169 'act_when' => $cn->sqlValue("NOW()"),
170 'act_start' => $cn->sqlValue("NOW()")
175 $sent = $cn->sendManual();
177 if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
178 $this->jerr($sent->getMessage());
181 $this->jok("SUCCESS");
187 $sent = $core_email->send($content);
189 if(is_object($sent)){
190 $this->jerr("Error sending email - " . $sent->toString());
193 $this->jok('SUCCESS');