<?
require_once('include/global.php');
require_once("include/admin_lib.php");
require_once("include/member_lib.php");
require_once('include/member_group_lib.php');

// check
if (!$_POST['sa_d_no'] || !$_GET['m_no'] || !$_POST['m_name'] || !$_POST['m_level'])
	msg("올바른 URL로 접근하여 주십시오.");


$mbr = member_info($_GET['m_no']);		// array

// [2006-11-02] 관리자모드일때, 관리자는 서버관리자의 정보를 변경할 수 없도록함.
	if ($mbr['m_level'] > $AUTH['auth_m_level'])
		msg("자신보다 높은 [".$G['LEVEL_NAME'][$G['LEVEL']['serveradmin']]."]레벨의 계정은 수정/삭제가 불가능합니다.");


if ($_GET['mode_sadmin'])
{
	auth_limit("serveradmin");

	// 사용가능한 도메인인지 확인.
		$sql = "SELECT d_name FROM ".$TB['DOMAIN']." WHERE d_no='". $_POST['sa_d_no'] . "' AND d_is_use='Y' ";
		$G_SYS['MAIL_DOMAIN'] = db_get_one($sql);
		if ($G_SYS['MAIL_DOMAIN'] == '')
			msg("존재하지 않거나 사용할 수 없는 도메인입니다.\\n\\n확인후 다시 시도하여 주십시오.");
		$d_no = $_POST['sa_d_no'];
} else
{
	auth_limit("admin");

	$_POST['sa_d_no'] = $G['DINFO']['d_no'];
	$d_no = $AUTH['auth_d_no'];     // 관리자는 자신이 속한 도메인의 회원만 수정 가능
}	// if()


// set
	$_POST['m_quota'] = $_POST['m_quota']*1024;
	$_POST['m_bigfile_quota'] = $_POST['m_bigfile_quota']*1024;
	$_POST['m_webhard_quota'] = $_POST['m_webhard_quota']*1024;


// 메일용량 할당량 제한
	mbr_mod_limit($_GET['m_no'], $_POST['m_quota'], $_POST['m_bigfile_quota'], $_POST['m_webhard_quota']);


// [2006-03-08] 메일서버가 동작중인지 확인
	mail_server_check_limit();

// get
	$mf = get_member_field();


// set
	// data
		$data2 = array();       // 조건에 따라 추가되는 업데이트 데이터

		#$m_id = strtolower($m_id);		// 소문자만 허용
		$m_jumin = $m_jumin_1 . "-" . $m_jumin_2;

		if ($m_birthday_1 && $m_birthday_2 && $m_birthday_3)
			$m_birthday = $m_birthday_1 . "-" . sprintf("%02d", $m_birthday_2) . "-" . sprintf("%02d", $m_birthday_3);

		$m_mobile = $m_mobile_1 . "-" . $m_mobile_2 . "-" . $m_mobile_3;
		$m_home_tel = $m_home_tel_1 . "-" . $m_home_tel_2 . "-" . $m_home_tel_3;
		//$m_home_zipcode = $m_home_zipcode_1 . "-" . $m_home_zipcode_2;
		$m_office_tel = $m_office_tel_1 . "-" . $m_office_tel_2 . "-" . $m_office_tel_3;
		$m_office_fax = $m_office_fax_1 . "-" . $m_office_fax_2 . "-" . $m_office_fax_3;
		//$m_office_zipcode = $m_office_zipcode_1 . "-" . $m_office_zipcode_2;

		if ($m_marrydate_1 && $m_marrydate_2 && $m_marrydate_3)
			$m_marrydate = $m_marrydate_1 . "-" . sprintf("%02d", $m_marrydate_2) . "-" . sprintf("%02d", $m_marrydate_3);

		if (trim($m_homepage) == "http://" ) $m_homepage = NULL;

		if ($m_date1_1 && $m_date1_2 && $m_date1_3)
			$m_date1 = $m_date1_1 . "-" . sprintf("%02d", $m_date1_2) . "-" . sprintf("%02d", $m_date1_3);
		if ($m_date2_1 && $m_date2_2 && $m_date2_3)
			$m_date2 = $m_date2_1 . "-" . sprintf("%02d", $m_date2_2) . "-" . sprintf("%02d", $m_date2_3);
		if ($m_date3_1 && $m_date3_2 && $m_date3_3)
			$m_date3 = $m_date3_1 . "-" . sprintf("%02d", $m_date3_2) . "-" . sprintf("%02d", $m_date3_3);
		if ($m_date4_1 && $m_date4_2 && $m_date4_3)
			$m_date4 = $m_date4_1 . "-" . sprintf("%02d", $m_date4_2) . "-" . sprintf("%02d", $m_date4_3);
		if ($m_date5_1 && $m_date5_2 && $m_date5_3)
			$m_date5 = $m_date5_1 . "-" . sprintf("%02d", $m_date5_2) . "-" . sprintf("%02d", $m_date5_3);


	// query
		#$m_id = to_db_str($m_id, $mf[m_id][length], "STRIP_TAGS");
