<?php

/**************************************************************************/
/* PHP-NUKE: Internet TV Block/Module                                     */
/* =====================================                                  */
/*                                                                        */
/* Copyright (c) 2003 by René Hart (webmaster@just4me.nl)                 */
/* http://www.just4me.nl                                                  */
/*                                                                        */
/* 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
$tv_width = 150;

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

if (eregi("block-Internet_TV.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}
// general 
global $prefix, $dbi, $currentlang, $TVFloatCookie, $tv, $name; 

$tv = $_POST['tvselect'];
$PHP_SELF = $_SERVER['PHP_SELF'];

// block settings
$result = sql_query("SELECT modulename, auto_start, picture, picture_dir, defpicture, nopicture_name, pop_block FROM ".$prefix."_internet_tv_settings", $dbi);
  list($modulename, $auto_start, $picture, $picture_dir, $defpicture, $nopicture_name, $pop_block) = 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");}

//tv station selection
if ($tv == 0){
$result=mysql_query("SELECT tv_id, tv_name, tv_stream, tv_url, tv_picture FROM ".$prefix."_internet_tv WHERE tv_language='$language' OR tv_language=''", $dbi);
$num=mysql_numrows($result);
if ($num == 1){
list($tv_id, $tv_name, $tv_stream, $tv_url, $tv_picture) = sql_fetch_row($result, $dbi);
$stream = $tv_stream;
if ($tv_url !="" AND $tv_url != "http://"){
$url = $tv_url;}
$stationname = $tv_name;
$tvstart = $autostart;
$tv = $tv_id;}
else {
	$stationname = ""._INTVNOC."";}
}else {
$result = sql_query("SELECT tv_name, tv_stream, tv_url, tv_picture FROM ".$prefix."_internet_tv WHERE tv_id='$tv'", $dbi);
list($tv_name, $tv_stream, $tv_url, $tv_picture) = sql_fetch_row($result, $dbi);
$stream = $tv_stream;
if ($tv_url !="" AND $tv_url != "http://"){
$url = $tv_url;}
$stationname = $tv_name;
$tvstart = "true";
}

// function to check for real player files
function checkreal($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 = $tv_picture;
if ($picture == 1 and ($picture_name =="" and $defpicture == 1))
 {$picture_name = $nopicture_name;}


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

elseif($name == $module_name)
 { $content = "<center>"._INTVDIS2."</center>";} 

else {

if ($url !=""){
$content = "<center>"._INTVSEL.":<br> <a HREF=$url target=\"_blank\">$stationname</a><br><br>";
}
else {
$content = "<center>"._INTVSEL.":<br> $stationname</a><br><br>";
}

if (checkreal($stream) == true)

{$content .= "
<OBJECT	ID=player	CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
	HEIGHT=146 WIDTH='$tv_width'>
	<PARAM NAME='controls' VALUE='ImageWindow,Controlpanel'>
	<PARAM NAME='console' VALUE='Clip1'>
	<PARAM NAME='autostart' VALUE=$tvstart>
	<PARAM NAME='src' VALUE='$stream'>
	<EMBED SRC='$stream' type='audio/x-pn-realaudio-plugin' CONSOLE='Clip1' CONTROLS='ImageWindow,ControlPanel' 
HEIGHT=146 WIDTH=$tv_width AUTOSTART=$tvstart pluginspage='http://www.real.com/'></EMBED> 

<noembed><a href='$stream'>Play $stationname</a></noembed>
	</OBJECT><br><br>";
}

else

{$content .= "
<OBJECT ID='Player' HEIGHT='151' WIDTH='$tv_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='false'>
   <PARAM NAME='Autostart' VALUE='$tvstart'>
   <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='$tv_width'
	height='151'
	AutoStart='$tvstart'
	showcontrols='$ShowControls' showstatusbar='$ShowStatusBar' showdisplay='$ShowDisplay'>
	</EMBED>
<noembed><a href='$stream'>Play $stationname</a></noembed>
	</OBJECT><br><br>";
}
if ($num != 1){
$content .= "<form name=\"form\" method=\"post\" action=\"\">";
$content .= "<select name=\"tvselect\" onchange=\"form.submit()\">";
$content .= "<option>- "._INTVCHO." -</option>";
$result = sql_query("SELECT tv_id, tv_name FROM ".$prefix."_internet_tv WHERE tv_language='$language' OR tv_language='' ORDER BY tv_name ASC", $dbi);
while(list($tv_id, $tv_name) = sql_fetch_row($result, $dbi)) {
$content .= "<OPTION VALUE=\"$tv_id\">$tv_name</option>";}
$content .= "</select></form>";
}

if(!$tv){}
else
{
$content .= "<a href=\"javascript:launch('modules.php?name=$module_name&file=popup$pop_block&tv=$tv&num=$num')\">"._INTVFLO."</A>";}
$content .= "</center>";
}
?>