<?php

//////////////////////////////////////////////////////////////
//===========================================================
// hf_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       8th Mar 2010
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function js_url(){	
	$js['givejs'] = func_get_args();
	return $GLOBALS['theme']['url'].'/js/givejs.php?'.http_build_query($js).'&'.$GLOBALS['globals']['version'].'.'.$GLOBALS['globals']['patch'];
}

function css_url(){	
	$r['givecss'] = func_get_args();
	return $GLOBALS['theme']['url'].'/css/givecss.php?'.http_build_query($r).'&'.$GLOBALS['globals']['version'].'.'.$GLOBALS['globals']['patch'];
}

function softheader($title = '', $leftbody = true){

global $theme, $globals, $kernel, $user, $l, $error, $servers, $version_changes, $leftmenu;

	if(optGET('jsnohf')){
		return true;
	}
	
	$title = ((empty($title)) ? $globals['sn'] : $title);
	
	// Show the all option instead
	$all = (in_array($GLOBALS['act'], array('addiso', 'addplan', 'addserver', 'addtemplate', 'adduser', 'mail', 'createtemplate', 'downloadiso', 'editemailtemp', 'editippool', 'editips', 'editplan', 'editserver', 'edittemplate', 'edituser', 'old_editvs', 'emailtemp', 'ippool', 'ips', 'iso', 'loginlogs', 'iplogs', 'logs', 'os', 'ostemplates', 'plans', 'servers', 'ubc', 'userlogs', 'users', 'vnc', 'webuzo', 'vs', 'backupservers', 'addbackupserver', 'editbackupserver', 'databackup', 'migrate', 'feedback', 'tasks', 'addippool', 'config', 'updates', 'recipes', 'addrecipe', 'editrecipe', 'clone', 'vps_stats', 'server_stats', 'config_slave', 'addvs', 'haproxy', 'backup_plans', 'addbackup_plan', 'editbackup_plan', 'euiso', 'webuzo', 'ha', 'twofactauth', 'storage', 'resource_pricing', 'billing', 'invoices', 'transactions', 'addinvoice', 'addtransaction', 'admin_acl', 'add_distro', 'adddnsplan','editdnsplan', 'dnsplans', 'domains', 'pdns', 'editpdns', 'rebuild', 'addips', 'addstorage', 'adduser_plans', 'managevps','list_distro', 'ipranges', 'addiprange', 'editiprange', 'edit_admin_acl', 'add_admin_acl', 'terminal', 'create_api', 'list_api', 'show_api_log', 'volumes', 'vpsrestore', 'smart_devices' ,'api_credential_edit','load_balancer','migrate_disk', 'passthrough', 'editpassthrough', 'firewall_plans', 'addfirewall_plan','editfirewall_plan', 'addserver_firewall_plan', 'server_firewall_plans', 'csf', 'vpsfirewallconfig', 'storageusage', 'user_sessions', 'user_notice', 'add_user_notice', 'edit_user_notice', 'adminindex', 'edittransaction', 'tax_rules', 'backup_dashboard', 'serverfirewall_status', 'support_access', 'list_kyc', 'kyc_setting', 'edit_kyc', 'cloud_setup', 'server_sshkeys', 'list_baremetals', 'add_baremetal', 'edit_baremetal', 'dnsrecords', 'manage_baremetal', 'list_datacenters',  'add_datacenter', 'edit_datacenter', 'list_dcfloors', 'add_dcfloors', 'edit_dcfloors', 'list_dcracks', 'add_dcracks', 'edit_dcracks', 'servergroups', 'notice', 'addmg', 'editsg', 'user_plans', 'edituser_plans', 'view_firewall_rules','')) ? 1 : 0);
	
	//Lets echo the top headers
	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset='.$globals['charset'].'" />
	<meta name="keywords" content="softaculous, software" />
	<title>'.$title.'</title>
	<link rel="stylesheet" type="text/css" href="'.css_url('bootstrap.min.css', 'jquery-ui.css', 'all.min.css', 'select2.css', 'dataTables-jui.css', 'font.css', 'admin.css', 'jquery.scrollbar.css', 'toastr.min.css').'" />
	<link rel="preconnect" href="https://fonts.googleapis.com">
	<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
	<link rel="shortcut icon" href="'.(empty($globals['favicon_url']) ? $theme['images'].'favicon.ico' : $globals['favicon_url']).'" />	

	<script language="javascript" src="'.js_url('jquery.js', 'jquery-ui.js', 'apexcharts.min.js', 'popper.min.js', 'bootstrap.min.js', 'tiptip.js', 'menu.js', 'select2.js', 'jquery.tablesorter.min.js', 'universal.js', 'jquery.scrollbar.min.js', 'toastr.min.js').'" type="text/javascript"></script>
	<script language="javascript" id="lazyload" type="text/javascript"></script>
<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
function on_load_theme(){
	var default_theme = localStorage.getItem("default_theme");
	const body = document.body;
	if(default_theme == "dark"){
		body.classList.add("dark");
	}else{
		body.classList.add("light");
	}
};


function theme_switcher(switcher = 0) {
    var default_theme = localStorage.getItem("default_theme");
    const body = document.body;
    const theme_checkbox = document.getElementById("theme_checkbox");

    if (!default_theme) {
        localStorage.setItem("default_theme", "light");
        default_theme = "light";
    }

    if (default_theme == "light") {
        theme_checkbox.checked = false;
    } else {
        theme_checkbox.checked = true;
    }

    if (switcher) {
        if (default_theme == "light") {
            body.classList.replace("light", "dark");
            localStorage.setItem("default_theme", "dark");
            theme_checkbox.checked = true;
        } else {
            body.classList.replace("dark", "light");
            localStorage.setItem("default_theme", "light");
            theme_checkbox.checked = false;
        }
    }
}



// For refreshing public notes every 10 secs
var interval = null;
var exportInterval = null;
var notes_search = null;
var notes_count = [0, 0];
var notes_currpage = [1, 1];
var success_lang = "'.__J('Success').'";
var error_lang = "'.__J('Error').'";
var warning_lang = "'.__J('Warning').'";
var note_lang = "'.__J('Note').'";
var global_docs = "'.$globals['docs'].'";

var pbar_notice = "'.__J('Note: This process may take a while.').'";
var pbar_tip = "'.__J('Navigating away from this page, will not affect this process.').'";

// Task log show/hide lang
var show_l = "'.__J('Show').'";
var hide_l = "'.__J('Hide').'";

// language for universal search
var l_unisear_hdr_res = "'.__J('Search Results').'";
var l_unisear_no_res = "'.__J('No search results!').'";
var l_unisear_show_all = "'.__J('Show all').'";
var l_unisear_res = "'.__J('results >>').'";

var show_more_l = "'.__J('Show more').'";
var show_less_l = "'.__J('Show less').'";

var open_guide_l = "'.__J('Open the guide').'";
var show_log_lang = "'.__J('Show Log').'";

cur_server = new Object();
cur_server.id = '.$globals['server'].';
cur_server.virt = "'.$servers[$globals['server']]['virt'].'";
function changeserver(id, virt, el){
	puller("serv_list");
	if(id == cur_server.id){
		return false;
	}
	cur_server.id = id;
	cur_server.virt = virt;
	setcookie("'.$globals['cookie_name'].'_server", id, 365);
	var cells = el.cells;
	$_("cur_serv_virt").src="'.$theme['images'].'admin/"+virt+"_28.gif";
	$_("cur_serv_name").innerHTML = cells[1].innerHTML;
	$_("cur_serv_ip").innerHTML = cells[2].innerHTML;
	try{ on_server_change(); }catch(e){	window.location.href = window.location.href; }
	return true;
};

// New changeserver function
function changeserver2(id) {
	 setcookie("'.$globals['cookie_name'].'_server", id, 365);
	 // to change url problem in manageserver 
	 var newurl = replaceUrlParam(window.location.href, "changeserid", id);
	 window.location = newurl;	
}

// Returns the template for server select drop down
function formatState (state) {
	if (!state.id) { return state.text; }
	var icon = $(state.element).data("icon");
	var $state = $(
		"<span><img src=\"" + icon + "\" class=\"img-flag mr-3\" /> " + state.text + "</span>"
	);
	return $state;
};

$(document).ready(function() {

	var menu_state = getcookie("menu_state");
	if (menu_state === "collapsed") {
		left_menu_toggle(true); // Force the state to be minimized
	} else {
		left_menu_toggle(false); // Force the state to be expanded
	}
	
	$("#dismiss_version").click(function(){
		$.ajax({
		   url: "'.$globals['index'].'disable_cur_version_changelog=1&cur_changelog_version='.str_replace(".","-",$globals['version'].'.'.$globals['patch']).'", 
		   success: function(result){
			   $("#version-modal").modal("hide");
		   }
	   	});
   	});

	$(".nav-server-select").select2({
		width: "100%",
	}); 
	function formatText (icon) {
		return $(\'<span>\'+(!empty($(icon.element).data(\'virt\')) ? show_server_virtname($(icon.element).data(\'virt\')) : \'\')+$(icon.element).html()+(!empty($(icon.element).data(\'icon-ram\')) ? \'<i class="fas \'+$(icon.element).data(\'icon-ram\')+\' mx-2"></i>\' +$(icon.element).data(\'ram-text\')+\'&nbsp;MB&nbsp;'.__J('Free').'\' : \'\')+(!empty($(icon.element).data(\'icon-disk\')) ? \'<i class="fas \'+$(icon.element).data(\'icon-disk\')+\' mx-2"></i>\' +$(icon.element).data(\'disk-text\')+\'&nbsp;GB&nbsp;'.__J('Free').'\' : \'\')+\'</span>\');
	};
	
	$(\'.server-select,#band_ser\').select2({
		width: "100%",
		templateSelection: formatText,
		templateResult: formatText
	});
	$(".server-select").on("change", function() {
		changeserver2(this.value);
	});	

	$(".virt-select, .chosen").select2({
		width:"100%"
	});
	
	$("#recipe").select2({
		placeholder : "",
		allowClear: true,
		width: "100%"
	});
	$("#recipe").on("select2:select", function (evt) {
		var element = evt.params.data.element;
		var $element = $(element);
	
	$element.detach();
		$(this).append($element);
		$(this).trigger("change");
	}); 
   
	$(".scrollbar, .search_scroll").scrollbar();

	$(".modal").on("hidden.bs.modal", function (e) {
		if($(".modal.show").length > 0){
			$("body").addClass("modal-open");
		}
	});

	$(".modal").on("shown.bs.modal", function (e) {
		$("#navbar, body").removeAttr("style");
	});
	var firstName = "'.@$user['name'].'";
	var intials = firstName.charAt(0);
	var profileImage = $(".charprofile").text(intials);

	// Get the first header element
	function set_leftmenu_top() {
		// Get the first header element
		const header_height = document.querySelector(".top-header").offsetHeight;

		// Set the top based on header height
		document.getElementById("left_collapsable_menu").style.top = header_height + "px";
	}

	// Calculate top when the page loads
	set_leftmenu_top();

	// Recalculate top when the window is resized
	window.addEventListener("resize", set_leftmenu_top);
	
});


// A function to show detailed errors
function deterr(){
	$(".deterr-toggle").toggle();
	$("#deterr-container").toggle("slow");
}

$( document ).ready(function() {
	if($(".wiki_help").length > 0){
		$(".wiki_help").tipTip({delay:100, defaultPosition:"left"});
	}
});


var note_template = \'<div data- data-type="" class="note"><div class="note_title"></div><pre class="note_content"></pre><div class="note_bottom"><div class="note_actions d-flex"><div class="note_notify"><div class="custom-control custom-checkbox"><input type="checkbox" class="custom-control-input" id="note_notify" checked><label class="custom-control-label" for="note_notify"> '.__J('Notify admins via email').'</label></div></div><a class="note_save" href="#" title="'.__J('Save').'" onclick="save_note(this); return false;"><i class="icon icon-save"></i></a><a class="note_cancel" href="#" title="'.__J('Cancel').'" onclick="cancel_edit_note(this); return false;"><i class="icon icon-undo"></i></a><a class="note_edit" href="#" title="'.__J('Edit').'" onclick="edit_note(this); return false;"><i class="icon icon-edit"></i></a><a class="note_done" href="#" title="'.__J('Done').'" onclick="perform_action(this, \\\'done\\\'); return false;"><i class="icon icon-done"></i></a><a class="note_delete" href="#" title="'.__J('Delete').'" onclick="perform_action(this, \\\'delete\\\'); return false;"><i class="icon icon-delete"></i></a></div><div class="note_info"></div></div></div>\';

var note_form_template = \'<div class="note_form"><input class="note_title form-control" type="text" maxlength="128" placeholder="'.__J('Title').'..." /><textarea class="note_content form-control" placeholder="'.__J('Content').'..." rows="1" onkeyup="adjust_textarea_height(this)"></textarea></div>\';

function add_note() {
	var type = $(".admin_notes ul.nav-tabs li.nav-item a.active").data("type");
	var el = type == 0 ? "#notes_private" : "#notes_public";
	
	// Create a copy of note template
	var $temp = $(note_template).clone();
	
	// Insert data into template
	$temp.data("type", type).addClass("note_editing note_unsaved");
	$temp.find(".note_info").html("'.__J('Unsaved').'");
	$temp.find(".note_edit, .note_done, .note_delete").hide();
	$temp.find("div.note_title").before(note_form_template);
	$temp.find("div.note_title, pre.note_content").hide();
	
	if(type == 0) {
		// If private note remove notify checkbox
		$temp.find(".note_notify").remove();
	} else {
		// If public note remove edit button
		$temp.find(".note_edit").remove();
	}
	
	// Add to start of notes
	$temp.prependTo(el + " .notes_content");
	
	update_note_placeholders();
}

function edit_note(el) {
	var note = $(el).closest(".note");
	
	$(note).addClass("note_editing");
	$(note).find(".note_edit, .note_done, .note_delete").hide();
	$(note).find(".note_save, .note_cancel").show();
	
	var title = $(note).find("div.note_title").text();
	var content = $(note).find("pre.note_content").text();
	
	// Insert note form and hide title, content
	$(note).find("div.note_title").before(note_form_template);
	$(note).find("div.note_title, pre.note_content").hide();
	
	// Set note form initial values
	$(note).find("input.note_title").val(title);
	$(note).find("textarea.note_content").val(content);
	
	adjust_textarea_height($(note).find("textarea.note_content"));
}

function cancel_edit_note(el) {
	var note = $(el).closest(".note");
	
	if($(note).hasClass("note_unsaved")) {
		$(note).remove();
		update_note_placeholders();
		return;
	}
	
	$(note).removeClass("note_editing");
	$(note).find(".note_edit, .note_done, .note_delete").show();
	$(note).find(".note_save, .note_cancel").hide();
	
	$(note).find("div.note_form").remove();
	$(note).find("div.note_title, pre.note_content").show();
}

function save_note(el) {
	var note = $(el).closest(".note");
	var noteid = $(note).data("id");
	var title = $(note).find("input.note_title").val();
	var content = $(note).find("textarea.note_content").val();
	var type = $(note).data("type");
	var notify = $(note).find(".note_notify input").is(":checked");
	
	if(!title) {
		showalert("'.__J('Note title cannot be empty.').'" ,"1");
		return false;
	}
	
	if(!content) {
		showalert("'.__J('Note content cannot be empty.').'" ,"1");
		return false;
	}
	
	var notedata = "edit="+noteid;
	var type_txt = type == 0 ? "private" : "public";
	
	// If noteid not present then add note
	if(!noteid) {
		notedata = "add=1&type="+type;
	}

	notedata += "&title="+encodeURIComponent(title)+"&content="+encodeURIComponent(content);
	
	if(notify) {
		notedata += "&notify=1";
	}
	
	// Stop refreshing temporarily
	clearInterval(interval);
	
	$.ajax({
		url: "'.$globals['index'].'&act=adminnotes&"+type_txt+"=1&page="+notes_currpage[type]+"&api=json",
		data: notedata,
		dataType : "json",
		method : "post",
		success:function(data){
			if("error" in data) {
				showalert(data["error"] ,"1");
				return;
			}
			
			update_count(type, data["count_"+type_txt]);
			
			if(!noteid) {
				noteid = data["done"];
			}
			
			var notes = data["notes_"+type_txt];
			
			var found = false;
			for(var i=0; i<notes.length; i++) {
				if(notes[i]["noteid"] == noteid) {
					// Update the note
					$(note).data("id", noteid);
					$(note).removeClass("note_editing note_unsaved");
					$(note).find(".note_notify").remove();
					$(note).find(".note_edit, .note_done, .note_delete").show();
					$(note).find(".note_save, .note_cancel").hide();
					
					$(note).find("div.note_form").remove();
					$(note).find("div.note_title").html(notes[i]["title"]).show();
					$(note).find("pre.note_content").html(notes[i]["content"]).show();
					
					if(type == 0) {
						$(note).find(".note_info").html(notes[i]["time"]).show();
					} else {
						$(note).find(".note_info").html(notes[i]["user"] + " (" + notes[i]["time"] + ")").show();
					}
					
					found = true;
					break;
				}
			}
			
			if(!found) {
				// Note does not exist on current page anymore.
				$(note).remove();
			}
		},
		complete: function() {
			// Start refreshing again
			interval = setInterval(function() {
				refresh_notes(1);
			}, 10000);
		}
	});
}

function perform_action(el, action){
	
	if(action == "delete"){
		showalert("'.__J('Are you sure you want to delete this note ?').'" ,"3" ,function(confirm){
			if(confirm == false){
				return false;
			}else{
				var note = $(el).closest(".note");
				var noteid = $(note).data("id");
				var type = $(note).data("type");
				var type_txt = type == 0 ? "private" : "public";
				
				clearInterval(interval);
				
				$.ajax({
					url: "'.$globals['index'].'&act=adminnotes&api=json&"+type_txt+"=1",
					data: action+"="+noteid,
					dataType : "json",
					method : "post",
					success:function(data){
						if("error" in data) {
							showalert(data["error"] ,"1");
							return;
						}
						
						$(note).remove();
						
						
						update_count(type, data["count_"+type_txt]);
						
						update_note_placeholders();
					},
					complete: function() {
						//Refresh public notes every 10 secs
						interval = setInterval(function() {
							refresh_notes(1);
						}, 10000);
					}
				 });
			}
		});
	}else{
		var note = $(el).closest(".note");
		var noteid = $(note).data("id");
		var type = $(note).data("type");
		var type_txt = type == 0 ? "private" : "public";
		
		clearInterval(interval);
		
		$.ajax({
			url: "'.$globals['index'].'&act=adminnotes&api=json&"+type_txt+"=1",
			data: action+"="+noteid,
			dataType : "json",
			method : "post",
			success:function(data){
				if("error" in data) {
					showalert(data["error"] ,"1");
					return;
				}
				
				$(note).remove();
				
				
				update_count(type, data["count_"+type_txt]);
				
				update_note_placeholders();
			},
			complete: function() {
				//Refresh public notes every 10 secs
				interval = setInterval(function() {
					refresh_notes(1);
				}, 10000);
			}
		 });
	}
	
	
};

function refresh_notes(type) {
	var query = "";
	
	if(type == 0) {
		query = "&private=1";
	} else if(type == 1) {
		query = "&public=1";
	}
	
	query += "&page="+notes_currpage[type];
	
	if(notes_search) {
		query += "&search="+encodeURIComponent(notes_search);
	}
	
	$.ajax({
		url: "'.$globals['index'].'&act=adminnotes&api=json"+query,
		dataType : "json",
		method : "get",
		timeout: 10000,
		success: function(data){
			if("notes_private" in data) {
				var notes = data["notes_private"];
				
				$("#notes_private .note:not(.note_editing)").remove();
				
				for(var i=0; i<notes.length; i++) {
					var $temp = $(note_template).clone();
					
					$temp.data("id", notes[i]["noteid"]).data("type", 0);
					$temp.find(".note_title").html(notes[i]["title"]);
					$temp.find(".note_content").html(notes[i]["content"]);
					$temp.find(".note_info").html(notes[i]["time"]);
					$temp.find(".note_save, .note_cancel").hide();
					$temp.find(".note_notify").remove();
					
					$temp.appendTo("#notes_private .notes_content");
				}
				
				update_count(0, data["count_private"]);
			}
			
			if("notes_public" in data) {
				var notes = data["notes_public"];
				
				$("#notes_public .note:not(.note_editing)").remove();
				
				for(var i=0; i<notes.length; i++) {
					var $temp = $(note_template).clone();
					
					$temp.data("id", notes[i]["noteid"]).data("type", 1);
					$temp.find(".note_title").html(notes[i]["title"]);
					$temp.find(".note_content").html(notes[i]["content"]);
					$temp.find(".note_info").html(notes[i]["user"] + " (" + notes[i]["time"] + ")");
					$temp.find(".note_notify, .note_save, .note_cancel, .note_edit").remove();
					
					if(notes[i]["uid"] != '.$user['uid'].') {
						$temp.find(".note_done, .note_delete").remove();
					}
					
					$temp.appendTo("#notes_public .notes_content");
				}
				
				update_count(1, data["count_public"]);
			}
			
			update_note_placeholders();
		}
	});
}

function refresh_search() {
	notes_search = $("#notes_search_input").val();
	notes_currpage = [1, 1];
	refresh_notes();
}

// Updates the notes count and pagination links
function update_count(type, count) {
	
	notes_count[type] = count;
	var pages = Math.ceil(count / 20);
	pages = pages == 0 ? 1 : pages;
	
	// If current page does not exist anymore
	if(notes_currpage[type] > pages) {
		notes_currpage[type] = pages;
	}
	
	var type_txt = type == 0 ? "private" : "public";
	
	// Update the count
	$("#count_"+type_txt).text(count);
	
	// Calculate pages
	var pg_start = (notes_currpage[type] - 2) < 1 ? 1 : (notes_currpage[type] - 2);
	var pg_end = (pg_start + 4) > pages ? pages : (pg_start + 4);
	
	var $ul = $("#notes_"+type_txt).find("ul");
	
	// Remove all page links
	$ul.find("li").remove();
	
	// Add prev link
	$ul.append("<li class=\"page-item " + (notes_currpage[type] == 1 ? "disabled" : "") + "\"><a href=\"javascript:void(0)\" class=\"page-link\" onclick=\"navigate_page(" + type + ", \'prev\'); return false;\"><span aria-hidden=\"true\">&laquo;</span></a></li>");
	
	// Add page links
	for(var i=pg_start; i<=pg_end; i++) {
		$ul.append("<li class=\"page-item " + (i == notes_currpage[type] ? "active" : "") + "\"><a href=\"javascript:void(0)\" class=\"page-link\" onclick=\"navigate_page(" + type + ", " + i + "); return false;\"><span aria-hidden=\"true\">" + i + "</span></a></li>");
	}
	
	// Add next link
	$ul.append("<li class=\"page-item " + (notes_currpage[type] == pages ? "disabled" : "") + "\"><a href=\"javascript:void(0)\" class=\"page-link\" onclick=\"navigate_page(" + type + ", \'next\'); return false;\"><span aria-hidden=\"true\">&raquo;</span></a></li>");
}

function del_terminal_sess(){

	var serid = $("#servers_terminal").val();

	var l = Array();
	l["del_tty_ses_conf"] = "'.__J('Are you sure you want to delete Terminal session(s)? If you are connected to terminal from other machine, it will be disconnected.').'";

	showalert(l["del_tty_ses_conf"] ,"3" ,function(confirm){
		if(confirm == false){
			return false;
		}else{
			var finalData = new Object();
			//alert(JSON.stringify(finalData));
			//return false;
			
			$("#progress_bar").show();
			
			$.ajax({
				type: "POST",
				url: "'.$globals['index'].'act=terminal&del_sess="+serid+"&api=json",
				dataType : "json",
				success: function(data){
					$("#progress_bar").hide();
					if("done" in data){
						setTimeout(function(){showalert("'.__J('The action was completed sucessfully').'");
						$("#alert-modal").on("hidden.bs.modal", function (e) {
							location.reload(true);
						})} ,200);
					}
				},
				error: function(data) {
					$("#progress_bar").hide();
					//alert(data.description);
					return false;
				}
			});
		}
	});

	return false;
};

function open_terminal(){
		
	let server_id = $("#servers_terminal").val();

	$.ajax({
		url: "'.$globals['index'].'&act=terminal&serid="+server_id+"&api=json",
		dataType : "json",
		method : "post",
		success:function(data){
			if("error" in data) {
				showalert(data["error"]["many_ttyd_sess"],"1");
				return;
			}else{
				window.open(data["url"] , "_blank");
			}
		}
	});
	
};

function update_note_placeholders() {
	
	// private notes
	if(notes_count[0] == 0 && $("#notes_private .note").length == 0) {
		$("#notes_private .note_placeholder").text("'.__J('No Notes').'").show();
	} else {
		$("#notes_private .note_placeholder").hide();
	}
	
	// public notes
	if(notes_count[1] == 0 && $("#notes_public .note").length == 0) {
		$("#notes_public .note_placeholder").text("'.__J('No Notes').'").show();
	} else {
		$("#notes_public .note_placeholder").hide();
	}
}

function navigate_page(type, page) {
	var type_txt = type == 0 ? "private" : "public";
	var pages = Math.ceil(notes_count[type] / 20);
	
	if(page == "prev" && notes_currpage[type] > 1) {
		notes_currpage[type]--;
	} else if(page == "next" && notes_currpage[type] < pages) {
		notes_currpage[type]++;
	} else if(page >= 1 && page <= pages) {
		notes_currpage[type] = page;
	} else {
		// Invalid page return
		return;
	}
	
	// Remove notes & show loading
	$("#notes_"+type_txt).find(".note:not(.note_unsaved)").remove();
	$("#notes_"+type_txt).find(".note_placeholder").text("'.__J('Loading').'").show();
	
	// Refresh the page.
	clearInterval(interval);
	
	refresh_notes(type);
	
	// Refresh public notes every 10 secs
	interval = setInterval(function() {
		refresh_notes(1);
	}, 10000);
}

function adjust_textarea_height(el) {
	$(el).each(function() {
		$(this).height("1px");
		$(this).height($(this).prop("scrollHeight")+"px");
	});
}

function close_notes() {
	$("#notes_link").popover("hide");
}

// decalred variables for focus and blur ajax calls and their functions
let active_request = true;
let task_count_interval;

$(document).ready(function() {
	$(".sticky").addClass("scrollbar-virt");
	$(".scrollbar-virt").scrollbar();
	
	var $el = $("#navbar");
	var bottom = $el.outerHeight(true);
	//$("table.tablesorter th").css("top",(bottom-1));
	
	$("#tasks").on("hidden.bs.modal", function (e) {
		// put your default event here
		clearInterval(task_interval);
		$("#showData").empty();
	});
	
	window.onfocus = function () {
		active_request= true;
		
		//clearing all past intervals incase its set
		if (task_count_interval) {
        		clearInterval(task_count_interval);
    		}

		task_count_interval = setInterval(gettaskscount, 5000);
	};
	

	window.onblur = function () {

		active_request = false;

		//clearing all past intervals incase its set
		if (task_count_interval) {
			clearInterval(task_count_interval);
			task_count_interval = null; // Reset the interval reference
		}

		task_count_interval = setInterval(gettaskscount, 5000);
	};
	
	
	$("#notesmodal").on("hidden.bs.modal", function (e) {
    		// put your default event here
		clearInterval(notes_interval);
	});

	$("#select2-server-select-container").parent().focus(function(){
		$(".select2-dropdown").css("z-index","1060");
	});

	$("form").on("focus", "input[type=number]", function (e) {
		$(this).on("wheel.disableScroll", function (e) {
			e.preventDefault()
		})
	})
	$("form").on("blur", "input[type=number]", function (e) {
		$(this).off("wheel.disableScroll")
	})

});

$(window).load(function() {
	gettaskscount();
});

function gettasks(){
	var divContainer = $("#showData");
	divContainer.html("<div class=\"splash-screen\"><div class=\"loader-lg\"></div></div>");

	refresh_top10_tasks(divContainer);
	
	task_interval = setInterval(function(){
		refresh_top10_tasks(divContainer);
	} ,3000);
	
	$("#tasks").modal();
}

function refresh_top10_tasks(divContainer){
	$.ajax({
		url: "'.$globals['index'].'&act=tasks&api=json&show=1&show_top_ten=1",
		dataType : "json",
		method : "post",
		success:function(data){
			if("error" in data){
				showalert(data["error"] ,"1");
				return;
			}
			var task_data = data["tasks"];
			//"actid", "vpsid", "status_txt", "progress", "started", "updated", "ended", "email", "server_name", "action_txt"
			
			divContainer.html("");
			if(empty(task_data)){
				$("#view_all_tasks").hide();
				divContainer.append("<div class=\"splash-screen\"><h5>'.__J('No running tasks!').'</h5></div>");
				return;
			}

			//Now arrange the array in desc order.

			var k = -1;
			for (var i in task_data) {
				k = k+1;
				task_data[k] = task_data[i];
				delete task_data[i];
			}
			
			var col = [];
			var th_col_name = ["Actid","VPS ID","User","Server(ID)","Started","Updated","Ended","Action","Status","Progress"];
			
			col = [ "actid", "vpsid", "email", "server_name", "started", "updated", "ended", "action_txt", "status_txt", "progress" ];
			
			var table = document.createElement("table");
			table.className ="table get_task tablesorter tablehover";
			// CREATE HTML TABLE HEADER ROW USING THE EXTRACTED HEADERS ABOVE.
			var tr = table.insertRow(-1);                   // TABLE ROW.
			for (var i = 0; i < th_col_name.length; i++) {
				var th = document.createElement("th");      // TABLE HEADER.
				th.innerHTML = th_col_name[i];
				if(th_col_name[i] == "VPS ID"){
					th.setAttribute(\'width\', \'60\');
				}
				tr.appendChild(th);
			}
			var flg_count = 0;
			// ADD JSON DATA TO THE TABLE AS ROWS.
			for (var i = Object.keys(task_data).length-1; i >= 0; i--) {
				if(empty(task_data[i]["not_updated"])){
					tr = table.insertRow(-1);
					for (var j in col) {
						var tabCell = tr.insertCell(-1);
						tabCell.innerHTML = task_data[i][col[j]];
						if(col[j] == "progress"){
							tabCell.setAttribute("tooltip",task_data[i][col[j]]);
							tabCell.setAttribute("class", "wrap");
						}
						if(col[j] == "status_txt"){
							var col_data = "";
							if(task_data[i]["action"] == "migrate2" || task_data[i]["action"] == "clone2" || task_data[i]["action"] == "multimigrateprog" || task_data[i]["action"] == "multicloneprog" || task_data[i]["action"] == "migrate_disk2"){
								
								var status_data = JSON.parse(task_data[i]["status_txt"]);
								col_data = "<div>";
								$.each(status_data, function(k, item){
									if(k != "progress"){
										col_data += "<b>"+k+"&nbsp;:&nbsp;&nbsp;</b>"+item+"<br>";
									}
								});
								col_data += "</div>";
								tabCell.innerHTML = col_data;
							}else{
								col_data = task_data[i][col[j]];
							}

							tabCell.setAttribute("class", "wrap");
							tabCell.setAttribute("tooltip", col_data);
						}
						if(col[j] == "server_name"){
							tabCell.append("("+task_data[i]["serid"]+")");
						}
						if(col[j] == "progress"){
							if(!isNaN(task_data[i]["progress"]))
							{
								tabCell.setAttribute("class", "");
								tabCell.innerHTML = "<div class=\"progress-cont\" id=\"progress-cont"+task_data[i]["actid"]+"\"><center><div class=\"text-center h6\" id=\"pbar"+task_data[i]["actid"]+"\">"+task_data[i]["progress"]+"%</center><div class=\"progress\"><div class=\"progress-bar bg-primary progress-bar-striped progress-bar-animated\" style=\"width:"+task_data[i]["progress"]+"px;\"></div></div></div>";
							}else{
								tabCell.innerHTML = task_data[i]["progress"];
							}
						}
					}
					flg_count++;
				}
			}
			
			if(empty(flg_count) || !task_data){
				$("#view_all_tasks").hide();
				divContainer.append("<div class=\"splash-screen\"><h5>'.__J('No running tasks!').'</h5></div>");
			}else{
				divContainer.append(table);
				$("#view_all_tasks").show();
			}
			
			show_tooltip();
			$(".popover").on("mouseleave", function () {
				$(this).popover(\'hide\');
			});
		},
		complete: function() {
			// Start refreshing again
			
		}
	});
}

function gettaskscount(){
	
	// return if the current tab is not an Active tab.
	// We do not want to make multiple Ajax calls if user has opened multiple Tabs
	if(!active_request) return;

	var count = 0;
	$.ajax({
		url: "'.$globals['index'].'&act=tasks&api=json&show=1&show_top_ten=1&show_task_count=1",
		dataType : "json",
		method : "post",
		success:function(data){
			if("error" in data) {
				showalert(data["error"] ,"1");
				return;
			}
			var task_data = data["tasks"];

			if(empty(task_data)){
				$(".task_count").html(0);
				return;
			}
			$(".task_count").html(task_data["count"]);
		}
	});	
}

function loadnotes(){
	refresh_notes();
		
	// Refresh public notes every 10 secs
	notes_interval = setInterval(function() {
		refresh_notes(1);
	}, 10000);
	$("#notesmodal").modal();
}';

if(empty($globals['disable_notifications'])){
	echo'
	let notify_interval;
	let notification_count_task;

	$(document).ready(function(){
		show_tooltip();

		get_notification();

		// Store the modal in a variable to avoid repetitive selection
		let $vmodal = $("#vmodal");

		$(document).on("click", "#notification, #notification2, .header_noti_item", function() {
			$vmodal.vmodal();

			let temp_div_data = `<div class="vmodal-loader"><div class="loader-lg"></div></div>`;

			// Set up show and hide event listeners for the modal once
			$vmodal.off("on.show.vmodal on.hidden.vmodal")  // Ensure no duplicate handlers
				.on("on.show.vmodal", function() {
				})
				.on("on.hidden.vmodal", function() {
					clearInterval(notify_interval);  // Clear interval when modal is hidden
				});

			// Display loading animation
			$vmodal.find(".vmodal-body").html(temp_div_data);

			// Load notifications and set interval
			get_notification();
			notify_interval = setInterval(get_notification, 5000);
		});


		$("#vmodal .vmodal-close, #vmodal_back").click(function(){
			$("#vmodal").vmodal();
		});
		
		//clearing all past intervals incase its set
		if (notification_count_task) {
			clearInterval(task_count_interval);
			notification_count_task = null; // Reset the interval reference
		}

		get_notification_count();

		notification_count_task = setInterval(function(){ get_notification_count(); }, 7000);

	});

	$("#vmodal .vmodal-body").empty().html(\'<div class="vmodal-loader">'.__J('No Notifications Yet!').'</div>\');
	let nid = new Array();
	let tmp_nid = new Object();

	let nids = "";

	function read_notification(ele){

		let parent_item = $(ele).closest(".noti-item, .header_noti_item");

		// Add the hide class to the element
		parent_item.addClass("hide");

		// Remove the element after a short delay
		setTimeout(function() {
			parent_item.remove();
		}, 200);

		// Initialize data object and assign nid value if it exists
		let data = {
			"nid": parent_item.data("nid")
		};

		$.ajax({
			type: "POST",
			url: "'.$globals['index'].'act=adminindex&read_notification=1&api=json",
			dataType : "json",
			data : data,
			success:function(response){
				nids = "";
				read_noti = false;
				get_notification_count();
			}		
		});
		
	};


	function handle_moreinfo_click(ele){
		nid = $(ele).parent().parent().parent(".noti-item").data("nid");
		$("#nid_"+nid).on("shown.bs.collapse", function(){
			nid_clicked[nid] = true;
		});
		
		$("#nid_"+nid).on("hidden.bs.collapse", function(){
			nid_clicked[nid] = false;
		});
	};

	function clear_all_notifications(){

		$("#clear_notifications_loader").show();
		$.ajax({
			type: "POST",
			url: "'.$globals['index'].'act=adminindex&clear_all_notification=1&api=json",
			dataType : "json",
			success:function(response){
				if(!empty(response["notification_cleared"])){
					$("#vmodal .vmodal-body").empty().html(\'<div class="vmodal-loader">'.__J('No Notifications Yet!').'</div>\');
					$("#clear_notifications_loader").hide();
				}
			}		
		});

		read_notification();
		
	};

	let nid_clicked = new Array();
	function get_notification(){
		$.ajax({
			type: "POST",
			url: "'.$globals['index'].'act=adminindex&notification=1&api=json",
			dataType : "json",
			success:function(response){
				if(!empty(response["notifications"])){
					var html = "<a href=\"javascript:clear_all_notifications()\"><div class=\"btn bg-danger w-100 mb-2 d-flex align-items-center justify-content-center border border-danger\"><div class=\"loader\" id=\"clear_notifications_loader\" style=\"display:none;\"></div>&nbsp;<i class=\"fas fa-trash-alt\"></i>&nbsp;'.__J('Clear All').'</div></a>";
					var notification_html = "";

					let note_count = 0 ;
					
					$.each(response["notifications"], function(k, v){
						// console.table(v);
						if(empty(v["body"])){
							v["body"] = "";
						}
						if(empty(v["title"])){
							v["title"] = "";
						}
						if(empty(v["data"])){
							v["data"] = "";
						}
						let id = k.replace("n", "");
						let opened = false;
						if(!empty(nid_clicked[id])){
							opened = true;
						}
						if(v["class"] == "danger"){
							notification_body = "notification_body_danger";
							noti_icon = \'<i class="fas fa-times"></i>\';
						}else if(v["class"] == "warning"){
							notification_body = "notification_body_warning";
							noti_icon = \'<i class="fas fa-exclamation"></i>\';
						}else{
							v["class"] = "success";
							notification_body = "notification_body_success";
							noti_icon = \'<i class="fas fa-check"></i>\';
						}

						if(note_count < 5){

							// limiting nottification title as well as body string length
							let notification_title = v["title"];
							notification_title =  notification_title.replace(/<\/?[^>]+(>|$)/g, "");
							notification_title =  notification_title.split(/<a|<|>|\(|\)/)[0];
							notification_title = (notification_title.length > 30 ? notification_title.substring(0, 30) + "....." : notification_title);

							let notification_body_content = v["body"];
							notification_body_content = (notification_body_content.length > 40 ? notification_body_content.substring(0, 40) + "....." : notification_body_content);

							// injectiong html data upto 5 notifications
							notification_html += `
								<div class="dropdown-item header_noti_item">
									<div class="`+v["class"]+`_notification_icon">
										<div class="notification_icon">
											<span>`+noti_icon+`</span>
										</div>
									</div>
									<div class="`+notification_body+` ml-1 mr-2 mb-1">
										<div class="d-flex justify-content-between">
											<span class="noti_server_name text-secondary">`+v["server"]+`</span>
											<div>
												<span class="noti_time text-primary mr-2">`+v["note_time"]+`'.__J(' ago').'</span>
											</div>
										</div>
										<div class="notification_body_item">
											<div class="noti_item_title">
												`+notification_title+`
											</div>
											<div class="noti_item_body">
												` + notification_body_content + `
												` + (v["data"] ? `<span onclick="handle_moreinfo_click(this);" data-toggle="collapse" data-target="#nid_` + id + `" aria-expanded="` + opened + `" aria-controls="nid_` + id + `" class="btn smol_virt px-1 py-0">More Info</span>` : " ") + `
											</div>
											<div class="collapse my-2 border rounded p-2 ` + (opened ? "show" : "") + `" id="nid_` + id + `">
												` + (v["data"] || " ") + `
											</div>
										</div>
									</div>
								</div>
							`;
							
							note_count++;
						};
					
						html += \'<div class="noti-item \'+v["class"]+\'" data-nid="\'+id+\'">\
									<div class="row">\
										<div class="col-sm-1">&nbsp</div>\
										<div class="col-sm-9">\
											<span class="noti-item-subtitle text-secondary">\'+v["server"]+\'</span>\
										</div>\
										<div class="col-sm-2">\
											<i class="fas fa-times fa-2x noti-item-close text-dark" onclick="read_notification(this);"></i>\
										</div>\
									</div>\
									<div class="row">\
										<div class="col-1">\
											<span>\'+noti_icon+\'</span>\
										</div>\
										<div class="col-11">\
											<div class="noti-item-title \'+v["class"]+\'">\
											\'+v["title"]+\'\
											</div>\
											<div class="noti-item-body text-dark">\
												\'+v["body"]+\' \'+(!empty(v["data"]) ? \'<span onclick="handle_moreinfo_click(this);" data-toggle="collapse" data-target="#nid_\'+id+\'" aria-expanded="\'+opened+\'" aria-controls="nid_\'+id+\'" class="btn smol_virt px-1 py-0">More Info</span>\' : \'\')+\'\
											</div>\
											<div class="text-dark collapse my-2 border rounded p-2 \'+(opened == true ? "show" : "")+\'" id="nid_\'+id+\'">\
												\'+v["data"]+\'\
											</div>\
											<br>\
											<div class="noti-item-time text-dark">\'+v["time"]+\'</div>\
										</div>\
									</div>\
								</div>\';
					});
					$("#vmodal .vmodal-body").html(html);
					
					$("#notification_div").html(notification_html);

				}else{
					$("#vmodal .vmodal-body").empty().html(\'<div class="vmodal-loader">'.__J('No Notifications Yet!').'</div>\');
					$("#notification_div").empty().html(\'<div class="vmodal-loader my-3">'.__J('No Notifications Yet!').'</div>\');
				}
				
			}		
		});
	}

	var previous_notification_count = null; // Initial previous count

	function get_notification_count(){
		
		// return if the current tab is not an Active tab.
		// We do not want to make multiple Ajax calls if user has opened multiple Tabs
		if(!active_request) return;
		
		$.ajax({
			type: "POST",
			url: "'.$globals['index'].'act=adminindex&notification_count=1&api=json",
			dataType : "json",

			success: function(response) {

				if (!empty(response["ncount"])) {
					
					if (response["ncount"] !== previous_notification_count) {
						
						// Updating the notification counts
						$("#nav-notification .notification-count").html(response["ncount"]);
						$(".dropdown-item .notification-count").html(response["ncount"]);

						// Add the zoom animation class to both elements
						$("#nav-notification .notification-count").addClass("zoom-animation");

						// Remove the animation class after the animation completes (0.3s)
						setTimeout(function() {
							$("#nav-notification .notification-count").removeClass("zoom-animation");
						}, 300);

						// Update the previous count with the new count
						previous_notification_count = response["ncount"];
					}
				}
			}
		
		});
	}

	function vmodal_handle(){
		if($("#vmodal").hasClass("show")){
			clearInterval(notify_interval);
			$(".vmodal_back").fadeOut(500);
			$("#vmodal").removeClass("show");
			return false;
		}else{
			$(".vmodal_back").fadeIn(500);
			$("#vmodal").addClass("show");
			return true;
		}
	};
	
	';
}
echo'
// ]]></script>

	</head>
	<body onload="bodyonload();"><script>on_load_theme();</script>
';

if(empty($globals['disable_notifications'])){
	echo '
		<div id="vmodal" class="vmodal shadow-lg">
			<div class="vmodal-heading">
				<div class="vmodal-title">'.__('Notification(s)').'</div>
				<span class="vmodal-close"><i class="fas fa-times fa-2x"></i></span>
			</div>
			<div class="vmodal-body">
				<div class="vmodal-loader"><div class="loader-lg"></div></div>
			</div>
		</div>';
}
$current_virt = $globals['version'].'.'.$globals['patch'];
echo'
<!-- Version modal start  -->
<div class="modal fade p-0" id="version-modal" tabindex="-1" role="dialog" data-backdrop="static" aria-hidden="true">
	<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h2 class="m-0 py-2">'.__('Change Log for version ').' : ('.$current_virt.')</h2>
			</div>
			<div class="modal-body pt-0">';
				$version_changes = get_changelog();
				if(!empty($version_changes)){
					$icon_map = [
								'feature' => '<i class="fas fa-star mr-2"></i>', 
								'features' => '<i class="fas fa-star mr-2"></i>', 
								'bugfix' => '<i class="fas fa-bug mr-2"></i>',
								'bugfixes' => '<i class="fas fa-bug mr-2"></i>',
								'task' => '<i class="fas fa-tasks mr-2"></i>',
								'tasks' => '<i class="fas fa-tasks mr-2"></i>'
							];
					foreach($version_changes as $key => $value){
						echo '<div class="card p-2 my-2">
								<h5 class="text-capitalize text-admin">'.$icon_map[$key].$key.'</h5><ol>
						';
						foreach($value as $kk => $vv){
							echo '<h6 class="p-2"><li>'.$vv.'</li></h6>';
						}
						echo '</ol></div>';
					}
					echo '<script>$("#version-modal").modal();</script>';
				}
			
			echo '
			</div>
			<div class="modal-footer pt-1 pb-1 d-flex align-items-center justify-content-center">
				<div class="row mx-auto w-100">
					<div class="offset-9 col-3 px-2">
						<button id="dismiss_version" type="button" data-dismiss="modal" class="btn green_btn w-100">Skip</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!--Version modal end -->
<!--Alert Modal Start -->
<div class="modal fade" id="alert-modal" tabindex="-1" role="dialog" data-backdrop="static" aria-hidden="true">
	<div class="modal-dialog modal-dialog-centered" role="document">
		<div class="modal-content">
			<div class="modal-header d-flex align-items-center mb-3">
				<div class="icon-box modal-title">
					<i class="fa text-success" aria-hidden="true"></i>
				</div>
				<h4 class="modal-title"><span id="success">'.__('Success').'</span><span id="error">'.__('Error').'</span><span id="warning">'.__('Warning').'</span><span id="confirmt">'.__('Confirm').'</span></h4>
				<button type="button" class="close btn-close text-dark" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body ">
							
			</div>
			<div class="modal-footer pt-1 pb-1 d-flex align-items-center">
				<div class="row mx-auto w-100 confirm">
					<div class="col-6 px-2">
						<a href=\'javascript:void(0)\' id="confirm" class="btn w-100">'.__('OK').'</a>
					</div>
					<div class="col-6 px-2">
						<a href=\'javascript:void(0)\' id="cancel" class="btn red_btn w-100">'.__('Cancel').'</a>
					</div>
				</div>
				<div class="row mx-auto w-100 ok">
					<div class="col-12 px-2">
						<button type="button" data-dismiss="modal" class="btn w-100">'.__('OK').'</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!--Alert Modal End -->

<!-- The tasks Modal -->
<div class="modal fade" id="tasks">
	<div class="modal-dialog modal-xl">
		<div class="modal-content">
			<div class="modal-header">
				<h5>'.__('Tasks').'</h5>
				<button type="button" class="close text-always-white" data-dismiss="modal">&times;</button>
			</div>
			<div class="modal-body pr-1 pl-1 pt-0 pb-2">
				<div id="showData" class="mx-2 mt-2"></div>
				<center><a href="'.$globals['ind'].'act=tasks" class="link_btn" id="view_all_tasks" style="display:none;">View all</a></center><br>
			</div>
		</div>
	</div>
</div>
<!-- The tasks Modal ends -->

<!--notes modal start-->
<div class="modal fade" id="notesmodal">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<h5>'.__('Notes').'</h5>
				<button type="button" class="close text-always-white" data-dismiss="modal">&times;</button>
			</div>
			<div class="modal-body admin_notes">
				<div class="row mx-auto w-100">
					<div class="col-12 pt-4">
						<form class="form-inline notes_search" onsubmit="refresh_search(); return false;">
							<div class="input-group w-100">
								<input id="notes_search_input" type="text" class="form-control rounded" placeholder="'.__('Search').'..."><span class="input-group-btn">&nbsp;&nbsp;&nbsp;<button class="btn btn-default" type="submit">'.__('Go').'</button></span>&nbsp;&nbsp;&nbsp;
								<a href="javascript:void(0)" onclick="add_note(); return false;" id="add_note" title="'.__('Add Note').'" class="btn" style="padding-top: .7rem !important;"><i class="icon icon-add"></i></a>
							</div>
						</form>
					</div>
				</div>
				<ul class="nav nav-tabs">
					<li role="presentation" class="nav-item" ><a href="#notes_private" role="tab" data-toggle="tab" class="nav-link active" data-type="0" >'.__('Private').'&nbsp;<span id="count_private" class="badge">0</span></a></li>
					<li role="presentation" class="nav-item" ><a class="nav-link"  href="#notes_public" role="tab" data-toggle="tab" data-type="1" >'.__('Public').'&nbsp;<span id="count_public" class="badge">0</span></a></li>
				</ul>
				<div class="tab-content scrollbar-virt">
					<div role="tabpanel" class="tab-pane active" id="notes_private">
						<nav aria-label="..." class="text-center">
							<ul class="pagination d-inline-flex">
								<li class="disabled page-item"><a href="javascript:void(0)" class="page-link"><span aria-hidden="true">&laquo;</span></a></li>
								<li class="active page-item"><a href="javascript:void(0)" class="page-link">1</a></li>
								<li class="disabled page-item"><a href="javascript:void(0)" class="page-link"><span aria-hidden="true">&raquo;</span></a></li>
							</ul>
						</nav>
						<div class="notes_content"></div>
						<div class="note_placeholder">'.__('Loading').'...</div>
					</div>
					<div role="tabpanel" class="tab-pane fade" id="notes_public">
						<nav aria-label="..." class="text-center">
							<ul class="pagination d-inline-flex">
								<li class="disabled page-item"><a href="javascript:void(0)" class="page-link"><span aria-hidden="true">&laquo;</span></a></li>
								<li class="active page-item"><a href="javascript:void(0)" class="page-link">1</a></li>
								<li class="disabled page-item"><a href="javascript:void(0)" class="page-link"><span aria-hidden="true">&raquo;</span></a></li>
							</ul>
						</nav>
						<div class="notes_content"></div>
						<div class="note_placeholder">'.__('Loading').'...</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!--notes modal ends-->';
	
	//The Menus of softwares
	if(!empty($leftbody)){

		$res = makequery("SELECT 
								(SELECT COUNT(vps.vpsid) FROM `vps` WHERE virt NOT IN ('baremetal', 'docker')) AS vpsnum,
								(SELECT COUNT(ipid) FROM `ips`) AS ipsnum,
								(SELECT COUNT(stid) FROM `storage`) AS numstorage, 
								(SELECT COUNT(plid) FROM `plans`) AS numplans, 
								(SELECT COUNT(uid) FROM `users`) AS numusers, 
								(SELECT COUNT(id) FROM `pdns`) AS numpdns, 
								(SELECT COUNT(osid) FROM `os`) AS numos, 
								(SELECT COUNT(rid) FROM `recipes`) AS numrecipes, 
								(SELECT COUNT(pid) FROM `passthrough`) AS numpassthrough,
								(SELECT COUNT(lbid) FROM `load_balancer`) AS load_balancer,
								(SELECT COUNT(vpsid) FROM `vps` WHERE virt = 'baremetal') AS numbaremetal,
								(SELECT COUNT(actid) FROM `tasks` WHERE 
												ended = 0 AND 
												updated >= ".(time() - $globals['notupdated_task'])." AND 
												started >= ".(time() - $globals['notupdated_task']).") AS numtasks");
		
		// Are there any vlues returned ?
		if(vsql_num_rows($res) > 0){		
			$row = vsql_fetch_assoc($res);
			$total['head_vs'] = $row['vpsnum'];
			$total['head_ippool'] = $row['ipsnum'];
			$total['head_servers'] = count($servers);
			$total['head_storage'] = $row['numstorage'];
			$total['head_plans'] = $row['numplans'];
			$total['head_users'] = $row['numusers'];
			$total['head_pdns'] = $row['numpdns'];
			$total['head_ostemplates'] = $row['numos'];
			$total['head_recipes'] = $row['numrecipes'];
			$total['head_passthrough'] = $row['numpassthrough'];
			$total['head_load_balancer'] = $row['load_balancer'];
			$total['head_baremetal'] = $row['numbaremetal'];
			// $total['head_tasks'] = $row['numtasks'];
		}
		echo '
<header class="top-header" id="nav_bar">
<div class="d-flex align-items-center" id="logo_search">
	<div class="logo">
		<div class="web-logo d-none d-sm-none d-md-block d-lg-block py-2">
			<a href="'.$globals['ind'].'">
				'.(empty($globals['logo_url']) ? '<svg class="normal_logo" xmlns="http://www.w3.org/2000/svg" version="1.2" viewBox="0 17 1080 233" width="1080" height="276">
				<title>Virtualizor-C-svg</title>
				<style>
					.yellow { fill: var(--virtualizor_orange) !important } 
					.primary { fill: var(--virtualizor_blue) !important } 
					.textC { fill: #FFF !important } 
				</style>
				<path id="Background" class="yellow" d="m232.5 33.3l1.3 170.6-166.1-170.6z"/>
				<path id="Layer 1" class="primary" d="m49.2 243.5l-1.2-170.7 166.1 170.7z"/>
				<path id="virtualizor " fill-rule="evenodd" class="textC" d="m269.5 74.9l24.2 73 23.5-73h16.6l-34.1 95.1h-12.3l-34.5-95.1zm97.6 0v95.1h-16.2v-95.1zm-17.6-25.2q0-4 2.4-6.7 2.4-2.7 7.2-2.7 4.7 0 7.2 2.7 2.5 2.7 2.5 6.7 0 3.9-2.5 6.6-2.5 2.6-7.2 2.6-4.8 0-7.2-2.6-2.4-2.7-2.4-6.6zm89.6 24.7v15.1q-3.7-0.6-8-0.6-16 0-21.7 13.6v67.5h-16.3v-95.1h15.8l0.3 11q8-12.8 22.7-12.8 4.7 0 7.2 1.3zm25.1-22.5h16.3v23h17.7v12.6h-17.7v58.9q0 5.8 2.3 8.7 2.4 2.8 8.1 2.8 2.8 0 7.8-1.1v13.2q-6.5 1.8-12.5 1.8-10.9 0-16.5-6.6-5.5-6.6-5.5-18.8v-58.9h-17.3v-12.6h17.3zm112.1 118.1l-0.4-9.4q-9.5 11.2-27.8 11.2-15.3 0-23.2-8.8-8-8.9-8-26.2v-61.9h16.2v61.5q0 21.6 17.6 21.6 18.6 0 24.8-13.9v-69.2h16.2v95.1zm116 0h-17.1q-1.4-2.8-2.3-10-11.3 11.8-27 11.8-14.1 0-23.2-7.9-8.9-8-8.9-20.2 0-14.9 11.2-23.1 11.4-8.2 31.8-8.2h15.9v-7.5q0-8.5-5.1-13.5-5.1-5.1-15.1-5.1-8.7 0-14.6 4.4-5.8 4.4-5.8 10.6h-16.4q0-7.1 5-13.7 5.1-6.7 13.7-10.6 8.7-3.8 19.1-3.8 16.4 0 25.8 8.2 9.3 8.2 9.6 22.6v43.8q0 13.1 3.4 20.8zm-44.1-12.4q7.7 0 14.5-3.9 6.9-4 10-10.3v-19.5h-12.8q-29.9 0-29.9 17.5 0 7.6 5.1 11.9 5.1 4.3 13.1 4.3zm83.9-122.6v135h-16.3v-135zm43.7 39.9v95.1h-16.3v-95.1zm-17.5-25.2q0-4 2.3-6.7 2.5-2.7 7.2-2.7 4.8 0 7.2 2.7 2.5 2.7 2.5 6.7 0 4-2.5 6.6-2.4 2.6-7.2 2.6-4.7 0-7.2-2.6-2.3-2.6-2.3-6.6zm111.8 36.7l-53 70.3h55.7v13.3h-75.5v-11.9l52.5-69.7h-51.7v-13.5h72zm15.3 36.3v-1.1q0-14 5.4-25.2 5.5-11.1 15.3-17.2 9.8-6 22.4-6 19.4 0 31.4 13.4 12 13.4 12 35.8v1.1q0 13.9-5.3 25-5.3 11-15.2 17.1-9.9 6.2-22.7 6.2-19.4 0-31.4-13.5-11.9-13.4-11.9-35.6zm16.3 0.8q0 15.8 7.3 25.4 7.4 9.6 19.7 9.6 12.4 0 19.7-9.7 7.3-9.7 7.3-27.2 0-15.7-7.5-25.3-7.4-9.8-19.7-9.8-12 0-19.4 9.6-7.4 9.6-7.4 27.4zm136.6-49.1v15.1q-3.7-0.6-8-0.6-16 0-21.7 13.6v67.5h-16.3v-95.1h15.8l0.3 11q8-12.7 22.7-12.7 4.7 0 7.2 1.2z"/>
				<path id="By Softaculous" fill-rule="evenodd" class="textC" d="m718.5 233h-12.4v-35.5h11.6q5.8 0 8.7 2.3 3 2.4 3 7.1 0 2.5-1.4 4.4-1.5 1.9-3.9 3 2.9 0.8 4.5 3.1 1.7 2.2 1.7 5.3 0 4.8-3.1 7.6-3.1 2.7-8.7 2.7zm0.1-16.6h-7.8v12.8h7.8q3.2 0 5.1-1.7 1.9-1.7 1.9-4.7 0-6.4-7-6.4zm-7.8-15.1v11.3h7.1q3.1 0 4.9-1.5 1.9-1.6 1.9-4.2 0-2.9-1.8-4.2-1.7-1.4-5.2-1.4zm27.8 5.3l6.6 19.8 6.2-19.8h4.8l-10.6 30.5q-2.5 6.6-7.8 6.6l-0.9-0.1-1.7-0.3v-3.7l1.2 0.1q2.3 0 3.6-0.9 1.3-0.9 2.1-3.4l1-2.7-9.4-26.1zm45.2 10.6q-6.1-1.8-8.8-4.3-2.8-2.5-2.8-6.2 0-4.2 3.4-7 3.4-2.7 8.7-2.7 3.7 0 6.5 1.4 2.9 1.4 4.5 3.9 1.6 2.5 1.6 5.4h-4.7q0-3.2-2.1-5-2-1.9-5.8-1.9-3.4 0-5.4 1.6-1.9 1.5-1.9 4.2 0 2.2 1.8 3.7 1.9 1.5 6.3 2.7 4.4 1.3 6.9 2.8 2.5 1.5 3.7 3.5 1.2 2 1.2 4.7 0 4.3-3.3 6.9-3.4 2.6-9 2.6-3.7 0-6.9-1.4-3.1-1.4-4.9-3.9-1.7-2.4-1.7-5.5h4.7q0 3.2 2.4 5.1 2.4 1.9 6.4 1.9 3.7 0 5.7-1.6 1.9-1.5 1.9-4.1 0-2.6-1.8-4-1.8-1.5-6.6-2.8zm17.2 2.7v-0.4q0-3.8 1.6-6.9 1.5-3.1 4.2-4.8 2.7-1.7 6.2-1.7 5.4 0 8.8 3.7 3.3 3.8 3.3 10v0.3q0 3.8-1.5 6.9-1.5 3.1-4.2 4.8-2.7 1.7-6.3 1.7-5.4 0-8.7-3.7-3.4-3.8-3.4-9.9zm4.6 0.2q0 4.4 2 7 2.1 2.7 5.5 2.7 3.4 0 5.5-2.7 2-2.7 2-7.6 0-4.3-2.1-7-2-2.7-5.5-2.7-3.3 0-5.4 2.7-2 2.6-2 7.6zm31.9 12.9h-4.5v-22.9h-4.2v-3.5h4.2v-2.7q0-4.3 2.3-6.6 2.2-2.3 6.4-2.3 1.5 0 3.1 0.4l-0.3 3.7q-1.1-0.3-2.4-0.3-2.2 0-3.4 1.3-1.2 1.3-1.2 3.7v2.8h5.6v3.5h-5.6zm12.2-32.8h4.5v6.4h5v3.5h-5v16.3q0 1.6 0.7 2.4 0.7 0.8 2.3 0.8 0.7 0 2.1-0.3v3.7q-1.8 0.5-3.5 0.5-3 0-4.5-1.9-1.6-1.8-1.6-5.2v-16.3h-4.8v-3.5h4.8zm35.8 32.8h-4.7q-0.4-0.8-0.7-2.8-3.1 3.3-7.5 3.3-3.9 0-6.4-2.2-2.5-2.3-2.5-5.7 0-4.1 3.1-6.3 3.2-2.3 8.9-2.3h4.4v-2.1q0-2.4-1.5-3.8-1.4-1.4-4.1-1.4-2.5 0-4.1 1.2-1.6 1.2-1.6 3h-4.6q0-2 1.4-3.8 1.4-1.9 3.8-3 2.5-1 5.3-1 4.6 0 7.2 2.3 2.6 2.2 2.7 6.2v12.2q0 3.6 0.9 5.8zm-12.2-3.5q2.1 0 4-1.1 1.9-1.1 2.8-2.8v-5.4h-3.6q-8.3 0-8.3 4.8 0 2.1 1.4 3.3 1.4 1.2 3.7 1.2zm28.9 0.3q2.5 0 4.3-1.5 1.8-1.4 2-3.6h4.2q-0.1 2.2-1.5 4.3-1.5 2-3.9 3.2-2.4 1.3-5.1 1.3-5.3 0-8.5-3.6-3.2-3.6-3.2-9.9v-0.7q0-3.9 1.4-6.9 1.4-3 4-4.7 2.7-1.6 6.3-1.6 4.5 0 7.4 2.6 2.9 2.7 3.1 6.9h-4.2q-0.2-2.5-2-4.2-1.7-1.6-4.3-1.6-3.4 0-5.3 2.5-1.9 2.4-1.9 7.1v0.9q0 4.6 1.9 7 1.9 2.5 5.3 2.5zm32 3.2l-0.1-2.6q-2.6 3.1-7.7 3.1-4.2 0-6.5-2.5-2.2-2.4-2.2-7.2v-17.2h4.5v17q0 6 4.9 6 5.2 0 6.9-3.8v-19.2h4.5v26.4zm16.1-37.5v37.5h-4.5v-37.5zm6 24.3v-0.3q0-3.9 1.5-7 1.6-3.1 4.3-4.7 2.7-1.7 6.2-1.7 5.4 0 8.7 3.7 3.4 3.7 3.4 9.9v0.4q0 3.8-1.5 6.9-1.5 3.1-4.3 4.8-2.7 1.7-6.3 1.7-5.3 0-8.7-3.8-3.3-3.7-3.3-9.9zm4.5 0.3q0 4.4 2.1 7 2 2.7 5.4 2.7 3.5 0 5.5-2.7 2-2.7 2-7.6 0-4.3-2-7-2.1-2.7-5.5-2.7-3.4 0-5.4 2.6-2.1 2.7-2.1 7.7zm41.6 12.9l-0.1-2.6q-2.6 3.1-7.7 3.1-4.2 0-6.5-2.5-2.2-2.4-2.2-7.2v-17.2h4.5v17q0 6 4.9 6 5.2 0 6.9-3.8v-19.2h4.5v26.4zm26.6-7q0-1.9-1.4-2.9-1.4-1-4.8-1.7-3.5-0.7-5.5-1.8-2-1-3-2.4-0.9-1.4-0.9-3.4 0-3.2 2.7-5.5 2.8-2.2 7-2.2 4.5 0 7.3 2.3 2.8 2.3 2.8 5.9h-4.5q0-1.8-1.6-3.2-1.6-1.3-4-1.3-2.4 0-3.8 1.1-1.4 1-1.4 2.8 0 1.6 1.3 2.4 1.3 0.9 4.7 1.6 3.3 0.8 5.4 1.8 2.1 1.1 3.1 2.6 1.1 1.4 1.1 3.6 0 3.5-2.9 5.6-2.8 2.2-7.3 2.2-3.2 0-5.6-1.2-2.5-1.1-3.9-3.1-1.3-2-1.3-4.3h4.5q0.1 2.2 1.8 3.6 1.7 1.3 4.5 1.3 2.6 0 4.1-1 1.6-1.1 1.6-2.8z"/>
				</svg>' : '<img src="'.$globals['logo_url'].'" class="normal_logo"/>').'
			</a>
		</div>
		<div class="mobile-logo d-block d-lg-none d-md-none d-sm-block ">
			<div class="ml-2">
				<a href="'.$globals['ind'].'">
				'.(empty($globals['admin_mob_logo_url']) ? '<svg xmlns="http://www.w3.org/2000/svg" version="1.2" viewBox="0 0 224 262" width="224" height="262" class="mobile_logo d-md-block d-sm-block d-lg-none">
						<title>Virtualizor-C-svg</title>
						<style>
						.virtmob1 { fill: var(--virtualizor_orange) } 
						.virtmob2 { fill: var(--virtualizor_blue) } 
						.virtmob3 { fill: var(--black) }
						</style>
						<path id="Background" class="virtmob1" d="m206.5 25.3l1.3 170.6-166.1-170.6z"/>
						<path id="Layer 1" class="virtmob2" d="m23.2 235.5l-1.2-170.7 166.1 170.7z"/>
					</svg>' : '<img src="'.$globals['admin_mob_logo_url'].'" class="mobile_logo d-md-block d-sm-block d-lg-none"/>').'
				</a>
			</div>
		</div>
	</div>	
	<div class="left-menu-button d-block d-lg-block" id="left_menu_toggle_btn">
		<a tooltip="'.__('Minimize Left Menu').'">
			<i class="fas fa-bars"></i>
		</a>
	</div>
	<div class="d-none d-md-block d-lg-block position-relative ml-2 ">
		<div id="loader"></div>
		<input autocomplete="new-password" type="text" class="adv_search" id="uni_search" placeholder="'.__('Search VPS, User, IPs').'" onKeyUp="uni_search(this.value);" onclick="uni_search(this.value);" />
		<div class="card text-dark" id="search_results"></div>
	</div>';
	if(empty($GLOBALS['is_dashboard'])){
		echo '<li class="align-items-center d-none d-lg-flex d-md-flex ml-3 server_selection">';
		if(!$all){
			echo '<select id="server-select" class="nav-server-select server-select custom-select" style="">';
			foreach($servers as $k => $v) {
				if(($v['serid'] == 0) && !empty($globals['is_master_only'])){
					$v['virt'] = 'msonly';
				}
				echo '<option value="'.$k.'" '.($k == $globals['server'] ? 'selected' : '').' data-virt="'.$v['virt'].'">'.$v['server_name'].' ('.$v['ip'].')'.($v['locked'] == 0 ? '' : ' (Locked)').'</option>';
			}
			echo '</select>';
		}
		echo'</li>';
	}
	echo'
	
</div>
<div class="d-flex align-items-center d-lg-flex d-md-flex mr-2" id="header_buttons">
	<li class="align-items-center d-lg-flex d-md-flex mx-2">
		<span class="terminal d-lg-flex align-items-center justify-content-center" tooltip="'.__('Support Access').'">
			<a href="'.$globals['index'].'act=support_access">
				<i class="fas fa-life-ring"></i>
			</a>
		</span>
	</li>';
	
	if(is_allowed('terminal')){
		echo '<li class="align-items-center d-none d-lg-flex d-md-flex" id="terminal_button">
			<span class="terminal d-lg-flex align-items-center justify-content-center" tooltip="'.__('Server(s) Terminal').'">
				<a id="terminal" href="javascript: void(0);" data-toggle="modal" data-target="#terminal_div">
					<i class="fas fa-terminal"></i>
				</a>
			</span>
		</li>';
	}
	
	echo '
	<li class="align-items-center d-none d-lg-flex d-md-flex mr-3">
		<div class="btn-group" id="header_notification">
			<a class="nav-link nav-icon" id="notification">
				<i class="far fa-bell"></i>
				<span class="notification-count text-always-white">0</span>
			</a>
			<div class="dropdown-menu dropdown-menu-arrow">
				<a class="dropdown-item d-flex justify-content-between align-items-center text-center">
					<div>'.__('You have total').'<span class="mx-1 text-primary notification-count">0</span>'.__('Notification(s)').'</div>
					<div id="notification2" class="ml-3 go_btn">
						'.__('Show all').'
					</div>
				</a>
				<div class="dropdown-divider"></div>
				<div id="notification_div"></div>
				<a href="javascript:void(0)" class="dropdown-item text-center text-primary" id="notification">
					'.__('Show All Notifications').'
				</a>
			</div>
		</div>
	</li>
	
	<li class="get-tasks d-flex align-items-center d-lg-flex d-md-flex mx-2">
		<span class="icon-fix d-flex align-items-center justify-content-center" tooltip="'.__('Tasks').'">
			<a class="nav-link" id="task_menu" href="'.$globals['ind'].'act=tasks"><i class="fas fa-tasks"></i></a></span>
		<span class="cursor-pointer icon-fix d-flex align-items-center justify-content-center task_count" onclick="gettasks()" tooltip="'.__('Get running tasks').'">0</span>
	</li>
	
	<li class="terminal d-flex align-items-center justify-content-center" onclick="theme_switcher(1);" tooltip="'.__('Dark mode').'" data-placement="right">
		<label for="theme_checkbox" class="themeToggle st-sunMoonThemeToggleBtn" type="checkbox">
			<input type="checkbox" id="theme_checkbox" class="themeToggleInput" onclick="theme_switcher(1);"/>
			<svg width="28" height="28" viewBox="0 0 28 28" fill="currentColor" stroke="none">
				<mask id="moon-mask">
					<rect x="0" y="0" width="28" height="28" fill="white"></rect>
					<circle cx="15" cy="4.2" r="12" fill="black"></circle>
				</mask>
				<circle
					class="sunMoon"
					cx="14"
					cy="14"
					r="12"
					mask="url(#moon-mask)"
				></circle>
				<g>
					<circle class="sunRay sunRay1" cx="26" cy="14" r="2"></circle>
					<circle class="sunRay sunRay2" cx="20.8" cy="22.8" r="2"></circle>
					<circle class="sunRay sunRay3" cx="7.2" cy="22.8" r="2"></circle>
					<circle class="sunRay sunRay4" cx="2" cy="14" r="2"></circle>
					<circle class="sunRay sunRay5" cx="7.2" cy="5.2" r="2"></circle>
					<circle class="sunRay sunRay6" cx="20.8" cy="5.2" r="2"></circle>
				</g>
			</svg>
		</label>
	</li>
	<li class="align-items-center d-none d-lg-flex d-md-flex mx-2">
		<span class="terminal d-flex align-items-center justify-content-center" tooltip="'.__('Documentation').'">
			<a id="document_link" href="'.$globals['docs'].'" target="_blank">
				<i class="fas fa-book"></i>
			</a>
		</span>
	</li>
	
	<li id="navbardrop" class="dropdown d-none d-lg-flex align-items-center justify-content-center d-lg-flex d-md-flex ml-2">
		<div class="d-flex align-items-center">
			<a class="nav-link p-1 dropdown-toggle d-flex align-items-center" href="#" data-toggle="dropdown">
				<span class="charprofile charprofile-lg d-flex align-items-center justify-content-center"></span>
			</a>
			<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton"><small>
				<a class="dropdown-item">'.__('Welcome ').'<b>'.@$user['name'].'</b></a>
				<a class="dropdown-item" href="'.$globals['ind'].'act=config">'.__('Master Settings').'</a>
				<a class="dropdown-item" href="'.$globals['ind'].'act=config_slave">'.__('Slave Settings').'</a>
				<a class="dropdown-item" href="'.$globals['ind'].'act=license">'.__('License Info').'</a>
				<a class="dropdown-item" href="'.$globals['ind'].'act=serverinfo">'.__('Server Info').'</a>
				<a class="dropdown-item" onclick="loadnotes()">'.__('Notes').'</a>
				<a class="dropdown-item" href="'.$globals['ind'].'act=feedback">'.__('Feedback').'</a></small>
			</div>
		</div>
	</li>
	
	<li class="align-items-center d-none d-lg-flex d-md-flex mx-2" id="logout_button" tooltip="'.__('Logout').'">
		<span class="terminal d-lg-flex align-items-center justify-content-center">
			<a id="terminal" href="'.$globals['ind'].'act=logout">
				<i class="fas fa-sign-out-alt" style="color:red"></i>
			</a>
		</span>
	</li>
	<div class="mobile-logo">
		<div class="d-flex align-items-center d-lg-none d-md-none">
			<div class="d-flex align-items-center ml-2">
				<a class="nav-link p-1 dropdown-toggle d-flex align-items-center" href="#" data-toggle="dropdown">
					<span class="charprofile charprofile-lg d-flex align-items-center justify-content-center"></span>
				</a>
				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton"><small>
					<h6 class="dropdown-header">'.__('Welcome').', <b>'.@$user['name'].'</b></h6>
					<a class="dropdown-item" href="'.$globals['ind'].'act=config">'.__('Master Settings').'</a>
					<a class="dropdown-item" href="'.$globals['ind'].'act=config_slave">'.__('Slave Settings').'</a>
					<a class="dropdown-item" href="'.$globals['ind'].'act=license">'.__('License Info').'</a>
					<a class="dropdown-item" href="'.$globals['ind'].'act=serverinfo">'.__('Server Info').'</a>
					<a class="dropdown-item" onclick="loadnotes()">'.__('Notes').'</a>
					<a class="dropdown-item" href="'.$globals['ind'].'act=feedback">'.__('Feedback').'</a></small>
					<a class="dropdown-item" href="'.$globals['ind'].'act=logout">'.__('Logout').'</a></small>
				</div>
			</div>
		</div>
	</div>
</div>
</header>
		<div class="left_menu_div '.($_COOKIE['menu_state'] == 'collapsed' ? 'left_menu_minimize' : '').'" id="left_collapsable_menu">
			<div class="left-main-menu">
				<div class="left-menu-list">
					<div class="row mx-auto w-100 left-search">
						<div class="col-sm-12 p-0" align="center">
							<!-- <form accept-charset="'.$globals['charset'].'" name="search" method="post" action="" onsubmit="return false;" id="searchform" class="form-horizontal">
								<div class="search-box">
									<input type="text" class="sai_search_box"  id="search_cat" onfocus="this.value=\'\';" onKeyUp="search_scripts(this.value);" onclick="search_scripts(this.value);" autocomplete="off" placeholder="'.__('Type to search').'" />
									<i class="fas fa-search"></i>
								</div>
								<div id="suggestions" class="sai_suggestions" style="position:absolute;left:0px; top:0px; display:none;"></div>
							</form> -->
							<div class="glass-search" >
								<input type="text" autocomplete="new-password" placeholder="Search menu..." class="glass-input" onKeyUp="search_scripts(this.value);"/>
								<i class="fas fa-search fa-md glass-icon"></i>
							</div>
						</div>
					</div>
					<ul class="menu-content collapse mt-40" id="menu-content">
						<!-- Dashboard starts here  -->
						<li class="menu-item text-nowrap '.(!empty($GLOBALS['act']) ? '': 'active').'">
							<div class="menu-name">
								<a class="d-flex align-items-center" href="'.$globals['ind'].'">
									<div class="left_menu_icon_fix">
										<i class="fas fa-home" id="menu_icon"></i>
									</div>
									<span class="menu_label"><label>'.__('Dashboard').'</label></span>
								</a>
							</div>
						<!-- Dashboard End-->';
						foreach($leftmenu as $cat => $val){
							
							if(!empty($val['hidden'])){
								continue;
							}

							echo
							'<li id="'.$cat.'" class="menu-item text-nowrap '.((!empty($val['sub_menu']) && array_key_exists($GLOBALS['act'], $val['sub_menu'])) || (!empty($val['act']) && $GLOBALS['act'] == $val['act']) ? 'active' : '' ).' '.(!empty($val['class']) ? $val['class'] : '').'" '.(!empty($val['onclick']) ? ' onclick="'.$val['onclick'].'"' : '').'>
								<div class="menu-name '.(!empty($val['sub_menu']) && array_key_exists($GLOBALS['act'], $val['sub_menu']) ? '' : 'collapsed').'" data-target="#'.$cat.'_content" data-toggle="collapse">
									'.(!empty($val['href']) ? '<a class="d-flex align-items-center" href="'.$val['href'].'" '.(!empty($val['attr']) ? $val['attr'] : '').' '.(!empty($val['target']) ? 'target="'.$val['target'].'"' : '').'>' : '');
									if(preg_match('/.png|.gif|.jpeg|jpg|.svg/is', $val['icon'])){
										echo '
										<div class="left_menu_icon_fix">
											'.$val['icon'].'
										</div>';
									}else{
										echo '
											<div class="left_menu_icon_fix">
												<i class="'.$val['icon'].'" id="menu_icon" ></i>
											</div>';
									}

									echo'<span class="menu_label">
											<label>'.$val['name'].'</label> 
										</span>
										<div class="no-effect align-items-center">';
											// count defined here
											if(array_key_exists($cat, $total) && !empty($total[$cat])){
												echo '<div class="count">'.$total[$cat].'</div>';
											}

											if(!empty($val['sub_menu']) && is_array($val['sub_menu'])){
												echo '<i class="fas fa-chevron-right ms-auto"></i>';
											}
										echo '
										</div>
										'.(!empty($val['href']) ? '</a>' : '');
									echo'
								</div>';
				
									if(!empty($val['sub_menu'])){
										echo' 
										<ul id="'.$cat.'_content" class="sub-menu collapse '.(array_key_exists($GLOBALS['act'], $val['sub_menu']) ? 'show' : '').'" data-parent="#menu-content" >';

										foreach($val['sub_menu'] as $opt1 => $submenu_options){
										
											
											if(!empty($submenu_options['hidden'])){
												continue;
											}

											$sa = '';

											(!empty($GLOBALS['_GET']['sa']) ? $sa = $GLOBALS['act'].'&sa='. $GLOBALS['_GET']['sa'] : $sa = $GLOBALS['act']);


											echo'<li class="'.($opt1 == $sa ? 'active-link' : '').'" tags="'.(!empty($submenu_options['tags']) ? $submenu_options['tags'] : '').'">
													<a class="text-decoration-none" href="'.$submenu_options['href'].'" '.(!empty($submenu_options['target']) ? $submenu_options['target'] : '').'>
														<span class="menu_item">'.$submenu_options['name'].'</span>
													</a>
												</li>
											';
											
										}
										echo' </ul>';
									}

								echo'
							</li>';
						}
						echo'
					</ul>
				</div>
			</div>
		</div>
		<div class="col-sm p-0 softcontent " id="softcontent">';
		show_backuply_notice();
		show_miner_notice();
	}
	
	echo '<script>theme_switcher();</script><script>

//To fix a bug in flot library
var matched, browser;
jQuery.uaMatch = function( ua ) {
    ua = ua.toLowerCase();

    var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
        /(msie) ([\w.]+)/.exec( ua ) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
        [];

    return {
        browser: match[ 1 ] || "",
        version: match[ 2 ] || "0"
    };
};

matched = jQuery.uaMatch( navigator.userAgent );
browser = {};

if ( matched.browser ) {
    browser[ matched.browser ] = true;
    browser.version = matched.version;
}

// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
    browser.webkit = true;
} else if ( browser.webkit ) {
    browser.safari = true;
}

jQuery.browser = browser;

	function left_menu_toggle(forceState = null) {
		var leftMenuDiv = document.querySelector(".left_menu_div");
		var noEffectSpans = document.querySelectorAll(".no-effect");
		var searchBoxes = document.querySelectorAll(".search-box");
		var softContent = document.getElementById("softcontent");
		var toggleButton = document.getElementById("left_menu_toggle_btn");
		var navBar = document.querySelector(".top-header");

		var isMinimized = leftMenuDiv.classList.contains("left_menu_minimize");
		var newState = (forceState !== null) ? forceState : !isMinimized;

		if (!newState) {
			$(".sub-menu").removeClass("hide");
			$(".collapsed").unbind();
			$(".left_menu_minimize .menu-item").unbind("mouseenter mouseleave");
			leftMenuDiv.classList.remove("left_menu_minimize");
			softContent.classList.remove("left_menu_min");
			toggleButton.classList.remove("collapsed");
			navBar.classList.remove("left_menu_minimize");

			noEffectSpans.forEach(function(span) {
				span.classList.remove("d-none");
				span.classList.add("d-flex");
			});

			searchBoxes.forEach(function(box) {
				box.classList.remove("d-none");
				box.classList.add("d-flex");
			});

			setcookie("menu_state", "expanded", 7);
		} else {
			toggleButton.classList.add("collapsed");
			softContent.classList.add("left_menu_min");
			leftMenuDiv.classList.add("left_menu_minimize");
			navBar.classList.add("left_menu_minimize");
			$(".sub-menu").removeClass("show");
			$(".sub-menu").addClass("hide");

			$(".collapsed").on("click", function(e) {
				e.stopPropagation();
			});

			$(".left_menu_minimize .menu-item").hover(
				function(e) {
					var value = $(this).offset();
					var scrollval = $(window).scrollTop();
					var topval = value.top - scrollval;
					var subtopval = topval + 39;	
					$(this).find(".menu_label").addClass("show position-fixed").css("top", topval + "px");
					$(this).find(".sub-menu").addClass("show position-fixed").css("top", subtopval + "px");
				},
				function(e) {
					$(this).find(".menu_label").removeClass("show position-fixed").css("top", "0px");
					$(this).find(".sub-menu").removeClass("show position-fixed").css("top", "0px");
				}
			);

			noEffectSpans.forEach(function(span) {
				span.classList.remove("d-flex");
				span.classList.add("d-none");
			});
			searchBoxes.forEach(function(box) {
				box.classList.remove("d-flex");
				box.classList.add("d-none");
			});

			setcookie("menu_state", "collapsed");
		}
	}


	function search_scripts(val) {
		var $val = val.toLowerCase();
		var found = 0;
		var qlen = val.length;

		// Remove all found attr
		$(".menu-item").find("[found]").removeAttr("found");

		if (qlen >= 1) {
			// Expand all sub-menus
			$(".menu-name").removeClass("collapsed");
			$(".sub-menu").addClass("show");

			// Find the options in the submenu li and the menu-name
			$(".menu-item .sub-menu li").each(function() {
				var text = $(this).text().toLowerCase();
				var search_tags = $(this).attr("tags") || "";
				if (text.indexOf($val) >= 0 || search_tags.indexOf($val) >= 0) {
					found = 1;
					$(this).attr("found", 1);
					$(this).show();  // Ensure the submenu item is visible
				} else {
					$(this).hide();  // Hide the submenu item if not matching
				}
			});

			$(".menu-item .menu-name").each(function() {
				var text = $(this).text().toLowerCase();
				if (text.indexOf($val) >= 0) {
					$(this).attr("found", 1);
					found = 1;
					$(this).removeClass("collapsed");
					$(this).parent().find(".sub-menu").addClass("show"); // Ensure sub-menu is displayed
				}
			});

		} else {
			// Collapse all sub-menus
			$(".menu-item .sub-menu").collapse("hide");
			$(".menu-item li.active .sub-menu").collapse("show");

			// Show all menu-names and sub-menu items
			$(".menu-item .menu-name").attr("found", 1);
			$(".menu-item .sub-menu li").show();
		}

		$(".menu-item .menu-name").each(function() {
			if ($(this).parent().find("[found]").length >= 1) {
				$(this).parent().show();
				$(this).parent().find(".sub-menu").collapse("show"); // Ensure sub-menu is displayed
			} else {
				$(this).parent().hide();
			}
		});

		if (qlen >= 1) {
			if (!found) {
				$(".no_data_found").show();
				$(".no_data_found").html("No data found!");
				$(".menu-list").hide();
			} else {
				$(".no_data_found").hide();
				$(".menu-list").show();
			}
		}
	}


	
	function remove_unnecessary_tables(){
		$.each(leftmenu, function (menu, submenu) {
			var id = $($("#head_"+menu).next("tr").find("div").children());
			if(id.children().length == 0){
				$("#head_"+menu).closest("table").remove();
				$("#head_"+menu).remove();
			}
		});
	}
	
	</script>';
	
	//Everything else will go here
	echo '
	<div class="modal fade"  id="logs_modal">
		<div class="modal-dialog modal-xl">
			<div class="modal-content">
				<div class="modal-header text-center rounded-top" id="logs_modal_head">
				<span class="fhead text-always-white">'.__('Logs').'</span>
					<button class="close text-always-white" data-dismiss="modal" >&times;</button>
				</div>
				<div class="modal-body" id="logs_modal_body" ></div>
			</div>
		</div>
	</div>

	<div class="modal fade"  id="common_modal">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header text-center rounded-top" id="common_modal_head">
				<span class="fhead text-always-white"></span>
					<button class="close text-always-white" data-dismiss="modal" >&times;</button>
				</div>
				<div class="modal-body" id="common_modal_body" ></div>
			</div>
		</div>
	</div>
	
	<!--search modal-->
	<div class="modal fade" role="dialog" id="search_modal" aria-hidden="false">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header text-center rounded-top">
					<span class="fhead text-always-white" id="search_header"></span>
					<button class="close text-always-white" data-dismiss="modal">X</button>
				</div>
				<div class="modal-body h-25">
					<div id="searchdata_loader" style="display:none;">
						<div class="splash-screen">
							<div class="loader-lg"></div>
						</div>
					</div>
					<div id="searchdata_pagination">
						<div class="pagination-top p-2 w-100 bg-white sticky-top" style="display:none;"></div>
						<div id="searchdata" class="ml-2 mr-2"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--search modal ends-->

	<!-- Terminal Modal starts here -->
	<div class="modal terminal-modal-lg" id="terminal_div">
		<div class="modal-dialog modal-dialog-centered modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<div class="terminal-header">
						<i class="fas fa-terminal mr-2"></i>
						'.__('Server Terminal').'
					</div>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
				</div>
				<div class="modal-body p-0 m-0" id="terminal_content">
					<div class="card p-2">';
						if(!empty($globals['disable_terminal_access'])){
							echo '<div class="notice mx-3"><b>'.__('Note').' : </b> &nbsp; '.__('Server web terminal is disbaled, If you want to access please enable it from the Master settings').'</div>';
						}else{
						
						echo'
							<div name="terminal_form">
								<input type="hidden" name="act" value="terminal" />
								<input type="hidden" name="from_theme" value="1" />
								<div class="row mx-auto w-100">
									<div class="col-6 my-2">
										<label>'.__('Select Server').'</label>
										<select name="serid" id="servers_terminal" class="virt-select w-50">';
										// r_print($servers);
										foreach($servers as $sk => $sv){
											echo '<option value="'.$sk.'" '.((!empty($_REQUEST['serid']) && (((int) $_REQUEST['serid']) == $sk)) ? 'selected="selected"' : '').'>'.$sv['server_name'].' ('.$sv['ip'].')</option>';
										}
									echo '
										</select>
									</div>
									<div class="col-6 d-flex align-items-end justify-content-end my-2">
										<a href="javascript:void(0)" title="'.__('Open terminal').'" class="btn mr-2" onclick="open_terminal(this.value);" '.(!empty($globals['disable_terminal_access']) ? 'disabled' : '').'><i class="fas fa-external-link-alt"></i> '.__('Open Terminal').'</a>
										<a href="javascript:void(0)" onclick="del_terminal_sess();return false;" title="'.__('Delete session').'" class="btn red_btn"><i class="fas fa-trash"></i> '.__('Delete session').'</a>
									</div>
								</div>
							</div>
							<div class="notice mx-3">
								'.__('Always close the terminal after use').'
							</div>';
						}
						echo'
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- Terminal Modal ends here -->

	<!-- Notice Modal starts here -->
	<div id="notices">';

	$admin_notices = get_notices('', true);

	if(is_array($admin_notices)){

		krsort($admin_notices);

		$notice_count = 0;

		foreach($admin_notices as $nid => $v){

			if($notice_count >= 2) break;

			if(!empty($v['dismissed'])) continue;

			echo 
			'<div id="ndiv_'.$nid.'" class="mx-3 admin_notice">
				<div class="d-flex justify-content-between">
					<div id="'.$nid.'">
						<a href="'.($v['link'] ?: '#').'"><h6 class="'.($v['type'] == 'danger' ? 'text-danger' : 'text-black').'">'.$v['title'].'</h6></a>
						<p class="text-black my-1">'.$v['body'].'</p>
					</div>
					'.(!empty($v['dismissable']) ? '<div><a aria-label="Close" data-nid="'.$nid.'" onclick="dismiss_notice(this)"><i class="fas fa-times"><div></div></i></a></div>' : '' ).'
				</div>
			</div>';

			$notice_count++;
		}

		// There are more notification which are not show add a hyperlink to notices page
		if($notice_count >= 2){
			echo 
			'<div id="all_notice" class="mx-3 admin_notice">
				<a href="'.$globals['index'].'&act=notice"><h6 class="text-black">'.__('Goto All Notices').'</h6></a>
			</div>';
		}
	}
	
	echo'
	</div>
	<!-- Notice Modal ends here -->';
	
}


function softfooter(){

global $theme, $globals, $kernel, $user, $l, $error, $end_time, $start_time, $servers;

if(optGET('jsnohf')){
	return true;
}

echo '</div>';

if(!empty($theme['leftbody'])){
	
	echo '</div></div>';

}

echo '<br />';

echo '<br /><div class="row w-100 mx-auto"><div class="col-sm-2"></div><div class="col-sm-12 col-md-12 col-lg-10" id="footer-div">';

$pageinfo = array();

if(!empty($globals['showntimetaken'])){

	$pageinfo[] = __('Page Created In').':'.substr($end_time-$start_time,0,5);

}

echo '
<footer>
<div align="center">'.__('All times are in').(empty($globals['pgtimezone']) ? '' : ' '.($globals['pgtimezone'] > 0 ? '+' : '').$globals['pgtimezone']).'. '.__('The time now is').' '.datify(time(), false).'.</div>
        <p class="pb-0 pt-0">'.copyright().', '.implode('&nbsp;&nbsp;|&nbsp;&nbsp;', $pageinfo).'.</p>
    </footer>
</div></div>';

echo'
<a id="back-to-top" href="#" class=" btn-dark back-to-top" role="button" ><i class="fas fa-angle-double-up"></i></span></a>

<script>

$(document).ready(function(){
	document.getElementById("left_menu_toggle_btn").addEventListener("click", function() {
		left_menu_toggle();
	});
	
	if($(".selected").length > 0){
		$("#left-menu .scrollbar").animate({ 
			scrollTop: $(".selected").offset().top - ($(window).height() / 3)
		}, "slow");
	}
     $(window).scroll(function () {
            if ($(this).scrollTop() > 100) {
                $("#back-to-top").fadeIn();
            } else {
                $("#back-to-top").fadeOut();
            }
        });
        // scroll body to 0px on click
        $("#back-to-top").click(function () {
            $("body,html").animate({
                scrollTop: 0
            }, 800);
            return false;
        });
});
</script>';

if(!empty($theme['copyright'])){

	echo unhtmlentities($theme['copyright']).'';

}

echo '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
function bodyonload(){
	if(aefonload != \'\'){		
		eval(aefonload);
	}
	'.(empty($onload) ? '' : 'eval(\''.implode(';', $onload).'\');').'
};
// ]]></script>

<script type="text/javascript">';

if($globals['lictype'] == '-2' || is_fake_license() == 2){
	
	echo 'var bottomdivs = Array();';

	if($globals['lictype'] == '-2'){
		echo 'bottomdivs.push("virt_dev_banner");';
	}

	if(is_fake_license() == 2){
		echo 'bottomdivs.push("virt_lic_sync_banner");';
	}

	echo '
	
	$(function(){
		$(window).resize(function(e){
			callbottomdivs(bottomdivs)
		});
		$.event.add(window, "scroll", function() {
			callbottomdivs(bottomdivs)
		});
		callbottomdivs(bottomdivs)
		//placeDevBanner();
		$("#bttom_banner").css("position","fixed");
		$("#bttom_banner").css("display","inline");
		$("#bttom_banner").css({"z-index":"10"});
		$("body").css("margin","0 0 "+$("#bttom_banner").height()+"px 0");
	});

	function callbottomdivs(divs){
		var div_height = 0;
		var foot_height = 0;
		for(x in divs){
			showBottomBanner(divs[x]);
			foot_height += $("#"+divs[x]).height();
			if(x > 0){
				div_height += $("#"+divs[x]).height();
				$("#"+divs[x]).css("bottom", div_height);
				$("body").css("margin","0 0 "+div_height+"px 0");
			}
		}
		
		$("#footer-div").css("margin","0 0 "+(foot_height - 20)+"px 0");
	}

	function showBottomBanner(ele) {
		//alert(ele)
		$("#"+ele).show();
		var docwidth = $("body").width();
		var newheight = $(document).scrollTop() + parseInt($(window).height()) - parseInt($("#"+ele).height());
		var lmenu_width = $("#left-menu").width();
		dev_banner_width = (docwidth - lmenu_width);
		dev_banner_left = lmenu_width;
		if($("#left-menu").is(":hidden")){
			dev_banner_width = "100%";
			dev_banner_left = 0;
		}
		
		$("#"+ele).css({"bottom":0, "left":dev_banner_left, "width":(dev_banner_width), "z-index":3});
		$("body").css("margin","0 0 "+$("#"+ele).height()+"px 0");
	}
	';
}

echo '
</script>

<div id="bttom_banner">
	<div id="virt_dev_banner" class="mx-auto" style="display:none;position: fixed;">
		<div class="notice mb-0">'.__('<strong>Dev License:</strong> This installation of VIRTUALIZOR is running under a Development License and is not authorized to be used for production use. <br>Please report any cases of abuse to support@virtualizor.com').'</div>
	</div>
	<div id="virt_lic_sync_banner" class="mx-auto" style="display:none;position: fixed;">
		<div class="e_notice mb-0">'.__('<strong>License Sync Error:</strong> It seems that your server is not in sync with Virtualizor servers. <br>Please report to support@virtualizor.com').'</div>
	</div>
</div>
</body>
</html>';
}


function error_handle($error, $table_width = '100%', $center = false, $ret = false, $echo_it = 0){

global $l, $theme;
	
	$str = '';
	
	// For showing logs
	$actid = (int) optREQ('actid');
	
	//on error call the form
	if(!empty($error)){

		apply_filters('error_handle', $error);
		
		$str = '
			<div id="error_box" '.((optREQ('jsnohf')  || !empty($echo_it)) ? 'class="e_notice"' : '').' align="left">
				<div style="width:'.$table_width.'" class="error" '.(($center) ? 'align="center"' : '' ).'>
					'.__('The following errors were found').' :<br/>
				<ul>';
		
		foreach($error as $ek => $ev){

			if(strcmp($ek, 'derr') == 0){
				$debug_arr = $error['derr'];
				continue;
			}
			
			$str .= '<li>'.preg_quote($ev, "'").'</li>';
		
		}
		
		if(!empty($actid)){
			$str .= '<li><a href="javascript:void(0);" onclick="return loadlogs('.$actid.');" class="btn p-2">'.__('Show Log').'</a></li>';
		}
		
		$str .= '</ul>
		</div>';
			
			//Append the additional debug error information
			if(!empty($debug_arr)){
				$str.= '<br />
				
				<div class="deterr-toggle">
					<center><a class="deterr" style="text-decoration:none;" href="#" onclick="deterr();"><img src="'.$theme['images'].'/collapsed.png"/>'.__('Show detailed information about this error').'</a></center>
				</div>
				
				<div class="deterr-toggle" style="display:none;">
					<center><a class="deterr" style="text-decoration:none;" href="#" onclick="deterr();"><img src="'.$theme['images'].'/expanded.png"/>'.__('Hide detailed information about this error').'</a></center>
				</div>
				
				<br/><br/>
				<div id="deterr-container" style="display:none;background-color:rgb(230, 230, 230);">
					<b>OUTPUT</b>:<pre>'.implode('', $debug_arr['output']).'</pre><br />
					<b>RETURN</b>: '.$debug_arr['return'].'
				</div>
				<br /><br />';
			}
			
		$str .= '</div>';
		$str = preg_replace("/\r|\n/", "", $str);
		if(empty($ret)){
			if(!optREQ('jsnohf') && empty($echo_it)){
				echo '<script>showalert(\''.$str.'\',"1");</script>';
			}else{
				echo $str;
			}			
		}else{
			return $str;
		}
	}

}
function show_alert($message, $action = '', $redirect = ''){
	global $globals; 

	if(!empty($message)){
		echo '<script>showalert(\''.$message.'\','.$action.');</script>';
		if(!empty($redirect)){
			echo '<script>
			$(document).ready(function() {
				$("#alert-modal").on("hidden.bs.modal", function (e) {
					// put your default event here
					window.location.href="'.$globals['ind'].'act='.$redirect.'";
				});
			});
			</script>';
		}
	}
}
//This will just echo that everything went fine
function success_message($message, $table_width = '100%', $center = false){

global $l;

	//on error call the form
	if(!empty($message)){
		echo '<table width="'.$table_width.'" cellpadding="2" cellspacing="1" class="error" '.(($center) ? 'align="center"' : '' ).'>
			<tr>
			<td>
			'.__('The following message was returned').' :
			<ul type="square">';
		
		foreach($message as $mk => $mv){
		
			echo '<li>'.$mv.'</li>';
		
		}
		
		
		echo '</ul>
			</td>
			</tr>
			</table>'.(($center) ? '</center>' : '' ).'
			<br />';
		
		
	}

}


function majorerror($title, $text, $heading = ''){

global $theme, $globals, $user, $l;

softheader(((empty($title)) ? __('Fatal Error') : $title), false);

?><br /><br />

<div class="row mx-auto w-100">
<div class="col-sm-2 col-md-2"></div>
<div class="col-sm-8 col-md-8 p-0 border" align="center">
<table cellpadding="2" cellspacing="1" class="table tablesorter border-primary m-0 bg_white" align="center">
	<tr>
	<th align="left">
	<span class="pull-left"><?php echo ((empty($heading)) ? __('The following error occured').':' : $heading);?></span>
	</th>
	</tr>
	
	<tr>
	<td colspan="2" align="center">
	<i class="fas fa-exclamation-triangle text-danger my-3" style="font-size:50px;"></i>
	</td>
	</tr>
	<tr>
	<td class="fhead" align="center"><?php echo $text;?><br />
	</td>
	</tr>

</table>
</div>
</div>
<center class="mt-5"><a href="javascript: window.history.go(-1)" class="link_btn"><?php echo __('Go Back');?></a></center>
<?php

softfooter();
?>
<script>
	$("#footer-div").removeClass("col-lg-10");
	$(".navbar-brand").next("div").css("display","none");
	$(".navbar-collapse .server_select").css("visibility","hidden");
	
</script>
<?php
//We must return
return true;

}

function message($title, $heading = '', $icon = '', $text = ''){

global $theme, $globals, $user, $l;

softheader(((empty($title)) ? __('Message') : $title), false);

?><br /><br />
<div class="row mx-auto w-100">
<div class="col-sm-2 col-md-2"></div>
<div class="col-sm-8 col-md-8" align="center">
<table width="70%" cellpadding="2" cellspacing="1" class="table tablesorter border" align="center">
	
	<tr>
	<th align="left">
		<span class="pull-left"><?php echo ((empty($heading)) ? __('The following message was returned').':' : $heading);?></span>
	</th>
	</tr>
	
	<tr>
	<td class="bg" colspan="2" align="center">
	<img src="<?php echo $theme['images'].(empty($icon)?'info.gif':$icon);?>" alt="" />
	</td>
	</tr>
	
	<tr>
	<td class="" align="left"><?php echo $text;?><br />
	</td>
	</tr>

</table>
</div>
</div>

<?php

softfooter();

//We must return
return true;

}

function page_links($num_res, $page, $max = 50){
	
global $l, $js, $globals, $theme;
	
	$pages = ceil($num_res/$max); // Number of Pages	
	$pg = ceil(($page/$max) + 1); //Current Page

	$_pages = array();
	
	if($pages > 1){
		
		// Show th Back Links if required
		if($pg != 1){			
			$_pages['&lt;&lt;'] = 1;			
			$_pages['&lt;'] = ($pg - 1);		
		}
		
		for($i = ($pg - 4); $i < $pg; $i++){			
			if($i >= 1){			
				$_pages[$i] = $i;			
			}		
		}
		
		$_pages[$pg] = $pg;
				
		for($i = ($pg + 1); $i <= ($pg + 4); $i++){		
			if($i <= $pages){			
				$_pages[$i] = $i;			
			}		
		}
		
		
		if($pg != $pages){			
			$_pages['&gt;'] = ($pg + 1);			
			$_pages['&gt;&gt;'] = $pages;		
		}	
	}
	
	// We show the jumper if its more than 50
	if($num_res > ($globals['rows_to_display'] > 0 ? $globals['rows_to_display'] : 50 )){

$name = 'pgjmp_'.generateRandStr(4);

if(empty($js['menu'])){
	echo '<script language="javascript" src="'.$theme['url'].'/js/menu.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
function go_to(max, pg, urlto){
	try{
	var urlto = (urlto || window.location).toString();
	var pg = pg || 0;
	var final = urlto.replace(/(&?)page\=(\d{1,4})|(&?)reslen\=(\d{1,500})/gi,"")+"&page="+pg+"&reslen="+max;
	window.location = final;
	}catch(e){ }
};
// ]]></script>';

	$js['menu'] = true;
}

$links = '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
createmenu("'.$name.'", [
[\'<div clas="row mx-auto w-100"><div class="pl-0 pr-2 d-inline-flex"><input type="text" class="form-control" name="page" id="in'.$name.'" size="10" /></div><div class="pl-0 d-inline-flex"><input type="button" value="'.__J('Go').'" onclick="go_to('.$max.', $_(\\\'in'.$name.'\\\').value)" class="go_btn go_btn_small"/></div>\']
]);

// ]]></script>

<div class="w-60 mr-4"><table class="cbgbor" cellspacing="1" cellpadding="0" border="0">
<tr>
<td><a href="javascript:void(0)" onmouseover="dropmenu(this, \''.$name.'\')" onmouseout="pullmenu(\''.$name.'\')" title="'.__('Type the page to jump to').'" > &nbsp; '.__('Page').' '.$pg.' '.__('of').' '.$pages.' &nbsp; </a></td>';

foreach($_pages as $k => $lv){
	$links .= '<td class="'.($k == $pg ? 'activepage' : 'pagelinks' ).'"><a href="javascript:go_to('.$max.', '.$lv.')">'.$k.'</a></td>';
}

$links .= '<td colspan="0">
<select name = "reslen" class="perpage custom-select border-0" onchange="return go_to(this.value)">
<option value="-1">--</option>
'.(!empty($globals['rows_to_display']) ? '<option value="'.$globals['rows_to_display'].'" '.($max == $globals['rows_to_display'] ? 'selected="selected"' : '').'>'.$globals['rows_to_display'].'</option>' : '').'
<option value="50" '.($max == 50 ? 'selected="selected"' : '').'>50</option>
<option value="100" '.($max == 100 ? 'selected="selected"' : '').'>100</option>
<option value="250" '.($max == 250 ? 'selected="selected"' : '').'>250</option>
<option value="500" '.($max == 500 ? 'selected="selected"' : '').'>500</option>
<option value="1000000" '.($max == 1000000 ? 'selected="selected"' : '').'>'.__('All').'</option>
</select></td><td> &nbsp; '.__('Rows').' &nbsp; </td></tr>
</table></div>';
	
	echo $links;
	
	}
	
}

// Echos a (?) URL
function virthelp($link){
	
	global $globals, $l;
	
	return '<a href="'.$globals['docs'].$link.'" target="_blank" tooltip="'.__('Open the guide').'"><i class="fas fa-external-link-alt info"></i></a>';	
}

// Displays the servers selection dropdown
function server_select(){
	
	global $servers, $theme, $globals, $l;
	
	echo '<div class="row mx-auto w-100">
		<div class="col-sm-12">
			<label class="control-label">'.__('Select Server').' : </label>
			<select id="server-select" class="server-select">';
				foreach($servers as $k => $v) {
					if(($v['serid'] == 0) && !empty($globals['is_master_only'])){
						$v['virt'] = 'msonly';
					}
					echo '<option value="'.$k.'" '.($k == $globals['server'] ? 'selected' : '').' data-virt="'.$v['virt'].'">'.$v['server_name'].' ('.$v['ip'].')'.($v['locked'] == 0 ? '' : ' (Locked)').'</option>';
				}
			echo '</select>
		</div>
	</div>';
	
}

function show_backuply_notice(){
	global $servers, $theme, $globals; 
	if(!has_plugin_license('backuply')){
		$show_banner = 0;
		foreach($servers as $serid => $ser){
			if(!empty($ser['virts']) && in_array('kvm', $ser['virts'])){
				$show_banner = 1;
				break;
			}
		}
		if($show_banner && !file_exists($globals['var'].'/backuply_banner')){
			echo '<div class="alert bg-light alert-dismissible fade show blink_me" role="alert">
					<div class="d-flex align-items-center">
						<img src="'.$theme['images'].'svgset/backuply-logo.svg" width="40px" />
						<span class="h6 m-0 ml-1"><a href="https://softaculous.com/clients/?ca=virtualizor">Try Backuply!</a></span>
						<p class="mb-0 ml-2 d-flex align-items-center"> Using backuply you can take automated incremental backups. To know more <a href="https://www.virtualizor.com/docs/backuply/" class="ml-1">Click Here</a>.</p>
					</div>
					<button type="button" class="close" data-dismiss="alert" aria-label="Close" id="close_backuply_banner">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<script>
					$(document).ready(function(){
						$("#close_backuply_banner").on("click", function(){
							$.ajax({
								url: "'.$globals['index'].'disable_backuply_ban=1"
							});
						})
					})
				</script>';
		}
	}

}

function show_miner_notice(){
	global $servers, $theme, $globals;
	if(file_exists('/var/virtualizor/miner_found') && !file_exists($globals['var'].'/hide_miner_found_banner')){
		echo '<div class="alert alert-danger alert-dismissible fade show blink_me" role="alert">
					<div class="d-flex align-items-center">
						<p class="mb-0 ml-2 d-flex align-items-center">We had detected a crypto miner on your server. We have cleaned it now ! However, you need to change your root password as soon as possible.</p>
					</div>
					<button type="button" class="close" data-dismiss="alert" aria-label="Close" id="close_miner_banner">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<script>
					$(document).ready(function(){
						$("#close_miner_banner").on("click", function(){
							$.ajax({
								url: "'.$globals['index'].'hide_miner_found_banner=1"
							});
						})
					})
				</script>';
	}

}


function get_checkbox($name, $text = '', $id = '', $chk_post = array('chk_it' => 1), $value = 1, $class_name = '', $events= array()){
	$events = implode(' ', $events);
	if(!array_key_exists('val', $chk_post)){
		$chk_post['val'] = false;
	}
	$chk_flag = '';
	if(!empty($chk_post['chk_it'])){
		$_name = $name;
		if(!empty($chk_post['name'])){
			$_name = $chk_post['name'];
		}
		$chk_flag = POSTchecked($_name, $chk_post['val']);
	}
	if(empty($id)){
		$id = generateRandStr(5);
	}

	return '<div class="custom-control custom-checkbox">
				<input type="checkbox" autocomplete="off" class="'.($name != 'select_all' ? 'ios' : '').' custom-control-input '.$class_name.'" name="'.$name.'" '.(!empty($id) ? 'id="'.$id.'"' : '').' '.$chk_flag.' '.($value != -1 ? 'value="'.$value.'"' : '').' '.$events.'>
				<label class="custom-control-label" for="'.$id.'">'.$text.'</label>
			</div>';
}

function get_switch($name, $text = '', $id = '', $chk_post = array('chk_it' => 1), $value = 1, $class_name = '', $events= array(), $is_large=''){
	$events = implode(' ', $events);
	if(!array_key_exists('val', $chk_post)){
		$chk_post['val'] = false;
	}
	if(!empty($chk_post['chk_it'])){
		$_name = $name;
		if(!empty($chk_post['name'])){
			$_name = $chk_post['name'];
		}
		$chk_flag = POSTchecked($_name, $chk_post['val']);
	}
	if(empty($id)){
		$id = generateRandStr(5);
	}

	return '<div class="custom-control custom-switch '.(!empty($is_large) ? 'custom-switch-lg' : '').'">
				<input type="checkbox" autocomplete="off" class="'.($name != 'select_all' ? 'ios' : '').' custom-control-input '.$class_name.'" name="'.$name.'" '.(!empty($id) ? 'id="'.$id.'"' : '').' '.$chk_flag.' '.($value != -1 ? 'value="'.$value.'"' : '').' '.$events.'>
				<label class="custom-control-label" for="'.$id.'">'.$text.'</label>
			</div>';
}

function get_num_records($count){
	global $l;
	if($count > 0){
		return '<div class="badge badge-virt-secondary">
					'.$count.'</b>'.__(' results found').'
				</div>';
	}
}

function get_breadcrumb($bread){
	global $globals, $l;

	$bread_crumb_array = [];

	// insert all bread in act of key with the value of thier name
	foreach($bread as $breadcrumb){
		$bread_crumb_array[]['act'] = $breadcrumb;
	}
	// r_print($bread_crumb_array);
	$cont =  '<nav aria-label="breadcrumb">
		<ol class="breadcrumb">
		';
		
	$last_element = array_pop($bread_crumb_array);
	
	end($bread_crumb_array);

	$left_menu = [
		'lm_file_mgr' => __('File Manager'),
		'lm_dashboard' => __('Dashboard'),
		'lm_vs' => __('Virtual Servers'),
		'lms_vs' => __('List All'),
		'lms_addvs' => __('Create VPS'),
		'lms_managevps' => __('Manage VPS'),
		'lms_rebuild' => __('Rebuild VPS'),
		'lms_addvs_xenhvm' => __('Create HVM VPS'),
		'lms_vnc' => __('Launch VPS'.' VNC'),
		'lms_migrate' => __('Migrate VPS'),
		'lms_clone' => __('Clone VPS'),
		'lms_haproxy' => __('Domain Forwarding'),
		'lms_ha' => __('High Availability'),
		'lm_load_balancer' => __('Load Balancer'),
		'lms_load_balancer' => __('List Load Balancer'),
		'lms_add_load_balancer' => __('Add Load Balancer'),
		'lms_manage_load_balancer' => __('Manage Load Balancer'),
		'lms_migrate_disk' => __('Migrate Disk'),
		'lm_ippool' => __('IP Pool'),
		'lms_ippool' => __('List IP Pools'),
		'lms_editippool' => __('Edit IP Pool'),
		'lms_addippool' => __('Add IP Pool'),
		'lms_ips' => __('List IPs'),
		'lms_addips' => __('Add IP'),
		'lms_editip' => __('Edit IP'),
		'lms_ipranges' => __('List IPv6 Subnets'),
		'lms_addiprange' => __('Add IPv6 Subnet'),
		'lms_managesubnets' => __('Manage IPv6 Subnets'),
		'lm_servers' => __('Servers'),
		'lms_servers' => __('List Servers'),
		'lms_addserver' => __('Add Server'),
		'lms_editserver' => __('Edit Server'),
		'lms_manageserver' => __('Manage Server'),
		'lms_servergroups' => __('Server Groups / Regions'),
		'lms_addsg' => __('Add Server Group / Region'),
		'lms_backupservers' => __('List Backup Servers'),
		'lms_addbackupserver' => __('Add Backup Server'),
		'lms_editbackupserver' => __('Edit Backup Server'),
		'lms_terminal' => __('Server Terminal'),
		'lms_server_sshkeys' => __('Server SSH Keys'),
		'lm_plans' => __('Plans'),
		'lms_plans' => __('List Plans'),
		'lms_editplan' => __('Edit Plan'),
		'lms_addplan' => __('Add Plan'),
		'lms_user_plans' => __('List User Plans'),
		'lms_adduser_plans' => __('Add User Plan'),
		'lms_edituser_plans' => __('Edit User Plan'),
		'lms_dnsplans' => __('List DNS Plans'),
		'lms_adddnsplan' => __('Add DNS Plan'),
		'lms_backup_plans' => __('List Backup Plans'),
		'lms_addbackup_plan' => __('Add Backup Plan'),
		'lms_editbackup_plan' => __('Edit Backup Plan'),
		'lm_vpsfirewall' => __('VPS Firewall'),
		'lms_vpsfirewallconfig' => __('Apply Firewall'),
		'lms_vpsfirewall_plans' => __('VPS Firewall Plans'),
		'lms_server_firewall_plans' => __('Server Firewall Plans'),
		'lms_addfirewall_plan' => __('Add Firewall Plan'),
		'lms_editfirewall_plan' => __('Edit Firewall Plan'),
		'lms_serverfirewall_status' => __('Server Firewall Status'),
		'lms_view_firewall_rules' => __('View Firewall Rules'), 
		'lm_users' => __('Users'),
		'lms_users' => __('List Users'),
		'lms_adduser' => __('Add User'),
		'lms_edituser' => __('Edit User'),
		'lms_mail' => __('Mail to User'),
		'lms_addcloud' => __('Add Cloud User'),
		'lms_user_sessions' => __('User Sessions'),
		'lms_user_notice' => __('User Notice'),
		'lms_add_user_notice' => __('Add User Notice'),
		'lms_edit_user_notice' => __('Edit User Notice'),
		'lm_storage' => __('Storage'),
		'lms_storage' => __('List Storage'),
		'lms_editstorage' => __('Edit Storage'),
		'lms_addstorage' => __('Add Storage'),
		'lms_orphaneddisks' => __('Orphaned Disks'),
		'lms_volumes' => __('Volumes'),
		'lms_storageusage' => __('Storage Usage'),
		'lms_smart_devices' => __('Disk health'),
		'lm_ostemplates' => __('Media'),
		'lms_iso' => __('List ISO'),
		'lms_addiso' => __('Add ISO'),
		'lms_editiso' => __('Edit ISO'),
		'lms_ostemplates' => __('OS Templates'),
		'lms_edit_ostemplates' => __('Edit OS Templates'),
		'lms_os' => __('Template Browser'),
		'lms_addtemplate' => __('Add Template'),
		'lms_createtemplate' => __('Create Template'),
		'lms_mediagroups' => __('Media Groups'),
		'lms_addmg' => __('Add Media Group'),
		'lms_editmg' => __('Edit Media Group'),
		'lms_list_distros' => __('List Distros'),
		'lms_add_distro' => __('Add Distro'),
		'lms_edit_distro' => __('Edit Distro'),
		'lms_euiso' => __('Enduser ISOs'),
		'lm_recipes' => __('Recipes'),
		'lms_recipes' => __('List Recipes'),
		'lms_addrecipe' => __('Add Recipe'),
		'lms_editrecipe' => __('Edit Recipe'),
		'lm_passthrough' => __('Passthrough'),
		'lms_passthrough' => __('List passthrough devices'),
		'lms_addpassthrough' => __('Add passthrough device'),
		'lms_editpassthrough' => __('Edit passthrough device'),
		'lm_tasks' => __('Tasks'),
		'lm_kyc' => __('KYC'),
		'lm_list_kyc' => __('List KYC'),
		'lms_edit_kyc' => __('Edit KYC'),
		'lms_kyc_setting' => __('KYC Setting'),
		'lm_config' => __('Configuration'),
		'lms_config' => __('Master Settings'),
		'lms_config_slave' => __('Slave Settings'),
		'lms_webuzo' => __('Webuzo Settings'),
		'lms_emailconfig' => __('Email Settings'),
		'lms_admin_acl' => __('Administrator ACL'),
		'lms_addadmin_acl' => __('Add Administrator ACL'),
		'lms_editadmin_acl' => __('Edit Administrator ACL'),
		'lms_serverinfo' => __('Server Info'),
		'lms_multivirt' => __('Multi Virtualization'),
		'lms_license' => __('License Info'),
		'quick_links' => __('Quick links'),
		'lms_hostname' => __('Change Hostname'),
		'lms_maintenance' => __('Maintenance'),
		'lms_kernelconf' => __('Kernel Config'),
		'lms_defaultvsconf' => __('Default VPS Config'),
		'lms_updates' => __('Updates'),
		'lms_pma' => __('phpMyAdmin'),
		'lms_emailtemp' => __('Email Templates'),
		'lms_edit_emailtemp' => __('Edit Email Template'),
		'lms_twofactauth' => __('Two Factor Authentication'),
		'lm_api' => __('API Credentials'),
		'lms_list_api' => __('List API Pair'),
		'lms_create_api' => __('Create API Pair'),
		'lms_edit_api' => __('Edit API Credential'),
		'lms_show_api_log' => __('Show API logs'),
		'lms_log_rotation' => __('Log Rotation'),
		'lms_performance' => __('Server Monitoring'),
		'lms_server_stats' => __('Server Statistics'),
		'lms_serverloads' => __('VPS Server Loads'),
		'lms_vps_stats' => __('VPS Statistics'),
		'lm_billing' => __('Billing'),
		'lms_billing' => __('Billing Settings'),
		'lms_resource_pricing' => __('Resource Pricing'),
		'lms_invoices' => __('Invoices'),
		'lms_transactions' => __('Transactions'),
		'lms_addinvoice' => __('Create Invoice'),
		'lms_addtransaction' => __('Add Transaction'),
		'lms_tax_rules' => __('Tax Rules'),
		'lm_ssl' => __('SSL Settings'),
		'lms_ssl' => __('SSL Files'),
		'lms_sslcert' => __('SSL Certificate'),
		'lms_createssl' => __('Create Certificate'),
		'lms_installssl' => __('Install SSL'),
		'lm_cpu' => __('CPU'),
		'lms_cpu' => __('CPU Usage'),
		'lms_vscpu' => __('VPS Utilization'),
		'lm_serverloads' => __('VPS Server Loads'),
		'lm_ram' => __('RAM'),
		'lms_ram' => __('Ram Usage'),
		'lms_vsram' => __('VPS Utilization'),
		'lm_disk' => __('Disk'),
		'lm_bandwidth' => __('Bandwidth'),
		'lms_bandwidth' => __('Bandwidth Usage'),
		'lms_vsbandwidth' => __('VPS Utilization'),
		'lm_tools' => __('Tools'),
		'lm_logs' => __('Logs'),
		'lm_filemanager' => __('File Manager'),
		'lm_services' => __('Services'),
		'lms_services' => __('List Services'),
		'lms_res_httpd' => __('Restart Web Server'),
		'lms_res_network' => __('Restart Network'),
		'lms_res_sendmail' => __('Restart Mail Server'),
		'lms_res_mysqld' => __('Restart MySQL'),
		'lms_res_iptables' => __('Restart IPTables'),
		'lm_processes' => __('Processes'),
		'lm_performance' =>'Server Monitoring',
		'lms_disk_health' =>'Raid Health',
		'lm_ssh' => 'SSH',
		'lms_logs' => __('Admin Logs'),
		'lms_userlogs' => __('VPS and Users'),
		'lms_loginlogs' => __('Login Logs'),
		'lms_iplogs' => __('IP Logs'),
		'lms_adminnotes' => __('Archived Notes'),
		'lm_databackup' => __(' Backup'),
		'lms_vpsbackupsettings' => __('VPS Backup Settings'),
		'lms_vpsrestore' => __('Restore '.'VPS Backups'),
		'lms_databackup' => __('Database Backup'),
		'lms_vpsbackup' => __('VPS Backup'),
		'lms_backup_dashboard' => __('Backup Dashboard'),
		'lm_firewall' => __('Firewall'),
		'lms_firewall' => __('Native Firewall'),
		'lms_csf' => __('ConfigServer (CSF)'),
		'lm_import' => __('Import'),
		'lms_import' => __('From OpenVZ 6'),
		'lms_hypervm' => __('From HyperVM'),
		'lms_veportal' => __('From vePortal'),
		'lms_solusvm' => __('From SolusVM'),
		'lms_feathur' => __('From Feathur'),
		'lms_proxmox' => __('From Proxmox'),
		'lms_xenserver' => __('From XenServer'),
		'lms_openvz7' => __('From OpenVZ 7'),
		'lms_kvm' => __('From KVM'),
		'lms_xen' => __('From Xen'),
		'lm_pdns' => __('Power DNS'),
		'lms_dnsrecords' => __('DNS Records'),
		'lms_dnszones' => __('DNS Zones'),
		'lms_pdns' => __('List PDNS Servers'),
		'lms_addpdns' => __('Add DNS Server'),
		'lms_editpdns' => __('Edit PDNS Server'),
		'lms_rdns' => __('Add Reverse DNS Zone'),
		'lms_add_dnsrecord' => __('Add DNS Record'),
		'lms_edit_dnsrecord' => __('Edit DNS Record'),
		'lm_server_stats' => __('Node Performance'),
		'lm_vps_stats' => __('VPS Statistics'),
		'lm_feedback' => __('Feedback'),
		'lms_edit_dns_plan' => __('Edit DNS Plan'),
		'lms_edit_invoice' => __('Edit Invoice'),
		'lms_editiprange' => __('Edit IPv6 Range'),
		'lms_editsg' => __('Edit Server Group / Region'),
		'lms_edittransaction' => __('Edit Transaction'),
		'lms_support_access' => __('Support Access'),
		'lm_cloud_setup' => __('Cloud Setup'),
		'lm_baremetals' => __('Baremetals'),
		'lms_list_baremetals' => __('List Baremetals'),
		'lms_add_baremetal' => __('Add Baremetal'),
		'lms_edit_baremetal' => __('Edit Baremetal'),
		'lms_manage_baremetal' => __('Manage Baremetal'),
		'lms_list_datacenters' => __('List Datacenters'),
		'lms_add_datacenter' => __('Add Datacenter'),
		'lms_edit_datacenter' => __('Edit Datacenter'),
		'lms_list_dcfloors' => __('List Datacenters Floors '),
		'lms_add_dcfloor' => __('Add Datacenter Floor'),
		'lms_edit_dcfloor' => __('Edit Datacenter Floor'),
		'lms_list_dcracks' => __('List Datacenters Racks'),
		'lms_add_dcrack' => __('Add Datacenter Rack'),
		'lms_edit_dcrack' => __('Edit Datacenter Rack'),
		'lm_notice' => __('Notice'),
	];

	foreach($bread_crumb_array as $v){
		// We do not want to show current page
		if($v['act'] == $_REQUEST['act']){
			continue;
		}
		// for by default dashboard
		if($v['act'] == 'dashboard'){
			$cont .= '<li class="breadcrumb-item"><a href="'.$globals['ind'].'">'.$left_menu['lm_'.$v['act']].'</a></li>';	
			continue;
		}

		$v['act'] = str_replace('lm_', '', $v['act']);
		$lang = (!empty($left_menu['lms_'.$v['act']]) ? $left_menu['lms_'.$v['act']] : (!empty($left_menu['lm_'.$v['act']]) ? $left_menu['lm_'.$v['act']] : $left_menu[$v['act']]));

		if($v['act'] == $_REQUEST['act']){
			$cont .= '<li class="breadcrumb-item active">'.$lang.'</li>';
		}else{
			$cont .= '<li class="breadcrumb-item active"><a href="'.$globals['ind'].'act='.$v['act'].'">'.$lang.'</a></li>';
		}
		
	}

	if($v['act'] != $_REQUEST['act']){
		$cont .= '<li class="breadcrumb-item active" aria-current="page">'.$left_menu[$last_element['act']].'</li>';
	}
	$cont .= '
		</ol>
	</nav>';

	return $cont;
}

function show_virt_type($virt){
	$virt_array = array("kvm" => "<span class=\"flatflare font-weight-bold\" style=\"color:var(--primarty_color)\">KVM</span>",
						"kvm lxc" => "<span class=\"flatflare font-weight-bold\" style=\"color:var(--primarty_color)\">KVM + LXC</span>",
						"proxk proxl" => "<span class=\"flatflare font-weight-bold\" style=\"color:#e57000\">Proxmox</span>",
						"openvz" => "<span class=\"flatflare font-weight-bold\" style=\"color:#42b355\">Openvz</span>",
						"vzk vzo"	=> "<span class=\"flatflare font-weight-bold\" style=\"color:#f76e6f\">Virtuozzo</span>",
						"xcp"	=> "<span class=\"flatflare font-weight-bold\" style=\"color:var(--primarty_color)\">XCP</span>",
						"xen"	=> "<span class=\"flatflare font-weight-bold\" style=\"color:var(--primarty_color)\">XEN</span>",
						"lxc"	=> "<span class=\"flatflare font-weight-bold\" style=\"color:var(--primarty_color)\">LXC</span>",
						"msonly" => "<span class=\"flatflare font-weight-bold\" style=\"color:#42b355\">Master Only</span>"
					);
	return $virt_array[$virt];
}



/**
 * Gives plan details along with vpsids or users
 * @author	Naufil Shaikh
 * @package	virtualizor
 * @param   $header = page name , $icon = icon name from fas or path of icon if its image or svg, $docs = documentation link, $search = int (1 or 0), $GLOBALS['breadcrumbs'] = array("vs","addvs")
 * @return  string|false code
 */
if(!function_exists('page_header')){
function page_header($header = '', $icon = '', $docs = '', $search = 0, $sorting = 0, $buttons = array(), $custom_html = ''){
	
	global $l, $breadcrumbs;
   
	if(empty($header)){
		return false;
	}

	$search_doc = '';

	if (!empty($custom_html)) {
		$search_doc .= $custom_html;
	}

	if (!empty($docs)) {
		$search_doc .= '
			<span class="icon-fix d-flex align-items-center justify-content-center" style="float: right !important;">
				<a href="' . $docs . '" target="_blank" tooltip="'.__('Click here to know more').'">
					<i class="fas fa-question text-black"></i>
				</a>
			</span>';
	}
	
	if (!empty($search) || !empty($sorting)){
		
		// search and sorting button icons
		$button_icons = [
			"search" => ["condition" => $search, "function" => "showsearch();", "icon" => "fa-search"],
			"sort" => ["condition" => $sorting, "function" => "show_sorting();", "icon" => "fa-sort"]
		];

		// foreach to fill icon and function
		foreach ($button_icons as $button_icon) {
			if (!empty($button_icon['condition'])) {
				$search_doc .= '
					<span class="icon-fix d-flex align-items-center justify-content-center" style="float: right !important;">
						<a href="javascript:'.$button_icon['function'].'" class="text-light">
							<i class="fas '.$button_icon['icon'].' text-black"></i>
						</a>
					</span>';
			}
		}
	}

	$add_buttons = '';

	if(!empty($buttons)){

		foreach ($buttons as $btn_no => $btn_details){
			$add_buttons .= '<div class="text-center gap-2">
								<a href="index.php?act='.$btn_details['act'].'" class="go_btn">
									<span class="btn_text">'.$btn_details['name'].'</span>
									<i class="fas fa-plus btn_icon"></i>
								</a>
							</div>';
		}
	}

	// RETURN DIV FOR HEADER
	return 
	'<div class="card2 mx-3 mt-3">
		<div class="row">
			<div class="card2-title col-8 col-md-6 col-lg-6 align-items-center">
				<div class="row">
					<div class="col-12">
						<i class="'.$icon.' text-admin"></i> '
						.$header.'
					</div>
					<div class="col-12">
						'.(!empty($breadcrumbs) ? get_breadcrumb($breadcrumbs) : '').'
					</div>
				</div>
			</div>
			<div class="col-4 col-md-6 col-lg-6 d-flex align-items-center justify-content-end">
				<div class="d-flex gap-1">'
					.$add_buttons.
				'</div>
				'.
				(!empty($search_doc) ? '
					<div class="flex_gap ml-2 ml-md-4 ml-lg-4">'
					.$search_doc.
					'</div>
				': '')
				.
				'
			</div>
		</div>
	</div>';
}
}