<?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');
header("Content-type: application/vnd-ms-excel");
 
// Mendefinisikan nama file ekspor "hasil-export.xls"
header("Content-Disposition: attachment; filename=kuisioner-export.xls");
 ?>
									<table  border="1" 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>
                               