diff --git a/admin/displayappointments.php b/admin/displayappointments.php index 6f44cb56..54d36ca1 100644 --- a/admin/displayappointments.php +++ b/admin/displayappointments.php @@ -1,251 +1,257 @@ - - * @copyright Deakin University 2007,2008 - * @package queXS - * @subpackage admin - * @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility - * @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"); - -/** - * Operator functions - */ -include ("../functions/functions.operator.php"); - -/** - * Input functions - */ -include ("../functions/functions.input.php"); - -/** - * Calendar functions - */ -include ("../functions/functions.calendar.php"); - -//Create a new blank appointment and then edit it -if (isset($_GET['new']) && isset($_GET['case_id'])) -{ - $case_id = bigintval($_GET['case_id']); - - $db->StartTrans(); - - //First create a call attempt - $operator_id = get_operator_id(); - - if ($operator_id == false) die(); - - //get the first respondent id for this case - $sql = "SELECT respondent_id - FROM respondent - WHERE case_id = '$case_id'"; - - $rs = $db->GetRow($sql); - - $respondent_id = $rs['respondent_id']; - - //get the first contact_phone_id for this case - $sql = "SELECT contact_phone_id - FROM contact_phone - WHERE case_id = '$case_id'"; - - $rs = $db->GetRow($sql); - - $contact_phone_id = $rs['contact_phone_id']; - - $sql = "INSERT INTO call_attempt (call_attempt_id,case_id,operator_id,respondent_id,start,end) - VALUES (NULL,$case_id,$operator_id,$respondent_id,CONVERT_TZ(NOW(),'System','UTC'),CONVERT_TZ(NOW(),'System','UTC'))"; - - $db->Execute($sql); - - $call_attempt_id = $db->Insert_ID(); - - - $sql = "INSERT INTO `appointment` - (appointment_id,case_id,contact_phone_id,call_attempt_id,start,end,require_operator_id,respondent_id,completed_call_id) - VALUES (NULL,'$case_id','$contact_phone_id','$call_attempt_id',CONVERT_TZ(NOW() + INTERVAL 1 DAY,'System','UTC'),CONVERT_TZ(NOW() + INTERVAL 1 DAY,'System','UTC'),NULL,$respondent_id,NULL)"; - - $db->Execute($sql); - - - $appointment_id = $db->Insert_ID(); - - $db->CompleteTrans(); - - $_GET['appointment_id'] = $appointment_id; -} - - -//update appointment -if (isset($_GET['start']) && isset($_GET['appointment_id'])) -{ - $appointment_id = bigintval($_GET['appointment_id']); - $start = $db->qstr($_GET['start']); - $end = $db->qstr($_GET['end']); - $contact_phone_id = bigintval($_GET['contact_phone_id']); - $respondent_id = bigintval($_GET['respondent_id']); - $require_operator_id = "NULL"; - if ($_GET['require_operator_id'] > 1) $require_operator_id = bigintval($_GET['require_operator_id']); - - //Edit this appointment in the database - $sql = "UPDATE appointment as a, respondent as r - SET a.start = CONVERT_TZ($start,r.Time_zone_name,'UTC'), a.end = CONVERT_TZ($end,r.Time_zone_name,'UTC'), a.contact_phone_id = $contact_phone_id, a.respondent_id = $respondent_id, - a.require_operator_id = $require_operator_id - WHERE a.appointment_id = $appointment_id - AND r.respondent_id = $respondent_id"; - - $db->Execute($sql); -} - - - -if (isset($_GET['appointment_id']) && isset($_GET['case_id'])) -{ - $appointment_id = bigintval($_GET['appointment_id']); - $case_id = bigintval($_GET['case_id']); - - if (isset($_GET['delete'])) - { - $sql = "DELETE FROM appointment - WHERE appointment_id = '$appointment_id'"; - - $db->Execute($sql); - - xhtml_head(T_("Now modify case outcome")); - - print "

" . T_("The appointment has been deleted. Now you must modify the case outcome") . "

"; - print "

" . T_("Modify case outcome") . "

