<?php
//$ip_header = substr($_SERVER['REMOTE_ADDR'],0,strlen('192.168'));
// if($ip_header!='192.168' && $ip_header!='127.0.0'){
// 	exit('ip error');
// }
error_reporting(E_ALL& ~E_NOTICE);
@session_start();
if($_SESSION['php_auth_user_doc'] != true && isset($_SERVER['PHP_AUTH_USER'])){
	if(isset($_SESSION['php_auth_user_doc'])){
		$_SESSION['php_auth_user_doc'] = false;
		unset($_SESSION['php_auth_user_doc']);
	}
	$user = md5($_SERVER['PHP_AUTH_USER']);
	$pass = md5($_SERVER['PHP_AUTH_PW']);
	if($user == md5('gsp.admin') && $pass == md5('123456')){
		$_SESSION['php_auth_user_doc'] = true;
	}
}
if (!isset($_SESSION['php_auth_user_doc']) || $_SESSION['php_auth_user_doc'] != true) {
	header('WWW-Authenticate: Basic realm="Guansheng Group Doc"');
	header('HTTP/1.0 401 Unauthorized');
	echo '登录失败';
	exit;
}
include('config.php');
include('fc.php');

function writeArray($arr,&$back,$key,$tag){
	if($key!='') $key.='.';
	foreach($arr as $k=>$v){
		if(is_array($v) || is_object($v)){
			if(!$_POST['ishow0'] && is_numeric($k)){
				$k='';
			}
			writeArray($v,$back,$key.$k,$tag);
		}else{
			$v = replacechar($v);
			$back[] = sprintf('$data["%s"][]=["key"=>"%s%s","example"=>"%s","must"=>1,"type"=>"string","name"=>""];'."\r\n",$tag,$key,$k,$v);
		}
	}
}

$path = './interface';

