<function name="rpcf_traffic_report_ex" id="0x3009"> <input> <integer name="type" /> <integer name="user_id" /> <integer name="account_id" /> <integer name="group_id" /> <integer name="apid" /> <integer name="time_start" /> <integer name="time_end" /> </input> <output> <double name="bytes_in_kbyte" /> <integer name="users_count" /> <for name="i" from="0" count="users_count"> <integer name="atr_size" /> <set dst="atr_size_array" src="atr_size" dst_index="i" /> <for name="j" from="0" count="atr_size"> <integer name="account_id" array_index="i,j" /> <string name="login" array_index="i,j" /> <if variable="type" value="0" condition="ne"> <integer name="add_param" array_index="i,j" /> </if> <integer name="tclass" array_index="i,j" /> <double name="base_cost" array_index="i,j" /> <long name="bytes" array_index="i,j" /> <double name="discount" array_index="i,j" /> </for> </for> </output> </function>
//$type //1-Отчет с группировкой по часам //2-Отчет с группировкой по дням //3-Общий отчет //4-Отчет с группировкой по IP function rpcf_traffic_report_ex($user_id,$time_start,$time_end, $type) { //0x3009 $ret=array(); if (!$this->connection->urfa_call(0x3009)) { print "Error calling function ". __FUNCTION__ ."\n"; return FALSE; } $packet = $this->connection->getPacket(); $packet->DataSetInt($type); $packet->DataSetInt($user_id); $packet->DataSetInt(0); $packet->DataSetInt(0); $packet->DataSetInt(0); $packet->DataSetInt($time_start); $packet->DataSetInt($time_end); $this->connection->urfa_send_param($packet); if ($x = $this->connection->urfa_get_data()) { $ret['bytes_in_kbyte']=$x->DataGetDouble(); $users_count=$x->DataGetInt(); $ret['users_count']=$users_count; $traffic=array(); for( $i=0; $i<$users_count; $i++ ) { $atr_size=$x->DataGetInt(); $traffic['atr_size']=$atr_size; $ips=array(); for( $j=0; $j<$atr_size; $j++ ) { $ips['account_id']=$x->DataGetInt(); $ips['login']=$x->DataGetString(); $ips['discount_date']=$x->DataGetInt(); $ips['tclass']=$x->DataGetInt(); $ips['base_cost']=$x->DataGetDouble(); $ips['bytes']=$x->DataGetLong(); $ips['discount']=$x->DataGetDouble(); $traffic['ips'][$j]=$ips; } $ret['traffic'][$i]=$traffic; } } return $ret; } //Вариант для "старого" urfa_get_data function rpcf_traffic_report_ex($user_id,$time_start,$time_end, $type) { //0x3009 $ret=array(); if (!$this->connection->urfa_call(0x3009)) { print "Error calling function ". __FUNCTION__ ."\n"; return FALSE; } $packet = $this->connection->getPacket(); $packet->DataSetInt($type); $packet->DataSetInt($user_id); $packet->DataSetInt(0); $packet->DataSetInt(0); $packet->DataSetInt(0); $packet->DataSetInt($time_start); $packet->DataSetInt($time_end); $this->connection->urfa_send_param($packet); if ($x = $this->connection->urfa_get_data()) { $ret['bytes_in_kbyte']=$x->DataGetDouble(); $users_count=$x->DataGetInt(); $ret['users_count']=$users_count; $traffic=array(); for( $i=0; $i<$users_count; $i++ ) { $x = $this->connection->urfa_get_data(); $atr_size=$x->DataGetInt(); $traffic['atr_size']=$atr_size; $ips=array(); for( $j=0; $j<$atr_size; $j++ ) { $x = $this->connection->urfa_get_data(); $ips['account_id']=$x->DataGetInt(); $ips['login']=$x->DataGetString(); $ips['discount_date']=$x->DataGetInt(); $ips['tclass']=$x->DataGetInt(); $ips['base_cost']=$x->DataGetDouble(); $ips['bytes']=$x->DataGetLong(); $ips['discount']=$x->DataGetDouble(); $traffic['ips'][$j]=$ips; } $ret['traffic'][$i]=$traffic; } $x = $this->connection->urfa_get_data(); } return $ret; }
$s.="<h4>Отчёт по трафику</h4>"; try { $urfa_admin = new URFAClient_Admin(UTM5_login,UTM5_passwd); $report=$urfa_admin->rpcf_traffic_report_ex($_SESSION['URFA']['user_id'],strtotime("-2 month"),strtotime("+1 day"),2); //0x3009 } catch (Exception $exception) { echo "Error in line ", $exception->getLine(); echo $exception->getMessage(); } $traffic=$report['traffic']; $atr_size=$traffic['0']['atr_size']; $ips=$traffic['0']['ips']; $t=array(); for ($i=0;$i<$atr_size;$i++) { $d_date = $ips[$i]['discount_date']; $tclass = $ips[$i]['tclass']; $bytes = $ips[$i]['bytes']; $discount = $ips[$i]['discount']; $t[$d_date][$tclass]['bytes']=$bytes; $t[$d_date][$tclass]['discount']=$discount; } krsort($t); $s.='<table class=nfo>'; $s.='<tr><th align=center>Дата</th><th align=center>Входящий трафик (байт)</th><th align=center>Исходящий трафик (байт)</th><th>Стоимость трафика (руб.)</th></tr>'; if (0==sizeof($t)) { $s.='<tr class=even>'; $s.='<td class=date>'.date("d.m.Y H:i",time()).'</td>'; $s.='<td class=money align=right>---</td>'; $s.='<td class=money align=right>---</td>'; $s.='<td class=money>0.00</td>'; $s.='</tr>'; } else { $i=0; while(list($d_date,$a)=each($t)) { $s.='<tr class='.((($i % 10)>=5)?'even':'odd').'>'; $s.='<td class=date>'.date("d.m.Y",$d_date).'</td>'; $s.='<td class=money align=right>'.number_format($a[T_CLASS_IN]['bytes']).'</td>'; $s.='<td class=money align=right>'.number_format($a[T_CLASS_OUT]['bytes']).'</td>'; $s.='<td class=money>'.sprintf("%01.2f",$a[T_CLASS_IN]['discount']).'</td>'; $s.='</tr>'; $i++; } } $s.='</table>';