<?php

/**************************************************************************/
/* XCommunity: Internet Radio Block/Module                                */
/* =====================================                                  */
/*                                                                        */
/* This program is free software. You can redistribute it and/or modify   */
/* it under the terms of the GNU General Public License as published by   */
/* the Free Software Foundation; either version 2 of the License.         */
/*                                                                        */
/**************************************************************************/


// setplayer display width change this if it doesn't fit in your template
$radio_width = 150;

//******************************************//
// DO NOT CHANGE ANYTHING ON THIS SCRIPT !! //
//       LEAVE COPYRIGHT IN PLACE           //
//******************************************//

if (eregi("block-Internet_Radio.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}
// general 
global $prefix, $dbi, $currentlang, $FloatCookie, $radio; 

$radio = $_POST['select'];
$PHP_SELF = $_SERVER['PHP_SELF'];

// block settings
$result = sql_query("SELECT modulename, auto_start, picture, picture_dir, defpicture, nopicture_name FROM ".$prefix."_internet_radio_settings", $dbi);
  list($modulename, $auto_start, $picture, $picture_dir, $defpicture, $nopicture_name) = sql_fetch_row($result, $dbi);

$module_name = $modulename;

if ($auto_start == 0) 
{$autostart = "false";}
else
{$autostart = "true";}

if (isset($currentlang)) {
        include("modules/$module_name/language/lang-$currentlang.php");
        $language = $currentlang;
} else {
    include("modules/$module_name/language/lang-$language.php");}

//radio station selection
if ($radio == 0){
$result=mysql_query("SELECT radio_id, radio_name, radio_stream, radio_url, radio_picture FROM ".$prefix."_internet_radio WHERE radio_language='$language' OR radio_language=''", $dbi);
$num=mysql_numrows($result);
if ($num == 1){
list($radio_id, $radio_name, $radio_stream, $radio_url, $radio_picture) = sql_fetch_row($result, $dbi);
$stream = $radio_stream;
if ($radio_url !="" AND $radio_url != "http://"){
$url = $radio_url;}
$stationname = $radio_name;
$radiostart = $autostart;
$radio = $radio_id;}
else {
	$stationname = ""._INRADNOC."";}
}else {
$result = sql_query("SELECT radio_name, radio_stream, radio_url, radio_picture FROM ".$prefix."_internet_radio WHERE radio_id='$radio'", $dbi);
list($radio_name, $radio_stream, $radio_url, $radio_picture) = sql_fetch_row($result, $dbi);
$stream = $radio_stream;
if ($radio_url !="" AND $radio_url != "http://"){
$url = $radio_url;}
$stationname = $radio_name;
$radiostart = "true";
}

// function to check for real player files
function check_real($t_url){

$temp_url = basename($t_url);
$temp_url = trim($temp_url);
$temp_url = strtolower($temp_url);
$check_ram = substr($temp_url, -3);
$check_rm = substr($temp_url, -2);

if ($check_rm == "rm"){
	return true;
	} elseif ($check_ram == "ram") {
			return true;
		} elseif ($check_rm == "ra") {
				return true;
			} elseif ($check_ram == "pls") {
				return true;
			 } elseif ($check_ram == "rpm") {
			 	return true;	
			  } else {
					return false;
					}
}

// script for opening window
echo "<SCRIPT LANGUAGE=\"JavaScript\">

function launch(url) {
  remote = open(url, \"\", \"width=190,height=190,left=0,top=0\");
}

</SCRIPT>";

// picture settings
$picture_name = $radio_picture;
if ($picture == 1 and ($picture_name =="" and $defpicture == 1))
 {$picture_name = $nopicture_name;}


// content to display
if(isset($FloatCookie)) 
 { $content = "<center>"._INRADDIS."</center>";} 

else {

if ($url !=""){
$content = "<center>"._INRADSEL.":<br> <a HREF=$url target=\"_blank\">$stationname</a><br><br>";
if ($picture == 1 and $picture_name != ""){
$content .= "<a href= $url target=\"_blank\"><img border=\"0\" src='$picture_dir/$picture_name'></a><br><br>";}
}
else {
$content = "<center>"._INRADSEL.":<br> $stationname</a><br><br>";
if ($picture == 1 and $picture_name != ""){
$content .= "<img border=\"0\" src='$picture_dir/$picture_name'></a><br><br>";}
}

if (check_real($stream) == true)

{$content .= "
<OBJECT	ID=player	CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
	HEIGHT=60 WIDTH='$radio_width'>
	<PARAM NAME='controls' VALUE='ControlPanel,StatusField'>
	<PARAM NAME='console' VALUE='Clip1'>
	<PARAM NAME='autostart' VALUE=$radiostart>
	<PARAM NAME='src' VALUE='$stream'>
	<EMBED SRC='$stream' type='audio/x-pn-realaudio-plugin' CONSOLE='Clip1' CONTROLS='ControlPanel,StatusField' 
HEIGHT=60 WIDTH=$radio_width AUTOSTART=$radiostart pluginspage='http://www.real.com/'></EMBED> 
              <noembed><a href='$stream'>Play $stationname</a></noembed>
	</OBJECT>";
}

else

{$content .= "
<OBJECT ID='Player' HEIGHT='50' WIDTH='$radio_width' classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112' standby='Loading Microsoft® Windows® Media Player components...'      type='application/x-oleobject'>
	 <PARAM NAME='Filename' value='$stream'>
	 <PARAM NAME='ShowControls' VALUE='true'>
   <PARAM NAME='ShowStatusBar' VALUE='true'>
   <PARAM NAME='Autostart' VALUE='$radiostart'>
   <PARAM NAME='ShowPositionControls' value='False'>
   <PARAM NAME='ShowTracker' value='False'>
	<EMBED type='application/x-mplayer2'
	pluginspage = 'http://www.microsoft.com/Windows/MediaPlayer/'
	SRC='$stream'
	name='Player'
	width='$radio_width'
	height='60'
	AutoStart='$radiostart'
	showcontrols='$ShowControls' showstatusbar='$ShowStatusBar' showdisplay='$ShowDisplay'>
	</EMBED>
<noembed><a href='$stream'>Play $stationname</a></noembed>
	</OBJECT>";
}
if ($num != 1){
$content .= "<br><br><form name=\"form\" method=\"post\" action=\"\">";
$content .= "<select name=\"select\" onchange=\"form.submit()\">";
$content .= "<option>- "._INRADCHO." -</option>";
$result = sql_query("SELECT radio_id, radio_name FROM ".$prefix."_internet_radio WHERE radio_language='$language' OR radio_language='' ORDER BY radio_name ASC", $dbi);
while(list($radio_id, $radio_name) = sql_fetch_row($result, $dbi)) {
$content .= "<OPTION VALUE=\"$radio_id\">$radio_name</option>";}
$content .= "</select></form>";
}
else
{
$content .= "<br><br>";
}

if(!$radio){$radio = 0;}
$content .= "<a href=\"javascript:launch('modules.php?name=$module_name&file=popup&radio=$radio&num=$num')\">"._INRADFLO."</A><br><br>Copyright <a HREF=\"http://www.xybersystem.com\" target=\"_blank\">XyberSYSTEM Intelligent Inc. Network</a>";
$content .= "</center>";
}
?>