From 81e6f40f26368c22ae9090b8086e7386eab3929e Mon Sep 17 00:00:00 2001 From: sunsetsystems Date: Mon, 4 Feb 2008 17:58:37 +0000 Subject: [PATCH] Optional new calendar layout, and restriction of each user to one facility, from Nethanel Vilensky (see Changelog) --- ChangeLog | 24 + interface/main/calendar/add_edit_event.php | 2067 +++++++------- interface/main/calendar/find_patient_popup.php | 272 +- interface/main/calendar/index.php | 368 +-- .../PostCalendar/plugins/function.pc_url.php | 301 +- .../PostCalendar/pntemplates/default/style/day.css | 29 +- .../pntemplates/default/views/day/default.html | 540 +--- .../default/views/day/fancy_template.html | 621 +++++ .../views/day/{default.html => orig_default.html} | 1062 +++---- .../default/views/global/fancy_navigation.html | 369 +++ .../default/views/global/navigation.html | 76 +- .../{navigation.html => orig_navigation.html} | 134 +- .../pntemplates/default/views/week/default.html | 535 +--- .../views/week/{default.html => orig_default.html} | 845 +++--- .../calendar/modules/PostCalendar/pnuserapi.php | 2902 ++++++++++---------- interface/main/main_info.php | 90 +- interface/usergroup/user_admin.php | 454 +-- interface/usergroup/usergroup_admin.php | 899 +++--- library/auth.inc | 460 ++-- library/dynarch_calendar_setup.js | 2 +- library/patient.inc | 1758 ++++++------ sql/2_8_3-to-2_8_4_upgrade.sql | 3 + sql/database.sql | 1 + 23 files changed, 6873 insertions(+), 6939 deletions(-) rewrite interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html (99%) create mode 100644 interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/fancy_template.html copy interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/{default.html => orig_default.html} (97%) create mode 100644 interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/fancy_navigation.html rewrite interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html (100%) copy interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/{navigation.html => orig_navigation.html} (97%) rewrite interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html (99%) copy interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/{default.html => orig_default.html} (57%) rewrite interface/main/main_info.php (61%) diff --git a/ChangeLog b/ChangeLog index 01c93017f..3efa6ebaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2008-02-04 Changes made to OpenEMR by CHEMED +1. Each user is associated with one facility (Default Facility) in the interface +2. Calendar will not be able to schedule appointments in a facility other than default for the user. +3. When clicking on the time slot to make an appointment the popup form is populated with relevant user and his facility. + These fields are made read only. +4. When scheduling a new appointment using "Add" button the user and facility fields are editable. +5. The Calendar is redesigned. + a) All the columns are of equial width. + b) Calendar view resizes itself on the browser window resize + c) Events are presented as colored chips overlaying the calendar, so the length of event is apparent. + d) IN/OUT/LUNCH etc. events are visually different from others (do not look like chips). + e) View (day/week/year) is selected by buttons. + f) When mousing over an icon to the left of jumpdate field user is presented with a popup overlay that + allows him to select a date from a calendar or some users from a list or a facility. + g) Facility change is immediate (no need to click on "Go" button). + h) To dismiss this popup user have to mouse over the icon again. + i) When printing the calendar old template wil be used, because of the problem in Firefox, which only + prints a first page of absolutely positioned DOM elements. New interface printing does work in IE. + j) The column headers stay in place and only the events list scrolls down. + k) Appointment Status symbol is shown in a top-right corner of event chip. +6. When selecting a patient for an appointment it is possible to search by whole or part of a phone number. +7. Bug: Calendar showed '12pm' as '12am' +8. Bug: The time on the event chip was in 24 hours format, changed to am/pm format. +9. Calendar UI choice is now a per-user option (new field added to users table). ------------------------------------------------------------------------ 2007-06-05 lemonsoftware Added multiple_providers option This customization was made for Dutch version. It is controlled in globals.php diff --git a/interface/main/calendar/add_edit_event.php b/interface/main/calendar/add_edit_event.php index 021cf1a2a..d2417e6c8 100644 --- a/interface/main/calendar/add_edit_event.php +++ b/interface/main/calendar/add_edit_event.php @@ -1,996 +1,1071 @@ - - // - // This program is free software; you can redistribute it and/or - // modify it under the terms of the GNU General Public License - // as published by the Free Software Foundation; either version 2 - // of the License, or (at your option) any later version. - - // The event editor looks something like this: - - //------------------------------------------------------------// - // Category __________________V O All day event // - // Date _____________ [?] O Time ___:___ __V // - // Title ___________________ duration ____ minutes // - // Patient _(Click_to_select)_ // - // Provider __________________V X Repeats ______V ______V // - // Status __________________V until __________ [?] // - // Comments ________________________________________________ // - // // - // [Save] [Find Available] [Delete] [Cancel] // - //------------------------------------------------------------// - - include_once("../../globals.php"); - include_once("$srcdir/patient.inc"); - include_once("$srcdir/forms.inc"); - - // Things that might be passed by our opener. - // - $eid = $_GET['eid']; // only for existing events - $date = $_GET['date']; // this and below only for new events - $userid = $_GET['userid']; - $default_catid = $_GET['catid'] ? $_GET['catid'] : '5'; - // - if ($date) - $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6); - else - $date = date("Y-m-d"); - // - $starttimem = '00'; - if (isset($_GET['starttimem'])) - $starttimem = substr('00' . $_GET['starttimem'], -2); - // - if (isset($_GET['starttimeh'])) { - $starttimeh = $_GET['starttimeh']; - if (isset($_GET['startampm'])) { - if ($_GET['startampm'] == '2' && $starttimeh < 12) - $starttimeh += 12; - } - } else { - $starttimeh = date("G"); - } - $startampm = ''; - - $info_msg = ""; - -// =========================== -// EVENTS TO FACILITIES (lemonsoftware) -// edit event case - if there is no association made, then insert one with the first facility -if ( $eid ) { - $selfacil = ''; - $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid"); - if ( !$facility['pc_facility'] ) { - $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility"); - $min = $qmin['minId']; - - // multiple providers case - if ( $GLOBALS['select_multi_providers'] ) { - $mul = $facility['pc_multiple']; - sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul"); - } - // EOS multiple - - sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid"); - $e2f = $minId; - } else { - $e2f = $facility['pc_facility']; - } -} -// EOS E2F -// =========================== - - - // If we are saving, then save and close the window. - // - if ($_POST['form_save']) { - - $event_date = fixDate($_POST['form_date']); - - // Compute start and end time strings to be saved. - if ($_POST['form_allday']) { - $tmph = 0; - $tmpm = 0; - $duration = 24 * 60; - } else { - $tmph = $_POST['form_hour'] + 0; - $tmpm = $_POST['form_minute'] + 0; - if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12; - $duration = $_POST['form_duration']; - } - $starttime = "$tmph:$tmpm:00"; - // - $tmpm += $duration; - while ($tmpm >= 60) { - $tmpm -= 60; - ++$tmph; - } - $endtime = "$tmph:$tmpm:00"; - - // Useless garbage that we must save. - $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' . - 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}'; - - // More garbage, but this time 1 character of it is used to save the - // repeat type. - if ($_POST['form_repeat']) { - $recurrspec = 'a:5:{' . - 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' . - 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' . - 's:19:"event_repeat_on_num";s:1:"1";' . - 's:19:"event_repeat_on_day";s:1:"0";' . - 's:20:"event_repeat_on_freq";s:1:"0";}'; - } else { - $recurrspec = 'a:5:{' . - 's:17:"event_repeat_freq";N;' . - 's:22:"event_repeat_freq_type";s:1:"0";' . - 's:19:"event_repeat_on_num";s:1:"1";' . - 's:19:"event_repeat_on_day";s:1:"0";' . - 's:20:"event_repeat_on_freq";s:1:"1";}'; - } - -/* ======================================================= -// UPDATE EVENTS -========================================================*/ - if ($eid) { - - // what is multiple key around this $eid? - $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid"); - - if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) { - /* ========================================== - // multi providers BOS - ==========================================*/ - - // obtain current list of providers regarding the multiple key - $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}"); - while ($current = sqlFetchArray($up)) { - $providers_current[] = $current['pc_aid']; - } - - $providers_new = $_POST['form_provider']; - - // this difference means that some providers from current was UNCHECKED - // so we must delete this event for them - $r1 = array_diff ($providers_current, $providers_new); - if (count ($r1)) { - foreach ($r1 as $to_be_removed) { - sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}"); - } - } - - // this difference means that some providers was added - // so we must insert this event for them - $r2 = array_diff ($providers_new, $providers_current); - if (count ($r2)) { - foreach ($r2 as $to_be_inserted) { - sqlInsert("INSERT INTO openemr_postcalendar_events ( pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility) - VALUES ( " . - "'" . $_POST['form_category'] . "', " . - "'" . $row['pc_multiple'] . "', " . - "'" . $to_be_inserted . "', " . - "'" . $_POST['form_pid'] . "', " . - "'" . $_POST['form_title'] . "', " . - "NOW(), " . - "'" . $_POST['form_comments'] . "', " . - "'" . $_SESSION['authUserID'] . "', " . - "'" . $event_date . "', " . - "'" . fixDate($_POST['form_enddate']) . "', " . - "'" . ($duration * 60) . "', " . - "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . - "'$recurrspec', " . - "'$starttime', " . - "'$endtime', " . - "'" . $_POST['form_allday'] . "', " . - "'" . $_POST['form_apptstatus'] . "', " . - "'" . $_POST['form_prefcat'] . "', " . - "'$locationspec', " . - "1, " . - "1, " .(int)$_POST['facility']. " )"); // FF stuff - } // foreach - } //if count - - - // after the two diffs above, we must update for remaining providers - // those who are intersected in $providers_current and $providers_new - foreach ($_POST['form_provider'] as $provider) { - sqlStatement("UPDATE openemr_postcalendar_events SET " . - "pc_catid = '" . $_POST['form_category'] . "', " . - "pc_pid = '" . $_POST['form_pid'] . "', " . - "pc_title = '" . $_POST['form_title'] . "', " . - "pc_time = NOW(), " . - "pc_hometext = '" . $_POST['form_comments'] . "', " . - "pc_informant = '" . $_SESSION['authUserID'] . "', " . - "pc_eventDate = '" . $event_date . "', " . - "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " . - "pc_duration = '" . ($duration * 60) . "', " . - "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " . - "pc_recurrspec = '$recurrspec', " . - "pc_startTime = '$starttime', " . - "pc_endTime = '$endtime', " . - "pc_alldayevent = '" . $_POST['form_allday'] . "', " . - "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " . - "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," . - "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff - "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}"); - } // foreach - -/* ========================================== -// multi providers EOS -==========================================*/ - - } elseif ( !$row['pc_multiple'] ) { - if ( $GLOBALS['select_multi_providers'] ) { - $prov = $_POST['form_provider'][0]; - } else { - $prov = $_POST['form_provider']; - } - - // simple provider case - sqlStatement("UPDATE openemr_postcalendar_events SET " . - "pc_catid = '" . $_POST['form_category'] . "', " . - "pc_aid = '" . $prov . "', " . - "pc_pid = '" . $_POST['form_pid'] . "', " . - "pc_title = '" . $_POST['form_title'] . "', " . - "pc_time = NOW(), " . - "pc_hometext = '" . $_POST['form_comments'] . "', " . - "pc_informant = '" . $_SESSION['authUserID'] . "', " . - "pc_eventDate = '" . $event_date . "', " . - "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " . - "pc_duration = '" . ($duration * 60) . "', " . - "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " . - "pc_recurrspec = '$recurrspec', " . - "pc_startTime = '$starttime', " . - "pc_endTime = '$endtime', " . - "pc_alldayevent = '" . $_POST['form_allday'] . "', " . - "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " . - "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," . - "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff - "WHERE pc_eid = '$eid'"); - - } - -// ======================================= -// EOS multi providers case -// ======================================= - - // EVENTS TO FACILITIES - $e2f = (int)$eid; - -/* ======================================================= -// INSERT EVENTS -========================================================*/ - } else { - -// ======================================= -// multi providers case -// ======================================= - -if (is_array($_POST['form_provider'])) { - - // obtain the next available unique key to group multiple providers around some event - $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events"); - $max = sqlFetchArray($q); - $new_multiple_value = $max['max'] + 1; - - foreach ($_POST['form_provider'] as $provider) { - sqlInsert("INSERT INTO openemr_postcalendar_events ( " . - "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " . - "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " . - "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " . - "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " . - ") VALUES ( " . - "'" . $_POST['form_category'] . "', " . - "'" . $new_multiple_value . "', " . - "'" . $provider . "', " . - "'" . $_POST['form_pid'] . "', " . - "'" . $_POST['form_title'] . "', " . - "NOW(), " . - "'" . $_POST['form_comments'] . "', " . - "'" . $_SESSION['authUserID'] . "', " . - "'" . $event_date . "', " . - "'" . fixDate($_POST['form_enddate']) . "', " . - "'" . ($duration * 60) . "', " . - "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . - "'$recurrspec', " . - "'$starttime', " . - "'$endtime', " . - "'" . $_POST['form_allday'] . "', " . - "'" . $_POST['form_apptstatus'] . "', " . - "'" . $_POST['form_prefcat'] . "', " . - "'$locationspec', " . - "1, " . - "1, " .(int)$_POST['facility']. " )"); // FF stuff - - } // foreach - -} else { -sqlInsert("INSERT INTO openemr_postcalendar_events ( " . - "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " . - "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " . - "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " . - "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " . - ") VALUES ( " . - "'" . $_POST['form_category'] . "', " . - "'" . $_POST['form_provider'] . "', " . - "'" . $_POST['form_pid'] . "', " . - "'" . $_POST['form_title'] . "', " . - "NOW(), " . - "'" . $_POST['form_comments'] . "', " . - "'" . $_SESSION['authUserID'] . "', " . - "'" . $event_date . "', " . - "'" . fixDate($_POST['form_enddate']) . "', " . - "'" . ($duration * 60) . "', " . - "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . - "'$recurrspec', " . - "'$starttime', " . - "'$endtime', " . - "'" . $_POST['form_allday'] . "', " . - "'" . $_POST['form_apptstatus'] . "', " . - "'" . $_POST['form_prefcat'] . "', " . - "'$locationspec', " . - "1, " . - "1," .(int)$_POST['facility']. ")"); // FF stuff - } // INSERT single - } // else - insert - - // Save new DOB if it's there. - $patient_dob = trim($_POST['form_dob']); - if ($patient_dob && $_POST['form_pid']) { - sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " . - "pid = '" . $_POST['form_pid'] . "'"); - } - - // Auto-create a new encounter if appropriate. - // - if ($GLOBALS['auto_create_new_encounters'] && - $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d')) - { - $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . - "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'"); - if ($tmprow['count'] == 0) { - $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" . - $_POST['form_provider'] . "'"); - $username = $tmprow['username']; - $facility = $tmprow['facility']; - $facility_id = $tmprow['facility_id']; - $conn = $GLOBALS['adodb']['db']; - $encounter = $conn->GenID("sequences"); - addForm($encounter, "New Patient Encounter", - sqlInsert("INSERT INTO form_encounter SET " . - "date = '$event_date', " . - "onset_date = '$event_date', " . - "reason = '" . $_POST['form_comments'] . "', " . - "facility = '$facility', " . - "facility_id = '$facility_id', " . - "pid = '" . $_POST['form_pid'] . "', " . - "encounter = '$encounter'" - ), - "newpatient", $_POST['form_pid'], "1", "NOW()", $username - ); - $info_msg .= "New encounter $encounter was created. "; - } - } - - } - else if ($_POST['form_delete']) { - // ======================================= - // multi providers case - // ======================================= - if ($GLOBALS['select_multi_providers']) { - // what is multiple key around this $eid? - $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid"); - if ( $row['pc_multiple'] ) { - sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}"); - } else { - sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid"); - } - // ======================================= - // EOS multi providers case - // ======================================= - } else { - sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'"); - } - } - - if ($_POST['form_save'] || $_POST['form_delete']) { - // Close this window and refresh the calendar display. - echo "\n\n\n\n\n"; - exit(); - } - - // If we get this far then we are displaying the form. - - $statuses = array( - '-' => '', - '*' => xl('* Reminder done'), - '+' => xl('+ Chart pulled'), - '?' => xl('? No show'), - '@' => xl('@ Arrived'), - '~' => xl('~ Arrived late'), - '!' => xl('! Left w/o visit'), - '#' => xl('# Ins/fin issue'), - '<' => xl('< In exam room'), - '>' => xl('> Checked out'), - '$' => xl('$ Coding done'), - ); - - $repeats = 0; // if the event repeats - $repeattype = '0'; - $repeatfreq = '0'; - $patientid = ''; - if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid']; - $patientname = xl('Click to select'); - $patienttitle = ""; - $hometext = ""; - $row = array(); - - // If we are editing an existing event, then get its data. - if ($eid) { - $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid"); - $date = $row['pc_eventDate']; - $userid = $row['pc_aid']; - $patientid = $row['pc_pid']; - $starttimeh = substr($row['pc_startTime'], 0, 2) + 0; - $starttimem = substr($row['pc_startTime'], 3, 2); - $repeats = $row['pc_recurrtype']; - $multiple_value = $row['pc_multiple']; - - if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) { - $repeattype = $matches[1]; - } - if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) { - $repeatfreq = $matches[1]; - } - $hometext = $row['pc_hometext']; - if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6); - } - - // If we have a patient ID, get the name and phone numbers to display. - if ($patientid) { - $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " . - "FROM patient_data WHERE pid = '" . $patientid . "'"); - $patientname = $prow['lname'] . ", " . $prow['fname']; - if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home']; - if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz']; - } - - // Get the providers list. - $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " . - "authorized != 0 AND active = 1 ORDER BY lname, fname"); - - // Get event categories. - $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " . - "FROM openemr_postcalendar_categories ORDER BY pc_catname"); - - // Fix up the time format for AM/PM. - $startampm = '1'; - if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01 - $startampm = '2'; - if ($starttimeh > 12) $starttimeh -= 12; - } -?> - - -<? echo $eid ? "Edit" : "Add New" ?> <?php xl('Event','e');?> - - - - - - - - - - - - - - - - - onunload='imclosing()'> - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- : - - - -    - /> - - -
- : - - ' - title='' - onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' /> - [?]'> - -    - /> - - - - ' /> : - ' />  - -
- : - - ' - style='width:100%' - title='' /> - -   - - - ' /> -
: -
- : - - ' readonly /> - - -   -
- : - - -"; - -while ($urow = sqlFetchArray($ures)) { - echo " \n"; - } - -echo ''; - -// ======================================= -// EOS multi providers case -// ======================================= -} else { -?> - - - - - -    - /> - - - - - - - -
- : - - - - - - - - -   - - - ' - onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' - title='' /> - [?]'> -
- : - - ' /> -
- : - - ' - onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' /> - [?]'> -
- -

-' /> -  -' onclick='find_available()' /> -  -' /> -  -' onclick='window.close()' /> -

-
-
- - - - - + + // + // This program is free software; you can redistribute it and/or + // modify it under the terms of the GNU General Public License + // as published by the Free Software Foundation; either version 2 + // of the License, or (at your option) any later version. + + // The event editor looks something like this: + + //------------------------------------------------------------// + // Category __________________V O All day event // + // Date _____________ [?] O Time ___:___ __V // + // Title ___________________ duration ____ minutes // + // Patient _(Click_to_select)_ // + // Provider __________________V X Repeats ______V ______V // + // Status __________________V until __________ [?] // + // Comments ________________________________________________ // + // // + // [Save] [Find Available] [Delete] [Cancel] // + //------------------------------------------------------------// + + include_once("../../globals.php"); + include_once("$srcdir/patient.inc"); + include_once("$srcdir/forms.inc"); + + // Things that might be passed by our opener. + // + $eid = $_GET['eid']; // only for existing events + $date = $_GET['date']; // this and below only for new events + $userid = $_GET['userid']; + $default_catid = $_GET['catid'] ? $_GET['catid'] : '5'; + // + if ($date) + $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6); + else + $date = date("Y-m-d"); + // + $starttimem = '00'; + if (isset($_GET['starttimem'])) + $starttimem = substr('00' . $_GET['starttimem'], -2); + // + if (isset($_GET['starttimeh'])) { + $starttimeh = $_GET['starttimeh']; + if (isset($_GET['startampm'])) { + if ($_GET['startampm'] == '2' && $starttimeh < 12) + $starttimeh += 12; + } + } else { + $starttimeh = date("G"); + } + $startampm = ''; + + $info_msg = ""; + +// =========================== +// EVENTS TO FACILITIES (lemonsoftware) +// edit event case - if there is no association made, then insert one with the first facility +/*if ( $eid ) { + $selfacil = ''; + $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid"); + if ( !$facility['pc_facility'] ) { + $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility"); + $min = $qmin['minId']; + + // multiple providers case + if ( $GLOBALS['select_multi_providers'] ) { + $mul = $facility['pc_multiple']; + sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul"); + } + // EOS multiple + + sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid"); + $e2f = $minId; + } else { + $e2f = $facility['pc_facility']; + } +}*/ +// EOS E2F +// =========================== +// =========================== + +// EVENTS TO FACILITIES (lemonsoftware) +//(CHEMED) get facility name +// edit event case - if there is no association made, then insert one with the first facility +if ( $eid ) { + $selfacil = ''; + $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name + FROM openemr_postcalendar_events + LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id) + WHERE pc_eid = $eid"); + if ( !$facility['pc_facility'] ) { + $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']); + $minId = $qmin['minId']; + $min_name = $qmin['facility']; + + // multiple providers case + if ( $GLOBALS['select_multi_providers'] ) { + $mul = $facility['pc_multiple']; + sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul"); + } + // EOS multiple + + sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid"); + $e2f = $minId; + $e2f_name = $min_name; + } else { + $e2f = $facility['pc_facility']; + $e2f_name = $facility['name']; + } +} +// EOS E2F +// =========================== + + + // If we are saving, then save and close the window. + // + if ($_POST['form_save']) { + + $event_date = fixDate($_POST['form_date']); + + // Compute start and end time strings to be saved. + if ($_POST['form_allday']) { + $tmph = 0; + $tmpm = 0; + $duration = 24 * 60; + } else { + $tmph = $_POST['form_hour'] + 0; + $tmpm = $_POST['form_minute'] + 0; + if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12; + $duration = $_POST['form_duration']; + } + $starttime = "$tmph:$tmpm:00"; + // + $tmpm += $duration; + while ($tmpm >= 60) { + $tmpm -= 60; + ++$tmph; + } + $endtime = "$tmph:$tmpm:00"; + + // Useless garbage that we must save. + $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' . + 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}'; + + // More garbage, but this time 1 character of it is used to save the + // repeat type. + if ($_POST['form_repeat']) { + $recurrspec = 'a:5:{' . + 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' . + 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' . + 's:19:"event_repeat_on_num";s:1:"1";' . + 's:19:"event_repeat_on_day";s:1:"0";' . + 's:20:"event_repeat_on_freq";s:1:"0";}'; + } else { + $recurrspec = 'a:5:{' . + 's:17:"event_repeat_freq";N;' . + 's:22:"event_repeat_freq_type";s:1:"0";' . + 's:19:"event_repeat_on_num";s:1:"1";' . + 's:19:"event_repeat_on_day";s:1:"0";' . + 's:20:"event_repeat_on_freq";s:1:"1";}'; + } + +/* ======================================================= +// UPDATE EVENTS +========================================================*/ + if ($eid) { + + // what is multiple key around this $eid? + $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid"); + + if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) { + /* ========================================== + // multi providers BOS + ==========================================*/ + + // obtain current list of providers regarding the multiple key + $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}"); + while ($current = sqlFetchArray($up)) { + $providers_current[] = $current['pc_aid']; + } + + $providers_new = $_POST['form_provider']; + + // this difference means that some providers from current was UNCHECKED + // so we must delete this event for them + $r1 = array_diff ($providers_current, $providers_new); + if (count ($r1)) { + foreach ($r1 as $to_be_removed) { + sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}"); + } + } + + // this difference means that some providers was added + // so we must insert this event for them + $r2 = array_diff ($providers_new, $providers_current); + if (count ($r2)) { + foreach ($r2 as $to_be_inserted) { + sqlInsert("INSERT INTO openemr_postcalendar_events ( pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility) + VALUES ( " . + "'" . $_POST['form_category'] . "', " . + "'" . $row['pc_multiple'] . "', " . + "'" . $to_be_inserted . "', " . + "'" . $_POST['form_pid'] . "', " . + "'" . $_POST['form_title'] . "', " . + "NOW(), " . + "'" . $_POST['form_comments'] . "', " . + "'" . $_SESSION['authUserID'] . "', " . + "'" . $event_date . "', " . + "'" . fixDate($_POST['form_enddate']) . "', " . + "'" . ($duration * 60) . "', " . + "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . + "'$recurrspec', " . + "'$starttime', " . + "'$endtime', " . + "'" . $_POST['form_allday'] . "', " . + "'" . $_POST['form_apptstatus'] . "', " . + "'" . $_POST['form_prefcat'] . "', " . + "'$locationspec', " . + "1, " . + "1, " .(int)$_POST['facility']. " )"); // FF stuff + } // foreach + } //if count + + + // after the two diffs above, we must update for remaining providers + // those who are intersected in $providers_current and $providers_new + foreach ($_POST['form_provider'] as $provider) { + sqlStatement("UPDATE openemr_postcalendar_events SET " . + "pc_catid = '" . $_POST['form_category'] . "', " . + "pc_pid = '" . $_POST['form_pid'] . "', " . + "pc_title = '" . $_POST['form_title'] . "', " . + "pc_time = NOW(), " . + "pc_hometext = '" . $_POST['form_comments'] . "', " . + "pc_informant = '" . $_SESSION['authUserID'] . "', " . + "pc_eventDate = '" . $event_date . "', " . + "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " . + "pc_duration = '" . ($duration * 60) . "', " . + "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " . + "pc_recurrspec = '$recurrspec', " . + "pc_startTime = '$starttime', " . + "pc_endTime = '$endtime', " . + "pc_alldayevent = '" . $_POST['form_allday'] . "', " . + "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " . + "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," . + "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff + "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}"); + } // foreach + +/* ========================================== +// multi providers EOS +==========================================*/ + + } elseif ( !$row['pc_multiple'] ) { + if ( $GLOBALS['select_multi_providers'] ) { + $prov = $_POST['form_provider'][0]; + } else { + $prov = $_POST['form_provider']; + } + + // simple provider case + sqlStatement("UPDATE openemr_postcalendar_events SET " . + "pc_catid = '" . $_POST['form_category'] . "', " . + "pc_aid = '" . $prov . "', " . + "pc_pid = '" . $_POST['form_pid'] . "', " . + "pc_title = '" . $_POST['form_title'] . "', " . + "pc_time = NOW(), " . + "pc_hometext = '" . $_POST['form_comments'] . "', " . + "pc_informant = '" . $_SESSION['authUserID'] . "', " . + "pc_eventDate = '" . $event_date . "', " . + "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " . + "pc_duration = '" . ($duration * 60) . "', " . + "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " . + "pc_recurrspec = '$recurrspec', " . + "pc_startTime = '$starttime', " . + "pc_endTime = '$endtime', " . + "pc_alldayevent = '" . $_POST['form_allday'] . "', " . + "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " . + "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," . + "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff + "WHERE pc_eid = '$eid'"); + + } + +// ======================================= +// EOS multi providers case +// ======================================= + + // EVENTS TO FACILITIES + + $e2f = (int)$eid; + +/* ======================================================= +// INSERT EVENTS +========================================================*/ + } else { + +// ======================================= +// multi providers case +// ======================================= + +if (is_array($_POST['form_provider'])) { + + // obtain the next available unique key to group multiple providers around some event + $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events"); + $max = sqlFetchArray($q); + $new_multiple_value = $max['max'] + 1; + + foreach ($_POST['form_provider'] as $provider) { + sqlInsert("INSERT INTO openemr_postcalendar_events ( " . + "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " . + "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " . + "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " . + "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " . + ") VALUES ( " . + "'" . $_POST['form_category'] . "', " . + "'" . $new_multiple_value . "', " . + "'" . $provider . "', " . + "'" . $_POST['form_pid'] . "', " . + "'" . $_POST['form_title'] . "', " . + "NOW(), " . + "'" . $_POST['form_comments'] . "', " . + "'" . $_SESSION['authUserID'] . "', " . + "'" . $event_date . "', " . + "'" . fixDate($_POST['form_enddate']) . "', " . + "'" . ($duration * 60) . "', " . + "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . + "'$recurrspec', " . + "'$starttime', " . + "'$endtime', " . + "'" . $_POST['form_allday'] . "', " . + "'" . $_POST['form_apptstatus'] . "', " . + "'" . $_POST['form_prefcat'] . "', " . + "'$locationspec', " . + "1, " . + "1, " .(int)$_POST['facility']. " )"); // FF stuff + + } // foreach + +} else { + +sqlInsert("INSERT INTO openemr_postcalendar_events ( " . + "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " . + "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " . + "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " . + "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " . + ") VALUES ( " . + "'" . $_POST['form_category'] . "', " . + "'" . $_POST['form_provider'] . "', " . + "'" . $_POST['form_pid'] . "', " . + "'" . $_POST['form_title'] . "', " . + "NOW(), " . + "'" . $_POST['form_comments'] . "', " . + "'" . $_SESSION['authUserID'] . "', " . + "'" . $event_date . "', " . + "'" . fixDate($_POST['form_enddate']) . "', " . + "'" . ($duration * 60) . "', " . + "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . + "'$recurrspec', " . + "'$starttime', " . + "'$endtime', " . + "'" . $_POST['form_allday'] . "', " . + "'" . $_POST['form_apptstatus'] . "', " . + "'" . $_POST['form_prefcat'] . "', " . + "'$locationspec', " . + "1, " . + "1," .(int)$_POST['facility']. ")"); // FF stuff + } // INSERT single + } // else - insert + + // Save new DOB if it's there. + $patient_dob = trim($_POST['form_dob']); + if ($patient_dob && $_POST['form_pid']) { + sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " . + "pid = '" . $_POST['form_pid'] . "'"); + } + + // Auto-create a new encounter if appropriate. + // + if ($GLOBALS['auto_create_new_encounters'] && + $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d')) + { + $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . + "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'"); + if ($tmprow['count'] == 0) { + $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" . + $_POST['form_provider'] . "'"); + $username = $tmprow['username']; + $facility = $tmprow['facility']; + $facility_id = $tmprow['facility_id']; + $conn = $GLOBALS['adodb']['db']; + $encounter = $conn->GenID("sequences"); + addForm($encounter, "New Patient Encounter", + sqlInsert("INSERT INTO form_encounter SET " . + "date = '$event_date', " . + "onset_date = '$event_date', " . + "reason = '" . $_POST['form_comments'] . "', " . + "facility = '$facility', " . + "facility_id = '$facility_id', " . + "pid = '" . $_POST['form_pid'] . "', " . + "encounter = '$encounter'" + ), + "newpatient", $_POST['form_pid'], "1", "NOW()", $username + ); + $info_msg .= "New encounter $encounter was created. "; + } + } + + } + else if ($_POST['form_delete']) { + // ======================================= + // multi providers case + // ======================================= + if ($GLOBALS['select_multi_providers']) { + // what is multiple key around this $eid? + $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid"); + if ( $row['pc_multiple'] ) { + sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}"); + } else { + sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid"); + } + // ======================================= + // EOS multi providers case + // ======================================= + } else { + sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'"); + } + } + + if ($_POST['form_save'] || $_POST['form_delete']) { + // Close this window and refresh the calendar display. + echo "\n\n\n\n\n"; + exit(); + } + // If we get this far then we are displaying the form. + + $statuses = array( + '-' => '', + '*' => xl('* Reminder done'), + '+' => xl('+ Chart pulled'), + '?' => xl('? No show'), + '@' => xl('@ Arrived'), + '~' => xl('~ Arrived late'), + '!' => xl('! Left w/o visit'), + '#' => xl('# Ins/fin issue'), + '<' => xl('< In exam room'), + '>' => xl('> Checked out'), + '$' => xl('$ Coding done'), + ); + + $repeats = 0; // if the event repeats + $repeattype = '0'; + $repeatfreq = '0'; + $patientid = ''; + if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid']; + $patientname = xl('Click to select'); + $patienttitle = ""; + $hometext = ""; + $row = array(); + + // If we are editing an existing event, then get its data. + if ($eid) { + $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid"); + $date = $row['pc_eventDate']; + $userid = $row['pc_aid']; + $patientid = $row['pc_pid']; + $starttimeh = substr($row['pc_startTime'], 0, 2) + 0; + $starttimem = substr($row['pc_startTime'], 3, 2); + $repeats = $row['pc_recurrtype']; + $multiple_value = $row['pc_multiple']; + + if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) { + $repeattype = $matches[1]; + } + if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) { + $repeatfreq = $matches[1]; + } + $hometext = $row['pc_hometext']; + if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6); + } + + // If we have a patient ID, get the name and phone numbers to display. + if ($patientid) { + $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " . + "FROM patient_data WHERE pid = '" . $patientid . "'"); + $patientname = $prow['lname'] . ", " . $prow['fname']; + if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home']; + if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz']; + } + + // Get the providers list. + $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " . + "authorized != 0 AND active = 1 ORDER BY lname, fname"); + + //------------------------------------- + //(CHEMED) + //Set default facility for a new event + if ($userid) { + $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid")); + $e2f = $pref_facility['facility_id']; + $e2f_name = $pref_facility['facility']; + } + //END of CHEMED ----------------------- + + // Get event categories. + $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " . + "FROM openemr_postcalendar_categories ORDER BY pc_catname"); + + // Fix up the time format for AM/PM. + $startampm = '1'; + if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01 + $startampm = '2'; + if ($starttimeh > 12) $starttimeh -= 12; + } + +?> + + +<? echo $eid ? "Edit" : "Add New" ?> <?php xl('Event','e');?> + + + + + + + + + + + + + + + + + onunload='imclosing()'> + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ : + + + +    + /> + + +
+ : + + ' + title='' + onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' /> + [?]'> + +    + /> + + + + ' /> : + ' />  + +
+ : + + ' + style='width:100%' + title='' /> + +   + + + ' /> +
: + + + + +
+ : + + ' readonly /> + + +   +
+ : + + +"; + + while ($urow = sqlFetchArray($ures)) { + echo " \n"; + } + + echo ''; + + +// ======================================= +// EOS multi providers case +// ======================================= +} else { +?> + + + '/> + + + + + + + + + + +    + /> + + + + + + + +
+ : + + + + + + + + +   + + + ' + onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' + title='' /> + [?]'> +
+ : + + ' /> +
+ : + + ' + onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' /> + [?]'> +
+ +

+' /> +  +' onclick='find_available()' /> +  +' /> +  +' onclick='window.close()' /> +

