Working on a flat file bookings calendar(an old open source)have made a few mods but am now totally stuck(not good enough to do this particular mod)
if anyone can help I will provide a link for free use of the script.
Have a form which passes values to a file for writing to a flat file database and am wanting to alter code to allow input of a "from" date to a "to" date to allow for a single entry for a period of days or weeks or whatever.
The file presently only writes data for an invidual day thus making it neccesary to add an entry for every single day.
formfield names on form for the to dates will be name2 etc
link is here http://www.ethicalweb.com.au/calendar/calendar.php
I am not asking anyone to do my work for me as its just something I am playing around with and will give away for free if anyone wants it. Any help much appreciated.
needs to be able to have user enter a date of arrival to departure and reflect dates. ie. 13 apr - 21 apr and add an entry for each individual day (13,14,15,16,17,18,19,20,21)
following code presently only handles one day at a single entry.
[code]
<html>
<head>
<title>Flat Calendar: Add</title>
<?php
if(ereg("[a-zA-Z0-9]",$event))
{
?>
<META HTTP-EQUIV="refresh" content="1;URL=../calendar.php">
<LINK rel="stylesheet" type="text/css" name="style" href="../calendar.css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
//returns highest key in the database
function getMaxKey($db) {
$maxKey = 0;
$sortby = "event_key";
$result = $db->getall();
foreach($result as $item){
$key = $item["event_key"];
if($key > $maxKey)
$maxKey = $key;
}
return $maxKey;
}
// Include the FFDB library
include("../ffdb.inc.php");
//open db or create new db
$db = new FFDB();
if (!$db->open("../calendar"))
{
// Define the database shema.
// Note that the "last_name" field is our key.
$schema = array(
array("event_key", FFDB_INT, "key"),
array("event_name", FFDB_STRING),
array("event_description", FFDB_STRING),
array("event_submitted_by", FFDB_STRING),
array("event_month", FFDB_STRING),
array("event_day", FFDB_INT),
array("event_year", FFDB_INT)
);
// Try and create it...
if (!$db->create("calendar", $schema))
{
echo "Error creating databasen";
return;
}
}
//if no key file create a new one
if(!file_exists("key.dat"))
{
$newKey = getMaxKey($db);
$newFile = fopen("key.dat", "w") Or die("Can't open file");
fwrite($newFile,$newKey);
fclose($newFile);
}
//add a record
//convert forms to record
$fileread = fopen("key.dat", "r")Or die("Can't open file");
$data = (int) fread($fileread, 10);
fclose($fileread);
$data++;
$fileread = fopen("key.dat", "w") Or die("Can't open file");
fwrite($fileread,$data);
fclose($fileread);
//removes escape slashes
$event = stripslashes($event);
$description = stripslashes($description);
$submitted = stripslashes($submitted);
//add html entities
$event = htmlentities($event,ENT_QUOTES);
$submitted = htmlentities($submitted,ENT_QUOTES);
$record["event_key"] = $data;
$record["event_name"] = $event;
$record["event_description"] = $description;
$record["event_submitted_by"] = $submitted;
$record["event_month"] = $month;
list($record["event_day"]) = sscanf($day, "%d"); // string -> int
list($record["event_year"]) = sscanf($year, "%d"); // string -> int
// Add a _new_ entry
echo("");
if (!$db->add($record))
echo("failed!n");
else {
//table to display after adding
$addedTable ="
<center><font class="back">Record Added: taking you back</font> </center>
<table cellpadding="0" cellspacing="2" border="0" bgcolor="#000000" align="center"><tr><td>
<table cellpadding="3" cellspacing="0" border="0" bgcolor="#CC0000" align="center">
<tr><td><font class="addHead"><a href="calendar.php" class="addHead">Calendar</a></font></TD></tr>
<tr><td>
<table cellpadding="3" cellspacing="0" border="0" bgcolor="#CCCCCC">
<tr>
<td width="150" align="right" height="26"><font class="AddLeft">Event : </font></td>
<td width="350" height="26"><font class="AddRight">$event</font></td>
</tr>
<tr bgcolor="#E3E3E3">
<td width="150" align="right"><font class="AddLeft">Event Description : </font></td>
<td width="350"><font class="AddRight">$description</font></td>
</tr>
<tr>
<td width="150</h5>" align="right"><font class="AddLeft">Date : </font></td>
<td width="350" ><font class="AddRight">$day $month $year</font></td>
</tr>
<tr bgcolor="#E3E3E3">
<td width="150" align="right"><font class="AddLeft">Submitted By : </font></td>
<td width="350"><font class="AddRight">$submitted</font></td>
</tr>
</table>
</td><tr>
<tr><td align="right"></td></tr>
</table>
</td></tr></table>
";
echo $addedTable;
}
}
else {
echo "You must enter an event name. Please go back to the previous
page and do so.";
}
?>
</body>
</html>
[code]
[ Message was edited by: stevenjm 04/24/2004 02:59 am ]
|