<?
require_once('include/global.php');
require_once("include/mail_lib.php");
require_once('include/pager.php');
require_once('include/addr_lib.php');
require_once('include/member_group_lib.php');
require_once('conf.inc.php');


// default
	if (!$_GET['type'])
	{
		if ($_GET['share'])
		{
			$_GET['type'] = 'S';		// 공용주소록
		} else
		{
			$_GET['type'] = 'G';		// 조직도
		}	// if()
	}	// if()


// data
if ($_GET['type'] == 'G')
{
	if ($G['DINFO']['d_mbrgrp_isuse'] == 'N')
		msg("조직도 사용이 제한되었습니다.\\n\\n관리자에게 문의하여 주십시오.");

	if (member_group_deny_check())
		msg("조직도를 사용할 수 없는 [".$AUTH['auth_mg_name']."]조직입니다.\\n\\n관리자에게 문의하여 주십시오.");


	// search


	// 조직 목록

		// data
			$DEBUG['mg_list_get']['start'] = getmicrotime();
			require_once('include/member_group_lib.php');
			$cg = new NmailMemberGroup;

			// [2008-08-13] 조직도 - 특정 조직만 조직도에서 제외하고, 사용을 제한하기(기본그룹으로만 제한함).
			$q_where_cg = '';
			if (is_array($G_SYS['MBR_GRP_DENY_MG_NO']) && sizeof($G_SYS['MBR_GRP_DENY_MG_NO']) > 0)
				$q_where_cg = " AND mg_no NOT IN (".implode($G_SYS['MBR_GRP_DENY_MG_NO'], ',').") ";

			$cg_data = $cg->getRowsByParent(0, 255, 1, "AND d_no='".$AUTH['auth_d_no']."'".$q_where_cg);
			$cg_data_cnt = (is_array($cg_data[$cg->field_key])) ? sizeof($cg_data[$cg->field_key]) : 0;
			$DEBUG['mg_list_get']['exec'] += getmicrotime() - $DEBUG['mg_list_get']['start'];


		// tree
			$DEBUG['mg_list_tree']['start'] = getmicrotime();

			require_once('addon/HTML_TreeMenu/TreeMenu.php');
			$menu  = new HTML_TreeMenu();

			// 조직
				$node = array();
				$node[0] = new HTML_TreeNode(
					array(
						'text' => lang_conv('조직도'), 
						'link' => "", 
						'icon' => 'folder_root.gif', 
						'expandedIcon' => 'folder_root.gif', 
						'expanded' => true, 
						'cssClass' => 'treeMenuBold'
						), 
					array(
						'onClick' => "parent.addr_list_update('".$_GET['type']."', '0', ''); treeMenuClick(this, true);", 
						'onMouseOver' => "treeMenuOver(this, 'treeMenuDefaultOver')", 
						'onMouseOut' => "treeMenuOut(this, 'treeMenuBold')"
						)
					);
				for ($i=0; $i<$cg_data_cnt; $i++)
				{
					$node[$cg_data[$cg->field_key][$i]] = &$node[$cg_data[$cg->field_parent][$i]]->addItem(
						new HTML_TreeNode(
							array(
								'text' => $cg_data[$cg->field_name][$i], 
								'link' => "", 
								'icon' => 'folder.gif', 
								'expandedIcon' => 'folder-expanded.gif'
								), 
							array(
								'onClick' => "parent.addr_list_update('".$_GET['type']."', '".$cg_data[$cg->field_key][$i]."', ''); treeMenuClick(this, false);", 
								'onMouseOver' => "treeMenuOver(this, 'treeMenuDefaultOver')", 
								'onMouseOut' => "treeMenuOut(this, 'treeMenuDefault')"
								)
							)
						);
				}	// for()
				$menu->addItem($node[0]);
				unset($node);

			// tree make
				$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => $nmpath.'/addon/HTML_TreeMenu/img', 'defaultClass' => 'treeMenuDefault'));
			$DEBUG['mg_list_tree']['exec'] += getmicrotime() - $DEBUG['mg_list_tree']['start'];

} else
{

	if ($_GET['type'] == 'S')
	{
		$_GET['share'] = 1;
		$addr_name = lang_conv('공용주소록');

		if ($G['DINFO']['d_shareaddr_isuse'] == 'N')
			msg("공용주소록 사용이 제한되었습니다.\\n\\n관리자에게 문의하여 주십시오.");
	} else 
	{
		$_GET['share'] = 0;		
		$addr_name = lang_conv('개인주소록');
	}	// if()

	// [2006-07-11] 공용주소록 구분
	set_addr_no_isshare($_GET['s_adg_no'], $_GET['share']);


	// 주소록 그룹
		//$addr_group = get_addr_group();
		// [2012-10-15] 주소록 그룹 트리 지원
		$cg = get_addr_group_tree_class();
		$cg_data = $cg->getRowsByParent(0, 255, 1, "AND " . get_addr_group_where());
		$cg_data_cnt = $cg->getRowsCount($cg_data);

	// tree
		$DEBUG['mg_list_tree']['start'] = getmicrotime();

		require_once('addon/HTML_TreeMenu/TreeMenu.php');
		$menu  = new HTML_TreeMenu();

		// 조직
			$node = array();
			$node[0] = new HTML_TreeNode(
				array(
					'text' => $addr_name, 'link' => "", 
					'icon' => 'folder_root.gif', 
					'expandedIcon' => 'folder_root.gif', 
					'expanded' => true, 
					'cssClass' => 'treeMenuBold'
					), 
				array(
					'onclick' => "parent.addr_list_update('".$_GET['type']."', '0', ''); treeMenuClick(this, true);", 
					'onMouseOver' => "treeMenuOver(this, 'treeMenuDefaultOver')", 
					'onMouseOut' => "treeMenuOut(this, 'treeMenuBold')"
					)
				);
			for ($i=0; $i<$cg_data_cnt; $i++)
			{
				$node[$cg_data[$cg->field_key][$i]] = &$node[$cg_data[$cg->field_parent][$i]]->addItem(
					new HTML_TreeNode(
						array(
							'text' => $cg_data[$cg->field_name][$i],
							'link' => "", 
							'icon' => 'folder.gif', 
							'expandedIcon' => 'folder-expanded.gif'
							), 
						array(
							'onclick' => "parent.addr_list_update('".$_GET['type']."', '".$cg_data[$cg->field_key][$i]."', ''); treeMenuClick(this, false);",
							'onMouseOver' => "treeMenuOver(this, 'treeMenuDefaultOver')", 
							'onMouseOut' => "treeMenuOut(this, 'treeMenuDefault')"
							)
						)
					);
			}	// for()
			$menu->addItem($node[0]);
			unset($node);

		// tree make
			$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => $nmpath.'/addon/HTML_TreeMenu/img', 'defaultClass' => 'treeMenuDefault'));
		$DEBUG['mg_list_tree']['exec'] += getmicrotime() - $DEBUG['mg_list_tree']['start'];
}	// if()




// skin view
	nskinset('webmail', 'addr_select_group.html', 'iframe');
	include($NSKIN['view_layout']);


require_once('include/global_end.php');
?>