<?php
  ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include("config.php");
//require_once("tcpdf_autoconfig.php");
 require_once("tcpdf.php");
 


if (isset($_POST['submit']))
{
//$subject = htmlspecialchars($_POST['subject']); Modified by Sana on [15.01.17][To insert arabic text][Start]
//$subject = htmlspecialchars($_POST['subject']);// mysqli_real_escape_string(html_entity_decode(htmlspecialchars((trim($_POST['subject'])))));

 $subject = mysqli_real_escape_string($con, $_POST['subject']);
//$from = htmlspecialchars($_POST['from']);
$from 	 = $_POST['from'];//mysqli_real_escape_string(htmlspecialchars($_POST['from']));
//$reply = htmlspecialchars($_POST['reply']);
$reply 	 =$_POST['reply'];// mysqli_real_escape_string(htmlspecialchars($_POST['reply']));
//Modified by Sana on [15.01.17][To insert arabic text][End]
$datetime = date('Y-m-d H:i:s', strtotime($_POST['datetime']));
$comp_date = date('Y-m-d H:i:s', strtotime($_POST['comp_date']));
$subscriber = htmlspecialchars($_POST['subscriber']);
$deliver = htmlspecialchars($_POST['delivered']);
$undeliver = htmlspecialchars($_POST['undelivered']);
$bounc = htmlspecialchars($_POST['bounced']);
$unique_view = htmlspecialchars($_POST['unique_view']);
$tot_views = htmlspecialchars($_POST['tot_views']);

$social_views = htmlspecialchars($_POST['social_views']);
$facebook = htmlspecialchars($_POST['facebook']);
$twitter = htmlspecialchars($_POST['twitter']);
$linked = htmlspecialchars($_POST['linked']);
$other = htmlspecialchars($_POST['other']);
$unique_clicker = htmlspecialchars($_POST['unique_clicker']);
$total_clicks = htmlspecialchars($_POST['total_clicks']);

 $Delivered = $deliver / $subscriber * 100;
 $Undelivered = $undeliver / $subscriber * 100;
 $Bounced = $bounc / $subscriber * 100;
 
 $Unique_viewer = $unique_view / $deliver * 100; 
 $Unique_click = $unique_clicker / $deliver * 100;

$sql="INSERT INTO `email_report` (
`subject` ,
`from` ,
`reply` ,
`datetime` ,
`subscriber` ,
`completed_date` ,
`delivered`,
`delivereds`,
`undelivered`,
`undelivereds`,
`bounced`,
`bounceds`,
`unique_view`,
`unique_views`,
`tot_views`,
`social_views`,
`facebook`,
`twitter`,
`linked`,
`other`,
`unique_clicker`,
`unique_clickers`,
`total_clicks`
)
VALUES('$subject','$from','$reply','$datetime','$subscriber','$comp_date','$Delivered','$deliver','$Undelivered','$undeliver','$Bounced','$bounc','$Unique_viewer','$unique_view','$tot_views','$social_views','$facebook','$twitter','$linked','$other','$Unique_click','$unique_clicker','$total_clicks')" ;

 

$result=mysqli_query($con,$sql);
if($result){
echo "<script>window.location='all_reports.php'</script>";
		
echo "Successful";
}

else {
    
 // mysql_error($result);
 print_r($subject);

//echo "ERROR";
}

}
?>