"; - } - else - { - //Display an edit form - $css = array("../css/timepicker.css","../include/jquery-ui/css/smoothness/jquery-ui-1.8.2.custom.css"); - $js = array("../include/jquery-ui/js/jquery-1.4.2.min.js","../include/jquery-ui/js/jquery-ui-1.8.2.custom.min.js","../include/timepicker/jquery-ui-timepicker-addon.js"); - xhtml_head(T_("Edit appointment"),false,$css,$js); - print ""; - - $sql = "SELECT a.contact_phone_id,a.call_attempt_id,CONVERT_TZ(a.start,'UTC',r.Time_zone_name) as start,CONVERT_TZ(a.end,'UTC',r.Time_zone_name) as end,a.respondent_id,a.require_operator_id - FROM appointment as a, respondent as r - WHERE a.appointment_id = '$appointment_id' - AND a.case_id = '$case_id' - AND r.respondent_id = a.respondent_id"; - - $rs = $db->GetRow($sql); - - if (!empty($rs)) - { - $respondent_id = $rs['respondent_id']; - $contact_phone_id = $rs['contact_phone_id']; - $require_operator_id = $rs['require_operator_id']; - $start = $rs['start']; - $end = $rs['end']; - - print "

"; - print "
"; - display_chooser($db->GetAll("SELECT respondent_id as value, firstname as description, CASE when respondent_id = '$respondent_id' THEN 'selected=\'selected\'' ELSE '' END as selected - FROM respondent - WHERE case_id = '$case_id'"),"respondent_id","respondent_id",false,false,false,false); - - - print "
"; - display_chooser($db->GetAll("SELECT contact_phone_id as value, - phone as description, - CASE when contact_phone_id = '$contact_phone_id' THEN 'selected=\'selected\'' ELSE '' END as selected - FROM contact_phone - WHERE case_id = '$case_id'"), - "contact_phone_id","contact_phone_id",false,false,false,false); - - print "
"; - print "
"; - print "
"; - $ops = $db->GetAll(" SELECT o.operator_id as value, - CONCAT(o.firstName, ' ', o.lastName) as description, - CASE WHEN o.operator_id = '$require_operator_id' THEN 'selected=\'selected\'' ELSE '' END as selected - FROM operator as o"); - $selected = "selected=\'selected\'"; - foreach($ops as $o) - { - if (!empty($o['selected'])) - { - $selected = ""; - break; - } - } - array_unshift($ops,array('value'=>0,'description'=>T_("Any operator"),'selected'=>$selected)); - display_chooser($ops,"require_operator_id","require_operator_id",false,false,false,false); - print ""; - print "
"; - - print "

"; - print "

" . T_("Cancel edit") . "

"; - print "

" . T_("Delete this appointment") . "

"; - } - } -} -else -{ - - $operator_id = get_operator_id(); - - xhtml_head(T_("Display Appointments"),true,array("../css/table.css")); - - print "

" . T_("Appointments") . "

" . T_("All appointments (with times displayed in your time zone)") . "

