<?PHP
/*
 * T-Rex is Lonely: A web comic?
 * This code is not intended for general consumption, but is available if you
 * want it.
 *
 * Copyright (C) 2009 Gregor Richards
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

require_once("lib/db.php");
require_once(
"lib/src.php");
openDB();
if (!isset(
$private)) $private false;
$creator false;
if (isset(
$_REQUEST["creator"])) {
    
$creator $db->escapeString($_REQUEST["creator"]);
}

?>
<!doctype html>
<html>
<head>
<title>T-Rex is Lonely Comics</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="StyleSheet" href="trilc.css" type="text/css"/>
</head>
<body>
    <p>
        <span class="header">T-Rex is Lonely</span><br/>
        Archives
    </p>

    <div class="main">
        <p class="notice"><a href="/">Back</a></p>

<?PHP
if ($creator !== false) {
    print 
"<span class='heading'>Munged by " htmlentities($_REQUEST["creator"], ENT_COMPAT"UTF-8") . "</span>";
}
?>
        <p>
        <?PHP
        $base 
dirname($_SERVER["PHP_SELF"]);
        if (
$base == "/"$base "";
        
$sql "SELECT * FROM comics WHERE" .
            (
$private " 1" " postdate <= " time()) .
            ((
$creator === false) ? " AND 1" " AND creator = '" $creator "'") .
            
";";
        
$result $db->query($sql);
        
$curtime time();
        if (
$result !== false) {
            while ((
$row $result->fetchArray(SQLITE3_ASSOC)) !== false) {
                print 
"<a href='$base/?id=" $row["id"] . "' style='font-weight: bold'>" .
                      
strftime("%e %B, %Y"$row["postdate"]) .
                      
"</a>: " .
                      
stripslashes($row["title"]) .
                      
"<br/>\n";
            }
            
$result->finalize();
        }
        
?>
        </p>

<?PHP
if ($creator !== false) {
    
$profile contributorProfile($creator);
    if (
$profile["public"] !== false) {
        print 
"<p>" stripslashes($profile["public"]) . "</p>";
    }
    if (
$private && $profile["private"] !== false) {
        print 
"<p>Private profile: " stripslashes($profile["private"]) . "</p>";
    }
}
closeDB();
?>

        <?PHP srcLink(); ?>
    </div>
</body>
</html>