From 20e80e3e4e2eb9011803f89aa61f7de1449d58fb Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Wed, 1 Feb 2017 14:38:53 +1100 Subject: [PATCH] Allow for tokens to be imported --- CHANGELOG | 3 +++ admin/assignsample.php | 13 +++++++++++-- database/quexs.sql | 1 + functions/functions.import.php | 12 ++++++++++++ functions/functions.operator.php | 19 +++++++++++++++++-- 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bce65ec0..2fbc8c8b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +INSERT INTO `sample_var_type` (`type`, `description`, `table`) VALUES(9, 'Token', ''); + + queXS 1.14.4 - Changes since 1.14.3 Fourth bug fix release. diff --git a/admin/assignsample.php b/admin/assignsample.php index 49e0460f..492ca220 100644 --- a/admin/assignsample.php +++ b/admin/assignsample.php @@ -79,6 +79,8 @@ $js_foot = array( ); global $db; +$error = ""; + if (isset($_GET['questionnaire_id']) && isset($_GET['sample']) && isset($_GET['call_max']) && isset($_GET['call_attempt_max'])) { //need to add sample to questionnaire @@ -144,10 +146,14 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['sample']) && isset($_GET[' $rs = $db->GetAll($sql); + $count = 0; foreach($rs as $r) - { + { + $count++; set_time_limit(30); - add_case($r['sample_id'],$questionnaire_id,"NULL",$testing,41, true); + if (add_case($r['sample_id'],$questionnaire_id,"NULL",$testing,41, true) === false) { + $error .= "
Failed to add case for record #$count"; + } } $db->CompleteTrans(); @@ -306,6 +312,9 @@ xhtml_head(T_("Assign samples to questionnaires"),true,$css,$js_head,false,false print " " . T_("Go back") . ""; +if (!empty($error)) { + print "
$error
"; +} $questionnaire_id = false; if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']); diff --git a/database/quexs.sql b/database/quexs.sql index ab62eab1..ad7fee93 100644 --- a/database/quexs.sql +++ b/database/quexs.sql @@ -1523,6 +1523,7 @@ INSERT INTO `sample_var_type` (`type`, `description`, `table`) VALUES(5, 'Postco INSERT INTO `sample_var_type` (`type`, `description`, `table`) VALUES(6, 'Respondent first name', ''); INSERT INTO `sample_var_type` (`type`, `description`, `table`) VALUES(7, 'Respondent last name', ''); INSERT INTO `sample_var_type` (`type`, `description`, `table`) VALUES(8, 'Email address', ''); +INSERT INTO `sample_var_type` (`type`, `description`, `table`) VALUES(9, 'Token', ''); -- -------------------------------------------------------- diff --git a/functions/functions.import.php b/functions/functions.import.php index 500bc08d..440abed9 100644 --- a/functions/functions.import.php +++ b/functions/functions.import.php @@ -95,6 +95,18 @@ function verify_fields($fields) } } + //check that only 0 or 1 token fields selected + $count = 0; + foreach($names as $val) + { + if ($val == 9) $count++; + } + + if ($count > 1) + { + return T_("No more than one field may be a token field"); + } + //check that there is one and one only primary phone selected $count = 0; foreach($names as $val) diff --git a/functions/functions.operator.php b/functions/functions.operator.php index 31a42c01..f6518588 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -354,10 +354,23 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = { global $db; + //if token is specified, get from sample + $sql = "SELECT sv.val + FROM sample_var as sv, sample_import_var_restrict as sivr + WHERE sv.sample_id = '$sample_id' + AND sv.var_id = sivr.var_id + AND sivr.type = 9"; //9 is the token value + + $dtoken = $db->GetOne($sql); + $ttries = 0; do { - $token = sRandomChars(); + if (empty($dtoken)) { + $token = sRandomChars(); + } else { + $token = $dtoken; + } $sql = "SELECT count(*) as c FROM `case` @@ -365,7 +378,9 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = $ttries++; } while ($db->GetOne($sql) > 0 && $ttries < 10); - + + if ($ttries >= 10) //failed to get a token + return false; $sql = "INSERT INTO `case` (case_id, sample_id, questionnaire_id, last_call_id, current_operator_id, current_call_id, current_outcome_id,token) VALUES (NULL, $sample_id, $questionnaire_id, NULL, $operator_id, NULL, '$current_outcome_id','$token')";