<?php
session_start();
if (!isset($_SESSION["username"])) {
    header("Location: unauthorize_access.php");
}
require("includes/dbconnect.php");
mysqli_query($conn, "drop view cdist"); 
mysqli_query($conn, "drop view cdist1"); 

mysqli_query($conn, "create view cdist as SELECT userid, `username`, level, status, `zimname`, zimmob, `email`, active, makhtab FROM usermain ORDER BY `name`")or die(mysqli_error($conn));
mysqli_query($conn, "create view cdist1 as SELECT a.*, b.`name` AS `levelname` FROM cdist a, level b WHERE a.level=b.code ORDER BY `name`")or die(mysqli_error($conn));
$result = mysqli_query($conn, "SELECT a.*, b.`name` AS `makhname` FROM cdist1 a, makhtab b WHERE a.makhtab = b.code ORDER BY `name`")or die(mysqli_error($conn));

//$result = mysqli_query($conn, "SELECT accode, code, `name`, `country`, `state`, `district`,`tehsil`, `city` FROM centre ORDER BY `name`");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Deeniyat</title>
    <link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="css/text.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="css/grid.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="css/layout.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="css/nav.css" media="screen" />
    <!--[if IE 6]><link rel="stylesheet" type="text/css" href="css/ie6.css" media="screen" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen" /><![endif]-->
    <link href="css/table/demo_page.css" rel="stylesheet" type="text/css" />
    <!-- BEGIN: load jquery -->
    <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery-ui/jquery.ui.core.min.js"></script>
    <script src="js/jquery-ui/jquery.ui.widget.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui/jquery.ui.accordion.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui/jquery.effects.core.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui/jquery.effects.slide.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui/jquery.ui.mouse.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui/jquery.ui.sortable.min.js" type="text/javascript"></script>
    <script src="js/table/jquery.dataTables.min.js" type="text/javascript"></script>
    <!-- END: load jquery -->
    <script type="text/javascript" src="js/table/table.js"></script>
    <script src="js/setup.js" type="text/javascript"></script>
    <script type="text/javascript">
	$(function() {
	
	    var menu_ul = $('.menu > li > ul'),
	           menu_a  = $('.menu > li > a');
	    
	    menu_ul.hide();
	
	    menu_a.click(function(e) {
	        e.preventDefault();
	        if(!$(this).hasClass('active')) {
	            menu_a.removeClass('active');
	            menu_ul.filter(':visible').slideUp('normal');
	            $(this).addClass('active').next().stop(true,true).slideDown('normal');
	        } else {
	            $(this).removeClass('active');
	            $(this).next().stop(true,true).slideUp('normal');
	        }
	    });
	
	});
</script>
    
    <!--For popup window-->
    <script >
