}
// 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();