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 = ' Sabaydee Plus/ACeS Forward Terminal Received in last 3 months summary report for username '.$username.'
Sabaydee Plus/ACeS Forward Terminal Received in last 3 months summary report

Received Phone ID/ACeS FWD#
'; for($i=1;$i<$fields;$i++){ $body_msg .=''; } $sum_column = array(); $sum_column[] = 0; $irow = 0; while ($row = mysql_fetch_assoc($s)) { $body_msg .=''; $irow++; $ireset = 0; $sbdacct = $row['sbdaccount']; foreach( $row as $value ) { if(($ireset >2 & $ireset < 5)){ $nvalue = number_format($value,2); }else{ $nvalue = $value; } if(($irow%2)==0 ){ $body_msg .=''; }else{ $body_msg .=''; } $sum_column[$ireset] += $value; $ireset++; } // $ireset=0; } //while $body_msg .= ""; // mysql_close($link); // Sum value $sql = "select 'Total Receive' as srctype,'in last 3 months' AS dsttype, SUM(successcall) AS calls, SUM(minutes) AS actmin, ROUND(SUM(minutes)/SUM(successcall),2) AS 'avgminpercall',concat('From ',date_sub( date(now()), interval 3 month),' to') as lastcalldate, date(now()) as sbdaccount FROM call_statistic WHERE calledstation LIKE concat('%999',if(length('$phone_id')=4,if('$phone_id' < 2000,'120','9'),'8'),'$phone_id') AND successcall>0 GROUP BY srctype,dsttype "; $s = mysql_query($sql); if ($s == 0) { die('Failed to query data to database:
'."\n".mysql_error()); } $fields = mysql_num_fields ( $s ); $irow = 0; while ($row = mysql_fetch_assoc($s)) { $body_msg .=''; $irow++; $ireset = 0; foreach( $row as $value ) { if(($ireset >2 & $ireset < 5)){ $nvalue = number_format($value,2); }else{ $nvalue = $value; } if(($irow%2)==0 ){ $body_msg .=''; }else{ $body_msg .=''; } $sum_column[$ireset] += $value; $ireset++; } // $ireset=0; } //while $body_msg .= ""; //sum_column[0] = "Total usage"; //$sum_column[1] = "in last 3 months"; //$sum_column[4] = round(($sum_column[3]/$sum_column[2]),2) ; //$sum_column[2] = round(($sum_column[7]-$sum_column[5])*100/$sum_column[5],2) ; //$sum_column[12] = ''; /*for($i=0;$i<$fields;$i++){ if($i >=3 & $i < 5){ $body_msg .=''; }else{ $body_msg .=''; } } */ $body_msg .=''; //$body_msg .=' '; // for($i=1;$i<$fields;$i++){ // $body_msg .=''; // // }; $body_msg .='
'.mysql_field_name($s, 0).''.mysql_field_name($s, $i).'
'; if($ireset == 6) { //Deep to each account usage $body_msg .= ' '.substr($nvalue,0,6).'xxxx '; } else if($ireset == 0 ) { //Deep to each account usage if(substr($nvalue,0,4) == 'SBD-' | substr($nvalue,0,4) == 'SATF' ) $body_msg .= ' '.$nvalue.' '; else $body_msg .= ' '.$nvalue.' '; } else $body_msg .= $nvalue.' '; if($ireset == 6) { //Deep to each account usage $body_msg .= ' '.substr($nvalue,0,6).'xxxx '; } else if($ireset == 0 ) { //Deep to each account usage if(substr($nvalue,0,4) == 'SBD-' | substr($nvalue,0,4) == 'SATF' ) $body_msg .= ' '.$nvalue.' '; else $body_msg .= ' '.$nvalue.' '; } else $body_msg .= $nvalue.'
'.$nvalue.''.$nvalue.'
'.number_format($sum_column[$i],2).''.$sum_column[$i].'
'.mysql_field_name($s, 0).''.mysql_field_name($s, $i).'
'; $body_msg .= 'กดเพื่อดูขาโทรออก (Terminal Callout) สำหรับ Phone ID#'.$phone_id.''; $body_msg .='
'; $body .= chunk_split(base64_encode($body_msg)); mysql_close($link); //send message //mail($to_email, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //mail($to_email1, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //mail($to_email2, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //mail($to_email3, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //echo "Report Send.
"; echo $body_msg; ?>