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; }
} // check for dupe $lookupID = current(Pommo_Subscribers::getIDByEmail($subscriber['email'], array(1, 2))); if ($lookupID && $lookupID != $subscriber['id']) { $json->fail(Pommo::_T('Email address already exists. Duplicates are not allowed.')); } if (!Pommo_Validate::subscriberData($subscriber['data'], $validateOptions) && !isset($_REQUEST['force'])) { $json->addErr(Pommo::_T('Fields failed validation') . " >>> "); $json->addErr($logger->getAll()); $json->fail(Pommo::_T('Error updating subscriber.')); } if (!Pommo_Subscribers::update($subscriber, 'REPLACE_ALL')) { $json->fail(Pommo::_T('Error updating subscriber.')); } // subscriber updated successfully, build output $out = array('email' => $subscriber['email'], 'id' => $subscriber['id']); // return human readable date formatting require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php'; $dateFields = Pommo_Fields::getByType('date'); foreach ($subscriber['data'] as $k => $val) { $out['d' . $k] = in_array($k, $dateFields) ? Pommo_Helper::timeToStr($val) : htmlspecialchars($val); } $json->add('callbackFunction', 'editSubscriber'); $json->add('callbackParams', $out); $json->addMsg(Pommo::_T('Subscriber Updated')); break; default: die('invalid request passed to ' . __FILE__); break; } $json->success();
<td><?php echo $this->logicNames[$logic_id]; ?> </td> <td> <ul> <?php $first = true; foreach ($values as $v) { if ($v) { if (!$first) { echo '<br />(' . _('or') . ')'; } if ('date' == $this->fields[$field_id]['type']) { echo Pommo_Helper::timeToStr($v); } else { echo $v; } } $first = false; } ?> </ul> </td> <td> <select onChange="poMMo.callback.updateRule({fieldID:'<?php echo $this->escape($field_id); ?> ',logic:'<?php
function smarty_modifier_pommoDateFormat($int) { return Pommo_Helper::timeToStr($int); }
public static function get($p = array(), $search = array('field' => null, 'string' => null)) { $defaults = array('status' => 'all', 'email' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null, 'id' => null); $p = Pommo_Api::getParams($defaults, $p); $dbo = Pommo::$_dbo; if ($p['status'] == 'all') { $p['status'] = null; } if (is_numeric($p['limit']) && !is_numeric($p['offset'])) { $p['offset'] = 0; } $o = array(); $query = "\n SELECT\n s.subscriber_id,\n s.email,\n s.time_touched,\n s.time_registered,\n s.flag,\n INET_NTOA(s.ip) ip,\n s.status,\n p.pending_code,\n p.pending_array,\n p.pending_type" . (is_numeric($p['sort']) ? ", d.value" : '') . (is_numeric($search['field']) ? ", search.value" : '') . " FROM " . $dbo->table['subscribers'] . " s\n LEFT JOIN " . $dbo->table['subscriber_pending'] . " p ON (s.subscriber_id = p.subscriber_id) " . (is_numeric($p['sort']) ? "LEFT JOIN (SELECT * FROM " . $dbo->table['subscriber_data'] . " WHERE field_id = " . (int) $p['sort'] . " ) AS d" . " ON (s.subscriber_id = d.subscriber_id)" : '') . (is_numeric($search['field']) ? "LEFT JOIN (SELECT value FROM " . $dbo->table['subscriber_data'] . " WHERE field_id = " . (int) $search['field'] . " ) AS search" . " ON (s.subscriber_id = search.subscriber_id)" : '') . " WHERE\n 1\n [AND s.subscriber_id IN(%C)]\n [AND s.status=%I]\n [AND s.email IN (%Q)]\n [AND %S LIKE '%%S%']\n [ORDER BY %S] [%S]\n [LIMIT %I, %I]"; // Check if we're sorting against a field. // If so, sort against the "value" column select. // If it's a numeric field, cast the value (string) as an Integer by the DBE for proper sorting. if (is_numeric($p['sort'])) { require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php'; $numericFields = Pommo_Fields::getByType(array('date', 'number')); $p['sort'] = in_array($p['sort'], $numericFields) ? 'CAST(value as SIGNED)' : 'value'; } // If we're searching/filtering, generate the proper SQL $searchSQL = NULL; if (!empty($search['field']) && !empty($search['string'])) { // make MySQL LIKE() compliant $search['string'] = addcslashes($search['string'], '%_'); $search['field'] = is_numeric($search['field']) ? 'search.value' : 's.' . $search['field']; } $query = $dbo->prepare($query, array($p['id'], $p['status'], $p['email'], $search['field'], $search['string'], $p['sort'], $p['order'], $p['offset'], $p['limit'])); while ($row = $dbo->getRows($query)) { $o[$row['subscriber_id']] = empty($row['pending_code']) ? Pommo_Subscribers::makeDB($row) : Pommo_Subscribers::makeDB($row, TRUE); } // fetch data if (!empty($o)) { // get any date fields for conversion. We can't use the MySQL 4.1/5 // engine, as it doesn't support negative timestamps... !!! require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php'; $dates = Pommo_Fields::getByType('date'); $query = "\n SELECT\n field_id,\n value,\n subscriber_id\n FROM\n " . $dbo->table['subscriber_data'] . "\n WHERE\n subscriber_id IN(%c)"; $query = $dbo->prepare($query, array(array_keys($o))); while ($row = $dbo->getRows($query)) { $o[$row['subscriber_id']]['data'][$row['field_id']] = in_array($row['field_id'], $dates) ? Pommo_Helper::timeToStr($row['value']) : $row['value']; } } return $o; }