<?
//정보 수정하기
function setMailConfig($code){
	//메일정보 테이블
	$tbl = $GLOBALS["_conf_tbl"]["mail_config"];

	if(mysql_real_escape_string($_POST[is_use])=="Y"){
		$is_use = "Y";
	}else{
		$is_use = "N";
	}
	//상품정보 테이블에 입력
	$sql = "UPDATE ".$tbl." set 
		is_use='".$is_use."',
		subject='".mysql_real_escape_string($_POST[subject])."',
		contents='".mysql_real_escape_string($_POST[contents])."'
		WHERE code = '".$code."'
	";

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

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


//정보 가져오기
function getMailConfig($code){
	$tbl = $GLOBALS["_conf_tbl"]["mail_config"];

    $sql  = "SELECT * ";
    $sql .= "FROM " .$tbl." ";
    $sql .= "WHERE code = '$code' ";

    $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 sendMailShopInfo($arrInfo, $arrMailInfo){
	if($arrMailInfo["list"][0]["is_use"]=="Y"){
		//변수치환
		$Mail_Subject = str_replace("{NAME}", $arrInfo["list"][0][order_name], stripslashes($arrMailInfo["list"][0]["subject"]));
		$Mail_Contents = stripslashes($arrMailInfo["list"][0]["contents"]);
		$Mail_Contents = str_replace("{ID}", $arrInfo["list"][0]["order_id"], $Mail_Contents);
		$Mail_Contents = str_replace("{NAME}", $arrInfo["list"][0]["order_name"], $Mail_Contents);
		$Mail_Contents = str_replace("{EMAIL}", stripslashes($arrInfo["list"][0]["order_email"]), $Mail_Contents);
		$Mail_Contents = str_replace("{ORDERZIP}", $arrInfo["list"][0]["order_zip"], $Mail_Contents);
		$Mail_Contents = str_replace("{ORDERADDRESS}", $arrInfo["list"][0]["order_address"], $Mail_Contents);
		$Mail_Contents = str_replace("{ORDERADDRESSEXT}", $arrInfo["list"][0]["order_address_ext"], $Mail_Contents);
		$Mail_Contents = str_replace("{ORDERPHONE}", $arrInfo["list"][0]["order_phone"], $Mail_Contents);
		$Mail_Contents = str_replace("{ORDERNO}", $arrInfo["list"][0]["order_no"], $Mail_Contents);
		$Mail_Contents = str_replace("{SUMMARY}", $arrInfo["list"][0]["order_summary"], $Mail_Contents);
		$Mail_Contents = str_replace("{PAYTYPE}", $GLOBALS["_SITE"]["SHOP"]["PAY_TYPE"][$arrInfo["list"][0]["pay_type"]], $Mail_Contents);
		$Mail_Contents = str_replace("{BANKTYPE}", $arrInfo["list"][0]["bank_type"], $Mail_Contents);
		$Mail_Contents = str_replace("{TOTAL}", number_format($arrInfo["list"][0]["total_amount"]), $Mail_Contents);
		$Mail_Contents = str_replace("{PAYTOTAL}", number_format($arrInfo["list"][0]["pay_amount"]), $Mail_Contents);
		$Mail_Contents = str_replace("{SHIPNAME}", $arrInfo["list"][0]["ship_name"], $Mail_Contents);
		$Mail_Contents = str_replace("{SHIPZIP}", $arrInfo["list"][0]["ship_zip"], $Mail_Contents);
		$Mail_Contents = str_replace("{SHIPADDRESS}", $arrInfo["list"][0]["ship_address"], $Mail_Contents);
		$Mail_Contents = str_replace("{SHIPADDRESSEXT}", $arrInfo["list"][0]["ship_address_ext"], $Mail_Contents);
		$Mail_Contents = str_replace("{SHIPPHONE}", $arrInfo["list"][0]["ship_phone"], $Mail_Contents);
		$Mail_Contents = str_replace("{SHIPMOBILE}", $arrInfo["list"][0]["ship_mobile"], $Mail_Contents);
		$Mail_Contents = str_replace("{COMMENT}", stripslashes($arrInfo["list"][0]["order_comment"]), $Mail_Contents);
		$mail = new smtp("mail.e-isac.co.kr");  //자체발송일 경우, 서버를 지정할수도 있음. 
		//$mail->debug();
		$mail->send($arrInfo["list"][0][order_email], $GLOBALS["_SITE"]["NAME"]."<".$GLOBALS["_SITE"]["EMAIL"].">", $Mail_Subject , $Mail_Contents, "y");
		return true;
	}else{
		return false;
	}
}

//회원가입, 탈퇴시 메일링
function sendMailMemberInfo($arrInfo, $arrMailInfo){
	if($arrMailInfo["list"][0]["is_use"]=="Y"){
		//변수치환
		$Mail_Subject = str_replace("{NAME}", $arrInfo["list"][0][user_name], stripslashes($arrMailInfo["list"][0]["subject"]));
		$Mail_Contents = stripslashes($arrMailInfo["list"][0]["contents"]);
		$Mail_Contents = str_replace("{ID}", $arrInfo["list"][0]["user_id"], $Mail_Contents);
		$Mail_Contents = str_replace("{NAME}", $arrInfo["list"][0]["user_name"], $Mail_Contents);
		$Mail_Contents = str_replace("{EMAIL}", stripslashes($arrInfo["list"][0]["email"]), $Mail_Contents);
		$Mail_Contents = str_replace("{ZIP}", $arrInfo["list"][0]["zip"], $Mail_Contents);
		$Mail_Contents = str_replace("{ADDRESS}", $arrInfo["list"][0]["address"], $Mail_Contents);
		$Mail_Contents = str_replace("{ADDRESSEXT}", $arrInfo["list"][0]["address_ext"], $Mail_Contents);
		$Mail_Contents = str_replace("{WDATE}", stripslashes($arrInfo["list"][0]["wdate"]), $Mail_Contents);
		$Mail_Contents = str_replace("{NDATE}", date("Y-m-d"), $Mail_Contents);
		$mail = new smtp("mail.e-isac.co.kr");  //자체발송일 경우, 서버를 지정할수도 있음. 
		//$mail->debug();
		$mail->send($arrInfo["list"][0][email], $GLOBALS["_SITE"]["NAME"]."<".$GLOBALS["_SITE"]["EMAIL"].">", $Mail_Subject , $Mail_Contents, "y");
		return true;
	}else{
		return false;
	}
}
?>