<?php
//Banner图片轮播
//唯一一个生成结果不放在output文件夹中
$banner_message = simplexml_load_file('SitestarMaker.xml');
$width = empty($banner_message->rotatebanner->width) ? 600 : $banner_message->rotatebanner->width;
$height = empty($banner_message->rotatebanner->height) ? 300 : $banner_message->rotatebanner->height;

$js = <<<js
<script type="text/javascript">
var count = 2;
var clickNum = 2;
function add_pic()
{
	if(clickNum > 10 || count > 20)
	{
		alert("不能再添加了！");
	}
	else
	{
		$('tbody').append('<tr id="a'+count+'"><td valign="top" nowrap width="10%"><span>第'+count+'帧图片:</span></td><td width="90%"><div class="tdstyle"><input id="pic'+count+'" name="pic'+count+'" type="file" style="width:195px;"/>&nbsp;&nbsp;字幕标题:<input type="text" id="pic_heading'+count+'" name="pic_heading'+count+'" maxlength="20"/>&nbsp;&nbsp;<input type="button" onclick="remove_pic(\''+count+'\');" value="删除帧"/></div></td></tr><tr id="b'+count+'"><td valign="top" nowrap width="10%"><span>字幕文本:</span></td><td width="90%"><div class="tdstyle"><input type="text" id="pic_paragraph'+count+'" name="pic_paragraph'+count+'" maxlength="20"/>&nbsp;&nbsp;链接:&nbsp;http://<input type="text" id="pic_link'+count+'" name="pic_link'+count+'" maxlength="20"/></div></td></tr><tr id="c'+count+'"><td colspan="2" style="border-bottom:1px solid #c4c5c5;color:#c4c5c5;font-size:10px;">分割线</td></tr>');
		count++;
		clickNum++;
	}
}

function remove_pic(src)
{
	clickNum--;
	$("#a"+src).remove();
	$("#b"+src).remove();
	$("#c"+src).remove();
}

function bannerSubmit()
{
	var i;
	for(i = 1;i < 21;i++)
	{
		if($('#pic'+i).val() == '')
		{
			alert("第"+i+"帧没有选择图片");
			return false;
		}
		else
		{
			var filepath = $('#pic'+i).val();
			var re = /(\\+)/g; 
			var filename=filepath.replace(re,"#");
			var one=filename.split("#");
			var two=one[one.length-1];
			var three=two.split(".");
			var last=three[three.length-1];
			last=last.toLowerCase();
			if(!(last == 'gif' || last == 'png' || last == 'jpg'))
			{
				alert("不支持此图片格式");
				return false;
			}
		}
	}
}

</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 style="text-align:left;position:relative;left:50px;"><font color="red">*</font>&nbsp;<font style="color:#c4c5c5;font-size:12px;">上传的图片长宽都相同会达到最好的效果,否则较大图片会被截取。上传图片文件名最好请不要用中文。</font></div>
<div class="divsettings">
	<form enctype="multipart/form-data" action="server.php" method="post" onsubmit="javascript:return bannerSubmit();">
	<table cellspacing="10" cellpadding="5" width="100%" border="0">
		<tbody>
			<tr>
				<td valign="top" nowrap width="10%"><span>自动播放:</span></td>
				<td width="90%">
					<div class="tdstyle">
                    	<input type="radio" checked="checked" value="auto" name="play" id="auto">自动播放
                    	<input type="radio" value="manual" name="play" id="manual">手动播放
                    </div>
				</td>
			</td>
			<tr id="a1">
				<td valign="top" nowrap width="10%"><span>第1帧图片:</span><input type="hidden" name="id" value="rotateBanner"/></td>
				<td width="90%">
					<div class="tdstyle">
                    	<input id="pic1" name="pic1" type="file" style="width:195px;"/>&nbsp;&nbsp;字幕标题:<input type="text" id="pic_heading1" name="pic_heading1" maxlength="20"/>&nbsp;&nbsp;<input type="button" id="add_pic1" onclick="add_pic();" value="添加帧"/>
                    </div>
				</td>
			</tr>
			<tr id="b1">
				<td valign="top" nowrap width="10%"><span>字幕文本:</span></td>
				<td width="90%">
					<div class="tdstyle">
                    	<input type="text" id="pic_paragraph1" name="pic_paragraph1" maxlength="20"/>&nbsp;&nbsp;链接:&nbsp;http://<input type="text" id="pic_link1" name="pic_link1" maxlength="20"/>
                    </div>
				</td>
			</tr>
			<tr id="c1">
				<td colspan="2" style="border-bottom:1px solid #c4c5c5;color:#c4c5c5;font-size:10px;">分割线</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td></td>
				<td class="tdstyle"><input type="submit" value="创建我的Banner >>" style="width:244px;" /></td>
			</tr>
		</tfoot>
	</table>
	</form>
</div>
<IFRAME name="cwin" border=0 marginWidth=0 marginHeight=0 src="cu3er/index.php" frameBorder=no width=$width scrolling=no height=$height></IFRAME>
<div style="text-align:left;margin-top:12px;">宽*高 {$width}px*{$height}px</div> 
html;
?>