PHP / MYSQL Help with Events Calendar output

Heya Guys,
Im hoping someone can help me or point me in the right direction for the following;

I am currently building a reservations system for a friend and the admin area works a treat, I downloaded myEvent Calendar in the hope this would forfill the calendar aspect of the admin area for each cottage but im finding it hard knowing how to link the mysql data into the existing framework for the myEvents Calendar?

it requires that the so called event be displayed like:

$thisCal->addEvent(date($newcheckinDate),
“Holiday Let Reservation, Mill Wheel Bob Johnson Family 01933 526655”,
“10:45 AM”,
“Reservation for 5 days”);

which is also rigged to a function somehow?

I have data to be rendered from mysql which I originally thought would nicely pump the variables etc into the section on the code displaying it how it should but as its being called from a function im not sure how id get it to work.

i really hope someone can help as its driving me around the twist.

please see below for example code:

THIS IS A Snippet From THE CALENDAR PAGE:

[php]<?
require(“myEventsCalendar.php”);

$thisCal = new MyEventsCalendar("/details.php");

$thisCal->setOverlibPath("/overlib.js");

$todaysDate = date(“d”) . “-” . date(“m”) . “-” . date(“Y”);

$sqlCommand = “SELECT * FROM reservations”;
$query = mysqli_query($connection, $sqlCommand) or die (mysqli_error());
$reservationDisplay = ‘’;
while ($row = mysqli_fetch_array($query)) {
$reservationid = $row[“id”];
$propertyname = $row[“propertyname”];
$checkindate = $row[“checkindate”];
$checkoutdate = $row[“checkoutdate”];
$checkintime = $row[“checkintime”];
$checkouttime = $row[“checkouttime”];
$customerref = $row[“customerref”];
$duration = $row[“duration”];
$pets = $row[“pets”];
$f = $thisCal->addEvent;
$newcheckinDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3-$2-$1",$checkindate);
$reservationDisplay .= ‘’ .$f. ‘(date(’ .$newcheckinDate. ‘),“Holiday Let Reservation, Mill Wheel Bob Johnson Family 01933 526655”,“10:45 AM”,“Reservation for 5 days”);’;
}
mysqli_free_result($query);

$reservationDisplay; <?php /*?>i was hoping that this variable would pump out what was required below<?php */?>

<?php /*?>This is how the data needs to be rendered<?php */?>

[php]
$thisCal->addEvent(date($newcheckinDate),
“Holiday Let Reservation, Mill Wheel Bob Johnson Family 01933 526655”,
“10:45 AM”,
“Reservation for 5 days”);

$thisCal->addEvent(date(“03-10-2013”),
“Holiday Let Reservation, Mill Wheel Bob Johnson Family 01933 526655”,
“10:45 AM”,
“Reservation for 5 days”);

if($_GET[“m”] && $_GET[“y”]) {
$thisCal->setMonth(trim($_GET[“m”]));
$thisCal->setDay(1);
$thisCal->setYear(trim($_GET[“y”]));
$thisCal->generateHTML(“adminhome.php?calendar=start”);
}
else {
$thisCal->setMonth(date(“m”));
$thisCal->setDay(1);
$thisCal->setYear(date(“Y”));
$thisCal->generateHTML(“adminhome.php?calendar=start”);
}

?>[/php]

========= Here is the MyEventsCalendar Page with the relevent functions etc from MyEventsCalendar =====================

Sorry for the long page etc

[php]<?php

/*

  • myEventsCalendar Class

**/

