librecat/include/header.php

66 lines
1.5 KiB
PHP
Raw Normal View History

2020-05-21 17:19:38 +00:00
<?php
include("settings.php");
2020-08-29 15:47:28 +00:00
include("functions.php");
2020-05-21 15:57:59 +00:00
session_start();
$db = new SQLite3('ask.db');
$users_table = $db->query("CREATE TABLE IF NOT EXISTS users(
2020-05-21 20:21:44 +00:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
2020-05-21 15:57:59 +00:00
username TEXT,
shadow TEXT,
name TEXT,
2020-08-16 11:03:05 +00:00
bio TEXT,
tw_oauth_token TEXT,
tw_oauth_verify TEXT
2020-05-21 15:57:59 +00:00
)");
$db->exec("CREATE TABLE IF NOT EXISTS questions(
2020-05-21 20:21:44 +00:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
2020-05-21 15:57:59 +00:00
user INTEGER,
by INTEGER,
question TEXT,
2020-05-22 00:20:59 +00:00
q_date INTEGER,
answer TEXT,
a_date INTEGER,
status INTEGER,
private INTEGER
2020-05-21 15:57:59 +00:00
);");
if(!$db->querySingle("SELECT EXISTS(SELECT * FROM users where id = 0);")){
echo "NOTICE: anonymous user created.";
$db->exec("INSERT INTO users(id, username, name) VALUES('0','anonymous','Anonymous');");
}
if($_SESSION["login"] === true){
2020-05-30 20:23:04 +00:00
echo("<div id='header'>");
2020-05-21 15:57:59 +00:00
echo("<a href='/'>LibreCat</a>");
echo(" | ");
$user = $db->query("SELECT * FROM users WHERE id = ".$_SESSION["uid"].";")->fetchArray(SQLITE3_ASSOC);
2020-05-21 17:19:38 +00:00
if($fancy_urls){
echo("<a href='/user/" . $user["username"] . "'>". $user["username"] . "</a>");
echo(" | ");
echo("<a href='/logout'>logout</a>");
}
else {
echo("<a href='/user.php?q=" . $user["username"] . "'>" . $user["username"] . "</a>");
echo(" | ");
echo("<a href='/logout.php'>logout</a>");
}
2020-05-30 20:23:04 +00:00
echo("</div>");
2020-05-21 15:57:59 +00:00
}
else{
2020-05-30 20:23:04 +00:00
echo("<div id='header'>");
2020-05-21 17:19:38 +00:00
echo("<a href='/'>LibreCat</a>");
echo(" | ");
if($fancy_urls){
echo("<a href='/login'>Login</a>");
}
else{
echo("<a href='/login.php'>Login</a>");
}
2020-05-30 20:23:04 +00:00
echo("</div>");
2020-05-21 15:57:59 +00:00
}
?>