<?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");
$msgId = $_POST['msgId'];
$tableName = $_POST['tableName'];
$arrayVal = $_POST['arrayVal']+1;
$allNumbersStatus = array();
$allNumbersStatusNew = array();
$arryDataVal = array();
$arryDataVal[] = '0';
if(in_array($arrayVal, $arryDataVal))
	$arrayVal = $arrayVal+1;
$realTime = "";
if(empty($tableName))
	$getMsgkeyQuery = mysqli_query($conn, "SELECT `numbers_status`,`numbers`,`real_insert_time`  FROM `temp_history`  WHERE `id` = '".$msgId."'");
else
	$getMsgkeyQuery = mysqli_query($conn, "SELECT `numbers_status`,`numbers`,`real_insert_time`  FROM `".$tableName."` WHERE `id` = '".$msgId."'");
$getMsgkeyRow = mysqli_fetch_array($getMsgkeyQuery);	
$arrayData = array();
$realTime = $getMsgkeyRow['real_insert_time'];
$numbersStatus = unserialize($getMsgkeyRow['numbers_status']);
if(is_array($numbersStatus)){
	$numbersArray = explode(",",$getMsgkeyRow['numbers']);
	foreach($numbersArray as $key=>$value){
		if(is_array($numbersStatus[$value])){
			$arrayData[$value] =$numbersStatus[$value][0];
			$allNumbersStatusNew = $allNumbersStatusNew + $numbersStatus;
		}
		else{
			$arrayData[$value] = $numbersStatus[$value];
		}
	}
}
$allNumbersStatus = $allNumbersStatus + $arrayData;
$reurnVval = "";
$valcolor = $_POST['valcolor'];
$allNumbersStatusVal = array_chunk($allNumbersStatus,100,true);
if(!array_key_exists($arrayVal, $allNumbersStatusVal)){
	echo $data=$reurnVval."#$#".$arrayVal."#$#".$valcolor;
	exit;
}
$allNumbersStatus = $allNumbersStatusVal[$arrayVal];
$arryDataVal[] = $arrayVal;
$notSend1 = array_keys($allNumbersStatus, -1);
$notSend2 = array_keys($allNumbersStatus, 10);
$notSend3 = array_keys($allNumbersStatus, 11);
$notSend4 = array_keys($allNumbersStatus, 12);
$notSend5 = array_keys($allNumbersStatus, 13);
$notSend6 = array_keys($allNumbersStatus, 14);
$notSend7 = array_keys($allNumbersStatus, 15);
$notSend8 = array_keys($allNumbersStatus, 17);
$notSend9 = array_keys($allNumbersStatus, 19);
$notSend10 = array_keys($allNumbersStatus, 20);
$notSend11 = array_keys($allNumbersStatus, 21);
$notSend12 = array_keys($allNumbersStatus, 51);
$notSend13 = array_keys($allNumbersStatus, 52);
$notSend14 = array_keys($allNumbersStatus, 64);
$notSend15 = array_keys($allNumbersStatus, 66);
$notSend16 = array_keys($allNumbersStatus, 67);
$notSend17 = array_keys($allNumbersStatus, 68);
$notSend18 = array_keys($allNumbersStatus, 69);
$notSend19 = array_keys($allNumbersStatus, 72);
$notSend20 = array_keys($allNumbersStatus, 73);
$notSend21 = array_keys($allNumbersStatus, 80);
$notSend22 = array_keys($allNumbersStatus, 81);
$notSend23 = array_keys($allNumbersStatus, 83);
$notSend24 = array_keys($allNumbersStatus, 84);
$notSend25 = array_keys($allNumbersStatus, 85);
$notSend27 = array_keys($allNumbersStatus, 88);
$notSend28 = array_keys($allNumbersStatus, 97);
$notSend29 = array_keys($allNumbersStatus, 98);
$notSend30 = array_keys($allNumbersStatus, 99);
$notSend = array_merge($notSend1,$notSend2,$notSend3,$notSend4,$notSend5,$notSend6,$notSend7,$notSend8,$notSend9,$notSend10,$notSend11,$notSend12,$notSend13,$notSend14,$notSend15,$notSend16,$notSend17,$notSend18,$notSend19,$notSend20,$notSend21,$notSend22,$notSend23,$notSend24,$notSend25,$notSend27,$notSend28,$notSend29,$notSend30);
$sent = array_keys($allNumbersStatus, 0);
$failed = array_keys($allNumbersStatus, 1);
$delivered = array_keys($allNumbersStatus, 2);
$unDelivered = array_keys($allNumbersStatus, 5);
$deleted = array_keys($allNumbersStatus, 6);
?>

