All pastes #115469 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-08-04 16:34 UTC
rendered paste body
pod_cal.php (called from index)

<?php
include ('include/calendar.php');
include ('config.php');
if(empty($getyearmonth)) {//if no yearmonth was passed to the page, then by default use today's month and year
	$dateComponents = getdate();
	$month = $dateComponents['mon'];
	$year = $dateComponents['year'];
}
else {//yearmonth was passed so use it to create calendar
	$year = substr($getyearmonth, 0, 4);
	$month = substr($getyearmonth, 5, 2);
}
if($month < 10){
	$month = '0'.$month;
}
$cal_query="SELECT * 
			FROM Thumann_roster.calendar_raids
			WHERE raidDate
			LIKE '$year-$month%';";		
$cal_rs = mysql_query($cal_query)or die(mysql_error());
while ($cal_row = mysql_fetch_array($cal_rs)) {
	$date = substr($cal_row['raidDate'], 0, 10);	
	$dateArray[] = $date;
}
echo build_calendar($month,$year,$dateArray); 
?>
<?php
     if (isset ($_GET['date'])) { 

          $date = $_GET['date']; 

     } else { 

          $date = date("Y-m-d"); 

     } 

     echo "<p><table width='350'><tr><td><p><span style=\"color: #656565;\"><b>Raids for $date</b></span></p>"; 

     $blogQuery = "SELECT title, content  
                   FROM calendar_raids WHERE raidDate = '$date'"; 

     $blogResult = mysql_query($blogQuery); 

     if (mysql_numrows($blogResult) > 0) { 

          while (list($title,$content) =  
               mysql_fetch_row($blogResult)) { 

echo border('syellow','start',$title);
echo '<table cellpadding="0" cellspacing="0"> ';
echo '<tr>';
echo '<td class="membersHeader">'.$content.'</td>';
echo '</tr>';
echo '<tr>';
echo '</table> ';
echo border('syellow','end');
echo "<br>";
          } 

     } else { 

           echo "No Raids available"; 

     } 

     echo "</td></tr></table></p>"; 

?> 

----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
calendar.php (included in pod_cal.php)

<?php
function build_calendar($month,$year,$dateArray) {

	//builds link for next month
	$nextmonth = $month;
	$nextmonth++;
	$next = "$year-$nextmonth";
	
	//builds link for previous month
	$prevmonth = $month;
	$prevmonth--;
	$prev = "$year-$prevmonth";		
	
	if($month == 12){//change $next link to January of next year if the displayed month is December
		$nextyear = $year;
		$nextyear++;
		$next = "$nextyear-01";
	}
	elseif($month == 1){//change $prev link to December of previous year if the displayed month is January
		$prevyear = $year;
		$prevyear--;
		$prev = "$prevyear-12";		
	}

     // Create array containing abbreviations of days of week.
     $daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');

     // What is the first day of the month in question?
     $firstDayOfMonth = mktime(0,0,0,$month,1,$year);

     // How many days does this month contain?
     $numberDays = date('t',$firstDayOfMonth);

     // Retrieve some information about the first day of the
     // month in question.
     $dateComponents = getdate($firstDayOfMonth);

     // What is the name of the month in question?
     $monthName = $dateComponents['month'];

     // What is the index value (0-6) of the first day of the
     // month in question.
     $dayOfWeek = $dateComponents['wday'];

     // Create the table tag opener and day headers
echo border('syellow','start');
     $calendar = "<table class='calendar'>
	 				<caption><a href='addon.php?roster_addon_name=tinyraidcal&yearmonth=$prev";if(!empty($getdate)){$calendar .="&date=$getdate";} $calendar .="' class='calendararrow'>&lt;</a>&nbsp;&nbsp;$monthName $year&nbsp;&nbsp;<a href='addon.php?roster_addon_name=tinyraidcal&yearmonth=$next";if(!empty($getdate)){$calendar .="&date=$getdate";} $calendar .="' class='calendararrow'>&gt;</a></caption>
						<tr>";   

     foreach($daysOfWeek as $day) { // Create the calendar headers
          $calendar .= "<th class='calheader'>$day</th>";
     }
     // Initiate the day counter, starting with the 1st.

     $currentDay = 1;

     $calendar .= "</tr><tr>";

     // The variable $dayOfWeek is used to
     // ensure that the calendar
     // display consists of exactly 7 columns.

     if ($dayOfWeek > 0) { 
          $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>"; 
     }

     while ($currentDay <= $numberDays) {// Seventh column (Saturday) reached. Start a new row.
		if ($dayOfWeek == 7) {
          	$dayOfWeek = 0;
			$calendar .= "</tr><tr>";
		}

         // Is the $currentDay a member of $dateArray? If so,
         // the day should be linked.
		if($currentDay < 10) {
			$currentDay = '0'.$currentDay;
		}
		/*if($month < 10) {NOT SURE WHY THIS MESSES UP THE SCRIPT
			$month = '0'.$month;
		}*/
		$date = "$year-$month-$currentDay";
		if (!empty($dateArray) && in_array($date,$dateArray)) {
         		 	$calendar .= "<td class='linkedday'>
                       		<a href='addon.php?roster_addon_name=tinyraidcal&date=$date' class='calendarlink'>$currentDay</a>
						  </td>";
		}
		else {// $currentDay is not a member of $dateArray.
			$calendar .= "<td class='day'>$currentDay</td>";
		}
		
		$currentDay++;
        $dayOfWeek++;
	}
	if ($dayOfWeek != 7) { // Complete the row of the last week in month, if necessary
		$remainingDays = 7 - $dayOfWeek;
		$calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";
	}
	$calendar .= "</table>";
	$calendar .= border('syellow','end');
return $calendar;
}

?>