Ability to post

This is HUUUUUUUGE milestone B)
This commit is contained in:
Jarkko Toivanen 2024-12-20 16:41:21 +02:00
parent f717080e8a
commit de4cbe9ee6
Signed by: jt
GPG key ID: 9151B109B73ECAD5
3 changed files with 36 additions and 4 deletions

View file

@ -195,5 +195,19 @@ class DataBase extends SQLite3 {
}
return $array;
}
function getPersonas($userid=NULL) {
if(!$userid) {
$userid = $this->getAuthedUserId();
}
$sql = "SELECT * FROM personas AS persona WHERE userid='$userid' ORDER BY name;";
$ret = $this->query($sql);
$array = array();
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
array_push($array, $row);
}
return $array;
}
}
?>

View file

@ -55,12 +55,16 @@ if(!$database) {
} else {
?>
<a href="logout.php">LOG OUT</a>
<form id="postform">
<form id="postform" method="post" action="post.php">
<textarea id="postformtextarea" name="text" rows="5" placeholder="Whatcha snuffin' about?"></textarea><br />
<div id="postformactionrow">
<select id="user" name="user">
<option value=0>SYSTEM</option>
<option value=1>User</option>
<select id="persona" name="persona">
<?php
$personas = $database->getPersonas();
foreach($personas as $persona) {
echo "<option value=" . $persona['persona.id'] . ">" . $persona['persona.name'] . "</option>";
}
?>
</select>
<input type="submit" id="submit" name="submit" value="Snuff!" />
</div>

14
src/post.php Normal file
View file

@ -0,0 +1,14 @@
<?php
if (empty($_POST) || !isset($_POST['submit'])) {
die("Post canceled: no post / no submit");
}
require_once('inc/database.php');
$db = new DataBase();
$userid = $db->getAuthedUserId();
$persid = $_POST['persona']; // TODO: CHECK OWNERSHIP! (db schema?)
if($userid) {
$db->addPost($_POST['text'], $userid, $persid);
}
header("Location: /");
?>