CREATE TABLE IF NOT EXISTS `price_russia ` ( `code` int(10) NOT NULL COMMENT ' ', `cost` varchar(10) NOT NULL COMMENT '', `region` varchar(100) NOT NULL COMMENT '', UNIQUE KEY `code` (`code`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS ` price_international` ( `code` int(10) NOT NULL COMMENT ' ', `price` varchar(10) NOT NULL COMMENT '', `country` varchar(100) NOT NULL COMMENT '', UNIQUE KEY `code` (`code`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `clients` ( `login` varchar(32) NOT NULL COMMENT '', `password` varchar(32) NOT NULL COMMENT '', `email` varchar(40) NOT NULL COMMENT 'Email', `rate` smallint(4) NOT NULL COMMENT '', UNIQUE KEY `login` (`login`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `clients_ext` ( `login` varchar(32) NOT NULL, `ext` int(6) NOT NULL, UNIQUE KEY `ext` (`ext`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `calls` ( `uniqueid` varchar(32) NOT NULL, `date` datetime NOT NULL, `login` varchar(32) NOT NULL, `rate` bigint(10) NOT NULL, `ext` bigint(10) NOT NULL, `dst` bigint(20) NOT NULL, `src` bigint(20) NOT NULL, `type` varchar(20) NOT NULL, `minutes` int(10) NOT NULL, `seconds` int(100) NOT NULL, `cost` int(10) NOT NULL, `description` varchar(100) NOT NULL, UNIQUE KEY `uniqueid` (`uniqueid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
mysql_query("UPDATE cdr SET userfield=`step1` WHERE userfield=``;");
function get_clients(){ // , . $query=mysql_query("SELECT rate,ext,login FROM clients, clients_ext WHERE clients_ext.login = clients.login"); while($row=mysql_fetch_assoc($query)){ $clients[$row['ext']]['rate']=$row['rate']; $clients[$row['ext']]['user']=$row['login']; } return $clients; }
function get_price_russia(){ // $query=mysql_query("SELECT * FROM price_russia"); while($row=mysql_fetch_assoc($query)){ $price[$row['code']]['cost']=$row['price']; $price[$row['code']]['description']=$row['region']; } return $price; }
function get_price_international(){ // . $query=mysql_query("SELECT * FROM price_international"); while($row=mysql_fetch_assoc($query)){ $price[$row['code']]['cost']=$row['price']; $price[$row['code']]['description']=$row['country']; } return $price; }
$clients=get_clients(); $price['russia']=get_price_russia(); $price['international']=get_price_international();
$query=mysql_query("SELECT * FROM cdr WHERE userfield=`step1`"); while($row=mysql_fetch_assoc($row)){ // }
( , .)
: function get_call_type($dst,$src){ $dst=strlen($dst); $src=strlen($src); if($scr<7 && $dst<7)$type='internal'; // . if($src<7 && $dst>=7)$type='outcoming'; // if($src>=7 && $dst<7)$type='incoming'; // return $type; } $type=get_call_type($row['dst'],$row['src']);
function get_ext_from_channel($channel){ // ext channel $channel=split("/",$channel); $channel=split("-",$channel[1]); return($channel[0]); } switch ($type) { case 'internal': $ext=$row['src']; break; case 'incoming': $ext=get_ext_from_channel($row['dstchannel']); break; case 'outcoming': $ext=get_ext_from_channel($row['channel']); break; }
$login=$clients[$ext]['login']
$rate=$clients[$ext]['rate']
$minutes=ceil($row['billsec']/60);
if($type=='outcoming'){ // . }else{ $cost=0; $description=0; }
// 8495 7 . function check_for_moscow($num){ if(strlen($num)==7)$num='8495'.$num; return $num; } $dst=check_for_moscow($row['dst']); // , . : 10. 11 - , - . function get_country_type($number){ if(strlen($number)<=11){ $return='russia'; }else{ $return='international'; } return $return; } $country=get_country_type($dst); $cost=''; $description=''; $i=1; // - (8xxx), 4 (810xxx) if($country=='international'){$s=3;}else{$s=1;} // , 9 - . 2-3 . while($cost==''){ $code=substr($dst,$s,$i); $cost=$price[$country][$code]['cost']; $description=$price[$country][$code]['description']; $i++; }
mysql_query("INSERT INTO calls(uniqueid, date, login, rate, ext, dst, src, type, minutes, seconds, cost, description) VALUES ('$row[uniqueid]', '$row[calldate]', '$login', '$rate', '$ext', '$dst', '$row[src]', '$type', '$minutes', '$row[billsec]', '$cost', '$description')");
mysql_query("UPDATE cdr SET userfield=`done` WHERE userfield=`step1`");
Source: https://habr.com/ru/post/124211/
All Articles