<?
include_once("./_common.php");

if (!$member[mb_id]) alert_close("회원만 이용하실 수 있습니다.");

$open_me	= 1;
if (!$member[mb_open] && $is_admin != "super" && $member[mb_id] != $mb_id) $open_me	= 0;
//-- alert_close("자신의 정보를 공개하지 않으면 다른분의 정보를 조회할 수 없습니다.\\n\\n정보공개 설정은 회원정보수정에서 하실 수 있습니다.");

$mb			= get_member($mb_id);				//-- 회원 기본정보
$zm_mb		= zm_getmember($mb_id);				//-- 회원 추가 정보
if (!$mb[mb_id]) alert_close("회원정보가 존재하지 않습니다.\\n\\n탈퇴하였을 수 있습니다.");
if (!$mb[mb_open] && $is_admin != "super" && $member[mb_id] != $mb_id) alert("$mb[mb_nick]님은 정보공개를 하지 않았습니다.\\n내 프로필로 이동 합니다.", "./profile.php?mb_id=$member[mb_id]");

$g4[title]	= $mb[mb_nick] . "님의 자기소개";
include_once("$g4[path]/head.sub.php");


$mb_nick	= get_sideview($mb[mb_id], $mb[mb_nick], $mb[mb_email], $mb[mb_homepage], $mb[mb_open]);

// 회원가입후 몇일째인지? + 1 은 당일을 포함한다는 뜻
$sql	= " select (TO_DAYS('$g4[time_ymdhis]') - TO_DAYS('$mb[mb_datetime]') + 1) as days ";
$row	= sql_fetch($sql);
$mb_reg_after	= $row[days];

$mb_homepage	= set_http($mb[mb_homepage]);
$mb_profile		= $mb[mb_profile] ? conv_content($mb[mb_profile],0) : "소개 내용이 없습니다.";

//-- ziumsoft. 조회 중인 아이디가 나? -----------
$sid	= "mb_id=".$mb_id;
if($member[mb_id] == $mb_id) $is_me = true; else $is_me = false;

//-- 메인 ---------------------------------------
//-- 배경 이미지
$bginfo	= sql_fetch("select * from $zmb[table_member_pic] where db_id='$member[mb_id]' and db_picno='0'");
if($bginfo[db_filename]) {
	if($bginfo[db_flag] == "1") {			//-- 한번만
		$bgrepeat	= "no-repeat";
	}elseif($bginfo[db_flag] == "2") {		//-- 가로
		$bgrepeat	= "repeat-x";
	}elseif($bginfo[db_flag] == "3") {		//-- 세로
		$bgrepeat	= "repeat-y";
	}elseif($bginfo[db_flag] == "4") {		//-- 가운데
		$bgrepeat	= "no-repeat";
		$bgposition	= "background-position:center center";
	}
	$bgimg		= $g4[path] . "/data/zm.exp/profile/" . $bginfo[db_dir] . "/" . $bginfo[db_filename];
}else{
	$bgimg		= $member_skin_path . "/img/profile_basic_bg.gif";
}
$write_bg	= "<style type='text/css'>body {background-image:url(\"$bgimg\"); background-repeat:$bgrepeat; $bgposition; }</style>";


