<?php
//banner雪片动画效果
$random = rand(0,1000);
if(file_exists('banner.swf'))
{
	$doc = new DOMDocument();
	$doc->load("Banner_Content_3.xml");
	$node_lists = $doc->getElementsByTagName('Content');
	$node  = $node_lists->item(0);
	$width  = $node->getAttribute('TheBannerWidth');
 	$height  = $node->getAttribute('TheBannerHeight');
	$pic_html = <<<pic
<div id="show_logo">
<embed src="banner.swf?$random" quality="high" wmode="transparent" bgcolor="#000000" width="$width" height="$height" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
<div style="text-align:left;margin-top:12px;">宽*高 {$width}px*{$height}px</div>
</div>
pic;
}
else
{
	$pic_html = <<<pic
<div style="display:none;" id="show_logo"><img id="show_img" src=""/></div>
pic;
}

$file_list = scandir('upload/banner');
$i = 0;
$upload_file = '';
foreach($file_list as $k => $v)
{
	if($v == '.' || $v == '..' || $v == '.svn')
	{
		continue;
	}
	else
	{
		$i++;
		$ext_name = substr($v,-3);
		$p = strlen($v)-strlen($ext_name)-1;
		$file_name = substr($v,0,$p);
		if($i % 3 == 0)
		{
			$upload_file .= "<input onclick='noPopup();' type='radio' value='$v' name='BackgroundImage' id='$file_name'><img style='width:160px;height:50px;' src='upload/banner/$v'/>&nbsp;&nbsp;&nbsp;<br>";
		}
		else
		{
			$upload_file .= "<input onclick='noPopup();' type='radio' value='$v' name='BackgroundImage' id='$file_name'><img style='width:160px;height:50px;' src='upload/banner/$v'/>&nbsp;&nbsp;&nbsp;&nbsp;";
		}
	}
}


$js = <<<js
<link rel="stylesheet" href="css/colorpicker.css" type="text/css" />
<link rel="stylesheet" href="../../script/thickbox.css" type="text/css" />
<script type="text/javascript" src="../../script/colorpicker.js"></script>
<script type="text/javascript" src="../../script/helper.js"></script>
<script type="text/javascript" src="../../script/thickbox.js"></script>
<script type="text/javascript">
var count = 2;
var clickNum = 2;
var flag = "false";
function add_text()
{
	if(clickNum < 11 && count < 21)
	{
		$('tbody').append('<tr id="a'+count+'"><td style="width:70px">第'+count+'帧文字：</td><td><input value="输入文字..." maxlength="25" type="text" id="text_'+count+'" name="text_'+count+'"/>&nbsp;&nbsp;字号：<input style="width:24px;" maxlength="3" onkeyup="validate($(this).val(),$(this));" type="text" id="font_size_'+count+'" name="font_size_'+count+'" value="32"/>像素&nbsp;&nbsp;颜色：<input style="width:50px;" onkeyup="$(this).attr(\'value\',\'\');" onclick="showColor(\'color_'+count+'\');"  type="text" id="color_'+count+'" name="color_'+count+'" value="#05f6af"/>&nbsp;&nbsp;水平对齐：<select id="falign_'+count+'"><option value="left">左对齐</option><option value="right">右对齐</option><option value="center">居中</option></select>&nbsp;&nbsp;<input type="button" value="删除动画帧" title="删除此帧" onclick="$(\'#a'+count+'\').remove();clickNum--;"></td></tr>');
		count++;
		clickNum++;
	}
}

function showColor(src)
{
	$('#'+src).ColorPicker({
		onSubmit: function(hsb, hex, rgb, el) {
			colorValue = '#'+hex;
    		$(el).val(colorValue);
    		$(el).ColorPickerHide();
		},
		onBeforeShow: function () {
    		$(this).ColorPickerSetColor(this.value);
    	}
	}).bind('keyup', function(){
    	$(this).ColorPickerSetColor(this.value);
    });
}

