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"),
+
:
diff --git a/admin/questionnairelist.php b/admin/questionnairelist.php
index 749bcbcb..5647b211 100644
--- a/admin/questionnairelist.php
+++ b/admin/questionnairelist.php
@@ -225,9 +225,11 @@ if (isset($_POST['update']) && isset($_GET['modify']))
$rws = 0;
$rs = 0;
$respsc = 0;
+ $referral = 0;
if (isset($_POST['ras'])) $ras = 1;
if (isset($_POST['rws'])) $rws = 1;
if (isset($_POST['respsc'])) $respsc = 1;
+ if (isset($_POST['referral'])) $referral = 1;
$name = $db->qstr(html_entity_decode($_POST['description']));
if (isset($_POST['rs_intro']))
@@ -242,7 +244,7 @@ if (isset($_POST['update']) && isset($_GET['modify']))
$rs_project_end = $db->qstr(html_entity_decode($_POST['rs_project_end'],true));
$sql = "UPDATE questionnaire
- SET description = $name, info = $info, rs_project_end = $rs_project_end, restrict_appointments_shifts = '$ras', restrict_work_shifts = '$rws', self_complete = $respsc
+ SET description = $name, info = $info, rs_project_end = $rs_project_end, restrict_appointments_shifts = '$ras', restrict_work_shifts = '$rws', self_complete = $respsc, referral = $referral
WHERE questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
@@ -302,7 +304,7 @@ if (isset($_GET['modify']))
$rs = $db->GetRow($sql);
- $testing = $rws = $ras = $rsc = "checked=\"checked\"";
+ $referral = $testing = $rws = $ras = $rsc = "checked=\"checked\"";
$rscd = "";
$aio = $qbq = $gat = "";
@@ -314,6 +316,7 @@ if (isset($_GET['modify']))
if ($rs['restrict_appointments_shifts'] != 1) $ras = "";
if ($rs['restrict_work_shifts'] != 1) $rws = "";
if ($rs['testing'] != 1) $testing = "";
+ if ($rs['referral'] != 1) $referral = "";
if ($rs['self_complete'] == 0)
{
$rsc = "";
@@ -329,6 +332,7 @@ if (isset($_GET['modify']))
/>
/>
/>
+
/>
onchange="if(this.checked==true) show(this,'limesc'); else hide(this,'limesc');" />
>
:
diff --git a/index.php b/index.php
index 1e214744..fb584b9b 100644
--- a/index.php
+++ b/index.php
@@ -132,12 +132,14 @@ print $script;
$case_id = get_case_id($operator_id,true);
-$sql = "SELECT q.self_complete
+$sql = "SELECT q.self_complete as sc,q.referral as r
FROM questionnaire as q, `case` as c
WHERE c.case_id = $case_id
AND c.questionnaire_id = q.questionnaire_id";
-$sc = $db->GetOne($sql);
+$scr = $db->GetRow($sql);
+$sc = $scr['sc'];
+$ref = $scr['r'];
?>
@@ -147,6 +149,7 @@ $sc = $db->GetOne($sql);
+

'/>
diff --git a/index_interface2.php b/index_interface2.php
index b40ca4fa..ff582265 100644
--- a/index_interface2.php
+++ b/index_interface2.php
@@ -197,12 +197,14 @@ print $script;
$case_id = get_case_id($operator_id,true);
-$sql = "SELECT q.self_complete
+$sql = "SELECT q.self_complete, q.referral
FROM questionnaire as q, `case` as c
WHERE c.case_id = $case_id
AND c.questionnaire_id = q.questionnaire_id";
-$sc = $db->GetOne($sql);
+$scr = $db->GetRow($sql);
+$sc = $scr['self_complete'];
+$ref = $scr['referral'];
?>
@@ -210,6 +212,7 @@ $sc = $db->GetOne($sql);

+

diff --git a/referral.php b/referral.php
new file mode 100644
index 00000000..4cb99cf2
--- /dev/null
+++ b/referral.php
@@ -0,0 +1,253 @@
+
+ * @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2013
+ * @package queXS
+ * @subpackage user
+ * @link http://www.acspri.org.au/ queXS was writen for ACSPRI
+ * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
+ *
+ */
+
+/**
+ * Configuration file
+ */
+include ("config.inc.php");
+
+/**
+ * Database file
+ */
+include ("db.inc.php");
+
+/**
+ * XHTML functions
+ */
+include ("functions/functions.xhtml.php");
+
+/**
+ * Operator functions
+ */
+include("functions/functions.operator.php");
+
+/**
+ * Input functions
+ */
+include("functions/functions.input.php");
+
+/**
+ * Import functions
+ */
+include("functions/functions.import.php");
+
+global $db;
+
+$operator_id = get_operator_id();
+
+$msg = "";
+
+if (isset($_POST['submit']))
+{
+ $case_id = get_case_id($operator_id);
+
+ $sql = "SELECT s.var
+ FROM sample_var as s, `case` as c
+ WHERE c.case_id = '$case_id'
+ AND s.sample_id = c.sample_id
+ AND s.type = 3";
+
+ $pphone = $db->GetOne($sql);
+
+ //validate primary phone number supplied
+ if (isset($_POST["v_$pphone"]) && only_numbers($_POST["v_$pphone"]) != "")
+ {
+ $phone = $db->qstr(only_numbers($_POST["v_$pphone"]));
+
+ //Create a new sample record and add CASEREFERREDFROM to be this current case id
+ $db->StartTrans();
+
+ //create a new sample entry
+ $sql = "SELECT s.import_id
+ FROM `sample` as s, `case` as c
+ WHERE c.case_id = '$case_id'
+ AND s.sample_id = c.sample_id";
+
+ $import_id = $db->GetOne($sql);
+
+ //get all sample records
+ $sql = "SELECT s.var,s.val, s.type
+ FROM sample_var as s, `case` as c
+ WHERE c.case_id = '$case_id'
+ AND s.sample_id = c.sample_id";
+
+ $rs = $db->GetAll($sql);
+
+ $tzone = DEFAULT_TIME_ZONE; //set this to default
+
+ //Get the timezone
+ foreach($rs as $r)
+ {
+ $tz = get_time_zone($_POST["v_" . $r['var']],$r['type']);
+ if ($tz !== false)
+ {
+ $tzone = $tz;
+ break;
+ }
+ }
+
+ $sql = "INSERT INTO `sample` (import_id,Time_zone_name,phone)
+ VALUES ($import_id,'$tzone',$phone)";
+
+ $db->Execute($sql);
+
+ $sample_id = $db->Insert_ID();
+
+ //insert sample var records
+ foreach($rs as $r)
+ {
+ $sql = "INSERT INTO `sample_var` (`sample_id`,`var`,`val`,`type`)
+ VALUES ('$sample_id','{$r['var']}'," . $db->qstr($_POST['v_' . $r['var']]) . ",'{$r['type']}')";
+ $db->Execute($sql);
+ }
+
+ //Add CASEREFERREDFROM record
+ $sql = "INSERT INTO `sample_var` (`sample_id`,`var`,`val`,`type`)
+ VALUES ('$sample_id','CASEREFERREDFROM','$case_id','1')";
+
+ $db->Execute($sql);
+
+ //Create a new case
+ $sql = "SELECT questionnaire_id
+ FROM `case`
+ WHERE case_id = '$case_id'";
+
+ $questionnaire_id = $db->GetOne($sql);
+
+ $ncase_id = add_case($sample_id,$questionnaire_id);
+
+ //If selected to call now - assign to this operator
+ if (isset($_POST['makecase']))
+ {
+ $sql = "SELECT MAX(sortorder)
+ FROM case_queue
+ WHERE operator_id = '$operator_id'";
+
+ $sortorder = $db->GetOne($sql);
+
+ $sortorder++;
+
+ $sql = "INSERT INTO case_queue (case_id,operator_id,sortorder)
+ VALUES ('$ncase_id', '$operator_id', '$sortorder')";
+
+ $db->Execute($sql);
+
+ }
+
+ //Add a note that we have referred another case
+ $sql = "INSERT INTO `case_note` (case_id,operator_id,note,datetime)
+ VALUES ($case_id,$operator_id,'" . T_("Generated referral to case id") . ": $ncase_id',CONVERT_TZ(NOW(),'System','UTC'))";
+
+ $db->Execute($sql);
+
+ //Add a note that it is referred from another case
+ $sql = "INSERT INTO `case_note` (case_id,operator_id,note,datetime)
+ VALUES ($ncase_id,$operator_id,'" . T_("Generated as referral from case id") . ": $case_id',CONVERT_TZ(NOW(),'System','UTC'))";
+
+ $db->Execute($sql);
+
+ if ($db->CompleteTrans())
+ {
+ $msg = T_("Created referral case - you may now close this window");
+ }
+ else
+ {
+ $msg = T_("Failed to create referral case - please check your input and try again");
+ }
+
+ }
+ else
+ {
+ $msg = T_("You must supply a primary phone number");
+ }
+}
+
+$case_id = get_case_id($operator_id);
+
+$js = "js/window.js";
+if (browser_ie()) $js = "js/window_ie6.js";
+
+xhtml_head(T_("Referral"),true,array("css/call.css"),array($js));
+
+$sql = "SELECT q.referral
+ FROM questionnaire as q, `case` as c
+ WHERE c.case_id = $case_id
+ AND c.questionnaire_id = q.questionnaire_id";
+
+$sc = $db->GetOne($sql);
+
+if ($sc == 1)
+{
+ print "
" . T_("Create referral") . "
";
+ if (!empty($msg)) print "
$msg
";
+ print "
";
+}
+else
+{
+ print "
" . T_("Referrals not available for this questionnaire") . "
";
+}
+
+xhtml_foot();
+
+?>