diff --git a/call.php b/call.php index 1766d6e8..117cb013 100644 --- a/call.php +++ b/call.php @@ -259,11 +259,7 @@ switch($state) $es = 1; if (is_voip_enabled($operator_id)) { - include("functions/functions.voip.php"); - $v = new voip(); - $v->connect(VOIP_SERVER); - $ext = get_extension($operator_id); - if ($v->getExtensionStatus($ext)) + if (get_extension_status($operator_id)) $es = 1; else $es = 0; @@ -339,11 +335,7 @@ switch($state) $es = 1; if (is_voip_enabled($operator_id)) { - include("functions/functions.voip.php"); - $v = new voip(); - $v->connect(VOIP_SERVER); - $ext = get_extension($operator_id); - if ($v->getExtensionStatus($ext)) + if (get_extension_status($operator_id)) $es = 1; else $es = 0; diff --git a/database/quexs.sql b/database/quexs.sql index f4912ac4..62ed5bcd 100644 --- a/database/quexs.sql +++ b/database/quexs.sql @@ -306,6 +306,7 @@ CREATE TABLE `operator` ( `Time_zone_name` char(64) NOT NULL, `enabled` tinyint(1) NOT NULL default '1', `voip` tinyint(1) NOT NULL default '1', + `voip_status` tinyint(1) NOT NULL default '0', PRIMARY KEY (`operator_id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `extension` (`extension`) diff --git a/functions/functions.operator.php b/functions/functions.operator.php index 42fce1ff..34652775 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -537,6 +537,26 @@ function get_call_number($call_id) return false; } +/** + * Return the extension status from the database + * + * @param int $operator_id The queXS Operator ID + * @return bool the extension status (false for offline, true for online) + * + */ +function get_extension_status($operator_id) +{ + global $db; + + $sql = "SELECT o.voip_status + FROM `operator` as o + WHERE o.operator_id = '$operator_id'"; + + $rs = $db->GetRow($sql); + if (!empty($rs) && $rs['voip_status'] == 1 ) return true; + return false; +} + /** * Return the extension password of an operator * diff --git a/functions/functions.voip.php b/functions/functions.voip.php index c1c6e68f..9a4ffefc 100644 --- a/functions/functions.voip.php +++ b/functions/functions.voip.php @@ -433,6 +433,21 @@ class voipWatch extends voip { } + function setExtensionStatus($ext, $online = true) + { + global $db; + + $s = $online ? 1 : 0; + + print(T_("Extension") . " $ext " . ($online ? T_("online") : T_("offline")) . "\n"); + + $sql = "UPDATE operator + SET voip_status = '$s' + WHERE extension = '$ext'"; + + $db->Execute($sql); + } + function setState($call_id,$state,$checkOutcome = false) { global $db; @@ -447,6 +462,33 @@ class voipWatch extends voip { $db->Execute($sql); } + /** + * Update the extension status for all extensions + */ + function updateAllExtensionStatus() + { + global $db; + + $sql = "SELECT extension,operator_id + FROM operator + WHERE voip = 1 AND enabled = 1"; + + $rs = $db->GetAll($sql); + + foreach($rs as $r) + { + $o = $r['operator_id']; + $e = $r['extension']; + + $s = $this->getExtensionStatus($e); + + if ($s == false) + $this->setExtensionStatus($e,false); + else + $this->setExtensionStatus($e,true); + } + } + /** * Watch for Asterisk events and make changes to the queXS databse if * appropriate @@ -460,12 +502,16 @@ class voipWatch extends voip { */ if ($process_id) include_once(dirname(__FILE__).'/../functions/functions.process.php'); - $line = ""; if ($this->socket === false) return false; + //Set initial extension status + $this->updateAllExtensionStatus(); + + + //Watch for events do { if (!$this->isConnected() || $this->socket === false){ @@ -522,6 +568,24 @@ class voipWatch extends voip { } } + /** + * The status of an extension has changed to unregistered + */ + else if (eregi("Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Unregistered",$line,$regs)) + { + print T_("Unregistered") . T_(" Extension ") . $regs[1] . "\n"; + $this->setExtensionStatus($regs[1],false); + } + + /** + * The status of an extension has changed to registered + */ + else if (eregi("Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Registered",$line,$regs)) + { + print T_("Registered") . T_(" Extension ") . $regs[1] . "\n"; + $this->setExtensionStatus($regs[1],true); + } + //print $line . "\n\n"; $line = ""; } diff --git a/status.php b/status.php index c0a64584..4d0d32e2 100644 --- a/status.php +++ b/status.php @@ -68,9 +68,6 @@ print "
" . get_operator_time($operator_id,"%a %d %b %h:%i%p") if (is_voip_enabled($operator_id)) { - include("functions/functions.voip.php"); - $v = new voip(); - $v->connect(VOIP_SERVER); $ext = get_extension($operator_id); $exta = $ext; //Get just the start of the extension for auto dial out @@ -78,7 +75,7 @@ if (is_voip_enabled($operator_id)) if (isset($exts[1])) $exta = $exts[1]; $extp = get_extension_password($operator_id); - if ($v->getExtensionStatus($ext)) + if (get_extension_status($operator_id)) print "
" . T_("VoIP On") . "
"; else print "
" . T_("VoIP Off") . "
";