<?php
session_start();
include 'koneksi/koneksi.php';
$app = mysql_fetch_array(mysql_query("SELECT * from aplikasi where id_user='$_SESSION[id]'"));
$id_pertanyaan = mysql_fetch_array(mysql_query("SELECT * from pertanyaan where id_user = '$_SESSION[id]' AND status='1' ORDER BY id DESC"));

$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">
    <!-- chartist CSS -->
    <link href="../assets/plugins/chartist-js/dist/chartist.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 class="active"> <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="javascript:void(0)">Home</a></li>
                            <li class="breadcrumb-item active">Dashboard</li>
                        </ol>
                    </div>
                    <div class="col-md-7 col-4 align-self-center">
                        <a target="_blank" href="https://api.whatsapp.com/send?phone=6281213876749" class="btn waves-effect waves-light btn-danger pull-right hidden-sm-down"><i class="mdi mdi-whatsapp"></i> Upgrade to Pro</a>
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- End Bread crumb and right sidebar toggle -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <!-- Row -->
				Pertanyaan aktif : <?= $id_pertanyaan['pertanyaan'];?><br/><br/>
                <div class="row">
					
                    <!-- Column -->
                    <div class="col-lg-8 col-md-7">
                        <div class="card">
                            <div class="card-block">
                                <div class="row">
                                    <div class="col-12">
                                        <div class="d-flex flex-wrap">
                                            <div>
                                                <h3 class="card-title">Grafik Survey </h3>
                                                <h6 class="card-subtitle">Grafik Survey Bulanan <?= $app ['nama_perusahaan'];?></h6> </div>
                                            <div class="ml-auto">
                                                <ul class="list-inline">
                                                    <?php if($app['sp']=='1'){ ?>
                                                    <li>
                                                        <h6 class="text-success"><i class="fa fa-circle font-10 m-r-10 "></i>Sangat Puas</h6> </li>
                                                    <?php ;} ?>    
                                                    <?php if($app['p']=='1'){ ?>
                                                    <li>
                                                        <h6 class="text-primary"><i class="fa fa-circle font-10 m-r-10"></i>Puas</h6> </li>
                                                        <?php ;} ?>    
                                                    <?php if($app['c']=='1'){ ?>
													<li>
                                                        <h6 class="text-warning"><i class="fa fa-circle font-10 m-r-10"></i>Cukup</h6> </li>
                                                        <?php ;} ?>    
                                                    <?php if($app['k']=='1'){ ?>
                                                        <li>
                                                        <h6 class="text-grey"><i class="fa fa-circle font-10 m-r-10"></i>Kurang</h6> </li>
                                                        <?php ;} ?>    
                                                    <?php if($app['tp']=='1'){ ?>
													<li>
                                                        <h6 class="text-danger"><i class="fa fa-circle font-10 m-r-10"></i>Tidak Puas</h6> </li>
                                                        <?php ;} ?>    
                                                    
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="amp-pxl" style="height: 360px;"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-5">
                        <div class="card">
                            <div class="card-block">
                                <h3 class="card-title">Grafik Hasil Survey</h3>
                                <h6 class="card-subtitle">Hasil keseluruhan survey</h6>
                                <div id="visitor" style="height:260px; width:100%;"></div>
                            </div>
                            <div>
                                <hr class="m-t-0 m-b-0">
                            </div>
                            <div class="card-block text-center ">
                                <ul class="list-inline m-b-0">
                                   <?php if($app['sp']=='1'){ ?>
                                                    <li>
                                                        <h6 class="text-success"><i class="fa fa-circle font-10 m-r-10 "></i>Sangat Puas</h6> </li>
                                                    <?php ;} ?>    
                                                    <?php if($app['p']=='1'){ ?>
                                                    <li>
                                                        <h6 class="text-primary"><i class="fa fa-circle font-10 m-r-10"></i>Puas</h6> </li>
                                                        <?php ;} ?>    
                                                    <?php if($app['c']=='1'){ ?>
													<li>
                                                        <h6 class="text-warning"><i class="fa fa-circle font-10 m-r-10"></i>Cukup</h6> </li>
                                                        <?php ;} ?>    
                                                    <?php if($app['k']=='1'){ ?>
                                                        <li>
                                                        <h6 class="text-grey"><i class="fa fa-circle font-10 m-r-10"></i>Kurang</h6> </li>
                                                        <?php ;} ?>    
                                                    <?php if($app['tp']=='1'){ ?>
													<li>
                                                        <h6 class="text-danger"><i class="fa fa-circle font-10 m-r-10"></i>Tidak Puas</h6> </li>
                                                        <?php ;} ?>  
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                <div class="col-lg-4 col-md-5">
                        <div class="card">
                            <div class="card-block">
                                <h3 class="card-title">Grafik Hasil Survey</h3>
                                <h6 class="card-subtitle">Per Kategori</h6>
                                <div id="visitor_kategori" style="height:260px; width:100%;"></div>
                            </div>
                            <div>
                                <hr class="m-t-0 m-b-0">
                            </div>
                            <div class="card-block text-center ">
                                
                            </div>
                        </div>
                    </div>
                </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>
    <!-- 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>
	

