<?php
// Version: 1.0; Themes

// The main sub template - for theme administration.
function template_main()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

	echo '
<table width="96%" cellspacing="0" cellpadding="0" border="0" align="center">
	<tr><td>

		<table width="36%" border="0" cellspacing="0" cellpadding="4" align="right" class="tborder" style="margin-left: 6px; float: right;">
			<tr class="titlebg">
				<td colspan="4">', $txt['theme4'], '</td>
			</tr>';

	// Show each theme.... with X for delete and a link to settings.
	foreach ($context['themes'] as $theme)
	{
		echo '
			<tr class="windowbg2">
				<td><b><a href="', $scripturl, '?action=theme;sa=settings;id=', $theme['id'], ';sesc=', $context['session_id'], '">', $theme['name'], '</a></b></td>
				<td width="16" align="right">';

		// You *cannot* delete the default theme.  It's important!
		if ($theme['id'] != 1)
			echo '
					<a href="', $scripturl, '?action=theme;sa=remove;th=', $theme['id'], ';sesc=', $context['session_id'], '" onclick="return confirm(\'', $txt['theme_remove_confirm'], '\');"><img src="', $settings['images_url'], '/icons/delete.gif" alt="', $txt['theme_remove'], '" title="', $txt['theme_remove'], '" border="0" /></a>';

		echo '
				</td>
			</tr>';
	}

	echo '
		</table>';

	// Show all the basic theme settings - like allowing users to select them, etc.
	echo '
		<div style="width: 62%;">

		<form action="', $scripturl, '?action=theme;sa=admin" method="post">
			<input type="hidden" value="0" name="options[theme_allow]" />
			<input type="hidden" value="0" name="options[theme_default]" />
			<table width="100%" cellpadding="4" cellspacing="0" border="0" class="tborder">
				<tr class="titlebg">
					<td colspan="3">
						<a href="', $scripturl, '?action=helpadmin;help=themes" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt[119], '" align="top" border="0" /></a>
						', $txt['themeadmin_title'], '
					</td>
				</tr>
				<tr class="windowbg">
					<td colspan="3" class="smalltext" style="padding: 2ex;">', $txt['themeadmin_explain'], '</td>
				</tr>
				<tr class="windowbg2">
					<td colspan="3"><input type="checkbox" value="1" name="options[theme_allow]"', $modSettings['theme_allow'] ? ' checked="checked"' : '', ' class="check" /> ', $txt['theme_allow'], '</td>
				</tr>
				<tr class="windowbg2">
					<td colspan="3"><input type="checkbox" value="1" name="options[theme_default]"', $modSettings['theme_default'] ? ' checked="checked"' : '', ' class="check" /> ', $txt['theme_default'], '</td>
				</tr>
				<tr class="windowbg2">
					<td width="35%">', $txt['theme_guests'], ':</td>
					<td width="30%" align="right">
						<select name="options[theme_guests]">';

	// Put an option for each theme in the select box.
	foreach ($context['themes'] as $theme)
		echo '
							<option value="', $theme['id'], '"', $modSettings['theme_guests'] == $theme['id'] ? ' selected="selected"' : '', '>', $theme['name'], '</option>';

	echo '
						</select>
					</td>
					<td class="smalltext">&nbsp; <a href="', $scripturl, '?action=theme;sa=pick;u=-1;sesc=', $context['session_id'], '">', $txt['theme_select'], '</a></td>
				</tr>
				<tr class="windowbg2">
					<td width="35%">', $txt['theme_reset'], ':</td>
					<td align="right">
						<select name="theme_reset">
							<option value="-1" selected="selected">', $txt['theme_nochange'], '</option>
							<option value="0">', $txt['theme_forum_default'], '</option>';

	// Same thing, this time for changing the theme of everyone.
	foreach ($context['themes'] as $theme)
		echo '
							<option value="', $theme['id'], '">', $theme['name'], '</option>';

	echo '
						</select>
					</td>
					<td class="smalltext">&nbsp; <a href="', $scripturl, '?action=theme;sa=pick;u=0;sesc=', $context['session_id'], '">', $txt['theme_select'], '</a></td>
				</tr>
				<tr class="windowbg2">
					<td colspan="3" align="center" valign="middle" style="padding-top: 2ex;"><input type="submit" name="submit" value="' . $txt[10] . '" /></td>
				</tr>
			</table>
			<input type="hidden" name="sc" value="', $context['session_id'], '" />
		</form>';

	// Warn them if theme creation isn't possible!
	if (!$context['can_create_new'])
		echo '
		<b>', $txt['theme_install_writable'], '</b><br /><br />';

		echo '
		<form action="', $scripturl, '?action=theme;sa=install" method="post" name="themeForm" enctype="multipart/form-data" onsubmit="return confirm(\'', $txt['theme_install_new_confirm'], '\');">
			<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tborder">
				<tr class="titlebg">
					<td colspan="2"><a href="', $scripturl, '?action=helpadmin;help=theme_install" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt[119], '" align="top" border="0" /></a> ', $txt['theme_install'], '</td>
				</tr>';

	// Here's a little box for installing a new theme.
	if ($context['can_create_new'])
		echo '
				<tr class="windowbg2">
					<td valign="top"><label for="theme_gz">', $txt['theme_install_file'], '</label>:</td>
					<td align="right" style="padding: 4px 1ex;"><input type="file" name="theme_gz" id="theme_gz" value="theme_gz" size="24" /></td>
				</tr>';

	echo '
				<tr class="windowbg2">
					<td valign="top" colspan="2" style="padding-bottom: 0;"><label for="theme_dir">', $txt['theme_install_dir'], '</label>:</td>
				</tr>
				<tr class="windowbg2">
					<td align="right" colspan="2"><input type="text" name="theme_dir" id="theme_dir" value="', $context['new_theme_dir'], '" size="40" /></td>
				</tr>';

	if ($context['can_create_new'])
		echo '
				<tr class="windowbg2">
					<td valign="top" colspan="2" style="padding-bottom: 0;"><label for="copy">', $txt['theme_install_new'], ':</label></td>
				</tr>
				<tr class="windowbg2">
					<td align="right" colspan="2"><input type="text" name="copy" id="copy" value="', $context['new_theme_name'], '" size="40" /></td>
				</tr>';

	echo '
				<tr><td class="windowbg2" colspan="2" align="right"><input type="submit" name="submit" value="', $txt['theme_install_go'], '" /></td></tr>
			</table>
			<input type="hidden" name="sc" value="', $context['session_id'], '" />
		</form>

		</div>';

	// And lastly, link to simplemachines.org for latest themes and info!
	echo '
		<table width="100%" cellspacing="0" cellpadding="4" border="0" class="tborder" style="clear: right; margin-top: 6px;">
			<tr class="titlebg">
				<td><a href="', $scripturl, '?action=helpadmin;help=latest_themes" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt[119], '" border="0" align="top" /></a> ', $txt['theme_latest'], '</td>
			</tr>
			<tr>
				<td class="windowbg2" id="themeLatest">', $txt['theme_latest_fetch'], '</td>
			</tr>
		</table>
		<script language="JavaScript" type="text/javascript"><!--
			window.smfForum_scripturl = "', $scripturl, '";
			window.smfForum_sessionid = "', $context['session_id'], '";
			window.smfThemes_writable = ', $context['can_create_new'] ? 'true' : 'false', ';
		// --></script>
		<script language="JavaScript" type="text/javascript" src="http://www.simplemachines.org/smf/latest-themes.js?language=', $context['user']['language'], '"></script>
		<script language="JavaScript" type="text/javascript"><!--
			var tempOldOnload;

			function smfSetLatestThemes()
			{
				if (typeof(window.smfLatestThemes) != "undefined")
					setInnerHTML(document.getElementById("themeLatest"), window.smfLatestThemes);

				if (tempOldOnload)
					tempOldOnload();
			}
		// --></script>
	</td></tr>
