setTPL("statistics.tpl.html"); function process_data($args) { global $ini; global $LU; global $db; global $tpl; global $extensions; global $tagging_enabled; if(isset($args['dateView'])) { // {{{ create date values $dateFrom = date("Y-m-d H:i:s",mktime(0,0,0,$args['dateView']['m'],1,$args['dateView']['Y'])); $dateTo = date("Y-m-d H:i:s",mktime(0,0,0,$args['dateView']['m']+1,1,$args['dateView']['Y'])); // }}} }//end if isset date vars if($LU->checkRight(GROUP_STATS)||$LU->checkRight(VIEW_ALL_EXT)) { if($LU->checkRight(VIEW_ALL_EXT)) { //we need to get the extension array from the db $ext_query="SELECT DISTINCT `user_phone` FROM `liveuser_users` WHERE `user_phone`<>'' ORDER BY `user_phone` ASC"; $ext_res = $db->query($ext_query); if(handleError($ext_res)) { $extension_array = array(); while($ext_res->fetchInto($ext_row)) { $extension_array[] = $ext_row['user_phone']; } } $tpl->assign('view_all','true'); } else { //use the $extensions variable defined in initialisation.inc.php $extension_array = explode(",",$extensions); } $full_summary = array(); $grand_total = array( 'international' => array('name'=>$ini['Output']['international'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'national' => array('name'=>$ini['Output']['national'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'local' =>array('name'=>$ini['Output']['local'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'fallback' => array('name'=>$ini['Output']['fallback'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'toll_free' =>array('name'=>$ini['Output']['toll_free'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'special' => array('name'=>$ini['Output']['special'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'vodacom' =>array('name'=>$ini['Output']['vodacom'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'mtn' => array('name'=>$ini['Output']['mtn'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'cellc' =>array('name'=>$ini['Output']['cellc'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0), 'incoming' => array('name'=>$ini['Output']['incoming'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0) ); if(!$tagging_enabled) { $grand_total['shared'] = array('name'=>$ini['Output']['shared'],'total_calls'=>0,'total_sec'=>0,'total_cost'=>0); } //make sure that the total row is the last in the set $grand_total['total'] = array('name'=>"Grand Totals",'total_calls'=>0,'total_sec'=>0,'total_cost'=>0); foreach ($extension_array as $ext) { $summary = fetchSummary($ext,'src',$db,$ini,$grand_total,$dateFrom,$dateTo); $totals = array_pop($summary); //$totals['total_sec'] = createTimeString($totals['total_sec']); $full_summary[] = array('phone'=>$ext,'stats'=>$summary,'totals'=>$totals); } //assign the $group_name variable created in initialisation.inc.php(DOESN'T APPLY TO 'VIEW ALL') if(isset($group_name)) { $tpl->assign('group_name',$group_name); } $grand_total_totals = array_pop($grand_total); $grand_total_disp['stats'] = $grand_total; $grand_total_disp['total'] = $grand_total_totals; if($ini['System']['show_empty_extensions']) { $tpl->assign('show_empty','true'); } $tpl->assign('full_stats',$full_summary); $tpl->assign('grand_total',$grand_total_disp); $tpl->assign('date_year',$args['dateView']['Y']); $tpl->assign('date_month',$args['dateView']['m']); $tpl->assign('return_page','stats'); //key for return page switch statement in detailed_stats.php } } $form = new HTML_QuickForm(); $form->addElement('date','dateView','Statistics for month: ',array('format'=>"Ym",'minYear'=>'2001','maxYear'=>date("Y")),'onChange=submit();'); if($form->validate()) { $form->process('process_data',false); } else { $defaults = array('dateView'=>array('Y'=>date("Y"),'m'=>date('m'))); $form->setDefaults($defaults); process_data($defaults); } $tpl->display($form); ?>