From 86778608d70831e0bba7bc957eeed13dd502f297 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 9 Sep 2016 10:41:53 +1000 Subject: [PATCH] Fix timezone issues with using @@session --- admin/displayappointments.php | 16 +++++++++------- admin/supervisor.php | 9 +++++---- admin/timezonetemplate.php | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/admin/displayappointments.php b/admin/displayappointments.php index 00e49079..4e19f33f 100644 --- a/admin/displayappointments.php +++ b/admin/displayappointments.php @@ -88,7 +88,7 @@ if (isset($_GET['start']) && isset($_GET['end']) && isset($_GET['update'])) // 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'))"; + 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(); @@ -292,19 +292,20 @@ else { xhtml_head(T_("Display Appointments"),true,$css,$js_head,false,30); print "

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

"; - $sql = "SELECT MIN(q.description) as description, MIN(si.description) as smpl, MIN(CONVERT_TZ(a.start,'UTC',@@session.time_zone)) as start, MIN(CONVERT_TZ(a.end,'UTC',@@session.time_zone)) as end,MIN(CONCAT(r.firstName, ' ', r.lastName)) as resp, MIN( IFNULL(ou.description,'" . TQ_("Not yet called") . "')) as outcome, MIN(oo.firstName) as makerName, MIN(ooo.firstName) as callerName, + $sql = "SELECT MIN(q.description) as description, MIN(si.description) as smpl, MIN(CONVERT_TZ(a.start,'UTC',co.Time_zone_name)) as start, MIN(CONVERT_TZ(a.end,'UTC',co.Time_zone_name)) as end,MIN(CONCAT(r.firstName, ' ', r.lastName)) as resp, MIN( IFNULL(ou.description,'" . TQ_("Not yet called") . "')) as outcome, MIN(oo.firstName) as makerName, MIN(ooo.firstName) as callerName, CONCAT('', c.case_id, '') as case_id, MIN(CONCAT('  ')) as link, MIN(CONCAT('  ')) as edit,MIN(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, `sample` as s, sample_import as si) on (c.sample_id = s.sample_id and 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 and si.sample_import_id = s.import_id) + JOIN (`case` as c, respondent as r, questionnaire as q, operator as oo, call_attempt as cc, operator as co, `sample` as s, sample_import as si) on (c.sample_id = s.sample_id and 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 and si.sample_import_id = s.import_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 LEFT JOIN (questionnaire_sample_quota as qsq) on (s.import_id = qsq.sample_import_id and c.questionnaire_id = qsq.questionnaire_id) LEFT JOIN (questionnaire_sample_quota_row as qsqr) on (s.import_id = qsqr.sample_import_id and c.questionnaire_id = qsqr.questionnaire_id) - WHERE q.enabled=1 AND si.enabled=1 AND a.end >= CONVERT_TZ(NOW(),'System','UTC') AND c.current_outcome_id IN (19,20,21,22) + WHERE q.enabled=1 AND si.enabled=1 AND a.end >= CONVERT_TZ(NOW(),'System','UTC') AND (qsq.quota_reached IS NULL OR qsq.quota_reached != 1) AND (qsqr.quota_reached IS NULL OR qsqr.quota_reached != 1) + AND co.operator_id = '$operator_id' GROUP BY c.case_id ORDER BY a.start ASC"; $rs = $db->GetAll($sql); if (!empty($rs)) { @@ -315,18 +316,19 @@ else { print "

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

"; - $sql = "SELECT MIN(q.description), MIN(si.description) as smpl, MIN(CONVERT_TZ(a.start,'UTC',@@session.time_zone)) as start, MIN(CONVERT_TZ(a.end,'UTC',@@session.time_zone)) as end, MIN(CONCAT(r.firstName, ' ', r.lastName)) as resp, + $sql = "SELECT MIN(q.description) as description, MIN(si.description) as smpl, MIN(CONVERT_TZ(a.start,'UTC',co.Time_zone_name)) as start, MIN(CONVERT_TZ(a.end,'UTC',co.Time_zone_name)) as end, MIN(CONCAT(r.firstName, ' ', r.lastName)) as resp, MIN(CONCAT('', c.case_id, '')) as case_id, MIN(CONCAT('  ')) as link, MIN(CONCAT('  ')) as edit FROM appointment as a - JOIN (`case` as c, respondent as r, questionnaire as q, `sample` as s, sample_import as si) on (a.case_id = c.case_id and a.respondent_id = r.respondent_id and q.questionnaire_id = c.questionnaire_id and s.sample_id = c.sample_id and s.import_id= si.sample_import_id) + JOIN (`case` as c, respondent as r, questionnaire as q, `sample` as s, sample_import as si, operator as co) on (a.case_id = c.case_id and a.respondent_id = r.respondent_id and q.questionnaire_id = c.questionnaire_id and s.sample_id = c.sample_id and s.import_id= si.sample_import_id) LEFT JOIN (`call` as ca) ON (ca.call_id = a.completed_call_id) LEFT JOIN (questionnaire_sample_quota as qsq) on (s.import_id = qsq.sample_import_id and c.questionnaire_id = qsq.questionnaire_id) LEFT JOIN (questionnaire_sample_quota_row as qsqr) on (s.import_id = qsqr.sample_import_id and c.questionnaire_id = qsqr.questionnaire_id) - WHERE q.enabled=1 AND si.enabled=1 AND a.end < CONVERT_TZ(NOW(),'System','UTC') AND a.completed_call_id IS NULL AND c.current_outcome_id IN (19,20,21,22) + WHERE q.enabled=1 AND si.enabled=1 AND a.end < CONVERT_TZ(NOW(),'System','UTC') AND a.completed_call_id IS NULL AND (qsq.quota_reached IS NULL OR qsq.quota_reached != 1 ) AND (qsqr.quota_reached IS NULL OR qsqr.quota_reached != 1) + AND co.operator_id = '$operator_id' GROUP BY c.case_id ORDER BY a.start ASC"; diff --git a/admin/supervisor.php b/admin/supervisor.php index 2d3dda34..c6d23479 100644 --- a/admin/supervisor.php +++ b/admin/supervisor.php @@ -320,7 +320,7 @@ if ($case_id != false) print "

 " . T_("Sample details")."

"; $sql = "SELECT sv.sample_id, MIN(c.case_id) as case_id , MIN(s.Time_zone_name) as Time_zone_name, - MIN(TIME_FORMAT(CONVERT_TZ(NOW(),@@session.time_zone,s.Time_zone_name),'". TIME_FORMAT ."')) as time + MIN(TIME_FORMAT(CONVERT_TZ(NOW(),'System',s.Time_zone_name),'". TIME_FORMAT ."')) as time FROM sample_var AS sv LEFT JOIN (`case` AS c , sample as s) ON ( c.sample_id = sv.sample_id AND s.sample_id = c.sample_id ) WHERE c.case_id = '$case_id' GROUP BY sv.sample_id"; @@ -363,8 +363,8 @@ if ($case_id != false) print "

 " . T_("Appointments")."

"; $sql = "SELECT - MIN(CONVERT_TZ(a.start,'UTC',@@session.time_zone)) as start, - MIN(CONVERT_TZ(a.end,'UTC',@@session.time_zone)) as end, + MIN(CONVERT_TZ(a.start,'UTC',co.Time_zone_name)) as start, + MIN(CONVERT_TZ(a.end,'UTC',co.Time_zone_name)) as end, MIN(CONCAT(r.firstName,' ', r.lastName)) as resp, MIN(IFNULL(ou.description,'" . T_("Not yet called") . "')) as outcome, MIN(CONCAT (oo.firstName,' ', oo.lastName)) as makerName, @@ -373,9 +373,10 @@ if ($case_id != false) MIN(CONCAT('  ')) as link, MIN(CONCAT('  ')) as edit 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) + JOIN (`case` as c, respondent as r, questionnaire as q, operator as oo, call_attempt as cc, operator as co) 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) WHERE c.case_id = '$case_id' + AND co.operator_id = '$operator_id' GROUP BY a.appointment_id ORDER BY a.start ASC"; diff --git a/admin/timezonetemplate.php b/admin/timezonetemplate.php index 3d6ec555..75265c7c 100644 --- a/admin/timezonetemplate.php +++ b/admin/timezonetemplate.php @@ -120,7 +120,7 @@ print "
"; print "

" . T_("Timezone list") . "

"; -$sql = "SELECT Time_zone_name, TIME_FORMAT(CONVERT_TZ(NOW(),@@session.time_zone,Time_zone_name),'". TIME_FORMAT ."') as time, CONCAT('

', TIME_FORMAT(TIMEDIFF( CONVERT_TZ(NOW(),'$dtz','$dtz'),CONVERT_TZ(NOW(), Time_zone_name,'$dtz')),' %H : %i'), '

') AS timediff, +$sql = "SELECT Time_zone_name, TIME_FORMAT(CONVERT_TZ(NOW(),'System',Time_zone_name),'". TIME_FORMAT ."') as time, CONCAT('

', TIME_FORMAT(TIMEDIFF( CONVERT_TZ(NOW(),'$dtz','$dtz'),CONVERT_TZ(NOW(), Time_zone_name,'$dtz')),' %H : %i'), '

') AS timediff, CONCAT('" . T_("Remove") . "') as link FROM timezone_template ORDER BY time ASC";