Backend
This commit is contained in:
24
Backend/notes.php
Normal file
24
Backend/notes.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
//Lucas
|
||||
require "db.php";
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
if ($action==='list') {
|
||||
$camp = isset($_GET['campaign_id']) ? (int)$_GET['campaign_id'] : 0;
|
||||
if ($camp<=0) bad('campaign_id required');
|
||||
$st=db()->prepare("SELECT id, campaign_id, user_id, text FROM campaign_notes WHERE campaign_id=? ORDER BY id DESC");
|
||||
$st->execute([$camp]);
|
||||
ok(['items'=>$st->fetchAll()]);
|
||||
}
|
||||
|
||||
if ($action==='add') {
|
||||
$b = body();
|
||||
$camp=(int)($b['campaign_id']??0); $uid=(int)($b['user_id']??0); $txt=trim($b['text']??'');
|
||||
if ($camp<=0||$uid<=0||$txt==='') bad('invalid');
|
||||
$st=db()->prepare("INSERT INTO campaign_notes(campaign_id,user_id,text) VALUES(?,?,?)");
|
||||
$st->execute([$camp,$uid,$txt]);
|
||||
ok(['id'=>db()->lastInsertId()]);
|
||||
}
|
||||
|
||||
http_response_code(404); echo json_encode(['ok'=>false,'error'=>'unknown action']);
|
Reference in New Issue
Block a user