// 선택 운영체제 switching 을 위해서 사용. (이전 운영체제 refresh 용 변수)
var beforeclick = null;
var ostype = Array("centos");
function setClear() {
window.setTimeout(function () {
$("#svment").html("");
},5000);
}
// 영숫자 체크 및 첫글자 체크.
function CheckValue(strValue) {
var strReg = /^[A-Za-z-0-9]+$/;
if (strValue[0] >= '0' && strValue[0] <= '9') {
$("#svment").html("");
$("#svment").html('첫글자는 영문이어야 합니다.');
setClear();
return false;
}
if (!strReg.test(strValue)) {
$("#svment").html("");
$("#svment").html('영문과 숫자만 입력가능합니다.');
setClear();
return false;
}
return true;
}
// 각 운영체제별 optionbox 셋팅 (value는 divtpe(운영체제 종류), osname(운영체제명), ospay(운영체제비용),
// dbpay (db 비용)
function setting_oslists(data) {
var major_gubun, minor_gubun, tag, divname = "";
major_gubun = data.split("\n");
// centos|CentOS 7.0 64bit|0|0|0|0|296da4b0-a4aa-4642-9a9a-3ee8549b0420|17|mariadb|3|CentOS 7.0 64bit / mariadb:10.1.13 / charset:utf-8
for (i = 0; i < major_gubun.length-1; i++) {
minor_gubun = major_gubun[i].split("|");
var divtype = minor_gubun[0];
var osname = minor_gubun[1];
var thisospay = minor_gubun[2];
var thisdiscountospay = minor_gubun[3];
var nextospay = minor_gubun[4];
var nextdiscountospay = minor_gubun[5];
var templateid = minor_gubun[6];
var idx = minor_gubun[7];
var servicetype = minor_gubun[8];
var program_idx = minor_gubun[9];
var servicename = minor_gubun[10];
var servicetitle = servicename;
if (osname == -2)
continue;
else if (osname == -1) {
divname = "#" + divtype;
$(divname).append("");
} else {
divname = "#" + divtype;
var a = "";
$(divname).append(
"");
}
}
$(divname).trigger('contentChanged');
}
function setting_date(data) {
// console.clear();
var gubun = null;
gubun = data.split("|");
var period = parseInt(gubun[0]);
var startday = gubun[1];
var startend = gubun[2];
var startdays = gubun[3];
var endstartday = gubun[4];
var endendday = gubun[5];
var enddays = gubun[6];
var alldays = gubun[7];
var html = "";
var estimate = "";
if(!alldays) alldays = startdays;
if(!endendday) endendday = startend;
if (period == 2) {
$(".next-month").show();
var a = startday.split(".");
if(a[1] < 10)
var startmonth = a[1].replace('0', "");
else var startmonth = a[1];
var a = endstartday.split(".");
if(a[1] < 10)
var nextmonth = a[1].replace('0', "");
else var nextmonth = a[1];
var starthtml = startmonth + " 월 금액 (" + startday + " ~ " + startend
+ " ) ";
$("#thismonth").html("");
$("#thismonth").html(starthtml);
var nexthtml = nextmonth + " 월 금액 (" + endstartday + " ~ " + endendday
+ " ) ";
$("#nextmonth").html("");
$("#nextmonth").html(nexthtml);
html = startday + " ~ " + startend + " (" + startdays + "일) + "
+ endstartday + " ~ " + endendday + " (1달)";
$("#pay_date").val("");
$("#pay_date").val(html);
} else if (period == 1) {
$(".next-month").hide();
var a = startday.split(".");
if(a[1] < 10)
var startmonth = a[1].replace('0', "");
else var startmonth = a[1];
var starthtml = startmonth + " 월 금액 (" + startday + " ~ " + startend
+ " ) ";
$("#thismonth").html("");
$("#thismonth").html(starthtml);
html = startday + " ~ " + startend + " (" + startdays + "일)";
$("#pay_date").val("");
$("#pay_date").val(html);
} else {
alert('문제가 발생이 되었습니다.');
exit;
}
$("#vmperiod").html("");
$("#vmperiod").html(html);
$("#period").val(period);
$("#startday").val(startday);
$("#startend").val(startend);
$("#startdays").val(startdays);
$("#endstartday").val(endstartday);
$("#endendday").val(endendday);
$("#enddays").val(enddays);
$("#alldays").val(alldays);
}
// vmlist 출력 (optionbox 로)
// 23926|21534|53000|47700|2|2|b1abfccf-5fbb-4eeb-be6f-c892572a06f5|19|100GB|0|0|0|0|0|0|0|0|1TB|centos 7.0 64bit|56e30117-0993-4be5-a36d-914396028d30
// thisservicepay.thisdiscountservicepay.nextservicepay,nextdiscountservicepay, vcpu,vmemory, serviceofferingid, idx, diskofferingdesc,thisdbpay,thisdiscountdbpay, nextdbpay, nextdiscountdbpay, thisospay, thisdiscountospay,nextospay, nextdiscountospay, $t,$osname, .$templateid
function setting_vmlists(data, disk, divtype, product) {
$('#viewPay').show();
var major_gubun, minor_gubun, tag, divname = "";
major_gubun = data.split("\n");
$("#choicevm").val('-1');
var os = $("#" + divtype + " option:selected").val();
var period = parseInt($("#period").val());
if(product == "ssd") {
$(".spec-select-disk").hide();
}
if (parseInt(major_gubun[0]) == -1) {
$("#cpucomment").html("");
$("#memorycomment").html("");
$("#diskcomment").html("");
$("#trafficcomment").html("");
$("#oscomment").html("");
$("#specloop").html("");
add_class(divtype);
all_pay_init();
var html = "
상품이 없습니다.
";
$("#specloop").html(html);
} else {
$("#choicevm").val('1');
var html = "";
for (i = 0; i < major_gubun.length - 1; i++) {
minor_gubun = major_gubun[i].split("|");
var thisservicepay = minor_gubun[0];
var thisdiscountservicepay = minor_gubun[1];
var nextservicepay = minor_gubun[2];
var nextdiscountservicepay = minor_gubun[3];
var vcpu = minor_gubun[4];
var vmemory = minor_gubun[5];
var serviceid = minor_gubun[6];
var idx = minor_gubun[7];
var tmpdisk = minor_gubun[8];
var thisdbpay = minor_gubun[9];
var thisdiscountdbpay = minor_gubun[10];
var nextdbpay = minor_gubun[11];
var nextdiscountdbpay = minor_gubun[12];
var tr = minor_gubun[17];
if(product == "ssd") {
$(".spec-select-disk").hide();
var ssddisk = minor_gubun[8];
disk = ssddisk;
}else{
$(".spec-select-disk").show();
disk = tmpdisk;
}
var cpucomment = vcpu + " vCore ";
var memorycomment = vmemory + " GB "
var diskcomment = disk ;
var trafficcomment = tr ;
$("#specloop").html("");
// 운영체제를 처음에 선택하면 1번 spec 으로 무조건 선택함.
if (i == 0) {
c = "checked";
$("#cpucomment").html("");
$("#memroycomment").html("");
$("#diskcomment").html("");
$("#trafficcomment").html("");
$("#cpucomment").html(cpucomment);
$("#memorycomment").html(memorycomment);
$("#diskcomment").html(diskcomment);
$("#trafficcomment").html(trafficcomment);
var pa = thisservicepay + "+" + thisdiscountservicepay + "+"
+ nextservicepay + "+" + nextdiscountservicepay + "+"
+ vcpu + "+" + vmemory + "+" +serviceid +"+"+idx+"+"+disk+"+"+thisdbpay+"+"+thisdiscountdbpay+"+"+nextdbpay+"+"+nextdiscountdbpay+"+"+tr;
html += "
"
+ vcpu
+ " vCore
"
+ vmemory
+ " GB
"
+ disk
+ "
"
+ tr
+ "
"
+ comma(nextservicepay)
+ "
";
html += "
\n";
$("#specloop").html(html);
var spec = $(":input:radio[name=spec]:checked").val();
writeEstimate(os, spec, disk);
} else {
c = "";
var pa = thisservicepay + "+" + thisdiscountservicepay + "+"
+ nextservicepay + "+" + nextdiscountservicepay + "+"
+ vcpu + "+" + vmemory + "+" +serviceid + "+" +idx+"+"+disk+"+"+thisdbpay+"+"+thisdiscountdbpay+"+"+nextdbpay+"+"+nextdiscountdbpay+"+"+tr;
html += "
"
+ vcpu
+ " vCore
"
+ vmemory
+ " GB
"
+ disk
+ "
"
+ tr
+ "
"
+ comma(nextservicepay)
+ "
";
html += "
\n";
$("#specloop").html(html);
}
}
$(":input:radio[name=spec]").change(function() {
var spec = $(":input:radio[name=spec]:checked").val();
var os = $("#" + divtype + " option:selected").val();
var period = parseInt($("#period").val());
var s = spec.split("+");
var o = os.split("+");
var tr= s[13];
if (period == 1) {
if((o[0] == 'redhat') || (o[0] == 'suse'))
var ospay = parseInt(o[2]);
else
var ospay = parseInt(o[3]);
var dbpay = parseInt(s[10]);
var sp = parseInt(s[1]);
} else {
if((o[0] == 'redhat') || (o[0] == 'suse'))
var ospay = parseInt(o[2]);
else
var ospay = parseInt(o[3]) + parseInt(o[5]);
var dbpay = parseInt(s[10]) + parseInt(s[12]);
var sp = parseInt(s[1]) + parseInt(s[3]);
}
var cpucomment = s[4] + " vCore ";
var memorycomment = s[5] + " GB "
var diskcomment = disk ;
var trafficcomment = tr ;
total_calc_pay(ospay, dbpay, sp);
$("#cpucomment").html("");
$("#cpucomment").html(cpucomment);
$("#memorycomment").html("");
$("#memorycomment").html(memorycomment);
$("#diskcomment").html("");
$("#diskcomment").html(diskcomment);
$("#trafficcomment").html("");
$("#trafficcomment").html(trafficcomment);
writeEstimate(os, spec, disk);
});
}
}
// disk 출력. (각각 받아온 디스크 용량 출력 (20G/100G or 50G/100G - windows)
function setting_disklists(data) {
var major_gubun, minor_gubun, tag, divname = "";
major_gubun = data.split("\n");
var hd1 = major_gubun[0];
var hd2 = major_gubun[1];
$('#disk1').val(hd1);
$("#hd1").text("");
$("#hd1").text(hd1);
$('#disk2').val(hd2);
$("#hd2").text("");
$("#hd2").text(hd2);
}
// vm 리스트 정보 받아오기.
function get_vmlists(zone, os, product, disk, divtype, program_idx) {
var data = "";
var startdays = $("#startdays").val();
var period = $("#period").val();
var startdays = $("#startdays").val();
var r = "mode=get_vmlists&zone=" + zone + "&os=" + os + "&product="
+ product + "&disk=" + disk + "&startdays=" + startdays
+ "&period=" + period + "&startdays=" + startdays+"&program_idx="+program_idx;
var url = "/market/demo_maria_server.act.php";
var ajax = $.ajax({
url : url,
type : 'post',
async : false,
datatype : 'html',
data : r,
cache : false,
timeout : 1000,
success : function(data) {
setting_vmlists(data, disk, divtype, product);
}
});
}
// 운영체제별 디스크 용량 받아오기.
function get_disklist(zone, os, product) {
var data = "";
var startdays = $("#startdays").val();
var r = "mode=get_disklists&zone=" + zone + "&os=" + os + "&product="
+ product;
var url = "/market/demo_maria_server.act.php";
var ajax = $.ajax({
url : url,
type : 'post',
async : false,
datatype : 'html',
data : r,
cache : false,
timeout : 1000,
success : function(data) {
setting_disklists(data);
}
});
}
function get_date() {
var data = "";
var r = "mode=get_date";
var url = "/market/demo_maria_server.act.php";
var ajax = $.ajax({
url : url,
type : 'post',
async : false,
datatype : 'html',
data : r,
cache : false,
timeout : 1000,
success : function(data) {
setting_date(data);
}
});
}
function graph_print () {
$(".print").printThis({
debug:false,
importCSS:true,
removeinline:false,
loadCSS: "../css/style.css",
printContainer:true
});
}
// zone 별로 운영체제 리스트 받아오기.
function get_oslists(zone) {
$("#zonecomment").html("");
$("#zonecomment").html(zone);
$('#centos option[value!="-1"]').remove();
var startdays = $("#startdays").val();
var period = $("#period").val();
var servicetype = $("#servicetype").val();
var data = "";
var r = "mode=get_oslists&zone=" + zone + "&startdays=" + startdays
+ "&period=" + period + "&servicetype="+servicetype;
var url = "/market/demo_maria_server.act.php";
var ajax = $.ajax({
url : url,
type : 'post',
async : false,
datatype : 'html',
data : r,
cache : false,
timeout : 1000,
success : function(data) {
setting_oslists(data);
}
});
}
// zone 에서 디폴트로 설정된 zone의 정보를 읽어오기.
function call_default_loading() {
var zonename = $(":input:radio[name=zone]:checked").val();
get_oslists(zonename);
}
// 숫자 , 추가
function comma(num) {
var len, point, str;
num = num + "";
point = num.length % 3;
len = num.length;
str = num.substring(0, point);
while (point < len) {
if (str != "")
str += ",";
str += num.substring(point, point + 3);
point += 3;
}
return str;
}
// 숫자 반올림.
function round(money) {
val = parseInt(money);
val = Math.round(val / 10) * 10;
return val;
}
function rou(pay) {
var npay, tax;
val = parseInt(pay);
tax = Math.floor(val / 10) * 10;
return tax;
}
// 금액 계산.
function total_calc_pay(os, db, service) {
var opay = parseInt(os);
var dpay = parseInt(db);
var sv = parseInt(service);
var s = "", t = "", tax = "";
var tax, ttax;
var total_pay = opay + dpay + sv;
tax = Math.floor(total_pay * 1.1);
//ttax = rou(tax);
ttax = tax;
s = comma(ttax);
$("#ppay").html("");
$("#ppay").html(s);
}
// 운영체제 리스트 모두 비활성화.
function add_class_init() {
for (i = 0; i < ostype.length; i++) {
var d = "#" + ostype[i] + "selected";
$(d).addClass("createserver-os-card");
$(d).removeClass("createserver-os-card-1");
}
}
// 특정 운영체제 선택시에 해당 운영체제만 활성화.
function add_class(divtype) {
for (i = 0; i < ostype.length; i++) {
var d = "#" + ostype[i] + "selected";
if (divtype == ostype[i]) {
$(d).addClass("createserver-os-card-1");
} else {
$(d).addClass("createserver-os-card");
$(d).removeClass("createserver-os-card-1");
}
}
}
//
function writeEstimate(os, service, disk) {
var o = os.split('+');
var ostype = o[0];
var osname = o[1];
var thisospay = o[2];
var thisdiscountospay = o[3];
var nextospay = o[4];
var nextdiscountospay = o[5];
var a = o[10].split("/");
var dbname = a[1];
var s = service.split("+");
var thisservicepay = s[0];
var thisdiscountservicepay = s[1];
var nextservicepay = s[2];
var nextdiscountservicepay = s[3];
var thisdbpay = s[9];
var thisdiscountdbpay = s[10];
var nextdbpay = s[11];
var nextdiscountdbpay = s[12];
var tr = s[13];
var vcpu = s[4];
var vmemory = s[5];
var dc_rate = $("#dc_rate").val();
var os_dc_rate = $("#os_dc_rate").val();
var db_dc_rate = $("#db_dc_rate").val();
var period = $("#period").val();
var dc = parseFloat(dc_rate) * 100;
var os_dc = parseFloat(os_dc_rate) * 100;
var db_dc = parseFloat(db_dc_rate) * 100;
if (o[0] == "centos") {
var oss = osname.split(" ");
var end = oss.length;
}
if (thisospay == '0')
var top = "-";
else
var top = comma(thisospay) + " 원 ";
if (thisdiscountospay == '0')
var tdop = "-";
else
var tdop = comma(thisdiscountospay) + " 원 ( " + os_dc + "% 할인 ) ";
if (nextospay == '0')
var nop = "-";
else
var nop = comma(nextospay) + " 원 ";
if (nextdiscountospay == '0')
var ndop = "-";
else
var ndop = comma(nextdiscountospay) + " 원 ( " + os_dc + "% 할인 ) ";
if (thisdbpay == '0')
var tdb = "-";
else
var tdb = comma(thisdbpay) + " 원 ";
if (thisdiscountdbpay == '0')
var tddb = "-";
else
var tddb = comma(thisdiscountdbpay) + " 원 ( " + db_dc + "% 할인 ) ";
if (nextdbpay == '0')
var ndb = "-";
else
var ndb = comma(nextdbpay) + " 원 ";
if (nextdiscountdbpay == '0')
var nddb = "-";
else
var nddb = comma(nextdiscountdbpay)+ " 원 ( " + db_dc + "% 할인 ) ";
if (period == 1) {
var totalospay = comma(thisospay) + " 원 ";
var totaldiscountospay = comma(thisdiscountospay) + " 원 ";
var totaldbpay = comma(thisdbpay) + " 원 ";
var totaldiscountdbpay = comma(thisdiscountdbpay) + " 원 ";
if((o[0] == "redhat") || (o[0] == "suse")) {
var tdiscounttotalpay = parseInt(thisospay) + parseInt(thisdiscountdbpay)
+ parseInt(thisdiscountservicepay);
}else{
var tdiscounttotalpay = parseInt(thisdiscountospay) + parseInt(thisdiscountdbpay)
+ parseInt(thisdiscountservicepay);
}
var ttotalpay = parseInt(thisospay) + parseInt(thisdbpay)
+ parseInt(thisservicepay);
var tdiscounttotal = tdiscounttotalpay;
var ttotal = ttotalpay;
} else {
var totalospay = thisospay + nextospay;
var totaldbpay = thisdbpay + nextdbpay;
if((o[0] == "redhat") || (o[0] == "suse")) {
var tdiscounttotalpay = parseInt(thisospay) + parseInt(thisdiscountdbpay)
+ parseInt(thisdiscountservicepay);
}else {
var tdiscounttotalpay = parseInt(thisdiscountospay) + parseInt(thisdiscountdbpay)
+ parseInt(thisdiscountservicepay);
}
var ndiscounttotalpay = parseInt(nextdiscountospay) + parseInt(nextdiscountdbpay)
+ parseInt(nextdiscountservicepay);
var ttotalpay = parseInt(thisospay) + parseInt(thisdbpay)
+ parseInt(thisservicepay);
var ntotalpay = parseInt(nextospay) + parseInt(nextdbpay)
+ parseInt(nextservicepay);
var tdiscounttotal = tdiscounttotalpay + ndiscounttotalpay;
var ttotal = ttotalpay + ntotalpay;
}
var speccomment = vcpu + " vCore / " + vmemory + " GB / " + disk + " / "+tr;
var cpucomment = vcpu + " vCore ";
var memorycomment = vmemory + " GB "
var diskcomment = disk ;
var trafficcomment = tr ;
var ttax = Math.floor((parseInt(tdiscounttotal) * 1.1) - parseInt(tdiscounttotal));
var ttaxall = parseInt(tdiscounttotal) + parseInt(ttax);
//var tto = rou(ttaxall);
var tto = ttaxall;
//var different = ttaxall - tto;
all_pay_init();
$("#tspec").html(speccomment);
$("#nspec").html(speccomment);
$("#tosname").html(osname);
$("#tdbname").html(dbname);
$("#tospay").html(top);
$("#tosdiscount").html(tdop);
$("#nospay").html(nop);
$("#nosdiscount").html(ndop);
$("#tdbpay").html(tdb);
$("#tdbdiscount").html(tddb);
$("#ndbpay").html(ndb);
$("#ndbdiscount").html(nddb);
$("#tspecpay").html(comma(thisservicepay) + " 원 ");
$("#tspecdiscount").html(
comma(thisdiscountservicepay) + " 원 ( " + dc + "% 할인 ) ");
$("#nosname").html(osname);
$("#ndbname").html(dbname);
$("#nspecpay").html(comma(nextservicepay) + " 원 ");
$("#nspecdiscount").html(
comma(nextdiscountservicepay) + " 원 (" + dc + "% 할인 ) ");
$("#ttotalpay").html(comma(tdiscounttotalpay) + " 원 ");
$("#ntotalpay").html(comma(ndiscounttotalpay) + " 원 ");
$("#supplypay").html(comma(ttotal) + " 원 ");
$("#openpay").html(comma(tdiscounttotal) + " 원 ");
$("#alltax").html(comma(ttax) + " 원 ");
//$("#subtract").html(comma(different) + " 원 ");
$("#alltotal").html("총 액 : " + comma(tto) + " 원 ");
$("#totalpay").val(ttotal);
$("#ktpay").val(ttotal);
$("#discountpay").val(tto);
$("#ktpay1").html("");
$("#ktpay1").html(comma(ttotal));
$("#serverdiscountpay").html("");
var disc = parseInt(ttotal) - parseInt(tdiscounttotal);
$("#serverdiscountpay").html(comma(disc));
//$("#subtract_pay").val(different);
}
function setting_servername (data) {
var resultcode = parseInt(data);
if(resultcode == 1) {
$("#svment").html("");
$("#svment").html("사용이 가능합니다.");
setClear();
}else {
$("#svment").html("");
$("#svment").html("사용이 불가능합니다.");
setClear();
}
}
function all_pay_init() {
$("#tspec").html("");
$("#nspec").html("");
$("#tosname").html("");
$("#tospay").html("");
$("#tosdiscount").html("");
$("#nospay").html("");
$("#nosdiscount").html("");
$("#tdbname").html("");
$("#ndbname").html("");
$("#tdbpay").html("");
$("#ndbpay").html("");
$("#tspecpay").html("");
$("#tspecdiscount").html("");
$("#nosname").html("");
$("#nspecpay").html("");
$("#nspecdiscount").html("");
$("#ttotalpay").html("");
$("#ntotalpay").html("");
$("#supplypay").html("");
$("#openpay").html("");
$("#alltax").html("");
$("#subtract").html("");
$("#alltotal").html("");
$("#totalpay").val("");
$("#discountpay").val("");
$("#ktpay").val("");
}
$(document).ready(function() {
$('select').on('contentChanged', function() {
// re-initialize (update)
$(this).material_select();
});
// $("#centos option[value='-1'").attr("disabled", true);
$('#centos option[value!="-1"]').remove();
$('#viewPay').hide();
add_class_init();
get_date();
var period = $("#period").val();
call_default_loading();
$("#sv-name").on("enter", function() {
$("#svment").html("");
});
$("#sv-name").on("blur", function() {
$("#svment").html("");
var svname = $("#sv-name").val();
if(svname.length==0) return;
if (!CheckValue(svname)) {
$("#sv-name").val("");
$("#sv-name").focus();
return;
}
if(svname.length < 5) {
$("#svment").html("");
$("#svment").html("서버명은 5자이상이어야 합니다.");
setClear();
return ;
}
$("#svment").html("");
var account = $("#accountid option:selected").val();
var r = "mode=check-servername&server_name="+svname+"&account="+account;
var url = "/market/demo_maria_server.act.php";
var ajax = $.ajax({
url : url,
type : 'post',
async : false,
datatype : 'html',
data : r,
cache : false,
timeout : 1000,
success : function(data) {
setting_servername(data);
}
});
});
// zone 정보 가져오기.
$(":input:radio[name='zone']").change(
function() {
var zonename = $(
":input:radio[name=zone]:checked")
.val();
if(zonename == "일본존") {
$("#suseselected").hide();
$("#redhatselected").hide();
}else {
$("#suseselected").show();
$("#redhatselected").show();
}
var me = document.createserver.product;
var di = document.createserver.disk;
for(var i=0; i