//		$m_pwd = to_db_str($m_pwd, $mf[m_pwd][length]);
		$m_lostpwd_q = to_db_str($m_lostpwd_q, $mf[m_lostpwd_q][length]);
		$m_lostpwd_a = to_db_str($m_lostpwd_a, $mf[m_lostpwd_a][length]);
		$m_name = to_db_str($m_name, $mf[m_name][length], "STRIP_TAGS");
		$m_last_name = to_db_str($m_last_name, $mf[m_last_name][length], "STRIP_TAGS");
		$m_email = to_db_str($m_email, $mf[m_email][length], "STRIP_TAGS");
		$m_homepage = to_db_str($m_homepage, $mf[m_homepage][length], "STRIP_TAGS");
		$m_jumin = to_db_str($m_jumin, 14);
		$m_mobile = to_db_str($m_mobile, $mf[m_mobile][length]);
		$m_home_tel = to_db_str($m_home_tel, $mf[m_home_tel][length]);
		$m_home_zipcode = to_db_str($m_home_zipcode, $mf[m_home_zipcode][length]);
		$m_home_addr1 = to_db_str($m_home_addr1, $mf[m_home_addr1][length]);
		$m_home_addr2 = to_db_str($m_home_addr2, $mf[m_home_addr2][length]);
		$m_office = to_db_str($m_office, $mf[m_office][length]);
		$m_office_subject = to_db_str($m_office_subject, $mf[m_office_subject][length]);
		$m_office_tel = to_db_str($m_office_tel, $mf[m_office_tel][length]);
		$m_office_zipcode = to_db_str($m_office_zipcode, $mf[m_office_zipcode][length]);
		$m_office_addr1 = to_db_str($m_office_addr1, $mf[m_office_addr1][length]);
		$m_office_addr2 = to_db_str($m_office_addr2, $mf[m_office_addr2][length]);
		$m_memo = to_db_str($m_memo, $mf[m_memo][length]);
		$m_etc1 = to_db_str($m_etc1, $mf[m_etc1][length]);
		$m_etc2 = to_db_str($m_etc2, $mf[m_etc2][length]);
		$m_etc3 = to_db_str($m_etc3, $mf[m_etc3][length]);
		$m_etc4 = to_db_str($m_etc4, $mf[m_etc4][length]);
		$m_etc5 = to_db_str($m_etc5, $mf[m_etc5][length]);
		$m_date1 = to_db_str($m_date1, $mf[m_date1][length]);
		$m_date2 = to_db_str($m_date2, $mf[m_date2][length]);
		$m_date3 = to_db_str($m_date3, $mf[m_date3][length]);
		$m_date4 = to_db_str($m_date4, $mf[m_date4][length]);
		$m_date5 = to_db_str($m_date5, $mf[m_date5][length]);

		// [2025-09-08] 사번 항목 추가.
		$m_emp_no = to_db_str($m_emp_no, $mf[m_emp_no][length]);

		// [2013-07-08] 비밀번호 안전 레벨
		if ($_POST['m_pwd'] != '')
		{
			$password_security_alert = member_password_security($_POST['m_pwd'], $mbr['m_id']);
			if ($password_security_alert != '')
				msg("입력하신 비밀번호는 사용할 수 없습니다.\\n\\n사유 : ".$password_security_alert);
		}	// if()

		if ($_POST['m_pwd']) {
			$data2['m_pwd'] = pwd_enc(stripslashes($_POST['m_pwd']), $mbr['m_id']);
		}


		// admin
		// 관리자모드일때, 관리자의 서버관리자의 정보를 변경할 수 없도록함.
			if ($mbr['m_level'] > $AUTH['auth_m_level'] || $m_level > $AUTH['auth_m_level'])
			{
				msg("[".$G['LEVEL_NAME'][$G['LEVEL']['serveradmin']]."]의 경우 레벨 항목은 수정되지 않습니다.", 0);
			} else
			{
				if ($m_level) {
					$data2['m_level'] = $m_level;
				}

				// [2013-02-07] 메일계정 할당수 제한
				if ($mbr['m_level'] == $G[LEVEL][wait] && $m_level > $G[LEVEL][wait])
					mbr_add_limit(0, 0, 0);
			}	// if()

		#$q_m_id = ($m_id) ? " m_id = '$m_id', " : "";

		if ($m_name) {
			$data2['m_name'] = $m_name;
		}

		if (strlen($m_jumin) == 14) {
			$data2['m_jumin'] = $m_jumin;
		}

		// 조직 갱신
		$mg_no_default = member_group_rel_update($_GET['m_no'], $_POST['mg_no'], $isReset=true);
		if ($mg_no_default > 0)
			$data2['mg_no'] = $mg_no_default;
		else
			$data2['mg_no'] = null;


	// default
		// [2008-07-23] 관리자의 수정은 기록하지 않음.
		//$m_last_modifydate = date("Y-m-d H:i:s");
		//$m_last_modifyhost = $_SERVER[REMOTE_ADDR];


	// 업로드 되었을때 새 파일이름을 저장하고, 기존 파일 유지시 기존 파일이름 저장.
		// [2015-10-01] upload file 유효성 문제개선
		$m_file1 = $_FILES[m_file1][tmp_name];
		$m_file2 = $_FILES[m_file2][tmp_name];
		$m_file3 = $_FILES[m_file3][tmp_name];
		$m_file4 = $_FILES[m_file4][tmp_name];
		$m_file5 = $_FILES[m_file5][tmp_name];
		$m_file1_dbname = (is_uploaded_file($m_file1)) ? $_FILES[m_file1][name] : $m_file1_old;
		$m_file2_dbname = (is_uploaded_file($m_file2)) ? $_FILES[m_file2][name] : $m_file2_old;
		$m_file3_dbname = (is_uploaded_file($m_file3)) ? $_FILES[m_file3][name] : $m_file3_old;
		$m_file4_dbname = (is_uploaded_file($m_file4)) ? $_FILES[m_file4][name] : $m_file4_old;
		$m_file5_dbname = (is_uploaded_file($m_file5)) ? $_FILES[m_file5][name] : $m_file5_old;


