public function handleForm(Context $context, $action)
 {
     if ($action == "createReservation") {
         if (isset($_POST['equip_id']) && $_POST['equip_id'] != "" && (isset($_POST['start_date']) && $_POST['start_date'] != "") && (isset($_POST['length']) && $_POST['length'] != "")) {
             $equipId = $_POST['equip_id'];
             $equip = EquipmentDao::getEquipmentByID($equipId);
             if ($equip != null) {
                 if (SessionUtil::getUserlevel() >= $equip->minUserLevel) {
                     $startDate = $_POST['start_date'];
                     $endDate = DateUtil::incrementDate($startDate, $_POST['length']);
                     $reservations = ReservationDao::getReservationsForEquipmentByDate($equipId, $startDate, $endDate);
                     if (count($reservations) == 0) {
                         $user = UserDao::getUserByUsername(SessionUtil::getUsername());
                         $reservation = ReservationDao::createReservation($user->id, $equipId, $_POST['length'], $startDate, $endDate, $_POST['user_comment']);
                         EmailUtil::sendNewReservationNotices($user, $reservation);
                     } else {
                         $context->addError("Reservations already exist during selected dates ({$startDate} and {$endDate}).");
                     }
                 } else {
                     $context->addError("Cannot reserve equipment (User Level).");
                 }
             } else {
                 $context->addError("No such equipment.");
             }
         } else {
             $context->addError("Required Field Left Blank.");
         }
     } else {
         $context->addError("Incorrect Action.");
     }
 }
 public static function updateReservationStatus($resId, $status, $sendEmail)
 {
     Database::doQuery("UPDATE " . Database::addPrefix(ReservationDao::table_name) . " SET mod_status = '" . Database::makeStringSafe($status) . "'" . " WHERE res_id = '" . Database::makeStringSafe($resId) . "'");
     if ($sendEmail) {
         $reservation = ReservationDao::getReservation($resId);
         $user = UserDao::getUserByID($reservation->userId);
         EmailUtil::sendUpdateReservationNotice($user, $reservation);
     }
 }
 public function generateHTML()
 {
     $reservation = ReservationDao::getReservation($_GET['resid']);
     if ($reservation == null) {
         $this->context->addError("Reservation Doesn't Exist.");
         return $this->context->getErrorHTML();
     }
     $user = UserDao::getUserByID($reservation->userId);
     $equip = EquipmentDao::getEquipmentByID($reservation->equipId);
     return "\n\t\t\t<center><h3>Reseravation Info</h3></center>\n\t\t\t<table class=\"viewreservation\">\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"header\">User Information</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\n\t\t\t\t\t<td class=\"centeredcellbold\">Name</th>\n\t\t\t\t\t<td class=\"centeredcell\">" . $user . "</td>\n\t\t\t\t\t<td class=\"centeredcellbold\">Warnings</th>\n\t\t\t\t\t<td class=\"centeredcell\"><a href=\"./index.php?pageid=viewWarnings&userid=" . $user->id['user_id'] . "\">" . WarningDao::getWarningCountForUserByType($user->id, RES_WARNING_ACTIVE) . "(" . WarningDao::getWarningCountForUser($user->id) . ")</a></td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"header\">Equipment Information</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=2 class=\"centeredcellbold\">Name</th>\n\t\t\t\t\t<td colspan=2 class=\"centeredcell\">" . $equip . "</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"header\">Reservation Information</td>\n\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t\t<td class=\"centeredcellbold\">Start Date</td>\n\t\t\t\t\t<td class=\"centeredcell\">" . $reservation->startDate . "</td>\n\t\t\t\t\t<td class=\"centeredcellbold\">End Date</td>\n\t\t\t\t\t<td class=\"centeredcell\">" . $reservation->endDate . "</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=4 class=\"centeredcellbold\">Current Status: " . $reservation->getColoredModStatusString() . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"centeredcellbold\">User Comment</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"topaligncell\">&nbsp;" . $reservation->userComment . "</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"centeredcellbold\">Admin Comment</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<td colspan=4 class=\"topaligncell\">&nbsp;" . $reservation->adminComment . "</td>\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t" . $this->getCheckinRow($reservation) . "\n\t\t\t\n\t\t\t</table>\n\t\t\n\t\t";
 }
 public function generateHTML()
 {
     $username = SessionUtil::getUsername();
     $user = UserDao::getUserByUsername($username);
     $reservations = ReservationDao::getReservationsForUser($user->id, 5);
     $reservationHTML = "";
     foreach ($reservations as $res) {
         $status = $res->getModStatusString();
         $equipment = EquipmentDao::getEquipmentByID($res->equipId);
         $reservationHTML = $reservationHTML . "<tr>\n\t\t\t\n\t\t\t\t\t<td class=\"myequip" . $status . "\">" . $equipment->name . "</td>\n\t\t\t\t\t<td class=\"myequip" . $status . "\">" . $status . "</td>\n\t\t\t\t\t<td class=\"myequip" . $status . "\">" . $res->startDate . "</td>\n\t\t\t\t\t<td class=\"myequip" . $status . "\">" . $res->endDate . "</td>\n\t\t\t\t\t<td class=\"myequip" . $status . "\"><a href=\"./index.php?pageid=viewReservation&resid=" . $res->id . "\">View</a></td>\n\t\t\t\t\t\t\n\t\t\t\t</tr>";
     }
     return OfficeHourCalendar::HTML . "<h3>Your Reservations</h3>\n\t\t\n\t\t<table class=\"myequip\">\n\t\t\n\t\t\t<tr>\n\t\t\n\t\t\t\t<td class=\"header\">Equipment Name</td>\n\t\t\t\t<td class=\"header\">Status</td>\n\t\t\t\t<td class=\"header\">Check-out Date</td>\n\t\t\t\t<td class=\"header\">Due Date</td>\n\t\t\t\t<td class=\"header\">-</td>\n\t\t\t\n\t\t\t</tr>\n\t\t\t\n\t\t\t" . $reservationHTML . "\n\t\n\t\t</table>";
 }
 public function handleForm(Context $context, $action)
 {
     if ($action == "delete") {
         if (SessionUtil::getUserlevel() == RES_USERLEVEL_ADMIN) {
             ReservationDao::deleteReservation($_POST['resid']);
         } else {
             $context->addError("Action Not Allowed (Userlevel)");
         }
     } else {
         if ($action == "checkin") {
             if (SessionUtil::getUserlevel() >= RES_USERLEVEL_LEADER) {
                 ReservationDao::updateReservationStatus($_POST['resid'], RES_STATUS_CHECKED_IN, false);
             } else {
                 $context->addError("Action Not Allowed (Userlevel)");
             }
         } else {
             if ($action == "checkout") {
                 if (SessionUtil::getUserlevel() >= RES_USERLEVEL_LEADER) {
                     ReservationDao::updateReservationStatus($_POST['resid'], RES_STATUS_CHECKED_OUT, false);
                 } else {
                     $context->addError("Action Not Allowed (Userlevel)");
                 }
             } else {
                 if ($action == "updateStatus") {
                     if (SessionUtil::getUserlevel() == RES_USERLEVEL_ADMIN) {
                         ReservationDao::updateReservationStatus($_POST['resid'], $_POST['status'], true);
                     } else {
                         $context->addError("Action Not Allowed (Userlevel)");
                     }
                 } else {
                     $context->addError("Incorrect Action.");
                 }
             }
         }
     }
 }