Unique Calendar Problem TOTALLY BAFFLED

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
boblangdon
Forum Newbie
Posts: 1
Joined: Tue Apr 30, 2002 9:26 pm
Location: NY

Unique Calendar Problem TOTALLY BAFFLED

Post by boblangdon »

Unique Calendar Problem TOTALLY BAFFLED

I have a unique project I'm working opn and I'm totally baffled!

It's two calendars, side by side and in reverse order (May/April). First
you enter your Zip Code (have DB set up ewth UPS codes, zones, and
shipping dates), then you click on the date you'd like to have your
borchures delivered by.

A red sphere will appear on the delivery date, preceded two or more days
(depending upon the DB results) with a yellow sphere designatng the
shipping date. 5 days before that, a purple sphere, represnting the date
the press is run. Two days before this, a green sphere represnenting
when you'll receive (and hopefully approve same day) your proof. Back up
two more days and a blue sphere represents the latest date you must
upload your files to the printer.

PROBLEM: ANy sphere falling on a weekend miust be backed up to the
prvious Friday.

Sounds simple, but it's proving otherwise. Maybe I need to start all
over and re-evaluate my approach.

First problem, because of the way I've designed the script, is getting
balls to fall into the previous month if necessary, but I won't worry
about that now.

The BIG problem is getting Saturdays and Sundays ($wday ==0 && $wday
==6) to back up.

Here's a simplifed excerpt of what I've tried so far.

BTW: you can see the work in progress at
http://www.dss-sites.com/BrochurePlace/

#################################################
//$day is ther numerical day of the mopnth and $wday is the
//numerical number of the day of week (Sun-Sat/ 0-6)

if (isset($delivery)){
$shipping = $delivery -2;
$print = $shipping -2;
$proof = $print -5;
$submit = $proof -2;

// bad code:
if(($day == $delivery) && ($wday == 0)){
$delivery = $delivery-2;
}elseif(($day == $delivery) && ($wday == 6)){
$delivery = $delivery-1;
}
// if this worked I'dd add if for each variable

if($day == $delivery){
print "<td><a href=$PHP_SELF?delivery=$day>$day<BR>$red_ball</a></td>;}
elseif($day == $shipping){
print "<td><a href=$PHP_SELF?delivery=$day>n$day<BR>$yellow_ball</a></td>;}
elseif($day == $print){
print "<td><a href=$PHP_SELF?delivery=$day>$day<BR>$green_ball</a></td>";}
elseif($day == $proof){
print "<td><a href=$PHP_SELF?delivery=$day>$day<BR>$purple_ball</a></td>";}
elseif($day == $submit){
print "<td><a href=$PHP_SELF?delivery=$day>$day<BR>$blue_ball</a></td>";
}}
#################################################

Please don't respond by tewlling me what a bonehead I am. I know that.

Obviously this won't work, because it's cycling through each day, it doesn't
know what to do when it comes to a weekend day, so it does nothing, but it will
place the other spheres.

I'm afraid I'll either need to rethink my whole way of omplementing the script
or write complex class.

I'm a fairly cmopetent PHP pscripte, and I've looked at a dozen other calendar
scripts for inspiration, but nothing that covers anyting like this.

Any ideas would be greatly appreciated.

To give you an idea how the script draws the calendar:
#####################################################
$date=getdate();
$month_num=$date["mon"];
$month_name=$date["month"];
$This_Month=$date["month"];
$year=$date["year"];
$date_today=getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day=$date_today["wday"];
$cont=true;
$today=27;
while(($today<=32)&&($cont)){
$date_today=getdate(mktime(0,0,0,$month_num,$today,$year));
if($date_today["mon"]!=$month_num){
$lastday=$today-1;
$cont=false;
}
$today++;
}

// Here I've omitted calendar 1's header (Month name) and second row with weekday names

$day=1;
$wday=$first_week_day;
$firstweek=true;
while($day<=$lastday){
if($firstweek){
print "<TR>";
if($wday < 6 && $day <= 0){
$colspan = (6-$wday);
print "<TD COLSPAN="$colspan" width="20" background="images/BlockRContent.gif" align="center" Valign="middle">
<IMG SRC="images/BlockRContent.gif"></td>
";
}
else{
print "<TD width="20" background="images/BlockRContent.gif" align="center" Valign="middle">
<IMG SRC="images/BlockRContent.gif"></td>
";
}
$firstweek=false;
}
if($wday==0){
print "<tr>
";
}

/////// Omitted problem code shown in beginning

if($wday < 6 && $day >= $lastday){
$colspan = (7-$wday);
print "<TD COLSPAN="$colspan" background="images/BlockRContent.gif" align="center" Valign="middle">
<IMG SRC="images/BlockRContent.gif"></TD>
</tr>
";
}
elseif($wday == 6){
print "</tr>
";
}
$wday++;
$wday=$wday%7;
$day++;
}

//// Now start calendar two (April)

$first_week_day=$date_today["wday"];
$date_today=getdate(mktime(0,0,0,$month_num,$today,$year));
if($date_today["mon"]!=$month_num){
$lastday=$today-1;
$cont=false;
$today++;
}

:(
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post by samscripts »

Hi, i've just put together a calendar class and thought i'd try out your problem as a way of testing it.

If this looks like the kind of thing you want, let me know and i'll mail you the code.

It differs from your approach in using dates in yyyy-mm-dd format rather than storing the day and the month separately which makes it easier.

It also subtracts weekdays from each date (doesn't count days on weekends) which may or may not be what you want, but can be easily changed.

Anyway, hope it helps, it was interesting trying to put it together and i've improved my class as a result.

Cheers, Sam
Post Reply