<?
	require_once("admin__check.php");

	// 获取或设置参数
	$job=trim($job);
	$id=floor(trim($id));

	// 已提交表单 (添加|改变状态)
	if($check=="ok"){	

		if($job==""){
			$flag="error";
			show_msg("错误：未知操作！","-1");
		}
		else{
			if($job=="add" and (strlen($name)<2 or strlen($name)>6) ){
				$flag="error";
				show_msg("错误：标签的长度为2～6个字符！","-1");
			}
			else{
				if($id<>""){
					$ids=array($id);
				}
				else{
					$ids=split(",",$ids);
				}
			}
		}

		if($flag<>"error"){
			$name=trim($name);
			$level=floor(trim($level));
			$status=floor(trim($status));
			if($status==2){
				$level=$level>=3?$level:3;
			}
			switch($job){
				case "add":	
					// 添加内容
					$sql="select * from ".TBL_PAGE_TAG." where name='".$name."' ";
					$result=mysql_query($sql);
					if(mysql_num_rows($result)<=0){
						$sql="insert into ".TBL_PAGE_TAG."(name,level,status) values('".$name."',".$level.",".$status.") ";
						mysql_query($sql);
					}
					else{
						$sql="update ".TBL_PAGE_TAG." set level=".$level." , status=".$status." where name='".$name."' ";	
						mysql_query($sql);
					}
					break;
				case "change":
					// 更改状态
					foreach($ids as $id){
						$sql="update ".TBL_PAGE_TAG." set level=".$level." , status=".$status." where id=".$id;	
						mysql_query($sql);	
					}
					break;
			}

			if(mysql_error()<>""){
				show_msg("数据库操作出错，请联系客服！");			
			}
			else{
				show_msg("数据更新成功！","-1");
			}

		}

	}
?>