<?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");
header('Content-Type: text/csv; charset=windows-1256');
header('Content-Disposition: attachment;filename=number.csv');

$delimiter = ",";
if($_POST['csvDelimiter'] == 1)
	$delimiter = ";";
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
$where="";
if(!empty($_POST["categoryId"])){
	$where=" AND categoryId='".$_POST['categoryId']."' ";
}
$query   = "select `name`, `number` from `$userNumber` where userId='".$_SESSION['userId']."' ".$where;
if($_POST['categoryId'] != '-1')
fputcsv($output, array('الاسم', 'الرقم'), $delimiter);	   
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result)){
	
	$row['name'] = iconv('UTF-8', 'WINDOWS-1256', $row['name']);
	fputcsv($output, $row, $delimiter);
}

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