<?php
include("../../../wp-load.php");
include("../../../wp-config.php");

global $k_radio ;


function k_temiz_getir($input) {
   $input = str_replace("\r\n", "", $input);	
   $input = strip_tags($input);	
   $input = htmlspecialchars_decode($input);	
   $input = html_entity_decode($input);
   return $input;
}
    $ipAdresi = $_SERVER['REMOTE_ADDR'];
    $sadeTarih = date("Y-m-d");
    $sadeSaat = date("H:i:s");
    $simdikiZaman = date("Y-m-d H:i:s");



	$gun = k_temiz_getir($_GET['gun']);
	if($gun == 'pazartesi'){
	$gun = '0';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}elseif($gun == 'sali'){
	$gun = '1';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}elseif($gun == 'carsamba'){
	$gun = '2';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}elseif($gun == 'persembe'){
	$gun = '3';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}elseif($gun == 'cuma'){
	$gun = '4';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}elseif($gun == 'cumartesi'){
	$gun = '5';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}elseif($gun == 'pazar'){
	$gun = '6';
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}else{
	$gun = date('w', strtotime("-1 day"));
	$gunData 	= get_option( 'yayinAkisi_'.$gun );
	}
	$hafta = date("W",strtotime($simdikiZaman));
	$bugunhaftaninkacinci = date("w",strtotime($simdikiZaman));
	$year = date("Y");

	

	$i=0;
	
	if(is_array($gunData)):
	
	$sortArray = array();
	
	foreach($gunData as $bilgi){
		
	$i++;

	$kac = count($bilgi['program_adi']);
	
	for($a=0; $a<$kac; $a++):
	
	$sortArray[$bilgi['program_saati'][$a]] = array($bilgi['program_adi'][$a],$bilgi['program_saati'][$a],$bilgi['program_bitis_saati'][$a],$bilgi['prg_id'][$a] );
	
	endfor;
		
	}
	
	ksort($sortArray);
	
	foreach($sortArray as $ver) {

	$my_postid = $ver[3];
	$content_post = get_post($my_postid);
	$title = $content_post->post_title;
	$content = $content_post->post_excerpt;
	
	//print_r($content_post);

	if($title != htmlspecialchars($ver[0])) {
		$program = null;
		$resim = plugin_dir_url( __FILE__ ) . "images/noimage.png";
	}else {
		$program = $ver[3];
		if (has_post_thumbnail( $program ) ):
		$image = wp_get_attachment_image_src( get_post_thumbnail_id( $program ), 'thumbnail' );
		$resim = $image[0];
		else:
		$resim = plugin_dir_url( __FILE__ ) . "images/noimage.png";
		endif;
	}

	
		$array['yayin_akisi'][] = array('gun' => $gun, 'id' => $id, 'name' => htmlspecialchars($ver[0]), 'picture' => $resim, 'date_time' => $ver[1], 'date_time_end' => $ver[2], 'program_id' => $program, 'content' => $content);
		
		
	}	
	
	
	endif;
	


echo json_encode($array);

?>