usage_max_number = 24;
usage_add_next_index = 0;
usage_record_next_index = 0;
var usage_record_arr = [];
var usage_name_arr = [];
var usage_3g_arr = [];
var usage_sim_arr = [];
var mapping_arr = [];
var mapping_device_arr = [];
var usage_record_csid_arr = [];
var usage_name_csid_arr = [];
var usage_3g_csid_arr = [];
var usage_sim_csid_arr = [];
var usage_enable_csid_arr = [];
var alter_csid_arr = [];
var xml = "system_data_usage.xml"
var limit_rate_arr = [1,1024,1048576];
var inter_value = 1;
var sim_value = 1;
var rule_number = 0;
var sim_used_arr = [0,0,0,0];
mapping_device_arr.push(1);
mapping_device_arr.push(1);
usage_record_csid_arr.push("N002029A0");
usage_name_csid_arr.push("S00000120");
usage_3g_csid_arr.push("N00000140");
usage_sim_csid_arr.push("N00000160");
usage_enable_csid_arr.push("N00000100");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A1");
usage_name_csid_arr.push("S00000121");
usage_3g_csid_arr.push("N00000141");
usage_sim_csid_arr.push("N00000161");
usage_enable_csid_arr.push("N00000101");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A2");
usage_name_csid_arr.push("S00000122");
usage_3g_csid_arr.push("N00000142");
usage_sim_csid_arr.push("N00000162");
usage_enable_csid_arr.push("N00000102");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A3");
usage_name_csid_arr.push("S00000123");
usage_3g_csid_arr.push("N00000143");
usage_sim_csid_arr.push("N00000163");
usage_enable_csid_arr.push("N00000103");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A4");
usage_name_csid_arr.push("S00000124");
usage_3g_csid_arr.push("N00000144");
usage_sim_csid_arr.push("N00000164");
usage_enable_csid_arr.push("N00000104");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A5");
usage_name_csid_arr.push("S00000125");
usage_3g_csid_arr.push("N00000145");
usage_sim_csid_arr.push("N00000165");
usage_enable_csid_arr.push("N00000105");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A6");
usage_name_csid_arr.push("S00000126");
usage_3g_csid_arr.push("N00000146");
usage_sim_csid_arr.push("N00000166");
usage_enable_csid_arr.push("N00000106");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A7");
usage_name_csid_arr.push("S00000127");
usage_3g_csid_arr.push("N00000147");
usage_sim_csid_arr.push("N00000167");
usage_enable_csid_arr.push("N00000107");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A8");
usage_name_csid_arr.push("S00000128");
usage_3g_csid_arr.push("N00000148");
usage_sim_csid_arr.push("N00000168");
usage_enable_csid_arr.push("N00000108");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029A9");
usage_name_csid_arr.push("S00000129");
usage_3g_csid_arr.push("N00000149");
usage_sim_csid_arr.push("N00000169");
usage_enable_csid_arr.push("N00000109");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029AA");
usage_name_csid_arr.push("S0000012A");
usage_3g_csid_arr.push("N0000014A");
usage_sim_csid_arr.push("N0000016A");
usage_enable_csid_arr.push("N0000010A");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029AB");
usage_name_csid_arr.push("S0000012B");
usage_3g_csid_arr.push("N0000014B");
usage_sim_csid_arr.push("N0000016B");
usage_enable_csid_arr.push("N0000010B");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029AC");
usage_name_csid_arr.push("S0000012C");
usage_3g_csid_arr.push("N0000014C");
usage_sim_csid_arr.push("N0000016C");
usage_enable_csid_arr.push("N0000010C");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029AD");
usage_name_csid_arr.push("S0000012D");
usage_3g_csid_arr.push("N0000014D");
usage_sim_csid_arr.push("N0000016D");
usage_enable_csid_arr.push("N0000010D");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029AE");
usage_name_csid_arr.push("S0000012E");
usage_3g_csid_arr.push("N0000014E");
usage_sim_csid_arr.push("N0000016E");
usage_enable_csid_arr.push("N0000010E");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029AF");
usage_name_csid_arr.push("S0000012F");
usage_3g_csid_arr.push("N0000014F");
usage_sim_csid_arr.push("N0000016F");
usage_enable_csid_arr.push("N0000010F");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B0");
usage_name_csid_arr.push("S00000130");
usage_3g_csid_arr.push("N00000150");
usage_sim_csid_arr.push("N00000170");
usage_enable_csid_arr.push("N00000110");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B1");
usage_name_csid_arr.push("S00000131");
usage_3g_csid_arr.push("N00000151");
usage_sim_csid_arr.push("N00000171");
usage_enable_csid_arr.push("N00000111");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B2");
usage_name_csid_arr.push("S00000132");
usage_3g_csid_arr.push("N00000152");
usage_sim_csid_arr.push("N00000172");
usage_enable_csid_arr.push("N00000112");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B3");
usage_name_csid_arr.push("S00000133");
usage_3g_csid_arr.push("N00000153");
usage_sim_csid_arr.push("N00000173");
usage_enable_csid_arr.push("N00000113");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B4");
usage_name_csid_arr.push("S00000134");
usage_3g_csid_arr.push("N00000154");
usage_sim_csid_arr.push("N00000174");
usage_enable_csid_arr.push("N00000114");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B5");
usage_name_csid_arr.push("S00000135");
usage_3g_csid_arr.push("N00000155");
usage_sim_csid_arr.push("N00000175");
usage_enable_csid_arr.push("N00000115");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B6");
usage_name_csid_arr.push("S00000136");
usage_3g_csid_arr.push("N00000156");
usage_sim_csid_arr.push("N00000176");
usage_enable_csid_arr.push("N00000116");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B7");
usage_name_csid_arr.push("S00000137");
usage_3g_csid_arr.push("N00000157");
usage_sim_csid_arr.push("N00000177");
usage_enable_csid_arr.push("N00000117");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B8");
usage_name_csid_arr.push("S00000138");
usage_3g_csid_arr.push("N00000158");
usage_sim_csid_arr.push("N00000178");
usage_enable_csid_arr.push("N00000118");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029B9");
usage_name_csid_arr.push("S00000139");
usage_3g_csid_arr.push("N00000159");
usage_sim_csid_arr.push("N00000179");
usage_enable_csid_arr.push("N00000119");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029BA");
usage_name_csid_arr.push("S0000013A");
usage_3g_csid_arr.push("N0000015A");
usage_sim_csid_arr.push("N0000017A");
usage_enable_csid_arr.push("N0000011A");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029BB");
usage_name_csid_arr.push("S0000013B");
usage_3g_csid_arr.push("N0000015B");
usage_sim_csid_arr.push("N0000017B");
usage_enable_csid_arr.push("N0000011B");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029BC");
usage_name_csid_arr.push("S0000013C");
usage_3g_csid_arr.push("N0000015C");
usage_sim_csid_arr.push("N0000017C");
usage_enable_csid_arr.push("N0000011C");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029BD");
usage_name_csid_arr.push("S0000013D");
usage_3g_csid_arr.push("N0000015D");
usage_sim_csid_arr.push("N0000017D");
usage_enable_csid_arr.push("N0000011D");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029BE");
usage_name_csid_arr.push("S0000013E");
usage_3g_csid_arr.push("N0000015E");
usage_sim_csid_arr.push("N0000017E");
usage_enable_csid_arr.push("N0000011E");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
usage_record_csid_arr.push("N002029BF");
usage_name_csid_arr.push("S0000013F");
usage_3g_csid_arr.push("N0000015F");
usage_sim_csid_arr.push("N0000017F");
usage_enable_csid_arr.push("N0000011F");
usage_name_arr.push("");
usage_3g_arr.push(0);
usage_sim_arr.push(0);
alter_csid_arr.push("N80004320");
alter_csid_arr.push("N80004321");
alter_csid_arr.push("N80004322");
alter_csid_arr.push("N80004323");
alter_csid_arr.push("N80004324");
alter_csid_arr.push("N80004325");
alter_csid_arr.push("N80004326");
alter_csid_arr.push("N80004327");
alter_csid_arr.push("N80004328");
alter_csid_arr.push("N80004329");
alter_csid_arr.push("N8000432A");
alter_csid_arr.push("N8000432B");
alter_csid_arr.push("N8000432C");
alter_csid_arr.push("N8000432D");
alter_csid_arr.push("N8000432E");
alter_csid_arr.push("N8000432F");
mapping_arr.push(0);
if(swm_phy_3g_4g2>0){
mapping_arr.push(0);
}
/*
get rule number
3g1-SIM A
3g1-SIM B
3g2-SIM A
3g2-SIM B
目前最多4條
*/
for(var a=0;a<2;a++)
{
if(mapping_arr[a] == 1)
{
var daul = eval("swm_dualsim"+(a+1));
rule_number += (daul)?2:1;
}
usage_max_number = rule_number;
}
for(var x=0;x<usage_max_number;x++)
{
var select = usage_3g_arr[x];
var sim = usage_sim_arr[x];
if(select == 1 && sim == 1)
{
sim_used_arr[0] = 1;
}
else if(select == 1 && sim == 2)
{
sim_used_arr[1] = 1;
}
else if(select == 2 && sim == 1)
{
sim_used_arr[2] = 1;
}
else if(select == 2 && sim == 2)
{
sim_used_arr[3] = 1;
}
}
function add_usage()
{
if(usage_record_next_index == usage_max_number)
{
alert("rule can't more than "+usage_record_next_index);
return false;
}
GURL("system_data_usage_add.htm?Nindex="+usage_add_next_index+"&Nrecord="+usage_record_next_index);
}
function edit_usage(index)
{
GURL("system_data_usage_edit.htm?Nindex="+index);
}
function del_uasge()
{
var tmp_del = document.getElementsByName("usage_del");
var del_arr = [];
var index = 0;
var del_index =0;
var new_index = 0;
var sent_str ="hide.htm?";
var iframe = document.getElementById("i_rxternal");
var reset_del = "";
var show_message = 0;
var show_message_str = "";
var alter = "";
for(var t=0;t<tmp_del.length;t++)
{
if(tmp_del[t].checked)
{
del_arr.push(tmp_del[t].value)
}
}
if(del_arr.length == 0)
{
alert("Please select at least one server!");
return false;
}
for(var r=0;r<usage_record_arr.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(usage_record_arr[r] == del_arr[n])
{
usage_record_arr[r] = "";
}
}
}
for(var a=0;a<usage_record_arr.length;a++)
{
if(usage_record_arr[a] != "" || usage_record_arr[a] === 0)
{
sent_str += (sent_str == "hide.htm?")?"":"&";
sent_str += usage_record_csid_arr[new_index]+"="+usage_record_arr[a];
new_index++;
}
}
for(var c=new_index;c<usage_max_number;c++)
{
sent_str += (sent_str == "hide.htm?")?"":"&";
sent_str += usage_record_csid_arr[c]+"=";
}
for(var x=0;x<del_arr.length;x++)
{
var xx = del_arr[x];
var alter_index = (usage_3g_arr[xx]-1)*2+(usage_sim_arr[xx]-1);
sent_str += (sent_str == "hide.htm?")?"":"&";
sent_str += usage_name_csid_arr[xx]+"=";
sent_str += "&"+usage_3g_csid_arr[xx]+"=0";
sent_str += "&"+usage_sim_csid_arr[xx]+"=0";
sent_str += "&"+usage_enable_csid_arr[xx]+"=0";
alter += "&"+alter_csid_arr[alter_index]+"=1"
}
iframe.src = sent_str+alter+'&csrftok='+get_csrf_token(); // Add for CSRF defense;
setTimeout("data_usage_list()",2000);
}
/* for add and edit*/
function check_save()
{
var return_value = check_name()&&check_cycle()&&check_sim_select();
save_time();
save_limit();
check_alter();
return return_value;
}
/*
year:
month:0~11
day:1~31
hour:0~23
min:0~59
把值轉換成UTC 因為 javascript UTC 值比 Linux 多1000 所以結果要多除1000
20160114 CTA FC0改成沒有時和分，直接設成0
*/
function save_time()
{
var time = document.getElementById('h_starttime');
var year = document.getElementById('s_year').value;
var month = document.getElementById('s_month').value;
var day = document.getElementById('s_day').value;
var d = new Date()
var gmt  = d.getTimezoneOffset();
gmt = gmt*60*1000;
var sec = Date.UTC(year, month, day, 0, 0);
time.value = (sec+gmt)/1000;
}
/*
統一轉換為 KB
*/
function save_limit()
{
var limit_type = document.getElementById('s_limit_type').value;
var limit = document.getElementById('t_limit').value;
var h_limit = document.getElementById('h_limit');
h_limit.value = parseInt(limit)*limit_rate_arr[limit_type];
}
/*
cycle day檢查範圍為1~90
weeklly和Monthly直接填1
*/
function check_cycle()
{
var cycle_type = document.getElementById('s_cycle_type').value;
var cycle = document.getElementById('t_cycle');
var hcycle = document.getElementById('h_cycle');
var show_message = 0;
var message = "";
cyclev = parseInt(cycle.value);
if(cycle_type == 1)
{
if(cycle.value == ""){
alert("Cycle Period can not be empty!")
return false;
}
}
if(cycle_type == 1){
hcycle.value = cycle.value;
}else{
hcycle.value = 1;
}
return true;
}
/*
3G1 => 1
3G2 => 2
.
.
*/
function show_inter()
{
var inter = document.getElementById("s_3g");
for(var a=0;a<16;a++)
{
if(mapping_arr[a] == 1)
{   swname=eval("swName_3G"+(a+1))
var op = new Option(swname,(a+1))
inter.add(op);
}
}
inter.value = (inter_value == "")?0:inter_value;
change_sim();
}
/*
swm_dualsim1 = true 代表3G 1會有SIM A SIM B
swm_dualsim2 = true 代表3G 2會有SIM A SIM B
SIM A = 1
SIM B = 2
*/
function change_sim()
{
var inter = document.getElementById("s_3g").value;
var sim = document.getElementById("s_sim");
var dual = eval("swm_dualsim"+inter);
var sim_number = /*(dual)?2:*/1;
var sim_name_arr = ["SIM A"/*,"SIM B"*/];
var op;
sim.innerHTML = "";
for(var c=0;c<sim_number;c++)
{
op = new Option(sim_name_arr[c],(c+1));
sim.add(op);
}
sim.value = sim_value;
}
/*
get alter index
index = (3g_value-1)*2+sim_value-1
*/
function check_alter()
{
var alter = document.getElementById("h_cce");
var inter = parseInt(document.getElementById("s_3g").value);
var sim = parseInt(document.getElementById("s_sim").value);
var index = (inter-1)*2+sim-1;
alter.name = alter_csid_arr[index];
}
function chgdate(m,d){
d.innerHTML=""
monthv=parseInt(m.value)+1;
if(monthv==1||monthv==3||monthv==5||monthv==7||monthv==8||monthv==10||monthv==12){
for(a=1;a<=31;a++){
eval("d.options.add(new Option("+a+","+a+"))");
}
}
if(monthv==4||monthv==6||monthv==9||monthv==11){
for(a=1;a<=30;a++){
eval("d.options.add(new Option("+a+","+a+"))");
}
}
if(monthv==2){
for(a=1;a<=29;a++){
eval("d.options.add(new Option("+a+","+a+"))");
}
}
}