$list = @file($dir."default.smo");
$member_info = array();
for($i=0; $i
{
$line = explode("/", substr($list[$i], 2));
$member_info[$i] = array($line[0], $line[1], trim($line[2]));
}
$ids = "";
for($i=0; $i
{
// 사용자는 통과하고 그룹명만으로 비교한다.
if(strstr($member_info[$i][2], ":")) continue;
$name = "{".$member_info[$i][2]."} ";
$users = getFind($member_info[$i][0], $member_info, $i);
if(substr($users, 0, 1) == ",")
$users = substr($users, 1);
$ids .= $name;
$ids .= $users."\n";
}
$path2 = $HOME."/etc/msgtree.tmp";
$fd = fopen($path2, "w");
if(!$fd) return 0;
fwrite($fd, $ids);
fclose($fd);
// 그룹내의 아이디를 찾는다.
function getFind($parent, $member_info, $start)
{
$user1 = "";
$user2 ="";
$user1 = getUser($parent, $member_info, $start);
$count = getChildCount($parent, $member_info);
for($i=$start+1; $i<=($start+$count); $i++)
{
if(strstr($member_info[$i][2], ":")) continue;
$tt = getUser($member_info[$i][0], $member_info, $i);
if(substr($tt, 0, 1) == ",")
$tt = substr($tt, 1);
$user2 .= ",".$tt;
}
$user = $user2 == "" ? $user1 : $user1.$user2;
return $user;
}
// 해당 노드의 자식노드 갯수를 반환
function getChildCount($parent, $member_info)
{
$cnt = 0;
for($i=0; $i
{
if($member_info[$i][1] == $parent)
{
if(!strstr($member_info[$i][2], ":"))
$cnt += getChildCount($member_info[$i][0], $member_info);
$cnt++;
}
}
return $cnt;
}
// 부모번호를 이용해 자식노드를 찾는다.
function getUser($parent, $member_info, $start)
{
$user="";
$first = 0;
$isOne = 1;
$count = getChildCount($parent, $member_info);
for($i=$start; $i<=($start+$count); $i++)
{
if(!strstr($member_info[$i][2], ":")) continue;
if($member_info[$i][1] == $parent)
{
if($first == 0)
{
$user = parse($member_info[$i][2]);
$first = 1;
$isOne = 0;
}
else
{
$isOne = 1;
$user .= (",".parse($member_info[$i][2]));
}
}
}
if($isOne == 0)
$user = ",".$user;
return $user;
}
function parse($str)
{
$tt = explode(":", $str);
return $tt[0];
}