/** * @author coster * @date 30.9.06 * Hilfsfunktionen für die Gesamtübersicht */ function printResAdmin($zimmer_id, $i, $month, $year, $saAktiviert, $link) { global $unterkunft_id; if (getDayName($i, $month, $year) == "SA" && $saAktiviert) { $isSamstag = true; } else { $isSamstag = false; } $status = getStatus($zimmer_id, $i, $month, $year, $link); if (sizeof($status) < 1 && hasChildRooms($zimmer_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true") { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $status = getStatus($child_zi_id, $i, $month, $year, $link); if (sizeof($status) > 0) { break; } } } ///////////////////////////////////////////////////////// //urlauberwechsel genau an diesem tag: ///////////////////////////////////////////////////////// if (isset($status) && sizeof($status) > 1) { //an diesem tag ist ein urlauberwechsel: ?> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td class="<?php echo parseStatus($status[0], $isSamstag); ?> " align="right" width="50%"></td> <td class="<?php echo parseStatus($status[1], $isSamstag); ?> " align="right" width="50%"> </td> </tr> </table> <?php } else { if (isset($status) && sizeof($status) == 1) { //schauen ob der letzte tag halb-frei ist: $nTag = $i + 1; $nMonat = $month; $nJahr = $year; $anzahlTage = getNumberOfDays($month, $year); if ($nTag > $anzahlTage) { $nTag = 1; $nMonat = $month + 1; } //ende if tag zu gross if ($nMonat > 12) { $nMonat = 1; $nJahr = $year + 1; } //ende if monat zu gross $nStatus = getStatus($zimmer_id, $nTag, $nMonat, $nJahr, $link); if (sizeof($nStatus) < 1 && hasChildRooms($zimmer_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true") { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $nStatus = getStatus($child_zi_id, $nTag, $nMonat, $nJahr, $link); if (sizeof($nStatus) > 0) { break; } } } //if (!(isset($nStatus)) && isset($status)){ if (sizeof($nStatus) == 0) { //am nächsten tag ist es frei: ?> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td class="<?php echo parseStatus($status[0], $isSamstag); ?> " align="right" width="50%"> </td> <td class="<?php echo parseStatus(0, $isSamstag); ?> " align="right" width="50%"></td> </tr> </table> <?php } else { //schauen ob der tag vorher frei ist: $vTag = $i - 1; $vMonat = $month; $vJahr = $year; if ($vTag < 1) { $vMonat = $month - 1; if ($vMonat < 1) { $vMonat = 12; $vJahr = $year - 1; } //ende if monat zu klein $vTag = getNumberOfDays($vMonat, $vJahr); } //ende if tag zu klein $vStatus = getStatus($zimmer_id, $vTag, $vMonat, $vJahr, $link); if (sizeof($vStatus) < 1 && hasChildRooms($zimmer_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true") { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $vStatus = getStatus($child_zi_id, $vTag, $vMonat, $vJahr, $link); if (sizeof($vStatus) > 0) { break; } } } if (sizeof($vStatus) == 0) { //am vorherigen tag ist es frei: ?> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td class="<?php echo parseStatus(0, $isSamstag); ?> " align="right" width="50%"></td> <td class="<?php echo parseStatus($status[0], $isSamstag); ?> " align="right" width="50%"> </td> </tr> </table> <?php } else { ?> <?php } } //ende else schauen ob tag vorher frei } else { //tag ausgeben: ?> <?php } } //ende else tag ausgeben }
function getFreieZimmer($unterkunft_id, $anzahlErwachsene, $anzahlKinder, $anzahlZimmer, $haustiere, $vonTag, $vonMonat, $vonJahr, $bisTag, $bisMonat, $bisJahr, $link) { //leeres array erzeugen zum speichern der freien zimmer: $freieZimmer = array(); //variable zum zaehlen der erwachsenenBetten, kinderBetten, freie zimmer $bettenErw = 0; $bettenKin = 0; $freieZi = 0; //reservierungs-funktionen einbinden: include_once "../include/reservierungFunctions.php"; //zimmer-funktionen hinzufügen: include_once "../include/zimmerFunctions.php"; //properties hinzufügen: include_once "../include/propertiesFunctions.php"; //alle zimmer der unterkunft auslesen und prüfen ob es im angegebenen zeitraum noch frei ist: $query = "\n\t\t\tSELECT \n\t\t\tPK_ID\t\t\n\t\t\tFROM\n\t\t\tRezervi_Zimmer\n\t\t\tWHERE\n\t\t\tFK_Unterkunft_ID = '{$unterkunft_id}'\t\n\t\t\tORDER BY\n\t\t\tZimmernr\n\t\t"; $res = mysqli_query($link, $query); while ($d = mysqli_fetch_array($res)) { //zimmer-id holen: $zi_id = $d["PK_ID"]; //wenn die suche nach erwachsenen oder kindern nach zimmern gefiltert //werden soll (z. b. ferienhäuser nur mit bestimmter personenanzahl): //dont check it if the accomodation has rooms and subrooms: if (!hasParentRooms($unterkunft_id)) { if (getPropertyValue(SUCHFILTER_ZIMMER, $unterkunft_id, $link) == "true") { if ($anzahlErwachsene > -1) { if (getBetten($unterkunft_id, $zi_id, $link) < $anzahlErwachsene) { continue; } } if ($anzahlKinder > -1) { if (getBettenKinder($unterkunft_id, $zi_id, $link) < $anzahlKinder) { continue; } } } } if (!isRoomTaken($zi_id, $vonTag, $vonMonat, $vonJahr, $bisTag, $bisMonat, $bisJahr, $link)) { //zimmer ist noch frei - dem array hinzufügen: $freieZimmer[] = $zi_id; $freieZi++; //zaehlen wie viele erwachsene und kinder platz haben: $bettenErw = $bettenErw + getBetten($unterkunft_id, $zi_id, $link); //echo("anzahlBetten insgesamt Erw =".$bettenErw."<br/>"); $bettenKin = $bettenKin + getBettenKinder($unterkunft_id, $zi_id, $link); //echo("anzahlBetten insgesamt Kin =".$bettenKin."<br/>"); } } if ($anzahlErwachsene > -1) { //checken ob genug betten fuer erwachsene frei sind: if ($anzahlErwachsene > $bettenErw) { //es sind nicht genug betten fuer erwachsene frei! $freieZimmer[0] = -1; } } if ($anzahlKinder > -1) { //wieviele betten sind noch frei wenn ich die erwachsenen reingelegt habe? if ($anzahlErwachsene > -1) { $insgesamtBettenFrei = $bettenErw + $bettenKin - $anzahlErwachsene; } else { $insgesamtBettenFrei = $bettenErw + $bettenKin; } //checken ob genug betten fuer kinder frei sind: if ($anzahlKinder > $insgesamtBettenFrei) { //echo("nicht genug betten fuer kinder!<br/>"); $freieZimmer[0] = -2; } } if ($anzahlZimmer > -1) { //checken ob genug zimmer insgesamt frei sind: if ($anzahlZimmer > $freieZi) { $freieZimmer[0] = -3; } } //check if a parent-child relation exists and remove the parent if the child is not free: $freeRooms = array(); if (count($freieZimmer) > 0 && hasParentRooms($unterkunft_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true") { global $root; include_once $root . "/include/zimmerFunctions.php"; foreach ($freieZimmer as $freeRoom) { $count = 0; $count2 = 0; //is the room a parent room? if (hasChildRooms($freeRoom)) { //the room is a parent room, check if ALL the children are free rooms $childs = getChildRooms($freeRoom); while ($c = mysqli_fetch_array($childs)) { $count2++; for ($i = 0; $i < count($freieZimmer); $i++) { if ($freieZimmer[$i] == $c['PK_ID']) { $count++; } } } if ($count == $count2) { $freeRooms[] = $freeRoom; } } else { $freeRooms[] = $freeRoom; } } } else { if (count($freieZimmer) > 0 && hasParentRooms($unterkunft_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) != "true") { global $root; include_once $root . "/include/zimmerFunctions.php"; include_once $root . "/include/reservierungFunctions.php"; foreach ($freieZimmer as $freeRoom) { $count = 0; $count2 = 0; //is the room a parent room? if (hasChildRooms($freeRoom)) { //the room is a parent room, check if ALL the children are occupied: $childs = getChildRooms($freeRoom); $allOcc = true; while ($c = mysqli_fetch_array($childs)) { $chid = $c['PK_ID']; //if the child is not occupied -> set to false! $taken = isRoomTaken($chid, $vonTag, $vonMonat, $vonJahr, $bisTag, $bisMonat, $bisJahr, $link); if (!$taken) { $allOcc = false; break; } } if (!$allOcc) { $freeRooms[] = $freeRoom; } } else { $freeRooms[] = $freeRoom; } } } else { $freeRooms = $freieZimmer; } } //checken ob genug zimmer insgesamt frei sind: if (count($freeRooms) < 1) { $freeRooms[0] = -3; } return $freeRooms; }
/** get an array with status numbers of the given day and room 0 = frei 1 = reserviert 2 = belegt @param $zimmer_id the room id @param $tag the day @param $monat the month @param $jahr the year @param $link the database connection link @return get an array with status numbers of the given day and room */ function getStatus($zimmer_id, $tag, $monat, $jahr, $link) { global $root; include_once $root . "/include/propertiesFunctions.php"; include_once $root . "/include/reservierungFunctions.php"; global $unterkunft_id; //true if reservations must be shown: $showReservation = false; $showReservationProp = getPropertyValue(SHOW_RESERVATION_STATE, $unterkunft_id, $link); if (!empty($showReservationProp) && $showReservationProp == "true") { $showReservation = true; } //generate a date for the sql query: if ($monat < 10 && strlen($monat) <= 1) { $monat = "0" . $monat; } if ($tag < 10 && strlen($tag) <= 1) { $tag = "0" . $tag; } $datum = $jahr . "-" . $monat . "-" . $tag; //get the state from the database: $query = "select \n\t\t\t\tStatus, PK_ID\n\t\t\t\tfrom \n\t\t\t\tRezervi_Reservierung\n\t\t\t\twhere \t\t\n\t\t\t\tFK_Zimmer_ID = '{$zimmer_id}' and\n\t\t\t\t('{$datum}' >= Datum_von and '{$datum}' <= Datum_bis)\n\t\t\t\torder by\n\t\t\t\tDatum_von\n\t\t\t\t"; $res = mysqli_query($link, $query); if (!$res) { die("Anfrage {$query} scheitert."); } //create the state array: $status = array(); $ids = array(); while ($d = mysqli_fetch_array($res)) { $state = $d["Status"]; if (!$showReservation && $state == STATUS_RESERVIERT) { //do not show reservation state continue; } $status[] = $state; $ids[] = $d['PK_ID']; } //ende while //if the room has child rooms and the parent-schild relation must be shown, check if the child has the same state $showParentRooms = false; $hasChildRooms = hasChildRooms($zimmer_id); if (getPropertyValue(RES_HOUSE, $unterkunft_id, $link) != "true") { $showParentRooms = true; } if ($showParentRooms === false || $hasChildRooms === false) { if (count($status) == 1) { //check if the next day is the same reservation: $nTag = $tag + 1; $nMonat = $monat; $nJahr = $jahr; $anzahlTage = getNumberOfDays($month, $year); if ($nTag > $anzahlTage) { $nTag = 1; $nMonat = $month + 1; } //ende if tag zu gross if ($nMonat > 12) { $nMonat = 1; $nJahr = $year + 1; } //ende if monat zu gross $datum = $nJahr . "-" . $nMonat . "-" . $nTag; //get the state from the database: $query = "select \n\t\t\t\t\t\tStatus, PK_ID\n\t\t\t\t\t\tfrom \n\t\t\t\t\t\tRezervi_Reservierung\n\t\t\t\t\t\twhere \t\t\n\t\t\t\t\t\tFK_Zimmer_ID = '{$zimmer_id}' and\n\t\t\t\t\t\t('{$datum}' >= Datum_von and '{$datum}' <= Datum_bis)\n\t\t\t\t\t\torder by\n\t\t\t\t\t\tDatum_von\n\t\t\t\t\t\t"; $res = mysqli_query($link, $query); if (!$res) { die("Anfrage {$query} scheitert."); } //create the state array: $nstatus = array(); $nids = array(); while ($d = mysqli_fetch_array($res)) { $state = $d["Status"]; if (!$showReservation && $state == STATUS_RESERVIERT) { //do not show reservation state continue; } $nstatus[] = $state; $nids[] = $d['PK_ID']; } //ende while if ($ids[0] != $nids[0]) { $status[] = 0; } //check if the previous day is the same reservation: $vTag = $tag - 1; $vMonat = $monat; $vJahr = $jahr; if ($vTag < 1) { $vMonat = $month - 1; if ($vMonat < 1) { $vMonat = 12; $vJahr = $year - 1; } //ende if monat zu klein $vTag = getNumberOfDays($vMonat, $vJahr); } //ende if tag zu klein $datum = $vJahr . "-" . $vMonat . "-" . $vTag; //get the state from the database: $query = "select \n\t\t\t\t\t\tStatus, PK_ID\n\t\t\t\t\t\tfrom \n\t\t\t\t\t\tRezervi_Reservierung\n\t\t\t\t\t\twhere \t\t\n\t\t\t\t\t\tFK_Zimmer_ID = '{$zimmer_id}' and\n\t\t\t\t\t\t('{$datum}' >= Datum_von and '{$datum}' <= Datum_bis)\n\t\t\t\t\t\torder by\n\t\t\t\t\t\tDatum_von\n\t\t\t\t\t\t"; $res = mysqli_query($link, $query); if (!$res) { die("Anfrage {$query} scheitert."); } //create the state array: $vstatus = array(); $vids = array(); while ($d = mysqli_fetch_array($res)) { $state = $d["Status"]; if (!$showReservation && $state == STATUS_RESERVIERT) { //do not show reservation state continue; } $vstatus[] = $state; $vids[] = $d['PK_ID']; } //ende while if (count($vstatus) == 1 && $ids[0] != $vids[0]) { $status[1] = $status[0]; $status[0] = 0; } } return $status; } //the room has child rooms and the parent-child relation must be shown.. //check if the child has the same state: //get all childs of the parent: $parentState = array(2); if (count($status) > 1) { $parentState = array(2, 2); //parent is occupied defaul } $childs = getChildRooms($zimmer_id); $childArray = array(); //create an array with child ids: while ($c = mysqli_fetch_array($childs)) { //continue 1 $childArray[] = $c['PK_ID']; } for ($l = 0; $l < count($parentState); $l++) { //continue 2 foreach ($childArray as $child_id) { //continue 1 $childStatus = getStatus($child_id, $tag, $monat, $jahr, $link); /* if ($parentState[$l] == 0){ //if parent is free, show the parent state as free $status[$l] = 0; continue 2; } */ if (!isset($childStatus[$l]) || $childStatus[$l] == 0) { //if any child is free set the parent state free $status[$l] = 0; continue 2; } if (isset($childStatus[$l]) && $childStatus[$l] == 1) { //if any child is reserved set the parent reserved $status[$l] = 1; //continue 2; } if ($parentState[$l] == 1) { $status[$l] = 1; //continue 2; } $status[$l] = $parentState[$l]; } //end while level 1 } //end for level 2 if ($status[0] == 0 && $status[1] == 0) { return null; } //var_dump($status); return $status; }
function removeChildRooms($zimmer_ids) { $newArr = array(); //is room with child rooms in array? $parentInArray = false; foreach ($zimmer_ids as $id) { if (hasChildRooms($id)) { $parentInArray = true; } } if ($parentInArray) { foreach ($zimmer_ids as $id) { if (hasRoomParentRooms($id) && in_array($id, $zimmer_ids)) { //tu nix } else { $newArr[] = $id; } } return $newArr; } return $zimmer_ids; }
function showMonth($month, $year, $unterkunft_id, $zimmer_id, $sprache, $saAktiviert, $link) { //anzahl der tage des monats: $anzahlTage = getNumberOfDays($month, $year); ?> <?php for ($i = 1; $i <= $anzahlTage; $i++) { $res_id = getReservierungID($zimmer_id, $i, $month, $year, $link); $statusString = getStatusString($zimmer_id, $i, $month, $year, $saAktiviert, $link); $gast_id = -1; ?> <div class="row"> <!-- wochentag anzeigen --> <div class="col-sm-1"> <label class="control-label"> <?php echo getUebersetzung(getDayName($i, $month, $year), $sprache, $link); ?> </label> </div> <!-- datum anzeigen --> <div class="col-sm-1 <?php echo $statusString; ?> "> <label class="control-label"> <?php printResAdmin($zimmer_id, $i, $month, $year, $saAktiviert, $link); ?> </label> </div> <!-- gast anzeigen --> <div class="col-sm-3"> <?php if ($statusString != "frei") { ?> <?php //gast-id auslesen: //$gast_id = getReservierungGastID($zimmer_id,$i,$month,$year,$link); $gast_ids = getReservierungGastIDs($zimmer_id, $i, $month, $year, $link); while ($h = mysqli_fetch_array($gast_ids)) { $gast_id = $h["FK_Gast_ID"]; //if child rooms available, check also childs: if (($gast_id == 1 || empty($gast_id)) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true" && hasChildRooms($zimmer_id)) { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $gast_id = getReservierungGastID($child_zi_id, $i, $month, $year, $link); if ($gast_id != 1 && $gast_id != "") { break; } } } //gast-namen ausgeben: if ($gast_id != 1 && $gast_id != "") { ?> <a href="./gastInfo/index.php?gast_id=<?php echo $gast_id; ?> &zimmer_id=<?php echo $zimmer_id; ?> &jahr=<?php echo $year; ?> &monat=<?php echo $month; ?> "> <?php echo getGuestNachname($gast_id, $link); ?> </a> <?php echo ", "; echo getGuestOrt($gast_id, $link); echo ", EW " . getErwachsene($res_id, $link) . ", K " . getKinder($res_id, $link) . ", " . getPension($res_id, $link); } else { if ($gast_id == "") { } else { echo getUebersetzung("anonymer Gast", $sprache, $link); } } } //ende while gast ids } else { echo " "; } ?> </div> </div> <?php } //ende for ?> <?php }
function printResAdminAJAX($zimmer_id, $i, $month, $year, $saAktiviert, $link, $unterkunft_id) { //global $unterkunft_id; $response = ""; $status = getStatus($zimmer_id, $i, $month, $year, $link); if (sizeof($status) < 1 && hasChildRooms($zimmer_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true") { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $status = getStatus($child_zi_id, $i, $month, $year, $link); if (sizeof($status) > 0) { break; } } } if (getDayName($i, $month, $year) == "SA" && $saAktiviert) { $isSamstag = true; } else { $isSamstag = false; } if (isset($status) && sizeof($status) > 1) { //an diesem tag ist ein urlauberwechsel: $response .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"; $response .= "<tr>"; $response .= "<td class=\"" . parseStatus($status[0], $isSamstag) . "\" align=\"right\" width=\"50%\">"; $response .= $i; $response .= "</td>"; $response .= "<td class=\"" . parseStatus($status[1], $isSamstag) . "\" align=\"right\" width=\"50%\"> "; $response .= "</td>"; $response .= "</tr>"; $response .= "</table>"; } else { if (isset($status) && sizeof($status) == 1) { //schauen ob der letzte tag halb-frei ist: $nTag = $i + 1; $nMonat = $month; $nJahr = $year; $anzahlTage = getNumberOfDays($month, $year); if ($nTag > $anzahlTage) { $nTag = 1; $nMonat = $month + 1; } //ende if tag zu gross if ($nMonat > 12) { $nMonat = 1; $nJahr = $year + 1; } //ende if monat zu gross $nStatus = getStatus($zimmer_id, $nTag, $nMonat, $nJahr, $link); //echo("nächster Tag: ");var_dump($nStatus); if (sizeof($nStatus) < 1 && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true" && hasChildRooms($zimmer_id)) { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $nStatus = getStatus($child_zi_id, $nTag, $nMonat, $nJahr, $link); if (sizeof($nStatus) > 0) { break; } } } if (sizeof($nStatus) == 0) { $response .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"; $response .= "<tr>"; $response .= "<td class=\"" . parseStatus($status[0], $isSamstag) . "\" align=\"right\" width=\"50%\">"; $response .= "</td>"; $response .= "<td class=\"frei\" align=\"right\" width=\"50%\"> "; $response .= $i; $response .= "</td>"; $response .= "</tr>"; $response .= "</table>"; } else { //schauen ob der tag vorher frei ist: $vTag = $i - 1; $vMonat = $month; $vJahr = $year; if ($vTag < 1) { $vMonat = $month - 1; if ($vMonat < 1) { $vMonat = 12; $vJahr = $year - 1; } //ende if monat zu klein $vTag = getNumberOfDays($vMonat, $vJahr); } //ende if tag zu klein $vStatus = getStatus($zimmer_id, $vTag, $vMonat, $vJahr, $link); if (sizeof($vStatus) < 1 && hasChildRooms($zimmer_id) && getPropertyValue(RES_HOUSE, $unterkunft_id, $link) == "true") { //if room is a parent, check if the child has another status: $childs = getChildRooms($zimmer_id); while ($c = mysqli_fetch_array($childs)) { $child_zi_id = $c['PK_ID']; $vStatus = getStatus($child_zi_id, $vTag, $vMonat, $vJahr, $link); if (sizeof($vStatus) > 0) { break; } } } if (sizeof($vStatus) == 0) { //am vorherigen tag ist es frei: $response .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"; $response .= "<tr>"; $response .= "<td class=\"frei\" align=\"right\" width=\"50%\">"; $response .= $i; $response .= "</td>"; $response .= "<td class=\"" . parseStatus($status[0], $isSamstag) . "\" align=\"right\" width=\"50%\"> "; $response .= "</td>"; $response .= "</tr>"; $response .= "</table>"; } else { $response .= $i; } } //ende else schauen ob tag vorher frei } else { //tag ausgeben: $response .= $i; } } //ende else tag ausgeben return $response; }