<?php

//////////////////////////////////////////////////////////////
//===========================================================
// adduser_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 adduser_plans_theme(){

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

softheader($l['<title>']);
					
echo page_header(__('Add User Plan'), 'fas fa-users', $globals['docs'].'add-user/', 0, 0, '');

$breadcrumbs = array( 'dashboard', 'lm_user_plans', 'lms_adduser_plans');

echo get_breadcrumb($breadcrumbs);

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");
}else{

echo '<script language="javascript" type="text/javascript">
var chk_flag = 0;	
function changepriority(priority){
	$_("io_0").className = "col-4 py-1 io";
	$_("io_1").className = "col-4 py-1 io";
	$_("io_2").className = "col-4 py-1 io";
	
	if (priority != ""){
		$_("io_"+priority).className = "col-4 py-1 io_over";
		$_("prior").value = priority;
	}
	
	if(priority == 1){
		$("#tr_acl").show();
	}else{
		$("#tr_acl").hide();
	}
	
	if(priority != 2){
		if($("#inhouse_billing").prop("checked")){
			chk_flag = 1;
			$("#inhouse_billing").trigger("click");
		}
	}

	if(priority == 2){
		if(chk_flag){
			chk_flag = 0;
			$("#inhouse_billing").trigger("click");
		}
	}

	$(".cloudfield").each(function(){
		if(priority == 2){
			$(this).css("display","flex");
		}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){}
	
}
var lang_no_limit = "'.__J('No Restriction').'";
addonload("changepriority(\''.POSTval('priority', 2).'\'); 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 class="card p-2 mx-3">
<div id="form-container">
<form accept-charset="'.$globals['charset'].'" name="adduser_plans" method="post" action="" class="form-horizontal">

<div class="row mx-auto w-100 my-3 border-bottom">
	<div class="col-sm-4">
		<label class="control-label">'.__('User Type').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The type of user').'"><i class="fas text-primary fa-info-circle"></i></a></label>
	</div>
	<div class="col-sm-6">
		<input type="hidden" id="prior" name="priority" value="">
		<div class="row mx-auto w-100">
			<div id="io_0" class="col-4 py-1 io"><a href="javascript:changepriority(\'0\');"><i class="fas fa-user text-dark"></i> '.__('User').'</a></div>
			<div id="io_2" class="col-4 py-1 io"><a href="javascript:changepriority(\'2\');"><i class="fas fa-user-shield text-dark"></i> '.__('Cloud').'</a></div>
			<div id="io_1" class="col-4 py-1 io"><a href="javascript:changepriority(\'1\');"><i class="fas fa-user-tie text-dark"></i> '.__('Admin').'</a></div>
		</div>
	</div>
</div>
<div class="row mx-auto w-100 my-3" id="plan_name_row">
	<div class="col-sm-4">
		<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>
	</div>
	<div class="col-sm-4 ">
		<input type="text" class="form-control w-100" name="plan_name" id="plan_name"  value="'.POSTval('plan_name', '').'" />
		
	</div>
</div>

<div class="row mx-auto w-100 my-3" id="tr_acl">
	<div class="col-sm-4">
		<label class="control-label">'.__('Access Control').'</label>
	</div>
	<div class="col-sm-4">
		<select class="custom-select virt-select w-100" name="acl_id" >
		<option value="0">'.__('Not used').'</option>';
		foreach($acls as $k => $v){
			echo '<option value="'.$v['aclid'].'" '.POSTselect('acl_id', $v['aclid']).'>'.$v['acl_name'].'</option>';
		}
echo '</select>
<span class="help-block"></span>
	</div>
</div>

<div class="row mx-auto w-100 my-3">
	<div class="col-sm-4">	
		<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>
	</div>
	<div class="col-sm-4">
		<select class="custom-select virt-select w-100" name="dnsplan_id">
		<option value="0">'.__('No Plan').'</option>';
		foreach($dnsplans as $k => $v){
			echo '<option value="'.$v['dnsplid'].'">'.$v['plan_name'].'</option>';
		}
echo '</select>
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="num_vs_row">
	<div class="col-sm-4">
		<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>
	</div>
	<div class="col-sm-4">
		<input type="number" class="form-control " name="num_vs" id="num_vs"  value="'.POSTval('num_vs', '').'" />
	</div>
</div>
';

if(!empty($globals['inhouse_billing'])){
	
echo '
<div class="row mx-auto w-100 my-3 cloudfield" id="inhouse_billing_row">
	<div class=" col-4">
		<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>
	</div>
	<div class=" col-4">
		'.get_checkbox('inhouse_billing', '', 'inhouse_billing', array('chk_it' => 1), 1, '', array('onchange="update_max_cost()"')).'
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="max_cost_row">
	<div class="col-sm-4">
		<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>
	</div>
	<div class="col-sm-4">
		<input type="number" class="form-control " name="max_cost" id="max_cost"  value="'.POSTval('max_cost', '').'" />
	</div>
</div>';

}

echo '
<div id="resources">
	<div class="row mx-auto w-100 my-3 cloudfield" id="num_users_row">
		<div class="col-sm-4">
			<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>
		</div>
		<div class="col-sm-4">
			<input type="number" class="form-control " name="num_users" id="num_users"  value="'.POSTval('num_users', '').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="space_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max Disk Space').'</label>
		</div>
		<div class="col-sm-4 sideLabel">
			<div class="input-group ">
				<input type="number" class="form-control rounded" name="space" id="space" value="'.POSTval('space', '').'" /> 
			<div class="input-group-append">
				<span class="input-group-text">GB</span>
			</div>
			</div>
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="ram_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max Ram').'</label>
		</div>
		<div class="col-sm-4 sideLabel">
			<div class="input-group ">
				<input type="number" class="form-control rounded" name="ram" id="ram"  value="'.POSTval('ram', '').'" />
			<div class="input-group-append">
				<span class="input-group-text">MB</span>
			</div>
			</div>
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="burst_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max Burst / Swap').'</label>
		</div>
		<div class="col-sm-4 sideLabel">
			<div class="input-group ">
				<input type="number" class="form-control rounded" name="burst" id="burst"  value="'.POSTval('burst', '').'" />  
			<div class="input-group-append">
				<span class="input-group-text">MB</span>
			</div>
			</div>
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="bandwidth_row">
		<div class="col-sm-4">
			<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>
		<div class="col-sm-4 sideLabel">
			<div class="input-group ">
				<input type="number" class="form-control rounded" name="bandwidth" id="bandwidth"  value="'.POSTval('bandwidth', '').'" />  
			<div class="input-group-append">
				<span class="input-group-text">GB</span>
			</div>
			</div>
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="cpu_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Default CPU Weight').'</label>
		</div>
		<div class="col-sm-4">
			<input type="number" class="form-control " name="cpu" id="cpu"  value="'.POSTval('cpu', '').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="cores_row">
		<div class="col-sm-4">
			<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>
		</div>
		<div class="col-sm-4">
			<input type="number" class="form-control " name="cores" id="cores"  value="'.POSTval('cores', '4').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="space_per_vm_row">
		<div class="col-sm-4">
			<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>
		</div>
		<div class="col-sm-4">
			<input type="number" class="form-control" name="space_per_vm" id="space_per_vm" size="15" value="'.POSTval('space_per_vm').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="cpu_percent_row">
		<div class="col-sm-4">
			<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>
		</div>
		<div class="col-sm-4">
			<input type="number" class="form-control " name="cpu_percent" id="cpu_percent"  value="'.POSTval('cpu_percent', '').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="num_cores_row">
		<div class="col-sm-4">
			<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>
		</div>
		<div class="col-sm-4">
		<input type="number" class="form-control " name="num_cores" id="num_cores"  value="'.POSTval('num_cores', '0').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="num_ipv4_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max IPv4').'</label>
		</div>
		<div class="col-sm-4">
		<input type="number" class="form-control " name="num_ipv4" id="num_ipv4"  value="'.POSTval('num_ipv4', '').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="num_ipint_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max Internal Ips').'</label>
		</div>
		<div class="col-sm-4">
		<input type="number" class="form-control" name="num_ip_int" id="num_ip_int" size="15" value="'.POSTval('num_ip_int', '').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="num_ipv6_subnet_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max IPv6 Subnets').'</label>
		</div>
		<div class="col-sm-4">
		<input type="number" class="form-control " name="num_ipv6_subnet" id="num_ipv6_subnet"  value="'.POSTval('num_ipv6_subnet', '').'" />
		</div>
	</div>

	<div class="row mx-auto w-100 my-3 cloudfield" id="num_ipv6_row">
		<div class="col-sm-4">
			<label class="control-label">'.__('Max IPv6').'</label>
		</div>
		<div class="col-sm-4">
		<input type="number" class="form-control " name="num_ipv6" id="num_ipv6"  value="'.POSTval('num_ipv6', '').'" />
		</div>
	</div>
</div>

<script type="text/javascript">
function netspeed(r){
	$_("network_speed").value = r;
}
function upspeed(r){
	$_("upload_speed").value = r;
}
</script>';

echo '
<div class="row mx-auto w-100 my-3 cloudfield" id="network_speed_row">
	<div class="col-sm-4">
		<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>
	<div class="col-sm-4 sideLabel">
		<div class="input-group">
			<input type="number" class="form-control rounded" name="network_speed" id="network_speed" size="8" value="'.POSTval('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>

<div class="row mx-auto w-100 my-3 cloudfield" id="upload_speed_row">
	<div class="col-sm-4">
		<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>
	<div class="col-sm-4 sideLabel">
		<div class="input-group" >
			<input type="number" class="form-control rounded" name="upload_speed" id="upload_speed" size="8" value="'.POSTval('upload_speed', '-1').'" />
			<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>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="total_iops_sec_row">
	<div class="col-sm-4">
		<label class="control-label">'.__('Total I/O\'s per sec').'</label>
	</div>

	<div class="col-sm-4 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', '').'" />
			<div class="input-group-append">
				<span class="input-group-text">M/s</span>
			</div>
		</div>
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="read_bytes_sec_row">
	<div class="col-sm-4">
		<label class="control-label">'.__('Read Mega Byte\'s/s').'</label>
	</div>
	<div class="col-sm-4 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', '').'" />
			<div class="input-group-append">
				<span class="input-group-text">M/s</span>
			</div>
		</div>
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="write_bytes_sec_row">
	<div class="col-sm-4">
		<label class="control-label">'.__('Write Mega Byte\'s/s').'</label>
	</div>
	<div class="col-sm-4 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', '').'" />
			<div class="input-group-append">
				<span class="input-group-text">M/s</span>
			</div>
		</div>
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="band_suspend">
	<div class="col-4">
		<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-4">
		'.get_checkbox('band_suspend', '', 'ck_band_sus').'
	</div>
