2
0
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:
azammitdcarf
2010-09-29 23:19:08 +00:00
parent 19143de1c0
commit 0ef7c93737
18 changed files with 674 additions and 33 deletions

View File

@@ -64,6 +64,7 @@ T_("Temporary Outcomes (normal cases)");
T_("Supervisor Outcomes (referred to supervisor)");
T_("Refusal Outcomes (respondent refused)");
T_("Final Outcomes (completed, final refusal, etc)");
T_("Miscellaneous - Unavailable for a week");
T_("Appointments");
T_("Monday");
T_("Tuesday");

View File

@@ -63,10 +63,11 @@ if (isset($_POST['import_file']))
$testing = 0;
$rs = 0;
$lime_sid = 0;
$lime_rs_sid = "NULL";
if (isset($_POST['ras'])) $ras = 1;
if (isset($_POST['rws'])) $rws = 1;
if (isset($_POST['testing'])) $testing = 1;
if (isset($_POST['rs'])) $rs = 1;
if ($_POST['selectrs'] != "none") $rs = 1;
$name = $db->qstr($_POST['description'],get_magic_quotes_gpc());
$rs_intro = $db->qstr($_POST['rs_intro'],get_magic_quotes_gpc());
@@ -78,8 +79,7 @@ if (isset($_POST['import_file']))
if ($_POST['select'] == "new")
{
//create one from scratch
include("../functions/functions.limesurvey.php");
include_once("../functions/functions.limesurvey.php");
$lime_sid = create_limesurvey_questionnaire($name);
}
else
@@ -88,8 +88,19 @@ if (isset($_POST['import_file']))
$lime_sid = bigintval($_POST['select']);
}
$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)
VALUES (NULL,$name,'$lime_sid','$ras','$rws','$rs',$rs_intro,$rs_project_intro,$rs_project_end,$rs_callback,$rs_answeringmachine,'$testing')";
if ($_POST['selectrs'] == "new")
{
//create one from scratch
include_once("../functions/functions.limesurvey.php");
$lime_rs_sid = create_limesurvey_questionnaire($db->qstr(T_("Respondent Selection for ") . $_POST['description']),false);
}
else if (is_numeric($_POST['selectrs']))
{
$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)
VALUES (NULL,$name,'$lime_sid','$ras','$rws','$rs',$rs_intro,$rs_project_intro,$rs_project_end,$rs_callback,$rs_answeringmachine,'$testing',$lime_rs_sid)";
$rs = $db->Execute($sql);
@@ -128,18 +139,34 @@ if (!empty($surveys))
print "<option value=\"{$s['sid']}\">" . T_("Existing questionnaire:") . " {$s['title']}</option>";
}
}
?></select></p>
<p><? echo T_("Respondent selection type:"); ?> <select name="selectrs"><option value="none" onclick="hide(this,'rstext');"><? echo T_("No respondent selection (go straight to questionnaire)"); ?></option><option value="old" onclick="show(this,'rstext');" ><? echo T_("Use basic respondent selection text (below)"); ?></option><option onclick="hide(this,'rstext');" value="new"><? echo T_("Create new respondent selection questionnaire in Limesurvey"); ?></option><?
$sql = "SELECT s.sid as sid, sl.surveyls_title AS title
FROM " . LIME_PREFIX . "surveys AS s
LEFT JOIN " . LIME_PREFIX . "surveys_languagesettings AS sl ON ( s.sid = sl.surveyls_survey_id
AND sl.surveyls_language = 'en' )
WHERE s.active = 'Y'";
$surveys = $db->GetAll($sql);
if (!empty($surveys))
{
foreach($surveys as $s)
{
print "<option onclick=\"hide(this, 'rstext');\" value=\"{$s['sid']}\">" . T_("Existing questionnaire:") . " {$s['title']}</option>";
}
}
?></select></p>
<p><? echo T_("Restrict appointments to shifts?"); ?> <input name="ras" type="checkbox" checked="checked"/></p>
<p><? echo T_("Restrict work to shifts?"); ?> <input name="rws" type="checkbox" checked="checked"/></p>
<p><? echo T_("Questionnaire for testing only?"); ?> <input name="testing" type="checkbox"/></p>
<p><? echo T_("Use respondent selection text?"); ?> <input name="rs" id="rs" type="checkbox" checked="checked" onclick="showHide(this,'rstext');"/></p>
<div id='rstext'>
<div id='rstext' style='display:none;'>
<p><? echo T_("Respondent selection introduction:"); ?> <textarea cols="40" rows="4" name="rs_intro"></textarea></p>
<p><? echo T_("Respondent selection project introduction:"); ?> <textarea cols="40" rows="4" name="rs_project_intro"></textarea></p>
<p><? echo T_("Respondent selection project end:"); ?> <textarea cols="40" rows="4" name="rs_project_end"></textarea></p>
<p><? echo T_("Respondent selection callback (already started questionnaire):"); ?> <textarea cols="40" rows="4" name="rs_callback"></textarea></p>
<p><? echo T_("Message to leave on an answering machine:"); ?> <textarea cols="40" rows="4" name="rs_answeringmachine"></textarea></p>
</div>
<p><? echo T_("Project end text (thank you screen):"); ?> <textarea cols="40" rows="4" name="rs_project_end"></textarea></p>
<p><input type="submit" name="import_file" value="<? echo T_("Create Questionnaire"); ?>"/></p>
</form>
<?

