<?

/**************************************************************************/
/* 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.         */
/*                                                                        */
/*                                                                        */
/**************************************************************************/

if (!eregi("admin.php", $PHP_SELF)) { die ("Access Denied"); }

$result = sql_query("select radminsuper, admlanguage from $prefix"._authors." where aid='$aid'", $dbi);
list($radminsuper) = sql_fetch_row($result, $dbi);

if ($radminsuper==1) {

function ITVdisplay() {
	global $language, $admin, $prefix, $dbi, $tvid ;
	include ('header.php');
	GraphicAdmin();
	OpenTable();
	echo ("<center><font class=\"title\"><b>Internet TV "._ADMINISTRATION."</b></font></center>");
	CloseTable();
	echo "<br>";
	OpenTable();
	  echo "<center><b>"._INTVPROG."</b></center><br>";
    $count = 0;
$idnum = 1;
    $result = sql_query("SELECT tv_id, tv_name, tv_language FROM ".$prefix."_internet_tv ORDER BY tv_name ASC", $dbi);
    while(list($tv_id, $tv_name, $tv_language) = sql_fetch_row($result, $dbi)) {
	if ($tv_language == "") {
	    $tv_language = ""._ALL."";
	}
	if ($tv_id != "") {
	    if ($count == 0) {
		echo "<table border=\"1\" width=\"100%\">";
		$count = 1;
	    }
	 echo "<tr><td><b>$idnum</b></td><td width=\"100%\">&nbsp;$tv_name&nbsp;</td><td align=\"center\">&nbsp;$tv_language&nbsp;</td><td nowrap>&nbsp;(<a href=\"admin.php?op=ITVedit&amp;tvid=$tv_id\">"._EDIT."</a>-<a href=\"admin.php?op=ITVdelete&amp;tvid=$tv_id\">"._DELETE."</a>)&nbsp;</td></tr>"; 
$idnum = $idnum + 1;
	   } }
  
    if (($tv_id == "") AND ($count == 0)) {
	echo "<center><i>"._INTVNOST."</i></center>";
    }
    if ($count == 1) {
        echo "</table>";
    }
	echo "<br><center><a href=\"admin.php?op=ITVnew\">"._INTVNEW."</a>";
  CloseTable();
  echo "<br>";
  OpenTable();
	$result = sql_query("SELECT modulename, auto_start, picture, picture_dir, defpicture, nopicture_name, tvvert, tvhor, pop_block, pop_mod FROM ".$prefix."_internet_tv_settings", $dbi);
  list($modulename, $auto_start, $picture, $picture_dir, $defpicture, $nopicture_name, $tvvert, $tvhor, $pop_block, $pop_mod) = sql_fetch_row($result, $dbi);
	echo "<center><b>"._INTVBLSET."</b></center><br>"
  ."<form action='admin.php' method='post'>"
  ."<table border='0'><tr><td>"
  .""._INTVMODNAME.":</td><td><select name='xmodulename'>";
    $handle=opendir('modules');
    while ($file = readdir($handle)) {
	if ( (!ereg("[.]",$file)) ) {
		$modulelist .= "$file ";
	}
    }
    closedir($handle);
    $modulelist = explode(" ", $modulelist);
    sort($modulelist);
    for ($i=0; $i < sizeof($modulelist); $i++) {
	if($modulelist[$i]!="") {
	  echo "<option name='xmodulename' value='$modulelist[$i]' ";
		if($modulelist[$i]==$modulename) echo "selected";
		echo ">$modulelist[$i]\n";
	}
    }
  echo "</select>"  
  ."</td></tr><tr><td>"._INTVAUTOST.":</td><td>";
  if ($auto_start==1) {
	  echo "<input type='radio' name='xautostart' value='1' checked>"._YES." &nbsp;
	  <input type='radio' name='xautostart' value='0'>"._NO."";
    } else {
	  echo "<input type='radio' name='xautostart' value='1'>"._YES." &nbsp;
	  <input type='radio' name='xautostart' value='0' checked>"._NO."";
    }
  echo "</td></tr><tr><td>"._INTVPICCHO.":</td><td>";
  if ($picture==1) {
	  echo "<input type='radio' name='xpicture' value='1' checked>"._YES." &nbsp;
	  <input type='radio' name='xpicture' value='0'>"._NO."";
    } else {
	  echo "<input type='radio' name='xpicture' value='1'>"._YES." &nbsp;
	  <input type='radio' name='xpicture' value='0' checked>"._NO."";
    }
  echo "</td></tr><tr><td>"
  .""._INTVPICDIR.":</td><td>"
	."<input type=\"text\" name=\"xpicturedir\" size=\"50\" maxlength=\"50\" value=\"$picture_dir\">"
	."</td></tr><tr><td>"._INTVPICDEF.":</td><td>";
  if ($defpicture==1) {
	  echo "<input type='radio' name='xdefpicture' value='1' checked>"._YES." &nbsp;
	  <input type='radio' name='xdefpicture' value='0'>"._NO."";
    } else {
	  echo "<input type='radio' name='xdefpicture' value='1'>"._YES." &nbsp;
	  <input type='radio' name='xdefpicture' value='0' checked>"._NO."";
    }
  echo "</td></tr><tr><td>"
  .""._INTVNOPICNAME.":</td><td>"
	."<input type=\"text\" name=\"xnopicturename\" size=\"50\" maxlength=\"50\" value=\"$nopicture_name\">"
  ."</td></tr><tr><td>"

  .""._INTVHEIGHT.":</td><td>"
	."<input type=\"text\" name=\"xtvvert\" size=\"5\" maxlength=\"3\" value=\"$tvvert\">"
	."</td></tr><tr><td>"
  .""._INTVWIDTH.":</td><td>"
	."<input type=\"text\" name=\"xtvhor\" size=\"5\" maxlength=\"3\" value=\"$tvhor\">"
  ."</td></tr><tr><td>"._INTVPOPBLOCK.":</td><td>";
  if ($pop_block==1) {
	  echo "<input type='radio' name='xpopblock' value='1' checked>"._INTVTYPE1." &nbsp;
	  <input type='radio' name='xpopblock' value='2'>"._INTVTYPE2."";
    } else {
	  echo "<input type='radio' name='xpopblock' value='1'>"._INTVTYPE1." &nbsp;
	  <input type='radio' name='xpopblock' value='2' checked>"._INTVTYPE2."";
    }
    echo"</td></tr><tr><td>"._INTVPOPMOD.":</td><td>";
  if ($pop_mod==1) {
	  echo "<input type='radio' name='xpopmod' value='1' checked>"._INTVTYPE1." &nbsp;
	  <input type='radio' name='xpopmod' value='2'>"._INTVTYPE2."";
    } else {
	  echo "<input type='radio' name='xpopmod' value='1'>"._INTVTYPE1." &nbsp;
	  <input type='radio' name='xpopmod' value='2' checked>"._INTVTYPE2."";
    }
  echo "</td></tr><tr><td><br><br>"
  ."<input type=\"hidden\" name=\"op\" value=\"ITVsettings\">"
  ."<input type=\"submit\" value=\""._SAVECHANGES."\">"
	."</tr></td></table></form>";
	CloseTable();
  include ('footer.php');
}

function ITVdelete() {
    global $prefix, $tvid, $dbi;
    sql_query("DELETE FROM ".$prefix."_internet_tv WHERE tv_id=$tvid", $dbi);
    Header("Location: admin.php?op=ITVdisplay");
}

function ITVedit() {
 global $tvid, $prefix, $dbi, $multilingual;
  include ('header.php');
	GraphicAdmin();
echo "
<script language=\"JavaScript\" type=\"text/javascript\">  
function checkform (form)
{
  if (form.tvname.value == \"\") {
  alert(\""._INTVERR1."\" );
  form.tvname.focus();
  return false ;
  }
  if (form.tvstream.value == \"http://\"){
  alert( \""._INTVERR2."\" );
  form.tvstream.focus();
  return false ;
  }
  return true ;
}
</script>";
	OpenTable();
	echo "<center><font class=\"title\"><b>Internet TV "._ADMINISTRATION."</b></font></center>";
	CloseTable();
	echo "<br>";
	$result = sql_query("SELECT tv_name, tv_stream, tv_url, tv_picture, tv_language FROM ".$prefix."_internet_tv WHERE tv_id=$tvid", $dbi);
        list($tv_name, $tv_stream, $tv_url, $tv_picture, $tv_language) = sql_fetch_row($result, $dbi);
	      OpenTable();
        echo "<center><font class=\"option\"><b>"._INTVEDIT."</b></font></center><br>";
	echo "<br><br>"
	    ."<form action=\"admin.php\" method=\"post\" onsubmit=\"return checkform(this);\">"
			."<table border='0'><tr><td>"
	    .""._INTVNAME.":</td><td>"
	    ."<input type=\"text\" name=\"tvname\" size=\"20\" maxlength=\"20\" value=\"$tv_name\">"
		  ."</td></tr><tr><td>"
	    .""._INTVSTREAM.":</td><td>"
			."<input type=\"text\" name=\"tvstream\" size=\"50\" maxlength=\"75\" value=\"$tv_stream\">"
			."</td></tr><tr><td>"
      .""._INTVURL.":</td><td>"
			."<input type=\"text\" name=\"tvurl\" size=\"50\" maxlength=\"50\" value=\"$tv_url\">"
			."&nbsp;("._OPTION.")</td></tr><tr><td>"
			.""._INTVPICT.":</td><td>"
			."<input type=\"text\" name=\"tvpicture\" size=\"50\" maxlength=\"50\" value=\"$tv_picture\">&nbsp;("._INTVPICTDIR.")"
			."</td></tr><tr><td>";
	if ($multilingual == 1) {
	    echo ""._LANGUAGE.":</td><td>"
		."<select name=\"tvlanguage\">";
	    $handle=opendir('language');
	    while ($file = readdir($handle)) {
		if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
	    	    $langFound = $matches[1];
	    	    $languageslist .= "$langFound ";
	    	}
	    }
	    closedir($handle);
	    $languageslist = explode(" ", $languageslist);
	    sort($languageslist);
	    for ($i=0; $i < sizeof($languageslist); $i++) {
	        if($languageslist[$i]!="") {
		    echo "<option name=\"tvlanguage\" value=\"$languageslist[$i]\" ";
		    if($languageslist[$i]==$tv_language) echo "selected";
		    echo ">".ucfirst($languageslist[$i])."\n</option>";
		}
	    }
	    if ($tv_language == "") {
		$sellang = "selected";
	    } else {
    		$sellang = "";
	    }
	    echo "<option value=\"\" $sellang>"._ALL."</option></select>";
	} else {
	    echo "<input type=\"hidden\" name=\"tvlanguage\" value=\"\">";
	}
	     echo "</td></tr><tr><td><br><br>"
			 ."<input type=\"hidden\" NAME=\"tvid\" size=\"50\" value=\"$tvid\">"
			 ."<input type=\"hidden\" name=\"op\" value=\"ITVchange\">"
			 ."<input type=\"submit\" value=\""._SAVECHANGES."\">"
	     ."</tr></td></table></form>";
	CloseTable();
	include ('footer.php');
  }


function ITVchange($tvid, $tvname, $tvstream, $tvurl, $tvpicture, $tvlanguage) {
 global $prefix, $dbi;
 sql_query("UPDATE ".$prefix."_internet_tv SET tv_name='$tvname', tv_stream='$tvstream', tv_url='$tvurl', tv_picture='$tvpicture', tv_language='$tvlanguage' WHERE tv_id=$tvid", $dbi);
 Header("Location: admin.php?op=ITVdisplay");
    
}

function ITVnew() {
 global $tvid, $prefix, $dbi, $multilingual;
  include ('header.php');
	GraphicAdmin();
echo "
<script language=\"JavaScript\" type=\"text/javascript\">  
function checkform (form)
{
  if (form.tvname.value == \"\") {
  alert(\""._INTVERR1."\" );
  form.tvname.focus();
  return false ;
  }
  if (form.tvstream.value == \"http://\") {
  alert( \""._INTVERR2."\" );
  form.tvstream.focus();
  return false ;
  }
  return true ;
}
</script>";
	OpenTable();
	echo "<center><font class=\"title\"><b>Internet TV "._ADMINISTRATION."</b></font></center>";
	CloseTable();
	echo "<br>";
	OpenTable();
  echo "<center><font class=\"option\"><b>"._INTVNEW."</b></font></center><br>";
	echo "<br><br>"
	    ."<form action=\"admin.php\" method=\"post\" onsubmit=\"return checkform(this);\">"
			."<table border='0'><tr><td>"
	    .""._INTVNAME.":</td><td>"
	    ."<input type=\"text\" name=\"tvname\" size=\"20\" maxlength=\"20\">"
		  ."</td></tr><tr><td>"
	    .""._INTVSTREAM.":</td><td>"
			."<input type=\"text\" name=\"tvstream\" size=\"50\" maxlength=\"75\" value=\"http://\">"
			."</td></tr><tr><td>"
      .""._INTVURL.":</td><td>"
			."<input type=\"text\" name=\"tvurl\" size=\"50\" maxlength=\"50\" value=\"http://\">"
				."&nbsp;("._OPTION.")</td></tr><tr><td>"
			.""._INTVPICT.":</td><td>"
			."<input type=\"text\" name=\"tvpicture\" size=\"50\" maxlength=\"50\" >&nbsp;("._INTVPICTDIR.")"
			."</td></tr><tr><td>";
	if ($multilingual == 1) {
	    echo ""._LANGUAGE.":</td><td>"
		."<select name=\"tvlanguage\">"
    ."<option value=\"\">"._ALL."</option>";
	    $handle=opendir('language');
	    while ($file = readdir($handle)) {
		if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
	    	    $langFound = $matches[1];
	    	    $languageslist .= "$langFound ";
	    	}
	    }
	    closedir($handle);
	    $languageslist = explode(" ", $languageslist);
	    sort($languageslist);
	    for ($i=0; $i < sizeof($languageslist); $i++) {
	        if($languageslist[$i]!="") {
		    echo "<option name=\"tvlanguage\" value=\"$languageslist[$i]\" ";
		    echo ">".ucfirst($languageslist[$i])."\n</option>";
		}
	    }
	    echo "</select>";
	} else {
	    echo "<input type=\"hidden\" name=\"tvlanguage\" value=\"\">";
	}
	     echo "</td></tr><tr><td><br><br>"
			 ."<input type=\"hidden\" name=\"op\" value=\"ITVadd\">"
			 ."<input type=\"submit\" value=\""._SAVECHANGES."\">"
	     ."</tr></td></table></form>";
	CloseTable();
	include ('footer.php');
  }



function ITVadd($tvname, $tvstream, $tvurl, $tvpicture, $tvlanguage) {
    global $prefix, $dbi;
sql_query("INSERT INTO ".$prefix."_internet_tv VALUES ('','$tvname', '$tvstream', '$tvurl', '$tvpicture', '$tvlanguage')", $dbi);
	Header("Location: admin.php?op=ITVdisplay");
    
}

function ITVsettings($xmodulename, $xautostart, $xpicture, $xpicturedir, $xdefpicture, $xnopicturename, $xtvvert, $xtvhor, $xpopblock, $xpopmod) {
 global $prefix, $dbi;
 sql_query("UPDATE ".$prefix."_internet_tv_settings SET modulename='$xmodulename', auto_start='$xautostart', picture='$xpicture', picture_dir='$xpicturedir', defpicture='$xdefpicture', nopicture_name='$xnopicturename', tvvert='$xtvvert', tvhor='$xtvhor', pop_block='$xpopblock', pop_mod='$xpopmod'", $dbi);
 Header("Location: admin.php?op=ITVdisplay");
   
}


switch($op) {

    case "ITVdisplay":
    ITVdisplay();
    break;

		case "ITVdelete":
    ITVdelete();
    break;

		case "ITVedit":
    ITVedit();
    break;

		case "ITVchange":
    ITVchange($tvid, $tvname, $tvstream, $tvurl, $tvpicture, $tvlanguage);
    break;

		case "ITVnew":
    ITVnew();
    break;

		case "ITVadd":
	  ITVadd($tvname, $tvstream, $tvurl, $tvpicture, $tvlanguage);
		break;

    case "ITVsettings":
	  ITVsettings($xmodulename, $xautostart, $xpicture, $xpicturedir, $xdefpicture, $xnopicturename, $xtvvert, $xtvhor, $xpopblock, $xpopmod);
		break;

}





} else {

    echo "Á¢±ÙÀÌ °ÅÀýµÇ¾ú½À´Ï´Ù.";
}
  
?>