Jump to content

Recommended Posts

I just looked through the list of tutorials that was salvaged from the previous site and I'm sorry to say that unless Dan or Ober happens to have some previous ancient sql dump, that one was not salvaged.  Only 62 tutorials were salvaged :*(

That is too bad.

 

I may actually have the code for the tutorial on a CD-ROM back up in Vancouver. 

 

I will be back there in a few days, there is a slim chance but it could be there. 

 

If it is I will send it to you.

 

Thanks,

Jamie

  • 2 months later...

Hi,

 

I was looking for the tutorial earlier, and couldn't find it either. I found some code that was originally based on the tutorial though. This has been heavily modified over a long period of time, but this one *should* be XHTML, CSS and WCAG 1.0 compliant. I don't remember if the original had more functionality than this, or less, or whatever, but I hope people find it useful anyway.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Calendar</title>
<style type="text/css">
body {
  font-family:Verdana, Arial, Helvetica, sans-serif;
  font-size: 0.7em;
}

.day {
  display: block;
  float: left;
  margin: 0 2px 2px 0;
  border: 1px solid #666666;
  width: 25px;
  padding: 2px;
  height: 20px;
  text-align: center;
  line-height: 20px;
}

.day_out {
  display: block;
  float: left;
  margin: 0 2px 2px 0;
  border: 1px solid #EEEEEE;
  color: #999999;
  width: 25px;
  padding: 2px;
  height: 20px;
  text-align: center;
  line-height: 20px;
}

.day_letter {
  display: block;
  float: left;
  margin: 0 2px 2px 0;
  border: 1px solid #666666;
  width: 25px;
  padding: 2px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  font-weight: bold;
  background: #efefef;
}

.month {
  display: block;
  float: left;
  margin: 0 2px 2px 0;
  border: 1px solid #666666;
  width: 223px;
  padding: 2px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  background: #efefef;
  font-weight:bold;
}

.left {
float: left;
}

.right {
float: right;
}

.prev {
  float:left;
  text-align:left;
  width: 74px;
  padding: 0;
  margin: 0;
}

.next {
  float:right;
  text-align:right;
  width: 74px;
  padding: 0;
  margin: 0;
}

.month_name {
  float:left;
  width: 75px;
  padding: 0;
  margin: 0;  
}

.links {
  display: block;
  float: left;
  margin: 0 2px 2px 0;
  width: 223px;
  padding: 2px;
  height: 20px;
  text-align: center;
  line-height: 20px;
}

</style>

</head>

<body>
<?php

// Error Reporting. On.
//ini_set("display_errors","2");
//error_reporting("E_ALL");
error_reporting('0'); 
ini_set('display_errors', '0'); 

if(!isset($_GET['date'])){ 
   $date = mktime(0,0,0,date('m'), date('d'), date('Y')); 
} else { 
   $date = $_GET['date']; 
}  

$day = date('d', $date); 
$month = date('n', $date); 
$year = date('Y', $date);

$month_start = mktime(0,0,0,$month, 1, $year);
$month_name = date('F', $month_start); 

$month_start_day = date('D', $month_start); 

switch($month_start_day){ 
    case "Sun": $offset = 0; break; 
    case "Mon": $offset = 1; break; 
    case "Tue": $offset = 2; break; 
    case "Wed": $offset = 3; break; 
    case "Thu": $offset = 4; break; 
    case "Fri": $offset = 5; break; 
    case "Sat": $offset = 6; break; 
} 

// Works for PHP 4 >= 4.0.7, PHP5

// determine how many days are in the last month. 
if($month == 1){ 
   $num_days_last = cal_days_in_month(0, 12, ($year -1)); 
} else { 
   $num_days_last = cal_days_in_month(0, ($month -1), $year); 
} 
// determine how many days are in the current month. 
$num_days_current = cal_days_in_month(0, $month, $year); 

// Build an array for the current days 
// in the month 
for($i = 1; $i <= $num_days_current; $i++){ 
    $num_days_array[] = $i; 
} 

