Calendar restraints

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Calendar restraints

Post by bimo »

hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm having a problem with something for far too long and I'm hoping that someone will see what I'm doing wrong.

I have a calendar that pulls events from an RSS feed and it works pretty well.  The problem is that  I don't want the user to be able to see months more than a year in the future or any months in the past and I'm having trouble adding just the right number of constraints.
Here's the logic I want it to use

Code: Select all

// if date doesn't exceed one year from now, don't display forward link
// if this month isn't january and displayed month isn't december 
// or if they are looking at next year but not more than 12 months away
show link to next month
// otherwise don't show next link

//if date = now, don't display backwards link
// if future months are being displayed 
// and if month is less than current month while year is greater
show link to next month
// otherwise don't show previous link
that seems to me like it should work but it's not so I thought maybe there's something else that I'm not getting. Here's the code:

Code: Select all

// make sure date doesn't exceed one year from now	
	$cur_mon = intval(date(m));
	$cur_year = intval(date(Y));
	print($cur_year);
	print("<br/>");
	print($cur_mon . " " . $month_num);//month_num gets passed in the query string and is how it knows which month to display.
	print("<br/>");
	
	print(date(Y)+1 . " " . $year);
	
	// if date doesn't exceed one year from now, don't display forward link
		// if this month isn't january and displayed month isn't december 
	if((date('mon') == 1 && $month_num == 12) || 
		// or if they are looking at next year but not more than 12 months away
	   ($year == $cur_year + 1 && $month_num >= $cur_mon))
	{
	   $next = "<a href=\"index.html?month_num=$month_num&year_now=$year&dir=f\">Next Month</a>";
	}
	// otherwise don't show next link
	else
	{
		$next = "";
		print("can't go for");
		
	}
	
	//if date = now, don't display backwards link
		// if future months are being displayed 
	if(($month_num > date('mon') && $year >= date('year')) &&
		// and if month is less than current month but year is greater
		($month_num < date('mon') && $year == $year+1))
		{
		$prev = "<a href=\"index.html?month_num=$month_num&year_now=$year&dir=b\">Previous Month</a>";
		}
		// otherwise don't show previous link
	else
	{
		$prev="";
	}
	// print calendar month
	print "
	<table width=\"350\">
	<tr><td style=\"padding-left: 125px; color:#003366; text-decoration: none; font-size: 1em; font-weight: normal;\"><a href=\"index.html\">Back to $this_month, $this_year</a></td></tr>
	<tr><td><a href=\"index.html?month_num=$month_num&year_now=$year&dir=b\">Previous Month</a></td>
		<td align=right><a href=\"index.html?month_num=$month_num&year_now=$year&dir=f\">Next Month</a></td>
	</tr>
	</table>".
I would really appreciate any advice that anyone could offer. I've been spinning my wheels for far too long....

here's a link to the calendar: http://bfa.cctsbaltimore.org/bfa_dev/ca ... index.html

hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

nevermind... sorry.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Calendar restraints

Post by RobertGonzalez »

bimo wrote: Here's the logic I want it to use

Code: Select all

// if date doesn't exceed one year from now, don't display forward link
// if this month isn't january and displayed month isn't december 
// or if they are looking at next year but not more than 12 months away
show link to next month
// otherwise don't show next link

//if date = now, don't display backwards link
// if future months are being displayed 
// and if month is less than current month while year is greater
show link to next month
// otherwise don't show previous link
You kinda answered this one yourself. Now it is just a matter of capturing the selected date and comparing within the scope of your constraints listed above.
Post Reply