Solved

Online Booking PHP software broken

Posted on 2007-11-26
4
837 Views
Last Modified: 2013-12-12
I'm still getting the hang of writing PHP and MySQL code, so bare with me please.

I downloaded an open source booking web app, Online Booking (http://sourceforge.net/projects/openbooking/).

Got everything working fine except when you go to schedule an actual appointment, the To Time: option doesn't display anything.  Well, I dug through the code and found the To Time: code on the showCalendar.php page.  Lo' and behold!  There's no code behind the drop down menu for the To Time: option!

I thought I may be able to get lucky and just use portions of the code from the From Time: option, but no luck.  It breaks the rest of the page.

So, I'm begging!  I need this booking system up within a few days, week tops!  Please, somebody dig through this code and help me find out how to get the To Time: option working!

P.S. You can download all the files from the link above.  Here it is again, just in case.  http://sourceforge.net/projects/openbooking/

I've attached a copy of showCalendar.php.

Also, if you want to see a working "demo", go to http://www.dcspd.com/book

login with demo and demo

Thanks a million!!!
<?php
 

  /*
 

      showCalendar.php
 

      Allows for full management of reservations.
 

      ----
 

      Copyright (C) 2002  David Thorne (mmmbena1@hotmail.com)
 

      This program is free software; you can redistribute it and/or

      modify it under the terms of the GNU General Public License

      as published by the Free Software Foundation version 2.
 

      This program is distributed in the hope that it will be useful,

      but WITHOUT ANY WARRANTY; without even the implied warranty of

      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

      GNU General Public License for more details.
 

      You should have received a copy of the GNU General Public License

      along with this program; if not, write to the Free Software

      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 

  */
 

  require_once "../system/access_privileges.php";

  if (!privileged('reservation')) {

    header("Location: ../no_access.php?privilege=Reservations");

    exit();

  }  
 

  session_start();
 

    // Gets only the selected form variables into global scope

    // Taken from http://www.php.net

    $param_list = array (

        'act','ID','year','month','day','startTimeBeforeVariance',

        'startTimeVariance','startTime','forMemberID','finishTime',

        'activityID','description','respending','recurrencePeriod',

        'Period','MemberID','ActivityID','BlockBookingID',

        'StartTime','Description','reservations',

        'reservationID','blockBookingID','startResource','finishResource',

        'startTimeOfDay','finishTimeOfDay','numberPeriods','chosenIDs',

        'resourceIDs','newres','oldres','minical',

        'endday','endmonth','endyear','startday','startmonth','startyear'

    );

    foreach ($param_list as $param) {

        @$$param=$_REQUEST[$param];

    }
 

  if (!isset($act)) { extract($_SESSION['_reservation']); }

  if (!isset($act)) { $act = ''; }
 

  if ($ID == '') $ID=$_SESSION['_resourceGroupID'];
 

  require "../system/shell_iframe_header.php";
 

  require_once "../system/opendb.php";

  require_once "../system/minicals.php";

  require_once "../system/recordset.php";

  require_once "../system/message.php";

  require_once "../system/time.php";

  require_once "../system/conflict.php";

  require_once "../system/global_preferences.php";
 

//  $db_connection = mysql_connect("localhost:/var/lib/mysql/mysql.sock","root","") or die("Fatal Error: Could not connect");

//  mysql_select_db("Sports") or die("Fatal Error: No Sports Database");
 

  // Retrieve resource group information

  $sql = "SELECT * FROM tbl_ResourceGroups WHERE ID=" . $ID;

  $result = mysql_query($sql) or die("Fatal Error: Resource Group Query Failed");

  $info = mysql_fetch_assoc($result) or die("Fatal Error: No Resource Group Information");
 

  // Retrieve section information for this resource group

  $sql = "SELECT * FROM tbl_Resources WHERE ResourceGroupID=" . $ID;

  $result = mysql_recordset($sql);

  $num_sections = count($result);
 

  $_SESSION['_resourceGroupID'] = $ID;
 

  if (!isset($day) or !isset($month) or !isset($year)) {

    $year = $_SESSION['_year'];

    $month = $_SESSION['_month'];

    $day = $_SESSION['_day'];

  } else {

    while (!checkdate($month, $day, $year)) $day--;

    $_SESSION['_year'] = $year;

    $_SESSION['_month'] = $month;

    $_SESSION['_day'] = $day;

  }
 

  if ($act == 'reserveaction') {
 

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    extract($_SESSION['_reservation']);
 

    if ($recurrencePeriod==0) {

        $endday = $day;

        $endmonth = $month;

        $endyear = $year;

    }
 

    if (checkdate($endmonth,$endday,$endyear)) {
 

      $failurenotice = 'Links to conflicts: ';
 

      $_SESSION['_reservation'] = array();
 

      $startTimeObj = new timeCalculator($startTime);

      $finishTimeObj = new timeCalculator($finishTime);
 

      $conflictlist="act=reserveaction&conflictid=".$reservationID."+".mktime($startTimeObj->hour,$startTimeObj->min,0,$month,$day,$year)."&";
 

      $numberPeriods = (($finishTimeObj->dumpTS()-$startTimeObj->dumpTS())/60)/5;
 

      $blockBookingID = mysql_send("INSERT INTO tbl_BlockBookings

(OperatorID,Pending) VALUES (" . $_SESSION['_id'] . "," . ($respending=='true'?'0':'1') . ")");
 

      $iday = $day;

      $imonth = $month;

      $iyear = $year;
 

// MH

      // Check for conflicts

      $no_conflicts=true;

      while (mktime(0,0,0,$imonth,$iday,$iyear)<=mktime(23,59,59,$endmonth,$endday,$endyear)) {

        $startTimeTS = mktime($startTimeObj->hour,$startTimeObj->min,0,$imonth,$iday,$iyear);

        $conflicts = conflict($startTimeTS,$numberPeriods*5,$resourceIDs);

        if ($conflicts) {

          $no_conflicts = false;

          foreach ($conflicts as $conflict) {

              $failurenotice .= "<a href=\"showCalendar.php?act=view&reservationID=".$conflict['id']."\">[" . strftime("%d/%m/%y %T", $conflict['startTime']) . "]</a> ";

              $conflictlist.="reservationid[]=".$conflict['id']."+".$conflict['startTime']."&";

          }

        }
 

        // And check the other reservations as well

        if ($recurrencePeriod==0) break;

        if ($recurrencePeriod==1) {

          do {

            $iday++;

          } while (strftime('%u',mktime(0,0,0,$imonth,$iday,$iyear)) > 5);

        }

        if ($recurrencePeriod==2) $iday += 7;

        if ($recurrencePeriod==3) $iday += 14;

      }
 

      // Reset the index date

      $iday = $day;

      $imonth = $month;

      $iyear = $year;
 

      // No conflicts - so go ahead

      if ($no_conflicts) {

        while (mktime(0,0,0,$imonth,$iday,$iyear)<=mktime(23,59,59,$endmonth,$endday,$endyear)) {

            $startTimeTS = mktime($startTimeObj->hour,$startTimeObj->min,0,$imonth,$iday,$iyear);
 

            $sql = "INSERT INTO tbl_Reservations (MemberID,ActivityID,ClientName,ClientTel,StartTime,Period,BlockBookingID,Description) VALUES ($forMemberID,$activityID,'$clientName','$clientTel','" . $startTimeTS . "'," . (5*$numberPeriods) . ",$blockBookingID,'" . $description . "')";

            $reservationID = mysql_send($sql);
 

            foreach ($resourceIDs as $resourceID) {

                $sql = "INSERT INTO tbl_ReservationMappings (ResourceID,ReservationID) VALUES ($resourceID,$reservationID)";

                mysql_send($sql);

            }
 

            if ($recurrencePeriod==0) break;

            if ($recurrencePeriod==1) {

              do {

                $iday++;

              } while (strftime('%u',mktime(0,0,0,$imonth,$iday,$iyear)) > 5);

            }

            if ($recurrencePeriod==2) $iday += 7;

            if ($recurrencePeriod==3) $iday += 14;

        }

        $act = '';

      } else {

        $message = 'CONFLICTS: '.$failurenotice . "<a href=\"#\" onclick=\"javascript:window.open('popupConflicts.php?".$conflictlist."','','status=0,toolabar=0,location=0,menus=0,directories=0,resizable=0,scrollbars=1,height=195,width=360')\">Popup conflicts...</a>";

        $act = 'reserve';

      }

    } else {

      $message = "CORRECTION: End date must be in a valid format";
 

      $act = 'reserve';

    }

  }
 

  if ($act == 'reserve') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    // remember the current reservation information

    $vars = array('act','year','month','day','startTimeBeforeVariance','startTimeOfDay','finishTimeOfDay','startTimeVariance','numberPeriods','startResource','finishResource');

    $_SESSION['_reservation'] = compact($vars);
 

    $startTimeOfDayObj = new timeCalculator($startTimeOfDay);

    $finishTimeOfDayObj = new timeCalculator($finishTimeOfDay);

    $startTimeObj = new timeCalculator($startTimeBeforeVariance);
 

    if (!isset($occurrences)) $occurences=1;

    $activities = mysql_recordset("SELECT * FROM tbl_Activities WHERE ResourceGroupID=$ID AND SectionCount<=" . (1+$finishResource-$startResource) . " ORDER BY Name");
 

    $sql = "SELECT tbl_Members.* FROM tbl_Members WHERE tbl_Members.ID>0 ORDER BY tbl_Members.Name";

    $members = mysql_recordset($sql);
 

    display($message);
 

    if (count($activities)>0) {

?>
 

<script language=javascript>

<!--
 

  function Deselect() {

    document.mainForm.target = 'status';

    document.mainForm.act.value = 'focus';

    document.mainForm.memberID.value = 0;

    document.mainForm.action = '../status.php';

    document.mainForm.submit();

    document.location = 'showCalendar.php?memberID=0';

  }
 

  function selectCont() {

    // Ensure that selected resources are next to each other

    firstsel = -1;

    lastsel = -1;

    for (i=0; i<document.getElementById('resourceIDs').length; i++) {

        if (document.getElementById('resourceIDs').options[i].selected) {

    //        alert(i + " is selected");

            if (firstsel != -1) {

                lastsel = i;

            } else {

                firstsel = i;

                lastsel = i;

            }

        }

    }

    //alert("first+last=" + firstsel + " " + lastsel);

    if (firstsel != -1) {

        for (i=firstsel; i<=lastsel; i++)

            document.getElementById('resourceIDs').options[i].selected = true;

    }

  }
 

  function correctDate() {

    <?php

                // correct for 2 digit year :(

                // Lets hope this wont be in use later

                if ($year < 80) {

                    $year += 2000;

                } else if ($year < 100) {

                    $year += 1900;

                }

    ?>

    leapyear=false;

    year = document.mainForm.endyear.value;

    if (((year % 4 == 0) && (year % 100 != 0)) ||

        (year % 400 == 0) && (year % 4000 !=0)) leapyear=true;

    var daysin = new Array ('', 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    if (leapyear) daysin[2]=29;

    for (i = 29; i<=31; i++) {

        if (i>daysin[document.mainForm.endmonth.value]) {

            document.mainForm.endday.options[i-1].disabled = true;

            if (document.mainForm.endday.options[i-1].selected == true) {

                document.mainForm.endday.options[daysin[document.mainForm.endmonth.value]-1].selected = true;

            }

        } else {

            document.mainForm.endday.options[i-1].disabled = false;

        }

    }

  }
 

  function enableEndDate() {

    if (document.mainForm.recurrencePeriod.value > 0) {

        disable = false;

    } else {

        disable = true;

    }

    document.mainForm.endyear.disabled = disable;

    document.mainForm.endmonth.disabled = disable;

    document.mainForm.endday.disabled = disable;

  }

// -->

</script>
 

  <form method=post name=mainForm>

  <input type=hidden name=ID value="<?=$ID?>">

  <input type=hidden name=act value=reserveaction>

  <input type=hidden name=year value="<?=$year?>">

  <input type=hidden name=month value="<?=$month?>">

  <input type=hidden name=day value="<?=$day?>">

  <input type=hidden name=startTimeBeforeVariance value="<?=$startTimeBeforeVariance?>">

  <input type=hidden name=startTimeVariance value="<?=$startTimeVariance?>">

  <table class=options cellpadding=0 cellspacing=10>

    <tr>

      <th colspan=2><b>Make Booking</b></th>

    </tr>

    <tr>

      <td>

        <table class=options cellpadding=4 cellspacing=0>

          <tr>

            <td align=right>Resource: </td>

            <td><b><?=$info['Name']?></b></td>

          </tr>

          <tr>

            <td align=right>Sections: </td>

            <td>

<?php

  // Sort the columns with natural order sort

  $to_sort = array();

  foreach ($result as $row) {

    array_push($to_sort, $row['Name']);

  }

  natcasesort($to_sort);
 

  $sorted = array();

  foreach($to_sort as $key => $value) {

    array_push($sorted, $result[$key]);

  }

  $result = $sorted;

?>

                <select id="resourceIDs" name="resourceIDs[]" size="5" multiple="multiple" onChange="selectCont()">

<?php

        foreach ($result as $key => $resource) { 

            $checked='';

            if ($startResource <= $key && $key <= $finishResource) {

                $checked=' selected="selected"';

            }

?>

                    <option value="<?=$resource['ID']?>" <?=$checked?>><?php

                        echo $resource[Name] ?></option>

<?php   }

?>

                </select>

            </td>

          </tr>

          <tr>

            <td align=right>Member: </td>

            <td><select name=forMemberID>

<?php

    foreach ($members as $record) {

?>

               <option value="<?=$record['ID']?>"><?=$record['Name']?></option>

<?php

    }

?>

             </select></td>

          </tr>

          <tr>

            <td align=right>On Date: </td>

            <td><b><?=strftime('%A %e %B %Y',mktime(0,0,0,$month,$day,$year))?></b></td>

          </tr>

          <tr>

            <td align=right>From Time: </td>

<?php $startTimeObj->addMinutes(5*$startTimeVariance); ?>

            <td>

              <select name=startTime>

<?php

  $currentTime = $startTimeOfDayObj;
 

  while ($currentTime->dump() < $finishTimeOfDayObj->dump()) {

    if ($currentTime->dump() == $startTimeObj->dump()) { $selected = ' selected="selected"'; } else { $selected = ''; }

    print '                <option value="'.$currentTime->dump().'"'.$selected.'>'.$currentTime->dump()."</option>\n";

    $currentTime->addMinutes(5);

  }

?>

              </select>

            </td>

          </tr>

          <tr>

            <td align=right>To Time: </td>

            <td>

              <select name=finishTime>

<?php

  $currentTime = $startTimeOfDayObj;

  $currentTime->addMinutes(5);

  $startTimeObj->addMinutes(5*$numberPeriods);
 

  while ($currentTime->dump() <= $finishTimeOfDayObj->dump()) {

    if ($currentTime->dump() == $startTimeObj->dump()) { $selected = ' selected="selected"'; } else { $selected = ''; }

    print '                <option value="'.$currentTime->dump().'"'.$selected.'>'.$currentTime->dump()."</option>\n";

    $currentTime->addMinutes(5);

  }

?>

              </select>

            </td>

          </tr>

          <tr>

            <td align=right>For Activity: </td>

            <td>

              <select name=activityID>

<?php

  if (isset($_REQUEST['activityID'])) {

    $activityID = $_REQUEST['activityID'];

  } else {

    $activityID = -1;

  }

  foreach ($activities as $record) {

    if ($record["ID"] == $activityID) {$checked = " selected";} else {$checked = "";};

    print ("                <option value='{$record['ID']}'${checked}>{$record['Name']}</option>\n");

  }

?>

              </select>

            </td>

          </tr>

          <tr>

            <td align=right valign=top>Description: </td>

            <td><textarea name="description" cols="50" rows="5"></textarea></td>

          </tr>

          <tr>

            <td colspan=2>Note: The first line of the description is displayed

                on the reservations calendar page.</td>

          </tr>

          <tr>

            <td valign=top></td>

            <td><input type="checkbox" name="respending" value="true" checked /> Confirm this booking.</td>

          </tr>

          <tr>

            <td align=right> Recurrence: </td>

            <td>

              <select name=recurrencePeriod onChange="enableEndDate()">

                <?php for ($i=0; $i<=3; $i++) {

                        $a = 'checked' . $i;

                        if ($recurrencePeriod == $i) {

                            $$a = 'selected="selected"';

                        } else {

                            $$a = '';

                        }

                      }

                ?>

                <option value='0' <?=$checked0?>>Single Reservation</option>

                <option value='1' <?=$checked1?>>Daily (Mon-Fri)</option>

                <option value='2' <?=$checked2?>>Weekly</option>

                <option value='3' <?=$checked3?>>Fortnightly</option>

              </select>

            </td>

          </tr>

          <tr>

            <td align=right>End Date: </td>

              <td>

                <select name="endday" onFocus="correctDate()" disabled="disabled"><?php

                for ($i=1; $i<=31; $i++) {

                    if (($i == $day && !isset($endday)) || $i == $endday) {

                        $checked = ' selected="selected"';

                    } else {

                        $checked = '';

                    }

                ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$i?></option>

          <?php } ?>

              </select>

              <select name="endmonth" onChange="correctDate()" disabled="disabled"><?php

                $months=array('','January','February','March','April','May',

                    'June','July','August','September','October','November',

                    'December');

                for ($i=1; $i<=12; $i++) {

                    if (($i == $month && !isset($endmonth)) || $i==$endmonth) {

                        $checked = ' selected="selected"';

                    } else {

                        $checked = '';

                    }

                ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$months[$i]?></option>

                <?php } ?>

              </select>

            <select name="endyear" onChange="correctDate()" disabled="disabled"><?php

                for ($i=$year-10; $i<=$year+10; $i++) {

                    if (($i == $year && !isset($endyear)) || $i == $endyear) {

                        $checked = ' selected="selected"';

                    } else {

                        $checked = '';

                    }

                ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$i?></option>

            <?php

                }

            ?></select>

            </td>

          </tr>

          <tr>

            <td align=right colspan=4><input type=submit class=button value="Make Reservation"><input type=reset class=button value="Reset"><input type=button class=button value="Cancel" onclick="document.location='showCalendar.php?act=&ID=<?=$ID?>'"></td>

          </tr>

        </table>

      </td>

    </tr>

  </table>

  </form>

  <script language="javascript" type="text/javascript"><!--

    enableEndDate();

  //--></script>
 

<?php

    } else {

      $message = "ERROR: No Activities Set Up";

      $act = "";

    }

  }
 

  if ($act == 'remove') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    if (!isset($chosenIDs)) {

        $message="ERROR: No reservations selected to cancel";

        $act = "view";

    } else {

        $flag = false;

        $act = "view";
 

        $block = mysql_recordset("SELECT * FROM tbl_Reservations WHERE BlockBookingID=" . $blockBookingID);
 

        foreach ($chosenIDs as $chosenID) {

          mysql_send("DELETE FROM tbl_ReservationMappings WHERE ReservationID=$chosenID");

          mysql_send("DELETE FROM tbl_Reservations WHERE ID=$chosenID");

          if ($chosenID == $reservationID) { $flag = true; }

        }
 

        if (count($chosenIDs) == $reservations) {

          mysql_send("DELETE FROM tbl_BlockBookings WHERE ID=$blockBookingID");

          $act = "";

          $flag = false;

        }
 

        $block = mysql_recordset("SELECT * FROM tbl_Reservations WHERE BlockBookingID=" . $blockBookingID);
 

        if ($flag) {

          $block = mysql_recordset("SELECT * FROM tbl_Reservations WHERE BlockBookingID=" . $blockBookingID . " ORDER BY StartTime");

          $reservationID = $block[0][ID];

        }

    }

  }
 

  if ($act == 'editaction') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    $_SESSION['_reservation'] = array();
 

    if (!isset($chosenIDs)) $chosenIDs = array();

    array_push($chosenIDs,$_REQUEST['reservationID']);
 

    $sql = "SELECT * FROM tbl_Reservations WHERE ";

    $flag=false;

    foreach($chosenIDs as $id) {

        if ($flag) {

            $sql.=" OR ID=$id";

        } else {

            $sql.="ID=$id";

            $flag=true;

        }

    }

    $records = mysql_recordset($sql);
 

    $startTimeObj = new timeCalculator($startTime);

    $finishTimeObj = new timeCalculator($finishTime);
 

    $period = $startTimeObj->periodUntil($finishTimeObj);

    if ($period <= 0) {

        $message="ERROR: The end time must be greater than the start time";

        $act="edit";

    } else {

        // MH

      // Check for conflicts

      $no_conflicts=true;

      foreach ($records as $record) {
 

        $currdate = $record['StartTime'];

        $imonth = strftime("%m", $currdate);

        $iday = strftime("%d", $currdate);

        $iyear = strftime("%y", $currdate);
 

        $conflicts = conflict($startTimeObj->dumpTSOnDate($iyear,$imonth,$iday), $period,$newres,$record['ID']);

        if ($conflicts) {

          $no_conflicts = false;

          foreach ($conflicts as $conflict) {

              $failurenotice .= "<a href=\"showCalendar.php?act=view&reservationID=".$conflict['id']."\">[" . strftime("%d/%m/%y %T", $conflict['startTime']) . "]</a> ";

              $conflictlist.="reservationid[]=".$conflict['id']."+".$conflict['startTime']."&";

          }

        }

      }
 

// ***************************

/*

				$conflictlist="act=editaction&conflictid=".$reservationID."+".mktime($startTimeObj->hour,$startTimeObj->min,0,$month,$day,$year)."&";

				$failurenotice="Links to conflict: ";

        foreach ($records as $record) {

            $currdate = $record['StartTime'];

            $imonth = strftime("%m", $currdate);

            $iday = strftime("%d", $currdate);

            $iyear = strftime("%y", $currdate);
 

        // Get reservations on the same day as the one we are considering

            $stimetmp = mktime(0,0,0,$imonth,$iday,$iyear);

            $etimetmp = mktime(23,59,59,$imonth,$iday,$iyear);

            foreach ($_REQUEST['newres'] as $resourceID) {

                $sql = <<<EOSQL

                SELECT StartTime,Period,ReservationID

                FROM tbl_Reservations,tbl_ReservationMappings

                WHERE tbl_Reservations.ID=tbl_ReservationMappings.ReservationID

                AND tbl_Reservations.ID != {$record['ID']}

                AND tbl_ReservationMappings.ResourceID=$resourceID

                AND tbl_Reservations.StartTime>=$stimetmp

                AND tbl_Reservations.StartTime<$etimetmp

EOSQL;

                $result=mysql_recordset($sql);
 

            // Now check each for conflicts
 

                foreach ($result as $res) {

                    if(conflicts($startTimeObj->dumpTSOnDate($iyear,$imonth,$iday), $period,

                    $res['StartTime'],$res['Period'])) {

                        $failurenotice .= "<a href=\"showCalendar.php?act=view&reservationID=".$res['ReservationID']."\">".strftime(" [%d/%m/%y %T] ",

                            $res['StartTime']) . "</a> ";

                            $conflictlist.="reservationid[]=".$res['ReservationID']."+".$res['StartTime']."&";

                        $no_conflicts=FALSE;

                    }

                }

            }

        }

*/

        if ($no_conflicts) {

            reset($records);

            foreach ($records as $record) {
 

                $currdate = $record['StartTime'];

                $imonth = strftime("%m", $currdate);

                $iday = strftime("%d", $currdate);

                $iyear = strftime("%y", $currdate);
 

                // Need to merge new start time with the date

                $st = mktime($startTimeObj->hour, $startTimeObj->min, 0,

                    $imonth, $iday, $iyear);
 

                // Update time

                mysql_send("UPDATE tbl_Reservations SET StartTime=$st,

                    Period=$period WHERE ID = {$record['ID']}");
 

                // Update resources

                $res_to_add=array_diff($_REQUEST['newres'], $_REQUEST['oldres']);

                $res_to_del=array_diff($_REQUEST['oldres'], $_REQUEST['newres']);
 

                foreach ($res_to_add as $resource) {

                    mysql_send("INSERT INTO tbl_ReservationMappings

                        (ReservationID, ResourceID) VALUES

                        ({$record['ID']}, $resource)");

                }
 

                foreach ($res_to_del as $resource) {

                    mysql_send("DELETE FROM tbl_ReservationMappings

                        WHERE ResourceID = $resource

                        AND ReservationID = {$record['ID']}");

                }

            }

                $message = "Reservation successfully updated [at " .

                    date("h:i a") . "]";

                $act = "view";
 

        } else {

            $message = "CONFLICTS: " . $failurenotice . "<a href=\"#\" onclick=\"javascript:window.open('popupConflicts.php?".$conflictlist."','','status=0,toolabar=0,location=0,menus=0,directories=0,resizable=0,scrollbars=1,height=195,width=360')\">Popup conflicts...</a>" . "<br />Changes to times and resources were unsuccessful due to conflicts with other reservations. All other changes were successful.";

            $act="edit";

        }

    }
 

    reset($records);

    foreach ($records as $record) {

        mysql_send("UPDATE tbl_Reservations SET MemberID={$_REQUEST['forMemberID']},

            ActivityID=$activityID, Description='{$_REQUEST['description']}'

            WHERE ID= {$record['ID']}");

    }
 

    mysql_send("UPDATE tbl_BlockBookings SET Pending=" .

        ($_REQUEST['respending']=='true'?'0':'1') .

        " WHERE ID=" . $records[0]['BlockBookingID']);
 
 

  }
 
 

  if ($act == 'confirm') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    $record = mysql_recordset("SELECT * FROM tbl_Reservations

        WHERE ID={$_REQUEST['reservationID']}");
 

    mysql_send("UPDATE tbl_BlockBookings SET Pending=" .

        ($_REQUEST['respending']=='true'?'0':'1') .

        " WHERE ID=" . $record[0]['BlockBookingID']);
 

        $message = "Reservation successfully updated [at ".date("h:i a") . "]";

        $act = "view";

  }
 

  if ($act == 'addaction') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }

    if ((checkdate($endmonth,$endday,$endyear) || $recurrencePeriod == 0) &&

            checkdate($startmonth,$startday,$startyear)) {
 

        // We have dates, we have a description - hopefully.. we have a go
 

        // Get the start time in seconds without any date

        $reservationTime=strftime("%H",$_POST['StartTime']) * 3600;

        $reservationTime+=strftime("%M",$_POST['StartTime']) * 60;
 

        // Now get the date range in unix time format also

        $sdate=mktime(0,0,0,$startmonth, $startday, $startyear);

        $edate=mktime(0,0,0,$endmonth,$endday,$endyear);
 

        $currdate=$sdate;
 

        // hack in case edate (doesnt matter for single reservation) > sdate

        if ($_POST['recurrencePeriod'] == 0) $edate = $sdate;
 

        // Check for conflicts

        $no_conflicts=TRUE;

        $conflictlist="act=addaction&conflictid=".$reservationID."+".mktime($_POST['StartTime']->hour,$_POST['StartTime']->min,0,$month,$day,$year)."&";

        $failurenotice="Links to conflicts: ";

        while ($currdate <= $edate) {

            $currtime = $currdate + $reservationTime;

            $imonth = strftime("%m", $currdate);

            $iday = strftime("%d", $currdate);

            $iyear = strftime("%y", $currdate);
 

            // Get reservations on the same day as the one we are considering

            $stimetmp = mktime(0,0,0,$imonth,$iday,$iyear);

            $etimetmp = mktime(23,59,59,$imonth,$iday,$iyear);

            foreach ($_POST['resourceIDs'] as $resourceID) {

                $sql = <<<EOSQL

                SELECT StartTime,Period,ReservationID

                FROM tbl_Reservations,tbl_ReservationMappings

                WHERE tbl_Reservations.ID=tbl_ReservationMappings.ReservationID

                AND tbl_ReservationMappings.ResourceID=$resourceID

                AND tbl_Reservations.StartTime>=$stimetmp 

                AND tbl_Reservations.StartTime<$etimetmp

EOSQL;

                $result=mysql_recordset($sql);
 

                // Now check each for conflicts

                foreach ($result as $res) {

                    if(conflicts($currtime, $_POST['Period'], $res['StartTime'],

                        $res['Period'])) {

                        $failurenotice .= "<a href=\"showCalendar.php?act=view&reservationID=".$res['ReservationID']."\">".strftime(" [%d/%m/%y %T] ",

                            $res['StartTime']) . "</a> ";

												$conflictlist.="reservationid[]=".$res['ReservationID']."+".$res['StartTime']."&";

                        $no_conflicts=FALSE;

                    }

                }

            }
 

            switch($_POST['recurrencePeriod']) {

            case 0:

                // Single

                $currdate=$edate+1; // Break out of loop

                break;

            case 1:

                // Daily

                do {

                    $currdate=addDays($currdate,1);

                } while (strftime("%u", $currdate) > 5);

                break;

            case 2:

                // Weekly

                $currdate=addDays($currdate,7);

                break;

            case 3:

                // Fortnightly

                $currdate=addDays($currdate,14);

                break;

            }

        }
 

        if ($no_conflicts) {

            $currdate=$sdate; // reset currdate

            while ($currdate <= $edate) {

                $currtime = $currdate + $reservationTime;
 

                $sql="INSERT INTO tbl_Reservations (MemberID, ActivityID, ";

                $sql.="StartTime, Period, BlockBookingID, Description) ";

                $sql.="VALUES ($_POST[MemberID], $_POST[ActivityID], ";

                $sql.="$currtime, $_POST[Period], $_POST[BlockBookingID], ";

                $sql.="\"$_POST[Description]\")";

                $reservationID = mysql_send($sql);
 

                //echo $reservationID;
 

                // funky loop here to get all resources used

                // (Needs to have resources passed from Add

                foreach ($_POST['resourceIDs'] as $resourceID) {

                    $sql="INSERT INTO tbl_ReservationMappings (ReservationID, ";

                    $sql.="ResourceID)";

                    $sql.="VALUES ($reservationID,$resourceID)";

                    mysql_send($sql);

                }
 

                //echo strftime("%d/%m/%y %T", $currtime) . "<br>";
 

                switch($_POST['recurrencePeriod']) {

                case 0:

                    // Single

                    $currdate=$edate+1; // Break out of loop

                    break;

                case 1:

                    // Daily

                    do {

                        $currdate=addDays($currdate,1);

                    } while (strftime("%u", $currdate) > 5);

                    break;

                case 2:

                    // Weekly

                    $currdate=addDays($currdate,7);

                    break;

                case 3:

                    // Fortnightly

                    $currdate=addDays($currdate,14);

                    break;

                }

            }
 

            // Right, all done, move to view

            $message = "Reservation successfully added [at ".date("h:i a")."]";

            $act="view";

        } else {

            $message = "CONFLICTS: " . $failurenotice . "<a href=\"#\" onclick=\"javascript:window.open('popupConflicts.php?".$conflictlist."','','status=0,toolabar=0,location=0,menus=0,directories=0,resizable=0,scrollbars=1,height=100,width=195')\">Popup conflicts...</a>";

            $act="Add";

        }
 

    } else {

        $message="ERROR: One of the dates entered is invalid";

        $act="Add";

    }

  }
 

  if ($act == 'Add') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    // Get one of the original reservations for time info etc..

    $sql="SELECT r.*, m.Name AS memberName, a.Name AS activityName ";

    $sql.="FROM tbl_Reservations AS r, tbl_Members AS m, tbl_Activities AS a ";

    $sql.="WHERE r.ID=$reservationID ";

    $sql.="AND m.ID=r.MemberID AND a.ID=r.ActivityID";

    $result = mysql_recordset($sql);

    $reservation=$result[0];
 

    // And get the Sections in use by the reservation

    $sql="SELECT rm.*, r.Name, r.ID AS rID ";

    $sql.="FROM tbl_ReservationMappings AS rm, tbl_Resources as r ";

    $sql.="WHERE rm.ReservationID=$reservationID AND rm.ResourceID=r.ID";

    $resources = mysql_recordset($sql);
 

    if (isset($_POST['Description'])) {

        $description = $_POST['Description'];

    } else {

        $description = $reservation['Description'];

    }
 

    // Sometimes, case sensitivity is a pain.. but rather than fix it, heres

    // a little hack

    if (isset($_POST['BlockBookingID'])) {

        $blockBookingID=$_POST['BlockBookingID'];

    } else {

        $blockBookingID=$_POST['blockBookingID'];

    }
 

    display($message);

?>

<script language="javascript"><!--
 

  function correctStartDate() {

    <?php

                // correct for 2 digit year :(

                // Lets hope this wont be in use later

                if ($year < 80) {

                    $year += 2000;

                } else if ($year < 100) {

                    $year += 1900;

                }

    ?>

    leapyear=false;

    year = document.mainForm.startyear.value;

    if (((year % 4 == 0) && (year % 100 != 0)) ||

        (year % 400 == 0) && (year % 4000 !=0)) leapyear=true;

    var daysin = new Array ('', 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    if (leapyear) daysin[2]=29;

    for (i = 29; i<=31; i++) {

        if (i>daysin[document.mainForm.startmonth.value]) {

            document.mainForm.startday.options[i-1].disabled = true;

            if (document.mainForm.startday.options[i-1].selected == true) {

                document.mainForm.startday.options[daysin[document.mainForm.startmonth.value]-1].selected = true;

            }

        } else {

            document.mainForm.startday.options[i-1].disabled = false;

        }

    }

  }
 

  function correctEndDate() {

    leapyear=false;

    year = document.mainForm.endyear.value;

    if (((year % 4 == 0) && (year % 100 != 0)) ||

        (year % 400 == 0) && (year % 4000 !=0)) leapyear=true;

    var daysin = new Array ('', 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    if (leapyear) daysin[2]=29;

    for (i = 29; i<=31; i++) {

        if (i>daysin[document.mainForm.endmonth.value]) {

            document.mainForm.endday.options[i-1].disabled = true;

            if (document.mainForm.endday.options[i-1].selected == true) {

                document.mainForm.endday.options[daysin[document.mainForm.endmonth.value]-1].selected = true;

            }

        } else {

            document.mainForm.endday.options[i-1].disabled = false;

        }

    }

  }
 

  function enableEndDate() {

    if (document.mainForm.recurrencePeriod.value > 0) {

        disable = false;

    } else {

        disable = true;

    }

    document.mainForm.endyear.disabled = disable;

    document.mainForm.endmonth.disabled = disable;

    document.mainForm.endday.disabled = disable;

  }

--></script>

  <form method=post name=mainForm>

  <input type=hidden name=ID value="<?=$ID?>">

  <input type=hidden name=act value="addaction">

  <input type=hidden name=Period value="<?=$reservation['Period']?>">

  <input type=hidden name=MemberID value="<?=$reservation['MemberID']?>">

  <input type=hidden name=ActivityID value="<?=$reservation['ActivityID']?>">

  <input type=hidden name=BlockBookingID value="<?=$blockBookingID?>">

  <input type=hidden name=StartTime value="<?=$reservation['StartTime'];?>">

  <?php

    foreach ($resources as $section) {

        echo "<input type=hidden name=resourceIDs[] value='$section[rID]'>";

    }

  ?>

  <table class=options cellpadding=0 cellspacing=10>

    <tr>

      <th colspan=2><b>Add Reservation</b></th>

    </tr>

    <tr>

      <td>

        <table class=options cellpadding=4 cellspacing=0>

          <tr>

            <td align="right">Resource: </td>

            <td><b><?=$info[Name]?></b></td>

          </tr>

          <tr>

            <td align="right">Sections: </td>

            <td><b><?php

                $printcomma=false;

                foreach ($resources as $section) {

                    if ($printcomma) {

                        echo ", ";

                    } else {

                        $printcomma = TRUE;

                    }

                    echo $section['Name'];

                }

            ?></b></td>

          </tr>

          <tr>

            <td align="right">Member: </td>

            <td><b><?=$reservation['memberName'];?></b></td>

          </tr>

          <tr>

            <td align="right">Activity: </td>

            <td><b><?=$reservation['activityName'];?></b></td>

          </tr>

          <tr>

            <td align=right>Start Time: </td>

            <td><b><?=strftime("%H:%M",$reservation['StartTime']);?></b></td>

          </tr>

          <tr>

            <td align=right>End Time: </td>

            <td><b><?=strftime("%H:%M",$reservation['StartTime']+

                ($reservation['Period']*60)) ?></b></td>

          <tr>

            <td align=right valign=top>Description: </td>

            <td><textarea name="Description" cols="50"

            rows="5"><?=$description?></textarea></td>

          </tr>

          <tr>

            <td colspan=2>Note: The first line of the description is displayed

                on the reservations calendar page.</td>

          </tr>

          <tr>

            <td align=right> Recurrence: </td>

            <td>

              <select name=recurrencePeriod onChange="enableEndDate()">

                <option value='0'>Single Reservation</option>

                <option value='1'>Daily (Mon-Fri)</option>

                <option value='2'>Weekly</option>

                <option value='3'>Fortnightly</option>

              </select>

            </td>

          </tr>
 

          <tr>

            <?php

                // Havent got any stored date range from a previous attempt

                if ($endyear=='') {

                    $startyear = $year;

                    $startmonth = $month;

                    $startday = $day;

                    $endyear = $year;

                    $endmonth = $month;

                    $endday = $day;

                }

            ?>

            <td align=right>Start Date: </td>

              <td>

                <select name="startday" onFocus="correctStartDate()"><?php

                for ($i=1; $i<=31; $i++) {

                    $checked = $i == $startday ? ' selected="selected"' : ''; ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$i?></option>

                <?php } ?>

              </select>

              <select name="startmonth" onChange="correctStartDate()"><?php

                $months=array('','January','February','March','April','May',

                    'June','July','August','September','October','November',

                    'December');

                for ($i=1; $i<=12; $i++) {

                    $checked = $i == $startmonth ? ' selected="selected"' : '' ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$months[$i]?></option>

                <?php } ?>

              </select>

            <select name="startyear" onChange="correctStartDate()"><?php

                for ($i=$year-10; $i<=$year+10; $i++) { 

                    $checked = $i == $startyear ? ' selected="selected"' : '' ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$i?></option>

            <?php

                }

            ?></select>

            </td>

          </tr>

          <tr>

            <td align=right>End Date: </td>

              <td>

                <select name="endday" disabled="disabled" onFocus="correctEndDate()"><?php

                for ($i=1; $i<=31; $i++) {

                    $checked = $i == $endday ? ' selected="selected"' : ''; ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$i?></option>

                <?php } ?>

              </select>

              <select name="endmonth" disabled="disabled" onChange="correctEndDate()"><?php

                $months=array('','January','February','March','April','May',

                    'June','July','August','September','October','November',

                    'December');

                for ($i=1; $i<=12; $i++) {

                    $checked = $i == $endmonth ? ' selected="selected"' : '' ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$months[$i]?></option>

                <?php } ?>

              </select>

            <select name="endyear" disabled="disabled" onChange="correctEndDate()"><?php

                for ($i=$year-10; $i<=$year+10; $i++) { 

                    $checked = $i == $endyear ? ' selected="selected"' : '' ?>

                    <option value="<?=$i?>"<?=$checked?>><?=$i?></option>

            <?php

                }

            ?></select>

            </td>

          </tr>

          <tr>

            <td align=right colspan=4>

                <input type=submit class=button value="Add Reservation">

                <input type=reset class=button value="Reset">

                <input type=button class=button value="Cancel"

                onclick="document.location='showCalendar.php?act=&ID=<?=$ID?>'">

            </td>

          </tr>

        </table>

      </td>

    </tr>

  </table>

  </form>

<?php

  }
 
 

  if ($act == 'view') {
 

    $_SESSION['_reservation'] = array();
 

    $today = $_SESSION['_today'];
 

    $reservation = mysql_recordset("SELECT tbl_Reservations.*,tbl_Activities.Name AS ActivityName FROM tbl_Reservations,tbl_Activities WHERE tbl_Reservations.ID=$reservationID AND tbl_Reservations.ActivityID=tbl_Activities.ID");

    if (count($reservation) == 0) {

      $reservation = mysql_recordset("SELECT tbl_Reservations.*,tbl_Activities.Name AS ActivityName FROM tbl_Reservations,tbl_Activities WHERE tbl_Reservations.ActivityID=tbl_Activities.ID");

    }

    $memberID = $reservation[0][MemberID];
 

    $operator = mysql_recordset("SELECT tbl_Operators.* FROM tbl_Operators, tbl_BlockBookings WHERE tbl_Operators.ID = tbl_BlockBookings.OperatorID AND tbl_BlockBookings.ID = " . $reservation[0]['BlockBookingID']);
 

    $mappings = mysql_recordset("SELECT tbl_Resources.* FROM tbl_ReservationMappings,tbl_Resources WHERE tbl_Resources.ID=tbl_ReservationMappings.ResourceID AND tbl_ReservationMappings.reservationID=$reservationID");

    $member = mysql_recordset("SELECT * FROM tbl_Members WHERE ID=$memberID");
 

    $todaytime  = mktime (0,0,0,date("m"),date("d"),date("Y"));

    $block = mysql_recordset("SELECT * FROM tbl_Reservations WHERE

    BlockBookingID=" . $reservation[0][BlockBookingID] .

    " AND (StartTime>=".$todaytime.") ORDER BY StartTime");

    $oldblock = mysql_recordset("SELECT * FROM tbl_Reservations WHERE

    BlockBookingID=" . $reservation[0][BlockBookingID] .

    " AND (StartTime<".$todaytime.") ORDER BY StartTime DESC");
 

    $blockbooking = mysql_recordset("SELECT * FROM tbl_BlockBookings WHERE ID=" . $reservation[0][BlockBookingID]);
 

    $startTimeObj = new timeCalculator(strftime('%H:%M',$reservation[0][StartTime]));
 

    display($message);

?>
 

<script language="javascript">

<!--
 

  function submitForm(act) {

    document.mainForm.act.value = act;

    document.mainForm.submit();

  }
 

//-->

</script>
 

  <form method=post name=mainForm>

  <input type=hidden name=ID value="<?=$ID?>">

  <input type=hidden name=MemberID value="<?=$memberID?>">

  <input type=hidden name=act value=confirm>

  <input type=hidden name=year value="<?=$year?>">

  <input type=hidden name=month value="<?=$month?>">

  <input type=hidden name=day value="<?=$day?>">

  <input type=hidden name=reservations value="<?=count($block)+count($oldblock)?>">

  <input type=hidden name=reservationID value="<?=$reservation[0][ID]?>">

  <input type=hidden name=blockBookingID value="<?=$reservation[0][BlockBookingID]?>">

  <table class=options cellpadding=4 cellspacing=10 width="90%" align="center">

    <tr>

      <th colspan=2><b>View Reservation</b></th>

    </tr>

    <tr>

      <td valign=top>

        <table class=options cellpadding=4 cellspacing=0>

          <tr>

            <td align=right>For Resource: </td>

            <td colspan=3><b><?=$info['Name']?></b></td>

          </tr>

          <tr>

            <td align=right>For Sections: </td>

            <td colspan=3>

<?php

  $flag = FALSE;

  foreach ($mappings as $resource) {

    if ($flag) {

      print ', ';

    } else {

      $flag = TRUE;

    }

    print '              <b>' . $resource[Name] . '</b>';

    print '<input type=hidden name="resourceIDs[]" value="' . $resource[ID] . '">';

  }

?>

            </td>

          </tr>

          <tr>

            <td align=right>For Member: </td>

            <td colspan=3><b><a href="../members/members.php?act=view&memberID=<?=$member[0]['ID']?>"><?=$member[0][Name]?></a></b></td>

          </tr>

          <tr>

            <td align="right">Booked By: </td>

            <td colspan=3><b><?=$operator[0]['Name']?></b></td>

          </tr>

<?php

  if ($member[0][ID] == 0) {

?>

          <tr>

            <td align=right>Name: </td>

            <td colspan=3><input type=text name=clientName value="<?=$reservation[0][ClientName]?>"></td>

          </tr>

          <tr>

            <td align=right>Tel: </td>

            <td colspan=3><input type=text name=clientTel value="<?=$reservation[0][ClientTel]?>"></td>

          </tr>

<?php

  }

?>

          <tr>

            <td align=right>On Date: </td>

            <td colspan=3><b><?=date("l j F Y",$reservation[0][StartTime])?></b></td>

          </tr>

          <tr>

            <td align=right>From Time: </td>

            <td colspan=3><b><?=$startTimeObj->dump()?></b></td>

          </tr>

          <tr>

            <td align=right>To Time: </td>

<?php $startTimeObj->addMinutes($reservation[0][Period]); ?>

            <td colspan=3><b><?=$startTimeObj->dump()?></b><input type=hidden name=Period value="<?=$reservation[0][Period]?>"></td>

          </tr>

          <tr>

            <td align=right>For Activity: </td>

            <td colspan=3><b><?=$reservation[0][ActivityName]?></b></td>

          </tr>

          <tr>

            <td align=right valign=top>Description: </td>

            <td colspan=3><b><?=$reservation[0][Description]?></b></td>

          </tr>

          <tr>

            <td colspan=2>Note: The first line of the description is displayed

                on the reservations calendar page.</td>

          </tr>

          <tr>

<?php

        if (privileged('modify')) {

?>

            <td valign=top>&nbsp;</td>

            <td><input type="checkbox" name="respending" value="true" <?=$blockbooking[0][Pending]==1?'':'checked="checked"'?> /> Confirm this booking.</td>

          </tr>

          <tr>

            <td align=right colspan=3><input type=submit class=button value="Submit Changes" /></td>

            <td align=right colspan=2><input type=button class=button

                value="Edit" onclick="submitForm('edit')">

            <input type=reset class=button value="Reset">

            </td>

<?php

        } else {

?>

            <td colspan="5">&nbsp;</td>

<?php

        }

?>

            <td align="left" colspan="2">

            <input type=button class=button value="Back to daily view" onclick="document.location='showCalendar.php?ID=<?=$ID?>'">

            <input type=button class=button value="Back to monthly view" onclick="document.location='showMonthly.php?month=<?=date("m",$reservation[0][StartTime])?>&year=<?=date("Y",$reservation[0][StartTime])?>&resourceID=<?=$mappings[0]['ID']?>'" /></td>

          </tr>

          <tr>

            <td></td>

            <td align=right colspan=3>&nbsp;</td>

          </tr>

        </table>

      </td>

      <td valign=top style="border-left: solid 1px #bbbbbb">

        <table class=options cellpadding=4 cellspacing=0>

<?php

  if (count($block) > 0) {

?>

          <tr valign=top>

            <td colspan=4>Present and upcoming reservations for this booking: </td>

          </tr>

          <tr>

            <td></td>

            <td colspan=3>

<?php

  $checkboxnumber = 0;

  foreach ($block as $record) {

    $text = "            ";

    if ($record[ID]!=$reservationID)

      $text .= "<a href=\"showCalendar.php?act=view&reservationID=" . $record[ID] . "\">";

    else

      $text .= "<b>";

    $text .= date("l j F Y",$record[StartTime]);

    if ($record[ID]!=$reservationID)

      $text .= "</a>";

    else

      $text .= "</b> (this)";

    if (privileged('modify')) {

        print "<input id=\"cb" . $checkboxnumber++ . "\" style=\"margin:0px\" type=checkbox name=\"chosenIDs[]\" value=\"" . $record[ID] . "\">&nbsp; $text";

    } else {

        print $text;

    }

    print "<br>\n";

  }

?>

            </td>

          </tr>

<?php

    if (privileged('modify')) {

?>

          <tr>

            <td></td>

            <td colspan=3><input type=button class=button value="Select All" onClick="setCheckBoxes()" />

          </tr>

          <tr>

            <td></td>

            <td colspan=3><input type=button class=button value="Cancel Reservation(s)" onclick="submitForm('remove')" />

          </tr>

<?php

    }

  } else {

          $checkboxnumber = 0;

?>

          <tr valign=top>

            <td colspan=4>Present and upcoming reservations for this booking: </td>

          </tr>

          <tr>

            <td></td>

            <td colspan=3><b>No reservations.</b>

            </td>

          </tr>

<?php

  }
 

    if (privileged('modify')) {

?>

          <tr>

            <td></td>

            <td colspan=3><input type=button class=button value="Add Reservation" onclick="submitForm('Add')" />

          </tr>

<?php

    }
 

  if (count($oldblock) > 0) {

?>

          <tr valign=top>

            <td colspan=4>Past reservations for this booking: </td>

          </tr>

          <tr>

            <td></td>

            <td colspan=3>

<?php

  foreach ($oldblock as $record) {

    $text = "            ";

    if ($record[ID]!=$reservationID)

      $text .= "<a href=\"showCalendar.php?act=view&reservationID=" . $record[ID] . "\">";

    else

      $text .= "<b>";

    $text .= date("l j F Y",$record[StartTime]);

    if ($record[ID]!=$reservationID)

      $text .= "</a>";

    else

      $text .= "</b> (this)";

    print $text;

    print "<br>\n";

  }

?>

            </td>

          </tr>

<?php

  }

?>

        </table>

      </td>

    </tr>

  </table>

  </form>
 

<script language="javascript" src="<? echo $site_url; ?>system/xplatform.js"></script>

<script language="javascript">

<!--

  function setCheckBoxes() {

    var i;

    for (i=0;i<=<?=$checkboxnumber?>;i++) {

        getObj('cb' + i).checked = 'true';

    }

  }

//-->

</script>
 

<?php
 

  }
 
 

  if ($act == 'edit') {

    if (!privileged('modify')) {

        require "../no_access.php";

        exit();

    }
 

    $_SESSION['_reservation'] = array();
 

    $today = $_SESION['_today'];
 

    $reservation = mysql_recordset("SELECT tbl_Reservations.*,tbl_Activities.Name AS ActivityName FROM tbl_Reservations,tbl_Activities WHERE tbl_Reservations.ID=$reservationID AND tbl_Reservations.ActivityID=tbl_Activities.ID");

    if (count($reservation) == 0) {
 

      $reservation = mysql_recordset("SELECT tbl_Reservations.*,tbl_Activities.Name AS ActivityName FROM tbl_Reservations,tbl_Activities WHERE tbl_Reservations.ActivityID=tbl_Activities.ID");

    }

    $memberID = $reservation[0][MemberID];
 

    $members = mysql_recordset("SELECT tbl_Members.* FROM tbl_Members WHERE

        tbl_Members.ID>0 ORDER BY tbl_Members.Name");
 

    $activities = mysql_recordset("SELECT * from tbl_Activities WHERE

        ResourceGroupID = $ID");
 

    $mappings = mysql_recordset("SELECT tbl_Resources.* FROM tbl_ReservationMappings,tbl_Resources WHERE tbl_Resources.ID=tbl_ReservationMappings.ResourceID AND tbl_ReservationMappings.reservationID=$reservationID");
 

    $allresources = mysql_recordset("SELECT * from tbl_Resources WHERE

        ResourceGroupID = $ID");
 

    $member = mysql_recordset("SELECT * FROM tbl_Members WHERE ID=$memberID");

    $block = mysql_recordset("SELECT * FROM tbl_Reservations WHERE BlockBookingID=" . $reservation[0][BlockBookingID] . " ORDER BY StartTime");
 

    $blockbooking = mysql_recordset("SELECT * FROM tbl_BlockBookings WHERE ID=" . $reservation[0][BlockBookingID]);
 

    $startTimeObj = new timeCalculator(strftime('%H:%M',$reservation[0][StartTime]));

    $startTimeOfDayObj = new timeCalculator($info['StartTime']);

    $finishTimeOfDayObj = new timeCalculator($info['FinishTime']);
 

    display($message);

?>
 

<script language="javascript">

<!--
 

  function submitForm(act) {

    document.mainForm.act.value = act;

    document.mainForm.submit();

  }
 

  function selectCont() {

    // Ensure that selected resources are next to each other

    firstsel = -1;

    lastsel = -1;

    for (i=0; i<document.getElementById('resourceIDs').length; i++) {

        if (document.getElementById('resourceIDs').options[i].selected) {

    //        alert(i + " is selected");

            if (firstsel != -1) {

                lastsel = i;

            } else {

                firstsel = i;

                lastsel = i;

            }

        }

    }

    //alert("first+last=" + firstsel + " " + lastsel);

    if (firstsel != -1) {

        for (i=firstsel; i<=lastsel; i++)

            document.getElementById('resourceIDs').options[i].selected = true;

    }

  }

//-->

</script>
 

  <form method=post name=mainForm>

  <input type=hidden name=ID value="<?=$ID?>">

  <input type=hidden name=MemberID value="<?=$memberID?>">

  <input type=hidden name=act value=editaction>

  <input type=hidden name=year value="<?=$year?>">

  <input type=hidden name=month value="<?=$month?>">

  <input type=hidden name=day value="<?=$day?>">

  <input type=hidden name=reservations value="<?=count($block)+count($oldblock)?>">

  <input type=hidden name=reservationID value="<?=$reservation[0][ID]?>">

  <input type=hidden name=blockBookingID value="<?=$reservation[0][BlockBookingID]?>">

  <table class=options cellpadding=4 cellspacing=10 width="90%" align="center">

    <tr>

      <th colspan=2><b>Edit Reservation</b></th>

    </tr>

    <tr>

      <td valign=top>

        <table class=options cellpadding=4 cellspacing=0>

          <tr>

            <td align=right>For Resource: </td>

            <td colspan=3><b><?=$info['Name']?></b></td>

          </tr>

          <tr>

            <td align=right>For Sections: </td>

            <td colspan=3>

                <select id="resourceIDs" name="newres[]" size="5" multiple="multiple" onChange="selectCont()">

<?php

        foreach ($allresources as $resource) { 

                    $checked='';

                    foreach ($mappings as $check) {

                        if ($resource['ID'] == $check['ID']) {

                            $checked=' selected="selected"';

                        }

                    }?>

                    <option value="<?=$resource['ID']?>" <?=$checked?>><?php

                        echo $resource[Name] ?></option>

<?php    }

?>

                </select>

<?php       foreach($mappings as $resource) {

                echo "<input type='hidden' name='oldres[]'

                    value='{$resource['ID']}'>";

            }

?>

            </td>

          </tr>

          <tr>

            <td colspan=4>

                Note: To select more than one section, either drag the mouse

                when selecting, or hold down CTRL and click on each entry.

            </td>

          </tr>

          <tr>

            <td align=right>For Member: </td>

            <td colspan=3>

                <select name=forMemberID>

            <?php

                foreach ($members as $record) {

                    if ($record['ID'] == $member[0][ID]) {

                        $checked = ' selected="selected"';

                    } else {

                        $checked = '';

                    }?><option value="<?=$record['ID']?>"<?=$checked?>>

                        <?=$record['Name']?></option>

            <?php } ?>

                </select></td>

          </tr>

          <tr>

            <td align=right>On Date: </td>

            <td colspan=3><b><?=date("l j F Y",$reservation[0][StartTime])?></b></td>

          </tr>

          <tr>

            <td align=right>From Time: </td>

            <td colspan=3><select name=startTime>

<?php

  $currentTime = $startTimeOfDayObj;
 

  while ($currentTime->dump() < $finishTimeOfDayObj->dump()) {

    if ($currentTime->dump() == $startTimeObj->dump()) { $selected = '

selected="selected"'; } else { $selected = ''; }

    print '                <option

value="'.$currentTime->dump().'"'.$selected.'>'.$currentTime->dump()."</option>\n";

    $currentTime->addMinutes(5);

  }

?>

              </select></td>

          </tr>

          <tr>

            <td align=right>To Time: </td>

            <td colspan=3><select name=finishTime>

<?php

  $startTimeObj->addMinutes($reservation[0][Period]);

  $currentTime = $startTimeOfDayObj;

  while ($currentTime->dump() <= $finishTimeOfDayObj->dump()) {

    if ($currentTime->dump() == $startTimeObj->dump()) { $selected = '

selected="selected"'; } else { $selected = ''; }

    print '                <option

value="'.$currentTime->dump().'"'.$selected.'>'.$currentTime->dump()."</option>\n";

    $currentTime->addMinutes(5);

  }

?>

              </select></td>

          </tr>

          <tr>

            <td align=right>For Activity: </td>

            <td colspan=3><select name=activityID>

            <?php

                foreach ($activities as $record) {

                    if ($record['ID'] == $reservation[0]['ActivityID']) {

                        $checked = ' selected="selected"';

                    } else {

                        $checked = '';

                    }?><option value="<?=$record['ID']?>"<?=$checked?>>

                        <?=$record['Name']?></option>

            <?php } ?>

                </select></td>

          </tr>

          <tr>

            <td align=right valign=top>Description: </td>

            <td colspan=3><textarea name="description" cols="50"

                rows="5"><?=$reservation[0][Description]?></textarea></td>

          </tr>

          <tr>

            <td colspan=2>Note: The first line of the description is displayed

                on the reservations calendar page.</td>

          </tr>

          <tr>

            <td valign=top></td>

            <td><input type="checkbox" name="respending" value="true" <?=$blockbooking[0][Pending]==1?'':'checked="checked"'?> /> Confirm this booking.</td>

          </tr>

          <tr>

            <td align=right colspan=4><input type=submit class=button value="Submit Changes" />

            <input type=reset class=button value="Reset">

            <input type=button class=button value="Back" onclick="document.location='showCalendar.php?ID=<?=$ID?>'"></td>

          </tr>

          <tr>

            <td></td>

            <td align=right colspan=3>&nbsp;</td>

          </tr>

        </table>

      </td>

      <td valign=top style="border-left: solid 1px #bbbbbb">

        <table class=options cellpadding=4 cellspacing=0>

          <tr valign=top>

            <td colspan=4>Apply changes to these bookings as well: </td>

          </tr>

          <tr>

            <td></td>

            <td colspan=3>

<?php

  $checkboxnumber = 0;

  foreach ($block as $record) {

    if ($record[ID]!=$reservationID) {

        $text = "            " . date("l j F Y",$record[StartTime]);

        print "<input id=\"cb" . $checkboxnumber . "\" style=\"margin:0px\" type=checkbox name=\"chosenIDs[]\" value=\"" . $record[ID] . "\">&nbsp; $text";

        print "<br>\n";

        $checkboxnumber++;

    }

  }

?>

            </td>

          </tr>

          <tr>

            <td></td>

            <td colspan=3><input type=button class=button value="Select All" onClick="setCheckBoxes()" />

          </tr>

    </tr>

  </table>

  </form>
 

<script language="javascript" src="<? echo $site_url; ?>system/xplatform.js"></script>

<script language="javascript">

<!--
 

  function setCheckBoxes() {

    var i;

    for (i=0;i<=<?=$checkboxnumber?>;i++) {

        getObj('cb' + i).checked = 'true';

    }

  }
 

//-->

</script>
 

<?php
 

  }
 

  if ($act == '') {
 

    $_SESSION['_reservation'] = array();
 

    $i= mktime(0,0,0,$month,$day+1,$year);

    $nextDayY = date("Y",$i);

    $nextDayM = date("m",$i);

    $nextDayD = date("d",$i);
 

    $i= mktime(0,0,0,$month,$day-1,$year);

    $previousDayY = date("Y",$i);

    $previousDayM = date("m",$i);

    $previousDayD = date("d",$i);
 

    // Calculate time information

    $startTime = new timeCalculator($info['StartTime']);

    $finishTime = new timeCalculator($info['FinishTime']);
 

    // Retrieve reservation information
 

    $sql = "SELECT tbl_Reservations.*,tbl_ResourceGroups.Period AS StandardPeriod,tbl_Resources.ID AS ResourceID,tbl_Activities.Name AS ActivityName, tbl_Members.Colour AS MemberColour, tbl_Members.Name AS MemberName, tbl_BlockBookings.Pending FROM tbl_Reservations,tbl_ReservationMappings,tbl_Resources,tbl_ResourceGroups,tbl_Activities,tbl_Members,tbl_BlockBookings WHERE tbl_Reservations.BlockBookingID=tbl_BlockBookings.ID AND tbl_Reservations.ID=tbl_ReservationMappings.ReservationID AND tbl_Resources.ID=tbl_ReservationMappings.ResourceID AND tbl_Activities.ID=tbl_Reservations.ActivityID AND tbl_Reservations.MemberID=tbl_Members.ID AND tbl_Reservations.StartTime>=" . mktime(0,0,0,$month,$day,$year) . " AND tbl_Reservations.StartTime<=" . mktime(0,0,0,$nextDayM,$nextDayD,$nextDayY) . " AND tbl_Resources.ResourceGroupID=$ID AND tbl_ResourceGroups.ID=$ID ORDER BY tbl_Reservations.StartTime,tbl_ReservationMappings.ResourceID";

    $reservations = mysql_recordset($sql);
 

    display($message);
 

?>
 

<script language="javascript" src="<? echo $site_url; ?>system/xplatform.js"></script>

<script language="javascript">

<!--
 

  var highlightColour = '#6666ff';

  var lowlightColour = '#dddddd';

  var highlightColumnColour = '#8888ff';

  var lowlightColumnColour = '#aaaacc';

  var highlightRowColour = '#8888ff';

  var lowlightRowColour = '#ccccee';

  var startx,starty,endx,endy,starti,startj,endi,endj,selecting = 0;

  var maxx = <?=$num_sections?>,maxy;

  var selectColumns = false,selectRows = false,conflict = false;
 

  function flip() {

    conflict = false;

    if (startx <= endx) {

      endi = endx;

      starti = startx;

    } else {

      endi = startx;

      starti = endx;

    }

    if (starty <= endy) {

      endj = endy;

      startj = starty;

    }else {

      endj = starty;

      startj = endy;

    }

  }
 

  function highlight(x,y) {

    if (!(x == 0 && y == 0)) {

      var Colour;
 

      if (y==0) {

        Colour = highlightColumnColour;

      } else if (x==0) {

        Colour = highlightRowColour;

      } else {

        Colour = highlightColour;

      }

      if (!(selecting == 1 && (x == 0 || y == 0))) {

        if (getObj('tx' + x + 'y' + y + 't') == null || getObj('tx' + x + 'y' + y + 't').className == 'reserved') {

          if (!(x == 0 || y == 0)) conflict = true;

        } else {

          setBGCOLOR(getObj('tx' + x + 'y' + y + 't'),Colour);

//          if (y > 0) getObj('tx' + x + 'y' + y + 't').style.border = 'solid 1px ' + Colour;

        }

      }

    }

  }
 

  function lowlight(x,y) {

    if (!(x == 0 && y == 0)) {

      var Colour;
 

      if (y==0) {

        Colour = lowlightColumnColour;

      } else if (x==0) {

        Colour = lowlightRowColour;

      } else {

        Colour = lowlightColour;

      }
 

      if (!(selecting == 1 && (x == 0 || y == 0))) {

        if (getObj('tx' + x + 'y' + y + 't') == null || getObj('tx' + x + 'y' + y + 't').className == 'reserved') {

          if (!(x == 0 || y == 0)) conflict = true;

        } else {

          setBGCOLOR(getObj('tx' + x + 'y' + y + 't'),Colour);

//          if (y > 0) getObj('tx' + x + 'y' + y + 't').style.border = 'solid 1px ' + Colour;

        }

      }

    }

  }
 

  function high(x,y) {

    if (selecting==0) {

      highlight(x,y);

      if (x == 0) {

        for (k=1;k<=maxx;k++) {

          highlight(k,y);

        }

      } else {

        highlight(x,0);

      }

      if (y == 0) {

        for (k=1;k<=maxy;k++) {

          highlight(x,k);

        }

      } else {

        highlight(0,y);

      }

    } else if (selecting == 1) {

      if (selectColumns == true) {

        endx = x;

      } else if (selectRows == true) {

        endy = y;

      } else {

        endy = y;

        endx = x;

      }

      flip();

      for (i=starti;i<=endi;i++) {

        for (j=startj;j<=endj;j++) {

          highlight(i,j);

        }

      }

      selecting = 0;

      highlight(0,y);

      highlight(x,0);

      selecting = 1;

    }

  }
 

  function low(x,y) {

    if (selecting==0) {

      lowlight(x,y);

      if (x == 0) {

        for (k=1;k<=maxx;k++) {

          lowlight(k,y);

        }

      } else {

        lowlight(x,0);

      }

      if (y == 0) {

        for (k=1;k<=maxy;k++) {

          lowlight(x,k);

        }

      } else {

        lowlight(0,y);

      }

    } else if (selecting == 1) {

      for (i=starti;i<=endi;i++) {

        for (j=startj;j<=endj;j++) {

          lowlight(i,j);

        }

      }

      selecting = 0;

      lowlight(0,y);

      lowlight(x,0);

      selecting = 1;

    }

  }
 

  function startSelect(x,y) {

    if (selecting == 0 && getObj('tx' + x + 'y' + y + 't').className != 'reserved') {

      if (y == 0) {

        startx = x;

        starty = 1;

        endy = maxy;

        selectColumns = true;

      } else if (x == 0) {

        startx = 1;

        starty = y;

        endx = maxx;

        selectRows = true;

      } else {

        starty = y;

        startx = x;

      }

      low(x,y);

      selecting = 1;

      high(x,y);

    } else if (selecting == 1 && getObj('tx' + x + 'y' + y + 't').className != 'reserved') {

      selecting = 2;

      selectColumns = false;

      selectRows = false;

      lowlight(0,y);

      lowlight(x,0);

    } else if (selecting == 2) {

      if (!conflict && getBGCOLOR('tx' + x + 'y' + y + 't') == highlightColour) {

        var timeObj = getObj('tx0y' + (startj-((startj-1)%6)) + 't');

        document.mainForm.startResource.value = starti-1;

        document.mainForm.finishResource.value = endi-1;

        document.mainForm.startTimeBeforeVariance.value = timeObj.innerHTML;

        document.mainForm.startTimeVariance.value = (startj-1)%6;

        document.mainForm.numberPeriods.value = 1 + endj - startj;

        document.mainForm.submit();

      } else {

        if (conflict && getBGCOLOR(getObj('tx' + x + 'y' + y + 't')) == highlightColour) {

          alert('You have chosen a block that conflicts with existing reservations.\n\nPlease choose another block.');

        }

        selecting = 0;

        for (i=starti;i<=endi;i++) {

          for (j=startj;j<=endj;j++) {

            lowlight(i,j);

          }

        }

      }

    }

  }
 

  function bookWholeDay() {

<?php

    $st = new timeCalculator($info['StartTime']);

    $ft = new timeCalculator($info['FinishTime']);

    $numper = $st->periodUntil($ft)/5;

?>

        document.mainForm.startResource.value = 0;

        document.mainForm.finishResource.value = 0;

        // Cheating here, starttime should be in half hour intervals

        // With the starttimevariance adding on 5 minutes each time

        document.mainForm.startTimeBeforeVariance.value = '<?=$info['StartTime']?>';

        document.mainForm.startTimeVariance.value = 0;

        document.mainForm.numberPeriods.value = <?=$numper?>;

        document.mainForm.submit();

  }
 
 

// -->

</script>
 

<form method=post action="showCalendar.php" name=mainForm>

<input type=hidden name=ID value="<?=$ID?>">

<input type=hidden name=startResource value="">

<input type=hidden name=finishResource value="">

<input type=hidden name=startTimeOfDay value="<?=$info['StartTime']?>">

<input type=hidden name=finishTimeOfDay value="<?=$info['FinishTime']?>">

<input type=hidden name=startTimeBeforeVariance value="">

<input type=hidden name=startTimeVariance value="">

<input type=hidden name=year value="<?=$year?>">

<input type=hidden name=month value="<?=$month?>">

<input type=hidden name=day value="<?=$day?>">

<input type=hidden name=numberPeriods value="">

<input type=hidden name=act value=reserve>
 

<?php

    $prev3months=mktime(0,0,0,$month - 3,$day,$year);

    $next3months=mktime(0,0,0,$month + 3,$day,$year);

    $prev6months=mktime(0,0,0,$month - 6,$day,$year);

    $next6months=mktime(0,0,0,$month + 6,$day,$year);

?>

<div id="minical" style="position:absolute;visibility:<?=(!isset($minical))?'hidden':$minical?>;top:5;left:5;border: solid black 1px;background:white;">

<table>

<tr>

<td style="font-size:10px;"><a href="showCalendar.php?year=<?=date("y",$prev3months)?>&month=<?=date("m",$prev3months)?>&day=<?=date("d",$prev3months)?>&minical=visible">Back 3 months</a></td>

<td style="font-size:10px;">&nbsp;</td>

<td align="right" style="font-size:10px;"><a href="showCalendar.php?year=<?=date("y",$next3months)?>&month=<?=date("m",$next3months)?>&day=<?=date("d",$next3months)?>&minical=visible">Forward 3 months</a></td>

</tr>

<tr>

<td style="font-size:10px;"><a href="showCalendar.php?year=<?=date("y",$prev6months)?>&month=<?=date("m",$prev6months)?>&day=<?=date("d",$prev6months)?>&minical=visible">Back 6 months</a></td>

<td style="font-size:10px;">&nbsp;</td>

<td align="right" style="font-size:10px;"><a href="showCalendar.php?year=<?=date("y",$next6months)?>&month=<?=date("m",$next6months)?>&day=<?=date("d",$next6months)?>&minical=visible">Forward 6 months</a></td>

</tr>

<tr>

<?php

  minicals($year, $month, $day, 'visible');

?>

</tr>

<tr><td colspan=3 align=right>[<a href="#" onClick="getObj('minical').style.visibility = 'hidden'">Close Calendar</a>]</td>

</tr>

</table>

</div>
 

<table cellpadding="0" cellspacing="0" width="100%" class="calendar">

<?php

  $i= mktime(0,0,0,$month,$day,$year);

  foreach ($reservations as $reservation) {

    $today[$reservation['ResourceID']][$reservation['StartTime']] = $reservation;

  }
 

  if (isset($today)) {

      $_SESSION['_today'] = $today;

  }
 

  // Sort the columns/resources with natural order sort

  $to_sort = array();

  foreach ($result as $row) {

    array_push($to_sort, $row['Name']);

  }

  natcasesort($to_sort);
 

  $sorted = array();

  foreach($to_sort as $key => $value) {

    array_push($sorted, $result[$key]);

  }
 

?>

  <tr>

    <td align=right colspan=<?=($num_sections+1)?>>Reservations for

    <b><?=$info['Name']?></b> on <b><?=strftime('%A %e %B %Y',$i)?></b></td>

  </tr>

  <tr>

    <td colspan=<?=$num_sections+1?>><a href="showCalendar.php?year=<?=$previousDayY?>&month=<?=$previousDayM?>&day=<?=$previousDayD?>">Previous Day</a> | <a href="showCalendar.php?year=<?=date('Y')?>&month=<?=date('m')?>&day=<?=date('d')?>">Today</a> | <a href="showCalendar.php?year=<?=$nextDayY?>&month=<?=$nextDayM?>&day=<?=$nextDayD?>">Next Day</a> |

<a onClick="getObj('minical').style.visibility='visible'" href="#">Launch Calendar...</a> | <a href="#" onclick="javascript:window.open('popupCalendar.php?year=<?=$year?>&month=<?=$month?>&day=<?=$day?>','','status=0,toolabar=0,location=0,menus=0,directories=0,resizable=0,scrollbars=0,height=195,width=360')">Popup Calendar...</a> | 

<?php

    if (privileged('modify')) {

?>

        <a href="javascript:bookWholeDay()">Whole Day Booking</a> |

<?php

    }

?>

<a href="showMonthly.php?year=<?=$year?>&month=<?=$month?>&resourceID=<?=$sorted[0]['ID']?>">Monthly view</a>

</td>

  </tr>

  <tr>

    <td></td>

<?php

  $strHeader = "";

  $strFooter = "";

  $i = 1;

  $columns = array();
 

  $tablewidth=100/count($sorted);
 

  foreach ($sorted as $row) {

    $today_resource[$i] = $row['ID'];

    if (privileged('modify')) {

        $strHeader .= '  <th width="'.$tablewidth.'%" bgcolor="#aaaacc" id=tx'.

        $i.'y0t onMouseOver="high(' . $i . ',0)" onMouseOut="low(' . $i .

        ',0)" onMouseDown="startSelect(' . $i . ',0)">&nbsp;' . $row['Name'] .

        '&nbsp;</th>' . "\n";

    } else {

        $strHeader .= '  <th width="'.$tablewidth.'%" bgcolor="#aaaacc" id=tx'.

        $i.'y0t>&nbsp;' . $row['Name'] . '&nbsp;</th>' . "\n";

    }
 

    $strFooter .= '  <th bgcolor="#aaaacc">&nbsp;' . $row['Name'] . '&nbsp;</th>' . "\n";

    $columns[] = 0;

    $i++;

  }

  print $strHeader;

?>

  </tr>

  <tr>

<?php

  $currentTime = $startTime;

//  print_r($today);

  $j = 1;

  $fives = 5;

  while ($currentTime->dump() < $finishTime->dump()) {

    if (privileged('modify')) {

?>

    <td rowspan=6 height=15px bgcolor="#ccccee" class=time id=tx0y<?=$j?>t onMouseOver="high(0,<?=$j?>)" onMouseOut="low(0,<?=$j?>)" onMouseDown="startSelect(0,<?=$j?>)"><?=$currentTime->dump()?></td>

<?php

    } else {

?>

    <td rowspan=6 height=15px bgcolor="#ccccee" class=time id=tx0y<?=$j?>t><?=$currentTime->dump()?></td>

<?php

    }

    for ($fives=0;$fives<6;$fives++) {

    for ($i=1;$i<=$num_sections;$i++) {

      $colspan = 1;

      $currtime = mktime($currentTime->hour,$currentTime->min,0,$month,$day,

         $year);

      if (isset($today[$today_resource[$i]][$currtime])) {

        $thisres = $today[$today_resource[$i]][$currtime];

        $columns[$i-1] = $thisres['Period']/5;

        for ($k=$i+1;$k<=$num_sections;$k++) {

          if (isset($today[$today_resource[$k]][$currtime]['ID']) &&

            $today[$today_resource[$k]][$currtime]['ID'] == $thisres['ID']) {

            $columns[$k-1] = $columns[$i-1];

            $colspan++;

            unset($today[$today_resource[$k]][$currtime]);

          }

        }

    if (privileged('modify')) {

?>

    <td colspan="<?=$colspan?>" bgcolor="<?=$thisres['MemberColour']?>"

rowspan="<?=$columns[$i-1]?>" height="<?=$columns[$i-1]*3?>px" valign="top" class="reserved" id=tx<?=$i?>y<?=$j?>t onMouseOver="high(<?=$i?>,<?=$j?>)" onMouseOut="low(<?=$i?>,<?=$j?>)" onClick="startSelect(<?=$i?>,<?=$j?>)">

<?php

    } else {

?>

    <td colspan="<?=$colspan?>" bgcolor="<?=$thisres['MemberColour']?>"

rowspan="<?=$columns[$i-1]?>" height="<?=$columns[$i-1]*3?>px" valign="top" class="reserved" id=tx<?=$i?>y<?=$j?>t>

<?php

    }

?>

      <a href="showCalendar.php?act=view&reservationID=<?=$thisres['ID']?>"><?=$thisres['MemberName']?></a>

<?php

        $thisresTimeObj = $currentTime;

        $thisresTimeObj->addMinutes($thisres['Period']);

        print '('.$thisres['ActivityName'].')';

        if ($columns[$i-1] > 10) print '<br>';

?>

      <b><?=$currentTime->dump().' - '.$thisresTimeObj->dump()?></b>

      <i><?=$thisres['Pending']==1?'(Pending)':''?></i>

<?php

      if ($columns[$i-1] > 20) print '<br>';

      // Print the first line of the description

      print strtok($thisres['Description'],"\r\n");

?>

    </td>

<?php

      }

      if ($columns[$i-1] == 0) {

        if (privileged('modify')) {

?>

    <td bgcolor="#dddddd" height="3px" class="unreserved<?=($fives==5)?'boundary':''?>" align="center" id=tx<?=$i?>y<?=$j?>t onMouseOver="high(<?=$i?>,<?=$j?>)" onMouseOut="low(<?=$i?>,<?=$j?>)" onClick="startSelect(<?=$i?>,<?=$j?>)"></td>

<?php

        } else {

?>

    <td bgcolor="#dddddd" height="3px" class="unreserved<?=($fives==5)?'boundary':''?>" align="center" id=tx<?=$i?>y<?=$j?>t></td>

<?php

        }

      } else {

        $columns[$i-1]--;

      }

    }

    $currentTime->addMinutes(5);

    $j++;

?>

  </tr>

  <tr>

<?php

    }

  }

?>

    <td></td>

<?php print $strFooter; ?>

  </tr>

</table>

</form>
 

<script language=javascript>

<!--

  maxy = <?=($j-1)?>;

// -->

</script>
 

<?php
 

  }
 

  require "../system/shell_iframe_footer.php"
 

?>

Open in new window

0
Comment
Question by:mcamed
  • 2
  • 2
4 Comments
 

Author Comment

by:mcamed
ID: 20352103
Also, after diggin a bit, it looks like there isn't even a MySQL db entry for the Finish Time....

Hmm.  I've tried emailing the creators, but I might need to bug the crap out of them.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20352394
I can't login to your webpage with demo and demo :)
But its ok, it sounds like (unless you have missed something) that this openbooking software is missing a chunk of its code, if this is truely the case, it cannot be fixed easily.

Hope you do get the creator's rsponse, if not, and if you want to get it up and running pretty soon, maybe switching to another online booking script is an option?
0
 

Author Comment

by:mcamed
ID: 20352846
That's an option, right there!  Do you have any suggestions while I'm awaiting his response?

Also, you can log in now.

demo and _demo <-Note the underscore!
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20353334
i'm not sure what your usage purpose is for the script, but this may help:
http://sourceforge.net/projects/phpreservation/
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now