Yes, I think that this is definalty a good idea to add to the next release version. It is actually on my (unpublished) roadmap just wasn't planning on doing it yet. This being a free script relying on donations which I supposedly develop in my free can't get as much attention as I would like

Anyway, let's see if I can explain this....
Add this somewhere near the beginning of the file to catch the requested data or define defaults before we start drawing the calendar:
- Code: Select all
if((isset($_REQUEST["year_month"])) && (!empty($_REQUEST["year_month"])) ){
$date_bits=explode("-",$_REQUEST["year_month"]); # 0=year, 1=month
define("START_YEAR", $date_bits[0]);
define("START_MONTH", $date_bits[1]);
}else{
define("START_YEAR", date('Y'));
define("START_MONTH", date('m'));
}
Next, find the bit of code that we modified yesterday that looped through the months to show (starting from "$the_months=array();" and ending BEFORE "// loop through months to draw calendar") and replace with this:
- Code: Select all
$the_months = array();
$j = 0;
$this_year = START_YEAR;
$this_month = START_MONTH;
while($num_months_shown<MONTHS_TO_SHOW){
// star new year and reset month numbers
if($this_month>12){
$this_month = $this_month-12; # remove full 12 months from cal num
$this_year = $this_year+1; # add 1 to current year
}
//echo "<br>".$this_month." - ".$this_year;
$this_month=sprintf("%02s",$this_month); # add 0 if less that 10
$the_months[$this_month]=array("year"=>$this_year,"month"=>$this_month);
++$num_months_shown;
++$this_month;
}
Finally the code for the form (select, radio, hrefs or whatever - my version is with select lists)
This was actually the toughest bit of code to get right as this is where we define the starting month AND year, being careful to catch the year changes.
This may not be the best or simplest way to send tell the calendar what to show, but it works and was able to take into account the months that we are showing (even though you want static 3 month blocks) and also the possibility to actually display the month names in the next and previous blocks (though I have disactivated that for your purpose). Well, here goes....
Just before your "form" for changing the blocks and AFTER the calendar has been defined add this:
- Code: Select all
// define select list month options and texts
// define LAST block - START
$last_month_start = (START_MONTH-MONTHS_TO_SHOW); # remove months_to_show x 2 to go back this block and then 1 more
$last_year_start = START_YEAR;
if($last_month_start<0){
$last_month_start=$last_month_start+12;
--$last_year_start;
}
// define LAST block - END
$last_month_end = $last_month_start+MONTHS_TO_SHOW;
$last_year_end = $last_year_start;
if($last_month_end>11){
$last_month_end=$last_month_end-12;
++$last_year_end;
}
// define months for text
//$last_block_txt = $lang["months"][$last_month_start-1]." ".$last_year_start." to ".$lang["months"][$last_month_end-2]." ".$last_year_end;
$last_block_txt ="Last 3 months";
// define NEXT block - START
$next_month_start = $this_month; # just use MONTH number that the loop has ended on
$next_year_start = $this_year; # just use YEAR number that the loop has ended on
if($next_month_start>11){
$next_month_start=$next_month_start-12;
++$next_year_start;
}
// define NEXT block - END
$next_month_end = $next_month_start+MONTHS_TO_SHOW;
$next_year_end = $next_year_start;
if($next_month_end>11){
$next_month_end=$next_month_end-12;
++$next_year_end;
}
// define months for text
//$next_block_txt = $lang["months"][$next_month_start-1]." ".$next_year_start." to ".$lang["months"][$next_month_end-1]." ".$next_year_end;
$next_block_txt= "Next 3 months";
Finally you will need to add the elements to the actual form which, as I said, is a select list in my case:
- Code: Select all
<select name="year_month" onchange="this.form.submit()">
<option value=""> - select months to show - </option>
<option value=""> Current '.MONTHS_TO_SHOW.' months </option>
<option value="'.$last_year_start.'-'.$last_month_start.'">'.$last_block_txt.'</option>
<option value="'.$next_year_start.'-'.$next_month_start.'" >'.$next_block_txt.'</option>
</select>
And that is it

I hope you are able to follow these instructions and also that I haven't missed any code out, I did this several hours ago and my mind has since moved on (if not my body)
Let me know how it goes

Chris