Jump to content

Event Calendar


june_c21

Recommended Posts

hi,

i had made this event calendar but the problem is how to link the date (user input) to the calendar table. So when user click on the date, it will list down the event.

 

here is my code

<?php

$host = 'localhost';
$user = 'root';
$password = '';
$dbase = 'calendars';

$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);




    $m = (!$m) ? date("m",mktime()) : "$m";
    $y = (!$y) ? date("Y",mktime()) : "$y";

if ($_SERVER['REQUEST_METHOD'] == "POST") 
{
	$eventdate = $_POST['eventdate']; 
	$event = $_POST['event']; 
	$staff_no = $_POST['staff_no'];

	$query= "INSERT INTO calendars( event,eventdate,staff_no) VALUES ('$event','$eventdate','$staff_no') ";
	$result = mysql_query($query,$dblink);

	echo "<br />";

	echo "<h2>Staff Attendance</h2>";
	// echo "This is a demo. We are not saving the event to the calendar, but you could.<br /><br />";
        // echo "We are demo-ing building the calendar, and interacting with it.<br /><br />";
        echo "<b>Staff No : </b> $staff_no </br>";
	echo "<b>Event:</b> $event<br />";
        echo "<b>Date:</b> $eventdate<br />";
	echo "</br>";
	echo "</br>";
	echo "<a href =calendar.php> Home </a>";
        exit();

}

?>
<html>
<head>
<title>Staff Attendance</title>
</head>
<body bgcolor="#FFFFFF" link="#0000CC" vlink="#0000CC">

<h2>KEV Staff Attendance</h2>

<blockquote>
<table>
<tr>
<td valign="top"><?php mk_drawCalendar($_GET['m'],$_GET['y']); ?></td>
<td width="25" nowrap><br /></td>

<form name="f" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
    <table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
    <tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add New Event</b></font></td></tr>
<tr><td><b>Staff No :</b></td><td><input type="text" name="staff_no" size="10" maxlength="10"></td></tr>
<tr><td><b>Event Date: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">mm/dd/yyyy</font></td></tr>	
<tr><td><b>Event:</b></td><td><input type="text" name="event" size="35" maxlength="128"></td></tr>
<tr><td colspan="2" align="center" bgcolor="#CCCCCC"><input type="submit" value="Add Event"></td></tr>
</table></td></tr></table></form>

</td>
</tr></table>
</blockquote>
</body>
</html>


<?php

//*********************************************************
// DRAW CALENDAR
//*********************************************************
/*
    Draws out a calendar (in html) of the month/year
    passed to it date passed in format mm-dd-yyyy 
*/
function mk_drawCalendar($m,$y)
{
    if ((!$m) || (!$y))
    { 
        $m = date("m",mktime());
        $y = date("Y",mktime());
    }

    /*== get what weekday the first is on ==*/
    $tmpd = getdate(mktime(0,0,0,$m,1,$y));
    $month = $tmpd["month"]; 
    $firstwday= $tmpd["wday"];

    $lastday = mk_getLastDayofMonth($m,$y);

?>
<table cellpadding="2" cellspacing="0" border="1">
<tr><td colspan="7" bgcolor="#CCCCDD">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr><th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th>
    <th><font size=2 ><?="$month $y"?></font></th>
    <th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th>
    </tr></table>
</td></tr>

<tr><th width=22 class="tcell">Sun</th><th width=22 class="tcell">Mon</th>
    <th width=22 class="tcell">Tues </th><th width=22 class="tcell">Wed</th>
    <th width=22 class="tcell">Thrus</th><th width=22 class="tcell">Fri</th>
    <th width=22 class="tcell">Sat</th></tr>

<?php $d = 1;
    $wday = $firstwday;
    $firstweek = true;

    /*== loop through all the days of the month ==*/
    while ( $d <= $lastday) 
    {

        /*== set up blank days for first week ==*/
        if ($firstweek) {
            echo "<tr>";
            for ($i=1; $i<=$firstwday; $i++) 
            { echo "<td><font size=2> </font></td>"; }
            $firstweek = false;
        }

        /*== Sunday start week with <tr> ==*/
        if ($wday==0) { echo "<tr>"; }

        /*== check for event ==*/  
        echo "<td class='tcell'>";
        echo "<a href=\"#\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
        echo "</td>\n";

        /*== Saturday end week with </tr> ==*/
        if ($wday==6) { echo "</tr>\n"; }

        $wday++;
        $wday = $wday % 7;
        $d++;
    }
?>

</tr></table>
Click on a date to select it and to populate the event date field on the bottom
<br />

<?php
/*== end drawCalendar function ==*/
} 




/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
    for ($tday=28; $tday <= 31; $tday++) 
    {
        $tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
        if ($tdate["mon"] != $mon) 
        { break; }

    }
    $tday--;

    return $tday;
}

?>

Link to comment
Share on other sites

i am not sure what you are wanting exactly because you are pretty vague on what you are asking but I will take a shot at helping/

 

You need to know two things:

 

1)You have to change the month and the year for the calendar before the query

 

2)You have to make a make a way to select the change needed (the month and year)

 

change the top code from

 

<?php
    $m = (!$m) ? date("m",mktime()) : "$m";
    $y = (!$y) ? date("Y",mktime()) : "$y";
?>

 

To this

 

<?php
$y = isset($_GET['y]) ? $_GET['y'] : date('Y');
$m = isset($_GET['m']) ? $_GET['m] : date('m');
?>

 

That is going to set up your sql query that will select the month and year from sql

 

Next you need to create the link that will allow users to select the month year and later the event

 

Change this 

 

<?php
echo "<a href =calendar.php> Home </a>";
?>

 

to this

 

<?php
echo "<a href=\"?y=$y&m=$m&day=\"> Home </a>";
?>

 

That should get you going in the right direction.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.