<?php
function defaultPage(){
if(!$_POST['pnd']){
$_POST['pnd'] = 1;
}
}
defaultPage();
?>
<?php
get_header();
?>
<main id="maincontent" role="main">
<div class="container">
<div class="row text-pkb">
<h1>НАВИГАЦИЯ</h1>
</div>
<div class="row">
<div class="pnd-list">
<div class="table-list">
<table>
<tr>
<?php $lists = $wpdb->get_results( "SELECT * FROM list" );
$counter=0;
?>
<?php foreach($lists as $list){
$counter++;
?>
<td>
<div tabindex="0" class='pnd-li' id="<?php echo $list->id ?>" data-pnd="pnd=<?php echo $list->id ?>">
<p><?php echo $list->number ?></p><p><?php echo $list->addres ?>
</div>
</td>
<?php if($counter == 9){
echo "</tr><tr>";
$counter = 0;
} ?>
<?php } ?>
</tr>
</table>
</div>
</div>
</div>
<div class="row">
<div class="pnd-addres">
<div class="addres-left">
<ul>
<?php
function definition($pnd){
$ar_pnd=array();
foreach($pnd as $pndOtd){
array_push($ar_pnd, $pndOtd->branch);
}
$ar_pnd=array_unique($ar_pnd);
$arr_otd = $ar_pnd;
return $arr_otd;
}
$pndid = 'number_'. $_POST['pnd'];
$pnd = $wpdb->get_results( "SELECT * FROM $pndid" );
$arr_otd = definition($pnd);
foreach($arr_otd as $otd){
?>
<li data-pnd="pnd=<?php echo $_POST['pnd'] ?>" data-otd="otd=<?php echo $otd ?>" tabindex='0' class='otd-but'><?php echo $otd ?></li>
<?php }?>
</ul>
</div>
<div class="addres-right">
<?php if($_POST['pnd'] == 1){ ?>
<h1>ДЛЯ УДОБНОГО ПОИСКА НАЖМИТЕ НА СТРОЕНИЕ</h1>
<div class="addres-info">
<img src="img/map.png" alt="">
</div>
<?php }else{ ?>
<div class="card">
<?php
$idPnd = $_POST['pnd'];
$addresPnd = $wpdb->get_results("SELECT * FROM list WHERE id LIKE $idPnd");
?>
<div class="card-left">
<div class="header-card">
<h2><?php echo $addresPnd[0]->number; ?></h2>
<p><?php echo $addresPnd[0]->addres; ?></p>
</div>
<div class="footer-card">
<p class="addresPnd"><?php echo $addresPnd[0]->addresFull; ?></p>
<p class="numberPnd"><?php echo $addresPnd[0]->contacts; ?></p>
</div>
</div>
<div class="card-right">
<img src="img/<?php echo $idPnd ?>.jpg" alt="<?php echo $idPnd ?>">
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="row">
<div class="pnd-tables">
<div class="table-name">
<table>
<?php
if($_POST['otd']){
$searchdb = $_POST['otd'];
$pnd = $wpdb->get_results( "SELECT * FROM $pndid WHERE branch LIKE '$searchdb'" );
}
function maxArr($pnd){
$maxArray = array();
foreach($pnd as $maxCount){
array_push($maxArray, $maxCount->floor);
}
$maxArray = array_map('intval',$maxArray);
$maxArray = max($maxArray);
return $maxArray;
}
$maxNumb = maxArr($pnd);
?>
<tr>
<td>Должность</td>
<td>ФИО</td>
<td>Адрес</td>
<td>Кабинет</td>
<td>Городской номер</td>
<td>Внутренний номер</td>
</tr>
<?php for($i=1;$i <= $maxNumb;$i++){ ?>
<tr><td colspan="6" class="separator"><?php echo $i ?> ЭТАЖ</td></tr>
<?php foreach($pnd as $tableName){
if($tableName->floor == $i){ ?>
<tr>
<td><?php echo $tableName->rank ?></td>
<td><?php echo $tableName->name ?></td>
<td><?php echo $tableName->addres ?></td>
<td><?php echo $tableName->cabinet ?></td>
<td><?php echo $tableName->cphone ?></td>
<td><?php echo $tableName->phone ?></td>
</tr>
<?php }
} ?>
<?php } ?>
</table>
<div class="time-z">
</div>
</div>
</div>
</div>
</div>
</main>
<script>
jQuery('.pnd-li').click(function(event){
var href = jQuery(this).attr('data-pnd');
jQuery.ajax({
type: 'POST',
url: '',
data: href,
success: function(html){
var temp = document.createElement('html');
temp.innerHTML = html;
var elem = jQuery(temp).find('.pnd-addres');
var elemTab = jQuery(temp).find('.table-name');
jQuery('.pnd-addres').html(elem);
jQuery('.table-name').html(elemTab);
},
error: function(xhr, status, error){
jQuery('.time-z').html(error);
}
});
});
jQuery('.otd-but').click(function(event){
var href = jQuery(this).attr('data-otd');
jQuery.ajax({
type: 'POST',
url: '',
data: href,
success: function(html){
var temp = document.createElement('html');
temp.innerHTML = html;
var elem = jQuery(temp).find('.table-name');
jQuery('.table-name').html(elem);
}
});
});
</script>
<?php get_footer(); ?>