| Server IP : 3.96.16.70 / Your IP : 216.73.216.15 Web Server : Apache System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/dumpchup.ca/behaviour-taco-bell/moderation/controller/ |
Upload File : |
<?php
if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['command']) ) {
if (in_array($_POST['command'], $cfg['validAjaxCommands'])) {
$command = $_POST['command'];
} else {
$output = array('result' => 'error', 'message' => 'Invalid Command');
exit (json_encode($output));
}
switch ($command) {
case 'moderate_post' :
if (isset($_POST['p_id']) && isset($_POST['status'])) {
try {
$pID = filter_var($_POST['p_id'], FILTER_SANITIZE_NUMBER_INT);
$status = filter_var($_POST['status'], FILTER_UNSAFE_RAW) == 'approved' ? 'approved' : 'denied';
$other = $status == 'approved' ? 'denied' : 'approved';
$sql = "UPDATE `participants` SET `".$status."` = :time, ".$other." = NULL WHERE `participants`.`id` = :pID;";
$update_participant = $db->prepare($sql);
$update_participant->execute(array("time"=>time(), "pID"=>$pID));
$output = array('result' => 'succes', 'message' => 'Signature is '.$status, 'status' => $status);
exit (json_encode($output));
} catch (exception $e) {
if ($cfg['stage'] == 'development')
exit($e->getMessage());
else {
$output = array('result' => 'DB Error', 'message' => $e->getMessage());
exit (json_encode($output));
}
}
} else {
$output = array('result' => 'error', 'message' => 'Invalid post values', 'POST' => $_POST);
exit (json_encode($output));
}
break;
case 'get_metrics' :
try {
$sql = "SELECT
SUM(CASE WHEN approved IS NULL AND denied IS NULL THEN 1 ELSE 0 END) AS waiting_to_moderate,
SUM(CASE WHEN approved IS NOT NULL AND denied IS NULL THEN 1 ELSE 0 END) AS notes_approved,
SUM(CASE WHEN denied IS NOT NULL AND approved IS NULL THEN 1 ELSE 0 END) AS notes_denied
FROM participants;";
$get_metrics = $db->prepare($sql);
$get_metrics->execute();
$metrics = $get_metrics->fetch(PDO::FETCH_ASSOC);
$output = array('result' => 'succes', 'metrics' => $metrics, 'time' => date("M d h:i a"));
exit (json_encode($output));
} catch (exception $e) {
if ($cfg['stage'] == 'development')
exit($e->getMessage());
else {
$output = array('result' => 'DB Error', 'message' => $e->getMessage());
exit (json_encode($output));
}
}
break;
case 'get_new_notes' :
if (isset($_POST['last_id'])) {
$last_id = filter_var($_POST['last_id'], FILTER_SANITIZE_NUMBER_INT);
try {
$sql = "SELECT participants.id as p_id, notes.id as id, signature, reason, background, approved, display_time FROM `participants`
LEFT JOIN notes ON participants.note_id = notes.id
WHERE approved IS NULL AND denied IS NULL ANd participants.id > :last_id ORDER BY datetime ASC LIMIT 2;";
$get_participant = $db->prepare($sql);
$get_participant->execute(array("last_id"=>$last_id));
$participants = $get_participant->fetchAll(PDO::FETCH_ASSOC);
if (empty($participants)) {
$output = array('result' => 'empty', 'last_id' => $last_id);
exit (json_encode($output));
}
$html = '';
foreach ($participants as $p) {
$html .= '<div class="note-container">
<div class="confirmation"></div>
<div id="p'.$p['p_id'].'" class="note-preview n'.$p['id'].'" style="background-color: '.$p['background'].'">
<p>'.$p['reason'].'</p>
<div class="sig"><img src="'.$p['signature'].'" /></div>
</div>
<div class="mod_buttons">
<div class="button deny secondary">Deny</div>
<div class="button approve">Approve</div>
</div>
</div>';
}
$output = array('result' => 'succes', 'html' => $html, 'last_id' => $p['p_id']);
exit (json_encode($output));
} catch (exception $e) {
if ($cfg['stage'] == 'development')
exit($e->getMessage());
else {
$output = array('result' => 'DB Error', 'message' => $e->getMessage());
exit (json_encode($output));
}
}
} else {
$output = array('result' => 'error', 'message' => 'Invalid post values', 'POST' => $_POST);
exit (json_encode($output));
}
break;
case 'get_note_metrics' :
try {
$sql = "SELECT note_id, reason, count(*) as tot FROM `participants` LEFT JOIN notes ON note_id = notes.id GROUP BY note_id;";
$get_metrics = $db->prepare($sql);
$get_metrics->execute();
$metrics = $get_metrics->fetchAll(PDO::FETCH_ASSOC);
$html = '<div class="note-metrics">
<div class="m-hdr">
<div>Note</div>
<div>Total</div>
</div>';
$total = 0;
foreach ($metrics as $i => $metric) {
$count = ++$i%2;
$html .= '<div class="row'.$count.'">
<div class="n">'.$metric['note_id'].'</div>
<div class="r">'.str_replace('<br>', " ", $metric['reason']).'</div>
<div class="t">'.$metric['tot'].'</div>
</div>';
$total += $metric['tot'];
}
$html .= '<div class="m-hdr">
<div>TOTAL</div>
<div>'.$total.'</div>
</div>';
$html .= '</div>';
$output = array('result' => 'succes', 'html' => $html);
exit (json_encode($output));
} catch (exception $e) {
if ($cfg['stage'] == 'development')
exit($e->getMessage());
else {
$output = array('result' => 'DB Error', 'message' => $e->getMessage());
exit (json_encode($output));
}
}
break;
default :
$output = array('result' => 'error', 'message' => 'Command not found');
exit (json_encode($output));
break;
}
}
?>