// proc
	// db update
		$data = array(
			'm_emp_no'         => $m_emp_no,
			'm_lostpwd_q'      => $m_lostpwd_q,
			'm_lostpwd_a'      => $m_lostpwd_a,
			'm_last_name'      => $m_last_name,
			'm_email'          => $m_email,
			'm_homepage'       => $m_homepage,
			'm_sex'            => $m_sex,
			'm_birthday'       => $m_birthday,
			'm_birthday_east'  => $m_birthday_east,
			'm_mobile'         => $m_mobile,
			'm_home_tel'       => $m_home_tel,
			'm_home_zipcode'   => $m_home_zipcode,
			'm_home_addr1'     => $m_home_addr1,
			'm_home_addr2'     => $m_home_addr2,
			'm_job'            => $m_job,
			'm_office'         => $m_office,
			'm_office_subject' => $m_office_subject,
			'm_office_tel'     => $m_office_tel,
			'm_office_fax'     => $m_office_fax,
			'm_office_zipcode' => $m_office_zipcode,
			'm_office_addr1'   => $m_office_addr1,
			'm_office_addr2'   => $m_office_addr2,
			'm_ismarry'        => $m_ismarry,
			'm_marrydate'      => $m_marrydate,
			'm_isremail'       => $m_isremail,
			'm_memo'           => $m_memo,
			'm_etc1'           => $m_etc1,
			'm_etc2'           => $m_etc2,
			'm_etc3'           => $m_etc3,
			'm_etc4'           => $m_etc4,
			'm_etc5'           => $m_etc5,
			'm_date1'          => $m_date1,
			'm_date2'          => $m_date2,
			'm_date3'          => $m_date3,
			'm_date4'          => $m_date4,
			'm_date5'          => $m_date5,
			'm_file1'          => $m_file1_dbname,
			'm_file2'          => $m_file2_dbname,
			'm_file3'          => $m_file3_dbname,
			'm_file4'          => $m_file4_dbname,
			'm_file5'          => $m_file5_dbname,
			'm_quota'          => $_POST['m_quota'],
			'm_bigfile_quota'  => $_POST['m_bigfile_quota'],
			'm_webhard_quota'  => $_POST['m_webhard_quota'],
			'mc_no'            => $_POST['mc_no'],
			'm_cfg_from_addr'  => $_POST['m_cfg_from_addr'],
		);
		$data = array_merge($data, $data2);

		if (isset($_POST['m_team_mail_is_use'])) {
			$data['m_team_mail_is_use'] = $_POST['m_team_mail_is_use'];
		}

		db_update($TB[MEMBER], $data, 'm_no = ? AND d_no = ?', array($_GET['m_no'], $d_no));

	// old file delete
		require_once("include/file.php");
		$errorMsg = NULL;

		// 새파일이 업로드되었을때 기존파일 삭제
		if ( is_uploaded_file($m_file1) ) $errorMsg .= file_del($m_file1_old, $_GET['m_no'], $UPLOAD_DIR[MEMBER]);
		if ( is_uploaded_file($m_file2) ) $errorMsg .= file_del($m_file2_old, $_GET['m_no'], $UPLOAD_DIR[MEMBER]);
		if ( is_uploaded_file($m_file3) ) $errorMsg .= file_del($m_file3_old, $_GET['m_no'], $UPLOAD_DIR[MEMBER]);
		if ( is_uploaded_file($m_file4) ) $errorMsg .= file_del($m_file4_old, $_GET['m_no'], $UPLOAD_DIR[MEMBER]);
		if ( is_uploaded_file($m_file5) ) $errorMsg .= file_del($m_file5_old, $_GET['m_no'], $UPLOAD_DIR[MEMBER]);


	// file upload
		$errorMsg .= file_up($m_file1, $_FILES[m_file1][name], $_FILES[m_file1][size], $UPLOAD_DIR[MEMBER], $_GET['m_no'], "ALL");
		$errorMsg .= file_up($m_file2, $_FILES[m_file2][name], $_FILES[m_file2][size], $UPLOAD_DIR[MEMBER], $_GET['m_no'], "ALL");
		$errorMsg .= file_up($m_file3, $_FILES[m_file3][name], $_FILES[m_file3][size], $UPLOAD_DIR[MEMBER], $_GET['m_no'], "ALL");
		$errorMsg .= file_up($m_file4, $_FILES[m_file4][name], $_FILES[m_file4][size], $UPLOAD_DIR[MEMBER], $_GET['m_no'], "ALL");
		$errorMsg .= file_up($m_file5, $_FILES[m_file5][name], $_FILES[m_file5][size], $UPLOAD_DIR[MEMBER], $_GET['m_no'], "ALL");


	// 웹메일용 처리 - 비밀번호만 변경.
	if ($_POST['m_pwd']) {
		mbr_mod($mbr['m_id'], $_POST['m_pwd']);
	}

	// [2008-10-21] 메일용량 갱신
	mbr_quota_mod($mbr['m_id'], $_POST['m_quota']);

	// [2006-08-08] 사용자 상태 갱신
	mbr_stats_update($_GET['m_no']);

	// [2025-07-29] 메일계정 관리 로그 개선
	mbr_proc_log($mbr['d_no'], $_GET['m_no'], $mbr['m_id'], 'MODMA');

// view
	if ($errorMsg)
		msg("메일 계정이 수정되었습니다.".$errorMsg, 0);

	movepage('admin_mbr_list.php?'.get_qs('mode'));

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