Jump to content

jcha

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jcha's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Im new to php, but with some help I have created a calendar that works with php and mysql. The problem i have is that it only works in php5 and not php4--which is what is on my web server.  I understand that some of the changes from php4 to php5 include the way object classes are handled and foreach loops.  when I run the script on my webserver everything works except setCalendarText().  Can this code be slightly altered to work for php4 or does it have to be completely rewritten? <table width="100%" border="0">             <tr>               <td height="40" valign="top"> <div align="center"></div>                 <div align="center">&nbsp;                   <?php class Day { function Day( $inmonth, $month, $day, $year) { $this->{'month'} = $month; $this->{'day'} = $day; $this->{'year'} = $year; $this->{'inmonth'} = $inmonth; $this->{'number'} = $number; $this->{'text'} = ""; } function get_day() { return $this->{'day'}; } function get_month() { return $this->{'month'}; } function get_year() { return $this->{'year'}; } function get_inmonth() { return $this->{'inmonth'}; } function get_number() { return $this->{'number'}; } function get_text() { return $this->{'text'}; } function set_text( $text ) { $this->{'text'} = $text; } } function setCalendarText( $days, $m, $d, $y, $text ) { foreach( $days as $day ) { if ( $day->get_day() == $d && $day->get_month() == $m && $day->get_year() == $y )     $day->set_text( $text ); } } function get_last_month ($month, $year ) { $lastmonth = $month - 1; $lastyear = $year; if ( $lastmonth < 0 ) { $lastmonth = 11; $lastyear -= 1; } return array ($lastmonth, $lastyear ); } function get_next_month ($month, $year ) { $nextmonth = $month + 1; $nextyear = $year; if ( $nextmonth > 11 ) { $nextmonth = 0; $nextyear += 1; } return array ($nextmonth, $nextyear ); } function makeCalendarDays( $month, $year ) { list( $nextmonth, $nextyear ) = get_next_month( $month, $year ); list( $lastmonth, $lastyear ) = get_last_month( $month, $year ); $dimlm = cal_days_in_month( CAL_GREGORIAN, $lastmonth + 1, $lastyear ); $jd = cal_to_jd( CAL_GREGORIAN, $month + 1, 1, $year ); $day = jddayofweek( $jd ); $dim = cal_days_in_month( CAL_GREGORIAN, $month + 1, $year ); $days = array(); for( $d = 0; $d < $day; $d++ ) $days []= new Day ( 0, $lastmonth +1, $dimlm, - ($day - $d) - 1, $lastyear ); for( $d=1; $d <= $dim; $d++ ) $days []= new Day ( 1, $month + 1, $d, $year ); $left = ( ( floor( ( $day + $dim ) / 7) + 1) * 7) - ( $day + $dim ); for( $d = 0; $d < $left; $d++ ) $days []= new Day( 0, $nextmonth + 1, $d+1, $nextyear ); return $days; } $today = getdate(); $year = $today['year']; $month = $today['mon'] -1; if (isset($_GET['year'])) $year = $_GET['year']; if (isset($_GET['month'])) $month = $_GET['month']; $days = makeCalendarDays( $month, $year ); //_______________________________________________________________________HERE setCalendarText( &$days, 8, 23, 2006, "test");//__________________________works in php5, but does not show up in php4 //________________________________________________________________________ $months = array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ); $day_names = array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ); ?>                   <div style="width:500px;">                     <table class="calendar" width="100%" cellspacing="0" cellpadding="1">                       <tr>                         <td width="13%" colspan="7" valign="top" class="calendar-title">                           <?php list( $nextmonth, $nextyear ) = get_next_month( $month, $year ); list( $lastmonth, $lastyear ) = get_last_month( $month, $year ); ?>                           <a href="cal.php?year=<?php echo($lastyear); ?>&month=<?php echo( $lastmonth ); ?>">&lt;&lt;</a>                           <?php echo( $months[$month] ); ?> <?php echo( $year ); ?>                           <a href="cal.php?year=<?php echo($nextyear); ?>&month=<?php echo( $nextmonth ); ?>">&gt;&gt;</a>                         </td>                       </tr>                       <tr>                         <?php  foreach( $day_names as $day ) { ?>                         <td valign="top" class="calendar-day-title"><?php echo( $day ); ?></td>                         <?php } ?>                       </tr>                       <?php $p=0; foreach( $days as $d ) { if ( $p == 0) echo ( "<tr>" ); $day_style = $d->get_inmonth() ? "calendar-day" : "calendar-outmonth-day"; ?>                       <td width="13%" valign="top" class="<?php echo ( $day_style ); ?>">                         <div class="calendar-day-number"> <?php echo( $d->get_day() ); ?>                         </div>                         <div class="calendar-content"> <?php echo( $d->get_text() ); ?>                         </div></td>                       <?php $p += 1; if ( $p == 7 ) $p = 0; } ?>                       </tr>                     </table>
×
×
  • 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.