function add(&$subscriber, $type = null)
{
global $pommo;
$dbo =& Pommo::$_dbo;
$logger =& Pommo::$_logger;
switch ($type) {
case 'add':
case 'del':
case 'change':
case 'password':
break;
default:
$logger->addErr('Unknown type passed to Pommo_Pending::add');
return false;
}
$p = array('subscriber_id' => $subscriber['id'], 'type' => $type, 'code' => Pommo_Helper::makeCode(), 'array' => $type == 'change' ? $subscriber : array());
$pending = Pommo_Pending::make($p);
if (!Pommo_Pending::validate($pending)) {
$logger->addErr('Pommo_Pending::add() failed validation');
return false;
}
if (!empty($pending['array'])) {
$pending['array'] = serialize($pending['array']);
}
// check for pre-existing pending request
if (Pommo_Pending::isPending($pending['subscriber_id'])) {
return false;
}
$query = "\n INSERT INTO " . $dbo->table['subscriber_pending'] . "\n SET\n [pending_array='%S',]\n subscriber_id=%i,\n pending_type='%s',\n pending_code='%s'";
$query = $dbo->prepare($query, array($pending['array'], $pending['subscriber_id'], $pending['type'], $pending['code']));
if (!$dbo->query($query)) {
return false;
}
return $pending['code'];
}