Added tag REL_8.07.30 for changeset bed35566add487fe7334f0ada904f35a17832656
[iserv-mod-room-reservation.git] / includes / mod_roomReservationConfig.inc
index 1aca132..8dde982 100644 (file)
  */
 
 require_once("sec/secure.inc");
+require_once("db.inc");
 require_once("mod_room-reservation/functions.inc");
 require_once("mod_room-reservation/mod_roomReservationTimeslice.inc");
+require_once("mod_room-reservation/mod_roomReservationRoomsManager.inc");
 
 /**
  * Determines if a privilege has been assigned
@@ -77,7 +79,7 @@ function rrConfigSortTimeslices(mod_roomReservationTimeslice $oTs1,
 
 define("MOD_ROOM_RESERVATION_CONFIGFILE_HEADER", "<?php
 /**
- * configuration file for package iserv-room-reservation
+ * configuration file for package iserv-mod-room-reservation
  * This file is written by the configuration script. Do not change it manually.
  */\n");
 
@@ -166,6 +168,74 @@ class mod_roomReservationConfig {
    */
   public function flushTimeslices() { $this->aoTimeslices = array(); }
   
+  /**
+   * Add a room to the list of rooms who can be booked. Throws an SQLException
+   * in case of an error.
+   * @param $sRoom (string) The name of the room
+   * @throws SQLException, Exception
+   * @return void
+   */
+  public function whitelistRoom($sRoom) {
+    if(!$this->isRoomWhitelisted($sRoom)) {
+      $r = db_store("mod_roomreservation_roomswhitelist",
+        array("rrr_name" => $sRoom));
+      if(!$r) {
+        throw new SQLException(MOD_ROOM_RESERVATION_ERROR_SQL);
+      } else {
+        log_insert(sprintf("Raum „%s“ für Buchungen zur Verfügung gestellt",
+         $sRoom));
+      }
+    }
+  }
+
+  /**
+   * Forbid bookings for a room. Throws an SQLException in case of an error.
+   * @param $sRoom The name of the room
+   * @throws SQLException
+   */
+  public function unWhitelistRoom($sRoom) {
+    $h = db_query("DELETE FROM mod_roomreservation_roomswhitelist WHERE ".
+       "rrr_name = $1;", $sRoom);
+    if(!$h) {
+      throw new SQLException(MOD_ROOM_RESERVATION_ERROR_SQL);
+    } else {
+      log_insert(sprintf("Raum „%s“ für Buchungen gesperrt", $sRoom));
+    }
+  }
+  
+  /**
+   * Determine if a room is allowed for booking. Throws an SQLException
+   * in case of an error.
+   * @param $sRoom (string) The name of the room
+   * @return bool
+   * @throws SQLException
+   */
+  public function isRoomWhitelisted($sRoom) {
+    $h = db_query("SELECT * FROM mod_roomreservation_roomswhitelist WHERE ".
+       "rrr_name=$1;", $sRoom);
+    if(!$h) {
+      throw new SQLException(MOD_ROOM_RESERVATION_ERROR_SQL);
+    }
+    return (pg_num_rows($h) > 0);
+  }
+
+  /**
+   * Get all rooms that are allowed for booking. Throws an SQLException
+   * in case of an error. 
+   * @throws SQLException
+   * @return array of mod_roomReservationRoomsManager objects
+   */
+  public function getWhitelistedRooms() {
+    $aor = mod_roomReservationRoomsManager::getRooms();
+    $ar = array();
+    foreach($aor as $key => $or) {
+      if($this->isRoomWhitelisted($or->getName())) {
+        $ar[] = $or;
+      }
+    }
+    return $ar;
+  }
+
   /**
    * Show or hide the weekend
    * @param $b (bool)
@@ -203,7 +273,7 @@ class mod_roomReservationConfig {
     $aot = $this->getTimeslices();
     $aRet = array();
     foreach($aot as $ao) {
-      $aRet[] = $bFormat ? _date("%#I:%M %p", $ao->getBegin()) : 
+      $aRet[] = $bFormat ? gmstrftime(_("%#I:%M %p"), $ao->getBegin()) : 
         $ao->getBegin();
     }
     return $aRet;
@@ -220,7 +290,8 @@ class mod_roomReservationConfig {
     $aot = $this->getTimeslices();
     $aRet = array();
     foreach($aot as $ao) {
-      $aRet[] = $bFormat ? _date("%#I:%M %p", $ao->getEnd()) : $ao->getEnd();
+      $aRet[] = $bFormat ? gmstrftime(_("%#I:%M %p"), $ao->getEnd()) :
+        $ao->getEnd();
     }
     return $aRet;
   }
This page took 0.025827 seconds and 4 git commands to generate.