<?
/*********************************** 관리자 정보 *************************************/

//관리자 정보 가져오기
function getAdminInfo($id){
    $sql  = "SELECT * ";
    $sql .= "FROM ".$GLOBALS["_conf_tbl"]["admin"]." ";
    $sql .= "WHERE a_id = '$id' ";
    $rs = mysql_query($sql, $GLOBALS[dblink]);
    $total_rs = mysql_num_rows($rs);
    
    if($total_rs > 0){
        $list['total'] = $total_rs;
        for($i=0; $i < $total_rs; $i++){
            $list['list'][$i] = mysql_fetch_assoc($rs);
        }
    }else{
        $list['total'] = 0;
    }
    return $list;
}

//관리자 등록
function inputAdmin(){
	$sql = "insert into ".$GLOBALS["_conf_tbl"]["admin"]." SET 
		a_id= '".mysql_real_escape_string($_POST[id])."',
		a_grade = 'ADMIN',
		a_date = now()
	";

	$rsf = mysql_query($sql,$GLOBALS[dblink]);
	
	$total = mysql_affected_rows($GLOBALS[dblink]);

	if($total > 0){
		return true;
	}else{
		return false;
	}
}

//관리자 수정
function updateAdmin($idx){
	//접근권한
	for($i=0; $i < count($_POST[a_auth]); $i++){
			$str_a_auth .= $_POST[a_auth][$i];
			if($i != count($_POST[a_auth])-1){
					$str_a_auth .= ",";
			}
	}

	$sql = "UPDATE ".$GLOBALS["_conf_tbl"]["admin"]." SET 
		a_pw= '".mysql_real_escape_string($_POST[a_pw])."',
		a_name= '".mysql_real_escape_string($_POST[a_name])."',
		a_class= '".mysql_real_escape_string($_POST[a_class])."',
		a_phone= '".mysql_real_escape_string($_POST[a_phone])."',
		a_email= '".mysql_real_escape_string($_POST[a_email])."',
		a_grade= '".mysql_real_escape_string($_POST[a_grade])."',
		a_auth= '".$str_a_auth."'
		WHERE idx = '$idx'
	";

	$rsf = mysql_query($sql,$GLOBALS[dblink]);

	if($rsf){
		return true;
	}else{
		return false;
	}
}

//관리자 수정
function updateAdminAuth(){
	$tbl = $GLOBALS["_conf_tbl"]["admin_menu_code"];

	$sql = "UPDATE ".$tbl." SET is_use = 'N' ";
	$rsf = mysql_query($sql,$GLOBALS[dblink]);
	//접근권한
	for($i=0; $i < count($_POST[a_auth]); $i++){
		/*
		$str_a_auth .= $_POST[a_auth][$i];
		if($i != count($_POST[a_auth])-1){
				$str_a_auth .= ",";
		}
		echo $str_a_auth;
		*/
		$sql = "UPDATE ".$tbl." SET is_use = 'Y' where m_code = '".$_POST[a_auth][$i]."'";
		$rsf = mysql_query($sql,$GLOBALS[dblink]);
	}
	/*
	$sql = "UPDATE ".$tbl." SET 
		a_pw= '".mysql_real_escape_string($_POST[a_pw])."',
		a_name= '".mysql_real_escape_string($_POST[a_name])."',
		a_class= '".mysql_real_escape_string($_POST[a_class])."',
		a_phone= '".mysql_real_escape_string($_POST[a_phone])."',
		a_email= '".mysql_real_escape_string($_POST[a_email])."',
		a_grade= '".mysql_real_escape_string($_POST[a_grade])."',
		a_auth= '".$str_a_auth."'
		WHERE idx = '$idx'
	";

	$rsf = mysql_query($sql,$GLOBALS[dblink]);
	*/
	if($rsf){
		return true;
	}else{
		return false;
	}
}

//관리자파일 삭제
function deleteAdmin($idx){
	$sql = "DELETE FROM ".$GLOBALS["_conf_tbl"]["admin"]." WHERE idx = '$idx' ";
	$rsf = mysql_query($sql,$GLOBALS[dblink]);

	$total = mysql_affected_rows($GLOBALS[dblink]);

	if($total > 0){
		return true;
	}else{
		return false;
	}
}

//관리자 로그인 로그 기록하기
function setAdminLoginLog($id,$login){
    $sql  = "INSERT INTO tbl_admin_login_log SET ";
    $sql .= "a_id = '$id', ";
    $sql .= "a_ip = '".$_SERVER[REMOTE_ADDR]."', ";
    $sql .= "a_login = '".$login."', ";
    $sql .= "a_date = now() ";
    $rs = mysql_query($sql, $GLOBALS[dblink]);
    $total_rs = mysql_affected_rows($GLOBALS[dblink]);
    
    return $total_rs;
}

