JSON OUTPUT INITIALIZATION *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/json.php'); $json = new PommoJSON(); // EXAMINE CALL switch ($_REQUEST['call']) { case 'wysiwyg': // update wysiwyg ++ state $wysiwyg = isset($_REQUEST['enable']) ? 'on' : 'off'; $pommo->_session['state']['mailing']['wysiwyg'] = $wysiwyg; PommoAPI::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': Pommo::requireOnce($pommo->_baseDir . 'inc/lib/lib.html2txt.php'); $h2t =& new html2text($_REQUEST['body']); $json->add('altbody', $h2t->get_text()); break; case 'getTemplateDescription': Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/templates.php'); $template = PommoMailingTemplate::getDescriptions(array('id' => $_REQUEST['id'])); $msg = empty($template[$_REQUEST['id']]) ? 'Aucune' : $template[$_REQUEST['id']]; die($msg); default: $json->fail(); break; } $json->success();
Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $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 = PommoMailingTemplate::make(array('name' => $_POST['name'], 'description' => $_POST['description'], 'body' => $pommo->_session['state']['mailing']['body'], 'altbody' => $pommo->_session['state']['mailing']['altbody'])); $id = PommoMailingTemplate::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();
$logger =& $pommo->_logger; $dbo =& $pommo->_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->prepareForForm(); /********************************** JSON OUTPUT INITIALIZATION *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/json.php'); $json = new PommoJSON(); $success = false; if (isset($_POST['skip']) || isset($_POST['template']) && !is_numeric($_POST['template'])) { $success = true; } elseif (isset($_POST['load'])) { $template = current(PommoMailingTemplate::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 = PommoMailingTemplate::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 { $smarty->assign('templates', PommoMailingTemplate::getNames()); $smarty->display('admin/mailings/mailing/templates.tpl'); Pommo::kill(); } $json->serve($success);
function add(&$in) { global $pommo; $dbo =& $pommo->_dbo; if (!PommoMailingTemplate::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; }