| Current Path : /home/h/a/p/happyrenas/myreco.online/administration/panel/ajax/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/h/a/p/happyrenas/myreco.online/administration/panel/ajax/email_queue_list.php |
<?
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../');
include("../../../configuration.php");
include("../../../includes/fonctions.php");
setlocale(LC_TIME, 'fr_FR.UTF-8');
include("auth.php");
header('Content-Type: application/json; charset=utf-8');
$draw = (int)($_GET['draw'] ?? 1);
$start = max(0, (int)($_GET['start'] ?? 0));
$length = (int)($_GET['length'] ?? 25);
if ($length < 1) $length = 25;
if ($length > 200) $length = 200;
$search = trim($_GET['search']['value'] ?? '');
$orderCol = (int)($_GET['order'][0]['column'] ?? 0);
$orderDir = strtolower($_GET['order'][0]['dir'] ?? 'desc') === 'asc' ? 'ASC' : 'DESC';
// Colonnes DataTables -> colonnes SQL autorisées (anti-injection)
$cols = [
0 => 'id',
1 => 'created_at',
2 => 'request_uid',
3 => 'token',
4 => 'destinataire_principal',
5 => 'objet',
6 => 'status',
7 => 'retries',
8 => 'last_attempt',
9 => 'next_attempt',
];
$orderBy = $cols[$orderCol] ?? 'id';
$esc = function($v) use ($db){
return "'" . $db->escape($v) . "'";
};
$where = "1=1";
if ($search !== ''){
$s = '%' . $search . '%';
$where .= " AND (
token LIKE " . $esc($s) . " OR
request_uid LIKE " . $esc($s) . " OR
destinataire_principal LIKE " . $esc($s) . " OR
objet LIKE " . $esc($s) . " OR
status LIKE " . $esc($s) . "
)";
}
// total
$total = (int)$db->get_var("SELECT COUNT(*) FROM email_queue");
// filtered
$filtered = $total;
if ($where !== "1=1"){
$filtered = (int)$db->get_var("SELECT COUNT(*) FROM email_queue WHERE $where");
}
// data
$rows = $db->get_results("
SELECT id, created_at, request_uid, token,
expediteur, destinataire_principal, destinataire_copie,
objet, status, retries, last_attempt, next_attempt
FROM email_queue
WHERE $where
ORDER BY $orderBy $orderDir
LIMIT $start, $length
");
function statusBadge($s){
$s = (string)$s;
$cls = 'badge badge-secondary';
if ($s === 'queued') $cls = 'badge badge-queued';
if ($s === 'sending') $cls = 'badge badge-sending';
if ($s === 'sent') $cls = 'badge badge-sent';
if ($s === 'failed') $cls = 'badge badge-failed';
return '<span class="'.$cls.'">'.htmlspecialchars($s, ENT_QUOTES, 'UTF-8').'</span>';
}
function date_fr($dt){
$dt = trim((string)$dt);
if ($dt === '' || $dt === '0000-00-00 00:00:00') return '';
$ts = strtotime($dt);
if (!$ts) return '';
return date('d/m/Y H:i', $ts); // ex: 21/12/2025 14:07
}
$data = [];
if ($rows){
foreach ($rows as $r){
$data[] = [
'id' => (int)$r->id,
'created_at' => $r->created_at,
'request_uid' => $r->request_uid,
'token' => $r->token,
'to' => $r->destinataire_principal,
'subject' => $r->objet,
'status_html' => statusBadge($r->status),
'retries' => (int)$r->retries,
'last_attempt'=> date_fr($r->last_attempt) ?: '',
'next_attempt'=> date_fr($r->next_attempt) ?: '',
'actions_html'=> '<button type="button" class="btn btn-sm btn-light btnQueueView" data-id="'.(int)$r->id.'">
<i class="fa fa-eye"></i> Voir
</button>',
];
}
}
echo json_encode([
'draw' => $draw,
'recordsTotal' => $total,
'recordsFiltered' => $filtered,
'data' => $data
], JSON_UNESCAPED_UNICODE);
exit;