<?php
!defined('EMLOG_ROOT') && exit('error');
//设置页面加载配置文件函数
function plugin_setting_view(){
    $set = Input::getStrVar('set');
	$active = Input::getStrVar('active');
	global $CACHE;?>
	<?php if(isset($_GET['succ']) && !empty($_POST)): 
		$plugin_storage = Storage::getInstance('Ixc_field');
		if($active=='menu'){
			if(isset($_POST['edit_sort'])){
				$sort = $plugin_storage->getValue('sort');
				foreach($_POST['edit_sort'] as $i => $value){
					foreach($sort as $val){
						Ixc_field_set($i,1,$val['value'],$value[$val['value']]);
					}
				}
			}
			if(isset($_POST['edit_user'])){
				$user = $plugin_storage->getValue('user');
				foreach($_POST['edit_user'] as $i => $value){
					foreach($user as $val){
						if($val['sort']==2){
							$value[$val['value']] = empty($value[$val['value']]) ? '' : ( $value[$val['value']] == '永久' ? '1' : strtotime($value[$val['value']]) );
							Ixc_field_set($i,2,$val['value'],$value[$val['value']]);
						}else{
							Ixc_field_set($i,2,$val['value'],$value[$val['value']]);
						}
						
					}
				}
			}
		}else{
			$DB = Database::getInstance();
			if(isset($_POST['article'])){
				$plugin_storage->setValue('article', array_values($_POST['article']),'array');
				foreach($_POST['article'] as $value){
					$val = 'field_'.$value['value'];
					$Ixc = $DB->num_rows($DB->query("show columns from ".DB_PREFIX."Ixc like '$val'"));
					if(isset($value['true'])){
						if($Ixc == 0)$DB->query("ALTER TABLE ".DB_PREFIX."Ixc ADD $val LONGTEXT NULL COMMENT '".$value['title']."'");
					}else{
						if($Ixc)$DB->query("ALTER TABLE ".DB_PREFIX."Ixc DROP $val");
					}
				}
				/*
				$sql = $DB->query("SHOW COLUMNS FROM ".DB_PREFIX."Ixc WHERE Field LIKE '%field_%'");
				
				foreach($_POST['article'] as $value){
					if($value['true'])
					$val = 'field_'.$value['value'];
					
				}
				while($row = $DB->fetch_array($sql)){
					echo $_POST['article'][$row['Field']].'<br>';
					echo $row['Field'].'<aaaaa>';
					
					
					//$sortid[] = $row['Field'];
				}
				*/
			}
			if(isset($_POST['sort'])){
				$plugin_storage->setValue('sort', array_values($_POST['sort']),'array');
				foreach($_POST['sort'] as $value){
					$val = 'sort_'.$value['value'];
					$Ixc = $DB->num_rows($DB->query("show columns from ".DB_PREFIX."Ixc like '$val'"));
					if(isset($value['true'])){
						if($Ixc == 0)$DB->query("ALTER TABLE ".DB_PREFIX."Ixc ADD $val LONGTEXT NULL COMMENT '".$value['title']."'");
					}else{
						if($Ixc)$DB->query("ALTER TABLE ".DB_PREFIX."Ixc DROP $val");
					}
				}
			}
			if(isset($_POST['user'])){
				$plugin_storage->setValue('user', array_values($_POST['user']),'array');
				foreach($_POST['user'] as $value){
					$val = 'user_'.$value['value'];
					$Ixc = $DB->num_rows($DB->query("show columns from ".DB_PREFIX."Ixc like '$val'"));
					if(isset($value['true'])){
						if($Ixc == 0)$DB->query("ALTER TABLE ".DB_PREFIX."Ixc ADD $val LONGTEXT NULL COMMENT '".$value['title']."'");
					}else{
						if($Ixc)$DB->query("ALTER TABLE ".DB_PREFIX."Ixc DROP $val");
					}
				}
			}
		}
		if(isset($_POST['Ixc']))$plugin_storage->setValue('Ixc',$_POST['Ixc'],'array');?>
        <div class="alert alert-success">保存成功</div>
	<?php endif; ?>
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">字段拓展</h1>
    </div>
    <ul class="nav nav-pills">
        <li class="nav-item"> <a href="plugin.php?plugin=Ixc_field" class="nav-link<?php if(empty($set))echo ' active';?>">文章字段</a></li>
        <li class="nav-item"> <a href="plugin.php?plugin=Ixc_field&set=sort" class="nav-link<?=$set=='sort'?' active':'';?>">分类字段</a></li>
        <li class="nav-item"> <a href="plugin.php?plugin=Ixc_field&set=user" class="nav-link<?=$set=='user'?' active':'';?>">用户字段</a></li>
        <li class="nav-item"> <a href="plugin.php?plugin=Ixc_field&set=Ixc" class="nav-link<?=$set=='Ixc'?' active':'';?>">插件设置</a></li>
        <li class="nav-item"> <a class="nav-link" target="_blank" href="store.php?action=plu&author_id=758">其他作品</a></li>
    </ul>
    <div class="card shadow mb-4 mt-2">
	<?php
	$plugin_storage = Storage::getInstance('Ixc_field');
	$Ixc = $plugin_storage->getValue('Ixc');
	if($set=='sort'){
		$sorts = $CACHE->readCache('sort');
		$sort = $plugin_storage->getValue('sort');
		if(!is_array($sort))$sort = [];?>
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold">分类字段操作</h6>
        </div>
		<div class="card-body">
			<ul class="nav nav-tabs">
				<li class="nav-item"> <a class="nav-link<?=$active!='menu'?' active':''?>" data-toggle="tab" href="#home">字段生成</a></li>
				<li class="nav-item"> <a class="nav-link<?=$active=='menu'?' active':''?>" data-toggle="tab" href="#menu">分类管理</a></li>
			</ul>
			<div class="tab-content">
				<div id="home" class="tab-pane<?=$active!='menu'?' active':''?>">
					<form action="plugin.php?plugin=Ixc_field&set=sort&succ=1" method="post">
						<div class="table-responsive">
							<table class="table table-bordered table-striped table-hover dataTable no-footer">
								<thead>
									<tr>
										<th>标题</th>
										<th>字段</th>
										<th>预值</th><?php if($Ixc['true']==1): ?>
										<th>实值</th><?php endif; ?><?php if($Ixc['array']==1): ?>
										<th>数组</th><?php endif; ?>
										<th>操作</th>
									</tr>
								</thead>
								<tbody id='Field'>
			<?php	foreach($sort as $i => $value){ ?>
									<tr id="Ixc_<?= $i ?>" style="cursor: move">
										<td><input type="text" name="sort[<?=$i?>][title]" class="form-control" value="<?=$value['title']?>"></td>
										<td><input type="text" name="sort[<?=$i?>][value]" class="form-control" value="<?=$value['value']?>"></td>
										<td><input type="text" name="sort[<?=$i?>][default]" class="form-control" value="<?=$value['default']?>"></td><?php if($Ixc['true']==1): ?>
										<td><input type="checkbox" name="sort[<?=$i?>][true]" value="y" class="ids" <?php if(isset($value['true']))echo 'checked';?>></td><?php endif; ?><?php if($Ixc['array']==1): ?>
										<td><input type="checkbox" name="sort[<?=$i?>][array]" value="y" class="ids" <?php if(isset($value['array']))echo 'checked';?>></td><?php endif; ?>
										<td><a href="javascript: del('Ixc_<?= $i ?>','<?php if(isset($value['true']))echo '1';?>');" class="badge badge-danger">删除</a></td>
									</tr>
			<?php 	} ?>
								</tbody>
							</table>
						</div>
						<div class="form-inline">
							<div class="btn-group btn-group-sm" role="group">
								<button type="reset" class="btn btn-sm btn-success" onclick="add()">添加</button>
								<button type="submit" class="btn btn-sm btn-primary">保存</button>
							</div>
						</div>
					</form>
					<div class="page">共有 <?= empty($i) ? 0 : $i+1 ?> 个字段</div>
				</div>
				<div id="menu" class="tab-pane<?=$active=='menu'?' active':''?>">
					<form action="plugin.php?plugin=Ixc_field&set=sort&active=menu&succ=1" method="post">
						<div class="table-responsive">
							<table class="table table-bordered table-striped table-hover">
								<thead>
								<tr>
									<th>名称</th><?php foreach($sort as $value){ ?><th><?=$value['title']?></th><?php } ?>
								</tr>
								</thead>
								<tbody>
								<?php
								foreach ($sorts as $key => $value):
									if($value['pid'] != 0)continue;
									?>
									<tr>
										<td class="sortname"><a href="sort.php?action=mod_sort&sid=<?= $value['sid'] ?>"><?= $value['sid'] ?>.<?= $value['sortname'] ?></a></td><?php foreach($sort as $val){ ?>
										<td><input type="text" name="edit_sort[<?=$value['sid']?>][<?=$val['value']?>]" class="form-control" value="<?=Ixc_sort($value['sid'],['value'=>$val['value']])?>"></td><?php } ?>
									</tr>
									<?php
									$children = $value['children'];
									foreach ($children as $key):
										$value = $sorts[$key];?>
										<tr>
											<td class="sortname">&nbsp; &nbsp;<a href="sort.php?action=mod_sort&sid=<?= $value['sid'] ?>"><?= $value['sid'] ?>.<?= $value['sortname'] ?></a></td><?php foreach($sort as $val){ ?>
											<td><input type="text" name="edit_sort[<?=$value['sid']?>][<?=$val['value']?>]" class="form-control" value="<?=Ixc_sort($value['sid'],['value'=>$val['value']])?>"></td><?php } ?>
										</tr>
									<?php endforeach ?>
								<?php endforeach ?>
								</tbody>
							</table>
						</div>
						<div class="list_footer">
							<input type="submit" value="保存" class="btn btn-sm btn-success">
						</div>
					</form>
					<div class="page">共有 <?=count($sorts)?> 个分类</div>
				</div>
				<div class="alert alert-primary">分类字段调用方法：<pre><code>&lt;?php echo Ixc_sort('分类ID',['value'=>'字段']); ?&gt;</code></pre>分类字段修改方法：<pre><code>&lt;?php echo Ixc_field_set('分类ID',1,'字段','修改的内容'); ?&gt; </code></pre></div>
			</div>
		</div>
	<script>
	var i = <?= empty($i) ? 0 : $i+1 ?>;
    $(function () {
        $('.dataTable tbody').sortable().disableSelection();
    });
	function add(){
		var html = '	<tr id=\'Ixc_'+ i +'\'>';
			html+= '								<td><input type="text" name="sort['+i+'][title]" class="form-control" value="标题"></td>';
			html+= '								<td><input type="text" name="sort['+i+'][value]" class="form-control" placeholder="字段仅支持英文、数字" ></td>';
			html+= '								<td><input type="text" name="sort['+i+'][default]" class="form-control" value=""></td>';<?php if($Ixc['true']==1): ?>
			html+= '								<td><input type="checkbox" name="sort['+i+'][true]" value="y" class="ids"></td>';<?php endif; ?><?php if($Ixc['array']==1): ?>
			html+= '								<td><input type="checkbox" name="sort['+i+'][array]" value="y" class="ids"></td>';<?php endif; ?>
			html+= '								<td><a href="javascript: del(\'Ixc_'+ i +'\');" class="badge badge-danger">删除</a></td>';
			html+= '							</tr>';
		$('#Field').append(html);
		i = i + 1;
	}
	function del(data,really=''){
		if(confirm('确定要删除吗？')){
			$('#' + data).remove();
		}
	}
	</script>
	<?php
	}elseif($set=='user'){
		$User_Model = new User_Model();
		$page = Input::getIntVar('page', 1);
		$keyword = Input::postStrVar('keyword');
		$email = $nickname = '';
		if (filter_var($keyword, FILTER_VALIDATE_EMAIL)) {
			$email = $keyword;
		} else {
			$nickname = $keyword;
		}
		$bbh = str_replace('pro ','',Option::EMLOG_VERSION);
		if($bbh >= '2.1.15'){
			$users = $User_Model->getUsers($email, $nickname, '', $page);
			$usernum = $User_Model->getUserCount($email, $nickname, '');
		}else{
			$users = $User_Model->getUsers($email, $nickname, $page);
			$usernum = $User_Model->getUserNum($email, $nickname);
		}
		$pageurl = pagination($usernum, Option::get('admin_perpage_num'), $page, "./plugin.php?plugin=Ixc_field&set=user&active=menu&page=");
		$user = $plugin_storage->getValue('user');
		if(!is_array($user))$user = [];?>
        <div class="card-header py-3">
			<div class="row justify-content-between">
				<div class="form-inline">
					<h6 class="m-2 font-weight-bold">用户字段操作</h6>
				</div>
				<form action="plugin.php?plugin=Ixc_field&set=user&active=menu" method="post">
					<div class="form-inline search-inputs-nowrap">
						<input type="text" name="keyword" value="" class="form-control m-1 small" placeholder="输入邮箱或昵称搜索...">
						<div class="input-group-append">
							<button class="btn btn-sm btn-success" type="submit">
								<i class="icofont-search-2"></i>
							</button>
						</div>
					</div>
				</form>
			</div>
        </div>
		<div class="card-body">
			<ul class="nav nav-tabs">
				<li class="nav-item"> <a class="nav-link<?=$active!='menu'?' active':''?>" data-toggle="tab" href="#home">字段生成</a></li>
				<li class="nav-item"> <a class="nav-link<?=$active=='menu'?' active':''?>" data-toggle="tab" href="#menu">用户管理</a></li>
			</ul>
			<div class="tab-content">
				<div id="home" class="tab-pane<?=$active!='menu'?' active':''?>">
					<form action="plugin.php?plugin=Ixc_field&set=user&succ=1" method="post">
						<div class="table-responsive">
							<table class="table table-bordered table-striped table-hover dataTable no-footer">
								<thead>
									<tr>
										<th>标题</th>
										<th>字段</th>
										<th>格式</th>
										<th>配置</th>
										<th>预值</th><?php if($Ixc['true']==1): ?>
										<th>实值</th><?php endif; ?><?php if($Ixc['array']==1): ?>
										<th>数组</th><?php endif; ?>
										<th>操作</th>
									</tr>
								</thead>
								<tbody id='Field'>
			<?php	foreach($user as $i => $value){ ?>
									<tr id="Ixc_<?= $i ?>" style="cursor: move">
										<td><input type="text" name="user[<?=$i?>][title]" class="form-control" value="<?=$value['title']?>"></td>
										<td><input type="text" name="user[<?=$i?>][value]" class="form-control" value="<?=$value['value']?>"></td>
										<td>
											<select name="user[<?=$i?>][sort]" class="form-control">
												<option value="0" <?php if($value['sort'] == 0)echo 'selected';?>>默认</option>
												<option value="1" <?php if($value['sort'] == 1)echo 'selected';?>>选择</option>
												<option value="2" <?php if($value['sort'] == 2)echo 'selected';?>>时间</option>
											</select>
										</td>
										<td><input type="text" name="user[<?=$i?>][other]" class="form-control" value="<?=$value['other']?>"></td>
										<td><input type="text" name="user[<?=$i?>][default]" class="form-control" value="<?=$value['default']?>"></td><?php if($Ixc['true']==1): ?>
										<td><input type="checkbox" name="user[<?=$i?>][true]" value="y" class="ids" <?php if(isset($value['true']))echo 'checked';?>></td><?php endif; ?><?php if($Ixc['array']==1): ?>
										<td><input type="checkbox" name="user[<?=$i?>][array]" value="y" class="ids" <?php if(isset($value['array']))echo 'checked';?>></td><?php endif; ?>
										<td><a href="javascript: del('Ixc_<?= $i ?>','<?php if(isset($value['true']))echo '1';?>');" class="badge badge-danger">删除</a></td>
									</tr>
			<?php 	} ?>
								</tbody>
							</table>
						</div>
						<div class="form-inline">
							<div class="btn-group btn-group-sm" role="group">
								<button type="reset" class="btn btn-sm btn-success" onclick="add()">添加</button>
								<button type="submit" class="btn btn-sm btn-primary">保存</button>
							</div>
						</div>
					</form>
					<div class="page">共有 <?= empty($i) ? 0 : $i+1 ?> 个字段</div>
				</div>
				<div id="menu" class="tab-pane<?=$active=='menu'?' active':''?>">
					<form action="plugin.php?plugin=Ixc_field&set=user&active=menu&succ=1" method="post">
						<div class="table-responsive">
							<table class="table table-bordered table-striped table-hover">
								<thead>
									<tr>
										<th></th>
										<th>用户名</th><?php foreach($user as $value){ ?><th><?=$value['title']?></th><?php } ?>
									</tr>
								</thead>
								<tbody>
								<?php
								foreach ($users as $key => $val):
									$avatar = empty($user_cache[$val['uid']]['avatar']) ? './views/images/avatar.svg' : '../' . $user_cache[$val['uid']]['avatar'];
									?>
									<tr>
										<td><img src="<?= $avatar ?>" height="35" width="35" class="rounded-circle"/></td>
										<td>
											<?php if (UID != $val['uid']): ?>
												<a href="user.php?action=edit&uid=<?= $val['uid'] ?>"><?= empty($val['name']) ? $val['login'] : $val['name'] ?></a>
											<?php else: ?>
												<a href="blogger.php"><?= empty($val['name']) ? $val['login'] : $val['name'] ?></a>
											<?php endif ?>
											<span class="small"><?= "<br/>".$val['uid'].'.'.$val['role'] ?></span>
										</td>
										<?php foreach($user as $value){
											$user_value = Ixc_user($val['uid'],['value'=>$value['value']]);
											if($value['sort']==1){ ?>
										<td>
											<select name="edit_user[<?=$val['uid']?>][<?=$value['value']?>]" class="form-control">
												<option value="0" <?php if($user_value == 0)echo 'selected';?>>默认</option>
											<?php
											$option = explode(',',$value['other']);
											foreach($option as $option_val){ 
												$option_value = explode('_',$option_val);?>
												<option value="<?= $option_value[0] ?>" <?php if($user_value == $option_value[0])echo 'selected';?>><?= $option_value[1] ?></option>
											<?php
											}
											?>
											</select>
										</td>
										<?php
											}else if($value['sort']==2){ ?>
										<td><input type="text" name="edit_user[<?=$val['uid']?>][<?= $value['value'] ?>]" class="form-control" value="<?= empty($user_value) ? '' : ( $user_value == '1' ? '永久' : date($value['other'], $user_value) ) ?>"></td>
										<?php
											}else{ ?>
										<td><input type="text" name="edit_user[<?=$val['uid']?>][<?= $value['value'] ?>]" class="form-control" value="<?= $user_value ?>"></td>
										<?php
											}
										} ?>
									</tr>
								<?php endforeach ?>
								</tbody>
							</table>
						</div>
						<div class="list_footer">
							<input type="submit" value="保存" class="btn btn-sm btn-success">
						</div>
					</form>
					<div class="text-center small">(有 <?=$usernum?> 个用户 )</div>
					<div class="page"><?= $pageurl ?></div>
				</div>
				<div class="alert alert-primary">用户字段调用方法：<pre><code>&lt;?php echo Ixc_user('用户ID',['value'=>'字段']); ?&gt;</code></pre>用户字段修改方法：<pre><code>&lt;?php echo Ixc_field_set('用户ID',2,'字段','修改的内容'); ?&gt; </code></pre></div>
			</div>
		</div>
	<script>
	var i = <?= empty($i) ? 0 : $i+1 ?>;
    $(function () {
        $('.dataTable tbody').sortable().disableSelection();
    });
	function add(){
		var html = '	<tr id=\'Ixc_'+ i +'\'>';
			html+= '								<td><input type="text" name="user['+i+'][title]" class="form-control" value="标题"></td>';
			html+= '								<td><input type="text" name="user['+i+'][value]" class="form-control" placeholder="字段仅支持英文、数字" ></td>';
			html+= '								<td>';
			html+= '									<select name="user['+i+'][sort]" class="form-control">';
			html+= '										<option value="0">默认</option>';
			html+= '										<option value="1">选择</option>';
			html+= '										<option value="2">时间</option>';
			html+= '									</select>';
			html+= '								</td>';
			html+= '								<td><input type="text" name="user['+i+'][other]" class="form-control" value=""></td>';
			html+= '								<td><input type="text" name="user['+i+'][default]" class="form-control" value=""></td>';<?php if($Ixc['true']==1): ?>
			html+= '								<td><input type="checkbox" name="user['+i+'][true]" value="y" class="ids"></td>';<?php endif; ?><?php if($Ixc['array']==1): ?>
			html+= '								<td><input type="checkbox" name="user['+i+'][array]" value="y" class="ids"></td>';<?php endif; ?>
			html+= '								<td><a href="javascript: del(\'Ixc_'+ i +'\');" class="badge badge-danger">删除</a></td>';
			html+= '							</tr>';
		$('#Field').append(html);
		i = i + 1;
		
	}
	function del(data,really=''){
		if(confirm('确定要删除吗？')){
			$('#' + data).remove();
		}
	}
	</script>
	<?php
	}elseif($set=='Ixc'){?>
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold">插件设置</h6>
        </div>
        <div class="card-body">
			<form action="plugin.php?plugin=Ixc_field&set=Ixc&succ=1" method="post">
                <div class="form-group">
                    <label>选项标题：</label>
                    <input type="text" name="Ixc[title]" class="form-control" value="<?=$Ixc['title']?>"/>
                </div>
                <div class="form-group">
                    <label>实值功能： (谨慎选择 默认关闭)</label>
                    <select name="Ixc[true]" class="form-control">
						<option value="0" <?php if($Ixc['true'] == 0)echo 'selected';?>>关闭</option>
						<option value="1" <?php if($Ixc['true'] == 1)echo 'selected';?>>开启</option>
					</select>
                </div>
                <div class="form-group">
                    <label>数组功能：</label>
                    <select name="Ixc[array]" class="form-control">
						<option value="0" <?php if($Ixc['array'] == 0)echo 'selected';?>>关闭</option>
						<option value="1" <?php if($Ixc['array'] == 1)echo 'selected';?>>开启</option>
					</select>
                </div>
				<input type="submit" class="btn btn-sm btn-primary" value="保存"/>
			</form>
        </div>
	<?php
	}else{
		$article = $plugin_storage->getValue('article');
		if(!is_array($article))$article = [];?>
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold">文章字段生成</h6>
        </div>
		<div class="card-body">
			<form action="plugin.php?plugin=Ixc_field&succ=1" method="post">
				<div class="table-responsive">
					<table class="table table-bordered table-striped table-hover dataTable no-footer">
						<thead>
							<tr>
								<th>标题</th>
								<th>字段</th>
								<th>类型</th>
								<th>配置及说明 多选例如：PHP,ZIP,APK</th>
								<th>预值</th><?php if($Ixc['true']==1): ?>
								<th>实段</th><?php endif; ?><?php if($Ixc['array']==1): ?>
								<th>数组</th><?php endif; ?>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id='Field'>
	<?php	foreach($article as $i => $value){ ?>
							<tr id="Ixc_<?= $i ?>" style="cursor: move">
								<td><input type="text" name="article[<?=$i?>][title]" class="form-control" value="<?=$value['title']?>"></td>
								<td><input type="text" name="article[<?=$i?>][value]" class="form-control" value="<?=$value['value']?>"></td>
								<td>
									<select name="article[<?=$i?>][sort]" class="form-control">
										<option value="0" <?php if($value['sort'] == 0)echo 'selected';?>>单行输入</option>
										<option value="1" <?php if($value['sort'] == 1)echo 'selected';?>>单行选择</option>
										<option value="2" <?php if($value['sort'] == 2)echo 'selected';?>>单选模式</option>
										<option value="3" <?php if($value['sort'] == 3)echo 'selected';?>>复选模式</option>
										<option value="4" <?php if($value['sort'] == 4)echo 'selected';?>>颜色选择</option>
										<option value="5" <?php if($value['sort'] == 5)echo 'selected';?>>数字输入</option>
										<option value="6" <?php if($value['sort'] == 6)echo 'selected';?>>普通文本域</option>
										<option value="7" <?php if($value['sort'] == 7)echo 'selected';?>>隐藏字段</option>
									</select>
								</td>
								<td><input type="text" name="article[<?=$i?>][other]" class="form-control" value="<?=$value['other']?>"></td>
								<td><input type="text" name="article[<?=$i?>][default]" class="form-control" value="<?=$value['default']?>"></td><?php if($Ixc['true']==1): ?>
								<td><input type="checkbox" name="article[<?=$i?>][true]" value="y" class="ids" <?php if(isset($value['true']))echo 'checked';?>></td><?php endif; ?><?php if($Ixc['array']==1): ?>
								<td><input type="checkbox" name="article[<?=$i?>][array]" value="y" class="ids" <?php if(isset($value['array']))echo 'checked';?>></td><?php endif; ?>
								<td><a href="javascript: del('Ixc_<?= $i ?>','<?php if(isset($value['true']))echo '1';?>');" class="badge badge-danger">删除</a></td>
							</tr>
	<?php 	} ?>
						</tbody>
					</table>
				</div>
				<div class="form-inline">
					<div class="btn-group btn-group-sm" role="group">
						<button type="reset" class="btn btn-sm btn-success" onclick="add()">添加</button>
						<button type="submit" class="btn btn-sm btn-primary">保存</button>
					</div>
				</div>
			</form>
			<div class="page">共有 <?= empty($i) ? 0 : $i+1 ?> 个字段</div>
			<div class="alert alert-primary">文章字段调用方法：<pre><code>&lt;?php echo Ixc_field('文章ID',['value'=>'字段']); ?&gt; </code></pre>文章字段修改方法：<pre><code>&lt;?php echo Ixc_field_set('文章ID',0,'字段','修改的内容'); ?&gt; </code></pre></div>
		</div>
	<script>
	var i = <?= empty($i) ? 0 : $i+1 ?>;
    $(function () {
        // 初始化拖动排序
        $('.dataTable tbody').sortable().disableSelection();
    });
	function add(){
		var html = '	<tr id=\'Ixc_'+ i +'\'>';
			html+= '								<td><input type="text" name="article['+i+'][title]" class="form-control" value="标题"></td>';
			html+= '								<td><input type="text" name="article['+i+'][value]" class="form-control" placeholder="字段仅支持英文、数字" ></td>';
			html+= '								<td>';
			html+= '									<select name="article['+i+'][sort]" class="form-control">';
			html+= '										<option value="0">单行输入</option>';
			html+= '										<option value="1">单行选择</option>';
			html+= '										<option value="2">单选模式</option>';
			html+= '										<option value="3">复选模式</option>';
			html+= '										<option value="4">颜色选择</option>';
			html+= '										<option value="5">数字输入</option>';
			html+= '										<option value="6">普通文本域</option>';
			html+= '										<option value="7">隐藏字段</option>';
			html+= '									</select>';
			html+= '								</td>';
			html+= '								<td><input type="text" name="article['+i+'][other]" class="form-control" value=""></td>';
			html+= '								<td><input type="text" name="article['+i+'][default]" class="form-control" value=""></td>';<?php if($Ixc['true']==1): ?>
			html+= '								<td><input type="checkbox" name="article['+i+'][true]" value="y" class="ids"></td>';<?php endif; ?><?php if($Ixc['array']==1): ?>
			html+= '								<td><input type="checkbox" name="article['+i+'][array]" value="y" class="ids"></td>';<?php endif; ?>
			html+= '								<td><a href="javascript: del(\'Ixc_'+ i +'\');" class="badge badge-danger">删除</a></td>';
			html+= '							</tr>';
			$('#Field').append(html);
		i = i + 1;
	}
	function del(data,really=''){
		if(confirm('确定要删除吗？')){
			$('#' + data).remove();
		}
	}
	</script>
	<?php	} ?>
    </div>
    <script>
        $("#menu_category_ext").addClass('active');
        $("#menu_ext").addClass('show');
    </script>
	
<?php
} ?>