<?php
include("include/header.php");

// Auto-install columns
try { $pdo->exec("ALTER TABLE settings ADD COLUMN IF NOT EXISTS smsbus_api_token VARCHAR(255) NOT NULL DEFAULT '', ADD COLUMN IF NOT EXISTS smsbus_api_url VARCHAR(255) NOT NULL DEFAULT 'https://sms-bus.com/api/control', ADD COLUMN IF NOT EXISTS smsbus_markup FLOAT NOT NULL DEFAULT 35"); } catch(PDOException $e){}
// Auto-install tables
try { $pdo->exec("CREATE TABLE IF NOT EXISTS smsbus_countries (id INT PRIMARY KEY, title VARCHAR(150) NOT NULL, code VARCHAR(10) NOT NULL DEFAULT '', updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(PDOException $e){}
try { $pdo->exec("CREATE TABLE IF NOT EXISTS smsbus_projects (id INT PRIMARY KEY, title VARCHAR(150) NOT NULL, code VARCHAR(50) NOT NULL DEFAULT '', updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(PDOException $e){}
try { $pdo->exec("CREATE TABLE IF NOT EXISTS smsbus_prices (id INT AUTO_INCREMENT PRIMARY KEY, country_id INT NOT NULL, project_id INT NOT NULL, project_title VARCHAR(150) NOT NULL DEFAULT '', project_code VARCHAR(50) NOT NULL DEFAULT '', cost_usd FLOAT NOT NULL DEFAULT 0, our_price FLOAT NOT NULL DEFAULT 0, total_count INT NOT NULL DEFAULT 0, synced_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE KEY uq_cp (country_id, project_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(PDOException $e){}
try { $pdo->exec("CREATE TABLE IF NOT EXISTS smsbus_orders (id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, request_id INT NOT NULL UNIQUE, phone VARCHAR(30) NOT NULL, country_id INT NOT NULL, country_title VARCHAR(150) NOT NULL DEFAULT '', project_id INT NOT NULL, project_title VARCHAR(150) NOT NULL DEFAULT '', cost_usd FLOAT NOT NULL DEFAULT 0, our_price DECIMAL(12,2) NOT NULL DEFAULT 0, status VARCHAR(30) NOT NULL DEFAULT 'waiting', sms_code VARCHAR(100) NOT NULL DEFAULT '', expires_at DATETIME, received_at DATETIME, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(PDOException $e){}

$smsbus_token = ''; $smsbus_url = 'https://sms-bus.com/api/control'; $smsbus_markup = 35;
try {
    $row = $pdo->query("SELECT smsbus_api_token, smsbus_api_url, smsbus_markup FROM settings WHERE id=1")->fetch(PDO::FETCH_ASSOC);
    if ($row) {
        $smsbus_token  = trim($row['smsbus_api_token'] ?? '');
        $smsbus_url    = !empty($row['smsbus_api_url']) ? $row['smsbus_api_url'] : 'https://sms-bus.com/api/control';
        $smsbus_markup = (float)($row['smsbus_markup'] ?? 35);
    }
} catch(PDOException $e){}

$countries_count = 0; $projects_count = 0; $orders_count = 0;
try { $countries_count = (int)$pdo->query("SELECT COUNT(*) FROM smsbus_countries")->fetchColumn(); } catch(PDOException $e){}
try { $projects_count  = (int)$pdo->query("SELECT COUNT(*) FROM smsbus_projects")->fetchColumn();  } catch(PDOException $e){}
try { $orders_count    = (int)$pdo->query("SELECT COUNT(*) FROM smsbus_orders")->fetchColumn();    } catch(PDOException $e){}

// Live connection check
$conn_status = 'unconfigured'; $conn_balance = null; $conn_msg = 'No token saved yet.';
if (!empty($smsbus_token)) {
    $ch_url = rtrim($smsbus_url, '/') . '/get/balance?token=' . urlencode($smsbus_token);
    $ch = curl_init($ch_url);
    curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10, CURLOPT_CONNECTTIMEOUT=>8, CURLOPT_SSL_VERIFYPEER=>false, CURLOPT_SSL_VERIFYHOST=>0]);
    $c_raw = curl_exec($ch); $c_err = curl_error($ch); $c_eno = curl_errno($ch); $c_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($c_eno !== 0) {
        $conn_status = 'network_error';
        if ($c_eno===6)  $conn_msg = 'DNS error — cannot resolve sms-bus.com';
        elseif ($c_eno===7)  $conn_msg = 'Connection refused — port 443 may be blocked';
        elseif ($c_eno===28) $conn_msg = 'Timeout — sms-bus.com unreachable from this server';
        else $conn_msg = 'cURL error '.$c_eno.': '.$c_err;
    } else {
        $d = json_decode($c_raw, true);
        $api_code = (int)($d['code'] ?? 0);
        if ($api_code === 401) { $conn_status='token_error'; $conn_msg='Token rejected (code 401) — invalid or expired'; }
        elseif ($api_code === 200 && isset($d['data']['balance'])) {
            $conn_status='ok'; $conn_balance=(float)$d['data']['balance']; $conn_msg='';
        } elseif ($c_code === 200 && $api_code !== 200) {
            $conn_status='token_error'; $conn_msg='HTTP 200 but API code '.$api_code;
        } else { $conn_status='network_error'; $conn_msg='HTTP '.$c_code.' from sms-bus.com'; }
    }
}
$bmap = ['ok'=>['success','check-circle','Connected'],'token_error'=>['danger','times-circle','Token Error'],'network_error'=>['warning','exclamation-triangle','Network Error'],'unconfigured'=>['secondary','plug','Not Configured']];
$b = $bmap[$conn_status] ?? $bmap['unconfigured'];
?>
<title>SMS-Bus Settings</title>
<div class="container-fluid" id="container-wrapper">
  <div class="d-sm-flex align-items-center justify-content-between mb-3">
    <h1 class="h3 mb-0 text-gray-800"><i class="fas fa-bus mr-2 text-warning"></i>SMS-Bus Settings</h1>
    <ol class="breadcrumb mb-0">
      <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
      <li class="breadcrumb-item"><a href="apis.php">APIs</a></li>
      <li class="breadcrumb-item active">SMS-Bus</li>
    </ol>
  </div>

  <!-- Connection Banner -->
  <div class="row mb-4">
    <div class="col-12">
      <div class="card shadow border-left-<?php echo $b[0]; ?>" id="connBannerCard">
        <div class="card-body py-3">
          <div class="d-flex align-items-center justify-content-between flex-wrap">
            <div class="d-flex align-items-center">
              <div class="mr-3" id="connIconWrap">
                <i class="fas fa-<?php echo $b[1]; ?> fa-2x text-<?php echo $b[0]; ?>"></i>
              </div>
              <div>
                <div class="font-weight-bold text-gray-800" style="font-size:1rem;">
                  SMS-Bus API &nbsp;<span class="badge badge-<?php echo $b[0]; ?>" id="connBadge"><?php echo $b[2]; ?></span>
                </div>
                <div class="small mt-1" id="connDetail">
                  <?php if($conn_status==='ok'): ?>
                    Balance: <strong class="text-success">$<?php echo number_format($conn_balance, 4); ?></strong>
                    &bull; <span class="text-success">Token valid</span>
                  <?php else: ?><?php echo htmlspecialchars($conn_msg); ?><?php endif; ?>
                </div>
              </div>
            </div>
            <div class="mt-2 mt-md-0">
              <button class="btn btn-sm btn-outline-<?php echo $b[0]; ?>" id="btnRecheck">
                <i class="fas fa-sync-alt mr-1"></i>Re-check Connection
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- Stat Cards -->
  <div class="row mb-4">
    <div class="col-xl-3 col-md-6 mb-3">
      <div class="card border-left-info shadow h-100 py-2"><div class="card-body">
        <div class="row no-gutters align-items-center">
          <div class="col mr-2"><div class="text-xs font-weight-bold text-info text-uppercase mb-1">Countries Synced</div>
          <div class="h5 mb-0 font-weight-bold text-gray-800" id="countriesCount"><?php echo number_format($countries_count); ?></div></div>
          <div class="col-auto"><i class="fas fa-globe fa-2x text-gray-300"></i></div>
        </div>
      </div></div>
    </div>
    <div class="col-xl-3 col-md-6 mb-3">
      <div class="card border-left-success shadow h-100 py-2"><div class="card-body">
        <div class="row no-gutters align-items-center">
          <div class="col mr-2"><div class="text-xs font-weight-bold text-success text-uppercase mb-1">Projects Synced</div>
          <div class="h5 mb-0 font-weight-bold text-gray-800" id="projectsCount"><?php echo number_format($projects_count); ?></div></div>
          <div class="col-auto"><i class="fas fa-list fa-2x text-gray-300"></i></div>
        </div>
      </div></div>
    </div>
    <div class="col-xl-3 col-md-6 mb-3">
      <div class="card border-left-warning shadow h-100 py-2"><div class="card-body">
        <div class="row no-gutters align-items-center">
          <div class="col mr-2"><div class="text-xs font-weight-bold text-warning text-uppercase mb-1">API Balance</div>
          <div class="h5 mb-0 font-weight-bold text-gray-800" id="apiBalance"><?php echo $conn_status==='ok' ? '$'.number_format($conn_balance,4) : '&mdash;'; ?></div></div>
          <div class="col-auto"><i class="fas fa-wallet fa-2x text-gray-300"></i></div>
        </div>
      </div></div>
    </div>
    <div class="col-xl-3 col-md-6 mb-3">
      <div class="card border-left-primary shadow h-100 py-2"><div class="card-body">
        <div class="row no-gutters align-items-center">
          <div class="col mr-2"><div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Orders</div>
          <div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo number_format($orders_count); ?></div></div>
          <div class="col-auto"><i class="fas fa-receipt fa-2x text-gray-300"></i></div>
        </div>
      </div></div>
    </div>
  </div>

  <div class="row">
    <!-- API Config -->
    <div class="col-lg-6 mb-4">
      <div class="card shadow">
        <div class="card-header py-3"><h6 class="m-0 font-weight-bold text-warning"><i class="fas fa-key mr-2"></i>API Configuration</h6></div>
        <div class="card-body">
          <div class="form-group">
            <label class="font-weight-bold">API URL</label>
            <input type="text" class="form-control" id="smsbus_api_url" value="<?php echo htmlspecialchars($smsbus_url); ?>" placeholder="https://sms-bus.com/api/control">
            <small class="text-muted">Leave as default unless using a proxy.</small>
          </div>
          <div class="form-group">
            <label class="font-weight-bold">API Token</label>
            <div class="input-group">
              <input type="password" class="form-control" id="smsbus_api_token" value="<?php echo htmlspecialchars($smsbus_token); ?>" placeholder="Paste your SMS-Bus API token">
              <div class="input-group-append">
                <button class="btn btn-outline-secondary" type="button" onclick="toggleToken()"><i class="fas fa-eye" id="toggleTokenIcon"></i></button>
              </div>
            </div>
            <small class="text-muted">Get yours at <a href="https://sms-bus.com" target="_blank">sms-bus.com</a> → Account settings</small>
          </div>
          <div class="form-group">
            <label class="font-weight-bold">Markup <small class="text-muted font-weight-normal">(% on top of USD &times; exchange rate)</small></label>
            <div class="input-group" style="max-width:180px;">
              <input type="number" class="form-control" id="smsbus_markup" value="<?php echo $smsbus_markup; ?>" min="0" max="1000" step="0.5">
              <div class="input-group-append"><span class="input-group-text">%</span></div>
            </div>
          </div>
          <button class="btn btn-warning" id="btnSaveSettings"><i class="fas fa-save mr-1"></i>Save &amp; Test Connection</button>
        </div>
      </div>
    </div>

    <!-- Sync -->
    <div class="col-lg-6 mb-4">
      <div class="card shadow">
        <div class="card-header py-3"><h6 class="m-0 font-weight-bold text-warning"><i class="fas fa-sync-alt mr-2"></i>Data Sync</h6></div>
        <div class="card-body">
          <p class="text-muted small mb-3">Sync countries, projects and prices from SMS-Bus. Run in order: <strong>Countries</strong> &rarr; <strong>Projects</strong> &rarr; <strong>Prices</strong>.</p>
          <div class="mb-3"><button class="btn btn-outline-primary btn-block" id="btnSyncCountries"><i class="fas fa-globe mr-1"></i>Sync Countries</button></div>
          <div class="mb-3"><button class="btn btn-outline-success btn-block" id="btnSyncProjects"><i class="fas fa-mobile-alt mr-1"></i>Sync Projects</button></div>
          <div class="mb-3">
            <button class="btn btn-outline-info btn-block" id="btnSyncPrices"><i class="fas fa-tags mr-1"></i>Sync Prices</button>
            <small class="text-muted d-block text-center mt-1">One API call per country — may take a moment</small>
          </div>
          <div class="mb-1"><button class="btn btn-warning btn-block" id="btnSyncAll"><i class="fas fa-sync-alt mr-1"></i>Full Sync (Countries + Projects + Prices)</button></div>
          <div id="syncResult" class="mt-3" style="display:none;"></div>
        </div>
      </div>
    </div>
  </div>

  <!-- Guide -->
  <div class="row">
    <div class="col-12">
      <div class="card shadow mb-4">
        <div class="card-header py-3"><h6 class="m-0 font-weight-bold text-warning"><i class="fas fa-info-circle mr-2"></i>Setup Guide</h6></div>
        <div class="card-body">
          <ol class="mb-2">
            <li>Register &amp; top up at <a href="https://sms-bus.com" target="_blank">sms-bus.com</a>.</li>
            <li>Copy your API token from the account settings page.</li>
            <li>Paste the token above and click <strong>Save &amp; Test Connection</strong> — banner turns green when working.</li>
            <li>Click <strong>Sync Countries</strong>, then <strong>Sync Projects</strong>, then <strong>Sync Prices</strong>.</li>
          </ol>
          <hr class="my-2">
          <p class="mb-0 small text-muted">Base URL: <code>https://sms-bus.com/api/control</code> &bull; Auth: <code>?token=YOUR_TOKEN</code></p>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
var AJAX = 'ajax/smsbus_admin_handler.php';

function toggleToken(){var i=document.getElementById('smsbus_api_token'),c=document.getElementById('toggleTokenIcon');i.type=i.type==='password'?'text':'password';c.className=i.type==='text'?'fas fa-eye-slash':'fas fa-eye';}

var bannerMap={ok:{cls:'success',icon:'check-circle',label:'Connected'},token_error:{cls:'danger',icon:'times-circle',label:'Token Error'},network_error:{cls:'warning',icon:'exclamation-triangle',label:'Network Error'},unconfigured:{cls:'secondary',icon:'plug',label:'Not Configured'},checking:{cls:'info',icon:'spinner fa-spin',label:'Checking...'}};

function setBanner(status, detail) {
  var m = bannerMap[status] || bannerMap.unconfigured;
  var card = document.getElementById('connBannerCard');
  card.className = card.className.replace(/border-left-\w+/, 'border-left-' + m.cls);
  document.getElementById('connBadge').className = 'badge badge-' + m.cls;
  document.getElementById('connBadge').textContent = m.label;
  document.getElementById('connIconWrap').innerHTML = '<i class="fas fa-' + m.icon + ' fa-2x text-' + m.cls + '"></i>';
  document.getElementById('connDetail').innerHTML = detail || '';
  document.getElementById('btnRecheck').className = 'btn btn-sm btn-outline-' + m.cls;
}

function recheckConnection(tok, url) {
  tok = tok || $.trim($('#smsbus_api_token').val());
  url = url || $.trim($('#smsbus_api_url').val()) || 'https://sms-bus.com/api/control';
  if (!tok) { setBanner('unconfigured', 'No token — paste your API token and click Save & Test.'); return; }
  setBanner('checking', '<i class="fas fa-spinner fa-spin mr-1"></i>Contacting sms-bus.com...');
  $('#btnRecheck').prop('disabled', true);
  $.ajax({
    url: AJAX, type: 'POST',
    data: { action: 'check_smsbus_balance', smsbus_api_token: tok, smsbus_api_url: url },
    dataType: 'json', timeout: 20000,
    success: function(d) {
      $('#btnRecheck').prop('disabled', false);
      if (d.status == '1') {
        var bal = parseFloat(d.balance).toFixed(4);
        $('#apiBalance').text('$' + bal);
        setBanner('ok', 'Balance: <strong class="text-success">$' + bal + '</strong> &bull; <span class="text-success">Token valid</span>');
      } else {
        var msg = d.msg || 'Unknown error';
        var st = (msg.indexOf('401') !== -1 || msg.toLowerCase().indexOf('token') !== -1) ? 'token_error' : 'network_error';
        setBanner(st, msg);
      }
    },
    error: function(xhr, status) {
      $('#btnRecheck').prop('disabled', false);
      setBanner('network_error', status === 'timeout' ? 'Timeout — sms-bus.com unreachable from this server' : 'Ajax failed — check PHP error logs');
    }
  });
}

$('#btnRecheck').on('click', function() { recheckConnection(); });

$('#btnSaveSettings').on('click', function() {
  var $b = $(this), tok = $.trim($('#smsbus_api_token').val()), url = $.trim($('#smsbus_api_url').val()) || 'https://sms-bus.com/api/control', mkp = parseFloat($('#smsbus_markup').val());
  if (isNaN(mkp) || mkp < 0) mkp = 35;
  if (!tok) { Swal.fire('Missing Token', 'Paste your SMS-Bus API Token first.', 'warning'); return; }
  $b.prop('disabled', true).html('<i class="fas fa-spinner fa-spin mr-1"></i>Saving...');
  $.ajax({
    url: AJAX, type: 'POST',
    data: { action: 'save_smsbus_settings', smsbus_api_url: url, smsbus_api_token: tok, smsbus_markup: mkp },
    dataType: 'json',
    success: function(d) {
      $b.prop('disabled', false).html('<i class="fas fa-save mr-1"></i>Save &amp; Test Connection');
      if (d.status == '1') { recheckConnection(tok, url); }
      else { Swal.fire('Save Error', d.msg || 'Could not save.', 'error'); }
    },
    error: function(xhr) { $b.prop('disabled', false).html('<i class="fas fa-save mr-1"></i>Save &amp; Test Connection'); Swal.fire('Failed', xhr.responseText || 'No response', 'error'); }
  });
});

function runSync(action, $btn, orig, cb) {
  $btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin mr-1"></i>Syncing...');
  $('#syncResult').html('<div class="alert alert-info mb-0"><i class="fas fa-spinner fa-spin mr-2"></i>Working...</div>').show();
  $.ajax({
    url: AJAX, type: 'POST', data: { action: action }, dataType: 'json', timeout: 360000,
    success: function(d) {
      $btn.prop('disabled', false).html(orig);
      var cls = d.status == '1' ? 'alert-success' : 'alert-danger', ico = d.status == '1' ? 'check-circle' : 'times-circle';
      $('#syncResult').html('<div class="alert ' + cls + ' mb-0"><i class="fas fa-' + ico + ' mr-2"></i>' + (d.msg || JSON.stringify(d)) + '</div>').show();
      if (d.status == '1' && cb) cb(d);
    },
    error: function(xhr, st) {
      $btn.prop('disabled', false).html(orig);
      var m = st === 'timeout' ? 'Timed out — sync may still be running server-side.' : 'Request failed.';
      $('#syncResult').html('<div class="alert alert-danger mb-0"><i class="fas fa-exclamation-triangle mr-2"></i>' + m + '</div>').show();
    }
  });
}

$('#btnSyncCountries').on('click', function() {
  runSync('sync_smsbus_countries', $(this), '<i class="fas fa-globe mr-1"></i>Sync Countries', function(d) { if (d.total) $('#countriesCount').text(d.total); });
});

$('#btnSyncProjects').on('click', function() {
  runSync('sync_smsbus_projects', $(this), '<i class="fas fa-mobile-alt mr-1"></i>Sync Projects', function(d) { if (d.total) $('#projectsCount').text(d.total); });
});

$('#btnSyncPrices').on('click', function() {
  var $btn = $(this), orig = '<i class="fas fa-tags mr-1"></i>Sync Prices';
  Swal.fire({ title: 'Sync Prices?', html: 'Calls the API once per country.<br><strong>May take a moment.</strong>', icon: 'question', showCancelButton: true, confirmButtonColor: '#f6c23e', confirmButtonText: 'Yes, Sync' }).then(function(r) {
    if (!r.isConfirmed) return;
    runSync('sync_smsbus_prices', $btn, orig);
  });
});

$('#btnSyncAll').on('click', function() {
  var $btn = $(this), orig = '<i class="fas fa-sync-alt mr-1"></i>Full Sync (Countries + Projects + Prices)';
  Swal.fire({ title: 'Full Sync?', html: 'Countries then Projects then Prices.', icon: 'question', showCancelButton: true, confirmButtonColor: '#f6c23e', confirmButtonText: 'Yes, Full Sync' }).then(function(r) {
    if (!r.isConfirmed) return;
    $btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin mr-1"></i>Syncing countries...');
    $('#syncResult').html('<div class="alert alert-info mb-0"><i class="fas fa-spinner fa-spin mr-2"></i>Step 1/3 — countries...</div>').show();
    $.ajax({ url: AJAX, type: 'POST', data: { action: 'sync_smsbus_countries' }, dataType: 'json', timeout: 60000,
      success: function(d1) {
        if (d1.total) $('#countriesCount').text(d1.total);
        $btn.html('<i class="fas fa-spinner fa-spin mr-1"></i>Syncing projects...');
        $('#syncResult').html('<div class="alert alert-info mb-0"><i class="fas fa-spinner fa-spin mr-2"></i>Step 2/3 — projects...</div>').show();
        $.ajax({ url: AJAX, type: 'POST', data: { action: 'sync_smsbus_projects' }, dataType: 'json', timeout: 60000,
          success: function(d2) {
            if (d2.total) $('#projectsCount').text(d2.total);
            $btn.html('<i class="fas fa-spinner fa-spin mr-1"></i>Syncing prices...');
            $('#syncResult').html('<div class="alert alert-info mb-0"><i class="fas fa-spinner fa-spin mr-2"></i>Step 3/3 — prices...</div>').show();
            $.ajax({ url: AJAX, type: 'POST', data: { action: 'sync_smsbus_prices' }, dataType: 'json', timeout: 360000,
              success: function(d3) {
                $btn.prop('disabled', false).html(orig);
                var ok = d1.status == '1' && d2.status == '1' && d3.status == '1';
                $('#syncResult').html('<div class="alert ' + (ok ? 'alert-success' : 'alert-warning') + ' mb-0"><strong>Countries:</strong> ' + (d1.msg || '') + '<br><strong>Projects:</strong> ' + (d2.msg || '') + '<br><strong>Prices:</strong> ' + (d3.msg || '') + '</div>').show();
              },
              error: function() { $btn.prop('disabled', false).html(orig); $('#syncResult').html('<div class="alert alert-warning mb-0">Countries & Projects OK. Prices failed.</div>').show(); }
            });
          },
          error: function() { $btn.prop('disabled', false).html(orig); $('#syncResult').html('<div class="alert alert-warning mb-0">Countries OK. Projects failed.</div>').show(); }
        });
      },
      error: function() { $btn.prop('disabled', false).html(orig); $('#syncResult').html('<div class="alert alert-danger mb-0">Countries sync failed.</div>').show(); }
    });
  });
});
</script>
<?php include("include/footer.php"); ?>
