<?php
require_once __DIR__.'/../includes/functions.php'; require_once __DIR__.'/../includes/mj_v3_helpers.php'; header('Content-Type: application/json');
try{ mj_v300_ensure_schema(); $j=json_decode(file_get_contents('php://input'),true)?:[]; $uid=(int)($_SESSION['user_id']??0); $aid=(int)($_SESSION['admin_id']??0); $endpoint=(string)($j['endpoint']??''); if($endpoint!==''&&table_exists('mj_browser_push_subscriptions')){ $keys=$j['keys']??[]; q('INSERT INTO mj_browser_push_subscriptions(user_id,admin_id,endpoint,auth_key,p256dh_key,permission_status,user_agent,last_seen_at,created_at) VALUES(?,?,?,?,?,?,?,NOW(),NOW())',[$uid?:null,$aid?:null,$endpoint,(string)($keys['auth']??''),(string)($keys['p256dh']??''),(string)($j['permission']??'granted'),(string)($_SERVER['HTTP_USER_AGENT']??'')]); } echo json_encode(['ok'=>true]); }catch(Throwable $e){ echo json_encode(['ok'=>false]); }