</div>
<div class="row mx-auto w-100 my-3 cloudfield" id="service_period">
	<div class="col-sm-4">
		<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>
	</div>
	<div class="col-sm-4">
		<input type="number" class="form-control w-25" min="0" max="31" id="txt_service_period" name="service_period" value="'.POSTval('service_period', '0').'" />
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="allowed_virts_row">
	<div class="col-xs-10 col-sm-4">
		<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>
	</div>
	<div class="col-xs-2 col-sm-4">
		<select class="form-control w-100" id="allowed_virts" multiple="multiple" name="allowed_virts[]" onchange="updatemg()">';
		$allowedvirts = (isset($_POST['allowed_virts']) ? $_POST['allowed_virts'] : []);
		foreach($globals['virts'] as $k => $v){
			echo '<option value="'.$v.'" '.(@in_array($k, $allowedvirts) ? 'selected="selected"' : '').'>'.$globals['virt_names'][$k].'</option>';
		}
		echo '
		</select>
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="sg_row">
	<div class="col-sm-4">
		<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>
	</div>
	<div class="col-sm-4">
		<select class="form-control w-100" name="sgs[]" multiple="multiple">';
			$sgs = (isset($_POST['sgs']) ? $_POST['sgs'] : []);
			foreach($servergroups as $sk => $sv){
				echo '<option value="'.$sk.'" '.(in_array($sk, $sgs) ? 'selected="selected"' : '').'>'.$sv['sg_name'].'</option>';
			}
			
		echo '</select>
	</div>
</div>

<div class="row mx-auto w-100 my-3 cloudfield" id="mg_row">
	<div class="col-sm-4">
		<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>
	</div>
	<div class="col-sm-4">
		<select class="form-control w-100" name="mgs[]" id="mg" multiple="multiple">';
			
			foreach($mgs as $mk => $mv){
				echo '<option value="'.$mk.'" type="'.$mv['mg_type'].'" '.(in_array($mk, @$_POST['mgs']) ? 'selected="selected"' : '').'>'.$mv['mg_name'].'</option>';
			}
			
		echo '</select>
	</div>
</div>
<style>

</style>
<br /><br />
<div class="text-center"><input type="submit" name="adduser_plans" value="'.__('Save Plan').'" class="go_btn"></div>
<br/><br/>
</form>
';

}

echo '</div></div></div>';
softfooter();

}

?>