<?php
session_start();
include('../include/connection.php');
include('../include/app_config.php');
if($_GET['type'] == "disco")
{
?>
<input type="hidden" name="lga"/>
<input type="hidden" name="state"/>
<div class="row row-pad">
    <div class="col-md-2"><label for="name">Select Disco</label></div>
                <div class="col-md-10">
                                    <select name="disco" class="form-control filter" id="discoid">
                                        <?php 
                                            $sql = "select id,name from discos";
                                            $fields = array();
                                            if($_SESSION['user_role'] == DISCO_USER_KEY)
                                            {
                                                $sql = "select d.id,d.name from disco_admin da left outer join users u on da.user_id=u.id left outer join discos d on da.disco_id=d.id where u.email=:user";
                                                $fields = array(':user'=>$_SESSION['user_session']);
                                            }
                                            $q=$con->select_query($sql,$fields);
                                            foreach($q as $r)
                                            {
                                                echo '<option value="'.$r['id'].'">'.$r['name'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>
                          </div>

<?php 
}
else if($_GET['type'] == "lga")
{
?>
<input type="hidden" name="disco"/>
    <div class="row row-pad">
    <div class="col-md-2"><label for="name">Select LGA</label></div>
                <div class="col-md-5">
                                    <select name="state" class="form-control" onchange="getLga(this.value)" id="stateid">
                                        <?php 
                                            $sql = "select id,name from state";
                                            $fields = array();
                                            if($_SESSION['user_role'] == DISCO_USER_KEY)
                                            {
                                                $sql = "select distinct(s.id),s.name from state s left outer join localgovt l on l.state_id=s.id  left outer join discos d on l.disco_id=d.id left outer join disco_admin da on da.disco_id=d.id inner join users u on da.user_id=u.id where u.email=:email";
                                                $fields = array(':email'=>$_SESSION['user_session']);
                                            }
                                            $q=$con->select_query($sql,$fields);
                                            foreach($q as $r)
                                            {
                                                echo '<option value="'.$r['id'].'">'.$r['name'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="col-md-5">
                                    <select name="lga" class="form-control" id="lgaid">
                                        <option value="">--select state first--</option>
                                    </select>
                                </div>
                          </div>
<?php 
}
else if($_GET['type'] == "state")
{
?>
<input type="hidden" name="lga"/>
<input type="hidden" name="disco"/>
<div class="row row-pad">
    <div class="col-md-2"><label for="name">Select State</label></div>
                <div class="col-md-10">
                                    <select name="state" class="form-control" id="stateid">
                                        <?php 
                                            $sql = "select id,name from state";
                                            $fields = array();
                                            if($_SESSION['user_role'] == DISCO_USER_KEY)
                                            {
                                                $sql = "select distinct(s.id),s.name from state s left outer join localgovt l on l.state_id=s.id  left outer join discos d on l.disco_id=d.id left outer join disco_admin da on da.disco_id=d.id inner join users u on da.user_id=u.id where u.email=:email";
                                                $fields = array(':email'=>$_SESSION['user_session']);
                                            }
                                            $q=$con->select_query($sql,$fields);
                                            foreach($q as $r)
                                            {
                                                echo '<option value="'.$r['id'].'">'.$r['name'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>
                          </div>
<?php 
}

?>
