Skip to content

Commit

Permalink
Fixes openemr#7633 appointment error for first appt (openemr#7634)
Browse files Browse the repository at this point in the history
* Fixes openemr#7633 appointment error for first appt

Error in first patient appointment due to php casting errors.

Fixes openemr#7633

* Make $eid condition checks explicit for safety

I believe php type casting will handle all of the if($eid) statements
everywhere but in order to make this explicit I changed the type
checking to strict typing everywhere the variable was used to prevent
subtle errors in the future.
  • Loading branch information
adunsulag authored Aug 7, 2024
1 parent cd42546 commit 817448c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions portal/add_edit_event_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

// Things that might be passed by our opener.
//
$eid = $_GET['eid'] ?? null; // only for existing events
$eid = intval($_GET['eid'] ?? 0); // only for existing events
$date = $_GET['date'] ?? null; // this and below only for new events
$userid = $_GET['userid'] ?? null;
$default_catid = ($_GET['catid'] ?? null) ? $_GET['catid'] : '5';
Expand All @@ -59,7 +59,7 @@
$patient_appointments = fetchAppointments('1970-01-01', '2382-12-31', $pid);
$checkEidInAppt = array_search($eid, array_column($patient_appointments, 'pc_eid'));

if (!empty($eid) && !$checkEidInAppt) {
if ($eid !== 0 && $checkEidInAppt === false) {
echo js_escape("error");
exit();
}
Expand Down Expand Up @@ -113,7 +113,7 @@
// 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) {
if ($eid !== 0) {
$selfacil = '';
$facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
FROM openemr_postcalendar_events
Expand Down Expand Up @@ -287,7 +287,7 @@
/* =======================================================
// UPDATE EVENTS
========================================================*/
if ($eid) {
if ($eid !== 0) {
// what is multiple key around this $eid?
$row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));

Expand Down Expand Up @@ -547,7 +547,7 @@
$row = array();

// If we are editing an existing event, then get its data.
if ($eid) {
if ($eid !== 0) {
$row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
$date = $row['pc_eventDate'];
$userid = $row['pc_aid'];
Expand Down Expand Up @@ -618,7 +618,7 @@
$catoptions = "";
$prefcat_options = " <option value='0'>-- " . xlt("None{{Category}}") . " --</option>\n";
$thisduration = 0;
if ($eid) {
if ($eid !== 0) {
$thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
}
while ($crow = sqlFetchArray($cres)) {
Expand All @@ -630,7 +630,7 @@
// This section is to build the list of preferred categories:
if ($duration) {
$prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
if ($eid) {
if ($eid !== 0) {
if ($crow['pc_catid'] == $row['pc_prefcatid']) {
$prefcat_options .= " selected";
}
Expand All @@ -646,7 +646,7 @@
echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . ";\n";
// echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
$catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
if ($eid) {
if ($eid !== 0) {
if ($crow['pc_catid'] == $row['pc_catid']) {
$catoptions .= " selected";
}
Expand Down Expand Up @@ -686,15 +686,15 @@
</div>
<div class="input-group col-12 col-md-6">
<label class="mr-2" for="form_date"><?php echo xlt('Date'); ?>:</label>
<input class="form-control mb-1" type='text' name='form_date' readonly id='form_date' value='<?php echo (isset($eid) && $eid) ? attr($row['pc_eventDate']) : attr($date); ?>' />
<input class="form-control mb-1" type='text' name='form_date' readonly id='form_date' value='<?php echo (isset($eid) && $eid !== 0) ? attr($row['pc_eventDate']) : attr($date); ?>' />
</div>
</div>
<div class="row">
<div class="form-group form-inline col-12">
<div class="input-group mb-1">
<label class="mr-2"><?php echo xlt('Time'); ?>:</label>
<input class="form-control col-2 col-md-3" type='text' name='form_hour' size='2' value='<?php echo (isset($eid)) ? $starttimeh : ''; ?>' title='<?php echo xla('Event start time'); ?>' readonly />
<input class="form-control col-2 col-md-3" type='text' name='form_minute' size='2' value='<?php echo (isset($eid)) ? $starttimem : ''; ?>' title='<?php echo xla('Event start time'); ?>' readonly />
<input class="form-control col-2 col-md-3" type='text' name='form_hour' size='2' value='<?php echo ((isset($eid) && $eid !== 0)) ? $starttimeh : ''; ?>' title='<?php echo xla('Event start time'); ?>' readonly />
<input class="form-control col-2 col-md-3" type='text' name='form_minute' size='2' value='<?php echo ((isset($eid) && $eid !== 0)) ? $starttimem : ''; ?>' title='<?php echo xla('Event start time'); ?>' readonly />
<select class="form-control col-3 col-md-4" name='form_ampm' title='Note: 12:00 noon is PM, not AM' readonly>
<option value='1'><?php echo xlt('AM'); ?></option>
<option value='2'<?php echo ($startampm == '2') ? " selected" : ""; ?>><?php echo xlt('PM'); ?></option>
Expand Down Expand Up @@ -874,7 +874,7 @@ function validate() {
return false;
}

<?php if ($eid) { ?>
<?php if ($eid !== 0) { ?>
set_display();
<?php } ?>
$(function () {
Expand Down

0 comments on commit 817448c

Please sign in to comment.