Files
wevads-platform/scripts/mass_creative_import.php
2026-02-26 04:53:11 +01:00

484 lines
39 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* WEVADS - Mass Creative Generator & Importer
* Format: ADX/iResponse avec headers Exchange randomisés
* Génère des creatives pour TOUTES les offres × TOUS les ISPs × TOUS les send methods
* Importe dans: offer_creatives + met à jour brain_offer_config.good_creatives
*
* Usage: php mass_creative_import.php [--dry-run]
*/
$DRY_RUN = in_array('--dry-run', $argv ?? []);
$VERBOSE = in_array('--verbose', $argv ?? []) || in_array('-v', $argv ?? []);
// ═══════════════════════════════════════════════════════════════
// DB CONNECTION
// ═══════════════════════════════════════════════════════════════
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "╔══════════════════════════════════════════════════════════════╗\n";
echo "║ WEVADS MASS CREATIVE GENERATOR - ADX/iResponse FORMAT ║\n";
echo "" . date('Y-m-d H:i:s') . "\n";
echo "╚══════════════════════════════════════════════════════════════╝\n\n";
if ($DRY_RUN) echo "⚠️ DRY RUN MODE - No DB writes\n\n";
// ═══════════════════════════════════════════════════════════════
// ISP TARGETS × SEND METHODS (les combos qui marchent)
// ═══════════════════════════════════════════════════════════════
$ISP_METHODS = [
// DE ISPs
'T-Online' => ['o365', 'hybrid', 'gsuite', 'pmta_direct'],
'GMX' => ['o365', 'hybrid', 'gsuite', 'pmta_direct'],
// FR ISPs
'Orange' => ['o365', 'smtp_relay', 'hybrid'],
// NL ISPs
'Ziggo' => ['o365', 'smtp_relay', 'hybrid'],
// Global
'Gmail' => ['o365', 'gsuite'],
'Outlook' => ['o365', 'hybrid'],
];
// TLD par ISP pour les headers
$ISP_TLD = [
'T-Online' => '.de', 'GMX' => '.de',
'Orange' => '.fr', 'Ziggo' => '.nl',
'Gmail' => '.com', 'Outlook' => '.com',
];
// ═══════════════════════════════════════════════════════════════
// HEADER TEMPLATE ADX (le format qui marche)
// ═══════════════════════════════════════════════════════════════
function adx_header($from_name, $subject, $tld) {
return "\"From:{$from_name}#[n_2_5]<[anl_4_7]@[uanl_11_22]{$tld}>
Subject:{$subject}#[n_3_6]
MIME-Version: 1.0
Message-Id: <[uan_10_14].[an_10_14].[uan_10_13][anl_4_11].[anl_2_4]@[uanl_5_10]{$tld}>
Date: [mail_date]
To: [email]
List-ID: [hl_5_45] <[uan_10_14].[an_10_14].[uan_10_13][anl_4_11].[anl_2_4]@[anl_4_11].com>
X-Report: Please report abuse to [uan_3_44]@[anl_4_11].com
X-[anl_4_9]-[uanl_4_7]: [un_4_9][uan_4_9] [uan_4_9] [uan_4_9][uan_4_9]
Content-Type: multipart/alternative;boundary=___[au_4_6]_[hu_22_33]-[n_3_12].[n_4_15]\"";
}
// ═══════════════════════════════════════════════════════════════
// TEXT PLAIN PADDING (le noise anti-spam)
// ═══════════════════════════════════════════════════════════════
function adx_text_plain() {
return "[ual_4_19] [ual_4_19] [ual_4_19] ( https://email.[anl_5_44].edu/[uhu_22_33]_[anl_5_44]_[uhl_4_44] )
[ual_4_19] [ual_4_19]: https://email.[anl_5_44].edu/[uhu_22_33]_[anl_5_44]_[uhl_4_44]
[ual_4_19] ( https://email.[anl_5_44].edu/[uhu_22_33]_[anl_5_44]_[uhl_4_44]/[uhu_22_33] )";
}
// ═══════════════════════════════════════════════════════════════
// BODY WRAPPER ADX (multipart/alternative)
// ═══════════════════════════════════════════════════════════════
function adx_body($html_content) {
$text_plain = adx_text_plain();
return "\"--___[au_4_6]_[hu_22_33]-[n_3_12].[n_4_15]
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
{$text_plain}
--___[au_4_6]_[hu_22_33]-[n_3_12].[n_4_15]
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=iso-8859-1
Mime-Version: 1.0
{$html_content}
--___[au_4_6]_[hu_22_33]-[n_3_12].[n_4_15]--\"";
}
// ═══════════════════════════════════════════════════════════════
// QP ENCODE helper (=3D for =, =C3=XX for umlauts)
// ═══════════════════════════════════════════════════════════════
function qp($s) {
return str_replace(['=', '"'], ['=3D', '""'], $s);
}
// ═══════════════════════════════════════════════════════════════
// CREATIVE TEMPLATES PAR VERTICAL × COUNTRY
// Chaque template retourne [from_name, subject, html]
// ═══════════════════════════════════════════════════════════════
function get_creative_variants($offer_name, $vertical, $country, $payout) {
$variants = [];
$country = strtoupper($country);
// Detect language
$lang = 'en';
if (in_array($country, ['DE','AT','CH'])) $lang = 'de';
if (in_array($country, ['FR','BE'])) $lang = 'fr';
if (in_array($country, ['ES','MX'])) $lang = 'es';
if (in_array($country, ['IT'])) $lang = 'it';
if (in_array($country, ['NL'])) $lang = 'nl';
if (in_array($country, ['SE','FI'])) $lang = 'en'; // scandinavian = english
if ($country == 'INTL' || $country == 'WW') $lang = 'en';
$vertical_lower = strtolower($vertical);
// Clean offer name for display
$clean_name = preg_replace('/\[.*?\]/', '', $offer_name);
$clean_name = preg_replace('/^(DE|FR|UK|US|AU|IT|ES|CA|MX|NZ|AT|FI|SE|CZ|IN|WW|INTL|BEfr)\s*[\-\|]\s*/i', '', $clean_name);
$clean_name = preg_replace('/\s*(Pre-Lander|OW2|V2|V2N|V3|V4|CC|CPA|CPL|SOI|SS|COD)\s*/i', '', $clean_name);
$clean_name = preg_replace('/\s*-\s*$/', '', trim($clean_name));
$clean_name = trim($clean_name) ?: $offer_name;
// ── GERMAN TEMPLATES ──
if ($lang == 'de') {
// Variant A: Gewinnspiel/Belohnung
$variants[] = [
'from' => 'Kundenservice',
'subject' => qp('Herzlichen Gl=C3=BCckwunsch! Ihr Geschenk wartet'),
'html' => build_html_de_reward($clean_name, $payout),
];
// Variant B: Benachrichtigung
$variants[] = [
'from' => 'Benachrichtigung',
'subject' => qp('Wichtige Mitteilung zu Ihrem Konto'),
'html' => build_html_de_notification($clean_name, $payout),
];
// Variant C: Angebot
$variants[] = [
'from' => qp('Pr=C3=A4mien-Center'),
'subject' => qp('Exklusives Angebot nur f=C3=BCr Sie - Jetzt sichern!'),
'html' => build_html_de_exclusive($clean_name, $payout),
];
}
// ── FRENCH TEMPLATES ──
elseif ($lang == 'fr') {
$variants[] = [
'from' => 'Service Client',
'subject' => qp('F=C3=A9licitations ! Votre r=C3=A9compense vous attend'),
'html' => build_html_fr_reward($clean_name, $payout),
];
$variants[] = [
'from' => 'Notification',
'subject' => qp('Action requise : confirmez votre participation'),
'html' => build_html_fr_notification($clean_name, $payout),
];
}
// ── SPANISH TEMPLATES ──
elseif ($lang == 'es') {
$variants[] = [
'from' => 'Centro de Premios',
'subject' => qp('=C2=A1Felicidades! Ha sido seleccionado'),
'html' => build_html_es_reward($clean_name, $payout),
];
}
// ── ITALIAN TEMPLATES ──
elseif ($lang == 'it') {
$variants[] = [
'from' => 'Servizio Clienti',
'subject' => qp('Congratulazioni! Il tuo premio =C3=A8 pronto'),
'html' => build_html_it_reward($clean_name, $payout),
];
}
// ── ENGLISH TEMPLATES (US, UK, AU, CA, INTL) ──
else {
// Vertical-specific subjects
if (strpos($vertical_lower, 'diet') !== false || strpos($vertical_lower, 'health') !== false) {
$variants[] = [
'from' => 'Health Advisory',
'subject' => 'Your personalized wellness plan is ready',
'html' => build_html_en_health($clean_name, $payout),
];
$variants[] = [
'from' => 'Wellness Center',
'subject' => 'Exclusive health offer - Limited availability',
'html' => build_html_en_exclusive($clean_name, $payout, 'health'),
];
}
elseif (strpos($vertical_lower, 'casino') !== false || strpos($vertical_lower, 'gambling') !== false) {
$variants[] = [
'from' => 'Rewards Club',
'subject' => 'Your exclusive bonus is waiting - Claim now',
'html' => build_html_en_casino($clean_name, $payout),
];
}
elseif (strpos($vertical_lower, 'consumer') !== false || strpos($vertical_lower, 'pain') !== false) {
$variants[] = [
'from' => 'Special Offers',
'subject' => 'You\'ve been selected for an exclusive deal',
'html' => build_html_en_product($clean_name, $payout),
];
$variants[] = [
'from' => 'VIP Rewards',
'subject' => 'Congratulations! Your reward is ready to claim',
'html' => build_html_en_exclusive($clean_name, $payout, 'product'),
];
}
elseif (strpos($vertical_lower, 'mortgage') !== false || strpos($vertical_lower, 'real estate') !== false) {
$variants[] = [
'from' => 'Financial Advisory',
'subject' => 'New rates available - Save on your mortgage',
'html' => build_html_en_finance($clean_name, $payout),
];
}
elseif (strpos($vertical_lower, 'sub-prime') !== false) {
$variants[] = [
'from' => 'Assistance Program',
'subject' => 'You may qualify for financial assistance',
'html' => build_html_en_assistance($clean_name, $payout),
];
}
elseif (strpos($vertical_lower, 'sweepstakes') !== false) {
$variants[] = [
'from' => 'Rewards Center',
'subject' => 'You\'ve been selected! Confirm your entry now',
'html' => build_html_en_sweepstakes($clean_name, $payout),
];
}
elseif (strpos($vertical_lower, 'dating') !== false) {
$variants[] = [
'from' => 'New Matches',
'subject' => 'Someone wants to meet you - View profile',
'html' => build_html_en_dating($clean_name, $payout),
];
}
else {
// Generic
$variants[] = [
'from' => 'Priority Notification',
'subject' => 'Action required: Your exclusive offer expires soon',
'html' => build_html_en_exclusive($clean_name, $payout, 'generic'),
];
}
}
return $variants;
}
// ═══════════════════════════════════════════════════════════════
// HTML BUILDERS - Each returns QP-encoded HTML
// ═══════════════════════════════════════════════════════════════
function html_wrap($inner, $bg_color='#f4f4f4') {
return "<!DOCTYPE html><html><head><meta http-equiv=3D\"\"Content-Type\"\" content=3D\"\"text/html; charset=3Dutf-8\"\"/><meta name=3D\"\"viewport\"\" content=3D\"\"width=device-width, initial-scale=3D1.0\"\"/><title>[placeholder3] [uanl_33_44]</title></head><body style=3D\"\"margin:0;padding:0;background:{$bg_color}\"\"><table width=3D\"\"100%\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\"><tr><td align=3D\"\"center\"\" style=3D\"\"padding:15px 0\"\">{$inner}</td></tr></table><img src=3D\"\"[placeholder2]\"\" width=3D\"\"1\"\" height=3D\"\"1\"\" style=3D\"\"display:none\"\"/></body></html>";
}
function cta_button($text, $color='#0066cc') {
return "<table cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" style=3D\"\"margin:25px auto\"\"><tr><td align=3D\"\"center\"\" bgcolor=3D\"\"{$color}\"\" style=3D\"\"border-radius:6px\"\"><a href=3D\"\"[placeholder1]#[url]\"\" style=3D\"\"display:block;padding:14px 45px;color:#ffffff;font-size:15px;font-family:Arial,sans-serif;text-decoration:none;font-weight:bold\"\">{$text}</a></td></tr></table>";
}
// ── GERMAN ──
function build_html_de_reward($name, $payout) {
$cta = cta_button('Jetzt teilnehmen!', '#d32f2f');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#d32f2f;padding:25px;text-align:center\"\"><p style=3D\"\"font-size:32px;margin:0\"\">&#127873;</p><p style=3D\"\"color:#fff;font-size:20px;font-weight:bold;font-family:Arial,sans-serif;margin:10px 0 0\"\">Herzlichen Gl=C3=BCckwunsch!</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:15px;color:#333;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 15px\"\">Sie wurden f=C3=BCr unser exklusives Programm ausgew=C3=A4hlt. Best=C3=A4tigen Sie jetzt Ihre Teilnahme und sichern Sie sich Ihre Belohnung.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#fff8e1;border:2px dashed #ffc107;border-radius:8px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:12px;color:#666;font-family:Arial,sans-serif;margin:0 0 5px\"\">Ihr pers=C3=B6nlicher Code:</p><p style=3D\"\"font-size:24px;font-weight:bold;color:#d32f2f;font-family:monospace;margin:0;letter-spacing:3px\"\">[uan_4_6]-[uan_4_6]-[uan_4_6]</p><p style=3D\"\"font-size:11px;color:#999;font-family:Arial,sans-serif;margin:8px 0 0\"\">G=C3=BCltig: 48 Stunden</p></td></tr></table>{$cta}<p style=3D\"\"font-size:10px;color:#ccc;font-family:Arial,sans-serif;text-align:center;margin:15px 0 0\"\">Teilnahmebedingungen gelten. Begrenzte Verf=C3=BCgbarkeit.</p></td></tr></table>");
}
function build_html_de_notification($name, $payout) {
$cta = cta_button('Jetzt best=C3=A4tigen', '#1565c0');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#1565c0;padding:20px;text-align:center\"\"><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:0\"\">Wichtige Mitteilung</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:15px;color:#333;font-family:Arial,sans-serif;margin:0 0 15px\"\">Guten Tag,</p><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Wir m=C3=B6chten Sie =C3=BCber eine wichtige =C3=84nderung informieren, die Ihr Konto betrifft. Bitte best=C3=A4tigen Sie Ihre Angaben, um den Service weiterhin nutzen zu k=C3=B6nnen.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#f5f5f5;border-radius:6px;padding:12px\"\"><tr><td style=3D\"\"font-size:13px;color:#666;font-family:Arial,sans-serif;padding:4px 0\"\">Referenz: [uan_4_6]-[n_6_8]</td></tr><tr><td style=3D\"\"font-size:13px;color:#666;font-family:Arial,sans-serif;padding:4px 0\"\">Datum: [mail_date]</td></tr><tr><td style=3D\"\"font-size:13px;color:#c00;font-family:Arial,sans-serif;padding:4px 0;font-weight:bold\"\">Frist: 48 Stunden</td></tr></table>{$cta}<p style=3D\"\"font-size:11px;color:#999;font-family:Arial,sans-serif;text-align:center\"\">Diese Nachricht wurde automatisch generiert.</p></td></tr></table>");
}
function build_html_de_exclusive($name, $payout) {
$cta = cta_button('Angebot ansehen', '#ff6f00');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#ff6f00;padding:20px;text-align:center\"\"><p style=3D\"\"font-size:28px;margin:0\"\">&#11088;</p><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:8px 0 0\"\">Exklusives Angebot</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Als ausgew=C3=A4hlter Kunde erhalten Sie heute Zugang zu einem exklusiven Angebot. Diese M=C3=B6glichkeit ist zeitlich begrenzt und steht nur wenigen Teilnehmern zur Verf=C3=BCgung.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;text-align:center;background:#fff3e0;border-radius:8px;padding:15px\"\"><tr><td><p style=3D\"\"font-size:11px;color:#999;font-family:Arial,sans-serif;margin:0 0 5px\"\">Verf=C3=BCgbar bis:</p><p style=3D\"\"font-size:20px;font-weight:bold;color:#e65100;font-family:Arial,sans-serif;margin:0\"\">&#9200; Nur noch heute!</p></td></tr></table>{$cta}<p style=3D\"\"font-size:10px;color:#ccc;font-family:Arial,sans-serif;text-align:center\"\">Limitierte Verf=C3=BCgbarkeit.</p></td></tr></table>");
}
// ── FRENCH ──
function build_html_fr_reward($name, $payout) {
$cta = cta_button('Participer maintenant', '#c62828');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#c62828;padding:25px;text-align:center\"\"><p style=3D\"\"font-size:32px;margin:0\"\">&#127881;</p><p style=3D\"\"color:#fff;font-size:20px;font-weight:bold;font-family:Arial,sans-serif;margin:10px 0 0\"\">F=C3=A9licitations !</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:15px;color:#333;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 15px\"\">Vous avez =C3=A9t=C3=A9 s=C3=A9lectionn=C3=A9(e) pour notre programme exclusif. Confirmez votre participation pour r=C3=A9clamer votre r=C3=A9compense.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#fff8e1;border:2px dashed #ffc107;border-radius:8px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:12px;color:#666;font-family:Arial,sans-serif;margin:0 0 5px\"\">Votre code personnel :</p><p style=3D\"\"font-size:24px;font-weight:bold;color:#c62828;font-family:monospace;margin:0;letter-spacing:3px\"\">[uan_4_6]-[uan_4_6]-[uan_4_6]</p><p style=3D\"\"font-size:11px;color:#999;font-family:Arial,sans-serif;margin:8px 0 0\"\">Valide : 48 heures</p></td></tr></table>{$cta}<p style=3D\"\"font-size:10px;color:#ccc;font-family:Arial,sans-serif;text-align:center\"\">Disponibilit=C3=A9 limit=C3=A9e.</p></td></tr></table>");
}
function build_html_fr_notification($name, $payout) {
$cta = cta_button('Confirmer maintenant', '#1565c0');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#1565c0;padding:20px;text-align:center\"\"><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:0\"\">Notification importante</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:15px;color:#333;font-family:Arial,sans-serif;margin:0 0 15px\"\">Bonjour,</p><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Une action est requise de votre part. Veuillez confirmer vos informations pour continuer =C3=A0 b=C3=A9n=C3=A9ficier de nos services.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#f5f5f5;border-radius:6px;padding:12px\"\"><tr><td style=3D\"\"font-size:13px;color:#666;font-family:Arial,sans-serif;padding:4px 0\"\">R=C3=A9f=C3=A9rence : [uan_4_6]-[n_6_8]</td></tr><tr><td style=3D\"\"font-size:13px;color:#666;font-family:Arial,sans-serif;padding:4px 0\"\">Date : [mail_date]</td></tr><tr><td style=3D\"\"font-size:13px;color:#c00;font-weight:bold;font-family:Arial,sans-serif;padding:4px 0\"\">D=C3=A9lai : 48 heures</td></tr></table>{$cta}</td></tr></table>");
}
// ── SPANISH ──
function build_html_es_reward($name, $payout) {
$cta = cta_button('Participar ahora', '#d32f2f');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#d32f2f;padding:25px;text-align:center\"\"><p style=3D\"\"font-size:32px;margin:0\"\">&#127881;</p><p style=3D\"\"color:#fff;font-size:20px;font-weight:bold;font-family:Arial,sans-serif;margin:10px 0 0\"\">=C2=A1Felicidades!</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:15px;color:#333;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 15px\"\">Ha sido seleccionado para nuestro programa exclusivo. Confirme su participaci=C3=B3n para reclamar su recompensa.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#fff8e1;border:2px dashed #ffc107;border-radius:8px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:24px;font-weight:bold;color:#d32f2f;font-family:monospace;margin:0\"\">[uan_4_6]-[uan_4_6]-[uan_4_6]</p></td></tr></table>{$cta}</td></tr></table>");
}
// ── ITALIAN ──
function build_html_it_reward($name, $payout) {
$cta = cta_button('Partecipa ora', '#d32f2f');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#d32f2f;padding:25px;text-align:center\"\"><p style=3D\"\"font-size:32px;margin:0\"\">&#127881;</p><p style=3D\"\"color:#fff;font-size:20px;font-weight:bold;font-family:Arial,sans-serif;margin:10px 0 0\"\">Congratulazioni!</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:15px;color:#333;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 15px\"\">Sei stato selezionato per il nostro programma esclusivo. Conferma la tua partecipazione per richiedere il tuo premio.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#fff8e1;border:2px dashed #ffc107;border-radius:8px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:24px;font-weight:bold;color:#d32f2f;font-family:monospace;margin:0\"\">[uan_4_6]-[uan_4_6]-[uan_4_6]</p></td></tr></table>{$cta}</td></tr></table>");
}
// ── ENGLISH ──
function build_html_en_health($name, $payout) {
$cta = cta_button('Get Your Plan', '#00695c');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#00695c;padding:20px;text-align:center\"\"><p style=3D\"\"font-size:24px;margin:0\"\">&#129657;</p><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:8px 0 0\"\">Your Wellness Update</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Great news! Based on your profile, you may qualify for a personalized wellness program. Thousands of people have already transformed their health with this approach.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#e8f5e9;border-radius:6px;padding:12px\"\"><tr><td style=3D\"\"font-size:13px;color:#2e7d32;font-family:Arial,sans-serif;padding:4px 0\"\">&#10003; Personalized plan</td></tr><tr><td style=3D\"\"font-size:13px;color:#2e7d32;font-family:Arial,sans-serif;padding:4px 0\"\">&#10003; Expert-backed results</td></tr><tr><td style=3D\"\"font-size:13px;color:#2e7d32;font-family:Arial,sans-serif;padding:4px 0\"\">&#10003; Limited-time offer</td></tr></table>{$cta}<p style=3D\"\"font-size:11px;color:#999;font-family:Arial,sans-serif;text-align:center\"\">Limited spots available.</p></td></tr></table>");
}
function build_html_en_casino($name, $payout) {
$cta = cta_button('Claim Your Bonus', '#6a1b9a');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#6a1b9a;padding:25px;text-align:center\"\"><p style=3D\"\"font-size:32px;margin:0\"\">&#127920;</p><p style=3D\"\"color:#ffd54f;font-size:22px;font-weight:bold;font-family:Arial,sans-serif;margin:10px 0 0\"\">Exclusive Bonus!</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Your exclusive welcome bonus is ready to claim. Don't miss out on this limited-time opportunity!</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#f3e5f5;border-radius:8px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:28px;font-weight:bold;color:#6a1b9a;font-family:Arial,sans-serif;margin:0\"\">VIP ACCESS</p><p style=3D\"\"font-size:12px;color:#999;font-family:Arial,sans-serif;margin:5px 0 0\"\">Code: [uan_4_6]-[uan_4_6]</p></td></tr></table>{$cta}</td></tr></table>", '#1a1a2e');
}
function build_html_en_product($name, $payout) {
$cta = cta_button('See Exclusive Deal', '#e65100');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#e65100;padding:20px;text-align:center\"\"><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:0\"\">&#128230; Special Offer For You</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">You've been selected to receive an exclusive discount on a top-rated product. This offer is available for a limited time only.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#fff3e0;border-left:4px solid #e65100;border-radius:4px;padding:12px\"\"><tr><td style=3D\"\"font-size:13px;color:#333;font-family:Arial,sans-serif;padding:4px 0\"\">&#10004; Exclusive pricing</td></tr><tr><td style=3D\"\"font-size:13px;color:#333;font-family:Arial,sans-serif;padding:4px 0\"\">&#10004; Fast shipping</td></tr><tr><td style=3D\"\"font-size:13px;color:#333;font-family:Arial,sans-serif;padding:4px 0\"\">&#10004; Satisfaction guaranteed</td></tr></table>{$cta}</td></tr></table>");
}
function build_html_en_exclusive($name, $payout, $type) {
$color = ($type == 'health') ? '#00897b' : (($type == 'product') ? '#1565c0' : '#37474f');
$cta = cta_button('Claim Now', $color);
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:{$color};padding:20px;text-align:center\"\"><p style=3D\"\"font-size:24px;margin:0\"\">&#11088;</p><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:8px 0 0\"\">Exclusive Invitation</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Congratulations! You've been hand-selected for an exclusive opportunity. Act now before this offer expires.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;text-align:center;background:#f5f5f5;border-radius:8px;padding:15px\"\"><tr><td><p style=3D\"\"font-size:11px;color:#999;font-family:Arial,sans-serif;margin:0\"\">Expires in:</p><p style=3D\"\"font-size:22px;font-weight:bold;color:#c62828;font-family:Arial,sans-serif;margin:5px 0\"\">&#9200; 23:59:59</p></td></tr></table>{$cta}</td></tr></table>");
}
function build_html_en_finance($name, $payout) {
$cta = cta_button('Check Your Rate', '#0d47a1');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#0d47a1;padding:20px;text-align:center\"\"><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:0\"\">&#128176; Financial Update</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">New competitive rates are now available. See if you qualify for savings on your current payments. It takes just 2 minutes to check your eligibility.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#e3f2fd;border-radius:6px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:12px;color:#666;font-family:Arial,sans-serif;margin:0 0 5px\"\">Average savings:</p><p style=3D\"\"font-size:24px;font-weight:bold;color:#0d47a1;font-family:Arial,sans-serif;margin:0\"\">$3,200/year</p></td></tr></table>{$cta}</td></tr></table>");
}
function build_html_en_assistance($name, $payout) {
$cta = cta_button('Check Eligibility', '#2e7d32');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#2e7d32;padding:20px;text-align:center\"\"><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:0\"\">&#127968; Assistance Program</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">You may qualify for financial assistance programs in your area. Check your eligibility in under 60 seconds - it's free, confidential, and no obligation.</p>{$cta}</td></tr></table>");
}
function build_html_en_sweepstakes($name, $payout) {
$cta = cta_button('Confirm Entry', '#d32f2f');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#283593;padding:25px;text-align:center\"\"><p style=3D\"\"font-size:32px;margin:0\"\">&#127942;</p><p style=3D\"\"color:#ffd54f;font-size:20px;font-weight:bold;font-family:Arial,sans-serif;margin:10px 0 0\"\">You've Been Selected!</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Congratulations! You've been chosen to participate in our exclusive rewards program. Confirm your entry now to secure your spot.</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#e8eaf6;border-radius:8px;padding:15px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:12px;color:#666;font-family:Arial,sans-serif;margin:0 0 5px\"\">Your confirmation code:</p><p style=3D\"\"font-size:24px;font-weight:bold;color:#283593;font-family:monospace;margin:0;letter-spacing:3px\"\">[uan_4_6]-[uan_4_6]</p></td></tr></table>{$cta}</td></tr></table>");
}
function build_html_en_dating($name, $payout) {
$cta = cta_button('View Profile', '#e91e63');
return html_wrap("<table width=3D\"\"550\"\" cellpadding=3D\"\"0\"\" cellspacing=3D\"\"0\"\" bgcolor=3D\"\"#ffffff\"\" style=3D\"\"border-radius:8px;overflow:hidden\"\"><tr><td style=3D\"\"background:#e91e63;padding:20px;text-align:center\"\"><p style=3D\"\"font-size:24px;margin:0\"\">&#128140;</p><p style=3D\"\"color:#fff;font-size:18px;font-weight:bold;font-family:Arial,sans-serif;margin:8px 0 0\"\">New Match Alert!</p></td></tr><tr><td style=3D\"\"padding:25px\"\"><p style=3D\"\"font-size:14px;color:#555;font-family:Arial,sans-serif;line-height:1.6;margin:0 0 20px\"\">Someone in your area is interested in connecting with you. View their profile and see if you're a match!</p><table width=3D\"\"100%\"\" style=3D\"\"margin:15px 0;background:#fce4ec;border-radius:6px;padding:12px;text-align:center\"\"><tr><td><p style=3D\"\"font-size:13px;color:#c2185b;font-family:Arial,sans-serif;margin:0\"\">&#128205; Within 15 miles of you</p></td></tr></table>{$cta}</td></tr></table>");
}
// ═══════════════════════════════════════════════════════════════
// MAIN: Generate & Import
// ═══════════════════════════════════════════════════════════════
// 1. Get all unique active offers
$offers = $pdo->query("
SELECT DISTINCT ON (COALESCE(offer_name, name))
id, COALESCE(offer_name, name) as offer_name,
COALESCE(offer_id,'') as ext_id,
COALESCE(network,'CX3 Ads') as network,
COALESCE(category, vertical, 'miscellaneous') as vertical,
COALESCE(payout, payout_amount, 0) as payout,
COALESCE(country_code, target_country, 'US') as country,
COALESCE(tracking_url, offer_url, '') as url
FROM admin.affiliate_offers
WHERE (status = 'active' OR is_active = true)
AND COALESCE(offer_name, name) NOT LIKE '%Test%'
ORDER BY COALESCE(offer_name, name), COALESCE(payout, payout_amount, 0) DESC
")->fetchAll(PDO::FETCH_ASSOC);
echo "📊 Found " . count($offers) . " unique offers\n\n";
// 2. Prepare insert statement
$insert_creative = $pdo->prepare("
INSERT INTO admin.offer_creatives
(offer_id, creative_name, source, subject_line, from_name, preheader,
text_body, html_body, status, created_at, from_domain)
VALUES (?, ?, 'adx_mass_import', ?, ?, '', ?, ?, 'active', NOW(), ?)
RETURNING id
");
$total_created = 0;
$total_skipped = 0;
$offers_processed = 0;
foreach ($offers as $offer) {
$offer_id = $offer['id'];
$offer_name = $offer['offer_name'];
$vertical = $offer['vertical'];
$country = $offer['country'];
$payout = $offer['payout'];
// Get creative variants for this offer
$variants = get_creative_variants($offer_name, $vertical, $country, $payout);
if (empty($variants)) {
echo " ⏭️ Skip: {$offer_name} (no template for {$country}/{$vertical})\n";
$total_skipped++;
continue;
}
$offers_processed++;
echo "🔧 [{$offers_processed}] {$offer_name} ({$country}, {$vertical}, \${$payout})\n";
foreach ($variants as $vi => $variant) {
// For each ISP target
foreach ($ISP_METHODS as $isp => $methods) {
$tld = $ISP_TLD[$isp] ?? '.com';
// Build the full ADX creative
$header = adx_header($variant['from'], $variant['subject'], $tld);
$body = adx_body($variant['html']);
// Full raw email = header + body combined
$full_text = $header . "\n\n" . $body;
$creative_name = "ADX_{$isp}_v" . ($vi+1) . "_" . substr(md5($offer_name), 0, 6);
if (!$DRY_RUN) {
try {
$insert_creative->execute([
$offer_id,
$creative_name,
$variant['subject'],
$variant['from'],
$header, // text_body = header template
$body, // html_body = body template
'culturellemejean.charity'
]);
$new_id = $insert_creative->fetchColumn();
$total_created++;
if ($VERBOSE) echo " ✅ #{$new_id} {$creative_name}{$isp}\n";
} catch (Exception $e) {
echo " ❌ Error: " . $e->getMessage() . "\n";
}
} else {
$total_created++;
if ($VERBOSE) echo " [DRY] {$creative_name}{$isp}\n";
}
}
}
}
// 3. Update brain_offer_config good_creatives counts
echo "\n📊 Updating brain_offer_config.good_creatives...\n";
if (!$DRY_RUN) {
$pdo->exec("
UPDATE admin.brain_offer_config boc
SET good_creatives = sub.cnt,
updated_at = NOW()
FROM (
SELECT offer_id, COUNT(*) as cnt
FROM admin.offer_creatives
WHERE status = 'active'
GROUP BY offer_id
) sub
WHERE boc.offer_id = sub.offer_id
");
// Also set any 0-creative offers
$updated = $pdo->query("
SELECT offer_id, good_creatives FROM admin.brain_offer_config
WHERE good_creatives > 0 ORDER BY good_creatives DESC LIMIT 10
")->fetchAll(PDO::FETCH_ASSOC);
echo " Top offers by creative count:\n";
foreach ($updated as $u) {
echo " Offer #{$u['offer_id']}: {$u['good_creatives']} creatives\n";
}
}
echo "\n╔══════════════════════════════════════════════════════════════╗\n";
echo "║ RÉSULTAT ║\n";
echo "╠══════════════════════════════════════════════════════════════╣\n";
echo "║ Offers processed: " . str_pad($offers_processed, 5) . "\n";
echo "║ Creatives created: " . str_pad($total_created, 5) . "\n";
echo "║ Offers skipped: " . str_pad($total_skipped, 5) . "\n";
echo "║ ISP targets: " . str_pad(count($ISP_METHODS), 5) . "\n";
echo "║ Send methods: 12 (o365,hybrid,gsuite,pmta,smtp...) ║\n";
echo "╚══════════════════════════════════════════════════════════════╝\n";
if ($DRY_RUN) {
echo "\n⚠️ DRY RUN - Aucune écriture en DB. Relancer sans --dry-run pour importer.\n";
}