<?php

/*
 * menu
 */
$menu_active = '';
$menu_sub_active = '';





/*
 * define variables
 */
GLOBAL $errors;

$imgExtension = array('jpg', 'jpeg', 'gif', 'png', 'ico');

$anyNum = rand(20, 500789000);

if (isset($_GET['success'])) {
  $success = mysqli_real_escape_string($con, $_GET['success']);
} else {
  $success = '';
}

if (isset($_GET['delete'])) {
  $delete = mysqli_real_escape_string($con, $_GET['delete']);
} else {
  $delete = '';
}

if (isset($_GET['new'])) {
  $new = mysqli_real_escape_string($con, $_GET['new']);
} else {
  $new = '';
}

if (isset($_GET['error'])) {
  $error = mysqli_real_escape_string($con, $_GET['error']);
} else {
  $error = '';
}

if (isset($_GET['tab'])) {
  $tab = mysqli_real_escape_string($con, $_GET['tab']);
} else {
  $tab = '';
}

if (isset($_GET['page'])) {
  $page = mysqli_real_escape_string($con, $_GET['page']);

  if (($page == 'edit') && (!isset($_GET['edit_id']))) {
    echo 'Something went wrong.';
    die();
  }
  if (($page == 'settings') && (!isset($_GET['edit_id']))) {
    echo 'Something went wrong.';
    die();
  }
  if (($page == 'detail') && (!isset($_GET['edit_id']))) {
    echo 'Something went wrong.';
    die();
  }
} else {
  $page = 'view';
}

if (isset($_GET['edit_id'])) {
  $edit_id = mysqli_real_escape_string($con, $_GET['edit_id']);

  if ($edit_id == '') {
    echo 'Something went wrong.';
    die();
  }
} else {
  $edit_id = '';
}

if (isset($_GET['delete_id'])) {
  $delete_id = mysqli_real_escape_string($con, $_GET['delete_id']);
} else {
  $delete_id = '';
}

if (isset($_GET['do_delete'])) {
  $do_delete = mysqli_real_escape_string($con, $_GET['do_delete']);
} else {
  $do_delete = '';
}

if (isset($_GET['type'])) {
  $type = mysqli_real_escape_string($con, $_GET['type']);
} else {
  $type = '';
}

if (isset($_GET['start_date'])) {
  $start_date = mysqli_real_escape_string($con, $_GET['start_date']);
} else {
  $start_date = '';
}

if (isset($_GET['end_date'])) {
  $end_date = mysqli_real_escape_string($con, $_GET['end_date']);
} else {
  $end_date = '';
}

if (isset($_GET['end_date'])) {
  $end_date = mysqli_real_escape_string($con, $_GET['end_date']);
} else {
  $end_date = '';
}





/*
 * define function
 */

$imgExtension = array('jpg', 'jpeg', 'gif', 'png');

function createSalt() {
  $string = md5(uniqid(rand(), true));
  return substr($string, 0, 3);
}

function timeAgo($time_ago) {
  return date('d/m/Y h:i', strtotime(str_replace('-', '/', $time_ago)));
}

/*
 * otp and superadmin check
 */
if ((isset($_SESSION['sess_user_id']))) {

  /*
   * set super admin
   */
  if ($_SESSION['sess_user_id'] == 1) {
    $superadmin = 1; // is superadmin
  } else {
    $superadmin = 0; // is not superadmin
  }


  /*
   * reset login
   */
  $data = Array(
      'last_login' => $db->now()
  );
  $db->where('id', $_SESSION['sess_user_id']);
  $db->update('users', $data);
}
