mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merged Ability to create new cases as a referral from an existing case feature
Also improves timezone detection
This commit is contained in:
@@ -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']);
|
||||
@@ -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"),
|
||||
<p><?php echo T_("Restrict appointments to shifts?"); ?> <input name="ras" type="checkbox" checked="checked"/></p>
|
||||
<p><?php echo T_("Restrict work to shifts?"); ?> <input name="rws" type="checkbox" checked="checked"/></p>
|
||||
<p><?php echo T_("Questionnaire for testing only?"); ?> <input name="testing" type="checkbox"/></p>
|
||||
<p><?php echo T_("Allow operators to generate referrals?"); ?> <input name="referral" type="checkbox"/></p>
|
||||
<p><?php echo T_("Allow for respondent self completion via email invitation?"); ?> <input name="respsc" type="checkbox" onchange="if(this.checked==true) show(this,'limesc'); else hide(this,'limesc');" /></p>
|
||||
<div id='limesc' style='display:none;'>
|
||||
<p><?php echo T_("Questionnaire display mode for respondent");?>: <select name="lime_mode"><option value="survey"><?php echo T_("All in one"); ?></option><option value="question"><?php echo T_("Question by question"); ?></option><option value="group"><?php echo T_("Group at a time"); ?></option></select></p>
|
||||
|
||||
@@ -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'],ENT_QUOTES,'UTF-8'));
|
||||
if (isset($_POST['rs_intro']))
|
||||
@@ -243,7 +245,7 @@ if (isset($_POST['update']) && isset($_GET['modify']))
|
||||
|
||||
|
||||
$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);
|
||||
@@ -303,7 +305,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 = "";
|
||||
@@ -315,6 +317,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 = "";
|
||||
@@ -330,6 +333,7 @@ if (isset($_GET['modify']))
|
||||
<p><?php echo T_("Restrict appointments to shifts?"); ?> <input name="ras" type="checkbox" <?php echo $ras; ?>/></p>
|
||||
<p><?php echo T_("Restrict work to shifts?"); ?> <input name="rws" type="checkbox" <?php echo $rws; ?>/></p>
|
||||
<p><?php echo T_("Questionnaire for testing only?"); ?> <input name="testing" type="checkbox" disabled="true" <?php echo $testing; ?>/></p>
|
||||
<p><?php echo T_("Allow operators to generate referrals?"); ?> <input name="referral" type="checkbox" <?php echo $referral; ?>/></p>
|
||||
<p><?php echo T_("Allow for respondent self completion via email invitation?"); ?> <input name="respsc" type="checkbox" <?php echo $rsc ?> onchange="if(this.checked==true) show(this,'limesc'); else hide(this,'limesc');" /></p>
|
||||
<div id='limesc' <?php echo $rscd; ?>>
|
||||
<p><?php echo T_("Questionnaire display mode for respondent");?>: <select name="lime_mode"><option <?php echo $aio;?> value="survey"><?php echo T_("All in one"); ?></option><option <?php echo $qbq; ?> value="question"><?php echo T_("Question by question"); ?></option><option <?php echo $gat; ?> value="group"><?php echo T_("Group at a time"); ?></option></select></p>
|
||||
|
||||
@@ -1384,6 +1384,7 @@ CREATE TABLE `questionnaire` (
|
||||
`lime_rs_sid` int(11) default NULL,
|
||||
`info` text collate utf8_unicode_ci,
|
||||
`self_complete` tinyint(1) NOT NULL default '0',
|
||||
`referral` TINYINT( 1 ) NOT NULL DEFAULT '0',
|
||||
`lime_mode` varchar(64) collate utf8_unicode_ci default NULL COMMENT 'Limesurvey mode for respondent self completion',
|
||||
`lime_template` varchar(128) collate utf8_unicode_ci default NULL COMMENT 'Limesurvey template for respondent self completion',
|
||||
`lime_endurl` varchar(256) collate utf8_unicode_ci default NULL COMMENT 'Forwarding end URL for respondent self completion',
|
||||
|
||||
@@ -257,7 +257,10 @@ function import_file($file, $description, $fields, $firstrow = 2)
|
||||
{
|
||||
$dkey = only_numbers($data[$key - 1]);
|
||||
if (!empty($dkey))
|
||||
{
|
||||
$data[$key - 1] = $dkey;
|
||||
$numberavail = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,38 +277,14 @@ function import_file($file, $description, $fields, $firstrow = 2)
|
||||
*
|
||||
*/
|
||||
foreach($selected_type as $key => $val)
|
||||
{
|
||||
$sql = "SELECT `table`
|
||||
FROM sample_var_type
|
||||
WHERE type = '$val'";
|
||||
|
||||
$tname = $db->GetRow($sql);
|
||||
|
||||
if (!empty($tname))
|
||||
{
|
||||
$tz = get_time_zone($data[$key - 1],$val);
|
||||
|
||||
if ($tz !== false)
|
||||
{
|
||||
$tname = $tname['table'];
|
||||
if (!empty($tname))
|
||||
{
|
||||
|
||||
$value = $db->Quote(only_numbers($data[$key - 1]));
|
||||
|
||||
$sql = "SELECT Time_zone_name as tz
|
||||
FROM `$tname`
|
||||
WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )";
|
||||
|
||||
$tz = $db->GetRow($sql);
|
||||
|
||||
//print("$sql<br/>");
|
||||
//if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
|
||||
|
||||
if (!empty($tz))
|
||||
{
|
||||
$tzone = $tz['tz'];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$tzone = $tz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -353,5 +332,42 @@ function import_file($file, $description, $fields, $firstrow = 2)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the timezone given the sample value and type
|
||||
*
|
||||
* @param string $value A sample value
|
||||
* @param integer $type The type of sample var (see sample_var_type table)
|
||||
*
|
||||
* @return string|bool Return the timezone name or false if not found
|
||||
*/
|
||||
function get_time_zone($value,$type)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT `table`
|
||||
FROM sample_var_type
|
||||
WHERE type = '$type'";
|
||||
|
||||
$tname = $db->GetOne($sql);
|
||||
|
||||
if (!empty($tname))
|
||||
{
|
||||
$value = $db->Quote($value);
|
||||
|
||||
$sql = "SELECT Time_zone_name as tz
|
||||
FROM `$tname`
|
||||
WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )
|
||||
ORDER BY CHAR_LENGTH(val) DESC";
|
||||
|
||||
$tz = $db->GetOne($sql);
|
||||
|
||||
if (!empty($tz))
|
||||
{
|
||||
return $tz;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -338,6 +338,117 @@ function is_respondent_selection($operator_id)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a case to the system based on a sample record
|
||||
*
|
||||
* @param int $sample_id The sample 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
|
||||
*
|
||||
* @return int The case id
|
||||
*/
|
||||
function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = 0)
|
||||
{
|
||||
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')";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
$case_id = $db->Insert_ID();
|
||||
|
||||
//if this sample is set as testing, assign internal numbers as numbers
|
||||
if ($testing == 1)
|
||||
{
|
||||
$db->Execute("SET @row := 0");
|
||||
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
SELECT $case_id as case_id,@row := @row + 1 AS priority,SUBSTRING_INDEX(e.extension,'/',-1) as phone, CONCAT(o.firstName, ' ', o.lastName)
|
||||
FROM operator as o, `extension` as e
|
||||
WHERE o.enabled = 1
|
||||
AND e.current_operator_id = o.operator_id";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
//add any phone numbers to contact phone
|
||||
|
||||
//$db->Execute("SET @row := 0");
|
||||
|
||||
$sql = "SELECT val as phone
|
||||
FROM sample_var
|
||||
WHERE sample_id = '$sample_id'
|
||||
AND val is NOT NULL
|
||||
AND val != \"\"
|
||||
AND (`type` = 2 or `type` = 3)
|
||||
ORDER BY `type` DESC";
|
||||
|
||||
$r5 = $db->GetAll($sql);
|
||||
|
||||
if (!empty($r5))
|
||||
{
|
||||
$i = 1;
|
||||
foreach ($r5 as $r5v)
|
||||
{
|
||||
$tnum = preg_replace("/[^0-9]/", "",$r5v['phone']);
|
||||
if (empty($tnum)) $tnum = "312345678"; //handle error condition
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
VALUES ($case_id,$i,$tnum,'')";
|
||||
$db->Execute($sql);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
VALUES ($case_id,1,312345678,'test only')";
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//add respondent details to respondent (if such details exist in the sample)
|
||||
|
||||
$sql = "INSERT INTO respondent (case_id,firstName,lastName,Time_zone_name)
|
||||
SELECT $case_id as case_id, IFNULL(s1.val,'') as firstName, IFNULL(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 = '$sample_id' and s2.type = 7)
|
||||
LEFT JOIN sample_var as s1 on (s1.sample_id = '$sample_id' and s1.type = 6)
|
||||
WHERE s3.sample_id = '$sample_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
|
||||
//add resopndent to Lime Survey token table for this questionnaire
|
||||
|
||||
//first we need to get the limesurvey survey id
|
||||
|
||||
if (!$db->HasFailedTrans()) //if the transaction hasn't failed
|
||||
{
|
||||
$sql = "SELECT lime_sid
|
||||
FROM questionnaire
|
||||
WHERE questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$lime_sid = $db->GetOne($sql);
|
||||
|
||||
if ($lime_sid)
|
||||
{
|
||||
$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)";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
}
|
||||
|
||||
return $case_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current or next case id
|
||||
*
|
||||
@@ -603,95 +714,8 @@ function get_case_id($operator_id, $create = false)
|
||||
|
||||
if (!empty($r3))
|
||||
{
|
||||
$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, {$r3['sample_id']}, {$r3['questionnaire_id']} , NULL, $operator_id, NULL, 1, '$token')";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
$case_id = $db->Insert_ID();
|
||||
|
||||
//if this sample is set as testing, assign internal numbers as numbers
|
||||
if ($r3['testing'] == 1)
|
||||
{
|
||||
$db->Execute("SET @row := 0");
|
||||
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
SELECT $case_id as case_id,@row := @row + 1 AS priority,SUBSTRING_INDEX(o.extension,'/',-1) as phone, CONCAT(o.firstName, ' ', o.lastName)
|
||||
FROM operator as o, `extension` as e
|
||||
WHERE o.enabled = 1
|
||||
AND e.current_operator_id = o.operator_id";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
//add any phone numbers to contact phone
|
||||
|
||||
//$db->Execute("SET @row := 0");
|
||||
|
||||
$sql = "SELECT val as phone
|
||||
FROM sample_var
|
||||
WHERE sample_id = '{$r3['sample_id']}'
|
||||
AND val is NOT NULL
|
||||
AND val != \"\"
|
||||
AND (`type` = 2 or `type` = 3)
|
||||
ORDER BY `type` DESC";
|
||||
|
||||
$r5 = $db->GetAll($sql);
|
||||
|
||||
if (!empty($r5))
|
||||
{
|
||||
$i = 1;
|
||||
foreach ($r5 as $r5v)
|
||||
{
|
||||
$tnum = preg_replace("/[^0-9]/", "",$r5v['phone']);
|
||||
if (empty($tnum)) $tnum = "312345678"; //handle error condition
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
VALUES ($case_id,$i,$tnum,'')";
|
||||
$db->Execute($sql);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
VALUES ($case_id,1,312345678,'test only')";
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//add respondent details to respondent (if such details exist in the sample)
|
||||
|
||||
$sql = "INSERT INTO respondent (case_id,firstName,lastName,Time_zone_name)
|
||||
SELECT $case_id as case_id, IFNULL(s1.val,'') as firstName, IFNULL(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']}'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
|
||||
//add resopndent to Lime Survey token table for this questionnaire
|
||||
|
||||
//first we need to get the limesurvey survey id
|
||||
|
||||
if (!$db->HasFailedTrans()) //if the transaction hasn't failed
|
||||
{
|
||||
$lime_sid = get_limesurvey_id($operator_id);
|
||||
|
||||
if ($lime_sid)
|
||||
{
|
||||
$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)";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
$case_id = add_case($r3['sample_id'],$r3['questionnaire_id'],$operator_id,$r3['testing']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -147,12 +147,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'];
|
||||
|
||||
?>
|
||||
|
||||
@@ -162,6 +164,7 @@ $sc = $db->GetOne($sql);
|
||||
<div class='box important'><a href="javascript:poptastic('call.php');"><?php echo T_("Call/Hangup"); ?></a></div>
|
||||
<div class='box'><a href="javascript:poptastic('supervisor.php');"><?php echo T_("Supervisor"); ?></a></div>
|
||||
<?php if ($sc == 1) { ?><div class='box'><a href="javascript:poptastic('email.php');"><?php echo T_("Email"); ?></a></div><?php } ?>
|
||||
<?php if ($ref == 1) { ?><div class='box'><a href="javascript:poptastic('referral.php');"><?php echo T_("Referral"); ?></a></div><?php } ?>
|
||||
<div class='box' id='recbox'><a id='reclink' class='offline' href="javascript:poptastic('record.php?start=start');"><?php echo T_("Start REC"); ?></a></div>
|
||||
<?php if (HEADER_EXPANDER_MANUAL){ ?> <div class='headerexpand'><img id='headerexpandimage' src='./images/arrow-up-2.png' alt='<?php echo T_('Arrow for expanding or contracting'); ?>'/></div> <?php } ?>
|
||||
<div class='box'><a href='index.php?'><?php echo T_("Restart"); ?></a></div>
|
||||
|
||||
@@ -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);
|
||||
<li id="item_1"><a href="javascript:poptastic('call_interface2.php');"><?php echo T_("Outcome"); ?> <img src="css/images/play.jpg" /></a></li>
|
||||
<li id="item_2_e" class="item_2_full_height"><a href="javascript:poptastic('appointment.php');"><?php echo T_("Appointment"); ?> <img src="css/images/plius.jpg" /></a></li>
|
||||
<?php if ($sc == 1) { ?><li id='item_4_e' class="item_2_full_height"><a href="javascript:poptastic('email.php?interface2=true');"><?php echo T_("Email"); ?> <img src="css/images/plius.jpg" /></a></li><?php } ?>
|
||||
<?php if ($ref == 1) { ?><li id='item_5_e' class="item_2_full_height"><a href="javascript:poptastic('referral.php?interface2=true');"><?php echo T_("Referral"); ?> <img src="css/images/plius.jpg" /></a></li><?php } ?>
|
||||
<li id="item_3_e" class="item_3_full_height"><a href="?endwork=endwork"><?php echo T_("End work"); ?> <img src="css/images/end.jpg" /></a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
253
referral.php
Normal file
253
referral.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
* Popup screen to manage referrals
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@acspri.org.au>
|
||||
* @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 "<div class='status'>" . T_("Create referral") . "</div>";
|
||||
if (!empty($msg)) print "<p>$msg</p>";
|
||||
print "<form action='?' method='post'>";
|
||||
|
||||
//Create a list of sample records matching this current case
|
||||
|
||||
$sql = "SELECT sv.var,t.description,sv.type
|
||||
FROM sample_var as sv, `case` as c, sample_var_type as t
|
||||
WHERE sv.sample_id = c.sample_id
|
||||
AND c.case_id = '$case_id'
|
||||
AND sv.type = t.type";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
foreach ($rs as $r)
|
||||
{
|
||||
$var = $r['var'];
|
||||
print "<div><label for='v_$var'>";
|
||||
|
||||
if ($r['type'] != 1)
|
||||
print T_($r['description']);
|
||||
else
|
||||
print $var;
|
||||
|
||||
print "</label><input type='text' name='v_$var' id='v_$var' ";
|
||||
|
||||
if (isset($_POST['v_' . $var]))
|
||||
print "value='" . $_POST['v_' .$var] . "' ";
|
||||
|
||||
print " /></div>";
|
||||
}
|
||||
|
||||
print "<div><label for='makecase'>" . T_("Call this new referral immediately after this case?") . "</label><input type='checkbox' name='makecase' id='makecase' checked='checked'/></div>";
|
||||
|
||||
print "<div><input type='submit' value='" . T_("Create referral") . "' name='submit' id='submit'/></div>";
|
||||
print "</form>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<p>" . T_("Referrals not available for this questionnaire") . "</p>";
|
||||
}
|
||||
|
||||
xhtml_foot();
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user