function PopupWindowCenter(URL, title,w,h)
{var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var newWin = window.open (URL, title, 'toolbar=no, location=no,directories=no, status=no, menubar=no, scrollbars=no, resizable=no,copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>
    <!End poopup Window-->
    <style>
        .print{
            background-image:url(images/print.png);
            background-repeat: no-repeat;
            width:4px;
            
        }
    </style>
    
    
    <!-- for table-->
        <script src="tables/media/js/jquery.js" type="text/javascript"></script>
        <script src="tables/media/js/jquery.dataTables.js" type="text/javascript"></script>
        
        <style type="text/css">
            @import "tables/media/css/demo_table_jui.css";
            @import "tables/media/themes/smoothness/jquery-ui-1.8.4.custom.css";
        </style>
        
        <style>
            *{
                font-family: arial;
            }
        </style>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function(){
                $('#datatables').dataTable({
                    "sPaginationType":"full_numbers",
                    "aaSorting":[[2, "desc"]],
                    "bJQueryUI":true
                });
            })
            
        </script>
    <!-- End table-->
        <head><script type="text/javascript">
        function Deleteqry(id)
        {
            if(confirm("Are you sure you want to delete this row?")==true)
                window.location="delete.php?delcust="+id;
            return false; 
        } 
        function Editqry(id)
        {
            window.Location="cityproc.php?edit="+id;
            return false;
        }
        </script>
 

</head>
<body>
    <div class="container_12">
        <div class="grid_12 header-repeat">
            <div id="branding">
                <div class="floatleft">3
                    
                    <img src="img/deen3.png" alt="Logo" /></div>
                <div class="floatright">
                    <div class="floatleft">
                        <img src="img/img-profile.jpg" alt="Profile Pic" /></div>
                    <div class="floatleft marginleft10">
                                <ul class="inline-ul floatleft">
                            <li><?php
                           echo 'Hello, ' . $_SESSION['username']
                             ?></li>
                            <li><a href="javascript:void(0);" onClick ="PopupWindowCenter('changepass.php?username=$user', 'PopupWindowCenter',600,700)">Config</a></li>
                            <li><a href="logout.php">Logout</a></li>
                        </ul>
                        <br />
                        
                    </div>
                </div>
                <div class="clear">
                </div>
            </div>
        </div>
        <div class="clear">
        </div>
           <div class="grid_12">
              <ul class="nav main">
                                <li class="ic-dashboard"><a href="#"><span>Graphical Analysis</span></a> </li>
                <li class="ic-form-style"><a href="#"><span>Nigran Entry</span></a></li>
		<li class="ic-form-style"><a href="makh_tab.php"><span>Makhtab Entry</span></a></li>
                <li class="ic-grid-tables"><a href="#"><span>Best 10</span></a></li>
                <li class="ic-gallery dd"><a href="javascript:"><span>Create User</span></a>
               		 <ul>
                             
                              <li><a href="javascript:void(0);" onClick ="PopupWindowCenter('admin.php', 'PopupWindowCenter',600,700)"><span>Create Admin User</span></a></li>    
                              <li><a href="usergrid.php"><span>Create Normal User</span></a></li>
                              <li><a href="javascript:void(0);" onClick ="PopupWindowCenter('niguser.php', 'PopupWindowCenter',600,700)"><span>Create Nigran User</span></a></li>
                         </ul>
                </li>
               <li class="ic-notifications"><a href="#"><span>Upcoming Events</span></a></li>
                 <li class="ic-form-style"><a href="javascript:void(0);" onClick ="PopupWindowCenter('company.php', 'PopupWindowCenter',600,700)">Company Setup</a></li>
            </ul>
        </div>
        <div class="clear">
        </div>
        <div class="grid_2">
            <div class="box sidemenu">
                <div class="block" id="section-menu">
                    <ul class="section menu">
                        <li><a class="menuitem">Masters</a>
                            <ul class="submenu">
                                <li><a href="counttab.php">Country</a></li>
                                <li><a href="statetab.php">State</a></li>
                                <li><a href="disttab.php">District</a></li>
                                <li><a href="tehtab.php">Tehsil</a></li>
                                <li><a href="cittab.php">City</a></li>
                                <li><a href="centtab.php">Center</a></li>
                                <li><a href="makh_tab.php">Makhtab</a></li>
                                <li><a href="subtab.php">Subject</a></li>
                                
                                
                                
                                
                               
                            </ul>
                        </li>
                        <li><a class="menuitem">Entries</a>
                            <ul class="submenu">
                                <li><a  href="nigran.php" >Nigran Statistics</a> </li>
                               <!-- <li><a>Center Head</a> </li>
                                <li><a>State Head</a> </li>
                                <li><a>Country Head</a> </li>
                                <li><a>Main</a> </li>-->
                            </ul>
                        </li>
                        <li><a class="menuitem">Reports</a>
                            <ul class="submenu">
                                <li><a href="repcat.php">Categorywise Total</a> </li>
                                <li><a href="nos.php" >No. of States</a> </li>
                                <li><a href="nod.php" >No. of Districts</a> </li>
                                <li><a href="not.php" >No. of Tehsil</a> </li>
                                <li><a href="nocity.php" >No. of Cities</a> </li>
                                <li><a href="noc.php" >No. of Centres</a> </li>
                                <li><a href="ras.php" >Subjectwise</a> </li>
                            </ul>
                        </li>
                        <li><a class="menuitem">Mis</a>
                            <ul class="submenu">
                                <li><a href="mdw.php" >Makhtab doing well</a> </li>
                                <li><a href="mndw.php" >Makhtab not doing well</a> </li>
                                <li><a href="nds.php" >Not Doing Well Subjectwise</a> </li>
                                <!--<li><a href="noc.php" target="open link in a new tab">Best 100 who are doing well</a> </li>
                                <li><a href="noc.php" target="open link in a new tab">Graphical analysis of Cities + State</a> </li>-->
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="grid_10">
            <div class="box round first grid">
              <!--  <h2>City Data</h2><h2><a href="city_lst.php?printchal" target="_blank">View</a><input type="button" name Export to pdf></input></h2>-->
                <h2>User</h2>
              <div class="">
                    <div id="container">

    <div id="dataTable">

        <div class="ui-grid ui-widget ui-widget-content ui-corner-all">

            <div class="ui-grid-header ui-widget-header ui-corner-top clearfix">

                <div class="header-left">
                    <!-- Left side of table header -->
                </div>

                <div class="header-left">
                    <div align="left">
                         &nbsp;&nbsp;<a href="user.php"><font color="green">+ Add New Record</font></a>
                    </div>
                      <input style="width:150px;" id="searchData" type="hidden"></div>
                </div>

            <table id="datatables" class="display">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Makhtab</th>
                        <th>Zimmedar Name</th>
                        <th>Zimmedar Mobile</th>
                        <th>Level</th>
                        <th>Email</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $a = 1;
                    while ($row = mysqli_fetch_array($result)) {
                    echo "<tr>";
                    echo "<td>$row[username]</td>";
                    echo "<td>$row[makhname]</td>";
                    echo "<td>$row[zimname]</td>";
                    echo "<td>$row[zimmob]</td>";
                    echo "<td>$row[levelname]</td>";
                    echo "<td>$row[email]</td>";
                    if($row["active"] == $a){
                    echo "<td>Active</td>";
                    }
                    else{
                    echo "<td>Inactive</td>";    
                    }
                    echo "<td><a href=\"userproc.php?userid=$row[userid]\"><img src='images/edit.png'></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"delete_user.php?userid=$row[userid]\" onClick=\"return confirm('Do you want to delete?');\"><img src='images/delete.png'></a></td>";
                    echo "</tr>";
                      
                    }
                    ?>
                </tbody>
            </table>
            
        </div>
    </div>

</div>
                  
                               </div>
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="clear">
    </div>

        
        
    <div id="site_info">
        <p>
            Powered By <a href="www.cepheisys.com">CepheiSys</a>
        </p>
    </div>
</body>
</html>
