ok, a simple solution for plain files.
So you need a file to store the information and therefor a name for that file.
I suggest saving the information in one file per week. The date of the first day of that week will do as name.
Code: Select all
<?php $currentDataFileName = date('Ymd', $dow[0]); ?>
( date('Ymd', ... will be used more than once, it's advisable to store that string but I'll skip that for now).
In any case (display or register a new reservation) you first need to read the information already stored.
Let's use a single line per reservation. The information you need is when,where,who (the "who" comes later).
Assume the data is excatly written as
when,where,who then there's a function that perfectly meets the criteria to read this information.
array fgetcsv ( resource handle, int length [, string delimiter [, string enclosure]])
Once you've opened the file for reading
Code: Select all
<?php
while( ($data = fgetcsv($fp, 512)) !== FALSE)
{
}
?>
will read the content. In each iteration of the loop $data will be an array having three elements (when,where,who).
Later down in the script you have to check for each table cell wether this position is already taken. It's probably faster and certainly easier to use php built-in functions search the elements.
Code: Select all
<?php
while( ($data = fgetcsv($fp, 512)) !== FALSE)
{
if (isset($reservation[$data[0]]))
$reservation[$data[0]][$data[1]] = $data[2];
else
$reservation[$data[0]] = array($data[1] => $data[2]);
}
?>
then
Code: Select all
<?php if (isset($reservation[<when>]) && isset($reservation[<when>][<where>])) ?>
tells you wether this location has been taken (without warnings)
And this e.g. has to be tested if a new reservation request has been made.
In the previous example a reservation request is done when
res and
date have been passed via GET
Code: Select all
<?php
if (isset($_GET['res']) && isset($_GET['date']))
{ // request for reservation
}
?>
first you should check wether
res and
date are valid, i.e.
res is equal to one of the elements in $positions and
date is within the current week.
Then you have to check wether this specific location has already been taken.
Code: Select all
<?php
if (isset($reservation[$_GET['date']]) && isset($reservation[$_GET['date']][$_GET['res']]))
{
echo $_GET['res'], '@', $_GET['date'], ' already taken';
}
?>
otherwise append the new recordset to the datafile. Therefor the datafile must also be opened for writing if a new request is handled.
(see also:
http://www.php.net/manual/en/function.flock.php)
Code: Select all
<?php
fwrite($fp, $_GET['date']);
fwrite($fp, ',');
fwrite($fp, $_GET['res']);
fwrite($fp, ',');
fwrite($fp, 'taken');
fwrite($fp, "\r\n");
?>
Maybe you should also mark the new record in the current $reservation-array
Code: Select all
<?php
$reservation[$_GET['date']][$_GET['res']] = 'taken'; //static string 'taken' for now
?>
when displaying the table check for each cell wether a reservation can be made or not
Code: Select all
<?php
if (isset($reservation[date('Ymd', $d)]) && isset($reservation[date('Ymd', $d)][$p]))
echo $reservation[date('Ymd', $d)][$p];
else
// provide appropriate link here
?>
If you protected the script via .htaccess (or similar) you can get the "who" from $_SERVER['PHP_AUTH_USER']
(see also:
http://www.php.net/manual/en/reserved.variables.php)
Code: Select all
<?php
fwrite($fp, $_GET['date']);
fwrite($fp, ',');
fwrite($fp, $_GET['res']);
fwrite($fp, ',');
fwrite($fp, $_SERVER['PHP_AUTH_USER']);
fwrite($fp, "\r\n");
?>
I think this should enable you to write the script otherwise you probably really have to hire someone
p.s.: code-snippets not tested. Don't blame me if there are errors in....