<?php

//////////////////////////////////////////////////////////////
//===========================================================
// addserver_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 addserver_theme(){

global $theme, $globals, $kernel, $user, $l, $ipblocks , $cluster, $error, $saved, $servergroups, $servers, $firewall_plans;

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

$GLOBALS['breadcrumbs'] = array( 'dashboard', 'lm_servers', 'lms_addserver');
					
echo page_header(__('Add Server'), 'icon icon-servers',$globals['docs'].'add-server/', 0, 0, '');

if(!empty($saved)){
	show_alert(__('The slave has been added. Return to <a href="index.php?act=servers">Servers Overview</a>'));
}

error_handle($error);

foreach($servergroups as $k => $v){
	$sg_ha[$k] = $v['sg_ha'];
	
	if(!empty($sg_ha[$k])){
		$sg_ha_on[$k] = $v['sg_ha'];
	}
}

echo '<script language="javascript" type="text/javascript">
	
	function isHa(){
		
		var sgid = parseInt(document.getElementById("sgid").value);
		
		var sg_ha = ['.implode(',', array_keys($sg_ha_on)).'];
		if(sg_ha.indexOf(sgid) != -1){
			showalert("'.__J('This server group has high availability enabled, Pacemaker utilities will be installed on this server.').'");
		}
	}
</script>

<div id="form-container" class="card p-2 mx-3">
	<form accept-charset="'.$globals['charset'].'" name="addippool" method="post" action="" class="form-horizontal">

		<div class="row mx-auto">

			<div class="col-md-6">

				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('Server Name').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The name of the server').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					<input type="text" class="form-control" name="server_name" id="server_name" size="30" value="'.POSTval('server_name','').'"/>
				</div>

				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('Server API Password').'&nbsp;<a class="info" data-placement="right" tooltip="'.htmlizer(__('The API password for controlling the server. See guide on <a href="https://www.virtualizor.com/docs/admin/server-clustering" target="_blank">Adding a server</a>')).'"><i class="fas text-primary fa-info-circle"></i></a></label>
					<input type="text" class="form-control" name="pass" id="pass" size="30" value="'.POSTval('pass', '').'" />
				</div>

				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('Choose Firewall Plan').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Select a Firewall Plan to apply to the server').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					<select name="fwid" id="fwid" class="custom-select virt-select">
						<option value="0">'.__('None').'</option>';
						foreach($firewall_plans as $k => $v){
							echo '<option value="'.$v['fwid'].'">'.$v['fw_plan_name'].'</option>';
						}
					echo'</select>
				</div>

				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('Lock Server').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If Locked, no new VPS will be created on this server').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					<div class="col-4">
					</div>
					<div class="col-4">
						'.get_checkbox('locked').'
					</div>
				</div>

			</div>

			<div class="col-md-6">

				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('IP Address').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The primary address of the server').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					<input type="text" class="form-control" name="ip" id="ip" size="30" value="'.POSTval('ip', '').'" />
				</div>
				
				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('Internal IP').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Set internal IP for cloud server(s). (Optional)').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					<input type="text" class="form-control" name="internal_ip" id="internal_ip" size="30" value="'.POSTval('internal_ip', '').'" />
				</div>
				
				<div class="row w-100 my-3 px-4">
					<label class="control-label">'.__('Server Group').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('The Server group that this server belongs to').'"><i class="fas text-primary fa-info-circle"></i></a></label>
					
					<select name="sgid" id="sgid" class="custom-select virt-select" onchange="isHa();">';
						foreach($servergroups as $k => $v){
							echo '<option value="'.$v['sgid'].'">'.$v['sg_name'].'</option>';
						}
					echo'</select>
				</div>
				
			</div>

		</div>

		<div class="text-center my-4">
			<input type="submit" name="addserver" class="go_btn" value="'.__('Add Server').'" />
		</div>	
	</form>
</div>';
softfooter();

}

?>