+
+
+ + + + + diff --git a/interface/main/calendar/find_patient_popup.php b/interface/main/calendar/find_patient_popup.php index 23bdc8a79..9e40b08fd 100644 --- a/interface/main/calendar/find_patient_popup.php +++ b/interface/main/calendar/find_patient_popup.php @@ -1,133 +1,139 @@ - - // - // This program is free software; you can redistribute it and/or - // modify it under the terms of the GNU General Public License - // as published by the Free Software Foundation; either version 2 - // of the License, or (at your option) any later version. - - include_once("../../globals.php"); - include_once("$srcdir/patient.inc"); - - $info_msg = ""; - - // If we are searching, search. - // - if ($_REQUEST['searchby'] && $_REQUEST['searchparm']) { - $searchby = $_REQUEST['searchby']; - $searchparm = $_REQUEST['searchparm']; - - if ($searchby == "Last") { - $result = getPatientLnames("$searchparm","*"); - } elseif ($searchby == "ID") { - $result = getPatientId("$searchparm","*"); - } elseif ($searchby == "DOB") { - $result = getPatientDOB("$searchparm","*"); - } elseif ($searchby == "SSN") { - $result = getPatientSSN("$searchparm","*"); - } - } -?> - - -<?php xl('Patient Finder','e'); ?> - - - - - - - - -> - -
-
- - - - - - - - - - - - - - - -
-
- - - - - ' - title=''> -   - '> - - -
-
- - - - - - - - - - -"; - echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - if ($iter['genericname2'] == 'Billing') { - echo " \n"; - } else { - echo "\n"; - } - echo " "; - } -?> -
$anchor$iterlname, $iterfname $itermname$anchor" . $iter['ss'] . "$anchor" . $iter['DOB'] . "$anchor" . $iter['pubpid'] . "" . $iter['genericval2'] . " 
- - - -
-
- - + + // + // This program is free software; you can redistribute it and/or + // modify it under the terms of the GNU General Public License + // as published by the Free Software Foundation; either version 2 + // of the License, or (at your option) any later version. + + include_once("../../globals.php"); + include_once("$srcdir/patient.inc"); + + $info_msg = ""; + + // If we are searching, search. + // + if ($_REQUEST['searchby'] && $_REQUEST['searchparm']) { + $searchby = $_REQUEST['searchby']; + $searchparm = $_REQUEST['searchparm']; + + if ($searchby == "Last") { + $result = getPatientLnames("$searchparm","*"); + } elseif ($searchby == "Phone") { //(CHEMED) Search by phone number + $result = getPatientPhone("$searchparm","*"); + } elseif ($searchby == "ID") { + $result = getPatientId("$searchparm","*"); + } elseif ($searchby == "DOB") { + $result = getPatientDOB("$searchparm","*"); + } elseif ($searchby == "SSN") { + $result = getPatientSSN("$searchparm","*"); + } + } +?> + + +<?php xl('Patient Finder','e'); ?> + + + + + + + + +> + +
+
+ + + + + + + + + + + + + + + +
+
+ + + + + ' + title=''> +   + '> + + +
+
+ + + + + + + + + + + +"; + echo " "; + echo " \n"; + echo " \n"; //(CHEMED) Search by phone number + echo " \n"; + echo " \n"; + echo " \n"; + if ($iter['genericname2'] == 'Billing') { + echo " \n"; + } else { + echo "\n"; + } + echo " "; + } +?> +
$anchor$iterlname, $iterfname $itermname$anchor" . $iter['phone_home'] . "$anchor" . $iter['ss'] . "$anchor" . $iter['DOB'] . "$anchor" . $iter['pubpid'] . "" . $iter['genericval2'] . " 
+ + + +
+
+ + diff --git a/interface/main/calendar/index.php b/interface/main/calendar/index.php index 44a1b20ed..b6931f84c 100644 --- a/interface/main/calendar/index.php +++ b/interface/main/calendar/index.php @@ -1,180 +1,188 @@ -StartPage(); - $output->Text('Failed to load module ' . $module .' ( At function: "'.$func.'" )'); - $output->EndPage(); - $output->PrintPage(); - exit; - } elseif (strlen($return) > 1) { - // Text - $output = new pnHTML(); - //$output->StartPage(); - $output->SetInputMode(_PNH_VERBATIMINPUT); - $output->Text($return); - $output->SetInputMode(_PNH_PARSEINPUT); - //$output->EndPage(); - $output->PrintPage(); - - } else { - - } - - exit; -} else { - // Old-old style of loading modules - if (empty($op)) { - $op = "modload"; - } - if (empty($file)) { - $file="index"; - } - - include 'includes/legacy.php'; - switch ($op) { - case 'modload': - - define("LOADED_AS_MODULE","1"); - // added for the module/system seperation [class007] - if (file_exists('modules/' . pnVarPrepForOS($name) . '/' . pnVarPrepForOS($file) . '.php')) { - include 'modules/' . pnVarPrepForOS($name) . '/' . pnVarPrepForOS($file) . '.php'; - } else { - // Failed to load the module - $output = new pnHTML(); - //$output->StartPage(); - $output->Text('Failed to load module ' . $module); - $output->EndPage(); - $output->PrintPage(); - exit; - } - break; - default: - // Failed to load the module - $output = new pnHTML(); - //$output->StartPage(); - $output->Text('Sorry, you cannot access this file directly...'); - $output->EndPage(); - $output->PrintPage(); - break; - } - - -} - - -?> +StartPage(); + $output->Text('Failed to load module ' . $module .' ( At function: "'.$func.'" )'); + $output->EndPage(); + $output->PrintPage(); + exit; + } elseif (strlen($return) > 1) { + // Text + $output = new pnHTML(); + //$output->StartPage(); + $output->SetInputMode(_PNH_VERBATIMINPUT); + $output->Text($return); + $output->SetInputMode(_PNH_PARSEINPUT); + //$output->EndPage(); + $output->PrintPage(); + + } else { + + } + + exit; +} else { + // Old-old style of loading modules + if (empty($op)) { + $op = "modload"; + } + if (empty($file)) { + $file="index"; + } + + include 'includes/legacy.php'; + switch ($op) { + case 'modload': + + define("LOADED_AS_MODULE","1"); + // added for the module/system seperation [class007] + if (file_exists('modules/' . pnVarPrepForOS($name) . '/' . pnVarPrepForOS($file) . '.php')) { + include 'modules/' . pnVarPrepForOS($name) . '/' . pnVarPrepForOS($file) . '.php'; + } else { + // Failed to load the module + $output = new pnHTML(); + //$output->StartPage(); + $output->Text('Failed to load module ' . $module); + $output->EndPage(); + $output->PrintPage(); + exit; + } + break; + default: + // Failed to load the module + $output = new pnHTML(); + //$output->StartPage(); + $output->Text('Sorry, you cannot access this file directly...'); + $output->EndPage(); + $output->PrintPage(); + break; + } + + +} + + +?> diff --git a/interface/main/calendar/modules/PostCalendar/plugins/function.pc_url.php b/interface/main/calendar/modules/PostCalendar/plugins/function.pc_url.php index 2a981369e..ae1e86950 100644 --- a/interface/main/calendar/modules/PostCalendar/plugins/function.pc_url.php +++ b/interface/main/calendar/modules/PostCalendar/plugins/function.pc_url.php @@ -1,146 +1,155 @@ -args
"; - //print_r($args); - //print "
args
"; - extract($args); unset($args); - - if(!isset($action)) $action = _SETTING_DEFAULT_VIEW; - if(empty($print)) { - $print = false; - } else { - $print = true; - } - $starth = ""; - if ($setdeftime == 1) - $starth = date("H"); - $ampm = 1; - if ($starth >= 12) - $ampm= 2; - - $template_view = pnVarCleanFromInput('tplview'); - $viewtype = strtolower(pnVarCleanFromInput('viewtype')); - $pc_username = pnVarCleanFromInput('pc_username'); - $category = pnVarCleanFromInput('pc_category'); - $topic = pnVarCleanFromInput('pc_topic'); - $popup = pnVarCleanFromInput('popup'); - if(!isset($date)) { - $Date = postcalendar_getDate(); - } else { - $Date = $date; - } - // some extra cleanup if necessary - $Date = str_replace('-','',$Date); - - $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); - $pcDir = pnVarPrepForOS($pcModInfo['directory']); - - switch($action) { - case 'submit' : - if (!empty($starth)) { - $link = pnModURL(__POSTCALENDAR__,'user','submit',array('tplview'=>$template_view,'Date'=>$Date, 'event_starttimeh' => $starth, 'event_startampm' => $ampm)); - } - else { - $link = pnModURL(__POSTCALENDAR__,'user','submit',array('tplview'=>$template_view,'Date'=>$Date)); - } - break; - - case 'submit-admin' : - $link = pnModURL(__POSTCALENDAR__,'admin','submit',array('tplview'=>$template_view,'Date'=>$Date)); - break; - - case 'search' : - $link = pnModURL(__POSTCALENDAR__,'user','search'); - break; - - case 'day' : - $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, - 'viewtype'=>'day', - 'Date'=>$Date, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic, - 'print'=>$print),$localpath); - break; - - case 'week' : - $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, - 'viewtype'=>'week', - 'Date'=>$Date, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic, - 'print'=>$print)); - break; - - case 'month' : - $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, - 'viewtype'=>'month', - 'Date'=>$Date, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic, - 'print'=>$print)); - break; - - case 'year' : - $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, - 'viewtype'=>'year', - 'Date'=>$Date, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic, - 'print'=>$print)); - break; - - case 'detail' : - if(isset($eid)) { - if(_SETTING_OPEN_NEW_WINDOW && !$popup) { - $link = "javascript:opencal($eid,'$Date');"; - } else { - $link = pnModURL(__POSTCALENDAR__,'user','view',array('Date'=>$Date, - 'tplview'=>$template_view, - 'viewtype'=>'details', - 'eid'=>$eid, - 'print'=>$print),$localpath); - } - } else { - $link = ''; - } - break; - } - if($print) { - $link .= '" target="_blank"'; - } elseif(_SETTING_OPEN_NEW_WINDOW && $viewtype == 'details') { - $link .= '" target="csCalendar"'; - } - echo $link; -} -?> +args
"; + //print_r($args); + //print "
args
"; + extract($args); unset($args); + + if(!isset($action)) $action = _SETTING_DEFAULT_VIEW; + if(empty($print)) { + $print = false; + } else { + $print = true; + } + $starth = ""; + if ($setdeftime == 1) + $starth = date("H"); + $ampm = 1; + if ($starth >= 12) + $ampm= 2; + + $template_view = pnVarCleanFromInput('tplview'); + $viewtype = strtolower(pnVarCleanFromInput('viewtype')); + // pnVarCleanFromInput('pc_username'); //(CHEMED) replaced by the code below + //(CHEMED) Facility filtering + $pc_username = $_SESSION['pc_username']; + $pc_facility = $_SESSION['pc_facility']; + //END (CHEMED) + + $category = pnVarCleanFromInput('pc_category'); + $topic = pnVarCleanFromInput('pc_topic'); + $popup = pnVarCleanFromInput('popup'); + if(!isset($date)) { + $Date = postcalendar_getDate(); + } else { + $Date = $date; + } + // some extra cleanup if necessary + $Date = str_replace('-','',$Date); + + $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); + $pcDir = pnVarPrepForOS($pcModInfo['directory']); + + switch($action) { + case 'submit' : + if (!empty($starth)) { + $link = pnModURL(__POSTCALENDAR__,'user','submit',array('tplview'=>$template_view,'Date'=>$Date, 'event_starttimeh' => $starth, 'event_startampm' => $ampm)); + } + else { + $link = pnModURL(__POSTCALENDAR__,'user','submit',array('tplview'=>$template_view,'Date'=>$Date)); + } + break; + + case 'submit-admin' : + $link = pnModURL(__POSTCALENDAR__,'admin','submit',array('tplview'=>$template_view,'Date'=>$Date)); + break; + + case 'search' : + $link = pnModURL(__POSTCALENDAR__,'user','search'); + break; + + case 'day' : + $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, + 'viewtype'=>'day', + 'Date'=>$Date, + 'pc_facility'=>$pc_facility, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic, + 'print'=>$print),$localpath); + break; + + case 'week' : + $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, + 'viewtype'=>'week', + 'Date'=>$Date, + 'pc_facility'=>$pc_facility, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic, + 'print'=>$print)); + break; + + case 'month' : + $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, + 'viewtype'=>'month', + 'Date'=>$Date, + 'pc_facility'=>$pc_facility, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic, + 'print'=>$print)); + break; + + case 'year' : + $link = pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view, + 'viewtype'=>'year', + 'Date'=>$Date, + 'pc_facility'=>$pc_facility, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic, + 'print'=>$print)); + break; + + case 'detail' : + if(isset($eid)) { + if(_SETTING_OPEN_NEW_WINDOW && !$popup) { + $link = "javascript:opencal($eid,'$Date');"; + } else { + $link = pnModURL(__POSTCALENDAR__,'user','view',array('Date'=>$Date, + 'tplview'=>$template_view, + 'viewtype'=>'details', + 'eid'=>$eid, + 'print'=>$print),$localpath); + } + } else { + $link = ''; + } + break; + } + if($print) { + $link .= '" target="_blank"'; + } elseif(_SETTING_OPEN_NEW_WINDOW && $viewtype == 'details') { + $link .= '" target="csCalendar"'; + } + echo $link; +} +?> diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/style/day.css b/interface/main/calendar/modules/PostCalendar/pntemplates/default/style/day.css index 35686589b..20b02550b 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/style/day.css +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/style/day.css @@ -1,14 +1,15 @@ - + diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html dissimilarity index 99% index 5a6d2f1b8..7831e7ca8 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html @@ -1,531 +1,9 @@ -[-*Smarty*-] -[-*****************************************************************************-] -[-* This is the source code for both day/default.html and week/default.html. *-] -[-* They should always be identical. If you change one, copy to the other! *-] -[-*****************************************************************************-] -[-* Copyright (C) 2005-2006 Rod Roark and others *-] -[-* *-] -[-* This program is free software; you can redistribute it and/or *-] -[-* modify it under the terms of the GNU General Public License *-] -[-* as published by the Free Software Foundation; either version 2 *-] -[-* of the License, or (at your option) any later version. *-] -[-*****************************************************************************-] -[-config_load file="default.conf"-] -[-*Load the Language Definitions*-] -[-config_load file="lang.$USER_LANG"-] -[-include file="$TPL_NAME/views/header.html"-] -[-* we want to include out stylesheet for this view*-] -[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] -[-eval var=$css-] - - - - - - - - - - - - - - - -[-php-] - - // A_CATEGORY is an ordered array of associative-array categories. - // Keys of interest are: id, name, color, desc, event_duration. - // - // echo "\n"; // debugging - // echo "\n"; // debugging - - $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY']; - - // [-if $PRINT_VIEW != 1-] - // [-*Main Navigation*-] - // [-include file="$TPL_NAME/views/global/navigation.html"-] - // [-/if-] - - $A_EVENTS =& $this->_tpl_vars['A_EVENTS']; - // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod - $providers =& $this->_tpl_vars['providers']; - $times =& $this->_tpl_vars['times']; - $interval = $this->_tpl_vars['interval']; - $viewtype = $this->_tpl_vars['VIEW_TYPE']; - $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL']; - $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL']; - $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL']; - $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL']; - - $Date = postcalendar_getDate(); - if (!isset($y)) $y = substr($Date, 0, 4); - if (!isset($m)) $m = substr($Date, 4, 2); - if (!isset($d)) $d = substr($Date, 6, 2); - - // echo "\n"; - - $MULTIDAY = count($A_EVENTS) > 1; - - $provinfo = getProviderInfo(); - - echo "
\n"; - echo "
\n"; - echo "\n"; - echo " \n"; - echo " \n"; - - // Build the scrolling selection list of providers. - echo " \n"; - - // Build the date and view type selectors and the Go button and the Today button. - echo " \n"; - - // Show the Add and Search buttons. - echo " \n"; - echo " \n"; - - // Show the date/range and its previous- and next-day/week selectors. - echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - echo "
\n"; - echo " \n"; - - // ============================== - // FACILITY FILTERING (lemonsoftware) - $facilities = getFacilities(); - echo " \n"; - // EOS FF - // ============================== - - echo " \n"; - - echo " \n" . - " [?]\n"; - - echo "  \n"; - echo "  \n"; - echo "  \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - $atmp = array_keys($A_EVENTS); - -if ($MULTIDAY) { - echo "<< \n"; - echo dateformat(strtotime($atmp[0])); - echo " - "; - echo dateformat(strtotime($atmp[count($atmp)-1])); - echo " >>\n"; - } else { - echo "<< \n"; - echo dateformat(strtotime($atmp[0]), true); - echo " >>\n"; - } - echo " \n"; - echo "  \n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - -[-/php-] - - - -[-assign var="dayname" value=$DATE|date_format:"%w"-] -[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] -[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] -[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] - -[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] - -[-php-] - - echo "\n"; - $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn'); - - // For each day... - foreach ($A_EVENTS as $date => $events) { - $need_headers = true; - $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2); - - // If multiple days then show a date header for each. - if ($MULTIDAY) { - echo " \n"; - echo " "; - echo " \n"; - } - - $arr_events = $S_EVENTS[$date]; - list($slotkey, $slotevent) = each($arr_events); - - // This is an array of provider status information for this day, - // used to properly assign table cell attributes. - $provstat = array(); - - $slotindex = 0; - $lastslotindex = count($times) - 1; - - // For each time slot... - foreach ($times as $slottime) { - $startampm = ($slottime['mer']) == "pm" ? 2 : 1; - $starttimeh = $slottime['hour']; - $starttimem = $slottime['minute']; - $slotendmins = $starttimeh * 60 + $starttimem + $interval; - - // Repeat doc names at 1PM. This is a kludge; omit it for released code. - // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true; - - // Get all events for all providers just for this time slot now, because we - // can pick up where we left off and because we don't want to re-scan all - // events for the day for each table cell. - // - $arr_slot = array(); - for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { - $starth = substr($slotevent['startTime'], 0, 2); - $startm = substr($slotevent['startTime'], 3, 2); - - if (($starth * 60 + $startm) >= $slotendmins) break; - - $arr_slot[$slotkey] = $slotevent; - - $catid = $slotevent['catid']; - $providerid = $slotevent['aid']; - $durminutes = ceil($slotevent['duration'] / 60); - $durslots = ceil($durminutes / $interval); - - // While we're here, collect information for cell cosmetics. - if ($catid == 2) { // in office - $provstat[$providerid]['in'] = true; - - // Save preferred category info for this IN event. - $provstat[$providerid]['in_cat'] = -1; - $provstat[$providerid]['in_slot0'] = $slotindex; - $provstat[$providerid]['in_slots'] = 1; - if ($slotevent['prefcatid']) { - foreach ($A_CATEGORY as $catkey => $catval) { - if ($catval['id'] == $slotevent['prefcatid']) { - $provstat[$providerid]['in_cat'] = $catkey; - $provstat[$providerid]['in_slots'] = - ceil(ceil($catval['event_duration'] / 60) / $interval); - break; - } - } - // Debugging: - if ($provstat[$providerid]['in_cat'] < 0) { - echo "\n"; // debugging - } - } - - } - else if ($catid == 3) { // out of office - $provstat[$providerid]['in'] = false; - } - else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types - // unavailable slots are marked 'res' for appropriate coloring. - $endindex = $slotindex + $durslots; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['res'] = true; - } - } - // If duration > slot size then mark slots for border control. A slot - // marked 'ext' is not to have a border between itself and the slot below. - if ($durslots > 1) { - $endindex = $slotindex + $durslots - 1; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['ext'] = true; - } - } - } - // Finished getting event information for this time slot. - - // Write a header row with the provider names if appropriate. - if ($need_headers) { - $need_headers = false; - echo " \n"; - foreach ($providers as $provider) { - echo " \n"; - } - echo " \n"; - } - - echo " \n"; - - // We are now ready to write the table row for the current time slot. - // This loops once for each provider to be displayed. - // - foreach ($providers as $provider) { - $providerid = $provider['id']; - - // Mark this as a no-bottom-border slot if the preferred category - // duration extends beyond it. - // - // echo "\n"; // debugging - // - if ($provstat[$providerid]['in']) { - if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots']) - $provstat[$providerid][$slotindex]['ext'] = true; - } - - $content = ""; // this will be the event cell content - - $clsuffix = "acell"; - if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) { - $clsuffix = "ucell"; - } - - // Remove top and/or bottom table cell borders using CSS when events span - // time slots or when the practitioner is not in-office. Using "rowspan" - // would be a difficult and inferior solution to this problem. - // - $tdstyleix = 0; - $timelabel = true; - if ($slotindex < $lastslotindex && - ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) { - $tdstyleix += 1; // no bottom - } - if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] || - !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) { - $tdstyleix += 2; // no top - $timelabel = false; - } - $tdstyle = ' ' . $tdstylearr[$tdstyleix]; - - $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh; - - $in_cat_id = 0; - if ($provstat[$providerid]['in_cat'] >= 0) { - $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']]; - if ($category['id']) $in_cat_id = $category['id']; - } - - // If a slot omits the top border, then we omit the TOD cell's top border - // and skip writing its time-of-day text. This way we can get some rows - // with no content at all, which should produce a more compact and readable - // calendar display. - - echo " \n"; - - echo " \n"; - - // Keep track of whether the doc was in during the previous time slot. - $provstat[$providerid]['wasin'] = $provstat[$providerid]['in']; - - } // end provider - - echo " \n"; - - ++$slotindex; - } // end time slot - } // end day - - echo "
" . - dateformat(strtotime($date), true) . "
"; - echo $provider['fname'][0] . " " . $provider['lname']; - echo "
"; - if ($timelabel) { - echo ""; - echo "$disptimeh:$starttimem"; - } else { - echo "
"; // 1x1 px content so the browser does not suppress borders - } - echo "
"; - - // Scan all events for this time slot and generate the associated HTML for - // this doc. JavaScript is used in hrefs to reduce the volume of output. - // - reset($arr_slot); - while (list($eventkey, $event) = each($arr_slot)) { - if ($event['aid'] != $providerid) continue; - if ($content) $content .= " "; - $starth = substr($event['startTime'], 0, 2); - $startm = substr($event['startTime'], 3, 2); - $eventid = $event['eid']; - $patientid = $event['pid']; - $commapos = strpos($event['patient_name'], ","); - $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos)))); - $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2)))); - $patient_dob = $event['patient_dob']; - $patient_age = $event['patient_age']; - $catid = $event['catid']; - $comment = addslashes($event['hometext']); - $catname = $event['catname']; - $title = "Age $patient_age ($patient_dob)"; - if ($comment && $GLOBALS['calendar_appt_style'] < 4) - $title .= " " . $comment; - if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) { - if ($catid == 2) $catname = "IN"; - else if ($catid == 3) $catname = "OUT"; - else if ($catid == 4) $catname = "VACATION"; - else if ($catid == 8) $catname = "LUNCH"; - else if ($catid == 11) $catname = "RESERVED"; - // Omit lunch, vacation, etc. if the doc is not in-office. - if ($provstat[$providerid]['in'] || $catid < 4) { - $content .= ""; - $content .= $catname; - if ($comment) $content .= " - $comment"; - $content .= ""; - } - } - else { // some sort of patient appointment - $content .= ""; - $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . ""; - $content .= ""; - if ($catid == 1) $content .= ""; - $content .= $lname; - if ($GLOBALS['calendar_appt_style'] != 1) { - $content .= "," . $fname; - if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) { - $content .= "(" . $event['title']; - if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4) - $content .= ": " . htmlspecialchars(trim($event['hometext'])) . ""; - $content .= ")"; - } - } - if ($catid == 1) $content .= ""; - $content .= ""; - } - } // end while - - if (! $content) $content = "
"; // so the browser does not suppress borders - echo $content . "
\n"; - - // [-*footer*-] - // [-include file="$TPL_NAME/views/global/footer.html"-] - // [-include file="$TPL_NAME/views/footer.html"-] - -[-/php-] - - - +[-*(CHEMED) if user prefers a fancy calendar switch to a different template*-] +[-php-] + $this->assign('cal_ui', $_SESSION['cal_ui']); +[-/php-] +[-if $cal_ui eq 2-] + [-include file="$TPL_NAME/views/day/fancy_template.html"-] +[-else-] [-*Use default template*-] + [-include file="$TPL_NAME/views/day/orig_default.html"-] +[-/if-] \ No newline at end of file diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/fancy_template.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/fancy_template.html new file mode 100644 index 000000000..2bfa91beb --- /dev/null +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/fancy_template.html @@ -0,0 +1,621 @@ +[-*Smarty*-] +[-*********************************************************************************-] +[-* This is the source code for both day/default.html and week/default.html. *-] +[-* They should always be identical. If you change one, copy to the other! *-] +[-*********************************************************************************-] +[-* Copyright (C) 2005-2006 Rod Roark and others *-] +[-* Copyright (C) 2008 CHEMED (Nethanel Vilensky) *-] +[-* *-] +[-* This program is free software; you can redistribute it and/or *-] +[-* modify it under the terms of the GNU General Public License *-] +[-* as published by the Free Software Foundation; either version 2 *-] +[-* of the License, or (at your option) any later version. *-] +[-*********************************************************************************-] + +[-if $PRINT_VIEW == 1-] + [-* The new calendar interface is not printed correctly by Firefox (because of abs. positioned DOM elements) *-] + [-* so we have to use the older interface instead *-] + [-include file="$TPL_NAME/views/day/orig_default.html"-] +[-else-] + +[-config_load file="default.conf"-] +[-*Load the Language Definitions*-] +[-config_load file="lang.$USER_LANG"-] +[-include file="$TPL_NAME/views/header.html"-] +[-* we want to include out stylesheet for this view*-] +[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] +[-eval var=$css-] + +[-*Main Navigation*-] +[-include file="$TPL_NAME/views/global/navigation.html"-] + +[-assign var="dayname" value=$DATE|date_format:"%w"-] +[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] +[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] +[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] + +[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] + +
[-* START Column labels *-] + [-foreach from=$providers item=provider-] +
+
[-$provider.lname-]
+ [-/foreach-] +
[-* END Column labels *-] + + +
[-* Main scrollable container *-] + +[-php-] + +//Used for sorting the event later +function compareEvents($a,$b) { + $start_a = $a['start_slot']; + $start_b = $b['start_slot']; + $end_a = $a['end_slot']; + $end_b = $b['end_slot']; + $dur_a = $a['data']['duration']; + $dur_b = $b['data']['duration']; + $cat_a = $a['data']['catid']; + $cat_b = $b['data']['catid']; + + //IN-OUT events are always the lowest in the list and show up right-most in the UI + if (($cat_a == '2') || ($cat_a == '3') || ($cat_a == '4') || ($cat_a == '8') || ($cat_a == '11')) { + return 1; + } + if (($cat_b == '2') || ($cat_b == '3') || ($cat_b == '4') || ($cat_b == '8') || ($cat_b == '11')) { + return -1; + } + + if (($start_a == $start_b) && + ($end_a == $end_b) && + ($dur_a == $dur_b)) {return 0;} //Events are alike + + if ($start_a == $start_b) { //Events start together + if ($dur_a != $dur_b) { //Simply sort by duration + return ($dur_a > $dur_b) ? -1 : 1; + } else { + return 0; + } + } + + if ($start_a < $start_b) { //a starts earlier than b + if ($end_a >= $end_b) { //events share slots + if ($dur_a != $dur_b) { //Simply sort by duration + return ($dur_a > $dur_b) ? -1 : 1; + } else { + return 0; + } + } else { //events do not share slots and $a is earlier than $b + return -1; + } + } + + if ($start_b < $start_a) { //b starts earlier than a + if ($end_b >= $end_a) { //events share slots + if ($dur_a != $dur_b) { //Simply sort by duration + return ($dur_a > $dur_b) ? -1 : 1; + } else { + return 0; + } + } else { //events do not share slots and $b is earlier than $a + return 1; + } + } +} + + //Configuration + + /* + ------------------------ <= $calendar_width => ------------------------------------------- + |<= $line_label_width => | <= $column_width => ||... |... | + ------------------------------------------------------------------------------------------ + |... | ... ||... |... | + ------------------------------------------------------------------------------------------ + + In a couple of places I am adding +1 to sizes. This is to account for extra 1px wide border around elements. + */ + + $day_start_y = 30; //Used for multiday display + + $start_hour = $GLOBALS['schedule_start']; + $end_hour = $GLOBALS['schedule_end']; + + $slot_minutes = $GLOBALS['calendar_interval']; + + if ($PRINT_VIEW != 1) { + $container_width = $_SESSION['pc_framewidth'] - 20; + } else { + $container_width = 900; //Make it fit to a landscape letter-sized paper + } + + $line_height = 80; + + $line_label_width = 40; + $scrollbar_width = 30; + + $calendar_width = $container_width - $scrollbar_width; + + $columns = count($providers); + $column_width = ($calendar_width / $columns) - $line_label_width; + + $hour_slots = 60 / $slot_minutes; + $hour_height = $hour_slots * $slot_height; + + $slots_count = ($end_hour - $start_hour) * $hour_slots + 1; //How many slots will we have per day + $calendar_height = $line_height * ($slots_count + 1) + 20; + + //Generate columns (each column is a provider) + // ['count'] how many columns we have altogether + // ['pid']['index'] which column is it counting from the left (0 based) + // ['pid']['x'] how far from the left edge the column starts (in pixels) + $columns = array('count' => 0); + foreach ($providers as $provider) { + $pid = $provider['id']; + $columns[$pid]['index'] = $columns['count']++; + $columns[$pid]['x'] = (($columns[$pid]['index'] + 1) * ($line_label_width + 1)) + ($column_width * $columns[$pid]['index']); + } + + //Re-Index categories array to make it more usefull + $categories = array(); + foreach ($A_CATEGORY as & $category) { + $categories[$category['id']] = $category; + } + + //For each day... + foreach ($A_EVENTS as $date => $event_list) { + + //Generate labels and positions for all the calendar lines + $lines = array(); //This will hold metadata for each visual calendar line + $hour = $start_hour; + $minutes = 0; + + for ($i = 1; $i <= $slots_count; $i++) { + $lines[$i] = array(); + $lines[$i]['index'] = $i; + $lines[$i]['ampm'] = $hour >= 12 ? '2' : '1'; //For the links + $lines[$i]['ampm_char'] = $hour >= 12 ? 'pm' : 'am'; //Visual representation + $lines[$i]['hour'] = $hour > 12 ? $hour - 12 : $hour; + $lines[$i]['min'] = $minutes; + $lines[$i]['date'] = $date; + $lines[$i]['label'] = $lines[$i]['hour'].":".str_pad($minutes, 2, '0', STR_PAD_LEFT).' 
'.$lines[$i]['ampm_char'].' '; + $lines[$i]['y'] = ($i-1) * ($line_height + 1) + $day_start_y; //Where to absolutely position the line + + //Go to the next slot + $minutes += $slot_minutes; + if (($i % $hour_slots) == 0) { //New hour starts + $hour++; + $minutes = 0; + } + } + + $arr_events = $S_EVENTS[$date]; + + $events = array(); //Temporary array for enumerating the events + $slots = array(); //This is the map of slots showing how many events share the slot and the CSS style for IN-OUT events + $provstat = array(); //Used to gray out the slots for which the provider is not available (out of office) + + //Initialize the slot map with defaul values + // ['adj'] Used for adjusting the chip's width and position from the left column edge (see further below) + // ['n'] How many events share the same slot + // ['provstat'] CSS style name as a visual cue that provider is available or not + foreach($providers as $provider) { + $slots[$provider['id']] = array(); + for ($i = 1; $i <= $slots_count; $i++) { + $slots[$provider['id']][$i] = array('adj' => 0, 'n' => 0, 'provstat' => 'cal_slot_out'); + } + } + + //Go through all the events for the day + list($slotkey, $slotevent) = each($arr_events); + for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { + $starth = substr($slotevent['startTime'], 0, 2); + $startm = substr($slotevent['startTime'], 3, 2); + $providerid = $slotevent['aid']; + + $start_slot = ($starth - $start_hour) * $hour_slots + floor($startm / $slot_minutes) + 1; + $durminutes = ceil($slotevent['duration'] / 60); //Convert from seconds to minutes + + //$durslots is the amount of slots the chip touches, even if it does not fill a complete slot + $durslots = ceil((($startm % $slot_minutes) + $durminutes) / $slot_minutes); + if ($durslots == 0) { //Event should take up at least one slot + $durslots = 1; + $durminutes = $slot_minutes; + } + + if (($start_slot + $durslots) > $slots_count) { //Event should not be longer than visible calendar + $durslots = $slots_count - $start_slot + 1; + $durminutes = $durslots * $slot_minutes; + } + + $end_slot = $start_slot + $durslots; + + //Events such as IN, OUT etc. require special handling (setting the CSS class name in the $slots map) + if ($slotevent['catid'] == 2) { + for ($i = $start_slot; $i <= $slots_count; $i++) { + $slots[$providerid][$i]['provstat'] = 'cal_slot_in'; + } + } + + if ($slotevent['catid'] == 3) { + for ($i = $start_slot; $i <= $slots_count; $i++) { + $slots[$providerid][$i]['provstat'] = 'cal_slot_out'; + } + } + + if ($slotevent['catid'] == 4) { + for ($i = $start_slot; $i < $start_slot + $durslots; $i++) { + $slots[$providerid][$i]['provstat'] = 'cal_slot_out'; + } + } + + if ($slotevent['catid'] == 8) { + for ($i = $start_slot; $i < $start_slot + $durslots; $i++) { + $slots[$providerid][$i]['provstat'] = 'cal_slot_out'; + } + } + //END special events handling + + //Mark slots as taken and count the chips in each slot + for ($i = $start_slot; $i < $end_slot; $i++) { + $slots[$providerid][$i]['n']++; + } + + //Calculate event chip dimensions + $x = $columns[$providerid]['x']; + $y = $lines[$start_slot]['y']; + $w = $column_width; + $h = $durslots * ($line_height + 1) - 2; + + $slotevent['duration'] = $durminutes; //Convert from seconds to minutes + + //Add event to the list for rendering + //attaching the category and event data from the database + if ($slotevent['eid'] != '') { //For some reason empty $slotevent sometimes exist. TODO: Figure out why + $events[$providerid][] = array( + 'left' => $x, + 'top' => $y, + 'width' => $w, + 'height' => $h, + 'start_slot' => $start_slot, + 'end_slot' => $end_slot, + 'category' => $categories[$slotevent['catid']], + 'data' => $slotevent + ); + } + + } + + $ready_events = array(); //This array will hold events with fully adjusted position + + + list($providerid, $events_list) = each($events); + for (; isset($providerid); list($providerid, $events_list) = each($events)) { + +/* Sorting debug: foreach ($events_list as $ev) { + print('ID: '.$ev['data']['eid'].' '); + print('Start: '.$ev['start_slot'].' End:'.$ev['end_slot'].' '); + print('Duration: '.$ev['data']['duration'].' '); + print('Top: '.$ev['top'].' Left:'.$ev['left'].' '); + print('---------------
'); + } + print "#########################################################################Sorting...
";*/ + + //Sort events so that they as much as possible do NOT overlap + usort($events_list, "compareEvents"); + +/* Sorting debug: foreach ($events_list as $ev) { + print('ID: '.$ev['data']['eid'].' '); + print('Start: '.$ev['start_slot'].' End:'.$ev['end_slot'].' '); + print('Duration: '.$ev['data']['duration'].' '); + print('Top: '.$ev['top'].' Left:'.$ev['left'].' '); + print('---------------
'); + } + exit;*/ + + if (!isset($ready_events[$providerid])) {$ready_events[$providerid] = array();} + foreach ($events_list as $event) { + $neighbors = 1; + //Find the max neccesary width divisor (how thin to make this chip) + //by going over each slot the chip overlays and seeing how many others are there + for ($i = $event['start_slot']; $i < $event['end_slot']; $i++) { + if ($slots[$providerid][$i]['n'] > $neighbors) {$neighbors = $slots[$providerid][$i]['n'];} + $slots[$providerid][$i]['adj']++; + } + //Adjust chip position and width (the magic number 3 adjusts for chip borders and the space between chips) + $event['width'] = floor(($column_width - ($neighbors * 3)) / $neighbors); + $event['left'] = $event['left'] + (($event['width'] + 3) * ($slots[$providerid][$event['start_slot']]['adj'] - 1)); + $ready_events[$providerid][] = $event; + } + //usort($ready_events[$providerid], "compareEvents"); + } + + + //Marshall some variables to Smarty engine + $this->assign('container_width', $container_width); + $this->assign('calendar_width', $calendar_width); + $this->assign('date', $date); + $this->assign_by_ref('lines', $lines); + $this->assign('line_height', $line_height); + $this->assign('hour_height', $hour_height); + $this->assign('line_label_width', $line_label_width); + $this->assign('column_width', $column_width); + $this->assign_by_ref('events', $ready_events); + $this->assign_by_ref('slots', $slots); + $this->assign('date_label_y', $day_start_y - 30); + $this->assign('calendar_height', $calendar_height); + +[-/php-] + + +
+
[-$date|date_format:"%A, %B %d, %Y"-]
+ [-foreach from=$lines item=line-] [-* START Lines *-] +
+ [-foreach from=$providers item=provider-] [-* START Columns (Providers) *-] + [-* Line label (hour:min) *-] + + [-assign var=pid value=$provider.id-] + [-assign var=lineindex value=$line.index-] +
 
+ [-*php-]print_r($slots);Exit;[-/php*-] + [-/foreach-] [-* END Columns (Providers) *-] +
+ [-/foreach-] [-* END Lines *-] +
+ +
[-* START Events overlay *-] + [-* We should access $events through $provider.id index to only show events for selected providers *-] + [-foreach from=$providers item=provider-] [-* START Columns (Providers) *-] + [-assign var=pid value=$provider.id-] + [-assign var=column value=$events.$pid-] + [-foreach from=$column item=event-] [-* START Events *-] + [-if $event.data.catid eq 2 || $event.data.catid eq 3 || $event.data.catid eq 4 || $event.data.catid eq 8 || $event.data.catid eq 11-] + + [-else-] +
+

+ [-$event.data.apptstatus-] + + [-$event.data.startTime|date_format:"%I:%M %p"-] + +

+

[-$event.data.duration-]min

+

[-$event.data.patient_name|default:'No name'-]

+

[-if $event.data.patient_dob ne ''-]Age: [-$event.data.patient_age-][-/if-]

+ [-if $event.data.hometext ne ''-]

[-$event.data.hometext|escape-]

[-/if-] + +
+ [-/if-] + [-/foreach-] [-* END Events *-] + [-/foreach-] [-* END Columns (Providers) *-] +
[-* END Events overlay *-] + + +[-php-] + //For multiday display we have to make the calendar larger + $day_start_y += ($line_height * ($slots_count+1)) + 50; + $calendar_height += $calendar_height; + } + +[-/php-] +
[-* END Main scrollable container *-] + + + + +[-/if-] \ No newline at end of file diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/orig_default.html similarity index 97% copy from interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html copy to interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/orig_default.html index 5a6d2f1b8..9d66c6d16 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/default.html +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/day/orig_default.html @@ -1,531 +1,531 @@ -[-*Smarty*-] -[-*****************************************************************************-] -[-* This is the source code for both day/default.html and week/default.html. *-] -[-* They should always be identical. If you change one, copy to the other! *-] -[-*****************************************************************************-] -[-* Copyright (C) 2005-2006 Rod Roark and others *-] -[-* *-] -[-* This program is free software; you can redistribute it and/or *-] -[-* modify it under the terms of the GNU General Public License *-] -[-* as published by the Free Software Foundation; either version 2 *-] -[-* of the License, or (at your option) any later version. *-] -[-*****************************************************************************-] -[-config_load file="default.conf"-] -[-*Load the Language Definitions*-] -[-config_load file="lang.$USER_LANG"-] -[-include file="$TPL_NAME/views/header.html"-] -[-* we want to include out stylesheet for this view*-] -[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] -[-eval var=$css-] - - - - - - - - - - - - - - - -[-php-] - - // A_CATEGORY is an ordered array of associative-array categories. - // Keys of interest are: id, name, color, desc, event_duration. - // - // echo "\n"; // debugging - // echo "\n"; // debugging - - $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY']; - - // [-if $PRINT_VIEW != 1-] - // [-*Main Navigation*-] - // [-include file="$TPL_NAME/views/global/navigation.html"-] - // [-/if-] - - $A_EVENTS =& $this->_tpl_vars['A_EVENTS']; - // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod - $providers =& $this->_tpl_vars['providers']; - $times =& $this->_tpl_vars['times']; - $interval = $this->_tpl_vars['interval']; - $viewtype = $this->_tpl_vars['VIEW_TYPE']; - $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL']; - $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL']; - $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL']; - $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL']; - - $Date = postcalendar_getDate(); - if (!isset($y)) $y = substr($Date, 0, 4); - if (!isset($m)) $m = substr($Date, 4, 2); - if (!isset($d)) $d = substr($Date, 6, 2); - - // echo "\n"; - - $MULTIDAY = count($A_EVENTS) > 1; - - $provinfo = getProviderInfo(); - - echo "
\n"; - echo "
\n"; - echo "\n"; - echo " \n"; - echo " \n"; - - // Build the scrolling selection list of providers. - echo " \n"; - - // Build the date and view type selectors and the Go button and the Today button. - echo " \n"; - - // Show the Add and Search buttons. - echo " \n"; - echo " \n"; - - // Show the date/range and its previous- and next-day/week selectors. - echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - echo "
\n"; - echo " \n"; - - // ============================== - // FACILITY FILTERING (lemonsoftware) - $facilities = getFacilities(); - echo " \n"; - // EOS FF - // ============================== - - echo " \n"; - - echo " \n" . - " [?]\n"; - - echo "  \n"; - echo "  \n"; - echo "  \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - $atmp = array_keys($A_EVENTS); - -if ($MULTIDAY) { - echo "<< \n"; - echo dateformat(strtotime($atmp[0])); - echo " - "; - echo dateformat(strtotime($atmp[count($atmp)-1])); - echo " >>\n"; - } else { - echo "<< \n"; - echo dateformat(strtotime($atmp[0]), true); - echo " >>\n"; - } - echo " \n"; - echo "  \n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - -[-/php-] - - - -[-assign var="dayname" value=$DATE|date_format:"%w"-] -[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] -[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] -[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] - -[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] - -[-php-] - - echo "\n"; - $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn'); - - // For each day... - foreach ($A_EVENTS as $date => $events) { - $need_headers = true; - $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2); - - // If multiple days then show a date header for each. - if ($MULTIDAY) { - echo " \n"; - echo " "; - echo " \n"; - } - - $arr_events = $S_EVENTS[$date]; - list($slotkey, $slotevent) = each($arr_events); - - // This is an array of provider status information for this day, - // used to properly assign table cell attributes. - $provstat = array(); - - $slotindex = 0; - $lastslotindex = count($times) - 1; - - // For each time slot... - foreach ($times as $slottime) { - $startampm = ($slottime['mer']) == "pm" ? 2 : 1; - $starttimeh = $slottime['hour']; - $starttimem = $slottime['minute']; - $slotendmins = $starttimeh * 60 + $starttimem + $interval; - - // Repeat doc names at 1PM. This is a kludge; omit it for released code. - // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true; - - // Get all events for all providers just for this time slot now, because we - // can pick up where we left off and because we don't want to re-scan all - // events for the day for each table cell. - // - $arr_slot = array(); - for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { - $starth = substr($slotevent['startTime'], 0, 2); - $startm = substr($slotevent['startTime'], 3, 2); - - if (($starth * 60 + $startm) >= $slotendmins) break; - - $arr_slot[$slotkey] = $slotevent; - - $catid = $slotevent['catid']; - $providerid = $slotevent['aid']; - $durminutes = ceil($slotevent['duration'] / 60); - $durslots = ceil($durminutes / $interval); - - // While we're here, collect information for cell cosmetics. - if ($catid == 2) { // in office - $provstat[$providerid]['in'] = true; - - // Save preferred category info for this IN event. - $provstat[$providerid]['in_cat'] = -1; - $provstat[$providerid]['in_slot0'] = $slotindex; - $provstat[$providerid]['in_slots'] = 1; - if ($slotevent['prefcatid']) { - foreach ($A_CATEGORY as $catkey => $catval) { - if ($catval['id'] == $slotevent['prefcatid']) { - $provstat[$providerid]['in_cat'] = $catkey; - $provstat[$providerid]['in_slots'] = - ceil(ceil($catval['event_duration'] / 60) / $interval); - break; - } - } - // Debugging: - if ($provstat[$providerid]['in_cat'] < 0) { - echo "\n"; // debugging - } - } - - } - else if ($catid == 3) { // out of office - $provstat[$providerid]['in'] = false; - } - else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types - // unavailable slots are marked 'res' for appropriate coloring. - $endindex = $slotindex + $durslots; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['res'] = true; - } - } - // If duration > slot size then mark slots for border control. A slot - // marked 'ext' is not to have a border between itself and the slot below. - if ($durslots > 1) { - $endindex = $slotindex + $durslots - 1; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['ext'] = true; - } - } - } - // Finished getting event information for this time slot. - - // Write a header row with the provider names if appropriate. - if ($need_headers) { - $need_headers = false; - echo " \n"; - foreach ($providers as $provider) { - echo " \n"; - } - echo " \n"; - } - - echo " \n"; - - // We are now ready to write the table row for the current time slot. - // This loops once for each provider to be displayed. - // - foreach ($providers as $provider) { - $providerid = $provider['id']; - - // Mark this as a no-bottom-border slot if the preferred category - // duration extends beyond it. - // - // echo "\n"; // debugging - // - if ($provstat[$providerid]['in']) { - if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots']) - $provstat[$providerid][$slotindex]['ext'] = true; - } - - $content = ""; // this will be the event cell content - - $clsuffix = "acell"; - if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) { - $clsuffix = "ucell"; - } - - // Remove top and/or bottom table cell borders using CSS when events span - // time slots or when the practitioner is not in-office. Using "rowspan" - // would be a difficult and inferior solution to this problem. - // - $tdstyleix = 0; - $timelabel = true; - if ($slotindex < $lastslotindex && - ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) { - $tdstyleix += 1; // no bottom - } - if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] || - !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) { - $tdstyleix += 2; // no top - $timelabel = false; - } - $tdstyle = ' ' . $tdstylearr[$tdstyleix]; - - $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh; - - $in_cat_id = 0; - if ($provstat[$providerid]['in_cat'] >= 0) { - $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']]; - if ($category['id']) $in_cat_id = $category['id']; - } - - // If a slot omits the top border, then we omit the TOD cell's top border - // and skip writing its time-of-day text. This way we can get some rows - // with no content at all, which should produce a more compact and readable - // calendar display. - - echo " \n"; - - echo " \n"; - - // Keep track of whether the doc was in during the previous time slot. - $provstat[$providerid]['wasin'] = $provstat[$providerid]['in']; - - } // end provider - - echo " \n"; - - ++$slotindex; - } // end time slot - } // end day - - echo "
" . - dateformat(strtotime($date), true) . "
"; - echo $provider['fname'][0] . " " . $provider['lname']; - echo "
"; - if ($timelabel) { - echo ""; - echo "$disptimeh:$starttimem"; - } else { - echo "
"; // 1x1 px content so the browser does not suppress borders - } - echo "
"; - - // Scan all events for this time slot and generate the associated HTML for - // this doc. JavaScript is used in hrefs to reduce the volume of output. - // - reset($arr_slot); - while (list($eventkey, $event) = each($arr_slot)) { - if ($event['aid'] != $providerid) continue; - if ($content) $content .= " "; - $starth = substr($event['startTime'], 0, 2); - $startm = substr($event['startTime'], 3, 2); - $eventid = $event['eid']; - $patientid = $event['pid']; - $commapos = strpos($event['patient_name'], ","); - $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos)))); - $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2)))); - $patient_dob = $event['patient_dob']; - $patient_age = $event['patient_age']; - $catid = $event['catid']; - $comment = addslashes($event['hometext']); - $catname = $event['catname']; - $title = "Age $patient_age ($patient_dob)"; - if ($comment && $GLOBALS['calendar_appt_style'] < 4) - $title .= " " . $comment; - if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) { - if ($catid == 2) $catname = "IN"; - else if ($catid == 3) $catname = "OUT"; - else if ($catid == 4) $catname = "VACATION"; - else if ($catid == 8) $catname = "LUNCH"; - else if ($catid == 11) $catname = "RESERVED"; - // Omit lunch, vacation, etc. if the doc is not in-office. - if ($provstat[$providerid]['in'] || $catid < 4) { - $content .= ""; - $content .= $catname; - if ($comment) $content .= " - $comment"; - $content .= ""; - } - } - else { // some sort of patient appointment - $content .= ""; - $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . ""; - $content .= ""; - if ($catid == 1) $content .= ""; - $content .= $lname; - if ($GLOBALS['calendar_appt_style'] != 1) { - $content .= "," . $fname; - if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) { - $content .= "(" . $event['title']; - if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4) - $content .= ": " . htmlspecialchars(trim($event['hometext'])) . ""; - $content .= ")"; - } - } - if ($catid == 1) $content .= ""; - $content .= ""; - } - } // end while - - if (! $content) $content = "
"; // so the browser does not suppress borders - echo $content . "
\n"; - - // [-*footer*-] - // [-include file="$TPL_NAME/views/global/footer.html"-] - // [-include file="$TPL_NAME/views/footer.html"-] - -[-/php-] - - - +[-*Smarty*-] +[-*****************************************************************************-] +[-* This is the source code for both day/default.html and week/default.html. *-] +[-* They should always be identical. If you change one, copy to the other! *-] +[-*****************************************************************************-] +[-* Copyright (C) 2005-2006 Rod Roark and others *-] +[-* *-] +[-* This program is free software; you can redistribute it and/or *-] +[-* modify it under the terms of the GNU General Public License *-] +[-* as published by the Free Software Foundation; either version 2 *-] +[-* of the License, or (at your option) any later version. *-] +[-*****************************************************************************-] +[-config_load file="default.conf"-] +[-*Load the Language Definitions*-] +[-config_load file="lang.$USER_LANG"-] +[-include file="$TPL_NAME/views/header.html"-] +[-* we want to include out stylesheet for this view*-] +[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] +[-eval var=$css-] + + + + + + + + + + + + + + + +[-php-] + + // A_CATEGORY is an ordered array of associative-array categories. + // Keys of interest are: id, name, color, desc, event_duration. + // + // echo "\n"; // debugging + // echo "\n"; // debugging + + $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY']; + + // [-if $PRINT_VIEW != 1-] + // [-*Main Navigation*-] + // [-include file="$TPL_NAME/views/global/navigation.html"-] + // [-/if-] + + $A_EVENTS =& $this->_tpl_vars['A_EVENTS']; + // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod + $providers =& $this->_tpl_vars['providers']; + $times =& $this->_tpl_vars['times']; + $interval = $this->_tpl_vars['interval']; + $viewtype = $this->_tpl_vars['VIEW_TYPE']; + $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL']; + $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL']; + $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL']; + $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL']; + + $Date = postcalendar_getDate(); + if (!isset($y)) $y = substr($Date, 0, 4); + if (!isset($m)) $m = substr($Date, 4, 2); + if (!isset($d)) $d = substr($Date, 6, 2); + + // echo "\n"; + + $MULTIDAY = count($A_EVENTS) > 1; + + $provinfo = getProviderInfo(); + + echo "
\n"; + echo "
\n"; + echo "\n"; + echo " \n"; + echo " \n"; + + // Build the scrolling selection list of providers. + echo " \n"; + + // Build the date and view type selectors and the Go button and the Today button. + echo " \n"; + + // Show the Add and Search buttons. + echo " \n"; + echo " \n"; + + // Show the date/range and its previous- and next-day/week selectors. + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo "
\n"; + echo " \n"; + + // ============================== + // FACILITY FILTERING (lemonsoftware) + $facilities = getFacilities(); + echo " \n"; + // EOS FF + // ============================== + + echo " \n"; + + echo " \n" . + " [?]\n"; + + echo "  \n"; + echo "  \n"; + echo "  \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + $atmp = array_keys($A_EVENTS); + +if ($MULTIDAY) { + echo "<< \n"; + echo dateformat(strtotime($atmp[0])); + echo " - "; + echo dateformat(strtotime($atmp[count($atmp)-1])); + echo " >>\n"; + } else { + echo "<< \n"; + echo dateformat(strtotime($atmp[0]), true); + echo " >>\n"; + } + echo " \n"; + echo "  \n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + +[-/php-] + + + +[-assign var="dayname" value=$DATE|date_format:"%w"-] +[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] +[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] +[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] + +[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] + +[-php-] + + echo "\n"; + $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn'); + + // For each day... + foreach ($A_EVENTS as $date => $events) { + $need_headers = true; + $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2); + + // If multiple days then show a date header for each. + if ($MULTIDAY) { + echo " \n"; + echo " "; + echo " \n"; + } + + $arr_events = $S_EVENTS[$date]; + list($slotkey, $slotevent) = each($arr_events); + + // This is an array of provider status information for this day, + // used to properly assign table cell attributes. + $provstat = array(); + + $slotindex = 0; + $lastslotindex = count($times) - 1; + + // For each time slot... + foreach ($times as $slottime) { + $startampm = ($slottime['mer']) == "pm" ? 2 : 1; + $starttimeh = $slottime['hour']; + $starttimem = $slottime['minute']; + $slotendmins = $starttimeh * 60 + $starttimem + $interval; + + // Repeat doc names at 1PM. This is a kludge; omit it for released code. + // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true; + + // Get all events for all providers just for this time slot now, because we + // can pick up where we left off and because we don't want to re-scan all + // events for the day for each table cell. + // + $arr_slot = array(); + for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { + $starth = substr($slotevent['startTime'], 0, 2); + $startm = substr($slotevent['startTime'], 3, 2); + + if (($starth * 60 + $startm) >= $slotendmins) break; + + $arr_slot[$slotkey] = $slotevent; + + $catid = $slotevent['catid']; + $providerid = $slotevent['aid']; + $durminutes = ceil($slotevent['duration'] / 60); + $durslots = ceil($durminutes / $interval); + + // While we're here, collect information for cell cosmetics. + if ($catid == 2) { // in office + $provstat[$providerid]['in'] = true; + + // Save preferred category info for this IN event. + $provstat[$providerid]['in_cat'] = -1; + $provstat[$providerid]['in_slot0'] = $slotindex; + $provstat[$providerid]['in_slots'] = 1; + if ($slotevent['prefcatid']) { + foreach ($A_CATEGORY as $catkey => $catval) { + if ($catval['id'] == $slotevent['prefcatid']) { + $provstat[$providerid]['in_cat'] = $catkey; + $provstat[$providerid]['in_slots'] = + ceil(ceil($catval['event_duration'] / 60) / $interval); + break; + } + } + // Debugging: + if ($provstat[$providerid]['in_cat'] < 0) { + echo "\n"; // debugging + } + } + + } + else if ($catid == 3) { // out of office + $provstat[$providerid]['in'] = false; + } + else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types + // unavailable slots are marked 'res' for appropriate coloring. + $endindex = $slotindex + $durslots; + for ($i = $slotindex; $i < $endindex; ++$i) { + $provstat[$providerid][$i]['res'] = true; + } + } + // If duration > slot size then mark slots for border control. A slot + // marked 'ext' is not to have a border between itself and the slot below. + if ($durslots > 1) { + $endindex = $slotindex + $durslots - 1; + for ($i = $slotindex; $i < $endindex; ++$i) { + $provstat[$providerid][$i]['ext'] = true; + } + } + } + // Finished getting event information for this time slot. + + // Write a header row with the provider names if appropriate. + if ($need_headers) { + $need_headers = false; + echo " \n"; + foreach ($providers as $provider) { + echo " \n"; + } + echo " \n"; + } + + echo " \n"; + + // We are now ready to write the table row for the current time slot. + // This loops once for each provider to be displayed. + // + foreach ($providers as $provider) { + $providerid = $provider['id']; + + // Mark this as a no-bottom-border slot if the preferred category + // duration extends beyond it. + // + // echo "\n"; // debugging + // + if ($provstat[$providerid]['in']) { + if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots']) + $provstat[$providerid][$slotindex]['ext'] = true; + } + + $content = ""; // this will be the event cell content + + $clsuffix = "acell"; + if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) { + $clsuffix = "ucell"; + } + + // Remove top and/or bottom table cell borders using CSS when events span + // time slots or when the practitioner is not in-office. Using "rowspan" + // would be a difficult and inferior solution to this problem. + // + $tdstyleix = 0; + $timelabel = true; + if ($slotindex < $lastslotindex && + ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) { + $tdstyleix += 1; // no bottom + } + if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] || + !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) { + $tdstyleix += 2; // no top + $timelabel = false; + } + $tdstyle = ' ' . $tdstylearr[$tdstyleix]; + + $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh; + + $in_cat_id = 0; + if ($provstat[$providerid]['in_cat'] >= 0) { + $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']]; + if ($category['id']) $in_cat_id = $category['id']; + } + + // If a slot omits the top border, then we omit the TOD cell's top border + // and skip writing its time-of-day text. This way we can get some rows + // with no content at all, which should produce a more compact and readable + // calendar display. + + echo " \n"; + + echo " \n"; + + // Keep track of whether the doc was in during the previous time slot. + $provstat[$providerid]['wasin'] = $provstat[$providerid]['in']; + + } // end provider + + echo " \n"; + + ++$slotindex; + } // end time slot + } // end day + + echo "
" . + dateformat(strtotime($date), true) . "
"; + echo $provider['fname'][0] . " " . $provider['lname']; + echo "
"; + if ($timelabel) { + echo ""; + echo "$disptimeh:$starttimem"; + } else { + echo "
"; // 1x1 px content so the browser does not suppress borders + } + echo "
"; + + // Scan all events for this time slot and generate the associated HTML for + // this doc. JavaScript is used in hrefs to reduce the volume of output. + // + reset($arr_slot); + while (list($eventkey, $event) = each($arr_slot)) { + if ($event['aid'] != $providerid) continue; + if ($content) $content .= " "; + $starth = substr($event['startTime'], 0, 2); + $startm = substr($event['startTime'], 3, 2); + $eventid = $event['eid']; + $patientid = $event['pid']; + $commapos = strpos($event['patient_name'], ","); + $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos)))); + $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2)))); + $patient_dob = $event['patient_dob']; + $patient_age = $event['patient_age']; + $catid = $event['catid']; + $comment = addslashes($event['hometext']); + $catname = $event['catname']; + $title = "Age $patient_age ($patient_dob)"; + if ($comment && $GLOBALS['calendar_appt_style'] < 4) + $title .= " " . $comment; + if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) { + if ($catid == 2) $catname = "IN"; + else if ($catid == 3) $catname = "OUT"; + else if ($catid == 4) $catname = "VACATION"; + else if ($catid == 8) $catname = "LUNCH"; + else if ($catid == 11) $catname = "RESERVED"; + // Omit lunch, vacation, etc. if the doc is not in-office. + if ($provstat[$providerid]['in'] || $catid < 4) { + $content .= ""; + $content .= $catname; + if ($comment) $content .= " - $comment"; + $content .= ""; + } + } + else { // some sort of patient appointment + $content .= ""; + $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . ""; + $content .= ""; + if ($catid == 1) $content .= ""; + $content .= $lname; + if ($GLOBALS['calendar_appt_style'] != 1) { + $content .= "," . $fname; + if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) { + $content .= "(" . $event['title']; + if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4) + $content .= ": " . htmlspecialchars(trim($event['hometext'])) . ""; + $content .= ")"; + } + } + if ($catid == 1) $content .= ""; + $content .= ""; + } + } // end while + + if (! $content) $content = "
"; // so the browser does not suppress borders + echo $content . "
\n"; + + // [-*footer*-] + // [-include file="$TPL_NAME/views/global/footer.html"-] + // [-include file="$TPL_NAME/views/footer.html"-] + +[-/php-] + + + diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/fancy_navigation.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/fancy_navigation.html new file mode 100644 index 000000000..1d70e151c --- /dev/null +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/fancy_navigation.html @@ -0,0 +1,369 @@ + + + + + + + + + + + + + + +[-php-] + + // A_CATEGORY is an ordered array of associative-array categories. + // Keys of interest are: id, name, color, desc, event_duration. + // + // echo "\n"; // debugging + // echo "\n"; // debugging + + $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY']; + + $A_EVENTS =& $this->_tpl_vars['A_EVENTS']; + // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod + $providers =& $this->_tpl_vars['providers']; + $times =& $this->_tpl_vars['times']; + $interval = $this->_tpl_vars['interval']; + $viewtype = $this->_tpl_vars['VIEW_TYPE']; + $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL']; + $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL']; + $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL']; + $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL']; + + $Date = postcalendar_getDate(); + if (!isset($y)) $y = substr($Date, 0, 4); + if (!isset($m)) $m = substr($Date, 4, 2); + if (!isset($d)) $d = substr($Date, 6, 2); + + // echo "\n"; + + // $MULTIDAY = count($A_EVENTS) > 1; // (CHEMED) not needed after week_view template changes + + $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']); //(CHEMED) + + [-/php-] + +
+ +
+ + [?] + + + + + + + +
+ + + +
+ + + + [-#_PC_THEME_PRINT#-] + +
+ +
+
+
+ +
+ + + + [-php-] + // ============================== + // FACILITY FILTERING (lemonsoftware)(CHEMED) + // $facilities = getFacilities(); // (CHEMED) commented this out + // We only want to see facilities that are a 'service location', + // as 'billing location' facilities should not have any patient appointments + // TODO: Is the above statement true? + $facilities = getServiceFacilities(); + [-/php-] + + + +
+ +
+ +
+ +

+[-php-] + // Show the date/range and its previous- and next-day/week selectors. + $atmp = array_keys($A_EVENTS); + +if ($MULTIDAY) { + echo "<< \n"; + echo dateformat(strtotime($atmp[0])); + echo " - "; + echo dateformat(strtotime($atmp[count($atmp)-1])); + echo " >>\n"; + } else { + echo "<< \n"; + echo dateformat(strtotime($atmp[0]), true); + echo " >>\n"; + } + +[-/php-] +

+ + \ No newline at end of file diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html dissimilarity index 100% index 3e070460c..f79c7ccd7 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html @@ -1,67 +1,9 @@ -[-*Smarty*-] -[-config_load file="navigation.conf"-] -[-*Load the Language Definitions*-] -[-config_load file="lang.$USER_LANG"-] - -[-pc_form_nav_open-] - - - - - - -
- - [-pc_filter label=#_PC_FILTER_LABEL# - class="" type="user,category,topic" - order="user,category,topic,jump"-] - [-pc_date_select day="on" month="on" - year="on" view="on" - label=#_PC_JUMP_MENU_LABEL# - order="month,day,year,view,jump"-] - - - - - - - - - - [-if $ACCESS_ADD eq true-] - - [-/if-] - - -
- [-#_PC_THEME_DAY#-] - - [-#_PC_THEME_WEEK#-] - - [-#_PC_THEME_MONTH#-] - - [-#_PC_THEME_YEAR#-] - - [-php-] - $todayh = date("H"); - [-/php-] - [-#_PC_THEME_SUBMIT#-] - - [-#_PC_THEME_SEARCH#-] -
-
+[-*(CHEMED) if user prefers a fancy calendar switch to a different template*-] +[-php-] + $this->assign('cal_ui', $_SESSION['cal_ui']); +[-/php-] +[-if $cal_ui eq 2-] + [-include file="$TPL_NAME/views/global/fancy_navigation.html"-] +[-else-] [-*Use default template*-] + [-include file="$TPL_NAME/views/global/orig_navigation.html"-] +[-/if-] \ No newline at end of file diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/orig_navigation.html similarity index 97% copy from interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html copy to interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/orig_navigation.html index 3e070460c..1b95ba230 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/navigation.html +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/global/orig_navigation.html @@ -1,67 +1,67 @@ -[-*Smarty*-] -[-config_load file="navigation.conf"-] -[-*Load the Language Definitions*-] -[-config_load file="lang.$USER_LANG"-] - -[-pc_form_nav_open-] - - - - - - -
- - [-pc_filter label=#_PC_FILTER_LABEL# - class="" type="user,category,topic" - order="user,category,topic,jump"-] - [-pc_date_select day="on" month="on" - year="on" view="on" - label=#_PC_JUMP_MENU_LABEL# - order="month,day,year,view,jump"-] - - - - - - - - - - [-if $ACCESS_ADD eq true-] - - [-/if-] - - -
- [-#_PC_THEME_DAY#-] - - [-#_PC_THEME_WEEK#-] - - [-#_PC_THEME_MONTH#-] - - [-#_PC_THEME_YEAR#-] - - [-php-] - $todayh = date("H"); - [-/php-] - [-#_PC_THEME_SUBMIT#-] - - [-#_PC_THEME_SEARCH#-] -
-
+[-*Smarty*-] +[-config_load file="navigation.conf"-] +[-*Load the Language Definitions*-] +[-config_load file="lang.$USER_LANG"-] + +[-pc_form_nav_open-] + + + + + + +
+ + [-pc_filter label=#_PC_FILTER_LABEL# + class="" type="user,category,topic" + order="user,category,topic,jump"-] + [-pc_date_select day="on" month="on" + year="on" view="on" + label=#_PC_JUMP_MENU_LABEL# + order="month,day,year,view,jump"-] + + + + + + + + + + [-if $ACCESS_ADD eq true-] + + [-/if-] + + +
+ [-#_PC_THEME_DAY#-] + + [-#_PC_THEME_WEEK#-] + + [-#_PC_THEME_MONTH#-] + + [-#_PC_THEME_YEAR#-] + + [-php-] + $todayh = date("H"); + [-/php-] + [-#_PC_THEME_SUBMIT#-] + + [-#_PC_THEME_SEARCH#-] +
+
diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html dissimilarity index 99% index 5a6d2f1b8..aebd896cf 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html @@ -1,531 +1,4 @@ -[-*Smarty*-] -[-*****************************************************************************-] -[-* This is the source code for both day/default.html and week/default.html. *-] -[-* They should always be identical. If you change one, copy to the other! *-] -[-*****************************************************************************-] -[-* Copyright (C) 2005-2006 Rod Roark and others *-] -[-* *-] -[-* This program is free software; you can redistribute it and/or *-] -[-* modify it under the terms of the GNU General Public License *-] -[-* as published by the Free Software Foundation; either version 2 *-] -[-* of the License, or (at your option) any later version. *-] -[-*****************************************************************************-] -[-config_load file="default.conf"-] -[-*Load the Language Definitions*-] -[-config_load file="lang.$USER_LANG"-] -[-include file="$TPL_NAME/views/header.html"-] -[-* we want to include out stylesheet for this view*-] -[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] -[-eval var=$css-] - - - - - - - - - - - - - - - -[-php-] - - // A_CATEGORY is an ordered array of associative-array categories. - // Keys of interest are: id, name, color, desc, event_duration. - // - // echo "\n"; // debugging - // echo "\n"; // debugging - - $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY']; - - // [-if $PRINT_VIEW != 1-] - // [-*Main Navigation*-] - // [-include file="$TPL_NAME/views/global/navigation.html"-] - // [-/if-] - - $A_EVENTS =& $this->_tpl_vars['A_EVENTS']; - // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod - $providers =& $this->_tpl_vars['providers']; - $times =& $this->_tpl_vars['times']; - $interval = $this->_tpl_vars['interval']; - $viewtype = $this->_tpl_vars['VIEW_TYPE']; - $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL']; - $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL']; - $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL']; - $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL']; - - $Date = postcalendar_getDate(); - if (!isset($y)) $y = substr($Date, 0, 4); - if (!isset($m)) $m = substr($Date, 4, 2); - if (!isset($d)) $d = substr($Date, 6, 2); - - // echo "\n"; - - $MULTIDAY = count($A_EVENTS) > 1; - - $provinfo = getProviderInfo(); - - echo "
\n"; - echo "
\n"; - echo "\n"; - echo " \n"; - echo " \n"; - - // Build the scrolling selection list of providers. - echo " \n"; - - // Build the date and view type selectors and the Go button and the Today button. - echo " \n"; - - // Show the Add and Search buttons. - echo " \n"; - echo " \n"; - - // Show the date/range and its previous- and next-day/week selectors. - echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - echo "
\n"; - echo " \n"; - - // ============================== - // FACILITY FILTERING (lemonsoftware) - $facilities = getFacilities(); - echo " \n"; - // EOS FF - // ============================== - - echo " \n"; - - echo " \n" . - " [?]\n"; - - echo "  \n"; - echo "  \n"; - echo "  \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - $atmp = array_keys($A_EVENTS); - -if ($MULTIDAY) { - echo "<< \n"; - echo dateformat(strtotime($atmp[0])); - echo " - "; - echo dateformat(strtotime($atmp[count($atmp)-1])); - echo " >>\n"; - } else { - echo "<< \n"; - echo dateformat(strtotime($atmp[0]), true); - echo " >>\n"; - } - echo " \n"; - echo "  \n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - -[-/php-] - - - -[-assign var="dayname" value=$DATE|date_format:"%w"-] -[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] -[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] -[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] - -[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] - -[-php-] - - echo "\n"; - $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn'); - - // For each day... - foreach ($A_EVENTS as $date => $events) { - $need_headers = true; - $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2); - - // If multiple days then show a date header for each. - if ($MULTIDAY) { - echo " \n"; - echo " "; - echo " \n"; - } - - $arr_events = $S_EVENTS[$date]; - list($slotkey, $slotevent) = each($arr_events); - - // This is an array of provider status information for this day, - // used to properly assign table cell attributes. - $provstat = array(); - - $slotindex = 0; - $lastslotindex = count($times) - 1; - - // For each time slot... - foreach ($times as $slottime) { - $startampm = ($slottime['mer']) == "pm" ? 2 : 1; - $starttimeh = $slottime['hour']; - $starttimem = $slottime['minute']; - $slotendmins = $starttimeh * 60 + $starttimem + $interval; - - // Repeat doc names at 1PM. This is a kludge; omit it for released code. - // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true; - - // Get all events for all providers just for this time slot now, because we - // can pick up where we left off and because we don't want to re-scan all - // events for the day for each table cell. - // - $arr_slot = array(); - for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { - $starth = substr($slotevent['startTime'], 0, 2); - $startm = substr($slotevent['startTime'], 3, 2); - - if (($starth * 60 + $startm) >= $slotendmins) break; - - $arr_slot[$slotkey] = $slotevent; - - $catid = $slotevent['catid']; - $providerid = $slotevent['aid']; - $durminutes = ceil($slotevent['duration'] / 60); - $durslots = ceil($durminutes / $interval); - - // While we're here, collect information for cell cosmetics. - if ($catid == 2) { // in office - $provstat[$providerid]['in'] = true; - - // Save preferred category info for this IN event. - $provstat[$providerid]['in_cat'] = -1; - $provstat[$providerid]['in_slot0'] = $slotindex; - $provstat[$providerid]['in_slots'] = 1; - if ($slotevent['prefcatid']) { - foreach ($A_CATEGORY as $catkey => $catval) { - if ($catval['id'] == $slotevent['prefcatid']) { - $provstat[$providerid]['in_cat'] = $catkey; - $provstat[$providerid]['in_slots'] = - ceil(ceil($catval['event_duration'] / 60) / $interval); - break; - } - } - // Debugging: - if ($provstat[$providerid]['in_cat'] < 0) { - echo "\n"; // debugging - } - } - - } - else if ($catid == 3) { // out of office - $provstat[$providerid]['in'] = false; - } - else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types - // unavailable slots are marked 'res' for appropriate coloring. - $endindex = $slotindex + $durslots; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['res'] = true; - } - } - // If duration > slot size then mark slots for border control. A slot - // marked 'ext' is not to have a border between itself and the slot below. - if ($durslots > 1) { - $endindex = $slotindex + $durslots - 1; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['ext'] = true; - } - } - } - // Finished getting event information for this time slot. - - // Write a header row with the provider names if appropriate. - if ($need_headers) { - $need_headers = false; - echo " \n"; - foreach ($providers as $provider) { - echo " \n"; - } - echo " \n"; - } - - echo " \n"; - - // We are now ready to write the table row for the current time slot. - // This loops once for each provider to be displayed. - // - foreach ($providers as $provider) { - $providerid = $provider['id']; - - // Mark this as a no-bottom-border slot if the preferred category - // duration extends beyond it. - // - // echo "\n"; // debugging - // - if ($provstat[$providerid]['in']) { - if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots']) - $provstat[$providerid][$slotindex]['ext'] = true; - } - - $content = ""; // this will be the event cell content - - $clsuffix = "acell"; - if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) { - $clsuffix = "ucell"; - } - - // Remove top and/or bottom table cell borders using CSS when events span - // time slots or when the practitioner is not in-office. Using "rowspan" - // would be a difficult and inferior solution to this problem. - // - $tdstyleix = 0; - $timelabel = true; - if ($slotindex < $lastslotindex && - ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) { - $tdstyleix += 1; // no bottom - } - if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] || - !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) { - $tdstyleix += 2; // no top - $timelabel = false; - } - $tdstyle = ' ' . $tdstylearr[$tdstyleix]; - - $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh; - - $in_cat_id = 0; - if ($provstat[$providerid]['in_cat'] >= 0) { - $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']]; - if ($category['id']) $in_cat_id = $category['id']; - } - - // If a slot omits the top border, then we omit the TOD cell's top border - // and skip writing its time-of-day text. This way we can get some rows - // with no content at all, which should produce a more compact and readable - // calendar display. - - echo " \n"; - - echo " \n"; - - // Keep track of whether the doc was in during the previous time slot. - $provstat[$providerid]['wasin'] = $provstat[$providerid]['in']; - - } // end provider - - echo " \n"; - - ++$slotindex; - } // end time slot - } // end day - - echo "
" . - dateformat(strtotime($date), true) . "
"; - echo $provider['fname'][0] . " " . $provider['lname']; - echo "
"; - if ($timelabel) { - echo ""; - echo "$disptimeh:$starttimem"; - } else { - echo "
"; // 1x1 px content so the browser does not suppress borders - } - echo "
"; - - // Scan all events for this time slot and generate the associated HTML for - // this doc. JavaScript is used in hrefs to reduce the volume of output. - // - reset($arr_slot); - while (list($eventkey, $event) = each($arr_slot)) { - if ($event['aid'] != $providerid) continue; - if ($content) $content .= " "; - $starth = substr($event['startTime'], 0, 2); - $startm = substr($event['startTime'], 3, 2); - $eventid = $event['eid']; - $patientid = $event['pid']; - $commapos = strpos($event['patient_name'], ","); - $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos)))); - $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2)))); - $patient_dob = $event['patient_dob']; - $patient_age = $event['patient_age']; - $catid = $event['catid']; - $comment = addslashes($event['hometext']); - $catname = $event['catname']; - $title = "Age $patient_age ($patient_dob)"; - if ($comment && $GLOBALS['calendar_appt_style'] < 4) - $title .= " " . $comment; - if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) { - if ($catid == 2) $catname = "IN"; - else if ($catid == 3) $catname = "OUT"; - else if ($catid == 4) $catname = "VACATION"; - else if ($catid == 8) $catname = "LUNCH"; - else if ($catid == 11) $catname = "RESERVED"; - // Omit lunch, vacation, etc. if the doc is not in-office. - if ($provstat[$providerid]['in'] || $catid < 4) { - $content .= ""; - $content .= $catname; - if ($comment) $content .= " - $comment"; - $content .= ""; - } - } - else { // some sort of patient appointment - $content .= ""; - $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . ""; - $content .= ""; - if ($catid == 1) $content .= ""; - $content .= $lname; - if ($GLOBALS['calendar_appt_style'] != 1) { - $content .= "," . $fname; - if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) { - $content .= "(" . $event['title']; - if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4) - $content .= ": " . htmlspecialchars(trim($event['hometext'])) . ""; - $content .= ")"; - } - } - if ($catid == 1) $content .= ""; - $content .= ""; - } - } // end while - - if (! $content) $content = "
"; // so the browser does not suppress borders - echo $content . "
\n"; - - // [-*footer*-] - // [-include file="$TPL_NAME/views/global/footer.html"-] - // [-include file="$TPL_NAME/views/footer.html"-] - -[-/php-] - - - +[-*Smarty*-] +[-* set MULTIDAY otherwise day header is not shown. This is what makes week view different from day view *-] +[-assign var=MULTIDAY value=true-] +[-include file="$TPL_NAME/views/day/default.html"-] \ No newline at end of file diff --git a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/orig_default.html similarity index 57% copy from interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html copy to interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/orig_default.html index 5a6d2f1b8..d8b14eb4c 100644 --- a/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/default.html +++ b/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/week/orig_default.html @@ -1,531 +1,314 @@ -[-*Smarty*-] -[-*****************************************************************************-] -[-* This is the source code for both day/default.html and week/default.html. *-] -[-* They should always be identical. If you change one, copy to the other! *-] -[-*****************************************************************************-] -[-* Copyright (C) 2005-2006 Rod Roark and others *-] -[-* *-] -[-* This program is free software; you can redistribute it and/or *-] -[-* modify it under the terms of the GNU General Public License *-] -[-* as published by the Free Software Foundation; either version 2 *-] -[-* of the License, or (at your option) any later version. *-] -[-*****************************************************************************-] -[-config_load file="default.conf"-] -[-*Load the Language Definitions*-] -[-config_load file="lang.$USER_LANG"-] -[-include file="$TPL_NAME/views/header.html"-] -[-* we want to include out stylesheet for this view*-] -[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] -[-eval var=$css-] - - - - - - - - - - - - - - - -[-php-] - - // A_CATEGORY is an ordered array of associative-array categories. - // Keys of interest are: id, name, color, desc, event_duration. - // - // echo "\n"; // debugging - // echo "\n"; // debugging - - $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY']; - - // [-if $PRINT_VIEW != 1-] - // [-*Main Navigation*-] - // [-include file="$TPL_NAME/views/global/navigation.html"-] - // [-/if-] - - $A_EVENTS =& $this->_tpl_vars['A_EVENTS']; - // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod - $providers =& $this->_tpl_vars['providers']; - $times =& $this->_tpl_vars['times']; - $interval = $this->_tpl_vars['interval']; - $viewtype = $this->_tpl_vars['VIEW_TYPE']; - $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL']; - $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL']; - $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL']; - $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL']; - - $Date = postcalendar_getDate(); - if (!isset($y)) $y = substr($Date, 0, 4); - if (!isset($m)) $m = substr($Date, 4, 2); - if (!isset($d)) $d = substr($Date, 6, 2); - - // echo "\n"; - - $MULTIDAY = count($A_EVENTS) > 1; - - $provinfo = getProviderInfo(); - - echo "
\n"; - echo "
\n"; - echo "\n"; - echo " \n"; - echo " \n"; - - // Build the scrolling selection list of providers. - echo " \n"; - - // Build the date and view type selectors and the Go button and the Today button. - echo " \n"; - - // Show the Add and Search buttons. - echo " \n"; - echo " \n"; - - // Show the date/range and its previous- and next-day/week selectors. - echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - echo "
\n"; - echo " \n"; - - // ============================== - // FACILITY FILTERING (lemonsoftware) - $facilities = getFacilities(); - echo " \n"; - // EOS FF - // ============================== - - echo " \n"; - - echo " \n" . - " [?]\n"; - - echo "  \n"; - echo "  \n"; - echo "  \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - $atmp = array_keys($A_EVENTS); - -if ($MULTIDAY) { - echo "<< \n"; - echo dateformat(strtotime($atmp[0])); - echo " - "; - echo dateformat(strtotime($atmp[count($atmp)-1])); - echo " >>\n"; - } else { - echo "<< \n"; - echo dateformat(strtotime($atmp[0]), true); - echo " >>\n"; - } - echo " \n"; - echo "  \n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - -[-/php-] - - - -[-assign var="dayname" value=$DATE|date_format:"%w"-] -[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] -[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] -[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] - -[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] - -[-php-] - - echo "\n"; - $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn'); - - // For each day... - foreach ($A_EVENTS as $date => $events) { - $need_headers = true; - $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2); - - // If multiple days then show a date header for each. - if ($MULTIDAY) { - echo " \n"; - echo " "; - echo " \n"; - } - - $arr_events = $S_EVENTS[$date]; - list($slotkey, $slotevent) = each($arr_events); - - // This is an array of provider status information for this day, - // used to properly assign table cell attributes. - $provstat = array(); - - $slotindex = 0; - $lastslotindex = count($times) - 1; - - // For each time slot... - foreach ($times as $slottime) { - $startampm = ($slottime['mer']) == "pm" ? 2 : 1; - $starttimeh = $slottime['hour']; - $starttimem = $slottime['minute']; - $slotendmins = $starttimeh * 60 + $starttimem + $interval; - - // Repeat doc names at 1PM. This is a kludge; omit it for released code. - // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true; - - // Get all events for all providers just for this time slot now, because we - // can pick up where we left off and because we don't want to re-scan all - // events for the day for each table cell. - // - $arr_slot = array(); - for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { - $starth = substr($slotevent['startTime'], 0, 2); - $startm = substr($slotevent['startTime'], 3, 2); - - if (($starth * 60 + $startm) >= $slotendmins) break; - - $arr_slot[$slotkey] = $slotevent; - - $catid = $slotevent['catid']; - $providerid = $slotevent['aid']; - $durminutes = ceil($slotevent['duration'] / 60); - $durslots = ceil($durminutes / $interval); - - // While we're here, collect information for cell cosmetics. - if ($catid == 2) { // in office - $provstat[$providerid]['in'] = true; - - // Save preferred category info for this IN event. - $provstat[$providerid]['in_cat'] = -1; - $provstat[$providerid]['in_slot0'] = $slotindex; - $provstat[$providerid]['in_slots'] = 1; - if ($slotevent['prefcatid']) { - foreach ($A_CATEGORY as $catkey => $catval) { - if ($catval['id'] == $slotevent['prefcatid']) { - $provstat[$providerid]['in_cat'] = $catkey; - $provstat[$providerid]['in_slots'] = - ceil(ceil($catval['event_duration'] / 60) / $interval); - break; - } - } - // Debugging: - if ($provstat[$providerid]['in_cat'] < 0) { - echo "\n"; // debugging - } - } - - } - else if ($catid == 3) { // out of office - $provstat[$providerid]['in'] = false; - } - else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types - // unavailable slots are marked 'res' for appropriate coloring. - $endindex = $slotindex + $durslots; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['res'] = true; - } - } - // If duration > slot size then mark slots for border control. A slot - // marked 'ext' is not to have a border between itself and the slot below. - if ($durslots > 1) { - $endindex = $slotindex + $durslots - 1; - for ($i = $slotindex; $i < $endindex; ++$i) { - $provstat[$providerid][$i]['ext'] = true; - } - } - } - // Finished getting event information for this time slot. - - // Write a header row with the provider names if appropriate. - if ($need_headers) { - $need_headers = false; - echo " \n"; - foreach ($providers as $provider) { - echo " \n"; - } - echo " \n"; - } - - echo " \n"; - - // We are now ready to write the table row for the current time slot. - // This loops once for each provider to be displayed. - // - foreach ($providers as $provider) { - $providerid = $provider['id']; - - // Mark this as a no-bottom-border slot if the preferred category - // duration extends beyond it. - // - // echo "\n"; // debugging - // - if ($provstat[$providerid]['in']) { - if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots']) - $provstat[$providerid][$slotindex]['ext'] = true; - } - - $content = ""; // this will be the event cell content - - $clsuffix = "acell"; - if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) { - $clsuffix = "ucell"; - } - - // Remove top and/or bottom table cell borders using CSS when events span - // time slots or when the practitioner is not in-office. Using "rowspan" - // would be a difficult and inferior solution to this problem. - // - $tdstyleix = 0; - $timelabel = true; - if ($slotindex < $lastslotindex && - ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) { - $tdstyleix += 1; // no bottom - } - if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] || - !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) { - $tdstyleix += 2; // no top - $timelabel = false; - } - $tdstyle = ' ' . $tdstylearr[$tdstyleix]; - - $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh; - - $in_cat_id = 0; - if ($provstat[$providerid]['in_cat'] >= 0) { - $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']]; - if ($category['id']) $in_cat_id = $category['id']; - } - - // If a slot omits the top border, then we omit the TOD cell's top border - // and skip writing its time-of-day text. This way we can get some rows - // with no content at all, which should produce a more compact and readable - // calendar display. - - echo " \n"; - - echo " \n"; - - // Keep track of whether the doc was in during the previous time slot. - $provstat[$providerid]['wasin'] = $provstat[$providerid]['in']; - - } // end provider - - echo " \n"; - - ++$slotindex; - } // end time slot - } // end day - - echo "
" . - dateformat(strtotime($date), true) . "
"; - echo $provider['fname'][0] . " " . $provider['lname']; - echo "
"; - if ($timelabel) { - echo ""; - echo "$disptimeh:$starttimem"; - } else { - echo "
"; // 1x1 px content so the browser does not suppress borders - } - echo "
"; - - // Scan all events for this time slot and generate the associated HTML for - // this doc. JavaScript is used in hrefs to reduce the volume of output. - // - reset($arr_slot); - while (list($eventkey, $event) = each($arr_slot)) { - if ($event['aid'] != $providerid) continue; - if ($content) $content .= " "; - $starth = substr($event['startTime'], 0, 2); - $startm = substr($event['startTime'], 3, 2); - $eventid = $event['eid']; - $patientid = $event['pid']; - $commapos = strpos($event['patient_name'], ","); - $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos)))); - $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2)))); - $patient_dob = $event['patient_dob']; - $patient_age = $event['patient_age']; - $catid = $event['catid']; - $comment = addslashes($event['hometext']); - $catname = $event['catname']; - $title = "Age $patient_age ($patient_dob)"; - if ($comment && $GLOBALS['calendar_appt_style'] < 4) - $title .= " " . $comment; - if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) { - if ($catid == 2) $catname = "IN"; - else if ($catid == 3) $catname = "OUT"; - else if ($catid == 4) $catname = "VACATION"; - else if ($catid == 8) $catname = "LUNCH"; - else if ($catid == 11) $catname = "RESERVED"; - // Omit lunch, vacation, etc. if the doc is not in-office. - if ($provstat[$providerid]['in'] || $catid < 4) { - $content .= ""; - $content .= $catname; - if ($comment) $content .= " - $comment"; - $content .= ""; - } - } - else { // some sort of patient appointment - $content .= ""; - $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . ""; - $content .= ""; - if ($catid == 1) $content .= ""; - $content .= $lname; - if ($GLOBALS['calendar_appt_style'] != 1) { - $content .= "," . $fname; - if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) { - $content .= "(" . $event['title']; - if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4) - $content .= ": " . htmlspecialchars(trim($event['hometext'])) . ""; - $content .= ")"; - } - } - if ($catid == 1) $content .= ""; - $content .= ""; - } - } // end while - - if (! $content) $content = "
"; // so the browser does not suppress borders - echo $content . "
\n"; - - // [-*footer*-] - // [-include file="$TPL_NAME/views/global/footer.html"-] - // [-include file="$TPL_NAME/views/footer.html"-] - -[-/php-] - - - +[-*Smarty*-] +[-*****************************************************************************-] +[-* This is the source code for both day/default.html and week/default.html. *-] +[-* They should always be identical. If you change one, copy to the other! *-] +[-*****************************************************************************-] +[-* Copyright (C) 2005-2006 Rod Roark and others *-] +[-* *-] +[-* This program is free software; you can redistribute it and/or *-] +[-* modify it under the terms of the GNU General Public License *-] +[-* as published by the Free Software Foundation; either version 2 *-] +[-* of the License, or (at your option) any later version. *-] +[-*****************************************************************************-] +[-config_load file="default.conf"-] +[-*Load the Language Definitions*-] +[-config_load file="lang.$USER_LANG"-] +[-include file="$TPL_NAME/views/header.html"-] +[-* we want to include out stylesheet for this view*-] +[-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-] +[-eval var=$css-] +[-if $PRINT_VIEW != 1-] +[-*Main Navigation*-] +[-include file="$TPL_NAME/views/global/navigation.html"-] +[-/if-] + + + +[-assign var="dayname" value=$DATE|date_format:"%w"-] +[-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-] +[-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-] +[-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-] + +[-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-] + +[-php-] + + echo "\n"; + $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn'); + + // For each day... + foreach ($A_EVENTS as $date => $events) { + $need_headers = true; + $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2); + //(CHEMED) set MULTIDAY otherwise day header is not shown. This is what makes week view different from day view + $MULTIDAY = true; + // If multiple days then show a date header for each. + if ($MULTIDAY) { + echo " \n"; + //(CHEMED) added color + echo " "; + echo " \n"; + } + + $arr_events = $S_EVENTS[$date]; + list($slotkey, $slotevent) = each($arr_events); + + // This is an array of provider status information for this day, + // used to properly assign table cell attributes. + $provstat = array(); + + $slotindex = 0; + $lastslotindex = count($times) - 1; + + // For each time slot... + foreach ($times as $slottime) { + $startampm = ($slottime['mer']) == "pm" ? 2 : 1; + $starttimeh = $slottime['hour']; + $starttimem = $slottime['minute']; + $slotendmins = $starttimeh * 60 + $starttimem + $interval; + + // Repeat doc names at 1PM. This is a kludge; omit it for released code. + // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true; + + // Get all events for all providers just for this time slot now, because we + // can pick up where we left off and because we don't want to re-scan all + // events for the day for each table cell. + // + $arr_slot = array(); + for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) { + $starth = substr($slotevent['startTime'], 0, 2); + $startm = substr($slotevent['startTime'], 3, 2); + + if (($starth * 60 + $startm) >= $slotendmins) break; + + $arr_slot[$slotkey] = $slotevent; + + $catid = $slotevent['catid']; + $providerid = $slotevent['aid']; + $durminutes = ceil($slotevent['duration'] / 60); + $durslots = ceil($durminutes / $interval); + + // While we're here, collect information for cell cosmetics. + if ($catid == 2) { // in office + $provstat[$providerid]['in'] = true; + + // Save preferred category info for this IN event. + $provstat[$providerid]['in_cat'] = -1; + $provstat[$providerid]['in_slot0'] = $slotindex; + $provstat[$providerid]['in_slots'] = 1; + if ($slotevent['prefcatid']) { + foreach ($A_CATEGORY as $catkey => $catval) { + if ($catval['id'] == $slotevent['prefcatid']) { + $provstat[$providerid]['in_cat'] = $catkey; + $provstat[$providerid]['in_slots'] = + ceil(ceil($catval['event_duration'] / 60) / $interval); + break; + } + } + // Debugging: + if ($provstat[$providerid]['in_cat'] < 0) { + echo "\n"; // debugging + } + } + + } + else if ($catid == 3) { // out of office + $provstat[$providerid]['in'] = false; + } + else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types + // unavailable slots are marked 'res' for appropriate coloring. + $endindex = $slotindex + $durslots; + for ($i = $slotindex; $i < $endindex; ++$i) { + $provstat[$providerid][$i]['res'] = true; + } + } + // If duration > slot size then mark slots for border control. A slot + // marked 'ext' is not to have a border between itself and the slot below. + if ($durslots > 1) { + $endindex = $slotindex + $durslots - 1; + for ($i = $slotindex; $i < $endindex; ++$i) { + $provstat[$providerid][$i]['ext'] = true; + } + } + } + // Finished getting event information for this time slot. + + // Write a header row with the provider names if appropriate. + if ($need_headers) { + $need_headers = false; + echo " \n"; + foreach ($providers as $provider) { + echo " \n"; + } + echo " \n"; + } + + echo " \n"; + + // We are now ready to write the table row for the current time slot. + // This loops once for each provider to be displayed. + // + foreach ($providers as $provider) { + $providerid = $provider['id']; + + // Mark this as a no-bottom-border slot if the preferred category + // duration extends beyond it. + // + // echo "\n"; // debugging + // + if ($provstat[$providerid]['in']) { + if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots']) + $provstat[$providerid][$slotindex]['ext'] = true; + } + + $content = ""; // this will be the event cell content + + $clsuffix = "acell"; + if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) { + $clsuffix = "ucell"; + } + + // Remove top and/or bottom table cell borders using CSS when events span + // time slots or when the practitioner is not in-office. Using "rowspan" + // would be a difficult and inferior solution to this problem. + // + $tdstyleix = 0; + $timelabel = true; + if ($slotindex < $lastslotindex && + ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) { + $tdstyleix += 1; // no bottom + } + if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] || + !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) { + $tdstyleix += 2; // no top + $timelabel = false; + } + $tdstyle = ' ' . $tdstylearr[$tdstyleix]; + + $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh; + + $in_cat_id = 0; + if ($provstat[$providerid]['in_cat'] >= 0) { + $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']]; + if ($category['id']) $in_cat_id = $category['id']; + } + + // If a slot omits the top border, then we omit the TOD cell's top border + // and skip writing its time-of-day text. This way we can get some rows + // with no content at all, which should produce a more compact and readable + // calendar display. + + echo " \n"; + + echo " \n"; + + // Keep track of whether the doc was in during the previous time slot. + $provstat[$providerid]['wasin'] = $provstat[$providerid]['in']; + + } // end provider + + echo " \n"; + + ++$slotindex; + } // end time slot + } // end day + + echo "
" . + dateformat(strtotime($date), true) . "
"; + echo $provider['fname'][0] . " " . $provider['lname']; + echo "
"; +// (CHEMED) always show timelabel if ($timelabel) { + echo ""; + echo "$disptimeh:$starttimem"; +// } else { +// echo "
"; // 1x1 px content so the browser does not suppress borders +// END (CHEMED) } + echo "
"; + + // Scan all events for this time slot and generate the associated HTML for + // this doc. JavaScript is used in hrefs to reduce the volume of output. + // + reset($arr_slot); + while (list($eventkey, $event) = each($arr_slot)) { + if ($event['aid'] != $providerid) continue; + if ($content) $content .= " "; + $starth = substr($event['startTime'], 0, 2); + $startm = substr($event['startTime'], 3, 2); + $eventid = $event['eid']; + $patientid = $event['pid']; + $commapos = strpos($event['patient_name'], ","); + $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos)))); + $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2)))); + $patient_dob = $event['patient_dob']; + $patient_age = $event['patient_age']; + $catid = $event['catid']; + $comment = addslashes($event['hometext']); + $catname = $event['catname']; + $title = "Age $patient_age ($patient_dob)"; + if ($comment && $GLOBALS['calendar_appt_style'] < 4) + $title .= " " . $comment; + if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) { + if ($catid == 2) $catname = "IN"; + else if ($catid == 3) $catname = "OUT"; + else if ($catid == 4) $catname = "VACATION"; + else if ($catid == 8) $catname = "LUNCH"; + else if ($catid == 11) $catname = "RESERVED"; + // Omit lunch, vacation, etc. if the doc is not in-office. + // Omit lunch, vacation, etc. if the doc is not in-office. + if ($provstat[$providerid]['in'] || $catid < 4) { + $content .= ""; +// $content .=""; //(CHEMED) Color events by category start + $content .= $catname; + if ($comment) $content .= " - $comment"; +// $content .=""; //(CHEMED) Color events by category end + $content .= ""; + } + } + else { // some sort of patient appointment + $content .= ""; + $content .=" "; //(CHEMED) Color events by category start + $content .= $starth . ':' . $startm . "".htmlspecialchars($event['apptstatus']).""; //(CHEMED) added 'span' to apptstatus + $content .=""; //(CHEMED) Color events by category end + $content .= ""; + $content .= ""; + $content .=""; //(CHEMED) Color events by category start + if ($catid == 1) $content .= ""; + $content .= $lname; + if ($GLOBALS['calendar_appt_style'] != 1) { + $content .= "," . $fname; + if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) { + $content .= "(" . $event['title']; + if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4) + $content .= ": " . htmlspecialchars(trim($event['hometext'])) . ""; + $content .= ")"; + } + } + if ($catid == 1) $content .= ""; + $content .=" "; //(CHEMED) Color events by category end + $content .= ""; + } + } // end while + + if (! $content) $content = "
"; // so the browser does not suppress borders + echo $content . "
\n"; + + // [-*footer*-] + // [-include file="$TPL_NAME/views/global/footer.html"-] + // [-include file="$TPL_NAME/views/footer.html"-] + +[-/php-] + + + diff --git a/interface/main/calendar/modules/PostCalendar/pnuserapi.php b/interface/main/calendar/modules/PostCalendar/pnuserapi.php index df44023e2..2e9fd06a9 100644 --- a/interface/main/calendar/modules/PostCalendar/pnuserapi.php +++ b/interface/main/calendar/modules/PostCalendar/pnuserapi.php @@ -1,1444 +1,1458 @@ -= 12) ? 'pm' : 'am'; - - // $minute is an array of time slot strings within this hour. - $minute = array('00'); - - for($minutes = $GLOBALS['calendar_interval']; $minutes <= 60; $minutes += $GLOBALS['calendar_interval']) { - if($minutes <= '9'){ - $under_ten = "0" . $minutes; - array_push($minute, "$under_ten"); - } - else if($minutes >= '60') { - break; - } - else { - array_push($minute, "$minutes"); - } - } - - foreach($minute as $m ){ - array_push($times, array("hour"=>$blocknum, "minute"=>$m, "mer"=>$mer)); - } - } - - //================================================================= - // get the module's information - //================================================================= - $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); - $pcDir = $modinfo['directory']; - unset($modinfo); - - //================================================================= - // grab the for post variable - //================================================================= - // $pc_username = pnVarCleanFromInput('pc_username'); - $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19 - $category = pnVarCleanFromInput('pc_category'); - $topic = pnVarCleanFromInput('pc_topic'); - - //================================================================= - // set the correct date - //================================================================= - $Date =& postcalendar_getDate(); - - //================================================================= - // get the current view - //================================================================= - if(!isset($viewtype)) { $viewtype = 'month'; } - - //================================================================= - // Find out what Template we're using - //================================================================= - $template_name = _SETTING_TEMPLATE; - if(!isset($template_name)) { $template_name = 'default'; } - - //================================================================= - // Find out what Template View to use - //================================================================= - $template_view = pnVarCleanFromInput('tplview'); - if(!isset($template_view)) { $template_view = 'default'; } - - //================================================================= - // See if the template view exists - //================================================================= - if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) { - $template_view_load = 'default'; - } else { - $template_view_load = pnVarPrepForOS($template_view); - } - - //================================================================= - // Grab the current theme information - //================================================================= - pnThemeLoad(pnUserGetTheme()); - global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2; - - //================================================================= - // Insert necessary JavaScript into the page - //================================================================= - $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup'); - - //================================================================= - // Setup Smarty Template Engine - //================================================================= - $tpl =& new pcSmarty(); - - //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) { - //diable caching completely - if (true) { - //================================================================= - // Let's just finish setting things up - //================================================================= - $the_year = substr($Date,0,4); - $the_month = substr($Date,4,2); - $the_day = substr($Date,6,2); - $last_day = Date_Calc::daysInMonth($the_month,$the_year); - - //================================================================= - // populate the template object with information for - // Month Names, Long Day Names and Short Day Names - // as translated in the language files - // (may be adding more here soon - based on need) - //================================================================= - $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN, - _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC); - - $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT, - _CALTUESDAYSHORT, _CALWEDNESDAYSHORT, - _CALTHURSDAYSHORT, _CALFRIDAYSHORT, - _CALSATURDAYSHORT); - - $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY, - _CALTUESDAY, _CALWEDNESDAY, - _CALTHURSDAY, _CALFRIDAY, - _CALSATURDAY); - //================================================================= - // here we need to set up some information for later - // variable creation. This helps us establish the correct - // date ranges for each view. There may be a better way - // to handle all this, but my brain hurts, so your comments - // are very appreciated and welcomed. - //================================================================= - switch (_SETTING_FIRST_DAY_WEEK) - { - case _IS_MONDAY: - $pc_array_pos = 1; - $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year)); - $week_day = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year)); - $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); - if($end_dow != 0) { - $the_last_day = $last_day+(7-$end_dow); - } else { - $the_last_day = $last_day; - } - break; - case _IS_SATURDAY: - $pc_array_pos = 6; - $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year)); - $week_day = date('w',mktime(0,0,0,$the_month,$the_day+1,$the_year)); - $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); - if($end_dow == 6) { - $the_last_day = $last_day+6; - } elseif($end_dow != 5) { - $the_last_day = $last_day+(5-$end_dow); - } else { - $the_last_day = $last_day; - } - break; - case _IS_SUNDAY: - default: - $pc_array_pos = 0; - $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year)); - $week_day = date('w',mktime(0,0,0,$the_month,$the_day,$the_year)); - $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); - if($end_dow != 6) { - $the_last_day = $last_day+(6-$end_dow); - } else { - $the_last_day = $last_day; - } - break; - } - - // passing the times array to the tpl the times array is for the days schedule - $tpl->assign_by_ref("times",$times); - // load the table width to the template - // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']); - - //================================================================= - // Week View is a bit of a pain in the ass, so we need to - // do some extra setup for that view. This section will - // find the correct starting and ending dates for a given - // seven day period, based on the day of the week the - // calendar is setup to run under (Sunday, Saturday, Monday) - //================================================================= - $first_day_of_week = sprintf('%02d',$the_day-$week_day); - $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year)); - list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day); - $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', - array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year))); - $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year)); - list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day); - $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', - array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year))); - - //================================================================= - // Setup some information so we know the actual month's dates - // also get today's date for later use and highlighting - //================================================================= - $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year)); - $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year)); - $today_date = postcalendar_today('%Y-%m-%d'); - - //================================================================= - // Setup the starting and ending date ranges for pcGetEvents() - //================================================================= - switch($viewtype) { - case 'day' : - $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year)); - $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year)); - break; - case 'week' : - $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year"; - $ending_date = "$week_last_day_month/$week_last_day_date/$week_last_day_year"; - $calendarView = Date_Calc::getCalendarWeek($week_first_day_date, - $week_first_day_month, - $week_first_day_year, - '%Y-%m-%d'); - break; - case 'month' : - $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year)); - $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year)); - $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d'); - break; - case 'year' : - $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year)); - $ending_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year+1)); - $calendarView = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d'); - break; - } - - //================================================================= - // Load the events - //================================================================= - if($viewtype != 'year') { - $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date, 'viewtype' => $viewtype)); - } else { - $eventsByDate = array(); - } - - //================================================================= - // Create an array with the day names in the correct order - //================================================================= - $daynames = array(); - $numDays = count($pc_long_day_names); - for($i=0; $i < $numDays; $i++) { - if($pc_array_pos >= $numDays) { - $pc_array_pos = 0; - } - array_push($daynames,$pc_long_day_names[$pc_array_pos]); - $pc_array_pos++; - } - unset($numDays); - $sdaynames = array(); - $numDays = count($pc_short_day_names); - for($i=0; $i < $numDays; $i++) { - if($pc_array_pos >= $numDays) { - $pc_array_pos = 0; - } - array_push($sdaynames,$pc_short_day_names[$pc_array_pos]); - $pc_array_pos++; - } - unset($numDays); - - //================================================================= - // Prepare some values for the template - //================================================================= - $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d'); - $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d'); - - $pc_prev = pnModURL(__POSTCALENDAR__,'user','view', - array('tplview'=>$template_view, - 'viewtype'=>'month', - 'Date'=>$prev_month, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - - $pc_next = pnModURL(__POSTCALENDAR__,'user','view', - array('tplview'=>$template_view, - 'viewtype'=>'month', - 'Date'=>$next_month, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - - $prev_day = Date_Calc::prevDay($the_day,$the_month,$the_year,'%Y%m%d'); - $next_day = Date_Calc::nextDay($the_day,$the_month,$the_year,'%Y%m%d'); - $pc_prev_day = pnModURL(__POSTCALENDAR__,'user','view', - array('tplview'=>$template_view, - 'viewtype'=>'day', - 'Date'=>$prev_day, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - - $pc_next_day = pnModURL(__POSTCALENDAR__,'user','view', - array('tplview'=>$template_view, - 'viewtype'=>'day', - 'Date'=>$next_day, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - - $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year)); - $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+1,$week_last_day_year)); - $pc_prev_week = pnModURL(__POSTCALENDAR__,'user','view', - array('viewtype'=>'week', - 'Date'=>$prev_week, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - $pc_next_week = pnModURL(__POSTCALENDAR__,'user','view', - array('viewtype'=>'week', - 'Date'=>$next_week, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - - $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1)); - $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+1)); - $pc_prev_year = pnModURL(__POSTCALENDAR__,'user','view', - array('viewtype'=>'year', - 'Date'=>$prev_year, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - $pc_next_year = pnModURL(__POSTCALENDAR__,'user','view', - array('viewtype'=>'year', - 'Date'=>$next_year, - 'pc_username'=>$pc_username, - 'pc_category'=>$category, - 'pc_topic'=>$topic)); - - //================================================================= - // Populate the template - //================================================================= - $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories'); - - if(isset($calendarView)) { - $tpl->assign_by_ref('CAL_FORMAT',$calendarView); - } - - if($viewtype == "week") { - $last_blocks = array(); - foreach($eventsByDate as $cdate => $day) { - $tblock = array_reverse($day['blocks']); - $last_blocks[$cdate] = count($tblock) -1; - for ($i=0;$iassign("last_blocks",$last_blocks); - } - - $tpl->assign('STYLE',$GLOBALS['style']); - $tpl->assign('show_days',$show_days); - $provinfo = getProviderInfo(); - $single = array(); - - // filter the display on the requested username, the provinfo array is - // used to build columns in the week view. - - foreach($provinfo as $provider) { - if(is_array($pc_username)){ - foreach($pc_username as $uname) { - if (!empty($pc_username) && $provider['username'] == $uname) { - array_push($single,$provider); - } - } - } - else { - if (!empty($pc_username) && $provider['username'] == $pc_username) { - array_push($single,$provider); - } - } - } - if ($single != null) { - $provinfo = $single; - } - - //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other"); - $tpl->assign_by_ref('providers', $provinfo); - - if (pnVarCleanFromInput("show_days") != 1) { - $tpl->assign('showdaysurl',"index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1"); - } - - $tpl->assign('interval', $GLOBALS['calendar_interval']); - $tpl->assign_by_ref('VIEW_TYPE',$viewtype); - $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names); - $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names); - $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names); - $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames); - $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames); - $tpl->assign_by_ref('A_EVENTS',$eventsByDate); - $tpl->assign_by_ref('A_CATEGORY',$all_categories); - $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev); - $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next); - $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day); - $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day); - $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week); - $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week); - $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year); - $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year); - $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start); - $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end); - $tpl->assign_by_ref('TODAY_DATE',$today_date); - $tpl->assign_by_ref('DATE',$Date); - $tpl->assign_by_ref('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__,'user','submit')); - $tpl->assign_by_ref('interval',$intervals); -}; - - //================================================================= - // Parse the template - //================================================================= - $template = "$template_name/views/$viewtype/$template_view_load.html"; - if(!$print) { - $output .= "\n\n\n\n"; - $output .= $tpl->fetch($template,$cacheid); // cache id - $output .= "\n\n\n\n"; - } else { - $theme = pnUserGetTheme(); - echo ""; - echo "\n\n\n"; - echo "\n"; - echo "\n"; - echo $output; - $tpl->display($template,$cacheid); - echo postcalendar_footer(); - echo "\n"; - session_write_close(); - exit; - } - //================================================================= - // Return the output - //================================================================= - return $output; -} - -/** - * postcalendar_userapi_eventPreview - * Creates the detailed event display and outputs html. - * Accepts an array of key/value pairs - * @param array $event array of event details from the form - * @return string html output - * @access public - */ -function postcalendar_userapi_eventPreview($args) -{ - // get the theme globals :: is there a better way to do this? - pnThemeLoad(pnUserGetTheme()); - global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5; - global $textcolor1, $textcolor2; - - extract($args); unset($args); - $uid = pnUserGetVar('uid'); - //================================================================= - // Setup Smarty Template Engine - //================================================================= - $tpl =& new pcSmarty(); - $tpl->caching = false; - // add preceding zeros - $event_starttimeh = sprintf('%02d',$event_starttimeh); - $event_starttimem = sprintf('%02d',$event_starttimem); - $event_startday = sprintf('%02d',$event_startday); - $event_startmonth = sprintf('%02d',$event_startmonth); - $event_endday = sprintf('%02d',$event_endday); - $event_endmonth = sprintf('%02d',$event_endmonth); - - if(!(bool)_SETTING_TIME_24HOUR) { - if($event_startampm == _PM_VAL) { - if($event_starttimeh != 12) { - $event_starttimeh+=12; - } - } elseif($event_startampm == _AM_VAL) { - if($event_starttimeh == 12) { - $event_starttimeh = 00; - } - } - } - - $event_startampm." - "; - $startTime = $event_starttimeh.':'.$event_starttimem.' '; - - $event = array(); - $event['eid'] = ''; - $event['uname'] = $uname; - $event['catid'] = $event_category; - if($pc_html_or_text == 'html') { - $prepFunction = 'pcVarPrepHTMLDisplay'; - } else { - $prepFunction = 'pcVarPrepForDisplay'; - } - $event['title'] = $prepFunction($event_subject); - $event['hometext'] = $prepFunction($event_desc); - $event['desc'] = $event['hometext']; - $event['date'] = $event_startyear.$event_startmonth.$event_startday; - $event['duration'] = $event_duration; - $event['duration_hours'] = $event_dur_hours; - $event['duration_minutes'] = $event_dur_minutes; - $event['endDate'] = $event_endyear.'-'.$event_endmonth.'-'.$event_endday; - $event['startTime'] = $startTime; - $event['recurrtype'] = ''; - $event['recurrfreq'] = ''; - $event['recurrspec'] = $event_recurrspec; - $event['topic'] = $event_topic; - $event['alldayevent'] = $event_allday; - $event['conttel'] = $prepFunction($event_conttel); - $event['contname'] = $prepFunction($event_contname); - $event['contemail'] = $prepFunction($event_contemail); - $event['website'] = $prepFunction(postcalendar_makeValidURL($event_website)); - $event['fee'] = $prepFunction($event_fee); - $event['location'] = $prepFunction($event_location); - $event['street1'] = $prepFunction($event_street1); - $event['street2'] = $prepFunction($event_street2); - $event['city'] = $prepFunction($event_city); - $event['state'] = $prepFunction($event_state); - $event['postal'] = $prepFunction($event_postal); - - //================================================================= - // get event's topic information - //================================================================= - if(_SETTING_DISPLAY_TOPICS) { - list($dbconn) = pnDBGetConn(); - $pntable = pnDBGetTables(); - $topics_table = $pntable['topics']; - $topics_column = $pntable['topics_column']; - $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage] - FROM $topics_table - WHERE $topics_column[topicid] = $event[topic] - LIMIT 1"; - $topic_result = $dbconn->Execute($topicsql); - list($event['topictext'],$event['topicimg']) = $topic_result->fields; - $topic_result->Close(); - } else { - $event['topictext'] = $event['topicimg'] = ''; - } - //================================================================= - // Find out what Template we're using - //================================================================= - $template_name = _SETTING_TEMPLATE; - if(!isset($template_name)) { - $template_name = 'default'; - } - //================================================================= - // populate the template - //================================================================= - if(!empty($event['location']) || !empty($event['street1']) || - !empty($event['street2']) || !empty($event['city']) || - !empty($event['state']) || !empty($event['postal'])) { - $tpl->assign('LOCATION_INFO',true); - } else { - $tpl->assign('LOCATION_INFO',false); - } - if(!empty($event['contname']) || !empty($event['contemail']) || - !empty($event['conttel']) || !empty($event['website'])) { - $tpl->assign('CONTACT_INFO',true); - } else { - $tpl->assign('CONTACT_INFO',false); - } - $tpl->assign_by_ref('A_EVENT',$event); - $tpl->assign('STYLE',$GLOBALS['style']); - //================================================================= - // Parse the template - //================================================================= - $output = "\n\n\n\n"; - $output .= "\n\n\n\n"; - $output .= $tpl->fetch($template_name.'/user/preview.html'); - $output .= "\n\n\n\n"; - - return $output; -} - -/** - * checkEventCollision - * Returns an array containing any events that collide with the specified event - * @params array(key=>value) - * @return array $events[][] - */ - function checkEventCollision($edata) { - - extract($edata); - $sdate = ($event_startmonth.'/'.$event_startday.'/'.$event_startyear); - $edate = $sdate; - //hour from forms is 12 not 24 format, convert here - if($event_startampm == 2 && $event_starttimeh != 12) - $event_starttimeh += 12; - elseif ($event_startampm == 1 && $event_starttimeh == 12) - $event_starttimeh -= 12; - - $stime = date("H:i:00",strtotime($event_starttimeh.':'.$event_starttimem.':00')); - $etime = date("H:i:00",$event_duration + strtotime($stime)); - //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate
"; - $a = array('collideFlag' => true,'start'=>$edate,'end'=>$sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime); - $eventsByDate =& postcalendar_userapi_pcGetEvents($a); - //print_r($eventsByDate); - $collisions = array(); - foreach ($eventsByDate as $day) { - foreach ($day as $event) { - if ($event['duration'] == 0 && $event['alldayevent'] == 0) { - continue; - } - elseif($event['alldayevent'] == 1) { - $collisions[] = $event; - } - $festart = strtotime($event['startTime']); - $feend = strtotime($event['startTime'] + $event['duration']); - $estart = strtotime($stime); - $eend = strtotime($etime); - - //echo "festart = $festart feend = $feend estart = $estart eend = $eend
"; - if ($festart < $eend && $feend > $estart) { - $collisions[] = $event; - } - elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) { - $collisions[] = $event; - } - elseif ($festart >= $estart && $festart < $eend) { - $collisions[] = $event; - } - } - } - //foreach ($collisions as $collide) { - // echo "collided: " . $collide['title'] . "
"; - //} - return $collisions; - } - -/** - * postcalendar_userapi_pcQueryEventsFA - * Returns an array containing the event's information for first available queiries - * @params array(key=>value) - * @params string key eventstatus - * @params int value -1 == hidden ; 0 == queued ; 1 == approved - * @return array $events[][] - */ -function &postcalendar_userapi_pcQueryEventsFA($args) { - - $end = '0000-00-00'; - extract($args); - $eventstatus = 1; - if (is_numeric($event_status)) - $eventstatus = $event_status; - - if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); } - list($sy,$sm,$sd) = explode('-',$start); - - list($dbconn) = pnDBGetConn(); - $pntable = pnDBGetTables(); - // link to the events tables - $table = $pntable['postcalendar_events']; - $cattable = $pntable['postcalendar_categories']; - - $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, a.pc_title, " . - "a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, a.pc_endDate, " . - "a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, a.pc_recurrspec, " . - "a.pc_topic, a.pc_alldayevent, a.pc_location, a.pc_conttel, " . - "a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, a.pc_sharing, " . - "a.pc_prefcatid, " . - "b.pc_catcolor, b.pc_catname, b.pc_catdesc, a.pc_pid, a.pc_aid, " . - "concat(u.fname,' ',u.lname) as provider_name, " . - "concat(pd.fname,' ',pd.lname) as patient_name, " . - "concat(u2.fname, ' ', u2.lname) as owner_name, pd.DOB as patient_dob " . - "FROM ( $table AS a, $cattable AS b ) " . - "LEFT JOIN users as u ON a.pc_aid = u.id " . - "LEFT JOIN users as u2 ON a.pc_aid = u2.id " . - "LEFT JOIN patient_data as pd ON a.pc_pid=pd.pid " . - "WHERE b.pc_catid = a.pc_catid " . - "AND a.pc_eventstatus = $eventstatus " . - "AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') " . - "AND a.pc_eventDate <= '$end' " . - "AND (a.pc_aid = '" . $provider_id . "' OR a.pc_aid = '')"; - - //====================================================================== - // START SEARCH FUNCTIONALITY - //====================================================================== - if(!empty($s_keywords)) $sql .= "AND ($s_keywords) "; - if(!empty($s_category)) $sql .= "AND ($s_category) "; - if(!empty($s_topic)) $sql .= "AND ($s_topic) "; - if(!empty($collide_etime) && !empty($collide_stime)) { - $sql .= "AND NOT ((pc_endTime <= '$collide_stime') OR (pc_startTime >= '$collide_etime')) AND pc_endTime IS NOT NULL "; - } - if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') "; - if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') "; - //====================================================================== - // Search sort and limitation - //====================================================================== - if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_startTime ASC"; - else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort"; - //====================================================================== - // END SEARCH FUNCTIONALITY - //====================================================================== - //echo "
sql: $sql
"; - $result = $dbconn->Execute($sql); - if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg()); - - // put the information into an array for easy access - $events = array(); - // return an empty array if we don't have any results - if(!isset($result)) { return $events; } - - for($i=0; !$result->EOF; $result->MoveNext()) { - - // get the results from the query - if(isset($tmp)) { unset($tmp); } $tmp = array(); - list($tmp['eid'], $tmp['uname'], $tmp['catid'], - $tmp['title'], $tmp['time'], $tmp['hometext'], - $tmp['eventDate'], $tmp['duration'], $tmp['endDate'], - $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'], - $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'], - $tmp['location'], $tmp['conttel'], $tmp['contname'], - $tmp['contemail'], $tmp['website'], $tmp['fee'], - $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'], - $tmp['catname'], $tmp['catdesc'], $tmp['pid'], - $tmp['aid'], $tmp['provider_name'], $tmp['patient_name'], - $tmp['owner_name'], $tmp['patient_dob']) = $result->fields; - - // grab the name of the topic - $topicname = pcGetTopicName($tmp['topic']); - // get the user id of event's author - $cuserid = @$nuke_users[strtolower($tmp['uname'])]; - // check the current event's permissions - // the user does not have permission to view this event - // if any of the following evaluate as false - if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) { - continue; - } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) { - continue; - } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) { - continue; - } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) { - continue; - } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) { - continue; - } - - // add event to the array if we passed the permissions check - // this is the common information - $events[$i]['eid'] = $tmp['eid']; - $events[$i]['uname'] = $tmp['uname']; - $events[$i]['uid'] = $cuserid; - $events[$i]['catid'] = $tmp['catid']; - $events[$i]['time'] = $tmp['time']; - $events[$i]['eventDate'] = $tmp['eventDate']; - $events[$i]['duration'] = $tmp['duration']; - // there has to be a more intelligent way to do this - @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60)); - $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2); - //'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - $events[$i]['endDate'] = $tmp['endDate']; - $events[$i]['startTime'] = $tmp['startTime']; - $events[$i]['recurrtype'] = $tmp['recurrtype']; - $events[$i]['recurrfreq'] = $tmp['recurrfreq']; - $events[$i]['recurrspec'] = $tmp['recurrspec']; - - $rspecs = unserialize($tmp['recurrspec']); - $events[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq']; - $events[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type']; - $events[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num']; - $events[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day']; - $events[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq']; - - $events[$i]['topic'] = $tmp['topic']; - $events[$i]['alldayevent'] = $tmp['alldayevent']; - $events[$i]['catcolor'] = $tmp['catcolor']; - $events[$i]['catname'] = $tmp['catname']; - $events[$i]['catdesc'] = $tmp['catdesc']; - $events[$i]['pid'] = $tmp['pid']; - $events[$i]['patient_name']= $tmp['patient_name']; - $events[$i]['provider_name'] = $tmp['provider_name']; - $events[$i]['owner_name'] = $tmp['owner_name']; - $events[$i]['patient_dob'] = $tmp['patient_dob']; - $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4); - $events[$i]['sharing'] = $tmp['sharing']; - $events[$i]['prefcatid'] = $tmp['prefcatid']; - $events[$i]['aid'] = $tmp['aid']; - $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']); - if($events[$i]['intervals'] == 0) - $events[$i]['intervals'] = 1; - // is this a public event to be shown as busy? - if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) { - // make it not display any information - $events[$i]['title'] = _USER_BUSY_TITLE; - $events[$i]['hometext'] = _USER_BUSY_MESSAGE; - $events[$i]['desc'] = _USER_BUSY_MESSAGE; - $events[$i]['conttel'] = ''; - $events[$i]['contname'] = ''; - $events[$i]['contemail'] = ''; - $events[$i]['website'] = ''; - $events[$i]['fee'] = ''; - $events[$i]['location'] = ''; - $events[$i]['street1'] = ''; - $events[$i]['street2'] = ''; - $events[$i]['city'] = ''; - $events[$i]['state'] = ''; - $events[$i]['postal'] = ''; - } else { - $display_type = substr($tmp['hometext'],0,6); - if($display_type == ':text:') { - $prepFunction = 'pcVarPrepForDisplay'; - $tmp['hometext'] = substr($tmp['hometext'],6); - } elseif($display_type == ':html:') { - $prepFunction = 'pcVarPrepHTMLDisplay'; - $tmp['hometext'] = substr($tmp['hometext'],6); - } else { - $prepFunction = 'pcVarPrepHTMLDisplay'; - } - unset($display_type); - $events[$i]['title'] = $prepFunction($tmp['title']); - $events[$i]['hometext'] = $prepFunction($tmp['hometext']); - $events[$i]['desc'] = $events[$i]['hometext']; - $events[$i]['conttel'] = $prepFunction($tmp['conttel']); - $events[$i]['contname'] = $prepFunction($tmp['contname']); - $events[$i]['contemail'] = $prepFunction($tmp['contemail']); - $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website'])); - $events[$i]['fee'] = $prepFunction($tmp['fee']); - $loc = unserialize($tmp['location']); - $events[$i]['location'] = $prepFunction($loc['event_location']); - $events[$i]['street1'] = $prepFunction($loc['event_street1']); - $events[$i]['street2'] = $prepFunction($loc['event_street2']); - $events[$i]['city'] = $prepFunction($loc['event_city']); - $events[$i]['state'] = $prepFunction($loc['event_state']); - $events[$i]['postal'] = $prepFunction($loc['event_postal']); - } - $i++; - } - unset($tmp); - $result->Close(); - return $events; -} - - -/** - * postcalendar_userapi_pcQueryEvents - * Returns an array containing the event's information - * @params array(key=>value) - * @params string key eventstatus - * @params int value -1 == hidden ; 0 == queued ; 1 == approved - * @return array $events[][] - */ -function &postcalendar_userapi_pcQueryEvents($args) -{ - $end = '0000-00-00'; - extract($args); - - // echo "\n"; // debugging - - // $pc_username = pnVarCleanFromInput('pc_username'); - $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19 - if (empty($pc_username) || is_array($pc_username)) { - $pc_username = "__PC_ALL__"; - } - - // echo "\n"; // debugging - - $topic = pnVarCleanFromInput('pc_topic'); - $category = pnVarCleanFromInput('pc_category'); - - if(!empty($pc_username) && (strtolower($pc_username) != 'anonymous')) { - if($pc_username=='__PC_ALL__' || $pc_username == -1) { - $ruserid = -1; - } else { - $ruserid = getIDfromUser($pc_username); - } - } - - if(!isset($eventstatus)) { $eventstatus = 1; } - // sanity check on eventstatus - if((int)$eventstatus < -1 || (int)$eventstatus > 1) { $eventstatus = 1; } - if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); } - list($sy,$sm,$sd) = explode('-',$start); - - list($dbconn) = pnDBGetConn(); - $pntable = pnDBGetTables(); - // link to the events tables - $table = $pntable['postcalendar_events']; - $cattable = $pntable['postcalendar_categories']; - $topictable = $pntable['postcalendar_topics']; - - $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, " . - "a.pc_title, a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, " . - "a.pc_endDate, a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, " . - "a.pc_recurrspec, a.pc_topic, a.pc_alldayevent, a.pc_location, " . - "a.pc_conttel, a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, " . - "a.pc_sharing, a.pc_prefcatid, b.pc_catcolor, b.pc_catname, " . - "b.pc_catdesc, a.pc_pid, a.pc_apptstatus, a.pc_aid, " . - "concat(u.fname,' ',u.lname) as provider_name, " . - "concat(pd.lname,', ',pd.fname) as patient_name, " . - "concat(u2.fname, ' ', u2.lname) as owner_name, " . - "DOB as patient_dob, pd.pubpid " . - "FROM ( $table AS a, $cattable AS b ) " . - "LEFT JOIN users as u ON a.pc_aid = u.id " . - "LEFT JOIN users as u2 ON a.pc_aid = u2.id " . - "LEFT JOIN patient_data as pd ON a.pc_pid = pd.pid " . - "WHERE b.pc_catid = a.pc_catid " . - "AND a.pc_eventstatus = $eventstatus " . - "AND ((a.pc_endDate >= '$start' AND a.pc_eventDate <= '$end') OR " . - "(a.pc_endDate = '0000-00-00' AND a.pc_eventDate >= '$start' AND " . - "a.pc_eventDate <= '$end')) "; - - //================================== - //FACILITY FILTERING (lemonsoftware) - if ( $_SESSION['pc_facility'] ) { - $pc_facility = $_SESSION['pc_facility']; - $sql .= " AND a.pc_facility = $pc_facility "; - } - //EOS FACILITY FILTERING (lemonsoftware) - //================================== - - - // The above 3 lines replaced these: - // AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') - // AND a.pc_eventDate <= '$end' "; - - if(!empty($providerID)) - { - $ruserid = $providerID; - } - - if(isset($ruserid)) { - // get all events for the specified username - if($ruserid == -1) { - $sql .= "AND (a.pc_sharing = '" . SHARING_BUSY . "' "; - $sql .= "OR a.pc_sharing = '" . SHARING_PUBLIC . "') "; - } else { - $sql .= "AND a.pc_aid = " . $ruserid . " "; - } - } elseif(!pnUserLoggedIn()) { - // get all events for anonymous users - $sql .= "AND a.pc_sharing = '" . SHARING_GLOBAL . "' "; - } else { - // get all events for logged in user plus global events - $sql .= "AND (a.pc_aid = " . $_SESSION['authUserID'] . " OR a.pc_sharing = '" . SHARING_GLOBAL . "') "; - } - - //====================================================================== - // START SEARCH FUNCTIONALITY - //====================================================================== - if(!empty($s_keywords)) $sql .= "AND ($s_keywords) "; - if(!empty($s_category)) $sql .= "AND ($s_category) "; - if(!empty($s_topic)) $sql .= "AND ($s_topic) "; - if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') "; - if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') "; - - //====================================================================== - // Search sort and limitation - //====================================================================== - if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_time DESC"; - else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort"; - - //====================================================================== - // END SEARCH FUNCTIONALITY - //====================================================================== - //echo "sq: $sql
"; - - // echo "\n"; // debugging - - $result = $dbconn->Execute($sql); - if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg()); - - // put the information into an array for easy access - $events = array(); - // return an empty array if we don't have any results - if(!isset($result)) { return $events; } - - for($i=0; !$result->EOF; $result->MoveNext()) { - - // WHY are we using an array for intermediate storage??? -- Rod - - // get the results from the query - if(isset($tmp)) { unset($tmp); } $tmp = array(); - list($tmp['eid'], $tmp['uname'], $tmp['catid'], - $tmp['title'], $tmp['time'], $tmp['hometext'], - $tmp['eventDate'], $tmp['duration'], $tmp['endDate'], - $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'], - $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'], - $tmp['location'], $tmp['conttel'], $tmp['contname'], - $tmp['contemail'], $tmp['website'], $tmp['fee'], - $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'], - $tmp['catname'], $tmp['catdesc'], $tmp['pid'], - $tmp['apptstatus'], $tmp['aid'], $tmp['provider_name'], - $tmp['patient_name'], $tmp['owner_name'], $tmp['patient_dob'], - $tmp['pubpid']) = $result->fields; - - // grab the name of the topic - $topicname = pcGetTopicName($tmp['topic']); - // get the user id of event's author - $cuserid = @$nuke_users[strtolower($tmp['uname'])]; - // check the current event's permissions - // the user does not have permission to view this event - // if any of the following evaluate as false - if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) { - continue; - } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) { - continue; - } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) { - continue; - } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) { - continue; - } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) { - continue; - } - - // add event to the array if we passed the permissions check - // this is the common information - - $events[$i]['intervals'] =($tmp['duration']/60)/ $GLOBALS['day_calandar_interval'];//sets the number of rows this event should span - print_r($events[$i]['intervals']); - - $events[$i]['eid'] = $tmp['eid']; - $events[$i]['uname'] = $tmp['uname']; - $events[$i]['uid'] = $cuserid; - $events[$i]['catid'] = $tmp['catid']; - $events[$i]['time'] = $tmp['time']; - $events[$i]['eventDate'] = $tmp['eventDate']; - $events[$i]['duration'] = $tmp['duration']; - // there has to be a more intelligent way to do this - @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60)); - $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2); - //'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - $events[$i]['endDate'] = $tmp['endDate']; - $events[$i]['startTime'] = $tmp['startTime']; - $events[$i]['recurrtype'] = $tmp['recurrtype']; - $events[$i]['recurrfreq'] = $tmp['recurrfreq']; - $events[$i]['recurrspec'] = $tmp['recurrspec']; - $events[$i]['topic'] = $tmp['topic']; - $events[$i]['alldayevent'] = $tmp['alldayevent']; - $events[$i]['catcolor'] = $tmp['catcolor']; - $events[$i]['catname'] = $tmp['catname']; - $events[$i]['catdesc'] = $tmp['catdesc']; - $events[$i]['pid'] = $tmp['pid']; - $events[$i]['apptstatus'] = $tmp['apptstatus']; - $events[$i]['pubpid'] = $tmp['pubpid']; - $events[$i]['patient_name']= $tmp['patient_name']; - $events[$i]['provider_name'] = $tmp['provider_name']; - $events[$i]['owner_name'] = $tmp['owner_name']; - $events[$i]['patient_dob'] = $tmp['patient_dob']; - $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4); - $events[$i]['sharing'] = $tmp['sharing']; - $events[$i]['prefcatid'] = $tmp['prefcatid']; - $events[$i]['aid'] = $tmp['aid']; - $events[$i]['topictext'] = $topicname; - $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']); - if($events[$i]['intervals'] == 0) - $events[$i]['intervals'] = 1; - // is this a public event to be shown as busy? - if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) { - // make it not display any information - $events[$i]['title'] = _USER_BUSY_TITLE; - $events[$i]['hometext'] = _USER_BUSY_MESSAGE; - $events[$i]['desc'] = _USER_BUSY_MESSAGE; - $events[$i]['conttel'] = ''; - $events[$i]['contname'] = ''; - $events[$i]['contemail'] = ''; - $events[$i]['website'] = ''; - $events[$i]['fee'] = ''; - $events[$i]['location'] = ''; - $events[$i]['street1'] = ''; - $events[$i]['street2'] = ''; - $events[$i]['city'] = ''; - $events[$i]['state'] = ''; - $events[$i]['postal'] = ''; - } else { - $display_type = substr($tmp['hometext'],0,6); - if($display_type == ':text:') { - $prepFunction = 'pcVarPrepForDisplay'; - $tmp['hometext'] = substr($tmp['hometext'],6); - } elseif($display_type == ':html:') { - $prepFunction = 'pcVarPrepHTMLDisplay'; - $tmp['hometext'] = substr($tmp['hometext'],6); - } else { - $prepFunction = 'pcVarPrepHTMLDisplay'; - } - unset($display_type); - $events[$i]['title'] = $prepFunction($tmp['title']); - $events[$i]['hometext'] = $prepFunction($tmp['hometext']); - $events[$i]['desc'] = $events[$i]['hometext']; - $events[$i]['conttel'] = $prepFunction($tmp['conttel']); - $events[$i]['contname'] = $prepFunction($tmp['contname']); - $events[$i]['contemail'] = $prepFunction($tmp['contemail']); - $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website'])); - $events[$i]['fee'] = $prepFunction($tmp['fee']); - $loc = unserialize($tmp['location']); - $events[$i]['location'] = $prepFunction($loc['event_location']); - $events[$i]['street1'] = $prepFunction($loc['event_street1']); - $events[$i]['street2'] = $prepFunction($loc['event_street2']); - $events[$i]['city'] = $prepFunction($loc['event_city']); - $events[$i]['state'] = $prepFunction($loc['event_state']); - $events[$i]['postal'] = $prepFunction($loc['event_postal']); - } - $i++; - } - unset($tmp); - $result->Close(); - return $events; -} - - -function getBlockTime($time) { - - if ($time == 0 || strlen($time) == 0) { - - return "all_day"; - } - $ts = strtotime($time); - $half = 0; - $minutes = date("i",$ts); - $hour = date("H",$ts); - if ($minutes >= 30) - $half = 1; - $blocknum = (($hour * 2) +$half); - return strval($blocknum); -} - -function &postcalendar_userapi_pcGetEvents($args) -{ - $s_keywords = $s_category = $s_topic = ''; - extract($args); - - $date =& postcalendar_getDate(); - $cy = substr($date,0,4); - $cm = substr($date,4,2); - $cd = substr($date,6,2); - if(isset($start) && isset($end)) { - // parse start date - list($sm,$sd,$sy) = explode('/',$start); - // parse end date - list($em,$ed,$ey) = explode('/',$end); - - $s = (int) "$sy$sm$sd"; - if($s > $date) { - $cy = $sy; - $cm = $sm; - $cd = $sd; - } - $start_date = Date_Calc::dateFormat($sd,$sm,$sy,'%Y-%m-%d'); - $end_date = Date_Calc::dateFormat($ed,$em,$ey,'%Y-%m-%d'); - } else { - $sm = $em = $cm; - $sd = $ed = $cd; - $sy = $cy; - $ey = $cy+2; - $start_date = $sy.'-'.$sm.'-'.$sd; - $end_date = $ey.'-'.$em.'-'.$ed; - } - if ($faFlag && !isset($events)) { - $a = array('faFlag' => true,'start'=>$start_date,'end'=>$end_date,'s_keywords'=>$s_keywords,'s_category'=>$s_category,'s_topic'=>$s_topic,'viewtype'=>$viewtype, 'provider_id' => $provider_id, 'event_status' => $event_status); - //print_r($a); - $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a); - } - elseif ($collideFlag && !isset($events)) { - - $a = array('collideFlag' => true,'start'=>$start_date,'end'=>$end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime); - $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a); - } - elseif ($listappsFlag && !isset($events)) { - - $a = array('listappsFlag' => true,'start'=>$start_date,'end'=>$end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords); - $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a); - } - else if(!isset($events)) { - if(!isset($s_keywords)) $s_keywords = ''; - $a = array('start'=>$start_date,'end'=>$end_date,'s_keywords'=>$s_keywords,'s_category'=>$s_category,'s_topic'=>$s_topic,'viewtype'=>$viewtype, "sort" => "pc_startTime ASC, a.pc_duration ASC ",'providerID' => $providerID); - $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a); - } - - //============================================================== - // Here we build an array consisting of the date ranges - // specific to the current view. This array is then - // used to build the calendar display. - //============================================================== - $days = array(); - $sday = Date_Calc::dateToDays($sd,$sm,$sy); - $eday = Date_Calc::dateToDays($ed,$em,$ey); - for($cday = $sday; $cday <= $eday; $cday++) { - $d = Date_Calc::daysToDate($cday,'%d'); - $m = Date_Calc::daysToDate($cday,'%m'); - $y = Date_Calc::daysToDate($cday,'%Y'); - $store_date = Date_Calc::dateFormat($d,$m,$y,'%Y-%m-%d'); - $days[$store_date] = array(); - } - - $days = calculateEvents($days,$events,$viewtype); - return $days; -} - -function calculateEvents($days,$events,$viewtype) { - $date =& postcalendar_getDate(); - $cy = substr($date,0,4); - $cm = substr($date,4,2); - $cd = substr($date,6,2); - - foreach($events as $event) { - // get the name of the topic - $topicname = pcGetTopicName($event['topic']); - - // parse the event start date - list($esY,$esM,$esD) = explode('-',$event['eventDate']); - - // grab the recurring specs for the event - $event_recurrspec = @unserialize($event['recurrspec']); - - // determine the stop date for this event - if($event['endDate'] == '0000-00-00') { - $stop = $end_date; - } else { - $stop = $event['endDate']; - } - - $start_date = "$cy-$cm-$cd"; - - // Optimization of the stop date to not be much later than required. - $tmpsecs = strtotime($start_date); - if ($viewtype == 'day') $tmpsecs += 2 * 24 * 3600; - else if ($viewtype == 'week') $tmpsecs += 8 * 24 * 3600; - else if ($viewtype == 'month') $tmpsecs += 32 * 24 * 3600; - else $tmpsecs += 367 * 24 * 3600; - $tmp = date('Y-m-d', $tmpsecs); - if ($stop > $tmp) $stop = $tmp; - - $eventD = $event['eventDate']; - $eventS = $event['startTime']; - - switch($event['recurrtype']) { - - //============================================================== - // Events that do not repeat only have a startday - //============================================================== - case NO_REPEAT : - - if(isset($days[$event['eventDate']])) { - array_push($days[$event['eventDate']],$event); - if ($viewtype == "week") { - //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."
"; - - fillBlocks($eventD,&$days); - //echo "for $eventD loading " . getBlockTime($eventS) . "

"; - $gbt = getBlockTime($eventS); - $days[$eventD]['blocks'][$gbt][$eventD][] = $event; - //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . "
"; - //echo "begin printing blocks for $eventD
"; - //print_r($days[$eventD]['blocks']); - //echo "end printing blocks
"; - } - } - - break; - - //============================================================== - // Find events that repeat at a certain frequency - // Every,Every Other,Every Third,Every Fourth - // Day,Week,Month,Year,MWF,TR,M-F,SS - //============================================================== - case REPEAT : - - $rfreq = $event_recurrspec['event_repeat_freq']; - $rtype = $event_recurrspec['event_repeat_freq_type']; - // we should bring the event up to date to make this a tad bit faster - // any ideas on how to do that, exactly??? dateToDays probably. - $nm = $esM; $ny = $esY; $nd = $esD; - $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d'); - while($occurance < $start_date) { - $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype); - list($ny,$nm,$nd) = explode('-',$occurance); - } - while($occurance <= $stop) { - if(isset($days[$occurance])) { - array_push($days[$occurance],$event); - if ($viewtype == "week") { - fillBlocks($occurance,&$days); - //echo "for $occurance loading " . getBlockTime($eventS) . "

"; - $gbt = getBlockTime($eventS); - $days[$occurance]['blocks'][$gbt][$occurance][] = $event; - //echo "begin printing blocks for $eventD
"; - //print_r($days[$occurance]['blocks']); - //echo "end printing blocks
"; - } - } - $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype); - list($ny,$nm,$nd) = explode('-',$occurance); - } - - break; - - //============================================================== - // Find events that repeat on certain parameters - // On 1st,2nd,3rd,4th,Last - // Sun,Mon,Tue,Wed,Thu,Fri,Sat - // Every N Months - //============================================================== - case REPEAT_ON : - - $rfreq = $event_recurrspec['event_repeat_on_freq']; - $rnum = $event_recurrspec['event_repeat_on_num']; - $rday = $event_recurrspec['event_repeat_on_day']; - - //============================================================== - // Populate - Enter data into the event array - //============================================================== - $nm = $esM; $ny = $esY; $nd = $esD; - // make us current - - while($ny < $cy) { - $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny)); - list($ny,$nm,$nd) = explode('-',$occurance); - } - // populate the event array - while($ny <= $cy) { - $dnum = $rnum; // get day event repeats on - do { - $occurance = Date_Calc::NWeekdayOfMonth($dnum--,$rday,$nm,$ny,$format="%Y-%m-%d"); - } while($occurance === -1); - if(isset($days[$occurance]) && $occurance <= $stop) { - array_push($days[$occurance],$event); - if ($viewtype == "week") { - fillBlocks($occurance,&$days); - //echo "for $occurance loading " . getBlockTime($eventS) . "

"; - $gbt = getBlockTime($eventS); - $days[$occurance]['blocks'][$gbt][$occurance][] = $event; - } - } - $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny)); - list($ny,$nm,$nd) = explode('-',$occurance); - } - - break; - - } // <- end of switch($event['recurrtype']) - } // <- end of foreach($events as $event) - return $days; -} - -function fillBlocks($td,&$ar) { - if (strlen ($td) > 0 && !isset($ar[$td]['blocks'])) { - $ar[$td]['blocks'] = array(); - for ($j=0;$j<48;$j++) - $ar[strval($td)]['blocks'][strval($j)] = array(); - $ar[strval($td)]['blocks']["all_day"] = array(); - } - - -} - -/** - * __increment() - * returns the next valid date for an event based on the - * current day,month,year,freq and type - * @private - * @returns string YYYY-MM-DD - */ -function &__increment($d,$m,$y,$f,$t) -{ - if($t == REPEAT_EVERY_DAY) { - return date('Y-m-d',mktime(0,0,0,$m,($d+$f),$y)); - } elseif($t == REPEAT_EVERY_WORK_DAY) { - //echo "special occurance
"; - $beginday = date("D",mktime(0,0,0,$m,$d,$y)); - $dayincrement = 1; - if ($beginday == "Fri") { - $dayincrement = 3; - } - elseif ($beginday == "Sat") { - $dayincrement = 2; - } - return date('Y-m-d',mktime(0,0,0,$m,($d+$dayincrement),$y)); - - } elseif($t == REPEAT_EVERY_WEEK) { - return date('Y-m-d',mktime(0,0,0,$m,($d+(7*$f)),$y)); - } elseif($t == REPEAT_EVERY_MONTH) { - return date('Y-m-d',mktime(0,0,0,($m+$f),$d,$y)); - } elseif($t == REPEAT_EVERY_YEAR) { - return date('Y-m-d',mktime(0,0,0,$m,$d,($y+$f))); - } -} - -?> += 12) ? 'pm' : 'am'; + + // $minute is an array of time slot strings within this hour. + $minute = array('00'); + + for($minutes = $GLOBALS['calendar_interval']; $minutes <= 60; $minutes += $GLOBALS['calendar_interval']) { + if($minutes <= '9'){ + $under_ten = "0" . $minutes; + array_push($minute, "$under_ten"); + } + else if($minutes >= '60') { + break; + } + else { + array_push($minute, "$minutes"); + } + } + + foreach($minute as $m ){ + array_push($times, array("hour"=>$blocknum, "minute"=>$m, "mer"=>$mer)); + } + } + + //================================================================= + // get the module's information + //================================================================= + $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); + $pcDir = $modinfo['directory']; + unset($modinfo); + + //================================================================= + // grab the for post variable + //================================================================= + // $pc_username = pnVarCleanFromInput('pc_username'); + $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19 + $category = pnVarCleanFromInput('pc_category'); + $topic = pnVarCleanFromInput('pc_topic'); + + //================================================================= + // set the correct date + //================================================================= + $Date =& postcalendar_getDate(); + + //================================================================= + // get the current view + //================================================================= + if(!isset($viewtype)) { $viewtype = 'month'; } + + //================================================================= + // Find out what Template we're using + //================================================================= + $template_name = _SETTING_TEMPLATE; + if(!isset($template_name)) { $template_name = 'default'; } + + //================================================================= + // Find out what Template View to use + //================================================================= + $template_view = pnVarCleanFromInput('tplview'); + if(!isset($template_view)) { $template_view = 'default'; } + + //================================================================= + // See if the template view exists + //================================================================= + if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) { + $template_view_load = 'default'; + } else { + $template_view_load = pnVarPrepForOS($template_view); + } + + //================================================================= + // Grab the current theme information + //================================================================= + pnThemeLoad(pnUserGetTheme()); + global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2; + + //================================================================= + // Insert necessary JavaScript into the page + //================================================================= + $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup'); + + //================================================================= + // Setup Smarty Template Engine + //================================================================= + $tpl =& new pcSmarty(); + + //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) { + //diable caching completely + if (true) { + //================================================================= + // Let's just finish setting things up + //================================================================= + $the_year = substr($Date,0,4); + $the_month = substr($Date,4,2); + $the_day = substr($Date,6,2); + $last_day = Date_Calc::daysInMonth($the_month,$the_year); + + //================================================================= + // populate the template object with information for + // Month Names, Long Day Names and Short Day Names + // as translated in the language files + // (may be adding more here soon - based on need) + //================================================================= + $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN, + _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC); + + $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT, + _CALTUESDAYSHORT, _CALWEDNESDAYSHORT, + _CALTHURSDAYSHORT, _CALFRIDAYSHORT, + _CALSATURDAYSHORT); + + $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY, + _CALTUESDAY, _CALWEDNESDAY, + _CALTHURSDAY, _CALFRIDAY, + _CALSATURDAY); + //================================================================= + // here we need to set up some information for later + // variable creation. This helps us establish the correct + // date ranges for each view. There may be a better way + // to handle all this, but my brain hurts, so your comments + // are very appreciated and welcomed. + //================================================================= + switch (_SETTING_FIRST_DAY_WEEK) + { + case _IS_MONDAY: + $pc_array_pos = 1; + $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year)); + $week_day = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year)); + $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); + if($end_dow != 0) { + $the_last_day = $last_day+(7-$end_dow); + } else { + $the_last_day = $last_day; + } + break; + case _IS_SATURDAY: + $pc_array_pos = 6; + $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year)); + $week_day = date('w',mktime(0,0,0,$the_month,$the_day+1,$the_year)); + $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); + if($end_dow == 6) { + $the_last_day = $last_day+6; + } elseif($end_dow != 5) { + $the_last_day = $last_day+(5-$end_dow); + } else { + $the_last_day = $last_day; + } + break; + case _IS_SUNDAY: + default: + $pc_array_pos = 0; + $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year)); + $week_day = date('w',mktime(0,0,0,$the_month,$the_day,$the_year)); + $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); + if($end_dow != 6) { + $the_last_day = $last_day+(6-$end_dow); + } else { + $the_last_day = $last_day; + } + break; + } + + // passing the times array to the tpl the times array is for the days schedule + $tpl->assign_by_ref("times",$times); + // load the table width to the template + // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']); + + //================================================================= + // Week View is a bit of a pain in the ass, so we need to + // do some extra setup for that view. This section will + // find the correct starting and ending dates for a given + // seven day period, based on the day of the week the + // calendar is setup to run under (Sunday, Saturday, Monday) + //================================================================= + $first_day_of_week = sprintf('%02d',$the_day-$week_day); + $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year)); + list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day); + $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', + array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year))); + $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year)); + list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day); + $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', + array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year))); + + //================================================================= + // Setup some information so we know the actual month's dates + // also get today's date for later use and highlighting + //================================================================= + $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year)); + $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year)); + $today_date = postcalendar_today('%Y-%m-%d'); + + //================================================================= + // Setup the starting and ending date ranges for pcGetEvents() + //================================================================= + switch($viewtype) { + case 'day' : + $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year)); + $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year)); + break; + case 'week' : + $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year"; + $ending_date = "$week_last_day_month/$week_last_day_date/$week_last_day_year"; + $calendarView = Date_Calc::getCalendarWeek($week_first_day_date, + $week_first_day_month, + $week_first_day_year, + '%Y-%m-%d'); + break; + case 'month' : + $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year)); + $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year)); + $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d'); + break; + case 'year' : + $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year)); + $ending_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year+1)); + $calendarView = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d'); + break; + } + + //================================================================= + // Load the events + //================================================================= + if($viewtype != 'year') { + $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date, 'viewtype' => $viewtype)); + } else { + $eventsByDate = array(); + } + + //================================================================= + // Create an array with the day names in the correct order + //================================================================= + $daynames = array(); + $numDays = count($pc_long_day_names); + for($i=0; $i < $numDays; $i++) { + if($pc_array_pos >= $numDays) { + $pc_array_pos = 0; + } + array_push($daynames,$pc_long_day_names[$pc_array_pos]); + $pc_array_pos++; + } + unset($numDays); + $sdaynames = array(); + $numDays = count($pc_short_day_names); + for($i=0; $i < $numDays; $i++) { + if($pc_array_pos >= $numDays) { + $pc_array_pos = 0; + } + array_push($sdaynames,$pc_short_day_names[$pc_array_pos]); + $pc_array_pos++; + } + unset($numDays); + + //================================================================= + // Prepare some values for the template + //================================================================= + $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d'); + $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d'); + + $pc_prev = pnModURL(__POSTCALENDAR__,'user','view', + array('tplview'=>$template_view, + 'viewtype'=>'month', + 'Date'=>$prev_month, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + + $pc_next = pnModURL(__POSTCALENDAR__,'user','view', + array('tplview'=>$template_view, + 'viewtype'=>'month', + 'Date'=>$next_month, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + + $prev_day = Date_Calc::prevDay($the_day,$the_month,$the_year,'%Y%m%d'); + $next_day = Date_Calc::nextDay($the_day,$the_month,$the_year,'%Y%m%d'); + $pc_prev_day = pnModURL(__POSTCALENDAR__,'user','view', + array('tplview'=>$template_view, + 'viewtype'=>'day', + 'Date'=>$prev_day, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + + $pc_next_day = pnModURL(__POSTCALENDAR__,'user','view', + array('tplview'=>$template_view, + 'viewtype'=>'day', + 'Date'=>$next_day, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + + $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year)); + $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+1,$week_last_day_year)); + $pc_prev_week = pnModURL(__POSTCALENDAR__,'user','view', + array('viewtype'=>'week', + 'Date'=>$prev_week, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + $pc_next_week = pnModURL(__POSTCALENDAR__,'user','view', + array('viewtype'=>'week', + 'Date'=>$next_week, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + + $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1)); + $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+1)); + $pc_prev_year = pnModURL(__POSTCALENDAR__,'user','view', + array('viewtype'=>'year', + 'Date'=>$prev_year, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + $pc_next_year = pnModURL(__POSTCALENDAR__,'user','view', + array('viewtype'=>'year', + 'Date'=>$next_year, + 'pc_username'=>$pc_username, + 'pc_category'=>$category, + 'pc_topic'=>$topic)); + + //================================================================= + // Populate the template + //================================================================= + $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories'); + + if(isset($calendarView)) { + $tpl->assign_by_ref('CAL_FORMAT',$calendarView); + } + + if($viewtype == "week") { + $last_blocks = array(); + foreach($eventsByDate as $cdate => $day) { + $tblock = array_reverse($day['blocks']); + $last_blocks[$cdate] = count($tblock) -1; + for ($i=0;$iassign("last_blocks",$last_blocks); + } + + $tpl->assign('STYLE',$GLOBALS['style']); + $tpl->assign('show_days',$show_days); + //================================== + //FACILITY FILTERING (CHEMED) + if ( $_SESSION['pc_facility'] ) { + $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']); + } else { + $provinfo = getProviderInfo(); + } + + //EOS FACILITY FILTERING (CHEMED) + //================================== + + + + $single = array(); + + // filter the display on the requested username, the provinfo array is + // used to build columns in the week view. + + foreach($provinfo as $provider) { + if(is_array($pc_username)){ + foreach($pc_username as $uname) { + if (!empty($pc_username) && $provider['username'] == $uname) { + array_push($single,$provider); + } + } + } + else { + if (!empty($pc_username) && $provider['username'] == $pc_username) { + array_push($single,$provider); + } + } + } + if ($single != null) { + $provinfo = $single; + } + + //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other"); + $tpl->assign_by_ref('providers', $provinfo); + + if (pnVarCleanFromInput("show_days") != 1) { + $tpl->assign('showdaysurl',"index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1"); + } + + $tpl->assign('interval', $GLOBALS['calendar_interval']); + $tpl->assign_by_ref('VIEW_TYPE',$viewtype); + $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names); + $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names); + $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names); + $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames); + $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames); + $tpl->assign_by_ref('A_EVENTS',$eventsByDate); + $tpl->assign_by_ref('A_CATEGORY',$all_categories); + $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev); + $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next); + $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day); + $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day); + $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week); + $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week); + $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year); + $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year); + $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start); + $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end); + $tpl->assign_by_ref('TODAY_DATE',$today_date); + $tpl->assign_by_ref('DATE',$Date); + $tpl->assign_by_ref('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__,'user','submit')); + $tpl->assign_by_ref('interval',$intervals); +}; + + //================================================================= + // Parse the template + //================================================================= + $template = "$template_name/views/$viewtype/$template_view_load.html"; + if(!$print) { + $output .= "\n\n\n\n"; + $output .= $tpl->fetch($template,$cacheid); // cache id + $output .= "\n\n\n\n"; + } else { + $theme = pnUserGetTheme(); + echo ""; + echo "\n\n\n"; + echo "\n"; + echo "\n"; + echo $output; + $tpl->display($template,$cacheid); + echo postcalendar_footer(); + echo "\n"; + session_write_close(); + exit; + } + //================================================================= + // Return the output + //================================================================= + return $output; +} + +/** + * postcalendar_userapi_eventPreview + * Creates the detailed event display and outputs html. + * Accepts an array of key/value pairs + * @param array $event array of event details from the form + * @return string html output + * @access public + */ +function postcalendar_userapi_eventPreview($args) +{ + // get the theme globals :: is there a better way to do this? + pnThemeLoad(pnUserGetTheme()); + global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5; + global $textcolor1, $textcolor2; + + extract($args); unset($args); + $uid = pnUserGetVar('uid'); + //================================================================= + // Setup Smarty Template Engine + //================================================================= + $tpl =& new pcSmarty(); + $tpl->caching = false; + // add preceding zeros + $event_starttimeh = sprintf('%02d',$event_starttimeh); + $event_starttimem = sprintf('%02d',$event_starttimem); + $event_startday = sprintf('%02d',$event_startday); + $event_startmonth = sprintf('%02d',$event_startmonth); + $event_endday = sprintf('%02d',$event_endday); + $event_endmonth = sprintf('%02d',$event_endmonth); + + if(!(bool)_SETTING_TIME_24HOUR) { + if($event_startampm == _PM_VAL) { + if($event_starttimeh != 12) { + $event_starttimeh+=12; + } + } elseif($event_startampm == _AM_VAL) { + if($event_starttimeh == 12) { + $event_starttimeh = 00; + } + } + } + + $event_startampm." - "; + $startTime = $event_starttimeh.':'.$event_starttimem.' '; + + $event = array(); + $event['eid'] = ''; + $event['uname'] = $uname; + $event['catid'] = $event_category; + if($pc_html_or_text == 'html') { + $prepFunction = 'pcVarPrepHTMLDisplay'; + } else { + $prepFunction = 'pcVarPrepForDisplay'; + } + $event['title'] = $prepFunction($event_subject); + $event['hometext'] = $prepFunction($event_desc); + $event['desc'] = $event['hometext']; + $event['date'] = $event_startyear.$event_startmonth.$event_startday; + $event['duration'] = $event_duration; + $event['duration_hours'] = $event_dur_hours; + $event['duration_minutes'] = $event_dur_minutes; + $event['endDate'] = $event_endyear.'-'.$event_endmonth.'-'.$event_endday; + $event['startTime'] = $startTime; + $event['recurrtype'] = ''; + $event['recurrfreq'] = ''; + $event['recurrspec'] = $event_recurrspec; + $event['topic'] = $event_topic; + $event['alldayevent'] = $event_allday; + $event['conttel'] = $prepFunction($event_conttel); + $event['contname'] = $prepFunction($event_contname); + $event['contemail'] = $prepFunction($event_contemail); + $event['website'] = $prepFunction(postcalendar_makeValidURL($event_website)); + $event['fee'] = $prepFunction($event_fee); + $event['location'] = $prepFunction($event_location); + $event['street1'] = $prepFunction($event_street1); + $event['street2'] = $prepFunction($event_street2); + $event['city'] = $prepFunction($event_city); + $event['state'] = $prepFunction($event_state); + $event['postal'] = $prepFunction($event_postal); + + //================================================================= + // get event's topic information + //================================================================= + if(_SETTING_DISPLAY_TOPICS) { + list($dbconn) = pnDBGetConn(); + $pntable = pnDBGetTables(); + $topics_table = $pntable['topics']; + $topics_column = $pntable['topics_column']; + $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage] + FROM $topics_table + WHERE $topics_column[topicid] = $event[topic] + LIMIT 1"; + $topic_result = $dbconn->Execute($topicsql); + list($event['topictext'],$event['topicimg']) = $topic_result->fields; + $topic_result->Close(); + } else { + $event['topictext'] = $event['topicimg'] = ''; + } + //================================================================= + // Find out what Template we're using + //================================================================= + $template_name = _SETTING_TEMPLATE; + if(!isset($template_name)) { + $template_name = 'default'; + } + //================================================================= + // populate the template + //================================================================= + if(!empty($event['location']) || !empty($event['street1']) || + !empty($event['street2']) || !empty($event['city']) || + !empty($event['state']) || !empty($event['postal'])) { + $tpl->assign('LOCATION_INFO',true); + } else { + $tpl->assign('LOCATION_INFO',false); + } + if(!empty($event['contname']) || !empty($event['contemail']) || + !empty($event['conttel']) || !empty($event['website'])) { + $tpl->assign('CONTACT_INFO',true); + } else { + $tpl->assign('CONTACT_INFO',false); + } + $tpl->assign_by_ref('A_EVENT',$event); + $tpl->assign('STYLE',$GLOBALS['style']); + //================================================================= + // Parse the template + //================================================================= + $output = "\n\n\n\n"; + $output .= "\n\n\n\n"; + $output .= $tpl->fetch($template_name.'/user/preview.html'); + $output .= "\n\n\n\n"; + + return $output; +} + +/** + * checkEventCollision + * Returns an array containing any events that collide with the specified event + * @params array(key=>value) + * @return array $events[][] + */ + function checkEventCollision($edata) { + + extract($edata); + $sdate = ($event_startmonth.'/'.$event_startday.'/'.$event_startyear); + $edate = $sdate; + //hour from forms is 12 not 24 format, convert here + if($event_startampm == 2 && $event_starttimeh != 12) + $event_starttimeh += 12; + elseif ($event_startampm == 1 && $event_starttimeh == 12) + $event_starttimeh -= 12; + + $stime = date("H:i:00",strtotime($event_starttimeh.':'.$event_starttimem.':00')); + $etime = date("H:i:00",$event_duration + strtotime($stime)); + //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate
"; + $a = array('collideFlag' => true,'start'=>$edate,'end'=>$sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime); + $eventsByDate =& postcalendar_userapi_pcGetEvents($a); + //print_r($eventsByDate); + $collisions = array(); + foreach ($eventsByDate as $day) { + foreach ($day as $event) { + if ($event['duration'] == 0 && $event['alldayevent'] == 0) { + continue; + } + elseif($event['alldayevent'] == 1) { + $collisions[] = $event; + } + $festart = strtotime($event['startTime']); + $feend = strtotime($event['startTime'] + $event['duration']); + $estart = strtotime($stime); + $eend = strtotime($etime); + + //echo "festart = $festart feend = $feend estart = $estart eend = $eend
"; + if ($festart < $eend && $feend > $estart) { + $collisions[] = $event; + } + elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) { + $collisions[] = $event; + } + elseif ($festart >= $estart && $festart < $eend) { + $collisions[] = $event; + } + } + } + //foreach ($collisions as $collide) { + // echo "collided: " . $collide['title'] . "
"; + //} + return $collisions; + } + +/** + * postcalendar_userapi_pcQueryEventsFA + * Returns an array containing the event's information for first available queiries + * @params array(key=>value) + * @params string key eventstatus + * @params int value -1 == hidden ; 0 == queued ; 1 == approved + * @return array $events[][] + */ +function &postcalendar_userapi_pcQueryEventsFA($args) { + + $end = '0000-00-00'; + extract($args); + $eventstatus = 1; + if (is_numeric($event_status)) + $eventstatus = $event_status; + + if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); } + list($sy,$sm,$sd) = explode('-',$start); + + list($dbconn) = pnDBGetConn(); + $pntable = pnDBGetTables(); + // link to the events tables + $table = $pntable['postcalendar_events']; + $cattable = $pntable['postcalendar_categories']; + + $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, a.pc_title, " . + "a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, a.pc_endDate, " . + "a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, a.pc_recurrspec, " . + "a.pc_topic, a.pc_alldayevent, a.pc_location, a.pc_conttel, " . + "a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, a.pc_sharing, " . + "a.pc_prefcatid, " . + "b.pc_catcolor, b.pc_catname, b.pc_catdesc, a.pc_pid, a.pc_aid, " . + "concat(u.fname,' ',u.lname) as provider_name, " . + "concat(pd.fname,' ',pd.lname) as patient_name, " . + "concat(u2.fname, ' ', u2.lname) as owner_name, pd.DOB as patient_dob " . + "FROM ( $table AS a, $cattable AS b ) " . + "LEFT JOIN users as u ON a.pc_aid = u.id " . + "LEFT JOIN users as u2 ON a.pc_aid = u2.id " . + "LEFT JOIN patient_data as pd ON a.pc_pid=pd.pid " . + "WHERE b.pc_catid = a.pc_catid " . + "AND a.pc_eventstatus = $eventstatus " . + "AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') " . + "AND a.pc_eventDate <= '$end' " . + "AND (a.pc_aid = '" . $provider_id . "' OR a.pc_aid = '')"; + + //====================================================================== + // START SEARCH FUNCTIONALITY + //====================================================================== + if(!empty($s_keywords)) $sql .= "AND ($s_keywords) "; + if(!empty($s_category)) $sql .= "AND ($s_category) "; + if(!empty($s_topic)) $sql .= "AND ($s_topic) "; + if(!empty($collide_etime) && !empty($collide_stime)) { + $sql .= "AND NOT ((pc_endTime <= '$collide_stime') OR (pc_startTime >= '$collide_etime')) AND pc_endTime IS NOT NULL "; + } + if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') "; + if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') "; + //====================================================================== + // Search sort and limitation + //====================================================================== + if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_startTime ASC"; + else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort"; + //====================================================================== + // END SEARCH FUNCTIONALITY + //====================================================================== + //echo "
sql: $sql
"; + $result = $dbconn->Execute($sql); + if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg()); + + // put the information into an array for easy access + $events = array(); + // return an empty array if we don't have any results + if(!isset($result)) { return $events; } + + for($i=0; !$result->EOF; $result->MoveNext()) { + + // get the results from the query + if(isset($tmp)) { unset($tmp); } $tmp = array(); + list($tmp['eid'], $tmp['uname'], $tmp['catid'], + $tmp['title'], $tmp['time'], $tmp['hometext'], + $tmp['eventDate'], $tmp['duration'], $tmp['endDate'], + $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'], + $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'], + $tmp['location'], $tmp['conttel'], $tmp['contname'], + $tmp['contemail'], $tmp['website'], $tmp['fee'], + $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'], + $tmp['catname'], $tmp['catdesc'], $tmp['pid'], + $tmp['aid'], $tmp['provider_name'], $tmp['patient_name'], + $tmp['owner_name'], $tmp['patient_dob']) = $result->fields; + + // grab the name of the topic + $topicname = pcGetTopicName($tmp['topic']); + // get the user id of event's author + $cuserid = @$nuke_users[strtolower($tmp['uname'])]; + // check the current event's permissions + // the user does not have permission to view this event + // if any of the following evaluate as false + if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) { + continue; + } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) { + continue; + } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) { + continue; + } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) { + continue; + } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) { + continue; + } + + // add event to the array if we passed the permissions check + // this is the common information + $events[$i]['eid'] = $tmp['eid']; + $events[$i]['uname'] = $tmp['uname']; + $events[$i]['uid'] = $cuserid; + $events[$i]['catid'] = $tmp['catid']; + $events[$i]['time'] = $tmp['time']; + $events[$i]['eventDate'] = $tmp['eventDate']; + $events[$i]['duration'] = $tmp['duration']; + // there has to be a more intelligent way to do this + @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60)); + $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2); + //'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + $events[$i]['endDate'] = $tmp['endDate']; + $events[$i]['startTime'] = $tmp['startTime']; + $events[$i]['recurrtype'] = $tmp['recurrtype']; + $events[$i]['recurrfreq'] = $tmp['recurrfreq']; + $events[$i]['recurrspec'] = $tmp['recurrspec']; + + $rspecs = unserialize($tmp['recurrspec']); + $events[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq']; + $events[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type']; + $events[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num']; + $events[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day']; + $events[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq']; + + $events[$i]['topic'] = $tmp['topic']; + $events[$i]['alldayevent'] = $tmp['alldayevent']; + $events[$i]['catcolor'] = $tmp['catcolor']; + $events[$i]['catname'] = $tmp['catname']; + $events[$i]['catdesc'] = $tmp['catdesc']; + $events[$i]['pid'] = $tmp['pid']; + $events[$i]['patient_name']= $tmp['patient_name']; + $events[$i]['provider_name'] = $tmp['provider_name']; + $events[$i]['owner_name'] = $tmp['owner_name']; + $events[$i]['patient_dob'] = $tmp['patient_dob']; + $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4); + $events[$i]['sharing'] = $tmp['sharing']; + $events[$i]['prefcatid'] = $tmp['prefcatid']; + $events[$i]['aid'] = $tmp['aid']; + $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']); + if($events[$i]['intervals'] == 0) + $events[$i]['intervals'] = 1; + // is this a public event to be shown as busy? + if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) { + // make it not display any information + $events[$i]['title'] = _USER_BUSY_TITLE; + $events[$i]['hometext'] = _USER_BUSY_MESSAGE; + $events[$i]['desc'] = _USER_BUSY_MESSAGE; + $events[$i]['conttel'] = ''; + $events[$i]['contname'] = ''; + $events[$i]['contemail'] = ''; + $events[$i]['website'] = ''; + $events[$i]['fee'] = ''; + $events[$i]['location'] = ''; + $events[$i]['street1'] = ''; + $events[$i]['street2'] = ''; + $events[$i]['city'] = ''; + $events[$i]['state'] = ''; + $events[$i]['postal'] = ''; + } else { + $display_type = substr($tmp['hometext'],0,6); + if($display_type == ':text:') { + $prepFunction = 'pcVarPrepForDisplay'; + $tmp['hometext'] = substr($tmp['hometext'],6); + } elseif($display_type == ':html:') { + $prepFunction = 'pcVarPrepHTMLDisplay'; + $tmp['hometext'] = substr($tmp['hometext'],6); + } else { + $prepFunction = 'pcVarPrepHTMLDisplay'; + } + unset($display_type); + $events[$i]['title'] = $prepFunction($tmp['title']); + $events[$i]['hometext'] = $prepFunction($tmp['hometext']); + $events[$i]['desc'] = $events[$i]['hometext']; + $events[$i]['conttel'] = $prepFunction($tmp['conttel']); + $events[$i]['contname'] = $prepFunction($tmp['contname']); + $events[$i]['contemail'] = $prepFunction($tmp['contemail']); + $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website'])); + $events[$i]['fee'] = $prepFunction($tmp['fee']); + $loc = unserialize($tmp['location']); + $events[$i]['location'] = $prepFunction($loc['event_location']); + $events[$i]['street1'] = $prepFunction($loc['event_street1']); + $events[$i]['street2'] = $prepFunction($loc['event_street2']); + $events[$i]['city'] = $prepFunction($loc['event_city']); + $events[$i]['state'] = $prepFunction($loc['event_state']); + $events[$i]['postal'] = $prepFunction($loc['event_postal']); + } + $i++; + } + unset($tmp); + $result->Close(); + return $events; +} + + +/** + * postcalendar_userapi_pcQueryEvents + * Returns an array containing the event's information + * @params array(key=>value) + * @params string key eventstatus + * @params int value -1 == hidden ; 0 == queued ; 1 == approved + * @return array $events[][] + */ +function &postcalendar_userapi_pcQueryEvents($args) +{ + $end = '0000-00-00'; + extract($args); + + // echo "\n"; // debugging + + // $pc_username = pnVarCleanFromInput('pc_username'); + $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19 + if (empty($pc_username) || is_array($pc_username)) { + $pc_username = "__PC_ALL__"; + } + + // echo "\n"; // debugging + + $topic = pnVarCleanFromInput('pc_topic'); + $category = pnVarCleanFromInput('pc_category'); + + if(!empty($pc_username) && (strtolower($pc_username) != 'anonymous')) { + if($pc_username=='__PC_ALL__' || $pc_username == -1) { + $ruserid = -1; + } else { + $ruserid = getIDfromUser($pc_username); + } + } + + if(!isset($eventstatus)) { $eventstatus = 1; } + // sanity check on eventstatus + if((int)$eventstatus < -1 || (int)$eventstatus > 1) { $eventstatus = 1; } + if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); } + list($sy,$sm,$sd) = explode('-',$start); + + list($dbconn) = pnDBGetConn(); + $pntable = pnDBGetTables(); + // link to the events tables + $table = $pntable['postcalendar_events']; + $cattable = $pntable['postcalendar_categories']; + $topictable = $pntable['postcalendar_topics']; + + $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, " . + "a.pc_title, a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, " . + "a.pc_endDate, a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, " . + "a.pc_recurrspec, a.pc_topic, a.pc_alldayevent, a.pc_location, " . + "a.pc_conttel, a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, " . + "a.pc_sharing, a.pc_prefcatid, b.pc_catcolor, b.pc_catname, " . + "b.pc_catdesc, a.pc_pid, a.pc_apptstatus, a.pc_aid, " . + "concat(u.fname,' ',u.lname) as provider_name, " . + "concat(pd.lname,', ',pd.fname) as patient_name, " . + "concat(u2.fname, ' ', u2.lname) as owner_name, " . + "DOB as patient_dob, pd.pubpid " . + "FROM ( $table AS a, $cattable AS b ) " . + "LEFT JOIN users as u ON a.pc_aid = u.id " . + "LEFT JOIN users as u2 ON a.pc_aid = u2.id " . + "LEFT JOIN patient_data as pd ON a.pc_pid = pd.pid " . + "WHERE b.pc_catid = a.pc_catid " . + "AND a.pc_eventstatus = $eventstatus " . + "AND ((a.pc_endDate >= '$start' AND a.pc_eventDate <= '$end') OR " . + "(a.pc_endDate = '0000-00-00' AND a.pc_eventDate >= '$start' AND " . + "a.pc_eventDate <= '$end')) "; + + //================================== + //FACILITY FILTERING (lemonsoftware)(CHEMED) + if ( $_SESSION['pc_facility'] ) { + $pc_facility = $_SESSION['pc_facility']; + $sql .= " AND a.pc_facility = $pc_facility + AND u.facility_id = $pc_facility + AND u2.facility_id = $pc_facility "; + } + //EOS FACILITY FILTERING (lemonsoftware) + //================================== + + + // The above 3 lines replaced these: + // AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') + // AND a.pc_eventDate <= '$end' "; + + if(!empty($providerID)) + { + $ruserid = $providerID; + } + + if(isset($ruserid)) { + // get all events for the specified username + if($ruserid == -1) { + $sql .= "AND (a.pc_sharing = '" . SHARING_BUSY . "' "; + $sql .= "OR a.pc_sharing = '" . SHARING_PUBLIC . "') "; + } else { + $sql .= "AND a.pc_aid = " . $ruserid . " "; + } + } elseif(!pnUserLoggedIn()) { + // get all events for anonymous users + $sql .= "AND a.pc_sharing = '" . SHARING_GLOBAL . "' "; + } else { + // get all events for logged in user plus global events + $sql .= "AND (a.pc_aid = " . $_SESSION['authUserID'] . " OR a.pc_sharing = '" . SHARING_GLOBAL . "') "; + } + + //====================================================================== + // START SEARCH FUNCTIONALITY + //====================================================================== + if(!empty($s_keywords)) $sql .= "AND ($s_keywords) "; + if(!empty($s_category)) $sql .= "AND ($s_category) "; + if(!empty($s_topic)) $sql .= "AND ($s_topic) "; + if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') "; + if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') "; + + //====================================================================== + // Search sort and limitation + //====================================================================== + if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_time DESC"; + else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort"; + + //====================================================================== + // END SEARCH FUNCTIONALITY + //====================================================================== + //echo "sq: $sql
"; + + // echo "\n"; // debugging + + $result = $dbconn->Execute($sql); + if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg()); + + // put the information into an array for easy access + $events = array(); + // return an empty array if we don't have any results + if(!isset($result)) { return $events; } + + for($i=0; !$result->EOF; $result->MoveNext()) { + + // WHY are we using an array for intermediate storage??? -- Rod + + // get the results from the query + if(isset($tmp)) { unset($tmp); } $tmp = array(); + list($tmp['eid'], $tmp['uname'], $tmp['catid'], + $tmp['title'], $tmp['time'], $tmp['hometext'], + $tmp['eventDate'], $tmp['duration'], $tmp['endDate'], + $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'], + $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'], + $tmp['location'], $tmp['conttel'], $tmp['contname'], + $tmp['contemail'], $tmp['website'], $tmp['fee'], + $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'], + $tmp['catname'], $tmp['catdesc'], $tmp['pid'], + $tmp['apptstatus'], $tmp['aid'], $tmp['provider_name'], + $tmp['patient_name'], $tmp['owner_name'], $tmp['patient_dob'], + $tmp['pubpid']) = $result->fields; + + // grab the name of the topic + $topicname = pcGetTopicName($tmp['topic']); + // get the user id of event's author + $cuserid = @$nuke_users[strtolower($tmp['uname'])]; + // check the current event's permissions + // the user does not have permission to view this event + // if any of the following evaluate as false + if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) { + continue; + } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) { + continue; + } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) { + continue; + } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) { + continue; + } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) { + continue; + } + + // add event to the array if we passed the permissions check + // this is the common information + + $events[$i]['intervals'] =($tmp['duration']/60)/ $GLOBALS['day_calandar_interval'];//sets the number of rows this event should span + print_r($events[$i]['intervals']); + + $events[$i]['eid'] = $tmp['eid']; + $events[$i]['uname'] = $tmp['uname']; + $events[$i]['uid'] = $cuserid; + $events[$i]['catid'] = $tmp['catid']; + $events[$i]['time'] = $tmp['time']; + $events[$i]['eventDate'] = $tmp['eventDate']; + $events[$i]['duration'] = $tmp['duration']; + // there has to be a more intelligent way to do this + @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60)); + $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2); + //'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + $events[$i]['endDate'] = $tmp['endDate']; + $events[$i]['startTime'] = $tmp['startTime']; + $events[$i]['recurrtype'] = $tmp['recurrtype']; + $events[$i]['recurrfreq'] = $tmp['recurrfreq']; + $events[$i]['recurrspec'] = $tmp['recurrspec']; + $events[$i]['topic'] = $tmp['topic']; + $events[$i]['alldayevent'] = $tmp['alldayevent']; + $events[$i]['catcolor'] = $tmp['catcolor']; + $events[$i]['catname'] = $tmp['catname']; + $events[$i]['catdesc'] = $tmp['catdesc']; + $events[$i]['pid'] = $tmp['pid']; + $events[$i]['apptstatus'] = $tmp['apptstatus']; + $events[$i]['pubpid'] = $tmp['pubpid']; + $events[$i]['patient_name']= $tmp['patient_name']; + $events[$i]['provider_name'] = $tmp['provider_name']; + $events[$i]['owner_name'] = $tmp['owner_name']; + $events[$i]['patient_dob'] = $tmp['patient_dob']; + $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4); + $events[$i]['sharing'] = $tmp['sharing']; + $events[$i]['prefcatid'] = $tmp['prefcatid']; + $events[$i]['aid'] = $tmp['aid']; + $events[$i]['topictext'] = $topicname; + $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']); + if($events[$i]['intervals'] == 0) + $events[$i]['intervals'] = 1; + // is this a public event to be shown as busy? + if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) { + // make it not display any information + $events[$i]['title'] = _USER_BUSY_TITLE; + $events[$i]['hometext'] = _USER_BUSY_MESSAGE; + $events[$i]['desc'] = _USER_BUSY_MESSAGE; + $events[$i]['conttel'] = ''; + $events[$i]['contname'] = ''; + $events[$i]['contemail'] = ''; + $events[$i]['website'] = ''; + $events[$i]['fee'] = ''; + $events[$i]['location'] = ''; + $events[$i]['street1'] = ''; + $events[$i]['street2'] = ''; + $events[$i]['city'] = ''; + $events[$i]['state'] = ''; + $events[$i]['postal'] = ''; + } else { + $display_type = substr($tmp['hometext'],0,6); + if($display_type == ':text:') { + $prepFunction = 'pcVarPrepForDisplay'; + $tmp['hometext'] = substr($tmp['hometext'],6); + } elseif($display_type == ':html:') { + $prepFunction = 'pcVarPrepHTMLDisplay'; + $tmp['hometext'] = substr($tmp['hometext'],6); + } else { + $prepFunction = 'pcVarPrepHTMLDisplay'; + } + unset($display_type); + $events[$i]['title'] = $prepFunction($tmp['title']); + $events[$i]['hometext'] = $prepFunction($tmp['hometext']); + $events[$i]['desc'] = $events[$i]['hometext']; + $events[$i]['conttel'] = $prepFunction($tmp['conttel']); + $events[$i]['contname'] = $prepFunction($tmp['contname']); + $events[$i]['contemail'] = $prepFunction($tmp['contemail']); + $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website'])); + $events[$i]['fee'] = $prepFunction($tmp['fee']); + $loc = unserialize($tmp['location']); + $events[$i]['location'] = $prepFunction($loc['event_location']); + $events[$i]['street1'] = $prepFunction($loc['event_street1']); + $events[$i]['street2'] = $prepFunction($loc['event_street2']); + $events[$i]['city'] = $prepFunction($loc['event_city']); + $events[$i]['state'] = $prepFunction($loc['event_state']); + $events[$i]['postal'] = $prepFunction($loc['event_postal']); + } + $i++; + } + unset($tmp); + $result->Close(); + return $events; +} + + +function getBlockTime($time) { + + if ($time == 0 || strlen($time) == 0) { + + return "all_day"; + } + $ts = strtotime($time); + $half = 0; + $minutes = date("i",$ts); + $hour = date("H",$ts); + if ($minutes >= 30) + $half = 1; + $blocknum = (($hour * 2) +$half); + return strval($blocknum); +} + +function &postcalendar_userapi_pcGetEvents($args) +{ + $s_keywords = $s_category = $s_topic = ''; + extract($args); + + $date =& postcalendar_getDate(); + $cy = substr($date,0,4); + $cm = substr($date,4,2); + $cd = substr($date,6,2); + if(isset($start) && isset($end)) { + // parse start date + list($sm,$sd,$sy) = explode('/',$start); + // parse end date + list($em,$ed,$ey) = explode('/',$end); + + $s = (int) "$sy$sm$sd"; + if($s > $date) { + $cy = $sy; + $cm = $sm; + $cd = $sd; + } + $start_date = Date_Calc::dateFormat($sd,$sm,$sy,'%Y-%m-%d'); + $end_date = Date_Calc::dateFormat($ed,$em,$ey,'%Y-%m-%d'); + } else { + $sm = $em = $cm; + $sd = $ed = $cd; + $sy = $cy; + $ey = $cy+2; + $start_date = $sy.'-'.$sm.'-'.$sd; + $end_date = $ey.'-'.$em.'-'.$ed; + } + if ($faFlag && !isset($events)) { + $a = array('faFlag' => true,'start'=>$start_date,'end'=>$end_date,'s_keywords'=>$s_keywords,'s_category'=>$s_category,'s_topic'=>$s_topic,'viewtype'=>$viewtype, 'provider_id' => $provider_id, 'event_status' => $event_status); + //print_r($a); + $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a); + } + elseif ($collideFlag && !isset($events)) { + + $a = array('collideFlag' => true,'start'=>$start_date,'end'=>$end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime); + $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a); + } + elseif ($listappsFlag && !isset($events)) { + + $a = array('listappsFlag' => true,'start'=>$start_date,'end'=>$end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords); + $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a); + } + else if(!isset($events)) { + if(!isset($s_keywords)) $s_keywords = ''; + $a = array('start'=>$start_date,'end'=>$end_date,'s_keywords'=>$s_keywords,'s_category'=>$s_category,'s_topic'=>$s_topic,'viewtype'=>$viewtype, "sort" => "pc_startTime ASC, a.pc_duration ASC ",'providerID' => $providerID); + $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a); + } + + //============================================================== + // Here we build an array consisting of the date ranges + // specific to the current view. This array is then + // used to build the calendar display. + //============================================================== + $days = array(); + $sday = Date_Calc::dateToDays($sd,$sm,$sy); + $eday = Date_Calc::dateToDays($ed,$em,$ey); + for($cday = $sday; $cday <= $eday; $cday++) { + $d = Date_Calc::daysToDate($cday,'%d'); + $m = Date_Calc::daysToDate($cday,'%m'); + $y = Date_Calc::daysToDate($cday,'%Y'); + $store_date = Date_Calc::dateFormat($d,$m,$y,'%Y-%m-%d'); + $days[$store_date] = array(); + } + + $days = calculateEvents($days,$events,$viewtype); + return $days; +} + +function calculateEvents($days,$events,$viewtype) { + $date =& postcalendar_getDate(); + $cy = substr($date,0,4); + $cm = substr($date,4,2); + $cd = substr($date,6,2); + + foreach($events as $event) { + // get the name of the topic + $topicname = pcGetTopicName($event['topic']); + + // parse the event start date + list($esY,$esM,$esD) = explode('-',$event['eventDate']); + + // grab the recurring specs for the event + $event_recurrspec = @unserialize($event['recurrspec']); + + // determine the stop date for this event + if($event['endDate'] == '0000-00-00') { + $stop = $end_date; + } else { + $stop = $event['endDate']; + } + + $start_date = "$cy-$cm-$cd"; + + // Optimization of the stop date to not be much later than required. + $tmpsecs = strtotime($start_date); + if ($viewtype == 'day') $tmpsecs += 2 * 24 * 3600; + else if ($viewtype == 'week') $tmpsecs += 8 * 24 * 3600; + else if ($viewtype == 'month') $tmpsecs += 32 * 24 * 3600; + else $tmpsecs += 367 * 24 * 3600; + $tmp = date('Y-m-d', $tmpsecs); + if ($stop > $tmp) $stop = $tmp; + + $eventD = $event['eventDate']; + $eventS = $event['startTime']; + + switch($event['recurrtype']) { + + //============================================================== + // Events that do not repeat only have a startday + //============================================================== + case NO_REPEAT : + + if(isset($days[$event['eventDate']])) { + array_push($days[$event['eventDate']],$event); + if ($viewtype == "week") { + //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."
"; + + fillBlocks($eventD,&$days); + //echo "for $eventD loading " . getBlockTime($eventS) . "

