2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Added email to respondent popup

Changed id's of self completion outcomes to allow for a few custom ones to not effect
Added email validation and token getting functions
Optout function of limesurvey to set outcome to refused and add a case note for clarity
Need to do: Complete email function to actually send an email invitation
This commit is contained in:
Adam Zammit
2013-02-25 15:25:08 +11:00
parent a22f4acd66
commit ae5c2f8431
7 changed files with 423 additions and 3 deletions

View File

@@ -15,8 +15,8 @@ UPDATE `case` SET token = case_id;
New outcomes for email invitation and online self completion:
INSERT INTO `outcome` (`outcome_id`, `aapor_id`, `description`, `default_delay_minutes`, `outcome_type_id`, `tryanother`, `contacted`, `tryagain`, `eligible`, `require_note`, `calc`) VALUES
(34, '1.1', 'Self completed online', 0, 4, 0, 1, 1, 1, 0, 'I'),
(35, '2.36', 'Self completion email invitation sent', 10080, 1, 0, 1, 1, 1, 0, 'O');
(40, '1.1', 'Self completed online', 0, 4, 0, 1, 1, 1, 0, 'I'),
(41, '2.36', 'Self completion email invitation sent', 10080, 1, 0, 1, 1, 1, 0, 'O');
New sample variable type (Email address):

View File