</table>';

	// Gotta love IE4, and its hatefulness...
	if ($context['browser']['is_ie4'])
		echo '
		<script language="JavaScript" type="text/javascript"><!--
			tempOldOnload = window.onload;
			window.onload = smfSetLatestThemes;
		// --></script>';
	else
		echo '
		<script language="JavaScript" type="text/javascript"><!--
			smfSetLatestThemes();
		// --></script>';
}

// This template allows for the selection of different themes ;).
function template_pick()
{
	global $context, $settings, $options, $scripturl, $txt;

	// Just go through each theme and show its information - thumbnail, etc.
	foreach ($context['available_themes'] as $theme)
		echo '
	<table align="center" width="85%" cellpadding="3" cellspacing="0" border="0" class="tborder">
		<tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
			<td rowspan="2" width="126" height="120"><img src="', $theme['thumbnail_href'], '" alt="" /></td>
			<td valign="top" style="padding-top: 5px;">
				<div style="font-size: larger; padding-bottom: 6px;"><b><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';id=', $theme['id'], ';sesc=', $context['session_id'], '">', $theme['name'], '</a></b></div>
				', $theme['description'], '
			</td>
		</tr>
		<tr class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
			<td valign="bottom" align="right" style="padding: 6px; padding-top: 0;">
				<div style="float: left;" class="smalltext"><i>', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</i></div>
				<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';id=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_set'], '</a> |
				<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';sesc=', $context['session_id'], '">', $txt['theme_preview'], '</a>
			</td>
		</tr>
	</table>
	<br />';
}