"; + $gbt = getBlockTime($eventS); + $days[$eventD]['blocks'][$gbt][$eventD][] = $event; + //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . "
"; + //echo "begin printing blocks for $eventD
"; + //print_r($days[$eventD]['blocks']); + //echo "end printing blocks
"; + } + } + + break; + + //============================================================== + // Find events that repeat at a certain frequency + // Every,Every Other,Every Third,Every Fourth + // Day,Week,Month,Year,MWF,TR,M-F,SS + //============================================================== + case REPEAT : + + $rfreq = $event_recurrspec['event_repeat_freq']; + $rtype = $event_recurrspec['event_repeat_freq_type']; + // we should bring the event up to date to make this a tad bit faster + // any ideas on how to do that, exactly??? dateToDays probably. + $nm = $esM; $ny = $esY; $nd = $esD; + $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d'); + while($occurance < $start_date) { + $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype); + list($ny,$nm,$nd) = explode('-',$occurance); + } + while($occurance <= $stop) { + if(isset($days[$occurance])) { + array_push($days[$occurance],$event); + if ($viewtype == "week") { + fillBlocks($occurance,&$days); + //echo "for $occurance loading " . getBlockTime($eventS) . "

"; + $gbt = getBlockTime($eventS); + $days[$occurance]['blocks'][$gbt][$occurance][] = $event; + //echo "begin printing blocks for $eventD
"; + //print_r($days[$occurance]['blocks']); + //echo "end printing blocks
"; + } + } + $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype); + list($ny,$nm,$nd) = explode('-',$occurance); + } + + break; + + //============================================================== + // Find events that repeat on certain parameters + // On 1st,2nd,3rd,4th,Last + // Sun,Mon,Tue,Wed,Thu,Fri,Sat + // Every N Months + //============================================================== + case REPEAT_ON : + + $rfreq = $event_recurrspec['event_repeat_on_freq']; + $rnum = $event_recurrspec['event_repeat_on_num']; + $rday = $event_recurrspec['event_repeat_on_day']; + + //============================================================== + // Populate - Enter data into the event array + //============================================================== + $nm = $esM; $ny = $esY; $nd = $esD; + // make us current + + while($ny < $cy) { + $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny)); + list($ny,$nm,$nd) = explode('-',$occurance); + } + // populate the event array + while($ny <= $cy) { + $dnum = $rnum; // get day event repeats on + do { + $occurance = Date_Calc::NWeekdayOfMonth($dnum--,$rday,$nm,$ny,$format="%Y-%m-%d"); + } while($occurance === -1); + if(isset($days[$occurance]) && $occurance <= $stop) { + array_push($days[$occurance],$event); + if ($viewtype == "week") { + fillBlocks($occurance,&$days); + //echo "for $occurance loading " . getBlockTime($eventS) . "