@@ -126,6 +126,7 @@ function display_outcomes($contacted,$ca,$case_id)
WHERE contacted = '$contacted'
AND outcome_id != 10"; //don't show completed if not
}
}
}
$rs = $db->GetAll($sql);
@@ -133,7 +134,13 @@ function display_outcomes($contacted,$ca,$case_id)
print "<div>";
if (!empty($rs))
{
$do = false;
//Get current outcome to set as default
$sql = "SELECT outcome
FROM `call`
WHERE call_attempt_id = $ca
AND `end` IS NULL";
$do = $db->GetOne($sql);
if (isset($_GET['defaultoutcome'])) $do = bigintval($_GET['defaultoutcome']);
foreach($rs as $r)
{

156
email.php Normal file
View File

@@ -0,0 +1,156 @@
<?php
/**
* Popup screen to manage calling and hanging up and assigning outcomes to calls
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2013
* @package queXS
* @subpackage user
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
*
*/
/**
* Configuration file
*/
include ("config.inc.php");
/**
* Database file
*/
include ("db.inc.php");
/**
* XHTML functions
*/
include ("functions/functions.xhtml.php");
/**
* Operator functions
*/
include("functions/functions.operator.php");
/**
* Input functions
*/
include("functions/functions.input.php");
/**
* LimeSurvey functions
*/
include("functions/functions.limesurvey.php");
global $db;
$operator_id = get_operator_id();
$msg = "";
if (isset($_POST['firstname']))
{
//validate email address
if (validate_email($_POST['email']))
{
$case_id = get_case_id($operator_id);
$lime_sid = get_lime_sid($case_id);
$token = get_token($case_id);
$email = $db->qstr($_POST['email']);
$firstname = $db->qstr($_POST['firstname']);
$lastname = $db->qstr($_POST['lastname']);
//update the limesurvey database email details
$sql = "UPDATE " . LIME_PREFIX ."tokens_{$lime_sid}
SET email = $email, firstname = $firstname, lastname = $lastname, emailstatus = 'OK'
WHERE token = '$token'";
$db->Execute($sql);
if (isset($_POST['submith']))
{
end_call($operator_id,41); //end with outcome sent
if (is_voip_enabled($operator_id))
{
include("functions/functions.voip.php");
$v = new voip();
$v->connect(VOIP_SERVER);
$v->hangup(get_extension($operator_id));
}
//disable recording
$newtext = T_("Start REC");
$js = "js/window.js";
if (browser_ie()) $js = "js/window_ie6.js";
xhtml_head(T_("Email"),true,array("css/call.css"),array($js),"onload='toggleRec(\"$newtext\",\"record.php?start=start\",\"offline\"); openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id) . "\"); parent.closePopup();'");
}
else if (isset($_POST['submit']))
{
$call_id = get_call($operator_id);
$sql = "UPDATE `call` as c
SET c.outcome_id = 41
WHERE c.call_id = $call_id";
$db->Execute($sql);
xhtml_head(T_("Email"),true,array("css/call.css"),array($js),"onload='parent.closePopup();'");
}
xhtml_foot();
die();
}
else
{
$msg = T_("The email address is not valid");
}
}
$case_id = get_case_id($operator_id);
$js = "js/window.js";
if (browser_ie()) $js = "js/window_ie6.js";
xhtml_head(T_("Email"),true,array("css/call.css"),array($js));
$sql = "SELECT sv1.val as firstname, sv2.val as lastname, sv3.val as email
FROM `case` as c
LEFT JOIN sample_var as sv1 on (sv1.sample_id = c.sample_id AND sv1.type = 6)
LEFT JOIN sample_var as sv2 on (sv2.sample_id = c.sample_id AND sv2.type = 7)
LEFT JOIN sample_var as sv3 on (sv3.sample_id = c.sample_id AND sv3.type = 8)
WHERE c.case_id = $case_id";
$rs = $db->GetRow($sql);
print "<div class='status'>" . T_("Email respondent for self completion") . "</div>";
if (!empty($msg)) print "<p>$msg</p>";
print "<form action='?' method='post'>";
print "<div><label for='firstname'>" . T_("First name") . "</label><input type='text' value='{$rs['firstname']}' name='firstname' id='firstname'/></div>";
print "<div><label for='lastname'>" . T_("Last name") . "</label><input type='text' value='{$rs['lastname']}' name='lastname' id='lastname'/></div>";
print "<div><label for='email'>" . T_("Email") . "</label><input type='text' value='{$rs['email']}' name='email' id='email'/></div>";
print "<div><input type='submit' value='" . T_("Send invitation") . "' name='submit' id='submit'/></div>";
print "<div><input type='submit' value='" . T_("Send invitation and Hang up") . "' name='submith' id='submith'/></div></form>";
xhtml_foot();
?>

View File

@@ -42,6 +42,214 @@ include_once(dirname(__FILE__).'/../config.inc.php');
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/*function validate_email($email)
{
// Create the syntactical validation regular expression
// Validate the syntax
// see http://data.iana.org/TLD/tlds-alpha-by-domain.txt
$maxrootdomainlength = 6;
return ( ! preg_match("/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,".$maxrootdomainlength."}))$/ix", $email)) ? FALSE : TRUE;
}*/
function validate_email($email){
$no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]";
$alpha = "[\\x41-\\x5a\\x61-\\x7a]";
$digit = "[\\x30-\\x39]";
$cr = "\\x0d";
$lf = "\\x0a";
$crlf = "(?:$cr$lf)";
$obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]";
$obs_text = "(?:$lf*$cr*(?:$obs_char$lf*$cr*)*)";
$text = "(?:[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|$obs_text)";
$text = "(?:$lf*$cr*$obs_char$lf*$cr*)";
$obs_qp = "(?:\\x5c[\\x00-\\x7f])";
$quoted_pair = "(?:\\x5c$text|$obs_qp)";
$wsp = "[\\x20\\x09]";
$obs_fws = "(?:$wsp+(?:$crlf$wsp+)*)";
$fws = "(?:(?:(?:$wsp*$crlf)?$wsp+)|$obs_fws)";
$ctext = "(?:$no_ws_ctl|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])";
$ccontent = "(?:$ctext|$quoted_pair)";
$comment = "(?:\\x28(?:$fws?$ccontent)*$fws?\\x29)";
$cfws = "(?:(?:$fws?$comment)*(?:$fws?$comment|$fws))";
$outer_ccontent_dull = "(?:$fws?$ctext|$quoted_pair)";
$outer_ccontent_nest = "(?:$fws?$comment)";
$outer_comment = "(?:\\x28$outer_ccontent_dull*(?:$outer_ccontent_nest$outer_ccontent_dull*)+$fws?\\x29)";
$atext = "(?:$alpha|$digit|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])";
$atext_domain = "(?:$alpha|$digit|[\\x2b\\x2d\\x5f])";
$atom = "(?:$cfws?(?:$atext)+$cfws?)";
$atom_domain = "(?:$cfws?(?:$atext_domain)+$cfws?)";
$qtext = "(?:$no_ws_ctl|[\\x21\\x23-\\x5b\\x5d-\\x7e])";
$qcontent = "(?:$qtext|$quoted_pair)";
$quoted_string = "(?:$cfws?\\x22(?:$fws?$qcontent)*$fws?\\x22$cfws?)";
$quoted_string = "(?:$cfws?\\x22(?:$fws?$qcontent)+$fws?\\x22$cfws?)";
$word = "(?:$atom|$quoted_string)";
$obs_local_part = "(?:$word(?:\\x2e$word)*)";
$obs_domain = "(?:$atom_domain(?:\\x2e$atom_domain)*)";
$dot_atom_text = "(?:$atext+(?:\\x2e$atext+)*)";
$dot_atom_text_domain = "(?:$atext_domain+(?:\\x2e$atext_domain+)*)";
$dot_atom = "(?:$cfws?$dot_atom_text$cfws?)";
$dot_atom_domain = "(?:$cfws?$dot_atom_text_domain$cfws?)";
$dtext = "(?:$no_ws_ctl|[\\x21-\\x5a\\x5e-\\x7e])";
$dcontent = "(?:$dtext|$quoted_pair)";
$domain_literal = "(?:$cfws?\\x5b(?:$fws?$dcontent)*$fws?\\x5d$cfws?)";
$local_part = "(($dot_atom)|($quoted_string)|($obs_local_part))";
$domain = "(($dot_atom_domain)|($domain_literal)|($obs_domain))";
$addr_spec = "$local_part\\x40$domain";
if (strlen($email) > 256) return FALSE;
$email = strip_comments($outer_comment, $email, "(x)");
if (!preg_match("!^$addr_spec$!", $email, $m)){
return FALSE;
}
$bits = array(
'local' => isset($m[1]) ? $m[1] : '',
'local-atom' => isset($m[2]) ? $m[2] : '',
'local-quoted' => isset($m[3]) ? $m[3] : '',
'local-obs' => isset($m[4]) ? $m[4] : '',
'domain' => isset($m[5]) ? $m[5] : '',
'domain-atom' => isset($m[6]) ? $m[6] : '',
'domain-literal' => isset($m[7]) ? $m[7] : '',
'domain-obs' => isset($m[8]) ? $m[8] : '',
);
$bits['local'] = strip_comments($comment, $bits['local']);
$bits['domain'] = strip_comments($comment, $bits['domain']);
if (strlen($bits['local']) > 64) return FALSE;
if (strlen($bits['domain']) > 255) return FALSE;
if (strlen($bits['domain-literal'])){
$Snum = "(\d{1,3})";
$IPv4_address_literal = "$Snum\.$Snum\.$Snum\.$Snum";
$IPv6_hex = "(?:[0-9a-fA-F]{1,4})";
$IPv6_full = "IPv6\:$IPv6_hex(:?\:$IPv6_hex){7}";
$IPv6_comp_part = "(?:$IPv6_hex(?:\:$IPv6_hex){0,5})?";
$IPv6_comp = "IPv6\:($IPv6_comp_part\:\:$IPv6_comp_part)";
$IPv6v4_full = "IPv6\:$IPv6_hex(?:\:$IPv6_hex){5}\:$IPv4_address_literal";
$IPv6v4_comp_part = "$IPv6_hex(?:\:$IPv6_hex){0,3}";
$IPv6v4_comp = "IPv6\:((?:$IPv6v4_comp_part)?\:\:(?:$IPv6v4_comp_part\:)?)$IPv4_address_literal";
if (preg_match("!^\[$IPv4_address_literal\]$!", $bits['domain'], $m)){
if (intval($m[1]) > 255) return FALSE;
if (intval($m[2]) > 255) return FALSE;
if (intval($m[3]) > 255) return FALSE;
if (intval($m[4]) > 255) return FALSE;
}else{
while (1){
if (preg_match("!^\[$IPv6_full\]$!", $bits['domain'])){
break;
}
if (preg_match("!^\[$IPv6_comp\]$!", $bits['domain'], $m)){
list($a, $b) = explode('::', $m[1]);
$folded = (strlen($a) && strlen($b)) ? "$a:$b" : "$a$b";
$groups = explode(':', $folded);
if (count($groups) > 6) return FALSE;
break;
}
if (preg_match("!^\[$IPv6v4_full\]$!", $bits['domain'], $m)){
if (intval($m[1]) > 255) return FALSE;
if (intval($m[2]) > 255) return FALSE;
if (intval($m[3]) > 255) return FALSE;
if (intval($m[4]) > 255) return FALSE;
break;
}
if (preg_match("!^\[$IPv6v4_comp\]$!", $bits['domain'], $m)){
list($a, $b) = explode('::', $m[1]);
$b = substr($b, 0, -1); # remove the trailing colon before the IPv4 address
$folded = (strlen($a) && strlen($b)) ? "$a:$b" : "$a$b";
$groups = explode(':', $folded);
if (count($groups) > 4) return FALSE;
break;
}
return FALSE;
}
}
}else{
$labels = explode('.', $bits['domain']);
if (count($labels) == 1) return FALSE;
foreach ($labels as $label){
if (strlen($label) > 63) return FALSE;
if (substr($label, 0, 1) == '-') return FALSE;
if (substr($label, -1) == '-') return FALSE;
}
if (preg_match('!^[0-9]+$!', array_pop($labels))) return FALSE;
}
return TRUE;
}
/**
* Return the number of completions for a given
* questionnaire, where the given sample var has

View File

@@ -646,6 +646,31 @@ function get_case_id($operator_id, $create = false)
}
/**
* Get the token based on the case id
*
* @param int $case_id The case id
*
* @return string|bool The token otherwise false if case doesn't exist
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2013-02-25
*/
function get_token($case_id)
{
global $db;
$sql = "SELECT token
FROM `case`
WHERE case_id = $case_id";
$token = $db->GetOne($sql);
if (empty($token)) return FALSE;
return $token;
}
/**
* Return the phone number of a call
*

View File

@@ -60,6 +60,29 @@ else
{
$usquery = "Update ".db_table_name("tokens_{$surveyid}")." set emailstatus='OptOut', usesleft=0 where token=".db_quoteall($token,true);
$usresult = $connect->Execute($usquery);
//queXS addition
//Set to Hard Refusal, respondent
$sql = "UPDATE `case`
SET current_outcome_id = 9
WHERE token = '$token'";
$connect->Execute($sql);
$sql = "SELECT case_id
FROM `case`
WHERE token = '$token'";
$case_id = $connect->GetOne($sql);
//Add a case note to clarify (need to translate this string)
$sql = "INSERT INTO `case_note` (case_id,operator_id,note,datetime)
VALUES ($case_id,1,'Self completion refused via opt out function',NOW())";
$connect->Execute($sql);
$html .= $clang->gT('You have been successfully removed from this survey.');
}
else

View File

@@ -137,6 +137,7 @@ print $script;
<div class='box'><a href="javascript:poptastic('appointment.php');"><?php echo T_("Appointment"); ?></a></div>
<div class='box important'><a href="javascript:poptastic('call.php');"><?php echo T_("Call/Hangup"); ?></a></div>
<div class='box'><a href="javascript:poptastic('supervisor.php');"><?php echo T_("Supervisor"); ?></a></div>
<div class='box'><a href="javascript:poptastic('email.php');"><?php echo T_("Email"); ?></a></div>
<div class='box' id='recbox'><a id='reclink' class='offline' href="javascript:poptastic('record.php?start=start');"><?php echo T_("Start REC"); ?></a></div>
<?php if (HEADER_EXPANDER_MANUAL){ ?> <div class='headerexpand'><img id='headerexpandimage' src='./images/arrow-up-2.png' alt='<?php echo T_('Arrow for expanding or contracting'); ?>'/></div> <?php } ?>
<div class='box'><a href='index.php?'><?php echo T_("Restart"); ?></a></div>