<?php
/**
 * Processing Forget password form data:
 * check data then generate new password and send it through SMPT Email
 *
 * 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";
$idUser = (int) $_POST["idUser"];

if(isset($_POST['backPage']))
	$backLink = $_POST['backPage'];
else
	$backLink = 'users.php';

if(empty($_POST["idUser"])) {
	header("location:".$backLink."");
  	exit;
}
include("validateLogin.php");
include("includeInformation.php");

$fullName = mysqli_real_escape_string($conn, ($_POST["fullName"]));
$mobile = mysqli_real_escape_string($conn, ($_POST["mobile"]));
if(strlen($mobile)!=12) {
	if(substr($mobile,0,2) == "05") {
		$mobile  =substr($mobile, 1, strlen($mobile));
		$mobile = "966".$mobile;
	} elseif(substr($mobile,0,1) == "5")
		$mobile = "966".$mobile;
}
$email = mysqli_real_escape_string($conn, ($_POST["email"]));
if(empty($fullName) || empty($mobile)) {
	header("location:users.php?res=2");
	exit;
}
$querySelect = "SELECT * FROM $userLogin WHERE (mobile='".$mobile."') AND `id`!=$idUser";
$resultSelect  = mysqli_query($conn, $querySelect);
$numSelect =mysqli_num_rows($resultSelect);
if(!empty($numSelect)) {
    header("location:".$backLink."?res=2");
	exit;	
}
$query  =" UPDATE `user_login` SET";
$query .=" fullName='".$fullName."',";
$query .=" mobile='".$mobile."',";
$query .=" email='".$email."'";
$query .=" WHERE id='".$idUser."'";
$result = mysqli_query($conn, $query);
if($result) {
	header("location:".$backLink."?res=1");
	exit;
}
header("location:".$backLink."?res=2");
exit;	
ob_end_flush();
?>
