<?php

//////////////////////////////////////////////////////////////
//===========================================================
// license_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 license_theme(){

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

softheader($l['<title>']);
					
echo page_header(__('License Info'), 'fas fa-wrench', $globals['docs'].'refresh-lience/');

$breadcrummbs = array('dashboard', 'lm_config', 'lms_license');

echo get_breadcrumb($breadcrummbs);

// Is it offline ?
$hypervisor_status = $cluster->statewise($globals['server']);
if(empty($info)){
	show_alert($globals['hypervisor_status'][$hypervisor_status], 1);
	echo '<div class="e_notice"><b>'.__('Note').' : </b> &nbsp; '.$globals['hypervisor_status'][$hypervisor_status].'</div>';
	
}else{
	$pre_id = generateRandStr(5);
echo '

<div class="row mx-auto w-100 my-3 justify-content-center">
	<div class="col-sm-8 p-0">
		<div class="roundheader">'.__('License Info').'</div>
		<table align="center" class="table no_border table-hover" cellpadding="3" cellspacing="4" border="0" width="100%">
			<tr>
				<td align="left" class="blue_td fhead" width="30%">'.__('Virtualizor License').'</td>
				<td class="val blue_td"><span id="'.$pre_id.'">'.$info['license'].'</span>&nbsp;<a id="a_'.$pre_id.'" href="javascript:copy($(\'#a_'.$pre_id.'\'),\''.$pre_id.'\')"><i class="fas fa-copy"></i></a> &nbsp; <a href="'.$globals['ind'].'act=license&refreshlicense=1" class="btn">'.__('Refresh License').'</a></td>
			</tr>
			'.
				(!empty($info['backuply']) ? '
				<tr>
					<td align="left" class="blue_td fhead" width="30%">'.__('Backuply License').'</td>
					<td class="val blue_td"><span id="'.$pre_id.'_backuply">'.$info['backuply'].'</span>&nbsp;<a id="a_'.$pre_id.'_backuply" href="javascript:copy($(\'#a_'.$pre_id.'_backuply\'),\''.$pre_id.'_backuply\')"><i class="fas fa-copy"></i></a></td>
				</tr>' : '').'
			'.
				(!empty($info['primary_ip']) ? '
				<tr>
					<td align="left" class="blue_td fhead" width="30%">'.__('License IP').'</td>
					<td class="val blue_td"><span id="'.$pre_id.'_primary_ip">'.$info['primary_ip'].'</span>&nbsp;<a id="a_'.$pre_id.'_primary_ip" href="javascript:copy($(\'#a_'.$pre_id.'_primary_ip\'),\''.$pre_id.'_primary_ip\')"><i class="fas fa-copy"></i></a></td>
				</tr>' : '').'
			<tr>
				<td align="left" class="blue_td fhead" width="30%">'.__('Server IP').'</td>
				<td class="val blue_td"><span id="'.$pre_id.'_server_addr">'.$info['SERVER_ADDR'].'</span>&nbsp;<a id="a_'.$pre_id.'_server_addr" href="javascript:copy($(\'#a_'.$pre_id.'_server_addr\'),\''.$pre_id.'_server_addr\')"><i class="fas fa-copy"></i></a></td>
			</tr>
			<tr>
				<td align="left" class="blue_td fhead" width="30%">'.__('License Type').'</td>
				<td class="val blue_td"><span class="val">'.$info['lictype_txt'].'</span> &nbsp;(<a href="https://www.virtualizor.com/pricing" target="_blank">'.__('Pricing').'</a>) &nbsp;(<a href="https://www.softaculous.com/clients?ca=virtbuy" target="_blank">'.__('Client Center').'</a>)</td>
			</tr>
			<tr>
				<td align="left" class="blue_td fhead" width="30%">'.__('Status').'</td>
				<td class="val blue_td">'.$info['active_txt'].'</td>
			</tr>
			<tr>
				<td align="left" class="blue_td fhead" width="30%">'.__('Expires').'</td>
				<td class="val blue_td">'.$info['licexpires_txt'].'</td>
			</tr>
			<tr>
				<td align="left" class="blue_td fhead" width="33%">'.__('Number of VPS').'</td>
				<td class="val blue_td">'.(empty($info['licnumvs']) ? __('Unlimited') : $info['licnumvs']).'</td>
			</tr>
		</table>

		<div class="roundheader toggle_hover cursor-pointer" onclick="toggle_enterlic();"><label id="toggle_indicator" class="min_width">-</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp'.__('Enter License Key').'</div>
		<div id="add_license_key" class="w-100">
			<div class="col-sm-12 p-0">
				<form name="lic_form" action="" method="POST" onsubmit="submit_licenseKey();return false;">
					<div class="form-group">
					<div class=" bgaddv row mx-auto w-100">
						<div align="left" class="col-sm-4 py-2 blue_td" width="20%">
							<label for="input_license_key" class="fhead">'.__('Enter Key').'</label><br />
							<span class="help-block">'.__('If you have another license key, please enter it here').'<br><b>'.__('Note').' : </b> '.__('Enter ONLY Private License (starts with VIRTD) Or Lifetime License (Starts with VIRTE)').' </span>							
						</div>
						<div class="col-sm-6 py-2">
							<input type="text" class="form-control my-2 " id="input_license_key" name="input_license_key">
						</div>	
						<div class="col-sm-1 py-2 text-center">
							<input type="submit" class="go_btn my-1" value="'.__('Submit').'" />
						</div>	
					</div>
					</div>
				</form>
			</div>
		</div>
		<div class="col-sm-12 text-center" id="process_img" style="display:none;">
			<div class="loader-lg"></div>
		</div>
	</div>
</div>
<br />
<br />';

}
echo '</div>';
echo '
<script>

	function toggle_enterlic(){

		if ($("#add_license_key").is(":hidden")){
			$("#add_license_key").slideDown("slow");
			$("#toggle_indicator").text(" - ");
		}else{
			$("#add_license_key").slideUp("slow");
			$("#toggle_indicator").text(" + ");
		}
	}
	
	function submit_licenseKey(){
		
		var lickey = $.trim($("#input_license_key").val());
		
		if(lickey.length != 29){
			showalert("'.__J('Key length is not valid, enter correct key and try again').'" ,"1");
			return;
		}
		
		if(!(/^VIRT(D|E)/.exec(lickey))){
			showalert("'.__J('Invalid License key').'<br>'.__J('Enter ONLY Private License (starts with VIRTD) Or Lifetime License (Starts with VIRTE)').'", 1);
			return;
		}
		
		$("#process_img").css("display","");
		
		$.ajax({
			url: "'.$globals['ind'].'act=license&api=json",
			data: "lickey="+lickey+"&licform=1",
			dataType: "json",
			type: "post",
			success: function(data){
				
				$("#process_img").css("display","none");
				if("error" in data){
					showalert(data["error"] ,"1");
					return false;
				}
				if("done" in data){
					showalert(data["done"]);
					$("#alert-modal").on("hidden.bs.modal", function (e) {
						location.reload(true);
					});
				}
			},
			error: function(data){
				$("#process_img").css("display","none");
				showalert("'.__J('Error fetching License').'" ,"1");
			}
		})
	}
	
</script>
';
softfooter();

}

?>