//-- 관리 ---------------------------------------
if($pcode == "adm") {
	//-- 친구 정보
	if($groupname) $gwhere	= "and f.db_group='$groupname'";
	$fres	= sql_query("select f.*, m.mb_id, m.mb_name, m.mb_nick, m.mb_email, m.mb_datetime, m.mb_homepage from $zmb[table_friend] f left join $g4[member_table] m on ( f.db_friend_id=m.mb_id ) where f.db_id='$member[mb_id]' $gwhere");

	$i			= 0;
	$friendlist	= array();
	while($frd = sql_fetch_array($fres)){
		$friendlist[$i][recno]		= $frd[db_recno];
		$friendlist[$i][id]			= $frd[db_id];
		$friendlist[$i][friend_id]	= $frd[db_friend_id];
		$friendlist[$i][group]		= $frd[db_group];
		$friendlist[$i][state]		= $frd[db_state];
		$friendlist[$i][mb_id]		= $frd[mb_id];
	  if($frd[db_state] == "2") {						//-- 친구 승인 되지 않은 경우 정보를 노출 하지 않음.
		$friendlist[$i][mb_name]	= $frd[mb_name];
		$friendlist[$i][mb_nick]	= $frd[mb_nick];
		$friendlist[$i][mb_email]	= $frd[mb_email];
		$friendlist[$i][mb_homepage]= $frd[mb_homepage];
		$friendlist[$i][mb_date]	= substr($frd[mb_datetime], 0, 10);

		$friendlist[$i][nick]		= get_sideview($frd[mb_id], $frd[mb_nick], $frd[mb_email], $frd[mb_homepage]);
	  }else{
		$friendlist[$i][nick]		= $frd[mb_nick];
	  }
		$i++;
	}

	//-- 그룹 목록
	$grouplist	= array();
	$i			= 0;
	$fgres		= sql_query("select db_group from $zmb[table_friend] where db_state='2' and db_id='$member[mb_id]'");
	while($fgrd = sql_fetch_array($fgres)) {
		if($fgrd[db_group]) {
			$grouplist[$i] = $fgrd[db_group]; 
			$i++; 
		}
	}

	//-- 공개 설정 선택 값
	$chk_open_level	= array();							//-- 공계 수준
	$elem_idx		= $zm_member[profile_open_level];
	if(!$elem_idx) $elem_idx	= "1";
	$chk_open_level[$elem_idx]	= "checked";

	$chk_open_condition	= array();						//-- 공개 조건
	$elem_idx		= $zm_member[profile_open_condition];
	if(!$elem_idx || ($member[mb_open] && $elem_idx=="3")) $elem_idx = "1";
	$chk_open_condition[$elem_idx]	= "checked";
} //-- end adm

//-- 프로필 사진 --------------------------------
if($zm_mb[profile_pic]) $profilepic		= $g4[path]."/data/zm.exp/profile/" . $zm_mb[profile_pic];
else					$profilepic		= $member_skin_path."/img/img_nopic.gif";

//-- 열람하는 회원이 나의 친구인가? 
$myfnd		= sql_fetch("select db_id, db_state from $zmb[table_friend] where db_id='$mb_id' and db_friend_id='$member[mb_id]'");
if($myfnd[db_state] == "2") $is_friend = true; else $is_friend = false;

//-- 단계별 공개 정보 ---------------------------
$myinfo		= array();									//-- 프로필 정보가 들어갈 배열 
$openlevel	= 0;										//-- 공개할 단계

//-- 모두 공개
if($zm_mb[profile_open_condition] == "1") {	
	$openlevel	= $zm_mb[profile_open_level]; 
}
//-- 친구 공개
if($zm_mb[profile_open_condition] == "2" && $is_friend) {	
	$openlevel	= $zm_mb[profile_open_level]; 
}
if(!$open_me && !$is_friend) $openlevel = 0;			//-- 어쨌든 내 정보를 공개하지 않았거나 친구도 아닐 땐 짤 없음.
if($is_me)	$openlevel = 3;

//-- 열람하는 회원이 나보다 레벨이 같거나 높음?
$mb_level	= ($member[mb_level] >= $mb[mb_level]) ?  1 : 0;

//-- 회원정보 -----------------------------------
$myinfo[mb_pic]		= $profilepic;							//-- 프로필 사진
$myinfo[signature]	= $mb[mb_signature];					//-- 서명
$myinfo[nick]		= get_sideview($mb[mb_id], $mb[mb_nick], $mb[mb_email], $mb[mb_homepage]);		//-- 별명
$myinfo[latelogin]	= ($mb_level) ? substr($mb[mb_today_login], 0, 10) : "알수없음";				//-- 최종접속일

