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

try { $pdo->exec("ALTER TABLE settings ADD COLUMN IF NOT EXISTS fivesim_api_token VARCHAR(255) NOT NULL DEFAULT '', ADD COLUMN IF NOT EXISTS fivesim_api_url VARCHAR(255) NOT NULL DEFAULT 'https://5sim.net/v1', ADD COLUMN IF NOT EXISTS fivesim_markup FLOAT NOT NULL DEFAULT 35"); } catch(PDOException $e){}
try { $pdo->exec("CREATE TABLE IF NOT EXISTS fivesim_countries (id INT AUTO_INCREMENT PRIMARY KEY, country_key VARCHAR(100) NOT NULL UNIQUE, title VARCHAR(150) NOT NULL, iso VARCHAR(10) NOT NULL DEFAULT '', prefix VARCHAR(20) NOT NULL DEFAULT '', updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(PDOException $e){}
try { $pdo->exec("CREATE TABLE IF NOT EXISTS fivesim_products (id INT AUTO_INCREMENT PRIMARY KEY, country_key VARCHAR(100) NOT NULL, product VARCHAR(150) NOT NULL, category VARCHAR(50) NOT NULL DEFAULT 'activation', qty INT NOT NULL DEFAULT 0, cost_usd FLOAT NOT NULL DEFAULT 0, our_price FLOAT NOT NULL DEFAULT 0, synced_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE KEY uq_cp (country_key, product)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(PDOException $e){}
try { $pdo->exec("CREATE TABLE IF NOT EXISTS fivesim_orders (id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, order_id5 BIGINT NOT NULL UNIQUE, phone VARCHAR(30) NOT NULL, country_key VARCHAR(100) NOT NULL, country_name VARCHAR(150) NOT NULL DEFAULT '', product VARCHAR(150) NOT NULL, operator VARCHAR(100) NOT NULL DEFAULT 'any', 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(50) NOT NULL DEFAULT '', sms_text TEXT, expires_at DATETIME, received_at DATETIME, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); $pdo->exec("ALTER TABLE fivesim_orders MODIFY COLUMN order_id5 BIGINT NOT NULL"); } catch(PDOException $e){}

$fivesim_token = ''; $fivesim_url = 'https://5sim.net/v1'; $fivesim_markup = 35;
try {
    $row = $pdo->query("SELECT fivesim_api_token, fivesim_api_url, fivesim_markup FROM settings WHERE id=1")->fetch(PDO::FETCH_ASSOC);
    if ($row) {
        $fivesim_token  = trim($row['fivesim_api_token'] ?? '');
        $fivesim_url    = !empty($row['fivesim_api_url']) ? $row['fivesim_api_url'] : 'https://5sim.net/v1';
        $fivesim_markup = (float)($row['fivesim_markup'] ?? 35);
    }
} catch(PDOException $e){}

$countries_count = 0; $products_count = 0; $orders_count = 0;
try { $countries_count = (int)$pdo->query("SELECT COUNT(*) FROM fivesim_countries")->fetchColumn(); } catch(PDOException $e){}
try { $products_count  = (int)$pdo->query("SELECT COUNT(*) FROM fivesim_products")->fetchColumn();  } catch(PDOException $e){}
try { $orders_count    = (int)$pdo->query("SELECT COUNT(*) FROM fivesim_orders")->fetchColumn();    } catch(PDOException $e){}

$conn_status = 'unconfigured'; $conn_balance = null; $conn_rating = null; $conn_msg = 'No token saved yet.';
if (!empty($fivesim_token)) {
    $ch = curl_init(rtrim($fivesim_url,'/').'/user/profile');
    curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>true,CURLOPT_TIMEOUT=>10,CURLOPT_CONNECTTIMEOUT=>8,CURLOPT_SSL_VERIFYPEER=>false,CURLOPT_SSL_VERIFYHOST=>0,CURLOPT_HTTPHEADER=>['Authorization: Bearer '.$fivesim_token,'Accept: application/json']]);
    $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 5sim.net';
        elseif ($c_eno===7)  $conn_msg = 'Connection refused — port 443 may be blocked';
        elseif ($c_eno===28) $conn_msg = 'Timeout — 5sim.net unreachable from this server';
        else $conn_msg = 'cURL error '.$c_eno.': '.$c_err;
    } elseif ($c_code===401) { $conn_status='token_error'; $conn_msg='Token rejected (HTTP 401) — invalid or expired'; }
    elseif ($c_code===403) { $conn_status='token_error'; $conn_msg='Token forbidden (HTTP 403)'; }
    elseif ($c_code===200) {
        $d = json_decode($c_raw, true);
        if (isset($d['balance'])) { $conn_status='ok'; $conn_balance=(float)$d['balance']; $conn_rating=(int)($d['rating']??0); $conn_msg=''; }
        else { $conn_status='token_error'; $conn_msg='HTTP 200 but no balance field in response'; }
    } else { $conn_status='network_error'; $conn_msg='HTTP '.$c_code.' from 5sim.net'; }
}
$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>5SIM 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-mobile-alt mr-2 text-info"></i>5SIM 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">5SIM</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;">
                  5SIM 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; Rating: <strong><?php echo $conn_rating; ?>/96</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">Products Synced</div>
          <div class="h5 mb-0 font-weight-bold text-gray-800" id="productsCount"><?php echo number_format($products_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) : '—'; ?></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-info"><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="fivesim_api_url" value="<?php echo htmlspecialchars($fivesim_url); ?>" placeholder="https://5sim.net/v1">
            <small class="text-muted">Leave as default unless using a proxy.</small>
          </div>
          <div class="form-group">
            <label class="font-weight-bold">Bearer Token</label>
            <div class="input-group">
              <input type="password" class="form-control" id="fivesim_api_token" value="<?php echo htmlspecialchars($fivesim_token); ?>" placeholder="Paste token from 5sim.net → Settings → Security">
              <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://5sim.net/settings/security" target="_blank">5sim.net → Settings → Security</a></small>
          </div>
          <div class="form-group">
            <label class="font-weight-bold">Markup <small class="text-muted font-weight-normal">(% on top of USD × exchange rate)</small></label>
            <div class="input-group" style="max-width:180px;">
              <input type="number" class="form-control" id="fivesim_markup" value="<?php echo $fivesim_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-info" 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-info"><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 and products from 5SIM. Run <strong>Sync Countries</strong> first, then <strong>Sync Products</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="btnSyncProducts"><i class="fas fa-list mr-1"></i>Sync Products &amp; Prices</button>
            <small class="text-muted d-block text-center mt-1">One API call per country — takes 1–3 min</small>
          </div>
          <div class="mb-1"><button class="btn btn-info btn-block" id="btnSyncAll"><i class="fas fa-sync-alt mr-1"></i>Full Sync (Countries + Products)</button></div>
          <hr class="my-3">
          <div class="mb-1"><button class="btn btn-danger btn-block" onclick="deleteAll5sim()"><i class="fas fa-trash-alt mr-1"></i>Delete All 5SIM Data</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-info"><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://5sim.net" target="_blank">5sim.net</a>.</li>
            <li>Go to <a href="https://5sim.net/settings/security" target="_blank">Settings → Security</a> and copy your API Token.</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 Products &amp; Prices</strong>.</li>
          </ol>
          <hr class="my-2">
          <p class="mb-0 small text-muted">Base URL: <code>https://5sim.net/v1</code> &bull; Auth: <code>Authorization: Bearer &lt;token&gt;</code> &bull; <a href="https://5sim.net/docs" target="_blank">Docs</a></p>
        </div>
      </div>
    </div>
  </div>
</div>

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

function toggleToken(){var i=document.getElementById('fivesim_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($('#fivesim_api_token').val());
  url=url||$.trim($('#fivesim_api_url').val())||'https://5sim.net/v1';
  if(!tok){setBanner('unconfigured','No token — paste your bearer token and click Save & Test.');return;}
  setBanner('checking','<i class="fas fa-spinner fa-spin mr-1"></i>Contacting 5sim.net...');
  $('#btnRecheck').prop('disabled',true);
  $.ajax({url:AJAX,type:'POST',data:{action:'check_fivesim_balance',fivesim_api_token:tok,fivesim_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),rat=d.rating||'—';
        $('#apiBalance').text('$'+bal);
        setBanner('ok','Balance: <strong class="text-success">$'+bal+'</strong> &bull; Rating: <strong>'+rat+'/96</strong> &bull; <span class="text-success">Token valid</span>');
      } else {
        var msg=d.msg||'Unknown error';
        var st=(msg.indexOf('401')!==-1||msg.indexOf('403')!==-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 — 5sim.net unreachable from this server':'Ajax failed — check PHP error logs');
    }
  });
}

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

$('#btnSaveSettings').on('click',function(){
  var $b=$(this),tok=$.trim($('#fivesim_api_token').val()),url=$.trim($('#fivesim_api_url').val())||'https://5sim.net/v1',mkp=parseFloat($('#fivesim_markup').val());
  if(isNaN(mkp)||mkp<0)mkp=35;
  if(!tok){Swal.fire('Missing Token','Paste your 5SIM Bearer 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_fivesim_settings',fivesim_api_url:url,fivesim_api_token:tok,fivesim_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_fivesim_countries',$(this),'<i class="fas fa-globe mr-1"></i>Sync Countries',function(d){if(d.total)$('#countriesCount').text(d.total);});});

$('#btnSyncProducts').on('click',function(){
  var $btn=$(this),orig='<i class="fas fa-list mr-1"></i>Sync Products &amp; Prices';
  Swal.fire({title:'Sync Products?',html:'Calls the API once per country.<br><strong>May take 1-3 minutes.</strong>',icon:'question',showCancelButton:true,confirmButtonColor:'#17a2b8',confirmButtonText:'Yes, Sync'}).then(function(r){
    if(!r.isConfirmed)return;
    runSync('sync_fivesim_products',$btn,orig,function(d){if(d.total_products)$('#productsCount').text(d.total_products);});
  });
});

$('#btnSyncAll').on('click',function(){
  var $btn=$(this),orig='<i class="fas fa-sync-alt mr-1"></i>Full Sync (Countries + Products)';
  Swal.fire({title:'Full Sync?',html:'Countries then products.<br>May take 1-3 minutes.',icon:'question',showCancelButton:true,confirmButtonColor:'#17a2b8',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/2 — countries...</div>').show();
    $.ajax({url:AJAX,type:'POST',data:{action:'sync_fivesim_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 products...');
        $('#syncResult').html('<div class="alert alert-info mb-0"><i class="fas fa-spinner fa-spin mr-2"></i>Step 2/2 — products...</div>').show();
        $.ajax({url:AJAX,type:'POST',data:{action:'sync_fivesim_products'},dataType:'json',timeout:360000,
          success:function(d2){
            $btn.prop('disabled',false).html(orig);
            if(d2.total_products)$('#productsCount').text(d2.total_products);
            var ok=d1.status=='1'&&d2.status=='1';
            $('#syncResult').html('<div class="alert '+(ok?'alert-success':'alert-warning')+' mb-0"><strong>Countries:</strong> '+(d1.msg||'')+'<br><strong>Products:</strong> '+(d2.msg||'')+'</div>').show();
          },
          error:function(xhr,st){$btn.prop('disabled',false).html(orig);$('#syncResult').html('<div class="alert alert-warning mb-0"><strong>Countries OK.</strong> '+(st==='timeout'?'Products timed out.':'Products 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();}
    });
  });
});

function deleteAll5sim() {
    Swal.fire({
        title: 'Delete ALL 5SIM Data?',
        html: '<p class="text-danger"><strong>This deletes all 5SIM countries and products from your database.</strong></p><p>You can re-sync after.</p>',
        icon: 'warning', showCancelButton: true,
        confirmButtonColor: '#e74a3b',
        confirmButtonText: '<i class="fas fa-trash-alt mr-1"></i> Delete All',
    }).then(function(r) {
        if (!r.isConfirmed) return;
        $.ajax({
            url: 'ajax/fivesim_admin_handler.php',
            type: 'POST', data: { action: 'delete_all_data' }, dataType: 'json',
            success: function(d) {
                if (d.status == '1') {
                    Swal.fire({icon:'success', title:'Done!', text:d.msg, timer:2000, showConfirmButton:false}).then(function(){location.reload();});
                } else { Swal.fire('Error', d.msg, 'error'); }
            },
            error: function() { Swal.fire('Error', 'Request failed.', 'error'); }
        });
    });
}
</script>
<?php include("include/footer.php"); ?>
