<?php
$favicon_data = array(
	'favicon_mode' => 'domain',
	'favicon_name' => '',
	'favicon_initials' => '',
	'favicon_background' => '#111827',
	'favicon_foreground' => '#ffffff',
	'theme_color' => '#111827',
	'favicon_last_generated' => ''
);

$sql = "SELECT title, value FROM settings_options WHERE title IN ('favicon_mode', 'favicon_name', 'favicon_initials', 'favicon_background', 'favicon_foreground', 'theme_color', 'favicon_last_generated')";
$result = $conn->prepare($sql);
$result->execute();
if ($result->rowCount()){
	while ($arr = $result->fetch()){
		$favicon_data[$arr['title']] = stripcslashes(str_replace('<br />', '', $arr['value']));
	}
}

if (!isset($favicon_data['favicon_mode']) || !in_array($favicon_data['favicon_mode'], array('domain', 'name', 'initials'))) $favicon_data['favicon_mode'] = 'domain';

$favicon_last_generated = NULL;
if (isset($favicon_data['favicon_last_generated']) && $favicon_data['favicon_last_generated']) $favicon_last_generated = date('d.m.Y H:i', intval($favicon_data['favicon_last_generated']));

print "
<span class='headline'>".LABEL_FAVICON."</span>
<div class='form-row'>
	<label for='favicon_file' class='form-label'>".LABEL_FAVICON_FILE."</label>
	<div class='form-cols'>
		<div class='form-col form-full'>
			<div class='form-controls'>
				<input type='file' class='field' id='favicon_file' name='favicon_file' accept='.png,.jpg,.jpeg,.gif,.webp,.bmp,.svg,image/png,image/jpeg,image/gif,image/webp,image/bmp,image/svg+xml'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->

<div class='form-row'>
	<label for='favicon_mode' class='form-label'>".LABEL_FAVICON_MODE."</label>
	<div class='form-cols'>
		<div class='form-col form-small'>
			<div class='form-controls'>
				<select class='select' name='favicon_mode' id='favicon_mode'>";
if ($favicon_data['favicon_mode'] == 'domain') print "<option value='domain' selected='selected'>".LABEL_FAVICON_DOMAIN."</option>";
else print "<option value='domain'>".LABEL_FAVICON_DOMAIN."</option>";
if ($favicon_data['favicon_mode'] == 'name') print "<option value='name' selected='selected'>".LABEL_FAVICON_NAME."</option>";
else print "<option value='name'>".LABEL_FAVICON_NAME."</option>";
if ($favicon_data['favicon_mode'] == 'initials') print "<option value='initials' selected='selected'>".LABEL_FAVICON_INITIALS."</option>";
else print "<option value='initials'>".LABEL_FAVICON_INITIALS."</option>";
print "
				</select>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->

<div class='form-row'>
	<label for='favicon_name' class='form-label'>".LABEL_FAVICON_NAME."</label>
	<div class='form-cols'>
		<div class='form-col form-medium'>
			<div class='form-controls'>
				<input type='text' class='field' id='favicon_name' name='favicon_name' value='".$favicon_data['favicon_name']."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->

<div class='form-row'>
	<label for='favicon_initials' class='form-label'>".LABEL_FAVICON_INITIALS."</label>
	<div class='form-cols'>
		<div class='form-col form-xxsmall'>
			<div class='form-controls'>
				<input type='text' class='field' id='favicon_initials' name='favicon_initials' maxlength='3' value='".$favicon_data['favicon_initials']."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->

<div class='form-row'>
	<label for='favicon_background' class='form-label'>".LABEL_FAVICON_BACKGROUND."</label>
	<div class='form-cols'>
		<div class='form-col form-xxsmall'>
			<div class='form-controls'>
				<input type='color' class='field' id='favicon_background' name='favicon_background' value='".$favicon_data['favicon_background']."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->
<div class='form-row'>
	<label for='favicon_foreground' class='form-label'>".LABEL_FAVICON_FOREGROUND."</label>
	<div class='form-cols'>
		<div class='form-col form-xxsmall'>
			<div class='form-controls'>
				<input type='color' class='field' id='favicon_foreground' name='favicon_foreground' value='".$favicon_data['favicon_foreground']."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->
<div class='form-row'>
	<label for='theme_color' class='form-label'>".LABEL_THEME_COLOR."</label>
	<div class='form-cols'>
		<div class='form-col form-xxsmall'>
			<div class='form-controls'>
				<input type='color' class='field' id='theme_color' name='theme_color' value='".$favicon_data['theme_color']."'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->
<div class='form-row'>
	<label for='favicon_generate' class='form-label'>".LABEL_FAVICON_GENERATE."</label>
	<div class='form-cols'>
		<div class='form-col'>
			<div class='form-controls'>
				<input type='checkbox' class='field' id='favicon_generate' name='favicon_generate' value='1'>
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->
<div class='form-row'>
	<span class='form-label'>".LABEL_FAVICON."</span>
	<div class='form-cols'>
		<div class='form-col form-full'>
			<div class='form-controls'>
				<span>".LABEL_FAVICON_NOTE."</span>";
if ($favicon_last_generated) print "<br><span>".LABEL_FAVICON_LAST_GENERATED.": ".$favicon_last_generated."</span>";
print "
			</div><!-- /.form-controls -->
		</div><!-- /.form-col -->
	</div><!-- /.form-cols -->
</div><!-- /.form-row -->

<hr />";