// Build an array for the number of days 
// in last month 
for($i = 1; $i <= $num_days_last; $i++){ 
    $num_days_last_array[] = $i; 
} 

// If the $offset from the starting day of the 
// week happens to be Sunday, $offset would be 0, 
// so don't need an offset correction. 

if($offset > 0){ 
    $offset_correction = array_slice($num_days_last_array, -$offset, $offset); 
    $new_count = array_merge($offset_correction, $num_days_array); 
    $offset_count = count($offset_correction); 
} 

// The else statement is to prevent building the $offset array. 
else { 
    $offset_count = 0; 
    $new_count = $num_days_array; 
} 

// count how many days we have with the two 
// previous arrays merged together 
$current_num = count($new_count); 

// Since we will have 5 HTML table rows (TR) 
// with 7 table data entries (TD) 
// we need to fill in 35 TDs 
// so, we will have to figure out 
// how many days to appened to the end 
// of the final array to make it 35 days. 

if($current_num > 35){ 
   $num_weeks = 6; 
   $outset = (42 - $current_num); 
} elseif($current_num < 35){ 
   $num_weeks = 5; 
   $outset = (35 - $current_num); 
} 
if($current_num == 35){ 
   $num_weeks = 5; 
   $outset = 0; 
} 
// Outset Correction 
for($i = 1; $i <= $outset; $i++){ 
   $new_count[] = $i; 
} 

// Now let's "chunk" the $all_days array 
// into weeks. Each week has 7 days 
// so we will array_chunk it into 7 days. 
$weeks = array_chunk($new_count, 7); 

// Build Previous and Next Links 
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date="; 
if($month == 1){ 
   $previous_link .= mktime(0,0,0,0,$day,($year)); 
} else { 
   $previous_link .= mktime(0,0,0,($month - 1),$day,$year); 
} 
$previous_link .= "\">« Prev</a>\n"; 

$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date="; 
if($month == 12){ 
   $next_link .= mktime(0,0,0,1,$day,($year + 1)); 
} else { 
   $next_link .= mktime(0,0,0,($month + 1),$day,$year); 
} 
$next_link .= "\">Next »</a>\n"; 

?>

<span class="month">
<strong><?PHP echo $month_name." ".$year; ?></strong>
</span>
<br clear="all" />

<span class="day_letter">S</span>
<span class="day_letter">M</span>
<span class="day_letter">T</span>
<span class="day_letter">W</span>
<span class="day_letter">T</span>
<span class="day_letter">F</span>
<span class="day_letter">S</span>
<br clear="all" />


<?PHP

// Now we break each key of the array  
// into a week and create a new table row for each 
// week with the days of that week in the table data 

$i = 0; 
foreach($weeks AS $week)
  { 
foreach($week as $d)
  { 
	if($i < $offset_count) { // Days BEFORE Current Month
		echo "<span class='day_out'>$d</span>\n";
	} 

	if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)) {
          if($date != mktime(0,0,0,$month,$d,$year)) { // Other Days in Current Month
  			echo "<span class='day'>$d</span>\n";
	  } else { // Day Selected in Current Month
		echo "\n<span class='day'><strong>$d</strong></span>\n\n";
	  } 
	} elseif ($outset > 0) { 
		if (($i >= ($num_weeks * 7) - $outset)) { // Days AFTER Current Conth.
			echo "<span class='day_out'>$d</span>\n";
		} 
        }
	  		  
        $i++; 

  } 
echo "<br clear='all' />\n\n";
  }

?>


<span class="links">
  <span class="prev">
<?PHP echo $previous_link; ?>
  </span>
  <?PHP     
    if ($month_name != date('F') || $year != date('Y')) {
  	  echo "<span class='month_name'>\n\t<a href='index.php'>To ".date('M')." ".date('Y')."</a>\n  </span>\n";
    }
  ?>
  <span class="next">
<?PHP echo $next_link; ?>
  </span>
</span>


</body>
</html>

 

Ps. I know the tutorial was really good, and really detailed, but I'm at work at the moment, and don't really have time to explain all the code. Sorry!

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.