Beispiel #1
0
 function subscriberData(&$in, $p = array())
 {
     $defaults = array('prune' => true, 'active' => true, 'log' => true, 'ignore' => false, 'ignoreInactive' => true, 'skipReq' => false);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $pommo->requireOnce($GLOBALS['pommo']->_baseDir . 'inc/helpers/fields.php');
     $logger =& $pommo->_logger;
     $fields = PommoField::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] = PommoHelper::timeToStr($in[$id]);
                 }
                 $in[$id] = PommoHelper::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 ('), $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 = PommoHelper::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 = PommoMailing::make(array(), TRUE);
         $state['status'] = 1;
         $state['current_status'] = 'stopped';
         $state['command'] = 'restart';
         $state['charset'] = $state['list_charset'];
         $mailing = PommoHelper::arrayIntersect($state, $mailing);
         $code = PommoMailing::add($mailing);
         // populate queue
         $queue = array($key);
         if (!PommoMailCtl::queueMake($queue)) {
             $logger->addErr('Unable to Populate Queue');
         } else {
             if (!PommoMailCtl::spawn($pommo->_baseUrl . 'admin/mailings/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.'));
Beispiel #3
0
 function &stateInit($name = 'default', $defaults = array(), $source = array())
 {
     global $pommo;
     if (empty($pommo->_session['state'][$name])) {
         $pommo->_session['state'][$name] = $defaults;
     }
     $state =& $pommo->_session['state'][$name];
     if (empty($defaults)) {
         return $state;
     }
     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 = PommoHelper::arrayIntersect($state, $defaults);
     }
     return $state;
 }