Jump to content

Looking for a PHP calendar script.


Recommended Posts

I've been looking for a calendar script for my website and have just finished going through the PHP Resource Index and Googling.

 

I need to post the times of my radio shows and club gigs.

 

There are lots of calendars out there, but they are all more complicated then what I need. I just want a display with times, dates and events. I'd like two columns, date and time in the left column, events details in the right column.

 

And then a page where I can add data on the fly from anywhere, and it just packs them under each other. It would also be cool if it would strike out passed events.

 

Oh, and it should preferably use a flat text database as opposed to SQL.

 

I thought something so simple would be all over the place... Anyone know of one?

Link to comment
Share on other sites

What you want is not to hard to program, although it is much easier to use a database then a flat file. With the database you can easily sort by date and exclude older date items etc..

Link to comment
Share on other sites

Ok here is a basic script for you.

very little error checking/features

It's just a demo for you, so you can write a better one.

 

for what you want you would need to write a date sort function to order the events, and add in a format function for strip slashes on input etc..

I didn't want to spend anymore time on it.

 

create a folder in your apache root folder stick these 3 files into it (make sure to change the owner of the txt file to apache so it can be written to.

 

in a web browser open http://localhost/foldername/index.php

 

event_list.txt

15/8/03	Pantera killing boy bands

25/8/03	Blah blah

28/8/03	My cat is vicious

20/8/03	A new event

30/8/03	SoulSe holiday

31/10/03	Johnnyv's birthday, Spooky;P

 

index.php

<HTML>

<BODY>

<?php

include("date.php");



event_input();

create_event_table();



?>

</BODY>

</HTML>

 

date.php

<?php

// events text file name used in functions

$filename = "event_list.txt";



function create_event_table()

{

// grab the contents of the file

$contents = read_event_file();

$contents = explode("n", $contents);

$contents_lenght = count($contents);

if($contents_lenght > 1)

{

$rows = "";

$i = 0;

 while($i < $contents_lenght)

 {

 $parts = explode("t", $contents[$i]);

	 if(compare_dates($parts[0]))// check if date is in future or today, if it is output it

	 {

	 $rows = $rows."<tr><td style="vertical-align: top;">$parts[0]</td><td style="vertical-align: top;">$parts[1]</td></tr>";

	 }

 $i++;

 }

echo "<table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 100%;"><tbody>n";

echo "<tr><td style="vertical-align: top;">Date</td><td style="vertical-align: top;">Event</td></tr>";

echo $rows;

echo "</tbody></table>n";

}

else

{

echo "No events in event list";

}

}



function event_input()

{

if($_POST['date'] && $_POST['event'])

{

// there is post data so input it into the file if it is a valid date

 if(compare_dates($_POST['date']))

 {

 // remove any endlines or tags that could cause problems

 $event = $_POST['event'];

 $event = ereg_replace("n"," ", $event);

 $event = ereg_replace("t"," ", $event);

 write_event_file($_POST['date'], $event);

 }

 else

 {

 echo "Invalid date!<br>";

 }

}

// make a form for adding events

echo "<FORM method="post" action="index.php">";

echo "Date: <INPUT type=text name="date" size=12>(d/m/y eg) 31/10/03)";

echo " Event: <INPUT type=text name="event" size=60>";

echo "<p><INPUT type=submit value="Add Event"></p></FORM>";

}





function read_event_file()

{

// function for reading the events text file

Global $filename;

$file = fopen($filename,"r");

$contents = fread($file, filesize($filename));

fclose($file);

return $contents;

}



function write_event_file($date, $event)

{

// function for writing to the events text file

Global $filename;

$file = fopen($filename,"a");

$line = $date."t".$event."n";

fwrite($file, $line);

fclose($file);

}



function compare_dates($date)

{

// bloody SoulSe not wanting to use a database, database date sorting much easier

$todays_date = date("d/m/y");

$todays_date = explode("/",$todays_date);

$date = explode("/",$date);

if($date[2] >= $todays_date[2])// year

{

 if($date[1] >= $todays_date[1])// month

 {

	 if($date[0] >= $todays_date[0])// day

	 {

	 return true;

	 }

	 else

	 {

	 return false;

	 }

 }

 else

 {

 return false;

 }

}

else

{

return false;

}

}



?>

Link to comment
Share on other sites

Thanks a lot, that is great.

 

I don't program at all, I was planning to learn PHP but then got really busy. So now I generally use other people's scripts.

 

I'll mess around with it and get it working, thanks again. :wink:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...