if($_POST['action'] && $_POST['dir']!=''){
	$contents = "<?php\r\n";
	$action = $_POST['action'];
	$function = $_POST['function'];
	$file = $_POST['file'];
	$req = $_POST['req'];
	$rep = $_POST['rep'];
	unset($_POST['action']);
	unset($_POST['file']);
	unset($_POST['req']);
	unset($_POST['rep']);
	foreach($_POST as $k=>$v){
		$v = str_replace("'","\'",$v);
		$contents.= '$data["'.$k.'"]='."'".$v."'".';'."\r\n";
	}
	$request=[];
	$reponse=[];
	if($action=='add'){
		if($function=='') exit('方法名不能为空');
		$file = $function;
		$jsonArr = json_decode($_POST['reponse_json'], JSON_OBJECT_AS_ARRAY);
		writeArray($jsonArr['data'],$reponse,'','reponse');
		if(count($jsonArr)==0) exit('成功返回的json格式错误');

		$jsonArr = json_decode($_POST['request_json'], JSON_OBJECT_AS_ARRAY);
		writeArray($jsonArr,$request,'','request');
	}else{
		if($req){
			foreach($req as $k=>$v){
				if(trim($v['key'])!=''){
					$v['example'] = replacechar($v['example']);
					$request[] = sprintf('$data["request"][]=["key"=>"%s","example"=>"%s","must"=>"%s","type"=>"%s","name"=>"%s"];'."\r\n",$v['key'],$v['example'],$v['must'],$v['type'],$v['name']);
				}
			}
		}
		if($rep){
			foreach($rep as $k=>$v){
				if(trim($v['key'])!=''){
					$v['example'] = replacechar($v['example']);
					$reponse[] = sprintf('$data["reponse"][]=["key"=>"%s","example"=>"%s","must"=>"%s","type"=>"%s","name"=>"%s"];'."\r\n",$v['key'],$v['example'],$v['must'],$v['type'],$v['name']);
				}
			}
		}
	}
	foreach($request as $v){
		$contents.= $v;
	}
	foreach($reponse as $v){
		$contents.= $v;
	}
	$contents.= 'return $data;';
	file_put_contents($path.'/'.$_POST['dir'].'/'.$file.'.php',$contents);
	header(sprintf('Location:?action=edit&dir=%s&file=%s',$_POST['dir'],$file));
}
$dirs = scanMain($path);
$list = include($path.'/list.php');
if(isset($_GET['dir']) && $_GET['dir']!=''){
	$files = scanSub($path.'/'.$_GET['dir']);
}
if(isset($_GET['action']) && $_GET['action']=='add'){
	$doc = getDoc($path.'/example.php');

}else if(isset($_GET['dir']) && $_GET['dir']!='' && $_GET['file']!=''){
	$file = $path.'/'.$_GET['dir'].'/'.$_GET['file'].'.php';
	$doc = getDoc($file);
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>接口文档</title>
<!--自适应声明部分-->
<meta name="applicable-device" content="pc" />
<style type="text/css">
a {font-size:16px;color: #06b;text-decoration:none;}
a:hover{color: blue;}
.book-summary{float:left;min-width:300px;width:15%;margin-right:12px;border-right: 1px solid #ccc;border-bottom: 1px solid #ccc}
.book-body{float:left;width:80%;max-width:1000px}

.book-summary ul li {
    /*list-style: none;*/
}
.book-summary ul li a{
    display: block;
    padding: 2px 2px;
    border-bottom: none;
    color: #495057;
    background: 0 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
}
.book-summary ul li a:hover{
	color: blue;
}
.book-summary ul .active,.book-summary ul .active a{
	color:#900;
	background-color: #f7f7f7;
}
.book h1 {
    font-size: 20px !important;
}
.book h4, .book h5, .book h6 {
    margin-top: 1.275em;
    margin-bottom: .85em;
    font-weight: 700;
}
blockquote {
    padding: 10px 15px;
    background:
    #f7f7f7;
	margin: 0;
    margin-bottom: 0px;
	margin-bottom: .85em;
	padding: 0 15px;
	color:#858585;
	border-left: 4px solid #e5e5e5;
}
code,pre {
    font-family: "SourceCodePro","PingFangSC-Regular", "sans-serif", "Hiragino Sans GB", "Microsoft YaHei","WenQuanYi Micro Hei";
	padding: .2em;
	margin: 0;
	background-color: #f7f7f7;
	font-size: .85em;
}
pre code{
	font-size: 12px !important;
}
table {
    display: table;
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    overflow: auto;
}
table tr {
    background-color: #fff;
	border-top: 1px solid #ccc;
}
table th {
    font-weight: 400;
    background: #eee;
}
table td, table th {
    padding: 6px 13px;
    border: 1px solid #ddd;
    word-break: break-all;
	font-size:14px;
	text-align:left;
}

pre {
    overflow: auto;
    word-wrap: normal;
    margin: 0;
    margin-bottom: 0px;
    padding: .85em 1em;
    margin-bottom: 1.275em;
    background: #f7f7f7;
    border-radius: 3px;
    word-break: break-word;
    max-height: 600px;
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
    border-radius: 5px;
}
pre.help{max-height:100%;}

textarea{font-size:12px;width:100%;}
input{font-size:12px;width:100%;padding:5px}
.trgroup{background-color: #eeeefa;}
</style>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="./fc.js"></script>
<script>
var reqCount=<?php echo (isset($doc['request']) && count($doc['request'])) ? count($doc['request']) : 0;?>;
var repCount=<?php echo (isset($doc['reponse']) && count($doc['reponse'])) ? count($doc['reponse']) : 0;?>;
var add_tr = function(obj){
	$tbody = $('.'+obj);
	if(obj=='request'){
		tag='req';
		idx = reqCount;
		reqCount++;
	}else{
		tag='rep';
		idx = repCount;
		repCount++;
	}
	if(tag=='req'){
		$tbody.append('<tr><td><input value="" name="'+tag+'['+idx+'][key]"></td><td><input value="" name="'+tag+'['+idx+'][name]"></td><td><input value="" name="'+tag+'['+idx+'][example]"></td><td><input value="1" name="'+tag+'['+idx+'][must]"></td><td><input value="string" name="'+tag+'['+idx+'][type]"></td></tr>');
	}else{
		$tbody.append('<tr><td><input value="" name="'+tag+'['+idx+'][key]"></td><td><input value="" name="'+tag+'['+idx+'][name]"></td><td><input value="" name="'+tag+'['+idx+'][example]"></td><td><input value="string" name="'+tag+'['+idx+'][type]"></td></tr>');
	}
};
var checking = function(){
	var request_json = $('#request_json').val();
	var reponse_json = $('#reponse_json').val();
	var error_json = $('#request_json').val();
	if(request_json!=''){
		try{
			var obj = JSON.parse(request_json);
		}catch(err){
			alert('请求参数Json格式有误');
			return false;
		}
	}
	if(error_json!=''){
		try{
			var obj = JSON.parse(error_json);
		}catch(err){
			alert('错误返回Json格式有误');
			return false;
		}
	}
	try{
		var obj = JSON.parse(reponse_json);
		if(!obj.hasOwnProperty("data")){
			alert('成功返回Json格式有误,必须要有data属性');
			return false;
		}
	}catch(err){
		alert('成功返回Json格式有误');
		return false;
	}
	<?php if(isset($_GET['action']) && $_GET['action']=='add'):?>
	if(<?php echo $_GET['action']=='add';?>){
		if($('#function').val()==''){
			alert('请输入方法名');
			return false;
		}
	}
	<?php endif;?>

	if($('#url').val()==''){
		alert('请输入接口URL');
		return false;
	}
	return true;
}
</script>
</head>
<body>
<div class="book">
  	<div class="book-summary">
		<h1 onclick="window.location.href='?'" style="cursor:pointer"><?php echo INTERFACE_NAME;?></h1>
    	<div>
			<ul>
				<?php foreach($dirs as $dir):?>
				<li><a href="?<?php if(isset($_GET['action'])):?>action=edit&<?php endif;?>dir=<?php echo basename($dir);?>"><?php echo basename($dir).' <span style="font-size:12px;color:#666">('.$list[basename($dir)]['name'].')</span>';?></a>
					<?php if( $_GET['dir'] == basename($dir)):?>
					<ul>
						<?php foreach($files as $file):
						$file = str_replace('.php','',basename($file));
						?>
						<li<?php if($file==$_REQUEST['file']) echo ' class="active"';?>><a href="?<?php if(isset($_GET['action'])):?>action=edit&<?php endif;?>dir=<?php echo basename($dir);?>&file=<?php echo $file;?>"><?php echo $file;?></a></li>
						<?php endforeach;?>
					</ul>
					<?php endif;?>
				</li>
				<?php endforeach;?>
			</ul>
		</div>
  	</div>
  	<div class="book-body">
    	<div class="no-apis"></div>
    	<div class="body-inner">
<!--Begin Right-->
<?php if($doc):?>
<form method="post" action="?" name="form_doc">
	    <div class="page-wrapper hide">
	        	<div class="page-inner">
						<?php if($_GET['action']=='add'):?>
						<h1><span style="color:#900"><?php echo $_GET['dir'];?></span></h1>
						<h1>接口方法</h1>
						<input id="function" name="function" autocomplete="off" value="">
						<?php else:?>
						<h1><?php echo basename($_GET['dir']);?>/<span style="color:#900"><?php echo $_GET['file'];?></span>
						<a href="test.php?dir=<?php echo $_GET['dir'];?>&file=<?php echo $_GET['file'];?>" target="_blank" style="font-size:12px;font-weight:1;color:blue">接口测试</a>
						<?php if(IS_EDIT):?>
							<a href="?action=edit&dir=<?php echo $_GET['dir'];?>&file=<?php echo $_GET['file'];?>" style="font-size:12px;font-weight:1;color:blue">编辑</a>
							<a href="?dir=<?php echo $_GET['dir'];?>&file=<?php echo $_GET['file'];?>" style="font-size:12px;font-weight:1;color:blue">浏览</a>
						<?php endif;//IS_EDIT?>
						</h1>
						<?php endif;//add?>
						<a name="_name"></a>
						<?php if(isset($_GET['action'])):?><h1>接口名称</h1><input name="name" autocomplete="off" value="<?php echo $doc['name'];?>"><?php else:?><h1><?php echo $doc['name'];?></h1><?php endif;?>
						<?php if(isset($_GET['action'])):?>
						<a name="_remark"></a>
						<h1>接口描述</h1>
	            		<blockquote>
						<textarea autocomplete="off" name="remark" rows="<?php $tmp =count(explode("\n",$doc['remark'])); if($tmp<3) $tmp=3; echo ($tmp<50)? $tmp:50;?>"><?php echo $doc['remark'];?></textarea>
						</div>
						</blockquote>
						<?php elseif(trim($doc['remark'])!=''):?>
	            		<blockquote><pre><?php echo format($doc['remark']);?></pre></blockquote>
						<?php endif;?>
						<a name="_url"></a>
	            		<h4>接口URL</h4>
	            		<code><?php if(isset($_GET['action'])):?><input value="<?php echo $doc['url'];?>" id="url" name="url" autocomplete="off"><?php else:?><?php echo $doc['url'];?><?php endif;?></code>
                        <h4>请求方式</h4>
	            		<code><?php if(isset($_GET['action'])):?><select name="method" autocomplete="off">
							<option value="GET" <?php if($doc['method']=='GET') echo 'selected';?>>GET</option>
							<option value="POST" <?php if($doc['method']=='POST') echo 'selected="selected"';?>>POST</option>
							<option value="GET|POST" <?php if($doc['method']=='GET|POST') echo 'selected="selected"';?>>GET|POST</option>
						</select><?php else:?><?php echo $doc['method'];?><?php endif;?></code>
                        <h4>请求 Content-Type</h4>
                        <code><?php if(isset($_GET['action'])):?><input autocomplete="off" value="<?php echo ($doc['content_type']=='') ? 'application/json' : $doc['content_type'];?>" name="content_type"><?php else:?><?php echo $doc['content_type'];?><?php endif;?></code>

	            		<!-- 开始 request_header -->
						<?php if(!isset($_GET['action']) || $_GET['action']=='edit'):?>
							<?php if($doc['request'] || isset($_GET['action'])):?>
							<a name="_request"></a>
							<div class="document-block-div fixtable">
								<h4>请求参数描述</h4>
								<table id="tablesort_request">
									<thead>
										<tr>
											<th width="20%">参数</th>
											<th>参数描述</th>
											<th width="20%">示例值</th>
											<th width="8%">必填</th>
											<th width="12%">类型</th>
										</tr>
									</thead>
									<tbody class="request">
										<?php if($doc['request'])foreach($doc['request'] as $k=>$v):?>
											<?php if(isset($_GET['action'])):?>
											<tr>
												<td><input autocomplete="off" name="req[<?php echo $k;?>][key]" value="<?php echo $v['key'];?>" style="width:100%"></td>
												<td><input autocomplete="off" name="req[<?php echo $k;?>][name]" value="<?php echo $v['name'];?>" style="width:100%"></td>
												<td><input autocomplete="off" name="req[<?php echo $k;?>][example]" value="<?php echo $v['example'];?>" style="width:100%"></td>
												<td>
												<select autocomplete="off" name="req[<?php echo $k;?>][must]">
													<option value="必填">必填</option>
													<option value="可选"<?php if($v['must']=='可选') echo ' selected';?>>可选</option>
												</select>
												</td>
												<td><input autocomplete="off" name="req[<?php echo $k;?>][type]" value="<?php echo $v['type'];?>" style="width:100%"></td>
											</tr>
											<?php else:?>
												<?php if(strtoupper($v['key'])=='--GROUP--'):?>
													<tr class="trgroup">
														<td colspan="5"><?php echo format($v['name']);?></td>
													</tr>
												<?php else:?>
													<tr>
														<td><?php echo $v['key'];?></td>
														<td><?php echo format($v['name']);?></td>
														<td><?php echo $v['example'];?></td>
														<td><?php echo $v['must'];?></td>
														<td><?php echo $v['type'];?></td>
													</tr>
												<?php endif;?>
											<?php endif;?>
										<?php endforeach;?>
									</tbody>
								</table>
								<?php if(isset($_GET['action'])):?><button type="button" onclick="add_tr('request')">添加</button>
								<input type="checkbox" id="sort_request" style="width:30px" autocomplete="off" onclick="sort(this,'#tablesort_request')"><label for="sort_request">拖动</label><?php endif;?>
							</div>
							<?php endif;//if($doc['reponse'])?>
							<?php if($doc['reponse'] || isset($_GET['action'])):?>
							<a name="_reponse"></a>
							<div class="document-block-div fixtable" id='contain'>
								<h4>成功响应Data描述</h4>
								<table id='tablesort_reponse'>
									<thead>
										<tr>
											<th width="20%">参数</th>
											<th>参数描述</th>
											<th width="40%">示例值</th>
											<th width="12%">类型</th>
										</tr>
									</thead>
									<tbody class="reponse">
										<?php if($doc['reponse'])foreach($doc['reponse'] as $k=>$v):?>
											<?php if(isset($_GET['action'])):?>
											<tr>
												<td><input autocomplete="off" name="rep[<?php echo $k;?>][key]" value="<?php echo $v['key'];?>" style="width:100%"></td>
												<td><input autocomplete="off" name="rep[<?php echo $k;?>][name]" value="<?php echo $v['name'];?>" style="width:100%"></td>
												<td><input autocomplete="off" name="rep[<?php echo $k;?>][example]" value="<?php echo $v['example'];?>" style="width:100%"></td>
												<td><input autocomplete="off" name="rep[<?php echo $k;?>][type]" value="<?php echo $v['type'];?>" style="width:100%"></td>
											</tr>
											<?php else:?>
												<?php if(strtoupper($v['key'])=='--GROUP--'):?>
													<tr class="trgroup">
														<td colspan="4"><?php echo format($v['name']);?></td>
													</tr>
												<?php else:?>
													<tr>
														<td><?php echo $v['key'];?></td>
														<td><?php echo format($v['name']);?></td>
														<td><?php echo $v['example'];?></td>
														<td><?php echo $v['type'];?></td>
													</tr>
												<?php endif;?>
											<?php endif;?>
										<?php endforeach;?>
									</tbody>
								</table>
								<?php if(isset($_GET['action'])):?><button type="button" onclick="add_tr('reponse')" style="width:100px">添加</button>
								<input type="checkbox" id="sort_reponse" style="width:30px" autocomplete="off" onclick="sort(this,'#tablesort_reponse')"><label for="sort_reponse">拖动</label><?php endif;?>
							</div>
							<?php endif;//if($doc['reponse'])?>
	            		<?php endif;//if($_GET['action']=='edit')?>

	            		<!-- 开始 request_body -->
						<a name="_request_json"></a>
						<h4>请求参数JSON示例<a style="font-size:12px;padding-left:20px;color:#069" href='javascript:console.log(<?php echo json_encode(json_decode($doc['request_json']));?>)'>控制台查看</a></h4>
						<?php if(isset($_GET['action'])):?><textarea id='request_json' name='request_json'  rows="<?php $tmp =count(explode("\n",$doc['request_json'])); if($tmp<6) $tmp=6; echo ($tmp<50)? $tmp:50;?>" onpropertychange='this.style.posHeight=this.scrollHeight' id=textarea onfocus='textarea.style.posHeight=this.scrollHeight' autocomplete="off"><?php echo $doc['request_json'];?></textarea><?php else:?><pre class="language-javascript"><code class="lang-json"><script>document.write(formatJson('<?php echo json_encode(json_decode($doc['request_json']));?>'));</script><?php endif;?></code></pre>

						<!-- 开始 response_body_error_text -->
	            		<h4>失败响应JSON示例<a style="font-size:12px;padding-left:20px;color:#069" href='javascript:console.log(<?php echo json_encode(json_decode($doc['error_json']));?>)'>控制台查看</a></h4>
						<?php if(isset($_GET['action'])):?><textarea id='error_json' name='error_json' rows=6 onpropertychange='this.style.posHeight=this.scrollHeight' id=textarea onfocus='textarea.style.posHeight=this.scrollHeight' autocomplete="off"><?php echo $doc['error_json'];?></textarea><?php else:?><pre class="language-javascript"><code class="lang-json"><script>document.write(formatJson('<?php echo json_encode(json_decode($doc['error_json']));?>'));</script><?php endif;?></code></pre>

						<!-- 开始 request_Query -->

	            		<!-- 开始 response_header -->

	            		<!-- 开始 response_cookie -->

	            		<!-- 开始 response_body -->

	            		<!-- 开始 response_body_text_ishide -->
						<a name="_reponse_json"></a>
	            		<h4>成功响应JSON示例<a style="font-size:12px;padding-left:20px;color:#069" href='javascript:console.log(<?php echo json_encode(json_decode($doc['reponse_json']));?>)'>控制台查看</a></h4>
						<?php if(isset($_GET['action'])):?><textarea id='reponse_json' name='reponse_json'  rows="<?php $tmp =count(explode("\n",$doc['reponse_json'])); if($tmp<6) $tmp=6; echo ($tmp<50)? $tmp:50;?>" onpropertychange='this.style.posHeight=this.scrollHeight' id=textarea onfocus='textarea.style.posHeight=this.scrollHeight' autocomplete="off"><?php echo $doc['reponse_json'];?></textarea><?php else:?><pre class="language-javascript"><code class="lang-json"><script>document.write(formatJson('<?php echo json_encode(json_decode($doc['reponse_json']));?>'));</script><?php endif;?></code></pre>
						<?php if($_GET['action']=='add'):?>
							<div><label for="ishow0">是否显示数组中的数字键<label><input type="checkbox" id="ishow0" name="ishow0" value="1" style="width:30px"></div>
						<?php endif;?>
						<br>
						<input type="hidden" name="action" value="<?php echo $_GET['action']?>">
						<input type="hidden" name="dir" value="<?php echo $_GET['dir']?>">
						<input type="hidden" name="file" value="<?php echo $_GET['file']?>">
						<?php if(isset($_GET['action'])):?><input type="submit" value=" 提 交 " onclick="return checking();" style="font-size:18px"><?php endif;?>
						<br>
						<br>
						<br>
						<br>
						<br>
	        	</div>
	      	</div>
	    </div>
</form>
<?php elseif($_GET['dir']):?>
	<?php if(IS_EDIT || $_GET['action']):?>
	<div><a href="?action=add&dir=<?php echo $_GET['dir'];?>" style="color:blue;border: 2px solid #e5e5e5;padding:5px">添加 <?php echo $_GET['dir'];?> 接口方法</a></div>
	<?php endif; //if($_GET['action'])?>
	<h1><?php echo basename($_GET['dir']).' <span style="color:#666">('.$list[basename($_GET['dir'])]['name'].')</span>';?></h1>
	<?php
	foreach($files as $file){
		$data = include($file);
		$func = str_replace('.php','',basename($file));
		echo '<h3 style="padding-left:25px"><a href="?';
		if(isset($_GET['action'])) echo 'action=edit&';
		echo 'dir='.$_GET['dir'].'&file='.$func.'">'.$func.'<span style="font-size:14px;color:blue;font-weight:1;padding-left:10px">'.$data["name"].'</span></a></h3>';
	}
	?>
<?php else:?>
<h1>入口地址</h1>
<div><strong style="color:#999"><?php echo API_MAIN_URL;?></strong></div>
<pre class="help">
<?php if(IS_EDIT) echo file_get_contents('./help.txt');?>
</pre>
<?php endif; //$_GET['file']!=''?>
<!--End Right-->
	</div>
</div>
<!--右侧悬浮处理 BEGIN-->
<?php if($_GET['file']):?>
<style>
.tipic{
	position: fixed;
	width: 120px;
	right: 50px;
	bottom: 20px;
}
.rq{
	width: 120px;
	height: 40px;
	text-align: center;
	line-height: 40px;
	background: #eee;
	color: #000;
	font-size: 12px;
	font-weight: bold;
	margin-bottom: 1px;
}
.return_top{
	width: 105px;
	height: 36px;
	cursor: pointer;
}
.nav{overflow: hidden;display:}
.nav a{
	display: block;
	font-size: 12px;
	width: 120px;
	height: 30px;
	line-height: 30px;
	text-align: left;
	margin-bottom: 1px;
	background: #efefef;
	color: #555;
	text-decoration: none;
	padding:0 10px;
	transition:all 0.5s linear;
	-webkit-transition:all 0.5s linear;
	-moz-transition:all 0.5s linear;
	-ms-transition:all 0.5s linear;
	-o-transition:all 0.5s linear;
}
.nav a:hover{
	color: blue;
}
</style>
<div class="tipic">
	<div class="rq"><a href="#">返回顶部</a></div>
	<div class="nav">
		<a href="#_name">接口名称</a>
		<a href="#_url">接口URL</a>
		<a href="#_request">请求参数描述</a>
		<a href="#_reponse">成功响应描述</a>
		<a href="#_request_json">请求参数Json</a>
		<a href="#_reponse_json">成功响应Json</a>
		<?php if(IS_EDIT):?>
			<?php if(isset($_GET['action'])):?>
				<a href="javascript:form_doc.submit()" style="color:#009">提交保存</a>
				<a href="?dir=<?php echo $_GET['dir'];?>&file=<?php echo $_GET['file'];?>" style="font-size:12px;font-weight:1;color:#900">浏览</a>
			<?php else:?>
				<a href="?action=edit&dir=<?php echo $_GET['dir'];?>&file=<?php echo $_GET['file'];?>" style="font-size:12px;font-weight:1;color:#900">编辑</a>
			<?php endif;?>
		<?php endif;//IS_EDIT?>
		<a href="test.php?dir=<?php echo $_GET['dir'];?>&file=<?php echo $_GET['file'];?>" target="_blank" style="color:#900">接口测试</a>
	</div>
	<div class="return_top" style="display:none"></div>
</div>

<script>
$(document).ready(function(){
	$(".return_top").click(function(){
		$("html,body").animate({"scrollTop":0},1000);
	});
	$(window).scroll(function(){
		var Sctop = $(window).scrollTop();
		//Sctop>200 ? $(".nav").stop().animate({"height":408},300) && $(".return_top").show() : $(".nav").stop().animate({"height":0},300)&&$(".return_top").hide();
	});

})
</script>
<?php endif;?>
<!--右侧悬浮处理 END-->

<!--表格编辑处理 BEGIN-->
<?php if($_GET['file'] && isset($_GET['action'])):?>
<style>
.mouseOver{background:#069;}
.mouseDown{background:#690;}
</style>
<script>
$(document).ready(function(){

});
var issort = false;
function sort(that,tableTag){
	issort = $(that).is(':checked');
	tableSort(tableTag,$(tableTag).parent());
}
//表格拖动
function tableSort(tableTag,overTag)
{
	var tbody = $(tableTag+' > tbody');
	var rows = tbody.children();
	var selectedRow;
	//压下鼠标时选取行
	rows.mousedown(function(){
		if(issort){
			selectedRow = this;
			tbody.css('cursor', 'move');
			$(this).addClass('mouseDown');
			return false;	//防止拖动时选取文本内容，必须和 mousemove 一起使用
		}
	});
	rows.mousemove(function(){
		return !issort;	//防止拖动时选取文本内容，必须和 mousedown 一起使用
	});
	//释放鼠标键时进行插入
	rows.mouseup(function(){
		if(issort && selectedRow)
		{
			if(selectedRow != this)
			{
				$(this).before($(selectedRow)).removeClass('mouseOver'); //插入
			}
			$(selectedRow).removeClass('mouseDown');
			tbody.css('cursor', 'default');
			selectedRow = null;
		}
	});
	//标示当前鼠标所在位置
	rows.hover(
		function(){
			if(selectedRow && selectedRow != this)
			{
				$(this).addClass('mouseOver');	//区分大小写的，写成 'mouseover' 就不行
			}
		},
		function(){
			if(selectedRow && selectedRow != this)
			{
				$(this).removeClass('mouseOver');
			}
		}
	);

	//当用户压着鼠标键移出 tbody 时，清除 cursor 的拖动形状，以前当前选取的 selectedRow
	tbody.mouseover(function(event){
		event.stopPropagation(); //禁止 tbody 的事件传播到外层的 div 中
	});
	$(overTag).mouseover(function(event){
		if($(event.relatedTarget).parents(overTag)) //event.relatedTarget: 获取该事件发生前鼠标所在位置处的元素
		{
			tbody.css('cursor', 'default');
			selectedRow = null;
		}
	});
}
</script>
<?php endif;// file && action?>
<!--表格编辑处理 END-->
</body>
</html>
