Jump to content

Why is "June" the only month that isn't showing up right?


datafan

Recommended Posts

This is a head scratcher for me. All the months in the calendar work fine but "June", which is the only month that starts on a Sunday, isn't formatting correctly. I have played with a if ($ChosenMonth == '6') { do this}; and also tried to change $actday and $firstDay in evey way I can think of, but nothing I can think of fixes the formatting of that first row.

Please take a peek here live, pick June and you will see exactly what I mean http://www.tamstouch.com/calcreate.php

Thanks for any help. I almost got this thing done!

 

The code in the Calendar Function that builds the first lines of the calendar:

<?php
// Get key day informations. 
// We need the first and last day of the month and the actual day
$today = getdate();
$pickmonth = getdate(mktime(0,0,0,$ChosenMonth,1,2008));
$firstDay = getdate(mktime(0,0,0,$pickmonth['mon'],1,$pickmonth['year']));
$lastDay  = getdate(mktime(0,0,0,$pickmonth['mon']+1,0,$pickmonth['year']));

// Create a table with the necessary header informations
echo '<table align="center">';
if ($ChosenMonth == '1'){
?>
<tr><th colspan="4"><a href="calcreate.php">HOME</a></th><th colspan="3"><a href="calcreate.php?c=<?php echo $ChosenMonth +1;?>">Next Month</a></th></tr>
<?php
}elseif($ChosenMonth == '12'){
?>
<tr><th colspan="3"><a href="calcreate.php?c=<?php echo $ChosenMonth -1;?>">Prev Month</a></th><th colspan="4"><a href="calcreate.php">HOME</a></th></tr>
<?php
}else{
?>
<tr><th colspan="2"><a href="calcreate.php?c=<?php echo $ChosenMonth -1;?>">Prev Month</a></th><th colspan="3"><a href="calcreate.php">HOME</a></th><th colspan="2"><a href="calcreate.php?c=<?php echo $ChosenMonth +1;?>">Next Month</a></th></tr>
<?php
}
echo '</table>';
echo '<table align="center">';
echo '  <tr><th colspan="7">'.$pickmonth['month']." - ".$pickmonth['year']."</th></tr>";
echo '<tr class="days">';
echo '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
echo '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';
    
// Display the first calendar row with correct positioning
echo '<tr>';
for($i=1;$i<$firstDay['wday'];$i++){
    echo '<td> </td>';
}

