Message Showing event

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
bobmulder5555
User
Posts: 60

Message Showing event

Post by bobmulder5555 »

Hi all,

Preamble:
I'm working on a project that displays a years worth of Doctor (General Practioners) (after planning with OptaPlanner) shifts. In NL a GP has his/her own practice during weekdays, and after hours (evening, nights, weekends and holidays) instead of being on duty 24/7 for their individual patients they now do shifts at on of the several doctors posts in a region that patients can use. Doctors posts have been migrating into hospitals during the last decade and now doctor's posts and the 'classic' ER are being integrated.
Once we have the yearly planning for the shifts (around 4100 for 100 doctors), doctors are free to swap shifts with other doctors, and they use it a lot. Our roster, which is in use since January 2, 2018 already has 850+ changes. All changes are managed through a central bureau, as GP's need certain certificates for certain shifts, so you can't swap shifts with just any other GP. That is checked by this bureau.

Question:
To undo a shift change I have created a dedicated view in which the user can select (using Modal) a Date, a shift, and more. Typically you'll select a date, which then lists all shifts on that day that have been changed. With a trash can for that change. As a shift can change doctors more than once, the listing is sorted per shift and per change. Users are only allowed to delete the last change made.
I keep track of the changes in two ways:
(1) in a change-record listing the shift, the previous doctor, the new doctor and the original doctor (The original doctor gets the financial compensation for that shift and clears it with the doctor that actually does the shift.). Also stuff like date/time of change and who has entered it into the system. AND the change number.
(2) the shift-item itself: the number of changes (just making it easy on myself, I could also count the number of linked change-records)

When undoing the last change I use the row_deleting event of the created view and first thing I do is test if it's the last change:

function Row_Deleting(&$rs) {
GLOBAL $sysbericht; //for any error messages

//Test if it's the last change
//get Roster-Item
$RI_key = $rs["DR_RI_ID"];
$RI_REC = ew_ExecuteRow("SELECT * FROM tbl3_ri_roosteritem WHERE RI_ID = " . $RI_key); //the Roster-Item in question

$aantal_muts = $RI_REC["RI_Aantal_Muts"]; //total number of changes to the RI
$wijz_nr = $rs["DR_AantalWijzigingen"]; //this is the change-number of the record to be deleted

if ($wijz_nr <> $aantal_muts) { //if the change-number == total number of changes, you have the last change-record
$sysbericht = "Only the LAST change may be revoked";
Return FALSE;
}
....
}

In 'Delete Page', Message_Showing event I have the following:
function Message_Showing(&$msg, $type) {

GLOBAL $sysbericht;

if ($type == 'success') {
	//$msg = "your success message";
} elseif ($type == 'failure') {
$msg = $sysbericht.", processing is cancelled";
} elseif ($type == 'warning') {
	//$msg = "your warning message";
} else {
	//$msg = "your message";
}

}

The following happens:

When I click the trashcan in the list view, it displays the delete-page for that record AND an 'empty' pop-up with ", processing cancelled" which I have to click away with OK.
I then get a clear Delete page. The user then confirms the deletion.
If it's NOT the last change then I get the expected pop-up again, but now stating correctly "Only the LAST change may be revoked, processing is cancelled"
If it IS the last change I get the expected pop-up with "Deletion successful"

But I always get that first empty pop-up with ", processing cancelled".

If I comment out my tailor-made failure message in message_showing, I DON'T get the first empty pop-up. After confirmation, If it's not the last change I get a correct pop-up with "deletion cancelled", - of course without my tailor-made message.
And if it's the last record I get the "deletion successful" pop-up.

So the process and the code seems to work, except for that first empty pop-up when I'm using custom messages.

What am I doing wrong here?

Thanks for any feedback!


arbei
User
Posts: 9284

Post by arbei »

The message cannot pass to the function "Message_Showing" with the global variable $sysbericht, because the process is as below.

Row_Deleting -> Page_Terminate -> Delete page reloaded -> Message_Showing.

Since the delete page is reloaded, so the variable $sysbericht is empty and create your problem.

Try to use the session variable to save your error message then try again.


bobmulder5555
User
Posts: 60

Post by bobmulder5555 »

