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

Removed references to LIME from functions.operator

This commit is contained in:
Adam Zammit
2017-02-07 12:00:49 +11:00
parent aba4fa0804
commit efaaee6d0a
3 changed files with 79 additions and 90 deletions

View File

@@ -71,15 +71,13 @@ function limerpc_init ($url,$user,$pass)
return true; return true;
} }
function get_token_value($questionnaire_id,$token, $value = 'sent') function limerpc_init_qid($qid)
{ {
global $limeRPC;
global $limeKey;
global $db; global $db;
$sql = "SELECT r.rpc_url, r.username, r.password, r.description, q.lime_id $sql = "SELECT r.rpc_url, r.username, r.password, r.description, q.lime_id
FROM remote as r, questionnaire as q FROM remote as r, questionnaire as q
WHERE q.questoinnaire_d = '$questionnaire_id' WHERE q.questoinnaire_d = '$qid'
AND q.remote_id = r.id"; AND q.remote_id = r.id";
$r = $db->GetRow($sql); $r = $db->GetRow($sql);
@@ -87,8 +85,43 @@ function get_token_value($questionnaire_id,$token, $value = 'sent')
$ret = false; $ret = false;
if (limerpc_init($r['rpc_url'],$r['username'],$r['password']) === true) { if (limerpc_init($r['rpc_url'],$r['username'],$r['password']) === true) {
$l = $limeRPC->get_participant_properties($limeKey,$r['lime_id'],array('token'=>$token),array($value)); return $r['lime_id'];
if (isset($l[$value]) { }
return false;
}
function lime_add_token($qid,$params)
{
global $limeKey;
global $limeRPC;
$ret = false;
$lime_id = limerpc_init_qid($qid);
if ($lime_id !== false) {
$l = $limeRPC->add_participants($limeKey,$lime_id,$params,false); //don't create token
if (!isset($l['status'])) {
$ret = $l; //array of data
}
}
return $ret;
}
function get_token_value($questionnaire_id,$token, $value = 'sent')
{
global $limeKey;
global $limeRPC;
$ret = false;
$lime_id = limerpc_init_qid($qid);
if ($lime_id !== false) {
$l = $limeRPC->get_participant_properties($limeKey,$lime_id,array('token'=>$token),array($value));
if (isset($l[$value])) {
$ret= $l[$value]; $ret= $l[$value];
} }
} }

View File

@@ -461,52 +461,18 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
//include limesurvey functions //include limesurvey functions
include_once(dirname(__FILE__).'/functions.limesurvey.php'); include_once(dirname(__FILE__).'/functions.limesurvey.php');
$ret = lime_add_token($questionnaire_id,array( 'firstname' => $lfirstname,
'lastname' => $llastname,
'email' => $lemail,
'token' => $token));
//fail to create case if can't add remote token
$sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,mpid) if ($ret === false)
VALUES (NULL,$lfirstname,$llastname,$lemail,'$token','".DEFAULT_LOCALE."','N','N',NULL)"; $db->FailTrans();
$db->Execute($sql);
$tid = $db->Insert_Id();
if ($addlimeattributes) if ($addlimeattributes)
{ {
//also add sample values as attributes //TODO: Add attributes from sample
//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'");
$lval = $db->qstr($lval);
$sql = "UPDATE " . LIME_PREFIX . "tokens_$lime_sid
SET $key = $lval
WHERE tid = '$tid'";
$db->Execute($sql);
}
} }
} }
} }
@@ -1245,19 +1211,7 @@ function get_call($operator_id,$respondent_id = "",$contact_phone_id = "",$creat
$db->Execute($sql); $db->Execute($sql);
$id = $db->Insert_Id(); $id = $db->Insert_Id();
//If respondent selection is enabled, add token to RS Limesurvey database //disable respondent selection instrument
$lime_rsid = is_respondent_selection($operator_id);
if ($lime_rsid !== true && $lime_rsid > 0 && !$db->HasFailedTrans())
//if the transaction hasn't failed and Limesurvey RS is enabled
{
$sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_rsid (tid,firstname,lastname,email,token,language,sent,completed,mpid)
VALUES (NULL,'','','',$id,'en','N','N',NULL)";
//Insert the token as the call_id
$db->Execute($sql);
}
} }
else else
{ {
@@ -1304,13 +1258,6 @@ function get_respondentselection_url($operator_id,$escape = true,$interface2 = f
if ($call_id) if ($call_id)
{ {
$sid = get_limesurvey_id($operator_id,true); //true for RS
if ($sid != false && !empty($sid) && $sid != 'NULL')
{
$url = LIME_URL . "index.php?interviewer=interviewer" . $amp . "loadall=reload" . $amp . "sid=$sid" . $amp . "token=$call_id" . $amp . "lang=" . DEFAULT_LOCALE;
}
else
{
if (is_respondent_selection($operator_id) === false) if (is_respondent_selection($operator_id) === false)
{ {
$url = get_limesurvey_url($operator_id); $url = get_limesurvey_url($operator_id);
@@ -1321,7 +1268,6 @@ function get_respondentselection_url($operator_id,$escape = true,$interface2 = f
{ {
$url = 'rs_intro.php'; $url = 'rs_intro.php';
} }
}
} }
//if ($db->HasFailedTrans()) { print "FAILED in get_limesurvey_url"; exit; } //if ($db->HasFailedTrans()) { print "FAILED in get_limesurvey_url"; exit; }
@@ -1357,7 +1303,7 @@ function get_limesurvey_url($operator_id)
$token = $db->GetOne($sql); $token = $db->GetOne($sql);
$sid = get_limesurvey_id($operator_id); $sid = get_limesurvey_id($operator_id);
$url = LIME_URL . "index.php?interviewer=interviewer&loadall=reload&sid=$sid&token=$token&lang=" . DEFAULT_LOCALE; $url = get_lime_url($case_id) . "/sid/$sid/token/$token/lang/" . DEFAULT_LOCALE;
$questionnaire_id = get_questionnaire_id($operator_id); $questionnaire_id = get_questionnaire_id($operator_id);
//get prefills //get prefills
@@ -1370,7 +1316,7 @@ function get_limesurvey_url($operator_id)
if (!empty($pf)) if (!empty($pf))
{ {
foreach ($pf as $p) foreach ($pf as $p)
$url .= "&" . $p['lime_sgqa'] . "=" . template_replace($p['value'],$operator_id,$case_id); $url .= "/" . $p['lime_sgqa'] . "/" . template_replace($p['value'],$operator_id,$case_id);
} }
} }
@@ -1794,8 +1740,7 @@ function update_single_row_quota($qsqri,$case_id = false)
{ {
//just determine if this case is linked to a matching sample record //just determine if this case is linked to a matching sample record
$sql2 = "SELECT count(*) as c $sql2 = "SELECT count(*) as c
FROM " . LIME_PREFIX . "survey_$lime_sid as s FROM `case` as c
JOIN `case` as c ON (c.case_id = '$case_id')
JOIN `sample` as sam ON (c.sample_id = sam.sample_id) "; JOIN `sample` as sam ON (c.sample_id = sam.sample_id) ";
$x = 1; $x = 1;
@@ -1805,7 +1750,7 @@ function update_single_row_quota($qsqri,$case_id = false)
$x++; $x++;
} }
$sql2 .= " WHERE s.token = c.token"; $sql2 .= " WHERE c.case_id = '$case_id'";
$match = $db->GetOne($sql2); $match = $db->GetOne($sql2);
} }
@@ -1813,14 +1758,20 @@ function update_single_row_quota($qsqri,$case_id = false)
{ {
//determine if the case is linked to a matching limesurvey record //determine if the case is linked to a matching limesurvey record
$sql2 = "SELECT count(*) as c $sql2 = "SELECT count(*) as c
FROM " . LIME_PREFIX . "survey_$lime_sid as s FROM `case` as c
JOIN `case` as c ON (c.case_id = '$case_id')
JOIN `sample` as sam ON (c.sample_id = sam.sample_id) JOIN `sample` as sam ON (c.sample_id = sam.sample_id)
WHERE s.token = c.token WHERE c.case_id = '$case_id'
"; ";
include_once(dirname(__FILE__).'/functions.limesurvey.php');
//get response data from Limesurvey
$resp = lime_get_responses_by_case($case_id);
foreach($qev as $ev) foreach($qev as $ev)
$sql2 .= " AND s.`{$ev['lime_sgqa']}` {$ev['comparison']} '{$ev['value']}' "; {
$sql2 .= " AND '" . $resp[$ev['lime_sgqa']] . " ' {$ev['comparison']} '{$ev['value']}' ";
}
$match = $db->GetOne($sql2); $match = $db->GetOne($sql2);
} }
@@ -1845,8 +1796,7 @@ function update_single_row_quota($qsqri,$case_id = false)
//find all completions from cases with matching sample records //find all completions from cases with matching sample records
$sql2 = "SELECT count(*) as c $sql2 = "SELECT count(*) as c
FROM " . LIME_PREFIX . "survey_$lime_sid as s FROM `case` as c
JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id')
JOIN `sample` as sam ON (c.sample_id = sam.sample_id AND sam.import_id = '$sample_import_id')"; JOIN `sample` as sam ON (c.sample_id = sam.sample_id AND sam.import_id = '$sample_import_id')";
$x = 1; $x = 1;
@@ -1856,25 +1806,32 @@ function update_single_row_quota($qsqri,$case_id = false)
$x++; $x++;
} }
$sql2 .= " WHERE s.submitdate IS NOT NULL $sql2 .= " WHERE c.questionnaire_id = '$questionnaire_id'
AND s.token = c.token"; AND c.current_outcome_id = 10"; //check completions by outcome
$completions = $db->GetOne($sql2); $completions = $db->GetOne($sql2);
} }
else else
{ {
//find all completions from cases with matching limesurvey records //find all completions from cases with matching limesurvey records
$sql2 = "SELECT count(*) as c $sql2 = "SELECT token
FROM " . LIME_PREFIX . "survey_$lime_sid as s FROM `case` as c
JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id') WHERE c.questionnaire_id = '$questionnaire_id'";
JOIN `sample` as sam ON (c.sample_id = sam.sample_id AND sam.import_id = '$sample_import_id')
WHERE s.submitdate IS NOT NULL //get all completed responses from limesurvey, indexed by token
AND s.token = c.token ";
include_once(dirname(__FILE__).'/functions.limesurvey.php');
$resp = lime_get_responses_by_questionnaire($questionnaire_id);
foreach($qev as $ev) foreach($qev as $ev)
{
//TODO: Exclude responses from the $resp array where there isn't a match
//based on the comparisons
$sql2 .= " AND s.`{$ev['lime_sgqa']}` {$ev['comparison']} '{$ev['value']}' "; $sql2 .= " AND s.`{$ev['lime_sgqa']}` {$ev['comparison']} '{$ev['value']}' ";
}
$completions = $db->GetOne($sql2);
$completions = count($resp);
} }
$updatequota = true; $updatequota = true;

View File

@@ -33,7 +33,6 @@ $maxLoginAttempt = 10;
$timeOutTime = 600; // 10 minutes $timeOutTime = 600; // 10 minutes
// sanitize a username // sanitize a username
// TODO: define the exact format of the username
// allow for instance 0-9a-zA-Z@_-. // allow for instance 0-9a-zA-Z@_-.
function sanitize_user($string) function sanitize_user($string)
{ {