librecat/action/publish-question.php

44 lines
1.2 KiB
PHP
Raw Normal View History

2020-05-21 18:06:16 +00:00
<?php
session_start();
2020-05-21 20:29:28 +00:00
include("../include/settings.php");
include("../include/functions.php");
2020-05-21 18:06:16 +00:00
$db = new SQLite3('../ask.db');
$p_user = $db->query("SELECT * FROM users WHERE id = '" . $_POST["uid"] . "';")->fetchArray(SQLITE3_ASSOC);
if(!$p_user || !$p_user["id"]){
echo "user not found";
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 = $p_user["id"];
$by = 0;
2020-05-21 20:29:28 +00:00
$question = htmlspecialchars($_POST["post-text"], ENT_QUOTES);
$priv = 0;
$time = strtotime('now');
2020-05-21 18:06:16 +00:00
2020-05-21 21:36:32 +00:00
if(isset($_SESSION["uid"]) && !$_POST["anon"]) $by = $_SESSION["uid"];
if($_POST["priv"]) $priv = 1;
2020-05-21 21:36:32 +00:00
2020-05-21 18:06:16 +00:00
// Insert user into DB
$db->exec("INSERT INTO questions(user,by,question,q_date,private) VALUES ('$u','$by','$question',". $time .",$priv);");
2020-05-21 18:06:16 +00:00
unset($_POST["post-text"]);
$q_new = $db->query("SELECT * FROM questions WHERE q_date = '" . $time . "';")->fetchArray(SQLITE3_ASSOC);
$new_get["q"] = $p_user["username"];
if($priv){
$new_get["p"] = $q_new["id"];
$new_get["key"] = md5($question);
}
header("Location: " . redirect("user", $new_get));
2020-05-21 18:06:16 +00:00
}
}
?>