April 2017
SunMonTueWedThuFriSat
      1
2345678
9101112131415
16171819202122
23242526272829
30      

Calendar Calendar

Latest topics
» Kabaddi, Kabaddi, Kabaddi, Kabaddi......PHP?
Fri Jul 22, 2011 1:37 pm by shyamsunder

» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12

» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202

» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar

» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar

» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar

» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar

» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar

» PHP Script to Extract Email Address from any text
Fri 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

View previous topic View next topic Go down

Calendar - monthly/yearly view in php

Post  scvinodkumar on Mon Feb 25, 2008 7:41 pm

<?php
class Calendar
{
/*Constructor for the Calendar class*/
function Calendar()
{
}
/*Get the array of strings used to label the days of the week. This array contains seven
elements, one for each day of the week. The first entry in this array represents Sunday. */
function getDayNames()
{
return $this->dayNames;
}
/* Set the array of strings used to label the days of the week. This array must contain seven
elements, one for each day of the week. The first entry in this array represents Sunday. */
function setDayNames($names)
{
$this->dayNames = $names;
}
/* Get the array of strings used to label the months of the year. This array contains twelve
elements, one for each month of the year. The first entry in this array represents January. */
function getMonthNames()
{
return $this->monthNames;
}
/* Set the array of strings used to label the months of the year. This array must contain twelve
elements, one for each month of the year. The first entry in this array represents January. */
function setMonthNames($names)
{
$this->monthNames = $names;
}
/* Gets the start day of the week. This is the day that appears in the first column
of the calendar. Sunday = 0.*/
function getStartDay()
{
return $this->startDay;
}
/* Sets the start day of the week. This is the day that appears in the first column
of the calendar. Sunday = 0. */
function setStartDay($day)
{
$this->startDay = $day;
}
/* Gets the start month of the year. This is the month that appears first in the year
view. January = 1.*/
function getStartMonth()
{
return $this->startMonth;
}
/* Sets the start month of the year. This is the month that appears first in the year
view. January = 1.*/
function setStartMonth($month)
{
$this->startMonth = $month;
}
/* Return the URL to link to in order to display a calendar for a given month/year.
You must override this method if you want to activate the "forward" and "back"
feature of the calendar.
Note: If you return an empty string from this function, no navigation link will
be displayed. This is the default behaviour.
If the calendar is being displayed in "year" view, $month will be set to zero. */
function getCalendarLink($month, $year)
{
return CalRoot."/index.php?com=calendar&year=".$year;
}

function getCalendarLink1($month, $year)
{
return CalRoot."/index.php?com=calendar&year=".$year."&amp;month=".$month;
}
/* Return the URL to link to for a given date.
You must override this method if you want to activate the date linking
feature of the calendar.
Note: If you return an empty string from this function, no navigation link will
be displayed. This is the default behaviour. */
function getDateLink($day, $month, $year)
{
return CalRoot."/index.php?year=".$year."&amp;month=".$month."&amp;day=".$day;
}
/* Return the HTML for the current month */
function getCurrentMonthView()
{
$d = getdate(time());
return $this->getMonthView($d["mon"], $d["year"]);
}
/* Return the HTML for the current year */
function getCurrentYearView()
{
$d = getdate(time());
return $this->getYearView($d["year"]);
}
/* Return the HTML for a specified month */
function getMonthView($month, $year)
{
return $this->getMonthHTML1($month, $year);
}
/*Return the HTML for a specified year */
function getYearView($year)
{
return $this->getYearHTML($year);
}
/********************************************************************************
The rest are private methods. No user-servicable parts inside.
You shouldn't need to call any of these functions directly.
*********************************************************************************/
/* Calculate the number of days in a month, taking into account leap years. */
function getDaysInMonth($month, $year)
{
if ($month < 1 || $month > 12)
{
return 0;
}
$d = $this->daysInMonth[$month - 1];
if ($month == 2)
{
// Check for leap year
// Forget the 4000 rule, I doubt I'll be around then...
if ($year%4 == 0)
{
if ($year%100 == 0)
{
if ($year%400 == 0)
{
$d = 29;
}
}
else
{
$d = 29;
}
}
}
return $d;
}
/* Generate the HTML for a given month */
function getMonthHTML($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->getCalendarLink($prev[0], $prev[1]);
$nextMonth = $this->getCalendarLink($next[0], $next[1]);
}
else
{
$prevMonth = "";
$nextMonth = "";
}

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

$s .= "<table class=\"miniCalTable\" cellpadding=\"2\" cellspacing=\"2\" align=\"left\" border=\"0\">\n";
$s .= "<tr>\n";
$s .= "<td align=\"center\" valign=\"top\">" . (($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.">$header</a></td>\n";
$s .= "<td align=\"center\" valign=\"top\">" . (($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->dayNames[($this->startDay)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayNames[($this->startDay+1)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayNames[($this->startDay+2)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayNames[($this->startDay+3)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayNames[($this->startDay+4)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayNames[($this->startDay+5)%7] . "</td>\n";
$s .= "<td align=\"center\" valign=\"top\" class=\"miniCalDOW\">" . $this->dayNames[($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";

return $s;
}

continue...

scvinodkumar
Admin

Posts : 40
Join date : 2008-01-30

View user profile http://solutions.aforumfree.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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