<?php

if(!isset($_COOKIE['BeenBefore'])) {
    $FirstVisit = "Yes";
	
	$cookiename = "BeenBefore";
	$cookievalue = "Yes";
	setcookie($cookiename, $cookievalue ,time()+(365*86400));
} else {
    $FirstVisit = "No";	
}

$rnd = rand(1, 10000);

include $_SERVER['DOCUMENT_ROOT'] . '/SQL/dbconnect.php';

$Presenters = mysqli_query($mysqli_master, "SELECT * from `live-Presenters`");
$PresRundown = mysqli_query($mysqli_master, "SELECT * from `live-OtherPres`");
$Rolodex = mysqli_query($mysqli_master, "SELECT * from `live-Rolodex`");

if (isset($_GET['Name'])) {
    $PresenterName = $_GET['Name'];
}
else {
    $PresenterName = 'chat-admin';
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>A1Radio Presenters<?php if ($PresenterName != 'chat-admin') { echo ' - ' . $_GET['Name']; }?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="format-detection" content="telephone=no" />
<meta name="apple-mobile-web-app-title" content="A1Radio.co.uk">
<meta name="application-name" content="A1Radio.co.uk">

<meta property="og:site_name" content="A1Radio" />
<meta property="og:url" content="https://www.a1radio.co.uk/presenterpage.php<?php if ($PresenterName != 'chat-admin') { echo '?Name=' . rawurlencode($_GET['Name']); }?>" />
<meta property="og:title" content="Listen to <?php if ($PresenterName != 'chat-admin') { echo $_GET['Name'] . 'on ';} ?> A1Radio" />
<meta property="og:image" content="https://www.a1radio.co.uk/img/pres/<?php echo ($PresenterName != 'chat-admin' ? 'facebook/' . rawurlencode($_GET['Name']) : 'thumb/-nobody'); ?>.png" />
<meta property="og:image:width" content="225" />
<meta property="og:image:height" content="225" />
<meta property="og:description" content="Join us for some great music <?php if ($PresenterName != 'chat-admin') { echo 'with ' . $_GET['Name']; } ?> on A1Radio.  Online, Anytime!" />
<meta property="og:type" content="website" />

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@A1OnlineAnytime" />
<meta name="twitter:title" content="Listen to <?php if ($PresenterName != 'chat-admin') { echo $_GET['Name'] . 'on ';} ?> on A1Radio" />
<meta name="twitter:description" content="Great music: Online, Anytime" />
<meta name="twitter:image" content="https://www.a1radio.co.uk/img/pres/<?php echo ($PresenterName != 'chat-admin' ? 'twitter/' . rawurlencode($_GET['Name']) : 'thumb/-nobody'); ?>.png" />
<meta name="twitter:url" content="https://www.a1radio.co.uk" />

<meta name="author" content="Gary Woodward" />
<meta name="description" content="A1Radio is an Internet Radio station broadcasting from Peterborough in the UK.  We broadcast 24/7 with live shows throughout the week, and you can interact with us on our Facebook page and online chatroom.  Online, Anytime!" />
<meta name="keywords" content="A1Radio, A1 Radio, A1, Internet Radio, Requests, Request Show, Peterborough, <?php 
while($row = $Presenters->fetch_assoc()) { echo $row['OnAirName'] . ', '; }
?>Radio Broadcasting, Online Anytime" />
<meta name="author" content="Gary Woodward" />
<meta name="robots" content="ALL" />
<meta name="revisit-after" content="7 days" />

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=<?php echo $rnd?>">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png?v=<?php echo $rnd?>" media="(prefers-color-scheme: light)">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png?v=<?php echo $rnd?>" media="(prefers-color-scheme: light)">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32-d.png?v=<?php echo $rnd?>" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16-d.png?v=<?php echo $rnd?>" media="(prefers-color-scheme: dark)">
<link rel="manifest" href="/site.webmanifest?v=<?php echo $rnd?>">
<link rel="mask-icon" href="/safari-pinned-tab.svgv=<?php echo $rnd?>" color="#992929">
<link rel="shortcut icon" href="/favicon.ico?v=<?php echo $rnd?>">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#992929">

<link rel="stylesheet" href="font-awesome/css/all.css?v=<?php echo $rnd?>">
<link rel="stylesheet" href="css/style.css?v=<?php echo $rnd?>">
<link rel="stylesheet" href="css/presenterpage.css?v=<?php echo $rnd?>">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="js/standard.js?v=<?php echo $rnd?>"></script>
<script src="js/jquery.cookie.js?v=<?php echo $rnd?>"></script>
<script src="js/clock/moment.js"></script>
<script src="js/clock/moment-timezone-with-data.js"></script>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XZ3ZM0E91J"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XZ3ZM0E91J');
</script>

<!-- PushAlert -->
<script type="text/javascript">
        (function(d, t) {
                var g = d.createElement(t),
                s = d.getElementsByTagName(t)[0];
                g.src = "https://cdn.pushalert.co/integrate_c8632531b3345197b77ebde948adeae8.js";
                s.parentNode.insertBefore(g, s);
        }(document, "script"));
</script>
<!-- End PushAlert -->
</head>
<body>
        <nav aria-label="Main Menu">
        <?php include('img/BigLogo.svg'); ?>
        <div id="fluff">
            <div id="slogan"></div>
            <div class="tod-clock">--- -- ---<br /><strong>--:----</strong></div>
        </div>  
        <div id="actuallinks" role="region" aria-label="Links">
            <a class="home" href="/">HOME</a>
            <!-- <a class="news" href="/news">NEWS</a> -->
            <a class="about" href="/aboutus">ABOUT US</a>
            <a class="sched" href="/schedule">SCHEDULE</a>
            <a class="pres" href="/presenters">PRESENTERS</a>
            <a class="chat" href="/chat">CHAT</a>
            <a class="cont" href="/contact">CONTACT US</a>
            <a class="links" href="/links">LINKS</a>
        </div>
        <div id="sociallinks">
            <a class="social" href="https://www.facebook.com/OnlineAnytime" aria-label="A1Radio Facebook Page (External Link)">
                <picture>
                <source media="(prefers-color-scheme: dark)" srcset="img/social/dark_Facebook.svg">
                <img class="social" src="img/social/Facebook.svg" alt="Facebook Logo" title="Like Our Facebook Page"></picture></a>
            <a class="social" href="https://www.twitter.com/A1OnlineAnytime/" aria-label="A1Radio X Page (External Link)">
                <picture>
                    <source media="(prefers-color-scheme: dark)" srcset="img/social/dark_Twitter.svg">
                    <img class="social" src="img/social/Twitter.svg" alt="Twitter/X Logo" title="Follow Us On Twitter/X: @A1OnlineAnytime"></picture></a>
            <a class="social" href="https://bsky.app/profile/a1radio.bsky.social/" aria-label="A1Radio Bluesky Page (External Link)">
                <picture>
                    <source media="(prefers-color-scheme: dark)" srcset="img/social/dark_Bluesky.svg">
                    <img class="social" src="img/social/Bluesky.svg" alt="Bluesky Logo" title="Follow Us On Bluesky: a1radio.bsky.social"></picture></a>
        </div>
</nav>
<header>
		<div id="flipper">
        <ul class="flipper anim">
        <?php
                $a = 0;

                if ($Rolodex->num_rows == 0) {
                    echo '<li style="display: flex"><i class="fa fa-thumbs-up fa-lg fa-pull-left"></i>HELLO<br />Welcome To <strong>A1Radio</strong></li>';
                }
                else {
                    while ($row = $Rolodex->fetch_assoc()) {
                        echo '<li ' . ($a == 0 ? 'style="display: flex"' : 'style="display: none"') . '>' . $row['icon'] . '<span>'. $row['TextLine1'] . '<br />' . $row['TextLine2'] . '</span></li>' . "\n";

                        $a++;
                    }
                }
            ?>
        </ul>
		</div>
        <button class="menu">MENU</button>
        <button class="listen">LISTEN</button>
        <button class="requests">REQUEST</button>
        <button class="sms">SMS</button>
    </header>
    <main>
<?php

if ($PresenterName == 'chat-admin') {
    echo '<h1>Who are you looking for?</h1>';
    echo "No presenter was selected. Please check your URL.";
    goto endbit;
}

$FirstName = substr($PresenterName,0,strpos($PresenterName, " ",0));
$PresenterImage = "img/pres/bio/" .  $PresenterName . ".png";

	if (file_exists($PresenterImage)) {
		echo '<img class="float" src="img/pres/bio/' . rawurlencode($PresenterName) . '.png" alt="Photo of ' . $PresenterName . '" title="Photo of ' . $PresenterName . '" />';
	}

$query3 = mysqli_stmt_init($mysqli_master);
mysqli_stmt_prepare($query3, "SELECT `a`.`ActualShowTitle`, `a`.`ActualPresenter`,
                            IF((`a`.`ActualStartTime`<UNIX_TIMESTAMP(now())) AND (`a`.`ActualEndTime`>UNIX_TIMESTAMP(NOW())), 'YES', 'NO') as IsItOnNow, CONCAT(DATE_FORMAT(FROM_UNIXTIME(`a`.`ActualStartTime`), '%a %D %b'), ' at ', LOWER(DATE_FORMAT(FROM_UNIXTIME(`a`.`ActualStartTime`), '%l:%i%p'))) as OnAirString
                                FROM `Merged Timetable` a
                                INNER JOIN (SELECT OnAirName FROM tblPresenters WHERE OnAirName=? OR PresenterName LIKE ?) AS b ON `a`.`ActualPresenter` = `b`.`OnAirName`
                                WHERE `a`.`ActualEndTime`>UNIX_TIMESTAMP(NOW()) AND (`a`.`ActualShowType` NOT IN ('A', 'R'))
                                ORDER BY `a`.`ActualStartTime` ASC LIMIT 5;");

$PNPCT = '%' . $PresenterName . '%';
mysqli_stmt_bind_param($query3, "ss", $PresenterName, $PNPCT);
mysqli_stmt_execute($query3);
$query3r = mysqli_stmt_get_result($query3);

$query3a = mysqli_stmt_init($mysqli_master);
mysqli_stmt_prepare($query3a, "SELECT EmailAddress, FacebookPage, TwitterHandle, Bio FROM tblPresenters WHERE OnAirName=? LIMIT 1");

mysqli_stmt_bind_param($query3a, "s", $PresenterName);
mysqli_stmt_execute($query3a);
$PresInfo = mysqli_stmt_get_result($query3a);

mysqli_close($mysqli_master);

echo '<h1>' . strtoupper($PresenterName) . "\n";

if ($PresInfo->num_rows > 0) {

	while($Infos = $PresInfo->fetch_assoc()) {
        if ($Infos['EmailAddress'] != "") {
            echo '<a href="mailto:' . $Infos['EmailAddress'] . '?Subject=A1Radio%20Contact" aria-label="E-Mail ' . $PresenterName . '"><i class="link fa fa-envelope" title="E-Mail This Presenter"></i></a> ' . "\n";
        }
        if($Infos['FacebookPage'] != "") {
            echo '<a href="' . $Infos['FacebookPage'] . '"><i class="link fab fa-facebook-square" title="Facebook Page"></i></a> ' . "\n";
        }
	    if($Infos['TwitterHandle'] != "") {
		    echo '<a href="https://www.twitter.com/' . $Infos['TwitterHandle'] . '"><i class="link fab fa-square-x-twitter" title="Twitter Page"></i></a>' . "\n";
	    }

        $ThisIsBio = $Infos['Bio'];
	}
	
	echo '</h1>' . "\n";
        
	if ($query3r->num_rows != 0) {
	    echo '<ul class="shows">';	

    	while($ShowInfo = $query3r->fetch_assoc()) { 		
            if ($ShowInfo['IsItOnNow'] == "YES") {
                echo '<li class="onnow"><span class="now">&nbsp;ON NOW!&nbsp;</span>' . $ShowInfo['ActualShowTitle'] . '</li>';	
            }
            else {
                echo '<li>' . $ShowInfo['ActualShowTitle'] . " - " . $ShowInfo['OnAirString'] . "</li>\n";
            }
	    }
	
	echo '</ul>';
	}

		if (!is_null($ThisIsBio)) {
            echo $ThisIsBio;
        }
		else {
            echo '<p>Please check back soon for more information!</p>';
        }
}
else {
	echo '</h1><p>No information is currently available for this presenter.</p>';
}

endbit:
        
echo '<div class="other-block">Other Presenters:<ul id="theothers">';

	while ($pres = $PresRundown->fetch_assoc()) {
		if ($pres['OnAirName'] != urldecode($PresenterName)) {
		$OtherPresenterImage = "img/pres/thumb/" .  $pres['OnAirName'] . ".png";

	        if (file_exists($OtherPresenterImage)) {
                $ImageName = $pres['OnAirName'];
	 	    }
		    else {
			    $ImageName = "_Blank";
		    }
		
		echo '<a href="/presenterpage.php?Name=' . urlencode($pres['OnAirName']) . '"><li class="otherpres" data-name="' . $pres['OnAirName'] . '">
		<img class="photo" src="img/pres/thumb/' . $ImageName . '.png" alt="Photo of ' . $pres['OnAirName'] . '" title="' . $pres['OnAirName'] . '">
		</li></a>';
		}
	}
echo '</ul></div>';

?></main>

<nav id="mobilemenu" aria-label="Mobile Menu">
    <i class="close fa-solid fa-square-xmark"></i>
    <section class="links off" aria-label="Mobile Links">
    <div class="heading" role="region" aria-label="Mobile Links">MENU</div>
        <div class="content">
            <a class="home" href="/">HOME</a>
            <!-- <a class="news" href="/news">NEWS</a> -->
            <a class="about" href="/aboutus">ABOUT US</a>
            <a class="sched" href="/schedule">SCHEDULE</a>
            <a class="pres" href="/presenters">PRESENTERS</a>
            <a class="chat" href="/chat">CHAT</a>
            <a class="cont" href="/contact">CONTACT US</a>
            <a class="links" href="/links">LINKS</a>
            <span style="--ao: 9">
            <a class="social" href="https://www.facebook.com/OnlineAnytime" aria-label="A1Radio Facebook Page (External Link)">
                    <picture>
                    <source media="(prefers-color-scheme: dark)" srcset="img/social/dark_Facebook.svg">
                    <img class="social" src="img/social/Facebook.svg" alt="Facebook Logo" title="Like Our Facebook Page"></picture></a>
                <a class="social" href="https://www.twitter.com/A1OnlineAnytime/" aria-label="A1Radio X Page (External Link)">
                    <picture>
                        <source media="(prefers-color-scheme: dark)" srcset="img/social/dark_Twitter.svg">
                        <img class="social" src="img/social/Twitter.svg" alt="Twitter/X Logo" title="Follow Us On Twitter/X: @A1OnlineAnytime"></picture></a>
                <a class="social" href="https://bsky.app/profile/a1radio.bsky.social/" aria-label="A1Radio Bluesky Page (External Link)">
                    <picture>
                    <source media="(prefers-color-scheme: dark)" srcset="img/social/dark_Bluesky.svg">
                    <img class="social" src="img/social/Bluesky.svg" alt="Bluesky Logo" title="Follow Us On Bluesky: a1radio.bsky.social"></picture></a>
                </span>
        </div>
    </section>
    <section class="streams off" aria-label="Mobile Stream Links">
        <div class="heading">STREAMS</div>
        <div class="content">
            <a class="mob" target="_blank" onclick="window.open('ListenLive.php?Res=Sp','targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=245`); return false;"><strong>SUPER HD</strong>320kbps AAC+</a>
            <a class="mob" target="_blank" onclick="window.open('ListenLive.php?Res=Hi','targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=245`); return false;"><strong>HIGH</strong>192kbps AAC+</a>
            <a class="mob" target="_blank" onclick="window.open('ListenLive.php?Res=Lo','targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=245`); return false;"><strong>LOW</strong>96kbps AAC+</a>
            <span class="lic"><img src="img/licence/PRS.svg" title="PRS Logo" alt="PRS Licenced" /><img src="img/licence/PPL.svg" title="PPL Logo" alt="PPL Licenced" /></span>
        </div>
    </section>
</nav>
<footer>
    <div id="listens">
    <img src="img/licence/PRS.svg" title="PRS Logo" alt="PRS Licenced" /><img src="img/licence/PPL.svg" title="PPL Logo" alt="PPL Licenced" /><span class="tunein">TUNE IN</span>
        <button onclick="window.open('ListenLive.php?Res=Sp','targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=245`); return false;" aria-label="SUPER 320kbps"><strong>SHD</strong>320kbps</button>
        <button onclick="window.open('ListenLive.php?Res=Hi','targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=245`); return false;" aria-label="HIGH 320kbps"><strong>HIGH</strong>192kbps</button>
        <button onclick="window.open('ListenLive.php?Res=Lo','targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=245`); return false;" aria-label="LOW 96kbps"><strong>LOW</strong>96kbps</button>
    </div>
    <div id="requests" data-display="0">
        <button id="launchreq" class="X" aria-label="REQUEST A SONG">
            REQUEST<br />A<br />SONG
        </button>
        <button id="launchlist" class="X" aria-label="VIEW REQUEST LIST">
            VIEW<br />REQUEST<br />LIST 
        </button>
    </div>
    <div id="nowandnext" data-display="first">
        <span id="shownow"><ul></ul></span>
        <span id="shownext"><ul></ul></span>
    </div>
    <div id="presenternow">
    </div>
    <span id="visit">▲ Visit Profile</span>
</footer>
<dialog class="req">
    <div class="select">
        <div class="tab-group">
            <input id="tab1" name="tab" value="Request" type="radio" onclick="ChangeDialog('Ask')" />
            <label for="tab1">
                Make A Request
            </label>
        </div>
        <div class="tab-group">
            <input id="tab2" name="tab" value="List" type="radio" onclick="ChangeDialog('Show')" />
            <label for="tab2">
                View Requests
            </label>
        </div>
    </div>
    <div class="ph"></div>
</dialog>
</body>
</html>