function validate(oNum,obj)
{
	if(!oNum)
	{ 
		obj.attr('value','');
		return false; 
	}
  	var strP=/^\d+(\.\d+)?$/; 
  	if(!strP.test(oNum)) 
  	{
		obj.attr('value',''); 
		return false; 
	}
  	try
  	{ 
  		if(parseFloat(oNum)!=oNum)
		{
			obj.attr('value','');
  			return false;
  		}
  	} 
  	catch(ex) 
  	{ 
  	 	obj.attr('value','');
  		return false;
  	} 
  	return true; 
}

function ajaxSend()
{
	var str;
	var i;
	str = "id=snowSwf&BackgroundImage="+$(':radio:checked').attr('value')+"&maxCellsize="+$('#maxCellsize').attr('value')+"&NumberOfCells="+$('#NumberOfCells').attr('value')+"&CellsDirection="+$('#CellsDirection').attr('value')+"&CellsSpeed="+$('#CellsSpeed').attr('value')+"&";
	for(i = 1;i < 21;i++)
	{
		if($('#a'+i).attr('id'))
		{
			if($('#text_'+i).val() == '')
			{
				alert('请填写第'+i+'帧文字');
				flag = "true";
				break;
			}
			else if(!$('#text_'+i).val())
			{
				
			}
			else
			{
				str += "text_"+i+"="+$('#text_'+i).val()+"&font_size_"+i+"="+$('#font_size_'+i).val()+"&color_"+i+"="+$('#color_'+i).val()+"&falign_"+i+"="+$('#falign_'+i).val()+"&";
			}
		}
	}
	str += "a=2";
	
	if(flag == "false")
	{
		$.ajax({
		   type: "POST",
		   url: "server.php",
		   data: str,
		   beforeSend:function(msg){
		   		$("#show_logo").css('display','block');
		   		$("#show_img").remove();
				$("#show_logo").append("<img id='show_img' src='images/loadingAnimation.gif'/>");
			},
		   success: function(msg){
				window.location.reload();
	   	   },
	   	   error: function(msg){
	   	   	 	alert(msg);
	   	   }
		});
	}
	else
	{
		flag = "false";
	}
}
function noPopup()
{
	$.ajax({
		   type: "POST",
		   url: "server.php",
		   data: "id=noPopup",
		   success:function(msg){
		   		//TODO
		   },
	   	   error: function(msg){
	   	   	 	alert(msg);
	   	   }
		});
}
$(document).ready(function(){
	noPopup();
});
</script>
js;