View File

@@ -169,7 +169,7 @@ if (isset($_POST['submit']))
$v->dial(get_extension($operator_id),get_call_number($call_id));
}
if (is_respondent_selection($operator_id))
$btext = "onload='openParentObject(\"main-content\",\"rs_intro.php\"); parent.closePopup();'";
$btext = "onload='openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id) . "\"); parent.closePopup();'";
else
$btext = "onload='parent.closePopup();'";
xhtml_head(T_("Call"),true,array("css/call.css"),array("js/window.js"),$btext);
@@ -188,7 +188,7 @@ if (isset($_POST['submit']))
}
//disable recording
$newtext = T_("Start REC");
xhtml_head(T_("Call"),true,array("css/call.css"),array("js/window.js"),"onload='toggleRec(\"$newtext\",\"record.php?start=start\",\"offline\"); parent.closePopup();'");
xhtml_head(T_("Call"),true,array("css/call.css"),array("js/window.js"),"onload='toggleRec(\"$newtext\",\"record.php?start=start\",\"offline\"); openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id) . "\"); parent.closePopup();'");
}
else
{
@@ -202,7 +202,7 @@ if (isset($_POST['submit']))
}
//disable recording
$newtext = T_("Start REC");
xhtml_head(T_("Call"),true,array("css/call.css"),array("js/window.js"),"onload='toggleRec(\"$newtext\",\"record.php?start=start\",\"offline\"); parent.closePopup();'");
xhtml_head(T_("Call"),true,array("css/call.css"),array("js/window.js"),"onload='toggleRec(\"$newtext\",\"record.php?start=start\",\"offline\"); openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id) . "\"); parent.closePopup();'");
}

View File

