diff --git a/index.php b/index.php index 20f2c706..5afc0972 100644 --- a/index.php +++ b/index.php @@ -123,7 +123,8 @@ else { '/^news\/archive\/?$/' => array('subtopic' => 'newsarchive'), '/^news\/archive\/[0-9]+\/?$/' => array('subtopic' => 'newsarchive', 'id' => '$2'), '/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1'), - '/^spells\/[A-Za-z0-9-_%]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'spells', 'vocation' => '$1', 'order' => '$2') + '/^spells\/[A-Za-z0-9-_%]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'spells', 'vocation' => '$1', 'order' => '$2'), + '/^houses\/view\/?$/' => array('subtopic' => 'houses', 'page' => 'view') ); foreach($rules as $rule => $redirect) { diff --git a/system/pages/houses.php b/system/pages/houses.php index 51585bd8..32e318a0 100644 --- a/system/pages/houses.php +++ b/system/pages/houses.php @@ -5,309 +5,188 @@ * @package MyAAC * @author Gesior * @author Slawkens - * @copyright 2017 MyAAC + * @author whiteblXK + * @copyright 2019 MyAAC * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Houses'; +$errors = array(); if(!$db->hasColumn('houses', 'name')) { - echo 'Houses list is not available on this server.'; + $errors[] = 'Houses list is not available on this server.'; + + $twig->display('houses.html.twig', array( + 'errors' => $errors + )); return; } -$rent = trim(strtolower($config['lua']['houseRentPeriod'])); -if($rent != 'yearly' && $rent != 'monthly' && $rent != 'weekly' && $rent != 'daily') - $rent = 'never'; + +$rentType = trim(strtolower($config['lua']['houseRentPeriod'])); +if($rentType != 'yearly' && $rentType != 'monthly' && $rentType != 'weekly' && $rentType != 'daily') + $rentType = 'never'; $state = ''; $order = ''; $type = ''; -?> - - - - - - -
-query('SELECT * FROM ' . $db->tableName('houses') . ' WHERE ' . $db->fieldName('name') . ' LIKE ' . $db->quote($houseName) . ' OR `id` = ' . $db->quote($houseId)); - if($house->rowCount() > 0) - { - $house = $house->fetch(); - $houseId = $house['id']; +if(isset($_GET['page']) && $_GET['page'] == 'view' && isset($_REQUEST['house'])) +{ + $beds = array("", "one", "two", "three", "fourth", "fifth"); + $houseName = $_REQUEST['house']; + $houseId = (Validator::number($_REQUEST['house']) ? $_REQUEST['house'] : -1); + $selectHouse = $db->query('SELECT * FROM ' . $db->tableName('houses') . ' WHERE ' . $db->fieldName('name') . ' LIKE ' . $db->quote($houseName) . ' OR `id` = ' . $db->quote($houseId)); - $title = $house['name'] . ' - ' . $title; - echo ' - - -
'; - $img_path = 'images/houses/' . $houseId . '.gif'; - if(file_exists($img_path)) - echo ''; - else - echo ''; + $house = array(); + if($selectHouse->rowCount() > 0) + { + $house = $selectHouse->fetch(); + $houseId = $house['id']; - echo ' - ' . $house['name'] . '
This house '; - $houseBeds = $house['beds']; - if($houseBeds > 0) - echo 'has ' . (isset($beds[$houseBeds]) ? $beds[$houseBeds] : $houseBeds) . ' bed' . ($houseBeds > 1 ? 's' : ''); - else - echo 'dont have any beds'; + $title = $house['name'] . ' - ' . $title; - echo '.

The house has a size of ' . $house['size'] . ' square meters.'; + $imgPath = 'images/houses/' . $houseId . '.gif'; + if(!file_exists($imgPath)) { + $imgPath = 'images/houses/default.jpg'; + } - if($rent != 'never') - echo ' The ' . $rent . ' rent is ' . $house['rent'] . ' gold and will be debited to the bank account on ' . $config['lua']['serverName'] . '.'; + $bedsMessage = null; + $houseBeds = $house['beds']; + if($houseBeds > 0) + $bedsMessage = 'House have ' . (isset($beds[$houseBeds]) ? $beds[$houseBeds] : $houseBeds) . ' bed' . ($houseBeds > 1 ? 's' : ''); + else + $bedsMessage = 'This house dont have any beds'; - $houseOwner = $house['owner']; - if($houseOwner > 0) - { - $guild = NULL; - echo '

The house has been rented by '; - if(isset($house['guild']) && $house['guild'] == 1) - { - $guild = new OTS_Guild(); - $guild->load($houseOwner); - echo getGuildLink($guild->getName()); - } - else - echo getCreatureName($houseOwner); + $houseOwner = $house['owner']; + if($houseOwner > 0) + { + $guild = NULL; + $owner = null; + if(isset($house['guild']) && $house['guild'] == 1) + { + $guild = new OTS_Guild(); + $guild->load($houseOwner); + $owner = getGuildLink($guild->getName()); + } + else + $owner = getCreatureName($houseOwner); - echo '.'; + if($rentType != 'never' && $house['paid'] > 0) + { + $who = ''; + if($guild) + $who = $guild->getName(); + else + { + $player = new OTS_Player(); + $player->load($houseOwner); + if($player->isLoaded()) + { + $sexs = array('She', 'He'); + $who = $sexs[$player->getSex()]; + } + } + $owner .= ' ' . $who . ' has paid the rent until ' . date("M d Y, H:i:s", $house['paid']) . ' CEST.'; + } + } + } + else + $errors[] = 'House with name ' . $houseName . ' does not exists.'; - if($rent != 'never' && $house['paid'] > 0) - { - $who = ''; - if($guild) - $who = $guild->getName(); - else - { - $player = new OTS_Player(); - $player->load($houseOwner); - if($player->isLoaded()) - { - $sexs = array('She', 'He'); - $who = $sexs[$player->getSex()]; - } - } - echo ' ' . $who . ' has paid the rent until ' . date("M d Y, H:i:s", $house['paid']) . ' CEST.'; - } - } + $twig->display('houses.view.html.twig', array( + 'errors' => $errors, + 'imgPath' => isset($imgPath) ? $imgPath : null, + 'houseName' => isset($house['name']) ? $house['name'] : null, + 'bedsMessage' => isset($bedsMessage) ? $bedsMessage : null, + 'houseSize' => isset($house['size']) ? $house['size'] : null, + 'houseRent' => isset($house['rent']) ? $house['rent'] : null, + 'owner' => isset($owner) ? $owner : null, + 'rentType' => isset($rentType) ? $rentType : null + )); - echo '
'; - } - else - echo 'House with name ' . $houseName . ' does not exists.'; - } - else - { - echo ' - Here you can see the list of all available houses, flats' . ($db->hasTable('houses', 'guild') ? ' or guildhall' : '') . '. - Click on any view button to get more information about a house or adjust - the search criteria and start a new search.

'; - if(isset($config['lua']['houseCleanOld'])) { - $cleanOld = (int)(eval('return ' . $config['lua']['houseCleanOld'] . ';') / (24 * 60 * 60)); - if($cleanOld > 0 || $rent != 'never') - { - echo 'Every morning during global server save there is automatic house cleaning. Server delete house owners who have not logged in last ' . $cleanOld . ' days'; - if($rent != 'never') - { - echo ' or have not paid ' . $rent . ' house rent. Remember to leave money for a rent in '; - $bank = getBoolean($config['lua']['bankSystem']); - if($bank) - echo 'your house bank account or '; + if (count($errors) > 0) { + return; + } +} - echo 'depo in same city where you have house!'; - } - else - echo '.'; +$cleanOldHouse = null; +if(isset($config['lua']['houseCleanOld'])) { + $cleanOldHouse = (int)(eval('return ' . $config['lua']['houseCleanOld'] . ';') / (24 * 60 * 60)); +} - echo '

'; - } - } +if(isset($_POST['town']) && isset($_POST['state']) && isset($_POST['order']) && (isset($_POST['type']) || !$db->hasColumn('houses', 'guild'))) +{ + $townName = $config['towns'][$_POST['town']]; + $order = $_POST['order']; + $orderby = '`name`'; + if(!empty($order)) + { + if($order == 'size') + $orderby = '`size`'; + else if($order == 'rent') + $orderby = '`rent`'; + } - echo '
'; + $town = 'town'; + if($db->hasColumn('houses', 'town_id')) + $town = 'town_id'; + else if($db->hasColumn('houses', 'townid')) + $town = 'townid'; - if(isset($_POST['town']) && isset($_POST['state']) && isset($_POST['order']) - && (isset($_POST['type']) || !$db->hasColumn('houses', 'guild'))) - { - $order = $_POST['order']; - $orderby = '`name`'; - if(!empty($order)) - { - if($order == 'size') - $orderby = '`size`'; - else if($order == 'rent') - $orderby = '`rent`'; - } + $whereby = '`' . $town . '` = ' .(int)$_POST['town']; + $state = $_POST['state']; + if(!empty($state)) + $whereby .= ' AND `owner` ' . ($state == 'free' ? '' : '!'). '= 0'; - $town = 'town'; - if($db->hasColumn('houses', 'town_id')) - $town = 'town_id'; - else if($db->hasColumn('houses', 'townid')) - $town = 'townid'; - - $whereby = '`' . $town . '` = ' .(int)$_POST['town']; - $state = $_POST['state']; - if(!empty($state)) - $whereby .= ' AND `owner` ' . ($state == 'free' ? '' : '!'). '= 0'; + $type = isset($_POST['type']) ? $_POST['type'] : NULL; + if($type == 'guildhalls' && !$db->hasColumn('houses', 'guild')) + $type = 'all'; - $type = isset($_POST['type']) ? $_POST['type'] : NULL; - if($type == 'guildhalls' && !$db->hasColumn('houses', 'guild')) - $type = 'all'; + if(!empty($type) && $type != 'all') + $whereby .= ' AND `guild` ' . ($type == 'guildhalls' ? '!' : '') . '= 0'; - if(!empty($type) && $type != 'all') - $whereby .= ' AND `guild` ' . ($type == 'guildhalls' ? '!' : '') . '= 0'; + $houses_info = $db->query('SELECT * FROM `houses` WHERE ' . $whereby. ' ORDER BY ' . $orderby); + $houses_count = $houses_info->rowCount(); - $houses_info = $db->query('SELECT * FROM `houses` WHERE ' . $whereby. ' ORDER BY ' . $orderby); + $players_info = $db->query("SELECT `houses`.`id` AS `houseid` , `players`.`name` AS `ownername` FROM `houses` , `players` , `accounts` WHERE `players`.`id` = `houses`.`owner` AND `accounts`.`id` = `players`.`account_id`"); + $players = array(); + foreach($players_info->fetchAll() as $player) + $players[$player['houseid']] = array('name' => $player['ownername']); - echo ' - - - - - '; - if($houses_info->rowCount() > 0) - { - echo ' - - - + $houses = array(); + foreach($houses_info->fetchAll() as $house) + { + $owner = isset($players[$house['id']]) ? $players[$house['id']] : array(); - - '; - } - else - echo ''; + $houseRent = null; + if($db->hasColumn('houses', 'guild') && $house['guild'] == 1 && $house['owner'] != 0) + { + $guild = new OTS_Guild(); + $guild->load($house['owner']); + $houseRent = 'Rented by ' . getGuildLink($guild->getName()); + } + else + { + if(!empty($owner['name'])) + $houseRent = 'Rented by ' . getPlayerLink($owner['name']); + else + $houseRent = 'Free'; + } - echo ''; + $houses[] = array('owner' => $owner, 'name' => $house['name'], 'size' => $house['size'], 'rent' => $house['rent'], 'rentedBy' => $houseRent); + } +} - $players_info = $db->query("SELECT `houses`.`id` AS `houseid` , `players`.`name` AS `ownername` FROM `houses` , `players` , `accounts` WHERE `players`.`id` = `houses`.`owner` AND `accounts`.`id` = `players`.`account_id`"); - $players = array(); - foreach($players_info->fetchAll() as $player) - $players[$player['houseid']] = array('name' => $player['ownername']); - - $rows = 1; - foreach($houses_info->fetchAll() as $house) - { - $owner = isset($players[$house['id']]) ? $players[$house['id']] : array(); - echo - ' - - - - - - '; - $rows++; - } - echo - '
Available ' . ($type == 'guildhalls' ? 'Guildhalls' : 'Houses and Flats').' in '.$config['towns'][$_POST['town']].' on '.$config['lua']['serverName'].'
NameSizeRentStatus No ' . ($type == 'guildhalls' ? 'guildhalls' : 'houses') . ' with specified criterias.
'.$house['name'].''.$house['size'].' sqm'.$house['rent'].' gold'; - if($db->hasColumn('houses', 'guild') && $house['guild'] == 1 && $house['owner'] != 0) - { - $guild = new OTS_Guild(); - $guild->load($house['owner']); - echo 'Rented by ' . getGuildLink($guild->getName()); - } - else - { - if(!empty($owner['name'])) - echo 'Rented by ' . getPlayerLink($owner['name']); - else - echo - 'Free'; - } - - echo ' - - - - - -
- - -
-
'. - '

'; - } - - echo ' -
- - - - - - - - - - - - - - '; - - if($db->hasColumn('houses', 'guild')) { - echo ' - - - '; - } - echo ' -
House Search
TownStatusOrder
'; - $townId = isset($_POST['town']) ? $_POST['town'] : ''; - $i = 0; - $checked = false; - foreach($config['towns'] as $id => $name) - { - if($id == 0) - continue; - - $i++; - if(((empty($townId) && !empty($name)) || $id == $townId) && !$checked) - { - $add = 'CHECKED'; - $checked = true; - } - else - $add = ''; - - if(!empty($name)) - echo '
'; - } - - echo ' -
-
-
-
-
-
-
-
-
- all
- houses and flats
- guildhalls
-
-
-
-
- ' . $twig->render('buttons.submit.html.twig') . ' -
-
'; - } - echo ' -
- '; -?> +$guild = $db->hasTable('houses', 'guild') ? ' or guildhall' : ''; +$twig->display('houses.html.twig', array( + 'state' => $state, + 'order' => $order, + 'type' => $type, + 'houseType' => $type == 'guildhalls' ? 'Guildhalls' : 'Houses and Flats', + 'townName' => isset($townName) ? $townName : null, + 'townId' => isset($_POST['town']) ? $_POST['town'] : null, + 'guild' => $guild, + 'cleanOldHouse' => isset($cleanOld) ? $cleanOld : null, + 'housesCount' => isset($houses_count) ? $houses_count : null, + 'houses' => isset($houses) ? $houses : null +)); \ No newline at end of file diff --git a/system/templates/houses.html.twig b/system/templates/houses.html.twig new file mode 100644 index 00000000..16a8ce71 --- /dev/null +++ b/system/templates/houses.html.twig @@ -0,0 +1,166 @@ +
+ {% if errors is not empty %} + {% for error in errors %} +

{{ error }}

+ {% endfor %} + {% else %} + +
+
+ + + + +
House Search
+ + + + +
+
+ + + + +
+
+ Here you can see the list of all available houses, flats{{ guildString }}. + Click on any view button to get more information about a house or adjust + the search criteria and start a new search. +

+ {% if cleanOldHouse is not empty or rentType != 'never' %} + Every morning during global server save there is automatic house cleaning. Server delete house owners who have not logged in last {{ cleanOldHouse }} days{% if rentType != 'never' %} or have not paid {{ rentType }} house rent. Remember to leave money for a rent in {% if config.lua.bankSystem is not empty %}your house bank or {% else %}depo in same city where you have house!{% endif %}{% else %}.{% endif %} +

+ {% endif %} + + {% if houses is not empty %} + + + + + + + + {% if housesCount > 0 %} + + + + + + + {% else %} + + {% endif %} + + + {% set i = 0 %} + {% for house in houses %} + {% set i = i + 1 %} + + + + + + + + + + + + {% endfor %} + +
Available {{ houseType }} {% if townName is not empty %}in {{ townName }}{% endif %}on {{ config.lua.serverName }}
NameSizeRentStatus No {{ houseType }} with specified criterias.
+ {{ house.name }} + + {{ house.size }} + + {{ house.rent }} golds + + {{ house.rentedBy|raw }} + +
+ + +
+
+
+ {% endif %} + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
House Search
TownStatusOrder
+ {% set checked = false %} + {% for id, name in config.towns if id > 0 %} + {% if ((townId is empty and name is not empty) or id == townId) and not checked %} + {% set variable = "checked" %} + {% set checked = true %} + {% else %} + {% set variable = "" %} + {% endif %} + + + +
+ {% endfor %} +
+ +
+ + +
+ + +
+
+ +
+ + +
+ + +
+
+ all
+ houses and flats
+ guildhalls
+
+
+ + + + + + + +
+ {{ include('buttons.submit.html.twig') }} +
+
+
+
+ {% endif %} +
\ No newline at end of file diff --git a/system/templates/houses.view.html.twig b/system/templates/houses.view.html.twig new file mode 100644 index 00000000..31fc5c23 --- /dev/null +++ b/system/templates/houses.view.html.twig @@ -0,0 +1,51 @@ +
+ {% if errors is not empty %} + {% for error in errors %} +

{{ error }}

+ {% endfor %} + {% else %} + +
+
+ + + + +
{{ houseName }}
+ + + + +
+
+ + + + +
+
+ + + + + +
+ {{ bedsMessage }} and has a size of {{ houseSize }} square meters. + + {% if rentType != 'never' %} + The {{ rentType }} is {{ houseRent }} gold and will be debited to the bank account on {{ config.lua.serverName }}. + {% endif %} +
+ + {% if owner is not empty %} + The house has been rented by {{ owner|raw }}. + {% else %} + No one has bought this house yet. + {% endif %} +
+
+
+ {% endif %} + +
+

\ No newline at end of file