$myinfo[lineword]	= 1;									//-- 한줄인사. 1사용, 0 or null 사용안함
$myinfo[joindate]	= ($mb_level) ? substr($mb[mb_datetime], 0, 10) : "알수없음";					//-- 가입일
$myinfo[location]	= ($zm_mb[location]) ? $zm_mb[location] : "비공개";								//-- 접속지역
$myinfo[belong]		= ($zm_mb[belong]) ? $zm_mb[belong] : "비공개";									//-- 소속
$myinfo[email]		= ($mb[mb_email]) ? $mb[mb_email] : "비공개";									//-- 이메일
$myinfo[homepage]	= ($mb_homepage) ? $mb_homepage : "비공개";										//-- 홈페이지
$myinfo[profile]	= ($mb_profile) ? $mb_profile : "비공개";										//-- 자기소개
$myinfo[minialbum]	= 1;									//-- 미니앨범

$myinfo[mblevel]	= $mb[mb_level];						//-- 회원등급
$myinfo[mblevelname]= $zm_levelname[$myinfo[mblevel]];	//-- 등급명 
if(is_numeric($mb[mb_birth]) && substr($mb[mb_birth], 0, 4) < date("Y", $g4[server_time])) 
	$myinfo[age]		= date("Y", $g4[server_time]) - substr($mb[mb_birth], 0, 4);					//-- 나이
$myinfo[age]		= ($myinfo[age]) ? $myinfo[age]:"비공개";
$myinfo[bloodtype]	= ($zm_mb[bloodtype]) ? $zm_mb[bloodtype] : "비공개";							//-- 혈액형
$myinfo[school1]	= ($zm_mb[school1]) ? $zm_mb[school1] : "비공개";								//-- 학교
$myinfo[school2]	= ($zm_mb[school2]) ? $zm_mb[school2] : "비공개";
$myinfo[school3]	= ($zm_mb[school3]) ? $zm_mb[school3] : "비공개";
$myinfo[iphak1]		= ($zm_mb[iphak1]) ? $zm_mb[iphak1] : "비공개";
$myinfo[iphak2]		= ($zm_mb[iphak2]) ? $zm_mb[iphak2] : "비공개";
$myinfo[iphak3]		= ($zm_mb[iphak3]) ? $zm_mb[iphak3] : "비공개";
$myinfo[tel]		= ($mb[mb_hp]) ? $mb[mb_hp] : $mb[mb_tel];										//-- 전화번호
$myinfo[tel]		= ($myinfo[tel]) ? $myinfo[tel] : "비공개";
if($openlevel == 1) {
	$myinfo[minialbum] = $myinfo[lineword] = 0;
	$myinfo[joindate] = $myinfo[location] = $myinfo[belong] = $myinfo[email] = $myinfo[homepage] = $myinfo[profile]	= "비공개";
	$myinfo[mblevel] = $myinfo[age] = $myinfo[bloodtype] = $myinfo[school1] = $myinfo[school2] = $myinfo[school3] = $myinfo[iphak1]	= $myinfo[iphak2] = "비공개";
	$myinfo[mblevelname] = $myinfo[iphak3] = $myinfo[tel] = "비공개 ";
} elseif($openlevel == 2) {
	$myinfo[mblevel] = $myinfo[age] = $myinfo[bloodtype] = $myinfo[school1] = $myinfo[school2] = $myinfo[school3] = $myinfo[iphak1]	= $myinfo[iphak2] = "비공개";
	$myinfo[mblevelname] = $myinfo[iphak3] = $myinfo[tel] = "비공개";
} elseif($openlevel == 3) {
	//-- 모두 공개
} else {										
	//-- G4 기본 스킨을 위한...
	$mb_homepage	= "";
	$mb[mb_level]	= 99;
	$profilepic		= $member_skin_path."/img/img_nopic.gif";
	$mb_nick = $mb[mb_level] = $mb[mb_point] = $mb_profile = "비공개";

	//-- 모두 비공개
	foreach($myinfo as $key=>$value) $myinfo[$key] = "비공개";
	$myinfo[mb_pic]		= $member_skin_path."/img/img_nopic.gif";
}

