PHP forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
March 2024
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Calendar Calendar

Latest topics
» Kabaddi, Kabaddi, Kabaddi, Kabaddi......PHP?
Calendar - monthly/yearly view in php - continue EmptyFri Jul 22, 2011 1:37 pm by shyamsunder

» Thousands of Free PHP Scripts Recommended
Calendar - monthly/yearly view in php - continue EmptyWed May 18, 2011 10:33 am by bizboy12

» PHP form validation problem?
Calendar - monthly/yearly view in php - continue EmptyWed Jan 12, 2011 1:25 pm by simy202

» string wrap
Calendar - monthly/yearly view in php - continue EmptySat Aug 02, 2008 2:06 pm by scvinodkumar

» retrieving current date rows
Calendar - monthly/yearly view in php - continue EmptyTue Jul 15, 2008 3:25 am by scvinodkumar

» number in words
Calendar - monthly/yearly view in php - continue EmptyTue Apr 29, 2008 3:10 pm by scvinodkumar

» Simple PHP Form Field Generator
Calendar - monthly/yearly view in php - continue EmptyFri Apr 25, 2008 12:28 pm by scvinodkumar

» PHP password generator
Calendar - monthly/yearly view in php - continue EmptyFri Apr 18, 2008 7:24 pm by scvinodkumar

» PHP Script to Extract Email Address from any text
Calendar - monthly/yearly view in php - continue EmptyFri Apr 18, 2008 7:18 pm by scvinodkumar

Search
 
 

Display results as :
 


Rechercher Advanced Search

Affiliates
free forum
 


Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Calendar - monthly/yearly view in php - continue

Go down

Calendar - monthly/yearly view in php - continue Empty Calendar - monthly/yearly view in php - continue

Post  scvinodkumar Mon Feb 25, 2008 7:42 pm

