Printer Friendly Version Print this thread
Email this thread to a friend eMail this thread to a friend
Featured Web Site Template

Hundreds More at Free Site Templates.com!

Web Site Partners
Sponsored Links
Jet City Software
 
Whos Here ?
Reflects user activity within the last 5 minutes
Moderator(s): Prowler, jcokos
Member Message

stevenjm
Joined: Eons Ago
# Posts: 824

View the profile for stevenjm Send stevenjm a private message

Posted: 2004-Apr-24 09:48
Edit Message Delete Message Reply to this message

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 ]





Sinoed
Joined: Dec 11, 2000
# Posts: 5266

View the profile for Sinoed Send Sinoed a private message

Posted: 2004-Jul-05 12:41
Edit Message Delete Message Reply to this message

Well you could either save it as two values or one. I did something similar when specifying an actual length of time and saved it as two dates in a database. If you're saving it as one you could take the two dates you have and join them together and call it the single date that works with the script that you have now. Since its broken down into days and months when it writes you'd have to join them separately. When you actually use it you could split the days at a certain number of characters. In my case I used a dropdown list for the values and then joined the strings together to create a date. By manipulating it correctly you could use the same thing on your calendar.



Code: [copy]





Just a thought, don't know if it helps or not. Good luck! :)



stevenjm
Joined: Eons Ago
# Posts: 824

View the profile for stevenjm Send stevenjm a private message

Posted: 2004-Jul-22 18:29
Edit Message Delete Message Reply to this message

hey Sinoed thanks - sorry I missed your reply.
I'll have a play with it when I get a chance



Sinoed
Joined: Dec 11, 2000
# Posts: 5266

View the profile for Sinoed Send Sinoed a private message

Posted: 2004-Jul-22 21:24
Edit Message Delete Message Reply to this message

No prob, hope it helps. smile


You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
  1. You have not yet logged in, or registered properly as a member
  2. You are a member, but no longer have posting rights.
  3. This is a private forum, for which you do not have permissions.

If you are a recent member, it's possible that you simply have not yet confirmed your account. Please check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions contained within.

If you cannot find this message, click here to Re-Send it.

If you are still experiencing problem, please read the Login Assistance Article for some advice on what may be causing your login not to work properly.

Switch to Advanced Editor and ... Create a New Topic or Reply to this Thread

New posts Forum is locked
© 1995  ·  iWeb, Inc  ·  DBA JimWorld Productions