From ae36595e720ef0920cc5323077a130fe07085166 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Wed, 20 Nov 2013 11:40:46 +1100 Subject: [PATCH] Added new feature of automatic dialling using AUTO_DIAL_SECONDS parameter in config file Will also automatically end the case after the same number of seconds --- call.php | 6 +- config.default.php | 7 ++ functions/functions.operator.php | 23 ++-- index.php | 6 +- nocallavailable.php | 178 ++++++++++++++++++++++++++++++- 5 files changed, 203 insertions(+), 17 deletions(-) diff --git a/call.php b/call.php index 0ce64cb5..8b1827be 100644 --- a/call.php +++ b/call.php @@ -183,10 +183,8 @@ if (isset($_POST['submit'])) $v->connect(VOIP_SERVER); $v->dial(get_extension($operator_id),get_call_number($call_id)); } - if (is_respondent_selection($operator_id)) - $btext = "onload='openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id) . "\"); parent.closePopup();'"; - else - $btext = "onload='parent.closePopup();'"; + + $btext = "onload='openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id) . "\"); parent.closePopup();'"; $js = "js/window.js"; if (browser_ie()) $js = "js/window_ie6.js"; diff --git a/config.default.php b/config.default.php index 9e4822cc..38a9c5a7 100644 --- a/config.default.php +++ b/config.default.php @@ -199,6 +199,13 @@ if (!defined('AUTO_COMPLETE_OUTCOME')) define('AUTO_COMPLETE_OUTCOME',false); */ if (!defined('AUTO_LOGOUT_MINUTES')) define('AUTO_LOGOUT_MINUTES',false); +/** + * The number of seconds to wait before automatically dialling the first available number or ending the case + * where an operator has an open screen + * False to disable + */ +if (!defined('AUTO_DIAL_SECONDS')) define('AUTO_DIAL_SECONDS',false); + /** * The default tab to start on on the main screen */ diff --git a/functions/functions.operator.php b/functions/functions.operator.php index f0776329..b3448b8d 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -1185,7 +1185,7 @@ function get_call($operator_id,$respondent_id = "",$contact_phone_id = "",$creat /** * Get the complete URL for the Limesurvey questionnaire of respondent selection - * If no case available, return an error screen + * If no call available, return an error screen * * @param int $operator_id The operator id * @param bool $escape Whether to escape the ampersands default true @@ -1210,13 +1210,22 @@ function get_respondentselection_url($operator_id,$escape = true,$interface2 = f { $sid = get_limesurvey_id($operator_id,true); //true for RS if ($sid != false && !empty($sid) && $sid != 'NULL') - $url = LIME_URL . "index.php?interviewer=interviewer&loadall=reload" . $amp . "sid=$sid" . $amp . "token=$call_id" . $amp . "lang=" . DEFAULT_LOCALE; + $url = LIME_URL . "index.php?interviewer=interviewer" . $amp . "loadall=reload" . $amp . "sid=$sid" . $amp . "token=$call_id" . $amp . "lang=" . DEFAULT_LOCALE; else - { - if ($interface2) - $url = 'rs_intro_interface2.php'; - else - $url = 'rs_intro.php'; + { + if (is_respondent_selection($operator_id) === false) + { + $url = get_limesurvey_url($operator_id); + if (!$escape) + $url = str_replace("&","&",$url); + } + else + { + if ($interface2) + $url = 'rs_intro_interface2.php'; + else + $url = 'rs_intro.php'; + } } } diff --git a/index.php b/index.php index 1e214744..2eaf544b 100644 --- a/index.php +++ b/index.php @@ -173,11 +173,7 @@ if ($ca) } } -if (!is_respondent_selection($operator_id)) - $data = get_limesurvey_url($operator_id); -else - $data = get_respondentselection_url($operator_id); - +$data = "nocallavailable.php"; $db->CompleteTrans(); diff --git a/nocallavailable.php b/nocallavailable.php index 8cdf7d77..0a06c4ae 100644 --- a/nocallavailable.php +++ b/nocallavailable.php @@ -44,16 +44,192 @@ include ("functions/functions.xhtml.php"); */ include ("lang.inc.php"); -$js = false; +if (isset($_GET['contact_phone'])) +{ + include_once ("functions/functions.operator.php"); + include_once ("functions/functions.input.php"); + $operator_id = get_operator_id(); + $contact_phone_id = bigintval($_GET['contact_phone']); + $call_attempt_id = get_call_attempt($operator_id,false); + $respondent_id = get_respondent_id($call_attempt_id); + $call_id = get_call($operator_id,$respondent_id,$contact_phone_id,true); + if ($call_id) + { + if (is_voip_enabled($operator_id)) + { + include("functions/functions.voip.php"); + $v = new voip(); + $v->connect(VOIP_SERVER); + $v->dial(get_extension($operator_id),get_call_number($call_id)); + } + header('Location: '.get_respondentselection_url($operator_id,false)); + die(); + } +} + + +$js = array(); if (AUTO_LOGOUT_MINUTES !== false) $js = array("include/jquery-ui/js/jquery-1.4.2.min.js","js/childnap.js"); +$jsw = "js/window.js"; +if (browser_ie()) $jsw = "js/window_ie6.js"; + +$js[] = $jsw; + xhtml_head(T_("No call available"),true,array("css/table.css"),$js); ?>

GetOne($sql); + } + else + { + //determine whether we should make any more calls based on the last call outcome + + $sql = "SELECT o.tryanother, o.require_note + FROM `call` as c, `outcome` as o + WHERE c.call_attempt_id = '$call_attempt_id' + AND c.outcome_id = o.outcome_id + ORDER BY call_id DESC + LIMIT 1"; + + $rs = $db->GetRow($sql); + + if ((empty($rs) || $rs['tryanother'] == 1)) //dial another number only when available and not ending + { + $rn = 0; + if (!empty($rs) && $rs['require_note'] == 1) $rn = 1; + + //an exclusion left join + $sql = "SELECT c. * + FROM contact_phone AS c + LEFT JOIN ( + SELECT contact_phone.contact_phone_id + FROM contact_phone + LEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id ) + LEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id ) + WHERE contact_phone.case_id = '$case_id' + AND outcome.tryagain =0 + ) AS l ON l.contact_phone_id = c.contact_phone_id + LEFT JOIN + ( + SELECT contact_phone_id + FROM `call` + WHERE call_attempt_id = '$call_attempt_id' + AND outcome_id != 18 + ) as ca on ca.contact_phone_id = c.contact_phone_id + WHERE c.case_id = '$case_id' + AND l.contact_phone_id IS NULL + AND ca.contact_phone_id IS NULL"; //only select numbers that should be tried again and have not been tried in this attempt which are not the accidental hang up outcome + + //could be updated to take in to account the time delay and outcome + + $rs = $db->GetAll($sql); + + if (!empty($rs)) + { + $contact_phone_id = $rs[0]['contact_phone_id']; + } + } + } + + $jsfunctocall = ""; + $texttodisplay = ""; + $endtexttodisplay = ""; + + if ($contact_phone_id !== false) + { + //got a number to dial so initiate the countdown to begin dialing + $texttodisplay = T_("Will dial in"); + $endtexttodisplay = T_("Dialling now"); + $jsfunctocall = "document.location.href = 'nocallavailable.php?contact_phone=" . $contact_phone_id . "';"; + } + else + { + //no more numbers to dial so initiate the countdown to end the case + $texttodisplay = T_("Will end case in"); + $endtexttodisplay = T_("Ending case now"); + $jsfunctocall = "openParent('endcase=endcase');"; + } + print "
"; + print " "; + + } + else + { + //voip extension not active + print "
" . T_("Your VoIP extension is not active. Please activate VoIP by clicking once on the red button that says 'VoIP Off'") . "
"; + } + } + else + { + //voip isn't enabled so can't auto dial + print "
" . T_("Auto dialling unavailable as VoIP is not enabled") . "
"; + } + } + else + { + //on a call so can't proceed + print "
" . T_("Auto dialling unavailable as you are already on a call") . "
"; + } +} + + xhtml_foot();