mSQL Calendar
This is the original version
of the VBScript/ASP translation of the calendar
This is the w3-msql "Lite" code for a cgi calendar.
I am keeping on the site for nostalgia's sake.
Note that the page keeps resubmitting to itself
with different values, depending on the month that is to be displayed. The same
procedure could be used for any validation, until the user gets the input right, at which
point the action of the form could be submitted to the mSQL database. In the
meanwhile, error values could be created that display in the page. All that is
necessary otherwise is to repopulate the form with the values that were submitted.
The initial idea was to create an events calendar in which events would be inserted from
the mSQL database. The mod() and abs() functions, which are
not included in Lite, make the calculation of Leap year values simpler.
<!
funct mod(real $n1, real $n2)
{
$nRemainder = $n1 / $n2 ;
$nAbs = abs( (real)$nRemainder ) ;
$nMod = $n1 - ( $nAbs * $n2 ) ;
$nMod = (int)$nMod;
return( $nMod ) ;
}
funct abs(real $nNum)
{
$cNum = (char)$nNum ;
$aParts = split( $cNum, "." ) ;
$nAbs = (int)$aParts[0] ;
return( $nAbs ) ;
}
>
<HTML>
<HEAD>
<TITLE>calendar</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff" TEXT="#00000">
<CENTER>
<TABLE BORDER CELLPADDING="2">
<!
$time = time(); /* get system time */
/* Current Month */
$day = unixtime2day($time); /* integer value 1-31 */
$dayOfWeek = (int)strftime("%w", $time); /* integer value 0-6 */
$month = unixtime2month($time); /* integer value 1-12 */
$year = unixtime2year($time); /* integer value xxxx */
/* Previous or Next Month (passed values) */
if ($submit == "Previous Month")
{
$month = (int)$lastMonth - 1;
$year = (int)$lastYear;
if ($month == 0)
{
$year--;
$month = 12;
}
}
if ($submit == "Next Month")
{
$month = (int)$lastMonth + 1;
$year = (int)$lastYear;
if ($month == 13)
{
$year++;
$month = 1;
}
}
/* Number of days of month 30 or 31, with special case of February (28 or 29) */
if ($month == 4 || $month == 6 || $month == 9 || $month == 11)
{
$numDays = 30;
}
else
{
if ($month != 2)
{
$numDays = 31;
}
}
if ($month == 2)
{
/* Leap year calculations:
All years that are evenly divisible by 400 or are evenly
divisible by 4 and NOT divisible by 100 are leap years.
*/
$year = (real)$year;
$test1 = mod($year, 400.0 );
if ($test1 == 0 )
{
$numDays = 29;
}
else
{
$test2 = mod($year, 4.0 );
$test3 = mod($year, 100.0 );
if ($test2 == 0 && $test3 > 0)
{
$numDays = 29;
}
else
{
$numDays = 28;
}
}
}
/* Make month name array */
$monthName[1] = "January";
$monthName[2] = "February";
$monthName[3] = "March";
$monthName[4] = "April";
$monthName[5] = "May";
$monthName[6] = "June";
$monthName[7] = "July";
$monthName[8] = "August";
$monthName[9] = "September";
$monthName[10] = "October";
$monthName[11] = "November";
$monthName[12] = "December";
/* Find day of week (0-6) of first day of month. $firstDayPos will
help determine later display of cells. */
if ($month == unixtime2month($time))
{
/* Current Month */
$count = $day;
$pos = $dayOfWeek;
while ($count > 0)
{
if ($count == 1) /* must come before $pos switch to preserve assignment */
{
$firstDayPos = $pos;
}
if ($pos == 0) /* must come before decrement, since Sunday = 0 */
{
$pos = 7; /* must be 7 so that next loop is 6 */
}
$count--;
$pos--;
}
}
/* Get new first day position depending on whether prev or next month
has 31, 30, 29, or 28 days. Cannot be calculated from current
Unix time. */
if ($submit == "Previous Month")
{
$firstDayPos = ((int)$lastFirstDayPos - $numDays) + 28;
if ($firstDayPos < 0)
{
$firstDayPos = $firstDayPos + 7;
}
}
if ($submit == "Next Month")
{
$firstDayPos = ((int)$lastFirstDayPos + (int)$lastNumDays) - 28;
if ($firstDayPos > 6)
{
$firstDayPos = $firstDayPos - 7;
}
}
/* Prepare events for insertion
For now I am placing only a check mark in the appropriate
day box.
*/
$eventDay = unixtime2day($time);
/* Make cell array */
$count = 0;
$dayNum = 1;
while ($count <= $numDays + $firstDayPos) /* Add number of initial blank days
to count */
{
if ($count < $firstDayPos)
{
/* Empty cells display as solid blank */
$cell[$count] = "<td></td>\n";
}
else
{
/* Create empty event array */
$event[$dayNum]="";
if ($month == unixtime2month($time) && (int)$year ==
unixtime2year($time) && $eventDay == $dayNum) /* Assign check to day */
{
$event[$eventDay] = "<IMG SRC=\"images/check7.gif\">";
}
$cell[$count] = "<TD align=\"left\" valign=\"top\">$dayNum
$event[$dayNum]</td>\n";
$dayNum++;
}
$count++;
}
/* Print the calendar elements. Table tags are above and below this in the
HTML.
Beginning first row tag and ending last row tag are outside the
loop. */
echo("<CAPTION><FONT size=\"5\">$monthName[$month]
$year</FONT></CAPTION>
<TR>
<TD align=\"center\"> Sunday </TD>
<TD align=\"center\"> Monday </TD>
<TD align=\"center\"> Tuesday </TD>
<TD align=\"center\"> Wednesday </TD>
<TD align=\"center\"> Thursday </TD>
<TD align=\"center\"> Friday </TD>
<TD align=\"center\"> Saturday </TD>
</TR>
<TR>");
$count = 0;
while ($count < $numDays + $firstDayPos)
{
echo("$cell[$count]");
/* Insert subsequent table row tags in appropriate place
after cell print */
if ($count == 6 || $count == 13 || $count == 20 || $count ==
27 || $count == 34)
{
echo("<TR></TR>");
/* Empty initial cells will display solid blank */
}
$count++;
/* Final unprinted empty cells will display solid blank */
}
echo("</TR></TABLE></CENTER>
<center><form action=\"/cgi-bin/w3-msql/~fischman/kosenko/calendar2.htm\">
<input type=\"hidden\" name=\"lastMonth\"
value=\"$month\">
<input type=\"hidden\" name=\"lastYear\"
value=\"$year\">
<input type=\"hidden\" name=\"lastFirstDayPos\"
value=\"$firstDayPos\">
<input type=\"hidden\" name=\"lastNumDays\"
value=\"$numDays\">
<input type=\"submit\"
name=\"submit\" value=\"Previous Month\">
<input type=\"submit\"
name=\"submit\" value=\"Next
Month\"></center>");
>
<p>This calendar uses Unix system clock values to enter at the
current month and to place a check mark at the current day.
The "Previous Month" and "Next Month" submit buttons then
resubmit values from which the previous or next month's calendar is
calculated. The script is written in mini-SQL's Lite scripting
language.</p>
</BODY>
</HTML>
| Programming
| VB Calendar |
E-mail Pete the answers to all his questions.
|