function testdbRoomLogsModule() { // Creates some room logs to add to the database $today = date('y-m-d'); $roomLog1 = new RoomLog($today); $roomLog2 = new RoomLog("11-02-07"); // Alter the status and log notes of a room $roomLog2->set_log_notes("Room Log 2"); $roomLog2->set_status("archived"); // test the insert function $this->assertTrue(insert_dbRoomLog($roomLog1)); $this->assertTrue(insert_dbRoomLog($roomLog2)); // test the retrieve function $this->assertEqual(retrieve_dbRoomLog($roomLog1->get_id())->get_status(), "unpublished"); $this->assertEqual(retrieve_dbRoomLog($roomLog2->get_id())->get_status(), "archived"); // test the update function $roomLog1->set_log_notes("Room Log 1 notes"); $this->assertTrue(update_dbRoomLog($roomLog1)); $this->assertEqual(retrieve_dbRoomLog($roomLog1->get_id())->get_log_notes(), "Room Log 1 notes"); // test the delete function $this->assertTrue(delete_dbRoomLog($roomLog1->get_id())); $this->assertFalse(retrieve_dbRoomLog($roomLog1->get_id())); $this->assertTrue(delete_dbRoomLog($roomLog2->get_id())); echo "testdbRoomLogs complete"; }
} } // Check if the save button was hit if ($_POST['submit'] == "Save Roomlog") { // Try to update the roomlog if (update_dbRoomLog($roomLog)) { echo "<h3 style=\"text-align:center\">Roomlog updated successfully</h3>"; } else { if (insert_dbRoomLog($roomLog)) { echo "<h3 style=\"text-align:center\">Roomlog saved successfully</h3>"; } } } // Check if today's room log has been saved before: if not, save it. if (!retrieve_dbRoomLog($roomLogID) && $roomLogID == date("y-m-d")) { if (insert_dbRoomLog($roomLog)) { echo "<h3 style=\"text-align:center\">Today's room log has been saved.</h3>"; } else { echo "<h3 style=\"text-align:center;color:red\">Today's room log has not been saved.</h3>"; } } ?> <!-- Display the room log --> <?php // Generate a date object from the given date $currentDate = strtotime($date); // String of this date, including the weekday and such $formattedDate = date("l, F j, Y", $currentDate); // Only display the room log if one exists if ($roomLog instanceof RoomLog) {
/** * function to update an entry in the dbRoomLogs database * @param $roomLog the room log to update */ function update_dbRoomLog($roomLog) { // check if the room log is a room log if (!$roomLog instanceof RoomLog) { //print an error echo "Invalid argument for update dbRoomLog function\n"; return false; } // find the roomlog in the database if (delete_dbRoomLog($roomLog->get_id())) { return insert_dbRoomLog($roomLog); // Update every room in the room log as well } else { echo mysql_error() . " unable to update dbRoomLog :" . $roomLog->get_id() . "\n"; return false; } }