// Okay, that theme was installed successfully!
function template_installed()
{
	global $context, $settings, $options, $scripturl, $txt;

	// Not much to show except a link back...
	echo '
		<table width="90%" cellpadding="4" cellspacing="0" class="tborder">
			<tr class="titlebg">
				<td>', $context['page_title'], '</td>
			</tr>
			<tr class="windowbg2">
				<td>
					<a href="', $scripturl, '?action=theme;sa=settings;id=', $context['installed_theme']['id'], ';sesc=', $context['session_id'], '">', $context['installed_theme']['name'], '</a> ', $txt['theme_installed_message'], '<br />
					<br />
					<a href="', $scripturl, '?action=theme;sa=admin;sesc=', $context['session_id'], '">', $txt[250], '</a>
				</td>
			</tr>
		</table>';
}

// Wanna edit the stylesheet?
function template_edit_style()
{
	global $context, $settings, $options, $scripturl, $txt;

	// Just show a big box.... grey out the Save button if it's not saveable... (ie. not 777.)
	echo '
		<form action="', $scripturl, '?action=theme;sa=edit;id=', $context['theme_id'], ';style" method="post">
			<table width="100%" cellpadding="3" cellspacing="0" border="0" class="tborder" align="center" style="table-layout: fixed;">', $context['session_error'] ? '
				<tr>
					<td>
						<br />
						<span style="color: red">' . $txt['error_session_timeout'] . '</span>
						<br />
					</td>
				</tr>' : '', '
				<tr class="titlebg">
					<td>', $txt['theme_edit'], '</td>
				</tr>
				<tr class="windowbg2">
					<td align="center" style="padding-bottom: 1ex;">';

	if (!$context['allow_save'])
		echo '
						', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '<br />';

	echo '
						<textarea name="entire_file" cols="80" rows="20" style="width: 96%; font-family: monospace; margin-top: 1ex; white-space: pre;">', $context['entire_file'], '</textarea><br />
						<input type="submit" name="submit" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' style="margin-top: 1ex;" />
					</td>
				</tr>
			</table>
			<input type="hidden" name="sc" value="', $context['session_id'], '" />
		</form>';
}

// This edits the template...
function template_edit_template()
{
	global $context, $settings, $options, $scripturl, $txt;

	// Not much to do here either, just a save button that can be disabled...
	echo '
		<form action="', $scripturl, '?action=theme;sa=edit;id=', $context['theme_id'], '" method="post">
			<table width="100%" cellpadding="3" cellspacing="0" border="0" class="tborder" align="center" style="table-layout: fixed;">', $context['session_error'] ? '
				<tr>
					<td>
						<br />
						<span style="color: red">' . $txt['error_session_timeout'] . '</span>
						<br />
					</td>
				</tr>' : '', '
				<tr class="titlebg">
					<td>', $txt['theme_edit'], '</td>
				</tr>
				<tr class="windowbg2">
					<td align="center" style="padding-bottom: 1ex;">';

	if (!$context['allow_save'])
		echo '
						', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '<br />';

	echo '
						<textarea name="entire_file" cols="80" rows="20" style="width: 96%; font-family: monospace; margin-top: 1ex; white-space: pre;">', $context['entire_file'], '</textarea><br />
						<input type="submit" name="submit" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' style="margin-top: 1ex;" />
					</td>
				</tr>
			</table>
			<input type="hidden" name="sc" value="', $context['session_id'], '" />
		</form>';
}

