From bfc6af3d7c871c0c336b7bf0314bdca05b9742ee Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Thu, 11 May 2017 12:20:48 +1000 Subject: [PATCH] Opt out of web when opting out of CATI --- functions/functions.limesurvey.php | 31 ++++++++++++++++++++++++++++++ functions/functions.operator.php | 17 +++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/functions/functions.limesurvey.php b/functions/functions.limesurvey.php index a4c11aa3..43e3f136 100644 --- a/functions/functions.limesurvey.php +++ b/functions/functions.limesurvey.php @@ -185,6 +185,37 @@ function lime_send_email($case_id,$email,$firstname,$lastname) return $ret; } +function lime_set_token_properties($case_id,$params = array('emailstatus' => 'OptOut')) +{ + global $db; + global $limeRPC; + global $limeKey; + + $sql = "SELECT c.token,c.questionnaire_id + FROM `case` as c + WHERE c.case_id = '$case_id'"; + + $rs = $db->GetRow($sql); + + $token = $rs['token']; + $qid = $rs['questionnaire_id']; + + $lime_id = limerpc_init_qid($qid); + + $ret = false; + + if ($lime_id !== false) { + $q = $limeRPC->set_participant_properties($limeKey,$lime_id,array('token' => $token),$params); + if (!isset($q['status'])) { + $ret = true; + } + } + + limerpc_close(); + + return $ret; +} + /** Get completed responses as an array based on the case_id */ diff --git a/functions/functions.operator.php b/functions/functions.operator.php index f6377151..28500b26 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -2287,7 +2287,22 @@ function end_case($operator_id) SET current_operator_id = NULL, current_call_id = NULL, sortorder = NULL, current_outcome_id = '$outcome', last_call_id = '$lastcall' WHERE case_id = '$case_id'"; - $o = $db->Execute($sql); + $o = $db->Execute($sql); + + //if this is a refusal outcome - set the Limesurvey token table to opt-out + //this will avoid sending email invitations once refused on the phone + + $sql = "SELECT count(*) + FROM outcome + WHERE outcome_type_id = 3 + AND outcome_id = $outcome"; + + $isrefusal = $db->GetOne($sql); + + if ($isrefusal > 0) { + include_once(dirname(__FILE__).'/functions.limesurvey.php'); + lime_set_token_properties($case_id,array('emailstatus' => 'OptOut')); + } $return = true; }