$(function() {
    "use strict";
    // ============================================================== 
    // Sales overview
    // ============================================================== 
	var chart2 = new Chartist.Bar('.amp-pxl', {
        labels: [<?php 
					$tahun=date('Y');
					$bulan = array (1 =>   'Januari',
										'Februari',
										'Maret',
										'April',
										'Mei',
										'Juni',
										'Juli',
										'Agustus',
										'September',
										'Oktober',
										'November',
										'Desember'
									);
									
					$s_month = mysql_query("SELECT MONTH(tanggal) as bulan from survey where id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' group by bulan ORDER BY tanggal DESC limit 6"); 
					while($d_month = mysql_fetch_array($s_month)){ ?> '<?php echo $bulan[$d_month['bulan']];?>',<?php ;}?>],
        series: [
                <?php if($app['sp']=='1'){ ?>
				[<?php $s_month = mysql_query("SELECT month(tanggal) as bulan from survey where id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' group by bulan ORDER BY tanggal DESC limit 6"); 
					while($d_month = mysql_fetch_array($s_month)){ ?> <?php $tsp = mysql_num_rows(mysql_query("SELECT * from survey where survey='SP' AND month(tanggal)='$d_month[bulan]' AND id_pertanyaan='$id_pertanyaan[id]'")); echo $tsp; ?>,<?php ;}?>],
				<?php ;} ?>
				<?php if($app['p']=='1'){ ?>
				[<?php $s_month = mysql_query("SELECT month(tanggal) as bulan from survey where id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' group by bulan ORDER BY tanggal DESC limit 6"); 
					while($d_month = mysql_fetch_array($s_month)){ ?> <?php $tp = mysql_num_rows(mysql_query("SELECT * from survey where survey='P' AND month(tanggal)='$d_month[bulan]' AND id_pertanyaan='$id_pertanyaan[id]'")); echo $tp; ?>,<?php ;}?>],
				<?php ;} ?>
				<?php if($app['c']=='1'){ ?>
				[<?php $s_month = mysql_query("SELECT month(tanggal) as bulan from survey where id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' group by bulan ORDER BY tanggal DESC limit 6"); 
					while($d_month = mysql_fetch_array($s_month)){ ?> <?php $tc = mysql_num_rows(mysql_query("SELECT * from survey where survey='C' AND month(tanggal)='$d_month[bulan]' AND id_pertanyaan='$id_pertanyaan[id]'")); echo $tc; ?>,<?php ;}?>],
				<?php ;} ?>
				<?php if($app['k']=='1'){ ?>
				[<?php $s_month = mysql_query("SELECT month(tanggal) as bulan from survey where id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' group by bulan ORDER BY tanggal DESC limit 6"); 
					while($d_month = mysql_fetch_array($s_month)){ ?> <?php $ttp = mysql_num_rows(mysql_query("SELECT * from survey where survey='TP' AND month(tanggal)='$d_month[bulan]' AND id_pertanyaan='$id_pertanyaan[id]'")); echo $ttp; ?>,<?php ;}?>],
				<?php ;} ?>
				<?php if($app['tp']=='1'){ ?>
				[<?php $s_month = mysql_query("SELECT month(tanggal) as bulan from survey where id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' group by bulan ORDER BY tanggal DESC limit 6"); 
					while($d_month = mysql_fetch_array($s_month)){ ?> <?php $tk = mysql_num_rows(mysql_query("SELECT * from survey where survey='K' AND month(tanggal)='$d_month[bulan]' AND id_pertanyaan='$id_pertanyaan[id]'")); echo $tk; ?>,<?php ;}?>]
				<?php ;} ?>
				
				]
    }, {
        axisX: {
            // On the x-axis start means top and end means bottom
            position: 'end',
            showGrid: false
        },
        axisY: {
            // On the y-axis start means left and end means right
            position: 'start'
        },
        high: '100',
        low: '0',
        plugins: [
            Chartist.plugins.tooltip()
        ]
    });

    var chart = [chart2];

    // ============================================================== 
    // This is for the animation
    // ==============================================================

    for (var i = 0; i < chart.length; i++) {
        chart[i].on('draw', function(data) {
            if (data.type === 'line' || data.type === 'area') {
                data.element.animate({
                    d: {
                        begin: 500 * data.index,
                        dur: 500,
                        from: data.path.clone().scale(1, 0).translate(0, data.chartRect.height()).stringify(),
                        to: data.path.clone().stringify(),
                        easing: Chartist.Svg.Easing.easeInOutElastic
                    }
                });
            }
            if (data.type === 'bar') {
                data.element.animate({
                    y2: {
                        dur: 500,
                        from: data.y1,
                        to: data.y2,
                        easing: Chartist.Svg.Easing.easeInOutElastic
                    },
                    opacity: {
                        dur: 500,
                        from: 0,
                        to: 1,
                        easing: Chartist.Svg.Easing.easeInOutElastic
                    }
                });
            }
        });
    }

    // ============================================================== 
    // Our visitor
    // ============================================================== 

    var chart = c3.generate({
        bindto: '#visitor',
        data: {
            columns: [
                <?php if($app['sp']=='1'){ ?>
                ['Sangat Puas',<?php $tsp = mysql_num_rows(mysql_query("SELECT * from survey where survey='SP' AND id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $tsp;?>],
                <?php ;} ?>
                <?php if($app['p']=='1'){ ?>
                ['Puas', <?php $tlp = mysql_num_rows(mysql_query("SELECT * from survey where survey='P' AND id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $tlp;?>],
                <?php ;} ?>
                <?php if($app['c']=='1'){ ?>
                ['Cukup', <?php $tc = mysql_num_rows(mysql_query("SELECT * from survey where survey='C' AND id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $tc;?>],
                <?php ;} ?>
                <?php if($app['k']=='1'){ ?>
                ['Kurang', <?php $tk = mysql_num_rows(mysql_query("SELECT * from survey where survey='K' AND id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $tk;?>],
				<?php ;} ?>
                <?php if($app['tp']=='1'){ ?>
                ['Tidak Puas', <?php $ttp = mysql_num_rows(mysql_query("SELECT * from survey where survey='TP' AND id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $ttp;?>],
		        <?php ;} ?>
		   ],

            type: 'donut',
            onclick: function(d, i) { console.log("onclick", d, i); },
            onmouseover: function(d, i) { console.log("onmouseover", d, i); },
            onmouseout: function(d, i) { console.log("onmouseout", d, i); }
        },
        donut: {
            label: {
                show: false
            },
            title: "<?php $totals = mysql_num_rows(mysql_query("SELECT * from survey WHERE id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $totals;?> visitor",
            width: 20,

        },

        legend: {
            hide: true
                //or hide: 'data1'
                //or hide: ['data1', 'data2']
        },
        color: {
            pattern: [<?php if($app['sp']=='1'){ ?>
                        'green',
                        <?php ;} ?>
                        <?php if($app['p']=='1'){ ?>
                        'blue', 
                        <?php ;} ?>
                        <?php if($app['c']=='1'){ ?>
                        'orange',
                        <?php ;} ?>
                        <?php if($app['k']=='1'){ ?>
                        'grey', 
                        <?php ;} ?>
                        <?php if($app['tp']=='1'){ ?>
                        'red'
                        <?php ;} ?>
                        ]
        }
    });

// ============================================================== 
    // Our visitor
    // ============================================================== 

    var chart3 = c3.generate({
        bindto: '#visitor_kategori',
        data: {
            columns: [ <?php $s_kategori = mysql_query("SELECT * from jenis_kelamin");
                    while ($kategori = mysql_fetch_array($s_kategori)){?>
                ['<?= $kategori['jenis_kelamin']?>',<?php $jkat = mysql_num_rows(mysql_query("SELECT * from survey where  id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun' and jenis_kelamin ='$kategori[kd_jenis]'")); echo $jkat;?>],
              
				<?php ;} ?>
		   ],

            type: 'donut',
            onclick: function(d, i) { console.log("onclick", d, i); },
            onmouseover: function(d, i) { console.log("onmouseover", d, i); },
            onmouseout: function(d, i) { console.log("onmouseout", d, i); }
        },
        donut: {
            label: {
                show: false
            },
            title: "<?php $totals = mysql_num_rows(mysql_query("SELECT * from survey WHERE id_pertanyaan='$id_pertanyaan[id]' and year(tanggal)='$tahun'")); echo $totals;?> visitor",
            width: 20,

        },

        legend: {
            hide: true
                //or hide: 'data1'
                //or hide: ['data1', 'data2']
        },
        color: {
            pattern: ['green', 'blue', 'orange', 'grey','red']
        }
    });




});

	</script>
</body>

</html>