"; + $gbt = getBlockTime($eventS); + $days[$occurance]['blocks'][$gbt][$occurance][] = $event; + } + } + $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny)); + list($ny,$nm,$nd) = explode('-',$occurance); + } + + break; + + } // <- end of switch($event['recurrtype']) + } // <- end of foreach($events as $event) + return $days; +} + +function fillBlocks($td,&$ar) { + if (strlen ($td) > 0 && !isset($ar[$td]['blocks'])) { + $ar[$td]['blocks'] = array(); + for ($j=0;$j<48;$j++) + $ar[strval($td)]['blocks'][strval($j)] = array(); + $ar[strval($td)]['blocks']["all_day"] = array(); + } + + +} + +/** + * __increment() + * returns the next valid date for an event based on the + * current day,month,year,freq and type + * @private + * @returns string YYYY-MM-DD + */ +function &__increment($d,$m,$y,$f,$t) +{ + if($t == REPEAT_EVERY_DAY) { + return date('Y-m-d',mktime(0,0,0,$m,($d+$f),$y)); + } elseif($t == REPEAT_EVERY_WORK_DAY) { + //echo "special occurance
"; + $beginday = date("D",mktime(0,0,0,$m,$d,$y)); + $dayincrement = 1; + if ($beginday == "Fri") { + $dayincrement = 3; + } + elseif ($beginday == "Sat") { + $dayincrement = 2; + } + return date('Y-m-d',mktime(0,0,0,$m,($d+$dayincrement),$y)); + + } elseif($t == REPEAT_EVERY_WEEK) { + return date('Y-m-d',mktime(0,0,0,$m,($d+(7*$f)),$y)); + } elseif($t == REPEAT_EVERY_MONTH) { + return date('Y-m-d',mktime(0,0,0,($m+$f),$d,$y)); + } elseif($t == REPEAT_EVERY_YEAR) { + return date('Y-m-d',mktime(0,0,0,$m,$d,($y+$f))); + } +} + +?> diff --git a/interface/main/main_info.php b/interface/main/main_info.php dissimilarity index 61% index debc49bf8..6a04a0595 100644 --- a/interface/main/main_info.php +++ b/interface/main/main_info.php @@ -1,29 +1,61 @@ - - - - -Main Screen - - - - - - - - - - - name="Calendar" scrolling="auto" frameborder="NO"> - - - -<body bgcolor="#FFFFFF"> - -</body> - - + + + + + +Main Screen + + + + + + + + + + + + +<body bgcolor="#FFFFFF"> + +</body> + + diff --git a/interface/usergroup/user_admin.php b/interface/usergroup/user_admin.php index e08284816..429a0c64b 100644 --- a/interface/usergroup/user_admin.php +++ b/interface/usergroup/user_admin.php @@ -1,215 +1,241 @@ - - - - - - - - - topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0> - - -

- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: " disabled>  : *
  : - /> -   : - /> -
: ">: ">
: ">:
: ">: ">
: ">:
: ">: ">
:
- -:
- - -
    -"> - - - onClick="javascript:this.form.newauthPass.value=MD5(this.form.clearPass.value);this.form.clearPass.value='';"> -    -[] -
- -

- - - - + + + + + + + + topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0> + + +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
: " disabled>  : *
  : + /> +   : + /> +
: ">: ">
: ">:
: ">: ">
: ">:
: ">: ">
:  
:
+ +:
+ + +
    +"> + + + onClick="javascript:this.form.newauthPass.value=MD5(this.form.clearPass.value);this.form.clearPass.value='';"> +    +[] +
+ +

+ + + + \ No newline at end of file diff --git a/interface/usergroup/usergroup_admin.php b/interface/usergroup/usergroup_admin.php index af5309334..ed46b1fb7 100644 --- a/interface/usergroup/usergroup_admin.php +++ b/interface/usergroup/usergroup_admin.php @@ -1,442 +1,457 @@ - - - - - - - - topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0> - - - -

- - - - - - - - - - - - - - - - - - - -
- -
- -: -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: :
  :
: :
: :
: :
  :
   >
- -
-
- -
-> -: -
- - -(Edit)
- - -
- - -: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:  :
: -:
: :
: :
: :
: :
: :
:
-:
- -
-> - -
-
-
- -: -
-: -    -: - -    -> - -
-
- -: -
- - -: - -    -: - -    -> - -
- -
- - - -"; - print ""; - print "\n"; -} -?> - -
?
" . $iter{"username"} . - "(Edit)" . - "" . - $iter{"fname"} . ' ' . $iter{"lname"}."" . - $iter{"info"} . "" . - $iter{"authorized"} . "
- -
- -Remove), "; -} - -foreach ($grouplist as $groupname => $list) { - print "" . $groupname . "
\n" . - substr($list,0,strlen($list)-2) . "
\n"; -} -?> - - - - - + + + + + + + + topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0> + + + +

