<?php

//////////////////////////////////////////////////////////////
//===========================================================
// edituser_plans_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 edituser_plans_theme(){

global $theme, $l, $globals, $kernel, $user_plans, $l, $error, $done, $mgs, $servergroups, $dnsplans, $acls;

softheader($l['<title>']);

$GLOBALS['breadcrumbs'] = array( 'dashboard', 'lm_user_plans', 'lms_edituser_plans');
					
echo page_header(__('Edit User Plans'), 'fas fa-users', '', 0, 0, '');

error_handle($error);

if(!empty($done)){
	show_alert(__('The User Plan has been saved. Return to <a href="index.php?act=user_plans">User Plans Overview</a>'), "", "user_plans");
}

echo '<script language="javascript" type="text/javascript">
var chk_flag = 0;	
function changepriority(priority){

	if (priority != ""){
		$_("prior").value = priority;
	}

	if(priority == 2){
		if(chk_flag){
			chk_flag = 0;
			$("#inhouse_billing").trigger("click");
		}
	}
	
	$(".cloudfield").each(function(){
		if(priority == 2){
			$(this).show();
		}else{
			$(this).hide();
		}
	});

	update_max_cost();
};

// Update the media groups when selected
function updatemg(){	

	$("#mg option").each(function(){
	try{
		if(!$_($(this).attr("type")).checked){
			$(this).attr("disabled","disabled");
		}else{
			$(this).attr("disabled", false);
		}
	}catch(e){}
	});

}

function update_max_cost(){
	
	try{
	
	// Show max cost field
	if($_("inhouse_billing").checked){
		$("#max_cost_row").show();
		//$("#resources").hide();
	}else{
		$("#max_cost_row").hide();
		//$("#resources").show();
	}
	
	}catch(e){}
	
}

function netspeed(r){
	$_("network_speed").value = r;
}

function upspeed(r){
	$_("upload_speed").value = r;
}

var lang_no_limit = "'.__J('No Restriction').'";
addonload("changepriority(\''.POSTval('priority', $user_plans['type']).'\'); updatemg(); fillspeedkBps();");
</script>
<style>
input[type="text"]{
	width:90%;
	float:left;
}
input[type="password"]{
	width:90%;
	float:left;
}

.sideLabel label{
	padding:8px;
	float:left;
}

.input-group-append{
	border: 0px !important;
}
</style>

