| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/usa_sites/governmentgrants.us/vx/usa/ai-overviews/ |
Upload File : |
<?php
session_start();
include_once($_SERVER['DOCUMENT_ROOT'].'/vx/lib/ua.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/vx/lib/func.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/vx_/site_info.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/vx/lib/mysql.php');
$user = $_SESSION['user'];
ob_start();
track_member_action('Page Visit','AI-Overviews');
if(empty($_SESSION['subscriptions']['2'])) {
$page_title = 'AI-Overviews';
$page_title_html = '
<div class="rib glyphicons glyphicons-imac va-middle v14_title_image"></div>
<div style="padding-top:6px;text-align:left;">
<h2>AI Overviews are for VIP Members!</h2>
<p style="text-align:left;font-size:10px;">Our AI reviews your profile and matches you with relevant funding opportunities from our database.</p>
</div>
<div style="clear:both;"></div>';
$redir_location = '/vx/usa/ai-overview/';
include_once($_SERVER['DOCUMENT_ROOT'].'/vx/usa/subscribe/v14.php');
}
$lead_id_res = $db->query("SELECT id FROM lc2{$siteCode}_lc.lc_leads WHERE customerID='".$db->clean($user)."'");
$lead_id = 0;
if(!empty($lead_id_res)) {
$lead_id = $lead_id_res[0]['id'];
}
// Load current profile data
$profile = [];
if($lead_id > 0) {
$profile_res = $db->query("
SELECT l.city, l.state, l.zip, lp.profile_category_id, lp.gender, lp.age, lp.citizenship, lp.money, lp.ethnicity, lp.employment_status, lp.description, lp.uniqueness
FROM lc2{$siteCode}_lc.lc_leads l
LEFT JOIN lc2{$siteCode}_lc.lead_profile lp ON lp.lead_id = l.id
WHERE l.id = {$lead_id}
");
if(!empty($profile_res)) {
$profile = $profile_res[0];
}
// Get category name from ID
$profile['category_name'] = '';
if(!empty($profile['profile_category_id'])) {
$cat_res = $db->query("SELECT category_name FROM grdb.grant_categories_new WHERE id = ".(int)$profile['profile_category_id']);
if(!empty($cat_res)) {
$profile['category_name'] = $cat_res[0]['category_name'];
}
}
}
// Check monthly update count
$updates_used = 0;
$updates_limit = 2;
if($lead_id > 0) {
$month_start = date('Y-m-01 00:00:00');
$update_count_res = $db->query("SELECT COUNT(*) as cnt FROM grdb.ai_overviews_updated WHERE site_code = '".$db->clean($siteCode)."' AND lead_id = {$lead_id} AND ts >= '{$month_start}'");
$updates_used = (int)($update_count_res[0]['cnt'] ?? 0);
}
$updates_remaining = max(0, $updates_limit - $updates_used);
// Load categories for dropdown
$categories = $db->query("SELECT id, category_name FROM grdb.grant_categories_new ORDER BY category_name");
if(empty($categories)) $categories = [];
// Load AI overviews with full grant details
$recommendations = ['start_here' => [], 'good_matches' => []];
if($lead_id > 0) {
$recs = $db->query("
SELECT r.grant_id, r.bucket, r.grant_name, r.grant_url, r.fit_summary, r.final_score, r.grant_org, r.funding_type, r.amount_min, r.amount_max,
a.overview AS ai_overview,
g.deadline, g.description AS grant_description, g.brief_summary AS grant_brief_summary,
g.org_name, g.org_phone1, g.org_email, g.org_url, g.who_can_apply,
gt.name AS application_type,
gn.categories_normalized_json
FROM grdb.profile_recommendation_feed r
LEFT JOIN grdb.ai_overviews a ON a.site_code = r.site_code AND a.lead_id = r.lead_id AND a.grant_id = r.grant_id
LEFT JOIN grdb.grd_grants g ON g.grants_id = r.grant_id
LEFT JOIN grdb.grd_types gt ON gt.types_id = g.types_id
LEFT JOIN grdb.grants_normalized gn ON gn.grant_id = r.grant_id
WHERE r.site_code = '".$db->clean($siteCode)."' AND r.lead_id = {$lead_id} AND r.released_at IS NOT NULL
ORDER BY r.final_score DESC
");
if(!empty($recs)) {
foreach($recs as $rec) {
$key = $rec['bucket'] ?? null;
if(isset($recommendations[$key])) {
$recommendations[$key][] = $rec;
}
}
}
}
$has_overviews = !empty($recommendations['start_here']) || !empty($recommendations['good_matches']);
// Load saved/favorited grants
$saved_grants = [];
if(!empty($user)) {
$saved_res = $db->query("SELECT grants_id FROM grdb.grd_usa_saved_grants WHERE site_code = '".$db->clean($siteCode)."' AND client_id = '".$db->clean($user)."'");
if(!empty($saved_res)) {
foreach($saved_res as $sg) {
$saved_grants[$sg['grants_id']] = true;
}
}
}
// Load site logos for grant URLs
$site_logos = [];
$logo_res = $db->query("SELECT site_domain, logo_url FROM grdb.grd_site_logos WHERE status = 'active'");
if(!empty($logo_res)) {
foreach($logo_res as $lr) {
$site_logos[$lr['site_domain']] = $lr['logo_url'];
}
}
// Helper: extract base domain from URL
function getBaseDomain($url) {
if(empty($url)) return '';
$host = parse_url($url, PHP_URL_HOST);
if(empty($host)) return '';
return ltrim($host, 'www.');
}
// Helper: get logo URL for a grant
function getGrantLogo($grant_url, $site_logos) {
$domain = getBaseDomain($grant_url);
if(empty($domain)) return '';
if(isset($site_logos[$domain])) return $site_logos[$domain];
// Try with www. prefix
if(isset($site_logos['www.' . $domain])) return $site_logos['www.' . $domain];
return '';
}
// Helper: format amount range
function formatAmount($min, $max) {
if($max > 0) {
return 'Up to $' . number_format($max, 0);
} elseif($min > 0) {
return '$' . number_format($min, 0) . '+';
}
return 'Varies';
}
// Helper: format deadline
function formatDeadline($deadline) {
if(empty($deadline) || $deadline === '0000-00-00') return 'Rolling';
$ts = strtotime($deadline);
if($ts === false) return 'Rolling';
return date('M j, Y', $ts);
}
// Helper: get categories from JSON
function getCategories($json) {
if(empty($json)) return '';
$cats = json_decode($json, true);
if(!is_array($cats)) return '';
return implode(', ', $cats);
}
// State options for dropdown
$states = ['AL'=>'Alabama','AK'=>'Alaska','AZ'=>'Arizona','AR'=>'Arkansas','CA'=>'California','CO'=>'Colorado','CT'=>'Connecticut','DE'=>'Delaware','DC'=>'District of Columbia','FL'=>'Florida','GA'=>'Georgia','HI'=>'Hawaii','ID'=>'Idaho','IL'=>'Illinois','IN'=>'Indiana','IA'=>'Iowa','KS'=>'Kansas','KY'=>'Kentucky','LA'=>'Louisiana','ME'=>'Maine','MD'=>'Maryland','MA'=>'Massachusetts','MI'=>'Michigan','MN'=>'Minnesota','MS'=>'Mississippi','MO'=>'Missouri','MT'=>'Montana','NE'=>'Nebraska','NV'=>'Nevada','NH'=>'New Hampshire','NJ'=>'New Jersey','NM'=>'New Mexico','NY'=>'New York','NC'=>'North Carolina','ND'=>'North Dakota','OH'=>'Ohio','OK'=>'Oklahoma','OR'=>'Oregon','PA'=>'Pennsylvania','PR'=>'Puerto Rico','RI'=>'Rhode Island','SC'=>'South Carolina','SD'=>'South Dakota','TN'=>'Tennessee','TX'=>'Texas','UT'=>'Utah','VT'=>'Vermont','VA'=>'Virginia','WA'=>'Washington','WV'=>'West Virginia','WI'=>'Wisconsin','WY'=>'Wyoming'];
// Profile display values
$p_city = htmlspecialchars($profile['city'] ?? '');
$p_state = htmlspecialchars($profile['state'] ?? '');
$p_state_full = $states[strtoupper(trim($profile['state'] ?? ''))] ?? $p_state;
$p_zip = htmlspecialchars($profile['zip'] ?? '');
$p_location = trim("{$p_city}, {$p_state_full} {$p_zip}", ', ');
$p_age = htmlspecialchars($profile['age'] ?? '');
$p_gender = htmlspecialchars($profile['gender'] ?? '-- Select --');
$p_ethnicity = htmlspecialchars($profile['ethnicity'] ?? '');
$p_category = htmlspecialchars($profile['category_name'] ?? '');
$p_citizenship = htmlspecialchars($profile['citizenship'] ?? '');
$p_employment = htmlspecialchars($profile['employment_status'] ?? '');
$p_money = htmlspecialchars($profile['money'] ?? '');
$p_description = htmlspecialchars($profile['description'] ?? '');
$p_uniqueness = htmlspecialchars($profile['uniqueness'] ?? '');
$is_vip = !empty($_SESSION['subscriptions']['2']);
$start_count = count($recommendations['start_here']);
$good_count = count($recommendations['good_matches']);
?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet">
<style>
:root {
--brand-blue: #122a86;
--brand-red: #d92b2b;
--brand-green: #1d8f47;
--ink: #1e293b;
--muted: #64748b;
--line: #e5e7eb;
--bg: #f6f8fc;
--card: #ffffff;
--start-bg: #eaf8ef;
--start-text: #1d8f47;
--good-bg: #ecf3ff;
--good-text: #2757c7;
--watch-bg: #fff5e8;
--watch-text: #b26b00;
--strong-bg: #eaf8ef;
--strong-text: #1d8f47;
--review-bg: #fff5e8;
--review-text: #b26b00;
--not-bg: #fde8e8;
--not-text: #b42318;
}
* { box-sizing: border-box; }
.ai-page {
font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
color: var(--ink);
}
.page-shell {
max-width: 1260px;
margin: 26px auto 60px;
padding: 0 18px;
}
.hero-card, .profile-card, .controls-card, .result-card {
background: var(--card);
border: 1px solid var(--line);
border-radius: 18px;
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
}
.controls-card { padding: 22px; }
.beta-banner {
display: flex; align-items: center; justify-content: space-between; gap: 14px;
padding: 14px 16px; margin-bottom: 14px;
background: linear-gradient(135deg, #fff7ed, #fffbeb);
border: 1px solid #fed7aa; border-radius: 14px; color: #9a3412;
}
.beta-badge {
display: inline-flex; align-items: center; gap: 8px;
padding: 7px 10px; border-radius: 999px; background: #fff;
border: 1px solid #fdba74; font-size: 1rem; font-weight: 800;
letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
}
.beta-copy { font-size: 1.1rem; line-height: 1.5; color: #7c2d12; }
.hero-card {
padding: 30px; margin-bottom: 18px;
background: linear-gradient(135deg, #ffffff 0%, #f7faff 100%);
}
.hero-layout {
display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, 500px);
gap: 28px; align-items: start; margin-top: 6px;
}
.hero-copy { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.hero-title-row { display: flex; align-items: center; gap: 16px; margin-bottom: 0; flex-wrap: wrap; }
.hero-ai-icon {
width: 64px; height: 64px; border-radius: 18px;
background: linear-gradient(135deg, var(--brand-blue), #1f49d8);
color: #fff; display: inline-flex; align-items: center; justify-content: center;
font-size: 1.5rem; box-shadow: 0 12px 24px rgba(18, 42, 134, .18);
}
.hero-title { font-size: clamp(2.1rem, 3.2vw, 3.2rem); font-weight: 800; margin: 0; letter-spacing: -0.04em; }
.hero-sub { color: var(--muted); font-size: 1.2rem; max-width: 860px; margin-bottom: 0; line-height: 1.6; }
.profile-inline-wrap { margin-top: 0; display: block; }
.profile-inline-wrap .profile-summary-bar {
background: #ffffff; box-shadow: 0 10px 24px rgba(15,23,42,0.06);
border: 1px solid #e5e7eb; margin-bottom: 0;
}
.profile-summary-bar {
position: relative; display: grid; gap: 14px; padding: 14px 16px;
background: rgba(255,255,255,0.65); border: 1px solid #dbe6ff; border-radius: 14px; margin-bottom: 18px;
}
.profile-summary-lines { display: grid; gap: 8px; min-width: 0; flex: 1; }
.profile-summary-line {
display: flex; align-items: center; gap: 8px; color: #334155;
font-size: 1.1rem; font-weight: 600; flex-wrap: wrap;
}
.profile-summary-line i { color: var(--brand-blue); width: 16px; text-align: center; flex-shrink: 0; }
.profile-edit-btn {
white-space: nowrap; border: 1px solid var(--brand-blue); color: var(--brand-blue);
background: #fff; border-radius: 10px; font-weight: 700; padding: 9px 14px; cursor: pointer;
}
.profile-edit-btn:hover { background: var(--brand-blue); color: #fff; }
.profile-form-wrap {
max-height: 1400px; overflow: hidden;
transition: max-height .35s ease, opacity .25s ease, margin-top .25s ease, padding-top .25s ease, border-top-color .25s ease;
opacity: 1; margin-top: 0; padding-top: 4px; border-top: 1px solid rgba(18, 42, 134, 0.08);
}
.profile-form-wrap.is-collapsed {
max-height: 0; opacity: 0; margin-top: -6px; padding-top: 0;
border-top-color: transparent; pointer-events: none;
}
.section-label {
display: inline-flex; align-items: center; gap: 8px; font-size: 1.8rem; font-weight: 700;
letter-spacing: .08em; text-transform: uppercase; color: var(--brand-blue); margin-bottom: 10px;
}
.profile-group { display: grid; gap: 10px; }
.profile-group-head {
display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 800;
color: #334155; padding-bottom: 8px; border-bottom: 1px solid rgba(18, 42, 134, 0.08); margin-bottom: 2px;
}
.profile-group-head i { color: var(--brand-blue); font-size: 1.1rem; }
.profile-row { --bs-gutter-x: 12px; --bs-gutter-y: 10px; align-items: end; }
.field-label { font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; color: #334155; }
.ai-page .form-control, .ai-page .form-select {
border-radius: 12px; border-color: #d7dce5; min-height: 44px; font-size: 1.1rem;
padding-top: 10px; padding-bottom: 10px;
}
.ai-page textarea.form-control { min-height: 108px; padding-top: 12px; }
.profile-sections { display: grid; gap: 18px; }
.updates-note { margin-top: 12px; font-size: 1.05rem; color: var(--muted); }
.btn-brand {
background: linear-gradient(135deg, var(--brand-blue), #1f49d8); border: none; border-radius: 12px;
min-height: 48px; font-weight: 700; box-shadow: 0 10px 20px rgba(18, 42, 134, .18); color: #fff;
}
.btn-brand i { color: #fff; }
.btn-brand:hover { background: linear-gradient(135deg, #102573, #1d42c1); color: #fff; }
.profile-primary-action { margin-top: 14px; }
.layout-grid { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
.tabs-wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: 100%; }
.tab-btn {
display:flex; flex-direction:column; align-items:center; justify-content:center;
border: 1px solid #d7dce5; background: #fff; color: #334155; border-radius: 12px;
padding: 12px; font-weight: 800; cursor: pointer; text-align: center;
transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.tab-desc { font-size: .95rem; font-weight: 500; margin-top: 4px; color:#64748b; line-height:1.2; }
.tab-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05); }
.tab-btn-title { display: flex; align-items: center; justify-content: center; gap: 7px; font-size: 1.15rem; }
.tab-btn.active.start { background: var(--start-bg); color: var(--start-text); border-color: #ccebd8; }
.tab-btn.active.good { background: var(--good-bg); color: var(--good-text); border-color: #d8e6ff; }
.panel { display: none; }
.panel.active { display: block; }
.results-stack { counter-reset: grant-counter; display: grid; gap: 16px; }
.result-card {
position: relative; padding: 18px 18px 18px 22px;
transition: transform .15s ease, box-shadow .15s ease; overflow: visible;
}
.result-card::before {
counter-increment: grant-counter; content: counter(grant-counter);
position: absolute; top: 16px; left: -10px;
background: var(--brand-blue); color: #fff; font-size: .75rem; font-weight: 800;
width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
box-shadow: 0 4px 10px rgba(0,0,0,.1);
}
.result-card:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(15, 23, 42, .08); }
.result-top { display: flex; justify-content: space-between; gap: 14px; align-items: start; margin-bottom: 12px; }
.result-main { display: flex; gap: 14px; align-items: flex-start; min-width: 0; flex: 1; }
.grant-logo {
width: 64px; height: 48px; border-radius: 12px; border: 1px solid #dbe3ee;
background: linear-gradient(135deg, #f8fafc, #eef4fb); color: #64748b;
display: flex; align-items: center; justify-content: center; flex-shrink: 0;
font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
overflow: hidden;
}
.grant-logo img {
max-width: 100%; max-height: 100%; object-fit: contain; display: block;
}
.result-title { margin: 0; font-size: 1.45rem; font-weight: 800; line-height: 1.35; letter-spacing: -0.01em; }
.result-title a { color: var(--ink); text-decoration: none; }
.result-title a:hover { color: var(--brand-blue); }
.ai-preview {
margin-top: 12px; color: #475569; font-size: 1.25rem; line-height: 1.6;
display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.grant-details { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 10px; color: #475569; font-size: 1.2rem; }
.grant-detail { display: flex; flex-direction: column; gap: 2px; min-width: 140px; }
.grant-detail-label { font-size: 1.05rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; color: #64748b; }
.grant-detail-value { font-weight: 700; color: #334155; }
.grant-taxonomy { margin-top: 10px; display: grid; gap: 6px; }
.grant-taxonomy-row { font-size: 1.2rem; color: #475569; }
.grant-taxonomy-row strong { color: #334155; margin-right: 6px; }
.details-panel {
display: none; margin-top: 14px; margin-left: 18px;
padding: 14px 0 0 14px; border-left: 3px solid #e2e8f0; color: #334155;
}
.details-panel.open { display: block; }
.details-label { display: block; font-size: 1rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #64748b; margin-bottom: 6px; }
.details-title { font-size: 1.55rem; font-weight: 800; line-height: 1.25; margin-bottom: 12px; color: var(--ink); }
.details-copy { font-size: 1.25rem; line-height: 1.7; color: #334155; }
.details-copy h4 { font-size: 1.2rem; margin: 18px 0 8px; font-weight: 800; color: var(--ink); }
.details-copy ul { margin: 0 0 12px 1.1rem; padding: 0; }
.details-copy li { margin-bottom: 6px; }
.details-org { margin-top: 14px; padding-top: 12px; border-top: 1px dashed #dbe3ee; font-size: 1.25rem; line-height: 1.7; }
.details-org strong { color: var(--ink); display: inline-block; min-width: 92px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.card-actions .btn { border-radius: 10px; font-weight: 700; padding: 10px 14px; font-size: 1.05rem; }
.btn-soft { background: #f8fafc; border: 1px solid #dbe3ee; color: #334155; }
.btn-outline-primary { border: 2px solid var(--brand-blue); color: var(--brand-blue); background: #fff; }
.btn-outline-primary:hover { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.btn-favorite { border: 2px solid #e11d48; color: #e11d48; background: #fff; }
.btn-favorite:hover { background: #e11d48; border-color: #e11d48; color: #fff; }
.btn-favorite.is-favorited { background: #e11d48; border-color: #e11d48; color: #fff; }
.btn-site { border: 2px solid #16a34a; color: #16a34a; background: #fff; }
.btn-site:hover { background: #16a34a; border-color: #16a34a; color: #fff; }
.summary-top { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.summary-copy { flex: 1; min-width: 280px; padding-right: 8px; }
.result-count { font-size: 1.45rem; font-weight: 800; }
.results-toolbar { display: grid; gap: 16px; margin-top: 8px; }
@media (max-width: 1100px) {
.hero-layout { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
.beta-banner { flex-direction: column; align-items: flex-start; }
.tabs-wrap { grid-template-columns: 1fr; }
.hero-title { font-size: 2.3rem; }
.result-top { flex-direction: column; padding-right: 0; }
.result-main { width: 100%; }
.summary-copy { padding-right: 0; }
}
</style>
<div class="ai-page">
<div class="page-shell">
<section class="hero-card">
<div class="section-label"><i class="fa-solid fa-microchip"></i> AI-Powered Search</div>
<div class="hero-layout">
<div class="hero-copy">
<div class="hero-title-row">
<div class="hero-ai-icon"><i class="fa-solid fa-robot"></i></div>
<div>
<h1 class="hero-title">AI Grant Research Assistant</h1>
</div>
</div>
<div class="hero-sub">
<strong>How it works:</strong><br>
1. <strong>Review your profile</strong> to make sure everything is accurate.<br>
2. <strong>Add more details</strong> — the more information you provide, the better your matches will be.<br>
3. <strong>Run your search</strong> to see your personalized funding opportunities. If the results don't look right, update your profile and search again.<br>
4. <strong>Save (<i class="fa-regular fa-heart"></i> Favorite)</strong> the grants you're interested in so you can come back and apply.<br><br>
<strong><i class="fa-solid fa-rotate"></i> New opportunities are added regularly</strong> — check back often for more matches.
</div>
</div>
<div class="profile-inline-wrap">
<div class="profile-summary-bar">
<div class="section-label" style="margin-bottom:8px;"><i class="fa-solid fa-id-card"></i> Profile</div>
<div style="font-size:1.2rem; color:#64748b; line-height:1.5; margin-bottom:10px;">Here's the information you entered when you registered.</div>
<div class="profile-summary-lines">
<?php if($p_location) { ?><div class="profile-summary-line"><i class="fa-solid fa-location-dot"></i><strong>City, State, Zip:</strong> <?=$p_location?></div><?php } ?>
<div class="profile-summary-line"><i class="fa-solid fa-user"></i><?php if($p_age) { ?><strong>Age:</strong> <?=$p_age?> • <?php } ?><strong>Gender:</strong> <?=$p_gender?></div>
<?php if($p_ethnicity) { ?><div class="profile-summary-line"><i class="fa-solid fa-earth-americas"></i><strong>Ethnicity:</strong> <?=$p_ethnicity?></div><?php } ?>
<div class="profile-summary-line"><i class="fa-solid fa-briefcase"></i><?php if($p_category) { ?><strong>Category:</strong> <?=$p_category?> • <?php } ?><?php if($p_citizenship) { ?><strong>Citizenship:</strong> <?=$p_citizenship?><?php } ?></div>
<?php if($p_employment) { ?><div class="profile-summary-line"><i class="fa-solid fa-building-user"></i><strong>Employment:</strong> <?=$p_employment?></div><?php } ?>
<?php if($p_money) { ?><div class="profile-summary-line"><i class="fa-solid fa-dollar-sign"></i><strong>Amount Needed:</strong> <?=$p_money?></div><?php } ?>
<?php if($p_uniqueness) { ?><div class="profile-summary-line"><i class="fa-solid fa-hourglass-half"></i><strong>Timeline:</strong> <?=$p_uniqueness?></div><?php } ?>
</div>
<?php if($is_vip) { ?>
<div style="margin-top:12px; display:flex; justify-content:flex-end; align-items:center; gap:12px;">
<button type="button" class="profile-edit-btn" id="toggleProfileEdit"><i class="fa-solid fa-pen-to-square me-1"></i>Edit Profile</button>
</div>
<div class="profile-form-wrap is-collapsed" id="profileFormWrap">
<form id="ai-profile-form">
<input type="hidden" name="lead_id" value="<?=$lead_id?>">
<div class="profile-sections">
<div class="profile-group">
<div class="profile-group-head"><i class="fa-solid fa-location-dot"></i> Location</div>
<div class="row profile-row">
<div class="col-md-4">
<label class="field-label">City</label>
<input class="form-control" name="city" value="<?=$p_city?>">
</div>
<div class="col-md-4">
<label class="field-label">State</label>
<select class="form-select" name="state">
<option value="">-- Select --</option>
<?php foreach($states as $abbr => $name) {
$sel = (strtoupper(trim($profile['state'] ?? '')) == $abbr) ? ' selected' : '';
echo "<option value=\"{$abbr}\"{$sel}>{$name}</option>";
} ?>
</select>
</div>
<div class="col-md-4">
<label class="field-label">Zip</label>
<input class="form-control" name="zip" value="<?=$p_zip?>" maxlength="10">
</div>
</div>
</div>
<div class="profile-group">
<div class="profile-group-head"><i class="fa-solid fa-user"></i> Profile</div>
<div class="row profile-row">
<div class="col-md-4">
<label class="field-label">Age</label>
<select class="form-select" name="age">
<option value="">-- Select --</option>
<?php
$ages = ['18-25','26-34','35-49','50-65','66-80','80+'];
foreach($ages as $a) {
$sel = (trim($profile['age'] ?? '') == $a) ? ' selected' : '';
echo "<option value=\"{$a}\"{$sel}>{$a}</option>";
} ?>
</select>
</div>
<div class="col-md-4">
<label class="field-label">Gender</label>
<select class="form-select" name="gender">
<option value="">-- Select --</option>
<?php
$genders = ['M','F'];
foreach($genders as $g) {
$sel = (strtolower(trim($profile['gender'] ?? '')) == strtolower($g)) ? ' selected' : '';
echo "<option value=\"{$g}\"{$sel}>{$g}</option>";
} ?>
</select>
</div>
<div class="col-md-4">
<label class="field-label">Ethnicity</label>
<select class="form-select" name="ethnicity">
<option value="">-- Select --</option>
<?php
$ethnicities = ['White/Caucasian','African American','Black','Hispanic','Latino','Asian','Native American','Indigenous','Arab','Middle Eastern','Pacific Islander','Multi-racial','Other'];
foreach($ethnicities as $et) {
$sel = (strtolower(trim($profile['ethnicity'] ?? '')) == strtolower($et)) ? ' selected' : '';
echo "<option value=\"{$et}\"{$sel}>{$et}</option>";
} ?>
</select>
</div>
</div>
</div>
<div class="profile-group">
<div class="profile-group-head"><i class="fa-solid fa-briefcase"></i> Background</div>
<div class="row profile-row">
<div class="col-md-4">
<label class="field-label">Category</label>
<select class="form-select" name="profile_category_id">
<option value="">-- Select --</option>
<?php foreach($categories as $cat) {
$sel = ((int)($profile['profile_category_id'] ?? 0) == (int)$cat['id']) ? ' selected' : '';
echo "<option value=\"{$cat['id']}\"{$sel}>".htmlspecialchars($cat['category_name'])."</option>";
} ?>
</select>
</div>
<div class="col-md-4">
<label class="field-label">Citizenship</label>
<select class="form-select" name="citizenship">
<option value="">-- Select --</option>
<?php
$citizenships = ['U.S. Citizen','Permanent Resident','Resident Alien','Not Sure'];
foreach($citizenships as $c) {
$sel = (strtolower(trim($profile['citizenship'] ?? '')) == strtolower($c)) ? ' selected' : '';
echo "<option value=\"{$c}\"{$sel}>{$c}</option>";
} ?>
</select>
</div>
<div class="col-md-4">
<label class="field-label">Employment Status</label>
<select class="form-select" name="employment_status">
<option value="">-- Select --</option>
<?php
$employments = ['Employed Full-Time','Employed Part-Time','Self Employed','Unemployed','Disabled','Retired','Collecting Social Security'];
foreach($employments as $e) {
$sel = (strtolower(trim($profile['employment_status'] ?? '')) == strtolower($e)) ? ' selected' : '';
echo "<option value=\"{$e}\"{$sel}>{$e}</option>";
} ?>
</select>
</div>
</div>
</div>
<div class="profile-group">
<div class="profile-group-head"><i class="fa-solid fa-money-bill-wave"></i> Funding Needs</div>
<div class="row profile-row">
<div class="col-12">
<label class="field-label">How much money do you need?</label>
<select class="form-select" name="money">
<option value="">-- Select --</option>
<?php
$amounts = ['Less than $5,000','$5,000 - $10,000','$10,000 - $25,000','$25,000 - $50,000','$50,000 - $100,000','$100,000 or More'];
foreach($amounts as $am) {
$sel = (trim($profile['money'] ?? '') == $am) ? ' selected' : '';
echo "<option value=\"{$am}\"{$sel}>{$am}</option>";
} ?>
</select>
</div>
<div class="col-12">
<label class="field-label">What do you need the money for?</label>
<textarea class="form-control" name="description" rows="3"><?=$p_description?></textarea>
</div>
<div class="col-12">
<label class="field-label">How soon do you need it?</label>
<input type="text" class="form-control" name="uniqueness" value="<?=$p_uniqueness?>">
</div>
</div>
</div>
</div>
<div class="d-grid mt-4">
<?php if($updates_remaining > 0) { ?>
<button type="submit" class="btn btn-brand">
<i class="fa-solid fa-wand-magic-sparkles me-2"></i>Update Profile & Find Grants
</button>
<div class="updates-note"><?=$updates_remaining?> of <?=$updates_limit?> updates remaining this month</div>
<?php } else { ?>
<button type="button" class="btn btn-brand" disabled>
<i class="fa-solid fa-wand-magic-sparkles me-2"></i>Update Profile & Find Grants
</button>
<div class="updates-note" style="color:#c00;">You've used all <?=$updates_limit?> updates this month. Resets next month.</div>
<?php } ?>
<span id="ai-profile-status" style="margin-top:10px;"></span>
</div>
</form>
</div>
<?php } else { ?>
<p style="margin-top:10px;"><em>Upgrade to VIP to edit your profile and get AI-powered grant matches!</em></p>
<?php } ?>
</div>
</div>
</div>
</section>
<?php if($is_vip) { ?>
<div class="layout-grid">
<?php if($has_overviews) { ?>
<div id="resultsShell">
<div class="controls-card">
<div class="beta-banner">
<div class="beta-badge"><i class="fa-solid fa-flask"></i> Beta Results</div>
<div class="beta-copy">You're viewing a beta version of AI-powered matches. Please help us improve it with your quick feedback.</div>
<div style="display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-left:auto;">
<div class="star-rating beta-star-rating" data-selected-rating="0" style="display:flex; gap:8px; font-size:2.2rem; cursor:pointer; color:#f59e0b;">
<i class="fa-regular fa-star" data-star="1"></i>
<i class="fa-regular fa-star" data-star="2"></i>
<i class="fa-regular fa-star" data-star="3"></i>
<i class="fa-regular fa-star" data-star="4"></i>
<i class="fa-regular fa-star" data-star="5"></i>
</div>
<input type="text" class="form-control beta-feedback-input" placeholder="Quick feedback..." style="max-width:320px; min-height:48px; font-size:1.15rem;">
<button class="btn btn-outline-secondary beta-feedback-submit" style="font-size:1.15rem; padding:10px 20px;">Send</button>
</div>
</div>
<div class="summary-top">
<div class="summary-copy">
<div class="result-count">Your Best Matches (Starting Set)</div>
<div class="text-secondary mt-1" style="font-size:1.2rem;">Favorite the opportunities you want to come back to, then check back often as we continue finding more grants that may fit your profile.</div>
</div>
</div>
<div class="results-toolbar">
<div class="tabs-wrap">
<button class="tab-btn active start" data-target="start-panel">
<span class="tab-btn-title"><i class="fa-solid fa-bullseye"></i> Start Here (<?=$start_count?>)</span>
<span class="tab-desc">Your strongest matches that closely align with your profile.</span>
</button>
<button class="tab-btn good" data-target="good-panel">
<span class="tab-btn-title"><i class="fa-solid fa-thumbs-up"></i> Good Match (<?=$good_count?>)</span>
<span class="tab-desc">Solid opportunities that align well with your profile.</span>
</button>
</div>
</div>
</div>
<!-- Start Here Panel -->
<div id="start-panel" class="panel active">
<div class="results-stack">
<?php if(!empty($recommendations['start_here'])) { ?>
<?php foreach($recommendations['start_here'] as $rec) { ?>
<article class="result-card">
<div class="result-top">
<div class="result-main">
<?php $logo_url = getGrantLogo($rec['grant_url'] ?? '', $site_logos); ?>
<div class="grant-logo"><?php if($logo_url) { ?><img src="<?=htmlspecialchars($logo_url)?>" alt=""><?php } else { ?>Grant<?php } ?></div>
<div>
<h3 class="result-title"><a href="<?=htmlspecialchars($rec['grant_url'] ?? '#')?>" target="_blank"><?=htmlspecialchars($rec['grant_name'] ?? 'Unnamed Grant')?></a></h3>
</div>
</div>
</div>
<div class="grant-details">
<div class="grant-detail">
<div class="grant-detail-label">Deadline</div>
<div class="grant-detail-value"><?=formatDeadline($rec['deadline'] ?? '')?></div>
</div>
<div class="grant-detail">
<div class="grant-detail-label">Amount</div>
<div class="grant-detail-value"><?=formatAmount($rec['amount_min'] ?? 0, $rec['amount_max'] ?? 0)?></div>
</div>
<?php if(!empty($rec['application_type'])) { ?>
<div class="grant-detail">
<div class="grant-detail-label">Funding Type</div>
<div class="grant-detail-value"><?=htmlspecialchars($rec['application_type'])?></div>
</div>
<?php } ?>
</div>
<?php $cats = getCategories($rec['categories_normalized_json'] ?? ''); ?>
<?php if($cats) { ?>
<div class="grant-taxonomy">
<div class="grant-taxonomy-row"><strong>Categories:</strong> <?=htmlspecialchars($cats)?></div>
</div>
<?php } ?>
<?php if(!empty($rec['ai_overview'])) { ?>
<div class="ai-preview"><?=htmlspecialchars($rec['ai_overview'])?></div>
<?php } elseif(!empty($rec['fit_summary'])) { ?>
<div class="ai-preview"><?=htmlspecialchars($rec['fit_summary'])?></div>
<?php } ?>
<?php if(!empty($rec['grant_description']) || !empty($rec['grant_brief_summary']) || !empty($rec['org_name'])) { ?>
<div class="details-panel above-actions">
<div class="details-label">Description</div>
<div class="details-title"><?=htmlspecialchars($rec['grant_name'] ?? '')?></div>
<div class="details-copy"><?=$rec['grant_description'] ?? $rec['grant_brief_summary'] ?? ''?></div>
<?php if(!empty($rec['org_name']) || !empty($rec['org_phone1']) || !empty($rec['org_email']) || !empty($rec['org_url'])) { ?>
<div class="details-org">
<?php if(!empty($rec['org_name'])) { ?><div><strong>Name:</strong> <?=htmlspecialchars($rec['org_name'])?></div><?php } ?>
<?php if(!empty($rec['org_phone1'])) { ?><div><strong>Phone:</strong> <?=htmlspecialchars($rec['org_phone1'])?></div><?php } ?>
<?php if(!empty($rec['org_email'])) { ?><div><strong>Email:</strong> <?=htmlspecialchars($rec['org_email'])?></div><?php } ?>
<?php if(!empty($rec['org_url'])) { ?><div><strong>Website:</strong> <?=htmlspecialchars($rec['org_url'])?></div><?php } ?>
<?php if(!empty($rec['who_can_apply'])) { ?><div><strong>Who Can Apply:</strong> <?=htmlspecialchars($rec['who_can_apply'])?></div><?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>
<div class="card-actions">
<button class="btn btn-outline-primary details-toggle" type="button" data-track="View Details"><i class="fa-solid fa-circle-info me-1"></i><span>View Details</span></button>
<?php $is_fav = !empty($saved_grants[$rec['grant_id']]); ?>
<button class="btn btn-favorite<?=$is_fav ? ' is-favorited' : ''?>" type="button" data-grant-id="<?=htmlspecialchars($rec['grant_id'])?>" data-track="Favorite"><?php if($is_fav) { ?><i class="fa-solid fa-heart me-1"></i>Favorited<?php } else { ?><i class="fa-regular fa-heart me-1"></i>Favorite<?php } ?></button>
<?php if(!empty($rec['grant_url'])) { ?>
<a class="btn btn-site" href="<?=htmlspecialchars($rec['grant_url'])?>" target="_blank" data-track="Go To Site"><i class="fa-solid fa-globe me-1"></i>Go To Site</a>
<?php } ?>
</div>
</article>
<?php } ?>
<?php } else { ?>
<p style="padding:20px;"><em>No "Start Here" matches found for your profile.</em></p>
<?php } ?>
</div>
</div>
<!-- Good Match Panel -->
<div id="good-panel" class="panel">
<div class="results-stack">
<?php if(!empty($recommendations['good_matches'])) { ?>
<?php foreach($recommendations['good_matches'] as $rec) { ?>
<article class="result-card">
<div class="result-top">
<div class="result-main">
<?php $logo_url = getGrantLogo($rec['grant_url'] ?? '', $site_logos); ?>
<div class="grant-logo"><?php if($logo_url) { ?><img src="<?=htmlspecialchars($logo_url)?>" alt=""><?php } else { ?>Grant<?php } ?></div>
<div>
<h3 class="result-title"><a href="<?=htmlspecialchars($rec['grant_url'] ?? '#')?>" target="_blank"><?=htmlspecialchars($rec['grant_name'] ?? 'Unnamed Grant')?></a></h3>
</div>
</div>
</div>
<div class="grant-details">
<div class="grant-detail">
<div class="grant-detail-label">Deadline</div>
<div class="grant-detail-value"><?=formatDeadline($rec['deadline'] ?? '')?></div>
</div>
<div class="grant-detail">
<div class="grant-detail-label">Amount</div>
<div class="grant-detail-value"><?=formatAmount($rec['amount_min'] ?? 0, $rec['amount_max'] ?? 0)?></div>
</div>
<?php if(!empty($rec['application_type'])) { ?>
<div class="grant-detail">
<div class="grant-detail-label">Funding Type</div>
<div class="grant-detail-value"><?=htmlspecialchars($rec['application_type'])?></div>
</div>
<?php } ?>
</div>
<?php $cats = getCategories($rec['categories_normalized_json'] ?? ''); ?>
<?php if($cats) { ?>
<div class="grant-taxonomy">
<div class="grant-taxonomy-row"><strong>Categories:</strong> <?=htmlspecialchars($cats)?></div>
</div>
<?php } ?>
<?php if(!empty($rec['ai_overview'])) { ?>
<div class="ai-preview"><?=htmlspecialchars($rec['ai_overview'])?></div>
<?php } elseif(!empty($rec['fit_summary'])) { ?>
<div class="ai-preview"><?=htmlspecialchars($rec['fit_summary'])?></div>
<?php } ?>
<?php if(!empty($rec['grant_description']) || !empty($rec['grant_brief_summary']) || !empty($rec['org_name'])) { ?>
<div class="details-panel above-actions">
<div class="details-label">Description</div>
<div class="details-title"><?=htmlspecialchars($rec['grant_name'] ?? '')?></div>
<div class="details-copy"><?=$rec['grant_description'] ?? $rec['grant_brief_summary'] ?? ''?></div>
<?php if(!empty($rec['org_name']) || !empty($rec['org_phone1']) || !empty($rec['org_email']) || !empty($rec['org_url'])) { ?>
<div class="details-org">
<?php if(!empty($rec['org_name'])) { ?><div><strong>Name:</strong> <?=htmlspecialchars($rec['org_name'])?></div><?php } ?>
<?php if(!empty($rec['org_phone1'])) { ?><div><strong>Phone:</strong> <?=htmlspecialchars($rec['org_phone1'])?></div><?php } ?>
<?php if(!empty($rec['org_email'])) { ?><div><strong>Email:</strong> <?=htmlspecialchars($rec['org_email'])?></div><?php } ?>
<?php if(!empty($rec['org_url'])) { ?><div><strong>Website:</strong> <?=htmlspecialchars($rec['org_url'])?></div><?php } ?>
<?php if(!empty($rec['who_can_apply'])) { ?><div><strong>Who Can Apply:</strong> <?=htmlspecialchars($rec['who_can_apply'])?></div><?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>
<div class="card-actions">
<button class="btn btn-outline-primary details-toggle" type="button" data-track="View Details"><i class="fa-solid fa-circle-info me-1"></i><span>View Details</span></button>
<?php $is_fav = !empty($saved_grants[$rec['grant_id']]); ?>
<button class="btn btn-favorite<?=$is_fav ? ' is-favorited' : ''?>" type="button" data-grant-id="<?=htmlspecialchars($rec['grant_id'])?>" data-track="Favorite"><?php if($is_fav) { ?><i class="fa-solid fa-heart me-1"></i>Favorited<?php } else { ?><i class="fa-regular fa-heart me-1"></i>Favorite<?php } ?></button>
<?php if(!empty($rec['grant_url'])) { ?>
<a class="btn btn-site" href="<?=htmlspecialchars($rec['grant_url'])?>" target="_blank" data-track="Go To Site"><i class="fa-solid fa-globe me-1"></i>Go To Site</a>
<?php } ?>
</div>
</article>
<?php } ?>
<?php } else { ?>
<p style="padding:20px;"><em>No "Good Match" results found for your profile.</em></p>
<?php } ?>
</div>
</div>
<div class="controls-card" style="margin-top:18px;">
<div class="beta-banner">
<div class="beta-badge"><i class="fa-solid fa-flask"></i> Beta Results</div>
<div class="beta-copy">How did we do? Rate your matches and help us improve.</div>
<div style="display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-left:auto;">
<div class="star-rating beta-star-rating" data-selected-rating="0" style="display:flex; gap:8px; font-size:2.2rem; cursor:pointer; color:#f59e0b;">
<i class="fa-regular fa-star" data-star="1"></i>
<i class="fa-regular fa-star" data-star="2"></i>
<i class="fa-regular fa-star" data-star="3"></i>
<i class="fa-regular fa-star" data-star="4"></i>
<i class="fa-regular fa-star" data-star="5"></i>
</div>
<input type="text" class="form-control beta-feedback-input" placeholder="Quick feedback..." style="max-width:320px; min-height:48px; font-size:1.15rem;">
<button class="btn btn-outline-secondary beta-feedback-submit" style="font-size:1.15rem; padding:10px 20px;">Send</button>
</div>
</div>
</div>
</div>
<?php } else { ?>
<div class="controls-card">
<p>You don't have any AI-generated grant matches yet. Update your profile above and click <strong>"Update Profile & Find Grants"</strong> to have our AI analyze your profile and find funding opportunities that match what you're looking for.</p>
</div>
<?php } ?>
</div>
<?php } else { ?>
<div class="controls-card" style="margin-top:18px;">
<p><em>Upgrade to VIP to see AI-powered grant recommendations tailored to your profile!</em></p>
</div>
<?php } ?>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Tab switching
document.querySelectorAll('.tab-btn').forEach(function(btn) {
btn.addEventListener('click', function () {
var target = this.dataset.target;
document.querySelectorAll('.tab-btn').forEach(function(b) { b.classList.remove('active'); });
this.classList.add('active');
document.querySelectorAll('.panel').forEach(function(panel) { panel.classList.remove('active'); });
var targetPanel = document.getElementById(target);
if (targetPanel) targetPanel.classList.add('active');
});
});
// Details toggle
document.querySelectorAll('.details-toggle').forEach(function(btn) {
btn.addEventListener('click', function () {
var card = this.closest('.result-card');
if (!card) return;
var panel = card.querySelector('.details-panel');
var label = this.querySelector('span');
if (!panel || !label) return;
var isOpen = panel.classList.contains('open');
panel.classList.toggle('open');
label.textContent = isOpen ? 'View Details' : 'Close Details';
});
});
// Favorite toggle (AJAX)
document.querySelectorAll('.btn-favorite').forEach(function(btn) {
btn.addEventListener('click', function () {
var el = this;
var grantId = el.getAttribute('data-grant-id');
var isOn = el.classList.contains('is-favorited');
var action = isOn ? 'remove' : 'add';
el.disabled = true;
fetch('/vx/usa/ai-overviews/toggle_favorite.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'grant_id=' + encodeURIComponent(grantId) + '&action=' + action
})
.then(function(r) { return r.json(); })
.then(function(resp) {
if (resp.success) {
el.classList.toggle('is-favorited');
var nowOn = el.classList.contains('is-favorited');
el.innerHTML = nowOn
? '<i class="fa-solid fa-heart me-1"></i>Favorited'
: '<i class="fa-regular fa-heart me-1"></i>Favorite';
}
el.disabled = false;
})
.catch(function() { el.disabled = false; });
});
});
// Track button clicks
document.querySelectorAll('[data-track]').forEach(function(el) {
el.addEventListener('click', function () {
var action = this.getAttribute('data-track');
fetch('/vx/usa/ai-overviews/track_action.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'action=' + encodeURIComponent(action)
});
});
});
// Profile edit toggle
var profileFormWrap = document.getElementById('profileFormWrap');
var toggleProfileEditBtn = document.getElementById('toggleProfileEdit');
if (toggleProfileEditBtn && profileFormWrap) {
toggleProfileEditBtn.addEventListener('click', function () {
var isCollapsed = profileFormWrap.classList.contains('is-collapsed');
profileFormWrap.classList.toggle('is-collapsed');
this.innerHTML = isCollapsed
? '<i class="fa-solid fa-xmark me-1"></i>Close Profile'
: '<i class="fa-solid fa-pen-to-square me-1"></i>Edit Profile';
});
}
// Profile form submit (AJAX to update.php)
var profileForm = document.getElementById('ai-profile-form');
if (profileForm) {
profileForm.addEventListener('submit', function(e) {
e.preventDefault();
var btn = this.querySelector('button[type=submit]');
var status = document.getElementById('ai-profile-status');
if (btn) btn.disabled = true;
if (status) status.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Updating profile and generating matches...<br><small style="color:#666;">Our AI is analyzing thousands of grants against your profile. This usually takes 1-2 minutes — please don\'t close this page.</small>';
var formData = new FormData(this);
fetch('/vx/usa/ai-overviews/update.php', {
method: 'POST',
body: new URLSearchParams(formData)
})
.then(function(r) { return r.json(); })
.then(function(resp) {
if (resp.success) {
if (status) status.innerHTML = '<i class="fa-solid fa-check" style="color:green;"></i> ' + resp.message;
setTimeout(function() { location.reload(); }, 2000);
} else {
if (status) status.innerHTML = '<i class="fa-solid fa-times" style="color:red;"></i> ' + (resp.error || 'An error occurred.');
if (btn) btn.disabled = false;
}
})
.catch(function() {
if (status) status.innerHTML = '<i class="fa-solid fa-times" style="color:red;"></i> An error occurred. Please try again.';
if (btn) btn.disabled = false;
});
});
}
// Beta star rating — works for all feedback forms on the page
function paintStars(ratingEl, value) {
ratingEl.querySelectorAll('i').forEach(function(star) {
var starValue = Number(star.getAttribute('data-star'));
if (starValue <= value) {
star.classList.remove('fa-regular');
star.classList.add('fa-solid');
} else {
star.classList.remove('fa-solid');
star.classList.add('fa-regular');
}
});
}
document.querySelectorAll('.beta-star-rating').forEach(function(ratingEl) {
ratingEl.querySelectorAll('i').forEach(function(star) {
star.addEventListener('mouseenter', function () {
paintStars(ratingEl, Number(this.getAttribute('data-star')));
});
star.addEventListener('click', function () {
var selected = Number(this.getAttribute('data-star'));
ratingEl.dataset.selectedRating = String(selected);
paintStars(ratingEl, selected);
});
});
ratingEl.addEventListener('mouseleave', function () {
paintStars(ratingEl, Number(ratingEl.dataset.selectedRating || 0));
});
});
document.querySelectorAll('.beta-feedback-submit').forEach(function(btn) {
btn.addEventListener('click', function () {
var container = btn.closest('.beta-banner');
var ratingEl = container.querySelector('.beta-star-rating');
var inputEl = container.querySelector('.beta-feedback-input');
var rating = ratingEl ? ratingEl.dataset.selectedRating : '0';
var feedback = inputEl ? inputEl.value.trim() : '';
if (rating === '0' && feedback === '') return;
btn.disabled = true;
btn.textContent = 'Sending...';
fetch('/vx/usa/ai-overviews/submit_feedback.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'rating=' + encodeURIComponent(rating) + '&feedback=' + encodeURIComponent(feedback)
})
.then(function(r) { return r.json(); })
.then(function(resp) {
btn.textContent = 'Thanks!';
if (inputEl) inputEl.value = '';
if (ratingEl) ratingEl.dataset.selectedRating = '0';
paintStars(ratingEl, 0);
setTimeout(function() {
btn.textContent = 'Send';
btn.disabled = false;
}, 2000);
})
.catch(function() {
btn.textContent = 'Error';
setTimeout(function() {
btn.textContent = 'Send';
btn.disabled = false;
}, 2000);
});
});
});
});
</script>
<?php
$body = ob_get_clean();
$title = "AI Overviews : ".$_SESSION['site_name'];
include($_SERVER['DOCUMENT_ROOT'].'/vx/usa/layout/non_angular_layout.php');
?>