<?= $this->extend('layouts/form.php') ?>

<?= $this->section('content') ?>
<?php
$siteid = 0;
$sitename = '';
$accountid = '';
$userid = '';
if(isset($sites)) { $data = $sites[0]; }
if(isset($new_value)) { $data = $new_value; }
if(isset($data)) {
	if(isset($data['siteid'])) { $siteid = $data['siteid']; }
	$sitename = $data['sitename'];
	$userid = $data['userid'];
	$accountid = $data['accountid'];
}
?>
<div class="form-body">
	<h3 class="card-title">Site Editor</h3>
	<hr>
	<?php 
	if(isset($validation)) {
	?>
		<div class='alert alert-danger alert-dismissible'>
			<?= $validation->listErrors(); ?>
			<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> <span aria-hidden="true"></span> </button>
		</div>
	<?php
	}
	?>

	<form method='post'>
		
		<input type='hidden' name='siteid' value='<?=$siteid;?>'/>
		
		<div class="form-group row">
			<label class="col-2 col-form-label">Site Name</label>
			<div class="col-10"><input class="form-control" type="text" name='sitename' value="<?=$sitename;?>"></div>
		</div>

		<div class="form-group row">
			<label class="col-2 col-form-label">Account</label>
			<div class="col-10">
				<select class="form-control select2" name='accountid' >
					<option value=''>-</option>
					<?php
					foreach ($accounts as $data) {
						$qaccountid = $data['accountid'];
						$qaccountname = $data['accountname'];

						$qaccountinitial = $data['initial'];
						if ($qaccountinitial != null) {
							$qaccountinitial = " (" . $qaccountinitial . ")";
						} else {
							$qaccountinitial = "";
						}
						
						if ($qaccountid == $accountid) { echo "<option value='$qaccountid' selected>$qaccountname $qaccountinitial</option>"; }
						else { echo "<option value='$qaccountid'>$qaccountname $qaccountinitial</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		
		<div class="form-group row">
			<label class="col-2 col-form-label">Marketing</label>
			<div class="col-10">
				<select class="form-control select2" name='userid' >
					<option value='0'>-</option>
					<?php
					foreach ($users as $data) {
						$quserid = $data['userid'];
						$firstname = $data['firstname'];
						$lastname = $data['lastname'];
						$username = $firstname." ".$lastname;
						if ($quserid == $userid) { echo "<option value='$quserid' selected>$username</option>"; }
						else { echo "<option value='$quserid'>$username</option>"; }
					}
					?>
				</select>
			</div>
		</div>

		<div class="form-group row">
			<label class="col-2 col-form-label">Start</label>
			<div class="col-10"><input class="form-control" type="date" required name='startdate' value='<?=date('Y-m-d');?>'></div>
		</div>
		
		<button type="button" class="btn btn-dark float-start" onclick="window.close()">Cancel</button>
		
		<button type="submit" class="btn btn-success text-white float-end"> <i class="fa fa-check"></i> Submit</button>
	
	</form>

</div>
<?= $this->endSection() ?>