Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/groups.php'); $pommo->init(); $logger =& $pommo->_logger; $dbo =& $pommo->_dbo; $pommo->toggleEscaping(TRUE); $state =& PommoAPI::stateInit('subscribers_manage'); $fields = PommoField::get(); $ids = FALSE; if (!empty($_POST['ids'])) { $ids = explode(',', $_POST['ids']); } // ====== CSV EXPORT ====== if ($_POST['type'] == 'csv') { if (!$ids) { $group = new PommoGroup($state['group'], $state['status']); $subscribers = $group->members(); } else { $subscribers = PommoSubscriber::get(array('id' => $ids)); } // supply headers $o = '"' . Pommo::_T('Email') . '"'; if (!empty($_POST['registered'])) { $o .= ',"' . Pommo::_T('Date Registered') . '"'; } if (!empty($_POST['ip'])) { $o .= ',"' . Pommo::_T('IP Address') . '"'; } foreach ($fields as $f) { $o .= ",\"{$f['name']}\""; } $o .= "\r\n";
// Calculate the offset $start = $state['limit'] * $state['page'] - $state['limit']; if ($start < 0) { $start = 0; } /********************************** RECORD RETREVIAL *********************************/ // Normalize sort column to match DB column if ($state['sort'] == 'registered' || $state['sort'] == 'touched') { $state['sort'] = 'time_' . $state['sort']; } elseif (substr($state['sort'], 0, 1) == 'd') { $state['sort'] = substr($state['sort'], 1); } // fetch subscribers for this page $subscribers = $group->members(array('sort' => $state['sort'], 'order' => $state['order'], 'limit' => $state['limit'], 'offset' => $start)); /********************************** OUTPUT FORMATTING *********************************/ // format subscribers for JSON output to jqGrid $subOut = array(); foreach ($subscribers as $s) { $sub = array('id' => $s['id'], 'email' => $s['email'], 'touched' => $s['touched'], 'registered' => $s['registered'], 'ip' => $s['ip']); foreach ($s['data'] as $key => $d) { $sub['d' . $key] = $d; } array_push($subOut, $sub); } $json->add(array('page' => $state['page'], 'total' => $state['pages'], 'records' => $group->_tally, 'rows' => $subOut)); $json->serve(); ?>