PX : code

dtCalendar by Maziar Aflatoun
Download this code


<?
/////////////////////////////////////////////////////////////////////////////////
// 
// dtcalendar(class)      :     Written by Maziar Aflatoun 2001
// email                :     maz88@home.com
// 
// To add an event use 
// $testcal = new dtCalendar;
// $testcal->initialize($current_month_new,$current_day_new,$current_year_new);
// $testcal->add_event(1); when set, there is an event for that specific day 
// $testcal->add_event(2); use
// $testcal->display();
//
//////////////////////////////////////////////////////////////////////////////////

class dtCalendar {

////////////////  General setting (user modify) /////////////////////////////////
var $col_today_bg = \\\"#EFF333\\\";
var $col_title_bg = \\\"#30267B\\\";
var $col_title_txt = \\\"#FFFFFF\\\";
var $col_cell_bg = \\\"#E6E6E6\\\";
var $col_nav_bg = \\\"#CCCCCC\\\";
var $col_nav_txt = \\\"#000000\\\";

// set to true/false to enable/disable top navigation bar (default=on)
var $show_nav = \\\"true\\\";

// set href page and it\\\'s target
var $href_page = \\\"viewselecteddate.php\\\";
var $target = \\\"_self\\\";

/////////////////////////////////////////////////////////////////////////////////


// valid months starting with jan <=> 1
var $valid_months = array(1=>\\\"Jan\\\", \\\"Feb\\\", \\\"Mar\\\", \\\"Apr\\\", \\\"May\\\", \\\"Jun\\\", \\\"Jul\\\", \\\"Aug\\\", \\\"Sep\\\", \\\"Oct\\\", \\\"Nov\\\", \\\"Dec\\\");

// valid days starting with Sat <=> 1 for table location
var $valid_days = array(\\\"Sat\\\"=>1, \\\"Sun\\\"=>2, \\\"Mon\\\"=>3, \\\"Tue\\\"=>4, \\\"Wed\\\"=>5, \\\"Thu\\\"=>6, \\\"Fri\\\"=>7);

var $months_events = array();

var $current_day;
var $current_month; 
var $current_year; 
var $current_date;
var $abbreviated_wkday;

var $current_month_str;

function dtCalendar() {
    $this->current_month = intval(date(\\\"m\\\"));
    $this->current_day = intval(date(\\\"d\\\"));
    $this->current_year = intval(date(\\\"Y\\\"));
          
     // Find the first day of any given month (displaying table usage) 
     $this->abbreviated_wkday = strftime(\\\"%a\\\", mktime(0,0,0,$this->current_month,1,$this->current_year));
     //$this->current_month_str = $this->valid_months[$this->current_month];     
}

function initialize($current_month_new, $current_day_new, $current_year_new) {
    $this->current_month = $current_month_new;
    $this->current_day = $current_day_new;
    $this->current_year = $current_year_new;
          
     // Find the first day of any given month (displaying table usage) 
     $this->abbreviated_wkday = strftime(\\\"%a\\\", mktime(0,0,0,$current_month_new,1,$current_year_new));     
}

// Add an event to the calendar
function add_event($event_day) {        
    $event_day++;
    $this->months_events[$event_day] = 1;
}

function display() {
  ?>
  <table width=\\\"500\\\" border=\\\"0\\\" cellspacing=\\\"0\\\" cellpadding=\\\"0\\\">
   <? if ($this->show_nav == \\\"true\\\") { ?>
     <tr> 
      <td bgcolor=\\\"<?=$this->col_nav_bg?>\\\">
        <form name=\\\"datesubmit\\\" method=\\\"post\\\" action=\\\"index.php\\\">
          <table width=\\\"100%\\\" border=\\\"0\\\" cellspacing=\\\"1\\\" cellpadding=\\\"5\\\">
            <tr>
              <td width=\\\"7%\\\" align=\\\"left\\\" valign=\\\"middle\\\"><font color=\\\"<?=$this->col_nav_txt?>\\\"><b>Year:</b></font></td>
              <td width=\\\"18%\\\" align=\\\"left\\\" valign=\\\"middle\\\"> 
                   <input type=\\\"hidden\\\" name=\\\"current_day_new\\\" value=\\\"1\\\">
                <select name=\\\"current_year_new\\\">
                  <? 
                      for ($yearcnt=2020; $yearcnt>1970; $yearcnt--){
                              $inctag=\\\"\\\";
                              if ($yearcnt == $this->current_year) {
                                        $inctag = \\\"selected\\\";
                                  }
                              print \\\"<option value=\\\'\\\".$yearcnt.\\\"\\\' $inctag>\\\".$yearcnt.\\\"</option>\\\";
                          }
                  ?>                                    
                </select>
              </td>
              <td width=\\\"9%\\\" align=\\\"left\\\" valign=\\\"middle\\\"><font color=\\\"<?=$this->col_nav_txt?>\\\"><b>Month:</b></font></td>
              <td width=\\\"16%\\\" align=\\\"left\\\" valign=\\\"middle\\\">
                <select name=\\\"current_month_new\\\">
                  <option value=\\\"1\\\" <?if ($this->current_month == \\\"01\\\") print \\\"selected\\\";?>>Jan</option>
                  <option value=\\\"2\\\" <?if ($this->current_month == \\\"02\\\") print \\\"selected\\\";?>>Feb</option>
                  <option value=\\\"3\\\" <?if ($this->current_month == \\\"03\\\") print \\\"selected\\\";?>>Mar</option>
                  <option value=\\\"4\\\" <?if ($this->current_month == \\\"04\\\") print \\\"selected\\\";?>>Apr</option>
                  <option value=\\\"5\\\" <?if ($this->current_month == \\\"05\\\") print \\\"selected\\\";?>>May</option>
                  <option value=\\\"6\\\" <?if ($this->current_month == \\\"06\\\") print \\\"selected\\\";?>>Jun</option>
                  <option value=\\\"7\\\" <?if ($this->current_month == \\\"07\\\") print \\\"selected\\\";?>>Jul</option>
                  <option value=\\\"8\\\" <?if ($this->current_month == \\\"08\\\") print \\\"selected\\\";?>>Aug</option>
                  <option value=\\\"9\\\" <?if ($this->current_month == \\\"09\\\") print \\\"selected\\\";?>>Sep</option>
                  <option value=\\\"10\\\" <?if ($this->current_month == \\\"10\\\") print \\\"selected\\\";?>>Oct</option>
                  <option value=\\\"11\\\" <?if ($this->current_month == \\\"11\\\") print \\\"selected\\\";?>>Nov</option>
                  <option value=\\\"12\\\" <?if ($this->current_month == \\\"12\\\") print \\\"selected\\\";?>>Dec</option>
                </select>
              </td>
              <td width=\\\"50%\\\" align=\\\"left\\\" valign=\\\"middle\\\">
                <input type=\\\"submit\\\" name=\\\"Submit\\\" value=\\\"Go\\\">
              </td>
            </tr>
          </table>
        </form>
      </td>
    </tr>    
    <? } ?>
    <tr> 
      <td align=\\\"left\\\" valign=\\\"top\\\">         
      <table width=\\\"100%\\\" border=\\\"0\\\" cellspacing=\\\"1\\\" cellpadding=\\\"1\\\">
        <tr bgcolor=\\\"<?=$this->col_title_bg?>\\\">
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Sat</b></font></td>
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Sun</b></font></td>
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Mon</b></font></td>
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Tue</b></font></td>
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Wed</b></font></td>
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Thu</b></font></td>
            <td align=\\\"left\\\"><font color=\\\"<?=$this->col_title_txt?>\\\"><b>Fri</b></font></td>
        </tr>                
        <? 
        $x_day=1;
        for ($tbl_row=1; $tbl_row < 7; $tbl_row++) {
        print \\\"<tr>\\\";
            for ($tbl_col=1; $tbl_col<8; $tbl_col++) {
                if (checkdate($this->current_month, $x_day, $this->current_year)) {              
                if (($tbl_col < intval($this->valid_days[$this->abbreviated_wkday])) && ($tbl_row==1)) {
                       print \\\"<td bgcolor=\\\".$this->col_cell_bg.\\\">&nbsp;</td>\\\";                        
                   } else {  
                           ($x_day < 10) ? $x_day_submit = \\\"0\\\".\\\"$x_day\\\" : $x_day_submit = $x_day;    
                           ($this->current_month < 10) ? $current_month_submit = \\\"0\\\".$this->current_month : $current_month_submit = $this->current_month;
                           
                           if ($this->current_day == $x_day) {
                               print \\\"<td align=left bgcolor=\\\".$this->col_today_bg.\\\">\\\";                           
                               print \\\"<b><a href=\\\'\\\".$this->href_page.\\\"?selecteddate=\\\".$this->current_year.\\\"-\\\".$current_month_submit.\\\"-\\\".$x_day_submit.\\\"\\\' target=\\\'\\\".$this->target.\\\"\\\'>\\\".$x_day++.\\\"</a></b>\\\"; 
                           } else {                                
                               print \\\"<td align=left bgcolor=\\\".$this->col_cell_bg.\\\">\\\";
                               print \\\"<a href=\\\'\\\".$this->href_page.\\\"?selecteddate=\\\".$this->current_year.\\\"-\\\".$current_month_submit.\\\"-\\\".$x_day_submit.\\\"\\\' target=\\\'\\\".$this->target.\\\"\\\'>\\\".$x_day++.\\\"</a>\\\";                        
                            }
                            if (isset($this->months_events[$x_day])) print \\\"<blink>*</blink>\\\"; 
                         print \\\"</td>\\\";                            
                   }                                   
              } else {
                       print \\\"<td align=center bgcolor=\\\".$this->col_cell_bg.\\\">&nbsp;</td>\\\";                       
               }               
          } // for    
        print \\\"</tr>\\\";
         }?>
      </table>
      </td>
    </tr>
  </table> <?
  }
} // end class
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.