<?php
if(!defined('MOD'))  die("access die");
$kid = intval($_GET['kid']);
$data = qdb::queryFirst("select * from ".TABLEPRE."tag where kid = '{$kid}' ");
if(empty($data)) qbase::showmsg("bad request");
if($_POST['myFormAc'] == 'update'){
	$data = array('status'=>200);
	if(intval($_POST['delete']) > 0){
		qbase::get_object('tag')->delKeyword($kid);
		qdb::query("delete from ".TABLEPRE."tag where kid = '{$kid}' ");
		adminLog("删除TAG");
	}else{
		$name = trim($_POST['name']);
		$detail = trim($_POST['detail']);
		$okid = qdb::queryAlone("select kid from ".TABLEPRE."tag where name = '{$name}' ");
		
		if($okid > 0){
			if($okid == $kid){
				qdb::query("update ".TABLEPRE."tag set detail = '{$detail}' where kid = '{$kid}' ");
			}else{
				$data = array('status'=>404, 'msg'=>'该关键词已经存在，请换一个');
			}
		}else{
			qdb::query("update ".TABLEPRE."tag set name = '{$name}', detail = '{$detail}' where kid = '{$kid}' ");
			adminLog("修改TAG");
		}
	}
	echo qbase::xmlprint(qbase::jsonencode($data));
	exit();
}
?>