Header('Cache-Control: no-cache');
Header('Pragma: no-cache');
//require("../authen.php");
$db_name = "a2billing";
set_time_limit(99000);
//Change the 3 follow lines for database setup.
//$db_host = "172.16.130.212:3307";
$db_host = "172.16.129.233";
$db_user = "report";
$db_pass = "xreport2008";
$to_email2="canat@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 = 1;
$report_data_date = fnc_date_calc($date_today,(($days_to_add)*-1));
if(!empty($_GET["phone_id"])){
$phone_id = $_GET["phone_id"];
} else{
$phone_id = "2000";
}
if(!empty($_GET["orderby"])){
$orderbystr = $_GET["orderby"];
} else{
$orderbystr = " end_date desc ";
}
$link = mysql_connect($db_host,$db_user,$db_pass) ;
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name);
$sql = "SELECT start_date, end_date, last_location FROM a2billing.sbdplus_location_hist
WHERE phone_id= '$phone_id' ";
//$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());
}
$fields = mysql_num_fields ( $s );
// 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 = '
| '.mysql_field_name($s, 0).' | '; for($i=1;$i<$fields;$i++){ $body_msg .=''.mysql_field_name($s, $i).' | '; } $sum_column = array(); $sum_column[] = 0; $irow = 0; while ($row = mysql_fetch_assoc($s)) { $body_msg .='
| '.$nvalue.' | '; }else{ $body_msg .=''.$nvalue.' | '; } $sum_column[$ireset] += $value; $ireset++; } // $ireset=0; } //while $body_msg .= "
| '.number_format($sum_column[$i],2).' | '; }else{ $body_msg .=''; } } */ $body_msg .=' |
| '.mysql_field_name($s, 0).' | '; for($i=1;$i<$fields;$i++){ $body_msg .=''.mysql_field_name($s, $i).' | '; }; $body_msg .='