mod_roomReservationBookingTable: if weekends are not shown, show the next week _also_...
[iserv-mod-room-reservation.git] / includes / mod_roomReservationBookingTable.inc
old mode 100755 (executable)
new mode 100644 (file)
index c325d88..fd85ef1
@@ -118,6 +118,8 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
   protected $strPostAccount;
   /** (int) recurrence interval, POST data */
   protected $nPostInterval;
+  /** (string) Array of error messages */
+  protected $asErrors = array();
   
   /***************************************************************************/
   /**
@@ -139,7 +141,11 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
     $this->oRm = $oRm;
     $this->oBm = $oBm;
    
-    $this->processRequestVariables();
+    try {
+      $this->processRequestVariables();
+    } catch(Exception $e) {
+      $this->asErrors[] = $e->getMessage();
+    }
     $this->addCSS();
   }
 
@@ -151,24 +157,26 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
    */
 
   /**
-   * Process the REQUEST variables and preset the some variables
+   * Process the REQUEST variables and preset the some variables. Throws an
+   * exception if the room provided by the GET data is not allowed for booking
    * @return void
+   * @throws Exception
    */
   protected function processRequestVariables() {
     
-    ########################
-    # FIXME remove this
-    var_export($_GET); echo "<p />";
-    var_export($_POST); echo "<p />";
-    ########################
-    
     // default values
-    $aoRooms = $this->oRm->getRooms();
-    if($aoRooms != array()) {
-      $or = $aoRooms[0];
-      $this->setRoom($or->getName());
+    $aoRooms = $this->oCfg->getWhitelistedRooms();
+    if(count($aoRooms) < 1) {
+      $this->setRoom("");
+    } else {
+      $this->setRoom($aoRooms[0]->getName());
+    }
+    // if weekends are not shown, show the next week already on saturday
+    if(!$this->oCfg->isShowWeekend() and (date("w") == 6 or date("w") == 0)) {
+      $this->setDate(strtotime("monday"));
+    } else {
+      $this->setDate(time());
     }
-    $this->setDate(time());
     $this->setAction(MOD_ROOM_RESERVATION_BT_ACTION_SHOW);
     $this->nPostInterval = 0;
    
@@ -185,8 +193,9 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
         MOD_ROOM_RESERVATION_BT_ACTION_SHOW)))));
       $this->setDate(isset($_GET["mod_roomReservationBookingTable"]["date"]) ?
         intval($_GET["mod_roomReservationBookingTable"]["date"]) : time());
-      $this->setRoom(isset($_GET["mod_roomReservationBookingTable"]["room"]) ?
-        $_GET["mod_roomReservationBookingTable"]["room"] : "");
+      if(isset($_GET["mod_roomReservationBookingTable"]["room"])) {
+        $this->setRoom($_GET["mod_roomReservationBookingTable"]["room"]);
+      }
       $this->setTsFirst(
         isset($_GET["mod_roomReservationBookingTable"]["tsfirst"]) ?
         intval($_GET["mod_roomReservationBookingTable"]["tsfirst"]) : 0);
@@ -265,16 +274,6 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
           $_POST["mod_roomReservationBookingTable"]["submitdelete"] : "");
       }
     }
-   
-    ################
-    /** FIXME remove this */
-    echo sprintf("date: %s <br />", $this->getDate());
-    echo sprintf("room: %s <br />", $this->getRoom());
-    echo sprintf("reason: %s <br />", $this->getReason());
-    echo sprintf("tsfirst: %s <br />", $this->getTsFirst());
-    echo sprintf("tslast: %s <br />", $this->getTsLast());
-    echo sprintf("action: %s <br />", $this->getAction());
-    ################
   }
  
   /***************************************************************************/
@@ -311,10 +310,19 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
  
   /**
    * Set the room of the requested booking or the room to be shown in the
-   * booking table
+   * booking table. Throws an Exception if the room is not allowed for booking.
    * @param $str (string)
+   * @throws Exception
    */
-  protected function setRoom($str) { $this->strRoom = $str; }
+  protected function setRoom($str) {
+    // only allow whitelisted rooms
+    if($this->oCfg->isRoomWhitelisted($str)) {
+      $this->strRoom = $str;
+    } else {
+      throw new Exception(_c("room-reservation:This room is not available ".
+       "for booking."));
+    }
+  }
  
   /**
    * Set the reason of the requested booking
@@ -403,9 +411,10 @@ class mod_roomReservationBookingsTable /* extends mclWidget */ {
     $strCss = <<<CSS
 #mod_roomReservationBookingTable .msg { font-weight:800; }
 #mod_roomReservationBookingTable td {
-  vertical-align:middle;
-  height:7em;
-  border:1px solid white; padding:0.4em;
+  vertical-align: middle;
+  height: 5em;
+  border: 1px solid white;
+  padding:0.4em;
 }
 #mod_roomReservationBookingTable td.booking { background-color:#5276AB; }
 #mod_roomReservationBookingTable td.new { background-color:#008015; }
@@ -440,7 +449,13 @@ CSS;
       throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED);
       return;
     }
-   
+    
+    // print error messages and return if there are any
+    if(count($this->asErrors) > 0) {
+      printf("<p class='err'>%s</p>", join("<br />\n", $this->asErrors));
+      return;
+    }
+    
     // Print the header with the days
     $ncTs = sizeof($this->oCfg->getTimeslices());
     $nDays = ($this->oCfg->isShowWeekend()) ? 7 : 5;
@@ -471,8 +486,8 @@ CSS;
       $strLessons = $this->oCfg->isShowLessons() ?_sprintf_ord(
         _c("room-reservation:%s# lesson"), $nTs + 1) . "<br />" : "";
       $oTs = $this->oCfg->getTimeslice($nTs);
-      $strTs = sprintf("%s - %s", strftime(_("%#I:%M %p"), $oTs->getBegin()),
-        strftime(_("%#I:%M %p"), $oTs->getEnd()));
+      $strTs = sprintf("%s - %s", gmstrftime(_("%#I:%M %p"), $oTs->getBegin()),
+        gmstrftime(_("%#I:%M %p"), $oTs->getEnd()));
       // First column: Lesson
       echo sprintf("<tr><td class='lesson'>%s</td>", $strLessons . $strTs);
      
@@ -562,6 +577,7 @@ CSS;
               if($nNewUid > 0) {
                 // print new booking and increment the "next row" variable by
                 // the current span
+                $oNewBooking->setUid($nNewUid);
                 $anNextRow[$i] += $this->printBooking($nTs, $ts, $oNewBooking,
                   MOD_ROOM_RESERVATION_BTPB_NEW);
               }
@@ -742,7 +758,8 @@ CSS;
    
     // print link to booking if the timeslice is later than now
     $oTs = $this->oCfg->getTimeslice($nTs);
-    $tsCur = strtotime(date("Y-m-d ", $ts) . date(" G:i",
+    // note: only the timeslices are in GMT!
+    $tsCur = strtotime(date("Y-m-d ", $ts) . gmdate(" G:i",
       $oTs->getEnd()));
     if($tsCur > time()) {
       $strURL = $_SERVER["PHP_SELF"] .
This page took 0.027272 seconds and 4 git commands to generate.