<?php require_once __DIR__.'/lib/v7_bootstrap.php';$flash=['ok'=>'','err'=>''];
if($_SERVER['REQUEST_METHOD']==='POST'){itz_v7_csrf($csrf);try{$id=(int)($_POST['id']??0);$status=(string)($_POST['status']??'open');if(!in_array($status,['open','in_progress','done','dismissed'],true))throw new RuntimeException('Status نامعتبر');$pdo->prepare('UPDATE itz_v7_admin_tasks SET status_name=:s,updated_at=:t WHERE id=:id')->execute([':s'=>$status,':t'=>time(),':id'=>$id]);$flash['ok']='Task به‌روزرسانی شد.';}catch(Throwable $e){$flash['err']=$e->getMessage();}}
$tasks=$pdo->query("SELECT * FROM itz_v7_admin_tasks ORDER BY FIELD(status_name,'open','in_progress','done','dismissed'),FIELD(priority_name,'urgent','high','normal'),id DESC LIMIT 300")->fetchAll(PDO::FETCH_ASSOC)?:[];
?>
<!doctype html><html lang="fa" dir="rtl"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Task Center | iTzAYDiN-BOT</title><link rel="stylesheet" href="css/theme.css"><link rel="stylesheet" href="css/admin-extra.css"><link rel="stylesheet" href="css/ay-controls.css"><script src="js/theme.js" defer></script><style>.taskgrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:10px}.task{padding:14px;border:1px solid var(--border-soft);border-radius:16px;background:var(--surface-2)}.urgent{border-color:rgba(239,68,68,.4)}.high{border-color:rgba(245,158,11,.35)}</style></head><body><section id="container"><?php include 'header.php';?><section id="main-content"><div class="wrapper"><div class="page-head"><div><div class="page-head__title">✅ Task Center</div><div class="page-head__sub">کارهای ساخته‌شده توسط Automation، Customer 360 و عملیات ادمین</div></div></div><?php if($flash['ok']):?><div class="alert alert-success"><?=itz_v7_h($flash['ok'])?></div><?php endif;?><div class="taskgrid"><?php foreach($tasks as $t):?><div class="task <?=itz_v7_h($t['priority_name'])?>"><small>#<?=intval($t['id'])?> · <?=itz_v7_h($t['source_name'])?></small><h3><?=itz_v7_h($t['title'])?></h3><p><?=itz_v7_h($t['description_text'])?></p><?php if($t['user_id']):?><a class="chip" href="customer360.php?user_id=<?=urlencode($t['user_id'])?>">User <?=itz_v7_h($t['user_id'])?></a><?php endif;?><form method="post" style="display:flex;gap:7px;margin-top:10px"><input type="hidden" name="_csrf" value="<?=itz_v7_h($csrf)?>"><input type="hidden" name="id" value="<?=intval($t['id'])?>"><select class="form-control" name="status"><?php foreach(['open','in_progress','done','dismissed'] as $s):?><option <?=$t['status_name']===$s?'selected':''?>><?=$s?></option><?php endforeach;?></select><button class="btn btn-primary btn-sm">ذخیره</button></form></div><?php endforeach;?></div></div></section></section></body></html>
