Page 1 of 1

Reservation Block System

Posted: Sat Apr 05, 2003 5:24 pm
by ISpyTy
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

Posted: Sat Apr 05, 2003 9:07 pm
by Jim
Question 1:

Don't you think this is in the wrong forum?


Question 2:

How much are you paying? Or do you expect someone you don't know to do this for you for free?


Question 3:

If Question 2 == yes... are you out of your mind!? ;)

Posted: Sat Apr 05, 2003 9:34 pm
by volka
but at least hints should be for free ;)

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>
and maybe it's a non-profit project....

Posted: Sun Apr 06, 2003 12:10 am
by ISpyTy
im working on a computer lab reservation script for my school that will allow teachers to, obviously, reserve computer labs for different parts of the day.

Posted: Sun Apr 06, 2003 12:13 am
by ISpyTy
hey volka, thanks a bunch for the "hint" but one question. i don't know if it does or not, when i ran the script it didn't, but once one of the "allocate" 's is clicked it should blank out that position so no other teacher can just reserve right over the other teacher.

Posted: Sun Apr 06, 2003 9:02 am
by volka
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 links
<a href="<?php echo $_SERVER['PHP_SELF'], '?res=', $p, '&date=', date('Ymd', $d); ?>">
the same script will be requested again. The position and date should be in $_GET['res']/$_GET['date']. So, if these parameters are set

Code: Select all

if (isset($_GET['res']) && isset($_GET['date']))
someone 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?

Posted: Sun Apr 06, 2003 4:35 pm
by ISpyTy
most likely flat files, dont u have to use like fopen and fwrite or something?

Posted: Wed Apr 09, 2003 4:35 pm
by ISpyTy
okay volka, want to help me write, or actually, want to actually write the code for actually reserving? pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee?

-Tyler

Posted: Thu Apr 10, 2003 2:17 am
by twigletmac
ISpyTy wrote:okay volka, want to help me write, or actually, want to actually write the code for actually reserving? pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee?

-Tyler
Do you want me to move this to the Job Hunt Forum?

Mac

Posted: Thu Apr 10, 2003 4:18 am
by volka
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....