select all Sundays red in a calendar class?
Posted: Wed Mar 05, 2014 8:12 am
Hello,
I am new to PHP.
I would be very grateful if anyone could help me how I could get all Sundays in my calendar with red colour.
Thanks in advance.
Here is my calendar class:
And my stylesheet:
Thanks.
I am new to PHP.
I would be very grateful if anyone could help me how I could get all Sundays in my calendar with red colour.
Thanks in advance.
Here is my calendar class:
Code: Select all
<?php
class CDisplayAlmanac
{
public $day;
public $month;
public $year;
public $timestamp;
private $prevMonth;
private $nextMonth;
private $dayOfMonth;
private $fullMonth;
private $noMonth;
private $firstDayTimeStamp;
private $dateArray;
private $firstDay;
private $lengthMonth;
private $totalSlots;
private $endSlots;
private $addToEnd;
private $gridLength;
private $displayHTML;
// create values for the almanac
public function __construct($d = 0, $m = 0, $y = 0)
{
if($d == 0)
{
$this->day = date("j");
}
else
{
$this->day = $d;
}
if($m == 0)
{
$this->month = date("n");
}
else
{
$this->month = $m;
}
if($y == 0)
{
$this->year = date("Y");
}
else
{
$this->year = $y;
}
// create values
$this->prevYear= $this->year;
$this->nextYear= $this->year;
$this->prevMonth= $this->month-1;
$this->nextMonth= $this->month+1;
if ($this->prevMonth == 0 )
{
$this->prevMonth= 12;
$this->prevYear = $this->year - 1;
}
if ($this->nextMonth == 13 )
{
$this->nextMonth = 1;
$this->nextYear = $this->year + 1;
}
$this->timestamp = mktime(0,0,0,$this->month,$this->day,$this->year);
$this->dayOfMonth = date('j',$this->timestamp);
$this->fullMonth = date('F',$this->timestamp);
$this->noMonth = date('n',$this->timestamp);
$this->firstDayTimeStamp = mktime(0,0,0,$this->noMonth,1,$this->year);
$this->dateArray = getdate($this->firstDayTimeStamp );
$this->firstDay = $this->dateArray['wday'];
if($this->firstDay == 0)
{
$this->firstDay = 6;
}
else
{
$this->firstDay--;
}
$this->lengthMonth = date('t',$this->timestamp);
$this->totalSlots = $this->firstDay + $this->lengthMonth;
$this->totalSlots--;
$this->endSlots = $this->totalSlots % 7;
$this->addToEnd = 7 - $this->endSlots;
$this->gridLength = $this->totalSlots + $this->addToEnd;
}
// create table and its contents
public function displayAlmanac()
{
$this->displayHTML = "<table>";
$this->displayHTML .= "<tr><td colspan=\"7\" class=\"almanac\"><img src='img/general.jpg' alt='image of a general'/>{$this->fullMonth} - {$this->year}</td></tr>";
$this->displayHTML .= "<tr class=\"mainCal\"><td>Mon</td><td>Tue</td><td>Wed</td><td>Thur</td><td>Fri</td><td>Sat</td>";
$this->displayHTML .= "<td class='sunday'>Sun</td></tr>";
for ($i=0; $i<$this->gridLength; $i++)
{
if(($i % 7) == 0 )
{
$this->displayHTML .= "<tr>";
}
// days in unselected month
if($i < $this->firstDay || ($i) > ($this->totalSlots))
{
$this->displayHTML .= "<td class='notused'></td>";
}
else
{
if(($i - $this->firstDay + 1) == $this->day)
{
$this->displayHTML .= "<td class='sunday'>". ($i - $this->firstDay + 1) . "</td>";
}
else
{
$this->displayHTML .= "<td>". ($i - $this->firstDay + 1) . "</td>";
}
}
if(($i % 7) == 6 )
{
$this->displayHTML .= "</tr>";
}
}
$this->displayHTML .= "<tr class=\"mainCal\">";
$this->displayHTML .= "<td><a href=\"{$_SERVER['PHP_SELF']}?month={$this->prevMonth}&year={$this->prevYear}\"><</a></td>";
$this->displayHTML .= "<td colspan=\"5\">Choose Month</td>";
$this->displayHTML .= "<td><a href=\"{$_SERVER['PHP_SELF']}?month={$this->nextMonth}&year={$this->nextYear}\">></a></td>";
$this->displayHTML .= "</tr></table>";
return $this->displayHTML;
}
}
?>
Code: Select all
table
{
font-family: Helvetica, arial;
font-size: 22px;
}
th, td
{
padding:20px;
background-color: #fff;
}
tr:nth-of-type(odd)
{
color:#000;
}
.almanac
{
text-align:center;
}
tr.mainCal td
{
width:30px;
text-align:center;
background-color: #C7CCDF;
}
table a:link
{
text-decoration:none;
color:#fff;
background-color: #000;
padding: 10px;
}
table a:hover
{
color:#6C3;
}
.pickedDay
{
border:2px solid #f00;
display:inline-block;
padding:2px;
}
.sunday
{
color: #f00;
}