<?php

session_start();
// paging code
// Query to count rows.
extract($_GET);
include_once 'inc/db_trans.inc.php';
include_once 'function/add_fun.php';
$officeid = $_GET["officeid"];
$officename = $_GET["officename"];
$frmdt = $_GET["frmdt"];
$todt = $_GET["todt"];
$usercode = $_SESSION['user_cd'];
$rsOffice = fatch_OfficeList($officeid, $officename, $frmdt, $todt, $usercode);
$items = 1;
// number of items per page.
$all = $_GET['a'];
$num_rows = mysqli_num_rows($rsOffice);
if ($all == "all") {
    $items = $num_rows;
}
$nrpage_amount = $num_rows / $items;
$page_amount = ceil($num_rows / $items);
$page_amount = $page_amount - 1;
$page = $_GET['p'];
$section = 'paging';
if ($page < "1") {
    $page = "0";
}
$p_num = $items * $page;
//end paging code
    $sub_div = isset($_SESSION['sub_div_o']) ? $_SESSION['sub_div_o'] : '';
    $frmdt = isset($_SESSION['frmdt']) ? $_SESSION['frmdt'] : '';
    $todt = isset($_SESSION['todt']) ? $_SESSION['todt'] : '';
}
if ($delcode != "" && $delcode != null) {
    $total = ofc_del_check(decode($delcode));
    if ($total == "0") {
        $aa = delete_office(decode($delcode));
        if ($aa == 1) {
            echo "<span class='alert-success'>Record deleted successfully</span><br />\n";
        }
    } else {
        echo "<span class='error'>Record already used</span><br />\n";
    }
}
$rsOffice_dum = fatch_OfficeList($sub_div, $officeid, $officename, $frmdt, $todt, $usercode);
$num_rows_dum = rowCount($rsOffice_dum);
$items = 50;
// number of items per page.
$all = $_GET['a'];
if ($all == "all") {
    $items = $num_rows_dum;
}
$items = $items == 0 ? 1 : $items;
$nrpage_amount = $num_rows_dum / $items;
$page_amount = ceil($num_rows_dum / $items);
$page_amount = $page_amount - 1;
$page = $_GET['p'];
$section = 'list-office-details';
if ($page < "1") {
    $page = "0";