?
| Current Path : /home/webyoo/www/backup/allback/docteur-site/cv/sym/a/leumi/site/ |
| Current File : /home/webyoo/www/backup/allback/docteur-site/cv/sym/a/leumi/site/cron_expire_subscriptions.php |
<?php
// =====================================================================
// CRON quotidien โ abonnements ืืชืืื
// 1) Relance par email la VEILLE de la fin de l'essai gratuit
// 2) Expire (sub_status='expired') les comptes dont la pรฉriode est finie
// ร planifier 1x/jour (cron-job.org).
// =====================================================================
include "start.php";
include "send_email.php";
// Sรฉcuritรฉ : autorisรฉ en ligne de commande (php) OU via URL avec la bonne clรฉ.
$CRON_KEY = 'ashkara_cron_2026';
if (php_sapi_name() !== 'cli' && (!isset($_GET['key']) || $_GET['key'] !== $CRON_KEY)) {
http_response_code(403);
exit('forbidden');
}
// ---- 1) Relance la veille (essai gratuit qui se termine DEMAIN) ----
$sent = 0;
$rem = mysqli_query($link, "SELECT id, name, email FROM rent_users
WHERE fk_type = 3
AND sub_status = 'active'
AND (sub_payer_id IS NULL OR sub_payer_id = '')
AND sub_until = DATE_ADD(CURDATE(), INTERVAL 1 DAY)");
if ($rem) {
while ($u = mysqli_fetch_assoc($rem)) {
$subject = "ืชืืืืจืช: ืชืงืืคืช ืืืืื ืฉืื ืืกืชืืืืช ืืืจ - ืืฉืืจื";
$msg = "<html><head><meta charset='UTF-8'></head><body dir='rtl' style='font-family:Arial,sans-serif;color:#222;'>";
$msg .= "<h2>ืฉืืื " . htmlspecialchars($u['name']) . ",</h2>";
$msg .= "<p>ืืืืฉ ืืืืื ืืืื ืื ืฉืื ืืืชืจ <strong>ืืฉืืจื</strong> ืืกืชืืื <strong>ืืืจ</strong>.</p>";
$msg .= "<p>ืืื ืฉืื ืืกืื ืฉืื ืืืฉืืื ืืืืคืืข ืืขืืื ืืืชืืื ืืืฉืืจ ืคืขืื, ืืฉ ืืืคืขืื ืื ืื ืืืืฉื ืืกื 99 โช.</p>";
$msg .= "<p style='text-align:center;margin:24px 0;'>";
$msg .= "<a href='https://ashkara.co/agent-subscribe.php' style='background:#0ec6d5;color:#fff;padding:12px 28px;border-radius:6px;text-decoration:none;font-weight:bold;'>ืืคืขื ืื ืื ืขืืฉืื</a>";
$msg .= "</p>";
$msg .= "<p style='font-size:13px;color:#666;'>ืื ืื ืืืคืขื ืื ืื, ืื ืืกืื ืฉืื ืืืกืชืจื ืืจืฉืืืช ืื ืืกืื ืขื ืืืกืืจืช ืืชืฉืืื.</p>";
$msg .= "</body></html>";
sendEmail($u['email'], $subject, $msg, 'ืืฉืืจื - ืชืืืืจืช ืื ืื');
$sent++;
}
}
// ---- 2) Expiration (pรฉriode terminรฉe) ----
mysqli_query($link, "UPDATE rent_users
SET sub_status = 'expired'
WHERE fk_type = 3
AND sub_status = 'active'
AND sub_until IS NOT NULL
AND sub_until < CURDATE()");
$expired = mysqli_affected_rows($link);
echo "OK - relances: " . $sent . " ยท expirรฉs: " . $expired;