<?php
session_start();
include 'koneksi/koneksi.php';
$app = mysql_fetch_array(mysql_query("SELECT * from aplikasi where id_user='$_SESSION[id]'"));

$skr = date('Y-m-d');

/**
 * Jika Tidak login atau sudah login tapi bukan sebagai admin
 * maka akan dibawa kembali kehalaman login atau menuju halaman yang seharusnya.
 */
if ( !isset($_SESSION['username'])) {

	header('location:../admin/login.php');
	exit();
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="../assets/images/favicon.png">
    <title><?= $app['nama_aplikasi'];?> - <?= $app['nama_perusahaan'];?> - admin</title>
    <!-- Bootstrap Core CSS -->
    <link href="../assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<!-- Bootstrap datetime picker-->
    <link href="datepicker/css/bootstrap-datepicker3.css" rel="stylesheet">

    <!-- chartist CSS -->
    <link href="../assets/plugins/chartist-js/dist/chartist.min.css" rel="stylesheet">
    <link href="../assets/plugins/chartist-js/dist/chartist-init.css" rel="stylesheet">
    <link href="../assets/plugins/chartist-plugin-tooltip-master/dist/chartist-plugin-tooltip.css" rel="stylesheet">
    <!--This page css - Morris CSS -->
    <link href="../assets/plugins/c3-master/c3.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="css/style.css" rel="stylesheet">
    <!-- You can change the theme colors from here -->
    <link href="css/colors/blue.css" id="theme" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body class="fix-header fix-sidebar card-no-border">
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
    </div>
    <!-- ============================================================== -->
    <!-- Main wrapper - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <div id="main-wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->
               <?php include"controller/topbar.php";?>

        <!-- ============================================================== -->
        <!-- End Topbar header -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <aside class="left-sidebar">
            <!-- Sidebar scroll-->
            <div class="scroll-sidebar">
                <!-- Sidebar navigation-->
                <nav class="sidebar-nav">
                    <ul id="sidebarnav">
                        <li > <a class="waves-effect waves-dark" href="index.php" aria-expanded="false"><i class="mdi mdi-gauge"></i><span class="hide-menu">Dashboard</span></a>
                        </li>
                        <li> <a class="waves-effect waves-dark" href="laporan.php?start=&end=" aria-expanded="false"><i class="mdi mdi-file-document"></i><span class="hide-menu">Laporan</span></a>
                        </li>
						<li> <a class="waves-effect waves-dark" href="pertanyaan.php" aria-expanded="false"><i class="mdi mdi-help"></i><span class="hide-menu">Pertanyaan</span></a>
                        </li>
                        <li> <a class="waves-effect waves-dark" href="feed.php" aria-expanded="false"><i class="mdi mdi-rss-box"></i><span class="hide-menu">Feed</span></a>
                        </li>
						  <li> <a class="waves-effect waves-dark" href="jenis_kelamin.php" aria-expanded="false"><i class="mdi mdi-account"></i><span class="hide-menu">Kategori</span></a>
                        </li>
                        <li> <a class="waves-effect waves-dark" href="setting.php" aria-expanded="false"><i class="mdi mdi-settings"></i><span class="hide-menu">Setting</span></a>
                        </li>
						<li> <a class="waves-effect waves-dark" href="profil.php" aria-expanded="false"><i class="mdi mdi-account-check"></i><span class="hide-menu">Profil</span></a>
                        </li>
						<li><hr></li>
						<li> <a class="waves-effect waves-dark" href="../index.php" target="_blank" aria-expanded="false"><i class="mdi mdi-arrow-expand-all"></i><span class="hide-menu">Front End</span></a>
                        </li>
						<li> <a class="waves-effect waves-dark text-danger" href="controller/logout.php" aria-expanded="false"><i class="mdi mdi-power text-danger"></i><span class="hide-menu">Logout</span></a>
                        </li>
                    </ul>
                </nav>
                <!-- End Sidebar navigation -->
            </div>
            <!-- End Sidebar scroll-->
            <!-- Bottom points-->
            <div class="sidebar-footer">
                <!-- item--><a href="setting.php" class="link" data-toggle="tooltip" title="Settings"><i class="ti-settings"></i></a>
                <!-- item--><a href="../index.php" class="link" data-toggle="tooltip" title="Front End"><i class="mdi mdi-arrow-expand-all"></i></a>
                <!-- item--><a href="controller/logout.php" class="link text-danger" data-toggle="tooltip" title="Logout"><i class="mdi mdi-power"></i></a> </div>
            <!-- End Bottom points-->
        </aside>
        <!-- ============================================================== -->
        <!-- End Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Page wrapper  -->
        <!-- ============================================================== -->
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Bread crumb and right sidebar toggle -->
                <!-- ============================================================== -->
                <div class="row page-titles">
                    <div class="col-md-5 col-8 align-self-center">
                        <h3 class="text-themecolor"><?= $app['nama_aplikasi'];?></h3>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index">Home</a></li>
                            <li class="breadcrumb-item active">Laporan</li>
                        </ol>
                    </div>
                    <div class="col-md-7 col-4 align-self-center">
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- End Bread crumb and right sidebar toggle -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <!-- Row -->
                <div class="row">
                    <!-- column -->
                    <div class="col-lg-12">
						<form method="GET">
						<div class="form-group form-inline">
							<div class='col-sm-12'>
								<input type='text' name="start" class="tanggal form-control" value="<?= $_GET['start']?>" Placeholder="Dari Tanggal"> - 
							
								<input type='text' name="end" class="tanggal form-control" value="<?= $_GET['end']?>" Placeholder="Sampai">
								<select name="kd_jenis" class=" form-control">
								<option value="" >Pilih Kategori</option>
								<?php
											$bg = $_GET['kd_jenis'];
											$sql_bg = mysql_query("SELECT * from jenis_kelamin");
											while($d_bg = mysql_fetch_array($sql_bg)){
											if ($bg == $d_bg['kd_jenis']){
											echo '<option value="'.$d_bg['kd_jenis'].'"  selected>'.$d_bg['kd_jenis'].' - '.$d_bg['jenis_kelamin'].'</option>';
												} else {
											echo '<option value="'.$d_bg['kd_jenis'].'"  >'.$d_bg['kd_jenis'].' - '.$d_bg['jenis_kelamin'].'</option>';
												}
											}
											?>
								</select>
								<button type="submit" class="btn btn-right btn-danger">FILTER</button>	
							</div>
						</div>
						</form>
						<?php if (isset($_GET['start']) && $_GET['end']) { ?>
						<?php $kategori = mysql_fetch_array(mysql_query("SELECT * from jenis_kelamin where kd_jenis='$_GET[kd_jenis]'"));?>
                        <div class="card">
                            <div id="detail" class="card-block">
                                <h4 class="card-title">Hasil Survey kategori <?= $kategori['jenis_kelamin'];?> tanggal <?= $_GET['start'];?> s/d <?= $_GET['end'];?></h4>
                                <div  class="table-responsive">
                                    <table  class="table table-bordered"  align="center">
                                        <thead>
                                            <tr>
                                                <td align="center">#</td>
                                                <td align="center">Tanggal</td>
                                                <td align="center">Kategori</td>
                                                <?php if($app['sp']=='1'){ ?>
                                                <td align="center">Sangat Puas</td>
                                                <?php ;} ?>
                                                <?php if($app['p']=='1'){ ?>
                                                <td align="center">Puas</td>
                                                <?php ;} ?>
                                                <?php if($app['c']=='1'){ ?>
												<td align="center">Cukup</td>
												<?php ;} ?>
                                                <?php if($app['k']=='1'){ ?>
												<td align="center">Kurang</td>
												<?php ;} ?>
                                                <?php if($app['tp']=='1'){ ?>
												<td align="center">Tidak Puas</td>
												<?php ;} ?>
												<td align="center"><b>TOTAL</b></td>
												
                                            </tr>
                                        </thead>
                                        <tbody>
											<?php 
											$id_pertanyaan = mysql_fetch_assoc(mysql_query("SELECT * from pertanyaan where id_user = '$_SESSION[id]' AND status='1' order by id desc"));
											$s_survey = mysql_query("SELECT * from survey where (tanggal between '$_GET[start]' AND '$_GET[end]') AND id_pertanyaan='$id_pertanyaan[id]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]' GROUP BY tanggal ");
											$i=1;
											while ($d_survey = mysql_fetch_array($s_survey)){
											?>
                                            <tr>
                                                <td align="center"><?= $i++;?></td>
                                                <td align="center"><?= $d_survey['tanggal'];?></td>
                                                <td align="center"><?php $kategori = mysql_fetch_array(mysql_query("SELECT * from jenis_kelamin where kd_jenis='$d_survey[jenis_kelamin]'")); echo $kategori['jenis_kelamin'];?></td>
                                                <?php if($app['sp']=='1'){ ?>
                                                <td align="center"><?php $sp = mysql_num_rows(mysql_query("SELECT * from survey where tanggal='$d_survey[tanggal]' AND id_pertanyaan='$id_pertanyaan[id]' AND survey='SP'  AND jenis_kelamin LIKE '%$_GET[kd_jenis]'" )); echo $sp;?></td>
                                                <?php ;} ?>
                                                <?php if($app['p']=='1'){ ?>
                                                <td align="center"><?php $p = mysql_num_rows(mysql_query("SELECT * from survey where tanggal='$d_survey[tanggal]' AND id_pertanyaan='$id_pertanyaan[id]' AND survey='P' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $p;?></td>
												<?php ;} ?>
                                                <?php if($app['c']=='1'){ ?>
												<td align="center"><?php $c = mysql_num_rows(mysql_query("SELECT * from survey where tanggal='$d_survey[tanggal]' AND id_pertanyaan='$id_pertanyaan[id]' AND survey='C' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $c;?></td>
												<?php ;} ?>
                                                <?php if($app['k']=='1'){ ?>
												<td align="center"><?php $k = mysql_num_rows(mysql_query("SELECT * from survey where tanggal='$d_survey[tanggal]' AND id_pertanyaan='$id_pertanyaan[id]' AND survey='K' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $k;?></td>
												<?php ;} ?>
                                                <?php if($app['tp']=='1'){ ?>
												<td align="center"><?php $tp = mysql_num_rows(mysql_query("SELECT * from survey where tanggal='$d_survey[tanggal]' AND id_pertanyaan='$id_pertanyaan[id]' AND survey='TP' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $tp;?></td>
												<?php ;} ?>
												<td align="center"><?php $total = mysql_num_rows(mysql_query("SELECT * from survey where tanggal='$d_survey[tanggal]' AND id_pertanyaan='$id_pertanyaan[id]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $total;?></td>
												</tr>
											<?php ;} ?>
											 <tr>
                                                <td align="center" colspan="3">Jumlah Total</td>
                                                 <?php if($app['sp']=='1'){ ?>
                                                <td align="center"><b><?php $tsp = mysql_num_rows(mysql_query("SELECT * from survey where survey='SP' AND id_pertanyaan='$id_pertanyaan[id]' AND tanggal between '$_GET[start]' AND '$_GET[end]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $tsp;?></b></td>
                                                 <?php ;} ?>
                                                <?php if($app['p']=='1'){ ?>
                                                <td align="center"><b><?php $tlp = mysql_num_rows(mysql_query("SELECT * from survey where survey='P' AND id_pertanyaan='$id_pertanyaan[id]'  AND tanggal between '$_GET[start]' AND '$_GET[end]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $tlp;?></b></td>
												<?php ;} ?>
                                                <?php if($app['c']=='1'){ ?>
												<td align="center"><b><?php $tc = mysql_num_rows(mysql_query("SELECT * from survey where survey='C' AND id_pertanyaan='$id_pertanyaan[id]' AND tanggal between '$_GET[start]' AND '$_GET[end]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $tc;?></b></td>
												<?php ;} ?>
                                                <?php if($app['k']=='1'){ ?>
												<td align="center"><b><?php $tk = mysql_num_rows(mysql_query("SELECT * from survey where survey='K' AND id_pertanyaan='$id_pertanyaan[id]' AND tanggal between '$_GET[start]' AND '$_GET[end]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $tk;?></b></td>
												<?php ;} ?>
                                                <?php if($app['tp']=='1'){ ?>
												<td align="center"><b><?php $ttp = mysql_num_rows(mysql_query("SELECT * from survey where survey='TP' AND id_pertanyaan='$id_pertanyaan[id]' AND tanggal between '$_GET[start]' AND '$_GET[end]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $ttp;?></b></td>
												<?php ;} ?>
												<td align="center"><b><?php $totals = mysql_num_rows(mysql_query("SELECT * from survey where tanggal between '$_GET[start]' AND '$_GET[end]' AND id_pertanyaan='$id_pertanyaan[id]' AND jenis_kelamin LIKE '%$_GET[kd_jenis]'")); echo $totals;?></b></td>
											
											</tr>
                                        </tbody>
                                    </table>
                                </div>
							</div>
							
                        </div>
						<script>
								function printContent(el){
									var restorepage = document.body.innerHTML;
									var printcontent = document.getElementById(el).innerHTML;
									document.body.innerHTML = printcontent;
									window.print();
									document.body.innerHTML = restorepage;
								}
								</script>
								<button target="_blank" onClick="printContent('detail')" class="btn btn-right btn-info"><i class="fa fa-print" ></i> PRINT</button>
								<a href="export.php?start=<?= $_GET['start'];?>&end=<?= $_GET['end'];?>&kd_jenis=<?= $_GET['kd_jenis']?>" target="_new"><button type="submit" class="btn btn-right btn-success"><i class="fa fa-file-excel-o" ></i> EXPORT TO EXCEL</button></a>	
								<?php if($app['saran']=='1'){ ?>
								<a href="saran.php?start=<?= $_GET['start'];?>&end=<?= $_GET['end'];?>&kd_jenis=<?= $_GET['kd_jenis']?>" target="_new"><button type="submit" class="btn btn-right btn-danger"><i class="fa fa-file-word-o" ></i> Lihat Saran</button></a>
						        <?php ;} ?>
						<?php ;} else {echo'';}?>
                    </div>
                </div>
                <!-- Row -->
               
                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
            <footer class="footer"> © 2019 <?= $app['nama_aplikasi'];?> - <?= $app['nama_perusahaan'];?> by besurvey.id</footer>
            <!-- ============================================================== -->
            <!-- End footer -->
            <!-- ============================================================== -->
        </div>
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="../assets/plugins/jquery/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="../assets/plugins/bootstrap/js/tether.min.js"></script>
    <script src="../assets/plugins/bootstrap/js/bootstrap.min.js"></script>
	 <!-- Bootstrap datetime picker-->
    <script src="js/daterangepicker.js"></script>
    <script src="datepicker/js/bootstrap-datepicker.js"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                $('.tanggal').datepicker({
                    todayHighlight: true,
					format: "yyyy-mm-dd",
                    autoclose:true
                });
            });
        </script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="js/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="js/sidebarmenu.js"></script>
    <!--stickey kit -->
    <script src="../assets/plugins/sticky-kit-master/dist/sticky-kit.min.js"></script>
    <!--Custom JavaScript -->
    <script src="js/custom.min.js"></script>
    <!-- ============================================================== -->
    <!-- This page plugins -->
    <!-- ============================================================== -->
    <!-- chartist chart -->
    <script src="../assets/plugins/chartist-js/dist/chartist.min.js"></script>
    <script src="../assets/plugins/chartist-plugin-tooltip-master/dist/chartist-plugin-tooltip.min.js"></script>
    <!--c3 JavaScript -->
    <script src="../assets/plugins/d3/d3.min.js"></script>
    <script src="../assets/plugins/c3-master/c3.min.js"></script>
    <!-- Chart JS -->
    <script src="js/dashboard1.js"></script>
</body>

</html>