<?php
if(!empty($notSend))
{
	foreach($notSend as $key=>$val){
		$aa = "";
		$bb = "";
		$cc = "";
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][2]) && is_integer($allNumbersStatusNew[$val][2]) && (strlen($allNumbersStatusNew[$val][2])<=14 && strlen($allNumbersStatusNew[$val][2])>=10)) 
			$aa = " <b>/</b> ".date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][2]);
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][1]) && is_integer($allNumbersStatusNew[$val][1]) && (strlen($allNumbersStatusNew[$val][1])<=14 && strlen($allNumbersStatusNew[$val][1])>=10) ) 
			$bb =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][1]); 
		else 
			$bb = "---";
		if(isset($allNumbersStatusNew[$val][4]) && !empty($allNumbersStatusNew[$val][4])) 
			$cc =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][4]); 
		else 
			$cc = "---";	
		if($valcolor%2==1)
				$color ="background-color:#f1f1f1;";
		else
					$color ="background-color:#ffffff;";	
	$reurnVval.= '<tr style="'.$color.'">
		<td style="text-align:center">'.$val.'</td>
		<td style="text-align:center">'.date('Y/m/d h:i:s a',$realTime).'</td>
		<td style="text-align:center">'.$cc.'</td>
		<td style="text-align:center">'.$bb.'</td>
		<td style="text-align:center">'.$messageStatusLBL[4].$aa.'</td>
	</tr>';
	$valcolor++;
	}
}?>
 <?php
