<?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");

$archiveData = '<html>';
$archiveData.= '<head>';
///$archiveData.= '<META http-equiv="Content-Language" content="ar-jo">';
$archiveData.= '<META http-equiv="Content-Type" content="text/html; charset=windows-1256">';
$archiveData.= '<META http-equiv="Content-Type" content="text/html; charset=utf-8">';
$archiveData.= '<link type="text/css" rel="stylesheet">';
$archiveData.= '</head>';
$archiveData.= '<body>';
$archiveData.= '<table border="1" dir="'.$dir.'" bordercolor="#ABCDEF" width="50%" cellspacing="0" cellpadding="0">';
$archiveData.= "<tr>
	<td align='center' width='100' class='gridHeaer'>".$archivesListLBL["username"]."</td>
	<td align='center' width='100' class='gridHeaer'>".$archivesListLBL["msg"]."</td>
	<td align='center' width='120' class='gridHeaer'>".$archivesListLBL["sender"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["numbers"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["date"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["numbersCount"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["msgLength"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["points"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details7"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details8"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details1"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details5"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details3"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details2"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details6"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["details4"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["msgInTime"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["reciveDate"]."</td>
	<td align='center' width='150' nowrap='nowrap' class='gridHeaer'>".$archivesListLBL["msgDoneTime"]."</td>

</tr>";


//username
//msg
//sender
//msgNumber
//numbers
//dateAndTime
//point
//count_number
//numer sent
//Count of sent
//numer delivered
//Count delivered
//numer not delivered
//Count not delivered
//numer not sent
//Count not sent
//numer deleted
//Count deleted
//numer failed
//Count failed
$result = mysqli_query($conn, $_SESSION['selectQuery']);
while($row= mysqli_fetch_assoc($result))
{
	$allNumbers = $row['numbers'];
	$explodeNumber = explode(',',$allNumbers);
	$explodeNumber = array_filter($explodeNumber);
	if(count($explodeNumber)>2000)
	{
		$arrayNumbers2000 = array_chunk($explodeNumber, 2000);
		foreach($arrayNumbers2000 AS $stringNumber)
		{
			 $implodeNumber = implode(',',$stringNumber);
			 $archiveData.= "<tr>
			 <td align='right' valign='top'>".$row['userName']."</td>
			 <td align='right' valign='top'>".$row['msg']."</td>
			 <td align='center' >".$row['userSender']."</td>
			 <td align='center'>".$implodeNumber."</td>
			 <td align='center'>".date("A h:i Y.m.d",$row['date'])."</td>
			 <td align='center' >".$row['countNumbers']."</td>
			 <td align='center' >".$row['numMsgs']."</td>
			 <td align='center' >".$row['points']."</td>
			 <td align='center' >".$row['rejectedNumber']."</td>
			 <td align='center' >".$row['countNotAccepted']."</td>
			 <td align='center' >".$row['delivered']."</td>
			<td align='center' >".$row['not_delivered']."</td>
			<td align='center' >".$row['accepted']."</td>
			<td align='center' >".$row['count_delivered']."</td>
			<td align='center' >".$row['count_not_delivered']."</td>
			<td align='center' >".$row['count_accepted']."</td>
			<td align='center' >".$row['timeSend']."</td>
			<td align='center' >".$row['realDate']."</td>
			<td align='center' >".$row['insert_date']."</td>
			</tr>";
			
		}
	}
	else
	{
		 $archiveData.= "<tr>
			 <td align='right' valign='top'>".$row['userName']."</td>
			 <td align='right' valign='top'>".$row['msg']."</td>
			 <td align='center' >".$row['userSender']."</td>
			 <td align='center'>".$row['numbers']."</td>
			 <td align='center'>".date("A h:i Y.m.d",$row['date'])."</td>
			 <td align='center' >".$row['countNumbers']."</td>
			 <td align='center' >".$row['numMsgs']."</td>
			 <td align='center' >".$row['points']."</td>
			 <td align='center' >".$row['rejectedNumber']."</td>
			 <td align='center' >".$row['countNotAccepted']."</td>
			 <td align='center' >".$row['delivered']."</td>
			<td align='center' >".$row['not_delivered']."</td>
			<td align='center' >".$row['accepted']."</td>
			<td align='center' >".$row['count_delivered']."</td>
			<td align='center' >".$row['count_not_delivered']."</td>
			<td align='center' >".$row['count_accepted']."</td>
			<td align='center' >".date("A h:i Y.m.d",$row['timeSend'])."</td>
			<td align='center' >".date("A h:i Y.m.d",$row['realDate'])."</td>
			<td align='center' >".date("A h:i Y.m.d",$row['insert_date'])."</td>
			</tr>";
		
	}
}
$archiveData.= '</table>';
$archiveData.= '</body>';
$archiveData.= '</html>';
echo $archiveData;
header("Content-length: ".strlen($archiveData));
header("Content-type: Text");
header("Content-Disposition: attachment; filename=archivesList.xls");

mysqli_close($conn);
ob_end_flush();  
?>
