/** * show extension status * @return objResponse object xajax response object */ function showStatus() { global $db; // get old status $cstatus = $_SESSION['status']; $objResponse = new xajaxResponse(); if ($_SESSION['curuser']['groupid'] == "") { return $objResponse; } //print_r($cstatus);exit; $peers = $_SESSION['curuser']['extensions']; $peerstatus = astercc::checkPeerStatus($_SESSION['curuser']['groupid'], $peers); #print_r($peerstatus);exit; $event = array('ring' => 1, 'dial' => 2, 'ringing' => 3, 'link' => 4); $event = array('RING' => 1, 'DIAL' => 2, 'RINGING' => 3, 'LINK' => 4); foreach ($peers as $peer) { // update peer status if ($_SESSION['curuser']['billingfield'] == 'accountcode') { $objResponse->addAssign("{$peer}-peer-status", "innerHTML", "<font color=green>NA In Acc Mode</font>"); } else { $query = "SELECT status,responsetime FROM peerstatus WHERE peername LIKE '%/{$peer}' "; $peer_status = $db->getRow($query); //print_r($peer_status );exit; if ($peer_status) { if ($peer_status['responsetime'] > 0) { if ($peer_status['responsetime'] > 300) { if (strstr($peer_status['status'], 'ok')) { $objResponse->addAssign("{$peer}-peer-status", "innerHTML", "<font color=red>" . $peer_status['status'] . "</font>"); } else { $objResponse->addAssign("{$peer}-peer-status", "innerHTML", "<font color=red>" . $peer_status['status'] . "(" . $peer_status['responsetime'] . " ms)</font>"); } } else { if (strstr($peer_status['status'], 'ok')) { $objResponse->addAssign("{$peer}-peer-status", "innerHTML", "<font color=green>" . $peer_status['status'] . "</font>"); } else { $objResponse->addAssign("{$peer}-peer-status", "innerHTML", "<font color=green>" . $peer_status['status'] . "(" . $peer_status['responsetime'] . " ms)</font>"); } } } else { $objResponse->addAssign("{$peer}-peer-status", "innerHTML", "<font color=red>" . $peer_status['status'] . "</font>"); } } } //echo "C".$cstatus[$peer]['disposition'].'P'.$peerstatus[$peer]['disposition'];exit; //print_r($peerstatus);exit; if ($cstatus[$peer]['disposition'] != $peerstatus[$peer]['disposition']) { // status changed //echo "C".$cstatus[$peer]['disposition'].'P'.$peerstatus[$peer]['disposition'];exit; //print_r($peerstatus);exit; if ($peerstatus[$peer]['disposition'] == '') { // a hangup event $objResponse->addScript("clearCurchannel('" . $peer . "');"); // set display name $objResponse->addAssign("{$peer}-displayname", "style.backgroundColor", ""); // should reload CDR $objResponse->addScript("removeTr('" . $peer . "');"); $objResponse->addScript('setTimeout("xajax_addUnbilled(\'' . $peer . '\')",3000);'); //wait daemon write data to cdr } else { //print_r($peerstatus);exit; // set display name $objResponse->addAssign("{$peer}-displayname", "style.backgroundColor", "#009900"); $destination = ''; if ($peerstatus[$peer]['destination'] != '') { $destination = '<br> ' . $peerstatus[$peer]['destination']; } else { #print $peerstatus[$peer]['destination'];die; # try get the destination in 5 sec $objResponse->addScript('setTimeout("xajax_checkDestination(\'' . $peer . '\',\'' . $peerstatus[$peer]['direction'] . '\')", 5000);'); } if ($peerstatus[$peer]['direction'] == 'outbound') { $objResponse->addAssign($peer . '-phone', 'innerHTML', "<img src='images/outbound.gif'>" . $peerstatus[$peer]['dst'] . $destination); //here } else { $objResponse->addAssign($peer . '-phone', 'innerHTML', "<img src='images/inbound.gif'>" . $peerstatus[$peer]['src'] . $destination); $objResponse->addAssign($peer . '-phone', 'style.color', '#009900'); } $objResponse->addAssign($peer . '-startat', 'innerHTML', $peerstatus[$peer]['starttime']); $objResponse->addAssign($peer . '-channel', 'value', $peerstatus[$peer]['srcchan']); $objResponse->addAssign($peer . '-dstchan', 'value', $peerstatus[$peer]['dstchan']); if ($peerstatus[$peer]['answertime'] != '0000-00-00 00:00:00') { if ($peerstatus[$peer]['pushcall'] == 'LINK' || $peerstatus[$peer]['pushcall'] == 'no') { $now = time(); $initSec = $now - strtotime($peerstatus[$peer]['answertime']); $objResponse->addScript("putCurrentTime('" . $peer . "-localanswertime',{$initSec});"); } else { $peerstatus[$peer]['disposition'] = $peerstatus[$peer]['pushcall']; } } } } //credit changed if ($cstatus[$peer]['credit'] != $peerstatus[$peer]['credit'] && ($peerstatus[$peer]['pushcall'] == 'LINK' || $peerstatus[$peer]['pushcall'] == 'no')) { $objResponse->addAssign($peer . '-price', 'innerHTML', astercc::creditDigits($peerstatus[$peer]['credit'])); } } $callbacks = $_SESSION['callbacks']; if (count($callbacks) > 0) { foreach ($callbacks as $key => $callback) { $localChan = 'local/' . $callback['legB']; $res = astercc::getCurLocalChan($localChan, $_SESSION['curuser']['groupid']); // print $localChan; // print "\n"; // print $callback['start']; // print "\n"; // print $res->numRows(); if ($res->numRows() == 0) { if ($callback['start'] != 0) { //hangup $objResponse->addScript("clearCurchannel('" . $localChan . "');"); $objResponse->addScript("clearCurchannel('" . $localChan . "-legb" . "');"); //$objResponse->addAlert("clearCurchannel('".$localChan."-legb"."');"); // should reload CDR $objResponse->addScript("removeTr('" . $localChan . "');"); $objResponse->addScript('xajax_addUnbilled("' . $callback['legB'] . '","' . $callback['legA'] . '");'); //$objResponse->addScript('setTimeout(xajax_addUnbilled("'.$localChan.'"),1000);'); //unset($_SESSION['callbacks'][$key]); $callback = null; } else { //not start yet } $_SESSION['callbacks'][$key]['start'] = 0; } else { if ($res->numRows() == 1) { //calling legA $_SESSION['callbacks'][$key]['start'] = 1; $res->fetchInto($legA); $destination = ''; if ($legA['destination'] != '') { $destination = '<br> ' . $legA['destination']; } $objResponse->addAssign($localChan . '-phone', 'innerHTML', $legA['dst'] . $destination); $objResponse->addAssign($localChan . '-startat', 'innerHTML', $legA['starttime']); $objResponse->addAssign($localChan . '-channel', 'value', $legA['srcchan']); // $objResponse->addAlert($legA['answertime']); if ($legA['answertime'] != '0000-00-00 00:00:00') { $now = time(); $initSec = $now - strtotime($legA['answertime']); $objResponse->addScript("putCurrentTime('" . $localChan . "-localanswertime',{$initSec});"); } /* if ($legA['dst'] != ''){ $rate = astercc::readRate($legA['dst'],$_SESSION['curuser']['groupid']); $objResponse->addAssign($localChan.'-rateinitial','innerHTML',floor($rate['rateinitial']*100)/100); $objResponse->addAssign($localChan.'-initblock','innerHTML',floor($rate['initblock']*100)/100); $objResponse->addAssign($localChan.'-billingblock','innerHTML',floor($rate['billingblock']*100)/100); $objResponse->addAssign($localChan.'-connectcharge','innerHTML',floor($rate['connectcharge']*100)/100); } */ $objResponse->addAssign($localChan . '-price', 'innerHTML', astercc::creditDigits($legA['credit'])); } else { if ($res->numRows() == 2) { //calling legB $_SESSION['callbacks'][$key]['start'] = 2; $res->fetchInto($legA); //**$destination = ''; if ($legA['destination'] != '') { $destination = '<br> ' . $legA['destination']; } $objResponse->addAssign($localChan . '-phone', 'innerHTML', $legA['dst'] . $destination); $objResponse->addAssign($localChan . '-startat', 'innerHTML', $legA['starttime']); $objResponse->addAssign($localChan . '-channel', 'value', $legA['srcchan']); if ($legA['answertime'] != '0000-00-00 00:00:00') { $now = time(); $initSec = $now - strtotime($legA['answertime']); $objResponse->addScript("putCurrentTime('" . $localChan . "-localanswertime',{$initSec});"); } /* if ($legA['dst'] != ''){ $rate = astercc::readRate($legA['dst'],$_SESSION['curuser']['groupid']); $objResponse->addAssign($localChan.'-rateinitial','innerHTML',floor($rate['rateinitial']*100)/100); $objResponse->addAssign($localChan.'-initblock','innerHTML',floor($rate['initblock']*100)/100); $objResponse->addAssign($localChan.'-billingblock','innerHTML',floor($rate['billingblock']*100)/100); $objResponse->addAssign($localChan.'-connectcharge','innerHTML',floor($rate['connectcharge']*100)/100); } */ $objResponse->addAssign($localChan . '-price', 'innerHTML', astercc::creditDigits($legA['credit'])); //** $res->fetchInto($legB); $destination = ''; if ($legB['destination'] != '') { $destination = '<br> ' . $legB['destination']; } $objResponse->addAssign($localChan . '-legb-phone', 'innerHTML', $legB['dst'] . $destination); $objResponse->addAssign($localChan . '-legb-startat', 'innerHTML', $legB['starttime']); $objResponse->addAssign($localChan . '-legb-channel', 'value', $legB['srcchan']); if ($legB['answertime'] != '0000-00-00 00:00:00') { $now = time(); $initSec = $now - strtotime($legB['answertime']); #print $legB['answertime']; $objResponse->addScript("putCurrentTime('" . $localChan . "-legb-localanswertime',{$initSec});"); } /* if ($legB['dst'] != ''){ $rate = astercc::readRate($legB['dst'],$_SESSION['curuser']['groupid']); $objResponse->addAssign($localChan.'-legb-rateinitial','innerHTML',floor($rate['rateinitial']*100)/100); $objResponse->addAssign($localChan.'-legb-initblock','innerHTML',floor($rate['initblock']*100)/100); $objResponse->addAssign($localChan.'-legb-billingblock','innerHTML',floor($rate['billingblock']*100)/100); $objResponse->addAssign($localChan.'-legb-connectcharge','innerHTML',floor($rate['connectcharge']*100)/100); } */ $objResponse->addAssign($localChan . '-legb-price', 'innerHTML', astercc::creditDigits($legB['credit'])); } } } } } $_SESSION['status'] = $peerstatus; //$objResponse->addScript('setTimeout("showStatus()", 2000);'); $objResponse->addAssign("spanLastRefresh", 'innerHTML', date("Y-m-d H:i:s", time())); return $objResponse; }