if (!$is_own) {
    error_403();
}
$more = array();
if ($page = get_int32("page")) {
    $more['page'] = $page;
}
if ($when = get_str("when")) {
    $more['when'] = $when;
    $history_url .= urlencode($when) . "/";
    # TO DO: find some better heuristic for this number
    # besides "pull it out of my ass" (20120206/straup)
    $more['per_page'] = 100;
}
$more['inflate_locality'] = 1;
$rsp = privatesquare_checkins_for_user($owner, $more);
# TO DO: oh god...timezones :-(
if ($when) {
    list($start, $stop) = datetime_when_parse($more['when']);
    $GLOBALS['smarty']->assign("when", $when);
    $GLOBALS['smarty']->assign("start", $start);
    $GLOBALS['smarty']->assign("stop", $stop);
}
$status_map = privatesquare_checkins_status_map();
$GLOBALS['smarty']->assign_by_ref("status_map", $status_map);
$GLOBALS['smarty']->assign("pagination_url", $GLOBALS['cfg']['abs_root_url'] . $history_url);
$GLOBALS['smarty']->assign_by_ref("owner", $owner);
$GLOBALS['smarty']->assign_by_ref("is_own", $is_own);
$export_formats = privatesquare_export_valid_formats();
$GLOBALS['smarty']->assign("export_formats", array_keys($export_formats));
$geo_stats = privatesquare_checkins_utils_geo_stats($rsp['rows']);
function privatesquare_checkins_export_for_user(&$user, $more = array())
{
    $rows = array();
    $count_pages = null;
    $args = array('page' => 1, 'per_page' => 100);
    # Note the order of things here: don't overwrite
    # what we've set in $args above
    if (count($more)) {
        $args = array_merge($more, $args);
    }
    while (!isset($count_pages) || $args['page'] <= $count_pages) {
        if (!isset($count_pages)) {
            $count_pages = $rsp['pagination']['page_count'];
        }
        # per the above we may need to add a flag to *not* fetch
        # the full venue listing out of the database (20120226/straup)
        $rsp = privatesquare_checkins_for_user($user, $args, $more);
        $rows = array_merge($rows, $rsp['rows']);
        $args['page'] += 1;
    }
    return okay(array('rows' => $rows));
}