From 06ad2c4d55c0357373c2b113658193477be86502 Mon Sep 17 00:00:00 2001 From: Stefano Fancello Date: Fri, 21 Sep 2018 16:58:50 +0200 Subject: [PATCH 1/4] Add "invalid" and "timeout" logging --- functions.inc.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions.inc.php b/functions.inc.php index 8dd2e7a..5521afc 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -28,6 +28,11 @@ function queuemetrics_hookGet_config($engine) { $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|${IVR_CONTEXT}')); $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); } + $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|${IVR_CONTEXT}')); + $ext->splice($context, 'i','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); + $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|${IVR_CONTEXT}')); + $ext->splice($context, 't','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); + } } } From f979cce4c24c1d82fca189b30300b6b4ec1a4ce2 Mon Sep 17 00:00:00 2001 From: Stefano Fancello Date: Thu, 27 Sep 2018 14:36:51 +0200 Subject: [PATCH 2/4] Also save IVR name --- functions.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 5521afc..ac1cdb9 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -25,12 +25,12 @@ function queuemetrics_hookGet_config($engine) { foreach($ivrentrieslist as $selection) { //splice into ivr selection - $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|${IVR_CONTEXT}')); + $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|${IVR_CONTEXT}|'.$item['name'])); $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); } - $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|${IVR_CONTEXT}')); + $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|${IVR_CONTEXT}|'.$item['name'])); $ext->splice($context, 'i','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); - $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|${IVR_CONTEXT}')); + $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|${IVR_CONTEXT}|'.$item['name'])); $ext->splice($context, 't','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); } From 1c8f89ea1448908cebc978438396d158d4749d04 Mon Sep 17 00:00:00 2001 From: Stefano Fancello Date: Thu, 27 Sep 2018 14:45:32 +0200 Subject: [PATCH 3/4] Better indentation --- functions.inc.php | 124 +++++++++++++++++++++--------------------- install.php | 30 +++++----- page.queuemetrics.php | 12 ++-- uninstall.php | 2 +- 4 files changed, 84 insertions(+), 84 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index ac1cdb9..1dea315 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -2,66 +2,66 @@ if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); } function queuemetrics_hookGet_config($engine) { - global $ext; - global $db; - - switch($engine) { - case "asterisk": - - $ivr_logging = queuemetrics_get_details('ivr_logging'); - if ($ivr_logging['value'] == 'true') { - - //get all ivrs - $ivrlist = ivr_get_details(); - if(is_array($ivrlist)) { - - foreach($ivrlist as $item) { - //splice into ivr to set the ivr selection var and append if already defined - $context = 'ivr-'.$item['id']; - - //get ivr selection - $ivrentrieslist = ivr_get_entries($item['id']); - if (is_array($ivrentrieslist)) { - - foreach($ivrentrieslist as $selection) { - //splice into ivr selection - $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|${IVR_CONTEXT}|'.$item['name'])); - $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); - } - $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|${IVR_CONTEXT}|'.$item['name'])); - $ext->splice($context, 'i','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); - $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|${IVR_CONTEXT}|'.$item['name'])); - $ext->splice($context, 't','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); - - } - } - } - } - break; - } + global $ext; + global $db; + + switch($engine) { + case "asterisk": + + $ivr_logging = queuemetrics_get_details('ivr_logging'); + if ($ivr_logging['value'] == 'true') { + + //get all ivrs + $ivrlist = ivr_get_details(); + if(is_array($ivrlist)) { + + foreach($ivrlist as $item) { + //splice into ivr to set the ivr selection var and append if already defined + $context = 'ivr-'.$item['id']; + + //get ivr selection + $ivrentrieslist = ivr_get_entries($item['id']); + if (is_array($ivrentrieslist)) { + + foreach($ivrentrieslist as $selection) { + //splice into ivr selection + $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|${IVR_CONTEXT}|'.$item['name'])); + $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); + } + $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|${IVR_CONTEXT}|'.$item['name'])); + $ext->splice($context, 'i','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); + $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|${IVR_CONTEXT}|'.$item['name'])); + $ext->splice($context, 't','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); + + } + } + } + } + break; + } } function queuemetrics_configpageinit($pagename) { global $currentcomponent; - $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; + $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : ''; - + if($pagename == 'queuemetrics'){ $currentcomponent->addprocessfunc('queuemetrics_configprocess'); - return true; + return true; } } //process received arguments function queuemetrics_configprocess(){ if (isset($_REQUEST['display']) && $_REQUEST['display'] == 'queuemetrics'){ - - //get variables - $get_var = array('ivr_logging'); - - foreach($get_var as $var){ + + //get variables + $get_var = array('ivr_logging'); + + foreach($get_var as $var){ $vars[$var] = isset($_REQUEST[$var]) ? $_REQUEST[$var] : ''; } @@ -69,7 +69,7 @@ function queuemetrics_configprocess(){ switch ($action) { case 'save': - queuemetrics_put_details($vars); + queuemetrics_put_details($vars); needreload(); redirect_standard_continue(); break; @@ -78,35 +78,35 @@ function queuemetrics_configprocess(){ } function queuemetrics_put_details($options) { - global $db; - - foreach ($options as $key => $item) { - $data[] = array($key, $item); - } + global $db; + + foreach ($options as $key => $item) { + $data[] = array($key, $item); + } - $sql = $db->prepare('REPLACE INTO queuemetrics_options (`keyword`, `value`) VALUES (?, ?)'); + $sql = $db->prepare('REPLACE INTO queuemetrics_options (`keyword`, `value`) VALUES (?, ?)'); $ret = $db->executeMultiple($sql, $data); - - if($db->IsError($ret)) { - die_freepbx($ret->getDebugInfo()."\n".$ret->getUserInfo()."\n".$db->last_query); + + if($db->IsError($ret)) { + die_freepbx($ret->getDebugInfo()."\n".$ret->getUserInfo()."\n".$db->last_query); } - return TRUE; + return TRUE; } function queuemetrics_get_details($keyword = '') { - global $db; + global $db; $sql = "SELECT * FROM queuemetrics_options"; - if (!empty($keyword)) { - $sql .= " WHERE `keyword` = '" . $keyword . "'"; - } + if (!empty($keyword)) { + $sql .= " WHERE `keyword` = '" . $keyword . "'"; + } - $res = $db->getAll($sql, DB_FETCHMODE_ASSOC); + $res = $db->getAll($sql, DB_FETCHMODE_ASSOC); if($db->IsError($res)) { die_freepbx($res->getDebugInfo()); } - return (isset($keyword) && $keyword != '') ? $res[0] : $res; + return (isset($keyword) && $keyword != '') ? $res[0] : $res; } ?> diff --git a/install.php b/install.php index 911a928..b22a9b4 100644 --- a/install.php +++ b/install.php @@ -6,24 +6,24 @@ $sql = "SELECT * FROM `queuemetrics_options` LIMIT 1"; $check = $db->query($sql); if(!DB::IsError($check)) { - out(_("queuemetrics table already exists, exiting")); + out(_("queuemetrics table already exists, exiting")); } else { - unset($sql); - $sql[] = "CREATE TABLE IF NOT EXISTS `queuemetrics_options` ( - `keyword` VARCHAR(25), - `value` TEXT, - UNIQUE KEY `keyword` (`keyword`) - )"; - - foreach ($sql as $q) { - $result = $db->query($q); - if($db->IsError($result)){ - die_freepbx($result->getDebugInfo()); - } - } + unset($sql); + $sql[] = "CREATE TABLE IF NOT EXISTS `queuemetrics_options` ( + `keyword` VARCHAR(25), + `value` TEXT, + UNIQUE KEY `keyword` (`keyword`) + )"; + + foreach ($sql as $q) { + $result = $db->query($q); + if($db->IsError($result)){ + die_freepbx($result->getDebugInfo()); + } + } - outn(_("creating queuemetrics...ok")); + outn(_("creating queuemetrics...ok")); } // sysadmin migration diff --git a/page.queuemetrics.php b/page.queuemetrics.php index ba3a594..21525b7 100644 --- a/page.queuemetrics.php +++ b/page.queuemetrics.php @@ -1,29 +1,29 @@ - $val) { - $var[$val['keyword']] = isset($_REQUEST[$val['keyword']]) ? $_REQUEST[$val['keyword']] : $val['value']; - $$val['keyword'] = $var[$val['keyword']]; + $var[$val['keyword']] = isset($_REQUEST[$val['keyword']]) ? $_REQUEST[$val['keyword']] : $val['value']; + $$val['keyword'] = $var[$val['keyword']]; } $checked = (isset($ivr_logging) && $ivr_logging == 'true')?'CHECKED':''; echo '

QueueMetrics

'; echo '
'; -echo ''; +echo ''; echo '

'; $table = new CI_Table(); $table->add_row( _('Settings')); $table->add_row('
'); -$table->add_row('Log IVR Selections ' . _('When checked, IVR selections will be reported by QueueMetrics') . '', ''); +$table->add_row('Log IVR Selections ' . _('When checked, IVR selections will be reported by QueueMetrics') . '', ''); $table->add_row(''); $table->add_row(''); $table->add_row(''); -echo $table->generate(); +echo $table->generate(); echo '














'; diff --git a/uninstall.php b/uninstall.php index 4e941f1..4496eb8 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,4 +1,4 @@ - Date: Thu, 27 Sep 2018 14:47:52 +0200 Subject: [PATCH 4/4] Use ivr context hardcoded in dialplan this instead of using IVRCONTEXT asterisk variable. May be useful if dialplan is entered not at the beginning of ivr context (like if IVR is inside a queue) --- functions.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 1dea315..f4b0bc3 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -25,12 +25,12 @@ function queuemetrics_hookGet_config($engine) { foreach($ivrentrieslist as $selection) { //splice into ivr selection - $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|${IVR_CONTEXT}|'.$item['name'])); + $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_setvar("IVRSELECTION", '${EXTEN}|'.$context.'|'.$item['name'])); $ext->splice($context, $selection['selection'], 'ivrsel-'.$selection['selection'], new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); } - $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|${IVR_CONTEXT}|'.$item['name'])); + $ext->splice($context, 'i','final', new ext_setvar("IVRSELECTION", 'i|'.$context.'|'.$item['name'])); $ext->splice($context, 'i','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); - $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|${IVR_CONTEXT}|'.$item['name'])); + $ext->splice($context, 't','final', new ext_setvar("IVRSELECTION", 't|'.$context.'|'.$item['name'])); $ext->splice($context, 't','final', new ext_queuelog('NONE','${UNIQUEID}','NONE','INFO', 'IVRAPPEND|${IVRSELECTION}')); }