<div id="form-container" class="card p-2 mx-3">
<form accept-charset="'.$globals['charset'].'" name="edituser_plans" method="post" action="" class="form-horizontal">
	<input type="hidden" id="prior" name="priority" value="2">
	<div class="row mx-auto w-100 mt-3">
		<div class="col-sm-6 mb-2" id="plan_name_row">
			<label class="control-label">'.__('Plan Name').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('A unique name for your reference').'"><i class="fas text-primary fa-info-circle"></i></a></label>
			<input type="text" class="form-control w-100" name="plan_name" id="plan_name" size="15" value="'.POSTval('plan_name', $user_plans['plan_name']).'" />
		</div>

		<div class="col-sm-6 mb-2">
			<label class="control-label">'.__('DNS Plan').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The DNS plan for the user').'"><i class="fas text-primary fa-info-circle"></i></a></label>
			<select class="custom-select w-100" name="dnsplan_id">
				<option value="0">'.__('No Plan').'</option>';
				foreach($dnsplans as $k => $v){
					echo '<option value="'.$v['dnsplid'].'" '.ex_POSTselect('dnsplan_id', $v['dnsplid'], $user_plans['dnsplid']).'>'.$v['plan_name'].'</option>';
				}
				echo 
			'</select>
		</div>
		
		<div class="col-sm-6 mb-2 cloudfield" id="num_vs_row">
			<label class="control-label">'.__('Number of VMs').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The maximum number of Virtual Machines this user can create. Zero (<b>0</b>) for unlimited.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
			<input type="number" class="form-control" name="num_vs" id="num_vs" size="15" value="'.POSTval('num_vs', $user_plans['num_vs']).'" />
		</div>';

		if(!empty($globals['inhouse_billing'])){
			echo '
			<div class="col-sm-6 mb-2 cloudfield" id="inhouse_billing_row">
				<div class="row d-flex h-100 align-items-center">
					<div class="col-12 my-4 my-sm-0 my-md-0 my-lg-0 col-md-6 d-flex gap-1">
						<label class="control-label">'.__('Enable Virtualizor Billing').'&nbsp;<a class="info" data-placement="right" tooltip="'.htmlizer(__('If enabled, Virtualizor will calculate resource usage and create invoices for the VMs. Otherwise your external billing system should manage the billing.<br /> For more information read <a href="https://www.virtualizor.com/docs/billing/virtualizor-cloud-billing-system" target="_blank">Virtualizor Billing</a>')).'"><i class="fas text-primary fa-info-circle"></i></a></label><br>
						<a href="https://www.virtualizor.com/docs/billing/virtualizor-cloud-billing-system" target="_blank">'.__('Refer This').'</a>
						'.get_switch('inhouse_billing', '', 'inhouse_billing', array('chk_it' => 1, 'val' => $user_plans['inhouse_billing']), 1, '', array('onchange="update_max_cost()"')).'
					</div>
					<div class="col-sm-12 col-md-6 col-lg-6 cloudfield" id="max_cost_row">
						<label class="control-label">'.__('Max Cost per VPS / month').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The Maximum cost of a VPS per month.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
						<input type="number" class="form-control" name="max_cost" id="max_cost" size="15" value="'.POSTval('max_cost', $user_plans['max_cost']).'" />
					</div>
				</div>
			</div>';
		}
		echo
	'</div>';

	echo'
	<div class="col-sm-12 my-4 cloudfield">
		<div class="row">
			<div class="col-lg-2 col-md-2 d-none d-md-block d-lg-block">
				<div class="nav flex-column nav-pills" id="resource-tab" role="tablist" aria-orientation="vertical">
					<a class="nav-link active" data-toggle="pill" href="#v-pills-general" role="tab" >'.__('General').'</a>
					<a class="nav-link" data-toggle="pill" href="#v-pills-cpu" role="tab" >'.__('CPU').'</a>
					<a class="nav-link" data-toggle="pill" href="#v-pills-ram" role="tab" >'.__('Ram').'</a>
					<a class="nav-link" data-toggle="pill" href="#v-pills-storage" role="tab" >'.__('Storage').'</a>
					<a class="nav-link" data-toggle="pill" href="#v-pills-network" role="tab" >'.__('Network').'</a>
				</div>
			</div>
			<div class="col-12 d-block d-md-none mb-3">
				<select class="form-control d-md-none" onchange="tab_to_select(this)">
					<option value="v-pills-general">'.__('General').'</option>
					<option value="v-pills-cpu">'.__('CPU').'</option>
					<option value="v-pills-ram">'.__('RAM').'</option>
					<option value="v-pills-storage">'.__('Storage').'</option>
					<option value="v-pills-network">'.__('Network').'</option>
				</select>
			</div>
			<div class="col-12 col-sm-12 col-md-10 col-lg-10">
				<div class="tab-content" id="resource-tabContent">
					<div class="tab-pane fade p-2 show active" id="v-pills-general" role="tabpanel" aria-labelledby="v-pills-general-tab">
						<div class="row mx-auto w-100 ">
							<div class="col-sm-6 mb-2 cloudfield" id="num_users_row">
								<label class="control-label">'.__('Number of Users').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The maximum number of sub-users this user can create. Zero (<b>0</b>) for unlimited.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<input type="number" class="form-control" name="num_users" id="num_users" size="15" value="'.POSTval('num_users', $user_plans['num_users']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="service_period">
								<label class="control-label">'.__('Billing cycle').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The billing cycle start date for bandwidth calculation.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<input type="number" class="form-control" min="0" max="31" id="txt_service_period" name="service_period" value="'.POSTval('service_period', $user_plans['service_period']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="allowed_virts_row">
								<label class="control-label">'.__('Allowed Virtualization').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The Virtualization type to allow this user').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<select class="form-control" id="allowed_virts" multiple="multiple" name="allowed_virts[]" onchange="updatemg()">';
									foreach($globals['virts'] as $k => $v){
										echo '<option value="'.$v.'" '.(@in_array($k, (empty($_POST['allowed_virts']) ? $user_plans['allowed_virts'] : @$_POST['allowed_virts'])) ? 'selected="selected"' : '').'>'.$globals['virt_names'][$k].'</option>';
									}
									echo '
								</select>
								<span class="help-block"></span>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="sg_row">
								<label class="control-label">'.__('Server Groups Allowed').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If no group is selected than the user will not be able to create any VPS').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<select class="form-control" name="sgs[]" multiple="multiple">';
									foreach($servergroups as $sk => $sv){
										echo '<option value="'.$sk.'" '.(in_array($sk, (empty($_POST['edituser_plans']) ? $user_plans['sg'] : @$_POST['sgs'])) ? 'selected="selected"' : '').'>'.$sv['sg_name'].'</option>';
									}
									echo'
								</select>
								<span class="help-block"></span>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="mg_row">
								<label class="control-label">'.__('Media Groups').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If no media group is selected, then ALL templates and ISO will become available to this user').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<select class="form-control" name="mgs[]" id="mg" multiple="multiple">';
									foreach($mgs as $mk => $mv){
										echo '<option value="'.$mk.'" type="'.$mv['mg_type'].'" '.(in_array($mk, (empty($_POST['edituser_plans']) ? $user_plans['mg'] : @$_POST['mgs'])) ? 'selected="selected"' : '').'>'.$mv['mg_name'].'</option>';
									}
									echo 
								'</select>
							</div>
						</div>
					</div>
					<div class="tab-pane fade p-2" id="v-pills-cpu" role="tabpanel" aria-labelledby="v-pills-cpu-tab">
						<div class="row mx-auto w-100 ">
							<div class="col-sm-6 mb-2 cloudfield" id="cpu_row">
								<label class="control-label">'.__('Default CPU Weight').'</label>
								<span class="help-block"></span>
								<input type="number" class="form-control rounded" name="cpu" id="cpu" size="15" value="'.POSTval('cpu', $user_plans['cpu']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="cores_row">
								<label class="control-label">'.__('Max Cores / VPS').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The user cannot create a VPS above this limit').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<input type="number" class="form-control" name="cores" id="cores" size="15" value="'.POSTval('cores', $user_plans['cores']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="cpu_percent_row">
								<label class="control-label">'.__('Default CPU % / Core').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('All VPS created by the user would have this CPU %. This is per core base. E.g. If user creates VPS with 2 cores and percentage is 40 total 80% will be assigned.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<input type="number" class="form-control" name="cpu_percent" id="cpu_percent" size="15" value="'.POSTval('cpu_percent', $user_plans['cpu_percent']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="num_cores_row">
								<label class="control-label">'.__('Total Cores').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The total number of cores allowed. Zero (<b>0</b>) means unlimited cores').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<input type="number" class="form-control" name="num_cores" id="num_cores" size="15" value="'.POSTval('num_cores', $user_plans['num_cores']).'" />
							</div>
						</div>
					</div>
					<div class="tab-pane fade p-2" id="v-pills-ram" role="tabpanel" aria-labelledby="v-pills-ram-tab">
						<div class="row mx-auto w-100 ">
							<div class="col-sm-6 mb-2 cloudfield" id="ram_row">
								<label class="control-label">'.__('Max Ram').'</label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control rounded" name="ram" id="ram" size="15" value="'.POSTval('ram', $user_plans['ram']).'" />
										<div class="input-group-append">
											<span class="input-group-text">MB</span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="burst_row">
								<label class="control-label">'.__('Max Burst / Swap').'</label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control rounded" name="burst" id="burst" size="15" value="'.POSTval('burst', $user_plans['burst']).'" />
										<div class="input-group-append">
											<span class="input-group-text">MB</span>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="tab-pane fade p-2" id="v-pills-storage" role="tabpanel" aria-labelledby="v-pills-storage-tab">
						<div class="row mx-auto w-100 ">
							<div class="col-sm-6 mb-2 cloudfield" id="space_row">
								<label class="control-label">'.__('Max Disk Space').'</label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control rounded" name="space" id="space" size="15" value="'.POSTval('space', $user_plans['space']).'" />
										<div class="input-group-append">
											<span class="input-group-text">GB</span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="space_per_vm_row">
								<label class="control-label">'.__('Max disk space / VPS').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The user cannot create a VPS above this limit').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<input type="number" class="form-control" name="space_per_vm" id="space_per_vm" size="15" value="'.POSTval('space_per_vm', $user_plans['space_per_vm']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="total_iops_sec_row">
								<label class="control-label">'.__('Total I/O\'s per sec').'</label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control" name="total_iops_sec" id="total_iops_sec" size="15" value="'.POSTval('total_iops_sec', $user_plans['total_iops_sec']).'" />
										<div class="input-group-append">
											<span class="input-group-text">M/s</span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="read_bytes_sec_row">
								<label class="control-label">'.__('Read Mega Byte\'s/s').'</label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control" name="read_bytes_sec" id="read_bytes_sec" size="15" value="'.POSTval('read_bytes_sec', $user_plans['read_bytes_sec']).'" />
										<div class="input-group-append">
											<span class="input-group-text">M/s</span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="write_bytes_sec_row">
								<label class="control-label">'.__('Write Mega Byte\'s/s').'</label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control" name="write_bytes_sec" id="write_bytes_sec" size="15" value="'.POSTval('write_bytes_sec', $user_plans['write_bytes_sec']).'" />
										<div class="input-group-append">
											<span class="input-group-text">M/s</span>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="tab-pane fade p-2" id="v-pills-network" role="tabpanel" aria-labelledby="v-pills-network-tab">
						<div class="row mx-auto w-100 ">
							<div class="col-sm-6 mb-2 cloudfield" id="num_ipv4_row">
								<label class="control-label">'.__('Max IPv4').'</label>
								<input type="number" class="form-control" name="num_ipv4" id="num_ipv4" size="15" value="'.POSTval('num_ipv4', $user_plans['num_ipv4']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="num_ipint_row">
								<label class="control-label">'.__('Max Internal Ips').'</label>
								<input type="number" class="form-control" name="num_ip_int" id="num_ip_int" size="15" value="'.POSTval('num_ip_int', $user_plans['num_ip_int']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="num_ipv6_subnet_row">
								<label class="control-label">'.__('Max IPv6 Subnets').'</label>
								<input type="number" class="form-control" name="num_ipv6_subnet" id="num_ipv6_subnet" size="15" value="'.POSTval('num_ipv6_subnet', $user_plans['num_ipv6_subnet']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="num_ipv6_row">
								<label class="control-label">'.__('Max IPv6').'</label>
								<input type="number" class="form-control" name="num_ipv6" id="num_ipv6" size="15" value="'.POSTval('num_ipv6', $user_plans['num_ipv6']).'" />
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="network_speed_row">
								<label class="control-label">'.__('Network Speed').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Enter 0 or leave empty for no restriction. <br />Use the select box for easy options').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<div class="input-group " >
									<input type="number" class="form-control rounded" name="network_speed" id="network_speed" size="8" value="'.POSTval('network_speed', $user_plans['network_speed']).'" />
									<div class="input-group-append">
										<span class="input-group-text mr-1">'.__('KB/s').'</span>
										<select class="virt-select speedkBps" name="network_speed2" id="network_speed2" onchange="netspeed(this.value)"></select>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="upload_speed_row">
								<label class="control-label">'.__('Upload Speed').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Enter 0 or leave empty for no restriction. <br /> Enter -1 for upload speed to be same as <b>Network Speed.</b> <br />Use the select box for easy options').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<div class="input-group">
									<input type="number" class="form-control rounded" name="upload_speed" id="upload_speed" size="8" value="'.POSTval('upload_speed', $user_plans['upload_speed']).'"/>	  
									<div class="input-group-append">
										<span class="input-group-text mr-1">'.__('KB/s').'</span>
										<select class="virt-select speedkBps" name="upload_speed2" id="upload_speed2" onchange="upspeed(this.value)"></select>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="bandwidth_row">
								<label class="control-label">'.__('Max Bandwidth').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Zero (<b>0</b>) means unlimited bandwidth').'"><i class="fas text-primary fa-info-circle"></i></a></label>
								<div class="sideLabel">
									<div class="input-group ">
										<input type="number" class="form-control rounded" name="bandwidth" id="bandwidth" size="15" value="'.POSTval('bandwidth', $user_plans['bandwidth']).'" />
										<div class="input-group-append">
											<span class="input-group-text">GB</span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-6 mb-2 cloudfield" id="band_suspend">
								<div class="row d-flex h-100 align-items-center">
									<div class="col-6">
										<label class="control-label">'.__('Bandwidth Suspend').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If checked then all the cloud user\'s VPS(s) will be suspended if the specified bandwidth limit is exceeded').'"><i class="fas text-primary fa-info-circle"></i></a></label>
									</div>
									<div class="col-6">
										'.get_switch('band_suspend', '', 'ck_band_sus', array('chk_it' => 1, 'val' => $user_plans['band_suspend'])).'
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	';

echo '
	<br /><br />
	<center>
	<input type="submit" name="edituser_plans" value="'.__('Save Plan').'" class="go_btn mt-5"></center>
	<br/><br/>
	</form>
</div>
';
softfooter();

}

?>