diff --git a/admin/process.php b/admin/process.php index 08003d10..c6f3e84b 100644 --- a/admin/process.php +++ b/admin/process.php @@ -59,7 +59,7 @@ function update_callback($buffer) { global $process_id; - process_append_data($process_id,"

" . $buffer . "

"); + process_append_data($process_id,$buffer); return ""; //empty buffer } diff --git a/admin/systemsort.php b/admin/systemsort.php index 64410481..9bf4dcf8 100644 --- a/admin/systemsort.php +++ b/admin/systemsort.php @@ -70,7 +70,7 @@ if ($p) kill_process($p); } - xhtml_head(T_("Monitor system wide case sorting"),true,false,false,false,false,true); + xhtml_head(T_("Monitor system wide case sorting"),true,array("../css/table.css"),false,false,false,true); print "

" . T_("Running process:") . " $p

"; @@ -84,16 +84,25 @@ if ($p) print "

" . T_("Kill the running process") . "

"; } - print process_get_data($p); + $d = process_get_data($p); + if ($d !== false) + { + xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry"))); + } + } else { - xhtml_head(T_("Monitor system wide case sorting")); + xhtml_head(T_("Monitor system wide case sorting"),true,array("../css/table.css")); print "

" . T_("Monitor system wide case sorting") . "

"; print "

" . T_("Click here to enable and begin system wide case sorting") . "

"; print "

" . T_("System wide case sorting is periodically (via SYSTEM_SORT_MINUTES configuration directive) sorting cases on a system wide basis instead of finding the most appropriate case each time an operator requests a new case. This may increase performance where there are a large number of cases or complex quotas in place. If you are not experiencing any performance problems, it is not recommended to use this feature.") . "

"; print "

" . T_("Outcome of last process run (if any)") . "

"; - print process_get_last_data(2); + $d = process_get_last_data(2); + if ($d !== false) + { + xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry"))); + } } xhtml_foot(); diff --git a/admin/systemsortprocess.php b/admin/systemsortprocess.php index e093f8d2..47d27035 100644 --- a/admin/systemsortprocess.php +++ b/admin/systemsortprocess.php @@ -54,7 +54,7 @@ function update_callback($buffer) { global $process_id; - process_append_data($process_id,"

" . $buffer . "

"); + process_append_data($process_id,$buffer); return ""; //empty buffer } @@ -92,7 +92,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin //Make sure that the system knows we are system sorting set_setting('systemsort',true); - print date("Y-m-d H:i") . " : " . T_("Sorting cases"); + print T_("Sorting cases"); $time_start = microtime(true); diff --git a/admin/voipmonitor.php b/admin/voipmonitor.php index fdc935c9..2a4c887c 100644 --- a/admin/voipmonitor.php +++ b/admin/voipmonitor.php @@ -70,7 +70,7 @@ if ($p) kill_process($p); } - xhtml_head(T_("Monitor VoIP Process"),true,false,false,false,false,true); + xhtml_head(T_("Monitor VoIP Process"),true,array("../css/table.css"),false,false,false,true); print "

" . T_("Running process:") . " $p

"; @@ -86,15 +86,23 @@ if ($p) print "

" . T_("Kill the running process") . " ". T_("(requires activity on the VoIP Server to take effect)") . "

"; } - print process_get_data($p); + $d = process_get_data($p); + if ($d !== false) + { + xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry"))); + } } else { - xhtml_head(T_("Monitor VoIP Process")); + xhtml_head(T_("Monitor VoIP Process"),true,array("../css/table.css")); print "

" . T_("Monitor VoIP Process") . "

"; print "

" . T_("Click here to begin monitoring the VoIP Process") . "

"; print "

" . T_("Outcome of last process run (if any)") . "

"; - print process_get_last_data(); + $d = process_get_last_data(); + if ($d !== false) + { + xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry"))); + } } xhtml_foot(); diff --git a/database/quexs.sql b/database/quexs.sql index 89be649f..af7676b8 100644 --- a/database/quexs.sql +++ b/database/quexs.sql @@ -453,6 +453,15 @@ CREATE TABLE `process` ( -- -------------------------------------------------------- +CREATE TABLE `process_log` ( +`process_log_id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY , +`process_id` BIGINT NOT NULL , +`datetime` DATETIME NOT NULL , +`data` TEXT NOT NULL , +INDEX ( `process_id` ) +) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE=utf8_unicode_ci; + + -- -- Table structure for table `questionnaire` -- diff --git a/functions/functions.process.php b/functions/functions.process.php index f74438a1..aabd0258 100644 --- a/functions/functions.process.php +++ b/functions/functions.process.php @@ -188,9 +188,8 @@ function process_append_data($process_id,$data) $data = $db->qstr($data,get_magic_quotes_gpc()); - $sql = "UPDATE `process` - SET `data` = CONCAT(`data`, $data) - WHERE `process_id` = '$process_id'"; + $sql = "INSERT INTO `process_log` (process_log_id,process_id,datetime,data) + VALUES (NULL,'$process_id',NOW(),$data)"; $db->Execute($sql); @@ -208,16 +207,17 @@ function process_get_data($process_id) { global $db; - $sql = "SELECT `data` - FROM `process` - WHERE `process_id` = '$process_id'"; + $sql = "SELECT process_log_id,datetime,data + FROM `process_log` + WHERE `process_id` = '$process_id' + ORDER BY process_log_id DESC"; - $rs = $db->GetRow($sql); + $rs = $db->GetAll($sql); if (!empty($rs)) - return $rs['data']; + return $rs; - return ""; + return false; } /** @@ -231,7 +231,7 @@ function process_get_last_data($type = 1) { global $db; - $sql = "SELECT `data` + $sql = "SELECT process_id FROM `process` WHERE type = '$type' ORDER BY `process_id` DESC @@ -240,9 +240,9 @@ function process_get_last_data($type = 1) $rs = $db->GetRow($sql); if (!empty($rs)) - return $rs['data']; + return process_get_data($rs['process_id']); - return ""; + return false; } ?> diff --git a/functions/functions.voip.php b/functions/functions.voip.php index 761b3c25..36ddcf22 100644 --- a/functions/functions.voip.php +++ b/functions/functions.voip.php @@ -326,7 +326,7 @@ class voip { return false; } - stream_set_timeout($this->socket, 1); + // stream_set_timeout($this->socket, 1); $q = "Action: Login\r\nUsername: $user\r\nSecret: $pass\r\nEvents: "; @@ -395,11 +395,14 @@ class voipWatch extends voip { function dbReconnect() { global $db; - - //keep reconnecting to the db so it doesn't time out - $db = newADOConnection(DB_TYPE); - $db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - $db->SetFetchMode(ADODB_FETCH_ASSOC); + + if (!$db->IsConnected()) + { + //keep reconnecting to the db so it doesn't time out + $db = newADOConnection(DB_TYPE); + $db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); + $db->SetFetchMode(ADODB_FETCH_ASSOC); + } } @@ -413,7 +416,7 @@ class voipWatch extends voip { { global $db; - $sql = "SELECT l.call_id + $sql = "SELECT l.call_id, c.case_id FROM operator AS o JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON ( c.current_operator_id = o.operator_id @@ -426,10 +429,14 @@ class voipWatch extends voip { $rs = $db->GetRow($sql); $call_id =0; + $case_id =0; if (!empty($rs)) + { $call_id =$rs['call_id']; + $case_id =$rs['case_id']; + } - return $call_id; + return array($call_id,$case_id); } @@ -511,10 +518,15 @@ class voipWatch extends voip { $this->updateAllExtensionStatus(); + $in = true; + + $time = time(); + //Watch for events do { - if (!$this->isConnected() || $this->socket === false){ + if (!$this->isConnected() || $this->socket === false || $in === FALSE){ + fclose($this->socket); print(T_("Disconnected") . "\n"); $this->connect(VOIP_SERVER,VOIP_ADMIN_USER,VOIP_ADMIN_PASS,true); if ($this->isConnected()) print (T_("Reconnected") . "\n"); @@ -522,6 +534,7 @@ class voipWatch extends voip { $in = fgets($this->socket, 4096); + //print "IN: $in\n"; /** @@ -536,10 +549,10 @@ class voipWatch extends voip { */ if (eregi("Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs)) { - $call_id = $this->getCallId($regs[1]); + list($call_id,$case_id) = $this->getCallId($regs[1]); if ($call_id != 0) { - print T_("Ringing") . T_(" Extension ") . $regs[1] . "\n"; + print T_("Ringing") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": $case_id\n"; $this->setState($call_id,2); } } @@ -548,10 +561,10 @@ class voipWatch extends voip { */ else if (eregi("Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)",$line,$regs)) { - $call_id = $this->getCallId($regs[1]); + list($call_id,$case_id) = $this->getCallId($regs[1]); if ($call_id != 0) { - print T_("Answered") . T_(" Extension ") . $regs[1] . "\n"; + print T_("Answered") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": $case_id\n"; $this->setState($call_id,3); } } @@ -560,10 +573,10 @@ class voipWatch extends voip { */ else if (eregi("Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs)) { - $call_id = $this->getCallId($regs[1]); + list($call_id,$case_id) = $this->getCallId($regs[1]); if ($call_id != 0) { - print T_("Hangup") . T_(" Extension ") . $regs[1] . "\n"; + print T_("Hangup") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": $case_id\n"; $this->setState($call_id,4,true); } } @@ -589,7 +602,7 @@ class voipWatch extends voip { //print $line . "\n\n"; $line = ""; } - else + else if ($in !== FALSE) { /** * Append the lines to the message if we are not yet at the end of one @@ -601,10 +614,11 @@ class voipWatch extends voip { @flush(); - if ($process_id) + if ($process_id && ((time() - $time) > 10)) { $this->dbReconnect(); $this->keepWatching = !is_process_killed($process_id); + $time = time(); } } while ($this->keepWatching);