Home arrow PHP arrow Page 5 - A Useful Event Calendar Written In PHP
PHP

A Useful Event Calendar Written In PHP


An events calendar allows you to keep a schedule of your appointments, etc. In this article Mitchell creates an extremely useful events calendar using only PHP.

Author Info:
By: Mitchell Harper
Rating: 4 stars4 stars4 stars4 stars4 stars / 198
June 10, 2002
TABLE OF CONTENTS:
  1. · A Useful Event Calendar Written In PHP
  2. · The event calendars logic
  3. · Creating the calendar
  4. · Highlighting days with events
  5. · Adding an event
  6. · Conclusion

print this article
SEARCH DEVARTICLES

A Useful Event Calendar Written In PHP - Adding an event
(Page 5 of 6 )

If a particular day is selected, then we also show a form to add a new event to the current day under the list of events. The form is just basic HTML and looks like this:

The form to add a new event

When the new event form is submitted, the AddPost function is called with the selected day, month and year, as well as the name and details of the post:

function AddPost($Day, $Month, $Year, $Name, $Desc)

AddPost simply opens the events file and output the details of the new post, like this:

// Add this event to the events file
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "a")
or die("<span class='error'>ERROR: Couldn't open events file to write event.</span>");

@fputs($fp, "$Month $Day $Year\r\n$Name\r\n$Desc\r\n")
or die("<span class='error'>ERROR: Couldn't write to events file.</span>");

@fclose($fp);


Deleting an event
As you may've noticed in the screenshot above, each event is displayed with a "Remove" link beneath it. This link calls cal.php with the details of the post to be deleted.

The DelPost function handles the deletion of an event, but because we're working with a file, we read all events in and then only write-out the ones that aren't marked for deletion by calling the AddPost function. We do this by comparing the selected event with all events in the events file:

for($i = 0; $i < sizeof($arrEvents); $i+=3)
{
if(!($arrEvents[$i] == $EventDate && $arrEvents[$i+1] == $Name && $arrEvents[$i+2] == $Desc))
{
// This entry hasn't been chosen to be deleted.
// We will add it back to the events
if($arrEvents[$i+1] != "" && $arrEvents[$i+2] != "")
{
// Start by getting the date of the post
$thisDate = explode(" ", $arrEvents[$i]);
AddPost($thisDate[1], $thisDate[0], $thisDate[2], $arrEvents[$i+1], $arrEvents[$i+2]);
}
}
}

blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials