diff --git a/admin/displayappointments.php b/admin/displayappointments.php index 3b10cc46..1e2df60a 100644 --- a/admin/displayappointments.php +++ b/admin/displayappointments.php @@ -54,13 +54,91 @@ include ("../functions/functions.operator.php"); */ 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']); + + //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 + 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'])) { - $appointment_id = bigintval($_GET['appointment_id']); - $case_id = bigintval($_GET['case_id']); - $sql = "DELETE FROM appointment WHERE appointment_id = '$appointment_id'"; @@ -70,27 +148,53 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id'])) print "

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

"; print "

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

"; - } - else if (isset($_GET['start'])) - { - //Edit this appointment in the database - - } else { //Display an edit form xhtml_head(T_("Edit appointment")); + $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 + 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']; + $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 ""; + print "
"; + + print "

"; + print "

" . T_("Cancel edit") . "

"; + } } } -else if (isset($_GET['new'])) -{ - -} else { @@ -100,7 +204,8 @@ else 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,'" . T_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, CONCAT('', c.case_id, '') as case_id, CONCAT('". T_("Delete") . "') as link + $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,'" . T_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, CONCAT('', c.case_id, '') as case_id, CONCAT('". T_("Delete") . "') as link, CONCAT('". T_("Edit") . "') as edit + 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) @@ -112,7 +217,7 @@ else if (!empty($rs)) { translate_array($rs,array("outcome")); - xhtml_table($rs,array("description","case_id","start","end","makerName","firstName","lastName","outcome","callerName","link"),array(T_("Questionnaire"),T_("Case ID"),T_("Start"),T_("End"),T_("Operator Name"),T_("Respondent Name"),T_("Surname"),T_("Current outcome"),T_("Operator who called"),T_("Delete"))); + xhtml_table($rs,array("description","case_id","start","end","makerName","firstName","lastName","outcome","callerName","link","edit"),array(T_("Questionnaire"),T_("Case ID"),T_("Start"),T_("End"),T_("Operator Name"),T_("Respondent Name"),T_("Surname"),T_("Current outcome"),T_("Operator who called"),T_("Delete"),T_("Edit"))); } else print "

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

"; @@ -121,4 +226,3 @@ else xhtml_foot(); ?> - diff --git a/admin/supervisor.php b/admin/supervisor.php index 4af4b8e9..bdadebe2 100644 --- a/admin/supervisor.php +++ b/admin/supervisor.php @@ -175,7 +175,7 @@ if ($case_id != false) print "

" . T_("Appointments")."

"; //View appointments - $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,'" . T_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, CONCAT('', c.case_id, '') as case_id, CONCAT('". T_("Delete") . "') as link + $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,'" . T_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, CONCAT('', c.case_id, '') as case_id, CONCAT('". T_("Delete") . "') as link, CONCAT('". T_("Edit") . "') as edit 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 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) @@ -188,11 +188,12 @@ if ($case_id != false) if (!empty($rs)) { translate_array($rs,array("outcome")); - xhtml_table($rs,array("description","start","end","makerName","firstName","lastName","outcome","callerName","link"),array(T_("Questionnaire"),T_("Start"),T_("End"),T_("Operator Name"),T_("Respondent Name"),T_("Surname"),T_("Current outcome"),T_("Operator who called"),T_("Delete"))); + xhtml_table($rs,array("description","start","end","makerName","firstName","lastName","outcome","callerName","link","edit"),array(T_("Questionnaire"),T_("Start"),T_("End"),T_("Operator Name"),T_("Respondent Name"),T_("Surname"),T_("Current outcome"),T_("Operator who called"),T_("Delete"),T_("Edit"))); } else print "

" . T_("No appointments for this case") . "

"; + print "

" . T_("Create appointment for this case") . "

"; //view calls and outcomes