2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

New feature: Allow restricting appointment to just yourself

This commit is contained in:
Adam Zammit
2013-03-07 15:32:09 +11:00
parent 33b3091ad3
commit e311c1df7b
5 changed files with 44 additions and 10 deletions

View File

@@ -119,10 +119,13 @@ if (isset($_GET['start']) && isset($_GET['appointment_id']))
$end = $db->qstr($_GET['end']); $end = $db->qstr($_GET['end']);
$contact_phone_id = bigintval($_GET['contact_phone_id']); $contact_phone_id = bigintval($_GET['contact_phone_id']);
$respondent_id = bigintval($_GET['respondent_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 //Edit this appointment in the database
$sql = "UPDATE appointment as a, respondent as r $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 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 WHERE a.appointment_id = $appointment_id
AND r.respondent_id = $respondent_id"; AND r.respondent_id = $respondent_id";
@@ -156,7 +159,7 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id']))
xhtml_head(T_("Edit appointment"),false,$css,$js); xhtml_head(T_("Edit appointment"),false,$css,$js);
print "<script type='text/javascript'>$(document).ready(function() { $('#start').datetimepicker({timeFormat: 'hh:mm:ss', dateFormat: 'yy-mm-dd'}); $('#end').datetimepicker({timeFormat: 'hh:mm:ss', dateFormat: 'yy-mm-dd'});});</script>"; print "<script type='text/javascript'>$(document).ready(function() { $('#start').datetimepicker({timeFormat: 'hh:mm:ss', dateFormat: 'yy-mm-dd'}); $('#end').datetimepicker({timeFormat: 'hh:mm:ss', dateFormat: 'yy-mm-dd'});});</script>";
$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 $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 FROM appointment as a, respondent as r
WHERE a.appointment_id = '$appointment_id' WHERE a.appointment_id = '$appointment_id'
AND a.case_id = '$case_id' AND a.case_id = '$case_id'
@@ -168,6 +171,7 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id']))
{ {
$respondent_id = $rs['respondent_id']; $respondent_id = $rs['respondent_id'];
$contact_phone_id = $rs['contact_phone_id']; $contact_phone_id = $rs['contact_phone_id'];
$require_operator_id = $rs['require_operator_id'];
$start = $rs['start']; $start = $rs['start'];
$end = $rs['end']; $end = $rs['end'];
@@ -188,6 +192,22 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id']))
print "</div><div><label for='start'>" . T_("Start time") . "</label><input type='text' value='$start' id='start' name='start'/></div>"; print "</div><div><label for='start'>" . T_("Start time") . "</label><input type='text' value='$start' id='start' name='start'/></div>";
print "<div><label for='end'>" . T_("End time") . "</label><input type='text' value='$end' id='end' name='end'/></div>"; print "<div><label for='end'>" . T_("End time") . "</label><input type='text' value='$end' id='end' name='end'/></div>";
print "<div><label for='require_operator_id'>" . T_("Appointment with") . "</label>";
$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 "<input type='hidden' value='$appointment_id' id='appointment_id' name='appointment_id'/>"; print "<input type='hidden' value='$appointment_id' id='appointment_id' name='appointment_id'/>";
print "<div><input type='submit' value='" . T_("Edit appointment") . "'/></div>"; print "<div><input type='submit' value='" . T_("Edit appointment") . "'/></div>";
@@ -206,20 +226,21 @@ else
print "<h1>" . T_("Appointments") . "</h1><h2>" . T_("All appointments (with times displayed in your time zone)") . "</h2>"; print "<h1>" . T_("Appointments") . "</h1><h2>" . T_("All appointments (with times displayed in your time zone)") . "</h2>";
$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('<a href=\'supervisor.php?case_id=', c.case_id, '\'>', c.case_id, '</a>') as case_id, CONCAT('<a href=\'?case_id=', c.case_id, '&amp;appointment_id=', a.appointment_id, '&amp;delete=delete\'>". T_("Delete") . "</a>') as link, CONCAT('<a href=\'?case_id=', c.case_id, '&amp;appointment_id=', a.appointment_id, '\'>". T_("Edit") . "</a>') as edit $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('<a href=\'supervisor.php?case_id=', c.case_id, '\'>', c.case_id, '</a>') as case_id, CONCAT('<a href=\'?case_id=', c.case_id, '&amp;appointment_id=', a.appointment_id, '&amp;delete=delete\'>". T_("Delete") . "</a>') as link, CONCAT('<a href=\'?case_id=', c.case_id, '&amp;appointment_id=', a.appointment_id, '\'>". T_("Edit") . "</a>') as edit,IFNULL(ao.firstName,'" . T_("Any operator") . "') as witho
FROM appointment as a 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) 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 (`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') WHERE a.end >= CONVERT_TZ(NOW(),'System','UTC')
ORDER BY a.start ASC"; ORDER BY a.start ASC";
$rs = $db->GetAll($sql); $rs = $db->GetAll($sql);
if (!empty($rs)) if (!empty($rs))
{ {
translate_array($rs,array("outcome")); translate_array($rs,array("outcome"));
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"))); 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 else
print "<p>" . T_("No appointments in the future") . "</p>"; print "<p>" . T_("No appointments in the future") . "</p>";

View File

@@ -99,8 +99,10 @@ if(isset($_POST['start']) && isset($_POST['end']) && isset($_POST['day']) && iss
$start = $_POST['start']; $start = $_POST['start'];
$end = $_POST['end']; $end = $_POST['end'];
$call_attempt_id = get_call_attempt($operator_id,false); $call_attempt_id = get_call_attempt($operator_id,false);
$require_operator_id = false;
if (isset($_POST['require_operator_id'])) $require_operator_id = bigintval($_POST['require_operator_id']);
make_appointment($respondent_id,$case_id,$contact_phone_id,$call_attempt_id,$day,$month,$year,$start,$end); make_appointment($respondent_id,$case_id,$contact_phone_id,$call_attempt_id,$day,$month,$year,$start,$end,$require_operator_id);
$db->CompleteTrans(); $db->CompleteTrans();
@@ -205,6 +207,8 @@ else if(isset($_GET['respondent_id']))
<form id="appointment" method="post" action=""> <form id="appointment" method="post" action="">
<?php print "<p>" . T_("Accept appointment from ") .convert_time($_GET['start']).T_(" till ").convert_time($_GET['end']).T_(" on ") . "$day/$month/$year? " . T_("on") . " $phonenum </p>"; ?> <?php print "<p>" . T_("Accept appointment from ") .convert_time($_GET['start']).T_(" till ").convert_time($_GET['end']).T_(" on ") . "$day/$month/$year? " . T_("on") . " $phonenum </p>"; ?>
<p> <p>
<?php print "<p><label for='require_operator_id'>" . T_("Appointment with myself only?"); ?></label>
<input type="checkbox" id="require_operator_id" name="require_operator_id" value="<?php echo $operator_id;?>">
<input type="hidden" name="start" value="<?php print $_GET['start']; ?>"/> <input type="hidden" name="start" value="<?php print $_GET['start']; ?>"/>
<input type="hidden" name="end" value="<?php print $_GET['end']; ?>"/> <input type="hidden" name="end" value="<?php print $_GET['end']; ?>"/>
<input type="hidden" name="day" value="<?php print $day; ?>"/> <input type="hidden" name="day" value="<?php print $day; ?>"/>

View File

@@ -67,10 +67,11 @@ $rs = "";
if ($case_id) if ($case_id)
{ {
$sql = "SELECT DATE_FORMAT(CONVERT_TZ(c.start,'UTC',r.Time_zone_name),'".DATE_TIME_FORMAT."') as start,DATE_FORMAT(CONVERT_TZ(c.end,'UTC',r.Time_zone_name),'".TIME_FORMAT."') as end, c.completed_call_id, IFNULL(ou.firstName,'" . T_("Not yet called") . "') as firstName, CONCAT(r.firstName, ' ', r.lastName) as respname, IFNULL(o.description,'" . T_("Not yet called") . "') as des $sql = "SELECT DATE_FORMAT(CONVERT_TZ(c.start,'UTC',r.Time_zone_name),'".DATE_TIME_FORMAT."') as start,DATE_FORMAT(CONVERT_TZ(c.end,'UTC',r.Time_zone_name),'".TIME_FORMAT."') as end, c.completed_call_id, IFNULL(ou.firstName,'" . T_("Not yet called") . "') as firstName, CONCAT(r.firstName, ' ', r.lastName) as respname, IFNULL(o.description,'" . T_("Not yet called") . "') as des, IFNULL(ao.firstName,'" . T_("Any operator") . "') as witho
FROM `appointment` as c FROM `appointment` as c
JOIN respondent as r on (r.respondent_id = c.respondent_id) JOIN respondent as r on (r.respondent_id = c.respondent_id)
LEFT JOIN (`call` as ca, outcome as o, operator as ou) on (ca.call_id = c.completed_call_id and ca.outcome_id = o.outcome_id and ou.operator_id = ca.operator_id) LEFT JOIN (`call` as ca, outcome as o, operator as ou) on (ca.call_id = c.completed_call_id and ca.outcome_id = o.outcome_id and ou.operator_id = ca.operator_id)
LEFT JOIN operator AS ao ON (ao.operator_id = c.require_operator_id)
WHERE c.case_id = '$case_id' WHERE c.case_id = '$case_id'
ORDER BY c.start DESC"; ORDER BY c.start DESC";
@@ -86,7 +87,7 @@ if (empty($rs))
else else
{ {
translate_array($rs,array("des")); translate_array($rs,array("des"));
xhtml_table($rs,array("start","end","respname","des","firstName"),array(T_("Start"),T_("End"),T_("Respondent"),T_("Outcome"),T_("Operator"))); xhtml_table($rs,array("start","end","respname","witho","des","firstName"),array(T_("Start"),T_("End"),T_("Respondent"),T_("Appointment with"),T_("Outcome"),T_("Operator")));
} }

View File

@@ -77,18 +77,22 @@ function add_contact_phone($case_id,$phone)
* @param int $y the year (4 digit) * @param int $y the year (4 digit)
* @param string $start The time in the format HH:MM:SS * @param string $start The time in the format HH:MM:SS
* @param string $end The time in the format HH:MM:SS * @param string $end The time in the format HH:MM:SS
* @param string|int $require_operator_id False if for any operator otherwise restrict this appointment to a particular operator
* @return bool Result false if failed to add else true * @return bool Result false if failed to add else true
*/ */
function make_appointment($respondent_id,$case_id,$contact_phone_id,$call_attempt_id,$d,$m,$y,$start,$end) function make_appointment($respondent_id,$case_id,$contact_phone_id,$call_attempt_id,$d,$m,$y,$start,$end,$require_operator_id = false)
{ {
global $db; global $db;
$start = "$y-$m-$d $start"; $start = "$y-$m-$d $start";
$end= "$y-$m-$d $end"; $end= "$y-$m-$d $end";
if ($require_operator_id == false)
$require_operator_id = "NULL";
$sql = "INSERT INTO `appointment` $sql = "INSERT INTO `appointment`
(appointment_id,case_id,contact_phone_id,call_attempt_id,start,end,require_operator_id,respondent_id,completed_call_id) (appointment_id,case_id,contact_phone_id,call_attempt_id,start,end,require_operator_id,respondent_id,completed_call_id)
SELECT NULL,'$case_id','$contact_phone_id','$call_attempt_id',CONVERT_TZ('$start',r.Time_zone_name,'UTC'),CONVERT_TZ('$end',r.Time_zone_name,'UTC'),NULL,$respondent_id,NULL SELECT NULL,'$case_id','$contact_phone_id','$call_attempt_id',CONVERT_TZ('$start',r.Time_zone_name,'UTC'),CONVERT_TZ('$end',r.Time_zone_name,'UTC'),$require_operator_id,$respondent_id,NULL
FROM respondent as r FROM respondent as r
WHERE r.respondent_id = '$respondent_id'"; WHERE r.respondent_id = '$respondent_id'";

View File

@@ -382,13 +382,16 @@ function get_case_id($operator_id, $create = false)
if ($systemsort) if ($systemsort)
{ {
//Just make sure that this case should go to this operator (assigned to this project and skill) //Just make sure that this case should go to this operator (assigned to this project and skill)
//Also check if this is an exclusive appointment
$sql = "SELECT c.case_id as caseid $sql = "SELECT c.case_id as caseid
FROM `case` as c FROM `case` as c
JOIN operator_questionnaire AS oq ON (oq.operator_id = '$operator_id' AND oq.questionnaire_id = c.questionnaire_id) JOIN operator_questionnaire AS oq ON (oq.operator_id = '$operator_id' AND oq.questionnaire_id = c.questionnaire_id)
JOIN outcome as ou ON (ou.outcome_id = c.current_outcome_id) JOIN outcome as ou ON (ou.outcome_id = c.current_outcome_id)
JOIN operator_skill as os ON (os.operator_id = '$operator_id' AND os.outcome_type_id = ou.outcome_type_id) JOIN operator_skill as os ON (os.operator_id = '$operator_id' AND os.outcome_type_id = ou.outcome_type_id)
LEFT JOIN appointment as apn on (apn.case_id = c.case_id AND apn.completed_call_id is NULL AND (CONVERT_TZ(NOW(),'System','UTC') >= apn.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= apn.end))
WHERE c.sortorder IS NOT NULL WHERE c.sortorder IS NOT NULL
AND c.current_operator_id IS NULL AND c.current_operator_id IS NULL
AND (apn.require_operator_id IS NULL OR apn.require_operator_id = '$operator_id')
ORDER BY c.sortorder ASC ORDER BY c.sortorder ASC
LIMIT 1"; LIMIT 1";
@@ -438,6 +441,7 @@ function get_case_id($operator_id, $create = false)
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL AND os.outcome_type_id != 2) AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL AND os.outcome_type_id != 2)
AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE case_id = c.case_id) < qs.call_attempt_max)) AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE case_id = c.case_id) < qs.call_attempt_max))
AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max)) AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max))
AND (apn.require_operator_id IS NULL OR apn.require_operator_id = '$operator_id')
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
ORDER BY apn.start DESC, a.start ASC, qsep.priority DESC ORDER BY apn.start DESC, a.start ASC, qsep.priority DESC
LIMIT 1"; LIMIT 1";