Message Showing event not working as expected

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.

Message Showing event not working as expected

Postby bobmulder5555 » Thu Jan 04, 2018 8:24 pm

Hi all,

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.

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!
Posts: 27
Joined: Tue Oct 13, 2015 4:51 pm

Re: Message Showing event not working as expected

Postby arbei » Fri Jan 05, 2018 12:03 pm

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.
Posts: 1495
Joined: Wed Sep 09, 2015 10:13 am

Re: Message Showing event not working as expected

Postby bobmulder5555 » Fri Jan 12, 2018 1:08 am

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.

Posts: 27
Joined: Tue Oct 13, 2015 4:51 pm

Re: Message Showing event not working as expected

Postby bobmulder5555 » Fri Jan 12, 2018 1:31 am

I found a work around in viewtopic.php?f=4&t=31910&p=117172&hilit=message_showing#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.
Posts: 27
Joined: Tue Oct 13, 2015 4:51 pm

Return to General Discussion (PHPMaker)