Jump to content

frostdragon

New Members
  • Posts

    3
  • Joined

  • Last visited

frostdragon's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. one last question how can i add a blank td at the end of the the calendar instead of it ending the table after the last day.
  2. Hello all, I am working on a event calendar i am taking a basic event calendar and put it into a class so i can make it event's that last for more then just one day each but i got it all working except for i can create 1 event and works fine but if it's more then 1 event it only shows the last one. thank you in advanced. <?php putenv("TZ=America/Chicago"); $time_dif = 0; date_default_timezone_set('America/Chicago'); class Calendar{ private $events = array(); private $start, $end; public function __construct($month = NULL, $year = NULL){ $this->monthNames = array("January","Febuary","March","April","May","June","July","August","September","October","November","December"); $this->weekNames = array("S","M","T","W","T","F","S"); $this->cMonth = $month; $this->cYear = $year; $this->prev_year = $this->cYear; $this->next_year = $this->cYear; $this->prev_month = $this->cMonth-1; $this->next_month = $this->cMonth+1; if($this->prev_month == 0){ $this->prev_month = 12; $this->prev_year = $this->cYear - 1; } if($this->next_month == 13){ $this->next_month = 1; $this->next_year = $this->cYear + 1; } $this->currentmonth = date('n'); $this->currentyear = date('Y'); $this->date = getdate(mktime(0,0,0,$this->cMonth,1,$this->cYear)); $this->timestamp = mktime(0,0,0,$this->cMonth,1,$this->cYear); $this->maxday = date("t", $this->timestamp); $this->thismonth = getdate($this->timestamp); $this->startday = $this->thismonth['wday']; $this->startday2 = date('N', mktime(0,0,0,$this->currentmonth,1,$this->currentyear)) - 0; $this->today = date("j"); } public function addEvent(DateTime $eventStart, DateTime $eventEnd, $description = null){ if($description === NULL){ end($this->events); $description = "Event " . (key($this->events) === null ? 0 : key($this->events) + 1); } $this->events[] = array('start' => $eventStart->format('Y-m-d'), 'end' => $eventEnd->format('Y-m-d'), 'description' => $description); } public function printCalendar(){ $output = '<table width="196" border="1" cellpadding="0" cellspacing="0">'; $output .= ' <tr>'; $output .= ' <td colspan="7">'; $output .= ' <table width="100%" border="0" cellpadding="0" cellspacing="0">'; $output .= ' <tr>'; $output .= ' <td align="center" width="10%">«</td>'; $output .= " <td align='center' width='80%'><strong>{$this->monthNames[$this->cMonth - 1]} {$this->cYear}</strong></td>"; $output .= ' <td align="center" width="10%">»</td>'; $output .= ' </tr>'; $output .= ' </table>'; $output .= ' </td>'; $output .= ' </tr>'; $output .= ' <tr>'; foreach($this->weekNames as $v){ $output .= " <td align='center' width='28' class='txt' background='#999999'><strong>$v</strong></td>"; } $output .= ' </tr>'; for($i=0; $i<($this->maxday+$this->startday); $i++){ if($this->cMonth < 10){ $month_format = "0$this->cMonth"; }else{ $month_format = $this->cMonth; } $cali = ($i - $this->startday + 1); if($cali < 10){ $day_format = "0".$cali.""; }else{ $day_format = $cali; } if(($i % 7) == 0) $output .= "</tr>\n"; $ev = ''; foreach($this->events as $event){ $date = $this->cYear."-".$this->cMonth."-".$cali; if($event['start'] <= $date && $event['end'] >= $date){ $ev = ''; $ev .= "<td align='center' bgcolor='#00FF00' title='".$event['description']."'>$cali</td>"; }elseif($cali == $this->today && $this->currentmonth == $this->cMonth && $this->currentyear == $this->cYear){ $ev = ''; $ev .= "<td align='center' bgcolor='red' title='Today'>$cali</td>"; }elseif($i <$this->startday){ $ev = ''; $ev .= "<td> </td>"; }else{ $ev = ''; $ev .= "<td align='center' bgcolor='white'>$cali</td>"; } } $output .= $ev; if(($i % 7) == 6) $output .= "</tr>\n"; } $output .= '</table>'; unset($calendar); return $output; } } $cal = new Calendar('03', '2014'); $cal->addEvent(new DateTime('2014-03-12'), new DateTime('2014-03-15'), 'Testing 1'); $cal->addEvent(new DateTime('2014-03-17'), new DateTime('2014-03-19'), 'Testing 2'); $cal->addEvent(new DateTime('2014-03-20'), new DateTime('2014-03-22'), 'Testing 3'); echo $cal->printCalendar(); ?>
×
×
  • 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.