<?php

/* INSTALLER DATA
---------------------------------*/

if (!defined('PARENT')) {
  exit;
}

$dataE = [];
$dtcount = 0;

// Path / zone checks..
$root = 'http://www.example.com/affiliate';
$zone = (isset($_POST['timezone']) ? $_POST['timezone'] : 'Europe/London');
if (isset($_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'])) {
  $root = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], 'install') - 1) . '/';
}
$ini_get = ini_get_all();
if (!isset($_POST['timezone'])) {
  if (date_default_timezone_get()) {
    $zone = date_default_timezone_get();
  } else {
    if (isset($ini_get['date.timezone']) && ini_get('date.timezone')) {
      $zone = ini_get('date.timezone');
    }
  }
}

// Find / replace tags..
$f_r = array(
  '{prefix}' => DB_PREFIX,
  '{date}' => date('Y-m-d'),
  '{script}' => SCRIPT_NAME,
  '{version}' => SCRIPT_VERSION,
  '{ts}' => strtotime(date('Y-m-d H:i:s')),
  '{rss}' => date('r'),
  '{zone}' => $zone,
  '{path}' => $DB->db_escape($root),
  '{sysname}' => (isset($_POST['aff']) && $_POST['aff'] ? $DB->db_escape($_POST['aff']) : 'My Affiliate System'),
  '{email}' => (isset($_POST['em']) && mswEmVal($_POST['em']) == 'yes' ? $DB->db_escape($_POST['em']) : 'email@example.com'),
  '{key}' => mswPK()
);

// Data..
$sTables = array(
  'boxes', 'pages', 'settings', 'social'
);

// Clear existing data..
$DB->db_truncate($sTables);

// Import new data..
foreach ($sTables AS $sql_file) {
  if (file_exists(PATH . 'control/sql/' . $sql_file . '.sql')) {
    $qD = $DB->db_query(strtr(mswTmp(PATH . 'control/sql/' . $sql_file . '.sql'), $f_r));
    if (!$qD) {
      $ERR = $DB->db_error(true);
      mswInsLog(DB_PREFIX . $sql_file, $ERR[1], $ERR[0], __LINE__, __FILE__, $DB, 'Insert Standard Data (' . $sql_file . '.sql)');
      ++$dcount;
    } else {
      mswInsLog('Data successfully installed: ' . $sql_file, 'instruction');
    }
  } else {
    mswInsLog(DB_PREFIX . $sql_file, $sql_file . '.sql - file does not exist', 0, __LINE__, __FILE__, $DB, 'Insert Standard Data (' . $sql_file . '.sql)');
    ++$dcount;
  }
}

?>