mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
New feature: Seperate limesurvey instrument for respondent selection
Dev Merged back changes from mcmasterlimers branch
This commit is contained in:
@@ -308,7 +308,7 @@ function spss_fieldmap($prefix = 'V') {
|
||||
foreach ($tokenattributes as $attributefield=>$attributedescription)
|
||||
{
|
||||
//Drop the token field, since it is in the survey too
|
||||
if($attributefield!='token') {
|
||||
if($attributefield!='token' && $attributefield!='callattempts' && $attributefield!='onappointment') { //queXS Addition
|
||||
$fieldno++;
|
||||
$fields[] = array('id'=>"$prefix$fieldno",'name'=>mb_substr($attributefield, 0, 8),
|
||||
'qid'=>0,'code'=>'','SPSStype'=>'A','LStype'=>'Undef',
|
||||
@@ -431,7 +431,7 @@ function spss_getquery() {
|
||||
$tokenattributes=GetTokenFieldsAndNames($surveyid,false);
|
||||
foreach ($tokenattributes as $attributefield=>$attributedescription) {
|
||||
//Drop the token field, since it is in the survey too
|
||||
if($attributefield!='token') {
|
||||
if($attributefield!='token' && $attributefield!='callattempts' && $attributefield!='onappointment') { //queXS Addition
|
||||
$query .= "{$dbprefix}tokens_$surveyid.$attributefield, ";
|
||||
}
|
||||
}
|
||||
@@ -454,4 +454,4 @@ function spss_getquery() {
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -1282,6 +1282,8 @@ if ($countquota > 0 && (!isset($countquotals) || $countquotals == 0)) {
|
||||
|
||||
if (isset($conditionsarray) && $conditionsarray) {//ONLY DO THIS IF THERE ARE CONDITIONS!
|
||||
$count='0';
|
||||
|
||||
|
||||
foreach ($conditionsarray as $car) {
|
||||
if ($importversion>=111)
|
||||
{
|
||||
@@ -1296,7 +1298,7 @@ if (isset($conditionsarray) && $conditionsarray) {//ONLY DO THIS IF THERE ARE CO
|
||||
}
|
||||
$conditionrowdata=array_combine($fieldorders,$fieldcontents);
|
||||
|
||||
$oldcid=$conditionrowdata["cid"];
|
||||
$oldcid=$conditionrowdata["cid"];
|
||||
$oldqid=$conditionrowdata["qid"];
|
||||
$oldcfieldname=$conditionrowdata["cfieldname"];
|
||||
$oldcqid=$conditionrowdata["cqid"];
|
||||
@@ -1321,7 +1323,11 @@ if (isset($conditionsarray) && $conditionsarray) {//ONLY DO THIS IF THERE ARE CO
|
||||
}
|
||||
foreach($fieldnames as $fns) {
|
||||
//if the $fns['oldcfieldname'] is not the same as $fns['oldfieldname'] then this is a multiple type question
|
||||
if ($fns['oldcfieldname'] == $fns['oldfieldname']) { //The normal method - non multiples
|
||||
if (stripos($oldcfieldname,'TOKEN') !== false) //detecting tokens
|
||||
{
|
||||
$newcfieldname = $oldcfieldname;
|
||||
}
|
||||
else if ($fns['oldcfieldname'] == $fns['oldfieldname']) { //The normal method - non multiples
|
||||
if ($oldcfieldname==$fns['oldcfieldname']) {
|
||||
$newcfieldname=$fns['newcfieldname'];
|
||||
}
|
||||
@@ -1332,6 +1338,7 @@ if (isset($conditionsarray) && $conditionsarray) {//ONLY DO THIS IF THERE ARE CO
|
||||
}
|
||||
}
|
||||
if (!isset($newcfieldname)) {$newcfieldname="";}
|
||||
|
||||
unset($conditionrowdata["cid"]);
|
||||
$conditionrowdata["qid"]=$newqid;
|
||||
$conditionrowdata["cfieldname"]=$newcfieldname;
|
||||
|
||||
@@ -3530,6 +3530,7 @@ function getHeader()
|
||||
{
|
||||
global $embedded, $surveyid, $rooturl,$defaultlang, $js_header_includes, $css_header_includes;
|
||||
|
||||
$js_header_includes[] = '/../../js/popup.js'; //queXS addition
|
||||
$js_header_includes = array_unique($js_header_includes);
|
||||
$css_header_includes = array_unique($css_header_includes);
|
||||
|
||||
@@ -6149,6 +6150,8 @@ function GetTokenConditionsFieldNames($surveyid)
|
||||
{
|
||||
$extra_attrs=GetAttributeFieldNames($surveyid);
|
||||
$basic_attrs=Array('firstname','lastname','email','token','language','sent','remindersent','remindercount');
|
||||
$basic_attrs[] = 'callattempts'; //queXS addition
|
||||
$basic_attrs[] = 'onappointment'; //queXS addition
|
||||
return array_merge($basic_attrs,$extra_attrs);
|
||||
}
|
||||
|
||||
@@ -6167,6 +6170,8 @@ function GetTokenFieldsAndNames($surveyid, $onlyAttributes=false)
|
||||
}
|
||||
$extra_attrs=GetAttributeFieldNames($surveyid);
|
||||
$basic_attrs=Array('firstname','lastname','email','token','language','sent','remindersent','remindercount');
|
||||
$basic_attrs[] = 'callattempts'; //queXS addition
|
||||
$basic_attrs[] = 'onappointment'; //queXS addition
|
||||
$basic_attrs_names=Array(
|
||||
$clang->gT('First Name'),
|
||||
$clang->gT('Last Name'),
|
||||
@@ -6177,6 +6182,9 @@ function GetTokenFieldsAndNames($surveyid, $onlyAttributes=false)
|
||||
$clang->gT('Last Reminder sent date'),
|
||||
$clang->gT('Total numbers of sent reminders'));
|
||||
|
||||
$basic_attrs_names[] = $clang->gT('queXS: Number of call attempts'); //queXS addition
|
||||
$basic_attrs_names[] = $clang->gT('queXS: On appointment?'); //queXS addition
|
||||
|
||||
$thissurvey=getSurveyInfo($surveyid);
|
||||
$attdescriptiondata=!empty($thissurvey['attributedescriptions']) ? $thissurvey['attributedescriptions'] : "";
|
||||
$attdescriptiondata=explode("\n",$attdescriptiondata);
|
||||
@@ -6228,6 +6236,22 @@ function GetAttributeValue($surveyid,$attrName,$token)
|
||||
$sanitized_token=$connect->qstr($token,get_magic_quotes_gpc());
|
||||
$surveyid=sanitize_int($surveyid);
|
||||
|
||||
if ($attrName == 'callattempts' || $attrName == 'onappointment') //queXS addition
|
||||
{
|
||||
include_once("quexs.php");
|
||||
$quexs_operator_id = get_operator_id();
|
||||
$quexs_case_id = get_case_id($quexs_operator_id);
|
||||
if ($quexs_case_id)
|
||||
{
|
||||
if ($attrName == 'callattempts')
|
||||
return get_call_attempts($quexs_case_id);
|
||||
else if ($attrName == 'onappointment')
|
||||
return is_on_appointment($quexs_case_id,$quexs_operator_id);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
$query="SELECT $attrName FROM {$dbprefix}tokens_$surveyid WHERE token=$sanitized_token";
|
||||
$result=db_execute_num($query);
|
||||
$count=$result->RecordCount();
|
||||
|
||||
@@ -227,6 +227,13 @@ if ((isset($move) && $move == "movesubmit") && (!isset($notanswered) || !$notan
|
||||
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL
|
||||
$url=str_replace("{LANG}", $clang->getlangcode(), $url); // to activate the LANG in the END URL
|
||||
|
||||
//queXS Addition
|
||||
include_once("quexs.php");
|
||||
$quexs_url = get_start_interview_url();
|
||||
$url = str_replace("{STARTINTERVIEWURL}", $quexs_url, $url);
|
||||
|
||||
|
||||
|
||||
header("Location: {$url}");
|
||||
|
||||
}
|
||||
|
||||
@@ -961,11 +961,11 @@ function quexs_submit_on_click($do = true)
|
||||
{
|
||||
include_once(dirname(__FILE__) . '/quexs.php');
|
||||
|
||||
$r = "";
|
||||
$r = "; $('.submit').css('display', ''); ";
|
||||
|
||||
if (LIME_AUTO_ADVANCE && $do)
|
||||
{
|
||||
$r = "; document.limesurvey.move.value = '";
|
||||
$r .= " document.limesurvey.move.value = '";
|
||||
if (isset($_SESSION['step']) && $_SESSION['step'] && ($_SESSION['step'] == $_SESSION['totalsteps']))
|
||||
$r .= "movesubmit";
|
||||
else
|
||||
@@ -976,6 +976,35 @@ function quexs_submit_on_click($do = true)
|
||||
return $r;
|
||||
}
|
||||
|
||||
function quexs_appointment($do)
|
||||
{
|
||||
include_once(dirname(__FILE__) . '/quexs.php');
|
||||
|
||||
$r = "";
|
||||
|
||||
if ($do)
|
||||
{
|
||||
$r = "; $('.submit').css('display', 'none'); parent.poptastic('" . QUEXS_URL . "appointment.php'); ";
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
function quexs_outcome($outcome)
|
||||
{
|
||||
include_once(dirname(__FILE__) . '/quexs.php');
|
||||
|
||||
$r = "";
|
||||
|
||||
if (is_numeric($outcome) && $outcome != 0)
|
||||
{
|
||||
$r = "; $('.submit').css('display', 'none'); parent.poptastic('" . QUEXS_URL . "call.php?defaultoutcome=$outcome'); ";
|
||||
}
|
||||
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function do_boilerplate($ia)
|
||||
{
|
||||
@@ -2006,7 +2035,31 @@ function do_list_flexible_radio($ia)
|
||||
{
|
||||
$check_ans ='';
|
||||
};
|
||||
$answer .= $wrapper['item-start'].' <input class="radio" type="radio" value="'.$ansrow['code'].'" name="'.$ia[1].'" id="answer'.$ia[1].$ansrow['code'].'"'.$check_ans.' onclick="if (document.getElementById(\'answer'.$ia[1].'othertext\') != null) document.getElementById(\'answer'.$ia[1].'othertext\').value=\'\';checkconditions(this.value, this.name, this.type)'.quexs_submit_on_click().'" />
|
||||
|
||||
//queXS check if this is designed to set an outcome:
|
||||
$quexs_outcome = false;
|
||||
$quexs_outcome_code = 0;
|
||||
if (strncasecmp($ansrow['title'],"{OUTCOME:",9) == 0)
|
||||
{
|
||||
$quexs_pos = strrpos($ansrow['title'],"}",8);
|
||||
if ($quexs_pos != false)
|
||||
{
|
||||
$quexs_outcome_code = substr($ansrow['title'],9,$quexs_pos - 9);
|
||||
$quexs_outcome = true;
|
||||
include_once(dirname(__FILE__) . '/quexs.php');
|
||||
$ansrow['title'] = quexs_template_replace($ansrow['title']);
|
||||
}
|
||||
}
|
||||
|
||||
//queXS check if this is designed to schedule an appointment:
|
||||
$quexs_appointment = false;
|
||||
if (strncasecmp($ansrow['title'],"{SCHEDULEAPPOINTMENT}",21) == 0)
|
||||
{
|
||||
$ansrow['title'] = $clang->gT("Schedule Appointment");
|
||||
$quexs_appointment = true;
|
||||
}
|
||||
|
||||
$answer .= $wrapper['item-start'].' <input class="radio" type="radio" value="'.$ansrow['code'].'" name="'.$ia[1].'" id="answer'.$ia[1].$ansrow['code'].'"'.$check_ans.' onclick="if (document.getElementById(\'answer'.$ia[1].'othertext\') != null) document.getElementById(\'answer'.$ia[1].'othertext\').value=\'\';checkconditions(this.value, this.name, this.type)'.quexs_submit_on_click(!$quexs_outcome && !$quexs_appointment).quexs_outcome($quexs_outcome_code).quexs_appointment($quexs_appointment).'" />
|
||||
<label for="answer'.$ia[1].$ansrow['code'].'" class="answertext">'.$ansrow['title'].'</label>
|
||||
'.$wrapper['item-end'];
|
||||
|
||||
@@ -3302,6 +3355,23 @@ function do_multipleshorttext($ia)
|
||||
{
|
||||
$myfname = $ia[1].$ansrow['code'];
|
||||
if ($ansrow['answer'] == "") {$ansrow['answer'] = " ";}
|
||||
|
||||
$quexs_answer = false;
|
||||
|
||||
if (strncasecmp($ansrow['answer'],"{SAMPLEUPDATE:",14) == 0) //queXS Addition
|
||||
{
|
||||
$ansrow['answer'] = substr($ansrow['answer'],14,-1); //remove token text
|
||||
include_once('quexs.php');
|
||||
$quexs_operator_id = get_operator_id();
|
||||
$quexs_case_id = get_case_id($quexs_operator_id);
|
||||
if ($quexs_case_id)
|
||||
{
|
||||
$quexs_answer = get_sample_variable($ansrow['answer'],$quexs_case_id);
|
||||
$tiwidth = strlen($quexs_answer) + 5;
|
||||
$maxsize = $tiwidth + 255;
|
||||
}
|
||||
}
|
||||
|
||||
$answer_main .= "\t<li>\n"
|
||||
. "\t\t<label for=\"answer$myfname\">{$ansrow['answer']}</label>\n"
|
||||
. "\t\t\t<span>\n\t\t\t\t".$prefix."\n\t\t\t\t".'<input class="text" type="text" size="'.$tiwidth.'" name="'.$myfname.'" id="answer'.$myfname.'" value="';
|
||||
@@ -3311,7 +3381,11 @@ function do_multipleshorttext($ia)
|
||||
$label_width = strlen(trim(strip_tags($ansrow['answer'])));
|
||||
}
|
||||
|
||||
if (isset($_SESSION[$myfname]))
|
||||
if ($quexs_answer !== false)
|
||||
{
|
||||
$answer_main .= $quexs_answer;
|
||||
}
|
||||
else if (isset($_SESSION[$myfname]))
|
||||
{
|
||||
$answer_main .= $_SESSION[$myfname];
|
||||
}
|
||||
|
||||
@@ -305,6 +305,11 @@ if ((isset($move) && $move == "movesubmit") && (!isset($notanswered) || !$notan
|
||||
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL
|
||||
$url=str_replace("{LANG}", $clang->getlangcode(), $url); // to activate the LANG in the END URL
|
||||
|
||||
//queXS Addition
|
||||
include_once("quexs.php");
|
||||
$quexs_url = get_start_interview_url();
|
||||
$url = str_replace("{STARTINTERVIEWURL}", $quexs_url, $url);
|
||||
|
||||
header("Location: {$url}");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,214 @@
|
||||
*/
|
||||
require_once(dirname(__FILE__).'/../../config.inc.php');
|
||||
|
||||
/**
|
||||
* Return the phone number of the latest appointment for this respondent
|
||||
*
|
||||
* @param int $respondent_id The respondent id
|
||||
* @return string The phone number
|
||||
*/
|
||||
function get_appointment_number($respondent_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
|
||||
$sql = "SELECT CONVERT_TZ(a.start,'UTC',r.Time_zone_name) as start, CONVERT_TZ(a.end,'UTC',r.Time_zone_name) as end, DATE(CONVERT_TZ(a.start,'UTC',r.Time_zone_name)) as startdate, c.phone
|
||||
FROM appointment as a
|
||||
JOIN (contact_phone as c, respondent as r) on (a.contact_phone_id = c.contact_phone_id AND r.respondent_id = '$respondent_id')
|
||||
WHERE a.respondent_id = '$respondent_id'
|
||||
ORDER BY a.appointment_id DESC";
|
||||
|
||||
$rs = $db->GetRow($sql); //Get the last one only
|
||||
|
||||
if (!empty($rs))
|
||||
return $rs['phone'];
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the time of the latest appointment for this respondent
|
||||
*
|
||||
* @param int $respondent_id The respondent id
|
||||
* @return string The time
|
||||
*/
|
||||
function get_appointment_time($respondent_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
|
||||
$sql = "SELECT DATE_FORMAT(CONVERT_TZ(a.start,'UTC',r.Time_zone_name),'".TIME_FORMAT."') as start
|
||||
FROM appointment as a
|
||||
JOIN (contact_phone as c, respondent as r) on (a.contact_phone_id = c.contact_phone_id AND r.respondent_id = '$respondent_id')
|
||||
WHERE a.respondent_id = '$respondent_id'
|
||||
ORDER BY a.appointment_id DESC";
|
||||
|
||||
$rs = $db->GetRow($sql); //Get the last one only
|
||||
|
||||
if (!empty($rs))
|
||||
return $rs['start'];
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the date of the latest appointment for this respondent
|
||||
*
|
||||
* @param int $respondent_id The respondent id
|
||||
* @return string The date
|
||||
*/
|
||||
function get_appointment_date($respondent_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
|
||||
$sql = "SELECT DATE_FORMAT(CONVERT_TZ(a.start,'UTC',r.Time_zone_name),'".DATE_FORMAT."') as startdate, c.phone
|
||||
FROM appointment as a
|
||||
JOIN (contact_phone as c, respondent as r) on (a.contact_phone_id = c.contact_phone_id AND r.respondent_id = '$respondent_id')
|
||||
WHERE a.respondent_id = '$respondent_id'
|
||||
ORDER BY a.appointment_id DESC";
|
||||
|
||||
$rs = $db->GetRow($sql); //Get the last one only
|
||||
|
||||
if (!empty($rs))
|
||||
return $rs['startdate'];
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the period of the day for the respondent
|
||||
*
|
||||
* @param int $respondent_id The respondent id
|
||||
* @return string Either morning, afternoon or evening based on the respondents time zone
|
||||
* @todo internationalise text : limesurvey or quexs?
|
||||
*
|
||||
*/
|
||||
function get_period_of_day($respondent_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
$sql = "SELECT HOUR(CONVERT_TZ(NOW(),'System',Time_zone_name)) as h
|
||||
FROM respondent
|
||||
WHERE respondent_id = '$respondent_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$hour = 10;
|
||||
if (!empty($rs))
|
||||
$hour = $rs['h'];
|
||||
|
||||
if ($hour < 12) return "morning";
|
||||
if ($hour < 17) return "afternoon";
|
||||
return "evening";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the sample record from data entered in limesurvey form
|
||||
*
|
||||
* @param int $lime_sid The limesurvey survey id
|
||||
* @param int $id The limesurvey record id of the data
|
||||
* @param array $postedfieldnames An array containing the fields that were just posted by limesurvey
|
||||
*
|
||||
*/
|
||||
function quexs_update_sample($lime_sid,$id,$postedfieldnames)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
//Search over the questionnaire database to find multiple short text responses which reference the sample
|
||||
$sql = "SELECT lq.sid,lq.gid,lq.qid,la.code,SUBSTR(la.answer,15,CHAR_LENGTH(la.answer)-15) as answer
|
||||
FROM `lime_questions` AS lq
|
||||
JOIN `lime_answers` AS la ON ( la.qid = lq.qid )
|
||||
WHERE lq.sid = '$lime_sid'
|
||||
AND lq.type = 'Q'
|
||||
AND (";
|
||||
|
||||
foreach($postedfieldnames as $pf) //restrict to only the ones just updated
|
||||
{
|
||||
$sql .= " CONCAT(lq.sid, 'X', lq.gid, 'X', lq.qid, la.code) LIKE '$pf' OR ";
|
||||
}
|
||||
|
||||
$sql = substr($sql,0,-4);
|
||||
$sql .= ") AND la.answer LIKE '{SAMPLEUPDATE:%'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
if (!empty($rs))
|
||||
{
|
||||
$operator_id = get_operator_id();
|
||||
$case_id = get_case_id($operator_id);
|
||||
|
||||
if ($case_id)
|
||||
{
|
||||
$sql = "SELECT sample_id
|
||||
FROM `case`
|
||||
WHERE case_id = '$case_id'";
|
||||
|
||||
$c = $db->GetRow($sql);
|
||||
|
||||
$sample_id = $c['sample_id'];
|
||||
|
||||
foreach($rs as $r) //Update the queXS sample database to reflect the updated data
|
||||
{
|
||||
$sgqa = $r['sid'] . 'X' . $r['gid'] . 'X' . $r['qid'] . $r['code'];
|
||||
$var = $r['answer'];
|
||||
|
||||
$sql = "UPDATE sample_var as sv, ".LIME_PREFIX."survey_$lime_sid as ld
|
||||
SET sv.val = ld.$sgqa
|
||||
WHERE sv.var LIKE '$var'
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND ld.id = '$id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of call attempts for this case
|
||||
*
|
||||
* @param $case_id The case id
|
||||
* @return int The number of call attempts
|
||||
*/
|
||||
function get_call_attempts($case_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
|
||||
$sql = "SELECT COUNT(call_attempt_id) AS c
|
||||
FROM call_attempt
|
||||
WHERE case_id = '$case_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
|
||||
if (empty($rs)) return "";
|
||||
|
||||
return $rs['c'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -66,6 +274,33 @@ function get_sample_variable($variable,$case_id)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the outcome code description
|
||||
*
|
||||
* @param string $variable The bit of information about the operator (eg firstName)
|
||||
* @param int $operator_id The operator id
|
||||
* @return string The information or a blank string if none found
|
||||
*
|
||||
*/
|
||||
function get_outcome_variable($variable)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
|
||||
$sql = "SELECT description as r
|
||||
FROM outcome
|
||||
WHERE outcome_id = '$variable'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if (empty($rs)) return "";
|
||||
|
||||
return $rs['r'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the operator
|
||||
*
|
||||
@@ -241,9 +476,171 @@ function quexs_template_replace($string)
|
||||
$string=str_replace($answreplace, $answreplace3, $string);
|
||||
}
|
||||
|
||||
while (stripos($string, "{Outcome:") !== false)
|
||||
{
|
||||
$answreplace=substr($string, stripos($string, "{Outcome:"), stripos($string, "}", stripos($string, "{Outcome:"))-stripos($string, "{Outcome:")+1);
|
||||
$answreplace2=substr($answreplace, 9, stripos($answreplace, "}", stripos($answreplace, "{Outcome:"))-9);
|
||||
$answreplace3=get_outcome_variable($answreplace2);
|
||||
$string=str_replace($answreplace, $answreplace3, $string);
|
||||
}
|
||||
|
||||
while (stripos($string, "{CALLATTEMPTS}") !== false)
|
||||
{
|
||||
$call_attempts = get_call_attempts($case_id);
|
||||
$string=str_ireplace("{CALLATTEMPTS}", $call_attempts, $string);
|
||||
}
|
||||
|
||||
while (stripos($string, "{ONAPPOINTMENT}") !== false)
|
||||
{
|
||||
$on_appointment = is_on_appointment($case_id,$operator_id);
|
||||
//todo: These must be internationalised, but I think I need to use Limesurveys so as not to conflict?
|
||||
$str = "Not on an appointment";
|
||||
if ($on_appointment)
|
||||
$str = "On an appointment";
|
||||
$string=str_ireplace("{ONAPPOINTMENT}", $str, $string);
|
||||
}
|
||||
|
||||
if (stripos($string, "{PERIODOFDAY}") !== false) $string=str_ireplace("{PERIODOFDAY}", get_period_of_day($respondent_id), $string);
|
||||
if (stripos($string, "{APPOINTMENTDATE}") !== false) $string=str_ireplace("{APPOINTMENTDATE}", get_appointment_date($respondent_id), $string);
|
||||
if (stripos($string, "{APPOINTMENTTIME}") !== false) $string=str_ireplace("{APPOINTMENTTIME}", get_appointment_time($respondent_id), $string);
|
||||
if (stripos($string, "{APPOINTMENTNUMBER}") !== false) $string=str_ireplace("{APPOINTMENTNUMBER}", get_appointment_number($respondent_id), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the limesurvey "survey id" of the current questionnaire assigned to the operator
|
||||
*
|
||||
* @param int $operator_id The operator
|
||||
* @return bool|int False if none found else the limesurvey sid
|
||||
*
|
||||
*/
|
||||
function get_limesurvey_id($operator_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
$sql = "SELECT q.lime_sid as lime_sid
|
||||
FROM `case` as c, questionnaire_sample as qs, sample as s, questionnaire as q
|
||||
WHERE c.current_operator_id = '$operator_id'
|
||||
AND c.sample_id = s.sample_id
|
||||
AND s.import_id = qs.sample_import_id
|
||||
AND q.questionnaire_id = qs.questionnaire_id
|
||||
AND c.questionnaire_id = q.questionnaire_id";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if (empty($rs))
|
||||
return false;
|
||||
|
||||
return $rs['lime_sid'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current questionnaire assigned to the operator
|
||||
* false if none
|
||||
*
|
||||
* @param int $operator_id The operator id
|
||||
* @return bool|int False if none otherwise the questionnare id
|
||||
*
|
||||
*/
|
||||
function get_questionnaire_id($operator_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
|
||||
$sql = "SELECT questionnaire_id
|
||||
FROM `case` as c
|
||||
WHERE c.current_operator_id = '$operator_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if (empty($rs)) return false;
|
||||
|
||||
return $rs['questionnaire_id'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get start interviewer URL
|
||||
*
|
||||
* @return string The URL to start the interview
|
||||
*/
|
||||
function get_start_interview_url()
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
$operator_id = get_operator_id();
|
||||
|
||||
$url = QUEXS_URL . "nocaseavailable.php";
|
||||
|
||||
$case_id = get_case_id($operator_id);
|
||||
|
||||
if ($case_id)
|
||||
{
|
||||
$sid = get_limesurvey_id($operator_id);
|
||||
$url = LIME_URL . "index.php?loadall=reload&sid=$sid&token=$case_id&lang=" . DEFAULT_LOCALE;
|
||||
$questionnaire_id = get_questionnaire_id($operator_id);
|
||||
|
||||
//get prefills
|
||||
$sql = "SELECT lime_sgqa,value
|
||||
FROM questionnaire_prefill
|
||||
WHERE questionnaire_id = '$questionnaire_id'";
|
||||
$pf = $db->GetAll($sql);
|
||||
|
||||
if (!empty($pf))
|
||||
{
|
||||
foreach ($pf as $p)
|
||||
$url .= "&" . $p['lime_sgqa'] . "=" . quexs_template_replace($p['value']);
|
||||
}
|
||||
}
|
||||
|
||||
//if ($db->HasFailedTrans()) { print "FAILED in get_limesurvey_url"; exit; }
|
||||
$db->CompleteTrans();
|
||||
|
||||
return $url;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return 1 if this operator is on an appointment
|
||||
*
|
||||
* @param int $case_id The case id
|
||||
* @param int $operator_id The operator id
|
||||
* @return int 0 if not on appointment 1 if they are
|
||||
*
|
||||
*/
|
||||
function is_on_appointment($case_id,$operator_id)
|
||||
{
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
$sql = "SELECT a.appointment_id
|
||||
FROM call_attempt as ca
|
||||
LEFT JOIN appointment as a on (a.case_id = ca.case_id and (ca.start >= a.start and ca.start <= a.end) and a.completed_call_id is NULL)
|
||||
WHERE ca.case_id = '$case_id'
|
||||
AND ca.operator_id = '$operator_id'
|
||||
AND ca.end IS NULL";
|
||||
|
||||
$a = $db->GetRow($sql);
|
||||
|
||||
if (empty($a) || empty($a['appointment_id']))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -117,12 +117,19 @@ if ((isset($_POST['fieldnames']) && $_POST['fieldnames']) || (isset($_POST['move
|
||||
{
|
||||
if ($result=$connect->Execute($subquery)) // Checked
|
||||
{
|
||||
|
||||
if (substr($subquery,0,6)=='INSERT')
|
||||
{
|
||||
$tempID=$connect->Insert_ID($thissurvey['tablename'],"id"); // Find out id immediately if inserted
|
||||
$_SESSION['srid'] = $tempID;
|
||||
$saved_id = $tempID;
|
||||
}
|
||||
|
||||
//queXS addition
|
||||
include_once('quexs.php');
|
||||
global $surveyid;
|
||||
quexs_update_sample($surveyid,$saved_id,$postedfieldnames);
|
||||
|
||||
if ($bFinalizeThisAnswer === true)
|
||||
{
|
||||
$connect->Execute("DELETE FROM ".db_table_name("saved_control")." where srid=".$_SESSION['srid'].' and sid='.$surveyid); // Checked
|
||||
|
||||
@@ -183,6 +183,12 @@ if ((isset($move) && $move == "movesubmit") && (!isset($notanswered) || !$notans
|
||||
$url=str_replace("{TOKEN}",$clienttoken, $url); // to activate the TOKEN in the END URL
|
||||
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL
|
||||
$url=str_replace("{LANG}", $clang->getlangcode(), $url); // to activate the LANG in the END URL
|
||||
|
||||
//queXS Addition
|
||||
include_once("quexs.php");
|
||||
$quexs_url = get_start_interview_url();
|
||||
$url = str_replace("{STARTINTERVIEWURL}", $quexs_url, $url);
|
||||
|
||||
//Automatically redirect the page to the "url" setting for the survey
|
||||
session_write_close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user