function stylePeriod($period, $type)
{
    // If length is given as a concatenated number
    // Loops through each character in string and calls self
    // using (some character,type)
    if (strlen($period) > 1) {
        // Initalise result
        $result = "";
        // For each character in string
        for ($i = 0; $i < strlen($period); $i++) {
            // Sets char as char in given position
            $thisint = (int) substr($period, $i, 1);
            // Append to result using output of function for each character
            $result .= stylePeriod($thisint, $type);
            // If not last item, print comma + space
            if ($i != strlen($period) - 1) {
                $result .= ", ";
            }
            // if
        }
        // for
        return $result;
    } else {
        if ($type == "period") {
            if ($period == 0) {
                return "All day";
            } else {
                return $period;
            }
            // else
        } elseif ($type == "vehicle") {
            switch ($period) {
                // accounts for break and lunch
                case 0:
                    return "All day";
                    break;
                case 1:
                    return 1;
                    break;
                case 2:
                    return 2;
                    break;
                case 3:
                    return "Break";
                    break;
                case 4:
                    return 3;
                    break;
                case 5:
                    return 4;
                    break;
                case 6:
                    return "Lunch";
                    break;
                case 7:
                    return 5;
                    break;
                case 8:
                    return 6;
                    break;
            }
            // switch
        } else {
            switch ($period) {
                case 0:
                    return "All day";
                    break;
                case 1:
                    return "9:00 - 10:00";
                    break;
                case 2:
                    return "10:00 - 11:00";
                    break;
                case 3:
                    return "11:00 - 12:00";
                    break;
                case 4:
                    return "12:00 - 13:00";
                    break;
                case 5:
                    return "13:00 - 14:00";
                    break;
                case 6:
                    return "14:00 - 15:00";
                    break;
                case 7:
                    return "15:00 - 16:00";
                    break;
                case 8:
                    return "16:00 - 17:00";
                    break;
            }
            // switch
        }
        // else
    }
    // else
}
Beispiel #2
0
function printTodayBookings()
{
    try {
        // Sets today's date in form YYYYMMDD for searching
        $today = date("Ymd");
        // Start by initialising an array, which will be used to loop through
        // to check each table for bookings
        // Stores table name, table string, and resource type
        $tables = array(array("laptoptrolley", "Laptop Trolley", "IT Equipment"), array("ipadtrolleyblack", "iPad Trolley (Black)", "IT Equipment"), array("ipadtrolleygrey", "iPad Trolley (Grey)", "IT Equipment"), array("conferenceroom", "Conference Room", "Rooms"), array("meetingroom", "Meeting Room", "Rooms"), array("minibusjbx", "Minibus JBX", "Vehicles"), array("minibusjha", "Minibus JHA", "Vehicles"), array("minibuslle", "Minibus LLE", "Vehicles"), array("minibusyhj", "Minibus YHJ", "Vehicles"), array("slt_grouptherapy", "Group Therapy", "SLTRooms"), array("slt_individualtherapy", "Individual Therapy", "SLTRooms"), array("slt_signalong", "Signalong", "SLTRooms"), array("slt_ace", "ACE", "Assessments"), array("slt_dls", "DLS", "Assessments"), array("slt_celf4", "CELF 4", "Assessments"), array("slt_rlsbst", "RLS BST", "Assessments"), array("slt_rlsapt", "RLS APT", "Assessments"), array("slt_rlswfvt", "RLS WFVT", "Assessments"), array("slt_clear", "CLEAR", "Assessments"), array("slt_celf3", "CELF 3", "Assessments"), array("slt_towk", "TOWK", "Assessments"), array("slt_clip", "CLIP", "Assessments"), array("slt_stass", "STASS", "Assessments"), array("slt_stap", "STAP", "Assessments"), array("slt_acap", "ACAP", "Assessments"), array("slt_screener", "Phonology Screener", "Assessments"), array("slt_ndp", "NDP", "Assessments"), array("slt_talc1", "TALC 1", "Assessments"), array("slt_talc2", "TALC 2", "Assessments"));
        // Sets a return string which will be printed once all other functions
        // have taken place
        // Mainly so number of bookings can be written first
        $returnstring = "";
        // Creates counter for the number of bookings
        $numbookings = 0;
        // For each element in array, i.e. for every table
        foreach ($tables as $table) {
            // Gets an array of all periods booked for this resource on this date
            $results = findBookingsForDate($today, $table[0], $table[1], $table[2]);
            if ($results) {
                for ($i = 0, $c = count($results); $i < $c; $i++) {
                    // Uses resulting period and resource type to style the period
                    $returnstring .= "{$table['1']} is booked for <b>" . stylePeriod($results[$i], $table[2]) . " </b><br>";
                    $numbookings += 1;
                }
                // for
            }
            // if
        }
        // foreach
        if ($numbookings == 0) {
            echo "<b>You have no bookings for today.</b><br>";
            echo "To make a booking, go to \"Make a Booking\" and select a resource.<br>";
        } else {
            // Different return string for a single booking
            if ($numbookings == 1) {
                echo "<b>You have {$numbookings} booking today:<br></b>";
                echo "<p>{$returnstring}<p>";
            } else {
                echo "<b>You have {$numbookings} bookings today:<br></b>";
                echo "<p style='line-height:200%;'>{$returnstring}</p>";
            }
            // else
        }
        // else
    } catch (Exception $e) {
        echo "<b>An error occured:</b><br>";
        echo $sqlDeleteFromTable . "<br>";
        echo $e->getMessage();
    } finally {
    }
}
function writeTable($conn, $showall)
{
    $id = $_SESSION["id"];
    $sqlGetBookings = "SELECT * FROM RecurringBookings\n                         WHERE BookedByID={$id}";
    $resultGetBookings = mysqli_query($conn, $sqlGetBookings);
    $today = date('Ymd');
    while ($row = mysqli_fetch_assoc($resultGetBookings)) {
        // if we want to show all bookings
        // or today's date is less than the end date of the booking
        if ($showall == true || strtotime($today) <= strtotime($row["EndDate"])) {
            echo "<tr>";
            echo "<td>" . styleResource($row["Resource"]) . "</td>";
            echo "<td>" . styleDay($row["RecurDay"]) . "</td>";
            echo "<td>" . stylePeriod($row["RecurPeriod"], getResourceType($row["Resource"])) . "</td>";
            echo "<td>";
            if ($row["isWeekly"] == 1) {
                echo "Week";
            } else {
                echo "Fortnight";
            }
            echo "</td>";
            echo "<td>" . styleDate($row["StartDate"]) . "</td>";
            echo "<td>" . styleDate($row["EndDate"]) . "</td>";
            ?>
        <td>
          <form method="POST" action="managerecurring.php">
          <!--Has a confirm box to make sure user can cancel action-->
          <button type="submit" id="deletebooking" name="deletebooking"
                  onclick="return confirm('Are you sure you want to delete this recurring record? \nThat includes ALL future bookings related to this recurrence!');"
                  value=<?php 
            echo "'" . $row["BookingID"] . "," . $row["Resource"] . "," . $row["BookedByID"] . "'";
            ?>
>Delete</button>
          </form>
        </td>
        <?php 
        }
        // if
    }
    // while
}
function writeBookingsForTable($includepast, $conn, $id, $table, $tablestring)
{
    $sqlGetBookings = "SELECT BookingID,BookingDate,BookingPeriod,BookingDesc FROM {$table}\n                             WHERE BookedByID={$id} ORDER BY bookingdate DESC, bookingperiod ASC";
    $resultGetBookings = mysqli_query($conn, $sqlGetBookings);
    while ($row = mysqli_fetch_assoc($resultGetBookings)) {
        // If includepast=true, i.e. write ALL bookings, past and current
        if ($includepast) {
            echo "<tr>";
            echo "<td>" . $row["BookingDesc"] . "</td>";
            echo "<td>" . $row["BookingDate"] . "</td>";
            echo "<td>" . stylePeriod($row["BookingPeriod"], getResourceType($table)) . "</td>";
            echo "<td>{$tablestring}</td>";
            ?>
              <td>
                <form method="POST" action="managebookings.php">
                <!--Has a confirm box to make sure user can cancel action-->
                <button type="submit" id="deletebooking" name="deletebooking" onclick="return confirm('Are you sure you want to delete this record?');" value=<?php 
            echo "'" . $row["BookingID"] . "," . $table . "'";
            ?>
>Delete</button>
                </form>
              </td>
              <?php 
            echo "</tr>";
        } else {
            // If booking date is not in the past, print row
            if (!checkIfInThePast($row["BookingDate"])) {
                echo "<tr>";
                echo "<td>" . $row["BookingDesc"] . "</td>";
                echo "<td>" . styleDate($row["BookingDate"]) . "</td>";
                echo "<td>" . stylePeriod($row["BookingPeriod"], getResourceType($table)) . "</td>";
                echo "<td>{$tablestring}</td>";
                ?>
                <td>
                  <form method="POST" action="managebookings.php">
                  <!--Has a confirm box to make sure user can cancel action-->
                  <button type="submit" id="deletebooking" name="deletebooking" onclick="return confirm('Are you sure you want to delete this record?');" value=<?php 
                echo "'" . $row["BookingID"] . "," . $table . "'";
                ?>
>Delete</button>
                  </form>
                </td>
                <?php 
                echo "</tr>";
            }
            // if
        }
        // else
    }
    // while
}