diff --git a/admin/displayappointments.php b/admin/displayappointments.php index 9602a935..b1419501 100644 --- a/admin/displayappointments.php +++ b/admin/displayappointments.php @@ -119,10 +119,13 @@ if (isset($_GET['start']) && isset($_GET['appointment_id'])) $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 + 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"; @@ -156,7 +159,7 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id'])) 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 + $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' @@ -168,6 +171,7 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id'])) { $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']; @@ -188,6 +192,22 @@ if (isset($_GET['appointment_id']) && isset($_GET['case_id'])) 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 "
"; @@ -206,20 +226,21 @@ 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, CONCAT('". T_("Edit") . "') 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('', c.case_id, '') as case_id, CONCAT('". T_("Delete") . "') as link, CONCAT('". T_("Edit") . "') as edit,IFNULL(ao.firstName,'" . T_("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","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 print "

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

"; diff --git a/appointment.php b/appointment.php index 9118def4..d7d1191f 100644 --- a/appointment.php +++ b/appointment.php @@ -99,8 +99,10 @@ if(isset($_POST['start']) && isset($_POST['end']) && isset($_POST['day']) && iss $start = $_POST['start']; $end = $_POST['end']; $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(); @@ -205,6 +207,8 @@ else if(isset($_GET['respondent_id']))
" . T_("Accept appointment from ") .convert_time($_GET['start']).T_(" till ").convert_time($_GET['end']).T_(" on ") . "$day/$month/$year? " . T_("on") . " $phonenum

"; ?>

+ + diff --git a/appointmentlist.php b/appointmentlist.php index 3cf0becf..c75044ae 100644 --- a/appointmentlist.php +++ b/appointmentlist.php @@ -67,10 +67,11 @@ $rs = ""; 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 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 operator AS ao ON (ao.operator_id = c.require_operator_id) WHERE c.case_id = '$case_id' ORDER BY c.start DESC"; @@ -86,7 +87,7 @@ if (empty($rs)) else { 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"))); } diff --git a/functions/functions.calendar.php b/functions/functions.calendar.php index 488e21e2..057ac75c 100644 --- a/functions/functions.calendar.php +++ b/functions/functions.calendar.php @@ -77,18 +77,22 @@ function add_contact_phone($case_id,$phone) * @param int $y the year (4 digit) * @param string $start 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 */ -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; $start = "$y-$m-$d $start"; $end= "$y-$m-$d $end"; + if ($require_operator_id == false) + $require_operator_id = "NULL"; + $sql = "INSERT INTO `appointment` (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 WHERE r.respondent_id = '$respondent_id'"; diff --git a/functions/functions.operator.php b/functions/functions.operator.php index ddd25eae..b102110d 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -382,13 +382,16 @@ function get_case_id($operator_id, $create = false) if ($systemsort) { //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 FROM `case` as c 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 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 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 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 ((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.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 ORDER BY apn.start DESC, a.start ASC, qsep.priority DESC LIMIT 1";