"; - - $sql = "SELECT q.description, CONVERT_TZ(a.start,'UTC',o.Time_zone_name) as start, CONVERT_TZ(a.end,'UTC',o.Time_zone_name) as end, r.firstName, r.lastName, IFNULL(ou.description,'" . TQ_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, CONCAT('', c.case_id, '') as case_id, CONCAT('". TQ_("Delete") . "') as link, CONCAT('". TQ_("Edit") . "') as edit,IFNULL(ao.firstName,'" . TQ_("Any operator") . "') as witho - - FROM appointment as a - JOIN (`case` as c, respondent as r, questionnaire as q, operator as o, operator as oo, call_attempt as cc) on (a.case_id = c.case_id and a.respondent_id = r.respondent_id and q.questionnaire_id = c.questionnaire_id and o.operator_id = '$operator_id' and a.call_attempt_id = cc.call_attempt_id and cc.operator_id = oo.operator_id) - LEFT JOIN (`call` as ca, outcome as ou, operator as ooo) ON (ca.call_id = a.completed_call_id and ou.outcome_id = ca.outcome_id and ca.operator_id = ooo.operator_id) - LEFT JOIN operator AS ao ON ao.operator_id = a.require_operator_id - WHERE a.end >= CONVERT_TZ(NOW(),'System','UTC') - ORDER BY a.start ASC"; - - $rs = $db->GetAll($sql); - - if (!empty($rs)) - { - translate_array($rs,array("outcome")); - xhtml_table($rs,array("description","case_id","start","end","makerName","witho","firstName","lastName","outcome","callerName","link","edit"),array(T_("Questionnaire"),T_("Case ID"),T_("Start"),T_("End"),T_("Operator Name"),T_("Appointment with"),T_("Respondent Name"),T_("Surname"),T_("Current outcome"),T_("Operator who called"),T_("Delete"),T_("Edit"))); - } - else - print "

" . T_("No appointments in the future") . "

"; - -} -xhtml_foot(); - -?> +qstr($_GET['start']); + $end = $db->qstr($_GET['end']); + $contact_phone_id = bigintval($_GET['contact_phone_id']); + $respondent_id = bigintval($_GET['respondent_id']); + $require_operator_id = "NULL"; + if ($_GET['require_operator_id'] > 1) $require_operator_id = bigintval($_GET['require_operator_id']); + + if ($_GET['new'] == 'create'){ + $case_id = bigintval($_GET['case_id']); + $operator_id = get_operator_id(); + if ($operator_id == false) die(); + $sql = "SELECT Time_zone_name FROM respondent WHERE respondent_id = '$respondent_id'"; + $respondent_tz = $db->GetOne($sql); + + // create a call attempt + $sql = "INSERT INTO call_attempt (call_attempt_id,case_id,operator_id,respondent_id,start,end) + VALUES (NULL,$case_id,$operator_id,$respondent_id,CONVERT_TZ(NOW(),@@session.time_zone,'UTC'),CONVERT_TZ(NOW(),@@session.time_zone,'UTC'))"; + $db->Execute($sql); + + $call_attempt_id = $db->Insert_ID(); + + $sql = "INSERT INTO `appointment` (appointment_id,case_id,contact_phone_id,call_attempt_id,start,end,require_operator_id,respondent_id,completed_call_id) + VALUES(NULL,$case_id,$contact_phone_id,$call_attempt_id,CONVERT_TZ($start,'$respondent_tz','UTC'),CONVERT_TZ($end,'$respondent_tz','UTC'),$require_operator_id,$respondent_id,NULL)"; + $db->Execute($sql); + + $appointment_id = $db->Insert_ID(); + + $_GET['appointment_id'] = $appointment_id; + $appointment_id = bigintval($_GET['appointment_id']); + + } else { + + $appointment_id = bigintval($_GET['appointment_id']); + + //Edit this appointment in the database + $sql = "UPDATE appointment as a, respondent as r + SET a.start = CONVERT_TZ($start,r.Time_zone_name,'UTC'), a.end = CONVERT_TZ($end,r.Time_zone_name,'UTC'), a.contact_phone_id = $contact_phone_id, a.respondent_id = $respondent_id, a.require_operator_id = $require_operator_id + WHERE a.appointment_id = $appointment_id + AND r.respondent_id = $respondent_id"; + + $db->Execute($sql); + } + unset ($_GET['start'],$_GET['end'],$_GET['appointment_id'],$_GET['case_id'],$_GET['new'],$_GET['update']); +} + + +if ( (isset($_GET['appointment_id']) && isset($_GET['case_id'])) ||(($_GET['new'] == 'new') && isset($_GET['case_id']))) +{ + $appointment_id = bigintval($_GET['appointment_id']); + $case_id = bigintval($_GET['case_id']); + + if (isset($_GET['delete'])) + { + $sql = "DELETE FROM appointment + WHERE appointment_id = '$appointment_id'"; + $db->Execute($sql); + + xhtml_head(T_("Now modify case outcome"),true,$css,$js_head); + + print "

" . T_("The appointment has been deleted. Now you must modify the case outcome") . "

+ " . T_("Modify case outcome") . "
"; + } + else + { + //Display an edit form + + if ($_GET['new'] == 'new'){$title = T_("Create NEW appointment");} else{$title = T_("Edit appointment"); $subtitle = "ID " . $appointment_id;} + + xhtml_head($title,true,$css,$js_head,false,false,false,$subtitle); + $lang = DEFAULT_LOCALE; + print ""; + + if ($_GET['new'] =='new'){ + $start = date("Y-m-d H:m:s"); + $end = date("Y-m-d H:m:s", mktime(0,0,0,date("m"),date("d")+7,date("Y"))); + $rtz = $_GET['rtz']; + } + if (isset($_GET['appointment_id'])) { + + $sql = "SELECT a.contact_phone_id,a.call_attempt_id, CONVERT_TZ(a.start,'UTC',r.Time_zone_name) as `start`, CONVERT_TZ(a.end,'UTC',r.Time_zone_name) as `end`, a.respondent_id, a.require_operator_id, r.Time_zone_name as rtz + FROM `appointment` as a, respondent as r + WHERE a.appointment_id = '$appointment_id' + AND a.case_id = '$case_id' + AND r.respondent_id = a.respondent_id"; + + $rs = $db->GetRow($sql); + + if (!empty($rs)){ + $respondent_id = $rs['respondent_id']; + $contact_phone_id = $rs['contact_phone_id']; + $require_operator_id = $rs['require_operator_id']; + $start = $rs['start']; + $end = $rs['end']; + $rtz = $rs['rtz']; + } + } + print "
"; + print ""; + + display_chooser($db->GetAll("SELECT respondent_id as value, CONCAT(firstName,' ',lastName) as description, + CASE when respondent_id = '$respondent_id' THEN 'selected=\'selected\'' ELSE '' END as selected + FROM respondent + WHERE case_id = '$case_id'"),"respondent_id","respondent_id",false,false,false,true,false,true,"pull-left"); + + print "

"; + display_chooser($db->GetAll("SELECT contact_phone_id as value, phone as description, + CASE when contact_phone_id = '$contact_phone_id' THEN 'selected=\'selected\'' ELSE '' END as selected + FROM contact_phone + WHERE case_id = '$case_id'"), + "contact_phone_id","contact_phone_id",false,false,false,true,false,true,"pull-left"); + + print "

". T_("ATTENTION! Keep in mind that you're setting 'Start' & 'End' appoinment times in RESPONDENT LOCAL TIME !!!") . "
"; + date_default_timezone_set($rtz); + print " +

" . $rtz . "

+ "; + + print "

+
"; + print "

+
"; + print "

"; + $ops = $db->GetAll("SELECT o.operator_id as value, + CONCAT(o.firstName, ' ', o.lastName) as description, + CASE WHEN o.operator_id = '$require_operator_id' THEN 'selected=\'selected\'' ELSE '' END as selected + FROM operator as o"); + $selected = "selected=\'selected\'"; + foreach($ops as $o) + { + if (!empty($o['selected'])) + { + $selected = ""; + break; + } + } + array_unshift($ops,array('value'=>0,'description'=>T_("Any operator"),'selected'=>$selected)); + display_chooser($ops,"require_operator_id","require_operator_id",false,false,false,true,false,true,"pull-left"); + print ""; + + if ($_GET['new'] == 'new') { print "";} + + print "


+ "; + + print "
"; + + print ""; + + print "
"; + } +} +else { + $operator_id = get_operator_id(); + $subtitle = T_("Appointments"); + xhtml_head(T_("Display Appointments"),true,$css,$js_head, false,30); //array("../css/table.css") + + print "

" . T_("All appointments (with times displayed in your time zone)") . "

"; + + $sql = "SELECT q.description, CONVERT_TZ(a.start,'UTC',@@session.time_zone) as start, CONVERT_TZ(a.end,'UTC',@@session.time_zone) as end, CONCAT(r.firstName, ' ', r.lastName) as resp, IFNULL(ou.description,'" . TQ_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, + CONCAT('', c.case_id, '') as case_id, + CONCAT('  ') as link, + CONCAT('  ') as edit,IFNULL(ao.firstName,'" . TQ_("Any operator") . "') as witho + FROM appointment as a + JOIN (`case` as c, respondent as r, questionnaire as q, operator as oo, call_attempt as cc) on (a.case_id = c.case_id and a.respondent_id = r.respondent_id and q.questionnaire_id = c.questionnaire_id and a.call_attempt_id = cc.call_attempt_id and cc.operator_id = oo.operator_id) + LEFT JOIN (`call` as ca, outcome as ou, operator as ooo) ON (ca.call_id = a.completed_call_id and ou.outcome_id = ca.outcome_id and ca.operator_id = ooo.operator_id) + LEFT JOIN operator AS ao ON ao.operator_id = a.require_operator_id + WHERE a.end >= CONVERT_TZ(NOW(),'System','UTC') + ORDER BY a.start ASC"; + + $rs = $db->GetAll($sql); + if (!empty($rs)) { + translate_array($rs,array("outcome")); + xhtml_table($rs,array("description","case_id","start","end","edit","makerName","witho","resp","outcome","callerName","link"),array(T_("Questionnaire"),T_("Case ID"),T_("Start"),T_("End"),"  ",T_("Created by"),T_("Appointment with"),T_("Respondent"),T_("Current outcome"),T_("Operator who called"),"  "),"tclass",false,false,"bs-table"); + + } else print "

" . T_("No appointments in the future") . "

"; + +} +xhtml_foot($js_foot); +?> + \ No newline at end of file