up
This commit is contained in:
@@ -21,6 +21,8 @@ try {
|
||||
COALESCE(u.name, u.phone_number) AS name,
|
||||
u.phone_number,
|
||||
u.avatar_url,
|
||||
u.bot_enabled,
|
||||
u.on_hold,
|
||||
lm.message_id AS last_message_id,
|
||||
lm.content AS last_message,
|
||||
lm.direction AS direction,
|
||||
@@ -48,15 +50,17 @@ try {
|
||||
// Formatear datos para el frontend
|
||||
$conversations = array_map(function($conv) {
|
||||
return [
|
||||
'id' => intval($conv['id']),
|
||||
'user_id' => intval($conv['user_id']),
|
||||
'content' => $conv['content'] ?? '',
|
||||
'name' => $conv['name'] ?? $conv['phone_number'],
|
||||
'phone_number' => $conv['phone_number'],
|
||||
'avatar_url' => $conv['avatar_url'] ?? null,
|
||||
'last_message' => $conv['last_message'] ?? '',
|
||||
'last_time' => $conv['last_time'] ?? null,
|
||||
'direction' => $conv['direction'] ?? 'incoming',
|
||||
'message_type' => $conv['message_type'] ?? 'text',
|
||||
'status' => $conv['status'] ?? 'sent',
|
||||
'created_at' => $conv['created_at'],
|
||||
'phone_number' => $conv['phone_number'],
|
||||
'name' => $conv['name'] ?? $conv['phone_number']
|
||||
'unread_count' => intval($conv['unread_count'] ?? 0),
|
||||
'bot_enabled' => isset($conv['bot_enabled']) ? (bool)$conv['bot_enabled'] : true,
|
||||
'on_hold' => isset($conv['on_hold']) ? (bool)$conv['on_hold'] : false
|
||||
];
|
||||
}, $conversations);
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ try {
|
||||
$approvedOnly = isset($_GET['approved_only']) && $_GET['approved_only'] == '1';
|
||||
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : null;
|
||||
|
||||
$sql = "SELECT id, name, template_name, language_code, category, status, body_text, created_at FROM message_templates";
|
||||
// Ajuste: some DBs may not have body_text column; omit it to avoid SQL errors
|
||||
$sql = "SELECT id, name, template_name, language_code, category, status, created_at FROM message_templates";
|
||||
$params = [];
|
||||
|
||||
if ($approvedOnly) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once '../config/config.php';
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
requireAuthentication();
|
||||
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$userId = isset($input['user_id']) ? intval($input['user_id']) : 0;
|
||||
if (!$userId) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'user_id required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$user = $db->fetch('SELECT phone_number FROM users WHERE id = :id', ['id' => $userId]);
|
||||
if (!$user) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'error' => 'User not found']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db->update('users', ['on_hold' => 0], 'id = :id', ['id' => $userId]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require_once '../config/config.php';
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
requireAuthentication();
|
||||
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$userId = isset($input['user_id']) ? intval($input['user_id']) : 0;
|
||||
$enabled = isset($input['enabled']) ? (int)$input['enabled'] : null;
|
||||
|
||||
if (!$userId || $enabled === null) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'user_id and enabled required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->update('users', ['bot_enabled' => $enabled], 'id = :id', ['id' => $userId]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user