<?php
require ("includes/check_auth_user.php");
require ("includes/dbconnect.php");
include ('includes/function.php');


include 'Adl/Configuration.php';
include 'Adl/Config/Parser.php';
include 'Adl/Config/JasperServer.php';
include 'Adl/Integration/RequestJasper.php';

try {
	$jasper = new Adl\Integration\RequestJasper();
	/*
	To send output to browser
	*/
	header('Content-type: application/txt');
	echo $jasper->run('/reports/samples/AllAccounts');
	
	/*
	To Save content to a file in the disk
	The path where the file will be saved is registered into config/data.ini
	*/
	//$jasper->run('/reports/samples/AllAccounts','PDF', null, true);

} catch (\Exception $e) {
	echo $e->getMessage();
	die;
}

$admin = $_SESSION["admin_" . $dbname];


if (isset($_POST["submit"])) {
    require("includes/dbconnect.php");

    $cond = "";
    $ncond = "";

    if (!empty($_POST["code"])) {
        $pcode = trim($_POST["code"]);
        $cond.= "AND code LIKE '%$pcode%'";
    }

    if (!empty($_POST["name"])) {
        $pname = trim($_POST["name"]);
        $ncond.= "AND `name` LIKE '%$pname%'";
    }



    $get = mysqli_query($conn, "SELECT code, `name` FROM `country` where `name`!='' $cond $ncond ORDER by `name`")or die(mysqli_error($conn));
    $getno = mysqli_num_rows($get);

    /* Normal Browser View Part */
    ?>    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>

            <style type="text/css">
                <!--
                @import url("css/table.css");
                -->
            </style>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
            <script>
                $(document).ready(function () {
                    $("#hide").click(function () {
                        $("#detail").toggle();
                        return true;
                    });
                });
            </script>

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        </head>
        <body>
            <?php
            $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysql_errno());
            $zcomp = mysqli_fetch_assoc($comp);
            echo "<font size='4px' color='#039'><b>$zcomp[compname]</font></b></font><br />";
            echo "<font size='2px' color='#039'><b> $zcomp[add1]</b></font><br /><br />";
            echo "<b><font color='#039'>State List &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='3px'>Date : " . date("M-d-Y") . "</b><br />";
            echo "<b>" . "Total States - $getno</b><br />";
            echo "<br />";
            ?>

            <table id="hor-minimalist-b" summary="Employee Pay Sheet">

                <thead>
                    <tr>
                        <th style="text-align:left;" scope="col" width="6"><b>Sr.</b></th>
                        <th style="text-align:left;" scope="col" width="2"><b>Country Code</b></th>
                        <th style="text-align:left;" scope="col" width="120"><b>Country Name</b></th>
                    </tr>
                </thead>

                <tbody>
                    <?php
                    $ctr = 0;
                    while ($city = mysqli_fetch_assoc($get)) {
                        $ctr++;
                        echo "<tr>";
                        echo "<td style=\"text-align:left;\" width=\"6\"> \n <span> $ctr </span> \n </td> \n";
                        echo "<td style=\"text-align:left;\" width=\"2\"> \n <span> $city[code] </span> \n </td> \n";
                        echo "<td style=\"text-align:left;\" width=\"120\"> \n <span> $city[name] </span> \n </td> \n";
                        echo "<\tr> ";
                    }
                    ?>
                </tbody>
                <tfoot>

                </tfoot>
            </table>
            </div>
        </body>
    </html>
<?php } ?>
