<!--{template 'head'}-->
<script language='javascript'>
function gs(t)
{
	var url,t ;
	url = "plugin.php?plugin=str_replace";
	AJAX.request( url,{
		method		: 'post',
		parameters  : 'type=ajax&tablename='+t,
		onComplete	: function(json)
		{
			var json = evaljson(json);
			BuildSel(json,$('f'));
		}
	});
}
function BuildSel(json,sel)
{
	sel.options.length=0;
	sel.options.add(new Option( "-----请选择-----",""));
	for(var i=0;i<json.length;i++)
	{
		sel.options.add(new Option(json[i],json[i]));
	}
}
var numTotal = 0;
function replaceData(){
	Form.send('myform', function(resp){
		var json = evaljson(resp);
		if(json.status == 200){
			numTotal += json.success;
			if(json.more){
				qmeCms.dialogView.form("替换", "<p class='padding'>已成功替换"+numTotal+"条数据，我们将继续...</p>", {width:400,type:'fixed'});
				$('p').value = parseInt($('p').value) + 1;
				return setTimeout(replaceData, 1000);
			}else{
				numTotal = 0;
				qmeCms.dialogView.form("替换", "<p class='padding'>操作完成，共替换"+numTotal+"条数据</p>", {width:400,type:'fixed'});
				$('p').value = 1;
				$('submit_btn').disabled = false;
			}
		}else{
			alert("不能对所选数据表操作");
			$('submit_btn').disabled = false;
		}
	});
}
function check()
{
	if(document.myform.tables.value=='0')
	{
		alert('请选择数据表');
		return false ;
	}
	if(document.myform.f.value=='0')
	{
		alert('请选择字段');
		return false ;
	}
	if(document.myform.search.value=='')
	{
		alert('请填写要替换的字符串');
		return false ;
	}
	$('p').value = 1;
	$('submit_btn').disabled = true;
	qmeCms.dialogView.form("替换", "<p class='loading'>操作中，请等待...</p>", {width:400,type:'fixed'});
	replaceData();
	return false ;
}
</script>
<style type="text/css">
.tableborder td{padding:4px 5px}
</style>
<table cellpadding="2" cellspacing="1" class="tableborder">
	<tr bgColor='#F1F3F5'>
		<td>
			此功能直接操作数据库，请谨慎
		</td>
	</tr>
</table>

<form name="myform" id="myform" method="post" action="plugin.php?plugin=str_replace" onsubmit="return check();">

<table cellpadding="2" cellspacing="1" class="tableborder">
	<tr>
		<th colspan=2>字符替换工具</th>
	</tr>
	<tr bgColor='#F1F3F5'>
		<td class=tablerowr width="30%">选择数据表与字段</td>
		<td>
			<input type="hidden" name="str_replace" value="ok">
			<select name="tables" onChange="gs(this.value);">
			<option value='0'>------请选择------</option>
			<!--{loop $lists $table}-->
			<option value='{$table}'>{$table}</option>
			<!--{/loop}-->
			</select>
			<select name="f" id="f">
			<option value=''>------请选择------</option>
			</select>
		</td>
	</tr>
	<tr bgColor='#F1F3F5'>
		<td class=tablerowr>要替换的内容</td>
		<td><input name='search' id='search' type='text' size='30' class="f-text"  /></td>
	</tr>
	<tr bgColor='#F1F3F5'>
		<td  class=tablerowr>被替换成为</td>
		<td><input name='replace' type='text' size='30' class="f-text" ></td>
	</tr>
	<tr bgColor='#F1F3F5'>
		<td  class=tablerowr>替换条件</td>
		<td><input name='condition' type='text' size='50' class="f-text" > 请输入sql语句，留空则替该数据表换所有内容<br><font color=red>(eg:绿色部分<font color=green>cid=5</font> 或者 <font color=green>cid=5 and channelid=2 </font>)</font></td>
	</tr>
	<tr align="center" bgColor='#F1F3F5'>
		<td colspan=2  class=tablerowl>
			<input type="hidden" name="p" id="p" value="1" />
			<input type="submit" name="submit" id="submit_btn" value=" 开始替换字符 " class="f-button" >
		</td>
	</tr>
</table>
</form>
<!--{template 'foot'}-->
