librecat/user.php

65 lines
1.6 KiB
PHP
Raw Normal View History

2020-05-17 00:02:20 +00:00
<?php
2020-05-21 15:57:59 +00:00
session_start();
2020-05-17 20:06:22 +00:00
$db = new SQLite3('ask.db');
2020-05-17 00:02:20 +00:00
2020-05-21 15:57:59 +00:00
$p_user = $db->query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC);
if(!$p_user || !$p_user["id"]){
2020-05-21 08:07:28 +00:00
include("404.php");
die();
}
2020-05-17 00:02:20 +00:00
2020-05-21 15:57:59 +00:00
if(isset($_SESSION["uid"])){
if($_SESSION["uid"] == $p_user["id"]){
$is_current_user = true;
}
}
2020-05-20 16:08:25 +00:00
?>
<html>
<head>
2020-05-21 15:57:59 +00:00
<title><?= $p_user["username"] ?> | LibreCat</title>
2020-05-20 16:08:25 +00:00
</head>
2020-05-21 15:57:59 +00:00
<body>
<?php include("include/header.php"); ?>
<h2><?= $p_user["username"] ?></h2>
<p><?= $p_user["bio"] ?></p>
2020-05-21 17:19:38 +00:00
<?php
if($is_current_user){
if($fancy_urls)
echo("<a href='/config'>config</a>");
else
echo("<a href='/config.php'>config</a>");
}
?>
2020-05-20 16:08:25 +00:00
2020-05-21 18:06:16 +00:00
<form name="input" action="/action/publish-question.php" method="post">
2020-05-20 16:08:25 +00:00
<p>Ask me anything</p>
<textarea id="post-text" name="post-text"></textarea>
<br/>
<?php if(isset($errorMsg)) echo "<p>$errorMsg</p>\n"; ?>
2020-05-21 18:06:16 +00:00
<input type="hidden" name="uid" value="<?= $p_user["id"] ?>"/>
2020-05-20 16:08:25 +00:00
<input type="submit" name="post-submit"/>
</form>
<?php
2020-05-21 09:04:09 +00:00
$u_prep = $db->prepare("SELECT * FROM users WHERE id = :id");
2020-05-21 15:57:59 +00:00
$qs = $db->query("SELECT * FROM questions WHERE user = '" . $p_user["id"] . "' LIMIT 0, 10;");
$time = new DateTime("@0");
2020-05-20 16:08:25 +00:00
while($current = $qs->fetchArray(SQLITE3_ASSOC)){
// Execute prepared statement
2020-05-21 09:04:09 +00:00
$u_prep->bindValue(":id", $current["by"], SQLITE3_INTEGER);
$q_user = $u_prep->execute()->fetchArray(SQLITE3_ASSOC);
2020-05-21 15:57:59 +00:00
echo("<h3>". $current["id"] ." - " . $q_user["name"] ."</h3>");
// Time
$time->setTimestamp($current["date"]);
echo($time->format("Y-m-d H:i:s"));
2020-05-20 16:08:25 +00:00
echo("<p>". $current["question"] ."<p>");
}
?>
</body>
</html>