checkRight(ADMIN)) { $ast_tbl = $ini['DB']['cdr_table']; $routefield = $ini['System']['routing_field']; //{{{ 0. General Health $tpl->assign('debug',$debug); //get max calldate $db_last_proc_q = "SELECT MAX(calldate) as max_calldate FROM $ast_tbl WHERE cost>='0'"; $db_last_proc_res = $db->query($db_last_proc_q); if(handleError($db_last_proc_res)) { $db_last_proc_res ->fetchInto($last_proc_dt); $tpl->assign('date_last_proc',$last_proc_dt['max_calldate']); } //check if AsteriskManager interface is up if($ini['Asterisk']['php_agi_enabled']==true) { $tpl->assign('php_agi_enabled','true'); require_once(LIB_AGI.'phpagi-asmanager.php'); $asm = new AGI_AsteriskManager(); if($asm->connect($ini['Asterisk']['host'], $ini['Asterisk']['user'], $ini['Asterisk']['pass'])) { $tpl->assign('php_agi_available','true'); $asm->disconnect(); } } //check if all the items that can be tagged are being tagged if(isset($ini['Tagging']['enabled'])) { if($ini['Tagging']['enabled']==true) { $tpl->assign('tagging_enabled','true'); $tag_chk_q = "SELECT COUNT(cdr_id) AS all_rows_count, COUNT(cdr_tag) AS tagged_count FROM `$ast_tbl` WHERE disposition = 'ANSWERED' AND cost >=0"; $tag_chk_res = $db->query($tag_chk_q); if(handleError($tag_chk_res)) { $tag_chk_res->fetchInto($tagging); $tpl->assign('tagging_res', $tagging); } } else { $tpl->assign('tagging_enabled','false'); } } else { $tpl->assign('tagging_enabled','not_found'); } //}}} //{{{ 1. check db health $db_check_q = "CHECK TABLE `$ast_tbl`,`zone`,`rate`,`ratetimetable`,`liveuser_users`"; $db_check_res = $db->query($db_check_q); if(handleError($db_check_res)) { $tables = array(); while($db_check_res->fetchInto($chk_row)) { $tables[] = $chk_row; } $tpl->assign('tables',$tables); } //}}} //{{{ 2.1 Unprocessed records $unproc_q = "SELECT DISTINCT `$routefield` AS `userfield`, COUNT(`$routefield`) as count FROM `$ast_tbl` WHERE cost ='-1' GROUP BY `$routefield`"; $unproc_res = $db->query($unproc_q); if(handleError($unproc_res)) { $unproc = array(); while($unproc_res->fetchInto($unproc_row)) { $unproc[] = $unproc_row; } $tpl->assign('unproc',$unproc); } //}}} //{{{ 2.2 Error records $err_q = "SELECT DISTINCT `$routefield` AS `userfield` , COUNT(`$routefield`) as count FROM `$ast_tbl` WHERE cost ='-2' GROUP BY `$routefield`"; $err_res = $db->query($err_q); if(handleError($err_res)) { $errors = array(); while($err_res->fetchInto($err_row)) { $errors[] = $err_row; } $tpl->assign('errors',$errors); } //}}} //{{{ 2.3 Total records $total_q = "SELECT DISTINCT `$routefield` AS `userfield` , COUNT(`$routefield`) as count FROM `$ast_tbl` GROUP BY `$routefield`"; $total_res = $db->query($total_q); if(handleError($total_res)) { $totals = array(); $userfields = array(); while($total_res->fetchInto($total_row)) { $totals[] = $total_row; //setup userfields for channel verification $userfields[$total_row['userfield']] = array( 'name'=>$total_row['userfield'], 'incoming'=>'N', 'zero_cost'=>'N', 'billed'=>'N', 'db_found'=>'Y', 'config_found'=>'N'); } $tpl->assign('totals',$totals); } //}}} //{{{ Channel Verification //{{{ billing section of config foreach($ini['Billing'] as $section=>$enabled) { $billing_channel = $ini['Translation'][$section]; //this is changed depending on each asterisk setup, in the config file if($enabled) { $enabled_str = 'Y'; $section_str = $section; } else { $enabled_str = 'N'; $section_str = ''; } //remove quotes for indexing $billing_channel = str_replace(array("'",'"'),'',$billing_channel); if(false!==strpos($billing_channel,',')) { //we have a comma separated channel list $channel_list = explode(',',$billing_channel); foreach($channel_list as $chan) { if(!isset($channel_index[$chan])) { $channel_index[$chan] = $section; if(isset($userfields[$chan])) { $userfields[$chan]['config_found'] = 'Y'; $userfields[$chan]['billed'] = $enabled_str; $userfields[$chan]['section'] = $section_str; } else { $userfields[$chan] = array( 'name'=>$chan, 'incoming'=>'N', 'zero_cost'=>'N', 'billed'=>$enabled_str, 'section'=>$section_str, 'db_found'=>'N', 'config_found'=>'Y'); } } } } else { //we should have just one channel if(!isset($channel_index[$billing_channel])) { $channel_index[$billing_channel] = $section; if(isset($userfields[$billing_channel])) { $userfields[$billing_channel]['config_found'] = 'Y'; $userfields[$billing_channel]['billed'] = $enabled_str; $userfields[$billing_channel]['section'] = $section_str; } else { $userfields[$billing_channel] = array( 'name'=>$billing_channel, 'incoming'=>'N', 'zero_cost'=>'N', 'billed'=>$enabled_str, 'section'=>$section_str, 'db_found'=>'N', 'config_found'=>'Y'); } } } } //}}} //{{{ incoming section of config $in_channel_str = str_replace("'",'',$ini['Incoming']['channels_in']); $incoming_channels = explode(',',$in_channel_str); foreach($incoming_channels as $in_channel_name) { $in_channel = trim($in_channel_name); if(isset($userfields[$in_channel])) { $userfields[$in_channel]['config_found'] = 'Y'; $userfields[$in_channel]['incoming'] = 'Y'; } else { $userfields[$in_channel] = array( 'name'=>$in_channel, 'billed'=>'N', 'incoming'=>'Y', 'zero_cost'=>'N', 'db_found'=>'N', 'config_found'=>'Y'); } } //}}} //{{{ zero cost section of config $zero_channel_str = str_replace("'",'',$ini['ZeroCost']['channels']); $zero_channels = explode(',',$zero_channel_str); foreach($zero_channels as $zero_channel_name) { $zero_channel = trim($zero_channel_name); if(isset($userfields[$zero_channel])) { $userfields[$zero_channel]['config_found'] = 'Y'; $userfields[$zero_channel]['zero_cost'] = 'Y'; } else { $userfields[$zero_channel] = array( 'name'=>$zero_channel, 'billed'=>'N', 'incoming'=>'N', 'zero_cost'=>'Y', 'db_found'=>'N', 'config_found'=>'Y'); } } //}}} ksort($userfields); $tpl->assign('userfields',$userfields); //}}} //{{{ zone and rate billing info $billing_q = "SELECT rt_channel_out, MAX(rt_effective) as rt_effective FROM `rate` WHERE rt_channel_out IN ( SELECT DISTINCT zn_channel_out FROM zone ) GROUP BY rt_channel_out ORDER BY rt_channel_out ASC"; $billing_res = $db->query($billing_q); if(handleError($billing_res)) { $billing = array(); while($billing_res->fetchInto($bill_row)) { $billing[]= $bill_row; } $tpl->assign('billing',$billing); } //}}} $tpl->setTPL('system_health.tpl.html'); $tpl->display(); } else { $tpl->setTPL('access_denied.tpl.html'); $tpl->display(); } ?>