<?php
require_once(dirname(__FILE__)."/config.php");
require_once(dirname(__FILE__)."/../include/inc_photograph.php");
require_once(dirname(__FILE__)."/../include/pub_oxwindow.php");
require_once(dirname(__FILE__)."/../member/inc/inc_archives_functions.php");
if(!isset($id)) $id = NULL;
$ID = ereg_replace("[^0-9]","",$id);
if($ID < 1){
	ShowMsg("含有非法操作!.","-1");
	exit();
}
$db = new DedeSql(false);

//取出圈子信息
$row = $db->GetOne("SELECT * FROM #@__groups WHERE groupid='{$ID}'");
if(!is_array($row)){
	$db->Close();
	ShowMsg("圈子不存在!","-1");
	exit();
}
$groupsname = $row['groupname'];
$groupstoreid = $row['storeid'];
$groupishidden = $row['ishidden'];
$groupissystem = $row['issystem'];
$groupcreater = $row['creater'];
$groupimg     = $row['groupimg'];
$ismaster     = $row['ismaster'];
$groupdes     = $row['des'];
$groupuid     = $row['uid'];
$groupisindex = $row['isindex'];
$groupsmalltype = $row['smalltype'];
if($cfg_ml->M_ID!=$groupuid){
	$db->Close();
	ShowMsg("该圈子不在你的管辖范围内!","-1");
	exit();
}
//编译小分类成数组
$smalltypes    = @explode(",",$row['smalltype']);
if(!isset($action)) $action = NULL;
if($action=="save"){
 $groupname = cn_substr($groupname,75);
 $storeid = ereg_replace("[^0-9]","",$store);
 $description = cn_substr($des,100);
 $row = $db->GetOne("SELECT tops FROM #@__store_groups WHERE storeid='{$storeid}'");
 if($row['tops'] >0 ) $rootstoreid = $row['tops'];
 else $rootstoreid = $storeid;
 //处理上传的缩略图
 if(!empty($litpic)) $litpic = GetUpImage('litpic',true,true,100,70);
 else $litpic = $groupimg;
 $inQuery = "UPDATE #@__groups SET groupname='".$groupname."',des='".$description."',groupimg='".$litpic."',rootstoreid='{$rootstoreid}',storeid='{$storeid}' WHERE groupid='{$ID}' AND uid='".$cfg_ml->M_ID."';";
 $db->SetQuery($inQuery);
 if(!$db->ExecuteNoneQuery()){
 	echo $db->GetError();
 	$db->Close();
	ShowMsg("把数据更新到数据库groups表时出错，请检查！","-1");
	exit();
 }else{
	ShowMsg("成功更改圈子设置！","-1");
	exit(); 
 }
}
//类目递归
$db->SetQuery("SELECT * FROM #@__store_groups WHERE tops=0 ORDER BY orders ASC");
$db->Execute(1);
$option = '';
while($rs = $db->GetArray(1)){
	$selected = "";
	if($rs['storeid']==$groupstoreid) $selected = "selected='selected'";
	$option .= "<option value='".$rs['storeid']."' ".$selected.">".$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)){
		$selected = "";
		if($rs['storeid']==$groupstoreid) $selected = "selected='selected'";
		$option .= "<option value='".$rs['storeid']."' ".$selected.">--".$rs['storename']."</option>\n";
	}
}
require_once(dirname(__FILE__)."/templets/mygroup_manage.htm");
$db->Close();
?>