<?php

require_once dirname(__FILE__) . '/../include/check_method.php';
check_method(array('GET'));
require dirname(__FILE__) . '/../include/use_type.php';
require dirname(__FILE__) . '/../include/connectDB.php';
$range = '';
if (preg_match('/^lines=/', $_SERVER['HTTP_RANGE'])) {
    $range = explode('=', $_SERVER['HTTP_RANGE']);
    $range = explode(',', $range[1]);
    $range = ' LIMIT ' . (int) $range[0] . ',' . (int) $range[1];
}
$users = mysql_query("SELECT nickname FROM users {$range}") or die(mysql_error());
switch (use_type(array('text/plain', 'application/json'), true)) {
    case 'application/json':
        header('Content-Type: application/json; charset=utf-8');
        echo '[';
        $first = true;
        while ($user = mysql_fetch_assoc($users)) {
            if (!$first) {
                echo ',';
            } else {
                $first = false;
            }
            echo '"' . addslashes($user['nickname']) . '"';
        }
        echo ']' . "\n";
        break;
    case 'text/plain':
        /* This is a problem if we don't support text/html. Old browsers may get this */
        header('Content-Type: text/plain; charset=utf-8');
if (!$error && ($_GET['openid_url'] || $_GET['openid_identifier'])) {
    include dirname(__FILE__) . '/try_auth.php';
    exit;
}
if (!$_REQUEST['return_to'] && stristr($_SERVER['HTTP_REFERER'], 'wiki.theveeb.com')) {
    $_REQUEST['return_to'] = $_SERVER['HTTP_REFERER'];
}
require_once dirname(__FILE__) . '/../include/use_type.php';
require_once dirname(__FILE__) . '/../include/check_method.php';
check_method(array('GET'));
require dirname(__FILE__) . '/../include/processCookie.php';
if (!$error) {
    $error = $_GET['error'];
}
switch (use_type(array('application/xhtml+xml', 'text/html'), true)) {
    case 'text/html':
        $noxml = true;
    case 'application/xhtml+xml':
        $title = 'Login';
        require dirname(__FILE__) . '/../include/invisible_header.php';
        ?>
		<style type="text/css">
			#openid_form {
				text-align: center;
			}
			#openid_form_submit {
				font-size: 1.2em;
				margin-top: 1em;
			}
			label {
            mysql_query("INSERT INTO user_activity (user_id, verb, item, private, timestamp) VALUES ({$LOGIN_DATA['user_id']}, 'purchased', '{$package['package']}', {$LOGIN_DATA['private']}, " . time() . ")") or die(mysql_error());
        }
        header('Content-Type: text/plain; charset=utf-8');
        echo "OK\n";
        break;
    case 'HEAD':
    case 'GET':
        $fields = array();
        foreach ($_GET as $k => $v) {
            if (!preg_match('/^x?oauth/', $k) && $k != 'callback' && $k != 'accept') {
                $fields[] = $k;
            }
        }
        $title = $package['package'];
        require dirname(__FILE__) . '/../include/use_type.php';
        switch (use_type(array('application/xhtml+xml', 'text/html', 'application/json', 'text/plain', 'text/javascript', 'application/rss+xml'), true)) {
            case 'application/rss+xml':
                header('Content-Type: application/rss+xml; charset=utf-8');
                echo '<?xml version="1.0" encoding="utf-8" ?>';
                ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Recent Reviews for <?php 
                echo htmlspecialchars($package['name']);
                ?>
</title>
		<link>http://<?php 
                echo $_SERVER['HTTP_HOST'] . APPROOT;
                ?>
apps/<?php 
                $package['package'];