<?php
/**
 * Checking login Data then redirect to index page
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    10-08-2020
 * @edited_by      Mohammad aljaouni
 * @last_edit_date 10-08-2020
 * @todo           Nothing
 */
ob_start();
session_start();
$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";
include("includeInformation.php");
unset($_SESSION["userPassword"]);
unset($_SESSION["adminName"]);
unset($_SESSION["userId"]);
unset($_SESSION["power"]);
unset($_SESSION["userAccount"]);
unset($_SESSION["otp"]);

if(empty($_POST["code"])) {
    header("location: otp.php?res=247");
    exit();
}
$code = mysqli_real_escape_string($conn, ($_POST["code"]));
if(empty($code)) {
    header("location: otp.php?res=247");
    exit();
}
$query = "SELECT * FROM user_login WHERE `id`='$_SESSION[OTPUserId]' AND `otp`='$code'";;
$result = mysqli_query($conn, $query);
if($result )
    $num = mysqli_num_rows($result);
if(empty($num)) {
    $_SESSION["otp"] = true;
    header("location: otp.php?res=246");
    exit();
} else {
    $row = mysqli_fetch_array($result);
    $_SESSION["userPassword"] = $row["password"];
	$_SESSION["adminName"] = $row["userName"];
	$_SESSION["userId"] = $row["id"];
	$_SESSION["power"] = $row["power"];
	$_SESSION["userAccount"] = $userAccount;
	$_SESSION["Language"] = 1;
	$queryInsertMove = "INSERT INTO `move_archive` (userId,`type`,`date`) VALUES ";
	$queryInsertMove .= "('".$_SESSION["userId"]."','1','".time()."')";
	$resultInsertMove = mysqli_query($conn, $queryInsertMove); 
    header("location: sendMsg.php");
    exit();
}
ob_end_flush();
?>
