static function &stateInit($name = 'default', $defaults = array(), $source = array()) { if (empty(Pommo::$_session['state'][$name])) { Pommo::$_session['state'][$name] =& $defaults; } $state =& Pommo::$_session['state'][$name]; if (empty($defaults)) { return $state; } //Add support for passing multi select options if (is_array($source)) { foreach ($source as $k => $v) { if (is_array($source[$k])) { $source[$k] = implode(',', $source[$k]); } } } foreach (array_keys($state) as $key) { if (array_key_exists($key, $source)) { $state[$key] = $source[$key]; } } // normalize the page state if (count($state) > count($defaults)) { $state = Pommo_Helper::arrayIntersect($state, $defaults); } return $state; }
function subscriberData(&$in, $p = array()) { $defaults = array('prune' => true, 'active' => true, 'log' => true, 'ignore' => false, 'ignoreInactive' => true, 'skipReq' => false); $p = Pommo_Api::getParams($defaults, $p); require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php'; $logger = Pommo::$_logger; $fields = Pommo_Fields::get(array('active' => $p['active'])); $valid = true; foreach ($fields as $id => $field) { $inactive = $field['active'] == 'on' ? false : true; if (!isset($in[$id]) && $p['skipReq']) { continue; } $in[$id] = @trim($in[$id]); if (empty($in[$id])) { unset($in[$id]); // don't include blank values if ($field['required'] == 'on') { if ($p['log']) { $logger->addErr(sprintf(Pommo::_T('%s is a required field.'), $field['prompt'])); } $valid = false; } continue; } // shorten $in[$id] = substr($in[$id], 0, 255); switch ($field['type']) { case "checkbox": if (strtolower($in[$id]) == 'true') { $in[$id] = 'on'; } if (strtolower($in[$id]) == 'false') { $in[$id] = ''; } if ($in[$id] != 'on' && $in[$id] != '') { if ($p['ignore'] || $inactive && $p['ignoreInactive']) { unset($in[$id]); break; } if ($p['log']) { $logger->addErr(sprintf(Pommo::_T('Illegal input for field %s.'), $field['prompt'])); } $valid = false; } break; case "multiple": if (is_array($in[$id])) { foreach ($in[$id] as $key => $val) { if (!in_array($val, $field['array'])) { if ($p['ignore'] || $inactive && $p['ignoreInactive']) { unset($in[$id]); break; } if ($p['log']) { $logger->addErr(sprintf(Pommo::_T('Illegal input for field %s.'), $field['prompt'])); } $valid = false; } } } elseif (!in_array($in[$id], $field['array'])) { if ($p['ignore'] || $inactive && $p['ignoreInactive']) { unset($in[$id]); break; } if ($p['log']) { $logger->addErr(sprintf(Pommo::_T('Illegal input for field %s.'), $field['prompt'])); } $valid = false; } break; case "date": // convert date to timestamp [float; using adodb time library] if (is_numeric($in[$id])) { $in[$id] = Pommo_Helper::timeToStr($in[$id]); } $in[$id] = Pommo_Helper::timeFromStr($in[$id]); if (!$in[$id]) { if ($p['ignore'] || $inactive && $p['ignoreInactive']) { unset($in[$id]); break; } if ($p['log']) { $logger->addErr(sprintf(Pommo::_T('Field (%s) must be a date (' . Pommo_Helper::timeGetFormat() . ').'), $field['prompt'])); } $valid = false; } break; case "number": if (!is_numeric($in[$id])) { if ($p['ignore'] || $inactive && $p['ignoreInactive']) { unset($in[$id]); break; } if ($p['log']) { $logger->addErr(sprintf(Pommo::_T('Field (%s) must be a number.'), $field['prompt'])); } $valid = false; } break; } } // prune if ($p['prune']) { $in = Pommo_Helper::arrayIntersect($in, $fields); } return $valid; }
$logger->addErr('Unable to Add Subscriber'); } else { // temp subscriber created $state['tally'] = 1; $state['group'] = Pommo::_T('Test Mailing'); if ($state['ishtml'] == 'off') { $state['body'] = $state['altbody']; $state['altbody'] = ''; } // create mailing $mailing = Pommo_Mailing::make(array(), TRUE); $state['status'] = 1; $state['current_status'] = 'stopped'; $state['command'] = 'restart'; $state['charset'] = $state['list_charset']; $mailing = Pommo_Helper::arrayIntersect($state, $mailing); $code = Pommo_Mailing::add($mailing); // populate queue $queue = array($key); if (!Pommo_Mail_Ctl::queueMake($queue)) { $logger->addErr('Unable to Populate Queue'); } else { if (!Pommo_Mail_Ctl::spawn(Pommo::$_baseUrl . 'ajax/mailings_send4.php?test=TRUE&code=' . $code)) { $logger->addErr('Unable to spawn background mailer'); } else { $smarty->assign('sent', $_POST['email']); } } } } elseif ($current) { $logger->addMsg(Pommo::_T('A mailing is currently taking place. Please try again later.'));