<?php
/**
 * Created by PhpStorm.
 * User: jedi
 * Date: 12/27/18
 * Time: 2:49 AM
 */

function auth(){
    if(!isset($_SERVER['PHP_AUTH_USER']))
        return false;
    if(!isset($_SERVER['PHP_AUTH_PW']))
        return false;
    if($_SERVER['PHP_AUTH_USER']!="c3cloc")
        return false;
    if($_SERVER['PHP_AUTH_PW']!="c3cloc")
        return false;
    return true;
}

function get_items(){
    global $mysqli;
    $res = $mysqli->query("SELECT * FROM items ORDER BY id ASC");
    $ret = array();
    while ($row = $res->fetch_assoc()) {
        $ret[] = $row;
    }
    return $ret;
}

if (!auth()) {
    header('WWW-Authenticate: Basic realm="C3CLOC"');
    header('HTTP/1.0 401 Unauthorized');
    exit;
} else {
    ?>
    <!--p>
        <?php
        $mysqli = new mysqli("localhost", "c3cloc", "lrE6AG74aoDBLy.y", "c3cloc");
        if ($mysqli->connect_errno) {
            echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }
        echo $mysqli->host_info . "\n";
        ?>
    </p>
    <hr>
    <p>
        <?php
        $res = $mysqli->query("SELECT id FROM items ORDER BY id ASC");

        echo "Result set order...\n";
        while ($row = $res->fetch_assoc()) {
            echo " id = " . $row['id'] . "\n";
        }
        ?>
    </p-->
    <?php

    include "templates/dashboard.php";
}
?>