//-- 미니 앨범 사진 
for($j = 1; $j <= 5; $j++) $myinfo['thumb_pic'.$j]	= $member_skin_path."/img/img_nopic.gif";		//-- 기본으로 빈 이미지를 채움

$q_pic	= sql_query("select * from $zmb[table_member_pic] where db_id='$mb_id'");
while($rd_pic = sql_fetch_array($q_pic)) {
	$pic_path_thumb	= $g4[path] . "/data/zm.exp/profile/" . $rd_pic[db_dir] . "/thumb/" . $rd_pic[db_filename];
	$pic_path		= $g4[path] . "/data/zm.exp/profile/" . $rd_pic[db_dir] . "/" . $rd_pic[db_filename];
	if(file_exists($pic_path_thumb)) {
		$myinfo['thumb_pic'.$rd_pic[db_picno]]	= $pic_path_thumb;
		$myinfo['pic'.$rd_pic[db_picno]]	= $pic_path;
	} else {
		$myinfo['thumb_pic'.$rd_pic[db_picno]]	= $member_skin_path."/img/img_nopic.gif";
		$myinfo['pic'.$rd_pic[db_picno]]	= "";
	}
}
//-----------------------------------------------

//-- 한줄 메모 리스트 ---------------------------
if($myinfo[lineword]) {
	$page_line		= 5;									//-- 한줄에 보여줄 라인 수
	
	$res	= sql_query("select db_recno from $zmb[table_lineword] where db_id='$mb_id'");
	$total_lw_count	= mysql_num_rows($res);

	$total_lw_page = ceil($total_lw_count / $page_line);	//-- 전체 페이지 계산
	if (!$lwpage) { $lwpage = 1; }							//-- 페이지가 없으면 첫 페이지 (1 페이지)
	$from_rec	= ($lwpage - 1) * $page_line;				//-- 시작 열을 구함

	$i			= 0;
	$list_lineword	= array();
	$res_lw		= sql_query("select l.*, m.mb_nick, m.mb_email, m.mb_homepage from $zmb[table_lineword] l left join $g4[member_table] m on (l.db_write_id=m.mb_id) where l.db_id = '$mb_id' order by l.db_recno desc limit $from_rec, $page_line");
	while($rd_lw = sql_fetch_array($res_lw)) {
		foreach($rd_lw as $key=>$value)	{
			$k		= substr($key, 3, strlen($key));
			$list_lineword[$i][$k] = $value;
		}

		$list_lineword[$i][subject]	= cut_str($list_lineword[$i][memo], 90, "");
		$list_lineword[$i][nick]	= get_sideview($list_lineword[$i][write_id], $list_lineword[$i][nick], $list_lineword[$i][email], $list_lineword[$i][homepage]);
		if(substr($list_lineword[$i][datetime], 0, 10) == date("Y-m-d", $g4[server_time])) 
			$list_lineword[$i][date]	= substr($list_lineword[$i][datetime], 11, 5);
		else
			$list_lineword[$i][date]	= substr($list_lineword[$i][datetime], 2, 14);

		$i++;
	}

	//-- 페이징
	$lineword_paging	= get_paging($config[cf_write_pages], $lwpage, $total_lw_page, "$g4[bbs_path]/profile.php?mb_id=$mb_id&lwpage=");
}

echo "<script type='text/javascript' src='$g4[path]/js/sideview.js'></script>";
include_once("$member_skin_path/profile.skin.php");
include_once("$g4[path]/tail.sub.php");
?>