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

Updated to trunk

This commit is contained in:
Adam Zammit
2015-09-02 14:42:05 +10:00
55 changed files with 3337 additions and 3357 deletions
+136 -22
View File
@@ -345,17 +345,19 @@ function is_respondent_selection($operator_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
* @param int $current_outcome_id The current outcome id (defaults to 1 - not attempted)
* @param bool $addlimeattributes If true, add sample values as lime attributes
*
* @return int The case id
*/
function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = 0)
function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = 0, $current_outcome_id = 1, $addlimeattributes = false)
{
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')";
VALUES (NULL, $sample_id, $questionnaire_id, NULL, $operator_id, NULL, '$current_outcome_id','$token')";
$db->Execute($sql);
@@ -440,10 +442,75 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
if ($lime_sid)
{
$lfirstname = '';
$llastname = '';
$lemail = '';
if ($addlimeattributes)
{
$lfirstname = $db->GetOne("SELECT sv.val
FROM sample_var as sv, sample_import_var_restrict as s
WHERE sv.var_id = s.var_id
AND sv.sample_id = '$sample_id'
AND s.type = '6'");
$llastname = $db->GetOne("SELECT sv.val
FROM sample_var as sv, sample_import_var_restrict as s
WHERE sv.var_id = s.var_id
AND sv.sample_id = '$sample_id'
AND s.type = '7'");
$lemail = $db->GetOne("SELECT sv.val
FROM sample_var as sv, sample_import_var_restrict as s
WHERE sv.var_id = s.var_id
AND sv.sample_id = '$sample_id'
AND s.type = '8'");
}
$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)";
VALUES (NULL,'$lfirstname','$llastname','$lemail','$token','".DEFAULT_LOCALE."','N','N',NULL)";
$db->Execute($sql);
$tid = $db->Insert_Id();
if ($addlimeattributes)
{
//also add sample values as attributes
//match by name
$sql = "SELECT attributedescriptions
FROM " . LIME_PREFIX . "surveys
WHERE sid = '$lime_sid'";
$names = $db->GetOne($sql);
$attdescriptiondata=explode("\n",$names);
$atts=array();
foreach ($attdescriptiondata as $attdescription)
{
if (!empty($attdescription))
$atts['attribute_'.substr($attdescription,10,strpos($attdescription,'=')-10)] = substr($attdescription,strpos($attdescription,'=')+1);
}
foreach($atts as $key => $val)
{
$lval = $db->GetOne("SELECT sv.val
FROM sample_var as sv, sample_import_var_restrict as s
WHERE sv.var_id = s.var_id
AND sv.sample_id = '$sample_id'
AND s.var LIKE '$val'");
$sql = "UPDATE " . LIME_PREFIX . "tokens_$lime_sid
SET $key = '$lval'
WHERE tid = '$tid'";
$db->Execute($sql);
}
}
}
}
@@ -2104,9 +2171,9 @@ function end_case($operator_id)
$lastcall = 0;
if (!empty($l))
$lastcall = $l['call_id'];
if ($count == 0) //no numbers to be tried again, get last outcome or 1
if ($count == 0) //no numbers to be tried again, get last outcome or 1
{
//last call
$sql = "SELECT c.outcome_id as outcome_id
@@ -2124,23 +2191,70 @@ function end_case($operator_id)
$outcome = $t['outcome_id'];
}
}
else if ($count >= 1) //one or more numbers to be tried again - first code as eligible if ever eligible...
{
//$r[0]['contact_phone_id'];
//code as eligible if ever eligible, or if referred to the supervisor, code as that if last call
$sql = "SELECT c.outcome_id as outcome_id
FROM `call` as c
JOIN outcome AS o ON ( c.outcome_id = o.outcome_id AND (o.eligible = 1 OR o.outcome_type_id = 2 OR o.outcome_type_id = 1) )
WHERE c.case_id = '$case_id'
ORDER BY c.call_id DESC";
$t = $db->GetRow($sql);
else if ($count >= 1) //one or more numbers to be tried again - see if max calls reached, then code as eligible if ever eligible...
{
$sql = "SELECT call_attempt_max,call_max
FROM questionnaire_sample as qs, `case` as c, sample as s
WHERE c.case_id = '$case_id'
AND c.sample_id = s.sample_id
AND qs.sample_import_id = s.import_id
AND qs.questionnaire_id = c.questionnaire_id";
$cm = $db->GetRow($sql);
$sql = "SELECT COUNT(*) as c
FROM call_attempt
WHERE case_id = '$case_id'";
if (!empty($t))
$outcome = $t['outcome_id'];
}
}
else
$callattempts = $db->GetOne($sql);
$sql = "SELECT COUNT(*) as c
FROM `call`
WHERE case_id = '$case_id'";
$calls = $db->GetOne($sql);
$eligsql = "SELECT count(*)
FROM `call` as c, `outcome` as o
WHERE c.outcome_id = o.outcome_id
AND o.eligible = 1
AND c.case_id = '$case_id'";
if ($cm['call_attempt_max'] > 0 && $callattempts >= $cm['call_attempt_max']) //max call attempts reached
{
//if ever eligible, code as eligible
if ($db->GetOne($eligsql) > 0)
$outcome = 44;
else
$outcome = 42;
}
else if ($cm['call_max'] > 0 && $calls >= $cm['call_max']) //max calls reached
{
//if ever eligible, code as eligible
if ($db->GetOne($eligsql) > 0)
$outcome = 45;
else
$outcome = 43;
}
else
{
//$r[0]['contact_phone_id'];
//code as eligible if ever eligible, or if referred to the supervisor, code as that if last call
$sql = "SELECT c.outcome_id as outcome_id
FROM `call` as c
JOIN outcome AS o ON ( c.outcome_id = o.outcome_id AND (o.eligible = 1 OR o.outcome_type_id = 2 OR o.outcome_type_id = 1) )
WHERE c.case_id = '$case_id'
ORDER BY c.call_id DESC";
$t = $db->GetRow($sql);
if (!empty($t))
$outcome = $t['outcome_id'];
}
}
}
else
{
//the last call is the call with the final otucome
$outcome = $a['outcome_id'];