Dziekuje za probe pomocy

Ponizej wklejam kod klasy i pliku z wywolaniami funkcji:
Ale juz chyba wiem co jest przyczyna...
Wywoluje 2 razy formularz i pewnie przy drugim wywolaniu ponawia sie wywolanie new Reservation i zeruje wszystkie wartosci.
Jak mozna to zrobic inaczej?
klasa:
<?php
class Reservation
{
public $bReserved;
public $iObjectId;
public $iUserId;
public $StartDate;
public $StartDatetime;
public $iStartHour;
public $iStartMinute;
public $EndDate;
public $EndDatetime;
public $iEndHour;
public $iEndMinute;
public $today;
public $year;
public $month;
public $day;
public $hour;
public $minutes;
public $aResult;
public $ObjSelect;
public $aSelected;
public $allReservations;
public $allReservationsId;
public $msg;
public $messages;
public $reservationId;
public $insert;
public function __construct()
{
$this->bReserved = false;
$this->iObjectId = ($_POST['Object_id']);
$this->iUserId = ($_POST['login']);
$this->StartDate = ($_POST['start_calendar']);
$this->EndDate = ($_POST['end_calendar']);
$this->year = 2000;
$this->aResult = array(); $this->ObjSelect = ($_POST['objSelect']);
$this->aSelected = array(); $this->StartDatetime = '';
$this->iStartHour = ($_POST['startHour']);
$this->iStartMinute = ($_POST['startMinute']);
$this->EndDatetime = '';
$this->iEndHour = ($_POST['endHour']);
$this->iEndMinute = ($_POST['endMinute']);
$this->allReservations = mysql_query("SELECT * FROM `reservation`"); $this->allReservationsId = array(); $this->msg = NULL;
$this->messages = array(); $this->reservationId = array(); $this->insert = ($_POST['confirm']);
}
public function getYear()
{
$this->year = $this->today[year];
return $this->year;
}
public function getMonth()
{
$this->month = $this->today[month];
return $this->month;
}
public function getDay()
{
$this->day = $this->today[mday];
return $this->day;
}
public function getHour()
{
$this->hour = $this->today[hours];
return $this->hour;
}
public function getMinutes()
{
$this->minutes = $this->today[minutes];
return $this->minutes;
}
public function setUser($login)
{
$userLogin = $login;
$query = mysql_query("SELECT `User_login_id` FROM `user_login` WHERE `Login` = '$login'"); $this->iUserId = $zm['User_login_id'];
return $this->iUserId;
}
public function reserve()
{
$StartTime = $this->iStartHour.':'.$this->iStartMinute.':00';
$this->StartDatetime = $this->StartDate." ".$withoutSpaces;
$EndTime = $this->iEndHour.':'.$this->iEndMinute.':00';
$this->EndDatetime = $this->EndDate." ".$withoutSpaces2;
$items = count($this->ObjSelect); $i = 0;
$id = 0;
while ($i < $items)
{
$ifResObjExist = mysql_query("SELECT * FROM `reservation` WHERE `Object_id`='".$this->ObjSelect[$i]."' ");
$objName = mysql_query("SELECT `Name` FROM object WHERE `Object_id`='".$this->ObjSelect[$i]."'");
// *** CHECK IF THE OBJECT IS NOT RESERVED
$k = 1;
if ($catch)
{
$start = $catch['Start_time'];
$end = $catch['End_time'];
if ($this->StartDatetime > $start AND $this->StartDatetime < $end)
{
$ObjNotToReserve = $this->ObjSelect[$i];
$this->msg = 'You can not reserve object '.$catchName['Name'];
$k = 0;
}
if ($this->EndDatetime > $start AND $this->EndDatetime < $end)
{
$ObjNotToReserve = $this->ObjSelect[$i];
$this->msg = '<BR><b>You can not reserve object '.$catchName['Name'].'<br>';
$k = 0;
}
}
if ($k)
{
mysql_query( "INSERT INTO `reservation` (`Object_id`, `User_login_id`, `Start_time`, `End_time` ) VALUES ( '".$this->ObjSelect[$i]."','".$this->iUserId."', '".$this->StartDatetime."', '".$this->EndDatetime."') ");
$this->msg = '<br><br>You have reserved object '.$catchName['Name'].
'<ul type="square"><li>from '.$this->StartDatetime.'<li>to '.$this->EndDatetime.'</ul>';
}
$this->messages[] = $this->msg;
$this->reservationId[] = $id;
$i++;
}
return $this->messages;
}
public function delete()
{
$items = count($this->reservationId);
// print_r($this->reservationId);
// exit;
$i = 0;
while ($i < $items)
{
mysql_query ("DELETE FROM `reservation` WHERE `Reservation_id` = '".$this->reservationId[$i]."' "); $i++;
}
$this->msg = 'You did not reserve any item';
return $this->msg;
}
public function getAllReservationsId()
{
{
$this->allReservationsId[] = $aRow;
}
return $this->allReservationsId;
}
}
?>
HTML
Plik z wywolaniem funkcji i formularzami:
include('tajne/config.php');
include('User.class.php');
include('Office.class.php');
include('Object.class.php');
include('Reservation.class.php');
include('callendar.php');
$userLogin = new User();
$bIfLogin = $userLogin->login();
$oOfficeD = new Office();
$AllOffices = $oOfficeD->getAllOffices();
$iObject = new Object();
$allObjects = $iObject->getAllObjectTypes();
$aGetObject = $iObject->getObject();
$id = $_POST['Object_type_id'];
$sObjType = $iObject->getTypeName($id);
$sOfficeName = $iObject->getOffice();
$oReservation = new Reservation();
$oReservation->setUser($bIfLogin);
$msg = '';
$i = 0;
if(isset($_POST['reserveObj']))
{
$msg = $oReservation->reserve();
$numberOf = count($msg);
}
if(isset($_POST['delete']))
{
$oReservation->delete();
}
?>
<div id="Table_01">
<div id="index-01">
<br><a href="http://www.zapatec.com/website/main/products/prod1/"></a><br>
</div>
<div id="index-reservation">
<p>
<?php
if( $bIfLogin )
{
?>
<?php
if( !isset($_POST['selectingObj']) AND !isset($_POST['reserveObj']))
{
?>
</div>
<div id="index-form-reserve_object">
<form action="reservation.php" method="post" name="selectObject">
<input type="hidden" name="selectingObj" value="k">
<select name="type_of_object" class="option">
<option value = "" >
-- Choose type --
</option>
<?php
foreach ($allObjects as $key2 => $allObjects)
{
?><br>
<option value = "<?php echo $allObjects['Object_type_id'] ;?>" >
<?php echo $allObjects['Type_of_object'] ;?>
</option>
<?php
} ?>
</select>
<br>
<br>
<select name="office" class="option">
<option value = "" >
-- Choose office --
</option>
<?php
foreach ($AllOffices as $key => $AllOffices)
{
?> <br>
<option value = "<?php echo $AllOffices['Office_id'] ;?>" >
<?php echo $AllOffices['City'] ;?>, <?php echo $AllOffices['Street'] ;?>
</option>
<?php
} ?>
</select>
<br>
<br>
<br>
<input name="sub" type="submit" value="Submit" class="submit"/>
</form>
<?php
}
if( isset($_POST['selectingObj']) AND !isset($_POST['reserveObj']))
{
?>
<form action="" method="post" name="reserveObject">
<input type="hidden" name="reserveObj" value="k">
<select name="objSelect[]" class="mul_sel" multiple="multiple">
<?php
foreach ($aGetObject as $key3 => $aGetObject)
{
?>
<br>
<option value = "<?php echo $aGetObject['Object_id'] ;?>" >
<?php echo $aGetObject['Name'] ?> <?php echo $aGetObject['Room'] ?>
<?php
} ?>
</select>
<div id="office_obj">
<br>
OFFICE:<br>
OBJECT TYPE:
</div>
<div id="office_obj_display">
<?php
?>
<br>
<?php
?>
</div>
<br>
<br>
<div id="start_end_field">
Start date:
<p style="margin-top:80">
End date:
</p>
</div>
<noscript>
<br/>
your browser does not support Javascript.
<br/>
Either enable Javascript in your Browser or upgrade to a newer version.
</noscript>
<br><a href="http://www.zapatec.com/website/main/products/prod1/"></a><br>
</div>
<div id="reservation-hours">
<input type="text" id="start_calendar" name="start_calendar" class="field"/>
<button id="trigger" class="submit_small"> callendar</button>
<script type="text/javascript">
Zapatec.Calendar.setup({
firstDay : 1,
range : [2007.01, 2999.12],
electric : false,
inputField : "start_calendar",
button : "trigger",
ifFormat : "%Y-%m-%d",
daFormat : "%Y-%m-%d"
});
//]]></script>
<br>
<br>
<!-- *** Reservation starts at:-->
<select name="startHour" class="option_short">
<?php
for ($i=0; $i<24; $i++)
{
switch ($i)
{
case 0: $ii = "00"; break;
case 1: $ii = "01"; break;
case 2: $ii = "02"; break;
case 3: $ii = "03"; break;
case 4: $ii = "04"; break;
case 5: $ii = "05"; break;
case 6: $ii = "06"; break;
case 7: $ii = "07"; break;
case 8: $ii = "08"; break;
case 9: $ii = "09"; break;
default: $ii = $i; break;
}
?>
<option value = " <?php echo $ii; ?> " > <?php echo $ii ?>
</option>
<?php
}
?>
</select>
<select name="startMinute" class="option_short">
<?php
$i = 0;
while ($i<60)
{
switch ($i)
{
case 0: $ii = "00"; break;
case 5: $ii = "05"; break;
default: $ii = $i; break;
}
?>
<option value = " <?php echo $ii; ?> " > <?php echo $ii ?>
</option>
<?php
$i = $i + 5;
}
?>
</select>
<br>
<br>
<br>
<br>
<!-- *** Reservation ends at:-->
<input type="text" id="end_calendar" name="end_calendar" class="field"/>
<button id="trigger2" class="submit_small">callendar</button>
<script type="text/javascript">//<![CDATA[
Zapatec.Calendar.setup({
firstDay : 1,
range : [2007.01, 2999.12],
electric : false,
inputField : "end_calendar",
button : "trigger2",
ifFormat : "%Y-%m-%d",
daFormat : "%Y-%m-%d"
});
//]]></script>
<br>
<br>
<select name="endHour" class="option_short">
<?php
for ($i=0; $i<24; $i++)
{
switch ($i)
{
case 0: $ii = "00"; break;
case 1: $ii = "01"; break;
case 2: $ii = "02"; break;
case 3: $ii = "03"; break;
case 4: $ii = "04"; break;
case 5: $ii = "05"; break;
case 6: $ii = "06"; break;
case 7: $ii = "07"; break;
case 8: $ii = "08"; break;
case 9: $ii = "09"; break;
default: $ii = $i; break;
}
?>
<option value = " <?php echo $i ?> " > <?php echo $ii ?>
</option>
<?php
}
?>
</select>
<select name="endMinute" class="option_short">
<?php
$i = 0;
while ($i<60)
{
switch ($i)
{
case 0: $ii = "00"; break;
case 5: $ii = "05"; break;
default: $ii = $i; break;
}
?>
<option value = " <?php echo $ii ?> " > <?php echo $ii ?>
</option>
<?php
$i = $i + 5;
}
?>
</select>
<br>
<br>
<br>
<input name="sub" type="submit" value="Submit" class="submit"/>
</form>
<?php
}
else if(isset($_POST['reserveObj']))
{
for ($i = 0; $i < $numberOf; $i++)
echo $msg[$i];
?>
<br><br>
<form action="" method="post" name="deleteObject">
<input type="hidden" name="confirm" value="k">
<input name="confirm" type="submit" value="confirm" class="submit"/>
</form>
<form action="" method="post" name="reserveObject">
<input type="hidden" name="delete" value="k">
<input name="delete" type="submit" value="undo" class="submit"/>
</form>
<?php
}
else if (isset($_POST['delete']))
{
echo $msg;
}
?>
</div>
<?php
}
else if( !$bIfLogin )
{
?>
<div id="index-login">
You are not Logged in!
Please go to