diff --git a/calendar.class.php b/calendar.class.php index fe13e11af04a5d2092d00647075ccd07dfe9ec4a..182c4bf36ab8ee691dea03dfc2965cf160110154 100644 --- a/calendar.class.php +++ b/calendar.class.php @@ -13,6 +13,7 @@ function display() { ### Extract information from the given date: $month = date("n", $this->date); $year = date("Y", $this->date); + $day = date("d", $this->date); ### Extract first day of the month: $first = date("w", mktime(0, 0, 0, $month, 1, $year)); @@ -21,70 +22,54 @@ function display() { $last = date("t", mktime(0, 0, 0, $month, 1, $year)); ### Calculate previous and next months dates: - $prev = mktime(0, 0, 0, $month - 1, 1, $year); - $next = mktime(0, 0, 0, $month + 1, 1, $year); + $prev = mktime(0, 0, 0, $month - 1, $day, $year); + $next = mktime(0, 0, 0, $month + 1, $day, $year); ### Generate calendar header: - print "<TABLE WIDTH=\"150\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\">"; - print " <TR><TH COLSPAN=\"7\"><A HREF=\"$PHP_SELF?date=$prev\"><<</A> ". date("F Y", $this->date) ." <A HREF=\"$PHP_SELF?date=$next\">>></A></TH></TR>"; - print " <TR><TH>S</TH><TH>M</TH><TH>T</TH><TH>W</TH><TH>T</TH><TH>F</TH><TH>S</TH></TR>\n"; + $output .= "<TABLE WIDTH=\"150\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\">"; + $output .= " <TR><TH COLSPAN=\"7\"><A HREF=\"$PHP_SELF?date=$prev\"><<</A> ". date("F Y", $this->date) ." <A HREF=\"$PHP_SELF?date=$next\">>></A></TH></TR>"; + $output .= " <TR><TH>S</TH><TH>M</TH><TH>T</TH><TH>W</TH><TH>T</TH><TH>F</TH><TH>S</TH></TR>\n"; ### Initialize temporary variables: - $day = 1; - $weekday = $first; + $nday = 1; + $sday = $first; ### Loop through all the days of the month: - while ($day <= $last) { + while ($nday <= $last) { ### Set up blank days for first week of the month: if ($first) { - print "<TR><TD COLSPAN=\"$first\"> </TD>"; + $output .= "<TR><TD COLSPAN=\"$first\"> </TD>"; $first = 0; } ### Start every week on a new line: - if ($weekday == 0) print "<TR>"; + if ($sday == 0) $output .= "<TR>"; ### Print one cell: - $date = mktime(0, 0, 0, $month, $day, $year); - if ($day == date("d", $this->date)) { - print "<TD ALIGN=\"center\"><B>$day</B></TD>"; - } - else { - print "<TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?date=$date\">$day</A></TD>"; - } + $date = mktime(0, 0, 0, $month, $nday, $year); + if ($nday > $day) $output .= "<TD ALIGN=\"center\">$nday</TD>"; + else if ($nday == $day) $output .= "<TD ALIGN=\"center\"><B>$nday</B></TD>"; + else $output .= "<TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?date=$date\">$nday</A></TD>"; ### Start every week on a new line: - if ($weekday == 6) print "</TR>"; + if ($sday == 6) $output .= "</TR>"; ### Update temporary variables: - $weekday++; - $weekday = $weekday % 7; - $day++; + $sday++; + $sday = $sday % 7; + $nday++; } ### End the calendar: - if ($weekday != 0) { - $end = 7 - $weekday; - print "<TD COLSPAN=\"$end\"> </TD></TR>"; + if ($sday != 0) { + $end = 7 - $sday; + $output .= "<TD COLSPAN=\"$end\"> </TD></TR>"; } - print "</TABLE>"; + $output .= "</TABLE>"; + + ### Return calendar: + return $output; } } - - -// ----------------------------------------------------------------------- -// ---------- TEMPORARY CODE - should be removed after testing ----------- -// ----------------------------------------------------------------------- - -print "<H1>CALENDAR TEST</H1>"; - -// Code to initialize and display a calendar: -if (!$date) $date = time(); -$calendar = new calendar($date); -$calendar->display(); - -// Debug output: -print "<P><B>Selected date:</B><BR>". date("l, F d, Y", $date) ."</P>"; - ?> diff --git a/functions.inc b/functions.inc index fa7a3d15cb5e52c579988a1cd86975ad3cb96309..423067bac4b204d96449560f745adea486e810d7 100644 --- a/functions.inc +++ b/functions.inc @@ -169,6 +169,11 @@ function displayAccount($theme) { } } +function displayCalendar($theme, $date) { + include "calendar.class.php"; + $calendar = new calendar($date); + $theme->box("Browse archives", $calendar->display()); +} function displayAccountSettings($theme) { global $user; diff --git a/index.php b/index.php index 0f7bd7bf477f74799c4079d29a7614e21b34e249..9fde6521aa98a25da7f5cedc4d2eb17222c6ecbb 100644 --- a/index.php +++ b/index.php @@ -7,18 +7,20 @@ addRefer($url); } - include "theme.inc"; $theme->header(); dbconnect(); -if (isset($user->storynum)) $number = $user->storynum; else $number = 10; +### Initialize variables: +$number = ($user->storynum) ? $user->storynum : 10; +$date = ($date) ? $date : time(); -$result = mysql_query("SELECT * FROM stories ORDER BY sid DESC LIMIT $number"); +### Perform query: +$result = mysql_query("SELECT * FROM stories WHERE time <= $date ORDER BY sid DESC LIMIT $number"); +### Display stories: while ($story = mysql_fetch_object($result)) { - ### Compose more-link: $morelink = "[ "; if ($story->article) { @@ -28,16 +30,15 @@ $bytes = strlen($story->article); $morelink .= "\"><FONT COLOR=\"$theme->hlcolor2\"><B>read more</B></FONT></A> | $bytes bytes in body | "; } - $query = mysql_query("SELECT sid FROM comments WHERE sid = $story->sid"); if (!$query) { $count = 0; } else { $count = mysql_num_rows($query); } - $morelink .= "<A HREF=\"article.php?sid=$story->sid"; if (isset($user->umode)) { $morelink .= "&mode=$user->umode"; } else { $morelink .= "&mode=threaded"; } if (isset($user->uorder)) { $morelink .= "&order=$user->uorder"; } else { $morelink .= "&order=0"; } if (isset($user->thold)) { $morelink .= "&thold=$user->thold"; } else { $morelink .= "&thold=0"; } $morelink .= "\"><FONT COLOR=\"$theme->hlcolor2\">$count comments</FONT></A> ]"; + ### Display story: $theme->abstract($story->aid, $story->informant, $story->time, stripslashes($story->subject), stripslashes($story->abstract), stripslashes($story->comments), $story->category, $story->department, $morelink); }