<?php
error_reporting(0);
close_browse();
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
global $db, $CcTvAi_com_userid;
$callback=SafeRequest("callback", "get");
if ($CcTvAi_com_userid) {
	$cd_fgid=SafeRequest("fgid", "get");
	$cd_uid=SafeRequest("uid", "get");
	if(!IsNumID($CcTvAi_com_userid)) {exit();}
	if(!IsNumID($cd_uid)) {exit();}
	if(!IsNumID($cd_fgid)) {exit();}
	$cd_fgName=unescape(SafeRequest("fg_name", "get"));
	$querys="select cd_id from " . tname('friendgroup') . " where cd_id='$cd_fgid'";
	if ($rows=$db->getrow($querys)) {
		if ($cd_fgName=='') {
			exit($_GET['callback'] . '({"error":10007})');
		}
		if (mb_strlen($cd_fgName, 'UTF8')>7) {
			exit($_GET['callback'] . '({"error":10006})');
		}
		$showstr='[';
		$db->query("update " . tname('friendgroup') . " set cd_name='" . $cd_fgName . "' where cd_uid='" . $CcTvAi_com_userid . "' and cd_id='" . $cd_fgid . "'");
		$query=$db->query("select * from " . tname('friendgroup') . " where cd_uid='$CcTvAi_com_userid' order by cd_id asc LIMIT 0,10");
		while ($row=$db->fetch_array($query)) {
			$showstr=$showstr . '{"fgid":"' . $row['cd_id'] . '","uid":"' . $row['cd_uid'] . '","fg_name":"' . $row['cd_name'] . '","num":"' . $row['cd_count'] . '"},';
		}
		$showstr=$showstr . ']';
		$showstr=ReplaceStr($showstr, ",]", "]");
		exit($_GET['callback'] . '({"error":' . $showstr . ',"data":{"uid":' . $cd_uid . ',"fgid":' . $cd_fgid . ',"is_quietly":0}})');
	} else {
		exit($_GET['callback'] . '({"error":20002})');
	}
} else {
	exit($_GET['callback'] . '({"error":20001})');
}
?>