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) {
23 if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
24 $this->jerr('Missing Options');
27 $mlq = DB_DataObject::factory($_REQUEST['_table']);
29 $mlq->get($_REQUEST['_id']);
33 $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
39 if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
40 $this->jerr('Missing Options');
43 if($_REQUEST['_table'] == 'core_email'){
44 $this->coreEmailSendTest();
47 $cn = DB_DataObject::factory('core_notify');
49 'evtype' => "{$_REQUEST['_table']}::SendPreviewEmail",
50 'onid' => $_REQUEST['_id'],
51 'ontable' => $_REQUEST['_table'],
52 'person_id' => $this->authUser->id,
53 'person_table' => 'Person',
54 'act_when' => $cn->sqlValue("NOW()"),
55 'act_start' => $cn->sqlValue("NOW()")
63 $mid = $_REQUEST['_id'];
65 $mlq = DB_DataObject::factory($_REQUEST['_table']);
67 $mlq->get($_REQUEST['_id']);
70 'template' => $mlq->name,
71 'person' => $this->authUser
74 $sent = DB_DataObject::factory($_REQUEST['_table'])->send($content);
76 if(!is_object($sent)){
77 $this->jok('SUCCESS');
80 $this->jerr('error!!:' . $sent->toString());
84 function coreEmailSendTest()
86 $core_email = DB_DataObject::factory('core_email');
88 if(!$core_email->get($_REQUEST['_id'])){
89 $this->jerr('Invalid Message ID');
92 if(empty($core_email->test_class)){
93 $this->jerr("[{$core_email->name}] does not has test class");
96 require_once "{$core_email->test_class}.php";
98 $cls = str_replace('/', '_', $core_email->test_class);
102 $method = "test_{$core_email->name}";
104 if(!method_exists($x, $method)){
105 $this->jerr("{$method} does not exists in {$cls}");
108 $content = $x->{$method}($this, $this->authUser);
110 $sent = $core_email->send($content);
112 if(is_object($sent)){
113 $this->jerr("Error sending email - " . $sent->toString());
116 $this->jok('SUCCESS');