X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=MessagePreview.php;h=f59cde177e0f2f376661919f83a9a373777494a8;hp=52fee8de3c5d3ccec66a79f55af70807a17b26cb;hb=refs%2Fheads%2Fwip_alan_T5884_add_photo_to_report;hpb=0586ad0114cd4f19ae434e3fcdf101afea810d4f diff --git a/MessagePreview.php b/MessagePreview.php index 52fee8de..f59cde17 100644 --- a/MessagePreview.php +++ b/MessagePreview.php @@ -18,13 +18,13 @@ class Pman_Core_MessagePreview extends Pman return true; } - function get() + function get($v, $opts=array()) { - if(empty($_REQUEST['_id'])){ - $this->jerr('id got error'); + if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){ + $this->jerr('Missing Options'); } - $mlq = DB_DataObject::factory('core_mailing_list_message'); + $mlq = DB_DataObject::factory($_REQUEST['_table']); $mlq->get($_REQUEST['_id']); @@ -33,60 +33,94 @@ class Pman_Core_MessagePreview extends Pman $this->showHtml = isset($_REQUEST['_as_html']) ? true : false; } - - function post() + + function post($v) { if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){ $this->jerr('Missing Options'); } - $msg = DB_DataObject::factory($_REQUEST['_table']); - - $msg->get($_REQUEST['_id']); + if($_REQUEST['_table'] == 'core_email'){ + $this->coreEmailSendTest(); + } - $res = $msg->send(array( - 'person' => $this->authUser, - 'replace_links' => false, - + $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()"), + 'act_start' => $cn->sqlValue("NOW()") )); - - if(is_object($res)){ - return $this->jerr( "an error occured sending the email " . $res->toString() ); + + $cn->insert(); + + $sent = $cn->sendManual(); + + if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){ + $this->jerr($sent->getMessage()); } - $this->jok("success"); - - -// $mid = $_REQUEST['_id']; -// -// $cfg = HTML_FlexyFramework::get()->Pman_Crm; -// -// -// -// $q = DB_DataObject::factory('crm_mailing_list_queue'); -// $q->id = 'test-message-'. $mid; -// $q->message_id = $mid; -// $q->message_id_subject = $q->message()->subject; -// $q->message_id_from_email = $cfg['from_email']; -// $q->message_id_from_name = "Email Test"; -// -// $q->cachedMailWithOutImages(true); -// $r = $q->getMailerObject($this->authUser, false, false, true); -// //print_r($r->toData()); -// $ret = $r->toData(); -// $images = file_get_contents(session_save_path() . '/email-cache-' . getenv('APACHE_RUN_USER') . '/mail/' . $q->id . '-images.txt'); -// // var_dump($images);exit; -// -// $ret['body'] = str_replace('%Images%', $images, $ret['body']); -// -// $sent = $r->send($ret); -// if(!is_object($sent)){ -// $this->jok('SUCCESS'); -// } -// $this->jerr('error!!:' . $sent->toString()); + $this->jok("SUCCESS"); - } + /* + $mid = $_REQUEST['_id']; + + $mlq = DB_DataObject::factory($_REQUEST['_table']); + + $mlq->get($_REQUEST['_id']); + + $content = array( + 'template' => $mlq->name, + 'person' => $this->authUser + ); + $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content); + + if(!is_object($sent)){ + $this->jok('SUCCESS'); + } + + $this->jerr('error!!:' . $sent->toString()); + */ } + function coreEmailSendTest() + { + $core_email = DB_DataObject::factory('core_email'); + + if(!$core_email->get($_REQUEST['_id'])){ + $this->jerr('Invalid Message ID'); + } + + if(empty($core_email->test_class)){ + $this->jerr("[{$core_email->name}] does not has test class"); + } + + require_once "{$core_email->test_class}.php"; + + $cls = str_replace('/', '_', $core_email->test_class); + + $x = new $cls; + + $method = "test_{$core_email->name}"; + + if(!method_exists($x, $method)){ + $this->jerr("{$method} does not exists in {$cls}"); + } + + $content = $x->{$method}($this, $this->authUser); + + $content['bcc'] = array(); + + $sent = $core_email->send($content); + + if(is_object($sent)){ + $this->jerr("Error sending email - " . $sent->toString()); + } + + $this->jok('SUCCESS'); + } }