<?php
$path="../../";
include("../../map.php");
$w=str_replace(",","",$_GET["w"]);
echo "<div class='wloc'><i class='fa fa-map-marker'></i> ".ucwords($w)."</div>";

function wtc($str){
	$a1=['overcast clouds','light snow','scattered clouds','heavy intensity rain','moderate rain','sky is clear','light rain','very heavy rain','rain and snow','snow','few clouds','broken clouds','Thu','Fri','Sat','Sun','Mon','Tue','Wed','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
	$a2=['Ç.Bulutlu','Hafif Kar Yağmurlu','Bulutlu','Sağanak Yağmurlu','Yağmurlu','Güneşli','H.Yağmurlu','H.Yağmurlu','Karla Karışık','Kar Yağmurlu','Bulutlu','Bulutlu','Perşembe','Cuma','Cumartesi','Pazar','Pazartesi','Salı','Çarşamba','Ock','Şbt','Mar','Nis','May','Haz','Tem','Ağs','Eyl','Ekm','Kas','Arl'];
	return str_replace($a1,$a2,$str);
}

function fastget($url,$t=1){
	$ch=curl_init($url);
	curl_setopt_array($ch,[
		CURLOPT_RETURNTRANSFER=>1,
		CURLOPT_CONNECTTIMEOUT=>$t,
		CURLOPT_TIMEOUT=>$t
	]);
	$d=curl_exec($ch); curl_close($ch);
	return $d;
}

$ctn=($mobile!="")?4:5;
$url="https://api.openweathermap.org/data/2.5/forecast/daily?q=$w&mode=json&units=metric&cnt=$ctn&appid=25e585073d9232f10fa66afa76d62fda";
$data=fastget($url,1);
$json=json_decode($data);

if($json && !empty($json->list)){
	echo '<div class="weathers">';
	foreach($json->list as $v){
		$icon=($v->weather[0]->icon=="01d")?"turn":"run";
		echo "
		<div class='v3-col-xs-6 tac w20' style='padding:5px;'>
			<div class='bg-warning' style='padding:15px 0;border-radius:10px;position:relative;'>
				<img class='wicon $icon' style='height:100px;position:absolute;top:-10px;right:5px;filter:opacity(.5);' 
				src='https://openweathermap.org/img/w/{$v->weather[0]->icon}.png' 
				title='".wtc($v->weather[0]->description)."'>
				<div class='wdate' style='margin-top:50px;'>".wtc(date('D',$v->dt))."</div>
				<p>".wtc($v->weather[0]->description)."</p>
				<div class='wdeg'>
					<b title='Gün'><i class='fa fa-sun-o'></i> ".round($v->temp->day)."</b>&deg 
					<b style='color:#ccc' title='Gece'><i class='fa fa-moon-o'></i> ".round($v->temp->night)."</b><span style='color:#ccc'>&deg</span>
				</div>
			</div>
		</div>";
	}
	echo '</div>';
}else{
	echo "<div style='padding:10px;color:#c00;font-weight:bold;'>Veri alınamadı…</div>";
}
?>