console.log(); let uchip = null; let mailaccounts_list = JSON.parse('{{mod.mailaccounts_list|json_encode|raw}}'); let forwarders_list = JSON.parse('{{mod.forwarders_list|json_encode|raw}}'); let forward_quota = JSON.parse('{{mod.fordwars_stats|json_encode|raw}}'); let pipes_list = JSON.parse('{{mod.pipes_list|raw}}'); function calculateQuota(){ let plan = $('#emaccount_plan').val(); $('#emaccountused').text(mailaccounts_list); if(plan >= 0){ if(mailaccounts_list == plan){ $('#addemailbtn').addClass('disabled'); $('#addemailbtn').prop('disabled', true) }else{ $('#addemailbtn').removeClass('disabled'); $('#addemailbtn').prop('disabled', false) } let percent = ((mailaccounts_list * 100) / plan).toFixed(0); $('#stat-percent-accounts').text(percent + '%'); let barcolor = getBarColor(percent); $('#baremailind').removeClass(); $('#baremailind').addClass(barcolor); $('#baremailind').width(percent + '%'); } } function addnewPipe(){ uchip.slideToggle('#new_pipe_form', '#main_pipe_view'); } function cancelnewPipe(){ uchip.slideToggle('#main_pipe_view', '#new_pipe_form', function(){ $('#forw').val(''); $('#domainforw option').eq(1).prop('selected', true); $('#phpversionfor').val('/usr/local/bin/php'); $('#filepipe').val(''); $('#pipe_file_selector').data('dir'); }); } function getBarColor(percent){ let classbar = ''; if (percent >=26 && percent <=50){ classbar = 'progress-bar progress-bar-success'; }else if(percent >=51 && percent <=75){ classbar = 'progress-bar progress-bar-warning'; }else if(percent >75){ classbar = 'progress-bar progress-bar-danger'; }else{ classbar = 'progress-bar'; } return classbar; } function calculateQuotaForw(){ $('#forwardused').text(forward_quota.account); let plan = forward_quota.pack; if(plan >= 0){ if(forward_quota.account == plan){ $('.btn-adder').addClass('disabled'); $('.btn-adder').prop('disabled', true) }else{ $('.btn-adder').removeClass('disabled'); $('.btn-adder').prop('disabled', false) } let percent = ((forward_quota.account* 100) / plan).toFixed(0); $('#stat_percent_forw').text(percent + '%'); let barcolor = getBarColor(percent); $('#barforwind').removeClass(); $('#barforwind').addClass(barcolor); $('#barforwind').width(percent + '%'); } } let pipe_table = null; function showFileSelector(){ $('#dir_explorer_domain .modal-body').html('
'); $('#dir_explorer_domain').modal('show'); callDirList('/'); } function selCurrentPath(){ let curpath = $('#current_path_dirsel').val(); $('.dir-sel-btn').attr('data-original-title',curpath); $('#dirsel').text(curpath); $('#dir_explorer_domain').modal('hide'); } function callDirList(directory){ uchip.handleButton('#sel_path_btn', 'fa-thumb-tack'); $('#dir_explorer_domain .modal-body').html('
'); uchip.call('module=forwarders_email&acc=filelisting', { data: 'basedir=' + directory, callback: function(response){ directory = directory.charAt(directory.length-1) == '/' ? directory : directory + '/'; renderDirSelector(directory, response); uchip.handleButton('#sel_path_btn', 'fa-thumb-tack', true); } }); } function renderDirSelector(base, items){ let dirs_html = ''; items.forEach((item) => { let item_html = '' if(item.isdir === true){ item_html = '
' + '' + item.item + '
'; }else{ item_html = '
' + '
' + item.item + '
{{langmod.MFWLAB9}}
'; } dirs_html += '
' + item_html + '
'; }); let html = ''; $('#dir_explorer_domain .modal-body').html(html); $('.dir-item').mouseover(function() { if($(this).data('isdir') !== true){ return; } $(this).find('.fa').removeClass('fa-folder-o').addClass('fa-folder-open-o'); }) .mouseout(function() { if($(this).data('isdir') !== true){ return; } $(this).find('.fa').removeClass('fa-folder-open-o').addClass('fa-folder-o'); }).click(function(){ let curpath = $('#current_path_dirsel').val(); if($(this).data('isdir') === true){ let dir = $(this).data('dir'); if(dir == '..'){ let pieces = curpath.split('/'); pieces.pop(); pieces.pop(); dir = pieces.join('/') }else{ dir = curpath + dir; } callDirList(dir); }else{ let file = $(this).find('.file-item-listing').data('file'); $('#pipe_file_selector').data('dir', curpath); $('#filepipe').val('/home/{{users}}' + curpath + file); $('#dir_explorer_domain').modal('hide'); } }); $('#dir_list').slideDown('fast'); } function pipeListTable(list){ pipes_list = list; let content_html = ''; if(pipes_list.length > 0){ let table_html = ''; let index = 0; pipes_list.forEach(function(pipe){ let button_state = ''; if(pipe.active == 1){ button_state = ''; }else{ button_state = ''; } table_html += '' + '' + (index + 1) + '' + '' + pipe.address + '' + '' + pipe.domain + '' + '' + pipe.php_path + '' + '' + pipe.script_path + '' + '' + '
' + button_state + '' + '
' + '' + ''; index++; }); content_html = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + table_html + '' + '
#{{langmod.ETITLEFW}}{{langmod.ETITLEDOMAIN}}{{langmod.EMLABEL12}}{{langmod.EMLABEL14}}{{langmod.EACTION}}
'; $('#pipe_table_container').html(content_html); $('#pipe_data_table').DataTable().destroy(); pipe_table = $('#pipe_data_table').DataTable(); }else{ content_html = '

No email pipes created

'; $('#pipe_table_container').html(content_html); } } $("#btn_pipeadd").click(function (){ //deletepipe var sw = 0; if($("#forw").val()==''){ sw = 1; $("#forw").css("border-color", "#A80705");} if($("#domainforw").val()==''){ sw = 1; $("#domainforw").css("border-color", "#A80705");} //if($("#phpversionfor").val()==''){ sw = 1; $("#phpversionfor").css("border-color", "#A80705");} if($("#filepipe").val()==''){ sw = 1; $("#filepipe").css("border-color", "#A80705");} if(sw==1){ noti_bubble('','{{langmod.EMLABEL15}}','error',false,false,'3000',true); return false; }else{ uchip.handleButton("#btn_pipeadd",'fa-floppy-o'); uchip.handleButton("#btn_pipecnl",'fa-ban'); // $("#btn_pipeadd").attr('disabled',true); // $("#btn_pipeadd").html(' {{langmod.EMLABEL13}}'); uchip.call('module=email_accounts&acc=addpipe', { data: "forw=" + $("#forw").val() + "&domainforw=" + $("#domainforw").val() + "&phpversionfor=" + $("#phpversionfor").val() + "&filepipe=" + $("#filepipe").val(), callback: function(response){ if(response.result == 'success'){ pipeListTable(response.list); forward_quota.account++; noti_bubble('','{{ langmod.EMLABEL16 }}','success',false,false,'3000',true); calculateQuotaForw(); cancelnewPipe(); }else{ noti_bubble('{{langmod.EMERROR}}','{{langmod.EMERROR}}','error',false,false,'3000',true); } uchip.handleButton("#btn_pipeadd",'fa-floppy-o', true); uchip.handleButton("#btn_pipecnl",'fa-ban', true); } }); } return false; }); let forwarders_table = null; function mailForwTable(list){ forwarders_list = list; let content_html = ''; if(forwarders_list.length > 0){ let table_html = ''; let index = 0; forwarders_list.forEach(function(forwarder){ let button_active = ''; if(forwarder.active == 1){ button_active = ''; }else if(forwarder.active == 5){ button_active = ''; }else{ button_active = ''; } table_html += '' + '' + (index + 1) + '' + '' + (forwarder.address.charAt(0) == '@' ? ' ' : '') + forwarder.address + '' + '
' + forwarder.goto + '
' + '' + forwarder.domain + '' + '' + '
' + ''+ button_active + '' + '
' + '' + ''; index++; }); let content_html = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + table_html + '' + '
#{{langmod.ETITLEFW}}{{langmod.ETITLEFWTO}}{{langmod.ETITLEDOMAIN}}{{langmod.EACTION}}
'; $('#table_forw_container').html(content_html); $('#table_forw_table').DataTable().destroy(); forwarders_table = $('#table_forw_table').DataTable(); $('[data-toggle="tooltip"]').tooltip() }else{ content_html = '

No email Forwarders created

'; $('#table_forw_container').html(content_html); } } function activepipeTwice(elem){ let email = $(elem).data('emailaddress'); let active = $(elem).data('status'); let btn_icon = 'fa-check'; let to_switch = 'fa-ban'; let class_add = 'btn-warning'; let class_rem = 'btn-success'; if(active != 1){ btn_icon = 'fa-ban'; to_switch = 'fa-check'; class_rem = 'btn-warning'; class_add = 'btn-success'; } uchip.handleButton(elem, btn_icon); uchip.call('module=email_accounts&acc=changestpipe', { data: "email=" + email + "&active=" + active, callback: function(response){ if(response.hasOwnProperty('result') && response.result == 'success'){ let action_type = '' let new_st = 0; if(active == 1){ new_st = 5; action_type = '{{langmod.EMLPIPEDEACTIVE}}'; }else{ new_st = 1; action_type = '{{langmod.EMLPIPEACTIVE}}'; } uchip.handleButton(elem, to_switch, true); $(elem).data('status', new_st); $(elem).removeClass(class_rem); $(elem).addClass(class_add); // switchEmailST(elem, response.response); noti_bubble(action_type,'{{langmod.EMSUCCT}}','success',false,false,'3000',true); }else{ uchip.handleButton(elem, btn_icon, true); noti_bubble('An error occurred','Ups!','error',false,false,'3000',true); } } }); } function deletepipe(st,email,dom, index){ if(st==0){ var strheader = '{{langmod.EDELETEEMAIL}}'; var strbody = '

'+email+'

'; var strfooter = ''; $("#deletemodalmail .modal-header").html(strheader); $("#deletemodalmail .modal-body").html(strbody); $("#deletemodalmail .modal-footer").html(strfooter); $("#deletemodalmail").modal('toggle'); return false; }else{ uchip.handleButton('#delp_button_' + index, 'fa-trash'); $("#deletemodalmail").modal('hide'); let tr = $('#tr_pipe_' + index); tr.addClass('deleting_tr'); uchip.call('module=email_accounts&acc=deletepipe', { data: "email=" + email + "&domain=" + dom, callback: function(response){ if(response.result == 'success'){ noti_bubble('{{langmod.EMLPIPEDELETED}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); tr.slideUp('fast', function(){ pipe_table.row(this).remove().draw(); }); forward_quota.account--; calculateQuotaForw(); }else{ noti_bubble('{{langmod.EMERROR}}','{{langmod.EMERROR}}','error',false,false,'3000',true); uchip.handleButton('#delp_button_' + index, 'fa-trash', true); tr.removeClass('deleting_tr'); } } }); } return false; } function forwardelete(st,email,tr){ if(st==0){ var strheader = '{{langmod.DBDELETEUSER}}'; var strbody = '

' + email + '

'; var strfooter = ''; $("#deletemodalmail .modal-header").html(strheader); $("#deletemodalmail .modal-body").html(strbody); $("#deletemodalmail .modal-footer").html(strfooter); $("#deletemodalmail").modal('toggle'); return false; }else if(st==1){ $("#deletemodalmail").modal('hide'); let button = '#delfm_button_' + tr; uchip.handleButton(button, 'fa-trash'); tr = $('#trfw_' + tr); tr.addClass('deleting_tr'); uchip.call('module=email_accounts&acc=forwardelete', { data: "email=" + email + "&goto="+$("#forwardersupd").val(), callback: function(response){ if(response.result == 'success'){ noti_bubble('{{langmod.EMSUCCT}}','{{langmod.EMLFORWARDDELETED}}','success',false,false,'3000',true); // $('#trfw_' + tr).slideUp(); tr.slideUp('fast', function(){ forwarders_table.row(this).remove().draw(); }); forward_quota.account--; calculateQuotaForw(); }else{ uchip.handleButton(button, 'fa-trash', true); tr.removeClass('deleting_tr'); noti_bubble('{{langmod.EMERROR}}','{{langmod.EMERROR}}','error',false,false,'3000',true); } } }); } } let mail_accounts_table = null; function mailAccountsTable(list){ mailaccounts_list = list; let content_html = ''; content_html = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
#{{langmod.ETITLEEMAIL}}{{langmod.ETITLEDOMAIN}}{{langmod.EMLABEL10}}{{langmod.ESPACE}}{{langmod.EACTION}}
'; // console.log('content_html', content_html); $('#table_email_container').append(content_html); $('.email-accounts-table').DataTable().destroy(); mail_accounts_table = $('.email-accounts-table').on('processing.dt', function (e, settings, processing) { $('#DataTables_Table_0_processing').hide(); if (processing) { $('#accounts_loader').fadeIn('fast'); // $('#DataTables_Table_0').fadeOut('fast', function(){ // $('#accounts_loader').fadeIn('fast'); // }); } else { $('#accounts_loader').fadeOut('fast'); // $('#accounts_loader').fadeOut('fast', function(){ // $('#DataTables_Table_0').fadeIn('fast'); // }); } }).DataTable({ serverSide: true, processing: true, ajax: { url: './{{users}}/index.php?module=email_accounts&acc=listemail', type: 'POST' }, columnDefs: [ { targets: -1, orderable: false } ], columns: [ { data: 'index' }, { data: 'email' }, { data: 'domain' }, { render: function ( data, type, row ){ return (row.lastaccess != null ? row.lastaccess : 'Never'); } }, { render: function ( data, type, row ){ let percent_usage = 0; if(row.quota > 0){ percent_usage = ((row.usade * 100) / row.quota); if(percent_usage > 100){ percent_usage = 100; } } let barcolor = getBarColor(percent_usage); percent_usage = percent_usage % 1 == 0 ? percent_usage : percent_usage.toFixed(2); let disp_usage = Math.round(((row.usade/1024)/1024)); disp_usage = disp_usage % 1 == 0 ? disp_usage : disp_usage.toFixed(2); let disp_quota = Math.round(((row.quota/1024)/1024)); disp_quota = disp_quota % 1 == 0 ? disp_quota : disp_quota.toFixed(2); return '' + '' + ' ' + '' + disp_usage + '/' + disp_quota + ' MB ' + percent_usage + '%' + '
' + '
' + '
'; } }, { render: function ( data, type, row ){ let st_title = '{{ langmod.EMSUSPENDED }}'; let btn_class = 'btn-success'; let bt_icon = 'fa-check'; if(row.active != 1){ st_title = '{{ langmod.EMACTIVE }}'; btn_class = 'btn-warning'; bt_icon = 'fa-ban'; } return '' + '' + '' + '' + '' + ''; }, className: 'actions-td' }, ], deferRender: true }); calculateQuota(); if(mailaccounts_list > 0){ // let table_content = ''; // let index = 1; // mailaccounts_list.forEach(function(emailacc){ // let percent_usage = 0; // if(emailacc.quota > 0){ // percent_usage = ((emailacc.usade * 100) / emailacc.quota); // if(percent_usage > 100){ // percent_usage = 100; // } // } // let barcolor = getBarColor(percent_usage); // let st_title = '{{ langmod.EMSUSPENDED }}'; // let btn_class = 'btn-success'; // let bt_icon = 'fa-check'; // if(emailacc.active != 1){ // st_title = '{{ langmod.EMACTIVE }}'; // btn_class = 'btn-danger'; // bt_icon = 'fa-ban'; // } // table_content += '' + // '' + index + '' + // '' + emailacc.email + '' + // '' + emailacc.domain + '' + // '' + (emailacc.lastaccess != null ? emailacc.lastaccess : 'Never') + '' + // '' + // '' + // '' + // ' ' + // '' + Math.round(((emailacc.usade/1024)/1024)) + '/' + Math.round(((emailacc.quota/1024)/1024)) + ' MB ' + percent_usage + '%' + // '
' + // '
' + // '
' + // '' + // '' + // '' + // '' + // '' + // '' + // '' + // ''+ // '' + // ''; // index++; // }); }else{ // content_html = '

No email accounts created

'; // $('#table_email_container').html(content_html); } } $("#btn-updatemodal").click(function (){ $("#alertdivforw").hide('blind'); if($("#forwardersupd").val()==''){ var msj='{{langmod.EFORWDI}}'; $("#alertdivforw").html('
'+msj+'
'); $("#alertdivforw").show('blind'); return false; }else{ btnporcess('off','btn-updatemodal','{{ langmod.EMLABEL9 }}'); uchip.call('module=email_accounts&acc=updateforwarders', { data: "email="+$("#hiddenemail").val()+"&goto="+$("#forwardersupd").val(), callback: function(response){ if(response.result == 'success'){ // $("#tdfw"+$("#idtrfw").val()).html($("#forwardersupd").val()); mailForwTable(response.list); btnporcess('on','btn-updatemodal','{{ langmod.EBTNEDITMODAL }}'); $("#editforwarddomain").modal('hide'); noti_bubble('{{langmod.EMUPDOKFORW}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); }else{ btnporcess('on','btn-updatemodal','{{ langmod.EBTNEDITMODAL }}'); noti_bubble('{{langmod.EERROR6}}','{{langmod.EMERROR}}','error',false,false,'3000',true); } } }); } }); function btnaddforwar(){ $("#alertforwar").hide(); if(($("#forwaraddres").val()=='') || ($("#domainforwar").val()=='') || ($("#forwarders").val()=='')){ noti_bubble('{{langmod.EFEILDR}}','{{langmod.EMERROR}}','error',false,false,'3000',true); return false; }else{ btnporcess('off','btn-addforwar','{{ langmod.EMLABEL9 }}'); uchip.call('module=email_accounts&acc=addforwar', { data: "forwaraddres="+$("#forwaraddres").val()+"&domainforwar="+$("#domainforwar").val()+"&forwarders="+$("#forwarders").val(), callback: function(response){ if(response.result != 'success'){ noti_bubble('{{langmod.EMERROR}}','{{langmod.EMERROR}}','error',false,false,'3000',true); btnporcess('on','btn-addforwar','{{ langmod.EYES }}'); mailForwTable(response.list); }else{ // console.log('response', response); noti_bubble('{{langmod.EMLFORWARDCREATED}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); // refrespanelnew('email_forwarders'); mailForwTable(response.list); forward_quota.account++; calculateQuotaForw(); btnporcess('on','btn-addforwar','{{ langmod.EYES }}'); $("#addmailmodal").modal('hide'); } } }); // $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); // $.ajax({ // type: "POST", // url: "./{{users}}/index.php?module=email_accounts&acc=addforwar", // data: "forwaraddres="+$("#forwaraddres").val()+"&domainforwar="+$("#domainforwar").val()+"&forwarders="+$("#forwarders").val(), // complete: function(datos){ // //alert(datos.responseText); // //if((datos.responseText==6) || (datos.responseText==9)){ // if(datos.responseText!=''){ // //if(datos.responseText==6){ var msj='{{langmod.ERROR6}}'; }else{ var msj='{{langmod.ERROR9}}'; } // //noti_bubble(msj,'{{langmod.EMERROR}}','error',false,false,'3000',true); // noti_bubble(datos.responseText,'{{langmod.EMERROR}}','error',false,false,'3000',true); // btnporcess('on','btn-addforwar','{{ langmod.EYES }}'); // return false; // } else{ // listforwar(); // noti_bubble('{{langmod.EMLFORWARDCREATED}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); // refrespanelnew('email_forwarders'); // btnporcess('on','btn-addforwar','{{ langmod.EYES }}'); // $("#addmailmodal").modal('hide'); // } // } // }); } } function btnaddemail(){ $("#alertemail").hide('blind'); let quotamail = parseInt($("#quotamail").val()); if(($("#emailaddres").val()=='') || ($("#domain").val()=='') || ($("#pass").val()=='') || !quotamail === parseInt(quotamail, 10)){ if(!quotamail === parseInt(quotamail, 10)){ $("#quotamail").addClass('error'); } noti_bubble('{{langmod.EFEILDR}}','{{langmod.EMERROR}}','error',false,false,'3000',true); return false; }else{ var pass=$("#pass").val(); pass=pass.replace('&','||@||'); pass=pass.replace('%','|/@/|'); $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); btnporcess('off','btnaddemail','{{ langmod.EMLABEL9 }}'); uchip.call('module=email_accounts&acc=addemail', { data: "email=" + $("#emailaddres").val() + "&domain=" + $("#domain").val() + "&pass=" + pass + ""amail=" + quotamail, callback: function(response){ if(response.result == 'success'){ // mailAccountsTable(response.list); mail_accounts_table.ajax.reload( null, false ); btnporcess('on','btnaddemail','{{ langmod.EADD }}'); noti_bubble('{{langmod.EMSUCCT}}','{{langmod.EMCREATOK}}','success',false,false,'3000',true); $("#addmailmodal").modal('hide'); }else{ if((response.code == 4) || (response.code == 5) || (response.code == 6)){ if(response.code == 4){ var msj='{{langmod.EERROR4}}';} if(response.code == 5){ var msj='{{langmod.EERROR5}}';} if(response.code == 6){ var msj='{{langmod.EERROR6}}';} noti_bubble(msj,'{{langmod.EMERROR}}','error',false,false,'3000',true); btnporcess('on','btnaddemail','{{ langmod.EADD }}'); } } } }); return false; } } mailAccountsTable(mailaccounts_list); mailForwTable(forwarders_list); pipeListTable(pipes_list); function forwardactiveTwice(elem){ let email = $(elem).data('emailaddress'); let st = $(elem).data('status'); let btn_icon = 'fa-check'; let to_switch = 'fa-ban'; let class_add = 'btn-warning'; let class_rem = 'btn-success'; if(st != 1){ btn_icon = 'fa-ban'; to_switch = 'fa-check'; class_rem = 'btn-warning'; class_add = 'btn-success'; } uchip.handleButton(elem, btn_icon); uchip.call('module=email_accounts&acc=changestforward', { data: "email=" + email + "&st=" + st, callback: function(response){ if(response.hasOwnProperty('result') && response.result == 'success'){ let action_type = '' let new_st = 0; if(st == 1){ new_st = 5; action_type = '{{langmod.EMLFORWARDDEACTIVE}}'; }else{ new_st = 1; action_type = '{{langmod.EMLFORWARDACTIVE}}'; } uchip.handleButton(elem, to_switch, true); $(elem).data('status', new_st); $(elem).removeClass(class_rem); $(elem).addClass(class_add); // switchEmailST(elem, response.response); noti_bubble(action_type,'{{langmod.EMSUCCT}}','success',false,false,'3000',true); }else{ uchip.handleButton(elem, btn_icon, true); noti_bubble('An error occurred','Ups!','error',false,false,'3000',true); } } }); // $.ajax({ // type: "POST", // dataType: "json", // url: "./{{users}}/index.php?module=email_accounts&acc=changestforward", // data: "email=" + email+"&st="+st, // complete: function (datos) { // datos = datos.responseJSON; // if(datos.hasOwnProperty('result') && datos.result == 'success'){ // let action_type = '' // if(datos.response == 5){ // action_type = '{{langmod.EMLFORWARDDEACTIVE}}'; // }else{ // action_type = '{{langmod.EMLFORWARDACTIVE}}'; // } // switchEmailST(elem, datos.response); // noti_bubble(action_type,'{{langmod.EMSUCCT}}','success',false,false,'3000',true); // }else{ // noti_bubble('An error occurred','Ups!','error',false,false,'3000',true); // } // $('.table-loader-cwp').hide(); // return false; // } // }); } function emailactiveTwice(elem){ let email = $(elem).data('emailaddress'); let st = $(elem).data('status'); let btn_icon = 'fa-ban'; let to_switch = 5; if(st != 1){ btn_icon = 'fa-check'; to_switch = 1; } uchip.handleButton(elem, btn_icon); uchip.call('module=email_accounts&acc=changestemail', { data: "email=" + email+"&st="+st, callback: function(response){ if(response.result == 'success'){ if(st == 1){ action_type = '{{langmod.EDESACTIVEEMAIL}}'; }else{ action_type = '{{langmod.EACTIVEEMAIL}}'; } uchip.handleButton(elem, btn_icon, false); switchEmailST(elem, to_switch); noti_bubble(action_type,'{{langmod.EMSUCCT}}','success',false,false,'3000',true); }else{ noti_bubble('An error occurred','Ups!','error',false,false,'3000',true); } } }); // $.ajax({ // type: "POST", // dataType: "json", // url: "./{{users}}/index.php?module=email_accounts&acc=changestemail", // data: "email=" + email+"&st="+st, // complete: function (datos) { // datos = datos.responseJSON; // if(datos.hasOwnProperty('result') && datos.result == 'success'){ // let action_type = '' // if(datos.response == 5){ // action_type = '{{langmod.EDESACTIVEEMAIL}}'; // }else{ // action_type = '{{langmod.EACTIVEEMAIL}}'; // } // switchEmailST(elem, datos.response); // noti_bubble(action_type,'{{langmod.EMSUCCT}}','success',false,false,'3000',true); // }else{ // noti_bubble('An error occurred','Ups!','error',false,false,'3000',true); // } // $('.table-loader-cwp').hide(); // return false; // } // }); } function emaildelete(st,email,tr){ if(st==0){ var strheader = '{{langmod.EDELETEEMAIL}}'; var strbody = '

'+email+'

'; var strfooter = ''; $("#deletemodalmail .modal-header").html(strheader); $("#deletemodalmail .modal-body").html(strbody); $("#deletemodalmail .modal-footer").html(strfooter); $("#deletemodalmail").modal('toggle'); return false; }else{ $("#deletemodalmail").modal('hide'); let button = '#delem_button_' + tr; uchip.handleButton(button, 'fa-trash'); tr = $('#mailaccount_line_' + tr); tr.addClass('deleting_tr'); uchip.call('module=email_accounts&acc=emaildelete', { data: "email=" + email + "&st=" + st, callback: function(response){ if(response.result == 'success'){ noti_bubble('{{langmod.EMDELETEEMOK}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); tr.slideUp('fast', function(){ mail_accounts_table.row(this).remove().draw(); }); mailaccounts_list--; calculateQuota(); }else{ uchip.handleButton(button, 'fa-trash', true); tr.removeClass('deleting_tr'); noti_bubble('{{langmod.EERROR2}}','{{langmod.EWARNING}}','error',false,false,'3000',true); } } }); return false; } return false; } // END CCMORALES NEW JS function activepipe(email,active){ $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=pipe&op=udp", data:"email="+email+"&active="+active, complete: function(datos){ //console.log(datos.responseText); $('#dataTables-pipe').DataTable().ajax.reload( function ( json ) { } ); noti_bubble('','{{langmod.EMLABEL16}}','success',false,false,'3000',true); return false; } }); } function updatelistemail(){ $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=updatelistemail", complete: function (datos) { $("#contenttr").html(datos.responseText); return false; } }); return false; } function switchEmailST(elem, response){ let icon = $(elem).find('i'); $(elem).data('status', response); if(response != 1){ $(elem).removeClass('btn-success'); $(elem).addClass('btn-warning'); icon.removeClass('fa-check'); icon.addClass('fa-ban'); }else{ $(elem).removeClass('btn-warning'); $(elem).addClass('btn-success'); icon.addClass('fa-check'); icon.removeClass('fa-ban'); } } function emailactive(email,st){ $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=changestemail", data: "email=" + email+"&st="+st, complete: function (datos) { $('#dataTables-examplemail').DataTable().ajax.reload( function ( json ) { } ); if(datos.responseText==5){ noti_bubble('{{langmod.EDESACTIVEEMAIL}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); } if(datos.responseText==1){ noti_bubble('{{langmod.EACTIVEEMAIL}}','{{langmod.EMSUCCT}}','success',false,false,'3000',true); } return false; } }); } function btncancelemail(){ $("#addmailmodal").modal('hide'); } function changerrandom(inputdiv, elem){ $(elem).hide(); $('.generator_loader').show(); var long = $(elem).parent().find("#lengthpass").val(); var typepass = $(elem).parent().find("#typepass").val(); $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=changerrandom&long="+long+"&typepass="+typepass, complete: function(datos){ $('.generator_loader').hide(); $(elem).show(); $("#"+inputdiv).val(datos.responseText); if(inputdiv == 'pass1email'){ $('#pass1email').pwstrength("forceUpdate"); $('#pass2email').val(datos.responseText); }else if(inputdiv == 'pass'){ $('#pass').pwstrength("forceUpdate"); } copyPass(inputdiv); return false; } }); return false; } $('#modal-changepassemail').on('shown.bs.modal', function (e) { }); $(document).ready(function() { {% if mod.isie == 1 %} uchip = new $.Uchip(); {% else %} uchip = new Uchip(); {% endif %} // var options1 = {}; options1.ui = { container: "#changepass_container", showVerdictsInsideProgressBar: true, viewports: { progress: ".pwstrength_viewport_progress" } }; options1.common = { debug: false, }; $('#pass1email').pwstrength(options1); // var table = $('#dataTables-examplefor').on( 'processing.dt', function ( e, settings, processing ) { // $('#dataTables-examplefor_processing').css('display', 'none'); // if (processing) { // $(this).hide(); // $('#tab-2 .table-loader-cwp').show(); // } else { // $('#tab-2 .table-loader-cwp').hide(); // $(this).show(); // } // }).DataTable({ // "processing": true, // "bProcessing": true, // "bServerSide": true, // 'iDisplayLength': 25, // "ajax": { // "url": "./{{users}}/index.php?module=email_accounts&acc=listforwar", // "type": "POST" // }, // responsive: true // }); // var table = $('#dataTables-examplemail').on( 'processing.dt', function ( e, settings, processing ) { // $('#dataTables-examplemail_processing').css('display', 'none'); // if (processing) { // $(this).hide(); // $('#tab-1 .table-loader-cwp').show(); // } else { // $('#tab-1 .table-loader-cwp').hide(); // $(this).show(); // } // }).DataTable({ // "processing": true, // "bProcessing": true, // "bServerSide": true, // 'iDisplayLength': 25, // "ajax": { // "url": "./{{users}}/index.php?module=email_accounts&acc=listemail", // "type": "POST" // }, // responsive: true // }); var table = $('#dataTables-pipe').on( 'processing.dt', function ( e, settings, processing ) { $('#dataTables-pipe_processing').css('display', 'none'); if (processing) { $(this).hide(); $('#tab-3 .table-loader-cwp').show(); } else { $('#tab-3 .table-loader-cwp').hide(); $(this).show(); } }).DataTable({ "processing": true, "bProcessing": true, "bServerSide": true, 'iDisplayLength': 25, "ajax": { "url": "./{{users}}/index.php?module=email_accounts&acc=pipe&op=list", "type": "POST" }, responsive: true }); }); $('#modal-changepassemail').on('hidden.bs.modal', function (e) { $('#pass1email').val(''); $('#pass2email').val(''); }) function refreshList(){ $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=listemail", complete: function(datos){ //$('.dataTables-example').DataTable().destroy(); //$("#contftp").html(datos.responseText); //$('.dataTables-example').DataTable(); $('#dataTables-examplemail').DataTable().ajax.reload( function ( json ) { } ); noti_bubble('{{langmod.EMSUCCT}}','{{langmod.EMCREATOK}}','success',false,false,'3000',true); refrespanelnew('email_accounts'); btnporcess('on','btnaddemail','{{ langmod.EADD }}'); $("#addmailmodal").modal('hide'); return false; } }); } function chancetabemail(sw){ $('.mail-tabs .nav-tabs a.active').removeClass('active'); if(sw==0){ $("#indemail").show(); $("#indforw").hide(); }else{ $("#indforw").show(); $("#indemail").hide(); } } $('#editforwarddomain').on('hidden.bs.modal', function (e) { // $('#forwardersupd').tagsinput('destroy'); }) let tagInputRendered = false; function myTrim(x) { return x.replace(/^\s+|\s+$/gm, ''); } function editforwar(elem){ let forward = $(elem).data('forward'); let goto = $(elem).data('goto'); let idtr = $(elem).data('idtr'); var msj='

{{langmod.ETITLEFW}}: ' + forward + '

'; $("#contentmodaludp").html(msj); goto = goto.replace(' ', ''); if(tagInputRendered){ $('#forwardersupd').tagsinput('destroy'); } $("#forwardersupd").val(goto); $("#editforwarddomain").modal('toggle'); $('#forwardersupd').tagsinput({ tagClass: 'cwp-tags-input' }); tagInputRendered = true; // console.log('HELLO THIS IS'); $('#forwardersupd').on('beforeItemAdd', function(event) { if (!validateEmail(myTrim(event.item))){ event.cancel = true; $('#invalid_mail_alert').slideDown(); setTimeout(function(){ $('#invalid_mail_alert').slideUp(); }, 3500); } // event.item: contains the item // event.cancel: set to true to prevent the item getting added }); return false; } function forwardactive(email,st){ $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=changestforward", data: "email=" + email+"&st="+st, complete: function (datos) { listforwar(); noti_bubble('{{langmod.EMSUCCT}}','{{langmod.EUPDFORW}}','success',false,false,'3000',true); return false; } }); } function ediquotaemail(email,quota){ $("#quotaemailmodal").val((quota/1024/1024)); $("#quotaemailtitle").html(email); $("#quotaemailhidde").html(email); $("#modal-updquotemail").modal('toggle'); return false; } function emailchangepass(email){ $("#labelemail").html(email); $("#modal-changepassemail").modal('toggle'); $("#emailpass").val(email); return false; } function addforwarbtn(){ var vheader=''; // var vbody='
' + '
' + '@' + '
' + '' + '' + '
' + '
'+ '
'+ '' + ' {{ langmod.ETITLEF3 }}' + '
{{langmod.MFWLAB14}}
' + '
' + ''+ ''; // {% for email2 in mod.email2 %} // vbody+=''; // {% endfor %} // vbody+='
{{ langmod.ETITLEF3 }}
'; var vfooter=' '; $("#addmailmodal .modal-header").html('

{{langmod.MFWLAB16}}

'); $("#addmailmodal .modal-body").html(vbody); $("#addmailmodal .modal-footer").html(vfooter); $("#addmailmodal").modal('toggle'); $('#forwarders').tagsinput({ tagClass: 'cwp-tags-input' }); $('#forwarders').on('beforeItemAdd', function(event) { if(!validateEmail(event.item)){ event.cancel = true; $('#invalid_mail_alert').slideDown(); setTimeout(function(){ $('#invalid_mail_alert').slideUp(); }, 3500); } // event.item: contains the item // event.cancel: set to true to prevent the item getting added }); return false; } function validateEmail(email) { {#var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email);#} return true; } function listforwar(){ } function btncancelforwar(){ $("#addmailmodal").modal('hide'); return false; } $("#addemailbtn").click(function (){ //let password_preset = $(this).data('pass'); let password_preset = generatePasswordRand(12,'num'); console.log(password_preset); var headermod = '

{{ langmod.EBNTADD }}

'; let bodymod = '
' + '
' + '
' + ' ' + '' + '
' + '@' + '
' + '' + '' + '
' + '
' + '
' + '
' + '' + '' + '' + '
' + '' + ' ' + '' + '
' + '' + '
' + '' + '' + '' + '' + '' + '
' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '' + ' ' + '' + '
' + ' ' + '' + '
' + '
' + '
'; var footermod = ' '; $("#addmailmodal .modal-header").html(headermod); $("#addmailmodal .modal-body").html(bodymod); $("#addmailmodal .modal-footer").html(footermod); var options1 = {}; options1.ui = { container: "#pwd-container", showVerdictsInsideProgressBar: true, viewports: { progress: ".pwstrength_viewport_progress" } }; options1.common = { debug: false, }; $('#pass').pwstrength(options1); $("#addmailmodal").modal('toggle'); }); function hideOnClickOutside(selector, second){ let forhide = false; if(second === undefined){ second = '#show_options_button'; forhide = true; } function outsideClickListener(event){ $target = $(event.target); if (!$target.closest(selector).length && !$target.closest(second).length && $(selector).is(':visible')) { if(forhide){ $(selector).hide(); }else{ $(selector).remove(); } removeClickListener(); } } function removeClickListener(){ document.removeEventListener('click', outsideClickListener) } document.addEventListener('click', outsideClickListener) } function closePGOPT(){ $('.pgopt_container').slideUp(); } function openPGOPT(){ if($('.pgopt_container').is(':visible')){ closePGOPT(); }else{ $('.pgopt_container').slideDown(); hideOnClickOutside('.pgopt_container'); } } function copyPass(elem){ let field = document.getElementById(elem); field.select(); document.execCommand('copy'); $('.mail-password-generator-copied').slideDown(); setTimeout(function(){ $('.mail-password-generator-copied').slideUp(); }, 4500); } function showConfigMenu(elem, id_elem){ let elem_data = $(elem).data('mailconfig'); let html_config = '

Windows live mail configuration

'; $(elem).parent().prepend(html_config); hideOnClickOutside('.' + id_elem, '#' + id_elem); } $("#domainforw").change(function (){ $.ajax({ type: "POST", url: "./{{ users }}/index.php?module=email_accounts&op=typephp&acc=pipe", data: "domain="+$("#domainforw").val(), complete: function(datos){ return false; } }); }); $("#btn-savequotaemail").click(function () { if($("#quotaemailmodal").val()==''){ noti_bubble('{{langmod.EMERROR}}','{{langmod.EMERROR2}}','error',false,true,'3000',true); return false; }else{ $("#btn-savequotaemail").attr('disabled',true); $("#btn-savequotaemail").addClass('disabled'); $.ajax({ type: "POST", url: "./{{users}}/index.php?module=email_accounts&acc=updquotaemail", data: "email=" + $("#quotaemailtitle").html() + ""a=" + (($("#quotaemailmodal").val()*1024)*1024), complete: function (datos) { $("#modal-updquotemail").modal('hide'); refreshList(); noti_bubble('{{langmod.EMSUCCT}}','{{langmod.EMUPDOK}}','success',false,false,'3000',true); //$("#bar_cp_mysql_manager").empty().removeData().attr('data-percent', porc).circliful( { backgroundColor: '#eeeeee', foregroundColor: bgcolorcirc }); $("#btn-savequotaemail").attr('disabled',false); $("#btn-savequotaemail").removeClass('disabled'); return false; } }) } }); $("#btn-changpassemail").click(function (){ btnporcess('off','btn-changpassemail','{{ langmod.EMLABEL9 }}'); if(($("#pass1email").val()=='') && ($("#pass1email").val()=='')) { noti_bubble('{{langmod.EMERROR}}','{{langmod.EFEILDR}}','error',false,true,'3000',true); btnporcess('on','btn-changpassemail','{{ langmod.EBTCSAVE }}'); return false; }else if( $("#pass1email").val() != $("#pass2email").val()){ noti_bubble('{{langmod.EMERROR}}','{{langmod.EERROR1}}','error',false,true,'3000',true); btnporcess('on','btn-changpassemail','{{ langmod.EBTCSAVE }}'); return false; }else{ uchip.call('module=email_accounts&acc=changpassemail', { data: "email="+$("#emailpass").val()+"&pass1email="+ btoa($("#pass1email").val()), callback: function(response){ if(response.result == 'success'){ $("#modal-changepassemail").modal('hide'); noti_bubble('{{langmod.EMSUCCT}}','{{langmod.EMCHANGEPASSOK}} '+$("#emailpass").val()+'','success',false,false,'3000',true); btnporcess('on','btn-changpassemail','{{ langmod.EBTCSAVE }}'); }else{ if(response.code==7){var msj='{{langmod.ERROR7}}'} if(response.code==8){var msj='{{langmod.ERROR8}}'} noti_bubble('{{langmod.EMERROR}}',+msj,'error',false,false,'3000',true); btnporcess('on','btn-changpassemail','{{ langmod.EBTCSAVE }}'); return false; } } }); return false; } });