//관리자 정보 가져오기
function getAdminMenu(){
    $sql  = "SELECT * ";
    $sql .= "FROM ".$GLOBALS["_conf_tbl"]["admin_menu_code"]." ";
    $sql .= "WHERE is_use = 'Y' order by m_name ";
    $rs = mysql_query($sql, $GLOBALS[dblink]);
    $total_rs = mysql_num_rows($rs);
    
    if($total_rs > 0){
        $list['total'] = $total_rs;
        for($i=0; $i < $total_rs; $i++){
            $list['list'][$i] = mysql_fetch_assoc($rs);
        }
    }else{
        $list['total'] = 0;
    }
    return $list;
}

//관리자 정보 가져오기
function getAdminMenu1(){
    $sql  = "SELECT * ";
    $sql .= "FROM ".$GLOBALS["_conf_tbl"]["admin_menu_code"]." ";
    $sql .= " order by m_name ";
    $rs = mysql_query($sql, $GLOBALS[dblink]);
    $total_rs = mysql_num_rows($rs);
    
    if($total_rs > 0){
        $list['total'] = $total_rs;
        for($i=0; $i < $total_rs; $i++){
            $list['list'][$i] = mysql_fetch_assoc($rs);
        }
    }else{
        $list['total'] = 0;
    }
    return $list;
}

function updateShopSet() {

	for($i=0; $i < count($_POST[payment]); $i++){
		$str_payment .= $_POST[payment][$i];
		if($i != count($_POST[payment])-1){
				$str_payment .= ",";
		}
	}

	$sql = "UPDATE ".$GLOBALS["_conf_tbl"]["shop_set"]." SET 
		shop_name = '".mysql_real_escape_string($_POST[shop_name])."',
		shop_url = '".mysql_real_escape_string($_POST[shop_url])."',
		shop_url1 = '".mysql_real_escape_string($_POST[shop_url1])."',
		shop_url2 = '".mysql_real_escape_string($_POST[shop_url2])."',
		admin_email = '".mysql_real_escape_string($_POST[admin_email])."',
		shop_title = '".mysql_real_escape_string($_POST[shop_title])."',
		shop_keyword = '".mysql_real_escape_string($_POST[shop_keyword])."',
		shop_content = '".mysql_real_escape_string($_POST[shop_content])."',
		shop_payment = '".$str_payment."',
		shop_pg_id = '".mysql_real_escape_string($_POST[shop_pg_id])."',
		shop_bankinfo = '".mysql_real_escape_string($_POST[shop_bankinfo])."',
		shop_delivery_company = '".mysql_real_escape_string($_POST[shop_delivery_company])."',
		shop_delivery_url = '".mysql_real_escape_string($_POST[shop_delivery_url])."',
		shop_delivery_gb = '".mysql_real_escape_string($_POST[delivery_gb])."',
		shop_delivery_default = '".mysql_real_escape_string($_POST[shop_delivery_default])."',
		shop_delivery_price = '".mysql_real_escape_string($_POST[shop_delivery_price])."',
		shop_delivery_high = '".mysql_real_escape_string($_POST[shop_delivery_high])."',
		shop_delivery_low = '".mysql_real_escape_string($_POST[shop_delivery_low])."',
		shop_point_member = '".mysql_real_escape_string($_POST[shop_point_member])."',
		shop_point_min = '".mysql_real_escape_string($_POST[shop_point_min])."',
		shop_point_max = '".mysql_real_escape_string($_POST[shop_point_max])."'
	";

	$rsf = mysql_query($sql,$GLOBALS[dblink]);

	if($rsf){
		return true;
	}else{
		return false;
	}
}

