From 620eaf0531bc3367d65c064122ca399e45e56ed5 Mon Sep 17 00:00:00 2001 From: Rod Roark Date: Wed, 23 Jan 2013 07:18:52 -0800 Subject: [PATCH] Added support for repeating events like "2nd Tuesday" or "Last Friday" of the month. --- interface/main/calendar/add_edit_event.php | 101 +++++++++++++++++++++++----- interface/main/calendar/find_appt_popup.php | 70 ++++++++++++++----- library/appointments.inc.php | 72 +++++++++++++++----- library/calendar_events.inc.php | 68 ++++++++++++++----- library/encounter_events.inc.php | 48 +++++++++++-- patients/find_appt_popup_user.php | 50 ++++++++++++-- 6 files changed, 329 insertions(+), 80 deletions(-) diff --git a/interface/main/calendar/add_edit_event.php b/interface/main/calendar/add_edit_event.php index 48225280f..19c1257d3 100644 --- a/interface/main/calendar/add_edit_event.php +++ b/interface/main/calendar/add_edit_event.php @@ -1,5 +1,5 @@ + // Copyright (C) 2005-2013 Rod Roark // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -203,6 +203,33 @@ if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save") } $endtime = "$tmph:$tmpm:00"; + // Set up working variables related to repeated events. + $my_recurrtype = 0; + $my_repeat_freq = 0 + $_POST['form_repeat_freq']; + $my_repeat_type = 0 + $_POST['form_repeat_type']; + $my_repeat_on_num = 1; + $my_repeat_on_day = 0; + $my_repeat_on_freq = 0; + if (!empty($_POST['form_repeat'])) { + $my_recurrtype = 1; + if ($my_repeat_type > 4) { + $my_recurrtype = 2; + $time = strtotime($event_date); + $my_repeat_on_day = 0 + date('w', $time); + $my_repeat_on_freq = $my_repeat_freq; + if ($my_repeat_type == 5) { + $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1; + } + else { + // Last occurence of this weekday on the month + $my_repeat_on_num = 5; + } + // Maybe not needed, but for consistency with postcalendar: + $my_repeat_freq = 0; + $my_repeat_type = 0; + } + } + // Useless garbage that we must save. $locationspecs = array("event_location" => "", "event_street1" => "", @@ -214,11 +241,11 @@ if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save") $locationspec = serialize($locationspecs); // capture the recurring specifications - $recurrspec = array("event_repeat_freq" => $_POST['form_repeat_freq'], - "event_repeat_freq_type" => $_POST['form_repeat_type'], - "event_repeat_on_num" => "1", - "event_repeat_on_day" => "0", - "event_repeat_on_freq" => "0", + $recurrspec = array("event_repeat_freq" => "$my_repeat_freq", + "event_repeat_freq_type" => "$my_repeat_type", + "event_repeat_on_num" => "$my_repeat_on_num", + "event_repeat_on_day" => "$my_repeat_on_day", + "event_repeat_on_freq" => "$my_repeat_on_freq", "exdate" => $_POST['form_repeat_exdate'] ); @@ -396,7 +423,7 @@ if ($_POST['form_action'] == "save") { "pc_eventDate = '" . add_escape_custom($event_date) . "', " . "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " . "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " . - "pc_recurrtype = '" . add_escape_custom(($_POST['form_repeat'] ? '1' : '0')) . "', " . + "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " . "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " . "pc_startTime = '" . add_escape_custom($starttime) . "', " . "pc_endTime = '" . add_escape_custom($endtime) . "', " . @@ -405,11 +432,10 @@ if ($_POST['form_action'] == "save") { "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," . "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " . - "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'"); + "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'"); } // foreach } - // ==================================== // single provider // ==================================== @@ -488,7 +514,7 @@ if ($_POST['form_action'] == "save") { "pc_eventDate = '" . add_escape_custom($event_date) . "', " . "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " . "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " . - "pc_recurrtype = '" . add_escape_custom(($_POST['form_repeat'] ? '1' : '0')) . "', " . + "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " . "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " . "pc_startTime = '" . add_escape_custom($starttime) . "', " . "pc_endTime = '" . add_escape_custom($endtime) . "', " . @@ -497,7 +523,7 @@ if ($_POST['form_action'] == "save") { "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," . "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " . - "WHERE pc_eid = '" . add_escape_custom($eid) . "'"); + "WHERE pc_eid = '" . add_escape_custom($eid) . "'"); } } @@ -684,6 +710,17 @@ if ($_POST['form_action'] == "save") { $repeatfreq = $rspecs['event_repeat_freq']; $repeatexdate = $rspecs['exdate']; // repeating date exceptions + // Adjustments for repeat type 2, a particular weekday of the month. + if ($repeats == 2) { + $repeatfreq = $rspecs['event_repeat_on_freq']; + if ($rspecs['event_repeat_on_num'] < 5) { + $repeattype = 5; + } + else { + $repeattype = 6; + } + } + $hometext = $row['pc_hometext']; if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6); } @@ -911,6 +948,36 @@ td { font-size:0.8em; } document.getElementById('img_enddate').style.visibility = myvisibility; } + // Constants used by dateChanged() function. + var occurNames = new Array( + '', + '', + '', + '' + ); + + // Monitor start date changes to adjust repeat type options. + function dateChanged() { + var f = document.forms[0]; + if (!f.form_date.value) return; + var d = new Date(f.form_date.value); + var downame = Calendar._DN[d.getUTCDay()]; + var nthtext = ''; + var occur = Math.floor((d.getUTCDate() - 1) / 7); + if (occur < 4) { // 5th is not allowed + nthtext = occurNames[occur] + ' ' + downame; + } + f.form_repeat_type.options[5].text = nthtext; + var lasttext = ''; + var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0); + if (tmp.getUTCDate() - d.getUTCDate() < 7) { + // This is a last occurrence of the specified weekday in the month, + // so permit that as an option. + lasttext = ' ' + downame; + } + f.form_repeat_type.options[6].text = lasttext; + } + // This is for callback by the find-available popup. function setappt(year,mon,mday,hours,minutes) { var f = document.forms[0]; @@ -1044,7 +1111,7 @@ $classpati=''; ' - onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' /> + onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' onchange='dateChanged()' /> [?]'> @@ -1297,9 +1364,10 @@ if ($GLOBALS['select_multi_providers']) {