* @since Version 2.0 */ class cmsMailEngine { public $DIR; public $uriData; public $controller; /** * Class constructor */ public function __construct($uriData, $DIR = false) { $this->uriData = $uriData; $this->DIR = $DIR; if (!$DIR) $this->DIR = __DIR__ ? __DIR__ : dirname(__FILE__); $this->controller = new cmsMailEngineController($this->uriData, $this->DIR, basename($this->DIR)); } /** * Default function to run * Skip if other callback defined */ public function run() { $action = getV('action'); if($action){ switch ($action) { case 'filter_table': cJSON::sendOk($this->controller->createCmsTable(getP('page'), getP('filter'), getP('headers'))); break; case 'selfLoad': cJSON::sendOk($this->controller->editCmsTableRecord(getV('id'))); break; case 'selfSave': if(getV('id')){ if($this->controller->oUser->chkPermission('CMS_MAILENGINE_EDIT', false, false)){ cJSON::sendOk($this->controller->saveRecordData(getV('id'), getP('fields'))); }else{ cJSON::sendError(); } }else{ if($this->controller->oUser->chkPermission('CMS_MAILENGINE_ADD_NEW', false, false)){ cJSON::sendOk($this->controller->saveRecordData(getV('id'), getP('fields'))); }else{ cJSON::sendError(); } } break; case 'deleteRecords': if($this->controller->oUser->chkPermission('CMS_MAILENGINE_DELETE')){ cJSON::sendOk($this->controller->delete(getP('fields'))); } break; case 'changeRecordsStatus': if($this->controller->oUser->chkPermission('CMS_MAILENGINE_EDIT')){ cJSON::sendOk($this->controller->changeEnumFields(getP('baseField'), getP('fields'))); } break; case 'qmail': $this->controller->showMail(getG('id')); break; case 'send': if($this->controller->oUser->chkPermission('CMS_MAILENGINE_SEND_NOW')){ if($rows = cJSON::decode(getP('fields'), true)){ $rows = $this->controller->module->db->prepData($rows); cJSON::sendOk(array('data' => $this->controller->pushMail(array_pop($rows), false, true))); } } break; case 'istopall': if($this->controller->oUser->chkPermission('CMS_MAILENGINE_ADD_NEW')){ cJSON::sendOk($this->controller->stopAllNewEmails()); } break; case 'iresumeall': if($this->controller->oUser->chkPermission('CMS_MAILENGINE_ADD_NEW')){ cJSON::sendOk($this->controller->resumeAllNewEmails()); } break; default: $this->controller->run(); break; } }else{ $this->controller->run(); } } /** * Show sent mails */ public function sentMailsAction($display = false) { $this->controller->history = true; $this->controller->module->table = cmsMailEngineController::SENT_MAIL_TABLE; if($display) $this->run(); } /** * Show sent mails */ public function outgoingMailsAction() { $this->controller->history = false; $this->controller->module->table = cmsMailEngineController::OUTGOING_MAIL_TABLE; $this->run(); } }