Hi, could you give a little more detail on how to do this? Even if I set $msg (the session variable) elsewhere, as soon as I uncomment the $msg lines in Message_Showing they appear twice; once after clicking the garbage can in Listview and once in the delete confirmation page.

I even uncommented each line in Message_Showing to see what happened and then ALL messages are shown in both pop-ups.

As soon as I comment out the $msg lines in Message_showing, it starts working as expected. But only with the terse std messages which don't give much insight to the user what went wrong.

It would also be okay to generate my own pop-up, but for now I don't have a clue how to make Message_showing this work.

Thx


bobmulder5555
User
Posts: 60

Post by bobmulder5555 »

I found a work around in http://www.hkvforums.com/viewtopic.php? ... ng#p117172

code is changed to:
if ($wijz_nr <> $aantal_muts) {
$this->setFailureMessage("Your Failure Message");
Return FALSE;

Message_Showing is 'empty', meaning all $msg lines remain commented out. But this at least works for me.


Wizard69
User
Posts: 16

Post by Wizard69 »

The great help desk give to me the solution ... that work perfectly

First af all check if ($msg <> "") and then check type.
And all goes ok.

Example

function Message_Showing(&$msg, $type) {
if ($msg <> "") {
if ($type == 'success') {
//$msg = "your success message";
} elseif ($type == 'failure') {
$msg = "Non è possibile cancellare il CLIENTE perchè probabilmente sono presenti degli Appuntamenti o un Piano Cure oppure un Saldo.";
} elseif ($type == 'warning') {
//$msg = "your warning message";
} else {
//$msg = "your message";
}
}
}


bobmulder5555
User
Posts: 60

Post by bobmulder5555 »

@Wizard69 wrote:
The great help desk give to me the solution ... that work perfectly

Little late, but thank you. I'm needing this function again, but now in a not-failure situation. So it would be nice to use the message modules


bobmulder5555
User
Posts: 60

Post by bobmulder5555 »

Yeah, I now understand how the process works. Thanks. So, just for others what I did:
When making changes to a roster, I have to check for double shift bookings on the same day. But I also wanted to make it possible to do a double booking, if you really wanted to. Shifts don't always overlap.

It's a list view with inline grid-edit, so it gets handled by Table-Specific/Common/Row_Updating
$check_double ="";
$check_double = ew_ExecuteRows("SELECT * FROM tbl3_ri_rosteritem WHERE RI_FullDateYYYYMMDD= '" . $checkdate ."' AND RI_ZVL_ID = " . $doctor_new . " AND RI_ROS_ID = ".$_SESSION["cur_ros"]); //I fetch all the rows that have the submitted person in the same roster on the same date.

if (!empty($check_double)) { //a booking is already here. empty() is a nifty test that returns true on NULL, 0, "", array() etc
if ($SESSION["force_double_dayshift"]==0) { //first time this double booking has been submitted
$
SESSION["force_double_dayshift"]=1; //set the flag for next time if you want to force
$this->CancelMessage = "This Doctor already has a shift today. The change is being cancelled. <br/><b><big>You can force a double booking by immediately submitting this change again.</big></b>";
return FALSE;
} else { //prepare message, but do the double booking
$SESSION[force_double_dayshift"]=0; //reset flag
$
SESSION["FDD_message_flag"]=1; //set message flag for the message-module
$_SESSION["FDD_message"]=" <br/><b><big>ATTN: You have chosen to force more than one daily shift for this doctor.</big></b>";
}
}

And then in Table-Specific/List Page/Message Showing

// Message Showing event
// $type = ''|'success'|'failure'|'warning'
function Message_Showing(&$msg, $type) {

//this is the one for a warning for double dr day
if ($msg <> "") { //this is a key test (but alas not part of the help file) as pointed out by Wizard69, otherwise you'll always see your custom messages appearing.
if ($type == 'success') {
if ($SESSION["FDD_message_flag"]==1) {
$
SESSION["FDD_message_flag"]=0; //clear flag for next time
$msg = $msg.$SESSION["FDD_message"]; //ADD your message to the std system message
$
SESSION["FDD_message"]=""; //clear message
}

} elseif ($type == 'failure') {
	//$msg = "your failure message";
} elseif ($type == 'warning') {
	//$msg = "your warning message";
} else {
	//$msg = "your message";
}
}

}

That's it, works like a charm.


Post Reply