@@ -54,6 +54,11 @@ if (!defined('DEFAULT_TIME_ZONE')) define('DEFAULT_TIME_ZONE', 'Australia/Victor
*/
if (!defined('DATE_TIME_FORMAT')) define('DATE_TIME_FORMAT','%a %d %b %I:%i%p');
/**
* Date format for displaying: see above for mySQL details
*/
if (!defined('DATE_FORMAT')) define('DATE_FORMAT','%a %d %b');
/**
* Time format for displaying: see above for mySQL details
*/

View File

@@ -409,6 +409,7 @@ INSERT INTO `outcome` VALUES(29, '3.14', 'Answering machine - Not a household',
INSERT INTO `outcome` VALUES(30, '4.10', 'Out of sample', 0, 4, 0, 1, 0, 0, 0, '');
INSERT INTO `outcome` VALUES(31, '2.20', 'Non contact', 180, 1, 1, 1, 1, 1, 0, 'NC');
INSERT INTO `outcome` VALUES(32, '4.80', 'Quota filled', 0, 4, 0, 1, 0, 0, 0, '');
INSERT INTO `outcome` VALUES(33, '2.36', 'Miscellaneous - Unavailable for a week', 10080, 1, 0, 1, 1, 1, 0, 'O');
-- --------------------------------------------------------
@@ -466,6 +467,7 @@ CREATE TABLE `questionnaire` (
`rs_project_end` text collate utf8_unicode_ci NOT NULL,
`rs_callback` text collate utf8_unicode_ci NOT NULL,
`rs_answeringmachine` text collate utf8_unicode_ci NOT NULL,
`lime_rs_sid` int(11) default NULL,
PRIMARY KEY (`questionnaire_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

View File

@@ -246,9 +246,10 @@ function getRandomID()
* With modifications
*
* @param string $title Questionnaire name
* @param bool $exittoend Whether to exit to the project end, or to the start of the questionnaire
* @link http://www.limesurvey.org/ LimeSurvey
*/
function create_limesurvey_questionnaire($title)
function create_limesurvey_questionnaire($title,$exittoend = true)
{
global $db;
@@ -286,7 +287,13 @@ function create_limesurvey_questionnaire($title)
. "'', '',\n"
. "'', '',\n"
. "'', '',\n"
. "'', '" . QUEXS_URL . "rs_project_end.php')";
. "'', '";
if ($exittoend)
$isquery .= QUEXS_URL . "rs_project_end.php')";
else
$isquery .= "{STARTINTERVIEWURL}')";
$isresult = $db->Execute($isquery) or die ($isquery."<br/>".$db->ErrorMsg());

View File

@@ -228,7 +228,7 @@ function template_replace($string,$operator_id,$case_id)
* enabled
*
* @param int $operator_id The operator id
* @return bool True if respondent selection enabled otherwise false
* @return bool|int True if respondent selection enabled, lime_sid if rs enabled with limesurvey otherwise false
*
*/
function is_respondent_selection($operator_id)
@@ -242,7 +242,7 @@ function is_respondent_selection($operator_id)
if (!$questionnaire_id)
return false;
$sql = "SELECT respondent_selection
$sql = "SELECT respondent_selection, lime_rs_sid
FROM questionnaire
WHERE questionnaire_id = '$questionnaire_id'";
@@ -255,7 +255,13 @@ function is_respondent_selection($operator_id)
return false;
if (!$rs) return false;
if ($rs['respondent_selection'] == 1) return true;
if ($rs['respondent_selection'] == 1){
if ($rs['lime_rs_sid'] > 0)
{
return $rs['lime_rs_sid'];
}
return true;
}
return false;
}
@@ -427,8 +433,10 @@ function get_case_id($operator_id, $create = false)
$i = 1;
foreach ($r5 as $r5v)
{
$tnum = ereg_replace('[^0-9]*','',$r5v['phone']);
if (empty($tnum)) $tnum = "312345678"; //handle error condition
$sql = "INSERT INTO contact_phone (case_id,priority,phone)
VALUES ($case_id,$i," . ereg_replace('[^0-9]*','',$r5v['phone']) . ")";
VALUES ($case_id,$i,$tnum)";
$db->Execute($sql);
$i++;
}
@@ -448,7 +456,8 @@ function get_case_id($operator_id, $create = false)
SELECT $case_id as case_id, s1.val as firstName, 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']}'";
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);
@@ -903,6 +912,20 @@ function get_call($operator_id,$respondent_id = "",$contact_phone_id = "",$creat
VALUES (NULL,'$operator_id','$case_id','$ca',CONVERT_TZ(NOW(),'System','UTC'),NULL,'$respondent_id','$contact_phone_id','0','1')";
$db->Execute($sql);
$id = $db->Insert_Id();
//If respondent selection is enabled, add token to RS Limesurvey database
$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
{
@@ -924,6 +947,39 @@ function get_call($operator_id,$respondent_id = "",$contact_phone_id = "",$creat
}
/**
* Get the complete URL for the Limesurvey questionnaire of respondent selection
* If no case available, return an error screen
*
* @param int $operator_id The operator id
* @return string The URL of the LimeSurvey questionnaire, or the URL of an error screen if none available
*
*/
function get_respondentselection_url($operator_id)
{
global $db;
$db->StartTrans();
$url = "nocallavailable.php";
$call_id = get_call($operator_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?loadall=reload&amp;sid=$sid&amp;token=$call_id&amp;lang=" . DEFAULT_LOCALE;
else
$url = 'rs_intro.php';
}
//if ($db->HasFailedTrans()) { print "FAILED in get_limesurvey_url"; exit; }
$db->CompleteTrans();
return $url;
}
/**
* Get the complete URL for the Limesurvey questionnaire
* If no case available, return an error screen
@@ -1782,17 +1838,21 @@ function end_call($operator_id,$outcome_id,$state = 5)
* Get the limesurvey "survey id" of the current questionnaire assigned to the operator
*
* @param int $operator_id The operator
* @param bool $rs If asking for respondent selection
* @return bool|int False if none found else the limesurvey sid
*
* @todo Implement session destruction here
*
*/
function get_limesurvey_id($operator_id)
function get_limesurvey_id($operator_id,$rs = false)
{
global $db;
$sql = "SELECT q.lime_sid as lime_sid
FROM `case` as c, questionnaire_sample as qs, sample as s, questionnaire as q
if ($rs)
$sql = "SELECT q.lime_rs_sid as sid";
else
$sql = "SELECT q.lime_sid as sid";
$sql .= " 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
@@ -1804,7 +1864,7 @@ function get_limesurvey_id($operator_id)
if (empty($rs))
return false;
return $rs['lime_sid'];
return $rs['sid'];
}

View File

@@ -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;
}
?>
?>

View File

@@ -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;

View File

@@ -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();

View File

@@ -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}");
}

View File

@@ -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'] = "&nbsp;";}
$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];
}

View File

@@ -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}");
}

View File

@@ -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;
}
?>

View File

@@ -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

View File

@@ -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();

View File

@@ -103,7 +103,7 @@ xhtml_head(T_("queXS"), true, array("css/index.css","css/tabber.css","include/jq
</div>
<div id="content">
<object class="embeddedobject" id="main-content" data="<? get_case_id($operator_id,true); get_call_attempt($operator_id,true); if (!is_respondent_selection($operator_id)) print(get_limesurvey_url($operator_id)); else print "rs_intro.php"; ?>" standby="Loading questionnaire..." type="application/xhtml+xml"><p>Error, try with Firefox</p></object>
<object class="embeddedobject" id="main-content" data="<? get_case_id($operator_id,true); get_call_attempt($operator_id,true); if (!is_respondent_selection($operator_id)) print(get_limesurvey_url($operator_id)); else print get_respondentselection_url($operator_id); ?>" standby="Loading questionnaire..." type="application/xhtml+xml"><p>Error, try with Firefox</p></object>
</div>
<div id="respondent">

View File

@@ -11,3 +11,15 @@ function showHide(me,id)
}
}
function show(me,id)
{
e = document.getElementById(id);
e.style.display = 'inline';
}
function hide(me,id)
{
e = document.getElementById(id);
e.style.display = 'none';
}