class myEventsCalendar
{
var $month = 0, $day = 0, $year = 0;
var $Months = Array(“January”, “February”,“March”, “April”, “May”, “June”, “July”,
“August”, “September”, “October”, “November”, “December”);

var $overlibPath = “”, $eventsId = array(), $eventsData = array(), $eventsCount = 0;

var $formDetailsAction = “”;

function myEventsCalendar($thisFormDetailsAction)
{
//set the destination to view event detail
$this->formDetailsAction = $thisFormDetailsAction;

//set additional parameters if necessary
//need to set month, day, and year
//before generating HTML
$this->eventsData = array();
$this->eventsCount = count($this->eventsData);
}

/*Append the parameter element to the vector/
function addEvent($thisDate,$thisEventTitle, $thisEventTime, $thisEventDescription)
{
if(!empty($thisDate))
{
$dateArr = explode("-",$thisDate);
$mIndex = intVal($dateArr[0]);
$dIndex = intVal($dateArr[1]);
$yIndex = intVal($dateArr[2]);

$dateIndex = $mIndex . “-” . $dIndex . “-” . $yIndex;

if(!$this->eventsId[$dateIndex]) {
$this->eventsId[$dateIndex] = 1;
}
else {
$numOfEvents = intVal($this->eventsId[$dateIndex]);
$numOfEvents = $numOfEvents + 1;
$this->eventsId[$dateIndex] = $numOfEvents;
}

$titleIdx = “title” . $this->eventsId[$dateIndex];
$timeIdx = “time” . $this->eventsId[$dateIndex];
$descrIdx = “description” . $this->eventsId[$dateIndex];

$this->eventsData[$dateIndex][$titleIdx] = $thisEventTitle;
$this->eventsData[$dateIndex][$timeIdx] = $thisEventTime;
$this->eventsData[$dateIndex][$descrIdx] = $thisEventDescription;

$this->eventsCount = count($this->eventsData);

return true;
}
else
return false;
}

function setMonth($thisMonth)
{
$this->month = $thisMonth;
}

function setYear($thisYear)
{
$this->year = $thisYear;
}

function setDay($thisDay)
{
$this->day = $thisDay;
}

function setOverlibPath($thisPath)
{
$this->overlibPath = $thisPath;
}

function getDayOfMonth($month, $day, $year)
{
$myresult = date(“l”, mktime(0, 0, 0, $month, $day, $year));
return $myresult;
}

function getMonthName($month, $day, $year)
{
$myresult = date(“F”, mktime(0, 0, 0, $month, $day, $year));
return $myresult;
}

function getWeekDay($day)
{
$myresult = 0;

switch ($day) {
case “Monday”: $myresult = 1; break;
case “Tuesday”: $myresult = 2; break;
case “Wednesday”: $myresult = 3; break;
case “Thursday”: $myresult = 4; break;
case “Friday”: $myresult = 5; break;
case “Saturday”: $myresult = 6; break;
case “Sunday”: $myresult = 7; break;
}
return $myresult;
}

function getNumDaysOfMonth($month, $year)
{
// non-leap year
$nonleap = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

// leap year
$leap = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

$isLeap = false ;

if (($year % 4) == 0) {
if (($year % 100) == 0 && ($year % 400) != 0) {
$isLeap = false;
} else {
$isLeap = true;
}
} else {
$isLeap = false;
}

if($isLeap == true) {
return $leap[$month - 1];
} else {
return $nonleap[$month - 1];
}
}

function isToday($month,$day,$year)
{
if( ($month == intval(date(“m”))) && ( $day == intval(date(“d”)))
&& ($year == intval(date(“Y”)))){
return true;
} else {
return false;
}

}

//Some book keeping
function getDetails($thisDate, $allDetails)
{
$counter = 1;
$titleIdx = “title” . $counter;
$timeIdx = “time” . $counter;
$descrIdx = “description” . $counter;
$result = “”;

//prepare overlib data
while($this->eventsData[$thisDate][$titleIdx] != “”) {

if($counter > 1){ $result .= “

”; }

$result .= "Reservation Details: " . $this->eventsData[$thisDate][$titleIdx];
$result .= "
Check in Time: " . $this->eventsData[$thisDate][$timeIdx];
if($allDetails) {
$result .= "
Summary: " . $this->eventsData[$thisDate][$descrIdx];
}

$counter = $counter + 1;
$titleIdx = “title” . $counter;
$timeIdx = “time” . $counter;
$descrIdx = “description” . $counter;

}
return $result;
}

//This function takes the parameters month, day, and year and
//queries the global array with the event information for any
//relevant events that occur on that date
function outputDay($thisMonth,$thisDay,$thisYear)
{
$thisDate = $thisMonth . “-” . $thisDay . “-” . $thisYear;

if($this->eventsId[$thisDate]) {
$overlib = $this->getDetails($thisDate, false);
$details = $this->getDetails($thisDate, true);

echo "

";

} else {
echo $thisDay;
}
}

//This function loops through the days available in the month and
//outputs each day accordingly. If an event is found, then it will
//add a link for that day which shows a preview on an overlib effect,
// and upon click, it takes the user to the corresponding details page
function generateHTML($toUrl)
{
//configure top navigation
$nextMonth = $this->month + 1;
$nextYear = $this->year;

if($nextMonth == 13) {
$nextMonth = 1;
$nextYear = $this->year + 1;
}

$prevMonth = $this->month - 1;
$prevYear = $this->year;

if($prevMonth == 0) {
$prevMonth = 12;
$prevYear = $this->year - 1;
}

//output overlib js path
echo “<script type=“text/javascript” src=”" . $this->overlibPath . “”>";

//output overlib div
echo “<div class=‘EventOverlay’ id=“overDiv” style=“position:absolute; visibility:hidden; z-index:1000;”>”;

//output detail form
echo “<form name=“jump_to_details” action=”" . $this->formDetailsAction . “” “;
echo “method=“POST”>\n”;
echo “<input type=“hidden” name=“event” value=””>\n";
echo “”;

//output javascript submit form (handler) method
echo “<script language=“Javascript”>\n”;
echo “\n”;
echo “function goToDetails(thisEvent) {\n”;
echo “document.jump_to_details.event.value=thisEvent\n”;
echo “document.jump_to_details.submit()\n”;
echo “}\n”;
echo “\n”;

//configure bottom navigation
$gobackwards = $toUrl . “&m=” . $prevMonth . “&y=” . $prevYear;
$goforward = $toUrl . “&m=” . $nextMonth . “&y=” . $nextYear;

echo “

”;
echo “<div class=‘CottageTitle’”;
echo “

Mill Wheel Cottage Reservations Calendar

”;
echo “
”;
echo “”;
echo “<table style=‘background-color:#f3f3f3; padding:10px;’ cellpadding=“10”>\n”;
echo “\n”;
echo " <td colspan=“7”>";
echo " <table style=‘background-color:#fff; border: 1px solid #ccc; padding:10px;’ cellpadding=“0” width=“100%”>\n";
echo " \n";
echo " <td width=“5%”><a href="" . $gobackwards .
“”>Previous Month\n";
echo " <td width=“90%” align=“center”>" .
$this->getMonthName($this->month , 1 , $this->year) .
" " . $this->year . “
\n”;
echo " <td width=“5%”><a href="" . $goforward .
“”>Previous Month\n";
echo " \n";
echo " \n";
echo " “;
echo “\n”;
echo “\n”;
echo " Sun\n”;
echo " Mon\n";
echo " Tue\n";
echo " Wed\n";
echo " Thu\n";
echo " Fri\n";
echo " Sat\n";
echo “\n”;

$newrow = 1;
$monLoop = $this->getNumDaysOfMonth($this->month, $this->year);
$startDay = intval($this->getWeekDay($this->getDayOfMonth(
$this->month, 1, $this->year)));
$begin = false;

for($i=1; $i <= $monLoop; $i++) {

if($startDay == 7) {
$begin = true;
}

if($newrow == 8 || $newrow == 1) {
echo “

”;
$newrow = 1;
}

if($begin == true) {

if( $this->isToday($this->month, $i, $this->year)) {
echo "

<font color=“red”>";
$this->outputDay(intVal($this->month), intVal($i), intVal($this->year));
echo “”;
} else {
echo " ";
$this->outputDay(intVal($this->month), intVal($i), intVal($this->year));
echo “”;
}
}

if($i <= $startDay && $begin == false ) {

echo "

";

if($i == $startDay) {
$begin = true;
$i = 0;
}
}

$newrow++;

if($newrow == 8) {
echo “

”;
}

}

echo “\n”;

echo “”;
echo “”;
}

}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service