if(!empty($sent))
{
	foreach($sent as $key=>$val){
		$aa = "";
		$bb = "";
$cc = "";
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][2]) && is_integer($allNumbersStatusNew[$val][2]) && (strlen($allNumbersStatusNew[$val][2])<=14 && strlen($allNumbersStatusNew[$val][2])>=10)) 
			$aa = " <b>/</b> ".date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][2]);
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][1]) && is_integer($allNumbersStatusNew[$val][1]) && (strlen($allNumbersStatusNew[$val][1])<=14 && strlen($allNumbersStatusNew[$val][1])>=10) ) 
			$bb = date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][1]); 
		else 
			$bb = "---";	
		if(isset($allNumbersStatusNew[$val][4]) && !empty($allNumbersStatusNew[$val][4])) 
			$cc =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][4]); 
		else 
			$cc = "---";		
			if($valcolor%2==1)
				$color ="background-color:#f1f1f1;";
		else
					$color ="background-color:#ffffff;";	
	$reurnVval.= '<tr style="'.$color.'">
		<td style="text-align:center">'.$val.'</td>
		<td style="text-align:center">'.date('Y/m/d h:i:s a',$realTime).'</td>
		<td style="text-align:center">'.$cc.'</td>
		<td style="text-align:center">'.$bb.'</td>
		<td style="text-align:center">'.$messageStatusLBL[0].$aa.'</td>
	</tr>';
	$valcolor++;
	}
}?>
<?php
if(!empty($failed))
{
	foreach($failed as $key=>$val){
		$aa = "";
		$bb = "";
$cc = "";
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][2]) && is_integer($allNumbersStatusNew[$val][2]) && (strlen($allNumbersStatusNew[$val][2])<=14 && strlen($allNumbersStatusNew[$val][2])>=10)) 
			$aa = " <b>/</b> ".date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][2]);
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][1]) && is_integer($allNumbersStatusNew[$val][1]) && (strlen($allNumbersStatusNew[$val][1])<=14 && strlen($allNumbersStatusNew[$val][1])>=10) ) 
			$bb = date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][1]); 
		else 
			$bb = "---";	
		if(isset($allNumbersStatusNew[$val][4]) && !empty($allNumbersStatusNew[$val][4])) 
			$cc =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][4]); 
		else 
			$cc = "---";		
			if($valcolor%2==1)
				$color ="background-color:#f1f1f1;";
		else
					$color ="background-color:#ffffff;";	
	$reurnVval.= '<tr style="'.$color.'">
		<td style="text-align:center">'.$val.'</td>
		<td style="text-align:center">'.date('Y/m/d h:i:s a',$realTime).'</td>
		<td style="text-align:center">'.$cc.'</td>
		<td style="text-align:center">'.$bb.'</td>
		<td style="text-align:center">'.$messageStatusLBL[1].$aa.'</td>
	</tr>';
	$valcolor++;
	}
}?>
<?php
if(!empty($delivered))
{
	foreach($delivered as $key=>$val){
		$aa = "";
		$bb = "";
$cc = "";
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][2]) && is_integer($allNumbersStatusNew[$val][2]) && (strlen($allNumbersStatusNew[$val][2])<=14 && strlen($allNumbersStatusNew[$val][2])>=10)) 
			$aa = " <b>/</b> ".date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][2]);
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][1]) && is_integer($allNumbersStatusNew[$val][1]) && (strlen($allNumbersStatusNew[$val][1])<=14 && strlen($allNumbersStatusNew[$val][1])>=10) ) 
			$bb = date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][1]); 
		else 
			$bb = "---";	
			if(isset($allNumbersStatusNew[$val][4]) && !empty($allNumbersStatusNew[$val][4])) 
			$cc =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][4]); 
		else 
			$cc = "---";	
			if($valcolor%2==1)
				$color ="background-color:#f1f1f1;";
		else
					$color ="background-color:#ffffff;";	
	$reurnVval.= '<tr style="'.$color.'">
		<td style="text-align:center">'.$val.'</td>
		<td style="text-align:center">'.date('Y/m/d h:i:s a',$realTime).'</td>
		<td style="text-align:center">'.$cc.'</td>
		<td style="text-align:center">'.$bb.'</td>
		<td style="text-align:center">'.$messageStatusLBL[2].$aa.'</td>
	</tr>';
	$valcolor++;
	}
}?>
<?php
if(!empty($unDelivered))
{
	foreach($unDelivered as $key=>$val){
		$aa = "";
		$bb = "";
$cc = "";
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][2]) && is_integer($allNumbersStatusNew[$val][2]) && (strlen($allNumbersStatusNew[$val][2])<=14 && strlen($allNumbersStatusNew[$val][2])>=10)) 
			$aa = " <b>/</b> ".date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][2]);
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][1]) && is_integer($allNumbersStatusNew[$val][1]) && (strlen($allNumbersStatusNew[$val][1])<=14 && strlen($allNumbersStatusNew[$val][1])>=10) ) 
			$bb = date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][1]); 
		else 
			$bb = "---";	
		if(isset($allNumbersStatusNew[$val][4]) && !empty($allNumbersStatusNew[$val][4])) 
			$cc =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][4]); 
		else 
			$cc = "---";			
			if($valcolor%2==1)
				$color ="background-color:#f1f1f1;";
		else
					$color ="background-color:#ffffff;";	
	$reurnVval.= '<tr style="'.$color.'">
		<td style="text-align:center">'.$val.'</td>
		<td style="text-align:center">'.date('Y/m/d h:i:s a',$realTime).'</td>
		<td style="text-align:center">'.$cc.'</td>
		<td style="text-align:center">'.$bb.'</td>
		<td style="text-align:center">'.$messageStatusLBL[3].$aa.'</td>
	</tr>';
	$valcolor++;
	}
}?>
<?php
if(!empty($deleted))
{
	foreach($deleted as $key=>$val){
		$aa = "";
		$bb = "";
$cc = "";
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][2]) && is_integer($allNumbersStatusNew[$val][2]) 
		&& (strlen($allNumbersStatusNew[$val][2])<=14 && strlen($allNumbersStatusNew[$val][2])>=10)) 
			$aa = " <b>/</b> ".date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][2]);
		if(isset($allNumbersStatusNew[$val][1]) && !empty($allNumbersStatusNew[$val][1]) && is_integer($allNumbersStatusNew[$val][1]) && (strlen($allNumbersStatusNew[$val][1])<=14 && strlen($allNumbersStatusNew[$val][1])>=10) ) 
			$bb = date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][1]); 
		else 
			$bb = "---";
		if(isset($allNumbersStatusNew[$val][4]) && !empty($allNumbersStatusNew[$val][4])) 
			$cc =  date('Y/m/d h:i:s a',$allNumbersStatusNew[$val][4]); 
		else 
			$cc = "---";			
			if($valcolor%2==1)
				$color ="background-color:#f1f1f1;";
		else
					$color ="background-color:#ffffff;";	
	$reurnVval.= '<tr style="'.$color.'">
		<td style="text-align:center">'.$val.'</td>
		<td style="text-align:center">'.date('Y/m/d h:i:s a',$realTime).'</td>
		<td style="text-align:center">'.$cc.'</td>
		<td style="text-align:center">'.$bb.'</td>
		<td style="text-align:center">'.$messageStatusLBL[5].$aa.'</td>
	</tr>';
	$valcolor++;
	}
}
echo $data=$reurnVval."#$#".$arrayVal."#$#".$valcolor;
ob_end_flush();
?>
