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 = "2000171";
}
if(!empty($_GET["orderby"])){
$orderbystr = $_GET["orderby"];
} else{
$orderbystr = " lastcalldate ";
}
$link = mysql_connect($db_host,$db_user,$db_pass) ;
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name);
$sql = "SELECT IF(length(MID(src,12))=4,concat('SBD-',MID(src,12)),if(length(MID(src,12))=7,concat('SATFWD-',MID(src,12)),'LAND')) AS srctype,
if(calledstation LIKE '%9999%',if(RIGHT(calledstation,5) IN ('04000','16070'),'CC-Free',
if(calledstation LIKE '%99998%',concat('SATFWD-',right(calledstation,7)),if(locate('9999',calledstation)<= 5,concat('SBD-',right(calledstation,4)),'Domestic'))),if(calledstation LIKE '99090%','Domestic',
if(calledstation LIKE '0%','Domestic-SP',
IF(calledstation LIKE '9909%','Inter','Inter-SP')))) AS dsttype, SUM(successcall) AS calls, SUM(minutes) AS actmin,
ROUND(SUM(minutes)/SUM(successcall),2) AS 'avgminpercall', max(lastcall) as lastcalldate,
concat(left(username,6),'xxxx') as sbdaccount
FROM call_statistic WHERE MID(src,12) = '$phone_id' AND
successcall>0
GROUP BY srctype,dsttype,sbdaccount ";
//$orderbystr = " todate desc ";
$sql = $sql." order by ".$orderbystr." desc";
//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 .='
| '; if($ireset == 6) { //Deep to each account usage $body_msg .= ' '.substr($nvalue,0,6).'xxxx '; } else if($ireset == 1 ) { //Deep to each account usage if(substr($nvalue,0,4) == 'SBD-' | substr($nvalue,0,4) == 'SATF' ) $body_msg .= ' '.$nvalue.' '; else if(substr($nvalue,0,5) == 'Inter') $body_msg .= ' '.$nvalue.' '; else if(substr($nvalue,0,8) == 'Domestic') $body_msg .= ' '.$nvalue.' '; else $body_msg .= $nvalue.' | '; } else $body_msg .= $nvalue.''; }else{ $body_msg .=''; if($ireset == 6) { //Deep to each account usage $body_msg .= ' '.substr($nvalue,0,6).'xxxx '; } else if($ireset == 1 ) { //Deep to each account usage if(substr($nvalue,0,4) == 'SBD-' | substr($nvalue,0,4) == 'SATF' ) $body_msg .= ' '.$nvalue.' '; else if(substr($nvalue,0,5) == 'Inter') $body_msg .= ' '.$nvalue.' '; else if(substr($nvalue,0,8) == 'Domestic') $body_msg .= ' '.$nvalue.' '; else $body_msg .= $nvalue.' | '; } else $body_msg .= $nvalue.''; } $sum_column[$ireset] += $value; $ireset++; } // $ireset=0; } //while $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 .=''.$sum_column[$i].' | '; } } */ $body_msg .='
| '.mysql_field_name($s, 0).' | '; // for($i=1;$i<$fields;$i++){ // $body_msg .=''.mysql_field_name($s, $i).' | '; // // }; $body_msg .='