<?php
require_once(dirname(__FILE__)."/config.php");
CheckPurview('group_Main');
require_once(dirname(__FILE__)."/../include/pub_datalist_dm.php");
require_once(dirname(__FILE__)."/../include/inc_functions.php");
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");
$db = new DedeSql(false);
if($action=="close"){
	$ID = ereg_replace("[^0-9]","",$ID);
	if($ID > 0)	$db->ExecuteNoneQuery("UPDATE #@__groups SET ishidden=1 WHERE groupid='$ID'");
}else if($action=="open"){
	$ID = ereg_replace("[^0-9]","",$ID);
	if($ID > 0)	$db->ExecuteNoneQuery("UPDATE #@__groups SET ishidden=0 WHERE groupid='$ID'");
}else if($action=="del"){
	$ID = ereg_replace("[^0-9]","",$ID);
	if($ID > 0) $db->ExecuteNoneQuery("DELETE FROM #@__groups WHERE groupid='$ID'");	
}

function GetGroupstore($id){
	global $db;
	$id = intval($id);
	$row = $db->GetOne("SELECT storename,tops FROM #@__store_groups WHERE storeid='{$id}'");
	if(is_array($row)){
		$store = $row['storename'];
		if(!$row['tops']){
			return $row['storename'];
		}else{
			$rs = $db->GetOne("SELECT storename FROM #@__store_groups WHERE storeid='".$row['tops']."'");
			return $rs['storename'].">".$store;
		}
	}else{
		return_nulls;
	}
}
$db->SetQuery("SELECT * FROM #@__store_groups WHERE tops=0 ORDER BY orders ASC");
$db->Execute(1);
while($rs = $db->GetArray(1)){
	$option .= "<option value='".$rs['storeid']."'>".$rs['storename']."</option>\n";
	$v = $rs['storeid'];
	$db->SetQuery("SELECT * FROM #@__store_groups WHERE tops='{$v}' ORDER BY orders ASC");
	$db->Execute(2);
	while($rs = $db->GetArray(2)){
		$option .= "<option value='".$rs['storeid']."'>--".$rs['storename']."</option>\n";
	}
}

$wheresql = "WHERE groupid>0";
if(!empty($keyword)){
	$wheresql .= " AND (groupname like '%".$keyword."%' OR des like '%".$keyword."%' OR creater like '%".$keyword."%')";
}
if(!empty($username)) $wheresql .= " AND creater like '%".$username."%'";
if($store > 0) $wheresql .= " AND (storeid='".$store."' OR rootstoreid='".$store."')";
$sql = "SELECT * FROM #@__groups $wheresql ORDER BY stime DESC";
$dlist = new DataList();
$dlist->pageSize = 20;
$dlist->SetParameter("username",$username);
$dlist->SetParameter("store",$store);
$dlist->SetParameter("keyword",$keyword);
$dlist->SetSource($sql);
include(dirname(__FILE__)."/templets/group_main.htm");
$dlist->Close();
$db->Close();
?>