+ + + + + + + + + + + + + + + + + + + +
+ +
+ +: +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
: :
  :
: :
: :
: :
  :
   >
+ +
+
+ +
+> +: +
+ + +(Edit)
+ + +
+ + +: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:  :
: +:
: :
: :
: :
: :
: :
:  
:
+:
+ +
+> + +
+
+
+ +: +
+: +    +: + +    +> + +
+
+ +: +
+ + +: + +    +: + +    +> + +
+ +
+ + + +"; + print ""; + print "\n"; +} +?> + +
?
" . $iter{"username"} . + "(Edit)" . + "" . + $iter{"fname"} . ' ' . $iter{"lname"}."" . + $iter{"info"} . "" . + $iter{"authorized"} . "
+ +
+ +Remove), "; +} + +foreach ($grouplist as $groupname => $list) { + print "" . $groupname . "
\n" . + substr($list,0,strlen($list)-2) . "
\n"; +} +?> + + + + + diff --git a/library/auth.inc b/library/auth.inc index aa9232b6a..ed159da12 100644 --- a/library/auth.inc +++ b/library/auth.inc @@ -1,228 +1,232 @@ - $timeout) { - newEvent("logout", $_SESSION['authUser'], $_SESSION['authProvider'], "timeout"); - authCloseSession(); - authLoginScreen(); - } else { - if (empty($GLOBALS['DAEMON_FLAG'])) $_SESSION["last_update"] = time(); - } -} - -//----------THINGS WE DO IF WE STILL LIKE YOU - -function authNewSession ($user, $pass, $provider) -{ - //session_name("OpenEMR"); - //session_id("81279258720".str_replace(".", "", $_SERVER['REMOTE_ADDR'])); - if(!session_id()) { - session_start(); - } - //echo "user is: $user pass is: $pass provider is: $provider
"; - $authDB = sqlQuery("select id, password, authorized, see_auth from users " . - "where username = '$user'"); - //echo "
auth pass: ".$authDB['password']; - if ($authDB['password'] == $pass) - { - //here, we check to see if the user is in fact a member of the correct group: - if ($authGroup = sqlQuery("select * from groups where user='$user' and name='$provider'")) { - $_SESSION['authUser'] = $user; - $_SESSION['authGroup'] = $authGroup['name']; - $_SESSION['authUserID'] = $authDB['id']; - $_SESSION['authPass'] = $pass; - $_SESSION['authProvider'] = $provider; - $_SESSION['authId'] = $authDB{'id'}; - $_SESSION['userauthorized'] = $authDB['authorized']; - // Some users may be able to authorize without being providers: - if ($authDB['see_auth'] > '2') $_SESSION['userauthorized'] = '1'; - return true; - } else { - return false; - } - } - else - return false; -} - -function authCheckSession () -{ - if (isset($_SESSION['authId'])) { - $authDB = sqlQuery("select username, password from users where id = '" . - $_SESSION['authId']."'"); - if ($_SESSION['authUser'] == $authDB['username'] && - $_SESSION['authPass'] == $authDB['password']) - { - return true; - } - else { - return false; - } - } - else { - return false; - } -} - -function authCloseSession () -{ - ob_start(); - session_unset(); -// $_SESSION = array(); - session_destroy(); - //setcookie(session_name(),"","","/"); - //the following does the same as the above line: - //if(isset($_COOKIE[session_name()])) { - // session_start(); - // session_destroy(); - unset($_COOKIE[session_name()]); - //} -} - -function authLoginScreen() -{ - //header("Location: https://{$_SERVER['HTTP_HOST']}{$GLOBALS['login_screen']}"); - header("Location: {$GLOBALS['login_screen']}"); - exit; -} - -function addUser ($username, $password_md5, $info, $authorized = 'yes') -{ - return sqlInsert("insert into users (username, password, info, authorized) values ('$username', '$password_md5', '$info', '$authorized')"); -} - -function delUser ($id) -{ - return sqlQuery("delete from users where id = '$id' limit 0,1"); -} - -function changePasword ($id, $new_md5) -{ - return sqlQuery("update users set password = '$new_md5' where id = '$id'"); -} - -function getUserList ($cols = '*', $limit = 'all', $start = '0') -{ - if ($limit = "all") - $rez = sqlStatement("select $cols from users where username != '' order by date DESC"); - else - $rez = sqlStatement("select $cols from users where username != '' order by date DESC limit $limit, $start"); - for ($iter = 0; $row = sqlFetchArray($rez); $iter++) - $tbl[$iter] = $row; - return $tbl; -} - -function getProviderList ($cols = '*', $limit= 'all', $start = '0') -{ - if ($limit = "all") - $rez = sqlStatement("select $cols from groups order by date DESC"); - else - $rez = sqlStatement("select $cols from groups order by date DESC limit $limit, $start"); - for ($iter = 0; $row = sqlFetchArray($rez); $iter++) - $tbl[$iter] = $row; - return $tbl; -} - -function addGroup ($groupname) -{ - return sqlInsert("insert into groups (name) values ('$groupname')"); -} - -function delGroup ($group_id) -{ - return sqlQuery("delete from groups where id = '$group_id' limit 0,1"); -} - -/*************************************************************** -//pennfirm -//Function currently user by new post calendar code to determine -//if a given user is in a group with another user -//and if so to allow editing of that users events -// -//*************************************************************/ - -function validateGroupStatus ($user_to_be_checked, $group_user) { - if (isset($user_to_be_checked) && isset($group_user)) { - if ($user_to_be_checked == $group_user) { - - return true; - } - elseif ($_SESSION['authorizeduser'] == 1) - return true; - - $query = "SELECT groups.name FROM users,groups WHERE users.username = \"" . mysql_real_escape_string($user_to_be_checked) . "\" " . - "AND users.username = groups.user group by groups.name"; - $result = sqlStatement($query); - - $usertbcGroups = array(); - - while ($row = mysql_fetch_array($result)) { - $usertbcGroups[] = $row[0]; - } - - $query = "SELECT groups.name FROM users,groups WHERE users.username = \"" . mysql_real_escape_string($group_user) . "\" " . - "AND users.username = groups.user group by groups.name"; - $result = sqlStatement($query); - - $usergGroups = array(); - - while ($row = mysql_fetch_array($result)) { - $usergGroups[] = $row[0]; - } - foreach ($usertbcGroups as $group) { - if(in_array($group,$usergGroups)) { - return true; - } - } - - } - - return false; -} -?> + $timeout) { + newEvent("logout", $_SESSION['authUser'], $_SESSION['authProvider'], "timeout"); + authCloseSession(); + authLoginScreen(); + } else { + if (empty($GLOBALS['DAEMON_FLAG'])) $_SESSION["last_update"] = time(); + } +} + +//----------THINGS WE DO IF WE STILL LIKE YOU + +function authNewSession ($user, $pass, $provider) +{ + //session_name("OpenEMR"); + //session_id("81279258720".str_replace(".", "", $_SERVER['REMOTE_ADDR'])); + if(!session_id()) { + session_start(); + } + //echo "user is: $user pass is: $pass provider is: $provider
"; + + //(CHEMED) added cal_ui to the list of fields, so we can change calendar UI for this user. + // Is this the right place to do it? + $authDB = sqlQuery("select id, password, authorized, see_auth, cal_ui from users " . + "where username = '$user'"); + //echo "
auth pass: ".$authDB['password']; + if ($authDB['password'] == $pass) + { + //here, we check to see if the user is in fact a member of the correct group: + if ($authGroup = sqlQuery("select * from groups where user='$user' and name='$provider'")) { + $_SESSION['authUser'] = $user; + $_SESSION['authGroup'] = $authGroup['name']; + $_SESSION['authUserID'] = $authDB['id']; + $_SESSION['authPass'] = $pass; + $_SESSION['authProvider'] = $provider; + $_SESSION['authId'] = $authDB{'id'}; + $_SESSION['cal_ui'] = $authDB['cal_ui']; + $_SESSION['userauthorized'] = $authDB['authorized']; + // Some users may be able to authorize without being providers: + if ($authDB['see_auth'] > '2') $_SESSION['userauthorized'] = '1'; + return true; + } else { + return false; + } + } + else + return false; +} + +function authCheckSession () +{ + if (isset($_SESSION['authId'])) { + $authDB = sqlQuery("select username, password from users where id = '" . + $_SESSION['authId']."'"); + if ($_SESSION['authUser'] == $authDB['username'] && + $_SESSION['authPass'] == $authDB['password']) + { + return true; + } + else { + return false; + } + } + else { + return false; + } +} + +function authCloseSession () +{ + ob_start(); + session_unset(); +// $_SESSION = array(); + session_destroy(); + //setcookie(session_name(),"","","/"); + //the following does the same as the above line: + //if(isset($_COOKIE[session_name()])) { + // session_start(); + // session_destroy(); + unset($_COOKIE[session_name()]); + //} +} + +function authLoginScreen() +{ + //header("Location: https://{$_SERVER['HTTP_HOST']}{$GLOBALS['login_screen']}"); + header("Location: {$GLOBALS['login_screen']}"); + exit; +} + +function addUser ($username, $password_md5, $info, $authorized = 'yes') +{ + return sqlInsert("insert into users (username, password, info, authorized) values ('$username', '$password_md5', '$info', '$authorized')"); +} + +function delUser ($id) +{ + return sqlQuery("delete from users where id = '$id' limit 0,1"); +} + +function changePasword ($id, $new_md5) +{ + return sqlQuery("update users set password = '$new_md5' where id = '$id'"); +} + +function getUserList ($cols = '*', $limit = 'all', $start = '0') +{ + if ($limit = "all") + $rez = sqlStatement("select $cols from users where username != '' order by date DESC"); + else + $rez = sqlStatement("select $cols from users where username != '' order by date DESC limit $limit, $start"); + for ($iter = 0; $row = sqlFetchArray($rez); $iter++) + $tbl[$iter] = $row; + return $tbl; +} + +function getProviderList ($cols = '*', $limit= 'all', $start = '0') +{ + if ($limit = "all") + $rez = sqlStatement("select $cols from groups order by date DESC"); + else + $rez = sqlStatement("select $cols from groups order by date DESC limit $limit, $start"); + for ($iter = 0; $row = sqlFetchArray($rez); $iter++) + $tbl[$iter] = $row; + return $tbl; +} + +function addGroup ($groupname) +{ + return sqlInsert("insert into groups (name) values ('$groupname')"); +} + +function delGroup ($group_id) +{ + return sqlQuery("delete from groups where id = '$group_id' limit 0,1"); +} + +/*************************************************************** +//pennfirm +//Function currently user by new post calendar code to determine +//if a given user is in a group with another user +//and if so to allow editing of that users events +// +//*************************************************************/ + +function validateGroupStatus ($user_to_be_checked, $group_user) { + if (isset($user_to_be_checked) && isset($group_user)) { + if ($user_to_be_checked == $group_user) { + + return true; + } + elseif ($_SESSION['authorizeduser'] == 1) + return true; + + $query = "SELECT groups.name FROM users,groups WHERE users.username = \"" . mysql_real_escape_string($user_to_be_checked) . "\" " . + "AND users.username = groups.user group by groups.name"; + $result = sqlStatement($query); + + $usertbcGroups = array(); + + while ($row = mysql_fetch_array($result)) { + $usertbcGroups[] = $row[0]; + } + + $query = "SELECT groups.name FROM users,groups WHERE users.username = \"" . mysql_real_escape_string($group_user) . "\" " . + "AND users.username = groups.user group by groups.name"; + $result = sqlStatement($query); + + $usergGroups = array(); + + while ($row = mysql_fetch_array($result)) { + $usergGroups[] = $row[0]; + } + foreach ($usertbcGroups as $group) { + if(in_array($group,$usergGroups)) { + return true; + } + } + + } + + return false; +} +?> diff --git a/library/dynarch_calendar_setup.js b/library/dynarch_calendar_setup.js index c269f7dd7..b3a8e10db 100644 --- a/library/dynarch_calendar_setup.js +++ b/library/dynarch_calendar_setup.js @@ -146,7 +146,7 @@ Calendar.setup = function (params) { } cal.create(params.flat); cal.show(); - return false; + return cal; // was "return false;" (fix from Nethanel Vilensky for OpenEMR) } var triggerEl = params.button || params.displayArea || params.inputField; diff --git a/library/patient.inc b/library/patient.inc index cb93bbfe6..d94f3b097 100644 --- a/library/patient.inc +++ b/library/patient.inc @@ -1,854 +1,904 @@ - 0) { - return $pi[0]['fname'] . " " . $pi[0]['lname']; - } - return ""; -} - -function getProviderId($providerName) { - $query = "select id from users where username = '". mysql_real_escape_string($providerName)."'"; - $rez = sqlStatement($query); - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - return $returnval; -} - -function getEthnoRacials() { - $returnval = array(""); - $sql = "select distinct lower(ethnoracial) as ethnoracial from patient_data"; - $rez = sqlStatement($sql); - for($iter=0; $row=sqlFetchArray($rez); $iter++) { - if (($row["ethnoracial"] != "")) { - array_push($returnval, $row["ethnoracial"]); - } - } - return $returnval; -} - -function getHistoryData($pid, $given = "*") -{ - $sql = "select $given from history_data where pid='$pid' order by date DESC limit 0,1"; - return sqlQuery($sql); -} - -// function getInsuranceData($pid, $type = "primary", $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name") -function getInsuranceData($pid, $type = "primary", $given = "insd.*, ic.name as provider_name") -{ - $sql = "select $given from insurance_data as insd " . - "left join insurance_companies as ic on ic.id = insd.provider " . - "where pid = '$pid' and type = '$type' order by date DESC limit 1"; - return sqlQuery($sql); -} - -function getInsuranceDataByDate($pid, $date, $type, - $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name") -{ // this must take the date in the following manner: YYYY-MM-DD - // this function recalls the insurance value that was most recently enterred from the - // given date. it will call up most recent records up to and on the date given, - // but not records enterred after the given date - $sql = "select $given from insurance_data as insd " . - "left join insurance_companies as ic on ic.id = provider " . - "where pid = '$pid' and date_format(date,'%Y-%m-%d') <= '$date' and " . - "type='$type' order by date DESC limit 1"; - return sqlQuery($sql); -} - -function getEmployerData($pid, $given = "*") -{ - $sql = "select $given from employer_data where pid='$pid' order by date DESC limit 0,1"; - return sqlQuery($sql); -} - -function getPatientLnames($lname = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") -{ - // Allow the last name to be followed by a comma and some part of a first name. - // New behavior for searches: - // Allows comma alone followed by some part of a first name - // If the first letter of either name is capital, searches for name starting - // with given substring (the expected behavior). If it is lower case, it - // it searches for the substring anywhere in the name. This applies to either - // last name or first name or both. The arbitrary limit of 100 results is set - // in the sql query below. --Mark Leeds - $lname = trim($lname); - $fname = ''; - if (preg_match('/^(.*),(.*)/', $lname, $matches)) { - $lname = trim($matches[1]); - $fname = trim($matches[2]); - } - $search_for_pieces1 = ''; - $search_for_pieces2 = ''; - if ($lname{0} != strtoupper($lname{0})) {$search_for_pieces1 = '%';} - if ($fname{0} != strtoupper($fname{0})) {$search_for_pieces2 = '%';} - $sql="select $given from patient_data where lname like '" - .$search_for_pieces1."$lname%' " - ."and fname like '" - .$search_for_pieces2."$fname%' " - ."order by $orderby limit 100"; - - if ($limit != "all") - $sql .= " limit $start, $limit"; - $rez = sqlStatement($sql); - - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - - return $returnval; -} - -function getPatientId($pid = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") -{ - $sql = "select $given from patient_data where pubpid like '$pid%' " . - "order by $orderby"; - - if ($limit != "all") - $sql .= " limit $start, $limit"; - $rez = sqlStatement($sql); - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - - return $returnval; -} - -function getPatientPID($pid = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") -{ - $command = "="; - if ($pid == -1) - $pid = "%"; - elseif (empty($pid)) - $pid = "NULL"; - - if (strstr($pid,"%")) - $command = "like"; - - $sql="select $given from patient_data where pid $command '$pid' order by $orderby"; - - if ($limit != "all") - $sql .= " limit $start, $limit"; - - $rez = sqlStatement($sql); - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - - return $returnval; -} - -function getPatientName($pid) { - if (empty($pid)) - return ""; - $patientData = getPatientPID($pid); - if (empty($patientData[0]['lname'])) - return ""; - $patientName = $patientData[0]['lname'] . ", " . $patientData[0]['fname']; - return $patientName; -} - -function getPatientDOB($DOB = "%", $given = "pid, id, lname, fname, mname", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") -{ - $DOB = fixDate($DOB, $DOB); - - $sql="select $given from patient_data where DOB like '$DOB%' " . - "order by $orderby"; - - if ($limit != "all") - $sql .= " limit $start, $limit"; - - $rez = sqlStatement($sql); - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - - return $returnval; -} - -function getPatientSSN($ss = "%", $given = "pid, id, lname, fname, mname, providerID", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") -{ - $sql="select $given from patient_data where ss like '$ss%' " . - "order by $orderby"; - - if ($limit != "all") - $sql .= " limit $start, $limit"; - - $rez = sqlStatement($sql); - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - - return $returnval; -} - -function getPatientIds($given = "pid, id, lname, fname, mname", $orderby = "id ASC", $limit="all", $start="0") -{ - $sql="select $given from patient_data order by $orderby"; - - if ($limit != "all") - $sql .= " limit $start, $limit"; - - $rez = sqlStatement($sql); - for($iter=0; $row=sqlFetchArray($rez); $iter++) - $returnval[$iter]=$row; - - return $returnval; -} - -//----------------------input functions -function newPatientData( $db_id="", - $title = "", - $fname = "", - $lname = "", - $mname = "", - $sex = "", - $DOB = "", - $street = "", - $postal_code = "", - $city = "", - $state = "", - $country_code = "", - $ss = "", - $occupation = "", - $phone_home = "", - $phone_biz = "", - $phone_contact = "", - $status = "", - $contact_relationship = "", - $referrer = "", - $referrerID = "", - $email = "", - $language = "", - $ethnoracial = "", - $interpretter = "", - $migrantseasonal = "", - $family_size = "", - $monthly_income = "", - $homeless = "", - $financial_review = "", - $pubpid = "", - $pid = "MAX(pid)+1", - $providerID = "", - $genericname1 = "", - $genericval1 = "", - $genericname2 = "", - $genericval2 = "", - $phone_cell = "", - $hipaa_mail = "", - $hipaa_voice = "", - $squad = 0, - $pharmacy_id = 0, - $drivers_license = "", - $hipaa_notice = "", - $hipaa_message = "" - ) -{ - $DOB = fixDate($DOB); - - $fitness = 0; - $referral_source = ''; - if ($pid) { - $rez = sqlQuery("select id, fitness, referral_source from patient_data where pid = $pid"); - // Check for brain damage: - if ($db_id != $rez['id']) { - $errmsg = "Internal error: Attempt to change patient_data.id from '" . - $rez['id'] . "' to '$db_id' for pid '$pid'"; - die($errmsg); - } - $fitness = $rez['fitness']; - $referral_source = $rez['referral_source']; - } - - $query = ("replace into patient_data set - id='$db_id', - title='$title', - fname='$fname', - lname='$lname', - mname='$mname', - sex='$sex', - DOB='$DOB', - street='$street', - postal_code='$postal_code', - city='$city', - state='$state', - country_code='$country_code', - drivers_license='$drivers_license', - ss='$ss', - occupation='$occupation', - phone_home='$phone_home', - phone_biz='$phone_biz', - phone_contact='$phone_contact', - status='$status', - contact_relationship='$contact_relationship', - referrer='$referrer', - referrerID='$referrerID', - email='$email', - language='$language', - ethnoracial='$ethnoracial', - interpretter='$interpretter', - migrantseasonal='$migrantseasonal', - family_size='$family_size', - monthly_income='$monthly_income', - homeless='$homeless', - financial_review='$financial_review', - pubpid='$pubpid', - pid = $pid, - providerID = '$providerID', - genericname1 = '$genericname1', - genericval1 = '$genericval1', - genericname2 = '$genericname2', - genericval2 = '$genericval2', - phone_cell = '$phone_cell', - pharmacy_id = '$pharmacy_id', - hipaa_mail = '$hipaa_mail', - hipaa_voice = '$hipaa_voice', - hipaa_notice = '$hipaa_notice', - hipaa_message = '$hipaa_message', - squad = '$squad', - fitness='$fitness', - referral_source='$referral_source', - date=NOW() - "); - - $id = sqlInsert($query); - $foo = sqlQuery("select pid from patient_data where id='$id' order by date limit 0,1"); - - sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home, - $phone_biz,$phone_cell,$email,$pid); - - return $foo['pid']; -} - -// Supported input date formats are: -// mm/dd/yyyy -// mm/dd/yy (assumes 20yy for yy < 10, else 19yy) -// yyyy/mm/dd -// also mm-dd-yyyy, etc. and mm.dd.yyyy, etc. -// -function fixDate($date, $default="0000-00-00") { - $fixed_date = $default; - $date = trim($date); - if (preg_match("'^[0-9]{1,4}[/.-][0-9]{1,2}[/.-][0-9]{1,4}$'", $date)) { - $dmy = preg_split("'[/.-]'", $date); - if ($dmy[0] > 99) { - $fixed_date = sprintf("%04u-%02u-%02u", $dmy[0], $dmy[1], $dmy[2]); - } else { - if ($dmy[0] != 0 || $dmy[1] != 0 || $dmy[2] != 0) { - if ($dmy[2] < 1000) $dmy[2] += 1900; - if ($dmy[2] < 1910) $dmy[2] += 100; - } - $fixed_date = sprintf("%04u-%02u-%02u", $dmy[2], $dmy[0], $dmy[1]); - } - } - - return $fixed_date; -} - -function updatePatientData($pid,$new) -{ - /******************************************************************* - $real = getPatientData($pid); - $new['DOB'] = fixDate($new['DOB']); - while(list($key, $value) = each ($new)) - $real[$key] = $value; - $real['date'] = "'+NOW()+'"; - $real['id'] = ""; - $sql = "insert into patient_data set "; - while(list($key, $value) = each($real)) - $sql .= $key." = '$value', "; - $sql = substr($sql, 0, -2); - return sqlInsert($sql); - *******************************************************************/ - - // The above was broken, though seems intent to insert a new patient_data - // row for each update. A good idea, but nothing is doing that yet so - // the code below does not yet attempt it. - - $new['DOB'] = fixDate($new['DOB']); - $db_id = $new['id']; - - $rez = sqlQuery("SELECT * FROM patient_data WHERE id = '$db_id'"); - // Check for brain damage: - if ($pid != $rez['pid']) { - $errmsg = "Internal error: Attempt to change patient data with pid = '" . - $rez['pid'] . "' when current pid is '$pid' for id '$db_id'"; - die($errmsg); - } - $sql = "UPDATE patient_data SET date = NOW()"; - foreach ($new as $key => $value) { - $sql .= ", $key = '$value'"; - } - $sql .= " WHERE id = '$db_id'"; - $id = sqlInsert($sql); - - sync_patient($db_id,$rez['fname'],$rez['lname'],$rez['street'],$rez['city'], - $rez['postal_code'],$rez['state'],$rez['phone_home'],$rez['phone_biz'], - $rez['phone_cell'],$rez['email'],$rez['pid']); - - return $id; -} - -function newEmployerData( $pid, - $name = "", - $street = "", - $postal_code = "", - $city = "", - $state = "", - $country = "" - ) -{ - return sqlInsert("insert into employer_data set - name='$name', - street='$street', - postal_code='$postal_code', - city='$city', - state='$state', - country='$country', - pid='$pid', - date=NOW() - "); -} - -function updateEmployerData($pid,$new) -{ - $real = getEmployerData($pid); - while(list($key, $value) = each ($new)) - $real[$key] = $value; - $real['date'] = "'+NOW()+'"; - $real['id'] = ""; - - $sql = "insert into employer_data set "; - while(list($key, $value) = each($real)) - $sql .= $key." = '$value', "; - $sql = substr($sql, 0, -2); - - - return sqlInsert($sql); -} - -// This updates or adds the given insurance data info, while retaining any -// previously added insurance_data rows that should be preserved. -// This does not directly support the maintenance of non-current insurance. -// -function newInsuranceData( - $pid, - $type = "", - $provider = "", - $policy_number = "", - $group_number = "", - $plan_name = "", - $subscriber_lname = "", - $subscriber_mname = "", - $subscriber_fname = "", - $subscriber_relationship = "", - $subscriber_ss = "", - $subscriber_DOB = "", - $subscriber_street = "", - $subscriber_postal_code = "", - $subscriber_city = "", - $subscriber_state = "", - $subscriber_country = "", - $subscriber_phone = "", - $subscriber_employer = "", - $subscriber_employer_street = "", - $subscriber_employer_city = "", - $subscriber_employer_postal_code = "", - $subscriber_employer_state = "", - $subscriber_employer_country = "", - $copay = "", - $subscriber_sex = "", - $effective_date = "0000-00-00") -{ - if (strlen($type) <= 0) return FALSE; - - // If a bad date was passed, err on the side of caution. - $effective_date = fixDate($effective_date, date('Y-m-d')); - - $idres = sqlStatement("SELECT * FROM insurance_data WHERE " . - "pid = '$pid' AND type = '$type' ORDER BY date DESC"); - $idrow = sqlFetchArray($idres); - - // Replace the most recent entry in any of the following cases: - // * Its effective date is >= this effective date. - // * It is the first entry and it has no (insurance) provider. - // * There is no encounter that is earlier than the new effective date but - // on or after the old effective date. - // Otherwise insert a new entry. - - $replace = false; - if ($idrow) { - if (strcmp($idrow['date'], $effective_date) > 0) { - $replace = true; - } - else { - if (!$idrow['provider'] && !sqlFetchArray($idres)) { - $replace = true; - } - else { - $ferow = sqlQuery("SELECT count(*) AS count FROM form_encounter " . - "WHERE pid = '$pid' AND date < '$effective_date 00:00:00' AND " . - "date >= '" . $idrow['date'] . " 00:00:00'"); - if ($ferow['count'] == 0) $replace = true; - } - } - } - - if ($replace) { - - // TBD: This is a bit dangerous in that a typo in entering the effective - // date can wipe out previous insurance history. So we want some data - // entry validation somewhere. - sqlStatement("DELETE FROM insurance_data WHERE " . - "pid = '$pid' AND type = '$type' AND date >= '$effective_date' AND " . - "id != " . $idrow['id']); - - $data = array(); - $data['type'] = $type; - $data['provider'] = $provider; - $data['policy_number'] = $policy_number; - $data['group_number'] = $group_number; - $data['plan_name'] = $plan_name; - $data['subscriber_lname'] = $subscriber_lname; - $data['subscriber_mname'] = $subscriber_mname; - $data['subscriber_fname'] = $subscriber_fname; - $data['subscriber_relationship'] = $subscriber_relationship; - $data['subscriber_ss'] = $subscriber_ss; - $data['subscriber_DOB'] = $subscriber_DOB; - $data['subscriber_street'] = $subscriber_street; - $data['subscriber_postal_code'] = $subscriber_postal_code; - $data['subscriber_city'] = $subscriber_city; - $data['subscriber_state'] = $subscriber_state; - $data['subscriber_country'] = $subscriber_country; - $data['subscriber_phone'] = $subscriber_phone; - $data['subscriber_employer'] = $subscriber_employer; - $data['subscriber_employer_city'] = $subscriber_employer_city; - $data['subscriber_employer_street'] = $subscriber_employer_street; - $data['subscriber_employer_postal_code'] = $subscriber_employer_postal_code; - $data['subscriber_employer_state'] = $subscriber_employer_state; - $data['subscriber_employer_country'] = $subscriber_employer_country; - $data['copay'] = $copay; - $data['subscriber_sex'] = $subscriber_sex; - $data['pid'] = $pid; - $data['date'] = $effective_date; - updateInsuranceData($idrow['id'], $data); - return $idrow['id']; - } - else { - return sqlInsert("INSERT INTO insurance_data SET - type = '$type', - provider = '$provider', - policy_number = '$policy_number', - group_number = '$group_number', - plan_name = '$plan_name', - subscriber_lname = '$subscriber_lname', - subscriber_mname = '$subscriber_mname', - subscriber_fname = '$subscriber_fname', - subscriber_relationship = '$subscriber_relationship', - subscriber_ss = '$subscriber_ss', - subscriber_DOB = '$subscriber_DOB', - subscriber_street = '$subscriber_street', - subscriber_postal_code = '$subscriber_postal_code', - subscriber_city = '$subscriber_city', - subscriber_state = '$subscriber_state', - subscriber_country = '$subscriber_country', - subscriber_phone = '$subscriber_phone', - subscriber_employer = '$subscriber_employer', - subscriber_employer_city = '$subscriber_employer_city', - subscriber_employer_street = '$subscriber_employer_street', - subscriber_employer_postal_code = '$subscriber_employer_postal_code', - subscriber_employer_state = '$subscriber_employer_state', - subscriber_employer_country = '$subscriber_employer_country', - copay = '$copay', - subscriber_sex = '$subscriber_sex', - pid = '$pid', - date = '$effective_date' - "); - } -} - -// This is used internally only. -function updateInsuranceData($id, $new) -{ - $fields = sqlListFields("insurance_data"); - $use = array(); - - while(list($key, $value) = each ($new)) { - if (in_array($key, $fields)) { - $use[$key] = $value; - } - } - - $sql = "UPDATE insurance_data SET "; - while(list($key, $value) = each($use)) - $sql .= $key . " = '$value', "; - $sql = substr($sql, 0, -2) . " WHERE id = '$id'"; - - sqlStatement($sql); -} - -function newHistoryData($pid, $new=false) { - $sql = "insert into history_data set pid = '$pid', date = NOW()"; - if ($new) { - while(list($key, $value) = each($new)) { - if (!get_magic_quotes_gpc()) $value = addslashes($value); - $sql .= ", $key = '$value'"; - } - } - return sqlInsert($sql); -} - -function updateHistoryData($pid,$new) -{ - $real = getHistoryData($pid); - while(list($key, $value) = each ($new)) - $real[$key] = $value; - $real['date'] = "'+NOW()+'"; - $real['id'] = ""; - - $sql = "insert into history_data set "; - while(list($key, $value) = each($real)) - $sql .= $key." = '$value', "; - $sql = substr($sql, 0, -2); - - - return sqlInsert($sql); -} - -function sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home, - $phone_biz,$phone_cell,$email,$pid="") -{ - $db = $GLOBALS['adodb']['db']; - $customer_info = array(); - - $sql = "SELECT foreign_id,foreign_table FROM integration_mapping where local_table = 'patient_data' and local_id = '" . $id . "'"; - $result = $db->Execute($sql); - if ($result && !$result->EOF) { - $customer_info['foreign_update'] = true; - $customer_info['foreign_id'] = $result->fields['foreign_id']; - $customer_info['foreign_table'] = $result->fields['foreign_table']; - } - - ///xml rpc code to connect to accounting package and add user to it - $customer_info['firstname'] = $fname; - $customer_info['lastname'] = $lname; - $customer_info['address'] = $street; - $customer_info['suburb'] = $city; - $customer_info['state'] = $state; - $customer_info['postcode'] = $postal_code; - - //ezybiz wants state as a code rather than abbreviation - $customer_info['geo_zone_id'] = ""; - $sql = "SELECT zone_id from geo_zone_reference where zone_code = '" . strtoupper($state) . "'"; - $db = $GLOBALS['adodb']['db']; - $result = $db->Execute($sql); - if ($result && !$result->EOF) { - $customer_info['geo_zone_id'] = $result->fields['zone_id']; - } - - //ezybiz wants country as a code rather than abbreviation - $customer_info['geo_country_id'] = ""; - $sql = "SELECT countries_id from geo_country_reference where countries_iso_code_2 = '" . strtoupper($country_code) . "'"; - $db = $GLOBALS['adodb']['db']; - $result = $db->Execute($sql); - if ($result && !$result->EOF) { - $customer_info['geo_country_id'] = $result->fields['countries_id']; - } - - $customer_info['phone1'] = $phone_home; - $customer_info['phone1comment'] = "Home Phone"; - $customer_info['phone2'] = $phone_biz; - $customer_info['phone2comment'] = "Business Phone"; - $customer_info['phone3'] = $phone_cell; - $customer_info['phone3comment'] = "Cell Phone"; - $customer_info['email'] = $email; - $customer_info['customernumber'] = $pid; - - $function['ezybiz.add_customer'] = array(new xmlrpcval($customer_info,"struct")); - $ws = new WSWrapper($function); - - // if the remote patient was added make an entry in the local mapping table to that updates can be made correctly - if (is_numeric($ws->value)) { - $sql = "REPLACE INTO integration_mapping set id = '" . $db->GenID("sequences") . "', foreign_id ='" . $ws->value . "', foreign_table ='customer', local_id = '" . $id . "', local_table = 'patient_data' "; - $db->Execute($sql) or die ("error: " . $db->ErrorMsg()); - } -} - -// Returns Date of Birth given YYYYMMDD from MySQL DATE_FORMAT(DOB,'%Y%m%d') -function getPatientAge($dobYMD) -{ - $tdyYMD=date("Ymd"); - $yearDiff = substr($tdyYMD,0,4) - substr($dobYMD,0,4); - $ageInMonths = ((substr($tdyYMD,0,4)*12)+substr($tdyYMD,4,2)) - - ((substr($dobYMD,0,4)*12)+substr($dobYMD,4,2)); - $dayDiff = substr($tdyYMD,6,2) - substr($dobYMD,6,2); - if ( $dayDiff < 0 ) { - $ageInMonths -= 1; - } - if ( $ageInMonths > 24 ) { - $age = intval($ageInMonths/12); - } - else { - $age = "$ageInMonths month"; - } - return $age; -} - -function dateToDB ($date) -{ - $date=substr ($date,6,4)."-".substr ($date,3,2)."-".substr($date, 0,2); - return $date; -} - -function DBToDate ($date) -{ - $date=substr ($date,5,2)."/".substr ($date,8,2)."/".substr($date, 0,4); - return $date; -} -?> + 0) { + return $pi[0]['fname'] . " " . $pi[0]['lname']; + } + return ""; +} + +function getProviderId($providerName) { + $query = "select id from users where username = '". mysql_real_escape_string($providerName)."'"; + $rez = sqlStatement($query); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + return $returnval; +} + +function getEthnoRacials() { + $returnval = array(""); + $sql = "select distinct lower(ethnoracial) as ethnoracial from patient_data"; + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) { + if (($row["ethnoracial"] != "")) { + array_push($returnval, $row["ethnoracial"]); + } + } + return $returnval; +} + +function getHistoryData($pid, $given = "*") +{ + $sql = "select $given from history_data where pid='$pid' order by date DESC limit 0,1"; + return sqlQuery($sql); +} + +// function getInsuranceData($pid, $type = "primary", $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name") +function getInsuranceData($pid, $type = "primary", $given = "insd.*, ic.name as provider_name") +{ + $sql = "select $given from insurance_data as insd " . + "left join insurance_companies as ic on ic.id = insd.provider " . + "where pid = '$pid' and type = '$type' order by date DESC limit 1"; + return sqlQuery($sql); +} + +function getInsuranceDataByDate($pid, $date, $type, + $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name") +{ // this must take the date in the following manner: YYYY-MM-DD + // this function recalls the insurance value that was most recently enterred from the + // given date. it will call up most recent records up to and on the date given, + // but not records enterred after the given date + $sql = "select $given from insurance_data as insd " . + "left join insurance_companies as ic on ic.id = provider " . + "where pid = '$pid' and date_format(date,'%Y-%m-%d') <= '$date' and " . + "type='$type' order by date DESC limit 1"; + return sqlQuery($sql); +} + +function getEmployerData($pid, $given = "*") +{ + $sql = "select $given from employer_data where pid='$pid' order by date DESC limit 0,1"; + return sqlQuery($sql); +} + +function getPatientLnames($lname = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") +{ + // Allow the last name to be followed by a comma and some part of a first name. + // New behavior for searches: + // Allows comma alone followed by some part of a first name + // If the first letter of either name is capital, searches for name starting + // with given substring (the expected behavior). If it is lower case, it + // it searches for the substring anywhere in the name. This applies to either + // last name or first name or both. The arbitrary limit of 100 results is set + // in the sql query below. --Mark Leeds + $lname = trim($lname); + $fname = ''; + if (preg_match('/^(.*),(.*)/', $lname, $matches)) { + $lname = trim($matches[1]); + $fname = trim($matches[2]); + } + $search_for_pieces1 = ''; + $search_for_pieces2 = ''; + if ($lname{0} != strtoupper($lname{0})) {$search_for_pieces1 = '%';} + if ($fname{0} != strtoupper($fname{0})) {$search_for_pieces2 = '%';} + $sql="select $given from patient_data where lname like '" + .$search_for_pieces1."$lname%' " + ."and fname like '" + .$search_for_pieces2."$fname%' " + ."order by $orderby limit 100"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + $rez = sqlStatement($sql); + + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +function getPatientId($pid = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") +{ + $sql = "select $given from patient_data where pubpid like '$pid%' " . + "order by $orderby"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +function getPatientPID($pid = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") +{ + $command = "="; + if ($pid == -1) + $pid = "%"; + elseif (empty($pid)) + $pid = "NULL"; + + if (strstr($pid,"%")) + $command = "like"; + + $sql="select $given from patient_data where pid $command '$pid' order by $orderby"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +function getPatientName($pid) { + if (empty($pid)) + return ""; + $patientData = getPatientPID($pid); + if (empty($patientData[0]['lname'])) + return ""; + $patientName = $patientData[0]['lname'] . ", " . $patientData[0]['fname']; + return $patientName; +} + +function getPatientDOB($DOB = "%", $given = "pid, id, lname, fname, mname", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") +{ + $DOB = fixDate($DOB, $DOB); + + $sql="select $given from patient_data where DOB like '$DOB%' " . + "order by $orderby"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +function getPatientSSN($ss = "%", $given = "pid, id, lname, fname, mname, providerID", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") +{ + $sql="select $given from patient_data where ss like '$ss%' " . + "order by $orderby"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +//(CHEMED) Search by phone number +function getPatientPhone($phone = "%", $given = "pid, id, lname, fname, mname, providerID", $orderby = "lname ASC, fname ASC", $limit="all", $start="0") +{ + $phone = ereg_replace( "[[:punct:]]","", $phone ); + $sql="select $given from patient_data where REPLACE(REPLACE(phone_home, '-', ''), ' ', '') REGEXP '$phone' " . + "order by $orderby"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +function getPatientIds($given = "pid, id, lname, fname, mname", $orderby = "id ASC", $limit="all", $start="0") +{ + $sql="select $given from patient_data order by $orderby"; + + if ($limit != "all") + $sql .= " limit $start, $limit"; + + $rez = sqlStatement($sql); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +//----------------------input functions +function newPatientData( $db_id="", + $title = "", + $fname = "", + $lname = "", + $mname = "", + $sex = "", + $DOB = "", + $street = "", + $postal_code = "", + $city = "", + $state = "", + $country_code = "", + $ss = "", + $occupation = "", + $phone_home = "", + $phone_biz = "", + $phone_contact = "", + $status = "", + $contact_relationship = "", + $referrer = "", + $referrerID = "", + $email = "", + $language = "", + $ethnoracial = "", + $interpretter = "", + $migrantseasonal = "", + $family_size = "", + $monthly_income = "", + $homeless = "", + $financial_review = "", + $pubpid = "", + $pid = "MAX(pid)+1", + $providerID = "", + $genericname1 = "", + $genericval1 = "", + $genericname2 = "", + $genericval2 = "", + $phone_cell = "", + $hipaa_mail = "", + $hipaa_voice = "", + $squad = 0, + $pharmacy_id = 0, + $drivers_license = "", + $hipaa_notice = "", + $hipaa_message = "" + ) +{ + $DOB = fixDate($DOB); + + $fitness = 0; + $referral_source = ''; + if ($pid) { + $rez = sqlQuery("select id, fitness, referral_source from patient_data where pid = $pid"); + // Check for brain damage: + if ($db_id != $rez['id']) { + $errmsg = "Internal error: Attempt to change patient_data.id from '" . + $rez['id'] . "' to '$db_id' for pid '$pid'"; + die($errmsg); + } + $fitness = $rez['fitness']; + $referral_source = $rez['referral_source']; + } + + $query = ("replace into patient_data set + id='$db_id', + title='$title', + fname='$fname', + lname='$lname', + mname='$mname', + sex='$sex', + DOB='$DOB', + street='$street', + postal_code='$postal_code', + city='$city', + state='$state', + country_code='$country_code', + drivers_license='$drivers_license', + ss='$ss', + occupation='$occupation', + phone_home='$phone_home', + phone_biz='$phone_biz', + phone_contact='$phone_contact', + status='$status', + contact_relationship='$contact_relationship', + referrer='$referrer', + referrerID='$referrerID', + email='$email', + language='$language', + ethnoracial='$ethnoracial', + interpretter='$interpretter', + migrantseasonal='$migrantseasonal', + family_size='$family_size', + monthly_income='$monthly_income', + homeless='$homeless', + financial_review='$financial_review', + pubpid='$pubpid', + pid = $pid, + providerID = '$providerID', + genericname1 = '$genericname1', + genericval1 = '$genericval1', + genericname2 = '$genericname2', + genericval2 = '$genericval2', + phone_cell = '$phone_cell', + pharmacy_id = '$pharmacy_id', + hipaa_mail = '$hipaa_mail', + hipaa_voice = '$hipaa_voice', + hipaa_notice = '$hipaa_notice', + hipaa_message = '$hipaa_message', + squad = '$squad', + fitness='$fitness', + referral_source='$referral_source', + date=NOW() + "); + + $id = sqlInsert($query); + $foo = sqlQuery("select pid from patient_data where id='$id' order by date limit 0,1"); + + sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home, + $phone_biz,$phone_cell,$email,$pid); + + return $foo['pid']; +} + +// Supported input date formats are: +// mm/dd/yyyy +// mm/dd/yy (assumes 20yy for yy < 10, else 19yy) +// yyyy/mm/dd +// also mm-dd-yyyy, etc. and mm.dd.yyyy, etc. +// +function fixDate($date, $default="0000-00-00") { + $fixed_date = $default; + $date = trim($date); + if (preg_match("'^[0-9]{1,4}[/.-][0-9]{1,2}[/.-][0-9]{1,4}$'", $date)) { + $dmy = preg_split("'[/.-]'", $date); + if ($dmy[0] > 99) { + $fixed_date = sprintf("%04u-%02u-%02u", $dmy[0], $dmy[1], $dmy[2]); + } else { + if ($dmy[0] != 0 || $dmy[1] != 0 || $dmy[2] != 0) { + if ($dmy[2] < 1000) $dmy[2] += 1900; + if ($dmy[2] < 1910) $dmy[2] += 100; + } + $fixed_date = sprintf("%04u-%02u-%02u", $dmy[2], $dmy[0], $dmy[1]); + } + } + + return $fixed_date; +} + +function updatePatientData($pid,$new) +{ + /******************************************************************* + $real = getPatientData($pid); + $new['DOB'] = fixDate($new['DOB']); + while(list($key, $value) = each ($new)) + $real[$key] = $value; + $real['date'] = "'+NOW()+'"; + $real['id'] = ""; + $sql = "insert into patient_data set "; + while(list($key, $value) = each($real)) + $sql .= $key." = '$value', "; + $sql = substr($sql, 0, -2); + return sqlInsert($sql); + *******************************************************************/ + + // The above was broken, though seems intent to insert a new patient_data + // row for each update. A good idea, but nothing is doing that yet so + // the code below does not yet attempt it. + + $new['DOB'] = fixDate($new['DOB']); + $db_id = $new['id']; + + $rez = sqlQuery("SELECT * FROM patient_data WHERE id = '$db_id'"); + // Check for brain damage: + if ($pid != $rez['pid']) { + $errmsg = "Internal error: Attempt to change patient data with pid = '" . + $rez['pid'] . "' when current pid is '$pid' for id '$db_id'"; + die($errmsg); + } + $sql = "UPDATE patient_data SET date = NOW()"; + foreach ($new as $key => $value) { + $sql .= ", $key = '$value'"; + } + $sql .= " WHERE id = '$db_id'"; + $id = sqlInsert($sql); + + sync_patient($db_id,$rez['fname'],$rez['lname'],$rez['street'],$rez['city'], + $rez['postal_code'],$rez['state'],$rez['phone_home'],$rez['phone_biz'], + $rez['phone_cell'],$rez['email'],$rez['pid']); + + return $id; +} + +function newEmployerData( $pid, + $name = "", + $street = "", + $postal_code = "", + $city = "", + $state = "", + $country = "" + ) +{ + return sqlInsert("insert into employer_data set + name='$name', + street='$street', + postal_code='$postal_code', + city='$city', + state='$state', + country='$country', + pid='$pid', + date=NOW() + "); +} + +function updateEmployerData($pid,$new) +{ + $real = getEmployerData($pid); + while(list($key, $value) = each ($new)) + $real[$key] = $value; + $real['date'] = "'+NOW()+'"; + $real['id'] = ""; + + $sql = "insert into employer_data set "; + while(list($key, $value) = each($real)) + $sql .= $key." = '$value', "; + $sql = substr($sql, 0, -2); + + + return sqlInsert($sql); +} + +// This updates or adds the given insurance data info, while retaining any +// previously added insurance_data rows that should be preserved. +// This does not directly support the maintenance of non-current insurance. +// +function newInsuranceData( + $pid, + $type = "", + $provider = "", + $policy_number = "", + $group_number = "", + $plan_name = "", + $subscriber_lname = "", + $subscriber_mname = "", + $subscriber_fname = "", + $subscriber_relationship = "", + $subscriber_ss = "", + $subscriber_DOB = "", + $subscriber_street = "", + $subscriber_postal_code = "", + $subscriber_city = "", + $subscriber_state = "", + $subscriber_country = "", + $subscriber_phone = "", + $subscriber_employer = "", + $subscriber_employer_street = "", + $subscriber_employer_city = "", + $subscriber_employer_postal_code = "", + $subscriber_employer_state = "", + $subscriber_employer_country = "", + $copay = "", + $subscriber_sex = "", + $effective_date = "0000-00-00") +{ + if (strlen($type) <= 0) return FALSE; + + // If a bad date was passed, err on the side of caution. + $effective_date = fixDate($effective_date, date('Y-m-d')); + + $idres = sqlStatement("SELECT * FROM insurance_data WHERE " . + "pid = '$pid' AND type = '$type' ORDER BY date DESC"); + $idrow = sqlFetchArray($idres); + + // Replace the most recent entry in any of the following cases: + // * Its effective date is >= this effective date. + // * It is the first entry and it has no (insurance) provider. + // * There is no encounter that is earlier than the new effective date but + // on or after the old effective date. + // Otherwise insert a new entry. + + $replace = false; + if ($idrow) { + if (strcmp($idrow['date'], $effective_date) > 0) { + $replace = true; + } + else { + if (!$idrow['provider'] && !sqlFetchArray($idres)) { + $replace = true; + } + else { + $ferow = sqlQuery("SELECT count(*) AS count FROM form_encounter " . + "WHERE pid = '$pid' AND date < '$effective_date 00:00:00' AND " . + "date >= '" . $idrow['date'] . " 00:00:00'"); + if ($ferow['count'] == 0) $replace = true; + } + } + } + + if ($replace) { + + // TBD: This is a bit dangerous in that a typo in entering the effective + // date can wipe out previous insurance history. So we want some data + // entry validation somewhere. + sqlStatement("DELETE FROM insurance_data WHERE " . + "pid = '$pid' AND type = '$type' AND date >= '$effective_date' AND " . + "id != " . $idrow['id']); + + $data = array(); + $data['type'] = $type; + $data['provider'] = $provider; + $data['policy_number'] = $policy_number; + $data['group_number'] = $group_number; + $data['plan_name'] = $plan_name; + $data['subscriber_lname'] = $subscriber_lname; + $data['subscriber_mname'] = $subscriber_mname; + $data['subscriber_fname'] = $subscriber_fname; + $data['subscriber_relationship'] = $subscriber_relationship; + $data['subscriber_ss'] = $subscriber_ss; + $data['subscriber_DOB'] = $subscriber_DOB; + $data['subscriber_street'] = $subscriber_street; + $data['subscriber_postal_code'] = $subscriber_postal_code; + $data['subscriber_city'] = $subscriber_city; + $data['subscriber_state'] = $subscriber_state; + $data['subscriber_country'] = $subscriber_country; + $data['subscriber_phone'] = $subscriber_phone; + $data['subscriber_employer'] = $subscriber_employer; + $data['subscriber_employer_city'] = $subscriber_employer_city; + $data['subscriber_employer_street'] = $subscriber_employer_street; + $data['subscriber_employer_postal_code'] = $subscriber_employer_postal_code; + $data['subscriber_employer_state'] = $subscriber_employer_state; + $data['subscriber_employer_country'] = $subscriber_employer_country; + $data['copay'] = $copay; + $data['subscriber_sex'] = $subscriber_sex; + $data['pid'] = $pid; + $data['date'] = $effective_date; + updateInsuranceData($idrow['id'], $data); + return $idrow['id']; + } + else { + return sqlInsert("INSERT INTO insurance_data SET + type = '$type', + provider = '$provider', + policy_number = '$policy_number', + group_number = '$group_number', + plan_name = '$plan_name', + subscriber_lname = '$subscriber_lname', + subscriber_mname = '$subscriber_mname', + subscriber_fname = '$subscriber_fname', + subscriber_relationship = '$subscriber_relationship', + subscriber_ss = '$subscriber_ss', + subscriber_DOB = '$subscriber_DOB', + subscriber_street = '$subscriber_street', + subscriber_postal_code = '$subscriber_postal_code', + subscriber_city = '$subscriber_city', + subscriber_state = '$subscriber_state', + subscriber_country = '$subscriber_country', + subscriber_phone = '$subscriber_phone', + subscriber_employer = '$subscriber_employer', + subscriber_employer_city = '$subscriber_employer_city', + subscriber_employer_street = '$subscriber_employer_street', + subscriber_employer_postal_code = '$subscriber_employer_postal_code', + subscriber_employer_state = '$subscriber_employer_state', + subscriber_employer_country = '$subscriber_employer_country', + copay = '$copay', + subscriber_sex = '$subscriber_sex', + pid = '$pid', + date = '$effective_date' + "); + } +} + +// This is used internally only. +function updateInsuranceData($id, $new) +{ + $fields = sqlListFields("insurance_data"); + $use = array(); + + while(list($key, $value) = each ($new)) { + if (in_array($key, $fields)) { + $use[$key] = $value; + } + } + + $sql = "UPDATE insurance_data SET "; + while(list($key, $value) = each($use)) + $sql .= $key . " = '$value', "; + $sql = substr($sql, 0, -2) . " WHERE id = '$id'"; + + sqlStatement($sql); +} + +function newHistoryData($pid, $new=false) { + $sql = "insert into history_data set pid = '$pid', date = NOW()"; + if ($new) { + while(list($key, $value) = each($new)) { + if (!get_magic_quotes_gpc()) $value = addslashes($value); + $sql .= ", $key = '$value'"; + } + } + return sqlInsert($sql); +} + +function updateHistoryData($pid,$new) +{ + $real = getHistoryData($pid); + while(list($key, $value) = each ($new)) + $real[$key] = $value; + $real['date'] = "'+NOW()+'"; + $real['id'] = ""; + + $sql = "insert into history_data set "; + while(list($key, $value) = each($real)) + $sql .= $key." = '$value', "; + $sql = substr($sql, 0, -2); + + + return sqlInsert($sql); +} + +function sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home, + $phone_biz,$phone_cell,$email,$pid="") +{ + $db = $GLOBALS['adodb']['db']; + $customer_info = array(); + + $sql = "SELECT foreign_id,foreign_table FROM integration_mapping where local_table = 'patient_data' and local_id = '" . $id . "'"; + $result = $db->Execute($sql); + if ($result && !$result->EOF) { + $customer_info['foreign_update'] = true; + $customer_info['foreign_id'] = $result->fields['foreign_id']; + $customer_info['foreign_table'] = $result->fields['foreign_table']; + } + + ///xml rpc code to connect to accounting package and add user to it + $customer_info['firstname'] = $fname; + $customer_info['lastname'] = $lname; + $customer_info['address'] = $street; + $customer_info['suburb'] = $city; + $customer_info['state'] = $state; + $customer_info['postcode'] = $postal_code; + + //ezybiz wants state as a code rather than abbreviation + $customer_info['geo_zone_id'] = ""; + $sql = "SELECT zone_id from geo_zone_reference where zone_code = '" . strtoupper($state) . "'"; + $db = $GLOBALS['adodb']['db']; + $result = $db->Execute($sql); + if ($result && !$result->EOF) { + $customer_info['geo_zone_id'] = $result->fields['zone_id']; + } + + //ezybiz wants country as a code rather than abbreviation + $customer_info['geo_country_id'] = ""; + $sql = "SELECT countries_id from geo_country_reference where countries_iso_code_2 = '" . strtoupper($country_code) . "'"; + $db = $GLOBALS['adodb']['db']; + $result = $db->Execute($sql); + if ($result && !$result->EOF) { + $customer_info['geo_country_id'] = $result->fields['countries_id']; + } + + $customer_info['phone1'] = $phone_home; + $customer_info['phone1comment'] = "Home Phone"; + $customer_info['phone2'] = $phone_biz; + $customer_info['phone2comment'] = "Business Phone"; + $customer_info['phone3'] = $phone_cell; + $customer_info['phone3comment'] = "Cell Phone"; + $customer_info['email'] = $email; + $customer_info['customernumber'] = $pid; + + $function['ezybiz.add_customer'] = array(new xmlrpcval($customer_info,"struct")); + $ws = new WSWrapper($function); + + // if the remote patient was added make an entry in the local mapping table to that updates can be made correctly + if (is_numeric($ws->value)) { + $sql = "REPLACE INTO integration_mapping set id = '" . $db->GenID("sequences") . "', foreign_id ='" . $ws->value . "', foreign_table ='customer', local_id = '" . $id . "', local_table = 'patient_data' "; + $db->Execute($sql) or die ("error: " . $db->ErrorMsg()); + } +} + +// Returns Date of Birth given YYYYMMDD from MySQL DATE_FORMAT(DOB,'%Y%m%d') +function getPatientAge($dobYMD) +{ + $tdyYMD=date("Ymd"); + $yearDiff = substr($tdyYMD,0,4) - substr($dobYMD,0,4); + $ageInMonths = ((substr($tdyYMD,0,4)*12)+substr($tdyYMD,4,2)) - + ((substr($dobYMD,0,4)*12)+substr($dobYMD,4,2)); + $dayDiff = substr($tdyYMD,6,2) - substr($dobYMD,6,2); + if ( $dayDiff < 0 ) { + $ageInMonths -= 1; + } + if ( $ageInMonths > 24 ) { + $age = intval($ageInMonths/12); + } + else { + $age = "$ageInMonths month"; + } + return $age; +} + +function dateToDB ($date) +{ + $date=substr ($date,6,4)."-".substr ($date,3,2)."-".substr($date, 0,2); + return $date; +} + +function DBToDate ($date) +{ + $date=substr ($date,5,2)."/".substr ($date,8,2)."/".substr($date, 0,4); + return $date; +} +?> diff --git a/sql/2_8_3-to-2_8_4_upgrade.sql b/sql/2_8_3-to-2_8_4_upgrade.sql index 7d2040103..6cb834854 100644 --- a/sql/2_8_3-to-2_8_4_upgrade.sql +++ b/sql/2_8_3-to-2_8_4_upgrade.sql @@ -223,3 +223,6 @@ INSERT INTO fee_sheet_options VALUES ('2Established Patient','2Limited','CPT4|99 INSERT INTO fee_sheet_options VALUES ('2Established Patient','3Detailed','CPT4|99213|'); INSERT INTO fee_sheet_options VALUES ('2Established Patient','4Extended','CPT4|99214|'); INSERT INTO fee_sheet_options VALUES ('2Established Patient','5Comprehensive','CPT4|99215|'); + +ALTER TABLE `users` + ADD COLUMN `cal_ui` tinyint(4) NOT NULL DEFAULT 1 COMMENT 'Specifies calendar display style'; diff --git a/sql/database.sql b/sql/database.sql index 4ae03537e..440ccfd01 100644 --- a/sql/database.sql +++ b/sql/database.sql @@ -1279,6 +1279,7 @@ CREATE TABLE `users` ( `phonew2` varchar(30) NOT NULL DEFAULT '', `phonecell` varchar(30) NOT NULL DEFAULT '', `notes` text NOT NULL DEFAULT '', + `cal_ui` tinyint(4) NOT NULL DEFAULT 1, PRIMARY KEY (`id`) ) ; -- 2.11.4.GIT