/*
Generate the HTML for a given month
*/
function getMonthHTML1($m, $y, $showYear = 1)
{
$s = "";

$a = $this->adjustDate($m, $y);
$month = $a[0];
$year = $a[1];

$daysInMonth = $this->getDaysInMonth($month, $year);
$date = getdate(mktime(12, 0, 0, $month, 1, $year));

$first = $date["wday"];
$monthName = $this->monthNames[$month - 1];

$prev = $this->adjustDate($month - 1, $year);
$next = $this->adjustDate($month + 1, $year);

if ($showYear == 1)
{
$prevMonth = $this->getCalendarLink1($prev[0], $prev[1]);
$nextMonth = $this->getCalendarLink1($next[0], $next[1]);
}
else
{
$prevMonth = "";
$nextMonth = "";
}

$header = $monthName . (($showYear > 0) ? " " . $year : "");

$s .="<table align=\"left\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\"><tr><td align=\"left\">";
$s .= "<table class=\"miniCalTable1\" width=\"100%\" cellpadding=\"15\" cellspacing=\"5\" align=\"center\" border=\"0\">\n";
$s .= "<tr>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalTitle\">" . (($prevMonth == "") ? "&nbsp;" : "<a href=\"$prevMonth\">&lt;&lt;</a>") . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalTitle\" colspan=\"5\"><a href=".CalRoot."/index.php?com=calendar&year=".$year."&month=".$month."><strong>$header</strong></a></td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalTitle\">" . (($nextMonth == "") ? "&nbsp;" : "<a href=\"$nextMonth\">&gt;&gt;</a>") . "</td>\n";
$s .= "</tr>\n";

$s .= "<tr>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay+1)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay+2)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay+3)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay+4)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay+5)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayFullNames[($this->startDay+6)%7] . "</td>\n";
$s .= "</tr>\n";


$query = "SELECT DISTINCT e.StartDate FROM " . HC_TblPrefix . "events e
LEFT JOIN " . HC_TblPrefix . "eventcategories ec ON (e.PkID = ec.EventID)
LEFT JOIN " . HC_TblPrefix . "locations as l ON (e.LocID = l.PkID)
WHERE e.IsActive = 1 AND e.IsApproved = 1 AND
(e.StartDate BETWEEN '" . date("Y-m-d", mktime(0,0,0,$month,1,$year)) .
"' AND '" . date("Y-m-d", mktime(0,0,0,$month+1,0,$year)) . "')";
$query = $query . " ORDER BY StartDate";
$result = doQuery($query);

//$events[];
if(hasRows($result)){
while($row = mysql_fetch_row($result)){
$events[] = stampToDate($row[0], "d");
}//end while
}//end if

// We need to work out what date to start at so that the first appears in the correct column
$d = $this->startDay + 1 - $first;
while ($d > 1)
{
$d -= 7;
}

// Make sure we know when today is, so that we can use a different CSS style
$today = getdate(time());

while ($d <= $daysInMonth)
{
$s .= "<tr>\n";

for ($i = 0; $i < 7; $i++)
{

$class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? "miniCalToday" : "miniCalFiller";
if(!empty($events))
{
if(in_array($d, $events)){
$class="miniCalEvents";
$class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? "miniCalToday" : "miniCalEvents";
}
}
//$s .= "<td class=\"$class\" align=\"right\" valign=\"top\">";
if ($d > 0 && $d <= $daysInMonth)
{
$link = $this->getDateLink($d, $month, $year);
$s .= "<td class=\"$class\" align=\"right\" valign=\"top\" onclick=\"window.location.href='$link'\">";
$s .= $d;
$s .= "</td>\n";
}
else
{
$s .= "<td class=\"$class\" align=\"right\" valign=\"top\" onclick=\"window.location.href='$link'\">";
$s .= "&nbsp;";
$s .= "</td>\n";
}
//$s .= "</td>\n";
$d++;
}
$s .= "</tr>\n";
}

$s .= "</table>\n";
$s .= "</td></tr></table>";

return $s;
}

/*
Generate the HTML for a given year
*/
function getYearHTML($year)
{
$s = "";
$prev = $this->getCalendarLink(0, $year - 1);
$next = $this->getCalendarLink(0, $year + 1);

$s .= "<table align=\"left\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\"><tr><td align=\"left\">";
$s .= "<table class=\"miniCalTable\" border=\"0\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\" width=\"100%\" style=\"border:1px solid #d6eaaa;\">\n";
$s .= "<tr style=\"border-bottom:1px solid #d6eaaa;\">";
$s .= "<td align=\"center\" valign=\"top\" align=\"left\">" . (($prev == "") ? "&nbsp;" : "<a href=\"$prev\">&lt;&lt;</a>") . "</td>\n";
$s .= "<td class=\"calendarHeader\" valign=\"top\" align=\"center\"><strong>" . (($this->startMonth > 1) ? $year . " - " . ($year + 1) : $year) ."</strong></td>\n";
$s .= "<td align=\"center\" valign=\"top\" align=\"right\">" . (($next == "") ? "&nbsp;" : "<a href=\"$next\">&gt;&gt;</a>") . "</td>\n";
$s .= "</tr>\n";
$s .= "<tr>";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(0 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(1 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(2 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "</tr>\n";
$s .= "<tr>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(3 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(4 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(5 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "</tr>\n";
$s .= "<tr>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(6 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(7 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(8 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "</tr>\n";
$s .= "<tr>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(9 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(10 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "<td class=\"miniCalTable\" valign=\"top\">" . $this->getMonthHTML(11 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "</tr>\n";
$s .= "</table>\n";
$s .= "</td></tr></table>";

return $s;
}

/*
Adjust dates to allow months > 12 and < 0. Just adjust the years appropriately.
e.g. Month 14 of the year 2001 is actually month 2 of year 2002.
*/
function adjustDate($month, $year)
{
$a = array();
$a[0] = $month;
$a[1] = $year;

while ($a[0] > 12)
{
$a[0] -= 12;
$a[1]++;
}

while ($a[0] <= 0)
{
$a[0] += 12;
$a[1]--;
}

return $a;
}

/*
The start day of the week. This is the day that appears in the first column
of the calendar. Sunday = 0.
*/
var $startDay = 0;

/*
The start month of the year. This is the month that appears in the first slot
of the calendar in the year view. January = 1.
*/
var $startMonth = 1;

/*
The labels to display for the days of the week. The first entry in this array
represents Sunday.
*/
var $dayNames = array("S", "M", "T", "W", "T", "F", "S");

var $dayFullNames = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

/*
The labels to display for the months of the year. The first entry in this array
represents January.
*/
var $monthNames = array("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December");


/*
The number of days in each month. You're unlikely to want to change this...
The first entry in this array represents January.
*/
var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

}


$cal = new Calendar;
if(isset($_REQUEST['year']) && isset($_REQUEST['month']))
echo $cal->getMonthView($_REQUEST['month'],$_REQUEST['year']);
elseif(isset($_REQUEST['year']))
echo $cal->getYearView($_REQUEST['year']);
else
echo $cal->getCurrentYearView();
?>

scvinodkumar
Admin

Posts : 40
Join date : 2008-01-30

https://solutions.aforumfree.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum