<?php
/*  
	[Phpup.Net!] (C)2009-2011 Phpup.net.
	This is NOT a freeware, use is subject to license terms
	$Id: admin.class.php 2010-08-24 10:42 $
*/

if (! defined ( 'IN_PHPUP' )) {
	exit ( 'Access Denied' );
}
class admin {
	static $filelist = array ();
	function index_action() {
		include ROOT_PATH . '/views/admin/index.php';
	}
	function login_action() {
		
		if (submitcheck ( 'commit' )) {
			$user = global_addslashes ( trim ( strip_tags ( $_POST ['username'] ) ) );
			$password = md52 ( $_POST ['password'] );
			$container = ' and username="' . $user . '" and pwd="' . $password . '" and usertype="adminuser"';
			$user_mod = new common ( 'user' );
			$userinfo = $user_mod->GetOne ( $container );
			
			if ($userinfo) {
				$adminlog_mod = new common ( 'dolog' );
				$adminlog_mod->InsertData ( array ('lastip' => real_ip (), 'lastdo' => '登陆', 'lasttime' => time (), 'username' => $userinfo ['username'], 'uid' => $userinfo ['uid'] ) );
				$GLOBALS ['session']->set ( array ('adminid' => $userinfo ['uid'], 'adminuser' => $userinfo ['username'] ) );
				
				echo '<SCRIPT LANGUAGE="JavaScript">
				<!--
					window.onload=function(){window.open("index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '","_top","")};
				//-->
				</SCRIPT>';
			} else {
				exit ( '<SCRIPT LANGUAGE="JavaScript">
				<!--
					alert("用户名或密码不正确!");
					parent.document.getElementById("user_pass").value="";
				//-->
				</SCRIPT>' );
			}
		} else {
			include ROOT_PATH . '/views/admin/login.php';
		}
	}
	function logout_action() {
		$GLOBALS ['session']->destroy ( array ('adminid' => '', 'adminuser' => '' ) );
		sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=login' );
	}
	
	function admin_action() {
		$uid = $GLOBALS ['session']->get ( 'adminid' );
		//得到个人信息
		$user_mod = new common ( 'user' );
		$userinfo = $user_mod->GetOne ( 'and uid=' . $uid, array ('uid', 'username', 'usertype' ) );
		$log_mod = new common ( 'dolog' );
		$logs = $log_mod->GetPage ( array (), 'and uid=' . $uid, 'limit 0,5', array (), 'order by id desc' );
		if (! checkfile ( 'countcache', 3600 )) {
			$count ['group'] = $this->_groupCount ();
			$count ['usercount'] = $this->_userCount ();
			$count ['sitecount'] = $this->_siteCount ();
			$count ['temp'] = $this->_tempCount ();
			write ( 'countcache', $count );
		} else {
			$count = read ( 'countcache' );
		}
		
		include ROOT_PATH . '/views/admin/adminframe.php';
	}
	//清空缓存
	function delcache_action()
	{
		$dofile=cleancache();
		if($dofile==='nowrite')
		{
			echo '<SCRIPT LANGUAGE="JavaScript">
			<!--
				parent.showDiglog("'.$GLOBALS['setting']['site_cache_dir'].'目录修改权限不足,请联系服务商");
			//-->
			</SCRIPT>';
		}
		elseif(!$dofile)
		{
			echo '<SCRIPT LANGUAGE="JavaScript">
			<!--
				parent.showDiglog("清空缓存失败,请在ftp上手动清除");
			//-->
			</SCRIPT>';
		}
		else
		{
			echo '<SCRIPT LANGUAGE="JavaScript">
			<!--
				parent.showDiglog("清空缓存成功");
			//-->
			</SCRIPT>';
		}
	}
	//后台系统变量
	function setting_action() {
		
		$type = $_GET ['type'];
		switch ($type) {
			case 'site' :
				include ROOT_PATH . '/views/admin/setting_site.php';
				break;
			case 'seo' :
				include ROOT_PATH . '/views/admin/setting_seo.php';
				break;
			case 'attach' :
				include ROOT_PATH . '/views/admin/setting_attach.php';
				break;
			case 'group' :
				include ROOT_PATH . '/views/admin/setting_group.php';
				break;
			case 'login' :
				echo '对不起，您是免费用户，请登录<a href="http://www.lhaitun.net" target="_blank">海豚湾</a>授权';
				exit;
				break;
			case 'template' :
				$dir = scandir ( ROOT_PATH . '/views' );
				foreach ( $dir as $k => $v ) {
					if (is_dir ( ROOT_PATH . '/views/' . $v ) && $v != '..' && $v != '.' && $v != 'admin' && $v != 'js') {
						if (is_file ( ROOT_PATH . '/views/' . $v . '/template.config.php' )) {
							include ROOT_PATH . '/views/' . $v . '/template.config.php';
							$tpldir [] = array ('tplname' => $v, 'thumb' => 'views/' . $v . '/' . $picture, 'author' => $author, 'desc' => $desc, 'info' => $info );
						}
					}
				}
				include ROOT_PATH . '/views/admin/setting_template.php';
				break;
			default :
				include ROOT_PATH . '/views/admin/setting_site.php';
				break;
		}
	}
	
	//处理系统提交数据
	function settingdata_action() {
		if (submitcheck ( 'commit' )) {
			unset($_POST['con']);
			unset($_POST['act']);
			$type = $_POST ['dotype'];
			unset ( $_POST ['commit'], $_POST ['dotype'] );
			
			$setting_mod = new common ( 'setting' );
			
			if ($_FILES ['site_logo'] ['name']) {
				$filename = explode ( '.', $_FILES ['site_logo'] ['name'] );
				$container = 'and variable="site_logo"';
				$data ['content'] = _upload ( 'site_logo', 'data/logo', 'logo.' . $filename [1] );
				$datalist = $setting_mod->GetOne ( $container );
				
				if ($datalist) {
					$setting_mod->UpdateData ( $data, $container );
				} else {
					$data ['variable'] = 'site_logo';
					$setting_mod->InsertData ( $data );
				}
			}
			
			foreach ( $_POST as $k => $v ) {
				$container = 'and variable="' . $k . '"';
				$data ['content'] = strip_tags ( $v );
				$datalist = $setting_mod->GetOne ( $container );
				if ($datalist) {
					$updatesql [$k] = $v;
				} else {
					$insertsql [$k] = $v;
				}
			}
			if ($insertsql) {
				foreach ( $insertsql as $key => $val ) {
					$setting_mod->InsertData ( array ('variable' => $key, 'content' => $val ) );
				}
			}
			if ($updatesql) {
				foreach ( $updatesql as $key => $val ) {
					$setting_mod->UpdateData ( array ('content' => $val ), 'and variable="' . $key . '"' );
				}
			}
			if ($type == 'template') {
				$dofile = cleancache ( '', 'data/compile' );
				if (! $dofile) {
					echo '<SCRIPT LANGUAGE="JavaScript">
					<!--
						alert("模板更新成功,清空系统编译失败,请手动清除");
					//-->
					</SCRIPT>';
				} else {
					echo '<SCRIPT LANGUAGE="JavaScript">
					<!--
						alert("模板更新成功");
					//-->
					</SCRIPT>';
				}
			}
			deletef ( 'setting' );
			if ($_REQUEST ['custom_url']) {
				sheader ( $_REQUEST ['custom_url'], 3, '修改成功', 'redirect', true );
			} else {
				sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=setting&type=' . $type, 3, '修改成功', 'redirect', true );
			}
		}
	}
	//会员列表
	function user_action() {
		$container = '';
		if ($_REQUEST ['username']) {
			$container .= ' and username like "%' . global_addslashes ( $_REQUEST ['username'] ) . '%"';
			$ext = '&username=' . $_REQUEST ['username'];
		}
		if (! empty ( $_REQUEST ['utype'] )) {
			$container .= ' and usertype="' . trim ( strip_tags ( $_REQUEST ['utype'] ) ) . '"';
			$ext .= '&utype=' . $_REQUEST ['utype'];
		}
		$showpage = array ('isshow' => 1, 'currentpage' => intval ( $_REQUEST ['page'] ), 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=user' . $ext, 'example' => 3 );
		$user_mod = new common ( 'user' );
		$userlist = $user_mod->GetPage ( $showpage, $container );
		include ROOT_PATH . '/views/admin/user.php';
	}
	/**
	 *添加会员
	 */
	function usermodify_action() {
		
		$updateid = intval ( $_REQUEST ['updateid'] );
		$user_mod = new common ( 'user' );
		$user = array ();
		if (submitcheck ( 'commit' )) {
			
			$data ['username'] = trim ( strip_tags ( $_POST ['username'] ) );
			$data ['email'] = trim ( strip_tags ( $_POST ['email'] ) );
			$data ['phone'] = trim ( strip_tags ( $_POST ['phone'] ) );
			$data ['connect_user'] = trim ( strip_tags ( $_POST ['connect_user'] ) );
			$data ['connect_content'] = trim ( strip_tags ( $_POST ['connect_content'] ) );
			$data ['sex'] = intval ( $_POST ['sex'] );
			$data ['qq'] = trim ( strip_tags ( $_POST ['qq'] ) );
			$usertype = array_keys ( $GLOBALS ['user_group'] );
			
			if (in_array ( $_POST ['usertype'], $usertype )) {
				$data ['usertype'] = trim ( strip_tags ( $_POST ['usertype'] ) );
			
			} else {
				$data ['usertype'] = 'normaluser';
			}
			if ($updateid > 0) {
				if (! empty ( $_POST ['password'] )) {
					$data ['pwd'] = md52 ( $_POST ['password'] );
				}
				if ($user_mod->UpdateData ( $data, 'and uid=' . $updateid )) {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=user', 3, '修改成功', 'redirect', true );
				} else {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=user', 3, '修改失败', 'redirect', true );
				}
			} else {
				$data ['updatetime'] = time ();
				$data ['pwd'] = md52 ( $_POST ['password'] );
				$data ['allowed'] = 1; //是否免验证
				if ($user_mod->InsertData ( $data )) {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=user', 3, '添加成功', 'redirect', true );
				}
			}
		} else {
			if ($updateid) {
				$user = $user_mod->GetOne ( 'and uid=' . $updateid );
			
			}
			include ROOT_PATH . '/views/admin/user_form.php';
		}
	}
	//会员组管理
	function usergroup_action() {
		$usergroup_mod = new common ( 'user_group' );
		
		$showpage = array ('isshow' => 1, 'currentpage' => intval ( $_REQUEST ['page'] ), 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=usergroup', 'example' => 3 );
		
		$usergroup = $usergroup_mod->GetPage ( $showpage, '' );
		include ROOT_PATH . '/views/admin/usergroup.php';
	}
	//添加会员组
	function usergroupmodify_action() {
		$usergroup_mod = new common ( 'user_group' );
		$updateid = $_REQUEST ['updateid'];
		$group = array ();
		if (submitcheck ( 'commit' )) {
			$data ['groupname'] = trim ( strip_tags ( $_POST ['groupname'] ) );
			$data ['groupkey'] = trim ( strip_tags ( $_POST ['groupkey'] ) );
			if ($updateid > 0) {
				if ($usergroup_mod->UpdateData ( $data, 'and groupid=' . $updateid )) {
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='update';objdata.id='$updateid';objdata.groupname='" . global_addslashes ( $data ['groupname'], 1 ) . "';objdata.groupkey='" . global_addslashes ( $data ['groupkey'], 1 ) . "';parent.parseMyGroupData(objdata);</SCRIPT>";
				}
			} else {
				if ($id = $usergroup_mod->InsertData ( $data )) {
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='add';objdata.id='$id';objdata.groupname='" . global_addslashes ( $data ['groupname'], 1 ) . "';objdata.groupkey='" . global_addslashes ( $data ['groupkey'], 1 ) . "';parent.parseMyGroupData(objdata);</SCRIPT>";
				}
			}
		} else {
			if ($updateid) {
				$group = $usergroup_mod->GetOne ( 'and groupid=' . $updateid );
			}
			include ROOT_PATH . '/views/admin/usergroup_ajax_form.php';
		}
	}
	
	//会员权限字段管理
	function userrole_action() {
		$userrole_mod = new common ( 'user_role' );
		
		$showpage = array ('isshow' => 1, 'currentpage' => intval ( $_REQUEST ['page'] ), 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=userrole', 'example' => 3 );
		
		$userrole = $userrole_mod->GetPage ( $showpage, '' );
		include ROOT_PATH . '/views/admin/userrole.php';
	}
	//添加会员权限字段
	function userrolemodify_action() {
		$userrole_mod = new common ( 'user_role' );
		$updateid = $_REQUEST ['updateid'];
		$role = array ();
		if (submitcheck ( 'commit' )) {
			$data ['rolename'] = trim ( strip_tags ( $_POST ['rolename'] ) );
			$data ['rolekey'] = trim ( strip_tags ( $_POST ['rolekey'] ) );
			$data ['roletype'] = trim ( strip_tags ( $_POST ['roletype'] ) );
			if ($updateid > 0) {
				if ($userrole_mod->UpdateData ( $data, 'and roleid=' . $updateid )) {
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='update';objdata.id='$updateid';objdata.rolename='" . global_addslashes ( $data ['rolename'], 1 ) . "';objdata.rolekey='" . global_addslashes ( $data ['rolekey'], 1 ) . "';objdata.roletype='" . global_addslashes ( $data ['roletype'], 1 ) . "';parent.parseMyRoleData(objdata);</SCRIPT>";
				}
			} else {
				if ($id = $userrole_mod->InsertData ( $data )) {
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='add';objdata.id='$id';objdata.rolename='" . global_addslashes ( $data ['rolename'], 1 ) . "';objdata.rolekey='" . global_addslashes ( $data ['rolekey'], 1 ) . "';objdata.roletype='" . global_addslashes ( $data ['roletype'], 1 ) . "';parent.parseMyRoleData(objdata);</SCRIPT>";
				}
			}
		} else {
			if ($updateid) {
				$role = $userrole_mod->GetOne ( 'and roleid=' . $updateid );
			}
			include ROOT_PATH . '/views/admin/userrole_ajax_form.php';
		}
	}
	//分配权限
	function roletogroup_action() {
		$groupid = trim ( strip_tags ( $_REQUEST ['gid'] ) );
		$role_group = new common ( 'user_g_r' );
		$role_checked = $role_group->GetOne ( 'and groupid="' . $groupid . '"' );
		if (submitcheck ( 'commit' )) {
			$data ['groupid'] = $groupid;
			$data ['roleid'] = implode ( ',', $_REQUEST ['roles'] );
			if ($role_checked) {
				if ($role_group->UpdateData ( $data, 'and groupid="' . $groupid . '"' )) {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=usergroup', 3, '修改成功', 'redirect', true );
				} else {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=usergroup', 3, '修改失败', 'redirect', true );
				}
			} else {
				if ($role_group->InsertData ( $data )) {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=usergroup', 3, '添加成功', 'redirect', true );
				} else {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=usergroup', 3, '添加失败', 'redirect', true );
				}
			}
		} else {
			if ($groupid) {
				
				$role_checked = explode ( ',', $role_checked ['roleid'] );
				$role_mod = new common ( 'user_role' );
				$role = $role_mod->GetPage ( array ('isshow' => 0 ) );
				foreach ( $role as $k => $v ) {
					if (in_array ( $v ['rolekey'], $role_checked )) {
						$v ['checked'] = 'checked';
					}
					$roles [$v ['roletype']] [] = $v;
				}
				include ROOT_PATH . '/views/admin/roles.php';
			} else {
				sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=usergroup', 3, '请选择会员组', 'redirect', true );
			}
		}
	}
	//分类管理
	function cate_action() {
		$cate_mod = new common ( 'catelist' );
		$catelist = array ();
		if ($GLOBALS ['cate']) {
			foreach ( $GLOBALS ['cate'] as $k => $v ) {
				$data = $cate_mod->GetPage ( array ('isshow' => 0 ), 'and parentid=' . $k );
				$catelist [$k] = $data;
			}
		}
		
		include ROOT_PATH . '/views/admin/cate.php';
	}
	/**
	 *添加分类
	 */
	function catemodify_action() {
		$this->cate = new common ( 'catelist' );
		$updateid = $_REQUEST ['updateid'];
		$cate = array ();
		if (submitcheck ( 'commit' )) {
			$data ['catename'] = trim ( strip_tags ( $_POST ['catename'] ) );
			$data ['sortorder'] = intval ( $_POST ['sortorder'] );
			$data ['recommend'] = intval ( $_POST ['recommend'] );
			$style = "";
			foreach ( $_POST ['css'] as $k => $v ) {
				$style .= ';' . $k . ':' . $v;
			}
			$data ['css'] = substr ( $style, 1 );
			$data ['keywords'] = trim ( strip_tags ( $_POST ['keywords'] ) );
			$data ['parentid'] = intval ( $_POST ['parentid'] );
			if ($updateid > 0) {
				if ($this->cate->UpdateData ( $data, 'and id=' . $updateid )) {
					deletef ( 'cate' );
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='update';objdata.id='$updateid';objdata.sortorder='" . $data ['sortorder'] . "';objdata.parentid='" . $data ['parentid'] . "';objdata.catename='" . global_addslashes ( $data ['catename'], 1 ) . "';parent.parseMyCateData(objdata);</SCRIPT>";
				}
			} else {
				if ($id = $this->cate->InsertData ( $data )) {
					deletef ( 'cate' );
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='add';objdata.id='$id';objdata.sortorder='" . $data ['sortorder'] . "';objdata.parentid='" . $data ['parentid'] . "';objdata.catename='" . global_addslashes ( $data ['catename'], 1 ) . "';parent.parseMyCateData(objdata);</SCRIPT>";
				}
			}
		} else {
			if ($updateid) {
				$cate = $this->cate->GetOne ( 'and id=' . $updateid );
			}
			include ROOT_PATH . '/views/admin/cate_ajax_form.php';
		}
	}
	//ajax修改添加处理
	function admin_ajax_action() {
		$key = empty ( $_GET ['primarykey'] ) ? 'id' : $_GET ['primarykey'];
		
		if (empty ( $_GET ['table'] )) {
			echo '参数有误';
			exit ();
		} elseif (empty ( $_GET ['field'] )) {
			echo '字段为空';
			exit ();
		} 

		elseif (intval ( $_GET ['primary'] ) == 0) {
			echo '主键不能为0';
			exit ();
		} 

		else {
			$obj = new common ( $_GET ['table'] );
			
			$data [$_GET ['field']] = trim ( strip_tags ( $_GET ['val'] ) );
			$container = "and " . $key . "=" . intval ( $_GET ['primary'] );
			$this->_cachedel ();
			$goods = $obj->GetOne ( $container );
			
			if ($goods && $obj->UpdateData ( $data, $container, true )) {
				exit ( '1' );
			} else {
				exit ( 'failed' );
			}
		}
	}
	//ajax删除处理
	function admin_delete_action() {
		$key = empty ( $_GET ['key'] ) ? 'id' : $_GET ['key'];
		if (empty ( $_GET ['table'] )) {
			echo '参数有误';
			exit ();
		} elseif (empty ( $_GET ['val'] )) {
			echo '字段值为空';
			exit ();
		} else {
			$val = global_addslashes ( $_GET ['val'] );
			$container = "and $key='" . trim ( $val ) . "'";
			$obj = new common ( $_GET ['table'] );
			$this->_cachedel ();
			$goods = $obj->GetOne ( $container );
			if ($goods && $obj->DeleteData ( '1 ' . $container )) {
				exit ( '1' );
			} else {
				exit ( 'failed' );
			}
		}
	
	}
	
	//城市管理
	function citylist_action() {
		$city_mod = new common ( 'city' );
		if(!empty($_POST['confirmbutton']) && $_POST['confirmbutton']=='批量删除')
		{
			$cityid=$_POST['cid'];
			
			if($cityid)
			{
				$ids=implode(',',$cityid);
				$container='1 and cityid in ('.$ids.')';
				if($city_mod->DeleteData($container))
				{
					sheader('index.php?con=admin&act=citylist',3,'批量删除成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=citylist',3,'批量删除失败','redirect',true);
				}
			}
		}
		else
		{
			
			$showpage = array ('isshow' => 1, 'currentpage' => $_REQUEST['page'], 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=citylist', 'example' => 2 );
			$cityinfo = $city_mod->GetPage ( $showpage, "", "", array (), " ORDER BY sortorder desc" );
			include ROOT_PATH . '/views/admin/citylist.php';
		}
	}
	
	function citymodify_action() {
		$city = new common ( 'city' );
		$updateid = $_REQUEST ['updateid'];
		$group = array ();
		if (submitcheck ( 'commit' )) {
			$data ['cityname'] = trim ( strip_tags ( $_POST ['cityname'] ) );
			
			$data ['isshow'] = trim ( strip_tags ( $_POST ['isshow'] ) );
			
			if ($updateid > 0) {
				$data ['sortorder'] = trim ( strip_tags ( $_POST ['sortorder'] ) );
				$data ['pinyin'] = trim ( strip_tags ( $_POST ['pinyin'] ) );
				if ($city->UpdateData ( $data, 'and cityid =' . $updateid )) {
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='update';objdata.id='$updateid';objdata.cityname='" . global_addslashes ( $data ['cityname'], 1 ) . "';objdata.pinyin='" . $data ['pinyin'] . "';objdata.sortorder='" . $data ['sortorder'] . "';objdata.isshow='" . $data ['isshow'] . "';parent.parseMyCityData(objdata);</SCRIPT>";
				}
			} else {
				$sortorder=$city->GetOne('',array('sortorder'),'order by sortorder desc');
				$data ['sortorder'] = $sortorder['sortorder']+1;
				$data ['pinyin'] = Pinyin ($data ['cityname'],$GLOBALS['charset']);
				$boo = $city->GetOne(" AND  cityname = '".$data ['cityname']."'");
				if($boo)
				{		
					echo "<script>alert('城市重复!');</script>";					
				}
				elseif ($id = $city->InsertData ( $data )) {
						echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='add';objdata.id='" . $id . "';objdata.cityname='" . global_addslashes ( $data ['cityname'], 1 ) . "';objdata.pinyin='" . $data ['pinyin'] . "';objdata.isshow='" . $data ['isshow'] . "';objdata.sortorder='" . $data ['sortorder'] . "';parent.parseMyCityData(objdata);</SCRIPT>";
					}
				
			}
		} else {
			if ($updateid) {
				$cityinfo = $city->GetOne ( 'and cityid=' . $updateid );
			}
			
			include ROOT_PATH . '/views/admin/city_ajax_form.php';
		}
	}
	
	//商圈管理
	function bizgrouplist_action() {
		
		$bizgroup = new common ( 'bizgroup' );
		$city = new common ( 'city' );
		
		$tmp_listcity = $city->GetPage ( array () );
		$listcity = array ();
		
		foreach ( $tmp_listcity as $key => $val ) {
			$listcity [$val ['pinyin']] = $val ['cityname'];
		}
		
		$showpage = array ('isshow' => 1, 'currentpage' => intval($_REQUEST['page']), 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=bizgrouplist', 'example' => 2 );
		$bizgroup = $bizgroup->GetPage ( $showpage, "", "", array (), " ORDER BY cityid  DESC" );
		
		foreach ( $bizgroup ['data'] as $key => $val ) {
			
			$bizgroup ['data'] [$key] ['cityname'] = $listcity [$val ['cityid']];
		}
		
		include ROOT_PATH . '/views/admin/bizgrouplist.php';
	}
	
	function bizgroupmodify_action() {
		
		$bizgroup = new common ( 'bizgroup' );
		$updateid = $_REQUEST ['updateid'];
		$group = array ();
		
		$city = new common ( 'city' );
		$tmp_listcity = $city->GetPage ( array () );
		$listcity = array ();
		
		foreach ( $tmp_listcity as $key => $val ) {
			$listcity [$val ['pinyin']] = $val ['cityname'];
		}
		
		if (submitcheck ( 'commit' )) {
			
			$data ['cityid'] = trim ( strip_tags ( $_POST ['cityid'] ) );
			$data ['bizname'] = trim ( strip_tags ( $_POST ['bizname'] ) );
			$cityname = $listcity [$data ['cityid']];
			
			if ($updateid > 0) {
				if ($bizgroup->UpdateData ( $data, 'and id =' . $updateid )) {
					
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='update';objdata.id='$updateid';objdata.cityname='" . global_addslashes ( $cityname, 1 ) . "';objdata.bizname='" . global_addslashes ( $data ['bizname'], 1 ) . "';objdata.cityid='" . $data ['cityid'] . "';parent.parseMyData(objdata);</SCRIPT>";
				}
			} else {
				if ($id = $bizgroup->InsertData ( $data )) {
					
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={}; objdata.dotype='add';objdata.id='" . $id . "';objdata.cityname='" . global_addslashes ( $cityname, 1 ) . "';objdata.bizname='" . global_addslashes ( $data ['bizname'], 1 ) . "';objdata.cityid='" . $data ['cityid'] . "';parent.parseMyData(objdata);</SCRIPT>";
				}
			}
		} else {
			
			if ($updateid) {
				
				$bizgroup_info = $bizgroup->GetOne ( 'and id =' . $updateid );
			}
			
			include ROOT_PATH . '/views/admin/bizgroup_ajax_form.php';
		}
	}
	//团购商品列表
	function listgroup_action() 
	{

		$where = "";
		$order="";
		$ext="";
		$sortform="";
		$sortlink="";
		
		if ($_REQUEST ['keyword']) {
			$where .= " AND subject  like  '%" . $_REQUEST ['keyword'] . "%' ";
			$ext.="&keyword=".$_REQUEST ['keyword'];	
			$sortlink.="&keyword=".$_REQUEST ['keyword'];
		}
		
		if (isset($_REQUEST ['cate']) && $_REQUEST ['cate']>=0) {
			$where .= " AND big_catelist   = " . intval($_REQUEST ['cate']) ;
			$ext.="&cate=".$_REQUEST ['cate'];
			$sortlink.="&cate=".$_REQUEST ['cate'];
		}
		
		if ($_REQUEST ['city']) {
			
			$where .= " AND cityid  = '" . $_REQUEST ['city'] . "'";
			$ext.="&city=".$_REQUEST ['city'];
			$sortlink.="&city=".$_REQUEST ['city'];
		}
		
		if ($_REQUEST ['site']) {
			
			$where .= " AND siteid = '" . $_REQUEST ['site'] . "'";
			$ext.="&site=".$_REQUEST ['site'];
			$sortlink.="&site=".$_REQUEST ['site'];
		}
		
		if ($_REQUEST ['timecheck'] == 2) {
			
			$where .= " AND lasttime <" . time ();
			$ext.="&timecheck=".$_REQUEST ['timecheck'];
			$sortlink.="&timecheck=".$_REQUEST ['timecheck'];
		}
		
		if ($_REQUEST ['timecheck'] == 3) {
			
			$where .= " AND lasttime >" . time ();
			$ext.="&timecheck=".$_REQUEST ['timecheck'];
			$sortlink.="&timecheck=".$_REQUEST ['timecheck'];
		}
				
		if($_REQUEST['starttime'])
		{
			$where .= " AND updatetime >" . strtotime($_REQUEST['starttime']);
			$ext.="&starttime=".$_REQUEST ['starttime'];
			$sortlink.="&starttime=".$_REQUEST ['starttime'];
		}
		
		if($_REQUEST['endtime'])
		{
			$where .= " AND updatetime <" . strtotime($_REQUEST['endtime']);
			$ext.="&endtime=".$_REQUEST ['endtime'];	
			$sortlink.="&endtime=".$_REQUEST ['endtime'];	
		}		
		if($_REQUEST['o_sortorder'])
		{
			$order.="ORDER BY sortorder ".$_REQUEST['o_sortorder'];
			$ext.="&o_sortorder=".$_REQUEST['o_sortorder'];
			$sortform.="&o_sortorder=".$_REQUEST['o_sortorder'];
		}

		if($_REQUEST['o_updatetime'])
		{
			$order.="ORDER BY updatetime ".$_REQUEST['o_updatetime'];
			$ext.="&o_updatetime=".$_REQUEST['o_updatetime'];
			$sortform.="&o_updatetime=".$_REQUEST['o_updatetime'];
		}

		if($_REQUEST['o_ispassed'])
		{
			$order.="ORDER BY ispassed ".$_REQUEST['o_ispassed'];
			$ext.="&o_ispassed=".$_REQUEST['o_ispassed'];
			$sortform.="&o_ispassed=".$_REQUEST['o_ispassed'];
		}

		if($_REQUEST['o_recommend'])
		{
			$order.="ORDER BY recommend ".$_REQUEST['o_recommend'];
			$ext.="&o_recommend=".$_REQUEST['o_recommend'];
			$sortform.="&o_recommend=".$_REQUEST['o_recommend'];
		}
	
		if(empty($order))
		{
			$order.="ORDER BY temporder asc";
		}
		
		if(empty($where))
		{
			$where .= " AND lasttime >" . time ();
		}

		$groups = new common ( 'groups' );
		$showpage = array ('isshow' => 1, 'currentpage' => $_REQUEST ['page'], 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=listgroup'.$ext, 'example' => 2 );
		$groups_info = $groups->GetPage ( $showpage, $where, "", array (), $order );

		$catelist_info = $this->get_allcate();
		include ROOT_PATH . '/views/admin/grouplist.php';
	}
	/**
	*批量管理团购
	*/
	function multigroup_action()
	{
		if(submitcheck('commit'))
		{
			$group_mod=new common('groups');
			$gids=implode(',',$_POST['gid']);
			$container=' and id in ('.($gids?$gids:0).')';
			$ext='';
			if(!empty($_REQUEST['ext']))
			{
				foreach($_REQUEST['ext'] as $k=>$v)
				{
					$ext.='&'.$k.'='.$v;
				}
			}
			if($_POST['confirmbutton']=='批量移动')
			{
				$catelist_info = $this->get_allcate();				
				$cate =$_REQUEST['cate'];
				$up_arr = array();	
				if($catelist_info[$cate]['parentid'] > 0 )
				{
					$parentid = $catelist_info[$cate]['parentid'];
					$up_arr['big_catelist'] = $catelist_info[$parentid]['id'];
					$up_arr['big_catelist_catename'] = $catelist_info[$parentid]['catename'];
					$up_arr['small_catelist'] = $catelist_info[$cate]['id'];
					$up_arr['small_catelist_catename'] = $catelist_info[$cate]['catename'];
			
				}else{
										
					$up_arr['big_catelist'] = $catelist_info[$cate]['id'];
					$up_arr['big_catelist_catename'] = $catelist_info[$cate]['catename'];
					$up_arr['small_catelist'] = 0;
					$up_arr['small_catelist_catename'] = '';
	
				}
				
		
				if($group_mod->UpdateData($up_arr,$container))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量移动分类成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量移动分类失败','redirect',true);
				}
			}
			if($_POST['confirmbutton']=='批量移动城市')
			{
				$citys=explode('-',$_POST['cuscitys']);
				
				if($group_mod->UpdateData(array('cityid'=>$citys[0],'cityname'=>$citys[1]),$container))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部移动成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部移动失败','redirect',true);
				}
			}
			
			
			if($_POST['confirmbutton']=='批量审核')
			{
				if($group_mod->UpdateData(array('ispassed'=>intval($_POST['ispassed'])),$container))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量审核成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量审核失败','redirect',true);
				}
			}
			if($_POST['confirmbutton']=='批量推荐')
			{
				if($group_mod->UpdateData(array('recommend'=>intval($_POST['recommend'])),$container))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量推荐成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量推荐失败','redirect',true);
				}
			}
			if($_POST['confirmbutton']=='删除过期')
			{
				if($group_mod->DeleteData('1 and lasttime<'.time()))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'删除过期成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'删除过期失败','redirect',true);
				}
			}
			if($_POST['confirmbutton']=='全部审核')
			{
				if($group_mod->UpdateData(array('ispassed'=>1),'and id>0'))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部审核成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部审核失败','redirect',true);
				}
			}
			if($_POST['confirmbutton']=='全部推荐')
			{
				if($group_mod->UpdateData(array('recommend'=>1),'and id>0'))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部推荐成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部推荐失败','redirect',true);
				}
			}
			if($_POST['confirmbutton']=='全部取消审核')
			{
				if($group_mod->UpdateData(array('ispassed'=>0),'and id>0'))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部取消审核成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'全部取消审核失败','redirect',true);
				}
			}
			
			if($_POST['confirmbutton']=='批量删除')
			{
				if($group_mod->DeleteData(' 1 '.$container))
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量删除成功','redirect',true);
				}
				else
				{
					sheader('index.php?con=admin&act=listgroup'.$ext,3,'批量删除失败','redirect',true);
				}
			}
		}
	}
	//添加团购
	function groupsmodify_action() {
		
		$groups = new common ( 'groups' );
		$updateid = $_REQUEST ['updateid'];
		
		//网站
		$site = new common ( 'site' );
		$sitelist = $site->GetPage ( array () );
		$sitelist_arr = array ();
		foreach ( $sitelist as $key => $val ) {
			$sitelist_arr [$val ['id']] = $val ['sitename'];
		}
		
		if (submitcheck ( 'commit' )) {
		
			$catelist = new common ( 'catelist' );
			$catelist_info_all = $catelist->GetPage ( array () );
			$catelist_info_arr = array ();
			foreach ( $catelist_info_all as $key => $val ) {
				$catelist_info_arr [$val ['id']] = $val ['catename'];
			}
			
			$data ['groupkey'] = md5(trim ( strip_tags ( $_REQUEST ['subject'] ) ).trim ( strip_tags ( $_REQUEST ['siteid'] ) ).trim($_REQUEST ['city']));
			$data ['subject'] = trim ( strip_tags ( $_REQUEST ['subject'] ) );
			$data ['shortsubject'] = trim ( strip_tags ( $_REQUEST ['shortsubject'] ) );
			$data ['starttime'] = strtotime( trim($_REQUEST ['starttime']) );
			$data ['lasttime'] =  strtotime (trim( $_REQUEST ['lasttime']) );
			$data ['siteid'] = trim ( strip_tags ( $_REQUEST ['siteid'] ) );
			$data ['groupsite'] = $sitelist_arr [$_REQUEST ['siteid']];
			$data ['cityid'] = trim($_REQUEST ['city']);
			$data ['cityname'] = $GLOBALS ['city'] [$_REQUEST ['city']] ['cityname'];
			$data ['bizgroup'] = trim ( strip_tags ( $_REQUEST ['bizgroup'] ) );
			$data ['bizname'] = $GLOBALS ['bizgroup'] [$_REQUEST ['bizgroup']] ['bizname'];
			$data ['big_catelist'] = trim ( strip_tags ( $_REQUEST ['big_catelist'] ) );
			$data ['small_catelist'] = trim ( strip_tags ( $_REQUEST ['small_catelist'] ) );
			$data ['big_catelist_catename'] = $catelist_info_arr [$_REQUEST ['big_catelist']];
			$data ['small_catelist_catename'] = $catelist_info_arr [$_REQUEST ['small_catelist']];
			$data ['url'] = trim ( strip_tags ( $_REQUEST ['url'] ) );
			$data ['oldprice'] = trim ( strip_tags ( $_REQUEST ['oldprice'] ) );
			$data ['nowprice'] = trim ( strip_tags ( $_REQUEST ['nowprice'] ) );
			$data ['nowpeople'] = trim ( strip_tags ( $_REQUEST ['nowpeople'] ) );
			$data ['hits'] = 0;
			$data ['keyword'] = trim ( strip_tags ( $_REQUEST ['keyword'] ) );
			$data ['sortorder'] = trim ( strip_tags ( $_REQUEST ['sortorder'] ) );
			$data ['ispassed'] = trim ( strip_tags ( $_REQUEST ['ispassed'] ) );
			$data ['recommend'] = trim ( strip_tags ( $_REQUEST ['recommend'] ) );
			$data ['commentcount'] = 0;
			$data ['favcount'] = 0;
			$data ['updatetime'] = time ();
		
			if ($_FILES ['thumb'] ['name']) {
				$filetime = date ( "Y/m", time () );
				$dir = "data/upload/group/" . $filetime;
				$data ['thumb'] = _upload ( 'thumb', $dir, '', array ('width' => 100, 'height' => 100 ) );
			}

			if ($updateid > 0) {
				if ($groups->UpdateData ( $data, 'and id =' . $updateid )) {
					
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=listgroup', 3, '更新成功！', 'redirect', true );
				}
			} else {
				if ($id = $groups->InsertData ( $data )) {
					
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=listgroup', 3, '添加成功！', 'redirect', true );
				}
			}
		} else {
			
			if ($updateid) {
				
				$groups_info = $groups->GetOne ( 'and id =' . $updateid );
			}
			
			include ROOT_PATH . '/views/admin/groups_form.php';
		}
	
	}
	//添加网站
	function sitemodify_action() {
		$updateid = $_REQUEST ['updateid'];
		$site = array ();
		$site_mod = new common ( 'site' );
		if (submitcheck ( 'commit' )) {
			
			$data ['sitename'] = trim ( strip_tags ( $_POST ['sitename'] ) );
			$data ['siteurl'] = $_POST ['siteurl'];
			$data ['siteapi'] = str_replace('lansei','lhaitun',$_POST ['siteapi']);
			$data ['cityapi'] = str_replace('lansei','lhaitun',$_POST ['cityapi']);
			
			$data ['citysiteapi'] = $_POST ['citysiteapi'];
			$data ['goodorder'] = $_POST ['goodorder'];
			$data ['recommend'] = intval ( $_POST ['recommend'] );
			$data ['apikey'] = trim ( $_POST ['apikey'] );
			$data ['limitcity'] = trim ( $_POST ['limitcity'] );
			$data ['limitnum'] = intval ( $_POST ['limitnum'] );
			$data ['level'] = intval ( $_POST ['level'] );
			$data ['cityrep'] = trim ( strip_tags ( $_POST ['cityrep'] ) );
			//$data ['sitetype'] = intval ( $_POST ['sitetype'] );
			$style = "";
			foreach ( $_POST ['css'] as $k => $v ) {
				$style .= ';' . $k . ':' . $v;
			}
			$data ['css'] = substr ( $style, 1 );
			$data ['isallowed'] = intval ( $_POST ['isallowed'] );
			$data ['pinyin'] = strtoupper($_POST ['pinyin']);
			$data ['gather_method'] = trim ( strip_tags ( $_POST ['gather_method'] ) );
			if ($_FILES ['logo'] ['name']) {
				$filetime = date ( "Y/m", time () );
				$dir = "data/upload/logo/" . $filetime;
				$data ['logo'] = _upload ( 'logo', $dir);
			}
			//$data ['qq'] = trim ( strip_tags ( $_POST ['qq'] ) );
			$data ['email'] = trim ( strip_tags ( $_POST ['email'] ) );
			//$data ['msn'] = trim ( strip_tags ( $_POST ['msn'] ) );
			$data ['tel'] = trim ( strip_tags ( $_POST ['tel'] ) );
			$style = "";
			foreach ( $_POST ['css'] as $k => $v ) {
				$style .= ';' . $k . ':' . $v;
			}
			$data ['css'] = substr ( $style, 1 );
			$data ['apirep'] = trim ( strip_tags ( $_POST ['apirep'] ) );
			if ($updateid > 0) {
				if ($site_mod->UpdateData ( $data, 'and id=' . $updateid )) {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=site', 3, $data ['sitename'].'修改成功', 'redirect', true );
				} else {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=site', 3, $data ['sitename'].'修改失败', 'redirect', true );
				}
			} else {
				
				if ($id = $site_mod->InsertData ( $data )) {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=site', 3, $data ['sitename'].'添加成功', 'redirect', true );
				
				} else {
					sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=site', 3, $data ['sitename'].'添加失败', 'redirect', true );
				}
			}
		
		} else {
			if ($updateid) {
				$site = $site_mod->GetOne ( 'and id=' . $updateid );
			}
			include ROOT_PATH . '/views/admin/site_form.php';
		}
	}
	//添加开通城市
	function sitecity_action()
	{
		$updateid = $_REQUEST ['updateid'];
		$site = array ();
		$site_mod = new common ( 'site' );
		if(submitcheck('commit'))
		{
			foreach($_POST ['sitecity'] as $k=>$v)
			{
				$_POST ['sitecity'][$k]=Pinyin($v,$GLOBALS['charset']);
			}
			$data ['cityid'] = implode ( ',', $_POST ['sitecity'] );
			
			if ($site_mod->UpdateData ( $data, 'and id=' . $updateid )) 
			{
				exit('<SCRIPT LANGUAGE="JavaScript">
				<!--
					alert("城市操作成功");
				//-->
				</SCRIPT>');
			}
			else
			{
				exit('<SCRIPT LANGUAGE="JavaScript">
				<!--
					alert("数据未发生改变");
				//-->
				</SCRIPT>');
			}
		}
		else
		{
			$site = $site_mod->GetOne ( 'and id=' . $updateid );
			
			include ROOT_PATH . '/views/admin/site_ajax_form.php';
		}
	}
	//同步网站城市
	function getsitecity_action()
	{
		$id = $_REQUEST ['id'];
		
		$citylist=array();
		if($id>0)
		{
			include ROOT_PATH.'/models/attach.php';
			$sitecity = array ();
			$site_mod = new common ( 'site' );
			$sitecity= $site_mod->GetOne ( 'and id=' . $id );
			$attach=new attach($sitecity);
			$citylist=$attach->parse_city(false,true);
		}
		if($citylist)
		{
			echo '{status:"success",data:[{cityid:"",cityname:""}';
			foreach($citylist as $k=>$v)
			{
				echo ',{cityid:"'.$v['cityid'].'",cityname:"'.charset_encode($v['cityname'],$GLOBALS['charset']).'"}';
			}
			echo ']}';
		}
		exit;
	}
	//网站管理
	function site_action() {
		$container = '';
		$extaurl = '';
		$site_mod=new common('site');
		
		if ($_GET ['keyword']) {
			$container = ' and sitename like "%' . $_GET ['keyword'] . '%"';
			$extaurl .= '&keyword=' . $_GET ['keyword'];
		}
		if ($_GET ['sitetype'] && $_GET ['sitetype'] > - 1) {
			$container .= ' and sitetype=' . intval ( $_GET ['sitetype'] );
			$extaurl .= '&sitetype=' . $_GET ['sitetype'];
		}
		if ($_GET ['pinyin']) {
			$container .= ' and pinyin ="' . $_GET ['pinyin'] . '"';
			$extaurl .= '&pinyin=' . $_GET ['pinyin'];
		}
		$showpage = array ('isshow' => 1, 'currentpage' => intval ( $_REQUEST ['page'] ), 'pagesize' => 20, 'url' => 'index.php?con=admin&act=site' . $extaurl, 'example' => 2 );
		$sitelist = $site_mod->GetPage ( $showpage, $container, '', array (), 'order by goodorder desc,id desc' );
		
		include ROOT_PATH . '/views/admin/site.php';
	}
	//批量操作网站
	function sitedo_action() {
		$gids = $_POST ['gid'];
		$button = $_POST ['confirmbutton'];
		$site_mod = new common ( 'site' );
		if ($gids) {
			$gids = implode ( ',', $gids );
			$container = "and id in (" . $gids . ")";
			if ($button == 'multi_del' && $site_mod->DeleteData ( '1 ' . $container )) {
				sheader ( 'index.php?con=admin&act=site', 3, '批量删除完成', 'redirect', true );
			} elseif ($button == 'multi_re' && $site_mod->UpdateData ( array ('recommend' => 1 ), $container )) {
				sheader ( 'index.php?con=admin&act=site', 3, '批量推荐完成', 'redirect', true );
			} elseif ($button == 'multi_cancel' && $site_mod->UpdateData ( array ('recommend' => 0 ), $container )) {
				sheader ( 'index.php?con=admin&act=site', 3, '批量取消推荐完成', 'redirect', true );
			} elseif ($button == 'multi_allow' && $site_mod->UpdateData ( array ('isallowed' => 1 ), $container )) {
				sheader ( 'index.php?con=admin&act=site', 3, '批量允许完成', 'redirect', true );
			} elseif ($button == 'multi_noallow' && $site_mod->UpdateData ( array ('isallowed' => 0 ), $container )) {
				sheader ( 'index.php?con=admin&act=site', 3, '批量禁止完成', 'redirect', true );
			} 

			else {
				sheader ( 'index.php?con=admin&act=site', 3, '批量操作完成', 'redirect', true );
			}
		} else {
			sheader ( 'index.php?con=admin&act=site', 3, '未指明参数', 'redirect', true );
		}
	}
	//自动生成url
	function attachurl_action()
	{
		$site_mod=new common('site');
		$siteid=intval($_REQUEST['siteid']);
		if($siteid>0)
		{
			include ROOT_PATH.'/models/attach.php';
			
			$site=$site_mod->GetOne('and id='.$siteid);
			
			if($site)
			{
				$attach=new attach($site);
				$citylist=$attach->parse_city();
				
				echo '{status:"success",data:[';
				if($citylist)
				{
					if(!empty($site['limitcity']))
					{
						foreach($citylist as $k=>$v)
						{
							$v['cityname']=charset_encode($v['cityname'],$GLOBALS['charset']);
							if(strpos(','.$site['limitcity'],$v['cityname']))
							{
								echo '{siteid:"'.$siteid.'",sitename:"'.$site['sitename'].'",cityname:"'.$v['cityname'].'",repurl:"'.str_replace('&','limengqiurl1',str_replace('?','limengqi2',$attach->parse_cityapi($v))).'"},';
							}
						}
					}
					else
					{
						foreach($citylist as $k=>$v)
						{
							$v['cityname']=charset_encode($v['cityname'],$GLOBALS['charset']);
							echo '{siteid:"'.$siteid.'",sitename:"'.$site['sitename'].'",cityname:"'.$v['cityname'].'",repurl:"'.str_replace('&','limengqiurl1',str_replace('?','limengqi2',$attach->parse_cityapi($v))).'"},';
						}
					}
				}
				else
				{
					echo '{siteid:"'.$siteid.'",sitename:"'.$site['sitename'].'",cityname:"全部",repurl:"'.str_replace('&','limengqiurl1',str_replace('?','limengqi2',$attach->parse_cityapi(array()))).'"}';
				}
				echo ']}';
			}
			exit;
		}
	}
	//采集
	function attach_action()
	{
		set_time_limit(30);
		$site_mod=new common('site');
		$siteid=intval($_REQUEST['siteid']);
		$starttime=microtime();

		if($siteid>0)
		{
			include ROOT_PATH.'/models/attach.php';
			
			$site=$site_mod->GetOne('and id='.$siteid);
			$attach=new attach($site);
			$myurl=str_replace('limengqi2','?',str_replace('limengqiurl1','&',$_REQUEST['repurl']));
			
			$tempdata=$attach->parse_group($myurl);
			
			if($id=$attach->insert_temp_table($tempdata))
			{
				if($id)
				{
					exit('{status:"success",siteid:"'.$site['id'].'",result:"采集成功",starttime:"'.$starttime.'",lasttime:"'.microtime().'"}');
				}
				else
				{
					exit('{status:"failed",siteid:"'.$site['id'].'",result:"入库失败"}');
				}
			}
			else
			{
				exit('{status:"failed",siteid:"'.$site['id'].'",result:"采集失败"}');
			}
		}
		else
		{
			$sites=$site_mod->GetPage(array('isshow'=>0),'and isallowed>0','',array('sitename','id','pinyin'));
			include ROOT_PATH.'/views/admin/attach.php';
			
		}
		
	}
	
	//网站分类
	function sitecate_action() {
		include ROOT_PATH . '/views/admin/sitecate.php';
	}
	//添加网站分类
	function sitecatemodify_action() {
		$updateid = $_REQUEST ['updateid'];
		$sitecate_mod = new common ( 'sitecate' );
		$sitecate = array ();
		if (submitcheck ( 'commit' ) &&  !empty($_POST ['sitecatename'])) {
			$data ['sitecatename'] = trim ( strip_tags ( $_POST ['sitecatename'] ) );
			$data ['sortorder'] = intval ( $_POST ['sortorder'] );
			if ($updateid > 0) {
				if ($sitecate_mod->UpdateData ( $data, 'and id=' . $updateid )) {
					deletef ( 'sitecate' );
		
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={};objdata.dotype='update';objdata.id='$updateid';objdata.sitecatename='" . global_addslashes ( $data ['sitecatename'], 1 ) . "';objdata.sortorder='" . $data ['sortorder'] . "'; parent.parseMysitecateData(objdata);</SCRIPT>";
				}
			} else {
				if ($id = $sitecate_mod->InsertData ( $data )) {
					deletef ( 'sitecate' );
					
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={};objdata.dotype='add';objdata.id='$id';objdata.sitecatename='" . global_addslashes ( $data ['sitecatename'], 1 ) . "';objdata.sortorder='" . $data ['sortorder'] . "';parent.parseMysitecateData(objdata);</SCRIPT>";
				}
			}
		} else {
			if ($updateid) {
				$sitecate = $sitecate_mod->GetOne ( 'and id=' . $updateid );
			}
			include ROOT_PATH . '/views/admin/sitecate_ajax_form.php';
		}
	}
	
	//入库操作
	function op_action() {
		
		$tempsite = new common ( "tempsite" );
		$tempids = $_REQUEST ['tempid'];
		$op = $_REQUEST ['op'];
		if (isset($_REQUEST ['cate']) && $_REQUEST ['cate']>=0) 
		{
			$ext.="&cate=".$_REQUEST ['cate'];
		}
		if ($op == "pass" && $tempids) {
			$GLOBALS['db']->query("update ".tname('groups')." set sortorder=0 where updatetime<".(time()-86400));
			$str_ids="";
			$str_ids = implode( ",", $tempids );
			$sql = "REPLACE INTO " . tname ( 'groups' ) . " (groupkey,subject,shortsubject,siteid,groupsite,url,thumb,oldprice,nowprice,discount,lasttime,starttime,sortorder,cityid,hits,ispassed,userid,keyword,updatetime,cityname,recommend,nowpeople,commentcount,favcount,bizgroup,bizname,big_catelist,small_catelist,big_catelist_catename,small_catelist_catename,citysname ) SELECT groupkey,subject,shortsubject,siteid,groupsite,url,thumb,oldprice,nowprice,discount,lasttime,starttime,sortorder,cityid,0 AS hits ,1 AS  ispassed ,0 AS userid ,keyword,updatetime,cityname,recommend,nowpeople,0 AS commentcount, 0 AS favcount ,bizgroup ,bizname,big_catelist,small_catelist,big_catelist_catename,small_catelist_catename,citysname FROM ". tname ( 'tempsite' ) ."  WHERE id IN (".$str_ids.")  order by id desc ";
			$GLOBALS['db']->query($sql);
			if($GLOBALS['db']->affected_rows())
			{
				$tempsite->DeleteData ("id IN (".$str_ids.")");
				sheader ( 'index.php?con=admin&act=listtempsite'.$ext, 3, '批量操作完成', 'redirect', true );
			}
			else
			{
				sheader ( 'index.php?con=admin&act=listtempsite'.$ext, 3, '批量操作失败', 'redirect', true );
			}
		}
		
		if ($op == "pass_all") {
			$GLOBALS['db']->query("update ".tname('groups')." set sortorder=0 where updatetime<".(time()-86400));
			$sql = "REPLACE INTO " . tname ( 'groups' ) . " (groupkey,subject,shortsubject,siteid,groupsite,url,thumb,oldprice,nowprice,discount,lasttime,starttime,sortorder,cityid,hits,ispassed,userid,keyword,updatetime,cityname,recommend,nowpeople,commentcount,favcount,bizgroup,bizname,big_catelist,small_catelist,big_catelist_catename,small_catelist_catename,citysname ) SELECT groupkey,subject,shortsubject,siteid,groupsite,url,thumb,oldprice,nowprice,discount,lasttime,starttime,sortorder,cityid,0 AS hits ,1 AS  ispassed ,0 AS userid ,keyword,updatetime,cityname,recommend,nowpeople,0 AS commentcount, 0 AS favcount ,bizgroup ,bizname,big_catelist,small_catelist,big_catelist_catename,small_catelist_catename,citysname FROM ". tname ( 'tempsite' ) ." order by id desc ";
			
			$GLOBALS['db']->query($sql);
			if($GLOBALS['db']->affected_rows())
			{
				$tempsite->ClearData ();
				sheader ( 'index.php?con=admin&act=listgroup', 3, '批量操作完成', 'redirect', true );
			}
			else
			{
				sheader ( 'index.php?con=admin&act=listtempsite'.$ext, 3, '批量操作失败', 'redirect', true );
			}
		}
		
		if ($op == "delete" && $tempids) {
			$del_where = " id  IN (";
			$del_where .= implode ( ",", $tempids );
			$del_where .= ")";
			$tempsite->DeleteData ( $del_where );
			sheader ( 'index.php?con=admin&act=listtempsite'.$ext, 3, '批量删除完成', 'redirect', true );
		}
		
		if ($op == "delete_all") {
			$tempsite->ClearData ();
			
			sheader ( 'index.php?con=admin&act=listtempsite'.$ext, 3, '全部清空完成', 'redirect', true );
		}
	
	}
	//权重表排序
	function temporder_action()
	{
		$tempsite = new common ( 'groups' );
		$sites=$tempsite->GetPage(array('isshow'=>0),'','',array('id','siteid'));
		$rows=array();
		foreach($GLOBALS['site'] as $k=>$v)
		{
			$gcount[$k]=0;
		}
		foreach($sites as $k=>$v)
		{
			$rows[$v['siteid']][]=$v;
			$gcount[$v['siteid']]++;
		}
		foreach($gcount as $k=>$v)
		{
			if($v==0)
			{
				unset($gcount[$k]);
			}
		}
		$max=max($gcount);
		$j=1;
		for($i=0;$i<$max;$i++)
		{
			foreach($gcount as $k=>$v)
			{
				if(isset($rows[$k][$i]))
				{
					$GLOBALS['db']->query('update '.tname("groups").'  set temporder='.$j.' where id='.$rows[$k][$i]['id']);
					$j++;
				}
				
			}
		}
		sheader ( 'index.php?con=admin&act=listgroup', 3, '全部排序完成', 'redirect', true );
	}
	//临时表手动修改
	function tempsitemodify_action() {
		$tempsite = new common ( 'tempsite' );
		$updateid = $_REQUEST ['updateid'];
		
		//网站
		$site = new common ( 'site' );
		$sitelist = $site->GetPage ( array () );
		$sitelist_arr = array ();
		foreach ( $sitelist as $key => $val ) {
			$sitelist_arr [$val ['id']] = $val ['sitename'];
		}
		
		if (submitcheck ( 'commit' )) {
			
			$catelist = new common ( 'catelist' );
			$catelist_info_all = $catelist->GetPage ( array () );
			$catelist_info_arr = array ();
			foreach ( $catelist_info_all as $key => $val ) {
				$catelist_info_arr [$val ['id']] = $val ['catename'];
			}
			
			$data ['groupkey'] = md5(trim ( strip_tags ( $_REQUEST ['subject'] ) ).trim ( strip_tags ( $_REQUEST ['siteid'] ) ).trim($_REQUEST ['city']));			
			$data ['subject'] = trim ( strip_tags ( $_REQUEST ['subject'] ) );
			$data ['shortsubject'] = trim ( strip_tags ( $_REQUEST ['shortsubject'] ) );
			$data ['starttime'] = strtotime ( $_REQUEST ['starttime'] );
			$data ['lasttime'] = strtotime ( $_REQUEST ['lasttime'] );
			$data ['siteid'] = trim ( strip_tags ( $_REQUEST ['siteid'] ) );
			$data ['groupsite'] = $sitelist_arr [$_REQUEST ['siteid']];
			$data ['cityid'] = trim(strip_tags($_REQUEST ['city']));
			$data ['cityname'] = $GLOBALS ['city'] [$_REQUEST ['city']] ['cityname'];
			$data ['bizgroup'] = trim ( strip_tags ( $_REQUEST ['bizgroup'] ) );
			$data ['bizname'] = $GLOBALS ['bizgroup'] [$_REQUEST ['bizgroup']] ['bizname'];
			$data ['big_catelist'] = trim ( strip_tags ( $_REQUEST ['big_catelist'] ) );
			$data ['small_catelist'] = trim ( strip_tags ( $_REQUEST ['small_catelist'] ) );
			$data ['big_catelist_catename'] = $catelist_info_arr [$_REQUEST ['big_catelist']];
			$data ['small_catelist_catename'] = $catelist_info_arr [$_REQUEST ['small_catelist']];
			$data ['url'] = trim ( strip_tags ( $_REQUEST ['url'] ) );
			$data ['oldprice'] = trim ( strip_tags ( $_REQUEST ['oldprice'] ) );
			$data ['nowprice'] = trim ( strip_tags ( $_REQUEST ['nowprice'] ) );
			$data ['nowpeople'] = trim ( strip_tags ( $_REQUEST ['nowpeople'] ) );
			$data ['keyword'] = trim ( strip_tags ( $_REQUEST ['keyword'] ) );
			$data ['sortorder'] = trim ( strip_tags ( $_REQUEST ['sortorder'] ) );
			$data ['recommend'] = trim ( strip_tags ( $_REQUEST ['recommend'] ) );
			$data ['updatetime'] = time ();
			
			if ($_FILES ['thumb'] ['name']) {
				$filetime = date ( "Y/m", time () );
				$dir = "data/upload/group/" . $filetime;
				$data ['thumb'] = _upload ( 'thumb', $dir, '', array ('width' => 100, 'height' => 100 ) );
			}
			
			if ($tempsite->UpdateData ( $data, 'and id =' . $updateid )) {
				
				sheader ( 'index.php?con=admin&act=listtempsite', 3, '更新成功', 'redirect', true );
			}
		
		} else {
			
			if ($updateid) {
				
				$tempsite_info = $tempsite->GetOne ( 'and id =' . $updateid );
			}
			
			include ROOT_PATH . '/views/admin/tempsite_form.php';
		}
	
	}
	//入库列表页
	function listtempsite_action() {
		$site = new common ( 'site' );
		$sitelist = $site->GetPage ( array () );
		$sitelist_arr = array ();
		foreach ( $sitelist as $key => $val ) {
			$sitelist_arr [$val ['id']] = $val ['sitename'];
		}
		
		$where = "";
		$order="order by id asc";
		$ext="";
		$sortform="";
		$sortlink="";
		
		if ($_REQUEST ['keyword']) {
			$where .= " AND subject  like  '%" . $_REQUEST ['keyword'] . "%' ";
			$ext.="&keyword=".$_REQUEST ['keyword'];	
			$sortlink.="&keyword=".$_REQUEST ['keyword'];
		}
		
		if (isset($_REQUEST ['cate']) && $_REQUEST ['cate']>=0) {
			$where .= " AND big_catelist   = " . $_REQUEST ['cate'] ;
			$ext.="&cate=".$_REQUEST ['cate'];
			$sortlink.="&cate=".$_REQUEST ['cate'];
		}
		
		if ($_REQUEST ['city']) {
			
			$where .= " AND cityid  = '" . $_REQUEST ['city'] . "'";
			$ext.="&city=".$_REQUEST ['city'];
			$sortlink.="&city=".$_REQUEST ['city'];
		}
		
		if ($_REQUEST ['site']) {
			
			$where .= " AND siteid = '" . $_REQUEST ['site'] . "'";
			$ext.="&site=".$_REQUEST ['site'];
			$sortlink.="&site=".$_REQUEST ['site'];
		}
		
		if ($_REQUEST ['timecheck'] == 2) {
			
			$where .= " AND lasttime <" . time ();
			$ext.="&timecheck=".$_REQUEST ['timecheck'];
			$sortlink.="&timecheck=".$_REQUEST ['timecheck'];
		}
		
		if ($_REQUEST ['timecheck'] == 3) {
			
			$where .= " AND lasttime >" . time ();
			$ext.="&timecheck=".$_REQUEST ['timecheck'];
			$sortlink.="&timecheck=".$_REQUEST ['timecheck'];
		}
		
	
		if($_REQUEST['o_sortorder'])
		{
			$order="ORDER BY sortorder ".$_REQUEST['o_sortorder'];
			$ext.="&o_sortorder=".$_REQUEST['o_sortorder'];
			$sortform.="&o_sortorder=".$_REQUEST['o_sortorder'];
		}

		if($_REQUEST['o_updatetime'])
		{
			$order="ORDER BY updatetime ".$_REQUEST['o_updatetime'];
			$ext.="&o_updatetime=".$_REQUEST['o_updatetime'];
			$sortform.="&o_updatetime=".$_REQUEST['o_updatetime'];
		}

		if($_REQUEST['o_ispassed'])
		{
			$order="ORDER BY ispassed ".$_REQUEST['o_ispassed'];
			$ext.="&o_ispassed=".$_REQUEST['o_ispassed'];
			$sortform.="&o_ispassed=".$_REQUEST['o_ispassed'];
		}

		if($_REQUEST['o_recommend'])
		{
			$order="ORDER BY recommend ".$_REQUEST['o_recommend'];
			$ext.="&o_recommend=".$_REQUEST['o_recommend'];
			$sortform.="&o_recommend=".$_REQUEST['o_recommend'];
		}
		
		
		$tempsite = new common ( 'tempsite' );
		$showpage = array ('isshow' => 1, 'currentpage' => $_REQUEST ['page'], 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=listtempsite'.$ext, 'example' => 2 );
		$tempsite_info = $tempsite->GetPage ( $showpage, $where, "", array (), $order );
		
		include ROOT_PATH . '/views/admin/listtempsite.php';
	}
	
	
	/**
	*其他网站
	*/	
	
	function  listothersite_action()
	{
		
		$where  = "";
		$ext='';
		if($_REQUEST['keyword'])
		{
			$where.=" AND  sitename LIKE '%".$_REQUEST['keyword']."%' ";	
			$ext.='&keyword='.$_REQUEST['keyword'];
		}
		
		if($_REQUEST['sitecate'])
		{
			$where.=" AND  cate = ".$_REQUEST['sitecate']." ";	
			$ext.='&sitecate='.$_REQUEST['sitecate'];
		}
	
		$othersite = new common ( 'othersite' );
		$showpage = array ('isshow' => 1, 'currentpage' => $_REQUEST ['page'], 'pagesize' => 20, 'url' => 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=listothersite'.$ext, 'example' => 2 );
		$othersite_info = $othersite->GetPage ( $showpage,$where,"",array(),"ORDER BY sort DESC" );
		
		include ROOT_PATH . '/views/admin/othersite.php';
	}

	
	/**
	*其他网站更新
	*/		
	function  othersitemodify_action()
	{
		$updateid = $_REQUEST ['updateid'];
		$othersite_mod = new common ( 'othersite' );
		$othersite = array ();
		if (submitcheck ( 'commit' ) &&  !empty($_POST ['sitename'])) {
			
			$data ['sitename'] = trim ( strip_tags ( $_POST ['sitename'] ) );
			$data ['url'] = trim ( strip_tags (  $_POST ['url'] ));
            $data ['cate'] = intval ( $_POST ['cate'] );
            $data ['sort']  = $_POST['sort'];		
            $data ['istop'] = intval ( $_POST ['istop'] );   
			$data ['recommend'] = intval ( $_POST ['recommend'] );
			$data['color']  = $_POST['color'];		
			if($_POST['font'])
			{
				$data['font']="font-weight:bold";
			}
			if(!empty($_REQUEST['img_url']))
			{
				$data ['img']=trim(strip_tags($_REQUEST['img_url']));
			}
			elseif ($_FILES ['img'] ['name']) {
				$dir = "data/upload/othersite/";
				$data ['img'] = _upload ( 'img', $dir, '', array ('width' => 148, 'height' => 60 ) );
			}
			
			if ($updateid > 0) {
				if ($othersite_mod->UpdateData ( $data, 'and id=' . $updateid )) {
					//deletef ( 'sitecate' );
					$cate = $GLOBALS['sitecate'][$data ['cate']]['sitecatename'];
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={};objdata.dotype='update';objdata.id='$updateid';objdata.sitename='" . global_addslashes ( $data ['sitename'], 1 ) . "';objdata.url='" . global_addslashes ( $data ['url'], 1 ) . "';objdata.cate='" . $cate . "';objdata.istop='" . $data ['istop'] . "'; objdata.img='" . $data ['img'] . "';objdata.recommend='" . $data ['recommend'] . "';objdata.color='" . $data ['color'] . "';objdata.font='" . $data ['font'] . "';objdata.sort='" . $data ['sort'] . "'; parent.parseMysitecateData(objdata);</SCRIPT>";
				}
			} else {
				if ($id = $othersite_mod->InsertData ( $data )) {
					//deletef ( 'sitecate' );
					$cate = $GLOBALS['sitecate'][$data ['cate']]['sitecatename'];
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={};objdata.dotype='add';objdata.id='$id';objdata.sitename='" . global_addslashes ( $data ['sitename'], 1 ) . "';objdata.url='" . global_addslashes ( $data ['url'], 1 ) . "';objdata.cate='" . $cate . "';objdata.istop='" . $data ['istop'] . "'; objdata.img='" . $data ['img'] . "';objdata.recommend='" . $data ['recommend'] . "';objdata.color='" . $data ['color'] . "';objdata.font='" . $data ['font'] . "'; objdata.sort='" . $data ['sort'] . "';parent.parseMysitecateData(objdata);</SCRIPT>";
				}
			}
		} else {
			
			if ($updateid) {
				$othersite = $othersite_mod->GetOne ( 'and id=' . $updateid );
			}
			include ROOT_PATH . '/views/admin/othersite_ajax_form.php';
		}		
		
		
	}
	
	
	/**
	*广告
	*/
	function ad_action()
	{
		$ad_mod=new common('ad');
		
		$updateid=intval($_GET['updateid']);
		if($updateid)
		{
			$ad=$ad_mod->GetOne($showpage);
			
			if($ad)
			{
				$f=explode('-',$ad['adindex']);
				
				if(is_file(ROOT_PATH.'/data/adjs/'.$f[1].'.js'))
				{
					$fp=fopen(ROOT_PATH.'/data/adjs/'.$f[1].'.js','w');
					fwrite($fp,'');
				}
				if(is_file(ROOT_PATH.'/data/adjs/'.$f[1].'.php'))
				{
					$fp=fopen(ROOT_PATH.'/data/adjs/'.$f[1].'.php','w');
					fwrite($fp,'');
				}
				$ad_mod->DeleteData('1 and id='.$updateid);
				sheader('index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad',3,'删除成功','redirect',true);
			}
			else
			{
				sheader('index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad',3,'参数为空','redirect',true);
			}
		}
		else
		{
		$showpage=array('isshow'=>1,'currentpage'=>intval($_REQUEST['page']),'pagesize'=>20,'url'=>'index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad','example'=>3);
		$ad=$ad_mod->GetPage($showpage);

		include ROOT_PATH.'/views/admin/ad.php';
		}

	}
	/**
	*广告操作
	*/
	function admodify_action()
	{
		$updateid=intval($_REQUEST['updateid']);
		$ad=array();
		$ad_mod=new common('ad');
		if(submitcheck('commit'))
		{
			$data['title']=trim(strip_tags($_POST['title']));
			$jsfile=!empty($_POST['adindex'])?str_replace('-','',$_POST['adindex']):'body';
			$data['adindex']=trim(strip_tags(str_replace('-','',$_POST['adtype']).'-'.$jsfile));
			if($_REQUEST['adtype']=='html')
			{
				$data['content']=str_replace('<?','',trim($_REQUEST['content']));
				$data['content']=str_replace('<?php','',$data['content']);
				writefile(ROOT_PATH.'/data/adjs/'.$jsfile.'.htm','<body style="margin:0px;padding:0px;">'.$data['content'].'</body>');
				writefile(ROOT_PATH.'/data/adjs/'.$jsfile.'.js','document.write(\'<iframe style="width:100%;height:100%" scrolling="no" frameborder="0" src="data/adjs/'.$jsfile.'.htm"></iframe>\');');
			}
			else
			{
				if($_FILES['thumb']['name'])
				{
					$thumb=_attach('thumb','data/upload/tempimg');
					foreach($thumb as $k=>$v)
					{
						$addata[]=array('img'=>$v,'url'=>$_POST['url'][$k],'info'=>global_addslashes($_POST['info'][$k]),'width'=>$_POST['width'][$k],'height'=>$_POST['height'][$k]);
					}
				}
				if($_POST['oldthumb'])
				{
					foreach($_POST['oldthumb'] as $k=>$v)
					{
						$addata[]=array('img'=>$v,'url'=>$_POST['oldurl'][$k],'info'=>global_addslashes($_POST['oldinfo'][$k]),'width'=>$_POST['oldwidth'][$k],'height'=>$_POST['oldheight'][$k]);
					}
				}
				
				foreach($addata as $val)
				{
					$content[]="{'img':'".$val['img']."','url':'".$val['url']."','info':'".global_addslashes($val['info'])."','width':'".intval($val['width'])."','height':'".intval($val['height'])."'}";
				}
				writefile(ROOT_PATH.'/data/adjs/'.$jsfile.'.js','var '.$jsfile.'_data=['.implode(',',$content).']');
				$data['content']=serialize($addata);
			}
			
			if($updateid)
			{
				if($ad_mod->UpdateData($data,'and id='.$updateid))
				{
					sheader('index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad',3,'修改成功','redirect',true);
				}
				else
				{
					sheader('index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad',3,'数据未发生变化，修改失败','redirect',true);
				}
			}
			else
			{
				if($insertid=$ad_mod->InsertData($data))
				{
					sheader('index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad',3,'添加成功','redirect',true);
				}
				else
				{
					sheader('index.php?con='.$GLOBALS['setting']['adminpath'].'&act=ad',3,'添加失败','redirect',true);
				}
			}
		}
		else
		{
			if($updateid>0)
			{
				$ad=$ad_mod->GetOne('and id='.$updateid);

				$ad['ad2']=explode('-',$ad['adindex']);
				if($ad['ad2'][0]=='image' || $ad['ad2'][0]=='flash')
				{
					$ad['content']=unserialize($ad['content']);
				}

			}
			include ROOT_PATH.'/views/admin/ad_form.php';
		}
	}
	
	//友情链接
	function link_action()
	{
		$link=new common('link');
		$showpage=array('isshow'=>1,'currentpage'=>intval($_REQUEST['page']),'pagesize'=>20,'url'=>'index.php?con=admin&act=link','example'=>2);
		$linklist=$link->GetPage($showpage,"","","","ORDER BY sortorder DESC");
		include ROOT_PATH.'/views/admin/link.php';
	}
	
	//友情链接修改
	function linkmodify_action()
	{
		$updateid=$_REQUEST['updateid'];
		$link_mod=new common('link');
		if(submitcheck('commit'))
		{
			$data['title'] 		= trim(strip_tags($_POST['title']));
			$data['url']   		= trim($_POST['url']);
			$data['decs']  		= trim(strip_tags($_POST['decs']));
			$data['type']  		= intval($_POST['type']);
			$data['sortorder']  = intval($_POST['sortorder']);
			
			if($_FILES['thumb']['name'])
			{
				$data['thumb']=_upload('thumb','data/upload/link');
			}
			if($updateid>0)
			{
				if($link_mod->UpdateData($data,'and id='.$updateid))
				{
					deletef('link');
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={};objdata.dotype='update';objdata.id='$updateid';objdata.title='".global_addslashes( $data ['title'], 1 )."';objdata.url='".global_addslashes ( $data ['url'], 1 )."';objdata.sortorder='". $data['sortorder']."';objdata.thumb='". $data['thumb']."'; parent.parseMysitecateData(objdata);</SCRIPT>";
				}
			}
			else
			{
				if($id=$link_mod->InsertData($data))
				{
					deletef('link');
					echo "<SCRIPT LANGUAGE='JavaScript'>var objdata={};objdata.dotype='add';objdata.id='$id';objdata.title='".global_addslashes( $data ['title'], 1 )."';objdata.url='".global_addslashes ( $data ['url'], 1 )."';objdata.sortorder='". $data['sortorder']."';objdata.thumb='". $data['thumb']."'; parent.parseMysitecateData(objdata);</SCRIPT>";
					
				}
			}
		}
		else
		{
			if($updateid)
			{
				$link=$link_mod->GetOne('and id='.$updateid);
			}
			include ROOT_PATH.'/views/admin/link_ajax_form.php';
		}
	}


	//自动分类
	function  autocate_action()
	{
		$table=!empty($_REQUEST['table']) && in_array($_REQUEST['table'],array('tempsite','groups'))?$_REQUEST['table']:'tempsite';
		
		if($_REQUEST['start'])
		{
			$start = $_REQUEST['start'];	
			
		}else{
			
			$start = 0;
		}
		$u=$table=='tempsite'?'listtempsite':'listgroup';
		
		$tempsite = new common($table);
		$all_count = $tempsite->GetCount();
		
		if($all_count < $start)
		{
			sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act='.$u, 3, '分类完成！', 'redirect', true );	
		}
		if($table=='tempsite')
		{
			$tempsite_info1 = $tempsite->GetPage(array(),"AND  big_catelist = 0 "," LIMIT $start , 1000");
		}
		else
		{
			$tempsite_info1 = $tempsite->GetPage(array(),"AND  big_catelist >0 and lasttime>".time()." and 	small_catelist>0"," LIMIT $start , 1000");
		}
		//自动匹配商圈
		$bizgroup = new common("bizgroup");
		$tmpbizgroup_info = $bizgroup->GetPage(array());
		$bizgroup_info = array();
		
		foreach($tmpbizgroup_info AS $key => $val)
		{
			$bizgroup_info[$val["cityid"]][] = $val;
		}
		
		foreach($bizgroup_info AS $k => $v)
		{
			foreach($tempsite_info1 AS $k2 => $v2)
			{
				if($v2['cityid'] == $k)
				{
					$my_bizgroup = 	$v['id'];
					$my_bizname  =  $v['bizname'];				
					$tempsite_bizname = $v2['bizname'];
					$tempsite_id      = $v2['id'];       
					similar_text($my_bizname,$tempsite_bizname,$p);
					if($p>60)
					{
						$date['bizgroup'] = $my_bizgroup;
						$data['bizname']  = $my_bizname; 
					    $tempsite->UpdateData($data," AND  id = ".$tempsite_id);   	
					}else{
						$date['bizgroup'] = 0;
						$data['bizname']  = ""; 
					    $tempsite->UpdateData($data," AND  id = ".$tempsite_id);	
					}
				}								
			}
		}
		
		//自动分类
		$catelist = new common("catelist");
		$tmp_cateinfo =$catelist->GetPage(array(),"","","","ORDER BY parentid ASC");
		$cateinfo = array();	
		foreach($tmp_cateinfo AS $key => $val)
		{				
			if($val['parentid'] == 0)
			{
				$cateinfo[$val['id']]=$val;			
			}else{
				$cateinfo[$val['parentid']]['node'][]=$val;
			}
		}	
                
		foreach($cateinfo AS $key => $val)
		{
			$keywords_arr = explode(",",$val['keywords']);
			foreach($tempsite_info1 AS $key2 => $val2)
			{
				foreach($keywords_arr AS $key3 => $val3)
				{
					if(strstr($val2['subject'],$val3))
					{
						$data['big_catelist']          = $val['id'];
						$data['big_catelist_catename'] = $val['catename'];
						$tempsite_info1[$key2]['catetag'] = $val['id'];
						$tempsite->UpdateData($data," AND  id = ".$val2['id']);		
						break;
					}
				}
			}
		
			if($val['node'])
			{ 
				foreach($val['node'] AS $key5 => $val5)
				{
					$keywords2_arr = explode(",",$val5['keywords']);
					foreach($tempsite_info1 AS $key6 => $val6)
					{		
						if($val6['catetag'] == $val5['parentid'])
						{
							foreach($keywords2_arr AS $key7 => $val7)
							{				
								if(strstr($val6['subject'],$val7))
								{
									$updateid = $val6['id'];
									$data2['small_catelist']          = $val5['id'];
									$data2['small_catelist_catename'] = $val5['catename'];
									$tempsite->UpdateData($data2," AND  id = ".$updateid);
									unset($tempsite_info1[$key6]);
						    	   	break;  							
								}
							}
						}
					}				
				}				
			}	
		}
	
		$next_start =$start + 1000;
		sheader ( 'index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . "&act=autocate&start=$next_start&table=$table", 3, "第".$start."到".$next_start."条团购,正在分类请稍等....", 'redirect', true );
	}

	function city2city_action()
	{
		require_once ROOT_PATH.'/inc/curl.class.php';
		$url="http://www.tgwowo.com/api/citytocity.php";

		$city_mod=new common('city');
		$rows=$city_mod->GetPage();
		$fields='`'.implode('`,`',array_keys($rows[0])).'`';
		foreach($rows as $k=>$v)
		{
			$tempdata[]='("'.implode('","',$v).'")';
		}
		$sql="INSERT INTO ".tname("city")."(".$fields.") values ".implode(',',$tempdata).";";
		file_put_contents(ROOT_PATH.'/data/cache/city2citybak.php',"<?php exit;?>\n".$sql);

		$curl = new curl();
		$info = $curl->get($url);
		$info = charset_encode($info,$GLOBALS['charset'],"utf-8");
		$str_city="INSERT INTO ".tname("city")."(cityid,cityname,sortorder,pinyin,isshow)VALUES";
		$str_bizgroup ="INSERT INTO ".tname("bizgroup")." (id,cityid,bizname ) VALUES ";
		$str_info = explode("|-|",$info);
		if(!empty($str_info[0]))
		{
			$str_city    .=$str_info[0];
			$del_city="DELETE FROM ".tname("city");
			$GLOBALS['db']->query($del_city);
			$GLOBALS['db']->query($str_city);
			deletef('city');
		}
		
		if(!empty($str_info[1]))
		{
			$str_bizgroup.=$str_info[1];
			$del_bizgroup="DELETE FROM ".tname("bizgroup");
			$GLOBALS['db']->query($del_bizgroup);
			$GLOBALS['db']->query($str_bizgroup);
			deletef('bizgroup');
		}
		
		echo "true";
	}
	
	function site2site_action()
	{
		include ROOT_PATH.'/models/attach.php';
		$url    = 'http://www.tgwowo.com/api/sitetosite.php?type=xml';
		$apirep = 'infos-info=id:limengqikey-id,sitename:limengqikey-sitename,siteurl:limengqikey-siteurl,breakurl:limengqikey-breakurl,sitetype:limengqikey-sitetype,cityid:limengqikey-cityid,sort:limengqikey-sort,pinyin:limengqikey-pinyin,siteapi:limengqikey-siteapi,localapi:limengqikey-localapi,apikey:limengqikey-apikey,apirep:limengqikey-apirep,css:limengqikey-css,recommend:limengqikey-recommend,isallowed:limengqikey-isallowed,cityapi:limengqikey-cityapi,cityrep:limengqikey-cityrep,citysiteapi:limengqikey-citysiteapi,qq:limengqikey-qq,msn:limengqikey-msn,tel:limengqikey-tel,level:limengqikey-level,logo:limengqikey-logo,email:limengqikey-email,goodorder:limengqikey-goodorder,gather_method:limengqikey-gather_method,breaksuff:limengqikey-breaksuff,limitcity:limengqikey-limitcity,limitnum:limengqikey-limitnum';
		$site=array('site'=>'同步网站','url'=>$url,'apirep'=>$apirep);
		
		$attach=new attach($site);
		$content=$attach->curl->get($site['url']);
		$data=$attach->parse_rule($content,$site['apirep']);
		
		if($data)
		{
			$site_mod=new common('site');
			$rows = $site_mod->GetPage();
			
			$transkey_arr = array();
			foreach($rows AS $key =>$val)
			{
				if($val['transkey']>0)
				{
					$transkey_arr[ $val['transkey']] = $val['id'];	
				}
			}

			$inser_sql  ='';
			$update_sql ='';
			
			foreach($data AS $key => $val)
			{			
				if($transkey_arr[$val['id']])
				{
					$data2['siteurl']   = $val['siteurl'];
					$data2['breaksuff'] = $val['breaksuff'];
					$data2['breakurl']  = $val['breakurl'];	
					$site_mod->UpdateData($data2, "  AND id= ".$transkey_arr[$val['id']]);					
												
				}else{
					
					
					if(!$inser_sql)
					{
						$inser_sql = 'INSERT INTO '.tname("site")." ( ";					
						foreach($val AS $key1 => $val1)
						{		
							if($key1 != 'id')
							{
								$inser_sql.="$key1,";			
							}			
						} 
			
						$inser_sql.="transkey) VALUES ";	
				
					}
					$val['sitename']=charset_encode($val['sitename'],$GLOBALS['charset'],'utf-8');
					$inser_sql.='(';
					foreach($val AS $key3 => $val3)
					{	
						
						if($key3 != 'id')
						{
							$inser_sql.="'".$val3."',";				
						}							
					}

					$inser_sql.="'".$val['id']."'),";
				}
			}
			
			$inser_sql = rtrim($inser_sql,',');
			
			if($inser_sql)
			{
				$GLOBALS['db']->query($inser_sql);
			}
			
		}else{
			
			echo 'false';
			exit;
		}
		
		if(!empty($GLOBALS['setting']['lhaitun_appkey']))
		{
			$d=$site_mod->GetPage();
			foreach($d as $k=>$v)
			{
				$v['breaksuff']=preg_replace('/([\?|&])e=[a-zA-Z0-9]*([&]?)/','\\1e='.$GLOBALS['setting']['lhaitun_appkey'].'\\2',$v['breaksuff']);
				$sql="update ".tname('site')." set `breaksuff`= '".$v['breaksuff']."' where id=".$v['id'];
				$GLOBALS['db']->query($sql);
			}
		}	
		
		echo "true";
		
	}
	
	function cate2cate_action()
	{
		require_once ROOT_PATH.'/inc/curl.class.php';
		$url="http://www.tgwowo.com/api/catetocate.php";

		$cate_mod=new common('catelist');
		$rows=$cate_mod->GetPage();
		$fields='`'.implode('`,`',array_keys($rows[0])).'`';
		foreach($rows as $k=>$v)
		{
			$tempdata[]='("'.implode('","',$v).'")';
		}
		$sql="INSERT INTO ".tname("cate")."(".$fields.") values ".implode(',',$tempdata).";";
		file_put_contents(ROOT_PATH.'/data/cache/cate2catebak.php',"<?php exit;?>\n".$sql);

		$curl = new curl();
		$info = $curl->get($url);
		$info = charset_encode($info,$GLOBALS['charset'],"utf-8");
		$str_cate="INSERT INTO ".tname('catelist')." (`id`, `catename`, `sortorder`, `keywords`, `parentid`) VALUES";
		if($info)
		{
			$str_cate.=$info;
			$del_cate="DELETE FROM".tname('catelist');
			
			$GLOBALS['db']->query($del_cate);
			$GLOBALS['db']->query($str_cate);	
			deletef('cate');
		}
		echo "true";		
	}
	
	
	function  othercate2othercate_action()
	{
		require_once ROOT_PATH.'/inc/curl.class.php';
		$url="http://www.tgwowo.com/api/othercate2othercate.php";
		
		$cate_mod=new common('sitecate');
		$rows=$cate_mod->GetPage();
		$fields='`'.implode('`,`',array_keys($rows[0])).'`';
		foreach($rows as $k=>$v)
		{
			$tempdata[]='("'.implode('","',$v).'")';
		}
		$sql="INSERT INTO ".tname("sitecate")."(".$fields.") values ".implode(',',$tempdata).";";
		file_put_contents(ROOT_PATH.'/data/cache/othercate2othercatebak.php',"<?php exit;?>\n".$sql);

		$curl = new curl();
		$info = $curl->get($url);
		$info = charset_encode($info,$GLOBALS['charset'],"utf-8");
		$str_othersite="INSERT INTO ".tname('sitecate')." (`id`, `sitecatename`, `sortorder`) VALUES";
		$str_othersite.=$info;
		if($info)
		{
			$del_othersite="DELETE FROM".tname('sitecate');
			
			$GLOBALS['db']->query($del_othersite);
			$GLOBALS['db']->query($str_othersite);
			deletef('sitecate');	
		}
		echo "true";			
	}
	
	function  othersite2othersite_action()
	{	
		require_once ROOT_PATH.'/inc/curl.class.php';
		$url="http://www.tgwowo.com/api/othersite2othersite.php";

		$cate_mod=new common('othersite');
		$rows=$cate_mod->GetPage();
		$fields='`'.implode('`,`',array_keys($rows[0])).'`';
		foreach($rows as $k=>$v)
		{
			$tempdata[]='("'.implode('","',$v).'")';
		}
		$sql="INSERT INTO ".tname("othersite")."(".$fields.") values ".implode(',',$tempdata).";";
		file_put_contents(ROOT_PATH.'/data/cache/othersite2othersitebak.php',"<?php exit;?>\n".$sql);

		$curl = new curl();
		$info = $curl->get($url);
		$info = charset_encode($info,$GLOBALS['charset'],"utf-8");
		$str_othersite="INSERT INTO ".tname('othersite')." (`id`, `sitename`, `url`, `cate`, `istop`, `recommend`, `color`, `font`, `sort`,`img`) VALUES";
		if($info)
		{
			$str_othersite.=$info;
			$del_othersite="DELETE FROM".tname('othersite');
			
			$GLOBALS['db']->query($del_othersite);
			$GLOBALS['db']->query($str_othersite);
			
			if(!empty($GLOBALS['setting']['lhaitun_appkey']))
			{
				$site_mod=new common('othersite');
				$d=$site_mod->GetPage();
				foreach($d as $k=>$v)
				{
					$v['url']=preg_replace('/([\?|&])e=[a-zA-Z0-9]*([&]?)/','\\1e='.$GLOBALS['setting']['lhaitun_appkey'].'\\2',$v['url']);
					$sql="update ".tname('othersite')." set `url`= '".$v['url']."' where id=".$v['id'];
					$GLOBALS['db']->query($sql);
				}
			}
		}
		deletef('othersite');
		echo "true";		
	}	

	
	function get_bizgroup_action() {
		
		$cityid = $_REQUEST ['cityid'];
		if($cityid)
		{
			$bizgroup = new common ( 'bizgroup' );
			$tmp_bizgroup = $bizgroup->GetPage ( array (), " AND cityid ='" . $cityid . "'" );
			$listbizgroup = array ();
			$i = 0;
			foreach ( $tmp_bizgroup as $key => $val ) {
				$listbizgroup [$i] ['id'] = $val ['id'];
				$listbizgroup [$i] ['bizname'] = charset_encode($val ['bizname'],'utf-8',$GLOBALS['charset']);
				$i ++;
			}
		
			echo json_encode ( $listbizgroup );
		}else{
			
			echo json_encode (array());
		}
	}
	
	function get_catelist_action() {
		$parentid = $_REQUEST ['parentid'];
		if($parentid > 0)
		{
			
			$catelist = new common ( 'catelist' );
			$tmp_catelist_info = $catelist->GetPage ( array (), " AND parentid = " . $parentid );
			$catelist_info = array ();
			$i = 0;
			foreach ( $tmp_catelist_info as $key => $val ) {
				$catelist_info [$i] ['id'] = $val ['id'];
				$catelist_info [$i] ['catename'] = charset_encode($val ['catename'],'utf-8',$GLOBALS['charset']);
				$i ++;
			}
		
			echo json_encode ( $catelist_info );			
			
		}else{
			
			echo json_encode (array());
			
		}

	}
	
	
	function  get_all_catelist_action()
	{
	
		$catelist = new common ( 'catelist' );
		$tmp_catelist_info = $catelist->GetPage ( array (),"", "", "", "ORDER BY parentid  ASC" );		
		$catelist_info = array ();	
		$node_arr = array();	
		$i = 0;
		foreach ( $tmp_catelist_info as $key => $val ) {
			
			if($val['parentid'] == 0)
			{
				$node_arr[$val['id']]=$val;		
				
			}
			
			if($val['parentid'] > 0)
			{
				$node_arr[$val['parentid']]['child'][]=$val;
				
			}

		} 
		
		
		foreach($node_arr AS $key => $val)
		{
			
			$catelist_info [$i] ['id'] = $val ['id'];
			$catelist_info [$i] ['catename'] = charset_encode($val ['catename'],'utf-8',$GLOBALS['charset']);
			
			$i ++;

			if($val['child'])
			{
				
				foreach($val['child'] AS $key2 => $val2)
				{
					$catelist_info [$i] ['id'] = $val2 ['id'];
					$catelist_info [$i] ['catename'] = "--".charset_encode($val2 ['catename'],'utf-8',$GLOBALS['charset']);
					$i ++;		
				}

			}
			
		}

	
		echo json_encode ( $catelist_info );			
	}
	

	function update_cate_action()
	{
		
		$id   = $_REQUEST['id'];
		$cate = $_REQUEST['cate'];
		$tag  = $_REQUEST['tag'];
		$catelist = new common ( 'catelist' );
		$catelist_info = $catelist->GetOne(" AND id =".$cate);	
		$con_tag =new common($tag);
		
		if($catelist_info['parentid'] == 0)
		{
			
			$data['big_catelist'] = $catelist_info['id']; 
			$data['big_catelist_catename'] = $catelist_info['catename'];
			$data['small_catelist'] = 0; 
			$data['small_catelist_catename'] = "";
		    $con_tag->UpdateData($data, " AND  id =".$id);	
			
		}else{
			
			$p_catelist_info = $catelist->GetOne(" AND id =".$catelist_info['parentid']);
			$data['big_catelist'] = $p_catelist_info['id']; 
			$data['big_catelist_catename'] = $p_catelist_info['catename'];
			$data['small_catelist'] = $catelist_info['id']; 
			$data['small_catelist_catename'] = $catelist_info['catename'];
			$con_tag->UpdateData($data, " AND  id =".$id);	
		}
		
	}
	
	
	function get_all_cityid_action()
	{
		
		$cityid = array();
		$i = 0;
		foreach( $GLOBALS['city'] AS $key => $val)
		{
			$cityid[$i]['cityid']= $key;
			$cityid[$i]['cityname']=charset_encode( $val['cityname'],'utf-8',$GLOBALS['charset']);		
			$i++;
		}
				
		echo json_encode ( $cityid );
	}
	
	function update_cityid_action()
	{	
		$id   = $_REQUEST['id'];
		$data['cityid']   = $_REQUEST['cityid'];	
		$data['cityname'] = $GLOBALS['city'][$data['cityid']]['cityname'];
		$data['bizgroup'] = 0;
		$data['bizname']  = "";

		$tag  = $_REQUEST['tag'];
		$con_tag =new common($tag);
		$con_tag->UpdateData($data, " AND  id =".$id);
	}
	//去除重复值
	function cleanre_action()
	{
		$sql='SELECT min( id ) as id , subject, siteid FROM '.tname('tempsite').' GROUP BY subject, siteid HAVING count( * ) >1';
		$query=$GLOBALS['db']->query($sql);
		while($rows=$GLOBALS['db']->fetch_array($query))
		{
			$usql="update ".tname('tempsite')." set cityname='全国',citysname='全国',cityid='quanguo',sortorder=0 where id=".$rows['id']." and cityid!='quanguo'";
			$GLOBALS['db']->query($usql);
			$dsql="delete from ".tname('tempsite')." where id!=".$rows['id']." and subject='".$rows['subject']."' and siteid=".$rows['siteid'];
			$GLOBALS['db']->query($dsql);
			
		}
		sheader ('index.php?con=' . $GLOBALS ['setting'] ['adminpath'] . '&act=listtempsite', 3, '重复值清理完成', 'redirect', true );
	}
	
	
	function  get_allcate()
	{
		
		$catelist = new common ( 'catelist' );
		$tmp_catelist_info = $catelist->GetPage ( array (),"", "", "", "ORDER BY parentid  ASC" );		
		$catelist_info = array ();	
		$node_arr = array();	
		foreach ( $tmp_catelist_info as $key => $val ) {
			
			if($val['parentid'] == 0)
			{
				$node_arr[$val['id']]=$val;		
				
			}
			
			if($val['parentid'] > 0)
			{
				$node_arr[$val['parentid']]['child'][]=$val;
				
			}
		} 
		
		foreach($node_arr AS $key => $val)
		{
			
			$catelist_info [$val ['id']] ['id'] = $val ['id'];
			$catelist_info [$val ['id']] ['catename'] = $val ['catename'];
			$catelist_info [$val ['id']] ['parentid'] = $val ['parentid'];

			if($val['child'])
			{
				
				foreach($val['child'] AS $key2 => $val2)
				{
					$catelist_info [$val2 ['id']] ['id'] = $val2 ['id'];
					$catelist_info [$val2 ['id']] ['catename'] = $val2 ['catename'];
					$catelist_info [$val2 ['id']] ['parentid'] = $val2 ['parentid'];
				}
			}
		}

		return $catelist_info ;
		
	}
	
	function plugins_action()
	{
		$plugins_mod=new common('plugins');
		$plugins=$plugins_mod->GetPage();
		
		foreach($plugins as $k=>$v)
		{
			$plugins[$k]['pluginsname']=unserialize($plugins[$k]['pluginsname']);
		}
		
		include ROOT_PATH . '/views/admin/plugins.php';
	}
	function pluginsmodify_action()
	{
		$plugins_mod=new common('plugins');
		$updateid=intval($_REQUEST['updateid']);
		if(submitcheck('commit'))
		{
			$d['title']=trim(strip_tags($_REQUEST['title']));
			$d['url']=trim(strip_tags($_REQUEST['url']));
			$d['isshow']=intval($_REQUEST['isshow']);
			$data['pluginsname']=serialize($d);
			
			if ($updateid > 0) {
				if ($plugins_mod->UpdateData ( $data, 'and id=' . $updateid )) {
					deletef('plugins');
					echo "<SCRIPT LANGUAGE='JavaScript'>parent.parseMyCateData();</SCRIPT>";
				}
			} else {
				if ($id = $plugins_mod->InsertData ( $data )) {
					deletef('plugins');
					echo "<SCRIPT LANGUAGE='JavaScript'>parent.parseMyCateData();</SCRIPT>";
				}
			}
		}
		else
		{
			if($updateid)
			{
				$plugins=$plugins_mod->GetOne('and id='.$updateid);
				$plugins['pluginsname']=unserialize($plugins['pluginsname']);
			}
			
			include ROOT_PATH . '/views/admin/plugins_ajax_form.php';
		}
	}
	/*-------------------------------------系统函数----------------------------------------------------------*/
	function _cachedel() {
		if (in_array ( $_GET ['table'], array ('catelist' ) )) {
			if ($_GET ['table'] == 'catelist') {
				deletef ( 'cate' );
			} else {
				deletef ( $_GET ['table'] );
			}
		
		}
	}
	function _checkcode($code) {
		include ROOT_PATH . './models/imgcode.php';
		$imgcode_mode = new Helper_ImgCode ();
		return $imgcode_mode->isValid ( $code );
	}
	//统计团购
	function _groupCount() {
		$group_mod = new common ( 'groups' );
		$group = $group_mod->GetPage ( array ('isshow' => 0 ) );
		$groupcount = array ('ispassed' => 0, 'nopassed' => 0 );
		foreach ( $group as $k => $v ) {
			if ($v ['ispassed']) {
				$groupcount ['ispassed'] ++;
			} else {
				$groupcount ['nopassed'] ++;
			}
		}
		
		return $groupcount;
	}
	//统计未入库
	function _tempCount() {
		$temp_mod = new common ( 'tempsite' );
		$temp = $temp_mod->GetCount ( '', 'id' );
		return $temp;
	}
	//统计会员
	function _userCount() {
		$user_mod = new common ( 'user' );
		$user = $user_mod->GetPage ( array ('isshow' => 0 ) );
		$usercount = array ('siteuser' => 0, 'normaluser' => 0 );
		foreach ( $user as $k => $v ) {
			if ($v ['usertype'] == 'siteuser') {
				$usercount ['siteuser'] ++;
			} else {
				$usercount ['normaluser'] ++;
			}
		}
		return $usercount;
	}
	//统计网站数
	function _siteCount() {
		$site_mod = new common ( 'site' );
		$site = $site_mod->GetPage ( array ('isshow' => 0 ) );
		$sitecount = array ('isallowed' => 0, 'noallowed' => 0 );
		foreach ( $site as $k => $v ) {
			if ($v ['isallowed'] == 1) {
				$sitecount ['isallowed'] ++;
			} else {
				$sitecount ['noallowed'] ++;
			}
		}
		return $sitecount;
	}
	
	
	function getnewsite_action()
	{
		
		include ROOT_PATH.'/models/attach.php';
		$url    = 'http://www.tgwowo.com/api/sitetosite.php?type=xml';
		$apirep = 'infos-info=id:limengqikey-id';
		$site=array('site'=>'同步网站','url'=>$url,'apirep'=>$apirep);
		
		$attach=new attach($site);
		$content=$attach->curl->get($site['url']);
		$data=$attach->parse_rule($content,$site['apirep']);
		
		$allsitenum = count($data);
		$site_mod=new common('site'); 
		$mysitenum = $site_mod->GetCount(' AND transkey  > 0 ');
		$transnum = $allsitenum-$mysitenum;
		
		echo $transnum;
	}
	
	
	
}  