//오픈진행
function updateShopSetOpen() {
	if($_POST[evnType]=="1"){
		//구사이트도메인 http://www. 제외
		$old=mysql_real_escape_string($_POST[oldsite]);
		//새사ㅣ트도메인 http://www. 제외
		$new=mysql_real_escape_string($_POST[newsite]);
	}else{
		//구사이트도메인 http://www. 제외
		$old=mysql_real_escape_string($_POST[newsite]);
		//새사ㅣ트도메인 http://www. 제외
		$new=mysql_real_escape_string($_POST[oldsite]);
	}

	//상품 업데이트
	$sql_up = "update tbl_shop_good set contents=REPLACE(contents,'$old','$new')";
	$result_up=mysql_query($sql_up);

	//제품 업데이트
	$sql_up = "update tbl_product set contents=REPLACE(contents,'$old','$new')";
	$result_up=mysql_query($sql_up);

	//분류 업데이트
	$sql_up = "update tbl_category set cat_content=REPLACE(cat_content,'$old','$new')";
	$result_up=mysql_query($sql_up);
	
	//HTML 업데이트
	$sql_up = "update tbl_html_contents set contents=REPLACE(contents,'$old','$new')";
	$result_up=mysql_query($sql_up);
	
	//게시판 헤더푸터
	$sql_up = "update tbl_board_info set header=REPLACE(header,'$old','$new')";
	$result_up=mysql_query($sql_up);

	$sql_up = "update tbl_board_info set footer=REPLACE(footer,'$old','$new')";
	$result_up=mysql_query($sql_up);

	//게시판 업데이트
	$sql = "select * from tbl_board_info";
	$result=mysql_query($sql) ;
	while($row=mysql_fetch_array($result)){
		$sql_up = "update tbl_board_".$row[boardid]." set contents=REPLACE(contents,'$old','$new')";
		$result_up=mysql_query($sql_up);
	}
	
	$sql_up = "update tbl_shop_set set shop_url=REPLACE(shop_url,'$old','$new')";
	$result_up=mysql_query($sql_up);

	if($result_up){
		return true;
	}else{
		return false;
	}
}

//로그초기화
function updateLog(){
	$sql_up = "delete from tbl_websight_log";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_browser";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_counter";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_domain";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_ip";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_keyword";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_os";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_page";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_referer";
	$result_up=mysql_query($sql_up);
	$sql_up = "delete from tbl_websight_log_searchengin";
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_websight_log convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_browser convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_counter convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_domain convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_ip convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_keyword convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_os convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_page convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_referer convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER TABLE tbl_websight_log_searchengin convert to charset utf8"; 
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER table tbl_websight_log auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_browser auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_counter auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_domain auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_ip auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_keyword auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_os auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_page auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_referer auto_increment = 1 ";
	$result_up=mysql_query($sql_up);
	$sql_up = "ALTER table tbl_websight_log_searchengin auto_increment = 1 ";
	$result_up=mysql_query($sql_up);

	if($result_up){
		return true;
	}else{
		return false;
	}
}

//영문추가
function addEnMode(){
	$sql_up = "alter table tbl_category add column cat_ename varchar(255) not null after cat_name;";
	$result_up=mysql_query($sql_up);

	$sql_up = "alter table tbl_product add column p_ename varchar(255) not null after p_name;";
	$result_up=mysql_query($sql_up);
	
	$sql_up = "ALTER TABLE tbl_category convert to charset utf8"; 
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_product convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	
	//게시판 업데이트
	$sql = "select * from tbl_board_info";
	$result=mysql_query($sql) ;
	while($row=mysql_fetch_array($result)){
		$sql_up = "ALTER TABLE tbl_board_".$row[boardid]." convert to charset utf8"; 
		$result_up=mysql_query($sql_up);
	}

	if($result_up){
		return true;
	}else{
		return false;
	}
}

//중문추가
function addCnMode(){
	$sql_up = "alter table tbl_category add column cat_cname varchar(255) not null after cat_name;";
	$result_up=mysql_query($sql_up);

	$sql_up = "alter table tbl_product add column p_cname varchar(255) not null after p_name;";
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_category convert to charset utf8"; 
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_product convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	
	//게시판 업데이트
	$sql = "select * from tbl_board_info";
	$result=mysql_query($sql) ;
	while($row=mysql_fetch_array($result)){
		$sql_up = "ALTER TABLE tbl_board_".$row[boardid]." convert to charset utf8"; 
		$result_up=mysql_query($sql_up);
	}

	if($result_up){
		return true;
	}else{
		return false;
	}
}

//일본어추가
function addJpMode(){
	$sql_up = "alter table tbl_category add column cat_jname varchar(255) not null after cat_name;";
	$result_up=mysql_query($sql_up);

	$sql_up = "alter table tbl_product add column p_jname varchar(255) not null after p_name;";
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_category convert to charset utf8"; 
	$result_up=mysql_query($sql_up);

	$sql_up = "ALTER TABLE tbl_product convert to charset utf8"; 
	$result_up=mysql_query($sql_up);
	
	//게시판 업데이트
	$sql = "select * from tbl_board_info";
	$result=mysql_query($sql) ;
	while($row=mysql_fetch_array($result)){
		$sql_up = "ALTER TABLE tbl_board_".$row[boardid]." convert to charset utf8"; 
		$result_up=mysql_query($sql_up);
	}

	if($result_up){
		return true;
	}else{
		return false;
	}
}
?>