Pommo::init(); $logger = Pommo::$_logger; $dbo = Pommo::$_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ require_once Pommo::$_baseDir . 'classes/Pommo_Template.php'; $view = new Pommo_Template(); /********************************** JSON OUTPUT INITIALIZATION *********************************/ require_once Pommo::$_baseDir . 'classes/Pommo_Json.php'; $json = new Pommo_Json(); $success = false; if (isset($_POST['skip']) || isset($_POST['template']) && !is_numeric($_POST['template'])) { $success = true; } elseif (isset($_POST['load'])) { $template = current(Pommo_Mailing_Template::get(array('id' => $_POST['template']))); Pommo::$_session['state']['mailing']['body'] = $template['body']; Pommo::$_session['state']['mailing']['altbody'] = $template['altbody']; $success = true; } elseif (isset($_POST['delete'])) { $msg = Pommo_Mailing_Template::delete($_POST['template']) ? Pommo::_T('Template Deleted') : Pommo::_T('Error with deletion.'); $json->add('callbackFunction', 'deleteTemplate'); $json->add('callbackParams', array('id' => $_POST['template'], 'msg' => $msg)); } else { $view->assign('templates', Pommo_Mailing_Template::getNames()); $view->display('admin/mailings/mailing/templates'); Pommo::kill(); } $json->serve($success);
JSON OUTPUT INITIALIZATION *********************************/ require_once Pommo::$_baseDir . 'classes/Pommo_Json.php'; $json = new Pommo_Json(); // EXAMINE CALL switch ($_REQUEST['call']) { case 'wysiwyg': // update wysiwyg ++ state $wysiwyg = isset($_REQUEST['enable']) ? 'on' : 'off'; Pommo::$_session['state']['mailing']['wysiwyg'] = $wysiwyg; Pommo_Api::configUpdate(array('list_wysiwyg' => $wysiwyg), true); break; case 'savebody': Pommo::$_session['state']['mailing']['body'] = $_REQUEST['body']; Pommo::$_session['state']['mailing']['altbody'] = $_REQUEST['altbody']; break; case 'altbody': require_once Pommo::$_baseDir . 'lib/lib.html2txt.php'; $h2t =& new html2text($_REQUEST['body']); $json->add('altbody', $h2t->get_text()); break; case 'getTemplateDescription': require_once Pommo::$_baseDir . 'classes/Pommo_Mailing_Template.php'; $template = Pommo_Mailing_Template::getDescriptions(array('id' => $_REQUEST['id'])); $msg = empty($template[$_REQUEST['id']]) ? 'Unknown' : $template[$_REQUEST['id']]; die($msg); default: $json->fail(); break; } $json->success();
require_once Pommo::$_baseDir . 'classes/Pommo_Template.php'; $smarty = new Pommo_Template(); $smarty->prepareForForm(); if (!SmartyValidate::is_registered_form() || empty($_POST)) { // ___ USER HAS NOT SENT FORM ___ SmartyValidate::connect($smarty, true); SmartyValidate::register_validator('name', 'name', 'notEmpty', false, false, 'trim'); SmartyValidate::register_validator('description', 'description', 'dummyValid', false, false, 'trim'); $vMsg = array(); $vMsg['name'] = Pommo::_T('Cannot be empty.'); $smarty->assign('vMsg', $vMsg); } else { // ___ USER HAS SENT FORM ___ SmartyValidate::connect($smarty); if (SmartyValidate::is_valid($_POST)) { // __ FORM IS VALID $t = Pommo_Mailing_Template::make(array('name' => $_POST['name'], 'description' => $_POST['description'], 'body' => Pommo::$_session['state']['mailing']['body'], 'altbody' => Pommo::$_session['state']['mailing']['altbody'])); $id = Pommo_Mailing_Template::add($t); if ($id) { $logger->addMsg(sprintf(Pommo::_T('Template %s saved.'), '<strong>' . $_POST['name'] . '</strong>')); $smarty->assign('success', true); } else { $logger->addMsg(Pommo::_T('Error with addition.')); } } else { // __ FORM NOT VALID $logger->addMsg(Pommo::_T('Please review and correct errors with your submission.')); } } $smarty->display('admin/mailings/mailing/ajax.addtemplate.tpl'); Pommo::kill();
function add(&$in) { global $pommo; $dbo =& Pommo::$_dbo; if (!Pommo_Mailing_Template::validate($in)) { return false; } $query = "\n\t\t\tINSERT INTO " . $dbo->table['templates'] . "\n\t\t\tSET\n\t\t\t[description='%S',]\n\t\t\t[body='%S',]\n\t\t\t[altbody='%S',]\n\t\t\tname='%s'"; $query = $dbo->prepare($query, @array($in['description'], $in['body'], $in['altbody'], $in['name'])); // fetch new subscriber's ID $id = $dbo->lastId($query); return !$id ? false : $id; }