function template_set_settings()
{
	global $context, $settings, $options, $scripturl, $txt;

	echo '
		<form action="', $scripturl, '?action=theme;sa=settings;id=', $context['theme_settings']['theme_id'], '" method="post" name="settings_form">
			<table border="0" width="80%" cellspacing="0" cellpadding="4" align="center" class="tborder">
				<tr class="titlebg">
					<td colspan="2"><a href="', $scripturl, '?action=helpadmin;help=17" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt[119], '" border="0" align="top" /></a> ', $txt['theme4'], ' - ', $context['theme_settings']['name'], '</td>
				</tr>';

	if ($context['theme_settings']['theme_id'] != 1)
		echo '
				<tr class="catbg">
					<td colspan="2"><img src="', $settings['images_url'], '/icons/config_sm.gif" alt="" border="0" align="top" /> ', $txt['theme_edit'], '</td>
				</tr>
				<tr class="windowbg2">
					<td colspan="2">
						<a href="', $scripturl, '?action=theme;sa=edit;id=', $context['theme_settings']['theme_id'], ';sesc=', $context['session_id'], '">', $txt['theme_edit_index'], '</a><br />
						<a href="', $scripturl, '?action=theme;sa=edit;id=', $context['theme_settings']['theme_id'], ';style;sesc=', $context['session_id'], '">', $txt['theme_edit_style'], '</a><br />
						<br />
					</td>
				</tr>';

	echo '
				<tr class="catbg">
					<td colspan="2"><img src="', $settings['images_url'], '/icons/config_sm.gif" alt="" border="0" align="top" /> ', $txt['theme5'], '</td>
				</tr>
				<tr class="windowbg2">
					<td>', $txt['actual_theme_name'], '</td>
					<td><input type="text" name="options[name]" value="', $context['theme_settings']['name'], '" size="32" /></td>
				</tr>
				<tr class="windowbg2">
					<td>', $txt['actual_theme_url'], '</td>
					<td><input type="text" name="options[theme_url]" value="', $context['theme_settings']['actual_theme_url'], '" size="50" /></td>
				</tr>
				<tr class="windowbg2">
					<td>', $txt['actual_images_url'], '</td>
					<td><input type="text" name="options[images_url]" value="', $context['theme_settings']['actual_images_url'], '" size="50" /></td>
				</tr>
				<tr class="windowbg2">
					<td>', $txt['actual_theme_dir'], '</td>
					<td><input type="text" name="options[theme_dir]" value="', $context['theme_settings']['actual_theme_dir'], '" size="50" /></td>
				</tr>
				<tr class="windowbg2">
					<td colspan="2"></td>
				</tr>
				<tr class="catbg">
					<td colspan="2"><img src="', $context['theme_settings']['images_url'], '/icons/config_sm.gif" alt="" border="0" align="top" /> ', $txt['theme6'], '</td>
				</tr>
				<tr class="windowbg2">
					<td colspan="2"><a href="', $scripturl, '?action=theme;sa=options;id=', $context['theme_settings']['theme_id'], ';sesc=', $context['session_id'], '">', $txt['theme_options_defaults_link'], '</a></td>
				</tr>
				<tr class="windowbg2">
					<td colspan="2"><a href="', $scripturl, '?action=theme;sa=options;id=', $context['theme_settings']['theme_id'], ';sesc=', $context['session_id'], ';who=1">', $txt['theme_options_reset_link'], '</a></td>
				</tr>';

	foreach ($context['settings'] as $setting)
	{
		echo '
				<tr class="windowbg2">
					<td colspan="2">';

		if ($setting['type'] == 'checkbox')
			echo '
						<input type="hidden" name="options[', $setting['id'], ']" value="0" />
						<label for="', $setting['id'], '"><input type="checkbox" name="options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($setting['value']) ? ' checked="checked"' : '', ' value="1" class="check" /> ', $setting['label'], '</label>';
		elseif ($setting['type'] == 'list')
		{
			echo '
						<label for="', $setting['id'], '">', $setting['label'], '</label>
						<select name="options[', $setting['id'], ']" id="', $setting['id'], '">';

			foreach ($setting['options'] as $value => $label)
			{
				echo '
							<option value="', $value, '"', $value == $setting['value'] ? ' selected="selected"' : '', '>', $label, '</option>';
			}

			echo '
						</select>';
		}
		else
			echo '
						<label for="', $setting['id'], '">', $setting['label'], '</label>
						<input type="text" name="options[', $setting['id'], ']" id="', $setting['id'], '" value="', $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', ' />';

		if (isset($setting['description']))
			echo '
						<div class="smalltext">', $setting['description'], '</div>';

		echo '
					</td>
				</tr>';
	}

	echo '
				<tr class="windowbg2">
					<td align="center" colspan="2"><br /><input type="submit" name="submit" value="', $txt[10], '" /></td>
				</tr>
			</table>
			<input type="hidden" name="sc" value="', $context['session_id'], '" />
		</form>';
}

