<?php

//////////////////////////////////////////////////////////////
//===========================================================
// editips_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 editips_theme(){
	

global $theme, $globals, $l, $cluster, $servers, $user, $error, $ippools, $ip, $ipid, $done, $servergroups;

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

if(!empty($done)){
	show_alert(__('The IP(s) have been saved. Return to <a href="index.php?act=ips">IP Overview</a>'),"0", "ips");
}

$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_ips', 'lms_editip');

echo page_header(__('Edit IP'), 'fas fa-users', '', 0, 0, '');

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

		<div class="row mx-auto w-100 my-2">
			<div class="col-sm-6">
				<label class="control-label">'.__('Enter IP').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If the IP Address is assigned, it cannot be edited.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<input type="text" class="form-control" name="ip"  size="30" '.(empty($ip['vpsid']) ? ' value="'.POSTval('ip' , $ip['ip']).'"' : 'value="'.$ip['ip'].'" disabled="disabled" ').'/>
			</div>
			<div class="col-sm-6">
				<label class="control-label">'.__('Enter MAC').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If left blank, the MAC address is auto-generated.').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<input type="text" class="form-control" name="mac_addr" value="'.POSTval('mac_addr', $ip['mac_addr']).'" size="30" />
			</div>
			<div class="col-sm-6 mt-2">
				<div class="row mx-auto">
					<div class="col-sm-12 d-flex justify-content-between p-0">
						<label class="control-label">'.__('Lock').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('Lock this IP').'"><i class="fas text-primary fa-info-circle"></i></a></label>
						'.get_switch('locked', '', '', array('chk_it' => 1, 'val' => $ip['locked'])).'
					</div>
				</div>
				<div class="row mx-auto">
					<div class="col-sm-12 p-0">
						<label class="control-label">'.__('IP Pool').': &nbsp;</label>
						'.(empty($ippools[$ip['ippid']]['ippool_name']) ? __('None') : $ippools[$ip['ippid']]['ippool_name']).'
					</div>
					<div class="col-sm-12 p-0"  id="ip_serid">
						<label class="control-label">'.__('Server').': &nbsp;</label>';
						$ip_serids = array_unique((array) $ip['ip_serid']);

						if (!empty($ip_serids)) {

							// All Servers
							if (in_array(-1, $ip_serids)) {
								echo __('All Servers') . '<br/>';
							}

							// Group Mode
							if (in_array(-2, $ip_serids) && !empty($ip['sgid'])) {

								foreach (array_unique($ip['sgid']) as $sgid) {

									if (!isset($servergroups[$sgid])) {
										continue;
									}

									$group = $servergroups[$sgid];

									echo '[Group] ' . $group['sg_name'] . '<br/>';

									echo'<div class="ml-5">';
									foreach ($group['servers'] as $servername) {
										echo '- ' . $servername . ', &nbsp;';
									}
									echo'</div>';
								}
							}

							// Direct Servers
							foreach ($ip_serids as $value) {

								if ($value >= 0 && isset($servers[$value])) {
									echo $servers[$value]['server_name'] . ', &nbsp;';
								}
							}
						}
						
					echo'</div>
				</div>
			</div>
			<div class="col-sm-6 mt-2">
				<label class="control-label">'.__('Note').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('You can define the note here, for eg. Why IP is locked or reserved?').'"><i class="fas text-primary fa-info-circle"></i></a></label>
				<textarea class="form-control" name="note" rows="4">'.POSTval('note', $ip['note']).'</textarea>
			</div>
			<div class="col-sm-12">
				<span class="help-block"></span>
				<center><input type="submit" name="editip" class="go_btn m-3" value="'.__('Submit').'"/></center>
			</div>
		</div>
	</form>
</div>';

softfooter();

}

