<?php

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

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

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

$breadcrumbs = array('dashboard', 'lm_users', 'lms_adduser');

echo get_breadcrumb($breadcrumbs);

error_handle($error);

if(!empty($done)){
	show_alert(__('The user has been saved. Return to <a href="index.php?act=users">Users Overview</a>'),"0","users");
}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();
		}
	});';
	
	if(!empty($globals['inhouse_billing'])){
		echo '
		update_userplan();
		update_max_cost();';
	}
	
echo ';
};

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

}

// Update the userplans
function update_userplan(){	
	
	var current_user_type = $_("prior").value;
	
	$("#uplid option").each(function(){
	try{
		if($(this).attr("type") == current_user_type || $(this).attr("type") == -1){
			$(this).show();
		}else{
			$(this).hide();
		}
	}catch(e){}
	});

}

// Load the userplans
function load_userplan(){		

	var url = "'.$globals['index'].'act=edituser_plans&api=json&uplid="+$("#uplid").val();
	
	// Load the details and also update the fields
	$.getJSON(url, function(data, textStatus, jqXHR) {
		
		$plan = data["user_plans"];
		
		$.each($plan, function( index, value ){
			
			if(index == "mgs"){
				
				var i = 0;
				var size = value.length;
				$options = $("#mg option");
				$("#mg option:selected").removeAttr("selected");
				for(i; i < size; i++){
					// filter the options with the specific value and select them
					if(value[i] != ""){
						$options.filter("[value="+value[i]+"]").prop("selected", true);
					}
				}
				
			}else if(index == "allowed_virts"){
				
				$("#allowed_virts option").each(function(){
					$(this).removeAttr("selected");
				});
				
				$("#allowed_virts option").each(function(){
				try{
					
					var _val = $(this).attr("value");
					for(x in value){
						if(value[x] == _val){
							$(this).attr("selected", "selected");
						}
					}
					
				}catch(e){}
				});
				
			}else{
				
				var ele = $("#adduser").find("[name="+ index +"]");
				
				if(empty(ele)){
					return;
				}
				
				if(ele.attr("type") == "checkbox"){
					if(!empty(value)){
						ele[0].checked = true;
					}else{
						ele[0].checked = false;
					}
				}else{
					// Set the value
					ele.val(value);
				}

				update_max_cost();
				
			}
		});

	});
	
}

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', (optGET('create') == 'cloud' ? 2 : 0)).'\'); updatemg(); fillspeedkBps();");
</script>
<style>
input[type="text"]{
	width:90%;
	float:left;
}
input[type="password"]{
	width:90%;
	float:left;
}

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

.input-group-append{
	border: 0px !important;
}
</style>
<div id="form-container" class="card p-2 mx-3">
	<form accept-charset="'.$globals['charset'].'" name="adduser" id="adduser" 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\');"><img class="mr-2" src="'.$theme['svg'].'user.svg">'.__('User').'</a></div>
					<div id="io_2" class="col-4 py-1 io"><a href="javascript:changepriority(\'2\');"><img class="mr-2" src="'.$theme['svg'].'cloud_users.svg">'.__('Cloud').'</a></div>
					<div id="io_1" class="col-4 py-1 io"><a href="javascript:changepriority(\'1\');"><img class="mr-2" src="'.$theme['svg'].'admin.svg">'.__('Admin').'</a></div>
				</div>
			</div>
		</div>
		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-4">
				<label class="control-label">'.__('User Email').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Email Address of the User').'"><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="newemail" id="newemail" size="30" value="'.POSTval('newemail', '').'" />
			</div>
		</div>

		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-4">
				<label class="control-label">'.__('Password').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The Password for the new user').'"><i class="fas text-primary fa-info-circle"></i></a></label>
			</div>
			<div class="col-sm-4">
			<input type="password" class="form-control w-100" name="newpass" id="newpass" size="30" value="'.POSTval('newpass', '').'" />
			</div>
		</div>

		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-4">
				<label class="control-label">'.__('First Name').'</label>
			</div>
			<div class="col-sm-4">
				<input type="text" class="form-control w-100" name="fname" size="30" value="'.POSTval('fname', '').'" />
			</div>
		</div>

		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-4">
				<label class="control-label">'.__('Last Name').'</label>
			</div>
			<div class="col-sm-4">
				<input type="text" class="form-control w-100" name="lname" size="30" value="'.POSTval('lname', '').'" />
			</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  w-100 virt-select select2-hidden-accessible" name="acl_id">
				<option value="0" '.POSTselect('acl_id', 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>
			</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 w-100 virt-select select2-hidden-accessible" name="dnsplan_id">
				<option value="0" '.POSTselect('dnsplan_id', 0).'>'.__('No Plan').'</option>';
				foreach($dnsplans as $k => $v){
					echo '<option value="'.$v['dnsplid'].'" '.POSTselect('dnsplan_id', $v['dnsplid']).'>'.$v['plan_name'].'</option>';
				}
			echo '</select>
			</div>
		</div>';

		if(!empty($globals['inhouse_billing'])){
		echo '
		<div class="row mx-auto w-100 my-3 cloudfield">
			<div class="col-sm-4">
				<label class="control-label">'.__('User Plan').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Assign the user to a predefined plan').'"><i class="fas text-primary fa-info-circle"></i></a></label>
			</div>
			<div class="col-sm-4">
				<select class="custom-select w-100 virt-select select2-hidden-accessible" id="uplid" name="uplid" onchange="load_userplan()">
				<option value="0" type="-1" '.POSTselect('uplid', 0).'>'.__('No Plan').'</option>';
				foreach($user_plans as $k => $v){
					echo '<option value="'.$v['uplid'].'" type="'.$v['type'].'" '.POSTselect('uplid', $v['uplid']).'>'.$v['plan_name'].'</option>';
				}
				echo '
				</select>
			</div>
		</div>';
		}

		echo 
		'<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" size="15" 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" size="15" 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" size="15" 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" size="15" 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" size="15" 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" size="15" 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" size="15" 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>
					<span class="help-block"></span>
				</div>
				<div class="col-sm-4">
					<input type="number" class="form-control rounded" name="cpu" id="cpu" size="15" 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" size="15" 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" size="15" 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" size="15" 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" size="15" 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" size="15" 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" size="15" 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>';

		$network_speed_values = array(128 => 1, 256 => 2, 384 => 3, 512 => 4, 640 => 5, 768 => 6, 896 => 7, 1024 => 8, 1152 => 9, 1280 => 10, 1920 => 15, 2560 => 20, 3849 => 30, 5120 => 40, 6400 => 50, 7680 => 60, 8960 => 70, 10240 => 80, 11520 => 90, 12800 => 100, 128000 => 1000, 1280000 => 10000);

	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">
				<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">
				<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 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>
				<span class="help-block"></span>
			</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>
				<span class="help-block"></span>
			</div>
		</div>';
		
		if(!empty($globals['premium_apps'])){
			echo '
				<div id="premium_apps_cb" class="row mx-auto w-100 my-3 cloudfield">
					<div class="col-4">	
						<label class="control-label">'.__('Enable Premium Applications').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If checked then premium application will be enabled for this Cloud User and its sub user(s)').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					</div>
					<div class="col-4">
						'.get_checkbox('webuzo_prem_apps', '', 'webuzo_prem_apps').'
					</div>
				</div>';
		}
		echo '
		<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>
		<span class="help-block"></span>
		<br/><br/>
		<center>
			<input type="submit" name="adduser" value="'.__('Save user').'" class="go_btn">
		</center>
		<br/><br/>
	</form>';
}

echo 
'</div>';

softfooter();

}

?>