<?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();
if(empty($_POST["userName"]) || empty($_POST["password"]) || empty($_POST["email"]) || empty($_POST["mobile"]))
{
	header("location: users.php?res=2");
	exit;
}
$userName = trim($_POST["userName"]);
$password = $_POST["password"];
$email = trim($_POST["email"]);
$mobile = trim($_POST["mobile"]);
if(empty($userName) || empty($password) || empty($email) || empty($mobile))
{
	header("location: users.php?res=2");
	exit;
}
$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";
include("validateLogin.php");
include("includeInformation.php");

$pass = 0;
$query = "SELECT id, userName, password, mobile FROM $userLogin WHERE userName='".$userName ."' OR mobile='".$mobile."'";
$result = mysqli_query($conn, $query);
$num=mysqli_num_rows($result);
if(empty($num))
{    
	$passwordMd5 = md5($password);
	$fullName = $_POST["fullName"];
	$defSender = "";
	if(!empty($_POST["sender2"]))
		$defSender = $_POST["sender2"];
	$queryInsert = "INSERT INTO ".$userLogin." (fatherId,power,userName,password,fullName,mobile,email,sendMSG,activetAcount,sender,date) values ";
	$queryInsert .= "('".$userId."','+','".$userName."','".$passwordMd5."','".$fullName."','".$mobile."','".$email."','1','1','".$defSender."','".time()."')";
	$resultInsert = mysqli_query($conn, $queryInsert);
	if($resultInsert)
	{
		header("location:users.php?res=1");
		exit();
	}else{
		header("location:users.php?res=2");
		exit();
	}
}
else
{
	$row = mysqli_fetch_row($result);
	if($row[3] == $userMobily)
	{
		header("location:users.php?res=13");
		exit();
	}
	elseif($row[1]==$userName)
	{
		header("location:users.php?res=12");
		exit();
	}
}
?>
