diff --git a/admin/casestatus.php b/admin/casestatus.php index 83a199f3..084ff1f2 100644 --- a/admin/casestatus.php +++ b/admin/casestatus.php @@ -1,219 +1,246 @@ - - * @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2013 - * @package queXS - * @subpackage admin - * @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_once(dirname(__FILE__).'/../config.inc.php'); - -/** - * Database file - */ -include ("../db.inc.php"); - -/** - * XHTML functions - */ -include ("../functions/functions.xhtml.php"); - -/** - * Display functions - */ -include("../functions/functions.display.php"); - -/** - * Input functions - */ -include("../functions/functions.input.php"); - -/** - * Generate the case status report - * - * @param mixed $questionnaire_id The quesitonnaire, if specified - * @param string $sample_id The sample, if speified - * @param mixed $outcome_id THe outcome id, if specified - * - * @return false if empty otherwise true if table drawn - * @author Adam Zammit - * @since 2012-10-02 - */ -function case_status_report($questionnaire_id = false, $sample_id = false, $outcome_id = false) -{ - global $db; - - $q = ""; - if ($questionnaire_id !== false) - $q = "AND c.questionnaire_id = $questionnaire_id"; - - $s = ""; - if ($sample_id !== false) - $s = "AND s.import_id = '$sample_id'"; - - $o = ""; - if ($outcome_id !== false) - $o = "AND c.current_outcome_id = $outcome_id"; - - - - - $sql = "SELECT CONCAT('', c.case_id, '') as case_id, - o.description as outcomes, - si.description as samples, - CASE WHEN ca.end IS NULL THEN '" . TQ_("Now") . "' - WHEN TIME_TO_SEC(TIMEDIFF(ca.end,CONVERT_TZ(DATE_SUB(NOW(), INTERVAL co.default_delay_minutes MINUTE),'System','UTC'))) < 0 THEN '" . TQ_("Now") . "' - ELSE ROUND(TIME_TO_SEC(TIMEDIFF(ca.end,CONVERT_TZ(DATE_SUB(NOW(), INTERVAL co.default_delay_minutes MINUTE),'System','UTC'))) / 60) - END AS availableinmin, - CASE WHEN oq.operator_id IS NULL THEN CONCAT('". TQ_("Not assigned, select to assign") ." ','') - ELSE CONCAT('". TQ_("Assigned to") . ": ', oq.firstName, ' " . TQ_("Order") . ":', cq.sortorder , ' (". TQ_("Click to unassign") .")') - END AS assignedoperator - FROM `case` as c - JOIN questionnaire as q ON (q.questionnaire_id = c.questionnaire_id and q.enabled = 1) - JOIN outcome as o ON (o.outcome_id = c.current_outcome_id AND o.outcome_type_id = 1) - JOIN sample as s ON (s.sample_id = c.sample_id $s) - JOIN sample_import as si ON (s.import_id = si.sample_import_id AND si.enabled = 1) - JOIN questionnaire_sample as qs ON (qs.questionnaire_id = q.questionnaire_id AND qs.sample_import_id = s.import_id) - LEFT JOIN `call` as ca ON (ca.call_id = c.last_call_id) - LEFT JOIN outcome as co ON (co.outcome_id = ca.outcome_id) - LEFT JOIN case_queue as cq ON (cq.case_id = c.case_id) - LEFT JOIN operator as oq ON (cq.operator_id = oq.operator_id) - WHERE c.current_operator_id IS NULL $q $o - ORDER BY availableinmin ASC"; - -// print $sql; - - print ("
"); - - xhtml_table($db->GetAll($sql),array('case_id','outcomes','samples','availableinmin','assignedoperator'),array(T_("Case id"),T_("Outcome"),T_("Sample"),T_("Case available in x minutes"),T_("Assigned to operator"))); - - $sql = "SELECT operator_id as value,CONCAT(firstName,' ', lastName) as description, '' selected - FROM operator - WHERE enabled = 1"; - - $rs3 = $db->GetAll($sql); - - print ""; - display_chooser($rs3, "operator_id", "operator_id",true,false,false); - - print (""); - print ("
"); - - return true; -} - -if (isset($_POST['operator_id']) && !empty($_POST['operator_id'])) -{ - $operator_id = intval($_POST['operator_id']); - - $db->StartTrans(); - - $sql = "SELECT MAX(sortorder) - FROM case_queue - WHERE operator_id = '$operator_id'"; - - $sortorder = $db->GetOne($sql); - - foreach($_POST as $key => $val) - { - $sortorder++; - - if (substr($key,0,1) == "c") - { - $sql = "INSERT INTO case_queue (case_id,operator_id,sortorder) - VALUES ('" . bigintval($val) . "', '$operator_id', '$sortorder')"; - - $db->Execute($sql); - } - } - - $db->CompleteTrans(); -} - -if (isset($_GET['unassign'])) -{ - $case_queue_id = bigintval($_GET['unassign']); - - $db->StartTrans(); - - $sql = "SELECT operator_id - FROM case_queue - WHERE case_queue_id = '$case_queue_id'"; - - $operator_id = $db->GetOne($sql); - - $sql = "DELETE FROM case_queue - WHERE case_queue_id = '$case_queue_id'"; - - $db->Execute($sql); - - $sql = "SELECT case_queue_id - FROM case_queue - WHERE operator_id = '$operator_id' - ORDER BY sortorder ASC"; - - $rs = $db->GetAll($sql); - - $sortorder = 1; - foreach($rs as $r) - { - $sql = "UPDATE case_queue - SET sortorder = '$sortorder' - WHERE case_queue_id = '{$r['case_queue_id']}'"; - - $db->Execute($sql); - - $sortorder++; - } - - - $db->CompleteTrans(); - -} - -xhtml_head(T_("Case status and assignment"),true,array("../css/table.css"),array("../js/window.js")); - -print "

" . T_("List cases by questionnaire and sample with the ability to assign them to be called next in a queue by a particular operator. If you assign cases to an operator, it will override the normal scheduling process and call them as soon as the operator is available.") . "

"; - -$questionnaire_id = false; -if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']); -$sample_import_id = false; -if (isset($_GET['sample_import_id']) && !empty($_GET['sample_import_id'])) $sample_import_id = bigintval($_GET['sample_import_id']); -$outcome_id = false; - -print ""; -display_questionnaire_chooser($questionnaire_id); -print ""; -display_sample_chooser($questionnaire_id,$sample_import_id,false); - -if ($questionnaire_id) - case_status_report($questionnaire_id,$sample_import_id,$outcome_id); - - -xhtml_foot(); - -?> + + * @since 2012-10-02 + */ + + +function case_status_report($questionnaire_id = false, $sample_id = false, $outcome_id = false) +{ + global $db; + + $q = ""; + if ($questionnaire_id !== false) + $q = "AND c.questionnaire_id = $questionnaire_id"; + + $s = ""; + if ($sample_id !== false) + $s = "AND s.import_id = '$sample_id'"; + + $o = ""; + if ($outcome_id !== false) + $o = "AND c.current_outcome_id = $outcome_id"; + + $sql = "SELECT CONCAT('', c.case_id, '') as case_id, + o.description as outcomes, + si.description as samples, s.Time_zone_name as timezone, (SELECT COUNT(*) FROM `call` WHERE `call`.case_id = c.case_id) as nrcalls, (SELECT COUNT(*) FROM call_attempt WHERE call_attempt.case_id = c.case_id) as nrattempts, + CASE WHEN ca.end IS NULL THEN '" . TQ_("Available") . "' + WHEN TIME_TO_SEC(TIMEDIFF(ca.end,CONVERT_TZ(DATE_SUB(NOW(), INTERVAL co.default_delay_minutes MINUTE),'System','UTC'))) < 0 THEN '" . TQ_("Available") . "' + ELSE CONCAT(ROUND(TIME_TO_SEC(TIMEDIFF(ca.end,CONVERT_TZ(DATE_SUB(NOW(), INTERVAL co.default_delay_minutes MINUTE),'System','UTC'))) / 60),' " . TQ_("minutes") . "') + END AS availableinmin, + CASE WHEN oq.operator_id IS NULL THEN + CONCAT('') + ELSE CONCAT('', oq.firstName,' ',oq.lastname,'') + END AS assignedoperator, + CASE WHEN oq.operator_id IS NULL THEN + CONCAT('') + ELSE CONCAT('   ', cq.sortorder ,' ') + END AS ordr, + CASE WHEN oq.operator_id IS NULL THEN + CONCAT('') + ELSE CONCAT('') + END AS flag + FROM `case` as c + JOIN questionnaire as q ON (q.questionnaire_id = c.questionnaire_id and q.enabled = 1) + JOIN outcome as o ON (o.outcome_id = c.current_outcome_id AND o.outcome_type_id = 1) + JOIN sample as s ON (s.sample_id = c.sample_id $s) + JOIN sample_import as si ON (s.import_id = si.sample_import_id AND si.enabled = 1) + JOIN questionnaire_sample as qs ON (qs.questionnaire_id = $questionnaire_id AND qs.sample_import_id = s.import_id) + LEFT JOIN `call` as ca ON (ca.call_id = c.last_call_id) + LEFT JOIN outcome as co ON (co.outcome_id = ca.outcome_id) + LEFT JOIN case_queue as cq ON (cq.case_id = c.case_id) + LEFT JOIN operator as oq ON (cq.operator_id = oq.operator_id) + WHERE c.current_operator_id IS NULL $q $o + ORDER BY availableinmin ASC"; + +// print $sql; + + print ("
"); + + xhtml_table($db->GetAll($sql),array('case_id','samples','timezone','nrattempts','nrcalls','outcomes','availableinmin','assignedoperator','ordr','flag'),array(T_("Case id"),T_("Sample"),T_("Timezone"),T_("Call attempts"),T_("Calls"),T_("Outcome"),T_("Available in"),T_("Assigned to"),T_("Order"),""), "tclass",false,false,"bs-table"); + + $sql = "SELECT operator_id as value,CONCAT(firstName,' ', lastName) as description, '' selected + FROM operator + WHERE enabled = 1"; + + $rs3 = $db->GetAll($sql); + + print "

" . T_("Assign selected cases to") . " " . T_("operator") . " : 

"; + display_chooser($rs3, "operator_id", "operator_id",true,false,false,true,false,true,"pull-left"); + + print " "; + print "

"; + + return true; +} + +if (isset($_POST['operator_id']) && !empty($_POST['operator_id'])) +{ + $operator_id = intval($_POST['operator_id']); + + $db->StartTrans(); + + $sql = "SELECT MAX(sortorder) + FROM case_queue + WHERE operator_id = '$operator_id'"; + + $sortorder = $db->GetOne($sql); + + foreach($_POST as $key => $val) + { + $sortorder++; + + if (substr($key,0,1) == "c") + { + $sql = "INSERT INTO case_queue (case_id,operator_id,sortorder) + VALUES ('" . bigintval($val) . "', '$operator_id', '$sortorder')"; + + $db->Execute($sql); + } + } + + $db->CompleteTrans(); +} + +if (isset($_GET['unassign'])) +{ + $case_queue_id = bigintval($_GET['unassign']); + + $db->StartTrans(); + + $sql = "SELECT operator_id + FROM case_queue + WHERE case_queue_id = '$case_queue_id'"; + + $operator_id = $db->GetOne($sql); + + $sql = "DELETE FROM case_queue + WHERE case_queue_id = '$case_queue_id'"; + + $db->Execute($sql); + + $sql = "SELECT case_queue_id + FROM case_queue + WHERE operator_id = '$operator_id' + ORDER BY sortorder ASC"; + + $rs = $db->GetAll($sql); + + $sortorder = 1; + foreach($rs as $r) + { + $sql = "UPDATE case_queue + SET sortorder = '$sortorder' + WHERE case_queue_id = '{$r['case_queue_id']}'"; + + $db->Execute($sql); + + $sortorder++; + } + + $db->CompleteTrans(); +} + +xhtml_head(T_("Case status and assignment"),true,$css,$js_head);//array("../css/table.css"),array("../js/window.js") +echo " " . T_("Go back") . " + "; + ?> + +

" . T_("Questionnaire") . ":

"; +display_questionnaire_chooser($questionnaire_id, false, "pull-left", "form-control"); +print "

" . T_("Sample") . ":

"; +display_sample_chooser($questionnaire_id,$sample_import_id,false, "pull-left", "form-control"); +print " +
"; +if ($questionnaire_id) + case_status_report($questionnaire_id,$sample_import_id,$outcome_id); + +xhtml_foot($js_foot); +?> + \ No newline at end of file