$html = <<<html
<div style="text-align:left;font-size:18px;font-family:'microsoft yahei';color:#006ec6;">Banner雪片动画</div>
<div class="tabstyle"></div>
<div class="divSettings">
 <table cellspacing="5">
     <tbody><tr>
        <td width="15%">Banner：</td>
        <td>
			<input onclick="noPopup();" type="radio" checked="checked" value="banner001" name="BackgroundImage" id="banner001"><img style="width:160px;height:50px;" src="images/banner001.jpg"/>&nbsp;&nbsp;&nbsp;
			<input onclick="noPopup();" type="radio" value="banner002" name="BackgroundImage" id="banner002"><img style="width:160px;height:50px;" src="images/banner002.jpg"/>&nbsp;&nbsp;&nbsp;
			<input onclick="noPopup();" type="radio" value="banner003" name="BackgroundImage" id="banner003"><img style="width:160px;height:50px;" src="images/banner003.jpg"/>&nbsp;&nbsp;&nbsp;<br>
			<input onclick="noPopup();" type="radio" value="banner004" name="BackgroundImage" id="banner004"><img style="width:160px;height:50px;" src="images/banner004.jpg"/>&nbsp;&nbsp;&nbsp;
			<input onclick="noPopup();" type="radio" value="banner005" name="BackgroundImage" id="banner005"><img style="width:160px;height:50px;" src="images/banner005.jpg"/>&nbsp;&nbsp;&nbsp;
			<input onclick="noPopup();" type="radio" value="banner006" name="BackgroundImage" id="banner006"><img style="width:160px;height:50px;" src="images/banner006.jpg"/>&nbsp;&nbsp;&nbsp;<br>
			<input onclick="noPopup();" type="radio" value="banner007" name="BackgroundImage" id="banner007"><img style="width:160px;height:50px;" src="images/banner007.jpg"/>&nbsp;&nbsp;&nbsp;
			<input onclick="noPopup();" type="radio" value="banner008" name="BackgroundImage" id="banner008"><img style="width:160px;height:50px;" src="images/banner008.jpg"/>&nbsp;&nbsp;&nbsp;
			<input onclick="noPopup();" type="radio" value="banner009" name="BackgroundImage" id="banner009"><img style="width:160px;height:50px;" src="images/banner009.jpg"/>&nbsp;&nbsp;&nbsp;<br>
			$upload_file
			<input type="button" value="更多"  onclick="show_iframe_win('snowPopup.php?page=1', '', 732, 303);"/><br><form enctype="multipart/form-data" action="server.php" method="post">添加自定义图片：<input type="file" name="custom_pic"/><input type="hidden" name="id" value="snowUpload"/><input type="submit" value="上传"/></form>
        </td>
     </tr>
     <tr>
        <td>雪片粗度：</td>
        <td>
         <select style="width: 120px;" id="maxCellsize" name="maxCellsize">
			<option value="18">极大</option>
			<option value="15">大</option>
			<option value="11" selected="selected">中（默认）</option>
			<option value="8">小</option>
			<option value="5">极小</option>
		</select> &nbsp;&nbsp;
                         雪片数目:&nbsp;
         <select style="width: 120px;" id="NumberOfCells" name="NumberOfCells">
			<option value="300">极多</option>
			<option value="200">多</option>
			<option value="100" selected="selected">中（默认）</option>
			<option value="65">少</option>
			<option value="30">极少</option>
		</select> 
        </td>
     </tr>
     
     <tr>
     	<td>移动方向：</td>
     	<td>
			<select name="CellsDirection" id="CellsDirection" style="width:155px;">
				<option value="MoveDown">从上到下</option>
				<option selected="selected" value="MoveUp">从下到上</option>
				<option value="MoveLeft">从右到左</option>
				<option value="MoveRight">从左到右</option>
			</select>&nbsp;&nbsp;
                         雪片速度:&nbsp;
         <select style="width: 120px;" id="CellsSpeed" name="CellsSpeed">
			<option value="10">极快</option>
			<option value="8">快</option>
			<option value="6" selected="selected">一般（默认）</option>
			<option value="4">慢</option>
			<option value="2">极慢</option>
		</select> 
     	
     	</td>
     </tr>
    <tr id="a1">
    	<td style="width:70px">第1帧文字：</td>
    	<td><input maxlength="20" type="text" id="text_1" name="text_1"/>&nbsp;&nbsp;字号：<input style="width:25px;" maxlength="3" onkeyup="validate($(this).attr('value'),$(this));" type="text" id="font_size_1" name="font_size_1" value="32"/>像素&nbsp;&nbsp;颜色：<input style="width:50px;" onkeyup="$(this).attr('value','');" onclick="showColor('color_1');"  type="text" id="color_1" name="color_1" value="#05f6af"/>&nbsp;&nbsp;水平对齐：<select id="falign_1"><option value="left">左对齐</option><option value="right">右对齐</option><option value="center">居中</option></select>&nbsp;&nbsp;<input onclick="add_text();" title="增加动画帧" type="button" value="增加动画帧" id="add"></td>
    </tr>
 </tbody>
 <tfoot>
 	<tr>
     	<td style="width:70px"></td>
        <td>
        	<input onclick="ajaxSend();" type="button" value="创建我的Banner >>" id="banner_button" style="width:244px;" />&nbsp;&nbsp;可能需要花费您一段时间，处理时请耐心等候。
        </td>
    </tr>
 </tfoot>
 </table>
</div>
$pic_html
html;
?>