From da87c070b9cadab2bc47c53fb35cec7261e76fdb Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Sep 2013 12:15:51 +1000 Subject: [PATCH 1/6] Make sure to only convert number fields to numbers (otherwise will blank out state field/etc) --- functions/functions.import.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions/functions.import.php b/functions/functions.import.php index 622dc986..6705f439 100644 --- a/functions/functions.import.php +++ b/functions/functions.import.php @@ -257,7 +257,10 @@ function import_file($file, $description, $fields, $firstrow = 2) { $dkey = only_numbers($data[$key - 1]); if (!empty($dkey)) + { + $data[$key - 1] = $dkey; $numberavail = 1; + } } } @@ -287,7 +290,7 @@ function import_file($file, $description, $fields, $firstrow = 2) if (!empty($tname)) { - $value = $db->Quote(only_numbers($data[$key - 1])); + $value = $db->Quote($data[$key - 1]); $sql = "SELECT Time_zone_name as tz FROM `$tname` From e43ce5c8e73bfe46bb498300e2080e3b68318279 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Sep 2013 12:54:35 +1000 Subject: [PATCH 2/6] Separated get_time_zone from number as a function --- functions/functions.import.php | 74 ++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/functions/functions.import.php b/functions/functions.import.php index 6705f439..817c8efd 100644 --- a/functions/functions.import.php +++ b/functions/functions.import.php @@ -277,38 +277,14 @@ function import_file($file, $description, $fields, $firstrow = 2) * */ foreach($selected_type as $key => $val) - { - $sql = "SELECT `table` - FROM sample_var_type - WHERE type = '$val'"; - - $tname = $db->GetRow($sql); - - if (!empty($tname)) + { + $tz = get_time_zone($data[$key - 1],$val); + + if ($tz !== false) { - $tname = $tname['table']; - if (!empty($tname)) - { - - $value = $db->Quote($data[$key - 1]); - - $sql = "SELECT Time_zone_name as tz - FROM `$tname` - WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )"; - - $tz = $db->GetRow($sql); - - //print("$sql
"); - //if ($db->HasFailedTrans()) { print "FAILED"; exit(); } - - if (!empty($tz)) - { - $tzone = $tz['tz']; - break; - } - - } - } + $tzone = $tz; + break; + } } @@ -356,5 +332,41 @@ function import_file($file, $description, $fields, $firstrow = 2) } +/** + * Get the timezone given the sample value and type + * + * @param string $value A sample value + * @param integer $type The type of sample var (see sample_var_type table) + * + * @return string|bool Return the timezone name or false if not found + */ +function get_time_zone($value,$type) +{ + global $db; + + $sql = "SELECT `table` + FROM sample_var_type + WHERE type = '$type'"; + + $tname = $db->GetOne($sql); + + if (!empty($tname)) + { + $value = $db->Quote($value); + + $sql = "SELECT Time_zone_name as tz + FROM `$tname` + WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )"; + + $tz = $db->GetOne($sql); + + if (!empty($tz)) + { + return $tz; + } + } + return false; +} + ?> From d9ba5d6e9545eb440a816ec735b0d0b20ad9aa08 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Sep 2013 14:25:15 +1000 Subject: [PATCH 3/6] Separated add_case from get_case_id function --- functions/functions.operator.php | 196 +++++++++++++++++-------------- 1 file changed, 108 insertions(+), 88 deletions(-) diff --git a/functions/functions.operator.php b/functions/functions.operator.php index f0776329..ead1f671 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -337,6 +337,112 @@ function is_respondent_selection($operator_id) return false; } +/** + * Add a case to the system based on a sample record + * + * @param int $sample_id The sample id + * @param int $questionnaire_id The questionnaire id + * @param int $operator_id The operator id (Default NULL) + * @param int $testing 0 if a live case otherwise 1 for a testing case + * + * @return int The case id + */ +function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = 0) +{ + global $db; + + $token = sRandomChars(); + + $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, 1, '$token')"; + + $db->Execute($sql); + + $case_id = $db->Insert_ID(); + + //if this sample is set as testing, assign internal numbers as numbers + if ($testing == 1) + { + $db->Execute("SET @row := 0"); + + $sql = "INSERT INTO contact_phone (case_id,priority,phone,description) + SELECT $case_id as case_id,@row := @row + 1 AS priority,SUBSTRING_INDEX(extension,'/',-1) as phone, CONCAT(firstName, ' ', lastName) + FROM operator + WHERE enabled = 1"; + + $db->Execute($sql); + } + else + { + //add any phone numbers to contact phone + + //$db->Execute("SET @row := 0"); + + $sql = "SELECT val as phone + FROM sample_var + WHERE sample_id = '$sample_id' + AND val is NOT NULL + AND val != \"\" + AND (`type` = 2 or `type` = 3) + ORDER BY `type` DESC"; + + $r5 = $db->GetAll($sql); + + if (!empty($r5)) + { + $i = 1; + foreach ($r5 as $r5v) + { + $tnum = preg_replace("/[^0-9]/", "",$r5v['phone']); + if (empty($tnum)) $tnum = "312345678"; //handle error condition + $sql = "INSERT INTO contact_phone (case_id,priority,phone,description) + VALUES ($case_id,$i,$tnum,'')"; + $db->Execute($sql); + $i++; + } + } + else + { + $sql = "INSERT INTO contact_phone (case_id,priority,phone,description) + VALUES ($case_id,1,312345678,'test only')"; + $db->Execute($sql); + } + + } + + //add respondent details to respondent (if such details exist in the sample) + + $sql = "INSERT INTO respondent (case_id,firstName,lastName,Time_zone_name) + SELECT $case_id as case_id, IFNULL(s1.val,'') as firstName, IFNULL(s2.val,'') as lastName, s3.Time_zone_name as Time_zone_name + FROM sample as s3 + LEFT JOIN sample_var as s2 on (s2.sample_id = '$sample_id' and s2.type = 7) + LEFT JOIN sample_var as s1 on (s1.sample_id = '$sample_id' and s1.type = 6) + WHERE s3.sample_id = '$sample_id'"; + + $db->Execute($sql); + + + //add resopndent to Lime Survey token table for this questionnaire + + //first we need to get the limesurvey survey id + + if (!$db->HasFailedTrans()) //if the transaction hasn't failed + { + $lime_sid = get_limesurvey_id($operator_id); + + if ($lime_sid) + { + $sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,mpid) + VALUES (NULL,'','','','$token','".DEFAULT_LOCALE."','N','N',NULL)"; + + $db->Execute($sql); + } + } + + return $case_id; +} + + /** * Get the current or next case id * @@ -602,94 +708,8 @@ function get_case_id($operator_id, $create = false) if (!empty($r3)) { - $token = sRandomChars(); - - $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, {$r3['sample_id']}, {$r3['questionnaire_id']} , NULL, $operator_id, NULL, 1, '$token')"; - - $db->Execute($sql); - - $case_id = $db->Insert_ID(); - - //if this sample is set as testing, assign internal numbers as numbers - if ($r3['testing'] == 1) - { - $db->Execute("SET @row := 0"); - - $sql = "INSERT INTO contact_phone (case_id,priority,phone,description) - SELECT $case_id as case_id,@row := @row + 1 AS priority,SUBSTRING_INDEX(extension,'/',-1) as phone, CONCAT(firstName, ' ', lastName) - FROM operator - WHERE enabled = 1"; - - $db->Execute($sql); - } - else - { - //add any phone numbers to contact phone - - //$db->Execute("SET @row := 0"); - - $sql = "SELECT val as phone - FROM sample_var - WHERE sample_id = '{$r3['sample_id']}' - AND val is NOT NULL - AND val != \"\" - AND (`type` = 2 or `type` = 3) - ORDER BY `type` DESC"; - - $r5 = $db->GetAll($sql); - - if (!empty($r5)) - { - $i = 1; - foreach ($r5 as $r5v) - { - $tnum = preg_replace("/[^0-9]/", "",$r5v['phone']); - if (empty($tnum)) $tnum = "312345678"; //handle error condition - $sql = "INSERT INTO contact_phone (case_id,priority,phone,description) - VALUES ($case_id,$i,$tnum,'')"; - $db->Execute($sql); - $i++; - } - } - else - { - $sql = "INSERT INTO contact_phone (case_id,priority,phone,description) - VALUES ($case_id,1,312345678,'test only')"; - $db->Execute($sql); - } - - } - - //add respondent details to respondent (if such details exist in the sample) - - $sql = "INSERT INTO respondent (case_id,firstName,lastName,Time_zone_name) - SELECT $case_id as case_id, IFNULL(s1.val,'') as firstName, IFNULL(s2.val,'') as lastName, s3.Time_zone_name as Time_zone_name - FROM sample as s3 - LEFT JOIN sample_var as s2 on (s2.sample_id = '{$r3['sample_id']}' and s2.type = 7) - LEFT JOIN sample_var as s1 on (s1.sample_id = '{$r3['sample_id']}' and s1.type = 6) - WHERE s3.sample_id = '{$r3['sample_id']}'"; - - $db->Execute($sql); - - - //add resopndent to Lime Survey token table for this questionnaire - - //first we need to get the limesurvey survey id - - if (!$db->HasFailedTrans()) //if the transaction hasn't failed - { - $lime_sid = get_limesurvey_id($operator_id); - - if ($lime_sid) - { - $sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,mpid) - VALUES (NULL,'','','','$token','".DEFAULT_LOCALE."','N','N',NULL)"; - - $db->Execute($sql); - } - } - } + $case_id = add_case($r3['sample_id'],$r3['questionnaire_id'],$operator_id,$r3['testing']); + } } else { From a4942630c40025cb74fc55ca2cc9daead1f598f7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Sep 2013 14:59:07 +1000 Subject: [PATCH 4/6] Select the match for timezone with the most digits --- functions/functions.import.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/functions.import.php b/functions/functions.import.php index 817c8efd..92fe97cb 100644 --- a/functions/functions.import.php +++ b/functions/functions.import.php @@ -356,7 +356,8 @@ function get_time_zone($value,$type) $sql = "SELECT Time_zone_name as tz FROM `$tname` - WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )"; + WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) ) + ORDER BY CHAR_LENGTH(val) DESC"; $tz = $db->GetOne($sql); From d23409f1101a1a0b97963df53d0fff16f3f40e08 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Sep 2013 14:59:42 +1000 Subject: [PATCH 5/6] Correctly get the limesurvey id --- functions/functions.operator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/functions/functions.operator.php b/functions/functions.operator.php index ead1f671..256709d5 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -428,7 +428,11 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = if (!$db->HasFailedTrans()) //if the transaction hasn't failed { - $lime_sid = get_limesurvey_id($operator_id); + $sql = "SELECT lime_sid + FROM questionnaire + WHERE questionnaire_id = '$questionnaire_id'"; + + $lime_sid = $db->GetOne($sql); if ($lime_sid) { From 98f246dd03276731e65c2257902eaecb6bdbb066 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Sep 2013 15:02:59 +1000 Subject: [PATCH 6/6] Added referral function (requires addition to database) --- CHANGELOG | 6 + admin/new.php | 7 +- admin/questionnairelist.php | 8 +- index.php | 7 +- index_interface2.php | 7 +- referral.php | 253 ++++++++++++++++++++++++++++++++++++ 6 files changed, 280 insertions(+), 8 deletions(-) create mode 100644 referral.php diff --git a/CHANGELOG b/CHANGELOG index 2efea6b0..08c85f58 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +New Feature: Accept case referrals + +Database updates: + +ALTER TABLE `questionnaire` ADD `referral` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `self_complete` + queXS 1.9.0 - Changes since 1.8.0 New Feature: Supervisor chat via XMPP/Jabber (allow interviewers to chat with a supervisor from the interviewer screen) diff --git a/admin/new.php b/admin/new.php index c6575d36..06185066 100644 --- a/admin/new.php +++ b/admin/new.php @@ -66,6 +66,7 @@ if (isset($_POST['import_file'])) $ras =0; $rws = 0; $testing = 0; + $referral = 0; $rs = 0; $lime_sid = 0; $respsc = 0; @@ -74,6 +75,7 @@ if (isset($_POST['import_file'])) if (isset($_POST['rws'])) $rws = 1; if (isset($_POST['testing'])) $testing = 1; if (isset($_POST['respsc'])) $respsc = 1; + if (isset($_POST['referral'])) $respsc = 1; if ($_POST['selectrs'] != "none") $rs = 1; $name = $db->qstr($_POST['description'],get_magic_quotes_gpc()); @@ -93,8 +95,8 @@ if (isset($_POST['import_file'])) $lime_rs_sid = bigintval($_POST['selectrs']); } - $sql = "INSERT INTO questionnaire (questionnaire_id,description,lime_sid,restrict_appointments_shifts,restrict_work_shifts,respondent_selection,rs_intro,rs_project_intro,rs_project_end,rs_callback,rs_answeringmachine,testing,lime_rs_sid,info,self_complete) - VALUES (NULL,$name,'$lime_sid','$ras','$rws','$rs',$rs_intro,$rs_project_intro,$rs_project_end,$rs_callback,$rs_answeringmachine,'$testing',$lime_rs_sid,$info,$respsc)"; + $sql = "INSERT INTO questionnaire (questionnaire_id,description,lime_sid,restrict_appointments_shifts,restrict_work_shifts,respondent_selection,rs_intro,rs_project_intro,rs_project_end,rs_callback,rs_answeringmachine,testing,lime_rs_sid,info,self_complete,referral) + VALUES (NULL,$name,'$lime_sid','$ras','$rws','$rs',$rs_intro,$rs_project_intro,$rs_project_end,$rs_callback,$rs_answeringmachine,'$testing',$lime_rs_sid,$info,$respsc,$referral)"; $rs = $db->Execute($sql); @@ -193,6 +195,7 @@ $ckeditorConfig = array("toolbar" => array(array("tokens","-","Source"),

+