2020-05-17 00:02:20 +00:00
|
|
|
<?php
|
2020-05-17 20:06:22 +00:00
|
|
|
$db = new SQLite3('ask.db');
|
2020-05-17 00:02:20 +00:00
|
|
|
|
2020-05-20 16:08:25 +00:00
|
|
|
$user = $db->query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC);
|
2020-05-21 08:07:28 +00:00
|
|
|
if(!$user || !$user["id"]){
|
|
|
|
include("404.php");
|
|
|
|
die();
|
|
|
|
}
|
2020-05-17 00:02:20 +00:00
|
|
|
|
2020-05-20 16:08:25 +00:00
|
|
|
if($validUser){
|
|
|
|
header("Location: /"); die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$errorMsg = "";
|
|
|
|
if(isset($_POST["post-submit"])){
|
|
|
|
if($_POST["post-text"] == "") $errorMsg = "The question can't be blank.";
|
|
|
|
else if(strlen($_POST["post-text"]) > 400) $errorMsg = "The question can't bee longer than 400 characters";
|
|
|
|
else{
|
|
|
|
$u = $user["id"];
|
|
|
|
$by = 0;
|
|
|
|
$question = htmlspecialchars($_POST["post-text"]);
|
|
|
|
|
|
|
|
// Insert user into DB
|
2020-05-21 11:57:27 +00:00
|
|
|
$db->exec("INSERT INTO questions(user,by,question,answered,date) VALUES ('$u','$by','$question',0,". strtotime('now') .");");
|
2020-05-20 16:08:25 +00:00
|
|
|
unset($_POST["post-text"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title><?= $user["username"] ?> | LibreCat</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2><?= $user["username"] ?></h2>
|
|
|
|
<p><?= $user["bio"] ?></p>
|
|
|
|
|
|
|
|
<form name="input" action="" method="post">
|
|
|
|
<p>Ask me anything</p>
|
|
|
|
<textarea id="post-text" name="post-text"></textarea>
|
|
|
|
<br/>
|
|
|
|
<?php if(isset($errorMsg)) echo "<p>$errorMsg</p>\n"; ?>
|
|
|
|
<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-20 16:08:25 +00:00
|
|
|
$qs = $db->query("SELECT * FROM questions WHERE user = '" . $user["id"] . "' LIMIT 0, 10;");
|
2020-05-21 11:57:27 +00:00
|
|
|
|
|
|
|
$time = new DateTime("@0");
|
2020-05-20 16:08:25 +00:00
|
|
|
while($current = $qs->fetchArray(SQLITE3_ASSOC)){
|
2020-05-21 11:57:27 +00:00
|
|
|
// 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 11:57:27 +00:00
|
|
|
|
2020-05-21 09:04:09 +00:00
|
|
|
echo("<h3>". $q_user["name"] ."</h3>");
|
2020-05-21 11:57:27 +00:00
|
|
|
|
|
|
|
// 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>
|