<?php
//  ------------------------------------------------------------------------ //
// 本模組由 tad 製作
// 製作日期：2008-02-28
// $Id: tad_play_list.php,v 1.2 2008/05/14 01:22:58 tad Exp $
// ------------------------------------------------------------------------- //
define("_TAD_PLAYER_UPLOAD_URL",XOOPS_URL."/uploads/tad_player/");
define("_TAD_PLAYER_FLV_URL",XOOPS_URL."/uploads/tad_player/flv/");
define("_TAD_PLAYER_IMG_URL",XOOPS_URL."/uploads/tad_player/img/");

//區塊主函式 (影音播放器區塊1說明)
function tad_player_play_list($options){
	global $xoopsDB;
	
  $width=$options[1];
	$height=$options[2]+$options[4]+20;
	$all_width=$width;
	$all_height=$height;
  $media=_TAD_PLAYER_UPLOAD_URL."{$options[0]}_list.xml";
  
  if(empty($file['image'])){
    $image=XOOPS_URL."/modules/tad_player/images/no_pic.png";
	}elseif(substr($file['image'],0,4)=="http"){
    $image=$file['image'];
	}else{
    $image=_TAD_PLAYER_IMG_URL.$file['image'];
	}
	
	
  $pic="s1.addVariable('image','{$image}');";
  $width_js="s1.addVariable('width','{$width}');
	s1.addVariable('displaywidth','{$width}');";
  $height_js="s1.addVariable('height','{$height}');
	s1.addVariable('displayheight','{$options[2]}');";
  $autoplay=($options[3]==1)?"true":"false";

	$block="
	<script type='text/javascript' src='".XOOPS_URL."/modules/tad_player/class/jw_player/swfobject.js'></script>
<div id='tad_play_list_block_container{$options[0]}'>this will be replaced by the SWF.</div>
<script type='text/javascript'>
	var s1 = new SWFObject('"._TAD_PLAYER_UPLOAD_URL."mediaplayer.swf','mediaplayer','{$all_width}','{$all_height}','6');
	s1.addParam('allowfullscreen','true');
	{$width_js}
	{$height_js}
	s1.addVariable('file','{$media}');
	{$pic}
	s1.addVariable('backcolor','0x000000');
	s1.addVariable('frontcolor','0xFFFFFF');
	s1.addVariable('lightcolor','0xFFFF00');
	s1.addVariable('screencolor','0xFCFCFC');
	s1.addVariable('rotatetime','60');
	s1.addVariable('overstretch','fit');
	s1.addVariable('showicons','true');
	s1.addVariable('shownavigation','true');
	s1.addVariable('showstop','false');
	s1.addVariable('showdigits','total');
	s1.addVariable('usefullscreen','true');
	s1.addVariable('autostart','{$autoplay}');
	s1.addVariable('repeat','{$options[5]}');

	s1.write('tad_play_list_block_container{$options[0]}');
</script>";
	return $block;
}

//區塊編輯函式
function tad_player_play_list_edit($options){
	global $xoopsDB;
	$select=tp_block_cate_select($options[0]);

  $chked3_1=($options[3]=='1')?"checked":"";
  $chked3_0=($options[3]=='0')?"checked":"";
	$chked5_0=($options[5]=="false")?"checked":"";
	$chked5_1=($options[5]=="true")?"checked":"";

	$form="
	"._MB_TADPLAYER_TAD_PLAYER_EDIT_BITEM0."<br>
	$select<br>
	"._MB_TADPLAYER_DISPLAY_WIDTH."
	<INPUT type='text' name='options[1]' value='{$options[1]}'><br>
	"._MB_TADPLAYER_DISPLAY_HEIGHT."
	<INPUT type='text' name='options[2]' value='{$options[2]}'><br>
	
	"._MB_TADPLAYER_TAD_PLAYER_EDIT_BITEM3."
	<INPUT type='radio' $chked3_1 name='options[3]' value='1'>"._MB_TADPLAYER_AUTOPLAY."
	<INPUT type='radio' $chked3_0 name='options[3]' value='0'>"._MB_TADPLAYER_DONT_AUTOPLAY."<br>
	"._MB_TADPLAYER_LIST_HEIGHT."<INPUT type='text' name='options[4]' value='{$options[4]}'><br>
	"._MB_TADPLAYER_TAD_PLAYER_EDIT_BITEM4."
	<INPUT type='radio' $chked5_1 name='options[5]' value='true'>"._MB_TADPLAYER_LIST_REPEAT."
	<INPUT type='radio' $chked5_0 name='options[5]' value='false'>"._MB_TADPLAYER_DONT_REPEAT."

	";
	return $form;
}



//分類選單
function tp_block_cate_select($pcsn=0){
	$cate_select=tp_block_get_tad_player_cate_option(0,0,$pcsn);
	$select="<select name='options[0]' size='6'>
	$cate_select
	</select>";

	return $select;
}


//取得分類下拉選單
function tp_block_get_tad_player_cate_option($of_csn=0,$level=0,$v="",$show_dot='1',$optgroup=true,$chk_view='1'){
	global $xoopsDB;
	$dot=($show_dot=='1')?str_repeat(_MB_TADPLAYER_BLANK,$level):"";
	$level+=1;

	$sql = "select count(*),pcsn from ".$xoopsDB->prefix("tad_player")." group by pcsn";
	$result = $xoopsDB->query($sql);
	while(list($count,$pcsn)=$xoopsDB->fetchRow($result)){
	  $cate_count[$pcsn]=$count;
	}

	$option=($of_csn)?"":"<option value='0'>"._MB_TADPLAYER_CATE_SELECT."</option>";
	$sql = "select pcsn,title from ".$xoopsDB->prefix("tad_player_cate")." where of_csn='{$of_csn}' order by sort";
	$result = $xoopsDB->query($sql);

	while(list($pcsn,$title)=$xoopsDB->fetchRow($result)){

		$selected=($v==$pcsn)?"selected":"";
	  if(empty($cate_count[$pcsn]) and $optgroup){
			$option.="<optgroup label='{$title}' style='font-style: normal;color:black;'>".tp_block_get_tad_player_cate_option($pcsn,$level,$v,"0")."</optgroup>";
		}else{
		  $counter=(empty($cate_count[$pcsn]))?0:$cate_count[$pcsn];
      $option.="<option value='{$pcsn}' $selected >{$dot}{$title} ($counter)</option>";
      $option.=tp_block_get_tad_player_cate_option($pcsn,$level,$v);
		}



	}
	return $option;
}

?>
