<?php
include('../../function/__data_app_db.php');
$__data_ction = 'false';
$errData = $__go_to ='';

if(isset($_POST["tkn"]) && $_POST["tkn"] == $_SESSION['signup_token']){
if (empty($_POST["user_name"])) {
    $errData .= "| Username/Phone/E-mail is required |";
  } else {
    $username = validate_jsnj_data($_POST['user_name']);
  }
if (empty($_POST["password"])) {
    $errData .= "| Password is required |";
  } else {
    $dec_password = validate_jsnj_data($_POST['password']);
    $password = md5($dec_password);
    $password_salt = $dec_password;
  }
if($errData=='')
 {	
	$query = $_conn_db->query("SELECT * FROM my_admin WHERE email = '$username' && password = '$password' && password_salt = '$password_salt' or mobile = '$username' && password = '$password' && password_salt = '$password_salt' or username = '$username' && password = '$password' && password_salt = '$password_salt'");
	$row = $query->num_rows;
	$fetch = $query->fetch_array();
		if($row > 0){
			$type = show_jsnj_data($fetch['type']);
			if($type == '1'){
			$_SESSION['user_num'] = show_jsnj_data($fetch['id']);
            $_SESSION['admin_login'] = 'true';
			$_SESSION['name'] = show_jsnj_data($fetch['name']);
			$_SESSION['password'] = show_jsnj_data($dec_password);
			$_SESSION['email'] = show_jsnj_data($fetch['email']);
			$_SESSION['mobile'] = show_jsnj_data($fetch['mobile']);
			$_SESSION['user_t'] = show_jsnj_data($fetch['type']);

				
			if(!empty($_POST['remember'])){
				setcookie("user_name", $username, time()+(10 * 365 * 24 * 60 * 60), '/');
				setcookie("user_password", $dec_password, time()+(10 * 365 * 24 * 60 * 60), '/');
			}else{
				if(ISSET($_COOKIE['user_name'])){
					setcookie("user_name", "");
				}
				if(ISSET($_COOKIE['user_password'])){
					setcookie("user_password", "");
				}
			}
	$__notif_title = 'Congratulations!';
	$__notif_disc = 'You are log in successfully please wait for dashboard.';
	$__notif_type = 'success';
	$__data_ction = 'true';
	$__go_to = 'dashboard';
   unset ($_SESSION['login_token']);
				} else {
				$__notif_title = 'Your account is temporary deactivate';
	$__notif_disc = 'Please contact us for reactivate your account';
	$__notif_type = 'danger';
			}
		}else{
	$__notif_title = 'Invalid username or password';
	$__notif_disc = 'Please enter a valid username or password';
	$__notif_type = 'danger';
		};
 }
	  else
 {
   $__notif_title = 'Oops!';
   $__notif_disc = $errData;
   $__notif_type = 'warning';
 };

$dataResult = array('page' => 'login', 'res' => $__data_ction, 'notif_title' => $__notif_title, 'notif_desc' => $__notif_disc,  'notif_type' => $__notif_type, 'goTo' => $__go_to);
echo json_encode($dataResult);  
} else {
   echo 'lol';
};
?>