Header('Cache-Control: no-cache');
Header('Pragma: no-cache');
//require("../authen.php");
$db_name = "ARS";
set_time_limit(99000);
//Change the 3 follow lines for database setup.
//$db_host = "172.16.130.212:3307";
$db_host = "172.16.177.14";
$db_user = "develop";
$db_pass = "";
$to_email="panya.p@jasmine.com";
//$to_email3="jparinya@jasmine.com";
function fnc_date_calc($this_date,$num_days){
$my_time = strtotime ($this_date); //converts date string to UNIX timestamp
$timestamp = $my_time + ($num_days * 86400); //calculates # of days passed ($num_days) * # seconds in a day (86400)
$return_date = date("Y-m-d",$timestamp); //puts the UNIX timestamp back into string format
return $return_date;//exit function and return string
}//end of function
function isValidDateTime($dateTime)
{
if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
if (checkdate($matches[2], $matches[3], $matches[1])) {
return true;
}
}
return false;
}
$date_today = Date("Y-m-d");
$days_to_add = 7;
$report_data_date = fnc_date_calc($date_today,(($days_to_add)*-1));
if(!empty($_GET["startdate"])){
$startdate = date($_GET["startdate"]);
} else{
// $startdate = $date_today;
$startdate = $report_data_date;
}
if(!empty($_GET["to_date"])){
$to_date = $_GET["to_date"];
}else{
$to_date = $date_today;
}
if(!empty($_GET["starttime"])){
$starttime = $_GET["starttime"];
} else{
$starttime = "00:00:00";
}
if(!empty($_GET["totime"])){
$totime = $_GET["totime"];
}else{
$totime = "23:59:59";
}
$startdate = $startdate." ".$starttime;
$to_date = $to_date." ".$totime;
//$sroute = $sroute."%";^
//$scountry = $scountry."%";^
if(!isValidDateTime($startdate)){
die("Invalid date format");
}
if(!isValidDateTime($to_date)){
die("Invalid date format");
}
$link = mysql_connect($db_host,$db_user,$db_pass) ;
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name);
//$sql = "SELECT status_date as DateTime,if(vlrnb='91870775001399','APAC',if(vlrnb='91870773001399','EMEA','OTHER')) as VLR,
//register as RegisterValue FROM m_roaming_register
//WHERE status_date between '$startdate' and '$to_date' order by status_date desc";
$sql = "SELECT status_date ,register FROM m_roaming_register
WHERE status_date between '$startdate' and '$to_date' and vlrnb='91870775001399' order by status_date desc";
//$orderbystr = " start_date desc ";
//$sql = $sql." order by ".$orderbystr;
//echo $sql;
//set_time_limit(99000);
$s = mysql_query($sql);
if ($s == 0)
{
die('Failed to query data to database:
'."\n".mysql_error());
}
// echo($sql);
//Send Mail
//add From: header
$headers = "From: panya.p@jasmine.com\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLMAIL");
//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text version of message
//$body = "--$boundary\r\n" .
// "Content-Type: text/plain; charset=windows-874\r\n" .
// "Content-Transfer-Encoding: base64\r\n\r\n";
//$body .= chunk_split(base64_encode("This is the plain text version! ทดสอบครับ"));
//HTML version of message
$body .= "--$boundary\r\n" .
"Content-Type: text/html; charset=windows-874\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$body_msg = '
| Date Time | APAC | EMEA | TOTAL |
| '.$DateT.' | '.$APAC.' | '.$EMEA.' | '.$TOTAL.' |