<?php
if (isset($_POST['datetime_from'])) $datetime_from = $_POST['datetime_from'];
else $datetime_from = NULL;
if (isset($_POST['datetime_to'])) $datetime_to = $_POST['datetime_to'];
else $datetime_to = NULL;

if ($datetime_to){
	$tmp_datetime_from = DateTime::createFromFormat('Y-m-d', $datetime_from);
	$tmp_datetime_to = DateTime::createFromFormat('Y-m-d', $datetime_to);
	if ($tmp_datetime_from->getTimestamp() >= $tmp_datetime_to->getTimestamp()) {
		$datetime_swop = $datetime_from;
		$datetime_from = $datetime_to;
		$datetime_to = $datetime_swop;
	}
}

if (!$datetime_to){
	$datetime_from = date('Y-m-d', time() - (3600 * 24 * $difference_days_from));
	$datetime_to = date('Y-m-d', time() + (3600 * 24 * $difference_days_to));
}

print "
<div class='form-row'>
	<label for='datetime_from' class='form-label'>".LABEL_DATETIME."</label>
	<div class='form-cols'>
		<div class='form-col form-medium'>
			<div class='form-controls'>
				<input type='date' class='field' name='datetime_from' id='datetime_from' value='".$datetime_from."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
		
		<label for='datetime_from' class='form-label-after'>&nbsp;-&nbsp;</label>
		
		<div class='form-col form-medium'>
			<div class='form-controls'>
				<input type='date' class='field' name='datetime_to' id='datetime_to' value='".$datetime_to."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
		
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->";