From ac4c1d6cbe34a2bfcea0bc895c6a22ee5e049bd5 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Thu, 9 Feb 2017 13:58:40 +1100 Subject: [PATCH] Email functions work! --- email.php | 19 ++++---------- functions/functions.limesurvey.php | 40 ++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/email.php b/email.php index 1fd11ecf..a6040fe5 100644 --- a/email.php +++ b/email.php @@ -81,24 +81,15 @@ if (isset($_POST['email']) && ((isset($_POST['firstname']) && !empty($_POST['fir $lime_sid = get_lime_sid($case_id); $ca = get_call_attempt($operator_id); $token = get_token($case_id); - $email = $db->qstr($_POST['email']); - $firstname = $db->qstr($_POST['firstname']); - $lastname = $db->qstr($_POST['lastname']); + $email = ($_POST['email']); + $firstname = ($_POST['firstname']); + $lastname = ($_POST['lastname']); - //set in Limesurvey - //set_participant_properties($sSessionKey, $lime_sid, array['token' => $token], array['email' => $email, 'firstname' => $firstname, 'lastname' => $lastname, 'emailstatus' => 'OK']); + $ret = lime_send_email($case_id,$email,$firstname,$lastname); - - if (0) //if mail sent - disable temporarily TODO: update properties in limesurvey + if ($ret) //if mail sent { - // Put call attempt id in to sent in Limesurvey - $sql = "UPDATE ". LIME_PREFIX . "tokens_{$lime_sid} - SET sent='$ca' - WHERE token='$token'"; - - //$db->Execute($sql); - //Add a note that sent $sql = "INSERT INTO `case_note` (case_id,operator_id,note,datetime) diff --git a/functions/functions.limesurvey.php b/functions/functions.limesurvey.php index 95b7f933..a4c11aa3 100644 --- a/functions/functions.limesurvey.php +++ b/functions/functions.limesurvey.php @@ -150,13 +150,49 @@ function lime_list_answeroptions($qid,$qcode) } +function lime_send_email($case_id,$email,$firstname,$lastname) +{ + 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),array('firstname' => $firstname, 'email' => $email, 'lastname' => $lastname)); + if (!isset($q['status'])) { + //send email + $q2 = $limeRPC->invite_participants($limeKey, $lime_id, array($q['tid'])); + if (!isset($q['status'])) { + $ret = true; + } + } + } + + limerpc_close(); + + return $ret; +} + + /** Get completed responses as an array based on the case_id */ function lime_get_responses_by_case($case_id,$fields = null) { global $db; - global $limeRPC; - global $limeKey; + global $limeRPC; + global $limeKey; $sql = "SELECT c.token,c.questionnaire_id FROM `case` as c