$actday = 0;
for($i=$firstDay['wday'];$i<=7;$i++){
    $actday++;

 

Complete Calendar Function :

<?php
//function to read flat file and build an array of the entries for the chosen month so we can use it throughout the script
$flatname = "masterflat.txt";
function readflat($flatname, $ChosenMonth){
global $lines;
$flatlist = file($flatname);
foreach ($flatlist as $row) {
	for($i=count($row) -1; $i >= 0; $i--){
		$result = explode("|", $row);
		$month = date ("n", $result[0]);
		if ($month == $ChosenMonth) {
			$lines[] = array($result[0], $result[1], $result[2], $result[3], $result[4]);
		}
	}
}
return $lines;
}

//function to sort the flat file array according to classroom and then time
function mysort($a, $b)
{
    $sc = strcmp($a[1], $b[1]); // compare classrooms
    if ($sc==0)                 // if they're equal, compare epoch
    {
        return $a[2] - $b[2];   // if a should sort above b, return -ve number
    }
    else return $sc;
}  // usort ($line, 'mysort');   // sort using custom function



function showCalendar($ChosenMonth, $lines){
// Get key day informations. 
// We need the first and last day of the month and the actual day
$today = getdate();
$pickmonth = getdate(mktime(0,0,0,$ChosenMonth,1,2008));
$firstDay = getdate(mktime(0,0,0,$pickmonth['mon'],1,$pickmonth['year']));
$lastDay  = getdate(mktime(0,0,0,$pickmonth['mon']+1,0,$pickmonth['year']));

// Create a table with the necessary header informations
echo '<table align="center">';
if ($ChosenMonth == '1'){
?>
<tr><th colspan="4"><a href="calcreate.php">HOME</a></th><th colspan="3"><a href="calcreate.php?c=<?php echo $ChosenMonth +1;?>">Next Month</a></th></tr>
<?php
}elseif($ChosenMonth == '12'){
?>
<tr><th colspan="3"><a href="calcreate.php?c=<?php echo $ChosenMonth -1;?>">Prev Month</a></th><th colspan="4"><a href="calcreate.php">HOME</a></th></tr>
<?php
}else{
?>
<tr><th colspan="2"><a href="calcreate.php?c=<?php echo $ChosenMonth -1;?>">Prev Month</a></th><th colspan="3"><a href="calcreate.php">HOME</a></th><th colspan="2"><a href="calcreate.php?c=<?php echo $ChosenMonth +1;?>">Next Month</a></th></tr>
<?php
}
echo '</table>';
echo '<table align="center">';
echo '  <tr><th colspan="7">'.$pickmonth['month']." - ".$pickmonth['year']."</th></tr>";
echo '<tr class="days">';
echo '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
echo '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';
    
// Display the first calendar row with correct positioning
echo '<tr>';
for($i=1;$i<$firstDay['wday'];$i++){
    echo '<td> </td>';
}

$actday = 0;
for($i=$firstDay['wday'];$i<=7;$i++){
    $actday++;

$pickday = getdate(mktime(0,0,0,$ChosenMonth,$actday,2008));
$pickdayep = date("U", mktime(0, 0, 0,$pickday['mon'],$pickday['mday'],$pickday['year']));
$pickdayepend= $pickdayep + 86400;

if ($actday == $today['mday'] && $pickmonth['mon'] == $today['mon'] && $pickmonth['year'] == $today['year']) {
	$class = ' class="actday"';
    }else{
        $class = '';
    }

echo "<td$class>$actday";
	if ($lines) {
	foreach ( $lines as $key => $line ) { 
		$line[2] = date("g:i a", strtotime("$line[2]"));
		$line[3] = date("g:i a", strtotime("$line[3]"));
		if ($line[1] == "c1") {
			$cellcolor = "ffff00";
		}elseif ($line[1] == "c2") {
				$cellcolor = "ffcc00";
		}elseif ($line[1] == "c3") {
				$cellcolor = "ff9900";
		}elseif ($line[1] == "c4") {
				$cellcolor = "00ff00";
		}elseif ($line[1] == "c5") {
				$cellcolor = "ffcccc";
		}elseif ($line[1] == "c6") {
				$cellcolor = "99ccff";
		}elseif ($line[1] == "MN") {
				$cellcolor = "00ffff";
		}			
		$day = date("j", $line[0]);
		if($day == $actday) {
			echo "<font style='font-size:8pt;'><TABLE align='center' style='background-color:#$cellcolor; width:126px;'><tr><td style='width:126px; height:5px;'>";
			echo "<a href=reservations/".$line[4].">".$line[1]." ".$line[2]." - ".$line[3]."</a><br>";
			echo "</td></tr></table></font>";
		}
	}
	}
    	
echo "</td>";
}
    echo '</tr>';
    
//Get how many complete weeks are in the actual month
$fullWeeks = floor(($lastDay['mday']-$actday)/7);

for ($i=0;$i<$fullWeeks;$i++){
    echo '<tr>';
    for ($j=0;$j<7;$j++){
        $actday++;
					            
	if ($actday == $today['mday'] && $pickmonth['mon'] == $today['mon'] && $pickmonth['year'] == $today['year']) {
            $class = ' class="actday"';
        }else{
            $class = '';
        }
	echo "<td$class>$actday";
	if ($lines) {
	foreach ( $lines as $key => $line ) {
		$line[2] = date("g:i a", strtotime("$line[2]"));
		$line[3] = date("g:i a", strtotime("$line[3]"));
		if ($line[1] == "c1") {
			$cellcolor = "ffff00";
		}elseif ($line[1] == "c2") {
				$cellcolor = "ffcc00";
		}elseif ($line[1] == "c3") {
				$cellcolor = "ff9900";
		}elseif ($line[1] == "c4") {
				$cellcolor = "00ff00";
		}elseif ($line[1] == "c5") {
				$cellcolor = "ffcccc";
		}elseif ($line[1] == "c6") {
				$cellcolor = "99ccff";
		}elseif ($line[1] == "MN") {
				$cellcolor = "00ffff";
		}			
		$day = date("j", $line[0]);
		if($day == $actday) {
			echo "<font style='font-size:8pt;'><TABLE align='center' style='background-color:#$cellcolor; width:126px;'><tr><td style='width:126px; height:5px;'>";
			echo "<a href=reservations/".$line[4].">".$line[1]." ".$line[2]." - ".$line[3]."</a><br>";
			echo "</td></tr></table></font>";
		}
	}
	}
    	
echo "</td>";

    }
    echo '</tr>';
}
    
//Now display the rest of the month
if ($actday < $lastDay['mday']){
    echo '<tr>';
      
    for ($i=0; $i<7;$i++){
        $actday++;

	if ($actday == $today['mday'] && $pickmonth['mon'] == $today['mon'] && $pickmonth['year'] == $today['year']) {
            $class = ' class="actday"';
        }else{
            $class = '';
        }
          
        if ($actday <= $lastDay['mday']){
		echo "<td$class>$actday";
		if ($lines) {
		foreach ( $lines as $key => $line ) {
			$line[2] = date("g:i a", strtotime("$line[2]"));
			$line[3] = date("g:i a", strtotime("$line[3]"));
			if ($line[1] == "c1") {
				$cellcolor = "ffff00";
			}elseif ($line[1] == "c2") {
				$cellcolor = "ffcc00";
			}elseif ($line[1] == "c3") {
				$cellcolor = "ff9900";
			}elseif ($line[1] == "c4") {
				$cellcolor = "00ff00";
			}elseif ($line[1] == "c5") {
				$cellcolor = "ffcccc";
			}elseif ($line[1] == "c6") {
				$cellcolor = "99ccff";
			}elseif ($line[1] == "MN") {
				$cellcolor = "00ffff";
			}			
		$day = date("j", $line[0]);
		if($day == $actday) {
			echo "<font style='font-size:8pt;'><TABLE align='center' style='background-color:#$cellcolor; width:126px;'><tr><td style='width:126px; height:5px;'>";
			echo "<a href=reservations/".$line[4].">".$line[1]." ".$line[2]." - ".$line[3]."</a><br>";
			echo "</td></tr></table></font>";
		}
		}
		}

    	
	echo "</td>";
        }else{
		echo '<td> </td>';
        }
    }
    echo '</tr>';
}

} //end of calendar function
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.