Reservation Block System
Moderator: General Moderators
Reservation Block System
Okay, i've had tried doing this myself, i've tried multiple people, and i've finally decided to let some other people do it that want to take it on. I need a php script that will show monday-friday with rows going like this:
Mon Tues Wednes Thurs Fri
A1:
A2:
B1:
B2:
C1:
C2:
D1:
D2:
then you can click on one of the boxes that the columns and rows form and you can reserve that day. simple as that. more or less. all reservations should reset on sunday so that their is s fresh week. and the days should display the day of the week that it is or just something like: Week of April 4-11 or whatever. if anyone would like to take this up PLEASE, PLEASE contact me at ISpyTy@bendcable.com
Thank you a billion in advance,
Tyler
Mon Tues Wednes Thurs Fri
A1:
A2:
B1:
B2:
C1:
C2:
D1:
D2:
then you can click on one of the boxes that the columns and rows form and you can reserve that day. simple as that. more or less. all reservations should reset on sunday so that their is s fresh week. and the days should display the day of the week that it is or just something like: Week of April 4-11 or whatever. if anyone would like to take this up PLEASE, PLEASE contact me at ISpyTy@bendcable.com
Thank you a billion in advance,
Tyler
but at least hints should be for free
and maybe it's a non-profit project....
Code: Select all
<?php
$d = getdate(); // current date
/**
$d['wday']: day of week, 0: sunday
$d['mday']-$d['wday']: start of the interval su-sa
*/
$dow = array();
// create array of seven dates su-sa
for($i=0; $i!=8; $i++)
$dow[] = mktime(12, 0, 0, $d['mon'], $d['mday']-$d['wday']+$i, $d['year']);
$positions = array('A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2');
?>
<html>
<body>
<table border="1">
<tr>
<td></td>
<?php
foreach($dow as $d)
echo ' <td>', date('j.n', $d), '</td>';
?>
</tr>
<?php
foreach($positions as $p)
{
?>
<tr>
<td><?php echo $p;?></td>
<?php
foreach($dow as $d)
{
?>
<td>
<a href="<?php echo $_SERVER['PHP_SELF'], '?res=', $p, '&date=', date('Ymd', $d); ?>">
allocate
</a>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</body>
</html>yes, it's only an example for creating the calendar view. It does not store/check any reservation at all.
If someone hits one fo the linkssomeone tries to allocate a ressource. You have to check then wether is location can still be fetch and if you have to mark this information (database/flatfile).
When displaying the calendar you have to check again for already allocated locations and not display the link if it already is.
Are you going to use a database or flat files or something else to store the data?
If someone hits one fo the links
the same script will be requested again. The position and date should be in $_GET['res']/$_GET['date']. So, if these parameters are set<a href="<?php echo $_SERVER['PHP_SELF'], '?res=', $p, '&date=', date('Ymd', $d); ?>">
Code: Select all
if (isset($_GET['res']) && isset($_GET['date']))When displaying the calendar you have to check again for already allocated locations and not display the link if it already is.
Are you going to use a database or flat files or something else to store the data?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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.( 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 readingwill 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.thentells 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 GETfirst 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.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)Maybe you should also mark the new record in the current $reservation-arraywhen displaying the table check for each cell wether a reservation can be made or not
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)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....
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]); ?>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)
{
}
?>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]);
}
?>Code: Select all
<?php if (isset($reservation[<when>]) && isset($reservation[<when>][<where>])) ?>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
}
?>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';
}
?>(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");
?>Code: Select all
<?php
$reservation[$_GET['date']][$_GET['res']] = 'taken'; //static string 'taken' for now
?>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
?>(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");
?>p.s.: code-snippets not tested. Don't blame me if there are errors in....