<?php
 
$row = $db->query("SELECT * FROM shoutcast WHERE id = '{$id}'")->fetch(PDO::FETCH_ASSOC);

$server = $row['radyo_ip']; //radyo İp adresini yazdım.
$port = $row['radyo_port']; //radyo port adresini yazdım.
 
$htt = 'http';
if (($port >= '7000') && ($port <= '8000')) { $htt = 'https'; }
if (($port >= '10000') && ($port <= '11000')) { $htt = 'https'; }
$get  = '/7.html';
$ch = curl_init("$htt://{$server}:{$port}{$get}"); //htt değeri girilen porta göre ya http yada https.

if (!$ch) die('Init failed. Bad URI?');
curl_setopt_array($ch,array(CURLOPT_RETURNTRANSFER=>TRUE,CURLOPT_USERAGENT=>'Mozilla'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
if (empty($response)) echo ('Bağlantınızı Konturol Ediniz..!');
if (preg_match('#^.*<BODY>(.*)</BODY>.*$#i',$response,$matches) < 1)
    echo ("".$response);
list($current,$status,$peak,$max,$reported,$bit,$song) = explode(',',$matches[1], 7);

 
$dt_min = new DateTime("last sunday");
$dt_min->modify('+1 day');
$dt_max = clone($dt_min);
$dt_max->modify('+6 days');
$haftabasi = $dt_min->format('Y-m-d');
$haftasonu = $dt_max->format('Y-m-d');
$aybasi = date("Y-m-d",strtotime('first day of this month'));
$aysonu = date("Y-m-d",strtotime('last day of this month'));

$z_bugun = $db->prepare("SELECT * FROM counter where counter_tarih=:counter_tarih");
$z_bugun->execute(array('counter_tarih' => date('Y-m-d')));
$bugun=$z_bugun->rowCount();

$z_buhafta = $db->prepare("SELECT * FROM counter where counter_tarih BETWEEN '{$haftabasi}' AND '{$haftasonu}';");
$z_buhafta->execute();
$buhafta=$z_buhafta->rowCount();

$z_buay = $db->prepare("SELECT * FROM counter where counter_tarih BETWEEN '{$aybasi}' AND '{$aysonu}';");
$z_buay->execute();
$buay=$z_buay->rowCount();

$z_tum = $db->prepare("SELECT * FROM counter");
$z_tum->execute();
$tum=$z_tum->rowCount();

$query=$db->prepare("SELECT * FROM shoutcast");
$query->execute();
$row=$query->fetch(PDO::FETCH_ASSOC);

$theme = $settings["theme"];

if (isset($_POST['editshoutcast'])) {
	$save=$db->prepare("UPDATE shoutcast SET
		radyo_frekans=:radyo_frekans,
		radyo_ip=:radyo_ip,
		radyo_port=:radyo_port 
		WHERE id=0");
	$insert=$save->execute(array(
		'radyo_frekans' => $_POST['radyo_frekans'],
		'radyo_ip' => $_POST['radyo_ip'],
		'radyo_port' => $_POST['radyo_port'] 
	));
	if ($insert) {
		$success = 'İşlem başarıyla gerçekleşti.';
	} else {
		$error = 'Bir hata oluştu.';
	}
}

require admin_view('index');