X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=MessagePreview.php;h=ec8cf6c69a68e7db93e6ce4b0ca78a5839a66fb9;hp=310bde57d4468e0cd309afa43efb65e466556b93;hb=HEAD;hpb=bd641c46f5dc2a024b9150517ee1728562754ab3 diff --git a/MessagePreview.php b/MessagePreview.php index 310bde57..384cdbd9 100644 --- a/MessagePreview.php +++ b/MessagePreview.php @@ -6,6 +6,10 @@ class Pman_Core_MessagePreview extends Pman { var $masterTemplate = 'mail/MessagePreview.html'; + + var $showHtml; + var $msg; + function getAuth() { if (HTML_FlexyFramework::get()->cli) { @@ -18,23 +22,66 @@ class Pman_Core_MessagePreview extends Pman return true; } - function get() + function get($v, $opts=array()) { - if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){ + + if((empty($_REQUEST['_id']) && empty($_REQUEST['template_name']) )|| empty($_REQUEST['_table'])){ $this->jerr('Missing Options'); } $mlq = DB_DataObject::factory($_REQUEST['_table']); + if (!empty($_REQUEST['template_name'])) { + $res = $mlq->get('name', $_REQUEST['template_name']); + } else { + $res = $mlq->get($_REQUEST['_id']); + } + if (!$res) { + $this->jerr("invalid id/name"); + } - $mlq->get($_REQUEST['_id']); + $this->showHtml = isset($_REQUEST['_as_html']) ? true : false; - $this->msg = $mlq; + + if (isset($_REQUEST['ontable']) && !empty($_REQUEST['onid']) && !empty($_REQUEST['evtype'])) { + $tn = preg_replace('/[^a-z_]+/i', '', $_REQUEST['ontable']); + + $t = DB_DataObject::factory($tn); + if (!is_a($t, 'DB_DataObject') && !is_a($t, 'PDO_DataObject')) { + $this->jerr("invalid URL"); + } + if (!$t->get($_REQUEST['onid'])) { + $this->jerr("invalid id"); + } + if (!method_exists($t,'notify'.$_REQUEST['evtype'])) { + $this->jerr("invalid evtype"); + } + + $m = 'notify'.$_REQUEST['evtype']; + $this->msg = (object)$t->$m('test@test.com', false, false, false); + // print_R($this->msg->mailer ); + $this->msg->subject = $this->msg->headers['Subject']; + $this->msg->from_email = $mlq->from_email; + $this->msg->from_name = $mlq->from_name; + $this->msg->plaintext = $this->msg->mailer->textbody ; + $this->msg->bodytext = $this->msg->mailer->htmlbody; + $this->msg->rcpts = $this->msg->mailer->rcpts; + // htmlbody + //$this->plaintext = + //$data->subject = $data['Subject; + + + - $this->showHtml = isset($_REQUEST['_as_html']) ? true : false; + return; + } + + $this->msg = $mlq; + $this->msg->rcpts = "send to "; + } - function post() + function post($v) { if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){ $this->jerr('Missing Options'); @@ -44,6 +91,28 @@ class Pman_Core_MessagePreview extends Pman $this->coreEmailSendTest(); } + $cn = DB_DataObject::factory('core_notify'); + $cn->setFrom(array( + 'evtype' => "{$_REQUEST['_table']}::SendPreviewEmail", + 'onid' => $_REQUEST['_id'], + 'ontable' => $_REQUEST['_table'], + 'person_id' => $this->authUser->id, + 'person_table' => 'Person', + 'act_when' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE"), + 'act_start' => $cn->sqlValue("NOW() + INTERVAL 10 MINUTE") + )); + + $cn->insert(); + + $sent = $cn->sendManual(); + + if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){ + $this->jerr($sent->getMessage()); + } + + $this->jok("SUCCESS"); + + /* $mid = $_REQUEST['_id']; $mlq = DB_DataObject::factory($_REQUEST['_table']); @@ -62,7 +131,7 @@ class Pman_Core_MessagePreview extends Pman } $this->jerr('error!!:' . $sent->toString()); - + */ } function coreEmailSendTest() @@ -88,9 +157,38 @@ class Pman_Core_MessagePreview extends Pman if(!method_exists($x, $method)){ $this->jerr("{$method} does not exists in {$cls}"); } - + /* $content = $x->{$method}($this, $this->authUser); + $content['bcc'] = array(); + */ + + + $cn = DB_DataObject::factory('core_notify'); + $cn->setFrom(array( + 'evtype' => 'Core_email::testData', + 'onid' => $_REQUEST['_id'], + 'ontable' => $_REQUEST['_table'], + 'person_id' => $this->authUser->id, + 'person_table' => 'Person', + 'act_when' => $cn->sqlValue("NOW()"), + 'act_start' => $cn->sqlValue("NOW()") + )); + + $cn->insert(); + + $sent = $cn->sendManual(); + + if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){ + $this->jerr($sent->getMessage()); + } + + $this->jok("SUCCESS"); + + + + + $sent = $core_email->send($content); if(is_object($sent)){