Hi, I'm displaying a monthly shift roster for doctors. Choosing the correct month to display is passed from a webpage or menu choice with a parameter:
//localhost/sszkXNf2/vw27_jaar_maand_dagregelslist.php?us_month=1 (to 12). This works fine.
To let the doctors browse easily to the next or previous month I've added two buttons that pass these parameters:
//localhost/sszkXNf2/vw27_jaar_maand_dagregelslist.php?us_month=91 (or 92).
To display the correct month I add a filter in Recordset_Selecting (all echo statements are for testing purposes).
This code calls a Global Code function to determine the correct month if 91 or 92 are passed as parameter."Of course I also need to do a wrap-around if the user is in January and clicks previous or December and clicks next.
The code uses $_SESSION["curmonth"] to determine the current month that is displayed and it is initialized to 1 in Login Page/User_LoggedIn
RECORDSET CODE
// Recordset Selecting event
function Recordset_Selecting(&$filter) {
// Enter your code here
echo "vw27 RSelect START: DQ session_curmonth= " . $SESSION["curmonth"] . "<br>";
//echo "vw27 RSelect START: SQ session_curmonth= " . $SESSION['curmonth'] . "<br>";
//echo "vw27 RSelect START: SQ us_month= " . $_GET['us_month'] . "<br>";
if(isset($GET['us_month']) && trim($GET['us_month'])!='') {
$newmonth = $GET['us_month'];
echo "vw27 RSelect User Selected Month DQ us_month/newmonth= " . $GET["us_month"] ."/". $newmonth ."<br>";
if ($newmonth >90) { //Next or Previous click
echo "Calling FCT det_next_page with newmonth = " . $newmonth . "<br>";
$MyResult = det_next_page($newmonth); //User clicked Next or Previous button; calc new month and do Jan/Dec-wrap-around if needed
$newmonth = $MyResult;
echo "BACK from FCT det_next_page: newmonth = " . $newmonth . "<br>";
}
//Now $newmonth is EITHER adjusted, OR it already was a valid month
echo "Setting maandvolgnr_id filter to newmonth = " . $newmonth . "<br>";
ew_AddFilter($filter, "pmh_maandvolgnr_id
= $newmonth");
$SESSION["curmonth"] = $newmonth; //Save current month value for next time
echo "Setting Session_curmonth/newmonth to " . $SESSION["curmonth"] . "/" . $newmonth . "<br>";
}
echo "LEAVING vw27 RSelect: DQ session_curmonth= " . $_SESSION["curmonth"] . "<br>";
}
NEXT PAGE FUNCTION in GLOBAL CODE.
function det_next_page (&$newmonth) {
//determine if user is going to previous or next month in vw27_listpage
// set wraparound in month 12 and month 1
//Planning period will be from 1-1 to 31-12 or with 1 or 2 weeks in the new year
//We will display these extra January Days in December so people will see the whole holidays
$cur_mth = $_SESSION["curmonth"];
echo "START det_next_page: newmonth = " . $newmonth . "<br>";
echo "cur_mth uit session_curmonth = " . $cur_mth . "<br>";
if ($newmonth==92) { //user wants to go to next month
echo "newmonth tested 92: ";
$cur_mth = $cur_mth+1;
echo "new cur_mth_adding_1 set to = " . $cur_mth . "<br>";
if ($cur_mth > 12) { // wrap around to January if in Dec
$cur_mth = 1;
echo "new cur_mth_wrap_around_to_1 set to = " . $cur_mth . "<br>";
echo "Tested Newmonth92 = Forward cur_mth is set to = " . $cur_mth . "<br>";
}
}
if ($newmonth==91) { //user wants to go to prev month
echo "newmonth tested 91: ";
$cur_mth = $cur_mth - 1;
echo "new cur_mth_subtracting_1 set to = " . $cur_mth . "<br>";
if ($cur_mth < 1) {// wrap around to December if in January
$cur_mth = 12;
echo "new cur_mth_wrap_around_to_12 set to = " . $cur_mth . "<br>";
echo "Tested Newmonth91 = Back cur_mth is set to = " . $cur_mth . "<br>";
}
}
echo "RETURN FROM det_next_page with cur_mth set to = " . $cur_mth . "<br>";
return $cur_mth;
}
What happens is that when then monthpage (a listpage) is rendered I can see (because of all the echo statements) that before the menubar (horizontal) is built I already see it going through Recordset_Selecting. Then it builds the horizontal menubar, breadcrumbs and export options.
Then I see it passing through Record_set selecting again, and then the listpage is displayed. With a valid month as parameter this doesn't matter, because I don't recalculate anything. But with 'Next' or 'Previous', like in January, I correctly calculate December as the new month the fist time. But then it goes through Recordset_selecting again with 91 as parameter (Back button), so it subtracts another month to november and thus displays November in stead of December.
FIRST Recordset_selecting Loop
vw27 RSelect START: DQ session_curmonth= 1
vw27 RSelect User Selected Month DQ us_month/newmonth= 91/91
Calling det_next_page met newmonth = 91
START det_next_page: newmonth = 91
cur_mth uit session_curmonth = 1
newmonth tested 91: new cur_mth_subtracting_1 set to = 0
new cur_mth_wrap_around_to_12 set to = 12
Tested Newmonth91 = Back cur_mth is set to = 12
RETURN FROM det_next_page with cur_mth set to = 12
Terug uit det_next_page: newmonth = 12
Setting maandvolgnr_id filter to newmonth = 12
Setting Session_curmonth/newmonth to 12/12
LEAVING vw27 RSelect: DQ session_curmonth= 12
MENUBAR ETC
SECOND Recordset_selecting Loop
vw27 RSelect START: DQ session_curmonth= 12
vw27 RSelect User Selected Month DQ us_month/newmonth= 91/91
Calling det_next_page met newmonth = 91
START det_next_page: newmonth = 91
cur_mth uit session_curmonth = 12
newmonth tested 91: new cur_mth_subtracting_1 set to = 11
RETURN FROM det_next_page with cur_mth set to = 11
Terug uit det_next_page: newmonth = 11
Setting maandvolgnr_id filter to newmonth = 11
Setting Session_curmonth/newmonth to 11/11
LEAVING vw27 RSelect: DQ session_curmonth= 11
ROSTERLISTING OF NOVEMBER
So, what am I doing wrong here? Of course I can build in a test to see if it's the first or second time it goes through Recordset_selecting, but I'd like to know why it passes twice and/or what I'm doing wrong and/or if I'm just having some kind of brain-fart.
Thanks!