<?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";
include("validateLogin.php");
include("includeInformation.php");
$msgKey = $_POST['msgKey'];
$allNumbersStatus = '';

$getMsgkeyQuery = mysqli_query($conn, "SELECT `numbers`,`history_table` FROM `temp_history`  WHERE `msg_key`='".$msgKey."'");
if( mysqli_num_rows($getMsgkeyQuery) )
{
	while( $getMsgkeyRow = mysqli_fetch_array($getMsgkeyQuery) )
	{
		$historyTBL = $getMsgkeyRow['history_table'];
		$numbersStatus = $getMsgkeyRow['numbers'];
		$allNumbersStatus = $allNumbersStatus.','.$numbersStatus;
	}

	$res = mysqli_query($conn, "SELECT numbers FROM ".$historyTBL." WHERE `msg_key` = '".$msgKey."'");
	while($row = mysqli_fetch_array($res) )
	{
		$numbersStatus = $row['numbers'];
		$allNumbersStatus = $allNumbersStatus.','.$numbersStatus;
	}
}
else
{
	$getHistoryTables = mysqli_query($conn, "SELECT DISTINCT group_id FROM `user_login`");
	
	for($c=0; $c<mysqli_num_rows($getHistoryTables); $c++)
	{	
		$historyTBL = 'history'.$c;
		$res = mysqli_query($conn, "SELECT numbers FROM ".$historyTBL." WHERE `msg_key` = '".$msgKey."'");
		if(mysqli_num_rows($res) )
		{
			while($row = mysqli_fetch_array($res) )
			{
				$numbersStatus = $row['numbers'];
				$allNumbersStatus = $allNumbersStatus.','.$numbersStatus;
			}
			break;
		}
	}
}

echo $allNumbersStatus;
ob_end_flush();
?>
