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 = Pommo::$_logger; $dbo = Pommo::$_dbo; $dupes = $tally = $flagged = 0; $dupe_emails = array(); $fp = fopen(Pommo::$_workDir . '/import.csv', 'r') or die('Unable to open CSV file'); $includeUnsubscribed = isset($_REQUEST['excludeUnsubscribed']) ? false : true; while (($row = fgetcsv($fp, 2048, ',', '"')) !== FALSE) { $subscriber = array('email' => false, 'registered' => time(), 'ip' => $_SERVER['REMOTE_ADDR'], 'status' => 1, 'data' => array()); foreach ($row as $key => $col) { $fid =& $_POST['f'][$key]; if (is_numeric($fid)) { $subscriber['data'][$fid] = $col; } elseif ($fid == 'email' && Pommo_Helper::isEmail($col)) { $subscriber['email'] = $col; } elseif ($fid == 'registered') { $subscriber['registered'] = Pommo_Helper::timeFromStr($col); } elseif ($fid == 'ip') { $subscriber['ip'] = $col; } } if ($subscriber['email']) { // check for dupe // TODO -- DO THIS IN BATCH ?? if (Pommo_Helper::isDupe($subscriber['email'], $includeUnsubscribed)) { $dupes++; $dupe_emails[] = $subscriber['email']; continue; } // validate/fix data if (!Pommo_Validate::subscriberData($subscriber['data'], array('log' => false, 'ignore' => true, 'active' => false))) { $subscriber['flag'] = 9;
function addFieldRule(&$group, &$field, &$logic, &$values, $type = 0) { global $pommo; $dbo =& Pommo::$_dbo; $type = $type == 'or' ? 1 : 0; // remove previous filters Pommo_Rules::deleteRule($group, $field, $logic); // get the field require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php'; $field = current(Pommo_Fields::get(array('id' => $field))); foreach ($values as $value) { // if this is a date type field, convert the values from human readable date // strings to timestamps appropriate for matching if ($field['type'] == 'date') { $value = Pommo_Helper::timeFromStr($value); } $v[] = $dbo->prepare("(%i,%i,'%s','%s',%i)", array($group, $field['id'], $logic, $value, $type)); } $query = "\n\t\t\tINSERT INTO " . $dbo->table['group_rules'] . "\n\t\t\t(group_id, field_id, logic, value, type)\n\t\t\tVALUES " . implode(',', $v); return $dbo->affected($query); }
require_once Pommo::$_baseDir . 'classes/Pommo_Template.php'; $smarty = new Pommo_Template(); $group = current(Pommo_Groups::get(array('id' => $state['group']))); if (empty($group)) { die('invalid input'); } if ($_REQUEST['ruleType'] == 'field') { $field = current(Pommo_Fields::get(array('id' => $_REQUEST['fieldID']))); $logic = isset($_REQUEST['logic']) && $_REQUEST['logic'] != "0" ? $_REQUEST['logic'] : false; $type = $_REQUEST['type'] == 'or' ? 'or' : 'and'; $values = array(); // check to see if we're editing [logic is passed *only* when edit button is clicked] if ($logic) { foreach ($group['rules'] as $rule) { if ($rule['logic'] == $logic && $rule['field_id'] == $_REQUEST['fieldID']) { $values[] = $field['type'] == 'date' ? Pommo_Helper::timeFromStr($rule['value']) : $rule['value']; } } } $firstVal = empty($values) ? false : array_shift($values); $logic = $logic ? Pommo_Rules::getEnglish(array($logic)) : Pommo_Rules::getEnglish(end(Pommo_Rules::getLegal($group, array($field)))); $smarty->assign('type', $type); $smarty->assign('field', $field); $smarty->assign('logic', $logic); $smarty->assign('values', $values); $smarty->assign('firstVal', $firstVal); $smarty->display('ajax/rule.field.tpl'); Pommo::kill(); } elseif ($_REQUEST['ruleType'] == 'group') { $match = Pommo_Groups::getNames($_REQUEST['fieldID']); $key = key($match);