This commit is contained in:
Lizandro Guarnizo
2026-01-21 22:51:57 -05:00
parent 32f5f580f7
commit a70b8f36b5
3 changed files with 49 additions and 1 deletions
+10 -1
View File
@@ -4,10 +4,17 @@ require_once __DIR__ . '/../config/config.php';
header('Content-Type: application/json; charset=utf-8');
if (function_exists('requireAuthentication')) requireAuthentication();
// Bypass authentication when debug=true is provided in query string
$debugMode = isset($_GET['debug']) && $_GET['debug'] === 'true';
if (!$debugMode && function_exists('requireAuthentication')) {
requireAuthentication();
}
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
// Debug log
if (function_exists('writeLog')) writeLog('INFO', 'delete_template.php start', ['raw_input' => $input, 'query' => $_GET]);
// Allow single id or array of ids
$ids = [];
if (isset($input['id'])) {
@@ -24,6 +31,8 @@ if (empty($ids) || array_filter($ids) === []) {
exit;
}
if (function_exists('writeLog')) writeLog('INFO', 'delete_template.php parsed ids', ['ids' => $ids]);
try {
$db = Database::getInstance();
+28
View File
@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../config/config.php';
try {
$db = Database::getInstance();
$ids = [3];
$placeholders = implode(',', array_fill(0,count($ids),'?'));
$existing = $db->fetchAll("SELECT id, name, template_name FROM message_templates WHERE id IN ($placeholders)", $ids);
var_export($existing);
$db->beginTransaction();
$db->execute("DELETE FROM message_templates WHERE id IN ($placeholders)", $ids);
$operatorId = 1;
$now = date('Y-m-d H:i:s');
foreach ($existing as $t) {
$db->insert('operator_activity', [
'user_id' => null,
'operator_id' => $operatorId,
'action' => 'delete_template',
'details' => 'Deleted template: ' . ($t['name'] ?? $t['template_name'] ?? $t['id']),
'created_at' => $now
]);
}
$db->commit();
echo "Deleted and logged\n";
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . PHP_EOL;
$db->rollback();
}
+11
View File
@@ -0,0 +1,11 @@
<?php
require_once __DIR__ . '/../config/config.php';
try {
$db = Database::getInstance();
$ids = [3];
$placeholders = implode(',', array_fill(0, count($ids), '?'));
$existing = $db->fetchAll("SELECT id, name, template_name FROM message_templates WHERE id IN ($placeholders)", $ids);
var_export($existing);
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . PHP_EOL;
}