<html>
	<head>
		<title></title>
		<script language='javascript'>
			function addGroup()
			{
				location.href = './add_group.html';
			}
		</script>			
	<head>		
<body>
<?php
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/pgsql.inc");
	
	$objConn = new DB_Sql;
	$enCoding = "set client_encoding = 'uhc'";
	$objConn->query($enCoding);

	$row = 0;
	$table = 0;
	
	$strSql  = "SELECT a.group_seq, a.group_name, b.member_name, b.member_cellphone ";
	$strSql .= "FROM t_group a ";
	$strSql .= "LEFT OUTER JOIN t_group_member b ON a.group_seq = b.group_seq ";
	$strSql .= "WHERE a.deleted_yn = 'N' ";
	$strSql .= "ORDER BY a.group_seq, b.member_name ";
	
	$objConn->query($strSql);

	if($objConn->nf() != 0)
	{		
		$chkFirst = 0;
		while($objConn->next_record())
		{
			if($chkFirst == 0) $pre_group_seq = $objConn->f("group_seq");				
			$group_seq = $objConn->f("group_seq");
			if($pre_group_seq != $group_seq)
			{
				$table++;							
				$row = 0;
			}
			$tmpArr[$table][$row][0] = $group_seq;
			$tmpArr[$table][$row][1] = $objConn->f("group_name");
			$tmpArr[$table][$row][2] = $objConn->f("member_name");
			$tmpArr[$table][$row][3] = $objConn->f("member_cellphone");				
			//echo $table."-".$row."<br>";
			//echo $pre_group_seq."-".$group_seq."<br>";
			$pre_group_seq = $group_seq;
			$row++;
			$chkFirst++;
		}	
		
		echo "<table width='230' border='0'>\n";	
		echo "	<tr>\n";
		echo "		<td colspan='".($table+1)."'>\n";
		echo "			<a href='javascript:addGroup();'>그룹추가</a>\n";
		echo "		</td>\n";
		echo "	</tr>\n";
		for($i=0; $i<($table+1); $i++)
		{	
			if(($i+1)%3 == 0) echo "	<tr align='center'>\n";
				echo "		<td valign='top' height='250'>\n";
				echo "			<table border='0' width='200'>\n";
				echo "				<tr>\n";
				echo "					<td align='center'><b>그룹명#".($i+1)." ".$tmpArr[$i][0][1]."</b></td>\n";
				echo "				</tr>\n";
				echo "			</table>\n";
				echo "		<table border='1' width='200'>\n";		
				for($j=0; $j<sizeof($tmpArr[$i]); $j++)
				{
					echo "				<tr>\n";
					echo "					<td width='10' align='center'>".($j+1)."</td>\n";			
					echo "					<td width='80' align='center'><a href='./mod_member.html?group=".$tmpArr[$i][0][0]."&cell=".$tmpArr[$i][$j][3]."'>".$tmpArr[$i][$j][2]."</a></td>\n";
					echo "					<td width='110'>&nbsp;".$tmpArr[$i][$j][3]."</td>\n";
					echo "				</tr>\n";
				}		
				echo "			</table>\n";
				echo "<div align='right'><a href='./add_member.html?group=".$tmpArr[$i][0][0]."'>멤버추가</a></div>";
				echo "	</td>\n";
			if(($i+1)%3 == 0) echo "	</tr>\n";
		}	
		echo "</table>";	
	}
?>
</body>
</html>