MessagePreview.php
[Pman.Core] / MessagePreview.php
index 161b830..53d70ee 100644 (file)
@@ -44,6 +44,21 @@ 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,
+            'act_when'  => $cn->sqlValue("NOW()"),
+            'act_start' => $cn->sqlValue("NOW()")
+        ));
+        
+        $cn->insert();
+        
+        $cn->sendManual();
+        
+        /*
         $mid = $_REQUEST['_id'];
         
         $mlq = DB_DataObject::factory($_REQUEST['_table']);
@@ -62,7 +77,7 @@ class Pman_Core_MessagePreview extends Pman
         }
         
         $this->jerr('error!!:' . $sent->toString());
-        
+        */
     }
     
     function coreEmailSendTest()
@@ -83,9 +98,20 @@ class Pman_Core_MessagePreview extends Pman
         
         $x = new $cls;
         
-        if(!method_exists($x, "test_{$core_email->name}")){
-            $this->jerr("Function test_{$core_email->name} does not exists");
+        $method = "test_{$core_email->name}";
+        
+        if(!method_exists($x, $method)){
+            $this->jerr("{$method} does not exists in {$cls}");
+        }
+
+        $content = $x->{$method}($this, $this->authUser);
+        
+        $sent = $core_email->send($content);
+        
+        if(is_object($sent)){
+            $this->jerr("Error sending email - " . $sent->toString());
         }
         
+        $this->jok('SUCCESS');
     }
 }