79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
||
|
|
|
||
|
|
// Number of records fetch
|
||
|
|
$numberOfRecords = 10;
|
||
|
|
|
||
|
|
$blockList = [];
|
||
|
|
|
||
|
|
$page = 1;
|
||
|
|
$search = null;
|
||
|
|
|
||
|
|
if (isset($_POST['searchTerm'])) {
|
||
|
|
$search = $_POST['searchTerm'];// Search text
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($_POST['page'])) {
|
||
|
|
$page = $_POST['page'];
|
||
|
|
}
|
||
|
|
|
||
|
|
$regionRfId = null;
|
||
|
|
|
||
|
|
if (isset($_POST['regionRfId'])) {
|
||
|
|
$regionRfId = $_POST['regionRfId'];
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($regionRfId == null) {
|
||
|
|
|
||
|
|
$curUser = new User();
|
||
|
|
$curUser->get($_SESSION['id']);
|
||
|
|
|
||
|
|
$regionRfId = $curUser->region_rf_id;
|
||
|
|
}
|
||
|
|
|
||
|
|
$cldr = 'rf_region_id = ' . $regionRfId;
|
||
|
|
|
||
|
|
if($regionRfId == 1 || $regionRfId == 2 || $regionRfId == 3) {
|
||
|
|
$cldr = '(rf_region_id in (select id from rf_regions where parent = ' . $regionRfId . '))';
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($search == null) {
|
||
|
|
$sqlCount = "SELECT count(id) FROM newbuildings where ". $cldr ." ORDER BY name, ID";
|
||
|
|
} else {
|
||
|
|
$sqlCount = "SELECT count(id) FROM newbuildings WHERE ". $cldr ." and name like '%" . trim($search) . "%' ORDER BY name, ID";
|
||
|
|
}
|
||
|
|
$rez = mysql_query($sqlCount);
|
||
|
|
$allCount = mysql_result($rez, 0);
|
||
|
|
|
||
|
|
$all_pages = ceil($allCount / $numberOfRecords);
|
||
|
|
|
||
|
|
$ot = ($page - 1) * $numberOfRecords;
|
||
|
|
|
||
|
|
if ($search == null) {
|
||
|
|
$sql = "SELECT * FROM newbuildings where ". $cldr ." ORDER BY name, ID LIMIT $ot, $numberOfRecords";
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
while ($block = mysql_fetch_assoc($rez)) {
|
||
|
|
$blockList[] = $block;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$sql = "SELECT * FROM newbuildings WHERE ". $cldr ." and name like '%" . trim($search) . "%' ORDER BY name, ID LIMIT $ot, $numberOfRecords";
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
while ($block = mysql_fetch_assoc($rez)) {
|
||
|
|
$blockList[] = $block;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$response = [];
|
||
|
|
$response['items'] = array();
|
||
|
|
$response['total_count'] = $allCount;
|
||
|
|
|
||
|
|
// Read Data
|
||
|
|
foreach ($blockList as $block) {
|
||
|
|
$response['items'][] = array(
|
||
|
|
"id" => $block['id'],
|
||
|
|
"text" => $block['name']
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
echo json_encode($response);
|
||
|
|
exit();
|