<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");
$sql=mysqli_query($conn, "select * from ".$_SESSION['lang']." where id=".$_GET["id"].""); $rs=mysqli_fetch_assoc($sql);
$jstn = json_decode($rs["n1"], true);
$jssi = json_decode($rs["n2"], true);
$jsa = json_decode($rs["n3"], true);
$jsi = json_decode($rs["n17"], true);
?>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div class="v3-col-md-12">
	<script>
		jQuery(document).ready(function(){
			jQuery("#filter").keyup(function() {
				var filter = jQuery(this).val(),
				count = 0;
				jQuery('#accordion div').each(function() {
					if (jQuery(this).text().search(new RegExp(filter, "i")) < 0) {
						jQuery(this).hide();
					} else {
						jQuery(this).show();
						count++;
					}
				});
			});
		});
	</script>
	<div class="">
		<fieldset class="grey-bg">
			<legend><?php echo translate("Anket Raporu")?></legend>
			<a onclick="divyaz('accordion')" class="v3-btn v3-btn-xs v3-btn-success" style="position: absolute; right: 15px; margin-top: -45px;"><i class="fa fa-print" aria-hidden="true"></i> Yazdır</a>
			<a href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&durum=clear" class="v3-btn v3-btn-xs v3-btn-warning" style="position: absolute; right: 85px; margin-top: -45px;"><i class="fa fa-eraser" aria-hidden="true"></i> Reset</a>
			<form action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>" method="post" style="position: absolute; margin-top: -55px; right: 160px;">
				<input id="filter" type="text" class="" name="q" style="" placeholder="Filtre">
				<input id="" type="date" name="ts1" style="" placeholder="">
				<input id="" type="date" name="ts2" style="" placeholder="">
				<button type="submit" class="v3-btn v3-btn-xs v3-btn-info">Filtre</button>
			</form>
			<div class="accordion" id="accordion" style="clear:both;margin-top: 10px;">
			<?php if($_POST["ts1"]=="" and $_POST["ts2"]==""){?>
				<div class="card card-default">
					<div class="card-header" style="height: 50px;background: aquamarine">
						<h4 class="card-title m-0">
							<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse0">
								<i class="fa fa-pie-chart" aria-hidden="true"></i> <?php echo translate("Anket Rapor")?>
							</a>
						</h4>
					</div>
					<div id="collapse0" class="collapse">
						<div class="card-body">
							<div class="row">
								<?php
								if(mysqli_num_rows($sql)>0) { $c=0; for ( $i=1 ; $i < 99 ; $i++ ){
									if($jssi["s".$i.""]==1){
										$c++;
									}
								}}
								if(mysqli_num_rows($sql)>0) { for ( $i=1 ; $i < 99 ; $i++ ){ $rcolor = ($i %2 ) ? "f9f9f9" : "eae9e9";
								?>
								<?php if(!empty($jstn["t".$i.""])){?>
									<?php if($jssi["i".$i.""]=="3"){?>
										<div class="v3-col-md-4 mt20 mmt20 mb10 mmb10" style="">
											<script type="text/javascript">
												google.charts.load("current", {packages:["corechart"]});
												google.charts.setOnLoadCallback(drawChart);
												function drawChart() {
													var data = google.visualization.arrayToDataTable([
														['Task', 'Hours per Day'],
														<?php
														$parcala=$jstn["n".$i.""]; $n= substr_count($parcala, ','); $s= 0; while ( $s <= $n ) {$baslik=explode(",",$parcala);
														$a=0; $b=0; $ip=0;
														foreach($jsa as $answers){$b++;
															foreach($answers as $key=>$value){
																//echo "".$key." : ".cevir4($jstn["t".$i.""])."<br>";
																if($key==str_replace(".", "_", cevir4($jstn["t".$i.""])) and $value==$baslik[$s]){$a++; }
															}
														}
														?>
														['<?php echo str_replace("'",'',$baslik[$s]);?>',	<?php echo $a?>],
														<?php $s++; }?>
														]);
													var options = {
														title: '<?php echo $jstn["t".$i.""]?>',
														is3D: true,
													};
													var chart = new google.visualization.PieChart(document.getElementById('piechart_3d<?php echo $i?>'));
													chart.draw(data, options);
												}
											</script>
											<div id="piechart_3d<?php echo $i?>" style="width: 100%;"></div>
										</div>
										<?php }?>
										<?php if($jssi["i".$i.""]=="4"){?>
											<div class="v3-col-md-4 mt20 mmt20 mb10 mmb10" style="">
												<?php
													$ques = explode(',',$jstn["n".$i.""]);
													$i0=0;$i1=0;$i2=0;$i3=0;$i4=0;$i5=0;$i6=0;$i7=0;$i8=0;$i9=0;
													foreach($jsa as $answers){$b++;
														foreach($answers as $key=>$value){
															if($key==str_replace(".", "_", cevir4($jstn["t".$i.""]))){
																if ($ques[0]<>"" and in_array($ques[0], $value)) {$i0++;}
																if ($ques[1]<>"" and in_array($ques[1], $value)) {$i1++;}
																if ($ques[2]<>"" and in_array($ques[2], $value)) {$i2++;}
																if ($ques[3]<>"" and in_array($ques[3], $value)) {$i3++;}
																if ($ques[4]<>"" and in_array($ques[4], $value)) {$i4++;}
																if ($ques[5]<>"" and in_array($ques[5], $value)) {$i5++;}
																if ($ques[6]<>"" and in_array($ques[6], $value)) {$i6++;}
																if ($ques[7]<>"" and in_array($ques[7], $value)) {$i7++;}
																if ($ques[8]<>"" and in_array($ques[8], $value)) {$i8++;}
																if ($ques[9]<>"" and in_array($ques[9], $value)) {$i9++;}
															}
														}
													}
												?>
												<script type="text/javascript">
												google.charts.load("current", {packages:["corechart"]});
												google.charts.setOnLoadCallback(drawChart);
												function drawChart() {
													var data = google.visualization.arrayToDataTable([
														['Task', 'Hours per Day'],
														<?php if ($ques[0]<>""){?>['<?php echo $ques[0];?>',	<?php echo $i0?>],<?php }?>
														<?php if ($ques[1]<>""){?>['<?php echo $ques[1];?>',	<?php echo $i1?>],<?php }?>
														<?php if ($ques[2]<>""){?>['<?php echo $ques[2];?>',	<?php echo $i2?>],<?php }?>
														<?php if ($ques[3]<>""){?>['<?php echo $ques[3];?>',	<?php echo $i3?>],<?php }?>
														<?php if ($ques[4]<>""){?>['<?php echo $ques[4];?>',	<?php echo $i4?>],<?php }?>
														<?php if ($ques[5]<>""){?>['<?php echo $ques[5];?>',	<?php echo $i5?>],<?php }?>
														<?php if ($ques[6]<>""){?>['<?php echo $ques[6];?>',	<?php echo $i6?>],<?php }?>
														<?php if ($ques[7]<>""){?>['<?php echo $ques[7];?>',	<?php echo $i7?>],<?php }?>
														<?php if ($ques[8]<>""){?>['<?php echo $ques[8];?>',	<?php echo $i8?>],<?php }?>
														<?php if ($ques[9]<>""){?>['<?php echo $ques[9];?>',	<?php echo $i9?>],<?php }?>
														]);
													var options = {
														title: '<?php echo $jstn["t".$i.""]?>',
														is3D: true,
													};
													var chart = new google.visualization.PieChart(document.getElementById('piechart_3d<?php echo $i?>'));
													chart.draw(data, options);
												}
											</script>
											<div id="piechart_3d<?php echo $i?>" style="width: 100%;"></div>
										</div>
									<?php }?>
								<?php }?>
							<?php }?>
						<?php }?>
					</div>
				</div>
			</div>
			</div>
			<?php }?>
			<?php
			ksort($jsa);
			$cws 	=	count($jsa);
			$b		=	0; $klimit=15;
			if($_GET["sayfa"] == "") {$pno = 0; $pfirst = 0; $plast = $klimit;}else{$pno = $_GET["sayfa"]; $pfirst = ($_GET["sayfa"]-1) * $klimit; $plast = ($_GET["sayfa"]) * $klimit;} $tpc=$cws/$klimit;
			foreach($jsa as $answers){$b++;
				$ts=explode(' ',$answers["Tarih"]); $ts_=explode('-',$ts[0]); $ts = "".$ts_[0]."-".$ts_[2]."-".$ts_[1]."";
				if((($_POST["ts1"]=="" and $_POST["ts2"]=="") and ($b > $pfirst and $b <= $plast)) or ($_POST["ts1"] <= $ts and $ts <= $_POST["ts2"])){
			?>
				<div class="card card-default">
					<div class="card-header" style="height: 50px;background: antiquewhite; cursor:pointer;" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $b?>">
						<h4 class="card-title m-0">
							<a style="width:95%; float:left;">
								<i class="fa fa-pie-chart" aria-hidden="true"></i> <?php if($answers["Ad_Soyad"]<>""){echo $answers["Ad_Soyad"];}else{echo $answers["Tarih"];}?>
							</a>
							<a href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&durum=sjson&jsid=<?php echo array_keys($jsa)[$b-1]?>" style="width:2%; float:right;" class="fa fa-trash noprint"></a>
						</h4>
					</div>
					<div id="collapse<?php echo $b?>" class="collapse <?php if($_POST["ts1"]<>"" and $_POST["ts2"]<>""){echo "show";}?>">
						<div class="card-body results" style="display: flow-root; padding-bottom:15px;">
							<?php
							foreach($answers as $key=>$value){
								if($key<>"sID" and $key<>"pID" and $key<>"PageID" and $key<>"Tarih" and $key<>"User_ID" and $key<>"IP" and substr($key,0,6)<>"attach" and !is_array($value)){
									?>
									<i class="fa fa-question-circle" aria-hidden="true"></i> <b><?php echo str_replace('_',' ',$key)?></b><br><i class="fa fa-commenting-o" aria-hidden="true"></i> <span class="v3-bg-info" style="padding: 0px 5px;"><?php echo $value;?></span><br>
								<?php }elseif(is_array($value)){?>
									<i class="fa fa-question-circle" aria-hidden="true"></i> <b><?php echo str_replace('_',' ',$key)?></b><br><i class="fa fa-commenting-o" aria-hidden="true"></i> <?php foreach($value as $value2){?><span class="v3-bg-info" style="padding: 0px 5px; margin-right:5px;"><?php echo $value2;?></span><?php }?><br>
								<?php }elseif(substr($key,0,6)=="attach"){?>
									<div class="v3-col-md-3" style="margin-top:15px;"><img src="<?php echo $value?>" style="width:100%;"></div>
								<?php }}?>
								<ol class="breadcrumb" style="margin: 10px 0px 0px 0px;">
								<?php
									foreach($answers as $key=>$value){
									if($key=="Tarih" or $key=="User_ID" or $key=="IP"){
									?>
									<li><b><?php echo str_replace('_',' ',$key)?></b> : <?php echo $value;?></li>
								<?php }}?>
								</ol>
							</div>
						</div>
					</div>
				<?php }}?>
			</div>
			<div class="pagination <?php if($_POST["ts1"]<>"" and $_POST["ts2"]<>""){echo "dn";}?>" role="navigation">
				<a class="v3-btn v3-btn-xs v3-btn-warning" style="padding:3px 10px; border-right:2px solid #ccc;" href="<?php if($_GET["sayfa"]>1){?>?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&sayfa=<?php echo $_GET["sayfa"]-1;?>#&tab-survey<?php }else{?>#<?php }?>">«</a>
				<select onChange="self.location.href=this.options[this.selectedIndex].value;">
				<?php for ($i = $sbas; $i <= $tpc; $i++) {$x=$i+1; ?>
					<option value="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&sayfa=<?php echo $x;?>#&tab-survey" <?php if($_GET["sayfa"]==$x){echo "disabled";}elseif($_GET["sayfa"]=="" and $x==1){echo "disabled";}?> <?php if($_GET["sayfa"]==$x){echo "selected";}?>><?php echo $x;?></option>
				<?php }?>
				</select>
				<a class="v3-btn v3-btn-xs v3-btn-warning" style="padding:3px 10px; border-right:2px solid #ccc;" href="<?php if($_GET["sayfa"]=="" or $_GET["sayfa"]>0){?>?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&sayfa=<?php echo $_GET["sayfa"]+1;?>#&tab-survey<?php }else{?>#<?php }?>">»</a>
			</div>
		</fieldset>
	</div>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
	<?php
	if($_GET["durum"] == "sjson"){
		unset($jsa[$_GET["jsid"]]);
		$aform = json_encode($jsa, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
		$sql2 = mysqli_query($conn, "update ".$_SESSION["lang"]." set n3='".addslashes(stripslashes($aform))."' where id=".$_GET["id"]."");
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&sayfa=".$_GET["sayfa"]."&durum=ok#&tab-survey",self,500,1);
	}elseif($_GET["durum"] == "clear"){
		$Rsq = mysqli_query($conn, "update ".$_SESSION['lang']." set n3='' where id=".$_GET["id"]."");
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok#&tab-icerik",self,500,1);
	}
	?>