function template_set_options()
{
	global $context, $settings, $options, $scripturl, $txt;

	echo '
		<form action="', $scripturl, '?action=theme;sa=options;id=', $context['theme_settings']['theme_id'], '" method="post" name="options_form">
			<input type="hidden" name="who" value="', $context['theme_options_reset'] ? 1 : 0, '" />
			<table border="0" width="80%" cellspacing="0" cellpadding="4" align="center" class="tborder">
				<tr class="titlebg">
					<td colspan="2">', $txt['theme_options_title'], ' - ', $context['theme_settings']['name'], '</td>
				</tr>
				<tr class="windowbg">
					<td colspan="2" class="smalltext" style="padding: 2ex;">', $context['theme_options_reset'] ? $txt['theme_options_reset'] : $txt['theme_options_defaults'], '</td>
				</tr>';

	foreach ($context['options'] as $setting)
	{
		echo '
				<tr class="windowbg2">
					<td colspan="2">';

		if ($context['theme_options_reset'])
			echo '
						<input type="checkbox" onclick="document.options_form.', $setting['id'], '.disabled = !this.checked;', $setting['type'] == 'checkbox' ? ' document.getElementById(\'optionreset_' . $setting['id'] . '\').name = this.checked ? \'options[' . $setting['id'] . ']\' : \'\';' : '', '" />';

		if ($setting['type'] == 'checkbox')
		{
			echo '
						<input type="hidden"', !$context['theme_options_reset'] ? ' name="options[' . $setting['id'] . ']"' : '', ' id="optionreset_', $setting['id'], '" value="0" />
						<label for="', $setting['id'], '"><input type="checkbox" name="options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($setting['value']) ? ' checked="checked"' : '', $context['theme_options_reset'] ? ' disabled="disabled"' : '', ' value="1" class="check" /> ', $setting['label'], '</label>';
		}
		elseif ($setting['type'] == 'list')
		{
			echo '
						<label for="', $setting['id'], '">', $setting['label'], '</label>
						<select name="options[', $setting['id'], ']" id="', $setting['id'], '"', $context['theme_options_reset'] ? ' disabled="disabled"' : '', '>';

			foreach ($setting['options'] as $value => $label)
			{
				echo '
							<option value="', $value, '"', $value == $setting['value'] ? ' selected="selected"' : '', '>', $label, '</option>';
			}

			echo '
						</select>';
		}
		else
			echo '
						<label for="', $setting['id'], '">', $setting['label'], '</label>
						<input type="text" name="options[', $setting['id'], ']" id="', $setting['id'], '" value="', $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', $context['theme_options_reset'] ? ' disabled="disabled"' : '', ' />';

		if (isset($setting['description']))
			echo '
						<div class="smalltext">', $setting['description'], '</div>';

		echo '
					</td>
				</tr>';
	}

	echo '
				<tr class="windowbg2">
					<td colspan="2"><a href="', $scripturl, '?action=theme;sa=settings;id=', $context['theme_settings']['theme_id'], ';sesc=', $context['session_id'], '">', $txt['theme_settings_link'], '</a></td>
				</tr>
				<tr class="windowbg2">
					<td align="center" colspan="2"><br /><input type="submit" name="submit" value="', $txt[10], '" /></td>
				</tr>
			</table>
			<input type="hidden" name="sc" value="', $context['session_id'], '" />
		</form>';
}

?>