<?php
function session_check()
{
  if (empty($_SESSION['logins'])) {
  ?>
  <script type="text/javascript">
    window.location.href="<?=base_url();?>";
  </script>
  <?php
  exit();
  }
}
//for admin only
function session_check_adm()
{
  if ($_SESSION['level']!=1) {
  ?>
  <script type="text/javascript">
    window.location.href="<?=base_url();?>";
  </script>
  <?php
  exit();
  }
}
//redirection 
function redirect($var)
{
  header("location:".$var);
}

function base_url()
{
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
    $root = $protocol . "://" . $_SERVER['HTTP_HOST'];
    $root .= "/" . DIR_MAIN;
    return $root;
}


// Base admin URL up to the admin folder, e.g., https://localhost/backend/admina
function base_admin()
{
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
    $root = $protocol . "://" . $_SERVER['HTTP_HOST'];
    $root .= "/" . DIR_ADMIN;
    return $root;
}

// Base index URL, e.g., https://localhost/backend/index.php/
function base_index()
{
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
    $root = $protocol . "://" . $_SERVER['HTTP_HOST'];
    $root .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
    $root .= 'index.php/';
    return $root;
}


function waktu_import($waktu) {

  $hours = floor($waktu / 3600);
  $minutes = floor(($waktu / 60) % 60);
  $seconds = $waktu % 60;

  return ($hours < 1?'':$hours.' Jam') . ($minutes < 1 ? '':$minutes.' Menit') . $seconds.' Detik';
}
?>