<?php
if($a=="del"){
	$delid=$_GET['id'];
	unset($custom[$delid]);
	shuffle($custom);
	$shuju = json_encode($custom);
	$sql = "UPDATE `".$qz."setting` SET `custom` = '" .$shuju. "' WHERE `id` = ".$sysinfo["id"].";";
	mysql_query($sql);
	header("location:?m=custom");
	die;
}elseif($a=="add" && $_POST){
	if(!$_POST['cname']){Msg("显示名称不能为空");GoBack();die;}
	if(!$_POST['cename']){Msg("变量名不能为空");GoBack();die;}
	//判断重复变量开始
	for($temp = 0;$temp < count($custom);$temp++){
		$result = array_intersect_assoc($custom[$temp],$_POST);
		if(@$result['cename']){Msg("变量名重复");GoBack();die;}
	}
	//判断结束
	$shuju = array(
		"cname" => urlencode($_POST['cname']),
		"cename" => urlencode($_POST['cename']),
		"cvalue" => '',
		"ctype" => $_POST['ctype']
	);
	$custom[]=$shuju;
	$custom = json_encode($custom);
	$sql = "UPDATE `".$qz."setting` SET `custom` = '" .$custom. "' WHERE `id` = ".$sysinfo["id"].";";
	mysql_query($sql);
	header("location:?m=custom");
}
?>
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/think/admin">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">系统设置</span></div>
        </div>
        <div class="result-wrap">
            <form action="?m=custom&a=add" method="post" id="myform" name="myform">
                <div class="config-items">
                    <div class="config-title">
                        <span><i class="icon-font">&#xe00a;</i> 自定义变量</span>
						<span style="float:right"><a class="btn btn-primary btn6 mr10" href="javascript:;" onclick="$('#addcustom').show();">添加自定义变量</a></span><br/><br/>
                    </div>
                    <div class="result-content">
						<div id="addcustom" style="display:none">
							<table width="100%" class="insert-tab">
                            <tbody>
                                <tr>
                                    <th width="200"><i class="require-red">*</i>显示名称：</th>
                                    <td><input type="text" id="" value="" size="32" name="cname" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>变量名(英文)：</th>
                                    <td><input type="text" id="" value="" size="32" name="cename" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>变量类型：</th>
                                    <td><select name="ctype" class="common-text select1">
											<option value="text">文本变量</option>
											<option value="img">图片变量</option>
										</select></td>
                                </tr>
                                <tr>
                                    <th></th>
                                    <td>
                                        <input type="submit" value="提交" class="btn btn-primary btn6 mr10">
                                        <input type="button" value="取消" onclick="$('#addcustom').hide();" class="btn btn6">
                                    </td>
                                </tr>
                            </tbody></table><br />
						</div>
					<table class="result-tab" width="100%">
                        <tbody><tr>
                            <th width="80px">ID</th>
                            <th>显示名称</th>
							<th>变量名</th>
							<th>变量类型</th>
                            <th width="100px">操作</th>
                        </tr>
<?php
	for($temp = 0;$temp < count($custom);$temp++){
echo '						<tr>
                            <td>'.($temp+1).'</td>
                            <td>'.urldecode($custom[$temp]["cname"]).'</td>
							<td>'.urldecode($custom[$temp]["cename"]).'</td>
							<td>'.$custom[$temp]["ctype"].'</td>
                            <td><a class="link-del" href="javascript:;" onclick="del(\''.($temp).'\')"><i class="icon-font"></i> 删除</a></td>
                        </tr>';
	}
?>

                    </tbody></table>
							
                    </div>
                </div>

            </form>
        </div>
    </div>
<script type="text/javascript">
function del(id){
		if(window.confirm('确定要删除？')){
                 //("确定");
				 document.location="?m=custom&a=del&id="+id;
                 return true;
              }else{
                 //("取消");
                 return false;
         }
}
</script>