Browse Source

Removed old crap in the rest of the templates

ie6 header spans, topslice, botslice, etc, etc.

Just rubbish we don't need in 2.1.  All gone now. :)
Antechinus 12 years ago
parent
commit
ffe9d46c86
38 changed files with 20275 additions and 20753 deletions
  1. 5 0
      Themes/READ_ME.txt
  2. 2 4
      Themes/default/BoardIndex.template.php
  3. 6 18
      Themes/default/Display.template.php
  4. 236 242
      Themes/default/Errors.template.php
  5. 308 320
      Themes/default/Login.template.php
  6. 207 221
      Themes/default/ManageAttachments.template.php
  7. 364 368
      Themes/default/ManageBans.template.php
  8. 689 705
      Themes/default/ManageBoards.template.php
  9. 116 118
      Themes/default/ManageCalendar.template.php
  10. 478 490
      Themes/default/ManageLanguages.template.php
  11. 40 42
      Themes/default/ManageMail.template.php
  12. 664 700
      Themes/default/ManageMaintenance.template.php
  13. 697 707
      Themes/default/ManageMembergroups.template.php
  14. 325 329
      Themes/default/ManageMembers.template.php
  15. 462 472
      Themes/default/ManageNews.template.php
  16. 622 638
      Themes/default/ManagePaid.template.php
  17. 1177 1187
      Themes/default/ManagePermissions.template.php
  18. 93 95
      Themes/default/ManageScheduledTasks.template.php
  19. 445 461
      Themes/default/ManageSearch.template.php
  20. 543 557
      Themes/default/ManageSmileys.template.php
  21. 204 211
      Themes/default/Memberlist.template.php
  22. 779 809
      Themes/default/ModerationCenter.template.php
  23. 109 111
      Themes/default/MoveTopic.template.php
  24. 48 52
      Themes/default/Notify.template.php
  25. 1826 1860
      Themes/default/Packages.template.php
  26. 1824 1856
      Themes/default/PersonalMessage.template.php
  27. 156 158
      Themes/default/Poll.template.php
  28. 1081 1091
      Themes/default/Post.template.php
  29. 2966 3012
      Themes/default/Profile.template.php
  30. 2 5
      Themes/default/Recent.template.php
  31. 684 702
      Themes/default/Register.template.php
  32. 196 204
      Themes/default/Reminder.template.php
  33. 246 248
      Themes/default/Reports.template.php
  34. 532 548
      Themes/default/Search.template.php
  35. 273 279
      Themes/default/SendTopic.template.php
  36. 457 473
      Themes/default/SplitTopics.template.php
  37. 1141 1178
      Themes/default/Themes.template.php
  38. 272 282
      Themes/default/Who.template.php

+ 5 - 0
Themes/READ_ME.txt

@@ -66,4 +66,9 @@
  2/	Haven't tackled rtl.css yet, but it shouldn't be hard to sort.
  
  3/ Oh yeah, the stuff I don't know about yet. You get that. Hey ho.
+ 
+ ===================================================================
+ 
+ Later: got rid of all the old spans and ie6 header stuff in the rest of the templates.
+ Also ditched the remaining middletext and normaltext classes. Yay! Less crap.
  

+ 2 - 4
Themes/default/BoardIndex.template.php

@@ -267,8 +267,7 @@ function template_info_center()
 
 	// Here's where the "Info Center" starts...
 	echo '
-	<span class="clear upperframe"><span></span></span>
-	<div class="roundframe" id="info_center"><div class="innerframe">
+	<div class="roundframe" id="info_center">
 		<div class="cat_bar">
 			<h3 class="catbg">
 				<img class="icon" id="upshrink_ic" src="', $settings['images_url'], '/collapse.png" alt="*" title="', $txt['upshrink_description'], '" style="display: none;" />
@@ -444,8 +443,7 @@ function template_info_center()
 
 	echo '
 		</div>
-	</div></div>
-	<span class="lowerframe"><span></span></span>';
+	</div>';
 
 	// Info center collapse object.
 	echo '

+ 6 - 18
Themes/default/Display.template.php

@@ -35,11 +35,10 @@ function template_main()
 			<div id="poll">
 				<div class="cat_bar">
 					<h3 class="catbg">
-						<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/topic/', $context['poll']['is_locked'] ? 'normal_poll_locked' : 'normal_poll', '.png" alt="" class="icon" /> ', $txt['poll'], '</span>
+						<img src="', $settings['images_url'], '/topic/', $context['poll']['is_locked'] ? 'normal_poll_locked' : 'normal_poll', '.png" alt="" class="icon" /> ', $txt['poll'], '
 					</h3>
 				</div>
 				<div class="windowbg">
-					<span class="topslice"><span></span></span>
 					<div class="content" id="poll_options">
 						<h4 id="pollquestion">
 							', $context['poll']['question'], '
@@ -55,8 +54,8 @@ function template_main()
 			foreach ($context['poll']['options'] as $option)
 			{
 				echo '
-						<dt class="middletext', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
-						<dd class="middletext statsbar', $option['voted_this'] ? ' voted' : '', '">';
+						<dt class="', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
+						<dd class="statsbar', $option['voted_this'] ? ' voted' : '', '">';
 
 				if ($context['allow_poll_view'])
 					echo '
@@ -91,7 +90,7 @@ function template_main()
 			// Show each option with its button - a radio likely.
 			foreach ($context['poll']['options'] as $option)
 				echo '
-								<li class="middletext">', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
+								<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
 
 			echo '
 							</ul>
@@ -109,7 +108,6 @@ function template_main()
 
 		echo '
 					</div>
-					<span class="botslice"><span></span></span>
 				</div>
 			</div>
 			<div id="pollmoderation">';
@@ -129,7 +127,6 @@ function template_main()
 					<h3 class="titlebg headerpadding">', $txt['calendar_linked_events'], '</h3>
 				</div>
 				<div class="windowbg">
-					<span class="topslice"><span></span></span>
 					<div class="content">
 						<ul class="reset">';
 
@@ -142,7 +139,6 @@ function template_main()
 		echo '
 						</ul>
 					</div>
-					<span class="botslice"><span></span></span>
 				</div>
 			</div>';
 	}
@@ -211,7 +207,6 @@ function template_main()
 
 		echo '
 				<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
-					<span class="topslice"><span></span></span>
 					<div class="post_wrapper">';
 
 		// Show information about the poster of this message.
@@ -628,7 +623,6 @@ function template_main()
 		echo '
 						</div>
 					</div>
-					<span class="botslice"><span></span></span>
 				</div>
 				<hr class="post_separator" />';
 	}
@@ -662,16 +656,11 @@ function template_main()
 			<div class="tborder" id="quickreplybox">
 				<div class="cat_bar">
 					<h3 class="catbg">
-						<span class="ie6_header floatright">
-							<a href="javascript:oQuickReply.swap();"><img src="', $settings['images_url'], '/', $options['display_quick_reply'] > 1 ? 'collapse' : 'expand', '.png" alt="+" id="quickReplyExpand" class="icon" /></a>
-						</span>
-						<span>
-							<a href="javascript:oQuickReply.swap();">', $txt['quick_reply'], '</a>
-						</span>
+						<a href="javascript:oQuickReply.swap();"><img src="', $settings['images_url'], '/', $options['display_quick_reply'] > 1 ? 'collapse' : 'expand', '.png" alt="+" id="quickReplyExpand" class="icon" /></a>
+						<a href="javascript:oQuickReply.swap();">', $txt['quick_reply'], '</a>
 					</h3>
 				</div>
 				<div id="quickReplyOptions"', $options['display_quick_reply'] > 1 ? '' : ' style="display: none"', '>
-					<span class="upperframe"><span></span></span>
 					<div class="roundframe">
 						<p class="smalltext lefttext">', $txt['quick_reply_desc'], '</p>
 						', $context['is_locked'] ? '<p class="alert smalltext">' . $txt['quick_reply_warning'] . '</p>' : '',
@@ -760,7 +749,6 @@ function template_main()
 							</div>
 						</form>
 					</div>
-					<span class="lowerframe"><span></span></span>
 				</div>
 			</div>';
 	}

+ 236 - 242
Themes/default/Errors.template.php

@@ -1,243 +1,237 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// @todo
-/*	This template file contains only the sub template fatal_error. It is
-	shown when an error occurs, and should show at least a back button and
-	$context['error_message'].
-*/
-
-// Show an error message.....
-function template_fatal_error()
-{
-	global $context, $settings, $options, $txt;
-
-	echo '
-	<div id="fatal_error">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', $context['error_title'], '
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div ', $context['error_code'], 'class="padding">', $context['error_message'], '</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-
-	// Show a back button (using javascript.)
-	echo '
-	<div class="centertext"><a href="javascript:history.go(-1)">', $txt['back'], '</a></div>';
-}
-
-function template_error_log()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-		<form action="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';start=', $context['start'], $context['has_filter'] ? $context['filter']['href'] : '', '" method="post" accept-charset="', $context['character_set'], '">';
-	
-	echo '
-			<div class="title_bar clear_right">
-				<h3 class="titlebg">
-					<span class="ie6_header floatleft">
-						<a href="', $scripturl, '?action=helpadmin;help=error_log" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['errlog'], '
-					</span>
-				</h3>
-			</div>
-			<div class="pagesection">
-				<div class="floatleft">
-					', $txt['pages'], ': ', $context['page_index'], '
-				</div>
-			</div>
-			<table border="0" cellspacing="1" class="table_grid" id="error_log">
-				<tr>
-					<td colspan="3" class="windowbg">
-						&nbsp;&nbsp;', $txt['apply_filter_of_type'], ':';
-
-	$error_types = array();
-	foreach ($context['error_types'] as $type => $details)
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="" /> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
-
-	echo '
-						', implode('&nbsp;|&nbsp;', $error_types), '
-					</td>
-				</tr>';
-
-	if ($context['has_filter'])
-		echo '
-				<tr>
-					<td colspan="3" class="windowbg">
-						<strong>&nbsp;&nbsp;', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], '&nbsp;&nbsp;[<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
-					</td>
-				</tr>';
-
-	echo '
-				<tr class="titlebg">
-					<td colspan="3" class="righttext" style="padding-right: 1.2ex">
-						<label for="check_all1"><strong>', $txt['check_all'], '</strong></label>&nbsp;
-						<input type="checkbox" id="check_all1" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all2.checked = this.checked;" class="input_check" />
-					</td>
-				</tr>';
-
-	// No errors, then show a message
-	if (count($context['errors']) == 0)
-		echo '
-				<tr class="windowbg">
-					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
-				</tr>';		
-			
-	// we have some errors, must be some mods installed :P
-	foreach ($context['errors'] as $error)
-	{
-		echo '
-				<tr class="windowbg', $error['alternate'] ? '2' : '', '">
-					<td class="half_width">
-						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=id_member;value=', $error['member']['id'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_member'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_member'], '" /></a>
-						<strong>', $error['member']['link'], '</strong><br />
-						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '" /></a>
-						<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>&nbsp;&nbsp;
-						<br />&nbsp;
-					</td>
-					<td class="half_width">
-						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><img src="', $settings['images_url'], '/sort_', $context['sort_direction'], '.png" alt="', $txt['reverse_direction'], '" /></a>
-						', $error['time'], '
-						<br />';
-
-		if ($error['member']['session'] != '')
-			echo '
-						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '" /></a>
-						', $error['member']['session'], '
-						<br />';
-
-		echo '
-						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=error_type;value=', $error['error_type']['type'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '" /></a>
-						', $txt['error_type'], ': ', $error['error_type']['name'], '
-					</td>';
-
-		echo '
-					<td rowspan="2" class="checkbox_column">
-						<input type="checkbox" name="delete[]" value="', $error['id'], '" class="input_check" />
-					</td>
-				</tr>
-				<tr class="windowbg', $error['alternate'] ? '2' : '', '">
-					<td colspan="2">
-						<div class="clear_left floatleft"><a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=url;value=', $error['url']['href'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_url'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_url'], '" /></a></div>
-						<div class="floatleft marginleft"><a href="', $error['url']['html'], '">', $error['url']['html'], '</a></div>
-						<div class="clear_left floatleft"><a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=message;value=', $error['message']['href'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_message'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_message'], '" /></a></div>
-						<div class="floatleft marginleft">', $error['message']['html'], '</div>';
-
-		if (!empty($error['file']))
-			echo '
-						<div class="clear_left floatleft"><a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '" /></a></div>
-						<div class="floatleft marginleft">
-							', $txt['file'], ': ', $error['file']['link'], '<br />
-							', $txt['line'], ': ', $error['file']['line'], '
-						</div>';
-
-		echo '
-					</td>
-				</tr>';
-	}
-
-	echo '
-				<tr class="titlebg">
-					<td colspan="3" class="righttext" style="padding-right: 1.2ex">
-						<label for="check_all2"><strong>', $txt['check_all'], '</strong></label>&nbsp;
-						<input type="checkbox" id="check_all2" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all1.checked = this.checked;" class="input_check" />
-					</td>
-				</tr>
-			</table>
-			<div class="pagesection floatleft">
-				&nbsp;&nbsp;', $txt['pages'], ': ', $context['page_index'], '
-			</div>';  
-
-	echo '
-			<div class="floatright" style="margin-top: 1ex">
-				<input type="submit" name="removeSelection" value="' . $txt['remove_selection'] . '" onclick="return confirm(\'' . $txt['remove_selection_confirm'] . '\');" class="button_submit" />
-				<input type="submit" name="delall" value="', $context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all'], '" onclick="return confirm(\'', $context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove'], '\');" class="button_submit" />
-			</div>
-			<br />';
-
-	if ($context['sort_direction'] == 'down')
-		echo '
-			<input type="hidden" name="desc" value="1" />';
-		
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-el_token_var'], '" value="', $context['admin-el_token'], '" />
-		</form>';
-}
-
-function template_show_file()
-{
-	global $context, $settings;
-
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<title>', $context['file_data']['file'], '</title>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
-	</head>
-	<body>
-		<table border="0" cellpadding="0" cellspacing="3">';
-	foreach ($context['file_data']['contents'] as $index => $line)
-	{
-		$line_num = $index+$context['file_data']['min'];
-		$is_target = $line_num == $context['file_data']['target'];
-		echo '
-			<tr>
-				<td align="right"', $is_target ? ' style="font-weight: bold; border: 1px solid black;border-width: 1px 0 1px 1px;">==&gt;' : '>', $line_num , ':</td>
-				<td style="white-space: nowrap;', $is_target ? ' border: 1px solid black;border-width: 1px 1px 1px 0;':'','">', $line, '</td>
-			</tr>';
-	}
-	echo '
-		</table>
-	</body>
-</html>';
-}
-
-function template_attachment_errors()
-{
-	global $context, $scripturl, $txt;
-
-	echo '
-	<div>
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', $txt['attach_error_title'], '
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="padding">
-				<div class="noticebox" />', 
-					$context['error_message'], '
-				</div>
-				<hr class="hrcolor" />
-				<a class="button_link" href="', $scripturl, $context['back_link'], '">', $txt['back'], '</a>
-				<span style="float: right; margin:.5em;"></span>
-				<a class="button_link" href="', $scripturl, $context['redirect_link'], '">', $txt['attach_continue'], '</a>
-				<br class="clear_right" />
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// @todo
+/*	This template file contains only the sub template fatal_error. It is
+	shown when an error occurs, and should show at least a back button and
+	$context['error_message'].
+*/
+
+// Show an error message.....
+function template_fatal_error()
+{
+	global $context, $settings, $options, $txt;
+
+	echo '
+	<div id="fatal_error">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $context['error_title'], '
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div ', $context['error_code'], 'class="padding">', $context['error_message'], '</div>
+		</div>
+	</div>
+	<br class="clear" />';
+
+	// Show a back button (using javascript.)
+	echo '
+	<div class="centertext"><a href="javascript:history.go(-1)">', $txt['back'], '</a></div>';
+}
+
+function template_error_log()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+		<form action="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';start=', $context['start'], $context['has_filter'] ? $context['filter']['href'] : '', '" method="post" accept-charset="', $context['character_set'], '">';
+	
+	echo '
+			<div class="title_bar clear_right">
+				<h3 class="titlebg">
+					<a href="', $scripturl, '?action=helpadmin;help=error_log" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['errlog'], '
+				</h3>
+			</div>
+			<div class="pagesection">
+				<div class="floatleft">
+					', $txt['pages'], ': ', $context['page_index'], '
+				</div>
+			</div>
+			<table border="0" cellspacing="1" class="table_grid" id="error_log">
+				<tr>
+					<td colspan="3" class="windowbg">
+						&nbsp;&nbsp;', $txt['apply_filter_of_type'], ':';
+
+	$error_types = array();
+	foreach ($context['error_types'] as $type => $details)
+		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="" /> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
+
+	echo '
+						', implode('&nbsp;|&nbsp;', $error_types), '
+					</td>
+				</tr>';
+
+	if ($context['has_filter'])
+		echo '
+				<tr>
+					<td colspan="3" class="windowbg">
+						<strong>&nbsp;&nbsp;', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], '&nbsp;&nbsp;[<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
+					</td>
+				</tr>';
+
+	echo '
+				<tr class="titlebg">
+					<td colspan="3" class="righttext" style="padding-right: 1.2ex">
+						<label for="check_all1"><strong>', $txt['check_all'], '</strong></label>&nbsp;
+						<input type="checkbox" id="check_all1" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all2.checked = this.checked;" class="input_check" />
+					</td>
+				</tr>';
+
+	// No errors, then show a message
+	if (count($context['errors']) == 0)
+		echo '
+				<tr class="windowbg">
+					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
+				</tr>';		
+			
+	// we have some errors, must be some mods installed :P
+	foreach ($context['errors'] as $error)
+	{
+		echo '
+				<tr class="windowbg', $error['alternate'] ? '2' : '', '">
+					<td class="half_width">
+						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=id_member;value=', $error['member']['id'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_member'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_member'], '" /></a>
+						<strong>', $error['member']['link'], '</strong><br />
+						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '" /></a>
+						<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>&nbsp;&nbsp;
+						<br />&nbsp;
+					</td>
+					<td class="half_width">
+						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><img src="', $settings['images_url'], '/sort_', $context['sort_direction'], '.png" alt="', $txt['reverse_direction'], '" /></a>
+						', $error['time'], '
+						<br />';
+
+		if ($error['member']['session'] != '')
+			echo '
+						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '" /></a>
+						', $error['member']['session'], '
+						<br />';
+
+		echo '
+						<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=error_type;value=', $error['error_type']['type'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '" /></a>
+						', $txt['error_type'], ': ', $error['error_type']['name'], '
+					</td>';
+
+		echo '
+					<td rowspan="2" class="checkbox_column">
+						<input type="checkbox" name="delete[]" value="', $error['id'], '" class="input_check" />
+					</td>
+				</tr>
+				<tr class="windowbg', $error['alternate'] ? '2' : '', '">
+					<td colspan="2">
+						<div class="clear_left floatleft"><a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=url;value=', $error['url']['href'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_url'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_url'], '" /></a></div>
+						<div class="floatleft marginleft"><a href="', $error['url']['html'], '">', $error['url']['html'], '</a></div>
+						<div class="clear_left floatleft"><a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=message;value=', $error['message']['href'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_message'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_message'], '" /></a></div>
+						<div class="floatleft marginleft">', $error['message']['html'], '</div>';
+
+		if (!empty($error['file']))
+			echo '
+						<div class="clear_left floatleft"><a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '"><img src="', $settings['images_url'], '/filter.png" alt="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '" /></a></div>
+						<div class="floatleft marginleft">
+							', $txt['file'], ': ', $error['file']['link'], '<br />
+							', $txt['line'], ': ', $error['file']['line'], '
+						</div>';
+
+		echo '
+					</td>
+				</tr>';
+	}
+
+	echo '
+				<tr class="titlebg">
+					<td colspan="3" class="righttext" style="padding-right: 1.2ex">
+						<label for="check_all2"><strong>', $txt['check_all'], '</strong></label>&nbsp;
+						<input type="checkbox" id="check_all2" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all1.checked = this.checked;" class="input_check" />
+					</td>
+				</tr>
+			</table>
+			<div class="pagesection floatleft">
+				&nbsp;&nbsp;', $txt['pages'], ': ', $context['page_index'], '
+			</div>';  
+
+	echo '
+			<div class="floatright" style="margin-top: 1ex">
+				<input type="submit" name="removeSelection" value="' . $txt['remove_selection'] . '" onclick="return confirm(\'' . $txt['remove_selection_confirm'] . '\');" class="button_submit" />
+				<input type="submit" name="delall" value="', $context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all'], '" onclick="return confirm(\'', $context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove'], '\');" class="button_submit" />
+			</div>
+			<br />';
+
+	if ($context['sort_direction'] == 'down')
+		echo '
+			<input type="hidden" name="desc" value="1" />';
+		
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-el_token_var'], '" value="', $context['admin-el_token'], '" />
+		</form>';
+}
+
+function template_show_file()
+{
+	global $context, $settings;
+
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<title>', $context['file_data']['file'], '</title>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
+	</head>
+	<body>
+		<table border="0" cellpadding="0" cellspacing="3">';
+	foreach ($context['file_data']['contents'] as $index => $line)
+	{
+		$line_num = $index+$context['file_data']['min'];
+		$is_target = $line_num == $context['file_data']['target'];
+		echo '
+			<tr>
+				<td align="right"', $is_target ? ' style="font-weight: bold; border: 1px solid black;border-width: 1px 0 1px 1px;">==&gt;' : '>', $line_num , ':</td>
+				<td style="white-space: nowrap;', $is_target ? ' border: 1px solid black;border-width: 1px 1px 1px 0;':'','">', $line, '</td>
+			</tr>';
+	}
+	echo '
+		</table>
+	</body>
+</html>';
+}
+
+function template_attachment_errors()
+{
+	global $context, $scripturl, $txt;
+
+	echo '
+	<div>
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $txt['attach_error_title'], '
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="padding">
+				<div class="noticebox" />', 
+					$context['error_message'], '
+				</div>
+				<hr class="hrcolor" />
+				<a class="button_link" href="', $scripturl, $context['back_link'], '">', $txt['back'], '</a>
+				<span style="float: right; margin:.5em;"></span>
+				<a class="button_link" href="', $scripturl, $context['redirect_link'], '">', $txt['attach_continue'], '</a>
+				<br class="clear_right" />
+			</div>
+		</div>
+	</div>';
+}
+
 ?>

+ 308 - 320
Themes/default/Login.template.php

@@ -1,321 +1,309 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// This is just the basic "login" form.
-function template_login()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
-
-		<form action="', $scripturl, '?action=login2" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
-		<div class="tborder login">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/login_sm.png" alt="" class="icon" /> ', $txt['login'], '</span>
-				</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe"><br class="clear" />';
-
-	// Did they make a mistake last time?
-	if (!empty($context['login_errors']))
-		echo '
-			<p class="errorbox">', implode('<br />', $context['login_errors']), '</p><br />';
-
-	// Or perhaps there's some special description for this time?
-	if (isset($context['description']))
-		echo '
-				<p class="description">', $context['description'], '</p>';
-
-	// Now just get the basic information - username, password, etc.
-	echo '
-				<dl>
-					<dt>', $txt['username'], ':</dt>
-					<dd><input type="text" name="user" size="20" value="', $context['default_username'], '" class="input_text" /></dd>
-					<dt>', $txt['password'], ':</dt>
-					<dd><input type="password" name="passwrd" value="', $context['default_password'], '" size="20" class="input_password" /></dd>
-				</dl>';
-
-	if (!empty($modSettings['enableOpenID']))
-		echo '<p><strong>&mdash;', $txt['or'], '&mdash;</strong></p>
-				<dl>
-					<dt>', $txt['openid'], ':</dt>
-					<dd><input type="text" name="openid_identifier" class="input_text openid_login" size="17" />&nbsp;<a href="', $scripturl, '?action=helpadmin;help=register_openid" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="centericon" /></a></dd>
-				</dl>
-				<hr />';
-
-	echo '
-				<dl>
-					<dt>', $txt['mins_logged_in'], ':</dt>
-					<dd><input type="text" name="cookielength" size="4" maxlength="4" value="', $modSettings['cookieTime'], '"', $context['never_expire'] ? ' disabled="disabled"' : '', ' class="input_text" /></dd>
-					<dt>', $txt['always_logged_in'], ':</dt>
-					<dd><input type="checkbox" name="cookieneverexp"', $context['never_expire'] ? ' checked="checked"' : '', ' class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>';
-	// If they have deleted their account, give them a chance to change their mind.
-	if (isset($context['login_show_undelete']))
-		echo '
-					<dt class="alert">', $txt['undelete_account'], ':</dt>
-					<dd><input type="checkbox" name="undelete" class="input_check" /></dd>';
-	echo '
-				</dl>
-				<p><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
-				<p class="smalltext"><a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a></p>
-				<input type="hidden" name="hash_passwrd" value="" />
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-		</form>';
-
-	// Focus on the correct input - username or password.
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			document.forms.frmLogin.', isset($context['default_username']) && $context['default_username'] != '' ? 'passwrd' : 'user', '.focus();
-		// ]]></script>';
-}
-
-// Tell a guest to get lost or login!
-function template_kick_guest()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// This isn't that much... just like normal login but with a message at the top.
-	echo '
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
-	<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" name="frmLogin" id="frmLogin"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
-		<div class="tborder login">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['warning'], '</h3>
-			</div>';
-
-	// Show the message or default message.
-	echo '
-			<p class="information centertext">
-				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br />';
-
-
-	if ($context['can_register'])
-		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=register', $context['forum_name_html_safe']);
-	else
-		echo $txt['login_below'];
-
-	// And now the login information.
-	echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<img src="', $settings['images_url'], '/icons/login_sm.png" alt="" class="icon" /> ', $txt['login'], '
-				</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<dl>
-					<dt>', $txt['username'], ':</dt>
-					<dd><input type="text" name="user" size="20" class="input_text" /></dd>
-					<dt>', $txt['password'], ':</dt>
-					<dd><input type="password" name="passwrd" size="20" class="input_password" /></dd>';
-
-	if (!empty($modSettings['enableOpenID']))
-		echo '
-				</dl>
-				<p><strong>&mdash;', $txt['or'], '&mdash;</strong></p>
-				<dl>
-					<dt>', $txt['openid'], ':</dt>
-					<dd><input type="text" name="openid_identifier" class="input_text openid_login" size="17" /></dd>
-				</dl>
-				<hr />
-				<dl>';
-
-	echo '
-					<dt>', $txt['mins_logged_in'], ':</dt>
-					<dd><input type="text" name="cookielength" size="4" maxlength="4" value="', $modSettings['cookieTime'], '" class="input_text" /></dd>
-					<dt>', $txt['always_logged_in'], ':</dt>
-					<dd><input type="checkbox" name="cookieneverexp" class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>
-				</dl>
-				<p class="centertext"><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
-				<p class="centertext smalltext"><a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a></p>
-			</div>
-			<span class="lowerframe"><span></span></span>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
-			<input type="hidden" name="hash_passwrd" value="" />
-		</div>
-	</form>';
-
-	// Do the focus thing...
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			document.forms.frmLogin.user.focus();
-		// ]]></script>';
-}
-
-// This is for maintenance mode.
-function template_maintenance()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Display the administrator's message at the top.
-	echo '
-<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
-<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
-	<div class="tborder login" id="maintenance_mode">
-		<div class="cat_bar">
-			<h3 class="catbg">', $context['title'], '</h3>
-		</div>
-		<p class="description">
-			<img class="floatleft" src="', $settings['images_url'], '/construction.png" width="40" height="40" alt="', $txt['in_maintain_mode'], '" />
-			', $context['description'], '<br class="clear" />
-		</p>
-		<div class="title_bar">
-			<h4 class="titlebg">', $txt['admin_login'], '</h4>
-		</div>
-		<span class="upperframe"><span></span></span>
-		<div class="roundframe">
-			<dl>
-				<dt>', $txt['username'], ':</dt>
-				<dd><input type="text" name="user" size="20" class="input_text" /></dd>
-				<dt>', $txt['password'], ':</dt>
-				<dd><input type="password" name="passwrd" size="20" class="input_password" /></dd>
-				<dt>', $txt['mins_logged_in'], ':</dt>
-				<dd><input type="text" name="cookielength" size="4" maxlength="4" value="', $modSettings['cookieTime'], '" class="input_text" /></dd>
-				<dt>', $txt['always_logged_in'], ':</dt>
-				<dd><input type="checkbox" name="cookieneverexp" class="input_check" /></dd>
-			</dl>
-			<p class="centertext"><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
-		</div>
-		<span class="lowerframe"><span></span></span>
-		<input type="hidden" name="hash_passwrd" value="" />
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
-	</div>
-</form>';
-}
-
-// This is for the security stuff - makes administrators login every so often.
-function template_admin_login()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Since this should redirect to whatever they were doing, send all the get data.
-	echo '
-<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
-
-<form action="', $scripturl, $context['get_data'], '" method="post" accept-charset="', $context['character_set'], '" name="frmLogin" id="frmLogin" onsubmit="hash', ucfirst($context['sessionCheckType']), 'Password(this, \'', $context['user']['username'], '\', \'', $context['session_id'], '\');">
-	<div class="tborder login" id="admin_login">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/login_sm.png" alt="" class="icon" /> ', $txt['login'], '</span>
-			</h3>
-		</div>
-		<span class="upperframe"><span></span></span>
-		<div class="roundframe centertext">';
-
-	if (!empty($context['incorrect_password']))
-		echo '
-			<div class="error">', $txt['admin_incorrect_password'], '</div>';
-
-	echo '
-			<strong>', $txt['password'], ':</strong>
-			<input type="password" name="', $context['sessionCheckType'], '_pass" size="24" class="input_password" />
-			<a href="', $scripturl, '?action=helpadmin;help=securityDisable_why" onclick="return reqWin(this.href);" class="help"><img class="icon" src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><br />
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-login_token_var'], '" value="', $context['admin-login_token'], '" />
-			<input type="submit" style="margin-top: 1em;" value="', $txt['login'], '" class="button_submit" />';
-
-	// Make sure to output all the old post data.
-	echo $context['post_data'], '
-		</div>
-		<span class="lowerframe"><span></span></span>
-	</div>
-	<input type="hidden" name="', $context['sessionCheckType'], '_hash_pass" value="" />
-</form>';
-
-	// Focus on the password box.
-	echo '
-<script type="text/javascript"><!-- // --><![CDATA[
-	document.forms.frmLogin.', $context['sessionCheckType'], '_pass.focus();
-// ]]></script>';
-}
-
-// Activate your account manually?
-function template_retry_activate()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Just ask them for their code so they can try it again...
-	echo '
-		<form action="', $scripturl, '?action=activate;u=', $context['member_id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">', $context['page_title'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">';
-
-	// You didn't even have an ID?
-	if (empty($context['member_id']))
-		echo '
-				<dl>
-					<dt>', $txt['invalid_activation_username'], ':</dt>
-					<dd><input type="text" name="user" size="30" class="input_text" /></dd>';
-
-	echo '
-					<dt>', $txt['invalid_activation_retry'], ':</dt>
-					<dd><input type="text" name="code" size="30" class="input_text" /></dd>
-				</dl>
-				<p><input type="submit" value="', $txt['invalid_activation_submit'], '" class="button_submit" /></p>
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</form>';
-}
-
-// Activate your account manually?
-function template_resend()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Just ask them for their code so they can try it again...
-	echo '
-		<form action="', $scripturl, '?action=activate;sa=resend" method="post" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">', $context['page_title'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<dl>
-					<dt>', $txt['invalid_activation_username'], ':</dt>
-					<dd><input type="text" name="user" size="40" value="', $context['default_username'], '" class="input_text" /></dd>
-				</dl>
-				<p>', $txt['invalid_activation_new'], '</p>
-				<dl>
-					<dt>', $txt['invalid_activation_new_email'], ':</dt>
-					<dd><input type="text" name="new_email" size="40" class="input_text" /></dd>
-					<dt>', $txt['invalid_activation_password'], ':</dt>
-					<dd><input type="password" name="passwd" size="30" class="input_password" /></dd>
-				</dl>';
-
-	if ($context['can_activate'])
-		echo '
-				<p>', $txt['invalid_activation_known'], '</p>
-				<dl>
-					<dt>', $txt['invalid_activation_retry'], ':</dt>
-					<dd><input type="text" name="code" size="30" class="input_text" /></dd>
-				</dl>';
-
-	echo '
-				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button_submit" /></p>
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</form>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// This is just the basic "login" form.
+function template_login()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
+
+		<form action="', $scripturl, '?action=login2" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
+		<div class="tborder login">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/login_sm.png" alt="" class="icon" /> ', $txt['login'], '
+				</h3>
+			</div>
+			<div class="roundframe"><br class="clear" />';
+
+	// Did they make a mistake last time?
+	if (!empty($context['login_errors']))
+		echo '
+			<p class="errorbox">', implode('<br />', $context['login_errors']), '</p><br />';
+
+	// Or perhaps there's some special description for this time?
+	if (isset($context['description']))
+		echo '
+				<p class="description">', $context['description'], '</p>';
+
+	// Now just get the basic information - username, password, etc.
+	echo '
+				<dl>
+					<dt>', $txt['username'], ':</dt>
+					<dd><input type="text" name="user" size="20" value="', $context['default_username'], '" class="input_text" /></dd>
+					<dt>', $txt['password'], ':</dt>
+					<dd><input type="password" name="passwrd" value="', $context['default_password'], '" size="20" class="input_password" /></dd>
+				</dl>';
+
+	if (!empty($modSettings['enableOpenID']))
+		echo '<p><strong>&mdash;', $txt['or'], '&mdash;</strong></p>
+				<dl>
+					<dt>', $txt['openid'], ':</dt>
+					<dd><input type="text" name="openid_identifier" class="input_text openid_login" size="17" />&nbsp;<a href="', $scripturl, '?action=helpadmin;help=register_openid" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="centericon" /></a></dd>
+				</dl>
+				<hr />';
+
+	echo '
+				<dl>
+					<dt>', $txt['mins_logged_in'], ':</dt>
+					<dd><input type="text" name="cookielength" size="4" maxlength="4" value="', $modSettings['cookieTime'], '"', $context['never_expire'] ? ' disabled="disabled"' : '', ' class="input_text" /></dd>
+					<dt>', $txt['always_logged_in'], ':</dt>
+					<dd><input type="checkbox" name="cookieneverexp"', $context['never_expire'] ? ' checked="checked"' : '', ' class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>';
+	// If they have deleted their account, give them a chance to change their mind.
+	if (isset($context['login_show_undelete']))
+		echo '
+					<dt class="alert">', $txt['undelete_account'], ':</dt>
+					<dd><input type="checkbox" name="undelete" class="input_check" /></dd>';
+	echo '
+				</dl>
+				<p><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
+				<p class="smalltext"><a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a></p>
+				<input type="hidden" name="hash_passwrd" value="" />
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
+			</div>
+		</div>
+		</form>';
+
+	// Focus on the correct input - username or password.
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			document.forms.frmLogin.', isset($context['default_username']) && $context['default_username'] != '' ? 'passwrd' : 'user', '.focus();
+		// ]]></script>';
+}
+
+// Tell a guest to get lost or login!
+function template_kick_guest()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// This isn't that much... just like normal login but with a message at the top.
+	echo '
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
+	<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" name="frmLogin" id="frmLogin"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
+		<div class="tborder login">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['warning'], '</h3>
+			</div>';
+
+	// Show the message or default message.
+	echo '
+			<p class="information centertext">
+				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br />';
+
+
+	if ($context['can_register'])
+		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=register', $context['forum_name_html_safe']);
+	else
+		echo $txt['login_below'];
+
+	// And now the login information.
+	echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/login_sm.png" alt="" class="icon" /> ', $txt['login'], '
+				</h3>
+			</div>
+			<div class="roundframe">
+				<dl>
+					<dt>', $txt['username'], ':</dt>
+					<dd><input type="text" name="user" size="20" class="input_text" /></dd>
+					<dt>', $txt['password'], ':</dt>
+					<dd><input type="password" name="passwrd" size="20" class="input_password" /></dd>';
+
+	if (!empty($modSettings['enableOpenID']))
+		echo '
+				</dl>
+				<p><strong>&mdash;', $txt['or'], '&mdash;</strong></p>
+				<dl>
+					<dt>', $txt['openid'], ':</dt>
+					<dd><input type="text" name="openid_identifier" class="input_text openid_login" size="17" /></dd>
+				</dl>
+				<hr />
+				<dl>';
+
+	echo '
+					<dt>', $txt['mins_logged_in'], ':</dt>
+					<dd><input type="text" name="cookielength" size="4" maxlength="4" value="', $modSettings['cookieTime'], '" class="input_text" /></dd>
+					<dt>', $txt['always_logged_in'], ':</dt>
+					<dd><input type="checkbox" name="cookieneverexp" class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>
+				</dl>
+				<p class="centertext"><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
+				<p class="centertext smalltext"><a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a></p>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
+			<input type="hidden" name="hash_passwrd" value="" />
+		</div>
+	</form>';
+
+	// Do the focus thing...
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			document.forms.frmLogin.user.focus();
+		// ]]></script>';
+}
+
+// This is for maintenance mode.
+function template_maintenance()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Display the administrator's message at the top.
+	echo '
+<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
+<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
+	<div class="tborder login" id="maintenance_mode">
+		<div class="cat_bar">
+			<h3 class="catbg">', $context['title'], '</h3>
+		</div>
+		<p class="description">
+			<img class="floatleft" src="', $settings['images_url'], '/construction.png" width="40" height="40" alt="', $txt['in_maintain_mode'], '" />
+			', $context['description'], '<br class="clear" />
+		</p>
+		<div class="title_bar">
+			<h4 class="titlebg">', $txt['admin_login'], '</h4>
+		</div>
+		<div class="roundframe">
+			<dl>
+				<dt>', $txt['username'], ':</dt>
+				<dd><input type="text" name="user" size="20" class="input_text" /></dd>
+				<dt>', $txt['password'], ':</dt>
+				<dd><input type="password" name="passwrd" size="20" class="input_password" /></dd>
+				<dt>', $txt['mins_logged_in'], ':</dt>
+				<dd><input type="text" name="cookielength" size="4" maxlength="4" value="', $modSettings['cookieTime'], '" class="input_text" /></dd>
+				<dt>', $txt['always_logged_in'], ':</dt>
+				<dd><input type="checkbox" name="cookieneverexp" class="input_check" /></dd>
+			</dl>
+			<p class="centertext"><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
+		</div>
+		<input type="hidden" name="hash_passwrd" value="" />
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
+	</div>
+</form>';
+}
+
+// This is for the security stuff - makes administrators login every so often.
+function template_admin_login()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Since this should redirect to whatever they were doing, send all the get data.
+	echo '
+<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
+
+<form action="', $scripturl, $context['get_data'], '" method="post" accept-charset="', $context['character_set'], '" name="frmLogin" id="frmLogin" onsubmit="hash', ucfirst($context['sessionCheckType']), 'Password(this, \'', $context['user']['username'], '\', \'', $context['session_id'], '\');">
+	<div class="tborder login" id="admin_login">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/icons/login_sm.png" alt="" class="icon" /> ', $txt['login'], '
+			</h3>
+		</div>
+		<div class="roundframe centertext">';
+
+	if (!empty($context['incorrect_password']))
+		echo '
+			<div class="error">', $txt['admin_incorrect_password'], '</div>';
+
+	echo '
+			<strong>', $txt['password'], ':</strong>
+			<input type="password" name="', $context['sessionCheckType'], '_pass" size="24" class="input_password" />
+			<a href="', $scripturl, '?action=helpadmin;help=securityDisable_why" onclick="return reqWin(this.href);" class="help"><img class="icon" src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><br />
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-login_token_var'], '" value="', $context['admin-login_token'], '" />
+			<input type="submit" style="margin-top: 1em;" value="', $txt['login'], '" class="button_submit" />';
+
+	// Make sure to output all the old post data.
+	echo $context['post_data'], '
+		</div>
+	</div>
+	<input type="hidden" name="', $context['sessionCheckType'], '_hash_pass" value="" />
+</form>';
+
+	// Focus on the password box.
+	echo '
+<script type="text/javascript"><!-- // --><![CDATA[
+	document.forms.frmLogin.', $context['sessionCheckType'], '_pass.focus();
+// ]]></script>';
+}
+
+// Activate your account manually?
+function template_retry_activate()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Just ask them for their code so they can try it again...
+	echo '
+		<form action="', $scripturl, '?action=activate;u=', $context['member_id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">', $context['page_title'], '</h3>
+			</div>
+			<div class="roundframe">';
+
+	// You didn't even have an ID?
+	if (empty($context['member_id']))
+		echo '
+				<dl>
+					<dt>', $txt['invalid_activation_username'], ':</dt>
+					<dd><input type="text" name="user" size="30" class="input_text" /></dd>';
+
+	echo '
+					<dt>', $txt['invalid_activation_retry'], ':</dt>
+					<dd><input type="text" name="code" size="30" class="input_text" /></dd>
+				</dl>
+				<p><input type="submit" value="', $txt['invalid_activation_submit'], '" class="button_submit" /></p>
+			</div>
+		</form>';
+}
+
+// Activate your account manually?
+function template_resend()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Just ask them for their code so they can try it again...
+	echo '
+		<form action="', $scripturl, '?action=activate;sa=resend" method="post" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">', $context['page_title'], '</h3>
+			</div>
+			<div class="roundframe">
+				<dl>
+					<dt>', $txt['invalid_activation_username'], ':</dt>
+					<dd><input type="text" name="user" size="40" value="', $context['default_username'], '" class="input_text" /></dd>
+				</dl>
+				<p>', $txt['invalid_activation_new'], '</p>
+				<dl>
+					<dt>', $txt['invalid_activation_new_email'], ':</dt>
+					<dd><input type="text" name="new_email" size="40" class="input_text" /></dd>
+					<dt>', $txt['invalid_activation_password'], ':</dt>
+					<dd><input type="password" name="passwd" size="30" class="input_password" /></dd>
+				</dl>';
+
+	if ($context['can_activate'])
+		echo '
+				<p>', $txt['invalid_activation_known'], '</p>
+				<dl>
+					<dt>', $txt['invalid_activation_retry'], ':</dt>
+					<dd><input type="text" name="code" size="30" class="input_text" /></dd>
+				</dl>';
+
+	echo '
+				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button_submit" /></p>
+			</div>
+		</form>';
+}
+
 ?>

+ 207 - 221
Themes/default/ManageAttachments.template.php

@@ -1,222 +1,208 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Template template wraps around the simple settings page to add javascript functionality.
-function template_avatar_settings_above()
-{
-}
-
-function template_avatar_settings_below()
-{
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-	var fUpdateStatus = function ()
-	{
-		document.getElementById("avatar_max_width_external").disabled = document.getElementById("avatar_download_external").checked;
-		document.getElementById("avatar_max_height_external").disabled = document.getElementById("avatar_download_external").checked;
-		document.getElementById("avatar_action_too_large").disabled = document.getElementById("avatar_download_external").checked;
-		document.getElementById("custom_avatar_dir").disabled = document.getElementById("custom_avatar_enabled").value == 0;
-		document.getElementById("custom_avatar_url").disabled = document.getElementById("custom_avatar_enabled").value == 0;
-
-	}
-	addLoadEvent(fUpdateStatus);
-// ]]></script>
-';
-}
-
-function template_browse()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="manage_attachments">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['attachment_manager_browse_files'], '</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<a href="', $scripturl, '?action=admin;area=manageattachments;sa=browse">', $context['browse_type'] === 'attachments' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;" /> ' : '', $txt['attachment_manager_attachments'], '</a> |
-				<a href="', $scripturl, '?action=admin;area=manageattachments;sa=browse;avatars">', $context['browse_type'] === 'avatars' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;" /> ' : '', $txt['attachment_manager_avatars'], '</a> |
-				<a href="', $scripturl, '?action=admin;area=manageattachments;sa=browse;thumbs">', $context['browse_type'] === 'thumbs' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;" /> ' : '', $txt['attachment_manager_thumbs'], '</a>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>';
-
-	template_show_list('file_list');
-	echo '
-	<br class="clear" />';
-
-}
-
-function template_maintenance()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="manage_attachments">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['attachment_stats'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">
-					<dt><strong>', $txt['attachment_total'], ':</strong></dt><dd>', $context['num_attachments'], '</dd>
-					<dt><strong>', $txt['attachment_manager_total_avatars'], ':</strong></dt><dd>', $context['num_avatars'], '</dd>
-					<dt><strong>', $txt['attachmentdir_size' . ($context['attach_multiple_dirs'] ? '_current' : '')], ':</strong></dt><dd>', $context['attachment_total_size'], ' ', $txt['kilobyte'], '</dd>
-					<dt><strong>', $txt['attachment_space' . ($context['attach_multiple_dirs'] ? '_current' : '')], ':</strong></dt><dd>', isset($context['attachment_space']) ? $context['attachment_space'] . ' ' . $txt['kilobyte'] : $txt['attachmentdir_size_not_set'], '</dd>
-				</dl>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<br class="clear" />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['attachment_integrity_check'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=manageattachments;sa=repair;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['attachment_integrity_check_desc'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" name="repair" value="', $txt['attachment_check_now'], '" class="button_submit" />
-					<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<br class="clear" />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['attachment_pruning'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=manageattachments" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');" style="margin: 0 0 2ex 0;">
-					', $txt['attachment_remove_old'], ' <input type="text" name="age" value="25" size="4" class="input_text" /> ', $txt['days_word'], '<br />
-					', $txt['attachment_pruning_message'], ': <input type="text" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br />
-					<input type="submit" name="remove" value="', $txt['remove'], '" class="button_submit" />
-					<input type="hidden" name="type" value="attachments" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="sa" value="byAge" />
-					<br class="clear_right" />
-				</form>
-				<hr />
-				<form action="', $scripturl, '?action=admin;area=manageattachments" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');" style="margin: 0 0 2ex 0;">
-					', $txt['attachment_remove_size'], ' <input type="text" name="size" id="size" value="100" size="4" class="input_text" /> ', $txt['kilobyte'], '<br />
-					', $txt['attachment_pruning_message'], ': <input type="text" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br />
-					<input type="submit" name="remove" value="', $txt['remove'], '" class="button_submit" />
-					<input type="hidden" name="type" value="attachments" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="sa" value="bySize" />
-					<br class="clear_right" />
-				</form>
-				<hr />
-				<form action="', $scripturl, '?action=admin;area=manageattachments" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');" style="margin: 0 0 2ex 0;">
-					', $txt['attachment_manager_avatars_older'], ' <input type="text" name="age" value="45" size="4" class="input_text" /> ', $txt['days_word'], '<br />
-					<input type="submit" name="remove" value="', $txt['remove'], '" class="button_submit" />
-					<input type="hidden" name="type" value="avatars" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="sa" value="byAge" />
-					<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_attachment_repair()
-{
-	global $context, $txt, $scripturl, $settings;
-
-	// If we've completed just let them know!
-	if ($context['completed'])
-	{
-		echo '
-	<div id="manage_attachments">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['repair_attachments_complete'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				', $txt['repair_attachments_complete_desc'], '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-	}
-
-	// What about if no errors were even found?
-	elseif (!$context['errors_found'])
-	{
-		echo '
-	<div id="manage_attachments">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['repair_attachments_complete'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				', $txt['repair_attachments_no_errors'], '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-	}
-	// Otherwise, I'm sad to say, we have a problem!
-	else
-	{
-		echo '
-	<div id="manage_attachments">
-		<form action="', $scripturl, '?action=admin;area=manageattachments;sa=repair;fixErrors=1;step=0;substep=0;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['repair_attachments'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['repair_attachments_error_desc'], '</p>';
-
-		// Loop through each error reporting the status
-		foreach ($context['repair_errors'] as $error => $number)
-		{
-			if (!empty($number))
-			echo '
-					<input type="checkbox" name="to_fix[]" id="', $error, '" value="', $error, '" class="input_check" />
-					<label for="', $error, '">', sprintf($txt['attach_repair_' . $error], $number), '</label><br />';
-		}
-
-		echo '		<br />
-					<input type="submit" value="', $txt['repair_attachments_continue'], '" class="button_submit" />
-					<input type="submit" name="cancel" value="', $txt['repair_attachments_cancel'], '" class="button_submit" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-	}
-}
-
-function template_attachment_paths()
-{
-	template_show_list('attach_paths');
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Template template wraps around the simple settings page to add javascript functionality.
+function template_avatar_settings_above()
+{
+}
+
+function template_avatar_settings_below()
+{
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+	var fUpdateStatus = function ()
+	{
+		document.getElementById("avatar_max_width_external").disabled = document.getElementById("avatar_download_external").checked;
+		document.getElementById("avatar_max_height_external").disabled = document.getElementById("avatar_download_external").checked;
+		document.getElementById("avatar_action_too_large").disabled = document.getElementById("avatar_download_external").checked;
+		document.getElementById("custom_avatar_dir").disabled = document.getElementById("custom_avatar_enabled").value == 0;
+		document.getElementById("custom_avatar_url").disabled = document.getElementById("custom_avatar_enabled").value == 0;
+
+	}
+	addLoadEvent(fUpdateStatus);
+// ]]></script>
+';
+}
+
+function template_browse()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="manage_attachments">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['attachment_manager_browse_files'], '</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<a href="', $scripturl, '?action=admin;area=manageattachments;sa=browse">', $context['browse_type'] === 'attachments' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;" /> ' : '', $txt['attachment_manager_attachments'], '</a> |
+				<a href="', $scripturl, '?action=admin;area=manageattachments;sa=browse;avatars">', $context['browse_type'] === 'avatars' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;" /> ' : '', $txt['attachment_manager_avatars'], '</a> |
+				<a href="', $scripturl, '?action=admin;area=manageattachments;sa=browse;thumbs">', $context['browse_type'] === 'thumbs' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;" /> ' : '', $txt['attachment_manager_thumbs'], '</a>
+			</div>
+		</div>
+	</div>';
+
+	template_show_list('file_list');
+	echo '
+	<br class="clear" />';
+
+}
+
+function template_maintenance()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="manage_attachments">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['attachment_stats'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">
+					<dt><strong>', $txt['attachment_total'], ':</strong></dt><dd>', $context['num_attachments'], '</dd>
+					<dt><strong>', $txt['attachment_manager_total_avatars'], ':</strong></dt><dd>', $context['num_avatars'], '</dd>
+					<dt><strong>', $txt['attachmentdir_size' . ($context['attach_multiple_dirs'] ? '_current' : '')], ':</strong></dt><dd>', $context['attachment_total_size'], ' ', $txt['kilobyte'], '</dd>
+					<dt><strong>', $txt['attachment_space' . ($context['attach_multiple_dirs'] ? '_current' : '')], ':</strong></dt><dd>', isset($context['attachment_space']) ? $context['attachment_space'] . ' ' . $txt['kilobyte'] : $txt['attachmentdir_size_not_set'], '</dd>
+				</dl>
+			</div>
+		</div>
+		<br class="clear" />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['attachment_integrity_check'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=manageattachments;sa=repair;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['attachment_integrity_check_desc'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" name="repair" value="', $txt['attachment_check_now'], '" class="button_submit" />
+					<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+		<br class="clear" />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['attachment_pruning'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=manageattachments" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');" style="margin: 0 0 2ex 0;">
+					', $txt['attachment_remove_old'], ' <input type="text" name="age" value="25" size="4" class="input_text" /> ', $txt['days_word'], '<br />
+					', $txt['attachment_pruning_message'], ': <input type="text" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br />
+					<input type="submit" name="remove" value="', $txt['remove'], '" class="button_submit" />
+					<input type="hidden" name="type" value="attachments" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="sa" value="byAge" />
+					<br class="clear_right" />
+				</form>
+				<hr />
+				<form action="', $scripturl, '?action=admin;area=manageattachments" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');" style="margin: 0 0 2ex 0;">
+					', $txt['attachment_remove_size'], ' <input type="text" name="size" id="size" value="100" size="4" class="input_text" /> ', $txt['kilobyte'], '<br />
+					', $txt['attachment_pruning_message'], ': <input type="text" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br />
+					<input type="submit" name="remove" value="', $txt['remove'], '" class="button_submit" />
+					<input type="hidden" name="type" value="attachments" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="sa" value="bySize" />
+					<br class="clear_right" />
+				</form>
+				<hr />
+				<form action="', $scripturl, '?action=admin;area=manageattachments" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');" style="margin: 0 0 2ex 0;">
+					', $txt['attachment_manager_avatars_older'], ' <input type="text" name="age" value="45" size="4" class="input_text" /> ', $txt['days_word'], '<br />
+					<input type="submit" name="remove" value="', $txt['remove'], '" class="button_submit" />
+					<input type="hidden" name="type" value="avatars" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="sa" value="byAge" />
+					<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_attachment_repair()
+{
+	global $context, $txt, $scripturl, $settings;
+
+	// If we've completed just let them know!
+	if ($context['completed'])
+	{
+		echo '
+	<div id="manage_attachments">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['repair_attachments_complete'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				', $txt['repair_attachments_complete_desc'], '
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+	}
+
+	// What about if no errors were even found?
+	elseif (!$context['errors_found'])
+	{
+		echo '
+	<div id="manage_attachments">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['repair_attachments_complete'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				', $txt['repair_attachments_no_errors'], '
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+	}
+	// Otherwise, I'm sad to say, we have a problem!
+	else
+	{
+		echo '
+	<div id="manage_attachments">
+		<form action="', $scripturl, '?action=admin;area=manageattachments;sa=repair;fixErrors=1;step=0;substep=0;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['repair_attachments'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>', $txt['repair_attachments_error_desc'], '</p>';
+
+		// Loop through each error reporting the status
+		foreach ($context['repair_errors'] as $error => $number)
+		{
+			if (!empty($number))
+			echo '
+					<input type="checkbox" name="to_fix[]" id="', $error, '" value="', $error, '" class="input_check" />
+					<label for="', $error, '">', sprintf($txt['attach_repair_' . $error], $number), '</label><br />';
+		}
+
+		echo '		<br />
+					<input type="submit" value="', $txt['repair_attachments_continue'], '" class="button_submit" />
+					<input type="submit" name="cancel" value="', $txt['repair_attachments_cancel'], '" class="button_submit" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+	}
+}
+
+function template_attachment_paths()
+{
+	template_show_list('attach_paths');
+}
+
 ?>

+ 364 - 368
Themes/default/ManageBans.template.php

@@ -1,369 +1,365 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_ban_edit()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="manage_bans">
-
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', $context['ban']['is_new'] ? $txt['ban_add_new'] : $txt['ban_edit'] . ' \'' . $context['ban']['name'] . '\'', '
-			</h3>
-		</div>';
-
-	if ($context['ban']['is_new'])
-		echo '
-		<div class="information">', $txt['ban_add_notes'], '</div>';
-
-	echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=ban;sa=edit" method="post" accept-charset="', $context['character_set'], '" onsubmit="if (this.ban_name.value == \'\') {alert(\'', $txt['ban_name_empty'], '\'); return false;} if (this.partial_ban.checked &amp;&amp; !(this.cannot_post.checked || this.cannot_register.checked || this.cannot_login.checked)) {alert(\'', $txt['ban_restriction_empty'], '\'); return false;}">
-					<dl class="settings">
-						<dt>
-							<strong><label for="ban_name">', $txt['ban_name'], ':</label></strong>
-						</dt>
-						<dd>
-							<input type="text" name="ban_name" id="ban_name" value="', $context['ban']['name'], '" size="47" maxlength="60" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="reason">', $txt['ban_reason'], ':</label></strong><br />
-							<span class="smalltext">', $txt['ban_reason_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea name="reason" id="reason" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['reason'], '</textarea>
-						</dd>
-						<dt>
-							<strong><label for="ban_notes">', $txt['ban_notes'], ':</label></strong><br />
-							<span class="smalltext">', $txt['ban_notes_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea name="notes" id="ban_notes" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['notes'], '</textarea>
-						</dd>
-					</dl>
-					<fieldset class="ban_settings floatleft">
-						<legend>
-							', $txt['ban_expiration'], '
-						</legend>
-						<input type="radio" name="expiration" value="never" id="never_expires" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'never' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="never_expires">', $txt['never'], '</label><br />
-						<input type="radio" name="expiration" value="one_day" id="expires_one_day" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'still_active_but_we_re_counting_the_days' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="expires_one_day">', $txt['ban_will_expire_within'], '</label>: <input type="text" name="expire_date" id="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" class="input_text" /> ', $txt['ban_days'], '<br />
-						<input type="radio" name="expiration" value="expired" id="already_expired" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'expired' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="already_expired">', $txt['ban_expired'], '</label>
-					</fieldset>
-					<fieldset class="ban_settings floatright">
-						<legend>
-							', $txt['ban_restriction'], '
-						</legend>
-						<input type="radio" name="full_ban" id="full_ban" value="1" onclick="fUpdateStatus();"', $context['ban']['cannot']['access'] ? ' checked="checked"' : '', ' class="input_radio" /> <label for="full_ban">', $txt['ban_full_ban'], '</label><br />
-						<input type="radio" name="full_ban" id="partial_ban" value="0" onclick="fUpdateStatus();"', !$context['ban']['cannot']['access'] ? ' checked="checked"' : '', ' class="input_radio" /> <label for="partial_ban">', $txt['ban_partial_ban'], '</label><br />
-						<input type="checkbox" name="cannot_post" id="cannot_post" value="1"', $context['ban']['cannot']['post'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_post">', $txt['ban_cannot_post'], '</label> (<a href="', $scripturl, '?action=helpadmin;help=ban_cannot_post" onclick="return reqWin(this.href);">?</a>)<br />
-						<input type="checkbox" name="cannot_register" id="cannot_register" value="1"', $context['ban']['cannot']['register'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_register">', $txt['ban_cannot_register'], '</label><br />
-						<input type="checkbox" name="cannot_login" id="cannot_login" value="1"', $context['ban']['cannot']['login'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_login">', $txt['ban_cannot_login'], '</label><br />
-					</fieldset>
-					<br class="clear_right" />';
-
-	if (!empty($context['ban_suggestions']))
-	{
-		echo '
-					<fieldset>
-						<legend>
-							', $txt['ban_triggers'], '
-						</legend>
-						<dl class="settings">
-							<dt>
-								<input type="checkbox" name="ban_suggestion[]" id="main_ip_check" value="main_ip" class="input_check" />
-								<label for="main_ip_check">', $txt['ban_on_ip'], '</label>
-							</dt>
-							<dd>
-								<input type="text" name="main_ip" value="', $context['ban_suggestions']['main_ip'], '" size="44" onfocus="document.getElementById(\'main_ip_check\').checked = true;" class="input_text" />
-							</dd>';
-
-		if (empty($modSettings['disableHostnameLookup']))
-			echo '
-							<dt>
-								<input type="checkbox" name="ban_suggestion[]" id="hostname_check" value="hostname" class="input_check" />
-								<label for="hostname_check">', $txt['ban_on_hostname'], '</label>
-							</dt>
-							<dd>
-								<input type="text" name="hostname" value="', $context['ban_suggestions']['hostname'], '" size="44" onfocus="document.getElementById(\'hostname_check\').checked = true;" class="input_text" />
-							</dd>';
-
-		echo '
-							<dt>
-								<input type="checkbox" name="ban_suggestion[]" id="email_check" value="email" class="input_check" checked="checked" />
-								<label for="email_check">', $txt['ban_on_email'], '</label>
-							</dt>
-							<dd>
-								<input type="text" name="email" value="', $context['ban_suggestions']['email'], '" size="44" onfocus="document.getElementById(\'email_check\').checked = true;" class="input_text" />
-							</dd>
-							<dt>
-								<input type="checkbox" name="ban_suggestion[]" id="user_check" value="user" class="input_check" checked="checked" />
-								<label for="user_check">', $txt['ban_on_username'], '</label>:
-							</dt>
-							<dd>';
-
-		if (empty($context['ban_suggestions']['member']['id']))
-			echo '
-								<input type="text" name="user" id="user" value="" size="44" class="input_text" />';
-		else
-			echo '
-								', $context['ban_suggestions']['member']['link'], '
-								<input type="hidden" name="bannedUser" value="', $context['ban_suggestions']['member']['id'], '" />';
-		echo '
-							</dd>';
-
-		if (!empty($context['ban_suggestions']['message_ips']))
-		{
-			echo '
-						</dl>
-						<div>', $txt['ips_in_messages'], ':</div>
-						<dl class="settings">';
-
-			foreach ($context['ban_suggestions']['message_ips'] as $ip)
-				echo '
-							<dt>
-								<input type="checkbox" name="ban_suggestion[ips][]" value="', $ip, '" class="input_check" />
-							</dt>
-							<dd>
-								', $ip, '
-							</dd>';
-		}
-
-		if (!empty($context['ban_suggestions']['error_ips']))
-		{
-			echo '
-						</dl>
-						<div>', $txt['ips_in_errors'], '</div>
-						<dl class="settings">';
-
-			foreach ($context['ban_suggestions']['error_ips'] as $ip)
-				echo '
-							<dt>
-								<input type="checkbox" name="ban_suggestion[ips][]" value="', $ip, '" class="input_check" />
-							</dt>
-							<dd>
-								', $ip, '
-							</dd>';
-		}
-
-		echo '
-							</dl>
-						</fieldset>';
-	}
-
-	echo '
-						<hr class="hrcolor" />
-						<input type="submit" name="', $context['ban']['is_new'] ? 'add_ban' : 'modify_ban', '" value="', $context['ban']['is_new'] ? $txt['ban_add'] : $txt['ban_modify'], '" class="button_submit" />
-						<input type="hidden" name="old_expire" value="', $context['ban']['expiration']['days'], '" />
-						<input type="hidden" name="bg" value="', $context['ban']['id'], '" />
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '" />
-						<br class="clear_right" />
-					</form>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	if (!$context['ban']['is_new'] && empty($context['ban_suggestions']))
-	{
-		echo '
-			<br />
-			<form action="', $scripturl, '?action=admin;area=ban;sa=edit" method="post" accept-charset="', $context['character_set'], '" style="padding: 0px;margin: 0px;" onsubmit="return confirm(\'', $txt['ban_remove_selected_triggers_confirm'], '\');">
-				<table class="table_grid" width="100%">
-					<thead>
-						<tr class="catbg">
-							<th scope="col" class="first_th" width="65%" align="left">', $txt['ban_banned_entity'], '</th>
-							<th scope="col" width="15%" align="center">', $txt['ban_hits'], '</th>
-							<th scope="col" width="15%" align="center">', $txt['ban_actions'], '</th>
-							<th scope="col" class="last_th" width="5%" align="center"><input type="checkbox" onclick="invertAll(this, this.form, \'ban_items\');" class="input_check" /></th>
-						</tr>
-					</thead>
-					<tbody>';
-		if (empty($context['ban_items']))
-			echo '
-						<tr class="windowbg2">
-							<td colspan="4">(', $txt['ban_no_triggers'], ')</td>
-						</tr>';
-		else
-		{
-			$alternate = true;
-			foreach ($context['ban_items'] as $ban_item)
-			{
-				echo '
-						<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" align="left">
-							<td>';
-				if ($ban_item['type'] == 'ip')
-					echo '		<strong>', $txt['ip'], ':</strong>&nbsp;', $ban_item['ip'];
-				elseif ($ban_item['type'] == 'hostname')
-					echo '		<strong>', $txt['hostname'], ':</strong>&nbsp;', $ban_item['hostname'];
-				elseif ($ban_item['type'] == 'email')
-					echo '		<strong>', $txt['email'], ':</strong>&nbsp;', $ban_item['email'];
-				elseif ($ban_item['type'] == 'user')
-					echo '		<strong>', $txt['username'], ':</strong>&nbsp;', $ban_item['user']['link'];
-				echo '
-							</td>
-							<td align="center">', $ban_item['hits'], '</td>
-							<td align="center"><a href="', $scripturl, '?action=admin;area=ban;sa=edittrigger;bg=', $context['ban']['id'], ';bi=', $ban_item['id'], '">', $txt['ban_edit_trigger'], '</a></td>
-							<td align="center"><input type="checkbox" name="ban_items[]" value="', $ban_item['id'], '" class="input_check" /></td>
-						</tr>';
-				$alternate = !$alternate;
-			}
-		}
-
-		echo '
-					</tbody>
-				</table>
-				<div class="flow_auto">
-					<div class="floatright">
-						<div class="additional_row">
-							<input type="submit" name="remove_selection" value="', $txt['ban_remove_selected_triggers'], '" class="button_submit" />
-							<a class="button_link" href="', $scripturl, '?action=admin;area=ban;sa=edittrigger;bg=', $context['ban']['id'], '">', $txt['ban_add_trigger'], '</a>
-						</div>
-					</div>
-				</div>
-				<br class="clear" />
-				<input type="hidden" name="bg" value="', $context['ban']['id'], '" />
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '" />
-			</form>';
-
-	}
-
-	echo '
-	</div>
-	<br class="clear" />
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var fUpdateStatus = function ()
-		{
-			document.getElementById("expire_date").disabled = !document.getElementById("expires_one_day").checked;
-			document.getElementById("cannot_post").disabled = document.getElementById("full_ban").checked;
-			document.getElementById("cannot_register").disabled = document.getElementById("full_ban").checked;
-			document.getElementById("cannot_login").disabled = document.getElementById("full_ban").checked;
-		}
-		addLoadEvent(fUpdateStatus);';
-
-	// Auto suggest only needed for adding new bans, not editing
-	if ($context['ban']['is_new'] && empty($_REQUEST['u']))
-		echo '
-			var oAddMemberSuggest = new smc_AutoSuggest({
-			sSelf: \'oAddMemberSuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sSuggestId: \'user\',
-			sControlId: \'user\',
-			sSearchType: \'member\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			bItemList: false
-		});
-
-		function onUpdateName(oAutoSuggest)
-		{
-			document.getElementById(\'user_check\').checked = true;
-			return true;
-		}
-		oAddMemberSuggest.registerCallback(\'onBeforeUpdate\', \'onUpdateName\');';
-
-	echo '// ]]></script>';
-}
-
-function template_ban_edit_trigger()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="manage_bans">
-		<form action="', $scripturl, '?action=admin;area=ban;sa=edit" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $context['ban_trigger']['is_new'] ? $txt['ban_add_trigger'] : $txt['ban_edit_trigger_title'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<fieldset>
-						<legend>
-							', $txt['ban_triggers'], '
-						</legend>
-						<dl class="settings">
-							<dt>
-								<input type="radio" name="bantype" value="ip_ban"', $context['ban_trigger']['ip']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
-								', $txt['ban_on_ip'], '
-							</dt>
-							<dd>
-								<input type="text" name="ip" value="', $context['ban_trigger']['ip']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'ip_ban\');" class="input_text" />
-							</dd>';
-				if (empty($modSettings['disableHostnameLookup']))
-				echo '
-							<dt>
-								<input type="radio" name="bantype" value="hostname_ban"', $context['ban_trigger']['hostname']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
-								', $txt['ban_on_hostname'], '
-							</dt>
-							<dd>
-								<input type="text" name="hostname" value="', $context['ban_trigger']['hostname']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'hostname_ban\');" class="input_text" />
-							</dd>';
-				echo '
-							<dt>
-								<input type="radio" name="bantype" value="email_ban"', $context['ban_trigger']['email']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
-								', $txt['ban_on_email'], '
-							</dt>
-							<dd>
-								<input type="text" name="email" value="', $context['ban_trigger']['email']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'email_ban\');" class="input_text" />
-							</dd>
-							<dt>
-								<input type="radio" name="bantype" value="user_ban"', $context['ban_trigger']['banneduser']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
-								', $txt['ban_on_username'], '
-							</dt>
-							<dd>
-								<input type="text" name="user" id="user" value="', $context['ban_trigger']['banneduser']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'user_ban\');" class="input_text" />
-							</dd>
-						</dl>
-					</fieldset>
-					<input type="submit" name="', $context['ban_trigger']['is_new'] ? 'add_new_trigger' : 'edit_trigger', '" value="', $context['ban_trigger']['is_new'] ? $txt['ban_add_trigger_submit'] : $txt['ban_edit_trigger_submit'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="bi" value="' . $context['ban_trigger']['id'] . '" />
-			<input type="hidden" name="bg" value="' . $context['ban_trigger']['group'] . '" />
-			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
-			<input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oAddMemberSuggest = new smc_AutoSuggest({
-			sSelf: \'oAddMemberSuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sSuggestId: \'username\',
-			sControlId: \'user\',
-			sSearchType: \'member\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			bItemList: false
-		});
-
-		function onUpdateName(oAutoSuggest)
-		{
-			selectRadioByName(oAutoSuggest.oTextHandle.form.bantype, \'user_ban\');
-			return true;
-		}
-		oAddMemberSuggest.registerCallback(\'onBeforeUpdate\', \'onUpdateName\');
-	// ]]></script>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_ban_edit()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="manage_bans">
+
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $context['ban']['is_new'] ? $txt['ban_add_new'] : $txt['ban_edit'] . ' \'' . $context['ban']['name'] . '\'', '
+			</h3>
+		</div>';
+
+	if ($context['ban']['is_new'])
+		echo '
+		<div class="information">', $txt['ban_add_notes'], '</div>';
+
+	echo '
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=ban;sa=edit" method="post" accept-charset="', $context['character_set'], '" onsubmit="if (this.ban_name.value == \'\') {alert(\'', $txt['ban_name_empty'], '\'); return false;} if (this.partial_ban.checked &amp;&amp; !(this.cannot_post.checked || this.cannot_register.checked || this.cannot_login.checked)) {alert(\'', $txt['ban_restriction_empty'], '\'); return false;}">
+					<dl class="settings">
+						<dt>
+							<strong><label for="ban_name">', $txt['ban_name'], ':</label></strong>
+						</dt>
+						<dd>
+							<input type="text" name="ban_name" id="ban_name" value="', $context['ban']['name'], '" size="47" maxlength="60" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="reason">', $txt['ban_reason'], ':</label></strong><br />
+							<span class="smalltext">', $txt['ban_reason_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="reason" id="reason" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['reason'], '</textarea>
+						</dd>
+						<dt>
+							<strong><label for="ban_notes">', $txt['ban_notes'], ':</label></strong><br />
+							<span class="smalltext">', $txt['ban_notes_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="notes" id="ban_notes" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['notes'], '</textarea>
+						</dd>
+					</dl>
+					<fieldset class="ban_settings floatleft">
+						<legend>
+							', $txt['ban_expiration'], '
+						</legend>
+						<input type="radio" name="expiration" value="never" id="never_expires" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'never' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="never_expires">', $txt['never'], '</label><br />
+						<input type="radio" name="expiration" value="one_day" id="expires_one_day" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'still_active_but_we_re_counting_the_days' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="expires_one_day">', $txt['ban_will_expire_within'], '</label>: <input type="text" name="expire_date" id="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" class="input_text" /> ', $txt['ban_days'], '<br />
+						<input type="radio" name="expiration" value="expired" id="already_expired" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'expired' ? ' checked="checked"' : '', ' class="input_radio" /> <label for="already_expired">', $txt['ban_expired'], '</label>
+					</fieldset>
+					<fieldset class="ban_settings floatright">
+						<legend>
+							', $txt['ban_restriction'], '
+						</legend>
+						<input type="radio" name="full_ban" id="full_ban" value="1" onclick="fUpdateStatus();"', $context['ban']['cannot']['access'] ? ' checked="checked"' : '', ' class="input_radio" /> <label for="full_ban">', $txt['ban_full_ban'], '</label><br />
+						<input type="radio" name="full_ban" id="partial_ban" value="0" onclick="fUpdateStatus();"', !$context['ban']['cannot']['access'] ? ' checked="checked"' : '', ' class="input_radio" /> <label for="partial_ban">', $txt['ban_partial_ban'], '</label><br />
+						<input type="checkbox" name="cannot_post" id="cannot_post" value="1"', $context['ban']['cannot']['post'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_post">', $txt['ban_cannot_post'], '</label> (<a href="', $scripturl, '?action=helpadmin;help=ban_cannot_post" onclick="return reqWin(this.href);">?</a>)<br />
+						<input type="checkbox" name="cannot_register" id="cannot_register" value="1"', $context['ban']['cannot']['register'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_register">', $txt['ban_cannot_register'], '</label><br />
+						<input type="checkbox" name="cannot_login" id="cannot_login" value="1"', $context['ban']['cannot']['login'] ? ' checked="checked"' : '', ' class="ban_restriction input_radio" /> <label for="cannot_login">', $txt['ban_cannot_login'], '</label><br />
+					</fieldset>
+					<br class="clear_right" />';
+
+	if (!empty($context['ban_suggestions']))
+	{
+		echo '
+					<fieldset>
+						<legend>
+							', $txt['ban_triggers'], '
+						</legend>
+						<dl class="settings">
+							<dt>
+								<input type="checkbox" name="ban_suggestion[]" id="main_ip_check" value="main_ip" class="input_check" />
+								<label for="main_ip_check">', $txt['ban_on_ip'], '</label>
+							</dt>
+							<dd>
+								<input type="text" name="main_ip" value="', $context['ban_suggestions']['main_ip'], '" size="44" onfocus="document.getElementById(\'main_ip_check\').checked = true;" class="input_text" />
+							</dd>';
+
+		if (empty($modSettings['disableHostnameLookup']))
+			echo '
+							<dt>
+								<input type="checkbox" name="ban_suggestion[]" id="hostname_check" value="hostname" class="input_check" />
+								<label for="hostname_check">', $txt['ban_on_hostname'], '</label>
+							</dt>
+							<dd>
+								<input type="text" name="hostname" value="', $context['ban_suggestions']['hostname'], '" size="44" onfocus="document.getElementById(\'hostname_check\').checked = true;" class="input_text" />
+							</dd>';
+
+		echo '
+							<dt>
+								<input type="checkbox" name="ban_suggestion[]" id="email_check" value="email" class="input_check" checked="checked" />
+								<label for="email_check">', $txt['ban_on_email'], '</label>
+							</dt>
+							<dd>
+								<input type="text" name="email" value="', $context['ban_suggestions']['email'], '" size="44" onfocus="document.getElementById(\'email_check\').checked = true;" class="input_text" />
+							</dd>
+							<dt>
+								<input type="checkbox" name="ban_suggestion[]" id="user_check" value="user" class="input_check" checked="checked" />
+								<label for="user_check">', $txt['ban_on_username'], '</label>:
+							</dt>
+							<dd>';
+
+		if (empty($context['ban_suggestions']['member']['id']))
+			echo '
+								<input type="text" name="user" id="user" value="" size="44" class="input_text" />';
+		else
+			echo '
+								', $context['ban_suggestions']['member']['link'], '
+								<input type="hidden" name="bannedUser" value="', $context['ban_suggestions']['member']['id'], '" />';
+		echo '
+							</dd>';
+
+		if (!empty($context['ban_suggestions']['message_ips']))
+		{
+			echo '
+						</dl>
+						<div>', $txt['ips_in_messages'], ':</div>
+						<dl class="settings">';
+
+			foreach ($context['ban_suggestions']['message_ips'] as $ip)
+				echo '
+							<dt>
+								<input type="checkbox" name="ban_suggestion[ips][]" value="', $ip, '" class="input_check" />
+							</dt>
+							<dd>
+								', $ip, '
+							</dd>';
+		}
+
+		if (!empty($context['ban_suggestions']['error_ips']))
+		{
+			echo '
+						</dl>
+						<div>', $txt['ips_in_errors'], '</div>
+						<dl class="settings">';
+
+			foreach ($context['ban_suggestions']['error_ips'] as $ip)
+				echo '
+							<dt>
+								<input type="checkbox" name="ban_suggestion[ips][]" value="', $ip, '" class="input_check" />
+							</dt>
+							<dd>
+								', $ip, '
+							</dd>';
+		}
+
+		echo '
+							</dl>
+						</fieldset>';
+	}
+
+	echo '
+						<hr class="hrcolor" />
+						<input type="submit" name="', $context['ban']['is_new'] ? 'add_ban' : 'modify_ban', '" value="', $context['ban']['is_new'] ? $txt['ban_add'] : $txt['ban_modify'], '" class="button_submit" />
+						<input type="hidden" name="old_expire" value="', $context['ban']['expiration']['days'], '" />
+						<input type="hidden" name="bg" value="', $context['ban']['id'], '" />
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '" />
+						<br class="clear_right" />
+					</form>
+				</div>
+			</div>';
+
+	if (!$context['ban']['is_new'] && empty($context['ban_suggestions']))
+	{
+		echo '
+			<br />
+			<form action="', $scripturl, '?action=admin;area=ban;sa=edit" method="post" accept-charset="', $context['character_set'], '" style="padding: 0px;margin: 0px;" onsubmit="return confirm(\'', $txt['ban_remove_selected_triggers_confirm'], '\');">
+				<table class="table_grid" width="100%">
+					<thead>
+						<tr class="catbg">
+							<th scope="col" class="first_th" width="65%" align="left">', $txt['ban_banned_entity'], '</th>
+							<th scope="col" width="15%" align="center">', $txt['ban_hits'], '</th>
+							<th scope="col" width="15%" align="center">', $txt['ban_actions'], '</th>
+							<th scope="col" class="last_th" width="5%" align="center"><input type="checkbox" onclick="invertAll(this, this.form, \'ban_items\');" class="input_check" /></th>
+						</tr>
+					</thead>
+					<tbody>';
+		if (empty($context['ban_items']))
+			echo '
+						<tr class="windowbg2">
+							<td colspan="4">(', $txt['ban_no_triggers'], ')</td>
+						</tr>';
+		else
+		{
+			$alternate = true;
+			foreach ($context['ban_items'] as $ban_item)
+			{
+				echo '
+						<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" align="left">
+							<td>';
+				if ($ban_item['type'] == 'ip')
+					echo '		<strong>', $txt['ip'], ':</strong>&nbsp;', $ban_item['ip'];
+				elseif ($ban_item['type'] == 'hostname')
+					echo '		<strong>', $txt['hostname'], ':</strong>&nbsp;', $ban_item['hostname'];
+				elseif ($ban_item['type'] == 'email')
+					echo '		<strong>', $txt['email'], ':</strong>&nbsp;', $ban_item['email'];
+				elseif ($ban_item['type'] == 'user')
+					echo '		<strong>', $txt['username'], ':</strong>&nbsp;', $ban_item['user']['link'];
+				echo '
+							</td>
+							<td align="center">', $ban_item['hits'], '</td>
+							<td align="center"><a href="', $scripturl, '?action=admin;area=ban;sa=edittrigger;bg=', $context['ban']['id'], ';bi=', $ban_item['id'], '">', $txt['ban_edit_trigger'], '</a></td>
+							<td align="center"><input type="checkbox" name="ban_items[]" value="', $ban_item['id'], '" class="input_check" /></td>
+						</tr>';
+				$alternate = !$alternate;
+			}
+		}
+
+		echo '
+					</tbody>
+				</table>
+				<div class="flow_auto">
+					<div class="floatright">
+						<div class="additional_row">
+							<input type="submit" name="remove_selection" value="', $txt['ban_remove_selected_triggers'], '" class="button_submit" />
+							<a class="button_link" href="', $scripturl, '?action=admin;area=ban;sa=edittrigger;bg=', $context['ban']['id'], '">', $txt['ban_add_trigger'], '</a>
+						</div>
+					</div>
+				</div>
+				<br class="clear" />
+				<input type="hidden" name="bg" value="', $context['ban']['id'], '" />
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '" />
+			</form>';
+
+	}
+
+	echo '
+	</div>
+	<br class="clear" />
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var fUpdateStatus = function ()
+		{
+			document.getElementById("expire_date").disabled = !document.getElementById("expires_one_day").checked;
+			document.getElementById("cannot_post").disabled = document.getElementById("full_ban").checked;
+			document.getElementById("cannot_register").disabled = document.getElementById("full_ban").checked;
+			document.getElementById("cannot_login").disabled = document.getElementById("full_ban").checked;
+		}
+		addLoadEvent(fUpdateStatus);';
+
+	// Auto suggest only needed for adding new bans, not editing
+	if ($context['ban']['is_new'] && empty($_REQUEST['u']))
+		echo '
+			var oAddMemberSuggest = new smc_AutoSuggest({
+			sSelf: \'oAddMemberSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'user\',
+			sControlId: \'user\',
+			sSearchType: \'member\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			bItemList: false
+		});
+
+		function onUpdateName(oAutoSuggest)
+		{
+			document.getElementById(\'user_check\').checked = true;
+			return true;
+		}
+		oAddMemberSuggest.registerCallback(\'onBeforeUpdate\', \'onUpdateName\');';
+
+	echo '// ]]></script>';
+}
+
+function template_ban_edit_trigger()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="manage_bans">
+		<form action="', $scripturl, '?action=admin;area=ban;sa=edit" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $context['ban_trigger']['is_new'] ? $txt['ban_add_trigger'] : $txt['ban_edit_trigger_title'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<fieldset>
+						<legend>
+							', $txt['ban_triggers'], '
+						</legend>
+						<dl class="settings">
+							<dt>
+								<input type="radio" name="bantype" value="ip_ban"', $context['ban_trigger']['ip']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
+								', $txt['ban_on_ip'], '
+							</dt>
+							<dd>
+								<input type="text" name="ip" value="', $context['ban_trigger']['ip']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'ip_ban\');" class="input_text" />
+							</dd>';
+				if (empty($modSettings['disableHostnameLookup']))
+				echo '
+							<dt>
+								<input type="radio" name="bantype" value="hostname_ban"', $context['ban_trigger']['hostname']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
+								', $txt['ban_on_hostname'], '
+							</dt>
+							<dd>
+								<input type="text" name="hostname" value="', $context['ban_trigger']['hostname']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'hostname_ban\');" class="input_text" />
+							</dd>';
+				echo '
+							<dt>
+								<input type="radio" name="bantype" value="email_ban"', $context['ban_trigger']['email']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
+								', $txt['ban_on_email'], '
+							</dt>
+							<dd>
+								<input type="text" name="email" value="', $context['ban_trigger']['email']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'email_ban\');" class="input_text" />
+							</dd>
+							<dt>
+								<input type="radio" name="bantype" value="user_ban"', $context['ban_trigger']['banneduser']['selected'] ? ' checked="checked"' : '', ' class="input_radio" />
+								', $txt['ban_on_username'], '
+							</dt>
+							<dd>
+								<input type="text" name="user" id="user" value="', $context['ban_trigger']['banneduser']['value'], '" size="50" onfocus="selectRadioByName(this.form.bantype, \'user_ban\');" class="input_text" />
+							</dd>
+						</dl>
+					</fieldset>
+					<input type="submit" name="', $context['ban_trigger']['is_new'] ? 'add_new_trigger' : 'edit_trigger', '" value="', $context['ban_trigger']['is_new'] ? $txt['ban_add_trigger_submit'] : $txt['ban_edit_trigger_submit'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="bi" value="' . $context['ban_trigger']['id'] . '" />
+			<input type="hidden" name="bg" value="' . $context['ban_trigger']['group'] . '" />
+			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
+			<input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oAddMemberSuggest = new smc_AutoSuggest({
+			sSelf: \'oAddMemberSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'username\',
+			sControlId: \'user\',
+			sSearchType: \'member\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			bItemList: false
+		});
+
+		function onUpdateName(oAutoSuggest)
+		{
+			selectRadioByName(oAutoSuggest.oTextHandle.form.bantype, \'user_ban\');
+			return true;
+		}
+		oAddMemberSuggest.registerCallback(\'onBeforeUpdate\', \'onUpdateName\');
+	// ]]></script>';
+}
+
 ?>

+ 689 - 705
Themes/default/ManageBoards.template.php

@@ -1,706 +1,690 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Template for listing all the current categories and boards.
-function template_main()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Table header.
-	echo '
-	<div id="manage_boards">
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['boardsEdit'], '</h3>
-		</div>';
-
-	if (!empty($context['move_board']))
-		echo '
-		<div class="information">
-			<p>', $context['move_title'], ' [<a href="', $scripturl, '?action=admin;area=manageboards">', $txt['mboards_cancel_moving'], '</a>]', '</p>
-		</div>';
-
-	// No categories so show a label.
-	if (empty($context['categories']))
-		echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content centertext">
-				', $txt['mboards_no_cats'], '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	// Loop through every category, listing the boards in each as we go.
-	foreach ($context['categories'] as $category)
-	{
-		// Link to modify the category.
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<a href="' . $scripturl . '?action=admin;area=manageboards;sa=cat;cat=' . $category['id'] . '">', $category['name'], '</a> <a href="' . $scripturl . '?action=admin;area=manageboards;sa=cat;cat=' . $category['id'] . '">', $txt['catModify'], '</a>
-				</h3>
-			</div>';
-
-		// Boards table header.
-		echo '
-		<form action="', $scripturl, '?action=admin;area=manageboards;sa=newboard;cat=', $category['id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<ul id="category_', $category['id'], '" class="reset nolist">';
-
-		if (!empty($category['move_link']))
-			echo '
-						<li><a href="', $category['move_link']['href'], '" title="', $category['move_link']['label'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $category['move_link']['label'], '" /></a></li>';
-
-		$alternate = false;
-
-		// List through every board in the category, printing its name and link to modify the board.
-		foreach ($category['boards'] as $board)
-		{
-
-			echo '
-						<li', !empty($modSettings['recycle_board']) && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board['id'] ? ' id="recycle_board"' : ' ', ' class="windowbg', $alternate ? '' : '2', '" style="padding-' . ($context['right_to_left'] ? 'right' : 'left') . ': ', 5 + 30 * $board['child_level'], 'px;', $board['move'] ? 'color: red;' : '', '"><span class="floatleft"><a href="', $scripturl, '?board=', $board['id'], '">', $board['name'], '</a>', !empty($modSettings['recycle_board']) && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board['id'] ? '<a href="' . $scripturl . '?action=admin;area=manageboards;sa=settings"> <img src="' . $settings['images_url'] . '/post/recycled.png" alt="' . $txt['recycle_board'] . '" /></a></span>' : '</span>', '
-							<span class="floatright">', $context['can_manage_permissions'] ? '<span class="modify_boards"><a href="' . $scripturl . '?action=admin;area=permissions;sa=index;pid=' . $board['permission_profile'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['mboards_permissions'] . '</a></span>' : '', '
-							<span class="modify_boards"><a href="', $scripturl, '?action=admin;area=manageboards;move=', $board['id'], '">', $txt['mboards_move'], '</a></span>
-							<span class="modify_boards"><a href="', $scripturl, '?action=admin;area=manageboards;sa=board;boardid=', $board['id'], '">', $txt['mboards_modify'], '</a></span></span><br style="clear: right;" />
-						</li>';
-
-			if (!empty($board['move_links']))
-			{
-				$alternate = !$alternate;
-
-				echo '
-						<li class="windowbg', $alternate ? '' : '2', '" style="padding-', $context['right_to_left'] ? 'right' : 'left', ': ', 5 + 30 * $board['move_links'][0]['child_level'], 'px;">';
-
-				foreach ($board['move_links'] as $link)
-					echo '
-							<a href="', $link['href'], '" class="move_links" title="', $link['label'], '"><img src="', $settings['images_url'], '/board_select_spot', $link['child_level'] > 0 ? '_child' : '', '.png" alt="', $link['label'], '" style="padding: 0px; margin: 0px;" /></a>';
-
-				echo '
-						</li>';
-			}
-			$alternate = !$alternate;
-		}
-
-		// Button to add a new board.
-		echo '
-					</ul>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['mboards_new_board'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-		<br class="clear" />';
-	}
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-// Template for editing/adding a category on the forum.
-function template_modify_category()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Print table header.
-	echo '
-	<div id="manage_boards">
-		<form action="', $scripturl, '?action=admin;area=manageboards;sa=cat2" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="cat" value="', $context['category']['id'], '" />
-				<div class="cat_bar">
-					<h3 class="catbg">
-					', isset($context['category']['is_new']) ? $txt['mboards_new_cat_name'] : $txt['catEdit'], '
-					</h3>
-				</div>
-				<div class="windowbg">
-					<span class="topslice"><span></span></span>
-					<div class="content">
-						<dl class="settings">';
-	// If this isn't the only category, let the user choose where this category should be positioned down the board index.
-	if (count($context['category_order']) > 1)
-	{
-		echo '
-						<dt><strong>', $txt['order'], ':</strong></dt>
-						<dd>
-							<select name="cat_order">';
-		// Print every existing category into a select box.
-		foreach ($context['category_order'] as $order)
-			echo '
-								<option', $order['selected'] ? ' selected="selected"' : '', ' value="', $order['id'], '">', $order['name'], '</option>';
-		echo '
-							</select>
-						</dd>';
-	}
-	// Allow the user to edit the category name and/or choose whether you can collapse the category.
-	echo '
-						<dt>
-							<strong>', $txt['full_name'], ':</strong><br />
-							<span class="smalltext">', $txt['name_on_display'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="cat_name" value="', $context['category']['editable_name'], '" size="30" tabindex="', $context['tabindex']++, '" class="input_text" />
-						</dd>
-						<dt>
-							<strong>' . $txt['collapse_enable'] . '</strong><br />
-							<span class="smalltext">' . $txt['collapse_desc'] . '</span>
-						</dt>
-						<dd>
-							<input type="checkbox" name="collapse"', $context['category']['can_collapse'] ? ' checked="checked"' : '', ' tabindex="', $context['tabindex']++, '" class="input_check" />
-						</dd>';
-
-	// Table footer.
-	echo '
-					</dl>
-					<hr class="hrcolor" />';
-
-	if (isset($context['category']['is_new']))
-		echo '
-						<input type="submit" name="add" value="', $txt['mboards_add_cat_button'], '" onclick="return !isEmptyText(this.form.cat_name);" tabindex="', $context['tabindex']++, '" class="button_submit" />';
-	else
-		echo '
-						<input type="submit" name="edit" value="', $txt['modify'], '" onclick="return !isEmptyText(this.form.cat_name);" tabindex="', $context['tabindex']++, '" class="button_submit" />
-						<input type="submit" name="delete" value="', $txt['mboards_delete_cat'], '" onclick="return confirm(\'', $txt['catConfirm'], '\');" class="button_submit" />';
-	echo '
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
-	if (!empty($context['token_check']))
-		echo '
-						<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	// If this category is empty we don't bother with the next confirmation screen.
-	if ($context['category']['is_empty'])
-		echo '
-						<input type="hidden" name="empty" value="1" />';
-
-	echo '
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// A template to confirm if a user wishes to delete a category - and whether they want to save the boards.
-function template_confirm_category_delete()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Print table header.
-	echo '
-	<div id="manage_boards">
-		<form action="', $scripturl, '?action=admin;area=manageboards;sa=cat2" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="cat" value="', $context['category']['id'], '" />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mboards_delete_cat'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['mboards_delete_cat_contains'], ':</p>
-					<ul>';
-
-	foreach ($context['category']['children'] as $child)
-		echo '
-						<li>', $child, '</li>';
-
-	echo '
-					</ul>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mboards_delete_what_do'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>
-						<label for="delete_action0"><input type="radio" id="delete_action0" name="delete_action" value="0" class="input_radio" checked="checked" />', $txt['mboards_delete_option1'], '</label><br />
-						<label for="delete_action1"><input type="radio" id="delete_action1" name="delete_action" value="1" class="input_radio"', count($context['category_order']) == 1 ? ' disabled="disabled"' : '', ' />', $txt['mboards_delete_option2'], '</label>:
-						<select name="cat_to" ', count($context['category_order']) == 1 ? 'disabled="disabled"' : '', '>';
-
-	foreach ($context['category_order'] as $cat)
-		if ($cat['id'] != 0)
-			echo '
-							<option value="', $cat['id'], '">', $cat['true_name'], '</option>';
-
-	echo '
-						</select>
-					</p>
-					<input type="submit" name="delete" value="', $txt['mboards_delete_confirm'], '" class="button_submit" />
-					<input type="submit" name="cancel" value="', $txt['mboards_delete_cancel'], '" class="button_submit" />
-					<input type="hidden" name="confirmation" value="1" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Below is the template for adding/editing an board on the forum.
-function template_modify_board()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// The main table header.
-	echo '
-	<div id="manage_boards">
-		<form action="', $scripturl, '?action=admin;area=manageboards;sa=board2" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="boardid" value="', $context['board']['id'], '" />
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', isset($context['board']['is_new']) ? $txt['mboards_new_board_name'] : $txt['boardsEdit'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-
-	// Option for choosing the category the board lives in.
-	echo '
-
-						<dt>
-							<strong>', $txt['mboards_category'], ':</strong>
-
-						</dt>
-						<dd>
-							<select name="new_cat" onchange="if (this.form.order) {this.form.order.disabled = this.options[this.selectedIndex].value != 0; this.form.board_order.disabled = this.options[this.selectedIndex].value != 0 || this.form.order.options[this.form.order.selectedIndex].value == \'\';}">';
-		foreach ($context['categories'] as $category)
-			echo '
-								<option', $category['selected'] ? ' selected="selected"' : '', ' value="', $category['id'], '">', $category['name'], '</option>';
-		echo '
-							</select>
-						</dd>';
-
-	// If this isn't the only board in this category let the user choose where the board is to live.
-	if ((isset($context['board']['is_new']) && count($context['board_order']) > 0) || count($context['board_order']) > 1)
-	{
-		echo '
-						<dt>
-							<strong>', $txt['order'], ':</strong>
-						</dt>
-						<dd>';
-
-	// The first select box gives the user the option to position it before, after or as a child of another board.
-	echo '
-							<select id="order" name="placement" onchange="this.form.board_order.disabled = this.options[this.selectedIndex].value == \'\';">
-								', !isset($context['board']['is_new']) ? '<option value="">(' . $txt['mboards_unchanged'] . ')</option>' : '', '
-								<option value="after">' . $txt['mboards_order_after'] . '...</option>
-								<option value="child">' . $txt['mboards_order_child_of'] . '...</option>
-								<option value="before">' . $txt['mboards_order_before'] . '...</option>
-							</select>';
-
-	// The second select box lists all the boards in the category.
-	echo '
-							<select id="board_order" name="board_order" ', isset($context['board']['is_new']) ? '' : 'disabled="disabled"', '>
-								', !isset($context['board']['is_new']) ? '<option value="">(' . $txt['mboards_unchanged'] . ')</option>' : '';
-	foreach ($context['board_order'] as $order)
-		echo '
-								<option', $order['selected'] ? ' selected="selected"' : '', ' value="', $order['id'], '">', $order['name'], '</option>';
-	echo '
-							</select>
-						</dd>';
-	}
-
-	// Options for board name and description.
-	echo '
-						<dt>
-							<strong>', $txt['full_name'], ':</strong><br />
-							<span class="smalltext">', $txt['name_on_display'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="board_name" value="', $context['board']['name'], '" size="30" class="input_text" />
-						</dd>
-						<dt>
-							<strong>', $txt['mboards_description'], ':</strong><br />
-							<span class="smalltext">', $txt['mboards_description_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea name="desc" rows="3" cols="35" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 99%; min-width: 99%' : 'width: 99%') . ';">', $context['board']['description'], '</textarea>
-						</dd>
-						<dt>
-							<strong>', $txt['permission_profile'], ':</strong><br />
-							<span class="smalltext">', $context['can_manage_permissions'] ? sprintf($txt['permission_profile_desc'], $scripturl . '?action=admin;area=permissions;sa=profiles;' . $context['session_var'] . '=' . $context['session_id']) : strip_tags($txt['permission_profile_desc']), '</span>
-						</dt>
-						<dd>
-							<select name="profile">';
-
-	if (isset($context['board']['is_new']))
-		echo '
-								<option value="-1">[', $txt['permission_profile_inherit'], ']</option>';
-
-	foreach ($context['profiles'] as $id => $profile)
-		echo '
-								<option value="', $id, '" ', $id == $context['board']['profile'] ? 'selected="selected"' : '', '>', $profile['name'], '</option>';
-
-	echo '
-							</select>
-						</dd>
-						<dt>
-							<strong>', $txt['mboards_groups'], ':</strong><br />
-							<span class="smalltext">', empty($modSettings['deny_boards_access']) ? $txt['mboards_groups_desc'] : $txt['boardsaccess_option_desc'], '</span>';
-
-	echo '
-						</dt>
-						<dd>';
-
-	if (!empty($modSettings['deny_boards_access']))
-		echo '
-							<table>
-								<tr>
-									<td></td>
-									<th>', $txt['permissions_option_on'], '</th>
-									<th>', $txt['permissions_option_off'], '</th>
-									<th>', $txt['permissions_option_deny'], '</th>
-								</tr>';
-
-	// List all the membergroups so the user can choose who may access this board.
-	foreach ($context['groups'] as $group)
-		if (empty($modSettings['deny_boards_access']))
-			echo '
-							<label for="groups_', $group['id'], '">
-								<input type="checkbox" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '"', $group['allow'] ? ' checked="checked"' : '', ' class="input_check" />
-								<span', $group['is_post_group'] ? ' class="post_group" title="' . $txt['mboards_groups_post_group'] . '"' : '', $group['id'] == 0 ? ' class="regular_members" title="' . $txt['mboards_groups_regular_members'] . '"' : '', '>
-									', $group['name'], '
-								</span>
-							</label><br />';
-		else
-			echo '
-								<tr>
-									<td>
-										<label for="groups_', $group['id'], '_a">
-											<span', $group['is_post_group'] ? ' class="post_group" title="' . $txt['mboards_groups_post_group'] . '"' : '', $group['id'] == 0 ? ' class="regular_members" title="' . $txt['mboards_groups_regular_members'] . '"' : '', '>
-												', $group['name'], '
-											</span>
-										</label>
-									</td>
-									<td>
-										<input type="radio" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '_a"', $group['allow'] ? ' checked="checked"' : '', ' class="input_radio" />
-									</td>
-									<td>
-										<input type="radio" name="groups[', $group['id'], ']" value="ignore" id="groups_', $group['id'], '_x"', !$group['allow'] && !$group['deny'] ? ' checked="checked"' : '', ' class="input_radio" />
-									</td>
-									<td>
-										<input type="radio" name="groups[', $group['id'], ']" value="deny" id="groups_', $group['id'], '_d"', $group['deny'] ? ' checked="checked"' : '', ' class="input_radio" />
-									</td>
-									<td></td>
-								</tr>';
-
-	if (empty($modSettings['deny_boards_access']))
-		echo '
-							<span class="select_all_box">
-								<em>', $txt['check_all'], '</em> <input type="checkbox" class="input_check" onclick="invertAll(this, this.form, \'groups[\');" />
-							</span>
-							<br />
-							<br />
-						</dd>';
-	else
-		echo '
-								<tr class="select_all_box">
-									<td>
-									</td>
-									<td>
-										<input type="radio" name="select_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'groups\', \'allow\');" />
-									</td>
-									<td>
-										<input type="radio" name="select_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'groups\', \'ignore\');" />
-									</td>
-									<td>
-										<input type="radio" name="select_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'groups\', \'deny\');" />
-									</td>
-									<td>
-										<em>', $txt['check_all'], '</em>
-									</td>
-								</tr>
-							</table>
-						</dd>';
-
-	// Options to choose moderators, specifiy as announcement board and choose whether to count posts here.
-	echo '
-						<dt>
-							<strong>', $txt['mboards_moderators'], ':</strong><br />
-							<span class="smalltext">', $txt['mboards_moderators_desc'], '</span><br />
-						</dt>
-						<dd>
-							<input type="text" name="moderators" id="moderators" value="', $context['board']['moderator_list'], '" size="30" class="input_text" />
-							<div id="moderator_container"></div>
-						</dd>
-					</dl>
-					<script type="text/javascript"><!-- // --><![CDATA[
-						$(document).ready(function () {
-							$(".select_all_box").each(function () {
-								$(this).removeClass(\'select_all_box\');
-							});
-						});
-					// ]]></script>
-					<hr class="hrcolor" />';
-
-	if (empty($context['board']['is_recycle']) && empty($context['board']['topics']))
-		echo '
-					<dl class="settings">
-						<dt>
-							<strong', $context['board']['topics'] ? ' style="color: gray;"' : '', '>', $txt['mboards_redirect'], ':</strong><br />
-							<span class="smalltext">', $txt['mboards_redirect_desc'], '</span><br />
-						</dt>
-						<dd>
-							<input type="checkbox" id="redirect_enable" name="redirect_enable"', $context['board']['topics'] ? ' disabled="disabled"' : '', $context['board']['redirect'] != '' ? ' checked="checked"' : '', ' onclick="refreshOptions();" class="input_check" />
-						</dd>
-					</dl>';
-
-	if (!empty($context['board']['is_recycle']))
-		echo '
-					<div class="information">', $txt['mboards_redirect_disabled_recycle'], '</div>';
-
-	if (empty($context['board']['is_recycle']) && !empty($context['board']['topics']))
-		echo '
-					<div class="information">
-						<strong>', $txt['mboards_redirect'],'</strong><br />
-						', $txt['mboards_redirect_disabled'], '
-					</div>';
-
-	if (!$context['board']['topics'] && empty($context['board']['is_recycle']))
-	{
-		echo '
-					<div id="redirect_address_div">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['mboards_redirect_url'], ':</strong><br />
-								<span class="smalltext">', $txt['mboards_redirect_url_desc'], '</span><br />
-							</dt>
-							<dd>
-								<input type="text" name="redirect_address" value="', $context['board']['redirect'], '" size="40" class="input_text" />
-							</dd>
-						</dl>
-					</div>';
-
-		if ($context['board']['redirect'])
-			echo '
-					<div id="reset_redirect_div">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['mboards_redirect_reset'], ':</strong><br />
-								<span class="smalltext">', $txt['mboards_redirect_reset_desc'], '</span><br />
-							</dt>
-							<dd>
-								<input type="checkbox" name="reset_redirect" class="input_check" />
-								<em>(', sprintf($txt['mboards_current_redirects'], $context['board']['posts']), ')</em>
-							</dd>
-						</dl>
-					</div>';
-	}
-
-	echo '
-					<div id="count_posts_div">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['mboards_count_posts'], ':</strong><br />
-								<span class="smalltext">', $txt['mboards_count_posts_desc'], '</span><br />
-							</dt>
-							<dd>
-								<input type="checkbox" name="count" ', $context['board']['count_posts'] ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-						</dl>
-					</div>';
-
-	// Here the user can choose to force this board to use a theme other than the default theme for the forum.
-	echo '
-					<div id="board_theme_div">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['mboards_theme'], ':</strong><br />
-								<span class="smalltext">', $txt['mboards_theme_desc'], '</span><br />
-							</dt>
-							<dd>
-								<select name="boardtheme" id="boardtheme" onchange="refreshOptions();">
-									<option value="0"', $context['board']['theme'] == 0 ? ' selected="selected"' : '', '>', $txt['mboards_theme_default'], '</option>';
-
-	foreach ($context['themes'] as $theme)
-		echo '
-									<option value="', $theme['id'], '"', $context['board']['theme'] == $theme['id'] ? ' selected="selected"' : '', '>', $theme['name'], '</option>';
-
-	echo '
-								</select>
-							</dd>
-						</dl>
-					</div>
-					<div id="override_theme_div">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['mboards_override_theme'], ':</strong><br />
-								<span class="smalltext">', $txt['mboards_override_theme_desc'], '</span><br />
-							</dt>
-							<dd>
-								<input type="checkbox" name="override_theme"', $context['board']['override_theme'] ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-						</dl>
-					</div>';
-
-	if (!empty($context['board']['is_recycle']))
-		echo '<div class="information">', $txt['mboards_recycle_disabled_delete'], '</div>';
-
-	echo '
-					<hr class="hrcolor" />
-					<input type="hidden" name="rid" value="', $context['redirect_location'], '" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-be-' . $context['board']['id'] . '_token_var'], '" value="', $context['admin-be-' . $context['board']['id'] . '_token'], '" />';
-
-	// If this board has no children don't bother with the next confirmation screen.
-	if ($context['board']['no_children'])
-		echo '
-					<input type="hidden" name="no_children" value="1" />';
-
-	if (isset($context['board']['is_new']))
-		echo '
-					<input type="hidden" name="cur_cat" value="', $context['board']['category'], '" />
-					<input type="submit" name="add" value="', $txt['mboards_new_board'], '" onclick="return !isEmptyText(this.form.board_name);" class="button_submit" />';
-	else
-		echo '
-					<input type="submit" name="edit" value="', $txt['modify'], '" onclick="return !isEmptyText(this.form.board_name);" class="button_submit" />';
-
-	if (!isset($context['board']['is_new']) && empty($context['board']['is_recycle']))
-		echo '
-					<span', $context['board']['is_recycle'] ? ' style="visibility:hidden">' : '>', '<input type="submit" name="delete" value="', $txt['mboards_delete_board'], '" onclick="return confirm(\'', $txt['boardConfirm'], '\');"', ' class="button_submit" /></span>';
-	echo '
-				<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />
-<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-<script type="text/javascript"><!-- // --><![CDATA[
-	var oModeratorSuggest = new smc_AutoSuggest({
-		sSelf: \'oModeratorSuggest\',
-		sSessionId: smf_session_id,
-		sSessionVar: smf_session_var,
-		sSuggestId: \'moderators\',
-		sControlId: \'moderators\',
-		sSearchType: \'member\',
-		bItemList: true,
-		sPostName: \'moderator_list\',
-		sURLMask: \'action=profile;u=%item_id%\',
-		sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-		sItemListContainerId: \'moderator_container\',
-		aListItems: [';
-
-	foreach ($context['board']['moderators'] as $id_member => $member_name)
-		echo '
-					{
-						sItemId: ', JavaScriptEscape($id_member), ',
-						sItemName: ', JavaScriptEscape($member_name), '
-					}', $id_member == $context['board']['last_moderator_id'] ? '' : ',';
-
-	echo '
-		]
-	});
-// ]]></script>';
-
-	// Javascript for deciding what to show.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		function refreshOptions()
-		{
-			var redirect = document.getElementById("redirect_enable");
-			var redirectEnabled = redirect ? redirect.checked : false;
-			var nonDefaultTheme = document.getElementById("boardtheme").value == 0 ? false : true;
-
-			// What to show?
-			document.getElementById("override_theme_div").style.display = redirectEnabled || !nonDefaultTheme ? "none" : "";
-			document.getElementById("board_theme_div").style.display = redirectEnabled ? "none" : "";
-			document.getElementById("count_posts_div").style.display = redirectEnabled ? "none" : "";';
-
-	if (!$context['board']['topics'] && empty($context['board']['is_recycle']))
-	{
-		echo '
-			document.getElementById("redirect_address_div").style.display = redirectEnabled ? "" : "none";';
-
-		if ($context['board']['redirect'])
-			echo '
-			document.getElementById("reset_redirect_div").style.display = redirectEnabled ? "" : "none";';
-	}
-
-	echo '
-		}
-		refreshOptions();
-	// ]]></script>';
-}
-
-// A template used when a user is deleting a board with child boards in it - to see what they want to do with them.
-function template_confirm_board_delete()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Print table header.
-	echo '
-	<div id="manage_boards">
-		<form action="', $scripturl, '?action=admin;area=manageboards;sa=board2" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="boardid" value="', $context['board']['id'], '" />
-
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mboards_delete_board'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['mboards_delete_board_contains'], '</p>
-						<ul>';
-
-	foreach ($context['children'] as $child)
-		echo '
-							<li>', $child['node']['name'], '</li>';
-
-	echo '
-						</ul>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mboards_delete_what_do'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>
-						<label for="delete_action0"><input type="radio" id="delete_action0" name="delete_action" value="0" class="input_radio" checked="checked" />', $txt['mboards_delete_board_option1'], '</label><br />
-						<label for="delete_action1"><input type="radio" id="delete_action1" name="delete_action" value="1" class="input_radio"', empty($context['can_move_children']) ? ' disabled="disabled"' : '', ' />', $txt['mboards_delete_board_option2'], '</label>:
-						<select name="board_to" ', empty($context['can_move_children']) ? 'disabled="disabled"' : '', '>';
-
-	foreach ($context['board_order'] as $board)
-		if ($board['id'] != $context['board']['id'] && empty($board['is_child']))
-			echo '
-							<option value="', $board['id'], '">', $board['name'], '</option>';
-
-	echo '
-						</select>
-					</p>
-					<input type="submit" name="delete" value="', $txt['mboards_delete_confirm'], '" class="button_submit" />
-					<input type="submit" name="cancel" value="', $txt['mboards_delete_cancel'], '" class="button_submit" />
-					<input type="hidden" name="confirmation" value="1" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Template for listing all the current categories and boards.
+function template_main()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Table header.
+	echo '
+	<div id="manage_boards">
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['boardsEdit'], '</h3>
+		</div>';
+
+	if (!empty($context['move_board']))
+		echo '
+		<div class="information">
+			<p>', $context['move_title'], ' [<a href="', $scripturl, '?action=admin;area=manageboards">', $txt['mboards_cancel_moving'], '</a>]', '</p>
+		</div>';
+
+	// No categories so show a label.
+	if (empty($context['categories']))
+		echo '
+		<div class="windowbg">
+			<div class="content centertext">
+				', $txt['mboards_no_cats'], '
+			</div>
+		</div>';
+
+	// Loop through every category, listing the boards in each as we go.
+	foreach ($context['categories'] as $category)
+	{
+		// Link to modify the category.
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<a href="' . $scripturl . '?action=admin;area=manageboards;sa=cat;cat=' . $category['id'] . '">', $category['name'], '</a> <a href="' . $scripturl . '?action=admin;area=manageboards;sa=cat;cat=' . $category['id'] . '">', $txt['catModify'], '</a>
+				</h3>
+			</div>';
+
+		// Boards table header.
+		echo '
+		<form action="', $scripturl, '?action=admin;area=manageboards;sa=newboard;cat=', $category['id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="windowbg">
+				<div class="content">
+					<ul id="category_', $category['id'], '" class="reset nolist">';
+
+		if (!empty($category['move_link']))
+			echo '
+						<li><a href="', $category['move_link']['href'], '" title="', $category['move_link']['label'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $category['move_link']['label'], '" /></a></li>';
+
+		$alternate = false;
+
+		// List through every board in the category, printing its name and link to modify the board.
+		foreach ($category['boards'] as $board)
+		{
+
+			echo '
+						<li', !empty($modSettings['recycle_board']) && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board['id'] ? ' id="recycle_board"' : ' ', ' class="windowbg', $alternate ? '' : '2', '" style="padding-' . ($context['right_to_left'] ? 'right' : 'left') . ': ', 5 + 30 * $board['child_level'], 'px;', $board['move'] ? 'color: red;' : '', '"><span class="floatleft"><a href="', $scripturl, '?board=', $board['id'], '">', $board['name'], '</a>', !empty($modSettings['recycle_board']) && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board['id'] ? '<a href="' . $scripturl . '?action=admin;area=manageboards;sa=settings"> <img src="' . $settings['images_url'] . '/post/recycled.png" alt="' . $txt['recycle_board'] . '" /></a></span>' : '</span>', '
+							<span class="floatright">', $context['can_manage_permissions'] ? '<span class="modify_boards"><a href="' . $scripturl . '?action=admin;area=permissions;sa=index;pid=' . $board['permission_profile'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['mboards_permissions'] . '</a></span>' : '', '
+							<span class="modify_boards"><a href="', $scripturl, '?action=admin;area=manageboards;move=', $board['id'], '">', $txt['mboards_move'], '</a></span>
+							<span class="modify_boards"><a href="', $scripturl, '?action=admin;area=manageboards;sa=board;boardid=', $board['id'], '">', $txt['mboards_modify'], '</a></span></span><br style="clear: right;" />
+						</li>';
+
+			if (!empty($board['move_links']))
+			{
+				$alternate = !$alternate;
+
+				echo '
+						<li class="windowbg', $alternate ? '' : '2', '" style="padding-', $context['right_to_left'] ? 'right' : 'left', ': ', 5 + 30 * $board['move_links'][0]['child_level'], 'px;">';
+
+				foreach ($board['move_links'] as $link)
+					echo '
+							<a href="', $link['href'], '" class="move_links" title="', $link['label'], '"><img src="', $settings['images_url'], '/board_select_spot', $link['child_level'] > 0 ? '_child' : '', '.png" alt="', $link['label'], '" style="padding: 0px; margin: 0px;" /></a>';
+
+				echo '
+						</li>';
+			}
+			$alternate = !$alternate;
+		}
+
+		// Button to add a new board.
+		echo '
+					</ul>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['mboards_new_board'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+		<br class="clear" />';
+	}
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+// Template for editing/adding a category on the forum.
+function template_modify_category()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Print table header.
+	echo '
+	<div id="manage_boards">
+		<form action="', $scripturl, '?action=admin;area=manageboards;sa=cat2" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="cat" value="', $context['category']['id'], '" />
+				<div class="cat_bar">
+					<h3 class="catbg">
+					', isset($context['category']['is_new']) ? $txt['mboards_new_cat_name'] : $txt['catEdit'], '
+					</h3>
+				</div>
+				<div class="windowbg">
+					<div class="content">
+						<dl class="settings">';
+	// If this isn't the only category, let the user choose where this category should be positioned down the board index.
+	if (count($context['category_order']) > 1)
+	{
+		echo '
+						<dt><strong>', $txt['order'], ':</strong></dt>
+						<dd>
+							<select name="cat_order">';
+		// Print every existing category into a select box.
+		foreach ($context['category_order'] as $order)
+			echo '
+								<option', $order['selected'] ? ' selected="selected"' : '', ' value="', $order['id'], '">', $order['name'], '</option>';
+		echo '
+							</select>
+						</dd>';
+	}
+	// Allow the user to edit the category name and/or choose whether you can collapse the category.
+	echo '
+						<dt>
+							<strong>', $txt['full_name'], ':</strong><br />
+							<span class="smalltext">', $txt['name_on_display'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="cat_name" value="', $context['category']['editable_name'], '" size="30" tabindex="', $context['tabindex']++, '" class="input_text" />
+						</dd>
+						<dt>
+							<strong>' . $txt['collapse_enable'] . '</strong><br />
+							<span class="smalltext">' . $txt['collapse_desc'] . '</span>
+						</dt>
+						<dd>
+							<input type="checkbox" name="collapse"', $context['category']['can_collapse'] ? ' checked="checked"' : '', ' tabindex="', $context['tabindex']++, '" class="input_check" />
+						</dd>';
+
+	// Table footer.
+	echo '
+					</dl>
+					<hr class="hrcolor" />';
+
+	if (isset($context['category']['is_new']))
+		echo '
+						<input type="submit" name="add" value="', $txt['mboards_add_cat_button'], '" onclick="return !isEmptyText(this.form.cat_name);" tabindex="', $context['tabindex']++, '" class="button_submit" />';
+	else
+		echo '
+						<input type="submit" name="edit" value="', $txt['modify'], '" onclick="return !isEmptyText(this.form.cat_name);" tabindex="', $context['tabindex']++, '" class="button_submit" />
+						<input type="submit" name="delete" value="', $txt['mboards_delete_cat'], '" onclick="return confirm(\'', $txt['catConfirm'], '\');" class="button_submit" />';
+	echo '
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
+	if (!empty($context['token_check']))
+		echo '
+						<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	// If this category is empty we don't bother with the next confirmation screen.
+	if ($context['category']['is_empty'])
+		echo '
+						<input type="hidden" name="empty" value="1" />';
+
+	echo '
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// A template to confirm if a user wishes to delete a category - and whether they want to save the boards.
+function template_confirm_category_delete()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Print table header.
+	echo '
+	<div id="manage_boards">
+		<form action="', $scripturl, '?action=admin;area=manageboards;sa=cat2" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="cat" value="', $context['category']['id'], '" />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mboards_delete_cat'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>', $txt['mboards_delete_cat_contains'], ':</p>
+					<ul>';
+
+	foreach ($context['category']['children'] as $child)
+		echo '
+						<li>', $child, '</li>';
+
+	echo '
+					</ul>
+				</div>
+			</div>
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mboards_delete_what_do'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>
+						<label for="delete_action0"><input type="radio" id="delete_action0" name="delete_action" value="0" class="input_radio" checked="checked" />', $txt['mboards_delete_option1'], '</label><br />
+						<label for="delete_action1"><input type="radio" id="delete_action1" name="delete_action" value="1" class="input_radio"', count($context['category_order']) == 1 ? ' disabled="disabled"' : '', ' />', $txt['mboards_delete_option2'], '</label>:
+						<select name="cat_to" ', count($context['category_order']) == 1 ? 'disabled="disabled"' : '', '>';
+
+	foreach ($context['category_order'] as $cat)
+		if ($cat['id'] != 0)
+			echo '
+							<option value="', $cat['id'], '">', $cat['true_name'], '</option>';
+
+	echo '
+						</select>
+					</p>
+					<input type="submit" name="delete" value="', $txt['mboards_delete_confirm'], '" class="button_submit" />
+					<input type="submit" name="cancel" value="', $txt['mboards_delete_cancel'], '" class="button_submit" />
+					<input type="hidden" name="confirmation" value="1" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Below is the template for adding/editing an board on the forum.
+function template_modify_board()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// The main table header.
+	echo '
+	<div id="manage_boards">
+		<form action="', $scripturl, '?action=admin;area=manageboards;sa=board2" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="boardid" value="', $context['board']['id'], '" />
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', isset($context['board']['is_new']) ? $txt['mboards_new_board_name'] : $txt['boardsEdit'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">';
+
+	// Option for choosing the category the board lives in.
+	echo '
+
+						<dt>
+							<strong>', $txt['mboards_category'], ':</strong>
+
+						</dt>
+						<dd>
+							<select name="new_cat" onchange="if (this.form.order) {this.form.order.disabled = this.options[this.selectedIndex].value != 0; this.form.board_order.disabled = this.options[this.selectedIndex].value != 0 || this.form.order.options[this.form.order.selectedIndex].value == \'\';}">';
+		foreach ($context['categories'] as $category)
+			echo '
+								<option', $category['selected'] ? ' selected="selected"' : '', ' value="', $category['id'], '">', $category['name'], '</option>';
+		echo '
+							</select>
+						</dd>';
+
+	// If this isn't the only board in this category let the user choose where the board is to live.
+	if ((isset($context['board']['is_new']) && count($context['board_order']) > 0) || count($context['board_order']) > 1)
+	{
+		echo '
+						<dt>
+							<strong>', $txt['order'], ':</strong>
+						</dt>
+						<dd>';
+
+	// The first select box gives the user the option to position it before, after or as a child of another board.
+	echo '
+							<select id="order" name="placement" onchange="this.form.board_order.disabled = this.options[this.selectedIndex].value == \'\';">
+								', !isset($context['board']['is_new']) ? '<option value="">(' . $txt['mboards_unchanged'] . ')</option>' : '', '
+								<option value="after">' . $txt['mboards_order_after'] . '...</option>
+								<option value="child">' . $txt['mboards_order_child_of'] . '...</option>
+								<option value="before">' . $txt['mboards_order_before'] . '...</option>
+							</select>';
+
+	// The second select box lists all the boards in the category.
+	echo '
+							<select id="board_order" name="board_order" ', isset($context['board']['is_new']) ? '' : 'disabled="disabled"', '>
+								', !isset($context['board']['is_new']) ? '<option value="">(' . $txt['mboards_unchanged'] . ')</option>' : '';
+	foreach ($context['board_order'] as $order)
+		echo '
+								<option', $order['selected'] ? ' selected="selected"' : '', ' value="', $order['id'], '">', $order['name'], '</option>';
+	echo '
+							</select>
+						</dd>';
+	}
+
+	// Options for board name and description.
+	echo '
+						<dt>
+							<strong>', $txt['full_name'], ':</strong><br />
+							<span class="smalltext">', $txt['name_on_display'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="board_name" value="', $context['board']['name'], '" size="30" class="input_text" />
+						</dd>
+						<dt>
+							<strong>', $txt['mboards_description'], ':</strong><br />
+							<span class="smalltext">', $txt['mboards_description_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="desc" rows="3" cols="35" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 99%; min-width: 99%' : 'width: 99%') . ';">', $context['board']['description'], '</textarea>
+						</dd>
+						<dt>
+							<strong>', $txt['permission_profile'], ':</strong><br />
+							<span class="smalltext">', $context['can_manage_permissions'] ? sprintf($txt['permission_profile_desc'], $scripturl . '?action=admin;area=permissions;sa=profiles;' . $context['session_var'] . '=' . $context['session_id']) : strip_tags($txt['permission_profile_desc']), '</span>
+						</dt>
+						<dd>
+							<select name="profile">';
+
+	if (isset($context['board']['is_new']))
+		echo '
+								<option value="-1">[', $txt['permission_profile_inherit'], ']</option>';
+
+	foreach ($context['profiles'] as $id => $profile)
+		echo '
+								<option value="', $id, '" ', $id == $context['board']['profile'] ? 'selected="selected"' : '', '>', $profile['name'], '</option>';
+
+	echo '
+							</select>
+						</dd>
+						<dt>
+							<strong>', $txt['mboards_groups'], ':</strong><br />
+							<span class="smalltext">', empty($modSettings['deny_boards_access']) ? $txt['mboards_groups_desc'] : $txt['boardsaccess_option_desc'], '</span>';
+
+	echo '
+						</dt>
+						<dd>';
+
+	if (!empty($modSettings['deny_boards_access']))
+		echo '
+							<table>
+								<tr>
+									<td></td>
+									<th>', $txt['permissions_option_on'], '</th>
+									<th>', $txt['permissions_option_off'], '</th>
+									<th>', $txt['permissions_option_deny'], '</th>
+								</tr>';
+
+	// List all the membergroups so the user can choose who may access this board.
+	foreach ($context['groups'] as $group)
+		if (empty($modSettings['deny_boards_access']))
+			echo '
+							<label for="groups_', $group['id'], '">
+								<input type="checkbox" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '"', $group['allow'] ? ' checked="checked"' : '', ' class="input_check" />
+								<span', $group['is_post_group'] ? ' class="post_group" title="' . $txt['mboards_groups_post_group'] . '"' : '', $group['id'] == 0 ? ' class="regular_members" title="' . $txt['mboards_groups_regular_members'] . '"' : '', '>
+									', $group['name'], '
+								</span>
+							</label><br />';
+		else
+			echo '
+								<tr>
+									<td>
+										<label for="groups_', $group['id'], '_a">
+											<span', $group['is_post_group'] ? ' class="post_group" title="' . $txt['mboards_groups_post_group'] . '"' : '', $group['id'] == 0 ? ' class="regular_members" title="' . $txt['mboards_groups_regular_members'] . '"' : '', '>
+												', $group['name'], '
+											</span>
+										</label>
+									</td>
+									<td>
+										<input type="radio" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '_a"', $group['allow'] ? ' checked="checked"' : '', ' class="input_radio" />
+									</td>
+									<td>
+										<input type="radio" name="groups[', $group['id'], ']" value="ignore" id="groups_', $group['id'], '_x"', !$group['allow'] && !$group['deny'] ? ' checked="checked"' : '', ' class="input_radio" />
+									</td>
+									<td>
+										<input type="radio" name="groups[', $group['id'], ']" value="deny" id="groups_', $group['id'], '_d"', $group['deny'] ? ' checked="checked"' : '', ' class="input_radio" />
+									</td>
+									<td></td>
+								</tr>';
+
+	if (empty($modSettings['deny_boards_access']))
+		echo '
+							<span class="select_all_box">
+								<em>', $txt['check_all'], '</em> <input type="checkbox" class="input_check" onclick="invertAll(this, this.form, \'groups[\');" />
+							</span>
+							<br />
+							<br />
+						</dd>';
+	else
+		echo '
+								<tr class="select_all_box">
+									<td>
+									</td>
+									<td>
+										<input type="radio" name="select_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'groups\', \'allow\');" />
+									</td>
+									<td>
+										<input type="radio" name="select_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'groups\', \'ignore\');" />
+									</td>
+									<td>
+										<input type="radio" name="select_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'groups\', \'deny\');" />
+									</td>
+									<td>
+										<em>', $txt['check_all'], '</em>
+									</td>
+								</tr>
+							</table>
+						</dd>';
+
+	// Options to choose moderators, specifiy as announcement board and choose whether to count posts here.
+	echo '
+						<dt>
+							<strong>', $txt['mboards_moderators'], ':</strong><br />
+							<span class="smalltext">', $txt['mboards_moderators_desc'], '</span><br />
+						</dt>
+						<dd>
+							<input type="text" name="moderators" id="moderators" value="', $context['board']['moderator_list'], '" size="30" class="input_text" />
+							<div id="moderator_container"></div>
+						</dd>
+					</dl>
+					<script type="text/javascript"><!-- // --><![CDATA[
+						$(document).ready(function () {
+							$(".select_all_box").each(function () {
+								$(this).removeClass(\'select_all_box\');
+							});
+						});
+					// ]]></script>
+					<hr class="hrcolor" />';
+
+	if (empty($context['board']['is_recycle']) && empty($context['board']['topics']))
+		echo '
+					<dl class="settings">
+						<dt>
+							<strong', $context['board']['topics'] ? ' style="color: gray;"' : '', '>', $txt['mboards_redirect'], ':</strong><br />
+							<span class="smalltext">', $txt['mboards_redirect_desc'], '</span><br />
+						</dt>
+						<dd>
+							<input type="checkbox" id="redirect_enable" name="redirect_enable"', $context['board']['topics'] ? ' disabled="disabled"' : '', $context['board']['redirect'] != '' ? ' checked="checked"' : '', ' onclick="refreshOptions();" class="input_check" />
+						</dd>
+					</dl>';
+
+	if (!empty($context['board']['is_recycle']))
+		echo '
+					<div class="information">', $txt['mboards_redirect_disabled_recycle'], '</div>';
+
+	if (empty($context['board']['is_recycle']) && !empty($context['board']['topics']))
+		echo '
+					<div class="information">
+						<strong>', $txt['mboards_redirect'],'</strong><br />
+						', $txt['mboards_redirect_disabled'], '
+					</div>';
+
+	if (!$context['board']['topics'] && empty($context['board']['is_recycle']))
+	{
+		echo '
+					<div id="redirect_address_div">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['mboards_redirect_url'], ':</strong><br />
+								<span class="smalltext">', $txt['mboards_redirect_url_desc'], '</span><br />
+							</dt>
+							<dd>
+								<input type="text" name="redirect_address" value="', $context['board']['redirect'], '" size="40" class="input_text" />
+							</dd>
+						</dl>
+					</div>';
+
+		if ($context['board']['redirect'])
+			echo '
+					<div id="reset_redirect_div">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['mboards_redirect_reset'], ':</strong><br />
+								<span class="smalltext">', $txt['mboards_redirect_reset_desc'], '</span><br />
+							</dt>
+							<dd>
+								<input type="checkbox" name="reset_redirect" class="input_check" />
+								<em>(', sprintf($txt['mboards_current_redirects'], $context['board']['posts']), ')</em>
+							</dd>
+						</dl>
+					</div>';
+	}
+
+	echo '
+					<div id="count_posts_div">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['mboards_count_posts'], ':</strong><br />
+								<span class="smalltext">', $txt['mboards_count_posts_desc'], '</span><br />
+							</dt>
+							<dd>
+								<input type="checkbox" name="count" ', $context['board']['count_posts'] ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+						</dl>
+					</div>';
+
+	// Here the user can choose to force this board to use a theme other than the default theme for the forum.
+	echo '
+					<div id="board_theme_div">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['mboards_theme'], ':</strong><br />
+								<span class="smalltext">', $txt['mboards_theme_desc'], '</span><br />
+							</dt>
+							<dd>
+								<select name="boardtheme" id="boardtheme" onchange="refreshOptions();">
+									<option value="0"', $context['board']['theme'] == 0 ? ' selected="selected"' : '', '>', $txt['mboards_theme_default'], '</option>';
+
+	foreach ($context['themes'] as $theme)
+		echo '
+									<option value="', $theme['id'], '"', $context['board']['theme'] == $theme['id'] ? ' selected="selected"' : '', '>', $theme['name'], '</option>';
+
+	echo '
+								</select>
+							</dd>
+						</dl>
+					</div>
+					<div id="override_theme_div">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['mboards_override_theme'], ':</strong><br />
+								<span class="smalltext">', $txt['mboards_override_theme_desc'], '</span><br />
+							</dt>
+							<dd>
+								<input type="checkbox" name="override_theme"', $context['board']['override_theme'] ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+						</dl>
+					</div>';
+
+	if (!empty($context['board']['is_recycle']))
+		echo '<div class="information">', $txt['mboards_recycle_disabled_delete'], '</div>';
+
+	echo '
+					<hr class="hrcolor" />
+					<input type="hidden" name="rid" value="', $context['redirect_location'], '" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-be-' . $context['board']['id'] . '_token_var'], '" value="', $context['admin-be-' . $context['board']['id'] . '_token'], '" />';
+
+	// If this board has no children don't bother with the next confirmation screen.
+	if ($context['board']['no_children'])
+		echo '
+					<input type="hidden" name="no_children" value="1" />';
+
+	if (isset($context['board']['is_new']))
+		echo '
+					<input type="hidden" name="cur_cat" value="', $context['board']['category'], '" />
+					<input type="submit" name="add" value="', $txt['mboards_new_board'], '" onclick="return !isEmptyText(this.form.board_name);" class="button_submit" />';
+	else
+		echo '
+					<input type="submit" name="edit" value="', $txt['modify'], '" onclick="return !isEmptyText(this.form.board_name);" class="button_submit" />';
+
+	if (!isset($context['board']['is_new']) && empty($context['board']['is_recycle']))
+		echo '
+					<span', $context['board']['is_recycle'] ? ' style="visibility:hidden">' : '>', '<input type="submit" name="delete" value="', $txt['mboards_delete_board'], '" onclick="return confirm(\'', $txt['boardConfirm'], '\');"', ' class="button_submit" /></span>';
+	echo '
+				<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />
+<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+<script type="text/javascript"><!-- // --><![CDATA[
+	var oModeratorSuggest = new smc_AutoSuggest({
+		sSelf: \'oModeratorSuggest\',
+		sSessionId: smf_session_id,
+		sSessionVar: smf_session_var,
+		sSuggestId: \'moderators\',
+		sControlId: \'moderators\',
+		sSearchType: \'member\',
+		bItemList: true,
+		sPostName: \'moderator_list\',
+		sURLMask: \'action=profile;u=%item_id%\',
+		sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+		sItemListContainerId: \'moderator_container\',
+		aListItems: [';
+
+	foreach ($context['board']['moderators'] as $id_member => $member_name)
+		echo '
+					{
+						sItemId: ', JavaScriptEscape($id_member), ',
+						sItemName: ', JavaScriptEscape($member_name), '
+					}', $id_member == $context['board']['last_moderator_id'] ? '' : ',';
+
+	echo '
+		]
+	});
+// ]]></script>';
+
+	// Javascript for deciding what to show.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		function refreshOptions()
+		{
+			var redirect = document.getElementById("redirect_enable");
+			var redirectEnabled = redirect ? redirect.checked : false;
+			var nonDefaultTheme = document.getElementById("boardtheme").value == 0 ? false : true;
+
+			// What to show?
+			document.getElementById("override_theme_div").style.display = redirectEnabled || !nonDefaultTheme ? "none" : "";
+			document.getElementById("board_theme_div").style.display = redirectEnabled ? "none" : "";
+			document.getElementById("count_posts_div").style.display = redirectEnabled ? "none" : "";';
+
+	if (!$context['board']['topics'] && empty($context['board']['is_recycle']))
+	{
+		echo '
+			document.getElementById("redirect_address_div").style.display = redirectEnabled ? "" : "none";';
+
+		if ($context['board']['redirect'])
+			echo '
+			document.getElementById("reset_redirect_div").style.display = redirectEnabled ? "" : "none";';
+	}
+
+	echo '
+		}
+		refreshOptions();
+	// ]]></script>';
+}
+
+// A template used when a user is deleting a board with child boards in it - to see what they want to do with them.
+function template_confirm_board_delete()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Print table header.
+	echo '
+	<div id="manage_boards">
+		<form action="', $scripturl, '?action=admin;area=manageboards;sa=board2" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="boardid" value="', $context['board']['id'], '" />
+
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mboards_delete_board'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>', $txt['mboards_delete_board_contains'], '</p>
+						<ul>';
+
+	foreach ($context['children'] as $child)
+		echo '
+							<li>', $child['node']['name'], '</li>';
+
+	echo '
+						</ul>
+				</div>
+			</div>
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mboards_delete_what_do'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>
+						<label for="delete_action0"><input type="radio" id="delete_action0" name="delete_action" value="0" class="input_radio" checked="checked" />', $txt['mboards_delete_board_option1'], '</label><br />
+						<label for="delete_action1"><input type="radio" id="delete_action1" name="delete_action" value="1" class="input_radio"', empty($context['can_move_children']) ? ' disabled="disabled"' : '', ' />', $txt['mboards_delete_board_option2'], '</label>:
+						<select name="board_to" ', empty($context['can_move_children']) ? 'disabled="disabled"' : '', '>';
+
+	foreach ($context['board_order'] as $board)
+		if ($board['id'] != $context['board']['id'] && empty($board['is_child']))
+			echo '
+							<option value="', $board['id'], '">', $board['name'], '</option>';
+
+	echo '
+						</select>
+					</p>
+					<input type="submit" name="delete" value="', $txt['mboards_delete_confirm'], '" class="button_submit" />
+					<input type="submit" name="cancel" value="', $txt['mboards_delete_cancel'], '" class="button_submit" />
+					<input type="hidden" name="confirmation" value="1" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 116 - 118
Themes/default/ManageCalendar.template.php

@@ -1,119 +1,117 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Editing or adding holidays.
-function template_edit_holiday()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Start with javascript for getting the calendar dates right.
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
-
-			function generateDays()
-			{
-				var days = 0, selected = 0;
-				var dayElement = document.getElementById("day"), yearElement = document.getElementById("year"), monthElement = document.getElementById("month");
-
-				monthLength[1] = 28;
-				if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
-					monthLength[1] = 29;
-
-				selected = dayElement.selectedIndex;
-				while (dayElement.options.length)
-					dayElement.options[0] = null;
-
-				days = monthLength[monthElement.value - 1];
-
-				for (i = 1; i <= days; i++)
-					dayElement.options[dayElement.length] = new Option(i, i);
-
-				if (selected < days)
-					dayElement.selectedIndex = selected;
-			}
-		// ]]></script>';
-
-	// Show a form for all the holiday information.
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=managecalendar;sa=editholiday" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt class="small_caption">
-							<strong>', $txt['holidays_title_label'], ':</strong>
-						</dt>
-						<dd class="small_caption">
-							<input type="text" name="title" value="', $context['holiday']['title'], '" size="55" maxlength="60" />
-						</dd>
-						<dt class="small_caption">
-							<strong>', $txt['calendar_year'], '</strong>
-						</dt>
-						<dd class="small_caption">
-							<select name="year" id="year" onchange="generateDays();">
-								<option value="0000"', $context['holiday']['year'] == '0000' ? ' selected="selected"' : '', '>', $txt['every_year'], '</option>';
-	// Show a list of all the years we allow...
-	for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
-		echo '
-								<option value="', $year, '"', $year == $context['holiday']['year'] ? ' selected="selected"' : '', '>', $year, '</option>';
-
-	echo '
-							</select>&nbsp;
-							', $txt['calendar_month'], '&nbsp;
-							<select name="month" id="month" onchange="generateDays();">';
-
-	// There are 12 months per year - ensure that they all get listed.
-	for ($month = 1; $month <= 12; $month++)
-		echo '
-								<option value="', $month, '"', $month == $context['holiday']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '</option>';
-
-	echo '
-							</select>&nbsp;
-							', $txt['calendar_day'], '&nbsp;
-							<select name="day" id="day" onchange="generateDays();">';
-
-	// This prints out all the days in the current month - this changes dynamically as we switch months.
-	for ($day = 1; $day <= $context['holiday']['last_day']; $day++)
-		echo '
-								<option value="', $day, '"', $day == $context['holiday']['day'] ? ' selected="selected"' : '', '>', $day, '</option>';
-
-	echo '
-							</select>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />';
-
-	if ($context['is_new'])
-		echo '
-					<input type="submit" value="', $txt['holidays_button_add'], '" class="button_submit" />';
-	else
-		echo '
-					<input type="submit" name="edit" value="', $txt['holidays_button_edit'], '" class="button_submit" />
-					<input type="submit" name="delete" value="', $txt['holidays_button_remove'], '" class="button_submit" />
-					<input type="hidden" name="holiday" value="', $context['holiday']['id'], '" />';
-	echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Editing or adding holidays.
+function template_edit_holiday()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Start with javascript for getting the calendar dates right.
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+
+			function generateDays()
+			{
+				var days = 0, selected = 0;
+				var dayElement = document.getElementById("day"), yearElement = document.getElementById("year"), monthElement = document.getElementById("month");
+
+				monthLength[1] = 28;
+				if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
+					monthLength[1] = 29;
+
+				selected = dayElement.selectedIndex;
+				while (dayElement.options.length)
+					dayElement.options[0] = null;
+
+				days = monthLength[monthElement.value - 1];
+
+				for (i = 1; i <= days; i++)
+					dayElement.options[dayElement.length] = new Option(i, i);
+
+				if (selected < days)
+					dayElement.selectedIndex = selected;
+			}
+		// ]]></script>';
+
+	// Show a form for all the holiday information.
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=managecalendar;sa=editholiday" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt class="small_caption">
+							<strong>', $txt['holidays_title_label'], ':</strong>
+						</dt>
+						<dd class="small_caption">
+							<input type="text" name="title" value="', $context['holiday']['title'], '" size="55" maxlength="60" />
+						</dd>
+						<dt class="small_caption">
+							<strong>', $txt['calendar_year'], '</strong>
+						</dt>
+						<dd class="small_caption">
+							<select name="year" id="year" onchange="generateDays();">
+								<option value="0000"', $context['holiday']['year'] == '0000' ? ' selected="selected"' : '', '>', $txt['every_year'], '</option>';
+	// Show a list of all the years we allow...
+	for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
+		echo '
+								<option value="', $year, '"', $year == $context['holiday']['year'] ? ' selected="selected"' : '', '>', $year, '</option>';
+
+	echo '
+							</select>&nbsp;
+							', $txt['calendar_month'], '&nbsp;
+							<select name="month" id="month" onchange="generateDays();">';
+
+	// There are 12 months per year - ensure that they all get listed.
+	for ($month = 1; $month <= 12; $month++)
+		echo '
+								<option value="', $month, '"', $month == $context['holiday']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '</option>';
+
+	echo '
+							</select>&nbsp;
+							', $txt['calendar_day'], '&nbsp;
+							<select name="day" id="day" onchange="generateDays();">';
+
+	// This prints out all the days in the current month - this changes dynamically as we switch months.
+	for ($day = 1; $day <= $context['holiday']['last_day']; $day++)
+		echo '
+								<option value="', $day, '"', $day == $context['holiday']['day'] ? ' selected="selected"' : '', '>', $day, '</option>';
+
+	echo '
+							</select>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />';
+
+	if ($context['is_new'])
+		echo '
+					<input type="submit" value="', $txt['holidays_button_add'], '" class="button_submit" />';
+	else
+		echo '
+					<input type="submit" name="edit" value="', $txt['holidays_button_edit'], '" class="button_submit" />
+					<input type="submit" name="delete" value="', $txt['holidays_button_remove'], '" class="button_submit" />
+					<input type="hidden" name="holiday" value="', $context['holiday']['id'], '" />';
+	echo '
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 478 - 490
Themes/default/ManageLanguages.template.php

@@ -1,491 +1,479 @@
-<?php
-
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-/**
- * Download a new language file.
- */
-function template_download_language()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	// Actually finished?
-	if (!empty($context['install_complete']))
-	{
-		echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', $txt['languages_download_complete'], '
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				', $context['install_complete'], '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-		return;
-	}
-
-	// An error?
-	if (!empty($context['error_message']))
-		echo '
-	<div class="errorbox">
-		', $context['error_message'], '
-	</div>';
-
-	// Provide something of an introduction...
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=languages;sa=downloadlang;did=', $context['download_id'], ';', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $txt['languages_download'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>
-						', $txt['languages_download_note'], '
-					</p>
-					<div class="smalltext">
-						', $txt['languages_download_info'], '
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	// Show the main files.
-	template_show_list('lang_main_files_list');
-
-	// Now, all the images and the likes, hidden via javascript 'cause there are so fecking many.
-	echo '
-			<br />
-			<div class="title_bar">
-				<h3 class="titlebg">
-					', $txt['languages_download_theme_files'], '
-				</h3>
-			</div>
-			<table class="table_grid" cellspacing="0" width="100%">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th" scope="col">
-							', $txt['languages_download_filename'], '
-						</th>
-						<th scope="col" width="100">
-							', $txt['languages_download_writable'], '
-						</th>
-						<th scope="col" width="100">
-							', $txt['languages_download_exists'], '
-						</th>
-						<th class="last_th" scope="col" width="50">
-							', $txt['languages_download_copy'], '
-						</th>
-					</tr>
-				</thead>
-				<tbody>';
-
-	foreach ($context['files']['images'] as $theme => $group)
-	{
-		$count = 0;
-		echo '
-				<tr class="titlebg">
-					<td colspan="4">
-						<img class="sort" src="', $settings['images_url'], '/sort_down.png" id="toggle_image_', $theme, '" alt="*" />&nbsp;', isset($context['theme_names'][$theme]) ? $context['theme_names'][$theme] : $theme, '
-					</td>
-				</tr>';
-
-		$alternate = false;
-		foreach ($group as $file)
-		{
-			echo '
-				<tr class="windowbg', $alternate ? '2' : '', '" id="', $theme, '-', $count++, '">
-					<td>
-						<strong>', $file['name'], '</strong><br />
-						<span class="smalltext">', $txt['languages_download_dest'], ': ', $file['destination'], '</span>
-					</td>
-					<td>
-						<span style="color: ', ($file['writable'] ? 'green' : 'red'), ';">', ($file['writable'] ? $txt['yes'] : $txt['no']), '</span>
-					</td>
-					<td>
-						', $file['exists'] ? ($file['exists'] == 'same' ? $txt['languages_download_exists_same'] : $txt['languages_download_exists_different']) : $txt['no'], '
-					</td>
-					<td>
-						<input type="checkbox" name="copy_file[]" value="', $file['generaldest'], '"', ($file['default_copy'] ? ' checked="checked"' : ''), ' class="input_check" />
-					</td>
-				</tr>';
-			$alternate = !$alternate;
-		}
-	}
-
-	echo '
-			</tbody>
-			</table>';
-
-	// Do we want some FTP baby?
-	// If the files are not writable, we might!
-	if (!empty($context['still_not_writable']))
-	{
-		if (!empty($context['package_ftp']['error']))
-			echo '
-			<div class="errorbox">
-				', $context['package_ftp']['error'], '
-			</div>';
-
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $txt['package_ftp_necessary'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['package_ftp_why'],'</p>
-					<dl class="settings">
-						<dt
-							<label for="ftp_server">', $txt['package_ftp_server'], ':</label>
-						</dt>
-						<dd>
-							<div class="floatright" style="margin-right: 1px;"><label for="ftp_port" style="padding-top: 2px; padding-right: 2ex;">', $txt['package_ftp_port'], ':&nbsp;</label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', isset($context['package_ftp']['port']) ? $context['package_ftp']['port'] : (isset($modSettings['package_port']) ? $modSettings['package_port'] : '21'), '" class="input_text" /></div>
-							<input type="text" size="30" name="ftp_server" id="ftp_server" value="', isset($context['package_ftp']['server']) ? $context['package_ftp']['server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), '" style="width: 70%;" class="input_text" />
-						</dd>
-
-						<dt>
-							<label for="ftp_username">', $txt['package_ftp_username'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="50" name="ftp_username" id="ftp_username" value="', isset($context['package_ftp']['username']) ? $context['package_ftp']['username'] : (isset($modSettings['package_username']) ? $modSettings['package_username'] : ''), '" style="width: 99%;" class="input_text" />
-						</dd>
-
-						<dt>
-							<label for="ftp_password">', $txt['package_ftp_password'], ':</label>
-						</dt>
-						<dd>
-							<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_text" />
-						</dd>
-
-						<dt>
-							<label for="ftp_path">', $txt['package_ftp_path'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $context['package_ftp']['path'], '" style="width: 99%;" class="input_text" />
-						</dd>
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	// Install?
-	echo '
-			<div class="righttext padding">
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="hidden" name="', $context['admin-dlang_token_var'], '" value="', $context['admin-dlang_token'], '" />
-				<input type="submit" name="do_install" value="', $txt['add_language_smf_install'], '" class="button_submit" />
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-
-	// The javascript for expand and collapse of sections.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[';
-
-	// Each theme gets its own handler.
-	foreach ($context['files']['images'] as $theme => $group)
-	{
-		$count = 0;
-		echo '
-			var oTogglePanel_', $theme, ' = new smc_Toggle({
-				bToggleEnabled: true,
-				bCurrentlyCollapsed: true,
-				aSwappableContainers: [';
-		foreach ($group as $file)
-			echo '
-					', JavaScriptEscape($theme . '-' . $count++), ',';
-		echo '
-					null
-				],
-				aSwapImages: [
-					{
-						sId: \'toggle_image_', $theme, '\',
-						srcExpanded: smf_images_url + \'/sort_down.png\',
-						altExpanded: \'*\',
-						srcCollapsed: smf_images_url + \'/selected.png\',
-						altCollapsed: \'*\'
-					}
-				]
-			});';
-	}
-
-	echo '
-	// ]]></script>';
-}
-
-/**
- * Edit language entries.
- */
-function template_modify_language_entries()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=languages;sa=editlang;lid=', $context['lang_id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $txt['edit_languages'], '
-				</h3>
-			</div>
-			<div class="information">
-				', $txt['edit_language_entries_primary'], '
-			</div>';
-
-	// Not writable?
-	if ($context['lang_file_not_writable_message'])
-	{
-		// Oops, show an error for ya.
-		echo '
-			<div class="errorbox">
-				', $context['lang_file_not_writable_message'], '
-			</div>';
-	}
-
-	// Show the language entries
-	echo '
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<fieldset>
-						<legend>', $context['primary_settings']['name'], '</legend>
-					<dl class="settings">
-						<dt>
-							<label for="character_set">', $txt['languages_character_set'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" name="character_set" id="character_set" size="20" value="', $context['primary_settings']['character_set'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
-						</dd>
-						<dt>
-							<label for="locale>', $txt['languages_locale'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" name="locale" id="locale" size="20" value="', $context['primary_settings']['locale'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
-						</dd>
-						<dt>
-							<label for="dictionary">', $txt['languages_dictionary'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" name="dictionary" id="dictionary" size="20" value="', $context['primary_settings']['dictionary'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
-						</dd>
-						<dt>
-							<label for="spelling">', $txt['languages_spelling'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" name="spelling" id="spelling" size="20" value="', $context['primary_settings']['spelling'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
-						</dd>
-						<dt>
-							<label for="rtl">', $txt['languages_rtl'], ':</label>
-						</dt>
-						<dd>
-							<input type="checkbox" name="rtl" id="rtl" ', $context['primary_settings']['rtl'] ? ' checked="checked"' : '', ' class="input_check"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' />
-						</dd>
-					</dl>
-					</fieldset>
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-mlang_token_var'], '" value="', $context['admin-mlang_token'], '" />
-					<input type="submit" name="save_main" value="', $txt['save'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled="disabled"' : '', ' class="button_submit" />';
-
-	// Allow deleting entries.
-	if ($context['lang_id'] != 'english')
-	{
-		// English can't be deleted though.
-		echo '
-						<input type="submit" name="delete_main" value="', $txt['delete'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled="disabled"' : '', ' onclick="confirm(\'', $txt['languages_delete_confirm'], '\');" class="button_submit" />';
-	}
-
-	echo '
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-
-		<form action="', $scripturl, '?action=admin;area=languages;sa=editlang;lid=', $context['lang_id'], ';entries" id="entry_form" method="post" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">
-					', $txt['edit_language_entries'], '
-				</h3>
-			</div>
-			<div id="taskpad" class="floatright">
-				', $txt['edit_language_entries_file'], ':
-					<select name="tfid" onchange="if (this.value != -1) document.forms.entry_form.submit();">';
-	foreach ($context['possible_files'] as $id_theme => $theme)
-	{
-		echo '
-						<option value="-1">', $theme['name'], '</option>';
-
-		foreach ($theme['files'] as $file)
-		{
-			echo '
-						<option value="', $id_theme, '+', $file['id'], '"', $file['selected'] ? ' selected="selected"' : '', '> =&gt; ', $file['name'], '</option>';
-		}
-	}
-
-	echo '
-					</select>
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-mlang_token_var'], '" value="', $context['admin-mlang_token'], '" />
-					<input type="submit" value="', $txt['go'], '" class="button_submit" />
-			</div>';
-
-	// Is it not writable?
-	// Show an error.
-	if (!empty($context['entries_not_writable_message']))
-		echo '
-			<div class="errorbox">
-				', $context['entries_not_writable_message'], '
-			</div>';
-
-	// Already have some file entries?
-	if (!empty($context['file_entries']))
-	{
-		echo '
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-
-		$cached = array();
-		foreach ($context['file_entries'] as $entry)
-		{
-			// Do it in two's!
-			if (empty($cached))
-			{
-				$cached = $entry;
-				continue;
-			}
-
-			echo '
-						<dt>
-							<span class="smalltext">', $cached['key'], '</span>
-						</dt>
-						<dd>
-							<span class="smalltext">', $entry['key'], '</span>
-						</dd>
-						<dt>
-							<input type="hidden" name="comp[', $cached['key'], ']" value="', $cached['value'], '" />
-							<textarea name="entry[', $cached['key'], ']" cols="40" rows="', $cached['rows'] < 2 ? 2 : $cached['rows'], '" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . ';">', $cached['value'], '</textarea>
-						</dt>
-						<dd>
-							<input type="hidden" name="comp[', $entry['key'], ']" value="', $entry['value'], '" />
-							<textarea name="entry[', $entry['key'], ']" cols="40" rows="', $entry['rows'] < 2 ? 2 : $entry['rows'], '" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . ';">', $entry['value'], '</textarea>
-						</dd>';
-			$cached = array();
-		}
-
-		// Odd number?
-		if (!empty($cached))
-		{
-			// Alternative time
-			echo '
-
-						<dt>
-							<span class="smalltext">', $cached['key'], '</span>
-						</dt>
-						<dd>
-						</dd>
-						<dt>
-							<input type="hidden" name="comp[', $cached['key'], ']" value="', $cached['value'], '" />
-							<textarea name="entry[', $cached['key'], ']" cols="40" rows="2" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . ';">', $cached['value'], '</textarea>
-						</dt>
-						<dd>
-						</dd>';
-		}
-
-		echo '
-					</dl>
-					<input type="submit" name="save_entries" value="', $txt['save'], '"', !empty($context['entries_not_writable_message']) ? ' disabled="disabled"' : '', ' class="button_submit" />';
-
-		echo '
-				</div>
-				<br class="clear" />
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-	echo '
-		</form>
-	</div>';
-}
-
-/**
- * Add a new language
- *
- */
-function template_add_language()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=languages;sa=add;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $txt['add_language'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<fieldset>
-						<legend>', $txt['add_language_smf'], '</legend>
-						<label class="smalltext">', $txt['add_language_smf_browse'], '</label>
-						<input type="text" name="smf_add" size="40" value="', !empty($context['smf_search_term']) ? $context['smf_search_term'] : '', '" class="input_text" />';
-
-	// Do we have some errors? Too bad.
-	if (!empty($context['smf_error']))
-	{
-		// Display a little error box.
-		echo '
-						<div><br /><p class="errorbox">', $txt['add_language_error_' . $context['smf_error']], '</p></div>';
-	}
-
-	echo '
-					</fieldset>', isBrowser('is_ie') ? '<input type="text" name="ie_fix" style="display: none;" class="input_text" /> ' : '', '
-					<input type="submit" name="smf_add_sub" value="', $txt['search'], '" class="button_submit" />
-					<br />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		';
-
-	// Had some results?
-	if (!empty($context['smf_languages']))
-	{
-		echo '
-			<div class="information">', $txt['add_language_smf_found'], '</div>';
-
-		template_show_list('smf_languages');
-	}
-
-	echo '
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+/**
+ * Download a new language file.
+ */
+function template_download_language()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	// Actually finished?
+	if (!empty($context['install_complete']))
+	{
+		echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $txt['languages_download_complete'], '
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				', $context['install_complete'], '
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+		return;
+	}
+
+	// An error?
+	if (!empty($context['error_message']))
+		echo '
+	<div class="errorbox">
+		', $context['error_message'], '
+	</div>';
+
+	// Provide something of an introduction...
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=languages;sa=downloadlang;did=', $context['download_id'], ';', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $txt['languages_download'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>
+						', $txt['languages_download_note'], '
+					</p>
+					<div class="smalltext">
+						', $txt['languages_download_info'], '
+					</div>
+				</div>
+			</div>';
+
+	// Show the main files.
+	template_show_list('lang_main_files_list');
+
+	// Now, all the images and the likes, hidden via javascript 'cause there are so fecking many.
+	echo '
+			<br />
+			<div class="title_bar">
+				<h3 class="titlebg">
+					', $txt['languages_download_theme_files'], '
+				</h3>
+			</div>
+			<table class="table_grid" cellspacing="0" width="100%">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th" scope="col">
+							', $txt['languages_download_filename'], '
+						</th>
+						<th scope="col" width="100">
+							', $txt['languages_download_writable'], '
+						</th>
+						<th scope="col" width="100">
+							', $txt['languages_download_exists'], '
+						</th>
+						<th class="last_th" scope="col" width="50">
+							', $txt['languages_download_copy'], '
+						</th>
+					</tr>
+				</thead>
+				<tbody>';
+
+	foreach ($context['files']['images'] as $theme => $group)
+	{
+		$count = 0;
+		echo '
+				<tr class="titlebg">
+					<td colspan="4">
+						<img class="sort" src="', $settings['images_url'], '/sort_down.png" id="toggle_image_', $theme, '" alt="*" />&nbsp;', isset($context['theme_names'][$theme]) ? $context['theme_names'][$theme] : $theme, '
+					</td>
+				</tr>';
+
+		$alternate = false;
+		foreach ($group as $file)
+		{
+			echo '
+				<tr class="windowbg', $alternate ? '2' : '', '" id="', $theme, '-', $count++, '">
+					<td>
+						<strong>', $file['name'], '</strong><br />
+						<span class="smalltext">', $txt['languages_download_dest'], ': ', $file['destination'], '</span>
+					</td>
+					<td>
+						<span style="color: ', ($file['writable'] ? 'green' : 'red'), ';">', ($file['writable'] ? $txt['yes'] : $txt['no']), '</span>
+					</td>
+					<td>
+						', $file['exists'] ? ($file['exists'] == 'same' ? $txt['languages_download_exists_same'] : $txt['languages_download_exists_different']) : $txt['no'], '
+					</td>
+					<td>
+						<input type="checkbox" name="copy_file[]" value="', $file['generaldest'], '"', ($file['default_copy'] ? ' checked="checked"' : ''), ' class="input_check" />
+					</td>
+				</tr>';
+			$alternate = !$alternate;
+		}
+	}
+
+	echo '
+			</tbody>
+			</table>';
+
+	// Do we want some FTP baby?
+	// If the files are not writable, we might!
+	if (!empty($context['still_not_writable']))
+	{
+		if (!empty($context['package_ftp']['error']))
+			echo '
+			<div class="errorbox">
+				', $context['package_ftp']['error'], '
+			</div>';
+
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $txt['package_ftp_necessary'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>', $txt['package_ftp_why'],'</p>
+					<dl class="settings">
+						<dt
+							<label for="ftp_server">', $txt['package_ftp_server'], ':</label>
+						</dt>
+						<dd>
+							<div class="floatright" style="margin-right: 1px;"><label for="ftp_port" style="padding-top: 2px; padding-right: 2ex;">', $txt['package_ftp_port'], ':&nbsp;</label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', isset($context['package_ftp']['port']) ? $context['package_ftp']['port'] : (isset($modSettings['package_port']) ? $modSettings['package_port'] : '21'), '" class="input_text" /></div>
+							<input type="text" size="30" name="ftp_server" id="ftp_server" value="', isset($context['package_ftp']['server']) ? $context['package_ftp']['server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), '" style="width: 70%;" class="input_text" />
+						</dd>
+
+						<dt>
+							<label for="ftp_username">', $txt['package_ftp_username'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="50" name="ftp_username" id="ftp_username" value="', isset($context['package_ftp']['username']) ? $context['package_ftp']['username'] : (isset($modSettings['package_username']) ? $modSettings['package_username'] : ''), '" style="width: 99%;" class="input_text" />
+						</dd>
+
+						<dt>
+							<label for="ftp_password">', $txt['package_ftp_password'], ':</label>
+						</dt>
+						<dd>
+							<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_text" />
+						</dd>
+
+						<dt>
+							<label for="ftp_path">', $txt['package_ftp_path'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $context['package_ftp']['path'], '" style="width: 99%;" class="input_text" />
+						</dd>
+					</dl>
+				</div>
+			</div>';
+	}
+
+	// Install?
+	echo '
+			<div class="righttext padding">
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="', $context['admin-dlang_token_var'], '" value="', $context['admin-dlang_token'], '" />
+				<input type="submit" name="do_install" value="', $txt['add_language_smf_install'], '" class="button_submit" />
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+
+	// The javascript for expand and collapse of sections.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[';
+
+	// Each theme gets its own handler.
+	foreach ($context['files']['images'] as $theme => $group)
+	{
+		$count = 0;
+		echo '
+			var oTogglePanel_', $theme, ' = new smc_Toggle({
+				bToggleEnabled: true,
+				bCurrentlyCollapsed: true,
+				aSwappableContainers: [';
+		foreach ($group as $file)
+			echo '
+					', JavaScriptEscape($theme . '-' . $count++), ',';
+		echo '
+					null
+				],
+				aSwapImages: [
+					{
+						sId: \'toggle_image_', $theme, '\',
+						srcExpanded: smf_images_url + \'/sort_down.png\',
+						altExpanded: \'*\',
+						srcCollapsed: smf_images_url + \'/selected.png\',
+						altCollapsed: \'*\'
+					}
+				]
+			});';
+	}
+
+	echo '
+	// ]]></script>';
+}
+
+/**
+ * Edit language entries.
+ */
+function template_modify_language_entries()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=languages;sa=editlang;lid=', $context['lang_id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $txt['edit_languages'], '
+				</h3>
+			</div>
+			<div class="information">
+				', $txt['edit_language_entries_primary'], '
+			</div>';
+
+	// Not writable?
+	if ($context['lang_file_not_writable_message'])
+	{
+		// Oops, show an error for ya.
+		echo '
+			<div class="errorbox">
+				', $context['lang_file_not_writable_message'], '
+			</div>';
+	}
+
+	// Show the language entries
+	echo '
+			<div class="windowbg">
+				<div class="content">
+					<fieldset>
+						<legend>', $context['primary_settings']['name'], '</legend>
+					<dl class="settings">
+						<dt>
+							<label for="character_set">', $txt['languages_character_set'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" name="character_set" id="character_set" size="20" value="', $context['primary_settings']['character_set'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
+						</dd>
+						<dt>
+							<label for="locale>', $txt['languages_locale'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" name="locale" id="locale" size="20" value="', $context['primary_settings']['locale'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
+						</dd>
+						<dt>
+							<label for="dictionary">', $txt['languages_dictionary'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" name="dictionary" id="dictionary" size="20" value="', $context['primary_settings']['dictionary'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
+						</dd>
+						<dt>
+							<label for="spelling">', $txt['languages_spelling'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" name="spelling" id="spelling" size="20" value="', $context['primary_settings']['spelling'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
+						</dd>
+						<dt>
+							<label for="rtl">', $txt['languages_rtl'], ':</label>
+						</dt>
+						<dd>
+							<input type="checkbox" name="rtl" id="rtl" ', $context['primary_settings']['rtl'] ? ' checked="checked"' : '', ' class="input_check"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' />
+						</dd>
+					</dl>
+					</fieldset>
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-mlang_token_var'], '" value="', $context['admin-mlang_token'], '" />
+					<input type="submit" name="save_main" value="', $txt['save'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled="disabled"' : '', ' class="button_submit" />';
+
+	// Allow deleting entries.
+	if ($context['lang_id'] != 'english')
+	{
+		// English can't be deleted though.
+		echo '
+						<input type="submit" name="delete_main" value="', $txt['delete'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled="disabled"' : '', ' onclick="confirm(\'', $txt['languages_delete_confirm'], '\');" class="button_submit" />';
+	}
+
+	echo '
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+
+		<form action="', $scripturl, '?action=admin;area=languages;sa=editlang;lid=', $context['lang_id'], ';entries" id="entry_form" method="post" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">
+					', $txt['edit_language_entries'], '
+				</h3>
+			</div>
+			<div id="taskpad" class="floatright">
+				', $txt['edit_language_entries_file'], ':
+					<select name="tfid" onchange="if (this.value != -1) document.forms.entry_form.submit();">';
+	foreach ($context['possible_files'] as $id_theme => $theme)
+	{
+		echo '
+						<option value="-1">', $theme['name'], '</option>';
+
+		foreach ($theme['files'] as $file)
+		{
+			echo '
+						<option value="', $id_theme, '+', $file['id'], '"', $file['selected'] ? ' selected="selected"' : '', '> =&gt; ', $file['name'], '</option>';
+		}
+	}
+
+	echo '
+					</select>
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-mlang_token_var'], '" value="', $context['admin-mlang_token'], '" />
+					<input type="submit" value="', $txt['go'], '" class="button_submit" />
+			</div>';
+
+	// Is it not writable?
+	// Show an error.
+	if (!empty($context['entries_not_writable_message']))
+		echo '
+			<div class="errorbox">
+				', $context['entries_not_writable_message'], '
+			</div>';
+
+	// Already have some file entries?
+	if (!empty($context['file_entries']))
+	{
+		echo '
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">';
+
+		$cached = array();
+		foreach ($context['file_entries'] as $entry)
+		{
+			// Do it in two's!
+			if (empty($cached))
+			{
+				$cached = $entry;
+				continue;
+			}
+
+			echo '
+						<dt>
+							<span class="smalltext">', $cached['key'], '</span>
+						</dt>
+						<dd>
+							<span class="smalltext">', $entry['key'], '</span>
+						</dd>
+						<dt>
+							<input type="hidden" name="comp[', $cached['key'], ']" value="', $cached['value'], '" />
+							<textarea name="entry[', $cached['key'], ']" cols="40" rows="', $cached['rows'] < 2 ? 2 : $cached['rows'], '" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . ';">', $cached['value'], '</textarea>
+						</dt>
+						<dd>
+							<input type="hidden" name="comp[', $entry['key'], ']" value="', $entry['value'], '" />
+							<textarea name="entry[', $entry['key'], ']" cols="40" rows="', $entry['rows'] < 2 ? 2 : $entry['rows'], '" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . ';">', $entry['value'], '</textarea>
+						</dd>';
+			$cached = array();
+		}
+
+		// Odd number?
+		if (!empty($cached))
+		{
+			// Alternative time
+			echo '
+
+						<dt>
+							<span class="smalltext">', $cached['key'], '</span>
+						</dt>
+						<dd>
+						</dd>
+						<dt>
+							<input type="hidden" name="comp[', $cached['key'], ']" value="', $cached['value'], '" />
+							<textarea name="entry[', $cached['key'], ']" cols="40" rows="2" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . ';">', $cached['value'], '</textarea>
+						</dt>
+						<dd>
+						</dd>';
+		}
+
+		echo '
+					</dl>
+					<input type="submit" name="save_entries" value="', $txt['save'], '"', !empty($context['entries_not_writable_message']) ? ' disabled="disabled"' : '', ' class="button_submit" />';
+
+		echo '
+				</div>
+				<br class="clear" />
+			</div>';
+	}
+	echo '
+		</form>
+	</div>';
+}
+
+/**
+ * Add a new language
+ *
+ */
+function template_add_language()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=languages;sa=add;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $txt['add_language'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<fieldset>
+						<legend>', $txt['add_language_smf'], '</legend>
+						<label class="smalltext">', $txt['add_language_smf_browse'], '</label>
+						<input type="text" name="smf_add" size="40" value="', !empty($context['smf_search_term']) ? $context['smf_search_term'] : '', '" class="input_text" />';
+
+	// Do we have some errors? Too bad.
+	if (!empty($context['smf_error']))
+	{
+		// Display a little error box.
+		echo '
+						<div><br /><p class="errorbox">', $txt['add_language_error_' . $context['smf_error']], '</p></div>';
+	}
+
+	echo '
+					</fieldset>', isBrowser('is_ie') ? '<input type="text" name="ie_fix" style="display: none;" class="input_text" /> ' : '', '
+					<input type="submit" name="smf_add_sub" value="', $txt['search'], '" class="button_submit" />
+					<br />
+				</div>
+			</div>
+		';
+
+	// Had some results?
+	if (!empty($context['smf_languages']))
+	{
+		echo '
+			<div class="information">', $txt['add_language_smf_found'], '</div>';
+
+		template_show_list('smf_languages');
+	}
+
+	echo '
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 40 - 42
Themes/default/ManageMail.template.php

@@ -1,43 +1,41 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_browse()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="manage_mail">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['mailqueue_stats'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">
-					<dt><strong>', $txt['mailqueue_size'], '</strong></dt>
-					<dd>', $context['mail_queue_size'], '</dd>
-					<dt><strong>', $txt['mailqueue_oldest'], '</strong></dt>
-					<dd>', $context['oldest_mail'], '</dd>
-				</dl>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<br class="clear" />';
-
-	template_show_list('mail_queue');
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_browse()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="manage_mail">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['mailqueue_stats'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">
+					<dt><strong>', $txt['mailqueue_size'], '</strong></dt>
+					<dd>', $context['mail_queue_size'], '</dd>
+					<dt><strong>', $txt['mailqueue_oldest'], '</strong></dt>
+					<dd>', $context['oldest_mail'], '</dd>
+				</dl>
+			</div>
+		</div>
+		<br class="clear" />';
+
+	template_show_list('mail_queue');
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 664 - 700
Themes/default/ManageMaintenance.template.php

@@ -1,701 +1,665 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Template for the database maintenance tasks.
-function template_maintain_database()
-{
-	global $context, $settings, $options, $txt, $scripturl, $db_type, $modSettings;
-
-	// If maintenance has finished tell the user.
-	if (!empty($context['maintenance_finished']))
-		echo '
-			<div class="maintenance_finished">
-				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
-			</div>';
-
-	echo '
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_optimize'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=optimize" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_optimize_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-					<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-
-		<div class="cat_bar">
-			<h3 class="catbg">
-			<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=maintenance_backup" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['maintain_backup'], '</span>
-			</h3>
-		</div>
-
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=backup" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_backup_info'], '</p>';
-
-	if ($db_type == 'sqlite')
-		echo '
-					<hr class="hrcolor" />
-					<p>
-						<input type="submit" value="', $txt['maintain_backup_save'], '" id="submitDump" class="button_submit" />
-						<br class="clear_right" />
-					</p>';
-	else
-	{
-		if ($context['safe_mode_enable'])
-			echo '
-					<div class="errorbox">', $txt['safe_mode_enabled'], '</div>';
-		else
-			echo '
-					<div class="', $context['suggested_method'] == 'use_external_tool' || $context['use_maintenance'] != 0 ? 'errorbox' : 'noticebox', '">
-						', $txt[$context['suggested_method']],
-						$context['use_maintenance'] != 0 ? '<br />' . $txt['enable_maintenance' . $context['use_maintenance']] : '',
-					'</div>';
-
-		echo '
-					<p>
-						<label for="struct"><input type="checkbox" name="struct" id="struct" onclick="document.getElementById(\'submitDump\').disabled = !document.getElementById(\'struct\').checked &amp;&amp; !document.getElementById(\'data\').checked;" class="input_check" checked="checked" /> ', $txt['maintain_backup_struct'], '</label><br />
-						<label for="data"><input type="checkbox" name="data" id="data" onclick="document.getElementById(\'submitDump\').disabled = !document.getElementById(\'struct\').checked &amp;&amp; !document.getElementById(\'data\').checked;" checked="checked" class="input_check" /> ', $txt['maintain_backup_data'], '</label><br />
-						<label for="compress"><input type="checkbox" name="compress" id="compress" value="gzip"', $context['suggested_method'] == 'zipped_file' ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['maintain_backup_gz'], '</label>
-					</p>
-					<hr class="hrcolor" />
-					<p>
-						<input ', $context['use_maintenance'] == 2 ? 'disabled="disabled" ' : '', 'type="submit" value="', $txt['maintain_backup_save'], '" id="submitDump" onclick="return document.getElementById(\'struct\').checked || document.getElementById(\'data\').checked;" class="button_submit" />
-						<br class="clear_right" />
-					</p>';
-	}
-
-	echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	// Show an option to convert to UTF-8 if we're not on UTF-8 yet.
-	if ($context['convert_utf8'])
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['utf8_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertutf8" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['utf8_introduction'], '</p>
-					', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext' ? '<p class="errorbox">' . $txt['utf8_cannot_convert_fulltext'] . '</p>' : '', '
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" ', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext' ? 'disabled="disabled"' : '', '/><br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	// We might want to convert entities if we're on UTF-8.
-	if ($context['convert_entities'])
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['entity_convert_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertentities" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['entity_convert_introduction'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-// Template for the routine maintenance tasks.
-function template_maintain_routine()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	// If maintenance has finished tell the user.
-	if (!empty($context['maintenance_finished']))
-		echo '
-			<div class="maintenance_finished">
-				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
-			</div>';
-
-	// Starts off with general maintenance procedures.
-	echo '
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_version'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=version" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_version_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_errors'], '</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=repairboards" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_errors_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_recount'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=recount" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_recount_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_logs'], '</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=logs" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_logs_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_cache'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=cleancache" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['maintain_cache_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-// Template for the member maintenance tasks.
-function template_maintain_members()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// If maintenance has finished tell the user.
-	if (!empty($context['maintenance_finished']))
-		echo '
-			<div class="maintenance_finished">
-				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
-			</div>';
-
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var warningMessage = \'\';
-		var membersSwap = false;
-
-		function swapMembers()
-		{
-			membersSwap = !membersSwap;
-			var membersForm = document.getElementById(\'membersForm\');
-
-			document.getElementById("membersIcon").src = smf_images_url + (membersSwap ? "/selected_open.png" : "/selected.png");
-			setInnerHTML(document.getElementById("membersText"), membersSwap ? "', $txt['maintain_members_choose'], '" : "', $txt['maintain_members_all'], '");
-			document.getElementById("membersPanel").style.display = (membersSwap ? "block" : "none");
-
-			for (var i = 0; i < membersForm.length; i++)
-			{
-				if (membersForm.elements[i].type.toLowerCase() == "checkbox")
-					membersForm.elements[i].checked = !membersSwap;
-			}
-		}
-
-		function checkAttributeValidity()
-		{
-			origText = \'', $txt['reattribute_confirm'], '\';
-			valid = true;
-
-			// Do all the fields!
-			if (!document.getElementById(\'to\').value)
-				valid = false;
-			warningMessage = origText.replace(/%member_to%/, document.getElementById(\'to\').value);
-
-			if (document.getElementById(\'type_email\').checked)
-			{
-				if (!document.getElementById(\'from_email\').value)
-					valid = false;
-				warningMessage = warningMessage.replace(/%type%/, \'', addcslashes($txt['reattribute_confirm_email'], "'"), '\').replace(/%find%/, document.getElementById(\'from_email\').value);
-			}
-			else
-			{
-				if (!document.getElementById(\'from_name\').value)
-					valid = false;
-				warningMessage = warningMessage.replace(/%type%/, \'', addcslashes($txt['reattribute_confirm_username'], "'"), '\').replace(/%find%/, document.getElementById(\'from_name\').value);
-			}
-
-			document.getElementById(\'do_attribute\').disabled = valid ? \'\' : \'disabled\';
-
-			setTimeout("checkAttributeValidity();", 500);
-			return valid;
-		}
-		setTimeout("checkAttributeValidity();", 500);
-	// ]]></script>
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_reattribute_posts'], '</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=members;activity=reattribute" method="post" accept-charset="', $context['character_set'], '">
-					<p><strong>', $txt['reattribute_guest_posts'], '</strong></p>
-					<dl class="settings">
-						<dt>
-							<label for="type_email"><input type="radio" name="type" id="type_email" value="email" checked="checked" class="input_radio" />', $txt['reattribute_email'], '</label>
-						</dt>
-						<dd>
-							<input type="text" name="from_email" id="from_email" value="" onclick="document.getElementById(\'type_email\').checked = \'checked\'; document.getElementById(\'from_name\').value = \'\';" />
-						</dd>
-						<dt>
-							<label for="type_name"><input type="radio" name="type" id="type_name" value="name" class="input_radio" />', $txt['reattribute_username'], '</label>
-						</dt>
-						<dd>
-							<input type="text" name="from_name" id="from_name" value="" onclick="document.getElementById(\'type_name\').checked = \'checked\'; document.getElementById(\'from_email\').value = \'\';" class="input_text" />
-						</dd>
-					</dl>
-					<dl class="settings">
-						<dt>
-							<label for="to"><strong>', $txt['reattribute_current_member'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="to" id="to" value="" class="input_text" />
-						</dd>
-					</dl>
-					<p class="maintain_members">
-						<input type="checkbox" name="posts" id="posts" checked="checked" class="input_check" />
-						<label for="posts">', $txt['reattribute_increase_posts'], '</label>
-					</p>
-					<hr class="hrcolor" />
-					<input type="submit" id="do_attribute" value="', $txt['reattribute'], '" onclick="if (!checkAttributeValidity()) return false; 
-					return confirm(warningMessage);" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft">
-					<a href="', $scripturl, '?action=helpadmin;help=maintenance_members" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['maintain_members'], '
-				</span>
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=members;activity=purgeinactive" method="post" accept-charset="', $context['character_set'], '" id="membersForm">
-					<p><a id="membersLink"></a>', $txt['maintain_members_since1'], '
-					<select name="del_type">
-						<option value="activated" selected="selected">', $txt['maintain_members_activated'], '</option>
-						<option value="logged">', $txt['maintain_members_logged_in'], '</option>
-					</select> ', $txt['maintain_members_since2'], ' <input type="text" name="maxdays" value="30" size="3" class="input_text" />', $txt['maintain_members_since3'], '</p>';
-
-	echo '
-					<p><a href="#membersLink" onclick="swapMembers();"><img src="', $settings['images_url'], '/selected.png" alt="+" id="membersIcon" /></a> <a href="#membersLink" onclick="swapMembers();" id="membersText" style="font-weight: bold;">', $txt['maintain_members_all'], '</a></p>
-					<div style="display: none; padding: 3px" id="membersPanel">';
-
-	foreach ($context['membergroups'] as $group)
-		echo '
-						<label for="groups', $group['id'], '"><input type="checkbox" name="groups[', $group['id'], ']" id="groups', $group['id'], '" checked="checked" class="input_check" /> ', $group['name'], '</label><br />';
-
-	echo '
-					</div>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_old_remove'], '" onclick="return confirm(\'', $txt['maintain_members_confirm'], '\');" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_recountposts'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=members;activity=recountposts" method="post" accept-charset="', $context['character_set'], '" id="membersRecountForm">
-					<p>', $txt['maintain_recountposts_info'], '</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>		
-	</div>
-	<br class="clear" />
-
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oAttributeMemberSuggest = new smc_AutoSuggest({
-			sSelf: \'oAttributeMemberSuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sSuggestId: \'attributeMember\',
-			sControlId: \'to\',
-			sSearchType: \'member\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			bItemList: false
-		});
-	// ]]></script>';
-}
-
-// Template for the topic maintenance tasks.
-function template_maintain_topics()
-{
-	global $scripturl, $txt, $context, $settings, $modSettings;
-
-	// If maintenance has finished tell the user.
-	if (!empty($context['maintenance_finished']))
-		echo '
-			<div class="maintenance_finished">
-				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
-			</div>';
-
-	// Bit of javascript for showing which boards to prune in an otherwise hidden list.
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var rotSwap = false;
-			function swapRot()
-			{
-				rotSwap = !rotSwap;
-
-				// Toggle icon
-				document.getElementById("rotIcon").src = smf_images_url + (rotSwap ? "/selected_open.png" : "/selected.png");
-				setInnerHTML(document.getElementById("rotText"), rotSwap ? ', JavaScriptEscape($txt['maintain_old_choose']), ' : ', JavaScriptEscape($txt['maintain_old_all']), ');
-
-				// Toggle panel
-				document.getElementById("rotPanel").style.display = !rotSwap ? "none" : "";
-
-				// Toggle checkboxes
-				var rotPanel = document.getElementById(\'rotPanel\');
-				var oBoardCheckBoxes = rotPanel.getElementsByTagName(\'input\');
-				for (var i = 0; i < oBoardCheckBoxes.length; i++)
-				{
-					if (oBoardCheckBoxes[i].type.toLowerCase() == "checkbox")
-						oBoardCheckBoxes[i].checked = !rotSwap;
-				}
-			}
-		// ]]></script>';
-
-	echo '
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_old'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content flow_auto">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=topics;activity=pruneold" method="post" accept-charset="', $context['character_set'], '">';
-
-	// The otherwise hidden "choose which boards to prune".
-	echo '
-					<p>
-						<a id="rotLink"></a>', $txt['maintain_old_since_days1'], '<input type="text" name="maxdays" value="30" size="3" />', $txt['maintain_old_since_days2'], '
-					</p>
-					<p>
-						<label for="delete_type_nothing"><input type="radio" name="delete_type" id="delete_type_nothing" value="nothing" class="input_radio" /> ', $txt['maintain_old_nothing_else'], '</label><br />
-						<label for="delete_type_moved"><input type="radio" name="delete_type" id="delete_type_moved" value="moved" class="input_radio" checked="checked" /> ', $txt['maintain_old_are_moved'], '</label><br />
-						<label for="delete_type_locked"><input type="radio" name="delete_type" id="delete_type_locked" value="locked" class="input_radio" /> ', $txt['maintain_old_are_locked'], '</label><br />
-					</p>';
-
-	if (!empty($modSettings['enableStickyTopics']))
-		echo '
-					<p>
-						<label for="delete_old_not_sticky"><input type="checkbox" name="delete_old_not_sticky" id="delete_old_not_sticky" class="input_check" checked="checked" /> ', $txt['maintain_old_are_not_stickied'], '</label><br />
-					</p>';
-
-		echo '
-					<p>
-						<a href="#rotLink" onclick="swapRot();"><img src="', $settings['images_url'], '/selected.png" alt="+" id="rotIcon" /></a> <a href="#rotLink" onclick="swapRot();" id="rotText" style="font-weight: bold;">', $txt['maintain_old_all'], '</a>
-					</p>
-					<div style="display: none;" id="rotPanel" class="flow_hidden">
-						<div class="floatleft" style="width: 49%">';
-
-	// This is the "middle" of the list.
-	$middle = ceil(count($context['categories']) / 2);
-
-	$i = 0;
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-							<fieldset>
-								<legend>', $category['name'], '</legend>
-								<ul class="reset">';
-
-		// Display a checkbox with every board.
-		foreach ($category['boards'] as $board)
-			echo '
-									<li style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'] * 1.5, 'em;"><label for="boards_', $board['id'], '"><input type="checkbox" name="boards[', $board['id'], ']" id="boards_', $board['id'], '" checked="checked" class="input_check" />', $board['name'], '</label></li>';
-
-		echo '
-								</ul>
-							</fieldset>';
-
-		// Increase $i, and check if we're at the middle yet.
-		if (++$i == $middle)
-			echo '
-						</div>
-						<div class="floatright" style="width: 49%;">';
-	}
-
-	echo '
-						</div>
-					</div>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['maintain_old_remove'], '" onclick="return confirm(\'', $txt['maintain_old_confirm'], '\');" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['move_topics_maintenance'], '</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=topics;activity=massmove" method="post" accept-charset="', $context['character_set'], '">
-					<p><label for="id_board_from">', $txt['move_topics_from'], ' </label>
-					<select name="id_board_from" id="id_board_from">
-						<option disabled="disabled">(', $txt['move_topics_select_board'], ')</option>';
-
-	// From board
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-						<option disabled="disabled">--------------------------------------</option>
-						<option disabled="disabled">', $category['name'], '</option>
-						<option disabled="disabled">--------------------------------------</option>';
-
-		foreach ($category['boards'] as $board)
-			echo '
-						<option value="', $board['id'], '"> ', str_repeat('==', $board['child_level']), '=&gt;&nbsp;', $board['name'], '</option>';
-	}
-
-	echo '
-					</select>
-					<label for="id_board_to">', $txt['move_topics_to'], '</label>
-					<select name="id_board_to" id="id_board_to">
-						<option disabled="disabled">(', $txt['move_topics_select_board'], ')</option>';
-
-	// To board
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-						<option disabled="disabled">--------------------------------------</option>
-						<option disabled="disabled">', $category['name'], '</option>
-						<option disabled="disabled">--------------------------------------</option>';
-
-		foreach ($category['boards'] as $board)
-			echo '
-						<option value="', $board['id'], '"> ', str_repeat('==', $board['child_level']), '=&gt;&nbsp;', $board['name'], '</option>';
-	}
-	echo '
-					</select></p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['move_topics_now'], '" onclick="if (document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_from\').selectedIndex].disabled || document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_to\').selectedIndex].disabled) return false; var confirmText = \'', $txt['move_topics_confirm'] . '\'; return confirm(confirmText.replace(/%board_from%/, document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_from\').selectedIndex].text.replace(/^=+&gt;&nbsp;/, \'\')).replace(/%board_to%/, document.getElementById(\'id_board_to\').options[document.getElementById(\'id_board_to\').selectedIndex].text.replace(/^=+&gt;&nbsp;/, \'\')));" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-// Simple template for showing results of our optimization...
-function template_optimize()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['maintain_optimize'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>
-					', $txt['database_numb_tables'], '<br />
-					', $txt['database_optimize_attempt'], '<br />';
-
-	// List each table being optimized...
-	foreach ($context['optimized_tables'] as $table)
-		echo '
-					', sprintf($txt['database_optimizing'], $table['name'], $table['data_freed']), '<br />';
-
-	// How did we go?
-	echo '
-					<br />', $context['num_tables_optimized'] == 0 ? $txt['database_already_optimized'] : $context['num_tables_optimized'] . ' ' . $txt['database_optimized'];
-
-	echo '
-				</p>
-				<p><a href="', $scripturl, '?action=admin;area=maintain">', $txt['maintain_return'], '</a></p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_convert_utf8()
-{
-	global $context, $txt, $settings, $scripturl;
-
-	echo '
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['utf8_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertutf8" method="post" accept-charset="', $context['character_set'], '">
-					<p>', $txt['utf8_introduction'], '</p>
-					<div>', $txt['utf8_warning'], '</div>
-
-					<dl class="settings">
-						<dt><strong>', $txt['utf8_source_charset'], ':</strong></dt>
-						<dd><select name="src_charset">';
-	foreach ($context['charset_list'] as $charset)
-		echo '
-							<option value="', $charset, '"', $charset === $context['charset_detected'] ? ' selected="selected"' : '', '>', $charset, '</option>';
-	echo '
-							</select></dd>
-						<dt><strong>', $txt['utf8_database_charset'], ':</strong></dt>
-						<dd>', $context['database_charset'], '</dd>
-						<dt><strong>', $txt['utf8_target_charset'], ': </strong></dt>
-						<dd>', $txt['utf8_utf8'], '</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['utf8_proceed'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
-					<input type="hidden" name="proceed" value="1" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_convert_entities()
-{
-	global $context, $txt, $settings, $scripturl;
-
-	echo '
-	<div id="manage_maintenance">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['entity_convert_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['entity_convert_introduction'], '</p>
-				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertentities;start=0;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-				<hr class="hrcolor" />
-				<input type="submit" value="', $txt['entity_convert_proceed'], '" class="button_submit" />
-				<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Template for the database maintenance tasks.
+function template_maintain_database()
+{
+	global $context, $settings, $options, $txt, $scripturl, $db_type, $modSettings;
+
+	// If maintenance has finished tell the user.
+	if (!empty($context['maintenance_finished']))
+		echo '
+			<div class="maintenance_finished">
+				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
+			</div>';
+
+	echo '
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_optimize'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=optimize" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_optimize_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+					<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+
+		<div class="cat_bar">
+			<h3 class="catbg">
+			<a href="', $scripturl, '?action=helpadmin;help=maintenance_backup" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['maintain_backup'], '
+			</h3>
+		</div>
+
+		<div class="windowbg2">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=backup" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_backup_info'], '</p>';
+
+	if ($db_type == 'sqlite')
+		echo '
+					<hr class="hrcolor" />
+					<p>
+						<input type="submit" value="', $txt['maintain_backup_save'], '" id="submitDump" class="button_submit" />
+						<br class="clear_right" />
+					</p>';
+	else
+	{
+		if ($context['safe_mode_enable'])
+			echo '
+					<div class="errorbox">', $txt['safe_mode_enabled'], '</div>';
+		else
+			echo '
+					<div class="', $context['suggested_method'] == 'use_external_tool' || $context['use_maintenance'] != 0 ? 'errorbox' : 'noticebox', '">
+						', $txt[$context['suggested_method']],
+						$context['use_maintenance'] != 0 ? '<br />' . $txt['enable_maintenance' . $context['use_maintenance']] : '',
+					'</div>';
+
+		echo '
+					<p>
+						<label for="struct"><input type="checkbox" name="struct" id="struct" onclick="document.getElementById(\'submitDump\').disabled = !document.getElementById(\'struct\').checked &amp;&amp; !document.getElementById(\'data\').checked;" class="input_check" checked="checked" /> ', $txt['maintain_backup_struct'], '</label><br />
+						<label for="data"><input type="checkbox" name="data" id="data" onclick="document.getElementById(\'submitDump\').disabled = !document.getElementById(\'struct\').checked &amp;&amp; !document.getElementById(\'data\').checked;" checked="checked" class="input_check" /> ', $txt['maintain_backup_data'], '</label><br />
+						<label for="compress"><input type="checkbox" name="compress" id="compress" value="gzip"', $context['suggested_method'] == 'zipped_file' ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['maintain_backup_gz'], '</label>
+					</p>
+					<hr class="hrcolor" />
+					<p>
+						<input ', $context['use_maintenance'] == 2 ? 'disabled="disabled" ' : '', 'type="submit" value="', $txt['maintain_backup_save'], '" id="submitDump" onclick="return document.getElementById(\'struct\').checked || document.getElementById(\'data\').checked;" class="button_submit" />
+						<br class="clear_right" />
+					</p>';
+	}
+
+	echo '
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>';
+
+	// Show an option to convert to UTF-8 if we're not on UTF-8 yet.
+	if ($context['convert_utf8'])
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['utf8_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertutf8" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['utf8_introduction'], '</p>
+					', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext' ? '<p class="errorbox">' . $txt['utf8_cannot_convert_fulltext'] . '</p>' : '', '
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" ', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext' ? 'disabled="disabled"' : '', '/><br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>';
+	}
+
+	// We might want to convert entities if we're on UTF-8.
+	if ($context['convert_entities'])
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['entity_convert_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertentities" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['entity_convert_introduction'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>';
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+// Template for the routine maintenance tasks.
+function template_maintain_routine()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	// If maintenance has finished tell the user.
+	if (!empty($context['maintenance_finished']))
+		echo '
+			<div class="maintenance_finished">
+				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
+			</div>';
+
+	// Starts off with general maintenance procedures.
+	echo '
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_version'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=version" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_version_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_errors'], '</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=repairboards" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_errors_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_recount'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=recount" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_recount_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_logs'], '</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=logs" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_logs_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_cache'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=cleancache" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['maintain_cache_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+// Template for the member maintenance tasks.
+function template_maintain_members()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// If maintenance has finished tell the user.
+	if (!empty($context['maintenance_finished']))
+		echo '
+			<div class="maintenance_finished">
+				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
+			</div>';
+
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var warningMessage = \'\';
+		var membersSwap = false;
+
+		function swapMembers()
+		{
+			membersSwap = !membersSwap;
+			var membersForm = document.getElementById(\'membersForm\');
+
+			document.getElementById("membersIcon").src = smf_images_url + (membersSwap ? "/selected_open.png" : "/selected.png");
+			setInnerHTML(document.getElementById("membersText"), membersSwap ? "', $txt['maintain_members_choose'], '" : "', $txt['maintain_members_all'], '");
+			document.getElementById("membersPanel").style.display = (membersSwap ? "block" : "none");
+
+			for (var i = 0; i < membersForm.length; i++)
+			{
+				if (membersForm.elements[i].type.toLowerCase() == "checkbox")
+					membersForm.elements[i].checked = !membersSwap;
+			}
+		}
+
+		function checkAttributeValidity()
+		{
+			origText = \'', $txt['reattribute_confirm'], '\';
+			valid = true;
+
+			// Do all the fields!
+			if (!document.getElementById(\'to\').value)
+				valid = false;
+			warningMessage = origText.replace(/%member_to%/, document.getElementById(\'to\').value);
+
+			if (document.getElementById(\'type_email\').checked)
+			{
+				if (!document.getElementById(\'from_email\').value)
+					valid = false;
+				warningMessage = warningMessage.replace(/%type%/, \'', addcslashes($txt['reattribute_confirm_email'], "'"), '\').replace(/%find%/, document.getElementById(\'from_email\').value);
+			}
+			else
+			{
+				if (!document.getElementById(\'from_name\').value)
+					valid = false;
+				warningMessage = warningMessage.replace(/%type%/, \'', addcslashes($txt['reattribute_confirm_username'], "'"), '\').replace(/%find%/, document.getElementById(\'from_name\').value);
+			}
+
+			document.getElementById(\'do_attribute\').disabled = valid ? \'\' : \'disabled\';
+
+			setTimeout("checkAttributeValidity();", 500);
+			return valid;
+		}
+		setTimeout("checkAttributeValidity();", 500);
+	// ]]></script>
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_reattribute_posts'], '</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=members;activity=reattribute" method="post" accept-charset="', $context['character_set'], '">
+					<p><strong>', $txt['reattribute_guest_posts'], '</strong></p>
+					<dl class="settings">
+						<dt>
+							<label for="type_email"><input type="radio" name="type" id="type_email" value="email" checked="checked" class="input_radio" />', $txt['reattribute_email'], '</label>
+						</dt>
+						<dd>
+							<input type="text" name="from_email" id="from_email" value="" onclick="document.getElementById(\'type_email\').checked = \'checked\'; document.getElementById(\'from_name\').value = \'\';" />
+						</dd>
+						<dt>
+							<label for="type_name"><input type="radio" name="type" id="type_name" value="name" class="input_radio" />', $txt['reattribute_username'], '</label>
+						</dt>
+						<dd>
+							<input type="text" name="from_name" id="from_name" value="" onclick="document.getElementById(\'type_name\').checked = \'checked\'; document.getElementById(\'from_email\').value = \'\';" class="input_text" />
+						</dd>
+					</dl>
+					<dl class="settings">
+						<dt>
+							<label for="to"><strong>', $txt['reattribute_current_member'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="to" id="to" value="" class="input_text" />
+						</dd>
+					</dl>
+					<p class="maintain_members">
+						<input type="checkbox" name="posts" id="posts" checked="checked" class="input_check" />
+						<label for="posts">', $txt['reattribute_increase_posts'], '</label>
+					</p>
+					<hr class="hrcolor" />
+					<input type="submit" id="do_attribute" value="', $txt['reattribute'], '" onclick="if (!checkAttributeValidity()) return false; 
+					return confirm(warningMessage);" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=helpadmin;help=maintenance_members" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['maintain_members'], '
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=members;activity=purgeinactive" method="post" accept-charset="', $context['character_set'], '" id="membersForm">
+					<p><a id="membersLink"></a>', $txt['maintain_members_since1'], '
+					<select name="del_type">
+						<option value="activated" selected="selected">', $txt['maintain_members_activated'], '</option>
+						<option value="logged">', $txt['maintain_members_logged_in'], '</option>
+					</select> ', $txt['maintain_members_since2'], ' <input type="text" name="maxdays" value="30" size="3" class="input_text" />', $txt['maintain_members_since3'], '</p>';
+
+	echo '
+					<p><a href="#membersLink" onclick="swapMembers();"><img src="', $settings['images_url'], '/selected.png" alt="+" id="membersIcon" /></a> <a href="#membersLink" onclick="swapMembers();" id="membersText" style="font-weight: bold;">', $txt['maintain_members_all'], '</a></p>
+					<div style="display: none; padding: 3px" id="membersPanel">';
+
+	foreach ($context['membergroups'] as $group)
+		echo '
+						<label for="groups', $group['id'], '"><input type="checkbox" name="groups[', $group['id'], ']" id="groups', $group['id'], '" checked="checked" class="input_check" /> ', $group['name'], '</label><br />';
+
+	echo '
+					</div>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_old_remove'], '" onclick="return confirm(\'', $txt['maintain_members_confirm'], '\');" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_recountposts'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=members;activity=recountposts" method="post" accept-charset="', $context['character_set'], '" id="membersRecountForm">
+					<p>', $txt['maintain_recountposts_info'], '</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />
+
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oAttributeMemberSuggest = new smc_AutoSuggest({
+			sSelf: \'oAttributeMemberSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'attributeMember\',
+			sControlId: \'to\',
+			sSearchType: \'member\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			bItemList: false
+		});
+	// ]]></script>';
+}
+
+// Template for the topic maintenance tasks.
+function template_maintain_topics()
+{
+	global $scripturl, $txt, $context, $settings, $modSettings;
+
+	// If maintenance has finished tell the user.
+	if (!empty($context['maintenance_finished']))
+		echo '
+			<div class="maintenance_finished">
+				', sprintf($txt['maintain_done'], $context['maintenance_finished']), '
+			</div>';
+
+	// Bit of javascript for showing which boards to prune in an otherwise hidden list.
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var rotSwap = false;
+			function swapRot()
+			{
+				rotSwap = !rotSwap;
+
+				// Toggle icon
+				document.getElementById("rotIcon").src = smf_images_url + (rotSwap ? "/selected_open.png" : "/selected.png");
+				setInnerHTML(document.getElementById("rotText"), rotSwap ? ', JavaScriptEscape($txt['maintain_old_choose']), ' : ', JavaScriptEscape($txt['maintain_old_all']), ');
+
+				// Toggle panel
+				document.getElementById("rotPanel").style.display = !rotSwap ? "none" : "";
+
+				// Toggle checkboxes
+				var rotPanel = document.getElementById(\'rotPanel\');
+				var oBoardCheckBoxes = rotPanel.getElementsByTagName(\'input\');
+				for (var i = 0; i < oBoardCheckBoxes.length; i++)
+				{
+					if (oBoardCheckBoxes[i].type.toLowerCase() == "checkbox")
+						oBoardCheckBoxes[i].checked = !rotSwap;
+				}
+			}
+		// ]]></script>';
+
+	echo '
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_old'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content flow_auto">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=topics;activity=pruneold" method="post" accept-charset="', $context['character_set'], '">';
+
+	// The otherwise hidden "choose which boards to prune".
+	echo '
+					<p>
+						<a id="rotLink"></a>', $txt['maintain_old_since_days1'], '<input type="text" name="maxdays" value="30" size="3" />', $txt['maintain_old_since_days2'], '
+					</p>
+					<p>
+						<label for="delete_type_nothing"><input type="radio" name="delete_type" id="delete_type_nothing" value="nothing" class="input_radio" /> ', $txt['maintain_old_nothing_else'], '</label><br />
+						<label for="delete_type_moved"><input type="radio" name="delete_type" id="delete_type_moved" value="moved" class="input_radio" checked="checked" /> ', $txt['maintain_old_are_moved'], '</label><br />
+						<label for="delete_type_locked"><input type="radio" name="delete_type" id="delete_type_locked" value="locked" class="input_radio" /> ', $txt['maintain_old_are_locked'], '</label><br />
+					</p>';
+
+	if (!empty($modSettings['enableStickyTopics']))
+		echo '
+					<p>
+						<label for="delete_old_not_sticky"><input type="checkbox" name="delete_old_not_sticky" id="delete_old_not_sticky" class="input_check" checked="checked" /> ', $txt['maintain_old_are_not_stickied'], '</label><br />
+					</p>';
+
+		echo '
+					<p>
+						<a href="#rotLink" onclick="swapRot();"><img src="', $settings['images_url'], '/selected.png" alt="+" id="rotIcon" /></a> <a href="#rotLink" onclick="swapRot();" id="rotText" style="font-weight: bold;">', $txt['maintain_old_all'], '</a>
+					</p>
+					<div style="display: none;" id="rotPanel" class="flow_hidden">
+						<div class="floatleft" style="width: 49%">';
+
+	// This is the "middle" of the list.
+	$middle = ceil(count($context['categories']) / 2);
+
+	$i = 0;
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+							<fieldset>
+								<legend>', $category['name'], '</legend>
+								<ul class="reset">';
+
+		// Display a checkbox with every board.
+		foreach ($category['boards'] as $board)
+			echo '
+									<li style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'] * 1.5, 'em;"><label for="boards_', $board['id'], '"><input type="checkbox" name="boards[', $board['id'], ']" id="boards_', $board['id'], '" checked="checked" class="input_check" />', $board['name'], '</label></li>';
+
+		echo '
+								</ul>
+							</fieldset>';
+
+		// Increase $i, and check if we're at the middle yet.
+		if (++$i == $middle)
+			echo '
+						</div>
+						<div class="floatright" style="width: 49%;">';
+	}
+
+	echo '
+						</div>
+					</div>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['maintain_old_remove'], '" onclick="return confirm(\'', $txt['maintain_old_confirm'], '\');" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+				</form>
+			</div>
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['move_topics_maintenance'], '</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=topics;activity=massmove" method="post" accept-charset="', $context['character_set'], '">
+					<p><label for="id_board_from">', $txt['move_topics_from'], ' </label>
+					<select name="id_board_from" id="id_board_from">
+						<option disabled="disabled">(', $txt['move_topics_select_board'], ')</option>';
+
+	// From board
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+						<option disabled="disabled">--------------------------------------</option>
+						<option disabled="disabled">', $category['name'], '</option>
+						<option disabled="disabled">--------------------------------------</option>';
+
+		foreach ($category['boards'] as $board)
+			echo '
+						<option value="', $board['id'], '"> ', str_repeat('==', $board['child_level']), '=&gt;&nbsp;', $board['name'], '</option>';
+	}
+
+	echo '
+					</select>
+					<label for="id_board_to">', $txt['move_topics_to'], '</label>
+					<select name="id_board_to" id="id_board_to">
+						<option disabled="disabled">(', $txt['move_topics_select_board'], ')</option>';
+
+	// To board
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+						<option disabled="disabled">--------------------------------------</option>
+						<option disabled="disabled">', $category['name'], '</option>
+						<option disabled="disabled">--------------------------------------</option>';
+
+		foreach ($category['boards'] as $board)
+			echo '
+						<option value="', $board['id'], '"> ', str_repeat('==', $board['child_level']), '=&gt;&nbsp;', $board['name'], '</option>';
+	}
+	echo '
+					</select></p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['move_topics_now'], '" onclick="if (document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_from\').selectedIndex].disabled || document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_to\').selectedIndex].disabled) return false; var confirmText = \'', $txt['move_topics_confirm'] . '\'; return confirm(confirmText.replace(/%board_from%/, document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_from\').selectedIndex].text.replace(/^=+&gt;&nbsp;/, \'\')).replace(/%board_to%/, document.getElementById(\'id_board_to\').options[document.getElementById(\'id_board_to\').selectedIndex].text.replace(/^=+&gt;&nbsp;/, \'\')));" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+// Simple template for showing results of our optimization...
+function template_optimize()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['maintain_optimize'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>
+					', $txt['database_numb_tables'], '<br />
+					', $txt['database_optimize_attempt'], '<br />';
+
+	// List each table being optimized...
+	foreach ($context['optimized_tables'] as $table)
+		echo '
+					', sprintf($txt['database_optimizing'], $table['name'], $table['data_freed']), '<br />';
+
+	// How did we go?
+	echo '
+					<br />', $context['num_tables_optimized'] == 0 ? $txt['database_already_optimized'] : $context['num_tables_optimized'] . ' ' . $txt['database_optimized'];
+
+	echo '
+				</p>
+				<p><a href="', $scripturl, '?action=admin;area=maintain">', $txt['maintain_return'], '</a></p>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_convert_utf8()
+{
+	global $context, $txt, $settings, $scripturl;
+
+	echo '
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['utf8_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertutf8" method="post" accept-charset="', $context['character_set'], '">
+					<p>', $txt['utf8_introduction'], '</p>
+					<div>', $txt['utf8_warning'], '</div>
+
+					<dl class="settings">
+						<dt><strong>', $txt['utf8_source_charset'], ':</strong></dt>
+						<dd><select name="src_charset">';
+	foreach ($context['charset_list'] as $charset)
+		echo '
+							<option value="', $charset, '"', $charset === $context['charset_detected'] ? ' selected="selected"' : '', '>', $charset, '</option>';
+	echo '
+							</select></dd>
+						<dt><strong>', $txt['utf8_database_charset'], ':</strong></dt>
+						<dd>', $context['database_charset'], '</dd>
+						<dt><strong>', $txt['utf8_target_charset'], ': </strong></dt>
+						<dd>', $txt['utf8_utf8'], '</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['utf8_proceed'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />
+					<input type="hidden" name="proceed" value="1" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_convert_entities()
+{
+	global $context, $txt, $settings, $scripturl;
+
+	echo '
+	<div id="manage_maintenance">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['entity_convert_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $txt['entity_convert_introduction'], '</p>
+				<form action="', $scripturl, '?action=admin;area=maintain;sa=database;activity=convertentities;start=0;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+				<hr class="hrcolor" />
+				<input type="submit" value="', $txt['entity_convert_proceed'], '" class="button_submit" />
+				<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 697 - 707
Themes/default/ManageMembergroups.template.php

@@ -1,708 +1,698 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_main()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	template_show_list('regular_membergroups_list');
-	echo '<br /><br />';
-	template_show_list('post_count_membergroups_list');
-
-}
-
-function template_new_group()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form id="new_group" action="', $scripturl, '?action=admin;area=membergroups;sa=add" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['membergroups_new_group'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="group_name_input"><strong>', $txt['membergroups_group_name'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="group_name" id="group_name_input" size="30" class="input_text" />
-						</dd>';
-	if ($context['undefined_group'])
-	{
-		echo '
-						<dt>
-							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], '</strong>:</label>
-						</dt>
-						<dd>
-							<fieldset id="group_type">
-								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
-								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" checked="checked" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';
-
-		if ($context['allow_protected'])
-			echo '
-								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';
-
-		echo '
-								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
-								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
-								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
-							</fieldset>
-						</dd>';
-	}
-
-	if ($context['post_group'] || $context['undefined_group'])
-		echo '
-						<dt id="min_posts_text">
-							<strong>', $txt['membergroups_min_posts'], ':</strong>
-						</dt>
-						<dd>
-							<input type="text" name="min_posts" id="min_posts_input" size="5" class="input_text" />
-						</dd>';
-	if (!$context['post_group'] || !empty($modSettings['permission_enable_postgroups']))
-	{
-		echo '
-						<dt>
-							<label for="permission_base"><strong>', $txt['membergroups_permissions'], ':</strong></label><br />
-							<span class="smalltext">', $txt['membergroups_can_edit_later'], '</span>
-						</dt>
-						<dd>
-							<fieldset id="permission_base">
-								<legend>', $txt['membergroups_select_permission_type'], '</legend>
-								<input type="radio" name="perm_type" id="perm_type_inherit" value="inherit" checked="checked" class="input_radio" />
-								<label for="perm_type_inherit">', $txt['membergroups_new_as_inherit'], ':</label>
-								<select name="inheritperm" id="inheritperm_select" onclick="document.getElementById(\'perm_type_inherit\').checked = true;">
-									<option value="-1">', $txt['membergroups_guests'], '</option>
-									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
-		foreach ($context['groups'] as $group)
-			echo '
-									<option value="', $group['id'], '">', $group['name'], '</option>';
-		echo '
-								</select><br />
-
-								<input type="radio" name="perm_type" id="perm_type_copy" value="copy" class="input_radio" />
-								<label for="perm_type_copy">', $txt['membergroups_new_as_copy'], ':</label>
-								<select name="copyperm" id="copyperm_select" onclick="document.getElementById(\'perm_type_copy\').checked = true;">
-									<option value="-1">', $txt['membergroups_guests'], '</option>
-									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
-		foreach ($context['groups'] as $group)
-			echo '
-									<option value="', $group['id'], '">', $group['name'], '</option>';
-		echo '
-								</select><br />
-
-								<input type="radio" name="perm_type" id="perm_type_predefined" value="predefined" class="input_radio" />
-								<label for="perm_type_predefined">', $txt['membergroups_new_as_type'], ':</label>
-								<select name="level" id="level_select" onclick="document.getElementById(\'perm_type_predefined\').checked = true;">
-									<option value="restrict">', $txt['permitgroups_restrict'], '</option>
-									<option value="standard" selected="selected">', $txt['permitgroups_standard'], '</option>
-									<option value="moderator">', $txt['permitgroups_moderator'], '</option>
-									<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
-								</select>
-							</fieldset>
-						</dd>';
-	}
-
-	echo '
-						<dt>
-							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['post_group'] ? '<br />
-							<span class="smalltext" style="font-weight: normal">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
-						</dt>
-						<dd>';
-
-	template_add_edit_group_boards_list(false);
-
-	echo '
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['membergroups_add_group'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	if ($context['undefined_group'])
-	{
-		echo '
-			<script type="text/javascript"><!-- // --><![CDATA[
-				function swapPostGroup(isChecked)
-				{
-					var min_posts_text = document.getElementById(\'min_posts_text\');
-					document.getElementById(\'min_posts_input\').disabled = !isChecked;
-					min_posts_text.style.color = isChecked ? "" : "#888888";
-				}
-				swapPostGroup(', $context['post_group'] ? 'true' : 'false', ');
-			// ]]></script>';
-	}
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_edit_group()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=membergroups;sa=edit;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="groupForm" id="groupForm">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['membergroups_edit_group'], ' - ', $context['group']['name'], '
-				</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="group_name_input"><strong>', $txt['membergroups_edit_name'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30" class="input_text" />
-						</dd>';
-
-	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
-		echo '
-
-						<dt id="group_desc_text">
-							<label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label>
-						</dt>
-						<dd>
-							<textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea>
-						</dd>';
-
-	// Group type...
-	if ($context['group']['allow_post_group'])
-	{
-		echo '
-						<dt>
-							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], ':</strong></label>
-						</dt>
-						<dd>
-							<fieldset id="group_type">
-								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
-								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" ', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';
-
-		if ($context['group']['allow_protected'])
-			echo '
-								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" ', $context['group']['type'] == 1 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';
-
-		echo '
-								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" ', $context['group']['type'] == 2 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
-								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" ', $context['group']['type'] == 3 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
-								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" ', $context['group']['is_post_group'] ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
-							</fieldset>
-						</dd>';
-	}
-
-	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
-		echo '
-						<dt id="group_moderators_text">
-							<label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="group_moderators" id="group_moderators" value="', $context['group']['moderator_list'], '" size="30" class="input_text" />
-							<div id="moderator_container"></div>
-						</dd>
-						<dt id="group_hidden_text">
-							<label for="group_hidden_input"><strong>', $txt['membergroups_edit_hidden'], ':</strong></label>
-						</dt>
-						<dd>
-							<select name="group_hidden" id="group_hidden_input" onchange="if (this.value == 2 &amp;&amp; !confirm(\'', $txt['membergroups_edit_hidden_warning'], '\')) this.value = 0;">
-								<option value="0" ', $context['group']['hidden'] ? '' : 'selected="selected"', '>', $txt['membergroups_edit_hidden_no'], '</option>
-								<option value="1" ', $context['group']['hidden'] == 1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_boardindex'], '</option>
-								<option value="2" ', $context['group']['hidden'] == 2 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_all'], '</option>
-							</select>
-						</dd>';
-
-	// Can they inherit permissions?
-	if ($context['group']['id'] > 1 && $context['group']['id'] != 3)
-	{
-		echo '
-						<dt id="group_inherit_text">
-							<label for="group_inherit_input"><strong>', $txt['membergroups_edit_inherit_permissions'], '</strong></label>:<br />
-							<span class="smalltext">', $txt['membergroups_edit_inherit_permissions_desc'], '</span>
-						</dt>
-						<dd>
-							<select name="group_inherit" id="group_inherit_input">
-								<option value="-2">', $txt['membergroups_edit_inherit_permissions_no'], '</option>
-								<option value="-1" ', $context['group']['inherited_from'] == -1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_guests'], '</option>
-								<option value="0" ', $context['group']['inherited_from'] == 0 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>';
-
-		// For all the inheritable groups show an option.
-		foreach ($context['inheritable_groups'] as $id => $group)
-			echo '
-								<option value="', $id, '" ', $context['group']['inherited_from'] == $id ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>';
-
-		echo '
-							</select>
-							<input type="hidden" name="old_inherit" value="', $context['group']['inherited_from'], '" />
-						</dd>';
-	}
-
-	if ($context['group']['allow_post_group'])
-		echo '
-
-						<dt id="min_posts_text">
-							<label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6" class="input_text" />
-						</dd>';
-	echo '
-						<dt>
-							<label for="online_color_input"><strong>', $txt['membergroups_online_color'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="online_color" id="online_color_input" value="', $context['group']['color'], '" size="20" class="input_text" />
-						</dd>
-						<dt>
-							<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" onkeyup="if (this.value.length > 2) this.value = 99;" onkeydown="this.onkeyup();" onchange="if (this.value != 0) this.form.icon_image.onchange();" class="input_text" />
-						</dd>
-						<dt>
-							<label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br />
-							<span class="smalltext">', $txt['membergroups_icon_image_note'], '</span>
-						</dt>
-						<dd>
-							', $txt['membergroups_images_url'], '
-							<input type="text" name="icon_image" id="icon_image_input" value="', $context['group']['icon_image'], '" onchange="if (this.value &amp;&amp; this.form.icon_count.value == 0) this.form.icon_count.value = 1; else if (!this.value) this.form.icon_count.value = 0; document.getElementById(\'star_preview\').src = smf_images_url + \'/\' + (this.value &amp;&amp; this.form.icon_count.value > 0 ? this.value.replace(/\$language/g, \'', $context['user']['language'], '\') : \'blank.png\');" size="20" class="input_text" />
-							<img id="star_preview" src="', $settings['images_url'], '/', $context['group']['icon_image'] == '' ? 'blank.png' : $context['group']['icon_image'], '" alt="*" />
-						</dd>
-						<dt>
-							<label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br />
-							<span class="smalltext">', $txt['membergroups_max_messages_note'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="max_messages" id="max_messages_input" value="', $context['group']['id'] == 1 ? 0 : $context['group']['max_messages'], '" size="6"', $context['group']['id'] == 1 ? ' disabled="disabled"' : '', ' class="input_text" />
-						</dd>';
-	if (!empty($context['categories']))
-	{
-		echo '
-						<dt>
-							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br />
-							<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
-						</dt>
-						<dd>';
-		template_add_edit_group_boards_list();
-		echo '
-						</dd>';
-	}
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['membergroups_edit_save'], '" class="button_submit" />', $context['group']['allow_delete'] ? '
-					<input type="submit" name="delete" value="' . $txt['membergroups_delete'] . '" onclick="return confirm(\'' . $txt['membergroups_confirm_delete'] . '\');" class="button_submit" />' : '', '
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var oModeratorSuggest = new smc_AutoSuggest({
-				sSelf: \'oModeratorSuggest\',
-				sSessionId: smf_session_id,
-				sSessionVar: smf_session_var,
-				sSuggestId: \'group_moderators\',
-				sControlId: \'group_moderators\',
-				sSearchType: \'member\',
-				bItemList: true,
-				sPostName: \'moderator_list\',
-				sURLMask: \'action=profile;u=%item_id%\',
-				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-				sItemListContainerId: \'moderator_container\',
-				aListItems: [';
-
-			foreach ($context['group']['moderators'] as $id_member => $member_name)
-				echo '
-							{
-								sItemId: ', JavaScriptEscape($id_member), ',
-								sItemName: ', JavaScriptEscape($member_name), '
-							}', $id_member == $context['group']['last_moderator_id'] ? '' : ',';
-
-			echo '
-				]
-			});
-		// ]]></script>';
-
-	if ($context['group']['allow_post_group'])
-		echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			function swapPostGroup(isChecked)
-			{
-				var min_posts_text = document.getElementById(\'min_posts_text\');
-				var group_desc_text = document.getElementById(\'group_desc_text\');
-				var group_hidden_text = document.getElementById(\'group_hidden_text\');
-				var group_moderators_text = document.getElementById(\'group_moderators_text\');
-				document.forms.groupForm.min_posts.disabled = !isChecked;
-				min_posts_text.style.color = isChecked ? "" : "#888888";
-				document.forms.groupForm.group_desc_input.disabled = isChecked;
-				group_desc_text.style.color = !isChecked ? "" : "#888888";
-				document.forms.groupForm.group_hidden_input.disabled = isChecked;
-				group_hidden_text.style.color = !isChecked ? "" : "#888888";
-				document.forms.groupForm.group_moderators.disabled = isChecked;
-				group_moderators_text.style.color = !isChecked ? "" : "#888888";
-			}
-			swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', ');
-		// ]]></script>';
-}
-
-function template_add_edit_group_boards_list($collapse = true)
-{
-	global $context, $txt, $modSettings;
-	echo '
-							<fieldset id="visible_boards">
-								<legend>', $txt['membergroups_new_board_desc'], '</legend>
-								<ul class="ignoreboards floatleft">';
-
-	foreach ($context['categories'] as $category)
-	{
-		if (empty($modSettings['deny_boards_access']))
-			echo '
-									<li class="category">
-										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'new_group\'); return false;"><strong>', $category['name'], '</strong></a>
-									<ul style="width:100%">';
-		else
-			echo '
-									<li class="category">
-										<strong>', $category['name'], '</strong>
-										<span class="select_all_box">
-											<em style="margin-left:5em;">', $txt['all_boards_in_cat'], ': </em>
-											<select onchange="select_in_category(', $category['id'], ', this, [', implode(',', array_keys($category['boards'])), ']);">
-												<option>---</option>
-												<option value="allow">', $txt['board_perms_allow'], '</option>
-												<option value="ignore">', $txt['board_perms_ignore'], '</option>
-												<option value="deny">', $txt['board_perms_deny'], '</option>
-											</select>
-										</span>
-										<ul style="width:100%" id="boards_list_', $category['id'], '">';
-
-		foreach ($category['boards'] as $board)
-		{
-			if (empty($modSettings['deny_boards_access']))
-				echo '
-										<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
-											<input type="checkbox" name="boardaccess[', $board['id'], ']" id="brd', $board['id'], '" value="\'allow\'" ', $board['allow'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="brd', $board['id'], '">', $board['name'], '</label>
-										</li>';
-			else
-				echo '
-											<li class="board" style="width:100%">
-												<span style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">', $board['name'], ': </span>
-												<span style="width:50%;float:right">
-													<input type="radio" name="boardaccess[', $board['id'], ']" id="allow_brd', $board['id'], '" value="allow" ', $board['allow'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="allow_brd', $board['id'], '">', $txt['permissions_option_on'], '</label>
-													<input type="radio" name="boardaccess[', $board['id'], ']" id="ignore_brd', $board['id'], '" value="ignore" ', !$board['allow'] && !$board['deny'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="ignore_brd', $board['id'], '">', $txt['permissions_option_off'], '</label>
-													<input type="radio" name="boardaccess[', $board['id'], ']" id="deny_brd', $board['id'], '" value="deny" ', $board['deny'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="deny_brd', $board['id'], '">', $txt['permissions_option_deny'], '</label>
-												</span>
-											</li>';
-		}
-
-		echo '
-									</ul>
-								</li>';
-	}
-
-	echo '
-							</ul>
-							<br class="clear" />';
-
-	if (empty($modSettings['deny_boards_access']))
-		echo '
-								<br />
-								<input type="checkbox" id="checkall_check" class="input_check" onclick="invertAll(this, this.form, \'boardaccess\');" /> <label for="checkall_check"><em>', $txt['check_all'], '</em></label>
-							</fieldset>';
-	else
-		echo '
-								<br />
-								<span class="select_all_box">
-									<em>', $txt['all'], ': </em>
-									<input type="radio" name="select_all" id="allow_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'allow\');" /> <label for="allow_all">', $txt['board_perms_allow'], '</label>
-									<input type="radio" name="select_all" id="ignore_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'ignore\');" /> <label for="ignore_all">', $txt['board_perms_ignore'], '</label>
-									<input type="radio" name="select_all" id="deny_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'deny\');" /> <label for="deny_all">', $txt['board_perms_deny'], '</label>
-								</span>
-							</fieldset>
-							<script type="text/javascript"><!-- // --><![CDATA[
-								$(document).ready(function () {
-									$(".select_all_box").each(function () {
-										$(this).removeClass(\'select_all_box\');
-									});
-								});
-							// ]]></script>';
-
-	if ($collapse)
-		echo '
-							<a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').style.display = \'block\'; document.getElementById(\'visible_boards_link\').style.display = \'none\'; return false;" id="visible_boards_link" style="display: none;">[ ', $txt['membergroups_select_visible_boards'], ' ]</a>
-							<script type="text/javascript"><!-- // --><![CDATA[
-								document.getElementById("visible_boards_link").style.display = "";
-								document.getElementById("visible_boards").style.display = "none";
-							// ]]></script>';
-}
-
-// Templating for viewing the members of a group.
-function template_group_members()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : '') , ';sa=members;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['name'], ':</strong>
-						</dt>
-						<dd>
-							<span ', $context['group']['online_color'] ? 'style="color: ' . $context['group']['online_color'] . ';"' : '', '>', $context['group']['name'], '</span> ', $context['group']['icons'], '
-						</dd>';
-	//Any description to show?
-	if (!empty($context['group']['description']))
-		echo '
-						<dt>
-							<strong>' . $txt['membergroups_members_description'] . ':</strong>
-						</dt>
-						<dd>
-							', $context['group']['description'] ,'
-						</dd>';
-
-	echo '
-						<dt>
-							<strong>', $txt['membergroups_members_top'], ':</strong>
-						</dt>
-						<dd>
-							', $context['total_members'] ,'
-						</dd>';
-	// Any group moderators to show?
-	if (!empty($context['group']['moderators']))
-	{
-		$moderators = array();
-		foreach ($context['group']['moderators'] as $moderator)
-			$moderators[] = '<a href="' . $scripturl . '?action=profile;u=' . $moderator['id'] . '">' . $moderator['name'] . '</a>';
-
-		echo '
-						<dt>
-							<strong>', $txt['membergroups_members_group_moderators'], ':</strong>
-						</dt>
-						<dd>
-							', implode(', ', $moderators) ,'
-						</dd>';
-	}
-
-	echo '
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-
-			<br />
-			<div class="title_bar">
-				<h4 class="titlebg">', $txt['membergroups_members_group_members'], '</h4>
-			</div>
-			<br />
-			<div class="pagesection">', $txt['pages'], ': ', $context['page_index'], '</div>
-			<table width="100%" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th"><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['name'], $context['sort_by'] == 'name' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>';
-
-	if ($context['can_send_email'])
-		echo '
-						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=email', $context['sort_by'] == 'email' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['email'], $context['sort_by'] == 'email' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>';
-
-	echo '
-						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=active', $context['sort_by'] == 'active' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['membergroups_members_last_active'], $context['sort_by'] == 'active' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
-						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=registered', $context['sort_by'] == 'registered' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['date_registered'], $context['sort_by'] == 'registered' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
-						<th ', empty($context['group']['assignable']) ? ' class="last_th" colspan="2"' : '', '><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=posts', $context['sort_by'] == 'posts' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['posts'], $context['sort_by'] == 'posts' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '','</a></th>';
-	if (!empty($context['group']['assignable']))
-		echo '
-						<th class="last_th" width="4%" align="center"><input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" /></th>';
-	echo '
-					</tr>
-				</thead>
-				<tbody>';
-
-	if (empty($context['members']))
-		echo '
-					<tr class="windowbg2">
-						<td colspan="6" align="center">', $txt['membergroups_members_no_members'], '</td>
-					</tr>';
-
-	$alternate = false;
-	foreach ($context['members'] as $member)
-	{
-		$alternate = !$alternate;
-		echo '
-					<tr class="', $alternate === true ? 'windowbg' : 'windowbg2', '">
-						<td>', $member['name'], '</td>';
-		if ($context['can_send_email'])
-		{
-			echo '
-						<td', $member['show_email'] == 'no_through_forum' && $settings['use_image_buttons'] ? ' align="center"' : '', '>';
-
-			// Is it totally hidden?
-			if ($member['show_email'] == 'no')
-				echo '
-								<em>', $txt['hidden'], '</em>';
-			// ... otherwise they want it hidden but it's not to this person?
-			elseif ($member['show_email'] == 'yes_permission_override')
-				echo '
-								<a href="mailto:', $member['email'], '"><em>', $member['email'], '</em></a>';
-			// ... otherwise it's visible - but only via an image?
-			elseif ($member['show_email'] == 'no_through_forum')
-				echo '
-								<a href="', $scripturl, '?action=emailuser;sa=email;uid=', $member['id'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . '" />' : $txt['email']), '</a>';
-			// ... otherwise it must be a 'yes', show it and show it fully.
-			else
-				echo '
-								<a href="mailto:', $member['email'], '">', $member['email'], '</a>';
-			echo '
-						</td>';
-		}
-
-		echo '
-						<td>', $member['last_online'], '</td>
-						<td>', $member['registered'], '</td>
-						<td', empty($context['group']['assignable']) ? ' colspan="2"' : '', '>', $member['posts'], '</td>';
-		if (!empty($context['group']['assignable']))
-			echo '
-						<td align="center" width="4%"><input type="checkbox" name="rem[]" value="', $member['id'], '" class="input_check" ', ($context['user']['id'] == $member['id'] && $context['group']['id'] == 1 ? 'onclick="if (this.checked) return confirm(\'' . $txt['membergroups_members_deadmin_confirm'] . '\')" ' : ''), '/></td>';
-		echo '
-					</tr>';
-	}
-
-	echo '
-				</tbody>
-			</table>';
-		
-	if (!empty($context['group']['assignable']))
-		echo '
-			<div class="floatright">
-				<input type="submit" name="remove" value="', $txt['membergroups_members_remove'], '" class="button_submit " />
-			</div>';
-	
-	echo '
-			<div class="pagesection flow_hidden">
-				<div class="floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
-			</div>
-			<br />';
-	
-	if (!empty($context['group']['assignable']))
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['membergroups_members_add_title'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong><label for="toAdd">', $txt['membergroups_members_add_desc'], ':</label></strong>
-						</dt>
-						<dd>
-							<input type="text" name="toAdd" id="toAdd" value="" class="input_text" />
-							<div id="toAddItemContainer"></div>
-						</dd>
-					</dl>
-					<input type="submit" name="add" value="', $txt['membergroups_members_add'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['mod-mgm_token_var'], '" value="', $context['mod-mgm_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-
-	if (!empty($context['group']['assignable']))
-		echo '
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var oAddMemberSuggest = new smc_AutoSuggest({
-				sSelf: \'oAddMemberSuggest\',
-				sSessionId: \'', $context['session_id'], '\',
-				sSessionVar: \'', $context['session_var'], '\',
-				sSuggestId: \'to_suggest\',
-				sControlId: \'toAdd\',
-				sSearchType: \'member\',
-				sPostName: \'member_add\',
-				sURLMask: \'action=profile;u=%item_id%\',
-				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-				bItemList: true,
-				sItemListContainerId: \'toAddItemContainer\'
-			});
-		// ]]></script>';
-}
-
-// Allow the moderator to enter a reason to each user being rejected.
-function template_group_request_reason()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	// Show a welcome message to the user.
-	echo '
-	<div id="moderationcenter">
-		<form action="', $scripturl, '?action=groups;sa=requests" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mc_groups_reason_title'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-
-	// Loop through and print out a reason box for each...
-	foreach ($context['group_requests'] as $request)
-		echo '
-						<dt>
-							<strong>', sprintf($txt['mc_groupr_reason_desc'], $request['member_link'], $request['group_link']), ':</strong>
-						</dt>
-						<dd>
-							<input type="hidden" name="groupr[]" value="', $request['id'], '" />
-							<textarea name="groupreason[', $request['id'], ']" rows="3" cols="40" style="' . (isBrowser('is_ie8') ? 'width: 635px; min-width: 96%; max-width: 96%' : 'min-width: 80%; max-width: 99%') . ';"></textarea>
-						</dd>';
-
-	echo '
-					</dl>
-					<input type="submit" name="go" value="', $txt['mc_groupr_submit'], '" class="button_submit" />
-					<input type="hidden" name="req_action" value="got_reason" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_main()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	template_show_list('regular_membergroups_list');
+	echo '<br /><br />';
+	template_show_list('post_count_membergroups_list');
+
+}
+
+function template_new_group()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form id="new_group" action="', $scripturl, '?action=admin;area=membergroups;sa=add" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['membergroups_new_group'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="group_name_input"><strong>', $txt['membergroups_group_name'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="group_name" id="group_name_input" size="30" class="input_text" />
+						</dd>';
+	if ($context['undefined_group'])
+	{
+		echo '
+						<dt>
+							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], '</strong>:</label>
+						</dt>
+						<dd>
+							<fieldset id="group_type">
+								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
+								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" checked="checked" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';
+
+		if ($context['allow_protected'])
+			echo '
+								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';
+
+		echo '
+								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
+								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
+								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
+							</fieldset>
+						</dd>';
+	}
+
+	if ($context['post_group'] || $context['undefined_group'])
+		echo '
+						<dt id="min_posts_text">
+							<strong>', $txt['membergroups_min_posts'], ':</strong>
+						</dt>
+						<dd>
+							<input type="text" name="min_posts" id="min_posts_input" size="5" class="input_text" />
+						</dd>';
+	if (!$context['post_group'] || !empty($modSettings['permission_enable_postgroups']))
+	{
+		echo '
+						<dt>
+							<label for="permission_base"><strong>', $txt['membergroups_permissions'], ':</strong></label><br />
+							<span class="smalltext">', $txt['membergroups_can_edit_later'], '</span>
+						</dt>
+						<dd>
+							<fieldset id="permission_base">
+								<legend>', $txt['membergroups_select_permission_type'], '</legend>
+								<input type="radio" name="perm_type" id="perm_type_inherit" value="inherit" checked="checked" class="input_radio" />
+								<label for="perm_type_inherit">', $txt['membergroups_new_as_inherit'], ':</label>
+								<select name="inheritperm" id="inheritperm_select" onclick="document.getElementById(\'perm_type_inherit\').checked = true;">
+									<option value="-1">', $txt['membergroups_guests'], '</option>
+									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
+		foreach ($context['groups'] as $group)
+			echo '
+									<option value="', $group['id'], '">', $group['name'], '</option>';
+		echo '
+								</select><br />
+
+								<input type="radio" name="perm_type" id="perm_type_copy" value="copy" class="input_radio" />
+								<label for="perm_type_copy">', $txt['membergroups_new_as_copy'], ':</label>
+								<select name="copyperm" id="copyperm_select" onclick="document.getElementById(\'perm_type_copy\').checked = true;">
+									<option value="-1">', $txt['membergroups_guests'], '</option>
+									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
+		foreach ($context['groups'] as $group)
+			echo '
+									<option value="', $group['id'], '">', $group['name'], '</option>';
+		echo '
+								</select><br />
+
+								<input type="radio" name="perm_type" id="perm_type_predefined" value="predefined" class="input_radio" />
+								<label for="perm_type_predefined">', $txt['membergroups_new_as_type'], ':</label>
+								<select name="level" id="level_select" onclick="document.getElementById(\'perm_type_predefined\').checked = true;">
+									<option value="restrict">', $txt['permitgroups_restrict'], '</option>
+									<option value="standard" selected="selected">', $txt['permitgroups_standard'], '</option>
+									<option value="moderator">', $txt['permitgroups_moderator'], '</option>
+									<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
+								</select>
+							</fieldset>
+						</dd>';
+	}
+
+	echo '
+						<dt>
+							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['post_group'] ? '<br />
+							<span class="smalltext" style="font-weight: normal">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
+						</dt>
+						<dd>';
+
+	template_add_edit_group_boards_list(false);
+
+	echo '
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['membergroups_add_group'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>';
+	if ($context['undefined_group'])
+	{
+		echo '
+			<script type="text/javascript"><!-- // --><![CDATA[
+				function swapPostGroup(isChecked)
+				{
+					var min_posts_text = document.getElementById(\'min_posts_text\');
+					document.getElementById(\'min_posts_input\').disabled = !isChecked;
+					min_posts_text.style.color = isChecked ? "" : "#888888";
+				}
+				swapPostGroup(', $context['post_group'] ? 'true' : 'false', ');
+			// ]]></script>';
+	}
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_edit_group()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=membergroups;sa=edit;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="groupForm" id="groupForm">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['membergroups_edit_group'], ' - ', $context['group']['name'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="group_name_input"><strong>', $txt['membergroups_edit_name'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30" class="input_text" />
+						</dd>';
+
+	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
+		echo '
+
+						<dt id="group_desc_text">
+							<label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label>
+						</dt>
+						<dd>
+							<textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea>
+						</dd>';
+
+	// Group type...
+	if ($context['group']['allow_post_group'])
+	{
+		echo '
+						<dt>
+							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], ':</strong></label>
+						</dt>
+						<dd>
+							<fieldset id="group_type">
+								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
+								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" ', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';
+
+		if ($context['group']['allow_protected'])
+			echo '
+								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" ', $context['group']['type'] == 1 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';
+
+		echo '
+								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" ', $context['group']['type'] == 2 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
+								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" ', $context['group']['type'] == 3 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
+								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" ', $context['group']['is_post_group'] ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
+							</fieldset>
+						</dd>';
+	}
+
+	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
+		echo '
+						<dt id="group_moderators_text">
+							<label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="group_moderators" id="group_moderators" value="', $context['group']['moderator_list'], '" size="30" class="input_text" />
+							<div id="moderator_container"></div>
+						</dd>
+						<dt id="group_hidden_text">
+							<label for="group_hidden_input"><strong>', $txt['membergroups_edit_hidden'], ':</strong></label>
+						</dt>
+						<dd>
+							<select name="group_hidden" id="group_hidden_input" onchange="if (this.value == 2 &amp;&amp; !confirm(\'', $txt['membergroups_edit_hidden_warning'], '\')) this.value = 0;">
+								<option value="0" ', $context['group']['hidden'] ? '' : 'selected="selected"', '>', $txt['membergroups_edit_hidden_no'], '</option>
+								<option value="1" ', $context['group']['hidden'] == 1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_boardindex'], '</option>
+								<option value="2" ', $context['group']['hidden'] == 2 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_all'], '</option>
+							</select>
+						</dd>';
+
+	// Can they inherit permissions?
+	if ($context['group']['id'] > 1 && $context['group']['id'] != 3)
+	{
+		echo '
+						<dt id="group_inherit_text">
+							<label for="group_inherit_input"><strong>', $txt['membergroups_edit_inherit_permissions'], '</strong></label>:<br />
+							<span class="smalltext">', $txt['membergroups_edit_inherit_permissions_desc'], '</span>
+						</dt>
+						<dd>
+							<select name="group_inherit" id="group_inherit_input">
+								<option value="-2">', $txt['membergroups_edit_inherit_permissions_no'], '</option>
+								<option value="-1" ', $context['group']['inherited_from'] == -1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_guests'], '</option>
+								<option value="0" ', $context['group']['inherited_from'] == 0 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>';
+
+		// For all the inheritable groups show an option.
+		foreach ($context['inheritable_groups'] as $id => $group)
+			echo '
+								<option value="', $id, '" ', $context['group']['inherited_from'] == $id ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>';
+
+		echo '
+							</select>
+							<input type="hidden" name="old_inherit" value="', $context['group']['inherited_from'], '" />
+						</dd>';
+	}
+
+	if ($context['group']['allow_post_group'])
+		echo '
+
+						<dt id="min_posts_text">
+							<label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6" class="input_text" />
+						</dd>';
+	echo '
+						<dt>
+							<label for="online_color_input"><strong>', $txt['membergroups_online_color'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="online_color" id="online_color_input" value="', $context['group']['color'], '" size="20" class="input_text" />
+						</dd>
+						<dt>
+							<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" onkeyup="if (this.value.length > 2) this.value = 99;" onkeydown="this.onkeyup();" onchange="if (this.value != 0) this.form.icon_image.onchange();" class="input_text" />
+						</dd>
+						<dt>
+							<label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br />
+							<span class="smalltext">', $txt['membergroups_icon_image_note'], '</span>
+						</dt>
+						<dd>
+							', $txt['membergroups_images_url'], '
+							<input type="text" name="icon_image" id="icon_image_input" value="', $context['group']['icon_image'], '" onchange="if (this.value &amp;&amp; this.form.icon_count.value == 0) this.form.icon_count.value = 1; else if (!this.value) this.form.icon_count.value = 0; document.getElementById(\'star_preview\').src = smf_images_url + \'/\' + (this.value &amp;&amp; this.form.icon_count.value > 0 ? this.value.replace(/\$language/g, \'', $context['user']['language'], '\') : \'blank.png\');" size="20" class="input_text" />
+							<img id="star_preview" src="', $settings['images_url'], '/', $context['group']['icon_image'] == '' ? 'blank.png' : $context['group']['icon_image'], '" alt="*" />
+						</dd>
+						<dt>
+							<label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br />
+							<span class="smalltext">', $txt['membergroups_max_messages_note'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="max_messages" id="max_messages_input" value="', $context['group']['id'] == 1 ? 0 : $context['group']['max_messages'], '" size="6"', $context['group']['id'] == 1 ? ' disabled="disabled"' : '', ' class="input_text" />
+						</dd>';
+	if (!empty($context['categories']))
+	{
+		echo '
+						<dt>
+							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br />
+							<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
+						</dt>
+						<dd>';
+		template_add_edit_group_boards_list();
+		echo '
+						</dd>';
+	}
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['membergroups_edit_save'], '" class="button_submit" />', $context['group']['allow_delete'] ? '
+					<input type="submit" name="delete" value="' . $txt['membergroups_delete'] . '" onclick="return confirm(\'' . $txt['membergroups_confirm_delete'] . '\');" class="button_submit" />' : '', '
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var oModeratorSuggest = new smc_AutoSuggest({
+				sSelf: \'oModeratorSuggest\',
+				sSessionId: smf_session_id,
+				sSessionVar: smf_session_var,
+				sSuggestId: \'group_moderators\',
+				sControlId: \'group_moderators\',
+				sSearchType: \'member\',
+				bItemList: true,
+				sPostName: \'moderator_list\',
+				sURLMask: \'action=profile;u=%item_id%\',
+				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+				sItemListContainerId: \'moderator_container\',
+				aListItems: [';
+
+			foreach ($context['group']['moderators'] as $id_member => $member_name)
+				echo '
+							{
+								sItemId: ', JavaScriptEscape($id_member), ',
+								sItemName: ', JavaScriptEscape($member_name), '
+							}', $id_member == $context['group']['last_moderator_id'] ? '' : ',';
+
+			echo '
+				]
+			});
+		// ]]></script>';
+
+	if ($context['group']['allow_post_group'])
+		echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			function swapPostGroup(isChecked)
+			{
+				var min_posts_text = document.getElementById(\'min_posts_text\');
+				var group_desc_text = document.getElementById(\'group_desc_text\');
+				var group_hidden_text = document.getElementById(\'group_hidden_text\');
+				var group_moderators_text = document.getElementById(\'group_moderators_text\');
+				document.forms.groupForm.min_posts.disabled = !isChecked;
+				min_posts_text.style.color = isChecked ? "" : "#888888";
+				document.forms.groupForm.group_desc_input.disabled = isChecked;
+				group_desc_text.style.color = !isChecked ? "" : "#888888";
+				document.forms.groupForm.group_hidden_input.disabled = isChecked;
+				group_hidden_text.style.color = !isChecked ? "" : "#888888";
+				document.forms.groupForm.group_moderators.disabled = isChecked;
+				group_moderators_text.style.color = !isChecked ? "" : "#888888";
+			}
+			swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', ');
+		// ]]></script>';
+}
+
+function template_add_edit_group_boards_list($collapse = true)
+{
+	global $context, $txt, $modSettings;
+	echo '
+							<fieldset id="visible_boards">
+								<legend>', $txt['membergroups_new_board_desc'], '</legend>
+								<ul class="ignoreboards floatleft">';
+
+	foreach ($context['categories'] as $category)
+	{
+		if (empty($modSettings['deny_boards_access']))
+			echo '
+									<li class="category">
+										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'new_group\'); return false;"><strong>', $category['name'], '</strong></a>
+									<ul style="width:100%">';
+		else
+			echo '
+									<li class="category">
+										<strong>', $category['name'], '</strong>
+										<span class="select_all_box">
+											<em style="margin-left:5em;">', $txt['all_boards_in_cat'], ': </em>
+											<select onchange="select_in_category(', $category['id'], ', this, [', implode(',', array_keys($category['boards'])), ']);">
+												<option>---</option>
+												<option value="allow">', $txt['board_perms_allow'], '</option>
+												<option value="ignore">', $txt['board_perms_ignore'], '</option>
+												<option value="deny">', $txt['board_perms_deny'], '</option>
+											</select>
+										</span>
+										<ul style="width:100%" id="boards_list_', $category['id'], '">';
+
+		foreach ($category['boards'] as $board)
+		{
+			if (empty($modSettings['deny_boards_access']))
+				echo '
+										<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
+											<input type="checkbox" name="boardaccess[', $board['id'], ']" id="brd', $board['id'], '" value="\'allow\'" ', $board['allow'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="brd', $board['id'], '">', $board['name'], '</label>
+										</li>';
+			else
+				echo '
+											<li class="board" style="width:100%">
+												<span style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">', $board['name'], ': </span>
+												<span style="width:50%;float:right">
+													<input type="radio" name="boardaccess[', $board['id'], ']" id="allow_brd', $board['id'], '" value="allow" ', $board['allow'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="allow_brd', $board['id'], '">', $txt['permissions_option_on'], '</label>
+													<input type="radio" name="boardaccess[', $board['id'], ']" id="ignore_brd', $board['id'], '" value="ignore" ', !$board['allow'] && !$board['deny'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="ignore_brd', $board['id'], '">', $txt['permissions_option_off'], '</label>
+													<input type="radio" name="boardaccess[', $board['id'], ']" id="deny_brd', $board['id'], '" value="deny" ', $board['deny'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="deny_brd', $board['id'], '">', $txt['permissions_option_deny'], '</label>
+												</span>
+											</li>';
+		}
+
+		echo '
+									</ul>
+								</li>';
+	}
+
+	echo '
+							</ul>
+							<br class="clear" />';
+
+	if (empty($modSettings['deny_boards_access']))
+		echo '
+								<br />
+								<input type="checkbox" id="checkall_check" class="input_check" onclick="invertAll(this, this.form, \'boardaccess\');" /> <label for="checkall_check"><em>', $txt['check_all'], '</em></label>
+							</fieldset>';
+	else
+		echo '
+								<br />
+								<span class="select_all_box">
+									<em>', $txt['all'], ': </em>
+									<input type="radio" name="select_all" id="allow_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'allow\');" /> <label for="allow_all">', $txt['board_perms_allow'], '</label>
+									<input type="radio" name="select_all" id="ignore_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'ignore\');" /> <label for="ignore_all">', $txt['board_perms_ignore'], '</label>
+									<input type="radio" name="select_all" id="deny_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'deny\');" /> <label for="deny_all">', $txt['board_perms_deny'], '</label>
+								</span>
+							</fieldset>
+							<script type="text/javascript"><!-- // --><![CDATA[
+								$(document).ready(function () {
+									$(".select_all_box").each(function () {
+										$(this).removeClass(\'select_all_box\');
+									});
+								});
+							// ]]></script>';
+
+	if ($collapse)
+		echo '
+							<a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').style.display = \'block\'; document.getElementById(\'visible_boards_link\').style.display = \'none\'; return false;" id="visible_boards_link" style="display: none;">[ ', $txt['membergroups_select_visible_boards'], ' ]</a>
+							<script type="text/javascript"><!-- // --><![CDATA[
+								document.getElementById("visible_boards_link").style.display = "";
+								document.getElementById("visible_boards").style.display = "none";
+							// ]]></script>';
+}
+
+// Templating for viewing the members of a group.
+function template_group_members()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : '') , ';sa=members;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['name'], ':</strong>
+						</dt>
+						<dd>
+							<span ', $context['group']['online_color'] ? 'style="color: ' . $context['group']['online_color'] . ';"' : '', '>', $context['group']['name'], '</span> ', $context['group']['icons'], '
+						</dd>';
+	//Any description to show?
+	if (!empty($context['group']['description']))
+		echo '
+						<dt>
+							<strong>' . $txt['membergroups_members_description'] . ':</strong>
+						</dt>
+						<dd>
+							', $context['group']['description'] ,'
+						</dd>';
+
+	echo '
+						<dt>
+							<strong>', $txt['membergroups_members_top'], ':</strong>
+						</dt>
+						<dd>
+							', $context['total_members'] ,'
+						</dd>';
+	// Any group moderators to show?
+	if (!empty($context['group']['moderators']))
+	{
+		$moderators = array();
+		foreach ($context['group']['moderators'] as $moderator)
+			$moderators[] = '<a href="' . $scripturl . '?action=profile;u=' . $moderator['id'] . '">' . $moderator['name'] . '</a>';
+
+		echo '
+						<dt>
+							<strong>', $txt['membergroups_members_group_moderators'], ':</strong>
+						</dt>
+						<dd>
+							', implode(', ', $moderators) ,'
+						</dd>';
+	}
+
+	echo '
+					</dl>
+				</div>
+			</div>
+
+			<br />
+			<div class="title_bar">
+				<h4 class="titlebg">', $txt['membergroups_members_group_members'], '</h4>
+			</div>
+			<br />
+			<div class="pagesection">', $txt['pages'], ': ', $context['page_index'], '</div>
+			<table width="100%" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th"><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['name'], $context['sort_by'] == 'name' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>';
+
+	if ($context['can_send_email'])
+		echo '
+						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=email', $context['sort_by'] == 'email' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['email'], $context['sort_by'] == 'email' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>';
+
+	echo '
+						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=active', $context['sort_by'] == 'active' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['membergroups_members_last_active'], $context['sort_by'] == 'active' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
+						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=registered', $context['sort_by'] == 'registered' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['date_registered'], $context['sort_by'] == 'registered' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
+						<th ', empty($context['group']['assignable']) ? ' class="last_th" colspan="2"' : '', '><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=posts', $context['sort_by'] == 'posts' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['posts'], $context['sort_by'] == 'posts' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '','</a></th>';
+	if (!empty($context['group']['assignable']))
+		echo '
+						<th class="last_th" width="4%" align="center"><input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" /></th>';
+	echo '
+					</tr>
+				</thead>
+				<tbody>';
+
+	if (empty($context['members']))
+		echo '
+					<tr class="windowbg2">
+						<td colspan="6" align="center">', $txt['membergroups_members_no_members'], '</td>
+					</tr>';
+
+	$alternate = false;
+	foreach ($context['members'] as $member)
+	{
+		$alternate = !$alternate;
+		echo '
+					<tr class="', $alternate === true ? 'windowbg' : 'windowbg2', '">
+						<td>', $member['name'], '</td>';
+		if ($context['can_send_email'])
+		{
+			echo '
+						<td', $member['show_email'] == 'no_through_forum' && $settings['use_image_buttons'] ? ' align="center"' : '', '>';
+
+			// Is it totally hidden?
+			if ($member['show_email'] == 'no')
+				echo '
+								<em>', $txt['hidden'], '</em>';
+			// ... otherwise they want it hidden but it's not to this person?
+			elseif ($member['show_email'] == 'yes_permission_override')
+				echo '
+								<a href="mailto:', $member['email'], '"><em>', $member['email'], '</em></a>';
+			// ... otherwise it's visible - but only via an image?
+			elseif ($member['show_email'] == 'no_through_forum')
+				echo '
+								<a href="', $scripturl, '?action=emailuser;sa=email;uid=', $member['id'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . '" />' : $txt['email']), '</a>';
+			// ... otherwise it must be a 'yes', show it and show it fully.
+			else
+				echo '
+								<a href="mailto:', $member['email'], '">', $member['email'], '</a>';
+			echo '
+						</td>';
+		}
+
+		echo '
+						<td>', $member['last_online'], '</td>
+						<td>', $member['registered'], '</td>
+						<td', empty($context['group']['assignable']) ? ' colspan="2"' : '', '>', $member['posts'], '</td>';
+		if (!empty($context['group']['assignable']))
+			echo '
+						<td align="center" width="4%"><input type="checkbox" name="rem[]" value="', $member['id'], '" class="input_check" ', ($context['user']['id'] == $member['id'] && $context['group']['id'] == 1 ? 'onclick="if (this.checked) return confirm(\'' . $txt['membergroups_members_deadmin_confirm'] . '\')" ' : ''), '/></td>';
+		echo '
+					</tr>';
+	}
+
+	echo '
+				</tbody>
+			</table>';
+		
+	if (!empty($context['group']['assignable']))
+		echo '
+			<div class="floatright">
+				<input type="submit" name="remove" value="', $txt['membergroups_members_remove'], '" class="button_submit " />
+			</div>';
+	
+	echo '
+			<div class="pagesection flow_hidden">
+				<div class="floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
+			</div>
+			<br />';
+	
+	if (!empty($context['group']['assignable']))
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['membergroups_members_add_title'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong><label for="toAdd">', $txt['membergroups_members_add_desc'], ':</label></strong>
+						</dt>
+						<dd>
+							<input type="text" name="toAdd" id="toAdd" value="" class="input_text" />
+							<div id="toAddItemContainer"></div>
+						</dd>
+					</dl>
+					<input type="submit" name="add" value="', $txt['membergroups_members_add'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>';
+	}
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['mod-mgm_token_var'], '" value="', $context['mod-mgm_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+
+	if (!empty($context['group']['assignable']))
+		echo '
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var oAddMemberSuggest = new smc_AutoSuggest({
+				sSelf: \'oAddMemberSuggest\',
+				sSessionId: \'', $context['session_id'], '\',
+				sSessionVar: \'', $context['session_var'], '\',
+				sSuggestId: \'to_suggest\',
+				sControlId: \'toAdd\',
+				sSearchType: \'member\',
+				sPostName: \'member_add\',
+				sURLMask: \'action=profile;u=%item_id%\',
+				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+				bItemList: true,
+				sItemListContainerId: \'toAddItemContainer\'
+			});
+		// ]]></script>';
+}
+
+// Allow the moderator to enter a reason to each user being rejected.
+function template_group_request_reason()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	// Show a welcome message to the user.
+	echo '
+	<div id="moderationcenter">
+		<form action="', $scripturl, '?action=groups;sa=requests" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mc_groups_reason_title'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">';
+
+	// Loop through and print out a reason box for each...
+	foreach ($context['group_requests'] as $request)
+		echo '
+						<dt>
+							<strong>', sprintf($txt['mc_groupr_reason_desc'], $request['member_link'], $request['group_link']), ':</strong>
+						</dt>
+						<dd>
+							<input type="hidden" name="groupr[]" value="', $request['id'], '" />
+							<textarea name="groupreason[', $request['id'], ']" rows="3" cols="40" style="' . (isBrowser('is_ie8') ? 'width: 635px; min-width: 96%; max-width: 96%' : 'min-width: 80%; max-width: 99%') . ';"></textarea>
+						</dd>';
+
+	echo '
+					</dl>
+					<input type="submit" name="go" value="', $txt['mc_groupr_submit'], '" class="button_submit" />
+					<input type="hidden" name="req_action" value="got_reason" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 325 - 329
Themes/default/ManageMembers.template.php

@@ -1,330 +1,326 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_search_members()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=viewmembers" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="floatleft">', $txt['search_for'], '</span>
-					<span class="smalltext floatright">', $txt['wild_cards_allowed'], '</span>
-				</h3>
-			</div>
-			<input type="hidden" name="sa" value="query" />
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="flow_hidden">
-						<div class="msearch_details floatleft">
-							<dl class="settings right">
-								<dt class="righttext">
-									<strong><label for="mem_id">', $txt['member_id'], ':</label></strong>
-									<select name="types[mem_id]">
-										<option value="--">&lt;</option>
-										<option value="-">&lt;=</option>
-										<option value="=" selected="selected">=</option>
-										<option value="+">&gt;=</option>
-										<option value="++">&gt;</option>
-									</select>
-								</dt>
-								<dd>
-									<input type="text" name="mem_id" id="mem_id" value="" size="6" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="age">', $txt['age'], ':</label></strong>
-									<select name="types[age]">
-										<option value="--">&lt;</option>
-										<option value="-">&lt;=</option>
-										<option value="=" selected="selected">=</option>
-										<option value="+">&gt;=</option>
-										<option value="++">&gt;</option>
-									</select>
-								</dt>
-								<dd>
-									<input type="text" name="age" id="age" value="" size="6" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="posts">', $txt['member_postcount'], ':</label></strong>
-									<select name="types[posts]">
-										<option value="--">&lt;</option>
-										<option value="-">&lt;=</option>
-										<option value="=" selected="selected">=</option>
-										<option value="+">&gt;=</option>
-										<option value="++">&gt;</option>
-									</select>
-								</dt>
-								<dd>
-									<input type="text" name="posts" id="posts" value="" size="6" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="reg_date">', $txt['date_registered'], ':</label></strong>
-									<select name="types[reg_date]">
-										<option value="--">&lt;</option>
-										<option value="-">&lt;=</option>
-										<option value="=" selected="selected">=</option>
-										<option value="+">&gt;=</option>
-										<option value="++">&gt;</option>
-									</select>
-								</dt>
-								<dd>
-									<input type="text" name="reg_date" id="reg_date" value="" size="10" class="input_text" /><span class="smalltext">', $txt['date_format'], '</span>
-								</dd>
-								<dt class="righttext">
-									<strong><label for="last_online">', $txt['viewmembers_online'], ':</label></strong>
-									<select name="types[last_online]">
-										<option value="--">&lt;</option>
-										<option value="-">&lt;=</option>
-										<option value="=" selected="selected">=</option>
-										<option value="+">&gt;=</option>
-										<option value="++">&gt;</option>
-									</select>
-								</dt>
-								<dd>
-									<input type="text" name="last_online" id="last_online" value="" size="10" class="input_text" /><span class="smalltext">', $txt['date_format'], '</span>
-								</dd>
-							</dl>
-						</div>
-						<div class="msearch_details floatright">
-							<dl class="settings right">
-								<dt class="righttext">
-									<strong><label for="membername">', $txt['username'], ':</label></strong>
-								</dt>
-								<dd>
-									<input type="text" name="membername" id="membername" value="" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="email">', $txt['email_address'], ':</label></strong>
-								</dt>
-								<dd>
-									<input type="text" name="email" id="email" value="" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="website">', $txt['website'], ':</label></strong>
-								</dt>
-								<dd>
-									<input type="text" name="website" id="website" value="" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="location">', $txt['location'], ':</label></strong>
-								</dt>
-								<dd>
-									<input type="text" name="location" id="location" value="" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="ip">', $txt['ip_address'], ':</label></strong>
-								</dt>
-								<dd>
-									<input type="text" name="ip" id="ip" value="" class="input_text" />
-								</dd>
-								<dt class="righttext">
-									<strong><label for="messenger">', $txt['messenger_address'], ':</label></strong>
-								</dt>
-								<dd>
-									<input type="text" name="messenger" id="messenger" value="" class="input_text" />
-								</dd>
-							</dl>
-						</div>
-					</div>
-					<div class="flow_hidden">
-						<div class="msearch_details floatleft">
-							<fieldset>
-								<legend>', $txt['gender'], '</legend>
-								<label for="gender-0"><input type="checkbox" name="gender[]" value="0" id="gender-0" checked="checked" class="input_check" /> ', $txt['undefined_gender'], '</label>&nbsp;&nbsp;
-								<label for="gender-1"><input type="checkbox" name="gender[]" value="1" id="gender-1" checked="checked" class="input_check" /> ', $txt['male'], '</label>&nbsp;&nbsp;
-								<label for="gender-2"><input type="checkbox" name="gender[]" value="2" id="gender-2" checked="checked" class="input_check" /> ', $txt['female'], '</label>
-							</fieldset>
-						</div>
-						<div class="msearch_details floatright">
-							<fieldset>
-								<legend>', $txt['activation_status'], '</legend>
-								<label for="activated-0"><input type="checkbox" name="activated[]" value="1" id="activated-0" checked="checked" class="input_check" /> ', $txt['activated'], '</label>&nbsp;&nbsp;
-								<label for="activated-1"><input type="checkbox" name="activated[]" value="0" id="activated-1" checked="checked" class="input_check" /> ', $txt['not_activated'], '</label>
-							</fieldset>
-						</div>
-					</div>
-				</div>
-				<span class="botslice clear_right"><span></span></span>
-			</div>
-			<br class="clear" />
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['member_part_of_these_membergroups'], '</h3>
-			</div>
-			<div class="flow_hidden">
-				<table width="49%" class="table_grid floatleft">
-					<thead>
-						<tr class="catbg">
-							<th scope="col" class="first_th">', $txt['membergroups'], '</th>
-							<th scope="col">', $txt['primary'], '</th>
-							<th scope="col" class="last_th">', $txt['additional'], '</th>
-						</tr>
-					</thead>
-					<tbody>';
-
-			foreach ($context['membergroups'] as $membergroup)
-				echo '
-						<tr class="windowbg2">
-							<td>', $membergroup['name'], '</td>
-							<td align="center">
-								<input type="checkbox" name="membergroups[1][]" value="', $membergroup['id'], '" checked="checked" class="input_check" />
-							</td>
-							<td align="center">
-								', $membergroup['can_be_additional'] ? '<input type="checkbox" name="membergroups[2][]" value="' . $membergroup['id'] . '" checked="checked" class="input_check" />' : '', '
-							</td>
-						</tr>';
-
-			echo '
-						<tr class="windowbg2">
-							<td>
-								<em>', $txt['check_all'], '</em>
-							</td>
-							<td align="center">
-								<input type="checkbox" onclick="invertAll(this, this.form, \'membergroups[1]\');" checked="checked" class="input_check" />
-							</td>
-							<td align="center">
-								<input type="checkbox" onclick="invertAll(this, this.form, \'membergroups[2]\');" checked="checked" class="input_check" />
-							</td>
-						</tr>
-					</tbody>
-				</table>
-
-				<table width="49%" class="table_grid floatright">
-					<thead>
-						<tr class="catbg">
-							<th scope="col" class="first_th">
-								', $txt['membergroups_postgroups'], '
-							</th>
-							<th class="last_th">&nbsp;</th>
-						</tr>
-					</thead>
-					<tbody>';
-
-			foreach ($context['postgroups'] as $postgroup)
-				echo '
-						<tr class="windowbg2">
-							<td>
-								', $postgroup['name'], '
-							</td>
-							<td width="40" align="center">
-								<input type="checkbox" name="postgroups[]" value="', $postgroup['id'], '" checked="checked" class="input_check" />
-							</td>
-						</tr>';
-
-			echo '
-						<tr class="windowbg2">
-							<td>
-								<em>', $txt['check_all'], '</em>
-							</td>
-							<td align="center">
-								<input type="checkbox" onclick="invertAll(this, this.form, \'postgroups[]\');" checked="checked" class="input_check" />
-							</td>
-						</tr>
-					</tbody>
-				</table>
-			</div><br />
-			<input type="submit" value="', $txt['search'], '" class="button_submit" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_admin_browse()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">';
-
-	template_show_list('approve_list');
-
-	// If we have lots of outstanding members try and make the admin's life easier.
-	if ($context['approve_list']['total_num_items'] > 20)
-	{
-		echo '
-		<br />
-		<form action="', $scripturl, '?action=admin;area=viewmembers" method="post" accept-charset="', $context['character_set'], '" name="postFormOutstanding" id="postFormOutstanding" onsubmit="return onOutstandingSubmit();">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['admin_browse_outstanding'], '</h3>
-			</div>
-			<script type="text/javascript"><!-- // --><![CDATA[
-				function onOutstandingSubmit()
-				{
-					if (document.forms.postFormOutstanding.todo.value == "")
-						return;
-
-					var message = "";
-					if (document.forms.postFormOutstanding.todo.value.indexOf("delete") != -1)
-						message = "', $txt['admin_browse_w_delete'], '";
-					else if (document.forms.postFormOutstanding.todo.value.indexOf("reject") != -1)
-						message = "', $txt['admin_browse_w_reject'], '";
-					else if (document.forms.postFormOutstanding.todo.value == "remind")
-						message = "', $txt['admin_browse_w_remind'], '";
-					else
-						message = "', $context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate'], '";
-
-					if (confirm(message + " ', $txt['admin_browse_outstanding_warn'], '"))
-						return true;
-					else
-						return false;
-				}
-			// ]]></script>
-
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							', $txt['admin_browse_outstanding_days_1'], ':
-						</dt>
-						<dd>
-							<input type="text" name="time_passed" value="14" maxlength="4" size="3" class="input_text" /> ', $txt['admin_browse_outstanding_days_2'], '.
-						</dd>
-						<dt>
-							', $txt['admin_browse_outstanding_perform'], ':
-						</dt>
-						<dd>
-							<select name="todo">
-								', $context['browse_type'] == 'activate' ? '
-								<option value="ok">' . $txt['admin_browse_w_activate'] . '</option>' : '', '
-								<option value="okemail">', $context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate'], ' ', $txt['admin_browse_w_email'], '</option>', $context['browse_type'] == 'activate' ? '' : '
-								<option value="require_activation">' . $txt['admin_browse_w_approve_require_activate'] . '</option>', '
-								<option value="reject">', $txt['admin_browse_w_reject'], '</option>
-								<option value="rejectemail">', $txt['admin_browse_w_reject'], ' ', $txt['admin_browse_w_email'], '</option>
-								<option value="delete">', $txt['admin_browse_w_delete'], '</option>
-								<option value="deleteemail">', $txt['admin_browse_w_delete'], ' ', $txt['admin_browse_w_email'], '</option>', $context['browse_type'] == 'activate' ? '
-								<option value="remind">' . $txt['admin_browse_w_remind'] . '</option>' : '', '
-							</select>
-						</dd>
-					</dl>
-					<input type="submit" value="', $txt['admin_browse_outstanding_go'], '" class="button_submit" />
-					<input type="hidden" name="type" value="', $context['browse_type'], '" />
-					<input type="hidden" name="sort" value="', $context['approve_list']['sort']['id'], '" />
-					<input type="hidden" name="start" value="', $context['approve_list']['start'], '" />
-					<input type="hidden" name="orig_filter" value="', $context['current_filter'], '" />
-					<input type="hidden" name="sa" value="approve" />', !empty($context['approve_list']['sort']['desc']) ? '
-					<input type="hidden" name="desc" value="1" />' : '', '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>';
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_search_members()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=viewmembers" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<span class="floatleft">', $txt['search_for'], '</span>
+					<span class="smalltext floatright">', $txt['wild_cards_allowed'], '</span>
+				</h3>
+			</div>
+			<input type="hidden" name="sa" value="query" />
+			<div class="windowbg">
+				<div class="content">
+					<div class="flow_hidden">
+						<div class="msearch_details floatleft">
+							<dl class="settings right">
+								<dt class="righttext">
+									<strong><label for="mem_id">', $txt['member_id'], ':</label></strong>
+									<select name="types[mem_id]">
+										<option value="--">&lt;</option>
+										<option value="-">&lt;=</option>
+										<option value="=" selected="selected">=</option>
+										<option value="+">&gt;=</option>
+										<option value="++">&gt;</option>
+									</select>
+								</dt>
+								<dd>
+									<input type="text" name="mem_id" id="mem_id" value="" size="6" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="age">', $txt['age'], ':</label></strong>
+									<select name="types[age]">
+										<option value="--">&lt;</option>
+										<option value="-">&lt;=</option>
+										<option value="=" selected="selected">=</option>
+										<option value="+">&gt;=</option>
+										<option value="++">&gt;</option>
+									</select>
+								</dt>
+								<dd>
+									<input type="text" name="age" id="age" value="" size="6" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="posts">', $txt['member_postcount'], ':</label></strong>
+									<select name="types[posts]">
+										<option value="--">&lt;</option>
+										<option value="-">&lt;=</option>
+										<option value="=" selected="selected">=</option>
+										<option value="+">&gt;=</option>
+										<option value="++">&gt;</option>
+									</select>
+								</dt>
+								<dd>
+									<input type="text" name="posts" id="posts" value="" size="6" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="reg_date">', $txt['date_registered'], ':</label></strong>
+									<select name="types[reg_date]">
+										<option value="--">&lt;</option>
+										<option value="-">&lt;=</option>
+										<option value="=" selected="selected">=</option>
+										<option value="+">&gt;=</option>
+										<option value="++">&gt;</option>
+									</select>
+								</dt>
+								<dd>
+									<input type="text" name="reg_date" id="reg_date" value="" size="10" class="input_text" /><span class="smalltext">', $txt['date_format'], '</span>
+								</dd>
+								<dt class="righttext">
+									<strong><label for="last_online">', $txt['viewmembers_online'], ':</label></strong>
+									<select name="types[last_online]">
+										<option value="--">&lt;</option>
+										<option value="-">&lt;=</option>
+										<option value="=" selected="selected">=</option>
+										<option value="+">&gt;=</option>
+										<option value="++">&gt;</option>
+									</select>
+								</dt>
+								<dd>
+									<input type="text" name="last_online" id="last_online" value="" size="10" class="input_text" /><span class="smalltext">', $txt['date_format'], '</span>
+								</dd>
+							</dl>
+						</div>
+						<div class="msearch_details floatright">
+							<dl class="settings right">
+								<dt class="righttext">
+									<strong><label for="membername">', $txt['username'], ':</label></strong>
+								</dt>
+								<dd>
+									<input type="text" name="membername" id="membername" value="" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="email">', $txt['email_address'], ':</label></strong>
+								</dt>
+								<dd>
+									<input type="text" name="email" id="email" value="" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="website">', $txt['website'], ':</label></strong>
+								</dt>
+								<dd>
+									<input type="text" name="website" id="website" value="" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="location">', $txt['location'], ':</label></strong>
+								</dt>
+								<dd>
+									<input type="text" name="location" id="location" value="" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="ip">', $txt['ip_address'], ':</label></strong>
+								</dt>
+								<dd>
+									<input type="text" name="ip" id="ip" value="" class="input_text" />
+								</dd>
+								<dt class="righttext">
+									<strong><label for="messenger">', $txt['messenger_address'], ':</label></strong>
+								</dt>
+								<dd>
+									<input type="text" name="messenger" id="messenger" value="" class="input_text" />
+								</dd>
+							</dl>
+						</div>
+					</div>
+					<div class="flow_hidden">
+						<div class="msearch_details floatleft">
+							<fieldset>
+								<legend>', $txt['gender'], '</legend>
+								<label for="gender-0"><input type="checkbox" name="gender[]" value="0" id="gender-0" checked="checked" class="input_check" /> ', $txt['undefined_gender'], '</label>&nbsp;&nbsp;
+								<label for="gender-1"><input type="checkbox" name="gender[]" value="1" id="gender-1" checked="checked" class="input_check" /> ', $txt['male'], '</label>&nbsp;&nbsp;
+								<label for="gender-2"><input type="checkbox" name="gender[]" value="2" id="gender-2" checked="checked" class="input_check" /> ', $txt['female'], '</label>
+							</fieldset>
+						</div>
+						<div class="msearch_details floatright">
+							<fieldset>
+								<legend>', $txt['activation_status'], '</legend>
+								<label for="activated-0"><input type="checkbox" name="activated[]" value="1" id="activated-0" checked="checked" class="input_check" /> ', $txt['activated'], '</label>&nbsp;&nbsp;
+								<label for="activated-1"><input type="checkbox" name="activated[]" value="0" id="activated-1" checked="checked" class="input_check" /> ', $txt['not_activated'], '</label>
+							</fieldset>
+						</div>
+					</div>
+				</div>
+			</div>
+			<br class="clear" />
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['member_part_of_these_membergroups'], '</h3>
+			</div>
+			<div class="flow_hidden">
+				<table width="49%" class="table_grid floatleft">
+					<thead>
+						<tr class="catbg">
+							<th scope="col" class="first_th">', $txt['membergroups'], '</th>
+							<th scope="col">', $txt['primary'], '</th>
+							<th scope="col" class="last_th">', $txt['additional'], '</th>
+						</tr>
+					</thead>
+					<tbody>';
+
+			foreach ($context['membergroups'] as $membergroup)
+				echo '
+						<tr class="windowbg2">
+							<td>', $membergroup['name'], '</td>
+							<td align="center">
+								<input type="checkbox" name="membergroups[1][]" value="', $membergroup['id'], '" checked="checked" class="input_check" />
+							</td>
+							<td align="center">
+								', $membergroup['can_be_additional'] ? '<input type="checkbox" name="membergroups[2][]" value="' . $membergroup['id'] . '" checked="checked" class="input_check" />' : '', '
+							</td>
+						</tr>';
+
+			echo '
+						<tr class="windowbg2">
+							<td>
+								<em>', $txt['check_all'], '</em>
+							</td>
+							<td align="center">
+								<input type="checkbox" onclick="invertAll(this, this.form, \'membergroups[1]\');" checked="checked" class="input_check" />
+							</td>
+							<td align="center">
+								<input type="checkbox" onclick="invertAll(this, this.form, \'membergroups[2]\');" checked="checked" class="input_check" />
+							</td>
+						</tr>
+					</tbody>
+				</table>
+
+				<table width="49%" class="table_grid floatright">
+					<thead>
+						<tr class="catbg">
+							<th scope="col" class="first_th">
+								', $txt['membergroups_postgroups'], '
+							</th>
+							<th class="last_th">&nbsp;</th>
+						</tr>
+					</thead>
+					<tbody>';
+
+			foreach ($context['postgroups'] as $postgroup)
+				echo '
+						<tr class="windowbg2">
+							<td>
+								', $postgroup['name'], '
+							</td>
+							<td width="40" align="center">
+								<input type="checkbox" name="postgroups[]" value="', $postgroup['id'], '" checked="checked" class="input_check" />
+							</td>
+						</tr>';
+
+			echo '
+						<tr class="windowbg2">
+							<td>
+								<em>', $txt['check_all'], '</em>
+							</td>
+							<td align="center">
+								<input type="checkbox" onclick="invertAll(this, this.form, \'postgroups[]\');" checked="checked" class="input_check" />
+							</td>
+						</tr>
+					</tbody>
+				</table>
+			</div><br />
+			<input type="submit" value="', $txt['search'], '" class="button_submit" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_admin_browse()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">';
+
+	template_show_list('approve_list');
+
+	// If we have lots of outstanding members try and make the admin's life easier.
+	if ($context['approve_list']['total_num_items'] > 20)
+	{
+		echo '
+		<br />
+		<form action="', $scripturl, '?action=admin;area=viewmembers" method="post" accept-charset="', $context['character_set'], '" name="postFormOutstanding" id="postFormOutstanding" onsubmit="return onOutstandingSubmit();">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['admin_browse_outstanding'], '</h3>
+			</div>
+			<script type="text/javascript"><!-- // --><![CDATA[
+				function onOutstandingSubmit()
+				{
+					if (document.forms.postFormOutstanding.todo.value == "")
+						return;
+
+					var message = "";
+					if (document.forms.postFormOutstanding.todo.value.indexOf("delete") != -1)
+						message = "', $txt['admin_browse_w_delete'], '";
+					else if (document.forms.postFormOutstanding.todo.value.indexOf("reject") != -1)
+						message = "', $txt['admin_browse_w_reject'], '";
+					else if (document.forms.postFormOutstanding.todo.value == "remind")
+						message = "', $txt['admin_browse_w_remind'], '";
+					else
+						message = "', $context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate'], '";
+
+					if (confirm(message + " ', $txt['admin_browse_outstanding_warn'], '"))
+						return true;
+					else
+						return false;
+				}
+			// ]]></script>
+
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							', $txt['admin_browse_outstanding_days_1'], ':
+						</dt>
+						<dd>
+							<input type="text" name="time_passed" value="14" maxlength="4" size="3" class="input_text" /> ', $txt['admin_browse_outstanding_days_2'], '.
+						</dd>
+						<dt>
+							', $txt['admin_browse_outstanding_perform'], ':
+						</dt>
+						<dd>
+							<select name="todo">
+								', $context['browse_type'] == 'activate' ? '
+								<option value="ok">' . $txt['admin_browse_w_activate'] . '</option>' : '', '
+								<option value="okemail">', $context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate'], ' ', $txt['admin_browse_w_email'], '</option>', $context['browse_type'] == 'activate' ? '' : '
+								<option value="require_activation">' . $txt['admin_browse_w_approve_require_activate'] . '</option>', '
+								<option value="reject">', $txt['admin_browse_w_reject'], '</option>
+								<option value="rejectemail">', $txt['admin_browse_w_reject'], ' ', $txt['admin_browse_w_email'], '</option>
+								<option value="delete">', $txt['admin_browse_w_delete'], '</option>
+								<option value="deleteemail">', $txt['admin_browse_w_delete'], ' ', $txt['admin_browse_w_email'], '</option>', $context['browse_type'] == 'activate' ? '
+								<option value="remind">' . $txt['admin_browse_w_remind'] . '</option>' : '', '
+							</select>
+						</dd>
+					</dl>
+					<input type="submit" value="', $txt['admin_browse_outstanding_go'], '" class="button_submit" />
+					<input type="hidden" name="type" value="', $context['browse_type'], '" />
+					<input type="hidden" name="sort" value="', $context['approve_list']['sort']['id'], '" />
+					<input type="hidden" name="start" value="', $context['approve_list']['start'], '" />
+					<input type="hidden" name="orig_filter" value="', $context['current_filter'], '" />
+					<input type="hidden" name="sa" value="approve" />', !empty($context['approve_list']['sort']['desc']) ? '
+					<input type="hidden" name="desc" value="1" />' : '', '
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>';
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 462 - 472
Themes/default/ManageNews.template.php

@@ -1,473 +1,463 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_email_members()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=news;sa=mailingcompose" method="post" class="flow_hidden" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['admin_newsletters'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['admin_news_select_recipients'], '
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['admin_news_select_group'], ':</strong><br />
-							<span class="smalltext">', $txt['admin_news_select_group_desc'], '</span>
-						</dt>
-						<dd>';
-
-	foreach ($context['groups'] as $group)
-				echo '
-							<label for="groups_', $group['id'], '"><input type="checkbox" name="groups[', $group['id'], ']" id="groups_', $group['id'], '" value="', $group['id'], '" checked="checked" class="input_check" /> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br />';
-
-	echo '
-							<br />
-							<label for="checkAllGroups"><input type="checkbox" id="checkAllGroups" checked="checked" onclick="invertAll(this, this.form, \'groups\');" class="input_check" /> <em>', $txt['check_all'], '</em></label>';
-
-	echo '
-						</dd>
-					</dl><br class="clear" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />
-
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<img id="advanced_panel_toggle" class="panel_toggle" style="display: none; src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png" alt="*" />
-					<a href="#" id="advanced_panel_link" >', $txt['advanced'], '</a>
-				</h3>
-			</div>
-
-			<div id="advanced_panel_div" class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['admin_news_select_email'], ':</strong><br />
-							<span class="smalltext">', $txt['admin_news_select_email_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea name="emails" rows="5" cols="30" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 98%; min-width: 98%' : 'width: 98%') . ';"></textarea>
-						</dd>
-						<dt>
-							<strong>', $txt['admin_news_select_members'], ':</strong><br />
-							<span class="smalltext">', $txt['admin_news_select_members_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="members" id="members" value="" size="30" class="input_text" />
-							<span id="members_container"></span>
-						</dd>
-					</dl>
-					<hr class="bordercolor" />
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['admin_news_select_excluded_groups'], ':</strong><br />
-							<span class="smalltext">', $txt['admin_news_select_excluded_groups_desc'], '</span>
-						</dt>
-						<dd>';
-
-	foreach ($context['groups'] as $group)
-				echo '
-							<label for="exclude_groups_', $group['id'], '"><input type="checkbox" name="exclude_groups[', $group['id'], ']" id="exclude_groups_', $group['id'], '" value="', $group['id'], '" class="input_check" /> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br />';
-
-	echo '
-							<br />
-							<label for="checkAllGroupsExclude"><input type="checkbox" id="checkAllGroupsExclude" onclick="invertAll(this, this.form, \'exclude_groups\');" class="input_check" /> <em>', $txt['check_all'], '</em></label><br />
-						</dd>
-						<dt>
-							<strong>', $txt['admin_news_select_excluded_members'], ':</strong><br />
-							<span class="smalltext">', $txt['admin_news_select_excluded_members_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="exclude_members" id="exclude_members" value="" size="30" class="input_text" />
-							<span id="exclude_members_container"></span>
-						</dd>
-					</dl>
-					<hr class="bordercolor" />
-					<dl class="settings">
-						<dt>
-							<label for="email_force"><strong>', $txt['admin_news_select_override_notify'], ':</strong></label><br />
-							<span class="smalltext">', $txt['email_force'], '</span>
-						</dt>
-						<dd>
-							<input type="checkbox" name="email_force" id="email_force" value="1" class="input_check" />
-						</dd>
-					</dl><br class="clear" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<div class="righttext">
-				<input type="submit" value="', $txt['admin_next'], '" class="button_submit" />
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-
-	// This is some javascript for the simple/advanced toggling and member suggest
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oAdvancedPanelToggle = new smc_Toggle({
-			bToggleEnabled: true,
-			bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
-			aSwappableContainers: [
-				\'advanced_panel_div\'
-			],
-			aSwapImages: [
-				{
-					sId: \'advanced_panel_toggle\',
-					srcExpanded: smf_images_url + \'/collapse.png\',
-					altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
-					srcCollapsed: smf_images_url + \'/expand.png\',
-					altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
-				}
-			],
-			aSwapLinks: [
-				{
-					sId: \'advanced_panel_link\',
-					msgExpanded: ', JavaScriptEscape($txt['advanced']), ',
-					msgCollapsed: ', JavaScriptEscape($txt['advanced']), '
-				}
-			],
-			oThemeOptions: {
-				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
-				sOptionName: \'admin_preferences\',
-				sSessionVar: smf_session_var,
-				sSessionId: smf_session_id,
-				sThemeId: \'1\'
-			}
-		});
-	// ]]></script>
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oMemberSuggest = new smc_AutoSuggest({
-			sSelf: \'oMemberSuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sSuggestId: \'members\',
-			sControlId: \'members\',
-			sSearchType: \'member\',
-			bItemList: true,
-			sPostName: \'member_list\',
-			sURLMask: \'action=profile;u=%item_id%\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			sItemListContainerId: \'members_container\',
-			aListItems: []
-		});
-		var oExcludeMemberSuggest = new smc_AutoSuggest({
-			sSelf: \'oExcludeMemberSuggest\',
-			sSessionId: \'', $context['session_id'], '\',
-			sSessionVar: \'', $context['session_var'], '\',
-			sSuggestId: \'exclude_members\',
-			sControlId: \'exclude_members\',
-			sSearchType: \'member\',
-			bItemList: true,
-			sPostName: \'exclude_member_list\',
-			sURLMask: \'action=profile;u=%item_id%\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			sItemListContainerId: \'exclude_members_container\',
-			aListItems: []
-		});
-	// ]]></script>';
-}
-
-function template_email_members_compose()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="post" id="preview_body">
-						', empty($context['preview_message']) ? '<br />' : $context['preview_message'], '
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div><br />';
-
-	echo '
-	<div id="admincenter">
-		<form name="newsmodify" action="', $scripturl, '?action=admin;area=news;sa=mailingsend" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<a href="', $scripturl, '?action=helpadmin;help=email_members" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a> ', $txt['admin_newsletters'], '
-				</h3>
-			</div>
-			<div class="information">
-				', $txt['email_variables'], '
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
-					<dl>
-						<dt>
-							<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
-						</dt>
-						<dd class="error" id="error_list">
-							', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
-						</dd>
-					</dl>
-				</div>
-				<dl id="post_header">
-					<dt class="clear_left">
-						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
-					</dt>
-					<dd id="pm_subject">
-						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="60" maxlength="60"',isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', '/>
-					</dd>
-				</dl><hr class="clear" />
-				<div id="bbcBox_message"></div>';
-
-	// What about smileys?
-	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
-		echo '
-				<div id="smileyBox_message"></div>';
-
-	// Show BBC buttons, smileys and textbox.
-	echo '
-				', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
-					
-					echo '
-					<ul class="reset">
-						<li><label for="send_pm"><input type="checkbox" name="send_pm" id="send_pm" ', !empty($context['send_pm']) ? 'checked="checked"' : '', 'class="input_check" onclick="checkboxes_status(this);" /> ', $txt['email_as_pms'], '</label></li>
-						<li><label for="send_html"><input type="checkbox" name="send_html" id="send_html" ', !empty($context['send_html']) ? 'checked="checked"' : '', 'class="input_check" onclick="checkboxes_status(this);" /> ', $txt['email_as_html'], '</label></li>
-						<li><label for="parse_html"><input type="checkbox" name="parse_html" id="parse_html" checked="checked" disabled="disabled" class="input_check" /> ', $txt['email_parsed_html'], '</label></li>
-					</ul>
-				<p id="shortcuts" class="smalltext">
-					', isBrowser('is_firefox') ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '
-				</p>
-				<p id="post_confirm_strip" class="righttext">
-					', template_control_richedit_buttons($context['post_box_name']), '
-				</p>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="email_force" value="', $context['email_force'], '" />
-			<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />
-			<input type="hidden" name="max_id_member" value="', $context['max_id_member'], '" />';
-
-	foreach ($context['recipients'] as $key => $values)
-		echo '
-			<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '" />';
-
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[';
-	// The functions used to preview a posts without loading a new page.
-	echo '
-			var txt_preview_title = "', $txt['preview_title'], '";
-			var txt_preview_fetch = "', $txt['preview_fetch'], '";
-			function previewPost()
-			{';
-	if (isBrowser('is_firefox'))
-		echo '
-				// Firefox doesn\'t render <marquee> that have been put it using javascript
-				if (document.forms.newsmodify.elements[', JavaScriptEscape($context['post_box_name']), '].value.indexOf(\'[move]\') != -1)
-				{
-					return submitThisOnce(document.forms.newsmodify);
-				}';
-	echo '
-				if (window.XMLHttpRequest)
-				{
-					// Opera didn\'t support setRequestHeader() before 8.01.
-					// @todo Remove support for old browsers
-					if (\'opera\' in window)
-					{
-						var test = new XMLHttpRequest();
-						if (!(\'setRequestHeader\' in test))
-							return submitThisOnce(document.forms.newsmodify);
-					}
-					// @todo Currently not sending poll options and option checkboxes.
-					var x = new Array();
-					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), '];
-					var checkboxFields = [\'send_html\', \'send_pm\'];
-
-					for (var i = 0, n = textFields.length; i < n; i++)
-						if (textFields[i] in document.forms.newsmodify)
-						{
-							// Handle the WYSIWYG editor.
-							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
-								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
-							else
-								x[x.length] = textFields[i] + \'=\' + document.forms.newsmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
-						}
-					for (var i = 0, n = checkboxFields.length; i < n; i++)
-						if (checkboxFields[i] in document.forms.newsmodify && document.forms.newsmodify.elements[checkboxFields[i]].checked)
-							x[x.length] = checkboxFields[i] + \'=\' + document.forms.newsmodify.elements[checkboxFields[i]].value;
-
-					x[x.length] = \'item=newsletterpreview\';
-
-					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=xmlhttp;sa=previews;xml\', x.join(\'&\'), onDocSent);
-
-					document.getElementById(\'preview_section\').style.display = \'\';
-					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
-					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
-
-					return false;
-				}
-				else
-					return submitThisOnce(document.forms.newsmodify);
-			}
-			function onDocSent(XMLDoc)
-			{
-				if (!XMLDoc)
-				{
-					document.forms.newsmodify.preview.onclick = new function ()
-					{
-						return true;
-					}
-					document.forms.newsmodify.preview.click();
-				}
-
-				// Show the preview section.
-				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
-				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
-
-				var bodyText = \'\';
-				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
-					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
-
-				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
-				document.getElementById(\'preview_body\').className = \'post\';
-
-				// Show a list of errors (if any).
-				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
-				var errorList = new Array();
-				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
-					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
-				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
-				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
-
-				// Adjust the color of captions if the given data is erroneous.
-				var captions = errors.getElementsByTagName(\'caption\');
-				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
-					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
-						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
-
-				if (errors.getElementsByTagName(\'post_error\').length == 1)
-					document.forms.newsmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
-				else if (document.forms.newsmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.newsmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
-				{
-					if (\'runtimeStyle\' in document.forms.newsmodify.', $context['post_box_name'], ')
-						document.forms.newsmodify.', $context['post_box_name'], '.style.borderColor = \'\';
-					else
-						document.forms.newsmodify.', $context['post_box_name'], '.style.border = null;
-				}
-				location.hash = \'#\' + \'preview_section\';
-			}';
-
-	echo '
-		// ]]></script>';
-
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			function checkboxes_status (item)
-			{
-				if (item.id == \'send_html\')
-					document.getElementById(\'parse_html\').disabled = !document.getElementById(\'parse_html\').disabled;
-				if (item.id == \'send_pm\')
-				{
-					if (!document.getElementById(\'send_html\').checked)
-						document.getElementById(\'parse_html\').disabled = true;
-					else
-						document.getElementById(\'parse_html\').disabled = false;
-					document.getElementById(\'send_html\').disabled = !document.getElementById(\'send_html\').disabled;
-				}
-			}
-		// ]]></script>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_email_members_send()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=news;sa=mailingsend" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<a href="', $scripturl, '?action=helpadmin;help=email_members" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a> ', $txt['admin_newsletters'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="progress_bar">
-						<div class="full_bar">', $context['percentage_done'], '% ', $txt['email_done'], '</div>
-						<div class="green_percent" style="width: ', $context['percentage_done'], '%;">&nbsp;</div>
-					</div>
-					<hr class="hrcolor" />
-					<input type="submit" name="b" value="', $txt['email_continue'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="subject" value="', $context['subject'], '" />
-					<input type="hidden" name="message" value="', $context['message'], '" />
-					<input type="hidden" name="start" value="', $context['start'], '" />
-					<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />
-					<input type="hidden" name="max_id_member" value="', $context['max_id_member'], '" />
-					<input type="hidden" name="send_pm" value="', $context['send_pm'], '" />
-					<input type="hidden" name="send_html" value="', $context['send_html'], '" />
-					<input type="hidden" name="parse_html" value="', $context['parse_html'], '" />';
-
-	// All the things we must remember!
-	foreach ($context['recipients'] as $key => $values)
-		echo '
-					<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '" />';
-
-	echo '
-				<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var countdown = 2;
-		doAutoSubmit();
-
-		function doAutoSubmit()
-		{
-			if (countdown == 0)
-				document.forms.autoSubmit.submit();
-			else if (countdown == -1)
-				return;
-
-			document.forms.autoSubmit.b.value = "', $txt['email_continue'], ' (" + countdown + ")";
-			countdown--;
-
-			setTimeout("doAutoSubmit();", 1000);
-		}
-	// ]]></script>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_email_members()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=news;sa=mailingcompose" method="post" class="flow_hidden" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['admin_newsletters'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['admin_news_select_recipients'], '
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['admin_news_select_group'], ':</strong><br />
+							<span class="smalltext">', $txt['admin_news_select_group_desc'], '</span>
+						</dt>
+						<dd>';
+
+	foreach ($context['groups'] as $group)
+				echo '
+							<label for="groups_', $group['id'], '"><input type="checkbox" name="groups[', $group['id'], ']" id="groups_', $group['id'], '" value="', $group['id'], '" checked="checked" class="input_check" /> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br />';
+
+	echo '
+							<br />
+							<label for="checkAllGroups"><input type="checkbox" id="checkAllGroups" checked="checked" onclick="invertAll(this, this.form, \'groups\');" class="input_check" /> <em>', $txt['check_all'], '</em></label>';
+
+	echo '
+						</dd>
+					</dl><br class="clear" />
+				</div>
+			</div>
+			<br />
+
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img id="advanced_panel_toggle" class="panel_toggle" style="display: none; src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png" alt="*" />
+					<a href="#" id="advanced_panel_link" >', $txt['advanced'], '</a>
+				</h3>
+			</div>
+
+			<div id="advanced_panel_div" class="windowbg2">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['admin_news_select_email'], ':</strong><br />
+							<span class="smalltext">', $txt['admin_news_select_email_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="emails" rows="5" cols="30" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 98%; min-width: 98%' : 'width: 98%') . ';"></textarea>
+						</dd>
+						<dt>
+							<strong>', $txt['admin_news_select_members'], ':</strong><br />
+							<span class="smalltext">', $txt['admin_news_select_members_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="members" id="members" value="" size="30" class="input_text" />
+							<span id="members_container"></span>
+						</dd>
+					</dl>
+					<hr class="bordercolor" />
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['admin_news_select_excluded_groups'], ':</strong><br />
+							<span class="smalltext">', $txt['admin_news_select_excluded_groups_desc'], '</span>
+						</dt>
+						<dd>';
+
+	foreach ($context['groups'] as $group)
+				echo '
+							<label for="exclude_groups_', $group['id'], '"><input type="checkbox" name="exclude_groups[', $group['id'], ']" id="exclude_groups_', $group['id'], '" value="', $group['id'], '" class="input_check" /> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br />';
+
+	echo '
+							<br />
+							<label for="checkAllGroupsExclude"><input type="checkbox" id="checkAllGroupsExclude" onclick="invertAll(this, this.form, \'exclude_groups\');" class="input_check" /> <em>', $txt['check_all'], '</em></label><br />
+						</dd>
+						<dt>
+							<strong>', $txt['admin_news_select_excluded_members'], ':</strong><br />
+							<span class="smalltext">', $txt['admin_news_select_excluded_members_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="exclude_members" id="exclude_members" value="" size="30" class="input_text" />
+							<span id="exclude_members_container"></span>
+						</dd>
+					</dl>
+					<hr class="bordercolor" />
+					<dl class="settings">
+						<dt>
+							<label for="email_force"><strong>', $txt['admin_news_select_override_notify'], ':</strong></label><br />
+							<span class="smalltext">', $txt['email_force'], '</span>
+						</dt>
+						<dd>
+							<input type="checkbox" name="email_force" id="email_force" value="1" class="input_check" />
+						</dd>
+					</dl><br class="clear" />
+				</div>
+			</div>
+			<div class="righttext">
+				<input type="submit" value="', $txt['admin_next'], '" class="button_submit" />
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+
+	// This is some javascript for the simple/advanced toggling and member suggest
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oAdvancedPanelToggle = new smc_Toggle({
+			bToggleEnabled: true,
+			bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
+			aSwappableContainers: [
+				\'advanced_panel_div\'
+			],
+			aSwapImages: [
+				{
+					sId: \'advanced_panel_toggle\',
+					srcExpanded: smf_images_url + \'/collapse.png\',
+					altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
+					srcCollapsed: smf_images_url + \'/expand.png\',
+					altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
+				}
+			],
+			aSwapLinks: [
+				{
+					sId: \'advanced_panel_link\',
+					msgExpanded: ', JavaScriptEscape($txt['advanced']), ',
+					msgCollapsed: ', JavaScriptEscape($txt['advanced']), '
+				}
+			],
+			oThemeOptions: {
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
+				sOptionName: \'admin_preferences\',
+				sSessionVar: smf_session_var,
+				sSessionId: smf_session_id,
+				sThemeId: \'1\'
+			}
+		});
+	// ]]></script>
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oMemberSuggest = new smc_AutoSuggest({
+			sSelf: \'oMemberSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'members\',
+			sControlId: \'members\',
+			sSearchType: \'member\',
+			bItemList: true,
+			sPostName: \'member_list\',
+			sURLMask: \'action=profile;u=%item_id%\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			sItemListContainerId: \'members_container\',
+			aListItems: []
+		});
+		var oExcludeMemberSuggest = new smc_AutoSuggest({
+			sSelf: \'oExcludeMemberSuggest\',
+			sSessionId: \'', $context['session_id'], '\',
+			sSessionVar: \'', $context['session_var'], '\',
+			sSuggestId: \'exclude_members\',
+			sControlId: \'exclude_members\',
+			sSearchType: \'member\',
+			bItemList: true,
+			sPostName: \'exclude_member_list\',
+			sURLMask: \'action=profile;u=%item_id%\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			sItemListContainerId: \'exclude_members_container\',
+			aListItems: []
+		});
+	// ]]></script>';
+}
+
+function template_email_members_compose()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<div class="post" id="preview_body">
+						', empty($context['preview_message']) ? '<br />' : $context['preview_message'], '
+					</div>
+				</div>
+			</div>
+		</div><br />';
+
+	echo '
+	<div id="admincenter">
+		<form name="newsmodify" action="', $scripturl, '?action=admin;area=news;sa=mailingsend" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<a href="', $scripturl, '?action=helpadmin;help=email_members" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a> ', $txt['admin_newsletters'], '
+				</h3>
+			</div>
+			<div class="information">
+				', $txt['email_variables'], '
+			</div>
+			<div class="windowbg">
+				<div class="content">
+				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
+					<dl>
+						<dt>
+							<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
+						</dt>
+						<dd class="error" id="error_list">
+							', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
+						</dd>
+					</dl>
+				</div>
+				<dl id="post_header">
+					<dt class="clear_left">
+						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
+					</dt>
+					<dd id="pm_subject">
+						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="60" maxlength="60"',isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', '/>
+					</dd>
+				</dl><hr class="clear" />
+				<div id="bbcBox_message"></div>';
+
+	// What about smileys?
+	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
+		echo '
+				<div id="smileyBox_message"></div>';
+
+	// Show BBC buttons, smileys and textbox.
+	echo '
+				', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
+					
+					echo '
+					<ul class="reset">
+						<li><label for="send_pm"><input type="checkbox" name="send_pm" id="send_pm" ', !empty($context['send_pm']) ? 'checked="checked"' : '', 'class="input_check" onclick="checkboxes_status(this);" /> ', $txt['email_as_pms'], '</label></li>
+						<li><label for="send_html"><input type="checkbox" name="send_html" id="send_html" ', !empty($context['send_html']) ? 'checked="checked"' : '', 'class="input_check" onclick="checkboxes_status(this);" /> ', $txt['email_as_html'], '</label></li>
+						<li><label for="parse_html"><input type="checkbox" name="parse_html" id="parse_html" checked="checked" disabled="disabled" class="input_check" /> ', $txt['email_parsed_html'], '</label></li>
+					</ul>
+				<p id="shortcuts" class="smalltext">
+					', isBrowser('is_firefox') ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '
+				</p>
+				<p id="post_confirm_strip" class="righttext">
+					', template_control_richedit_buttons($context['post_box_name']), '
+				</p>
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="email_force" value="', $context['email_force'], '" />
+			<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />
+			<input type="hidden" name="max_id_member" value="', $context['max_id_member'], '" />';
+
+	foreach ($context['recipients'] as $key => $values)
+		echo '
+			<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '" />';
+
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[';
+	// The functions used to preview a posts without loading a new page.
+	echo '
+			var txt_preview_title = "', $txt['preview_title'], '";
+			var txt_preview_fetch = "', $txt['preview_fetch'], '";
+			function previewPost()
+			{';
+	if (isBrowser('is_firefox'))
+		echo '
+				// Firefox doesn\'t render <marquee> that have been put it using javascript
+				if (document.forms.newsmodify.elements[', JavaScriptEscape($context['post_box_name']), '].value.indexOf(\'[move]\') != -1)
+				{
+					return submitThisOnce(document.forms.newsmodify);
+				}';
+	echo '
+				if (window.XMLHttpRequest)
+				{
+					// Opera didn\'t support setRequestHeader() before 8.01.
+					// @todo Remove support for old browsers
+					if (\'opera\' in window)
+					{
+						var test = new XMLHttpRequest();
+						if (!(\'setRequestHeader\' in test))
+							return submitThisOnce(document.forms.newsmodify);
+					}
+					// @todo Currently not sending poll options and option checkboxes.
+					var x = new Array();
+					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), '];
+					var checkboxFields = [\'send_html\', \'send_pm\'];
+
+					for (var i = 0, n = textFields.length; i < n; i++)
+						if (textFields[i] in document.forms.newsmodify)
+						{
+							// Handle the WYSIWYG editor.
+							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
+								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
+							else
+								x[x.length] = textFields[i] + \'=\' + document.forms.newsmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
+						}
+					for (var i = 0, n = checkboxFields.length; i < n; i++)
+						if (checkboxFields[i] in document.forms.newsmodify && document.forms.newsmodify.elements[checkboxFields[i]].checked)
+							x[x.length] = checkboxFields[i] + \'=\' + document.forms.newsmodify.elements[checkboxFields[i]].value;
+
+					x[x.length] = \'item=newsletterpreview\';
+
+					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=xmlhttp;sa=previews;xml\', x.join(\'&\'), onDocSent);
+
+					document.getElementById(\'preview_section\').style.display = \'\';
+					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
+					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
+
+					return false;
+				}
+				else
+					return submitThisOnce(document.forms.newsmodify);
+			}
+			function onDocSent(XMLDoc)
+			{
+				if (!XMLDoc)
+				{
+					document.forms.newsmodify.preview.onclick = new function ()
+					{
+						return true;
+					}
+					document.forms.newsmodify.preview.click();
+				}
+
+				// Show the preview section.
+				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
+				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
+
+				var bodyText = \'\';
+				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
+					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
+
+				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
+				document.getElementById(\'preview_body\').className = \'post\';
+
+				// Show a list of errors (if any).
+				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
+				var errorList = new Array();
+				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
+					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
+				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
+				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
+
+				// Adjust the color of captions if the given data is erroneous.
+				var captions = errors.getElementsByTagName(\'caption\');
+				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
+					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
+						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
+
+				if (errors.getElementsByTagName(\'post_error\').length == 1)
+					document.forms.newsmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
+				else if (document.forms.newsmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.newsmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
+				{
+					if (\'runtimeStyle\' in document.forms.newsmodify.', $context['post_box_name'], ')
+						document.forms.newsmodify.', $context['post_box_name'], '.style.borderColor = \'\';
+					else
+						document.forms.newsmodify.', $context['post_box_name'], '.style.border = null;
+				}
+				location.hash = \'#\' + \'preview_section\';
+			}';
+
+	echo '
+		// ]]></script>';
+
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			function checkboxes_status (item)
+			{
+				if (item.id == \'send_html\')
+					document.getElementById(\'parse_html\').disabled = !document.getElementById(\'parse_html\').disabled;
+				if (item.id == \'send_pm\')
+				{
+					if (!document.getElementById(\'send_html\').checked)
+						document.getElementById(\'parse_html\').disabled = true;
+					else
+						document.getElementById(\'parse_html\').disabled = false;
+					document.getElementById(\'send_html\').disabled = !document.getElementById(\'send_html\').disabled;
+				}
+			}
+		// ]]></script>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_email_members_send()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=news;sa=mailingsend" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<a href="', $scripturl, '?action=helpadmin;help=email_members" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a> ', $txt['admin_newsletters'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<div class="progress_bar">
+						<div class="full_bar">', $context['percentage_done'], '% ', $txt['email_done'], '</div>
+						<div class="green_percent" style="width: ', $context['percentage_done'], '%;">&nbsp;</div>
+					</div>
+					<hr class="hrcolor" />
+					<input type="submit" name="b" value="', $txt['email_continue'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="subject" value="', $context['subject'], '" />
+					<input type="hidden" name="message" value="', $context['message'], '" />
+					<input type="hidden" name="start" value="', $context['start'], '" />
+					<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />
+					<input type="hidden" name="max_id_member" value="', $context['max_id_member'], '" />
+					<input type="hidden" name="send_pm" value="', $context['send_pm'], '" />
+					<input type="hidden" name="send_html" value="', $context['send_html'], '" />
+					<input type="hidden" name="parse_html" value="', $context['parse_html'], '" />';
+
+	// All the things we must remember!
+	foreach ($context['recipients'] as $key => $values)
+		echo '
+					<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '" />';
+
+	echo '
+				<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var countdown = 2;
+		doAutoSubmit();
+
+		function doAutoSubmit()
+		{
+			if (countdown == 0)
+				document.forms.autoSubmit.submit();
+			else if (countdown == -1)
+				return;
+
+			document.forms.autoSubmit.b.value = "', $txt['email_continue'], ' (" + countdown + ")";
+			countdown--;
+
+			setTimeout("doAutoSubmit();", 1000);
+		}
+	// ]]></script>';
+}
+
 ?>

+ 622 - 638
Themes/default/ManagePaid.template.php

@@ -1,639 +1,623 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// The template for adding or editing a subscription.
-function template_modify_subscription()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=paidsubscribe;sa=modify;sid=', $context['sub_id'], '" method="post">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['paid_' . $context['action_type'] . '_subscription'], '</h3>
-			</div>';
-
-	if (!empty($context['disable_groups']))
-		echo '
-			<div class="information">
-				<span class="alert">', $txt['paid_mod_edit_note'], '</span>
-			</div>
-			';
-	echo '
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							', $txt['paid_mod_name'], ':
-						</dt>
-						<dd>
-							<input type="text" name="name" value="', $context['sub']['name'], '" size="30" class="input_text" />
-						</dd>
-						<dt>
-							', $txt['paid_mod_desc'], ':
-						</dt>
-						<dd>
-							<textarea name="desc" rows="3" cols="40">', $context['sub']['desc'], '</textarea>
-						</dd>
-						<dt>
-							<label for="repeatable_check">', $txt['paid_mod_repeatable'], '</label>:
-						</dt>
-						<dd>
-							<input type="checkbox" name="repeatable" id="repeatable_check"', empty($context['sub']['repeatable']) ? '' : ' checked="checked"', ' class="input_check" />
-						</dd>
-						<dt>
-							<label for="activated_check">', $txt['paid_mod_active'], '</label>:<br /><span class="smalltext">', $txt['paid_mod_active_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="checkbox" name="active" id="activated_check"', empty($context['sub']['active']) ? '' : ' checked="checked"', ' class="input_check" />
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<dl class="settings">
-						<dt>
-							', $txt['paid_mod_prim_group'], ':<br /><span class="smalltext">', $txt['paid_mod_prim_group_desc'], '</span>
-						</dt>
-						<dd>
-							<select name="prim_group" ', !empty($context['disable_groups']) ? 'disabled="disabled"' : '', '>
-								<option value="0" ', $context['sub']['prim_group'] == 0 ? 'selected="selected"' : '', '>', $txt['paid_mod_no_group'], '</option>';
-
-	// Put each group into the box.
-	foreach ($context['groups'] as $id => $name)
-		echo '
-								<option value="', $id, '" ', $context['sub']['prim_group'] == $id ? 'selected="selected"' : '', '>', $name, '</option>';
-
-	echo '
-							</select>
-						</dd>
-						<dt>
-							', $txt['paid_mod_add_groups'], ':<br /><span class="smalltext">', $txt['paid_mod_add_groups_desc'], '</span>
-						</dt>
-						<dd>';
-
-	// Put a checkbox in for each group
-	foreach ($context['groups'] as $id => $name)
-		echo '
-							<label for="addgroup_', $id, '"><input type="checkbox" id="addgroup_', $id, '" name="addgroup[', $id, ']"', in_array($id, $context['sub']['add_groups']) ? ' checked="checked"' : '', ' ', !empty($context['disable_groups']) ? ' disabled="disabled"' : '', ' class="input_check" />&nbsp;<span class="smalltext">', $name, '</span></label><br />';
-
-	echo '
-						</dd>
-						<dt>
-							', $txt['paid_mod_reminder'], ':<br /><span class="smalltext">', $txt['paid_mod_reminder_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="reminder" value="', $context['sub']['reminder'], '" size="6" class="input_text" />
-						</dd>
-						<dt>
-							', $txt['paid_mod_email'], ':<br /><span class="smalltext">', $txt['paid_mod_email_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea name="emailcomplete" rows="6" cols="40">', $context['sub']['email_complete'], '</textarea>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="radio" name="duration_type" id="duration_type_fixed" value="fixed" ', empty($context['sub']['duration']) || $context['sub']['duration'] == 'fixed' ? 'checked="checked"' : '', ' class="input_radio" onclick="toggleDuration(\'fixed\');" />
-					<strong>', $txt['paid_mod_fixed_price'], '</strong>
-					<br />
-					<div id="fixed_area" ', empty($context['sub']['duration']) || $context['sub']['duration'] == 'fixed' ? '' : 'style="display: none;"', '>
-						<fieldset>
-							<dl class="settings">
-								<dt>
-									', $txt['paid_cost'], ' (', str_replace('%1.2f', '', $modSettings['paid_currency_symbol']), '):
-								</dt>
-								<dd>
-									<input type="text" name="cost" value="', empty($context['sub']['cost']['fixed']) ? '0' : $context['sub']['cost']['fixed'], '" size="4" class="input_text" />
-								</dd>
-								<dt>
-									', $txt['paid_mod_span'], ':
-								</dt>
-								<dd>
-									<input type="text" name="span_value" value="', $context['sub']['span']['value'], '" size="4" class="input_text" />
-									<select name="span_unit">
-										<option value="D" ', $context['sub']['span']['unit'] == 'D' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_days'], '</option>
-										<option value="W" ', $context['sub']['span']['unit'] == 'W' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_weeks'], '</option>
-										<option value="M" ', $context['sub']['span']['unit'] == 'M' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_months'], '</option>
-										<option value="Y" ', $context['sub']['span']['unit'] == 'Y' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_years'], '</option>
-									</select>
-								</dd>
-							</dl>
-						</fieldset>
-					</div>
-					<input type="radio" name="duration_type" id="duration_type_flexible" value="flexible" ', !empty($context['sub']['duration']) && $context['sub']['duration'] == 'flexible' ? 'checked="checked"' : '', ' class="input_radio" onclick="toggleDuration(\'flexible\');" />
-					<strong>', $txt['paid_mod_flexible_price'], '</strong>
-					<br />
-					<div id="flexible_area" ', !empty($context['sub']['duration']) && $context['sub']['duration'] == 'flexible' ? '' : 'style="display: none;"', '>
-						<fieldset>';
-
-	//!! Removed until implemented
-	if (!empty($sdflsdhglsdjgs))
-		echo '
-							<dl class="settings">
-								<dt>
-									<label for="allow_partial_check">', $txt['paid_mod_allow_partial'], '</label>:<br /><span class="smalltext">', $txt['paid_mod_allow_partial_desc'], '</span>
-								</dt>
-								<dd>
-									<input type="checkbox" name="allow_partial" id="allow_partial_check"', empty($context['sub']['allow_partial']) ? '' : ' checked="checked"', ' class="input_check" />
-								</dd>
-							</dl>';
-
-	echo '
-							<div class="information">
-								<strong>', $txt['paid_mod_price_breakdown'], '</strong><br />
-								', $txt['paid_mod_price_breakdown_desc'], '
-							</div>
-							<dl class="settings">
-								<dt>
-									<strong>', $txt['paid_duration'], '</strong>
-								</dt>
-								<dd>
-									<strong>', $txt['paid_cost'], ' (', preg_replace('~%[df\.\d]+~', '', $modSettings['paid_currency_symbol']), ')</strong>
-								</dd>
-								<dt>
-									', $txt['paid_per_day'], ':
-								</dt>
-								<dd>
-									<input type="text" name="cost_day" value="', empty($context['sub']['cost']['day']) ? '0' : $context['sub']['cost']['day'], '" size="5" class="input_text" />
-								</dd>
-								<dt>
-									', $txt['paid_per_week'], ':
-								</dt>
-								<dd>
-									<input type="text" name="cost_week" value="', empty($context['sub']['cost']['week']) ? '0' : $context['sub']['cost']['week'], '" size="5" class="input_text" />
-								</dd>
-								<dt>
-									', $txt['paid_per_month'], ':
-								</dt>
-								<dd>
-									<input type="text" name="cost_month" value="', empty($context['sub']['cost']['month']) ? '0' : $context['sub']['cost']['month'], '" size="5" class="input_text" />
-								</dd>
-								<dt>
-									', $txt['paid_per_year'], ':
-								</dt>
-								<dd>
-									<input type="text" name="cost_year" value="', empty($context['sub']['cost']['year']) ? '0' : $context['sub']['cost']['year'], '" size="5" class="input_text" />
-								</dd>
-							</dl>
-						</fieldset>
-					</div>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['paid_settings_save'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-pms_token_var'], '" value="', $context['admin-pms_token'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-
-}
-
-function template_delete_subscription()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=paidsubscribe;sa=modify;sid=', $context['sub_id'], ';delete" method="post">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['paid_delete_subscription'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['paid_mod_delete_warning'], '</p>
-
-					<input type="submit" name="delete_confirm" value="', $txt['paid_delete_subscription'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-pmsd_token_var'], '" value="', $context['admin-pmsd_token'], '" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-
-}
-
-// Add or edit an existing subscriber.
-function template_modify_user_subscription()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Some quickly stolen javascript from Post, could do with being more efficient :)
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
-		// ]]></script>';
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;sid=', $context['sub_id'], ';lid=', $context['log_id'], '" method="post">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $txt['paid_' . $context['action_type'] . '_subscription'], ' - ', $context['current_subscription']['name'], '
-					', empty($context['sub']['username']) ? '' : ' (' . $txt['user'] . ': ' . $context['sub']['username'] . ')', '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-
-	// Do we need a username?
-	if ($context['action_type'] == 'add')
-		echo '
-
-						<dt>
-							<strong>', $txt['paid_username'], ':</strong><br />
-							<span class="smalltext">', $txt['one_username'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="name" id="name_control" value="', $context['sub']['username'], '" size="30" class="input_text" />
-						</dd>';
-
-	echo '
-						<dt>
-							<strong>', $txt['paid_status'], ':</strong>
-						</dt>
-						<dd>
-							<select name="status">
-								<option value="0" ', $context['sub']['status'] == 0 ? 'selected="selected"' : '', '>', $txt['paid_finished'], '</option>
-								<option value="1" ', $context['sub']['status'] == 1 ? 'selected="selected"' : '', '>', $txt['paid_active'], '</option>
-							</select>
-						</dd>
-					</dl>
-					<fieldset>
-						<legend>', $txt['start_date_and_time'], '</legend>
-						<select name="year" id="year" onchange="generateDays(\'\');">';
-
-	// Show a list of all the years we allow...
-	for ($year = 2005; $year <= 2030; $year++)
-		echo '
-							<option value="', $year, '"', $year == $context['sub']['start']['year'] ? ' selected="selected"' : '', '>', $year, '</option>';
-
-	echo '
-						</select>&nbsp;
-						', (isset($txt['calendar_month']) ? $txt['calendar_month'] : $txt['calendar_month']), '&nbsp;
-						<select name="month" id="month" onchange="generateDays(\'\');">';
-
-	// There are 12 months per year - ensure that they all get listed.
-	for ($month = 1; $month <= 12; $month++)
-		echo '
-							<option value="', $month, '"', $month == $context['sub']['start']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '</option>';
-
-	echo '
-						</select>&nbsp;
-						', (isset($txt['calendar_day']) ? $txt['calendar_day'] : $txt['calendar_day']), '&nbsp;
-						<select name="day" id="day">';
-
-	// This prints out all the days in the current month - this changes dynamically as we switch months.
-	for ($day = 1; $day <= $context['sub']['start']['last_day']; $day++)
-		echo '
-							<option value="', $day, '"', $day == $context['sub']['start']['day'] ? ' selected="selected"' : '', '>', $day, '</option>';
-
-	echo '
-						</select>
-						', $txt['hour'], ': <input type="text" name="hour" value="', $context['sub']['start']['hour'], '" size="2" class="input_text" />
-						', $txt['minute'], ': <input type="text" name="minute" value="', $context['sub']['start']['min'], '" size="2" class="input_text" />
-					</fieldset>
-					<fieldset>
-						<legend>', $txt['end_date_and_time'], '</legend>
-						<select name="yearend" id="yearend" onchange="generateDays(\'end\');">';
-
-	// Show a list of all the years we allow...
-	for ($year = 2005; $year <= 2030; $year++)
-		echo '
-							<option value="', $year, '"', $year == $context['sub']['end']['year'] ? ' selected="selected"' : '', '>', $year, '</option>';
-
-	echo '
-						</select>&nbsp;
-						', (isset($txt['calendar_month']) ? $txt['calendar_month'] : $txt['calendar_month']), '&nbsp;
-						<select name="monthend" id="monthend" onchange="generateDays(\'end\');">';
-
-	// There are 12 months per year - ensure that they all get listed.
-	for ($month = 1; $month <= 12; $month++)
-		echo '
-							<option value="', $month, '"', $month == $context['sub']['end']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '</option>';
-
-	echo '
-						</select>&nbsp;
-						', (isset($txt['calendar_day']) ? $txt['calendar_day'] : $txt['calendar_day']), '&nbsp;
-						<select name="dayend" id="dayend">';
-
-	// This prints out all the days in the current month - this changes dynamically as we switch months.
-	for ($day = 1; $day <= $context['sub']['end']['last_day']; $day++)
-		echo '
-							<option value="', $day, '"', $day == $context['sub']['end']['day'] ? ' selected="selected"' : '', '>', $day, '</option>';
-
-	echo '
-						</select>
-						', $txt['hour'], ': <input type="text" name="hourend" value="', $context['sub']['end']['hour'], '" size="2" class="input_text" />
-						', $txt['minute'], ': <input type="text" name="minuteend" value="', $context['sub']['end']['min'], '" size="2" class="input_text" />
-					</fieldset>
-					<input type="submit" name="save_sub" value="', $txt['paid_settings_save'], '" class="button_submit" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-		var oAddMemberSuggest = new smc_AutoSuggest({
-			sSelf: \'oAddMemberSuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sSuggestId: \'name_subscriber\',
-			sControlId: \'name_control\',
-			sSearchType: \'member\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			bItemList: false
-			});
-		// ]]></script>';
-
-	if (!empty($context['pending_payments']))
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pending_payments'], '</h3>
-		</div>
-		<div class="information">
-		', $txt['pending_payments_desc'], '
-		</div>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pending_payments_value'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<ul class="pending_payments">';
-
-		foreach ($context['pending_payments'] as $id => $payment)
-		{
-			echo '
-					<li class="reset">
-						', $payment['desc'], '
-						<span class="floatleft"><a href="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;lid=', $context['log_id'], ';pending=', $id, ';accept">', $txt['pending_payments_accept'], '</a></span>
-						<span class="floatright"><a href="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;lid=', $context['log_id'], ';pending=', $id, ';remove">', $txt['pending_payments_remove'], '</a></span>
-					</li>';
-		}
-
-		echo '
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-		</div>
-	<br class="clear" />';
-}
-
-// Template for a user to edit/pick their subscriptions.
-function template_user_subscription()
-{
-	global $context, $txt, $scripturl, $modSettings;
-
-	echo '
-	<div id="paid_subscription">
-		<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=subscriptions;confirm" method="post">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['subscriptions'], '</h3>
-			</div>';
-
-	if (empty($context['subscriptions']))
-	{
-		echo '
-			<div class="information">
-				', $txt['paid_subs_none'], '
-			</div>';
-	}
-	else
-	{
-		echo '
-			<div class="information">
-				', $txt['paid_subs_desc'], '
-			</div>';
-
-		// Print out all the subscriptions.
-		$alternate = false;
-		foreach ($context['subscriptions'] as $id => $subscription)
-		{
-			$alternate = !$alternate;
-
-			// Ignore the inactive ones...
-			if (empty($subscription['active']))
-				continue;
-
-			echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $subscription['name'], '</h3>
-			</div>
-			<div class="windowbg', $alternate ? '' : '2', '">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p><strong>', $subscription['name'], '</strong></p>
-					<p class="smalltext">', $subscription['desc'], '</p>';
-
-			if (!$subscription['flexible'])
-				echo '
-					<div><strong>', $txt['paid_duration'], ':</strong> ', $subscription['length'], '</div>';
-
-			if ($context['user']['is_owner'])
-			{
-				echo '
-					<strong>', $txt['paid_cost'], ':</strong>';
-
-				if ($subscription['flexible'])
-				{
-					echo '
-					<select name="cur[', $subscription['id'], ']">';
-
-					// Print out the costs for this one.
-					foreach ($subscription['costs'] as $duration => $value)
-						echo '
-						<option value="', $duration, '">', sprintf($modSettings['paid_currency_symbol'], $value), '/', $txt[$duration], '</option>';
-
-					echo '
-					</select>';
-				}
-				else
-					echo '
-					', sprintf($modSettings['paid_currency_symbol'], $subscription['costs']['fixed']);
-
-				echo '
-					<hr class="hrcolor" />
-					<input type="submit" name="sub_id[', $subscription['id'], ']" value="', $txt['paid_order'], '" class="button_submit" />
-					<br class="clear_right" />';
-			}
-			else
-				echo '
-					<a href="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;sid=', $subscription['id'], ';uid=', $context['member']['id'], (empty($context['current'][$subscription['id']]) ? '' : ';lid=' . $context['current'][$subscription['id']]['id']), '">', empty($context['current'][$subscription['id']]) ? $txt['paid_admin_add'] : $txt['paid_edit_subscription'], '</a>';
-
-			echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-		}
-	}
-
-	echo '
-		</form>
-		<br class="clear"/>
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['paid_current'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['paid_current_desc'], '
-		</div>
-		<table width="100%" class="table_grid">
-			<thead>
-				<tr class="catbg">
-					<th class="first_th" width="30%">', $txt['paid_name'], '</th>
-					<th align="center">', $txt['paid_status'], '</th>
-					<th align="center">', $txt['start_date'], '</th>
-					<th class="last_th" align="center">', $txt['end_date'], '</th>
-				</tr>
-			</thead>
-			<tbody>';
-
-	if (empty($context['current']))
-		echo '
-				<tr class="windowbg">
-					<td align="center" colspan="4">
-						', $txt['paid_none_yet'], '
-					</td>
-				</tr>';
-
-	$alternate = false;
-	foreach ($context['current'] as $sub)
-	{
-		$alternate = !$alternate;
-
-		if (!$sub['hide'])
-			echo '
-				<tr class="windowbg', $alternate ? '' : '2', '">
-					<td>
-						', (allowedTo('admin_forum') ? '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modifyuser;lid=' . $sub['id'] . '">' . $sub['name'] . '</a>' : $sub['name']), '
-					</td><td>
-						<span style="color: ', ($sub['status'] == 2 ? 'green' : ($sub['status'] == 1 ? 'red' : 'orange')), '"><strong>', $sub['status_text'], '</strong></span>
-					</td><td>
-						', $sub['start'], '
-					</td><td>
-						', $sub['end'], '
-					</td>
-				</tr>';
-	}
-	echo '
-			</tbody>
-		</table>
-	</div>
-	<br class="clear" />';
-}
-
-// The "choose payment" dialog.
-function template_choose_payment()
-{
-	global $context, $txt, $modSettings, $scripturl;
-
-	echo '
-	<div id="paid_subscription">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['paid_confirm_payment'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['paid_confirm_desc'], '
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">
-					<dt>
-						<strong>', $txt['subscription'], ':</strong>
-					</dt>
-					<dd>
-						', $context['sub']['name'], '
-					</dd>
-					<dt>
-						<strong>', $txt['paid_cost'], ':</strong>
-					</dt>
-					<dd>
-						', $context['cost'], '
-					</dd>
-				</dl>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	// Do all the gateway options.
-	foreach ($context['gateways'] as $gateway)
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $gateway['title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				', $gateway['desc'], '<br />
-					<form action="', $gateway['form'], '" method="post">';
-
-		if (!empty($gateway['javascript']))
-			echo '
-						<script type="text/javascript"><!-- // --><![CDATA[
-							', $gateway['javascript'], '
-						// ]]></script>';
-
-		foreach ($gateway['hidden'] as $name => $value)
-			echo '
-						<input type="hidden" id="', $gateway['id'], '_', $name, '" name="', $name, '" value="', $value, '" />';
-
-		echo '
-						<br /><input type="submit" value="', $gateway['submit'], '" class="button_submit" />
-					</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-// The "thank you" bit...
-function template_paid_done()
-{
-	global $context, $txt, $modSettings, $scripturl;
-
-	echo '
-	<div id="paid_subscription">
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['paid_done'], '</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['paid_done_desc'], '</p>
-				<br />
-				<a href="', $scripturl, '?action=profile;u=', $context['member']['id'], ';area=subscriptions">', $txt['paid_sub_return'], '</a>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// The template for adding or editing a subscription.
+function template_modify_subscription()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=paidsubscribe;sa=modify;sid=', $context['sub_id'], '" method="post">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['paid_' . $context['action_type'] . '_subscription'], '</h3>
+			</div>';
+
+	if (!empty($context['disable_groups']))
+		echo '
+			<div class="information">
+				<span class="alert">', $txt['paid_mod_edit_note'], '</span>
+			</div>
+			';
+	echo '
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							', $txt['paid_mod_name'], ':
+						</dt>
+						<dd>
+							<input type="text" name="name" value="', $context['sub']['name'], '" size="30" class="input_text" />
+						</dd>
+						<dt>
+							', $txt['paid_mod_desc'], ':
+						</dt>
+						<dd>
+							<textarea name="desc" rows="3" cols="40">', $context['sub']['desc'], '</textarea>
+						</dd>
+						<dt>
+							<label for="repeatable_check">', $txt['paid_mod_repeatable'], '</label>:
+						</dt>
+						<dd>
+							<input type="checkbox" name="repeatable" id="repeatable_check"', empty($context['sub']['repeatable']) ? '' : ' checked="checked"', ' class="input_check" />
+						</dd>
+						<dt>
+							<label for="activated_check">', $txt['paid_mod_active'], '</label>:<br /><span class="smalltext">', $txt['paid_mod_active_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="checkbox" name="active" id="activated_check"', empty($context['sub']['active']) ? '' : ' checked="checked"', ' class="input_check" />
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<dl class="settings">
+						<dt>
+							', $txt['paid_mod_prim_group'], ':<br /><span class="smalltext">', $txt['paid_mod_prim_group_desc'], '</span>
+						</dt>
+						<dd>
+							<select name="prim_group" ', !empty($context['disable_groups']) ? 'disabled="disabled"' : '', '>
+								<option value="0" ', $context['sub']['prim_group'] == 0 ? 'selected="selected"' : '', '>', $txt['paid_mod_no_group'], '</option>';
+
+	// Put each group into the box.
+	foreach ($context['groups'] as $id => $name)
+		echo '
+								<option value="', $id, '" ', $context['sub']['prim_group'] == $id ? 'selected="selected"' : '', '>', $name, '</option>';
+
+	echo '
+							</select>
+						</dd>
+						<dt>
+							', $txt['paid_mod_add_groups'], ':<br /><span class="smalltext">', $txt['paid_mod_add_groups_desc'], '</span>
+						</dt>
+						<dd>';
+
+	// Put a checkbox in for each group
+	foreach ($context['groups'] as $id => $name)
+		echo '
+							<label for="addgroup_', $id, '"><input type="checkbox" id="addgroup_', $id, '" name="addgroup[', $id, ']"', in_array($id, $context['sub']['add_groups']) ? ' checked="checked"' : '', ' ', !empty($context['disable_groups']) ? ' disabled="disabled"' : '', ' class="input_check" />&nbsp;<span class="smalltext">', $name, '</span></label><br />';
+
+	echo '
+						</dd>
+						<dt>
+							', $txt['paid_mod_reminder'], ':<br /><span class="smalltext">', $txt['paid_mod_reminder_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="reminder" value="', $context['sub']['reminder'], '" size="6" class="input_text" />
+						</dd>
+						<dt>
+							', $txt['paid_mod_email'], ':<br /><span class="smalltext">', $txt['paid_mod_email_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="emailcomplete" rows="6" cols="40">', $context['sub']['email_complete'], '</textarea>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="radio" name="duration_type" id="duration_type_fixed" value="fixed" ', empty($context['sub']['duration']) || $context['sub']['duration'] == 'fixed' ? 'checked="checked"' : '', ' class="input_radio" onclick="toggleDuration(\'fixed\');" />
+					<strong>', $txt['paid_mod_fixed_price'], '</strong>
+					<br />
+					<div id="fixed_area" ', empty($context['sub']['duration']) || $context['sub']['duration'] == 'fixed' ? '' : 'style="display: none;"', '>
+						<fieldset>
+							<dl class="settings">
+								<dt>
+									', $txt['paid_cost'], ' (', str_replace('%1.2f', '', $modSettings['paid_currency_symbol']), '):
+								</dt>
+								<dd>
+									<input type="text" name="cost" value="', empty($context['sub']['cost']['fixed']) ? '0' : $context['sub']['cost']['fixed'], '" size="4" class="input_text" />
+								</dd>
+								<dt>
+									', $txt['paid_mod_span'], ':
+								</dt>
+								<dd>
+									<input type="text" name="span_value" value="', $context['sub']['span']['value'], '" size="4" class="input_text" />
+									<select name="span_unit">
+										<option value="D" ', $context['sub']['span']['unit'] == 'D' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_days'], '</option>
+										<option value="W" ', $context['sub']['span']['unit'] == 'W' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_weeks'], '</option>
+										<option value="M" ', $context['sub']['span']['unit'] == 'M' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_months'], '</option>
+										<option value="Y" ', $context['sub']['span']['unit'] == 'Y' ? 'selected="selected"' : '', '>', $txt['paid_mod_span_years'], '</option>
+									</select>
+								</dd>
+							</dl>
+						</fieldset>
+					</div>
+					<input type="radio" name="duration_type" id="duration_type_flexible" value="flexible" ', !empty($context['sub']['duration']) && $context['sub']['duration'] == 'flexible' ? 'checked="checked"' : '', ' class="input_radio" onclick="toggleDuration(\'flexible\');" />
+					<strong>', $txt['paid_mod_flexible_price'], '</strong>
+					<br />
+					<div id="flexible_area" ', !empty($context['sub']['duration']) && $context['sub']['duration'] == 'flexible' ? '' : 'style="display: none;"', '>
+						<fieldset>';
+
+	//!! Removed until implemented
+	if (!empty($sdflsdhglsdjgs))
+		echo '
+							<dl class="settings">
+								<dt>
+									<label for="allow_partial_check">', $txt['paid_mod_allow_partial'], '</label>:<br /><span class="smalltext">', $txt['paid_mod_allow_partial_desc'], '</span>
+								</dt>
+								<dd>
+									<input type="checkbox" name="allow_partial" id="allow_partial_check"', empty($context['sub']['allow_partial']) ? '' : ' checked="checked"', ' class="input_check" />
+								</dd>
+							</dl>';
+
+	echo '
+							<div class="information">
+								<strong>', $txt['paid_mod_price_breakdown'], '</strong><br />
+								', $txt['paid_mod_price_breakdown_desc'], '
+							</div>
+							<dl class="settings">
+								<dt>
+									<strong>', $txt['paid_duration'], '</strong>
+								</dt>
+								<dd>
+									<strong>', $txt['paid_cost'], ' (', preg_replace('~%[df\.\d]+~', '', $modSettings['paid_currency_symbol']), ')</strong>
+								</dd>
+								<dt>
+									', $txt['paid_per_day'], ':
+								</dt>
+								<dd>
+									<input type="text" name="cost_day" value="', empty($context['sub']['cost']['day']) ? '0' : $context['sub']['cost']['day'], '" size="5" class="input_text" />
+								</dd>
+								<dt>
+									', $txt['paid_per_week'], ':
+								</dt>
+								<dd>
+									<input type="text" name="cost_week" value="', empty($context['sub']['cost']['week']) ? '0' : $context['sub']['cost']['week'], '" size="5" class="input_text" />
+								</dd>
+								<dt>
+									', $txt['paid_per_month'], ':
+								</dt>
+								<dd>
+									<input type="text" name="cost_month" value="', empty($context['sub']['cost']['month']) ? '0' : $context['sub']['cost']['month'], '" size="5" class="input_text" />
+								</dd>
+								<dt>
+									', $txt['paid_per_year'], ':
+								</dt>
+								<dd>
+									<input type="text" name="cost_year" value="', empty($context['sub']['cost']['year']) ? '0' : $context['sub']['cost']['year'], '" size="5" class="input_text" />
+								</dd>
+							</dl>
+						</fieldset>
+					</div>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['paid_settings_save'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-pms_token_var'], '" value="', $context['admin-pms_token'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+
+}
+
+function template_delete_subscription()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=paidsubscribe;sa=modify;sid=', $context['sub_id'], ';delete" method="post">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['paid_delete_subscription'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>', $txt['paid_mod_delete_warning'], '</p>
+
+					<input type="submit" name="delete_confirm" value="', $txt['paid_delete_subscription'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-pmsd_token_var'], '" value="', $context['admin-pmsd_token'], '" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+
+}
+
+// Add or edit an existing subscriber.
+function template_modify_user_subscription()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Some quickly stolen javascript from Post, could do with being more efficient :)
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+		// ]]></script>';
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;sid=', $context['sub_id'], ';lid=', $context['log_id'], '" method="post">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $txt['paid_' . $context['action_type'] . '_subscription'], ' - ', $context['current_subscription']['name'], '
+					', empty($context['sub']['username']) ? '' : ' (' . $txt['user'] . ': ' . $context['sub']['username'] . ')', '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">';
+
+	// Do we need a username?
+	if ($context['action_type'] == 'add')
+		echo '
+
+						<dt>
+							<strong>', $txt['paid_username'], ':</strong><br />
+							<span class="smalltext">', $txt['one_username'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="name" id="name_control" value="', $context['sub']['username'], '" size="30" class="input_text" />
+						</dd>';
+
+	echo '
+						<dt>
+							<strong>', $txt['paid_status'], ':</strong>
+						</dt>
+						<dd>
+							<select name="status">
+								<option value="0" ', $context['sub']['status'] == 0 ? 'selected="selected"' : '', '>', $txt['paid_finished'], '</option>
+								<option value="1" ', $context['sub']['status'] == 1 ? 'selected="selected"' : '', '>', $txt['paid_active'], '</option>
+							</select>
+						</dd>
+					</dl>
+					<fieldset>
+						<legend>', $txt['start_date_and_time'], '</legend>
+						<select name="year" id="year" onchange="generateDays(\'\');">';
+
+	// Show a list of all the years we allow...
+	for ($year = 2005; $year <= 2030; $year++)
+		echo '
+							<option value="', $year, '"', $year == $context['sub']['start']['year'] ? ' selected="selected"' : '', '>', $year, '</option>';
+
+	echo '
+						</select>&nbsp;
+						', (isset($txt['calendar_month']) ? $txt['calendar_month'] : $txt['calendar_month']), '&nbsp;
+						<select name="month" id="month" onchange="generateDays(\'\');">';
+
+	// There are 12 months per year - ensure that they all get listed.
+	for ($month = 1; $month <= 12; $month++)
+		echo '
+							<option value="', $month, '"', $month == $context['sub']['start']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '</option>';
+
+	echo '
+						</select>&nbsp;
+						', (isset($txt['calendar_day']) ? $txt['calendar_day'] : $txt['calendar_day']), '&nbsp;
+						<select name="day" id="day">';
+
+	// This prints out all the days in the current month - this changes dynamically as we switch months.
+	for ($day = 1; $day <= $context['sub']['start']['last_day']; $day++)
+		echo '
+							<option value="', $day, '"', $day == $context['sub']['start']['day'] ? ' selected="selected"' : '', '>', $day, '</option>';
+
+	echo '
+						</select>
+						', $txt['hour'], ': <input type="text" name="hour" value="', $context['sub']['start']['hour'], '" size="2" class="input_text" />
+						', $txt['minute'], ': <input type="text" name="minute" value="', $context['sub']['start']['min'], '" size="2" class="input_text" />
+					</fieldset>
+					<fieldset>
+						<legend>', $txt['end_date_and_time'], '</legend>
+						<select name="yearend" id="yearend" onchange="generateDays(\'end\');">';
+
+	// Show a list of all the years we allow...
+	for ($year = 2005; $year <= 2030; $year++)
+		echo '
+							<option value="', $year, '"', $year == $context['sub']['end']['year'] ? ' selected="selected"' : '', '>', $year, '</option>';
+
+	echo '
+						</select>&nbsp;
+						', (isset($txt['calendar_month']) ? $txt['calendar_month'] : $txt['calendar_month']), '&nbsp;
+						<select name="monthend" id="monthend" onchange="generateDays(\'end\');">';
+
+	// There are 12 months per year - ensure that they all get listed.
+	for ($month = 1; $month <= 12; $month++)
+		echo '
+							<option value="', $month, '"', $month == $context['sub']['end']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '</option>';
+
+	echo '
+						</select>&nbsp;
+						', (isset($txt['calendar_day']) ? $txt['calendar_day'] : $txt['calendar_day']), '&nbsp;
+						<select name="dayend" id="dayend">';
+
+	// This prints out all the days in the current month - this changes dynamically as we switch months.
+	for ($day = 1; $day <= $context['sub']['end']['last_day']; $day++)
+		echo '
+							<option value="', $day, '"', $day == $context['sub']['end']['day'] ? ' selected="selected"' : '', '>', $day, '</option>';
+
+	echo '
+						</select>
+						', $txt['hour'], ': <input type="text" name="hourend" value="', $context['sub']['end']['hour'], '" size="2" class="input_text" />
+						', $txt['minute'], ': <input type="text" name="minuteend" value="', $context['sub']['end']['min'], '" size="2" class="input_text" />
+					</fieldset>
+					<input type="submit" name="save_sub" value="', $txt['paid_settings_save'], '" class="button_submit" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+		var oAddMemberSuggest = new smc_AutoSuggest({
+			sSelf: \'oAddMemberSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'name_subscriber\',
+			sControlId: \'name_control\',
+			sSearchType: \'member\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			bItemList: false
+			});
+		// ]]></script>';
+
+	if (!empty($context['pending_payments']))
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pending_payments'], '</h3>
+		</div>
+		<div class="information">
+		', $txt['pending_payments_desc'], '
+		</div>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pending_payments_value'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<ul class="pending_payments">';
+
+		foreach ($context['pending_payments'] as $id => $payment)
+		{
+			echo '
+					<li class="reset">
+						', $payment['desc'], '
+						<span class="floatleft"><a href="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;lid=', $context['log_id'], ';pending=', $id, ';accept">', $txt['pending_payments_accept'], '</a></span>
+						<span class="floatright"><a href="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;lid=', $context['log_id'], ';pending=', $id, ';remove">', $txt['pending_payments_remove'], '</a></span>
+					</li>';
+		}
+
+		echo '
+				</ul>
+			</div>
+		</div>';
+	}
+
+	echo '
+		</div>
+	<br class="clear" />';
+}
+
+// Template for a user to edit/pick their subscriptions.
+function template_user_subscription()
+{
+	global $context, $txt, $scripturl, $modSettings;
+
+	echo '
+	<div id="paid_subscription">
+		<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=subscriptions;confirm" method="post">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['subscriptions'], '</h3>
+			</div>';
+
+	if (empty($context['subscriptions']))
+	{
+		echo '
+			<div class="information">
+				', $txt['paid_subs_none'], '
+			</div>';
+	}
+	else
+	{
+		echo '
+			<div class="information">
+				', $txt['paid_subs_desc'], '
+			</div>';
+
+		// Print out all the subscriptions.
+		$alternate = false;
+		foreach ($context['subscriptions'] as $id => $subscription)
+		{
+			$alternate = !$alternate;
+
+			// Ignore the inactive ones...
+			if (empty($subscription['active']))
+				continue;
+
+			echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $subscription['name'], '</h3>
+			</div>
+			<div class="windowbg', $alternate ? '' : '2', '">
+				<div class="content">
+					<p><strong>', $subscription['name'], '</strong></p>
+					<p class="smalltext">', $subscription['desc'], '</p>';
+
+			if (!$subscription['flexible'])
+				echo '
+					<div><strong>', $txt['paid_duration'], ':</strong> ', $subscription['length'], '</div>';
+
+			if ($context['user']['is_owner'])
+			{
+				echo '
+					<strong>', $txt['paid_cost'], ':</strong>';
+
+				if ($subscription['flexible'])
+				{
+					echo '
+					<select name="cur[', $subscription['id'], ']">';
+
+					// Print out the costs for this one.
+					foreach ($subscription['costs'] as $duration => $value)
+						echo '
+						<option value="', $duration, '">', sprintf($modSettings['paid_currency_symbol'], $value), '/', $txt[$duration], '</option>';
+
+					echo '
+					</select>';
+				}
+				else
+					echo '
+					', sprintf($modSettings['paid_currency_symbol'], $subscription['costs']['fixed']);
+
+				echo '
+					<hr class="hrcolor" />
+					<input type="submit" name="sub_id[', $subscription['id'], ']" value="', $txt['paid_order'], '" class="button_submit" />
+					<br class="clear_right" />';
+			}
+			else
+				echo '
+					<a href="', $scripturl, '?action=admin;area=paidsubscribe;sa=modifyuser;sid=', $subscription['id'], ';uid=', $context['member']['id'], (empty($context['current'][$subscription['id']]) ? '' : ';lid=' . $context['current'][$subscription['id']]['id']), '">', empty($context['current'][$subscription['id']]) ? $txt['paid_admin_add'] : $txt['paid_edit_subscription'], '</a>';
+
+			echo '
+				</div>
+			</div>';
+		}
+	}
+
+	echo '
+		</form>
+		<br class="clear"/>
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['paid_current'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['paid_current_desc'], '
+		</div>
+		<table width="100%" class="table_grid">
+			<thead>
+				<tr class="catbg">
+					<th class="first_th" width="30%">', $txt['paid_name'], '</th>
+					<th align="center">', $txt['paid_status'], '</th>
+					<th align="center">', $txt['start_date'], '</th>
+					<th class="last_th" align="center">', $txt['end_date'], '</th>
+				</tr>
+			</thead>
+			<tbody>';
+
+	if (empty($context['current']))
+		echo '
+				<tr class="windowbg">
+					<td align="center" colspan="4">
+						', $txt['paid_none_yet'], '
+					</td>
+				</tr>';
+
+	$alternate = false;
+	foreach ($context['current'] as $sub)
+	{
+		$alternate = !$alternate;
+
+		if (!$sub['hide'])
+			echo '
+				<tr class="windowbg', $alternate ? '' : '2', '">
+					<td>
+						', (allowedTo('admin_forum') ? '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modifyuser;lid=' . $sub['id'] . '">' . $sub['name'] . '</a>' : $sub['name']), '
+					</td><td>
+						<span style="color: ', ($sub['status'] == 2 ? 'green' : ($sub['status'] == 1 ? 'red' : 'orange')), '"><strong>', $sub['status_text'], '</strong></span>
+					</td><td>
+						', $sub['start'], '
+					</td><td>
+						', $sub['end'], '
+					</td>
+				</tr>';
+	}
+	echo '
+			</tbody>
+		</table>
+	</div>
+	<br class="clear" />';
+}
+
+// The "choose payment" dialog.
+function template_choose_payment()
+{
+	global $context, $txt, $modSettings, $scripturl;
+
+	echo '
+	<div id="paid_subscription">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['paid_confirm_payment'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['paid_confirm_desc'], '
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">
+					<dt>
+						<strong>', $txt['subscription'], ':</strong>
+					</dt>
+					<dd>
+						', $context['sub']['name'], '
+					</dd>
+					<dt>
+						<strong>', $txt['paid_cost'], ':</strong>
+					</dt>
+					<dd>
+						', $context['cost'], '
+					</dd>
+				</dl>
+			</div>
+		</div>';
+
+	// Do all the gateway options.
+	foreach ($context['gateways'] as $gateway)
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $gateway['title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				', $gateway['desc'], '<br />
+					<form action="', $gateway['form'], '" method="post">';
+
+		if (!empty($gateway['javascript']))
+			echo '
+						<script type="text/javascript"><!-- // --><![CDATA[
+							', $gateway['javascript'], '
+						// ]]></script>';
+
+		foreach ($gateway['hidden'] as $name => $value)
+			echo '
+						<input type="hidden" id="', $gateway['id'], '_', $name, '" name="', $name, '" value="', $value, '" />';
+
+		echo '
+						<br /><input type="submit" value="', $gateway['submit'], '" class="button_submit" />
+					</form>
+			</div>
+		</div>';
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+// The "thank you" bit...
+function template_paid_done()
+{
+	global $context, $txt, $modSettings, $scripturl;
+
+	echo '
+	<div id="paid_subscription">
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['paid_done'], '</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<p>', $txt['paid_done_desc'], '</p>
+				<br />
+				<a href="', $scripturl, '?action=profile;u=', $context['member']['id'], ';area=subscriptions">', $txt['paid_sub_return'], '</a>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 1177 - 1187
Themes/default/ManagePermissions.template.php

@@ -1,1188 +1,1178 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_permission_index()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Not allowed to edit?
-	if (!$context['can_modify'])
-		echo '
-	<div class="errorbox">
-		', sprintf($txt['permission_cannot_edit'], $scripturl . '?action=admin;area=permissions;sa=profiles'), '
-	</div>';
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=permissions;sa=quick" method="post" accept-charset="', $context['character_set'], '" name="permissionForm" id="permissionForm">';
-
-		if (!empty($context['profile']))
-			echo '
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['permissions_for_profile'], ': &quot;', $context['profile']['name'], '&quot;</h3>
-			</div>';
-
-		echo '
-			<table width="100%" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th">', $txt['membergroups_name'], '</th>
-						<th width="10%" align="center" valign="middle">', $txt['membergroups_members_top'], '</th>';
-
-			if (empty($modSettings['permission_enable_deny']))
-				echo '
-						<th width="16%" align="center">', $txt['membergroups_permissions'], '</th>';
-			else
-				echo '
-						<th width="8%" align="center">', $txt['permissions_allowed'], '</th>
-						<th width="8%" align="center">', $txt['permissions_denied'], '</th>';
-
-			echo '
-						<th width="10%" align="center" valign="middle">', $context['can_modify'] ? $txt['permissions_modify'] : $txt['permissions_view'], '</th>
-						<th class="last_th" width="4%" align="center" valign="middle">
-							', $context['can_modify'] ? '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form, \'group\');" />' : '', '
-						</th>
-					</tr>
-				</thead>
-				<tbody>';
-
-	$alternate = false;
-	foreach ($context['groups'] as $group)
-	{
-		$alternate = !$alternate;
-		echo '
-					<tr class="windowbg', $alternate ? '2' : '', '">
-						<td>
-							', $group['name'], $group['id'] == -1 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_guests" onclick="return reqWin(this.href);">?</a>)' : ($group['id'] == 0 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_regular_members" onclick="return reqWin(this.href);">?</a>)' : ($group['id'] == 1 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_administrator" onclick="return reqWin(this.href);">?</a>)' : ($group['id'] == 3 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_moderator" onclick="return reqWin(this.href);">?</a>)' : '')));
-
-		if (!empty($group['children']))
-			echo '
-							<br /><span class="smalltext">', $txt['permissions_includes_inherited'], ': &quot;', implode('&quot;, &quot;', $group['children']), '&quot;</span>';
-
-		echo '
-						</td>
-						<td align="center">', $group['can_search'] ? $group['link'] : $group['num_members'], '</td>';
-
-		if (empty($modSettings['permission_enable_deny']))
-			echo '
-						<td width="16%" align="center">', $group['num_permissions']['allowed'], '</td>';
-		else
-			echo '
-						<td width="8%" align="center"', $group['id'] == 1 ? ' style="font-style: italic;"' : '', '>', $group['num_permissions']['allowed'], '</td>
-						<td width="8%" align="center"', $group['id'] == 1 || $group['id'] == -1 ? ' style="font-style: italic;"' : (!empty($group['num_permissions']['denied']) ? ' style="color: red;"' : ''), '>', $group['num_permissions']['denied'], '</td>';
-
-		echo '
-						<td align="center">', $group['allow_modify'] ? '<a href="' . $scripturl . '?action=admin;area=permissions;sa=modify;group=' . $group['id'] . (empty($context['profile']) ? '' : ';pid=' . $context['profile']['id']) . '">' . ($context['can_modify'] ? $txt['permissions_modify'] : $txt['permissions_view']). '</a>' : '', '</td>
-						<td align="center">', $group['allow_modify'] && $context['can_modify'] ? '<input type="checkbox" name="group[]" value="' . $group['id'] . '" class="input_check" />' : '', '</td>
-					</tr>';
-	}
-
-	echo '
-				</tbody>
-			</table>
-			<br />';
-
-	// Advanced stuff...
-	if ($context['can_modify'])
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<img id="permissions_panel_toggle" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png"  alt="*" />
-					<a href="#" id="permissions_panel_link">', $txt['permissions_advanced_options'], '</a>
-				</h3>
-			</div>
-			<div id="permissions_panel_advanced" class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<fieldset>
-						<legend>', $txt['permissions_with_selection'], '</legend>
-						<dl class="settings admin_permissions">
-							<dt>
-								', $txt['permissions_apply_pre_defined'], ' <a href="', $scripturl, '?action=helpadmin;help=permissions_quickgroups" onclick="return reqWin(this.href);">(?)</a>:
-							</dt>
-							<dd>
-								<select name="predefined">
-									<option value="">(', $txt['permissions_select_pre_defined'], ')</option>
-									<option value="restrict">', $txt['permitgroups_restrict'], '</option>
-									<option value="standard">', $txt['permitgroups_standard'], '</option>
-									<option value="moderator">', $txt['permitgroups_moderator'], '</option>
-									<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
-								</select>
-							</dd>
-							<dt>
-								', $txt['permissions_like_group'], ':
-							</dt>
-							<dd>
-								<select name="copy_from">
-									<option value="empty">(', $txt['permissions_select_membergroup'], ')</option>';
-		foreach ($context['groups'] as $group)
-		{
-			if ($group['id'] != 1)
-				echo '
-									<option value="', $group['id'], '">', $group['name'], '</option>';
-		}
-
-		echo '
-								</select>
-							</dd>
-							<dt>
-								<select name="add_remove">
-									<option value="add">', $txt['permissions_add'], '...</option>
-									<option value="clear">', $txt['permissions_remove'], '...</option>';
-		if (!empty($modSettings['permission_enable_deny']))
-			echo '
-									<option value="deny">', $txt['permissions_deny'], '...</option>';
-		echo '
-								</select>
-							</dt>
-							<dd style="overflow:auto;">
-								<select name="permissions">
-									<option value="">(', $txt['permissions_select_permission'], ')</option>';
-		foreach ($context['permissions'] as $permissionType)
-		{
-			if ($permissionType['id'] == 'membergroup' && !empty($context['profile']))
-				continue;
-
-			foreach ($permissionType['columns'] as $column)
-			{
-				foreach ($column as $permissionGroup)
-				{
-					if ($permissionGroup['hidden'])
-						continue;
-
-					echo '
-									<option value="" disabled="disabled">[', $permissionGroup['name'], ']</option>';
-					foreach ($permissionGroup['permissions'] as $perm)
-					{
-						if ($perm['hidden'])
-							continue;
-
-						if ($perm['has_own_any'])
-							echo '
-									<option value="', $permissionType['id'], '/', $perm['own']['id'], '">&nbsp;&nbsp;&nbsp;', $perm['name'], ' (', $perm['own']['name'], ')</option>
-									<option value="', $permissionType['id'], '/', $perm['any']['id'], '">&nbsp;&nbsp;&nbsp;', $perm['name'], ' (', $perm['any']['name'], ')</option>';
-						else
-							echo '
-									<option value="', $permissionType['id'], '/', $perm['id'], '">&nbsp;&nbsp;&nbsp;', $perm['name'], '</option>';
-					}
-				}
-			}
-		}
-		echo '
-								</select>
-							</dd>
-						</dl>
-					</fieldset>
-					<input type="submit" value="', $txt['permissions_set_permissions'], '" onclick="return checkSubmit();" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-		// Javascript for the advanced stuff.
-		echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oPermissionsPanelToggle = new smc_Toggle({
-			bToggleEnabled: true,
-			bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
-			aSwappableContainers: [
-				\'permissions_panel_advanced\'
-			],
-			aSwapImages: [
-				{
-					sId: \'permissions_panel_toggle\',
-					srcExpanded: smf_images_url + \'/collapse.png\',
-					altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
-					srcCollapsed: smf_images_url + \'/expand.png\',
-					altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
-				}
-			],
-			aSwapLinks: [
-				{
-					sId: \'permissions_panel_link\',
-					msgExpanded: ', JavaScriptEscape($txt['advanced']), ',
-					msgCollapsed: ', JavaScriptEscape($txt['advanced']), '
-				}
-			],
-			oThemeOptions: {
-				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
-				sOptionName: \'admin_preferences\',
-				sSessionVar: smf_session_var,
-				sSessionId: smf_session_id,
-				sThemeId: \'1\',
-				sAdditionalVars: \';admin_key=app\'
-			}
-		});';
-
-		echo '
-
-		function checkSubmit()
-		{
-			if ((document.forms.permissionForm.predefined.value != "" && (document.forms.permissionForm.copy_from.value != "empty" || document.forms.permissionForm.permissions.value != "")) || (document.forms.permissionForm.copy_from.value != "empty" && document.forms.permissionForm.permissions.value != ""))
-			{
-				alert("', $txt['permissions_only_one_option'], '");
-				return false;
-			}
-			if (document.forms.permissionForm.predefined.value == "" && document.forms.permissionForm.copy_from.value == "" && document.forms.permissionForm.permissions.value == "")
-			{
-				alert("', $txt['permissions_no_action'], '");
-				return false;
-			}
-			if (document.forms.permissionForm.permissions.value != "" && document.forms.permissionForm.add_remove.value == "deny")
-				return confirm("', $txt['permissions_deny_dangerous'], '");
-
-			return true;
-		}
-	// ]]></script>';
-
-		if (!empty($context['profile']))
-			echo '
-			<input type="hidden" name="pid" value="', $context['profile']['id'], '" />';
-
-		echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-mpq_token_var'], '" value="', $context['admin-mpq_token'], '" />';
-	}
-	else
-		echo '
-			</table>';
-
-	echo '
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_by_board()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<form id="admincenter" action="', $scripturl, '?action=admin;area=permissions;sa=board" method="post" accept-charset="', $context['character_set'], '">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['permissions_boards'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['permissions_boards_desc'], '
-		</div>
-		<div class="title_bar">
-			<h3 id="board_permissions" class="titlebg flow_hidden">
-				<span class="perm_name floatleft">', $txt['board_name'], '</span>
-				<span class="perm_profile floatleft">', $txt['permission_profile'], '</span>
-			</h3>
-		</div>';
-
-	if (!$context['edit_all'])
-		echo '
-			<div class="content">
-			<a class="button_link" href="', $scripturl, '?action=admin;area=permissions;sa=board;edit;', $context['session_var'], '=', $context['session_id'], '">', $txt['permissions_board_all'], '</a>
-			<br class="clear_right" />
-			</div>';
-
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg"><strong>', $category['name'], '</strong></h3>
-		</div>';
-
-		if (!empty($category['boards']))
-			echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<ul class="perm_boards flow_hidden">';
-
-		$alternate = false;
-
-		foreach ($category['boards'] as $board)
-		{
-			$alternate = !$alternate;
-
-			echo '
-
-					<li class="flow_hidden' ,' windowbg', $alternate ? '' : '2','">
-						<span class="perm_board floatleft">
-							<a href="', $scripturl, '?action=admin;area=manageboards;sa=board;boardid=', $board['id'], ';rid=permissions;', $context['session_var'], '=', $context['session_id'], '">', str_repeat('-', $board['child_level']), ' ', $board['name'], '</a>
-						</span>
-						<span class="perm_boardprofile floatleft">';
-			if ($context['edit_all'])
-			{
-				echo '
-							<select name="boardprofile[', $board['id'], ']">';
-
-				foreach ($context['profiles'] as $id => $profile)
-					echo '
-								<option value="', $id, '" ', $id == $board['profile'] ? 'selected="selected"' : '', '>', $profile['name'], '</option>';
-
-				echo '
-							</select>';
-			}
-			else
-				echo '
-							<a href="', $scripturl, '?action=admin;area=permissions;sa=index;pid=', $board['profile'], ';', $context['session_var'], '=', $context['session_id'], '"> [', $board['profile_name'], ']</a>';
-
-			echo '
-						</span>
-					</li>';
-		}
-
-		if (!empty($category['boards']))
-			echo '
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-		<div class="content">';
-
-	if ($context['edit_all'])
-		echo '
-			<input type="submit" name="save_changes" value="', $txt['save'], '" class="button_submit" />';
-	else
-		echo '
-			
-			<a class="button_link" href="', $scripturl, '?action=admin;area=permissions;sa=board;edit;', $context['session_var'], '=', $context['session_id'], '">', $txt['permissions_board_all'], '</a>';
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-mpb_token_var'], '" value="', $context['admin-mpb_token'], '" />
-		</div>
-	</form>
-	<br class="clear" />';
-}
-
-// Edit permission profiles (predefined).
-function template_edit_profiles()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=permissions;sa=profiles" method="post" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['permissions_profile_edit'], '</h3>
-			</div>
-
-			<table width="100%" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th">', $txt['permissions_profile_name'], '</th>
-						<th>', $txt['permissions_profile_used_by'], '</th>
-						<th class="last_th" width="5%">', $txt['delete'], '</th>
-					</tr>
-				</thead>
-				<tbody>';
-	$alternate = false;
-	foreach ($context['profiles'] as $profile)
-	{
-		echo '
-					<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
-						<td>';
-
-		if (!empty($context['show_rename_boxes']) && $profile['can_edit'])
-			echo '
-							<input type="text" name="rename_profile[', $profile['id'], ']" value="', $profile['name'], '" class="input_text" />';
-		else
-			echo '
-							<a href="', $scripturl, '?action=admin;area=permissions;sa=index;pid=', $profile['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $profile['name'], '</a>';
-
-		echo '
-						</td>
-						<td>
-							', !empty($profile['boards_text']) ? $profile['boards_text'] : $txt['permissions_profile_used_by_none'], '
-						</td>
-						<td align="center">
-							<input type="checkbox" name="delete_profile[]" value="', $profile['id'], '" ', $profile['can_delete'] ? '' : 'disabled="disabled"', ' class="input_check" />
-						</td>
-					</tr>';
-		$alternate = !$alternate;
-	}
-
-	echo '
-				</tbody>
-			</table>
-			<div class="righttext padding">
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="hidden" name="', $context['admin-mpp_token_var'], '" value="', $context['admin-mpp_token'], '" />';
-
-	if ($context['can_edit_something'])
-		echo '
-				<input type="submit" name="rename" value="', empty($context['show_rename_boxes']) ? $txt['permissions_profile_rename'] : $txt['permissions_commit'], '" class="button_submit" />';
-
-	echo '
-				<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" class="button_submit" />
-				<br class="clear" />
-			</div>
-		</form>
-		<br />
-		<form action="', $scripturl, '?action=admin;area=permissions;sa=profiles" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['permissions_profile_new'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['permissions_profile_name'], ':</strong>
-						</dt>
-						<dd>
-							<input type="text" name="profile_name" value="" class="input_text" />
-						</dd>
-						<dt>
-							<strong>', $txt['permissions_profile_copy_from'], ':</strong>
-						</dt>
-						<dd>
-							<select name="copy_from">';
-
-	foreach ($context['profiles'] as $id => $profile)
-		echo '
-								<option value="', $id, '">', $profile['name'], '</option>';
-
-	echo '
-							</select>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-mpp_token_var'], '" value="', $context['admin-mpp_token'], '" />
-					<input type="submit" name="create" value="', $txt['permissions_profile_new_create'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_modify_group()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Cannot be edited?
-	if (!$context['profile']['can_modify'])
-	{
-		echo '
-		<div class="errorbox">
-			', sprintf($txt['permission_cannot_edit'], $scripturl . '?action=admin;area=permissions;sa=profiles'), '
-		</div>';
-	}
-	else
-	{
-		echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			window.smf_usedDeny = false;
-
-			function warnAboutDeny()
-			{
-				if (window.smf_usedDeny)
-					return confirm("', $txt['permissions_deny_dangerous'], '");
-				else
-					return true;
-			}
-		// ]]></script>';
-	}
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=permissions;sa=modify2;group=', $context['group']['id'], ';pid=', $context['profile']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="permissionForm" id="permissionForm" onsubmit="return warnAboutDeny();">';
-
-	if (!empty($modSettings['permission_enable_deny']) && $context['group']['id'] != -1)
-		echo '
-			<div class="information">
-				', $txt['permissions_option_desc'], '
-			</div>';
-
-	echo '
-			<div class="cat_bar">
-				<h3 class="catbg">';
-	if ($context['permission_type'] == 'board')
-		echo '
-				', $txt['permissions_local_for'], ' &quot;', $context['group']['name'], '&quot; ', $txt['permissions_on'], ' &quot;', $context['profile']['name'], '&quot;';
-	else
-		echo '
-				', $context['permission_type'] == 'membergroup' ? $txt['permissions_general'] : $txt['permissions_board'], ' - &quot;', $context['group']['name'], '&quot;';
-	echo '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					', $txt['permissions_change_view'], ': ', ($context['view_type'] == 'simple' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*" />' : ''), '<a href="', $scripturl, '?action=admin;area=permissions;sa=modify;group=', $context['group']['id'], ($context['permission_type'] == 'board' ? ';pid=' . $context['profile']['id'] : ''), ';view=simple">', $txt['permissions_view_simple'], '</a> |
-					', ($context['view_type'] == 'classic' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*" />' : ''), '<a href="', $scripturl, '?action=admin;area=permissions;sa=modify;group=', $context['group']['id'], ($context['permission_type'] == 'board' ? ';pid=' . $context['profile']['id'] : ''), ';view=classic">', $txt['permissions_view_classic'], '</a>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<div class="flow_hidden">';
-
-	// Draw out the main bits.
-	if ($context['view_type'] == 'simple')
-		template_modify_group_simple($context['permission_type']);
-	else
-		template_modify_group_classic($context['permission_type']);
-
-	// If this is general permissions also show the default profile.
-	if ($context['permission_type'] == 'membergroup')
-	{
-		echo '
-			</div>
-			<br />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['permissions_board'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['permissions_board_desc'], '
-			</div>
-			<div class="flow_hidden">';
-
-		if ($context['view_type'] == 'simple')
-			template_modify_group_simple('board');
-		else
-			template_modify_group_classic('board');
-
-	}
-	echo '
-		</div>';
-
-	if ($context['profile']['can_modify'])
-		echo '
-			<div class="righttext padding">
-				<input type="submit" value="', $txt['permissions_commit'], '" class="button_submit" />
-			</div>';
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-mp_token_var'], '" value="', $context['admin-mp_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-
-}
-
-// A javascript enabled clean permissions view.
-function template_modify_group_simple($type)
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Simple only has one column so we only need bother ourself with that one.
-	$permission_data = &$context['permissions'][$type]['columns'][0];
-
-	// Short cut for disabling fields we can't change.
-	$disable_field = $context['profile']['can_modify'] ? '' : 'disabled="disabled" ';
-
-	echo '
-			<table width="100%" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th colspan="2" width="100%" align="left" class="first_th"></th>';
-				if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-					echo '
-						<th colspan="3" width="9" class="last_th">&nbsp;</th>';
-				else
-					echo '
-						<th>', $txt['permissions_option_on'], '</th>
-						<th>', $txt['permissions_option_off'], '</th>
-						<th class="last_th">', $txt['permissions_option_deny'], '</th>';
-					echo '
-					</tr>
-				</thead>
-				<tbody>';
-
-	foreach ($permission_data as $id_group => $permissionGroup)
-	{
-		if (empty($permissionGroup['permissions']))
-			continue;
-
-		// Are we likely to have something in this group to display or is it all hidden?
-		$has_display_content = false;
-		if (!$permissionGroup['hidden'])
-		{
-			// Before we go any further check we are going to have some data to print otherwise we just have a silly heading.
-			foreach ($permissionGroup['permissions'] as $permission)
-				if (!$permission['hidden'])
-					$has_display_content = true;
-
-			if ($has_display_content)
-			{
-				echo '
-					<tr class="windowbg">
-						<td colspan="2" width="100%" align="left">
-							<a href="#" onclick="return toggleBreakdown(\'', $id_group, '\');">
-								<img src="', $settings['images_url'], '/selected_open.png" id="group_toggle_img_', $id_group, '" alt="*" />&nbsp;<strong>', $permissionGroup['name'], '</strong>
-							</a>
-						</td>';
-				if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-					echo '
-						<td colspan="3" width="10">
-							<div id="group_select_div_', $id_group, '">
-								<input type="checkbox" id="group_select_', $id_group, '" name="group_select_', $id_group, '" class="input_check" onclick="determineGroupState(\'', $id_group, '\', this.checked ? \'on\' : \'off\');" style="display: none;" ', $disable_field, '/>
-							</div>
-						</td>';
-				else
-					echo '
-						<td align="center">
-							<div id="group_select_div_on_', $id_group, '">
-								<input type="radio" id="group_select_on_', $id_group, '" name="group_select_', $id_group, '" value="on" onclick="determineGroupState(\'', $id_group, '\', \'on\');" style="display: none;" ', $disable_field, ' class="input_radio" />
-							</div>
-						</td>
-						<td align="center">
-							<div id="group_select_div_off_', $id_group, '">
-								<input type="radio" id="group_select_off_', $id_group, '" name="group_select_', $id_group, '" value="off" onclick="determineGroupState(\'', $id_group, '\', \'off\');" style="display: none;" ', $disable_field, ' class="input_radio" />
-							</div>
-						</td>
-						<td align="center">
-							<div id="group_select_div_deny_', $id_group, '">
-								<input type="radio" id="group_select_deny_', $id_group, '" name="group_select_', $id_group, '" value="deny" onclick="determineGroupState(\'', $id_group, '\', \'deny\');" style="display: none;" ', $disable_field, ' class="input_radio" />
-							</div>
-						</td>';
-					echo '
-					</tr>';
-			}
-		}
-
-		$alternate = false;
-		foreach ($permissionGroup['permissions'] as $permission)
-		{
-			// If it's hidden keep the last value.
-			if ($permission['hidden'] || $permissionGroup['hidden'])
-			{
-				echo '
-					<tr style="display: none;">
-						<td>
-							<input type="hidden" name="perm[', $type, '][', $permission['id'], ']" value="', $permission['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['select'], '" />
-						</td>
-					</tr>';
-			}
-			else
-			{
-				echo '
-					<tr id="perm_div_', $id_group, '_', $permission['id'], '" class="', $alternate ? 'windowbg' : 'windowbg2', '">
-						<td valign="top" width="10" style="padding-right: 1ex;">
-							', $permission['help_index'] ? '<a href="' . $scripturl . '?action=helpadmin;help=' . $permission['help_index'] . '" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '" /></a>' : '', '
-						</td>
-						<td valign="top" width="100%" align="left" style="padding-bottom: 2px;">', $permission['name'], '</td>';
-
-					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-						echo '
-						<td valign="top" style="padding-bottom: 2px;"><input type="checkbox" id="select_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' onclick="determineGroupState(\'', $id_group, '\');" value="on" class="input_check" ', $disable_field, '/></td>';
-					else
-						echo '
-						<td valign="top" width="10" style="padding-bottom: 2px;"><input type="radio" id="select_on_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" onclick="determineGroupState(\'', $id_group, '\');" class="input_radio" ', $disable_field, '/></td>
-						<td valign="top" width="10" style="padding-bottom: 2px;"><input type="radio" id="select_off_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'off' ? ' checked="checked"' : '', ' value="off" onclick="determineGroupState(\'', $id_group, '\');" class="input_radio" ', $disable_field, '/></td>
-						<td valign="top" width="10" style="padding-bottom: 2px;"><input type="radio" id="select_deny_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'denied' ? ' checked="checked"' : '', ' value="deny" onclick="window.smf_usedDeny = true; determineGroupState(\'', $id_group, '\');" class="input_radio" ', $disable_field, '/></td>';
-
-					echo '
-					</tr>';
-			}
-				$alternate = !$alternate;
-		}
-
-		if (!$permissionGroup['hidden'] && $has_display_content)
-			echo '
-					<tr id="group_hr_div_', $id_group, '" class="windowbg2 perm_groups">
-						<td colspan="5" width="100%"></td>
-					</tr>';
-	}
-	echo '
-				</tbody>
-			</table>
-	<script type="text/javascript"><!-- // --><![CDATA[';
-
-	if ($context['profile']['can_modify'] && empty($context['simple_javascript_displayed']))
-	{
-		// Only show this once.
-		$context['simple_javascript_displayed'] = true;
-
-		// This function decides what to do when ANYTHING is touched!
-		echo '
-		var groupPermissions = new Array();
-		function determineGroupState(id_group, forceState)
-		{
-			if (typeof(forceState) != "undefined")
-				thisState = forceState;
-
-			// Cycle through this groups elements.
-			var curState = false, thisState;
-			for (var i = 0; i < groupPermissions[id_group].length; i++)
-			{';
-
-		if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-			echo '
-				if (typeof(forceState) != "undefined")
-				{
-					document.getElementById(\'select_\' + groupPermissions[id_group][i]).checked = forceState == \'on\' ? 1 : 0;
-				}
-
-				thisState = document.getElementById(\'select_\' + groupPermissions[id_group][i]).checked ? \'on\' : \'off\';';
-		else
-			echo '
-				if (typeof(forceState) != "undefined")
-				{
-					document.getElementById(\'select_on_\' + groupPermissions[id_group][i]).checked = forceState == \'on\' ? 1 : 0;
-					document.getElementById(\'select_off_\' + groupPermissions[id_group][i]).checked = forceState == \'off\' ? 1 : 0;
-					document.getElementById(\'select_deny_\' + groupPermissions[id_group][i]).checked = forceState == \'deny\' ? 1 : 0;
-				}
-
-				if (document.getElementById(\'select_on_\' + groupPermissions[id_group][i]).checked)
-					thisState = \'on\';
-				else if (document.getElementById(\'select_off_\' + groupPermissions[id_group][i]).checked)
-					thisState = \'off\';
-				else
-					thisState = \'deny\';';
-
-		echo '
-				// Unless this is the first element, or it\'s the same state as the last we\'re buggered.
-				if (curState == false || thisState == curState)
-				{
-					curState = thisState;
-				}
-				else
-				{
-					curState = \'fudged\';
-					i = 999;
-				}
-			}
-
-			// First check the right master is selected!';
-		if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-			echo '
-			document.getElementById("group_select_" + id_group).checked = curState == \'on\' ? 1 : 0;';
-		else
-			echo '
-			document.getElementById("group_select_on_" + id_group).checked = curState == \'on\' ? 1 : 0;
-			document.getElementById("group_select_off_" + id_group).checked = curState == \'off\' ? 1 : 0;
-			document.getElementById("group_select_deny_" + id_group).checked = curState == \'deny\' ? 1 : 0;';
-
-		// Force the display?
-		echo '
-			if (curState != \'fudged\')
-				toggleBreakdown(id_group, "none");';
-		echo '
-		}';
-	}
-
-	// Some more javascript to be displayed as long as we are editing.
-	if ($context['profile']['can_modify'])
-	{
-		foreach ($permission_data as $id_group => $permissionGroup)
-		{
-			if (empty($permissionGroup['permissions']))
-				continue;
-
-			// As before...
-			$has_display_content = false;
-			if (!$permissionGroup['hidden'])
-			{
-				// Make sure we can show it.
-				foreach ($permissionGroup['permissions'] as $permission)
-					if (!$permission['hidden'])
-						$has_display_content = true;
-
-				// Make all the group indicators visible on JS only.
-				if ($has_display_content)
-				{
-					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-						echo '
-			document.getElementById("group_select_div_', $id_group, '").parentNode.className = "lockedbg";
-			document.getElementById("group_select_', $id_group, '").style.display = "";';
-					else
-						echo '
-			document.getElementById("group_select_div_on_', $id_group, '").parentNode.className = "lockedbg";
-			document.getElementById("group_select_div_off_', $id_group, '").parentNode.className = "lockedbg";
-			document.getElementById("group_select_div_deny_', $id_group, '").parentNode.className = "lockedbg";
-			document.getElementById("group_select_on_', $id_group, '").style.display = "";
-			document.getElementById("group_select_off_', $id_group, '").style.display = "";
-			document.getElementById("group_select_deny_', $id_group, '").style.display = "";';
-				}
-
-				$perm_ids = array();
-				$count = 0;
-				foreach ($permissionGroup['permissions'] as $permission)
-				{
-					if (!$permission['hidden'])
-					{
-						// Need this for knowing what can be tweaked.
-						$perm_ids[] = "'$permission[id]'";
-					}
-				}
-				// Declare this groups permissions into an array.
-				if (!empty($perm_ids))
-					echo '
-			groupPermissions[\'', $id_group, '\'] = new Array(', count($perm_ids), ');';
-				foreach ($perm_ids as $count => $id)
-					echo '
-			groupPermissions[\'', $id_group, '\'][', $count, '] = ', $id, ';';
-
-				// Show the group as required.
-				if ($has_display_content)
-				echo '
-			determineGroupState(\'', $id_group, '\');';
-			}
-		}
-	}
-
-	echo '
-		// ]]></script>';
-}
-
-// The SMF 1.x way of looking at permissions.
-function template_modify_group_classic($type)
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	$permission_type = &$context['permissions'][$type];
-	$disable_field = $context['profile']['can_modify'] ? '' : 'disabled="disabled" ';
-
-	echo '
-				<div class="windowbg2">
-					<span class="topslice"><span></span></span>
-					<div class="content">';
-
-	foreach ($permission_type['columns'] as $column)
-	{
-		echo '
-						<table width="49%" class="table_grid perm_classic floatleft">';
-
-		foreach ($column as $permissionGroup)
-		{
-			if (empty($permissionGroup['permissions']))
-				continue;
-
-			// Are we likely to have something in this group to display or is it all hidden?
-			$has_display_content = false;
-			if (!$permissionGroup['hidden'])
-			{
-				// Before we go any further check we are going to have some data to print otherwise we just have a silly heading.
-				foreach ($permissionGroup['permissions'] as $permission)
-					if (!$permission['hidden'])
-						$has_display_content = true;
-
-				if ($has_display_content)
-				{
-					echo '
-							<tr class="catbg">
-								<th colspan="2" width="100%" align="left"><strong class="smalltext">', $permissionGroup['name'], '</strong></th>';
-					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-						echo '
-								<th colspan="3" width="10"></th>';
-					else
-						echo '
-								<th align="center"><div>', $txt['permissions_option_on'], '</div></th>
-								<th align="center"><div>', $txt['permissions_option_off'], '</div></th>
-								<th align="center"><div>', $txt['permissions_option_deny'], '</div></th>';
-					echo '
-							</tr>';
-				}
-			}
-
-			$alternate = false;
-			foreach ($permissionGroup['permissions'] as $permission)
-			{
-				// If it's hidden keep the last value.
-				if ($permission['hidden'] || $permissionGroup['hidden'])
-				{
-					echo '
-							<tr style="display: none;">
-								<td>';
-
-					if ($permission['has_own_any'])
-					{
-						// Guests can't have own permissions.
-						if ($context['group']['id'] != -1)
-							echo '
-									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']" value="', $permission['own']['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['own']['select'], '" />';
-
-						echo '
-									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']" value="', $permission['any']['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['any']['select'], '" />';
-					}
-					else
-						echo '
-									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['id'], ']" value="', $permission['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['select'], '" />';
-					echo '
-								</td>
-							</tr>';
-				}
-				else
-				{
-					echo '
-							<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
-								<td width="10">
-									', $permission['show_help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=permissionhelp_' . $permission['id'] . '" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '" /></a>' : '', '
-								</td>';
-
-					if ($permission['has_own_any'])
-					{
-						echo '
-								<td colspan="4" width="100%" align="left">', $permission['name'], '</td>
-							</tr><tr class="', $alternate ? 'windowbg' : 'windowbg2', '">';
-
-						// Guests can't do their own thing.
-						if ($context['group']['id'] != -1)
-						{
-							echo '
-								<td></td>
-								<td width="100%" class="smalltext" align="right">', $permission['own']['name'], ':</td>';
-
-							if (empty($modSettings['permission_enable_deny']))
-								echo '
-								<td colspan="3"><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_check" ', $disable_field, '/></td>';
-							else
-								echo '
-								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_radio" ', $disable_field, '/></td>
-								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'off' ? ' checked="checked"' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
-								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'denied' ? ' checked="checked"' : '', ' value="deny" class="input_radio" ', $disable_field, '/></td>';
-
-							echo '
-							</tr><tr class="', $alternate ? 'windowbg' : 'windowbg2', '">';
-						}
-
-						echo '
-								<td></td>
-								<td width="100%" class="smalltext" align="right">', $permission['any']['name'], ':</td>';
-
-						if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-							echo '
-								<td colspan="3"><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_check" ', $disable_field, '/></td>';
-						else
-							echo '
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" onclick="document.forms.permissionForm.', $permission['own']['id'], '_on.checked = true;" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'off' ? ' checked="checked"' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select']== 'denied' ? ' checked="checked"' : '', ' value="deny" id="', $permission['any']['id'], '_deny" onclick="window.smf_usedDeny = true;" class="input_radio" ', $disable_field, '/></td>';
-
-						echo '
-							</tr>';
-					}
-					else
-					{
-						echo '
-								<td width="100%" align="left">', $permission['name'], '</td>';
-
-						if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
-							echo '
-								<td><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_check" ', $disable_field, '/></td>';
-						else
-							echo '
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'off' ? ' checked="checked"' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'denied' ? ' checked="checked"' : '', ' value="deny" onclick="window.smf_usedDeny = true;" class="input_radio" ', $disable_field, '/></td>';
-
-						echo '
-							</tr>';
-					}
-				}
-				$alternate = !$alternate;
-			}
-
-			if (!$permissionGroup['hidden'] && $has_display_content)
-				echo '
-							<tr class="windowbg2">
-								<td colspan="5" width="100%"><!--separator--></td>
-							</tr>';
-		}
-	echo '
-						</table>';
-	}
-	echo '
-				<br class="clear" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-}
-
-function template_inline_permissions()
-{
-	global $context, $settings, $options, $txt, $modSettings;
-
-	echo '
-		<fieldset id="', $context['current_permission'], '">
-			<legend><a href="javascript:void(0);" onclick="document.getElementById(\'', $context['current_permission'], '\').style.display = \'none\';document.getElementById(\'', $context['current_permission'], '_groups_link\').style.display = \'block\'; return false;">', $txt['avatar_select_permission'], '</a></legend>';
-	if (empty($modSettings['permission_enable_deny']))
-		echo '
-			<ul class="permission_groups">';
-	else
-		echo '
-			<div class="information">', $txt['permissions_option_desc'], '</div>
-			<dl class="settings">
-				<dt>
-					<span class="perms"><strong>', $txt['permissions_option_on'], '</strong></span>
-					<span class="perms"><strong>', $txt['permissions_option_off'], '</strong></span>
-					<span class="perms" style="color: red;"><strong>', $txt['permissions_option_deny'], '</strong></span>
-				</dt>
-				<dd>
-				</dd>';
-	foreach ($context['member_groups'] as $group)
-	{
-		if (!empty($modSettings['permission_enable_deny']))
-			echo '
-				<dt>';
-		else
-			echo '
-				<li>';
-
-		if (empty($modSettings['permission_enable_deny']))
-			echo '
-					<input type="checkbox" name="', $context['current_permission'], '[', $group['id'], ']" value="on"', $group['status'] == 'on' ? ' checked="checked"' : '', ' class="input_check" />';
-		else
-			echo '
-					<span class="perms"><input type="radio" name="', $context['current_permission'], '[', $group['id'], ']" value="on"', $group['status'] == 'on' ? ' checked="checked"' : '', ' class="input_radio" /></span>
-					<span class="perms"><input type="radio" name="', $context['current_permission'], '[', $group['id'], ']" value="off"', $group['status'] == 'off' ? ' checked="checked"' : '', ' class="input_radio" /></span>
-					<span class="perms"><input type="radio" name="', $context['current_permission'], '[', $group['id'], ']" value="deny"', $group['status'] == 'deny' ? ' checked="checked"' : '', ' class="input_radio" /></span>';
-
-		if (!empty($modSettings['permission_enable_deny']))
-			echo '
-				</dt>
-				<dd>
-					<span', $group['is_postgroup'] ? ' style="font-style: italic;"' : '', '>', $group['name'], '</span>
-				</dd>';
-		else
-			echo '
-					<span', $group['is_postgroup'] ? ' style="font-style: italic;"' : '', '>', $group['name'], '</span>
-				</li>';
-	}
-
-	if (empty($modSettings['permission_enable_deny']))
-		echo '
-			</ul>';
-	else
-		echo '
-			</dl>';
-
-	echo '
-		</fieldset>
-
-		<a href="javascript:void(0);" onclick="document.getElementById(\'', $context['current_permission'], '\').style.display = \'block\'; document.getElementById(\'', $context['current_permission'], '_groups_link\').style.display = \'none\'; return false;" id="', $context['current_permission'], '_groups_link" style="display: none;">[ ', $txt['avatar_select_permission'], ' ]</a>
-
-		<script type="text/javascript"><!-- // --><![CDATA[
-			document.getElementById("', $context['current_permission'], '").style.display = "none";
-			document.getElementById("', $context['current_permission'], '_groups_link").style.display = "";
-		// ]]></script>';
-}
-
-// Edit post moderation permissions.
-function template_postmod_permissions()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=permissions;sa=postmod;', $context['session_var'], '=', $context['session_id'], '" method="post" name="postmodForm" id="postmodForm" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['permissions_post_moderation'], '</h3>
-			</div>';
-
-	// Got advanced permissions - if so warn!
-	if (!empty($modSettings['permission_enable_deny']))
-		echo '
-				<div class="information">', $txt['permissions_post_moderation_deny_note'], '</div>';
-
-	echo '
-				<div class="righttext padding">
-					', $txt['permissions_post_moderation_select'], ':
-					<select name="pid" onchange="document.forms.postmodForm.submit();">';
-
-	foreach ($context['profiles'] as $profile)
-		if ($profile['can_modify'])
-			echo '
-						<option value="', $profile['id'], '" ', $profile['id'] == $context['current_profile'] ? 'selected="selected"' : '', '>', $profile['name'], '</option>';
-
-	echo '
-					</select>
-					<input type="submit" value="', $txt['go'], '" class="button_submit" />
-			</div>
-			<table width="100%" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th"></th>
-						<th align="center" colspan="3">
-							', $txt['permissions_post_moderation_new_topics'], '
-						</th>
-						<th align="center" colspan="3">
-							', $txt['permissions_post_moderation_replies_own'], '
-						</th>
-						<th align="center" colspan="3">
-							', $txt['permissions_post_moderation_replies_any'], '
-						</th>
-						<th class="last_th" align="center" colspan="3">
-							', $txt['permissions_post_moderation_attachments'], '
-						</th>
-					</tr>
-					<tr class="titlebg">
-						<th width="30%">
-							', $txt['permissions_post_moderation_group'], '
-						</th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
-						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
-					</tr>
-				</thead>
-				<tbody>';
-
-	foreach ($context['profile_groups'] as $group)
-	{
-		echo '
-					<tr>
-						<td width="40%" class="windowbg">
-							<span ', ($group['color'] ? 'style="color: ' . $group['color'] . '"' : ''), '>', $group['name'], '</span>';
-			if (!empty($group['children']))
-				echo '
-							<br /><span class="smalltext">', $txt['permissions_includes_inherited'], ': &quot;', implode('&quot;, &quot;', $group['children']), '&quot;</span>';
-
-			echo '
-						</td>
-						<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="allow" ', $group['new_topic'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="moderate" ', $group['new_topic'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="disallow" ', $group['new_topic'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="allow" ', $group['replies_own'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="moderate" ', $group['replies_own'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="disallow" ', $group['replies_own'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="allow" ', $group['replies_any'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="moderate" ', $group['replies_any'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="disallow" ', $group['replies_any'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="allow" ', $group['attachment'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="moderate" ', $group['attachment'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-						<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="disallow" ', $group['attachment'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
-					</tr>';
-	}
-
-	echo '
-				</tbody>
-			</table>
-			<div class="righttext padding">
-				<input type="submit" name="save_changes" value="', $txt['permissions_commit'], '" class="button_submit" />
-				<input type="hidden" name="', $context['admin-mppm_token_var'], '" value="', $context['admin-mppm_token'], '" />
-			</div>
-		</form>
-		<p class="smalltext" style="padding-left: 10px;">
-			<strong>', $txt['permissions_post_moderation_legend'], ':</strong><br />
-			<img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" /> - ', $txt['permissions_post_moderation_allow'], '<br />
-			<img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" /> - ', $txt['permissions_post_moderation_moderate'], '<br />
-			<img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" /> - ', $txt['permissions_post_moderation_disallow'], '
-		</p>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_permission_index()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Not allowed to edit?
+	if (!$context['can_modify'])
+		echo '
+	<div class="errorbox">
+		', sprintf($txt['permission_cannot_edit'], $scripturl . '?action=admin;area=permissions;sa=profiles'), '
+	</div>';
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=permissions;sa=quick" method="post" accept-charset="', $context['character_set'], '" name="permissionForm" id="permissionForm">';
+
+		if (!empty($context['profile']))
+			echo '
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['permissions_for_profile'], ': &quot;', $context['profile']['name'], '&quot;</h3>
+			</div>';
+
+		echo '
+			<table width="100%" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th">', $txt['membergroups_name'], '</th>
+						<th width="10%" align="center" valign="middle">', $txt['membergroups_members_top'], '</th>';
+
+			if (empty($modSettings['permission_enable_deny']))
+				echo '
+						<th width="16%" align="center">', $txt['membergroups_permissions'], '</th>';
+			else
+				echo '
+						<th width="8%" align="center">', $txt['permissions_allowed'], '</th>
+						<th width="8%" align="center">', $txt['permissions_denied'], '</th>';
+
+			echo '
+						<th width="10%" align="center" valign="middle">', $context['can_modify'] ? $txt['permissions_modify'] : $txt['permissions_view'], '</th>
+						<th class="last_th" width="4%" align="center" valign="middle">
+							', $context['can_modify'] ? '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form, \'group\');" />' : '', '
+						</th>
+					</tr>
+				</thead>
+				<tbody>';
+
+	$alternate = false;
+	foreach ($context['groups'] as $group)
+	{
+		$alternate = !$alternate;
+		echo '
+					<tr class="windowbg', $alternate ? '2' : '', '">
+						<td>
+							', $group['name'], $group['id'] == -1 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_guests" onclick="return reqWin(this.href);">?</a>)' : ($group['id'] == 0 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_regular_members" onclick="return reqWin(this.href);">?</a>)' : ($group['id'] == 1 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_administrator" onclick="return reqWin(this.href);">?</a>)' : ($group['id'] == 3 ? ' (<a href="' . $scripturl . '?action=helpadmin;help=membergroup_moderator" onclick="return reqWin(this.href);">?</a>)' : '')));
+
+		if (!empty($group['children']))
+			echo '
+							<br /><span class="smalltext">', $txt['permissions_includes_inherited'], ': &quot;', implode('&quot;, &quot;', $group['children']), '&quot;</span>';
+
+		echo '
+						</td>
+						<td align="center">', $group['can_search'] ? $group['link'] : $group['num_members'], '</td>';
+
+		if (empty($modSettings['permission_enable_deny']))
+			echo '
+						<td width="16%" align="center">', $group['num_permissions']['allowed'], '</td>';
+		else
+			echo '
+						<td width="8%" align="center"', $group['id'] == 1 ? ' style="font-style: italic;"' : '', '>', $group['num_permissions']['allowed'], '</td>
+						<td width="8%" align="center"', $group['id'] == 1 || $group['id'] == -1 ? ' style="font-style: italic;"' : (!empty($group['num_permissions']['denied']) ? ' style="color: red;"' : ''), '>', $group['num_permissions']['denied'], '</td>';
+
+		echo '
+						<td align="center">', $group['allow_modify'] ? '<a href="' . $scripturl . '?action=admin;area=permissions;sa=modify;group=' . $group['id'] . (empty($context['profile']) ? '' : ';pid=' . $context['profile']['id']) . '">' . ($context['can_modify'] ? $txt['permissions_modify'] : $txt['permissions_view']). '</a>' : '', '</td>
+						<td align="center">', $group['allow_modify'] && $context['can_modify'] ? '<input type="checkbox" name="group[]" value="' . $group['id'] . '" class="input_check" />' : '', '</td>
+					</tr>';
+	}
+
+	echo '
+				</tbody>
+			</table>
+			<br />';
+
+	// Advanced stuff...
+	if ($context['can_modify'])
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img id="permissions_panel_toggle" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png"  alt="*" />
+					<a href="#" id="permissions_panel_link">', $txt['permissions_advanced_options'], '</a>
+				</h3>
+			</div>
+			<div id="permissions_panel_advanced" class="windowbg">
+				<div class="content">
+					<fieldset>
+						<legend>', $txt['permissions_with_selection'], '</legend>
+						<dl class="settings admin_permissions">
+							<dt>
+								', $txt['permissions_apply_pre_defined'], ' <a href="', $scripturl, '?action=helpadmin;help=permissions_quickgroups" onclick="return reqWin(this.href);">(?)</a>:
+							</dt>
+							<dd>
+								<select name="predefined">
+									<option value="">(', $txt['permissions_select_pre_defined'], ')</option>
+									<option value="restrict">', $txt['permitgroups_restrict'], '</option>
+									<option value="standard">', $txt['permitgroups_standard'], '</option>
+									<option value="moderator">', $txt['permitgroups_moderator'], '</option>
+									<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
+								</select>
+							</dd>
+							<dt>
+								', $txt['permissions_like_group'], ':
+							</dt>
+							<dd>
+								<select name="copy_from">
+									<option value="empty">(', $txt['permissions_select_membergroup'], ')</option>';
+		foreach ($context['groups'] as $group)
+		{
+			if ($group['id'] != 1)
+				echo '
+									<option value="', $group['id'], '">', $group['name'], '</option>';
+		}
+
+		echo '
+								</select>
+							</dd>
+							<dt>
+								<select name="add_remove">
+									<option value="add">', $txt['permissions_add'], '...</option>
+									<option value="clear">', $txt['permissions_remove'], '...</option>';
+		if (!empty($modSettings['permission_enable_deny']))
+			echo '
+									<option value="deny">', $txt['permissions_deny'], '...</option>';
+		echo '
+								</select>
+							</dt>
+							<dd style="overflow:auto;">
+								<select name="permissions">
+									<option value="">(', $txt['permissions_select_permission'], ')</option>';
+		foreach ($context['permissions'] as $permissionType)
+		{
+			if ($permissionType['id'] == 'membergroup' && !empty($context['profile']))
+				continue;
+
+			foreach ($permissionType['columns'] as $column)
+			{
+				foreach ($column as $permissionGroup)
+				{
+					if ($permissionGroup['hidden'])
+						continue;
+
+					echo '
+									<option value="" disabled="disabled">[', $permissionGroup['name'], ']</option>';
+					foreach ($permissionGroup['permissions'] as $perm)
+					{
+						if ($perm['hidden'])
+							continue;
+
+						if ($perm['has_own_any'])
+							echo '
+									<option value="', $permissionType['id'], '/', $perm['own']['id'], '">&nbsp;&nbsp;&nbsp;', $perm['name'], ' (', $perm['own']['name'], ')</option>
+									<option value="', $permissionType['id'], '/', $perm['any']['id'], '">&nbsp;&nbsp;&nbsp;', $perm['name'], ' (', $perm['any']['name'], ')</option>';
+						else
+							echo '
+									<option value="', $permissionType['id'], '/', $perm['id'], '">&nbsp;&nbsp;&nbsp;', $perm['name'], '</option>';
+					}
+				}
+			}
+		}
+		echo '
+								</select>
+							</dd>
+						</dl>
+					</fieldset>
+					<input type="submit" value="', $txt['permissions_set_permissions'], '" onclick="return checkSubmit();" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>';
+
+		// Javascript for the advanced stuff.
+		echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oPermissionsPanelToggle = new smc_Toggle({
+			bToggleEnabled: true,
+			bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
+			aSwappableContainers: [
+				\'permissions_panel_advanced\'
+			],
+			aSwapImages: [
+				{
+					sId: \'permissions_panel_toggle\',
+					srcExpanded: smf_images_url + \'/collapse.png\',
+					altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
+					srcCollapsed: smf_images_url + \'/expand.png\',
+					altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
+				}
+			],
+			aSwapLinks: [
+				{
+					sId: \'permissions_panel_link\',
+					msgExpanded: ', JavaScriptEscape($txt['advanced']), ',
+					msgCollapsed: ', JavaScriptEscape($txt['advanced']), '
+				}
+			],
+			oThemeOptions: {
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
+				sOptionName: \'admin_preferences\',
+				sSessionVar: smf_session_var,
+				sSessionId: smf_session_id,
+				sThemeId: \'1\',
+				sAdditionalVars: \';admin_key=app\'
+			}
+		});';
+
+		echo '
+
+		function checkSubmit()
+		{
+			if ((document.forms.permissionForm.predefined.value != "" && (document.forms.permissionForm.copy_from.value != "empty" || document.forms.permissionForm.permissions.value != "")) || (document.forms.permissionForm.copy_from.value != "empty" && document.forms.permissionForm.permissions.value != ""))
+			{
+				alert("', $txt['permissions_only_one_option'], '");
+				return false;
+			}
+			if (document.forms.permissionForm.predefined.value == "" && document.forms.permissionForm.copy_from.value == "" && document.forms.permissionForm.permissions.value == "")
+			{
+				alert("', $txt['permissions_no_action'], '");
+				return false;
+			}
+			if (document.forms.permissionForm.permissions.value != "" && document.forms.permissionForm.add_remove.value == "deny")
+				return confirm("', $txt['permissions_deny_dangerous'], '");
+
+			return true;
+		}
+	// ]]></script>';
+
+		if (!empty($context['profile']))
+			echo '
+			<input type="hidden" name="pid" value="', $context['profile']['id'], '" />';
+
+		echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-mpq_token_var'], '" value="', $context['admin-mpq_token'], '" />';
+	}
+	else
+		echo '
+			</table>';
+
+	echo '
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_by_board()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<form id="admincenter" action="', $scripturl, '?action=admin;area=permissions;sa=board" method="post" accept-charset="', $context['character_set'], '">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['permissions_boards'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['permissions_boards_desc'], '
+		</div>
+		<div class="title_bar">
+			<h3 id="board_permissions" class="titlebg flow_hidden">
+				<span class="perm_name floatleft">', $txt['board_name'], '</span>
+				<span class="perm_profile floatleft">', $txt['permission_profile'], '</span>
+			</h3>
+		</div>';
+
+	if (!$context['edit_all'])
+		echo '
+			<div class="content">
+			<a class="button_link" href="', $scripturl, '?action=admin;area=permissions;sa=board;edit;', $context['session_var'], '=', $context['session_id'], '">', $txt['permissions_board_all'], '</a>
+			<br class="clear_right" />
+			</div>';
+
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg"><strong>', $category['name'], '</strong></h3>
+		</div>';
+
+		if (!empty($category['boards']))
+			echo '
+		<div class="windowbg">
+			<div class="content">
+				<ul class="perm_boards flow_hidden">';
+
+		$alternate = false;
+
+		foreach ($category['boards'] as $board)
+		{
+			$alternate = !$alternate;
+
+			echo '
+
+					<li class="flow_hidden' ,' windowbg', $alternate ? '' : '2','">
+						<span class="perm_board floatleft">
+							<a href="', $scripturl, '?action=admin;area=manageboards;sa=board;boardid=', $board['id'], ';rid=permissions;', $context['session_var'], '=', $context['session_id'], '">', str_repeat('-', $board['child_level']), ' ', $board['name'], '</a>
+						</span>
+						<span class="perm_boardprofile floatleft">';
+			if ($context['edit_all'])
+			{
+				echo '
+							<select name="boardprofile[', $board['id'], ']">';
+
+				foreach ($context['profiles'] as $id => $profile)
+					echo '
+								<option value="', $id, '" ', $id == $board['profile'] ? 'selected="selected"' : '', '>', $profile['name'], '</option>';
+
+				echo '
+							</select>';
+			}
+			else
+				echo '
+							<a href="', $scripturl, '?action=admin;area=permissions;sa=index;pid=', $board['profile'], ';', $context['session_var'], '=', $context['session_id'], '"> [', $board['profile_name'], ']</a>';
+
+			echo '
+						</span>
+					</li>';
+		}
+
+		if (!empty($category['boards']))
+			echo '
+				</ul>
+			</div>
+		</div>';
+	}
+
+	echo '
+		<div class="content">';
+
+	if ($context['edit_all'])
+		echo '
+			<input type="submit" name="save_changes" value="', $txt['save'], '" class="button_submit" />';
+	else
+		echo '
+			
+			<a class="button_link" href="', $scripturl, '?action=admin;area=permissions;sa=board;edit;', $context['session_var'], '=', $context['session_id'], '">', $txt['permissions_board_all'], '</a>';
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-mpb_token_var'], '" value="', $context['admin-mpb_token'], '" />
+		</div>
+	</form>
+	<br class="clear" />';
+}
+
+// Edit permission profiles (predefined).
+function template_edit_profiles()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=permissions;sa=profiles" method="post" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['permissions_profile_edit'], '</h3>
+			</div>
+
+			<table width="100%" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th">', $txt['permissions_profile_name'], '</th>
+						<th>', $txt['permissions_profile_used_by'], '</th>
+						<th class="last_th" width="5%">', $txt['delete'], '</th>
+					</tr>
+				</thead>
+				<tbody>';
+	$alternate = false;
+	foreach ($context['profiles'] as $profile)
+	{
+		echo '
+					<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+						<td>';
+
+		if (!empty($context['show_rename_boxes']) && $profile['can_edit'])
+			echo '
+							<input type="text" name="rename_profile[', $profile['id'], ']" value="', $profile['name'], '" class="input_text" />';
+		else
+			echo '
+							<a href="', $scripturl, '?action=admin;area=permissions;sa=index;pid=', $profile['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $profile['name'], '</a>';
+
+		echo '
+						</td>
+						<td>
+							', !empty($profile['boards_text']) ? $profile['boards_text'] : $txt['permissions_profile_used_by_none'], '
+						</td>
+						<td align="center">
+							<input type="checkbox" name="delete_profile[]" value="', $profile['id'], '" ', $profile['can_delete'] ? '' : 'disabled="disabled"', ' class="input_check" />
+						</td>
+					</tr>';
+		$alternate = !$alternate;
+	}
+
+	echo '
+				</tbody>
+			</table>
+			<div class="righttext padding">
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="', $context['admin-mpp_token_var'], '" value="', $context['admin-mpp_token'], '" />';
+
+	if ($context['can_edit_something'])
+		echo '
+				<input type="submit" name="rename" value="', empty($context['show_rename_boxes']) ? $txt['permissions_profile_rename'] : $txt['permissions_commit'], '" class="button_submit" />';
+
+	echo '
+				<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" class="button_submit" />
+				<br class="clear" />
+			</div>
+		</form>
+		<br />
+		<form action="', $scripturl, '?action=admin;area=permissions;sa=profiles" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['permissions_profile_new'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['permissions_profile_name'], ':</strong>
+						</dt>
+						<dd>
+							<input type="text" name="profile_name" value="" class="input_text" />
+						</dd>
+						<dt>
+							<strong>', $txt['permissions_profile_copy_from'], ':</strong>
+						</dt>
+						<dd>
+							<select name="copy_from">';
+
+	foreach ($context['profiles'] as $id => $profile)
+		echo '
+								<option value="', $id, '">', $profile['name'], '</option>';
+
+	echo '
+							</select>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-mpp_token_var'], '" value="', $context['admin-mpp_token'], '" />
+					<input type="submit" name="create" value="', $txt['permissions_profile_new_create'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_modify_group()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Cannot be edited?
+	if (!$context['profile']['can_modify'])
+	{
+		echo '
+		<div class="errorbox">
+			', sprintf($txt['permission_cannot_edit'], $scripturl . '?action=admin;area=permissions;sa=profiles'), '
+		</div>';
+	}
+	else
+	{
+		echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			window.smf_usedDeny = false;
+
+			function warnAboutDeny()
+			{
+				if (window.smf_usedDeny)
+					return confirm("', $txt['permissions_deny_dangerous'], '");
+				else
+					return true;
+			}
+		// ]]></script>';
+	}
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=permissions;sa=modify2;group=', $context['group']['id'], ';pid=', $context['profile']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="permissionForm" id="permissionForm" onsubmit="return warnAboutDeny();">';
+
+	if (!empty($modSettings['permission_enable_deny']) && $context['group']['id'] != -1)
+		echo '
+			<div class="information">
+				', $txt['permissions_option_desc'], '
+			</div>';
+
+	echo '
+			<div class="cat_bar">
+				<h3 class="catbg">';
+	if ($context['permission_type'] == 'board')
+		echo '
+				', $txt['permissions_local_for'], ' &quot;', $context['group']['name'], '&quot; ', $txt['permissions_on'], ' &quot;', $context['profile']['name'], '&quot;';
+	else
+		echo '
+				', $context['permission_type'] == 'membergroup' ? $txt['permissions_general'] : $txt['permissions_board'], ' - &quot;', $context['group']['name'], '&quot;';
+	echo '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					', $txt['permissions_change_view'], ': ', ($context['view_type'] == 'simple' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*" />' : ''), '<a href="', $scripturl, '?action=admin;area=permissions;sa=modify;group=', $context['group']['id'], ($context['permission_type'] == 'board' ? ';pid=' . $context['profile']['id'] : ''), ';view=simple">', $txt['permissions_view_simple'], '</a> |
+					', ($context['view_type'] == 'classic' ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*" />' : ''), '<a href="', $scripturl, '?action=admin;area=permissions;sa=modify;group=', $context['group']['id'], ($context['permission_type'] == 'board' ? ';pid=' . $context['profile']['id'] : ''), ';view=classic">', $txt['permissions_view_classic'], '</a>
+				</div>
+			</div>
+			<div class="flow_hidden">';
+
+	// Draw out the main bits.
+	if ($context['view_type'] == 'simple')
+		template_modify_group_simple($context['permission_type']);
+	else
+		template_modify_group_classic($context['permission_type']);
+
+	// If this is general permissions also show the default profile.
+	if ($context['permission_type'] == 'membergroup')
+	{
+		echo '
+			</div>
+			<br />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['permissions_board'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['permissions_board_desc'], '
+			</div>
+			<div class="flow_hidden">';
+
+		if ($context['view_type'] == 'simple')
+			template_modify_group_simple('board');
+		else
+			template_modify_group_classic('board');
+
+	}
+	echo '
+		</div>';
+
+	if ($context['profile']['can_modify'])
+		echo '
+			<div class="righttext padding">
+				<input type="submit" value="', $txt['permissions_commit'], '" class="button_submit" />
+			</div>';
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-mp_token_var'], '" value="', $context['admin-mp_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+
+}
+
+// A javascript enabled clean permissions view.
+function template_modify_group_simple($type)
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Simple only has one column so we only need bother ourself with that one.
+	$permission_data = &$context['permissions'][$type]['columns'][0];
+
+	// Short cut for disabling fields we can't change.
+	$disable_field = $context['profile']['can_modify'] ? '' : 'disabled="disabled" ';
+
+	echo '
+			<table width="100%" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th colspan="2" width="100%" align="left" class="first_th"></th>';
+				if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+					echo '
+						<th colspan="3" width="9" class="last_th">&nbsp;</th>';
+				else
+					echo '
+						<th>', $txt['permissions_option_on'], '</th>
+						<th>', $txt['permissions_option_off'], '</th>
+						<th class="last_th">', $txt['permissions_option_deny'], '</th>';
+					echo '
+					</tr>
+				</thead>
+				<tbody>';
+
+	foreach ($permission_data as $id_group => $permissionGroup)
+	{
+		if (empty($permissionGroup['permissions']))
+			continue;
+
+		// Are we likely to have something in this group to display or is it all hidden?
+		$has_display_content = false;
+		if (!$permissionGroup['hidden'])
+		{
+			// Before we go any further check we are going to have some data to print otherwise we just have a silly heading.
+			foreach ($permissionGroup['permissions'] as $permission)
+				if (!$permission['hidden'])
+					$has_display_content = true;
+
+			if ($has_display_content)
+			{
+				echo '
+					<tr class="windowbg">
+						<td colspan="2" width="100%" align="left">
+							<a href="#" onclick="return toggleBreakdown(\'', $id_group, '\');">
+								<img src="', $settings['images_url'], '/selected_open.png" id="group_toggle_img_', $id_group, '" alt="*" />&nbsp;<strong>', $permissionGroup['name'], '</strong>
+							</a>
+						</td>';
+				if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+					echo '
+						<td colspan="3" width="10">
+							<div id="group_select_div_', $id_group, '">
+								<input type="checkbox" id="group_select_', $id_group, '" name="group_select_', $id_group, '" class="input_check" onclick="determineGroupState(\'', $id_group, '\', this.checked ? \'on\' : \'off\');" style="display: none;" ', $disable_field, '/>
+							</div>
+						</td>';
+				else
+					echo '
+						<td align="center">
+							<div id="group_select_div_on_', $id_group, '">
+								<input type="radio" id="group_select_on_', $id_group, '" name="group_select_', $id_group, '" value="on" onclick="determineGroupState(\'', $id_group, '\', \'on\');" style="display: none;" ', $disable_field, ' class="input_radio" />
+							</div>
+						</td>
+						<td align="center">
+							<div id="group_select_div_off_', $id_group, '">
+								<input type="radio" id="group_select_off_', $id_group, '" name="group_select_', $id_group, '" value="off" onclick="determineGroupState(\'', $id_group, '\', \'off\');" style="display: none;" ', $disable_field, ' class="input_radio" />
+							</div>
+						</td>
+						<td align="center">
+							<div id="group_select_div_deny_', $id_group, '">
+								<input type="radio" id="group_select_deny_', $id_group, '" name="group_select_', $id_group, '" value="deny" onclick="determineGroupState(\'', $id_group, '\', \'deny\');" style="display: none;" ', $disable_field, ' class="input_radio" />
+							</div>
+						</td>';
+					echo '
+					</tr>';
+			}
+		}
+
+		$alternate = false;
+		foreach ($permissionGroup['permissions'] as $permission)
+		{
+			// If it's hidden keep the last value.
+			if ($permission['hidden'] || $permissionGroup['hidden'])
+			{
+				echo '
+					<tr style="display: none;">
+						<td>
+							<input type="hidden" name="perm[', $type, '][', $permission['id'], ']" value="', $permission['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['select'], '" />
+						</td>
+					</tr>';
+			}
+			else
+			{
+				echo '
+					<tr id="perm_div_', $id_group, '_', $permission['id'], '" class="', $alternate ? 'windowbg' : 'windowbg2', '">
+						<td valign="top" width="10" style="padding-right: 1ex;">
+							', $permission['help_index'] ? '<a href="' . $scripturl . '?action=helpadmin;help=' . $permission['help_index'] . '" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '" /></a>' : '', '
+						</td>
+						<td valign="top" width="100%" align="left" style="padding-bottom: 2px;">', $permission['name'], '</td>';
+
+					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+						echo '
+						<td valign="top" style="padding-bottom: 2px;"><input type="checkbox" id="select_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' onclick="determineGroupState(\'', $id_group, '\');" value="on" class="input_check" ', $disable_field, '/></td>';
+					else
+						echo '
+						<td valign="top" width="10" style="padding-bottom: 2px;"><input type="radio" id="select_on_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" onclick="determineGroupState(\'', $id_group, '\');" class="input_radio" ', $disable_field, '/></td>
+						<td valign="top" width="10" style="padding-bottom: 2px;"><input type="radio" id="select_off_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'off' ? ' checked="checked"' : '', ' value="off" onclick="determineGroupState(\'', $id_group, '\');" class="input_radio" ', $disable_field, '/></td>
+						<td valign="top" width="10" style="padding-bottom: 2px;"><input type="radio" id="select_deny_', $permission['id'], '" name="perm[', $type, '][', $permission['id'], ']"', $permission['select'] == 'denied' ? ' checked="checked"' : '', ' value="deny" onclick="window.smf_usedDeny = true; determineGroupState(\'', $id_group, '\');" class="input_radio" ', $disable_field, '/></td>';
+
+					echo '
+					</tr>';
+			}
+				$alternate = !$alternate;
+		}
+
+		if (!$permissionGroup['hidden'] && $has_display_content)
+			echo '
+					<tr id="group_hr_div_', $id_group, '" class="windowbg2 perm_groups">
+						<td colspan="5" width="100%"></td>
+					</tr>';
+	}
+	echo '
+				</tbody>
+			</table>
+	<script type="text/javascript"><!-- // --><![CDATA[';
+
+	if ($context['profile']['can_modify'] && empty($context['simple_javascript_displayed']))
+	{
+		// Only show this once.
+		$context['simple_javascript_displayed'] = true;
+
+		// This function decides what to do when ANYTHING is touched!
+		echo '
+		var groupPermissions = new Array();
+		function determineGroupState(id_group, forceState)
+		{
+			if (typeof(forceState) != "undefined")
+				thisState = forceState;
+
+			// Cycle through this groups elements.
+			var curState = false, thisState;
+			for (var i = 0; i < groupPermissions[id_group].length; i++)
+			{';
+
+		if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+			echo '
+				if (typeof(forceState) != "undefined")
+				{
+					document.getElementById(\'select_\' + groupPermissions[id_group][i]).checked = forceState == \'on\' ? 1 : 0;
+				}
+
+				thisState = document.getElementById(\'select_\' + groupPermissions[id_group][i]).checked ? \'on\' : \'off\';';
+		else
+			echo '
+				if (typeof(forceState) != "undefined")
+				{
+					document.getElementById(\'select_on_\' + groupPermissions[id_group][i]).checked = forceState == \'on\' ? 1 : 0;
+					document.getElementById(\'select_off_\' + groupPermissions[id_group][i]).checked = forceState == \'off\' ? 1 : 0;
+					document.getElementById(\'select_deny_\' + groupPermissions[id_group][i]).checked = forceState == \'deny\' ? 1 : 0;
+				}
+
+				if (document.getElementById(\'select_on_\' + groupPermissions[id_group][i]).checked)
+					thisState = \'on\';
+				else if (document.getElementById(\'select_off_\' + groupPermissions[id_group][i]).checked)
+					thisState = \'off\';
+				else
+					thisState = \'deny\';';
+
+		echo '
+				// Unless this is the first element, or it\'s the same state as the last we\'re buggered.
+				if (curState == false || thisState == curState)
+				{
+					curState = thisState;
+				}
+				else
+				{
+					curState = \'fudged\';
+					i = 999;
+				}
+			}
+
+			// First check the right master is selected!';
+		if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+			echo '
+			document.getElementById("group_select_" + id_group).checked = curState == \'on\' ? 1 : 0;';
+		else
+			echo '
+			document.getElementById("group_select_on_" + id_group).checked = curState == \'on\' ? 1 : 0;
+			document.getElementById("group_select_off_" + id_group).checked = curState == \'off\' ? 1 : 0;
+			document.getElementById("group_select_deny_" + id_group).checked = curState == \'deny\' ? 1 : 0;';
+
+		// Force the display?
+		echo '
+			if (curState != \'fudged\')
+				toggleBreakdown(id_group, "none");';
+		echo '
+		}';
+	}
+
+	// Some more javascript to be displayed as long as we are editing.
+	if ($context['profile']['can_modify'])
+	{
+		foreach ($permission_data as $id_group => $permissionGroup)
+		{
+			if (empty($permissionGroup['permissions']))
+				continue;
+
+			// As before...
+			$has_display_content = false;
+			if (!$permissionGroup['hidden'])
+			{
+				// Make sure we can show it.
+				foreach ($permissionGroup['permissions'] as $permission)
+					if (!$permission['hidden'])
+						$has_display_content = true;
+
+				// Make all the group indicators visible on JS only.
+				if ($has_display_content)
+				{
+					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+						echo '
+			document.getElementById("group_select_div_', $id_group, '").parentNode.className = "lockedbg";
+			document.getElementById("group_select_', $id_group, '").style.display = "";';
+					else
+						echo '
+			document.getElementById("group_select_div_on_', $id_group, '").parentNode.className = "lockedbg";
+			document.getElementById("group_select_div_off_', $id_group, '").parentNode.className = "lockedbg";
+			document.getElementById("group_select_div_deny_', $id_group, '").parentNode.className = "lockedbg";
+			document.getElementById("group_select_on_', $id_group, '").style.display = "";
+			document.getElementById("group_select_off_', $id_group, '").style.display = "";
+			document.getElementById("group_select_deny_', $id_group, '").style.display = "";';
+				}
+
+				$perm_ids = array();
+				$count = 0;
+				foreach ($permissionGroup['permissions'] as $permission)
+				{
+					if (!$permission['hidden'])
+					{
+						// Need this for knowing what can be tweaked.
+						$perm_ids[] = "'$permission[id]'";
+					}
+				}
+				// Declare this groups permissions into an array.
+				if (!empty($perm_ids))
+					echo '
+			groupPermissions[\'', $id_group, '\'] = new Array(', count($perm_ids), ');';
+				foreach ($perm_ids as $count => $id)
+					echo '
+			groupPermissions[\'', $id_group, '\'][', $count, '] = ', $id, ';';
+
+				// Show the group as required.
+				if ($has_display_content)
+				echo '
+			determineGroupState(\'', $id_group, '\');';
+			}
+		}
+	}
+
+	echo '
+		// ]]></script>';
+}
+
+// The SMF 1.x way of looking at permissions.
+function template_modify_group_classic($type)
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	$permission_type = &$context['permissions'][$type];
+	$disable_field = $context['profile']['can_modify'] ? '' : 'disabled="disabled" ';
+
+	echo '
+				<div class="windowbg2">
+					<div class="content">';
+
+	foreach ($permission_type['columns'] as $column)
+	{
+		echo '
+						<table width="49%" class="table_grid perm_classic floatleft">';
+
+		foreach ($column as $permissionGroup)
+		{
+			if (empty($permissionGroup['permissions']))
+				continue;
+
+			// Are we likely to have something in this group to display or is it all hidden?
+			$has_display_content = false;
+			if (!$permissionGroup['hidden'])
+			{
+				// Before we go any further check we are going to have some data to print otherwise we just have a silly heading.
+				foreach ($permissionGroup['permissions'] as $permission)
+					if (!$permission['hidden'])
+						$has_display_content = true;
+
+				if ($has_display_content)
+				{
+					echo '
+							<tr class="catbg">
+								<th colspan="2" width="100%" align="left"><strong class="smalltext">', $permissionGroup['name'], '</strong></th>';
+					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+						echo '
+								<th colspan="3" width="10"></th>';
+					else
+						echo '
+								<th align="center"><div>', $txt['permissions_option_on'], '</div></th>
+								<th align="center"><div>', $txt['permissions_option_off'], '</div></th>
+								<th align="center"><div>', $txt['permissions_option_deny'], '</div></th>';
+					echo '
+							</tr>';
+				}
+			}
+
+			$alternate = false;
+			foreach ($permissionGroup['permissions'] as $permission)
+			{
+				// If it's hidden keep the last value.
+				if ($permission['hidden'] || $permissionGroup['hidden'])
+				{
+					echo '
+							<tr style="display: none;">
+								<td>';
+
+					if ($permission['has_own_any'])
+					{
+						// Guests can't have own permissions.
+						if ($context['group']['id'] != -1)
+							echo '
+									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']" value="', $permission['own']['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['own']['select'], '" />';
+
+						echo '
+									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']" value="', $permission['any']['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['any']['select'], '" />';
+					}
+					else
+						echo '
+									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['id'], ']" value="', $permission['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['select'], '" />';
+					echo '
+								</td>
+							</tr>';
+				}
+				else
+				{
+					echo '
+							<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+								<td width="10">
+									', $permission['show_help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=permissionhelp_' . $permission['id'] . '" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '" /></a>' : '', '
+								</td>';
+
+					if ($permission['has_own_any'])
+					{
+						echo '
+								<td colspan="4" width="100%" align="left">', $permission['name'], '</td>
+							</tr><tr class="', $alternate ? 'windowbg' : 'windowbg2', '">';
+
+						// Guests can't do their own thing.
+						if ($context['group']['id'] != -1)
+						{
+							echo '
+								<td></td>
+								<td width="100%" class="smalltext" align="right">', $permission['own']['name'], ':</td>';
+
+							if (empty($modSettings['permission_enable_deny']))
+								echo '
+								<td colspan="3"><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_check" ', $disable_field, '/></td>';
+							else
+								echo '
+								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_radio" ', $disable_field, '/></td>
+								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'off' ? ' checked="checked"' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
+								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'denied' ? ' checked="checked"' : '', ' value="deny" class="input_radio" ', $disable_field, '/></td>';
+
+							echo '
+							</tr><tr class="', $alternate ? 'windowbg' : 'windowbg2', '">';
+						}
+
+						echo '
+								<td></td>
+								<td width="100%" class="smalltext" align="right">', $permission['any']['name'], ':</td>';
+
+						if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+							echo '
+								<td colspan="3"><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_check" ', $disable_field, '/></td>';
+						else
+							echo '
+								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" onclick="document.forms.permissionForm.', $permission['own']['id'], '_on.checked = true;" class="input_radio" ', $disable_field, '/></td>
+								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'off' ? ' checked="checked"' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
+								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select']== 'denied' ? ' checked="checked"' : '', ' value="deny" id="', $permission['any']['id'], '_deny" onclick="window.smf_usedDeny = true;" class="input_radio" ', $disable_field, '/></td>';
+
+						echo '
+							</tr>';
+					}
+					else
+					{
+						echo '
+								<td width="100%" align="left">', $permission['name'], '</td>';
+
+						if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+							echo '
+								<td><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_check" ', $disable_field, '/></td>';
+						else
+							echo '
+								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_radio" ', $disable_field, '/></td>
+								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'off' ? ' checked="checked"' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
+								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'denied' ? ' checked="checked"' : '', ' value="deny" onclick="window.smf_usedDeny = true;" class="input_radio" ', $disable_field, '/></td>';
+
+						echo '
+							</tr>';
+					}
+				}
+				$alternate = !$alternate;
+			}
+
+			if (!$permissionGroup['hidden'] && $has_display_content)
+				echo '
+							<tr class="windowbg2">
+								<td colspan="5" width="100%"><!--separator--></td>
+							</tr>';
+		}
+	echo '
+						</table>';
+	}
+	echo '
+				<br class="clear" />
+				</div>
+			</div>';
+}
+
+function template_inline_permissions()
+{
+	global $context, $settings, $options, $txt, $modSettings;
+
+	echo '
+		<fieldset id="', $context['current_permission'], '">
+			<legend><a href="javascript:void(0);" onclick="document.getElementById(\'', $context['current_permission'], '\').style.display = \'none\';document.getElementById(\'', $context['current_permission'], '_groups_link\').style.display = \'block\'; return false;">', $txt['avatar_select_permission'], '</a></legend>';
+	if (empty($modSettings['permission_enable_deny']))
+		echo '
+			<ul class="permission_groups">';
+	else
+		echo '
+			<div class="information">', $txt['permissions_option_desc'], '</div>
+			<dl class="settings">
+				<dt>
+					<span class="perms"><strong>', $txt['permissions_option_on'], '</strong></span>
+					<span class="perms"><strong>', $txt['permissions_option_off'], '</strong></span>
+					<span class="perms" style="color: red;"><strong>', $txt['permissions_option_deny'], '</strong></span>
+				</dt>
+				<dd>
+				</dd>';
+	foreach ($context['member_groups'] as $group)
+	{
+		if (!empty($modSettings['permission_enable_deny']))
+			echo '
+				<dt>';
+		else
+			echo '
+				<li>';
+
+		if (empty($modSettings['permission_enable_deny']))
+			echo '
+					<input type="checkbox" name="', $context['current_permission'], '[', $group['id'], ']" value="on"', $group['status'] == 'on' ? ' checked="checked"' : '', ' class="input_check" />';
+		else
+			echo '
+					<span class="perms"><input type="radio" name="', $context['current_permission'], '[', $group['id'], ']" value="on"', $group['status'] == 'on' ? ' checked="checked"' : '', ' class="input_radio" /></span>
+					<span class="perms"><input type="radio" name="', $context['current_permission'], '[', $group['id'], ']" value="off"', $group['status'] == 'off' ? ' checked="checked"' : '', ' class="input_radio" /></span>
+					<span class="perms"><input type="radio" name="', $context['current_permission'], '[', $group['id'], ']" value="deny"', $group['status'] == 'deny' ? ' checked="checked"' : '', ' class="input_radio" /></span>';
+
+		if (!empty($modSettings['permission_enable_deny']))
+			echo '
+				</dt>
+				<dd>
+					<span', $group['is_postgroup'] ? ' style="font-style: italic;"' : '', '>', $group['name'], '</span>
+				</dd>';
+		else
+			echo '
+					<span', $group['is_postgroup'] ? ' style="font-style: italic;"' : '', '>', $group['name'], '</span>
+				</li>';
+	}
+
+	if (empty($modSettings['permission_enable_deny']))
+		echo '
+			</ul>';
+	else
+		echo '
+			</dl>';
+
+	echo '
+		</fieldset>
+
+		<a href="javascript:void(0);" onclick="document.getElementById(\'', $context['current_permission'], '\').style.display = \'block\'; document.getElementById(\'', $context['current_permission'], '_groups_link\').style.display = \'none\'; return false;" id="', $context['current_permission'], '_groups_link" style="display: none;">[ ', $txt['avatar_select_permission'], ' ]</a>
+
+		<script type="text/javascript"><!-- // --><![CDATA[
+			document.getElementById("', $context['current_permission'], '").style.display = "none";
+			document.getElementById("', $context['current_permission'], '_groups_link").style.display = "";
+		// ]]></script>';
+}
+
+// Edit post moderation permissions.
+function template_postmod_permissions()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=permissions;sa=postmod;', $context['session_var'], '=', $context['session_id'], '" method="post" name="postmodForm" id="postmodForm" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['permissions_post_moderation'], '</h3>
+			</div>';
+
+	// Got advanced permissions - if so warn!
+	if (!empty($modSettings['permission_enable_deny']))
+		echo '
+				<div class="information">', $txt['permissions_post_moderation_deny_note'], '</div>';
+
+	echo '
+				<div class="righttext padding">
+					', $txt['permissions_post_moderation_select'], ':
+					<select name="pid" onchange="document.forms.postmodForm.submit();">';
+
+	foreach ($context['profiles'] as $profile)
+		if ($profile['can_modify'])
+			echo '
+						<option value="', $profile['id'], '" ', $profile['id'] == $context['current_profile'] ? 'selected="selected"' : '', '>', $profile['name'], '</option>';
+
+	echo '
+					</select>
+					<input type="submit" value="', $txt['go'], '" class="button_submit" />
+			</div>
+			<table width="100%" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th"></th>
+						<th align="center" colspan="3">
+							', $txt['permissions_post_moderation_new_topics'], '
+						</th>
+						<th align="center" colspan="3">
+							', $txt['permissions_post_moderation_replies_own'], '
+						</th>
+						<th align="center" colspan="3">
+							', $txt['permissions_post_moderation_replies_any'], '
+						</th>
+						<th class="last_th" align="center" colspan="3">
+							', $txt['permissions_post_moderation_attachments'], '
+						</th>
+					</tr>
+					<tr class="titlebg">
+						<th width="30%">
+							', $txt['permissions_post_moderation_group'], '
+						</th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" title="', $txt['permissions_post_moderation_allow'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" title="', $txt['permissions_post_moderation_moderate'], '" /></th>
+						<th align="center"><img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" title="', $txt['permissions_post_moderation_disallow'], '" /></th>
+					</tr>
+				</thead>
+				<tbody>';
+
+	foreach ($context['profile_groups'] as $group)
+	{
+		echo '
+					<tr>
+						<td width="40%" class="windowbg">
+							<span ', ($group['color'] ? 'style="color: ' . $group['color'] . '"' : ''), '>', $group['name'], '</span>';
+			if (!empty($group['children']))
+				echo '
+							<br /><span class="smalltext">', $txt['permissions_includes_inherited'], ': &quot;', implode('&quot;, &quot;', $group['children']), '&quot;</span>';
+
+			echo '
+						</td>
+						<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="allow" ', $group['new_topic'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="moderate" ', $group['new_topic'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="disallow" ', $group['new_topic'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="allow" ', $group['replies_own'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="moderate" ', $group['replies_own'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="disallow" ', $group['replies_own'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="allow" ', $group['replies_any'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="moderate" ', $group['replies_any'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="disallow" ', $group['replies_any'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="allow" ', $group['attachment'] == 'allow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="moderate" ', $group['attachment'] == 'moderate' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+						<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="disallow" ', $group['attachment'] == 'disallow' ? 'checked="checked"' : '', ' class="input_radio" /></td>
+					</tr>';
+	}
+
+	echo '
+				</tbody>
+			</table>
+			<div class="righttext padding">
+				<input type="submit" name="save_changes" value="', $txt['permissions_commit'], '" class="button_submit" />
+				<input type="hidden" name="', $context['admin-mppm_token_var'], '" value="', $context['admin-mppm_token'], '" />
+			</div>
+		</form>
+		<p class="smalltext" style="padding-left: 10px;">
+			<strong>', $txt['permissions_post_moderation_legend'], ':</strong><br />
+			<img src="', $settings['default_images_url'], '/admin/post_moderation_allow.png" alt="', $txt['permissions_post_moderation_allow'], '" /> - ', $txt['permissions_post_moderation_allow'], '<br />
+			<img src="', $settings['default_images_url'], '/admin/post_moderation_moderate.png" alt="', $txt['permissions_post_moderation_moderate'], '" /> - ', $txt['permissions_post_moderation_moderate'], '<br />
+			<img src="', $settings['default_images_url'], '/admin/post_moderation_deny.png" alt="', $txt['permissions_post_moderation_disallow'], '" /> - ', $txt['permissions_post_moderation_disallow'], '
+		</p>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 93 - 95
Themes/default/ManageScheduledTasks.template.php

@@ -1,96 +1,94 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Template for listing all scheduled tasks.
-function template_view_scheduled_tasks()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	// We completed some tasks?
-	if (!empty($context['tasks_were_run']))
-		echo '
-	<div id="task_completed">
-		', $txt['scheduled_tasks_were_run'], '
-	</div>';
-
-	template_show_list('scheduled_tasks');
-}
-
-// A template for, you guessed it, editing a task!
-function template_edit_scheduled_tasks()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	// Starts off with general maintenance procedures.
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=scheduledtasks;sa=taskedit;save;tid=', $context['task']['id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['scheduled_task_edit'], '</h3>
-			</div>
-			<div class="information">
-				<em>', sprintf($txt['scheduled_task_time_offset'], $context['server_time']), ' </em>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['scheduled_tasks_name'], ':</strong>
-						</dt>
-						<dd>
-							', $context['task']['name'], '<br />
-							<span class="smalltext">', $context['task']['desc'], '</span>
-						</dd>
-						<dt>
-							<strong><label for="regularity">', $txt['scheduled_task_edit_interval'], ':</label></strong>
-						</dt>
-						<dd>
-							', $txt['scheduled_task_edit_repeat'], '
-							<input type="text" name="regularity" id="regularity" value="', empty($context['task']['regularity']) ? 1 : $context['task']['regularity'], '" onchange="if (this.value < 1) this.value = 1;" size="2" maxlength="2" class="input_text" />
-							<select name="unit">
-								<option value="0">', $txt['scheduled_task_edit_pick_unit'], '</option>
-								<option value="0">---------------------</option>
-								<option value="m" ', empty($context['task']['unit']) || $context['task']['unit'] == 'm' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_m'], '</option>
-								<option value="h" ', $context['task']['unit'] == 'h' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_h'], '</option>
-								<option value="d" ', $context['task']['unit'] == 'd' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_d'], '</option>
-								<option value="w" ', $context['task']['unit'] == 'w' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_w'], '</option>
-							</select>
-						</dd>
-						<dt>
-							<strong><label for="start_time">', $txt['scheduled_task_edit_start_time'], ':</label></strong><br />
-							<span class="smalltext">', $txt['scheduled_task_edit_start_time_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="offset" id="start_time" value="', $context['task']['offset_formatted'], '" size="6" maxlength="5" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="enabled">', $txt['scheduled_tasks_enabled'], ':</label></strong>
-						</dt>
-						<dd>
-							<input type="checkbox" name="enabled" id="enabled" ', !$context['task']['disabled'] ? 'checked="checked"' : '', ' class="input_check" />
-						</dd>
-					</dl>
-					<div class="righttext">
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="', $context['admin-st_token_var'], '" value="', $context['admin-st_token'], '" />
-						<input type="submit" name="save" value="', $txt['scheduled_tasks_save_changes'], '" class="button_submit" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Template for listing all scheduled tasks.
+function template_view_scheduled_tasks()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	// We completed some tasks?
+	if (!empty($context['tasks_were_run']))
+		echo '
+	<div id="task_completed">
+		', $txt['scheduled_tasks_were_run'], '
+	</div>';
+
+	template_show_list('scheduled_tasks');
+}
+
+// A template for, you guessed it, editing a task!
+function template_edit_scheduled_tasks()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	// Starts off with general maintenance procedures.
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=scheduledtasks;sa=taskedit;save;tid=', $context['task']['id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['scheduled_task_edit'], '</h3>
+			</div>
+			<div class="information">
+				<em>', sprintf($txt['scheduled_task_time_offset'], $context['server_time']), ' </em>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['scheduled_tasks_name'], ':</strong>
+						</dt>
+						<dd>
+							', $context['task']['name'], '<br />
+							<span class="smalltext">', $context['task']['desc'], '</span>
+						</dd>
+						<dt>
+							<strong><label for="regularity">', $txt['scheduled_task_edit_interval'], ':</label></strong>
+						</dt>
+						<dd>
+							', $txt['scheduled_task_edit_repeat'], '
+							<input type="text" name="regularity" id="regularity" value="', empty($context['task']['regularity']) ? 1 : $context['task']['regularity'], '" onchange="if (this.value < 1) this.value = 1;" size="2" maxlength="2" class="input_text" />
+							<select name="unit">
+								<option value="0">', $txt['scheduled_task_edit_pick_unit'], '</option>
+								<option value="0">---------------------</option>
+								<option value="m" ', empty($context['task']['unit']) || $context['task']['unit'] == 'm' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_m'], '</option>
+								<option value="h" ', $context['task']['unit'] == 'h' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_h'], '</option>
+								<option value="d" ', $context['task']['unit'] == 'd' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_d'], '</option>
+								<option value="w" ', $context['task']['unit'] == 'w' ? 'selected="selected"' : '', '>', $txt['scheduled_task_reg_unit_w'], '</option>
+							</select>
+						</dd>
+						<dt>
+							<strong><label for="start_time">', $txt['scheduled_task_edit_start_time'], ':</label></strong><br />
+							<span class="smalltext">', $txt['scheduled_task_edit_start_time_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="offset" id="start_time" value="', $context['task']['offset_formatted'], '" size="6" maxlength="5" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="enabled">', $txt['scheduled_tasks_enabled'], ':</label></strong>
+						</dt>
+						<dd>
+							<input type="checkbox" name="enabled" id="enabled" ', !$context['task']['disabled'] ? 'checked="checked"' : '', ' class="input_check" />
+						</dd>
+					</dl>
+					<div class="righttext">
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="', $context['admin-st_token_var'], '" value="', $context['admin-st_token'], '" />
+						<input type="submit" name="save" value="', $txt['scheduled_tasks_save_changes'], '" class="button_submit" />
+					</div>
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 445 - 461
Themes/default/ManageSearch.template.php

@@ -1,462 +1,446 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_modify_weights()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=managesearch;sa=weights" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['search_weights'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt class="large_caption">
-							<a href="', $scripturl, '?action=helpadmin;help=search_weight_frequency" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight1_val">
-							', $txt['search_weight_frequency'], ':</label>
-						</dt>
-						<dd class="large_caption">
-							<span class="search_weight"><input type="text" name="search_weight_frequency" id="weight1_val" value="', empty($modSettings['search_weight_frequency']) ? '0' : $modSettings['search_weight_frequency'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
-							<span id="weight1" class="search_weight">', $context['relative_weights']['search_weight_frequency'], '%</span>
-						</dd>
-						<dt class="large_caption">
-							<a href="', $scripturl, '?action=helpadmin;help=search_weight_age" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight2_val">
-							', $txt['search_weight_age'], ':</label>
-						</dt>
-						<dd class="large_caption">
-							<span class="search_weight"><input type="text" name="search_weight_age" id="weight2_val" value="', empty($modSettings['search_weight_age']) ? '0' : $modSettings['search_weight_age'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
-							<span id="weight2" class="search_weight">', $context['relative_weights']['search_weight_age'], '%</span>
-						</dd>
-						<dt class="large_caption">
-							<a href="', $scripturl, '?action=helpadmin;help=search_weight_length" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight3_val">
-							', $txt['search_weight_length'], ':</label>
-						</dt>
-						<dd class="large_caption">
-							<span class="search_weight"><input type="text" name="search_weight_length" id="weight3_val" value="', empty($modSettings['search_weight_length']) ? '0' : $modSettings['search_weight_length'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
-							<span id="weight3" class="search_weight">', $context['relative_weights']['search_weight_length'], '%</span>
-						</dd>
-						<dt class="large_caption">
-							<a href="', $scripturl, '?action=helpadmin;help=search_weight_subject" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight4_val">
-							', $txt['search_weight_subject'], ':</label>
-						</dt>
-						<dd class="large_caption">
-							<span class="search_weight"><input type="text" name="search_weight_subject" id="weight4_val" value="', empty($modSettings['search_weight_subject']) ? '0' : $modSettings['search_weight_subject'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
-							<span id="weight4" class="search_weight">', $context['relative_weights']['search_weight_subject'], '%</span>
-						</dd>
-						<dt class="large_caption">
-							<a href="', $scripturl, '?action=helpadmin;help=search_weight_first_message" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight5_val">
-							', $txt['search_weight_first_message'], ':</label>
-						</dt>
-						<dd class="large_caption">
-							<span class="search_weight"><input type="text" name="search_weight_first_message" id="weight5_val" value="', empty($modSettings['search_weight_first_message']) ? '0' : $modSettings['search_weight_first_message'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
-							<span id="weight5" class="search_weight">', $context['relative_weights']['search_weight_first_message'], '%</span>
-						</dd>
-						<dt class="large_caption">
-							<a href="', $scripturl, '?action=helpadmin;help=search_weight_frequency" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" align="top" /></a><label for="weight6_val">
-							', $txt['search_weight_sticky'], ':</label>
-						</dt>
-						<dd class="large_caption">
-							<span class="search_weight"><input type="text" name="search_weight_sticky" id="weight6_val" value="', empty($modSettings['search_weight_sticky']) ? '0' : $modSettings['search_weight_sticky'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
-							<span id="weight6" class="search_weight">', $context['relative_weights']['search_weight_sticky'], '%</span>
-						</dd>
-						<dt class="large_caption">
-							<strong>', $txt['search_weights_total'], '</strong>
-						</dt>
-						<dd class="large_caption">
-							<span id="weighttotal" class="search_weight"><strong>', $context['relative_weights']['total'], '</strong></span>
-							<span class="search_weight"><strong>100%</strong></span>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['search_weights_save'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-msw_token_var'], '" value="', $context['admin-msw_token'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_select_search_method()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=managesearch;sa=method" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['search_method'], '</h3>
-			</div>
-			<div class="information">
-				<div class="smalltext" style="font-weight: normal;"><a href="', $scripturl, '?action=helpadmin;help=search_why_use_index" onclick="return reqWin(this.href);">', $txt['search_create_index_why'], '</a></div>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-
-			';
-	if (!empty($context['table_info']))
-		echo '
-						<dt>
-							<strong>', $txt['search_method_messages_table_space'], ':</strong>
-						</dt>
-						<dd>
-							', $context['table_info']['data_length'], '
-						</dd>
-						<dt>
-							<strong>', $txt['search_method_messages_index_space'], ':</strong>
-						</dt>
-						<dd>
-							', $context['table_info']['index_length'], '
-						</dd>';
-	echo '
-					</dl>
-					', $context['double_index'] ? '<div class="information">
-					' . $txt['search_double_index'] . '</div>' : '', '
-					<fieldset class="search_settings floatleft">
-						<legend>', $txt['search_index'], '</legend>
-						<dl>
-							<dt><input type="radio" name="search_index" value=""', empty($modSettings['search_index']) ? ' checked="checked"' : '', ' class="input_radio" />
-							', $txt['search_index_none'], '
-							</dt>';
-
-	if ($context['supports_fulltext'])
-	{
-		echo '
-							<dt>
-								<input type="radio" name="search_index" value="fulltext"', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext' ? ' checked="checked"' : '', empty($context['fulltext_index']) ? ' onclick="alert(\'' . $txt['search_method_fulltext_warning'] . '\'); selectRadioByName(this.form.search_index, \'fulltext\');"': '', ' class="input_radio" />
-								', $txt['search_method_fulltext_index'], '
-							</dt>
-							<dd>
-
-								<span class="smalltext">';
-	if (empty($context['fulltext_index']) && empty($context['cannot_create_fulltext']))
-		echo '
-									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_no_index_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=createfulltext;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_method_fulltext_create'], '</a>]';
-	elseif (empty($context['fulltext_index']) && !empty($context['cannot_create_fulltext']))
-		echo '
-									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_fulltext_cannot_create'];
-	else
-		echo '
-									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_index_already_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=removefulltext;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_method_fulltext_remove'], '</a>]<br />
-									<strong>', $txt['search_index_size'], ':</strong> ', $context['table_info']['fulltext_length'];
-	echo '
-									</span>
-							</dd>';
-	}
-
-	echo '
-							<dt>
-								<input type="radio" name="search_index" value="custom"', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom' ? ' checked="checked"' : '', $context['custom_index'] ? '' : ' onclick="alert(\'' . $txt['search_index_custom_warning'] . '\'); selectRadioByName(this.form.search_method, \'1\');"', ' class="input_radio" />
-								', $txt['search_index_custom'], '
-							</dt>
-							<dd>
-								<span class="smalltext">';
-	if ($context['custom_index'])
-		echo '
-									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_index_already_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=removecustom;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_index_custom_remove'], '</a>]<br />
-									<strong>', $txt['search_index_size'], ':</strong> ', $context['table_info']['custom_index_length'];
-	elseif ($context['partial_custom_index'])
-		echo '
-									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_index_partial'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=removecustom;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_index_custom_remove'], '</a>] [<a href="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex;resume;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_index_custom_resume'], '</a>]<br />
-									<strong>', $txt['search_index_size'], ':</strong> ', $context['table_info']['custom_index_length'];
-	else
-		echo '
-									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_no_index_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex">', $txt['search_index_create_custom'], '</a>]';
-	echo '
-								</span>
-							</dd>';
-
-	foreach ($context['search_apis'] as $api)
-	{
-		if (empty($api['label']) || $api['has_template'])
-			continue;
-
-		echo '
-							<dt>
-								<input type="radio" name="search_index" value="', $api['setting_index'], '"', !empty($modSettings['search_index']) && $modSettings['search_index'] == $api['setting_index'] ? ' checked="checked"' : '', ' class="input_radio" />
-								', $api['label'] ,'
-							</dt>';
-
-	if ($api['desc'])
-		echo '
-							<dd>
-								<span class="smalltext">', $api['desc'], '</span>
-							</dd>';
-	}
-
-	echo '
-						</dl>
-					</fieldset>
-					<fieldset class="search_settings floatright">
-					<legend>', $txt['search_method'], '</legend>
-						<input type="checkbox" name="search_force_index" id="search_force_index_check" value="1"', empty($modSettings['search_force_index']) ? '' : ' checked="checked"', ' class="input_check" /><label for="search_force_index_check">', $txt['search_force_index'], '</label><br />
-						<input type="checkbox" name="search_match_words" id="search_match_words_check" value="1"', empty($modSettings['search_match_words']) ? '' : ' checked="checked"', ' class="input_check" /><label for="search_match_words_check">', $txt['search_match_words'], '</label>
-					</fieldset>
-					<hr class="hrcolor clear" />
-					<input type="submit" name="save" value="', $txt['search_method_save'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-msmpost_token_var'], '" value="', $context['admin-msmpost_token'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice clear"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_create_index()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex;step=1" method="post" accept-charset="', $context['character_set'], '" name="create_index">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['search_create_index'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="predefine_select">', $txt['search_predefined'], ':</label>
-						</dt>
-						<dd>
-							<select name="bytes_per_word" id="predefine_select">
-								<option value="2">', $txt['search_predefined_small'], '</option>
-								<option value="4" selected="selected">', $txt['search_predefined_moderate'], '</option>
-								<option value="5">', $txt['search_predefined_large'], '</option>
-							</select>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['search_create_index_start'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-	</form>
-	</div>';
-}
-
-function template_create_index_progress()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex;step=1" name="autoSubmit" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['search_create_index'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div><p>',
-						$txt['search_create_index_not_ready'], '</p>
-						<div class="progress_bar">
-							<div class="full_bar">', $context['percentage'], '%</div>
-							<div class="green_percent" style="width: ', $context['percentage'], '%;">&nbsp;</div>
-						</div>
-					</div>
-					<hr class="hrcolor" />
-					<input type="submit" name="b" value="', $txt['search_create_index_continue'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="step" value="', $context['step'], '" />
-			<input type="hidden" name="start" value="', $context['start'], '" />
-			<input type="hidden" name="bytes_per_word" value="', $context['index_settings']['bytes_per_word'], '" />
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var countdown = 10;
-		doAutoSubmit();
-
-		function doAutoSubmit()
-		{
-			if (countdown == 0)
-				document.forms.autoSubmit.submit();
-			else if (countdown == -1)
-				return;
-
-			document.forms.autoSubmit.b.value = "', $txt['search_create_index_continue'], ' (" + countdown + ")";
-			countdown--;
-
-			setTimeout("doAutoSubmit();", 1000);
-		}
-	// ]]></script>';
-
-}
-
-function template_create_index_done()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['search_create_index'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['search_create_index_done'], '</p>
-				<p>
-					<strong><a href="', $scripturl, '?action=admin;area=managesearch;sa=method">', $txt['search_create_index_done_link'], '</a></strong>
-				</p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-// Add or edit a search engine spider.
-function template_spider_edit()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=sengines;sa=editspiders;sid=', $context['spider']['id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['add_spider_desc'], '
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong><label for="spider_name">', $txt['spider_name'], ':</label></strong><br />
-							<span class="smalltext">', $txt['spider_name_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="spider_name" id="spider_name" value="', $context['spider']['name'], '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="spider_agent">', $txt['spider_agent'], ':</label></strong><br />
-							<span class="smalltext">', $txt['spider_agent_desc'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="spider_agent" id="spider_agent" value="', $context['spider']['agent'], '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="spider_ip">', $txt['spider_ip_info'], ':</label></strong><br />
-							<span class="smalltext">', $txt['spider_ip_info_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea name="spider_ip" id="spider_ip" rows="4" cols="20">', $context['spider']['ip_info'], '</textarea>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $context['page_title'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-ses_token_var'], '" value="', $context['admin-ses_token'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Show... spider... logs...
-function template_show_spider_logs()
-{
-	global $context, $txt, $settings, $scripturl;
-
-	echo '
-	<div id="admincenter">';
-
-	// Standard fields.
-	template_show_list('spider_logs');
-
-	echo '
-		<br />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['spider_logs_delete'], '</h3>
-		</div>
-		<form action="', $scripturl, '?action=admin;area=sengines;sa=logs" method="post" accept-charset="', $context['character_set'], '">
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>
-						', $txt['spider_logs_delete_older'], '
-						<input type="text" name="older" id="older" value="7" size="3" class="input_text" />
-						', $txt['spider_logs_delete_day'], '
-					</p>	
-					<hr class="hrcolor" />
-					<input type="submit" name="delete_entries" value="', $txt['spider_logs_delete_submit'], '" onclick="if (document.getElementById(\'older\').value &lt; 1 &amp;&amp; !confirm(\'' . addcslashes($txt['spider_logs_delete_confirm'], "'") . '\')) return false; return true;" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-sl_token_var'], '" value="', $context['admin-sl_token'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Show... spider... stats...
-function template_show_spider_stats()
-{
-	global $context, $txt, $settings, $scripturl;
-
-	echo '
-	<div id="admincenter">';
-
-	// Standard fields.
-	template_show_list('spider_stat_list');
-
-	echo '
-		<br />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['spider_logs_delete'], '</h3>
-		</div>
-		<form action="', $scripturl, '?action=admin;area=sengines;sa=stats" method="post" accept-charset="', $context['character_set'], '">
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>
-						', sprintf($txt['spider_stats_delete_older'], '<input type="text" name="older" id="older" value="90" size="3" class="input_text" />'), '
-					</p>
-					<hr class="hrcolor" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-ss_token_var'], '" value="', $context['admin-ss_token'], '" />
-					<input type="submit" name="delete_entries" value="', $txt['spider_logs_delete_submit'], '" onclick="if (document.getElementById(\'older\').value &lt; 1 &amp;&amp; !confirm(\'' . addcslashes($txt['spider_logs_delete_confirm'], "'") . '\')) return false; return true;" class="button_submit" />
-					<br />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_modify_weights()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=managesearch;sa=weights" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['search_weights'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt class="large_caption">
+							<a href="', $scripturl, '?action=helpadmin;help=search_weight_frequency" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight1_val">
+							', $txt['search_weight_frequency'], ':</label>
+						</dt>
+						<dd class="large_caption">
+							<span class="search_weight"><input type="text" name="search_weight_frequency" id="weight1_val" value="', empty($modSettings['search_weight_frequency']) ? '0' : $modSettings['search_weight_frequency'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
+							<span id="weight1" class="search_weight">', $context['relative_weights']['search_weight_frequency'], '%</span>
+						</dd>
+						<dt class="large_caption">
+							<a href="', $scripturl, '?action=helpadmin;help=search_weight_age" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight2_val">
+							', $txt['search_weight_age'], ':</label>
+						</dt>
+						<dd class="large_caption">
+							<span class="search_weight"><input type="text" name="search_weight_age" id="weight2_val" value="', empty($modSettings['search_weight_age']) ? '0' : $modSettings['search_weight_age'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
+							<span id="weight2" class="search_weight">', $context['relative_weights']['search_weight_age'], '%</span>
+						</dd>
+						<dt class="large_caption">
+							<a href="', $scripturl, '?action=helpadmin;help=search_weight_length" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight3_val">
+							', $txt['search_weight_length'], ':</label>
+						</dt>
+						<dd class="large_caption">
+							<span class="search_weight"><input type="text" name="search_weight_length" id="weight3_val" value="', empty($modSettings['search_weight_length']) ? '0' : $modSettings['search_weight_length'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
+							<span id="weight3" class="search_weight">', $context['relative_weights']['search_weight_length'], '%</span>
+						</dd>
+						<dt class="large_caption">
+							<a href="', $scripturl, '?action=helpadmin;help=search_weight_subject" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight4_val">
+							', $txt['search_weight_subject'], ':</label>
+						</dt>
+						<dd class="large_caption">
+							<span class="search_weight"><input type="text" name="search_weight_subject" id="weight4_val" value="', empty($modSettings['search_weight_subject']) ? '0' : $modSettings['search_weight_subject'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
+							<span id="weight4" class="search_weight">', $context['relative_weights']['search_weight_subject'], '%</span>
+						</dd>
+						<dt class="large_caption">
+							<a href="', $scripturl, '?action=helpadmin;help=search_weight_first_message" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a><label for="weight5_val">
+							', $txt['search_weight_first_message'], ':</label>
+						</dt>
+						<dd class="large_caption">
+							<span class="search_weight"><input type="text" name="search_weight_first_message" id="weight5_val" value="', empty($modSettings['search_weight_first_message']) ? '0' : $modSettings['search_weight_first_message'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
+							<span id="weight5" class="search_weight">', $context['relative_weights']['search_weight_first_message'], '%</span>
+						</dd>
+						<dt class="large_caption">
+							<a href="', $scripturl, '?action=helpadmin;help=search_weight_frequency" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" align="top" /></a><label for="weight6_val">
+							', $txt['search_weight_sticky'], ':</label>
+						</dt>
+						<dd class="large_caption">
+							<span class="search_weight"><input type="text" name="search_weight_sticky" id="weight6_val" value="', empty($modSettings['search_weight_sticky']) ? '0' : $modSettings['search_weight_sticky'], '" onchange="calculateNewValues()" size="3" class="input_text" /></span>
+							<span id="weight6" class="search_weight">', $context['relative_weights']['search_weight_sticky'], '%</span>
+						</dd>
+						<dt class="large_caption">
+							<strong>', $txt['search_weights_total'], '</strong>
+						</dt>
+						<dd class="large_caption">
+							<span id="weighttotal" class="search_weight"><strong>', $context['relative_weights']['total'], '</strong></span>
+							<span class="search_weight"><strong>100%</strong></span>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['search_weights_save'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-msw_token_var'], '" value="', $context['admin-msw_token'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_select_search_method()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=managesearch;sa=method" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['search_method'], '</h3>
+			</div>
+			<div class="information">
+				<div class="smalltext" style="font-weight: normal;"><a href="', $scripturl, '?action=helpadmin;help=search_why_use_index" onclick="return reqWin(this.href);">', $txt['search_create_index_why'], '</a></div>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+
+			';
+	if (!empty($context['table_info']))
+		echo '
+						<dt>
+							<strong>', $txt['search_method_messages_table_space'], ':</strong>
+						</dt>
+						<dd>
+							', $context['table_info']['data_length'], '
+						</dd>
+						<dt>
+							<strong>', $txt['search_method_messages_index_space'], ':</strong>
+						</dt>
+						<dd>
+							', $context['table_info']['index_length'], '
+						</dd>';
+	echo '
+					</dl>
+					', $context['double_index'] ? '<div class="information">
+					' . $txt['search_double_index'] . '</div>' : '', '
+					<fieldset class="search_settings floatleft">
+						<legend>', $txt['search_index'], '</legend>
+						<dl>
+							<dt><input type="radio" name="search_index" value=""', empty($modSettings['search_index']) ? ' checked="checked"' : '', ' class="input_radio" />
+							', $txt['search_index_none'], '
+							</dt>';
+
+	if ($context['supports_fulltext'])
+	{
+		echo '
+							<dt>
+								<input type="radio" name="search_index" value="fulltext"', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext' ? ' checked="checked"' : '', empty($context['fulltext_index']) ? ' onclick="alert(\'' . $txt['search_method_fulltext_warning'] . '\'); selectRadioByName(this.form.search_index, \'fulltext\');"': '', ' class="input_radio" />
+								', $txt['search_method_fulltext_index'], '
+							</dt>
+							<dd>
+
+								<span class="smalltext">';
+	if (empty($context['fulltext_index']) && empty($context['cannot_create_fulltext']))
+		echo '
+									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_no_index_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=createfulltext;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_method_fulltext_create'], '</a>]';
+	elseif (empty($context['fulltext_index']) && !empty($context['cannot_create_fulltext']))
+		echo '
+									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_fulltext_cannot_create'];
+	else
+		echo '
+									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_index_already_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=removefulltext;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_method_fulltext_remove'], '</a>]<br />
+									<strong>', $txt['search_index_size'], ':</strong> ', $context['table_info']['fulltext_length'];
+	echo '
+									</span>
+							</dd>';
+	}
+
+	echo '
+							<dt>
+								<input type="radio" name="search_index" value="custom"', !empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom' ? ' checked="checked"' : '', $context['custom_index'] ? '' : ' onclick="alert(\'' . $txt['search_index_custom_warning'] . '\'); selectRadioByName(this.form.search_method, \'1\');"', ' class="input_radio" />
+								', $txt['search_index_custom'], '
+							</dt>
+							<dd>
+								<span class="smalltext">';
+	if ($context['custom_index'])
+		echo '
+									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_index_already_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=removecustom;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_index_custom_remove'], '</a>]<br />
+									<strong>', $txt['search_index_size'], ':</strong> ', $context['table_info']['custom_index_length'];
+	elseif ($context['partial_custom_index'])
+		echo '
+									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_index_partial'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=removecustom;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_index_custom_remove'], '</a>] [<a href="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex;resume;', $context['session_var'], '=', $context['session_id'], ';', $context['admin-msm_token_var'], '=', $context['admin-msm_token'], '">', $txt['search_index_custom_resume'], '</a>]<br />
+									<strong>', $txt['search_index_size'], ':</strong> ', $context['table_info']['custom_index_length'];
+	else
+		echo '
+									<strong>', $txt['search_index_label'], ':</strong> ', $txt['search_method_no_index_exists'], ' [<a href="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex">', $txt['search_index_create_custom'], '</a>]';
+	echo '
+								</span>
+							</dd>';
+
+	foreach ($context['search_apis'] as $api)
+	{
+		if (empty($api['label']) || $api['has_template'])
+			continue;
+
+		echo '
+							<dt>
+								<input type="radio" name="search_index" value="', $api['setting_index'], '"', !empty($modSettings['search_index']) && $modSettings['search_index'] == $api['setting_index'] ? ' checked="checked"' : '', ' class="input_radio" />
+								', $api['label'] ,'
+							</dt>';
+
+	if ($api['desc'])
+		echo '
+							<dd>
+								<span class="smalltext">', $api['desc'], '</span>
+							</dd>';
+	}
+
+	echo '
+						</dl>
+					</fieldset>
+					<fieldset class="search_settings floatright">
+					<legend>', $txt['search_method'], '</legend>
+						<input type="checkbox" name="search_force_index" id="search_force_index_check" value="1"', empty($modSettings['search_force_index']) ? '' : ' checked="checked"', ' class="input_check" /><label for="search_force_index_check">', $txt['search_force_index'], '</label><br />
+						<input type="checkbox" name="search_match_words" id="search_match_words_check" value="1"', empty($modSettings['search_match_words']) ? '' : ' checked="checked"', ' class="input_check" /><label for="search_match_words_check">', $txt['search_match_words'], '</label>
+					</fieldset>
+					<hr class="hrcolor clear" />
+					<input type="submit" name="save" value="', $txt['search_method_save'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-msmpost_token_var'], '" value="', $context['admin-msmpost_token'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_create_index()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex;step=1" method="post" accept-charset="', $context['character_set'], '" name="create_index">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['search_create_index'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="predefine_select">', $txt['search_predefined'], ':</label>
+						</dt>
+						<dd>
+							<select name="bytes_per_word" id="predefine_select">
+								<option value="2">', $txt['search_predefined_small'], '</option>
+								<option value="4" selected="selected">', $txt['search_predefined_moderate'], '</option>
+								<option value="5">', $txt['search_predefined_large'], '</option>
+							</select>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['search_create_index_start'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+	</form>
+	</div>';
+}
+
+function template_create_index_progress()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=managesearch;sa=createmsgindex;step=1" name="autoSubmit" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['search_create_index'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<div><p>',
+						$txt['search_create_index_not_ready'], '</p>
+						<div class="progress_bar">
+							<div class="full_bar">', $context['percentage'], '%</div>
+							<div class="green_percent" style="width: ', $context['percentage'], '%;">&nbsp;</div>
+						</div>
+					</div>
+					<hr class="hrcolor" />
+					<input type="submit" name="b" value="', $txt['search_create_index_continue'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="step" value="', $context['step'], '" />
+			<input type="hidden" name="start" value="', $context['start'], '" />
+			<input type="hidden" name="bytes_per_word" value="', $context['index_settings']['bytes_per_word'], '" />
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>
+	<br class="clear" />
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var countdown = 10;
+		doAutoSubmit();
+
+		function doAutoSubmit()
+		{
+			if (countdown == 0)
+				document.forms.autoSubmit.submit();
+			else if (countdown == -1)
+				return;
+
+			document.forms.autoSubmit.b.value = "', $txt['search_create_index_continue'], ' (" + countdown + ")";
+			countdown--;
+
+			setTimeout("doAutoSubmit();", 1000);
+		}
+	// ]]></script>';
+
+}
+
+function template_create_index_done()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['search_create_index'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $txt['search_create_index_done'], '</p>
+				<p>
+					<strong><a href="', $scripturl, '?action=admin;area=managesearch;sa=method">', $txt['search_create_index_done_link'], '</a></strong>
+				</p>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+// Add or edit a search engine spider.
+function template_spider_edit()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=sengines;sa=editspiders;sid=', $context['spider']['id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['add_spider_desc'], '
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong><label for="spider_name">', $txt['spider_name'], ':</label></strong><br />
+							<span class="smalltext">', $txt['spider_name_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="spider_name" id="spider_name" value="', $context['spider']['name'], '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="spider_agent">', $txt['spider_agent'], ':</label></strong><br />
+							<span class="smalltext">', $txt['spider_agent_desc'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="spider_agent" id="spider_agent" value="', $context['spider']['agent'], '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="spider_ip">', $txt['spider_ip_info'], ':</label></strong><br />
+							<span class="smalltext">', $txt['spider_ip_info_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="spider_ip" id="spider_ip" rows="4" cols="20">', $context['spider']['ip_info'], '</textarea>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $context['page_title'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-ses_token_var'], '" value="', $context['admin-ses_token'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Show... spider... logs...
+function template_show_spider_logs()
+{
+	global $context, $txt, $settings, $scripturl;
+
+	echo '
+	<div id="admincenter">';
+
+	// Standard fields.
+	template_show_list('spider_logs');
+
+	echo '
+		<br />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['spider_logs_delete'], '</h3>
+		</div>
+		<form action="', $scripturl, '?action=admin;area=sengines;sa=logs" method="post" accept-charset="', $context['character_set'], '">
+			<div class="windowbg">
+				<div class="content">
+					<p>
+						', $txt['spider_logs_delete_older'], '
+						<input type="text" name="older" id="older" value="7" size="3" class="input_text" />
+						', $txt['spider_logs_delete_day'], '
+					</p>	
+					<hr class="hrcolor" />
+					<input type="submit" name="delete_entries" value="', $txt['spider_logs_delete_submit'], '" onclick="if (document.getElementById(\'older\').value &lt; 1 &amp;&amp; !confirm(\'' . addcslashes($txt['spider_logs_delete_confirm'], "'") . '\')) return false; return true;" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-sl_token_var'], '" value="', $context['admin-sl_token'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Show... spider... stats...
+function template_show_spider_stats()
+{
+	global $context, $txt, $settings, $scripturl;
+
+	echo '
+	<div id="admincenter">';
+
+	// Standard fields.
+	template_show_list('spider_stat_list');
+
+	echo '
+		<br />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['spider_logs_delete'], '</h3>
+		</div>
+		<form action="', $scripturl, '?action=admin;area=sengines;sa=stats" method="post" accept-charset="', $context['character_set'], '">
+			<div class="windowbg">
+				<div class="content">
+					<p>
+						', sprintf($txt['spider_stats_delete_older'], '<input type="text" name="older" id="older" value="90" size="3" class="input_text" />'), '
+					</p>
+					<hr class="hrcolor" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-ss_token_var'], '" value="', $context['admin-ss_token'], '" />
+					<input type="submit" name="delete_entries" value="', $txt['spider_logs_delete_submit'], '" onclick="if (document.getElementById(\'older\').value &lt; 1 &amp;&amp; !confirm(\'' . addcslashes($txt['spider_logs_delete_confirm'], "'") . '\')) return false; return true;" class="button_submit" />
+					<br />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 543 - 557
Themes/default/ManageSmileys.template.php

@@ -1,558 +1,544 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Editing the smiley sets.
-function template_editsets()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">';
-
-	template_show_list('smiley_set_list');
-
-	echo '
-		<br />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['smiley_sets_latest'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<div id="smileysLatest">', $txt['smiley_sets_latest_fetch'], '</div>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />
-	<script type="text/javascript"><!-- // --><![CDATA[
-		window.smfForum_scripturl = "', $scripturl, '";
-		window.smfForum_sessionid = "', $context['session_id'], '";
-		window.smfForum_sessionvar = "', $context['session_var'], '";
-	// ]]></script>';
-
-	if (empty($modSettings['disable_smf_js']))
-		echo '
-	<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-smileys.js"></script>';
-
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		function smfSetLatestSmileys()
-		{
-			if (typeof(window.smfLatestSmileys) != "undefined")
-				setInnerHTML(document.getElementById("smileysLatest"), window.smfLatestSmileys);';
-
-		if (!empty($context['selected_set']))
-			echo '
-
-			changeSet("', $context['selected_set'], '");';
-		if (!empty($context['selected_smiley']))
-			echo '
-			loadSmiley(', $context['selected_smiley'], ');';
-
-		echo '
-		}';
-
-		echo '
-			smfSetLatestSmileys();';
-
-		echo '
-	// ]]></script>';
-}
-
-// Modifying a smiley set.
-function template_modifyset()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=smileys;sa=editsets" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-				', $context['current_set']['is_new'] ? $txt['smiley_set_new'] : $txt['smiley_set_modify_existing'], '
-				</h3>
-			</div>';
-
-		// If this is an existing set, and there are still un-added smileys - offer an import opportunity.
-		if (!empty($context['current_set']['can_import']))
-		{
-			echo '
-			<div class="information">
-				', $context['current_set']['can_import'] == 1 ? $txt['smiley_set_import_single'] : $txt['smiley_set_import_multiple'], ' <a href="', $scripturl, '?action=admin;area=smileys;sa=import;set=', $context['current_set']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['here'], '</a> ', $context['current_set']['can_import'] == 1 ? $txt['smiley_set_to_import_single'] : $txt['smiley_set_to_import_multiple'], '
-			</div>';
-		}
-
-		echo '
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong><label for="smiley_sets_name">', $txt['smiley_sets_name'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="text" name="smiley_sets_name" id="smiley_sets_name" value="', $context['current_set']['name'], '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="smiley_sets_path">', $txt['smiley_sets_url'], '</label>: </strong>
-						</dt>
-						<dd>
-							', $modSettings['smileys_url'], '/';
-		if ($context['current_set']['id'] == 'default')
-			echo '<strong>default</strong><input type="hidden" name="smiley_sets_path" id="smiley_sets_path" value="default" />';
-		elseif (empty($context['smiley_set_dirs']))
-			echo '
-							<input type="text" name="smiley_sets_path" id="smiley_sets_path" value="', $context['current_set']['path'], '" class="input_text" /> ';
-		else
-		{
-			echo '
-							<select name="smiley_sets_path" id="smiley_sets_path">';
-			foreach ($context['smiley_set_dirs'] as $smiley_set_dir)
-				echo '
-								<option value="', $smiley_set_dir['id'], '"', $smiley_set_dir['current'] ? ' selected="selected"' : '', $smiley_set_dir['selectable'] ? '' : ' disabled="disabled"', '>', $smiley_set_dir['id'], '</option>';
-			echo '
-							</select> ';
-		}
-		echo '
-							/..
-						</dd>
-						<dt>
-							<strong><label for="smiley_sets_default">', $txt['smiley_set_select_default'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="checkbox" name="smiley_sets_default" id="smiley_sets_default" value="1"', $context['current_set']['selected'] ? ' checked="checked"' : '', ' class="input_check" />
-						</dd>';
-
-		// If this is a new smiley set they have the option to import smileys already in the directory.
-		if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable']))
-			echo '
-						<dt>
-							<strong><label for="smiley_sets_import">', $txt['smiley_set_import_directory'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="checkbox" name="smiley_sets_import" id="smiley_sets_import" value="1" class="input_check" />
-						</dd>';
-
-		echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['smiley_sets_save'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-mss_token_var'], '" value="', $context['admin-mss_token'], '" />
-			<input type="hidden" name="set" value="', $context['current_set']['id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Editing an individual smiley
-function template_modifysmiley()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=smileys;sa=editsmileys" method="post" accept-charset="', $context['character_set'], '" name="smileyForm" id="smileyForm">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['smiley_modify_existing'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['smiley_preview'], ': </strong>
-						</dt>
-						<dd>
-							<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['current_smiley']['filename'], '" id="preview" alt="" /> (', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();">';
-
-		foreach ($context['smiley_sets'] as $smiley_set)
-			echo '
-							<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected="selected"' : '', '>', $smiley_set['name'], '</option>';
-
-		echo '
-							</select>)
-						</dd>
-						<dt>
-							<strong><label for="smiley_code">', $txt['smileys_code'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="text" name="smiley_code" id="smiley_code" value="', $context['current_smiley']['code'], '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="smiley_filename">', $txt['smileys_filename'], '</label>: </strong>
-						</dt>
-						<dd>';
-			if (empty($context['filenames']))
-				echo '
-							<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" class="input_text" />';
-			else
-			{
-				echo '
-							<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();">';
-				foreach ($context['filenames'] as $filename)
-					echo '
-								<option value="', $filename['id'], '"', $filename['selected'] ? ' selected="selected"' : '', '>', $filename['id'], '</option>';
-				echo '
-							</select>';
-			}
-			echo '
-						</dd>
-						<dt>
-							<strong><label for="smiley_description">', $txt['smileys_description'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="text" name="smiley_description" id="smiley_description" value="', $context['current_smiley']['description'], '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="smiley_location">', $txt['smileys_location'], '</label>: </strong>
-						</dt>
-						<dd>
-							<select name="smiley_location" id="smiley_location">
-								<option value="0"', $context['current_smiley']['location'] == 0 ? ' selected="selected"' : '', '>
-									', $txt['smileys_location_form'], '
-								</option>
-								<option value="1"', $context['current_smiley']['location'] == 1 ? ' selected="selected"' : '', '>
-									', $txt['smileys_location_hidden'], '
-								</option>
-								<option value="2"', $context['current_smiley']['location'] == 2 ? ' selected="selected"' : '', '>
-									', $txt['smileys_location_popup'], '
-								</option>
-							</select>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="smiley_save" value="', $txt['smileys_save'], '" class="button_submit" />
-					<input type="submit" name="deletesmiley" value="', $txt['smileys_delete'], '" onclick="return confirm(\'', $txt['smileys_delete_confirm'], '\');" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="smiley" value="', $context['current_smiley']['id'], '" />
-		</form>
-	</div>
-	<br class="clear" />
-	<script type="text/javascript"><!-- // --><![CDATA[
-		function updatePreview()
-		{
-			var currentImage = document.getElementById("preview");
-			currentImage.src = "', $modSettings['smileys_url'], '/" + document.forms.smileyForm.set.value + "/" + document.forms.smileyForm.smiley_filename.value;
-		}
-	// ]]></script>';
-}
-
-// Adding a new smiley.
-function template_addsmiley()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=smileys;sa=addsmiley" method="post" accept-charset="', $context['character_set'], '" name="smileyForm" id="smileyForm" enctype="multipart/form-data">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['smileys_add_method'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<ul class="reset">
-						<li>
-							<label for="method-existing"><input type="radio" onclick="switchType();" name="method" id="method-existing" value="existing" checked="checked" class="input_radio" /> ', $txt['smileys_add_existing'], '</label>
-						</li>
-						<li>
-							<label for="method-upload"><input type="radio" onclick="switchType();" name="method" id="method-upload" value="upload" class="input_radio" /> ', $txt['smileys_add_upload'], '</label>
-						</li>
-					</ul>
-					<br />
-					<fieldset id="ex_settings">
-						<dl class="settings">
-							<dt>
-								<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['filenames'][0]['id'], '" id="preview" alt="" />
-							</dt>
-							<dd>
-								', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();selectMethod(\'existing\');">
-
-							';
-
-		foreach ($context['smiley_sets'] as $smiley_set)
-			echo '
-								<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected="selected"' : '', '>', $smiley_set['name'], '</option>';
-
-		echo '
-								</select>
-							</dd>
-							<dt>
-								<strong><label for="smiley_filename">', $txt['smileys_filename'], '</label>: </strong>
-							</dt>
-							<dd>';
-	if (empty($context['filenames']))
-		echo '
-								<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" onchange="selectMethod(\'existing\');" class="input_text" />';
-	else
-	{
-		echo '
-									<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();selectMethod(\'existing\');">';
-		foreach ($context['filenames'] as $filename)
-			echo '
-									<option value="', $filename['id'], '"', $filename['selected'] ? ' selected="selected"' : '', '>', $filename['id'], '</option>';
-		echo '
-								</select>';
-	}
-
-	echo '
-							</dd>
-						</dl>
-					</fieldset>
-					<fieldset id="ul_settings" style="display: none;">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['smileys_add_upload_choose'], ':</strong><br />
-								<span class="smalltext">', $txt['smileys_add_upload_choose_desc'], '</span>
-							</dt>
-							<dd>
-								<input type="file" name="uploadSmiley" id="uploadSmiley" onchange="selectMethod(\'upload\');" class="input_file" />
-							</dd>
-							<dt>
-								<strong><label for="sameall">', $txt['smileys_add_upload_all'], ':</label></strong>
-							</dt>
-							<dd>
-								<input type="checkbox" name="sameall" id="sameall" checked="checked" class="input_check" onclick="swapUploads(); selectMethod(\'upload\');" />
-							</dd>
-						</dl>
-					</fieldset>
-
-					<dl id="uploadMore" style="display: none;" class="settings">';
-	foreach ($context['smiley_sets'] as $smiley_set)
-		echo '
-						<dt>
-							', $txt['smileys_add_upload_for1'], ' <strong>', $smiley_set['name'], '</strong> ', $txt['smileys_add_upload_for2'], ':
-						</dt>
-						<dd>
-							<input type="file" name="individual_', $smiley_set['name'], '" onchange="selectMethod(\'upload\');" class="input_file" />
-						</dd>';
-	echo '
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br class="clear" />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['smiley_new'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong><label for="smiley_code">', $txt['smileys_code'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="text" name="smiley_code" id="smiley_code" value="" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="smiley_description">', $txt['smileys_description'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="text" name="smiley_description" id="smiley_description" value="" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="smiley_location">', $txt['smileys_location'], '</label>: </strong>
-						</dt>
-						<dd>
-							<select name="smiley_location" id="smiley_location">
-								<option value="0" selected="selected">
-									', $txt['smileys_location_form'], '
-								</option>
-								<option value="1">
-									', $txt['smileys_location_hidden'], '
-								</option>
-								<option value="2">
-									', $txt['smileys_location_popup'], '
-								</option>
-							</select>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="smiley_save" value="', $txt['smileys_save'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Ordering smileys.
-function template_setorder()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">';
-
-	foreach ($context['smileys'] as $location)
-	{
-		echo '
-		<form action="', $scripturl, '?action=admin;area=smileys;sa=editsmileys" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $location['title'], '</h3>
-			</div>
-			<div class="information">
-				', $location['description'], '
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<strong>', empty($context['move_smiley']) ? $txt['smileys_move_select_smiley'] : $txt['smileys_move_select_destination'], '...</strong><br />';
-		foreach ($location['rows'] as $row)
-		{
-			if (!empty($context['move_smiley']))
-				echo '
-					<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $row[0]['row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $txt['smileys_move_here'], '" /></a>';
-
-			foreach ($row as $smiley)
-			{
-				if (empty($context['move_smiley']))
-					echo '<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;move=', $smiley['id'], '"><img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" style="padding: 2px; border: 0px solid black;" alt="', $smiley['description'], '" /></a>';
-				else
-					echo '<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" style="padding: 2px; border: ', $smiley['selected'] ? '2px solid red' : '0px solid black', ';" alt="', $smiley['description'], '" /><a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';after=', $smiley['id'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '" title="', $txt['smileys_move_here'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $txt['smileys_move_here'], '" /></a>';
-			}
-
-			echo '
-					<br />';
-		}
-		if (!empty($context['move_smiley']))
-			echo '
-					<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $location['last_row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $txt['smileys_move_here'], '" /></a>';
-		echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		<input type="hidden" name="reorder" value="1" />
-	</form>
-	<br />';
-	}
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-// Editing Message Icons
-function template_editicons()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	template_show_list('message_icon_list');
-}
-
-// Editing an individual message icon
-function template_editicon()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=smileys;sa=editicon;icon=', $context['new_icon'] ? '0' : $context['icon']['id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $context['new_icon'] ? $txt['icons_new_icon'] : $txt['icons_edit_icon'], '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-	if (!$context['new_icon'])
-		echo '
-						<dt>
-							<strong>', $txt['smiley_preview'], ': </strong>
-						</dt>
-						<dd>
-							<img src="', $context['icon']['image_url'], '" alt="', $context['icon']['title'], '" />
-						</dd>';
-	echo '
-						<dt>
-							<strong><label for="icon_filename">', $txt['smileys_filename'], '</label>: </strong><br /><span class="smalltext">', $txt['icons_filename_all_png'], '</span>
-						</dt>
-						<dd>
-							<input type="text" name="icon_filename" id="icon_filename" value="', !empty($context['icon']['filename']) ? $context['icon']['filename'] . '.gif' : '', '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="icon_description">', $txt['smileys_description'], '</label>: </strong>
-						</dt>
-						<dd>
-							<input type="text" name="icon_description" id="icon_description" value="', !empty($context['icon']['title']) ? $context['icon']['title'] : '', '" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="icon_board_select">', $txt['icons_board'], '</label>: </strong>
-						</dt>
-						<dd>
-							<select name="icon_board" id="icon_board_select">
-								<option value="0"', empty($context['icon']['board_id']) ? ' selected="selected"' : '', '>', $txt['icons_edit_icons_all_boards'], '</option>';
-
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-								<optgroup label="', $category['name'], '">';
-		foreach ($category['boards'] as $board)
-			echo '
-									<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
-		echo '
-								</optgroup>';
-	}
-	echo '
-							</select>
-						</dd>
-						<dt>
-							<strong><label for="icon_location">', $txt['smileys_location'], '</label>: </strong>
-						</dt>
-						<dd>
-							<select name="icon_location" id="icon_location">
-								<option value="0"', empty($context['icon']['after']) ? ' selected="selected"' : '', '>', $txt['icons_location_first_icon'], '</option>';
-
-	// Print the list of all the icons it can be put after...
-	foreach ($context['icons'] as $id => $data)
-		if (empty($context['icon']['id']) || $id != $context['icon']['id'])
-			echo '
-								<option value="', $id, '"', !empty($context['icon']['after']) && $id == $context['icon']['after'] ? ' selected="selected"' : '', '>', $txt['icons_location_after'], ': ', $data['title'], '</option>';
-
-	echo '
-							</select>
-						</dd>
-					</dl>';
-
-	if (!$context['new_icon'])
-		echo '
-					<input type="hidden" name="icon" value="', $context['icon']['id'], '" />';
-
-	echo '
-					<hr class="hrcolor" />
-					<input type="submit" name="icons_save" value="', $txt['smileys_save'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Editing the smiley sets.
+function template_editsets()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">';
+
+	template_show_list('smiley_set_list');
+
+	echo '
+		<br />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['smiley_sets_latest'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<div id="smileysLatest">', $txt['smiley_sets_latest_fetch'], '</div>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />
+	<script type="text/javascript"><!-- // --><![CDATA[
+		window.smfForum_scripturl = "', $scripturl, '";
+		window.smfForum_sessionid = "', $context['session_id'], '";
+		window.smfForum_sessionvar = "', $context['session_var'], '";
+	// ]]></script>';
+
+	if (empty($modSettings['disable_smf_js']))
+		echo '
+	<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-smileys.js"></script>';
+
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		function smfSetLatestSmileys()
+		{
+			if (typeof(window.smfLatestSmileys) != "undefined")
+				setInnerHTML(document.getElementById("smileysLatest"), window.smfLatestSmileys);';
+
+		if (!empty($context['selected_set']))
+			echo '
+
+			changeSet("', $context['selected_set'], '");';
+		if (!empty($context['selected_smiley']))
+			echo '
+			loadSmiley(', $context['selected_smiley'], ');';
+
+		echo '
+		}';
+
+		echo '
+			smfSetLatestSmileys();';
+
+		echo '
+	// ]]></script>';
+}
+
+// Modifying a smiley set.
+function template_modifyset()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=smileys;sa=editsets" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+				', $context['current_set']['is_new'] ? $txt['smiley_set_new'] : $txt['smiley_set_modify_existing'], '
+				</h3>
+			</div>';
+
+		// If this is an existing set, and there are still un-added smileys - offer an import opportunity.
+		if (!empty($context['current_set']['can_import']))
+		{
+			echo '
+			<div class="information">
+				', $context['current_set']['can_import'] == 1 ? $txt['smiley_set_import_single'] : $txt['smiley_set_import_multiple'], ' <a href="', $scripturl, '?action=admin;area=smileys;sa=import;set=', $context['current_set']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['here'], '</a> ', $context['current_set']['can_import'] == 1 ? $txt['smiley_set_to_import_single'] : $txt['smiley_set_to_import_multiple'], '
+			</div>';
+		}
+
+		echo '
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong><label for="smiley_sets_name">', $txt['smiley_sets_name'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="text" name="smiley_sets_name" id="smiley_sets_name" value="', $context['current_set']['name'], '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="smiley_sets_path">', $txt['smiley_sets_url'], '</label>: </strong>
+						</dt>
+						<dd>
+							', $modSettings['smileys_url'], '/';
+		if ($context['current_set']['id'] == 'default')
+			echo '<strong>default</strong><input type="hidden" name="smiley_sets_path" id="smiley_sets_path" value="default" />';
+		elseif (empty($context['smiley_set_dirs']))
+			echo '
+							<input type="text" name="smiley_sets_path" id="smiley_sets_path" value="', $context['current_set']['path'], '" class="input_text" /> ';
+		else
+		{
+			echo '
+							<select name="smiley_sets_path" id="smiley_sets_path">';
+			foreach ($context['smiley_set_dirs'] as $smiley_set_dir)
+				echo '
+								<option value="', $smiley_set_dir['id'], '"', $smiley_set_dir['current'] ? ' selected="selected"' : '', $smiley_set_dir['selectable'] ? '' : ' disabled="disabled"', '>', $smiley_set_dir['id'], '</option>';
+			echo '
+							</select> ';
+		}
+		echo '
+							/..
+						</dd>
+						<dt>
+							<strong><label for="smiley_sets_default">', $txt['smiley_set_select_default'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="checkbox" name="smiley_sets_default" id="smiley_sets_default" value="1"', $context['current_set']['selected'] ? ' checked="checked"' : '', ' class="input_check" />
+						</dd>';
+
+		// If this is a new smiley set they have the option to import smileys already in the directory.
+		if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable']))
+			echo '
+						<dt>
+							<strong><label for="smiley_sets_import">', $txt['smiley_set_import_directory'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="checkbox" name="smiley_sets_import" id="smiley_sets_import" value="1" class="input_check" />
+						</dd>';
+
+		echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['smiley_sets_save'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-mss_token_var'], '" value="', $context['admin-mss_token'], '" />
+			<input type="hidden" name="set" value="', $context['current_set']['id'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Editing an individual smiley
+function template_modifysmiley()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=smileys;sa=editsmileys" method="post" accept-charset="', $context['character_set'], '" name="smileyForm" id="smileyForm">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['smiley_modify_existing'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['smiley_preview'], ': </strong>
+						</dt>
+						<dd>
+							<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['current_smiley']['filename'], '" id="preview" alt="" /> (', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();">';
+
+		foreach ($context['smiley_sets'] as $smiley_set)
+			echo '
+							<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected="selected"' : '', '>', $smiley_set['name'], '</option>';
+
+		echo '
+							</select>)
+						</dd>
+						<dt>
+							<strong><label for="smiley_code">', $txt['smileys_code'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="text" name="smiley_code" id="smiley_code" value="', $context['current_smiley']['code'], '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="smiley_filename">', $txt['smileys_filename'], '</label>: </strong>
+						</dt>
+						<dd>';
+			if (empty($context['filenames']))
+				echo '
+							<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" class="input_text" />';
+			else
+			{
+				echo '
+							<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();">';
+				foreach ($context['filenames'] as $filename)
+					echo '
+								<option value="', $filename['id'], '"', $filename['selected'] ? ' selected="selected"' : '', '>', $filename['id'], '</option>';
+				echo '
+							</select>';
+			}
+			echo '
+						</dd>
+						<dt>
+							<strong><label for="smiley_description">', $txt['smileys_description'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="text" name="smiley_description" id="smiley_description" value="', $context['current_smiley']['description'], '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="smiley_location">', $txt['smileys_location'], '</label>: </strong>
+						</dt>
+						<dd>
+							<select name="smiley_location" id="smiley_location">
+								<option value="0"', $context['current_smiley']['location'] == 0 ? ' selected="selected"' : '', '>
+									', $txt['smileys_location_form'], '
+								</option>
+								<option value="1"', $context['current_smiley']['location'] == 1 ? ' selected="selected"' : '', '>
+									', $txt['smileys_location_hidden'], '
+								</option>
+								<option value="2"', $context['current_smiley']['location'] == 2 ? ' selected="selected"' : '', '>
+									', $txt['smileys_location_popup'], '
+								</option>
+							</select>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="smiley_save" value="', $txt['smileys_save'], '" class="button_submit" />
+					<input type="submit" name="deletesmiley" value="', $txt['smileys_delete'], '" onclick="return confirm(\'', $txt['smileys_delete_confirm'], '\');" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="smiley" value="', $context['current_smiley']['id'], '" />
+		</form>
+	</div>
+	<br class="clear" />
+	<script type="text/javascript"><!-- // --><![CDATA[
+		function updatePreview()
+		{
+			var currentImage = document.getElementById("preview");
+			currentImage.src = "', $modSettings['smileys_url'], '/" + document.forms.smileyForm.set.value + "/" + document.forms.smileyForm.smiley_filename.value;
+		}
+	// ]]></script>';
+}
+
+// Adding a new smiley.
+function template_addsmiley()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=smileys;sa=addsmiley" method="post" accept-charset="', $context['character_set'], '" name="smileyForm" id="smileyForm" enctype="multipart/form-data">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['smileys_add_method'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<ul class="reset">
+						<li>
+							<label for="method-existing"><input type="radio" onclick="switchType();" name="method" id="method-existing" value="existing" checked="checked" class="input_radio" /> ', $txt['smileys_add_existing'], '</label>
+						</li>
+						<li>
+							<label for="method-upload"><input type="radio" onclick="switchType();" name="method" id="method-upload" value="upload" class="input_radio" /> ', $txt['smileys_add_upload'], '</label>
+						</li>
+					</ul>
+					<br />
+					<fieldset id="ex_settings">
+						<dl class="settings">
+							<dt>
+								<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['filenames'][0]['id'], '" id="preview" alt="" />
+							</dt>
+							<dd>
+								', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();selectMethod(\'existing\');">
+
+							';
+
+		foreach ($context['smiley_sets'] as $smiley_set)
+			echo '
+								<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected="selected"' : '', '>', $smiley_set['name'], '</option>';
+
+		echo '
+								</select>
+							</dd>
+							<dt>
+								<strong><label for="smiley_filename">', $txt['smileys_filename'], '</label>: </strong>
+							</dt>
+							<dd>';
+	if (empty($context['filenames']))
+		echo '
+								<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" onchange="selectMethod(\'existing\');" class="input_text" />';
+	else
+	{
+		echo '
+									<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();selectMethod(\'existing\');">';
+		foreach ($context['filenames'] as $filename)
+			echo '
+									<option value="', $filename['id'], '"', $filename['selected'] ? ' selected="selected"' : '', '>', $filename['id'], '</option>';
+		echo '
+								</select>';
+	}
+
+	echo '
+							</dd>
+						</dl>
+					</fieldset>
+					<fieldset id="ul_settings" style="display: none;">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['smileys_add_upload_choose'], ':</strong><br />
+								<span class="smalltext">', $txt['smileys_add_upload_choose_desc'], '</span>
+							</dt>
+							<dd>
+								<input type="file" name="uploadSmiley" id="uploadSmiley" onchange="selectMethod(\'upload\');" class="input_file" />
+							</dd>
+							<dt>
+								<strong><label for="sameall">', $txt['smileys_add_upload_all'], ':</label></strong>
+							</dt>
+							<dd>
+								<input type="checkbox" name="sameall" id="sameall" checked="checked" class="input_check" onclick="swapUploads(); selectMethod(\'upload\');" />
+							</dd>
+						</dl>
+					</fieldset>
+
+					<dl id="uploadMore" style="display: none;" class="settings">';
+	foreach ($context['smiley_sets'] as $smiley_set)
+		echo '
+						<dt>
+							', $txt['smileys_add_upload_for1'], ' <strong>', $smiley_set['name'], '</strong> ', $txt['smileys_add_upload_for2'], ':
+						</dt>
+						<dd>
+							<input type="file" name="individual_', $smiley_set['name'], '" onchange="selectMethod(\'upload\');" class="input_file" />
+						</dd>';
+	echo '
+					</dl>
+				</div>
+			</div>
+			<br class="clear" />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['smiley_new'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong><label for="smiley_code">', $txt['smileys_code'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="text" name="smiley_code" id="smiley_code" value="" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="smiley_description">', $txt['smileys_description'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="text" name="smiley_description" id="smiley_description" value="" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="smiley_location">', $txt['smileys_location'], '</label>: </strong>
+						</dt>
+						<dd>
+							<select name="smiley_location" id="smiley_location">
+								<option value="0" selected="selected">
+									', $txt['smileys_location_form'], '
+								</option>
+								<option value="1">
+									', $txt['smileys_location_hidden'], '
+								</option>
+								<option value="2">
+									', $txt['smileys_location_popup'], '
+								</option>
+							</select>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="smiley_save" value="', $txt['smileys_save'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Ordering smileys.
+function template_setorder()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">';
+
+	foreach ($context['smileys'] as $location)
+	{
+		echo '
+		<form action="', $scripturl, '?action=admin;area=smileys;sa=editsmileys" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $location['title'], '</h3>
+			</div>
+			<div class="information">
+				', $location['description'], '
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<strong>', empty($context['move_smiley']) ? $txt['smileys_move_select_smiley'] : $txt['smileys_move_select_destination'], '...</strong><br />';
+		foreach ($location['rows'] as $row)
+		{
+			if (!empty($context['move_smiley']))
+				echo '
+					<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $row[0]['row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $txt['smileys_move_here'], '" /></a>';
+
+			foreach ($row as $smiley)
+			{
+				if (empty($context['move_smiley']))
+					echo '<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;move=', $smiley['id'], '"><img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" style="padding: 2px; border: 0px solid black;" alt="', $smiley['description'], '" /></a>';
+				else
+					echo '<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" style="padding: 2px; border: ', $smiley['selected'] ? '2px solid red' : '0px solid black', ';" alt="', $smiley['description'], '" /><a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';after=', $smiley['id'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '" title="', $txt['smileys_move_here'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $txt['smileys_move_here'], '" /></a>';
+			}
+
+			echo '
+					<br />';
+		}
+		if (!empty($context['move_smiley']))
+			echo '
+					<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $location['last_row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/smiley_select_spot.png" alt="', $txt['smileys_move_here'], '" /></a>';
+		echo '
+				</div>
+			</div>
+		<input type="hidden" name="reorder" value="1" />
+	</form>
+	<br />';
+	}
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+// Editing Message Icons
+function template_editicons()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	template_show_list('message_icon_list');
+}
+
+// Editing an individual message icon
+function template_editicon()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=smileys;sa=editicon;icon=', $context['new_icon'] ? '0' : $context['icon']['id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $context['new_icon'] ? $txt['icons_new_icon'] : $txt['icons_edit_icon'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">';
+	if (!$context['new_icon'])
+		echo '
+						<dt>
+							<strong>', $txt['smiley_preview'], ': </strong>
+						</dt>
+						<dd>
+							<img src="', $context['icon']['image_url'], '" alt="', $context['icon']['title'], '" />
+						</dd>';
+	echo '
+						<dt>
+							<strong><label for="icon_filename">', $txt['smileys_filename'], '</label>: </strong><br /><span class="smalltext">', $txt['icons_filename_all_png'], '</span>
+						</dt>
+						<dd>
+							<input type="text" name="icon_filename" id="icon_filename" value="', !empty($context['icon']['filename']) ? $context['icon']['filename'] . '.gif' : '', '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="icon_description">', $txt['smileys_description'], '</label>: </strong>
+						</dt>
+						<dd>
+							<input type="text" name="icon_description" id="icon_description" value="', !empty($context['icon']['title']) ? $context['icon']['title'] : '', '" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="icon_board_select">', $txt['icons_board'], '</label>: </strong>
+						</dt>
+						<dd>
+							<select name="icon_board" id="icon_board_select">
+								<option value="0"', empty($context['icon']['board_id']) ? ' selected="selected"' : '', '>', $txt['icons_edit_icons_all_boards'], '</option>';
+
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+								<optgroup label="', $category['name'], '">';
+		foreach ($category['boards'] as $board)
+			echo '
+									<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
+		echo '
+								</optgroup>';
+	}
+	echo '
+							</select>
+						</dd>
+						<dt>
+							<strong><label for="icon_location">', $txt['smileys_location'], '</label>: </strong>
+						</dt>
+						<dd>
+							<select name="icon_location" id="icon_location">
+								<option value="0"', empty($context['icon']['after']) ? ' selected="selected"' : '', '>', $txt['icons_location_first_icon'], '</option>';
+
+	// Print the list of all the icons it can be put after...
+	foreach ($context['icons'] as $id => $data)
+		if (empty($context['icon']['id']) || $id != $context['icon']['id'])
+			echo '
+								<option value="', $id, '"', !empty($context['icon']['after']) && $id == $context['icon']['after'] ? ' selected="selected"' : '', '>', $txt['icons_location_after'], ': ', $data['title'], '</option>';
+
+	echo '
+							</select>
+						</dd>
+					</dl>';
+
+	if (!$context['new_icon'])
+		echo '
+					<input type="hidden" name="icon" value="', $context['icon']['id'], '" />';
+
+	echo '
+					<hr class="hrcolor" />
+					<input type="submit" name="icons_save" value="', $txt['smileys_save'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 204 - 211
Themes/default/Memberlist.template.php

@@ -1,212 +1,205 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Displays a sortable listing of all members registered on the forum.
-function template_main()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div class="main_section" id="memberlist">
-		<div class="cat_bar">
-			<h4 class="catbg">
-				<span class="floatleft">', $txt['members_list'], '</span>';
-		if (!isset($context['old_search']))
-				echo '
-				<span class="floatright">', $context['letter_links'], '</span>';
-		echo '
-			</h4>
-		</div>
-		<div class="pagesection">
-			', template_button_strip($context['memberlist_buttons'], 'right'), '
-			<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
-		</div>';
-
-	echo '
-		<div id="mlist" class="tborder topic_table">
-			<table class="table_grid" cellspacing="0" width="100%">
-			<thead>
-				<tr class="catbg">';
-
-	// Display each of the column headers of the table.
-	foreach ($context['columns'] as $key => $column)
-	{
-		// @TODO maybe find something nicer?
-		if ($key == 'email_address' && !$context['can_send_email'])
-			continue;
-
-		// This is a selected column, so underline it or some such.
-		if ($column['selected'])
-			echo '
-					<th scope="col" class="', isset($column['class']) ? ' ' . $column['class'] : '', '" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . ' nowrap="nowrap">
-						<a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" /></th>';
-		// This is just some column... show the link and be done with it.
-		else
-			echo '
-					<th scope="col" class="', isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' width="' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '>
-						', $column['link'], '</th>';
-	}
-	echo '
-				</tr>
-			</thead>
-			<tbody>';
-
-	// Assuming there are members loop through each one displaying their data.
-	$alternate = true;
-	if (!empty($context['members']))
-	{
-		foreach ($context['members'] as $member)
-		{
-			echo '
-				<tr class="windowbg', $alternate ? '2' : '', '"', empty($member['sort_letter']) ? '' : ' id="letter' . $member['sort_letter'] . '"', '>
-					<td class="centertext">
-						', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['text'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" class="centericon" />' : $member['online']['label'], $context['can_send_pm'] ? '</a>' : '', '
-					</td>
-					<td class="lefttext">', $member['link'], '</td>';
-			if ($context['can_send_email'])
-				echo '
-					<td class="centertext">', $member['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $member['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $member['name'] . '" /></a>', '</td>';
-
-		if (!isset($context['disabled_fields']['website']))
-			echo '
-					<td class="centertext">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" class="new_win"><img src="' . $settings['images_url'] . '/www.png" alt="' . $member['website']['title'] . '" title="' . $member['website']['title'] . '" /></a>' : '', '</td>';
-
-		// ICQ?
-		if (!isset($context['disabled_fields']['icq']))
-			echo '
-					<td class="centertext">', $member['icq']['link'], '</td>';
-
-		// AIM?
-		if (!isset($context['disabled_fields']['aim']))
-			echo '
-					<td class="centertext">', $member['aim']['link'], '</td>';
-
-		// YIM?
-		if (!isset($context['disabled_fields']['yim']))
-			echo '
-					<td class="centertext">', $member['yim']['link'], '</td>';
-
-		// MSN?
-		if (!isset($context['disabled_fields']['msn']))
-			echo '
-					<td class="centertext">', $member['msn']['link'], '</td>';
-
-		// Group and date.
-		echo '
-					<td class="lefttext">', empty($member['group']) ? $member['post_group'] : $member['group'], '</td>
-					<td class="lefttext">', $member['registered_date'], '</td>';
-
-		if (!isset($context['disabled_fields']['posts']))
-		{
-			echo '
-					<td style="white-space: nowrap" width="15">', $member['posts'], '</td>
-					<td class="statsbar" width="120">';
-
-			if (!empty($member['post_percent']))
-				echo '
-						<div class="bar" style="width: ', $member['post_percent'] + 4, 'px;">
-							<div style="width: ', $member['post_percent'], 'px;"></div>
-						</div>';
-
-			echo '
-					</td>';
-		}
-
-		echo '
-				</tr>';
-				
-			$alternate = !$alternate;
-		}
-	}
-	// No members?
-	else
-		echo '
-				<tr>
-					<td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td>
-				</tr>';
-
-				echo '
-			</tbody>
-			</table>
-		</div>';
-		
-	// Show the page numbers again. (makes 'em easier to find!)
-	echo '
-		<div class="pagesection">
-			<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>';
-
-	// If it is displaying the result of a search show a "search again" link to edit their criteria.
-	if (isset($context['old_search']))
-		echo '
-			<a class="button_link" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>';
-	echo '
-		</div>
-	</div>';
-
-}
-
-// A page allowing people to search the member list.
-function template_search()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Start the submission form for the search!
-	echo '
-	<form action="', $scripturl, '?action=mlist;sa=search" method="post" accept-charset="', $context['character_set'], '">
-		<div id="memberlist">
-			<div class="cat_bar">
-				<h3 class="catbg mlist">
-					<span class="ie6_header floatleft">', !empty($settings['use_buttons']) ? '<img src="' . $settings['images_url'] . '/buttons/search.png" alt="" class="icon" />' : '', $txt['mlist_search'], '</span>
-				</h3>
-			</div>
-			<div class="pagesection">
-				', template_button_strip($context['memberlist_buttons'], 'right'), '
-			</div>';
-	
-	// Display the input boxes for the form.
-	echo '	<div id="memberlist_search" class="clear">
-				<span class="upperframe"><span></span></span>';
-	
-	echo '
-				<div class="roundframe">
-					<dl id="mlist_search" class="settings">
-						<dt>
-							<label><strong>', $txt['search_for'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="search" value="', $context['old_search'], '" size="40" class="input_text" />
-						</dd>
-						<dt>
-							<label><strong>', $txt['mlist_search_filter'], ':</strong></label>
-						</dt>';
-
-	foreach ($context['search_fields'] as $id => $title)
-	{
-		echo '
-						<dd>
-							<label for="fields-', $id, '"><input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '" ', in_array($id, $context['search_defaults']) ? 'checked="checked"' : '', ' class="input_check floatright" />', $title, '</label>
-						</dd>';
-	}
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="submit" value="' . $txt['search'] . '" class="button_submit" />
-					<br class="clear_right" />
-				</div>';	
-	echo '
-				<span class="lowerframe"><span></span></span>
-			</div>
-		</div>
-	</form>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Displays a sortable listing of all members registered on the forum.
+function template_main()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div class="main_section" id="memberlist">
+		<div class="cat_bar">
+			<h4 class="catbg">
+				<span class="floatleft">', $txt['members_list'], '</span>';
+		if (!isset($context['old_search']))
+				echo '
+				<span class="floatright">', $context['letter_links'], '</span>';
+		echo '
+			</h4>
+		</div>
+		<div class="pagesection">
+			', template_button_strip($context['memberlist_buttons'], 'right'), '
+			<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
+		</div>';
+
+	echo '
+		<div id="mlist" class="tborder topic_table">
+			<table class="table_grid" cellspacing="0" width="100%">
+			<thead>
+				<tr class="catbg">';
+
+	// Display each of the column headers of the table.
+	foreach ($context['columns'] as $key => $column)
+	{
+		// @TODO maybe find something nicer?
+		if ($key == 'email_address' && !$context['can_send_email'])
+			continue;
+
+		// This is a selected column, so underline it or some such.
+		if ($column['selected'])
+			echo '
+					<th scope="col" class="', isset($column['class']) ? ' ' . $column['class'] : '', '" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . ' nowrap="nowrap">
+						<a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" /></th>';
+		// This is just some column... show the link and be done with it.
+		else
+			echo '
+					<th scope="col" class="', isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' width="' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '>
+						', $column['link'], '</th>';
+	}
+	echo '
+				</tr>
+			</thead>
+			<tbody>';
+
+	// Assuming there are members loop through each one displaying their data.
+	$alternate = true;
+	if (!empty($context['members']))
+	{
+		foreach ($context['members'] as $member)
+		{
+			echo '
+				<tr class="windowbg', $alternate ? '2' : '', '"', empty($member['sort_letter']) ? '' : ' id="letter' . $member['sort_letter'] . '"', '>
+					<td class="centertext">
+						', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['text'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" class="centericon" />' : $member['online']['label'], $context['can_send_pm'] ? '</a>' : '', '
+					</td>
+					<td class="lefttext">', $member['link'], '</td>';
+			if ($context['can_send_email'])
+				echo '
+					<td class="centertext">', $member['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $member['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $member['name'] . '" /></a>', '</td>';
+
+		if (!isset($context['disabled_fields']['website']))
+			echo '
+					<td class="centertext">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" class="new_win"><img src="' . $settings['images_url'] . '/www.png" alt="' . $member['website']['title'] . '" title="' . $member['website']['title'] . '" /></a>' : '', '</td>';
+
+		// ICQ?
+		if (!isset($context['disabled_fields']['icq']))
+			echo '
+					<td class="centertext">', $member['icq']['link'], '</td>';
+
+		// AIM?
+		if (!isset($context['disabled_fields']['aim']))
+			echo '
+					<td class="centertext">', $member['aim']['link'], '</td>';
+
+		// YIM?
+		if (!isset($context['disabled_fields']['yim']))
+			echo '
+					<td class="centertext">', $member['yim']['link'], '</td>';
+
+		// MSN?
+		if (!isset($context['disabled_fields']['msn']))
+			echo '
+					<td class="centertext">', $member['msn']['link'], '</td>';
+
+		// Group and date.
+		echo '
+					<td class="lefttext">', empty($member['group']) ? $member['post_group'] : $member['group'], '</td>
+					<td class="lefttext">', $member['registered_date'], '</td>';
+
+		if (!isset($context['disabled_fields']['posts']))
+		{
+			echo '
+					<td style="white-space: nowrap" width="15">', $member['posts'], '</td>
+					<td class="statsbar" width="120">';
+
+			if (!empty($member['post_percent']))
+				echo '
+						<div class="bar" style="width: ', $member['post_percent'] + 4, 'px;">
+							<div style="width: ', $member['post_percent'], 'px;"></div>
+						</div>';
+
+			echo '
+					</td>';
+		}
+
+		echo '
+				</tr>';
+				
+			$alternate = !$alternate;
+		}
+	}
+	// No members?
+	else
+		echo '
+				<tr>
+					<td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td>
+				</tr>';
+
+				echo '
+			</tbody>
+			</table>
+		</div>';
+		
+	// Show the page numbers again. (makes 'em easier to find!)
+	echo '
+		<div class="pagesection">
+			<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>';
+
+	// If it is displaying the result of a search show a "search again" link to edit their criteria.
+	if (isset($context['old_search']))
+		echo '
+			<a class="button_link" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>';
+	echo '
+		</div>
+	</div>';
+
+}
+
+// A page allowing people to search the member list.
+function template_search()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Start the submission form for the search!
+	echo '
+	<form action="', $scripturl, '?action=mlist;sa=search" method="post" accept-charset="', $context['character_set'], '">
+		<div id="memberlist">
+			<div class="cat_bar">
+				<h3 class="catbg mlist">
+					', !empty($settings['use_buttons']) ? '<img src="' . $settings['images_url'] . '/buttons/search.png" alt="" class="icon" />' : '', $txt['mlist_search'], '
+				</h3>
+			</div>
+			<div class="pagesection">
+				', template_button_strip($context['memberlist_buttons'], 'right'), '
+			</div>
+			<div id="memberlist_search" class="clear">
+				<div class="roundframe">
+					<dl id="mlist_search" class="settings">
+						<dt>
+							<label><strong>', $txt['search_for'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="search" value="', $context['old_search'], '" size="40" class="input_text" />
+						</dd>
+						<dt>
+							<label><strong>', $txt['mlist_search_filter'], ':</strong></label>
+						</dt>';
+
+	foreach ($context['search_fields'] as $id => $title)
+	{
+		echo '
+						<dd>
+							<label for="fields-', $id, '"><input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '" ', in_array($id, $context['search_defaults']) ? 'checked="checked"' : '', ' class="input_check floatright" />', $title, '</label>
+						</dd>';
+	}
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="submit" value="' . $txt['search'] . '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</div>
+	</form>';
+}
+
 ?>

+ 779 - 809
Themes/default/ModerationCenter.template.php

@@ -1,810 +1,780 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_moderation_center()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	// Show a welcome message to the user.
-	echo '
-	<div id="modcenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['moderation_center'], '</h3>
-		</div>
-		<div class="information">
-			<strong>', $txt['hello_guest'], ' ', $context['user']['name'], '!</strong>
-			<p>
-				', $txt['mc_description'], '
-			</p>
-		</div>';
-
-	$alternate = true;
-	// Show all the blocks they want to see.
-	foreach ($context['mod_blocks'] as $block)
-	{
-		$block_function = 'template_' . $block;
-
-		echo '
-		<div class="modblock_', $alternate ? 'left' : 'right', '">', function_exists($block_function) ? $block_function() : '', '</div>';
-
-		if (!$alternate)
-			echo '
-		<br class="clear" />';
-
-		$alternate = !$alternate;
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-function template_latest_news()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=live_news" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a> ', $txt['mc_latest_news'], '</span>
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<div id="smfAnnouncements" class="smalltext">', $txt['mc_cannot_connect_sm'], '</div>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	// This requires a lot of javascript...
-	// @todo Put this in it's own file!!
-	echo '
-		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=current-version.js"></script>
-		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/admin.js?alp21"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var oAdminIndex = new smf_AdminIndex({
-				sSelf: \'oAdminCenter\',
-
-				bLoadAnnouncements: true,
-				sAnnouncementTemplate: ', JavaScriptEscape('
-					<dl>
-						%content%
-					</dl>
-				'), ',
-				sAnnouncementMessageTemplate: ', JavaScriptEscape('
-					<dt><a href="%href%">%subject%</a> ' . $txt['on'] . ' %time%</dt>
-					<dd>
-						%message%
-					</dd>
-				'), ',
-				sAnnouncementContainerId: \'smfAnnouncements\'
-			});
-		// ]]></script>';
-
-}
-
-// Show all the group requests the user can see.
-function template_group_requests_block()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<a href="', $scripturl, '?action=groups;sa=requests">', $txt['mc_group_requests'], '</a>
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content modbox">
-				<ul class="reset">';
-
-		foreach ($context['group_requests'] as $request)
-			echo '
-				<li class="smalltext">
-					<a href="', $request['request_href'], '">', $request['group']['name'], '</a> ', $txt['mc_groupr_by'], ' ', $request['member']['link'], '
-				</li>';
-
-		// Don't have any watched users right now?
-		if (empty($context['group_requests']))
-			echo '
-				<li>
-					<strong class="smalltext">', $txt['mc_group_requests_none'], '</strong>
-				</li>';
-
-		echo '
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-}
-
-// A block to show the current top reported posts.
-function template_reported_posts_block()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<a href="', $scripturl, '?action=moderate;area=reports">', $txt['mc_recent_reports'], '</a>
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content modbox">
-				<ul class="reset">';
-
-		foreach ($context['reported_posts'] as $report)
-			echo '
-					<li class="smalltext">
-						<a href="', $report['report_href'], '">', $report['subject'], '</a> ', $txt['mc_reportedp_by'], ' ', $report['author']['link'], '
-					</li>';
-
-		// Don't have any watched users right now?
-		if (empty($context['reported_posts']))
-			echo '
-					<li>
-						<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
-					</li>';
-
-		echo '
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-}
-
-function template_watched_users()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<a href="', $scripturl, '?action=moderate;area=userwatch">', $txt['mc_watched_users'], '</a>
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content modbox">
-				<ul class="reset">';
-
-		foreach ($context['watched_users'] as $user)
-			echo '
-					<li>
-						<span class="smalltext">', sprintf(!empty($user['last_login']) ? $txt['mc_seen'] : $txt['mc_seen_never'], $user['link'], $user['last_login']), '</span>
-					</li>';
-
-		// Don't have any watched users right now?
-		if (empty($context['watched_users']))
-			echo '
-					<li>
-						<strong class="smalltext">', $txt['mc_watched_users_none'], '</strong>
-					</li>';
-
-		echo '
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-}
-
-// Little section for making... notes.
-function template_notes()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-		<form action="', $scripturl, '?action=moderate;area=index" method="post">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mc_notes'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content modbox">';
-
-		if (!empty($context['notes']))
-		{
-			echo '
-					<ul class="reset moderation_notes">';
-
-			// Cycle through the notes.
-			foreach ($context['notes'] as $note)
-				echo '
-						<li class="smalltext"><a href="', $note['delete_href'], '"><img src="', $settings['images_url'], '/pm_recipient_delete.png" alt="" /></a> <strong>', $note['author']['link'], ':</strong> ', $note['text'], '</li>';
-
-			echo '
-					</ul>
-					<div class="pagesection notes">
-						<span class="smalltext">', $txt['pages'], ': ', $context['page_index'], '</span>
-					</div>';
-		}
-
-		echo '
-					<div class="floatleft post_note">
-						<input type="text" name="new_note" value="', $txt['mc_click_add_note'], '" style="width: 95%;" onclick="if (this.value == \'', $txt['mc_click_add_note'], '\') this.value = \'\';" class="input_text" />
-					</div>
-					<div class="floatright">
-						<input type="submit" name="makenote" value="', $txt['mc_add_note'], '" class="button_submit" />
-					</div>
-					<br class="clear" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>';
-}
-
-function template_reported_posts()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-	<form action="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';start=', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', $context['view_closed'] ? $txt['mc_reportedp_closed'] : $txt['mc_reportedp_active'], '
-			</h3>
-		</div>
-		<div class="pagesection floatleft">
-			', $txt['pages'], ': ', $context['page_index'], '
-		</div>';
-
-	// Make the buttons.
-	$close_button = create_button('close.png', $context['view_closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', $context['view_closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', 'class="centericon"');
-	$details_button = create_button('details.png', 'mc_reportedp_details', 'mc_reportedp_details', 'class="centericon"');
-	$ignore_button = create_button('ignore.png', 'mc_reportedp_ignore', 'mc_reportedp_ignore', 'class="centericon"');
-	$unignore_button = create_button('ignore.png', 'mc_reportedp_unignore', 'mc_reportedp_unignore', 'class="centericon"');
-
-	foreach ($context['reports'] as $report)
-	{
-		echo '
-		<div class="', $report['alternate'] ? 'windowbg' : 'windowbg2', '">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<div>
-					<div class="floatleft">
-						<strong><a href="', $report['topic_href'], '">', $report['subject'], '</a></strong> ', $txt['mc_reportedp_by'], ' <strong>', $report['author']['link'], '</strong>
-					</div>
-					<div class="floatright">
-						<a href="', $report['report_href'], '">', $details_button, '</a>
-						<a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';ignore=', (int) !$report['ignore'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$report['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $report['ignore'] ? $unignore_button : $ignore_button, '</a>
-						<a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';close=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a>
-						', !$context['view_closed'] ? '<input type="checkbox" name="close[]" value="' . $report['id'] . '" class="input_check" />' : '', '
-					</div>
-				</div><br />
-				<div class="smalltext">
-					&#171; ', $txt['mc_reportedp_last_reported'], ': ', $report['last_updated'], ' &#187;<br />';
-
-		// Prepare the comments...
-		$comments = array();
-		foreach ($report['comments'] as $comment)
-			$comments[$comment['member']['id']] = $comment['member']['link'];
-
-		echo '
-					&#171; ', $txt['mc_reportedp_reported_by'], ': ', implode(', ', $comments), ' &#187;
-				</div>
-				<hr />
-				', $report['body'], '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	// Were none found?
-	if (empty($context['reports']))
-		echo '
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p class="centertext">', $txt['mc_reportedp_none_found'], '</p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	echo '
-		<div class="pagesection">
-			<div class="floatleft">
-				', $txt['pages'], ': ', $context['page_index'], '
-			</div>
-			<div class="floatright">
-				', !$context['view_closed'] ? '<input type="submit" name="close_selected" value="' . $txt['mc_reportedp_close_selected'] . '" class="button_submit" />' : '', '
-			</div>
-		</div>
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-	</form>
-	<br class="clear" />';
-}
-
-// Show a list of all the unapproved posts
-function template_unapproved_posts()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	// Just a big table of it all really...
-	echo '
-	<div id="modcenter">
-	<form action="', $scripturl, '?action=moderate;area=postmod;start=', $context['start'], ';sa=', $context['current_view'], '" method="post" accept-charset="', $context['character_set'], '">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['mc_unapproved_posts'], '</h3>
-		</div>';
-
-	// Make up some buttons
-	$approve_button = create_button('approve.png', 'approve', 'approve', 'class="centericon"');
-	$remove_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
-
-	// No posts?
-	if (empty($context['unapproved_items']))
-		echo '
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p class="centertext">', $txt['mc_unapproved_' . $context['current_view'] . '_none_found'], '</p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	else
-		echo '
-			<div class="pagesection floatleft">
-				', $txt['pages'], ': ', $context['page_index'], '
-			</div>';
-
-	foreach ($context['unapproved_items'] as $item)
-	{
-		echo '
-		<div class="topic clear">
-			<div class="', $item['alternate'] == 0 ? 'windowbg2' : 'windowbg', ' core_posts">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="counter">', $item['counter'], '</div>
-					<div class="topic_details">
-						<h5><strong>', $item['category']['link'], ' / ', $item['board']['link'], ' / ', $item['link'], '</strong></h5>
-						<span class="smalltext"><strong>', $txt['mc_unapproved_by'], ' ', $item['poster']['link'], ' ', $txt['on'], ':</strong> ', $item['time'], '</span>
-					</div>
-					<div class="list_posts">
-						<div class="post">', $item['body'], '</div>
-					</div>
-					<span class="floatright">
-						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';approve=', $item['id'], '">', $approve_button, '</a>';
-
-			if ($item['can_delete'])
-				echo '
-					', $context['menu_separator'], '
-						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';delete=', $item['id'], '">', $remove_button, '</a>';
-
-			if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
-				echo '
-						<input type="checkbox" name="item[]" value="', $item['id'], '" checked="checked" class="input_check" /> ';
-
-			echo '
-					</span>
-					<br class="clear" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>';
-	}
-
-	echo '
-		<div class="pagesection">';
-
-	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
-		echo '
-			<div class="floatright">
-				<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'', $txt['mc_unapproved_sure'], '\')) submit();">
-					<option value="0">', $txt['with_selected'], ':</option>
-					<option value="0">-------------------</option>
-					<option value="approve">&nbsp;--&nbsp;', $txt['approve'], '</option>
-					<option value="delete">&nbsp;--&nbsp;', $txt['delete'], '</option>
-				</select>
-				<noscript><input type="submit" name="mc_go" value="', $txt['go'], '" class="button_submit" /></noscript>
-			</div>';
-
-	if (!empty($context['unapproved_items']))
-		echo '
-			<div class="floatleft">
-				<div class="pagelinks">', $txt['pages'], ': ', $context['page_index'], '</div>
-			</div>';
-
-	echo '
-		</div>
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-	</form>
-	</div>
-	<br class="clear" />';
-}
-
-// List all attachments awaiting approval.
-function template_unapproved_attachments()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	// Show all the attachments still oustanding.
-	echo '
-	<div id="modcenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['mc_unapproved_attachments'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['mc_unapproved_attachments_desc'], '
-		</div>';
-
-	template_show_list('mc_unapproved_attach');
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-function template_viewmodreport()
-{
-	global $context, $scripturl, $txt;
-
-	echo '
-	<div id="modcenter">
-		<form action="', $scripturl, '?action=moderate;area=reports;report=', $context['report']['id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', sprintf($txt['mc_viewmodreport'], $context['report']['message_link'], $context['report']['author']['link']), '
-				</h3>
-			</div>
-			<div class="title_bar">
-				<h3 class="titlebg">
-					<span class="floatleft">
-						', sprintf($txt['mc_modreport_summary'], $context['report']['num_reports'], $context['report']['last_updated']), '
-					</span>
-					<span class="floatright">';
-
-		// Make the buttons.
-		$close_button = create_button('close.png', $context['report']['closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', $context['report']['closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', 'class="centericon"');
-		$ignore_button = create_button('ignore.png', 'mc_reportedp_ignore', 'mc_reportedp_ignore', 'class="centericon"');
-		$unignore_button = create_button('ignore.png', 'mc_reportedp_unignore', 'mc_reportedp_unignore', 'class="centericon"');
-
-		echo '
-						<a href="', $scripturl, '?action=moderate;area=reports;ignore=', (int) !$context['report']['ignore'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$context['report']['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $context['report']['ignore'] ? $unignore_button : $ignore_button, '</a>
-						<a href="', $scripturl, '?action=moderate;area=reports;close=', (int) !$context['report']['closed'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a>
-					</span>
-				</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					', $context['report']['body'], '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mc_modreport_whoreported_title'], '</h3>
-			</div>';
-
-	foreach ($context['report']['comments'] as $comment)
-		echo '
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p class="smalltext">', sprintf($txt['mc_modreport_whoreported_data'], $comment['member']['link'] . (empty($comment['member']['id']) && !empty($comment['member']['ip']) ? ' (' . $comment['member']['ip'] . ')' : ''), $comment['time']), '</p>
-					<p>', $comment['message'], '</p>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	echo '
-			<br />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mc_modreport_mod_comments'], '</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	if (empty($context['report']['mod_comments']))
-		echo '
-					<p class="centertext">', $txt['mc_modreport_no_mod_comment'], '</p>';
-
-	foreach ($context['report']['mod_comments'] as $comment)
-		echo
-					'<p>', $comment['member']['link'], ': ', $comment['message'], ' <em class="smalltext">(', $comment['time'], ')</em></p>';
-
-	echo '
-					<textarea rows="2" cols="60" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 60%; min-width: 60%' : 'width: 60%') . ';" name="mod_comment"></textarea>
-					<div>
-						<input type="submit" name="add_comment" value="', $txt['mc_modreport_add_mod_comment'], '" class="button_submit" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />';
-
-	$alt = false;
-
-	template_show_list('moderation_actions_list');
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Callback function for showing a watched users post in the table.
-function template_user_watch_post_callback($post)
-{
-	global $scripturl, $context, $txt, $delete_button;
-
-	// We'll have a delete please bob.
-	if (empty($delete_button))
-		$delete_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
-
-	$output_html = '
-					<div>
-						<div class="floatleft">
-							<strong><a href="' . $scripturl . '?topic=' . $post['id_topic'] . '.' . $post['id'] . '#msg' . $post['id'] . '">' . $post['subject'] . '</a></strong> ' . $txt['mc_reportedp_by'] . ' <strong>' . $post['author_link'] . '</strong>
-						</div>
-						<div class="floatright">';
-
-	if ($post['can_delete'])
-		$output_html .= '
-							<a href="' . $scripturl . '?action=moderate;area=userwatch;sa=post;delete=' . $post['id'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(\'' . $txt['mc_watched_users_delete_post'] . '\');">' . $delete_button . '</a>
-							<input type="checkbox" name="delete[]" value="' . $post['id'] . '" class="input_check" />';
-
-	$output_html .= '
-						</div>
-					</div><br />
-					<div class="smalltext">
-						&#171; ' . $txt['mc_watched_users_posted'] . ': ' . $post['poster_time'] . ' &#187;
-					</div>
-					<hr />
-					' . $post['body'];
-
-	return $output_html;
-}
-
-// Moderation settings
-function template_moderation_settings()
-{
-	global $settings, $options, $context, $txt, $scripturl;
-
-	echo '
-	<div id="modcenter">
-		<form action="', $scripturl, '?action=moderate;area=settings" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mc_prefs_title'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['mc_prefs_desc'], '
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['mc_prefs_homepage'], ':</strong>
-						</dt>
-						<dd>';
-
-	foreach ($context['homepage_blocks'] as $k => $v)
-		echo '
-							<label for="mod_homepage_', $k, '"><input type="checkbox" id="mod_homepage_', $k, '" name="mod_homepage[', $k, ']"', in_array($k, $context['mod_settings']['user_blocks']) ? ' checked="checked"' : '', ' class="input_check" /> ', $v, '</label><br />';
-
-	echo '
-						</dd>';
-
-	// If they can moderate boards they have more options!
-	if ($context['can_moderate_boards'])
-	{
-		echo '
-						<dt>
-							<strong><label for="mod_show_reports">', $txt['mc_prefs_show_reports'], '</label>:</strong>
-						</dt>
-						<dd>
-							<input type="checkbox" id="mod_show_reports" name="mod_show_reports" ', $context['mod_settings']['show_reports'] ? 'checked="checked"' : '', ' class="input_check" />
-						</dd>
-						<dt>
-							<strong><label for="mod_notify_report">', $txt['mc_prefs_notify_report'], '</label>:</strong>
-						</dt>
-						<dd>
-							<select id="mod_notify_report" name="mod_notify_report">
-								<option value="0" ', $context['mod_settings']['notify_report'] == 0 ? 'selected="selected"' : '', '>', $txt['mc_prefs_notify_report_never'], '</option>
-								<option value="1" ', $context['mod_settings']['notify_report'] == 1 ? 'selected="selected"' : '', '>', $txt['mc_prefs_notify_report_moderator'], '</option>
-								<option value="2" ', $context['mod_settings']['notify_report'] == 2 ? 'selected="selected"' : '', '>', $txt['mc_prefs_notify_report_always'], '</option>
-							</select>
-						</dd>';
-
-	}
-
-	if ($context['can_moderate_approvals'])
-	{
-		echo '
-
-						<dt>
-							<strong><label for="mod_notify_approval">', $txt['mc_prefs_notify_approval'], '</label>:</strong>
-						</dt>
-						<dd>
-							<input type="checkbox" id="mod_notify_approval" name="mod_notify_approval" ', $context['mod_settings']['notify_approval'] ? 'checked="checked"' : '', ' class="input_check" />
-						</dd>';
-	}
-
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['mod-set_token_var'], '" value="', $context['mod-set_token'], '" />
-					<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Show a notice sent to a user.
-function template_show_notice()
-{
-	global $txt, $settings, $options, $context;
-
-	// We do all the HTML for this one!
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<title>', $context['page_title'], '</title>
-		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
-	</head>
-	<body>
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['show_notice'], '</h3>
-		</div>
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['show_notice_subject'], ': ', $context['notice_subject'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl>
-					<dt>
-						<strong>', $txt['show_notice_text'], ':</strong>
-					</dt>
-					<dd>
-						', $context['notice_body'], '
-					</dd>
-				</dl>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</body>
-</html>';
-
-}
-
-// Add or edit a warning template.
-function template_warn_template()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="modcenter">
-		<form action="', $scripturl, '?action=moderate;area=warnings;sa=templateedit;tid=', $context['id_template'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['mc_warning_template_desc'], '
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="errorbox"', empty($context['warning_errors']) ? ' style="display: none"' : '', ' id="errors">
-						<dl>
-							<dt>
-								<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
-							</dt>
-							<dd class="error" id="error_list">
-								', empty($context['warning_errors']) ? '' : implode('<br />', $context['warning_errors']), '
-							</dd>
-						</dl>
-					</div>
-					<div id="box_preview"', !empty($context['template_preview']) ? '' : ' style="display:none"', '>
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['preview'] , '</strong>
-							</dt>
-							<dd id="template_preview">
-								', !empty($context['template_preview']) ? $context['template_preview'] : '', '
-							</dd>
-						</dl>
-					</div>
-					<dl class="settings">
-						<dt>
-							<strong><label for="template_title">', $txt['mc_warning_template_title'], '</label>:</strong>
-						</dt>
-						<dd>
-							<input type="text" id="template_title" name="template_title" value="', $context['template_data']['title'], '" size="30" class="input_text" />
-						</dd>
-						<dt>
-							<strong><label for="template_body">', $txt['profile_warning_notify_body'], '</label>:</strong><br />
-							<span class="smalltext">', $txt['mc_warning_template_body_desc'], '</span>
-						</dt>
-						<dd>
-							<textarea id="template_body" name="template_body" rows="10" cols="45" class="smalltext">', $context['template_data']['body'], '</textarea>
-						</dd>
-					</dl>';
-
-	if ($context['template_data']['can_edit_personal'])
-		echo '
-					<input type="checkbox" name="make_personal" id="make_personal" ', $context['template_data']['personal'] ? 'checked="checked"' : '', ' class="input_check" />
-						<label for="make_personal">
-							<strong>', $txt['mc_warning_template_personal'], '</strong>
-						</label>
-						<br />
-						<span class="smalltext">', $txt['mc_warning_template_personal_desc'], '</span>
-						<br />';
-
-	echo '
-					<hr class="hrcolor" />
-					<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button_submit" />
-					<input type="submit" name="save" value="', $context['page_title'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['mod-wt_token_var'], '" value="', $context['mod-wt_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />
-	<script type="text/javascript"><!-- // --><![CDATA[
-		$(document).ready(function() {
-			$("#preview_button").click(function() {
-				return ajax_getTemplatePreview();
-			});
-		});
-
-		function ajax_getTemplatePreview ()
-		{
-			$.ajax({
-				type: "POST",
-				url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
-				data: {item: "warning_preview", title: $("#template_title").val(), body: $("#template_body").val(), user: $(\'input[name="u"]\').attr("value")},
-				context: document.body,
-				success: function(request){
-					$("#box_preview").css({display:""});
-					$("#template_preview").html($(request).find(\'body\').text());
-					if ($(request).find("error").text() != \'\')
-					{
-						$("#errors").css({display:""});
-						var errors_html = \'\';
-						var errors = $(request).find(\'error\').each(function() {
-							errors_html += $(this).text() + \'<br />\';
-						});
-
-						$(document).find("#error_list").html(errors_html);
-					}
-					else
-					{
-						$("#errors").css({display:"none"});
-						$("#error_list").html(\'\');
-					}
-				return false;
-				},
-			});
-			return false;
-		}
-	// ]]></script>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_moderation_center()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	// Show a welcome message to the user.
+	echo '
+	<div id="modcenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['moderation_center'], '</h3>
+		</div>
+		<div class="information">
+			<strong>', $txt['hello_guest'], ' ', $context['user']['name'], '!</strong>
+			<p>
+				', $txt['mc_description'], '
+			</p>
+		</div>';
+
+	$alternate = true;
+	// Show all the blocks they want to see.
+	foreach ($context['mod_blocks'] as $block)
+	{
+		$block_function = 'template_' . $block;
+
+		echo '
+		<div class="modblock_', $alternate ? 'left' : 'right', '">', function_exists($block_function) ? $block_function() : '', '</div>';
+
+		if (!$alternate)
+			echo '
+		<br class="clear" />';
+
+		$alternate = !$alternate;
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+function template_latest_news()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=helpadmin;help=live_news" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a> ', $txt['mc_latest_news'], '
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<div id="smfAnnouncements" class="smalltext">', $txt['mc_cannot_connect_sm'], '</div>
+			</div>
+		</div>';
+
+	// This requires a lot of javascript...
+	// @todo Put this in it's own file!!
+	echo '
+		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=current-version.js"></script>
+		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/admin.js?alp21"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var oAdminIndex = new smf_AdminIndex({
+				sSelf: \'oAdminCenter\',
+
+				bLoadAnnouncements: true,
+				sAnnouncementTemplate: ', JavaScriptEscape('
+					<dl>
+						%content%
+					</dl>
+				'), ',
+				sAnnouncementMessageTemplate: ', JavaScriptEscape('
+					<dt><a href="%href%">%subject%</a> ' . $txt['on'] . ' %time%</dt>
+					<dd>
+						%message%
+					</dd>
+				'), ',
+				sAnnouncementContainerId: \'smfAnnouncements\'
+			});
+		// ]]></script>';
+
+}
+
+// Show all the group requests the user can see.
+function template_group_requests_block()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=groups;sa=requests">', $txt['mc_group_requests'], '</a>
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content modbox">
+				<ul class="reset">';
+
+		foreach ($context['group_requests'] as $request)
+			echo '
+				<li class="smalltext">
+					<a href="', $request['request_href'], '">', $request['group']['name'], '</a> ', $txt['mc_groupr_by'], ' ', $request['member']['link'], '
+				</li>';
+
+		// Don't have any watched users right now?
+		if (empty($context['group_requests']))
+			echo '
+				<li>
+					<strong class="smalltext">', $txt['mc_group_requests_none'], '</strong>
+				</li>';
+
+		echo '
+				</ul>
+			</div>
+		</div>';
+}
+
+// A block to show the current top reported posts.
+function template_reported_posts_block()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=moderate;area=reports">', $txt['mc_recent_reports'], '</a>
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content modbox">
+				<ul class="reset">';
+
+		foreach ($context['reported_posts'] as $report)
+			echo '
+					<li class="smalltext">
+						<a href="', $report['report_href'], '">', $report['subject'], '</a> ', $txt['mc_reportedp_by'], ' ', $report['author']['link'], '
+					</li>';
+
+		// Don't have any watched users right now?
+		if (empty($context['reported_posts']))
+			echo '
+					<li>
+						<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
+					</li>';
+
+		echo '
+				</ul>
+			</div>
+		</div>';
+}
+
+function template_watched_users()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=moderate;area=userwatch">', $txt['mc_watched_users'], '</a>
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content modbox">
+				<ul class="reset">';
+
+		foreach ($context['watched_users'] as $user)
+			echo '
+					<li>
+						<span class="smalltext">', sprintf(!empty($user['last_login']) ? $txt['mc_seen'] : $txt['mc_seen_never'], $user['link'], $user['last_login']), '</span>
+					</li>';
+
+		// Don't have any watched users right now?
+		if (empty($context['watched_users']))
+			echo '
+					<li>
+						<strong class="smalltext">', $txt['mc_watched_users_none'], '</strong>
+					</li>';
+
+		echo '
+				</ul>
+			</div>
+		</div>';
+}
+
+// Little section for making... notes.
+function template_notes()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+		<form action="', $scripturl, '?action=moderate;area=index" method="post">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mc_notes'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content modbox">';
+
+		if (!empty($context['notes']))
+		{
+			echo '
+					<ul class="reset moderation_notes">';
+
+			// Cycle through the notes.
+			foreach ($context['notes'] as $note)
+				echo '
+						<li class="smalltext"><a href="', $note['delete_href'], '"><img src="', $settings['images_url'], '/pm_recipient_delete.png" alt="" /></a> <strong>', $note['author']['link'], ':</strong> ', $note['text'], '</li>';
+
+			echo '
+					</ul>
+					<div class="pagesection notes">
+						<span class="smalltext">', $txt['pages'], ': ', $context['page_index'], '</span>
+					</div>';
+		}
+
+		echo '
+					<div class="floatleft post_note">
+						<input type="text" name="new_note" value="', $txt['mc_click_add_note'], '" style="width: 95%;" onclick="if (this.value == \'', $txt['mc_click_add_note'], '\') this.value = \'\';" class="input_text" />
+					</div>
+					<div class="floatright">
+						<input type="submit" name="makenote" value="', $txt['mc_add_note'], '" class="button_submit" />
+					</div>
+					<br class="clear" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>';
+}
+
+function template_reported_posts()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+	<form action="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';start=', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $context['view_closed'] ? $txt['mc_reportedp_closed'] : $txt['mc_reportedp_active'], '
+			</h3>
+		</div>
+		<div class="pagesection floatleft">
+			', $txt['pages'], ': ', $context['page_index'], '
+		</div>';
+
+	// Make the buttons.
+	$close_button = create_button('close.png', $context['view_closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', $context['view_closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', 'class="centericon"');
+	$details_button = create_button('details.png', 'mc_reportedp_details', 'mc_reportedp_details', 'class="centericon"');
+	$ignore_button = create_button('ignore.png', 'mc_reportedp_ignore', 'mc_reportedp_ignore', 'class="centericon"');
+	$unignore_button = create_button('ignore.png', 'mc_reportedp_unignore', 'mc_reportedp_unignore', 'class="centericon"');
+
+	foreach ($context['reports'] as $report)
+	{
+		echo '
+		<div class="', $report['alternate'] ? 'windowbg' : 'windowbg2', '">
+			<div class="content">
+				<div>
+					<div class="floatleft">
+						<strong><a href="', $report['topic_href'], '">', $report['subject'], '</a></strong> ', $txt['mc_reportedp_by'], ' <strong>', $report['author']['link'], '</strong>
+					</div>
+					<div class="floatright">
+						<a href="', $report['report_href'], '">', $details_button, '</a>
+						<a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';ignore=', (int) !$report['ignore'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$report['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $report['ignore'] ? $unignore_button : $ignore_button, '</a>
+						<a href="', $scripturl, '?action=moderate;area=reports', $context['view_closed'] ? ';sa=closed' : '', ';close=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a>
+						', !$context['view_closed'] ? '<input type="checkbox" name="close[]" value="' . $report['id'] . '" class="input_check" />' : '', '
+					</div>
+				</div><br />
+				<div class="smalltext">
+					&#171; ', $txt['mc_reportedp_last_reported'], ': ', $report['last_updated'], ' &#187;<br />';
+
+		// Prepare the comments...
+		$comments = array();
+		foreach ($report['comments'] as $comment)
+			$comments[$comment['member']['id']] = $comment['member']['link'];
+
+		echo '
+					&#171; ', $txt['mc_reportedp_reported_by'], ': ', implode(', ', $comments), ' &#187;
+				</div>
+				<hr />
+				', $report['body'], '
+			</div>
+		</div>';
+	}
+
+	// Were none found?
+	if (empty($context['reports']))
+		echo '
+		<div class="windowbg2">
+			<div class="content">
+				<p class="centertext">', $txt['mc_reportedp_none_found'], '</p>
+			</div>
+		</div>';
+
+	echo '
+		<div class="pagesection">
+			<div class="floatleft">
+				', $txt['pages'], ': ', $context['page_index'], '
+			</div>
+			<div class="floatright">
+				', !$context['view_closed'] ? '<input type="submit" name="close_selected" value="' . $txt['mc_reportedp_close_selected'] . '" class="button_submit" />' : '', '
+			</div>
+		</div>
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+	</form>
+	<br class="clear" />';
+}
+
+// Show a list of all the unapproved posts
+function template_unapproved_posts()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	// Just a big table of it all really...
+	echo '
+	<div id="modcenter">
+	<form action="', $scripturl, '?action=moderate;area=postmod;start=', $context['start'], ';sa=', $context['current_view'], '" method="post" accept-charset="', $context['character_set'], '">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['mc_unapproved_posts'], '</h3>
+		</div>';
+
+	// Make up some buttons
+	$approve_button = create_button('approve.png', 'approve', 'approve', 'class="centericon"');
+	$remove_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
+
+	// No posts?
+	if (empty($context['unapproved_items']))
+		echo '
+		<div class="windowbg2">
+			<div class="content">
+				<p class="centertext">', $txt['mc_unapproved_' . $context['current_view'] . '_none_found'], '</p>
+			</div>
+		</div>';
+	else
+		echo '
+			<div class="pagesection floatleft">
+				', $txt['pages'], ': ', $context['page_index'], '
+			</div>';
+
+	foreach ($context['unapproved_items'] as $item)
+	{
+		echo '
+		<div class="topic clear">
+			<div class="', $item['alternate'] == 0 ? 'windowbg2' : 'windowbg', ' core_posts">
+				<div class="content">
+					<div class="counter">', $item['counter'], '</div>
+					<div class="topic_details">
+						<h5><strong>', $item['category']['link'], ' / ', $item['board']['link'], ' / ', $item['link'], '</strong></h5>
+						<span class="smalltext"><strong>', $txt['mc_unapproved_by'], ' ', $item['poster']['link'], ' ', $txt['on'], ':</strong> ', $item['time'], '</span>
+					</div>
+					<div class="list_posts">
+						<div class="post">', $item['body'], '</div>
+					</div>
+					<span class="floatright">
+						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';approve=', $item['id'], '">', $approve_button, '</a>';
+
+			if ($item['can_delete'])
+				echo '
+					', $context['menu_separator'], '
+						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';delete=', $item['id'], '">', $remove_button, '</a>';
+
+			if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
+				echo '
+						<input type="checkbox" name="item[]" value="', $item['id'], '" checked="checked" class="input_check" /> ';
+
+			echo '
+					</span>
+					<br class="clear" />
+				</div>
+			</div>
+		</div>';
+	}
+
+	echo '
+		<div class="pagesection">';
+
+	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
+		echo '
+			<div class="floatright">
+				<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'', $txt['mc_unapproved_sure'], '\')) submit();">
+					<option value="0">', $txt['with_selected'], ':</option>
+					<option value="0">-------------------</option>
+					<option value="approve">&nbsp;--&nbsp;', $txt['approve'], '</option>
+					<option value="delete">&nbsp;--&nbsp;', $txt['delete'], '</option>
+				</select>
+				<noscript><input type="submit" name="mc_go" value="', $txt['go'], '" class="button_submit" /></noscript>
+			</div>';
+
+	if (!empty($context['unapproved_items']))
+		echo '
+			<div class="floatleft">
+				<div class="pagelinks">', $txt['pages'], ': ', $context['page_index'], '</div>
+			</div>';
+
+	echo '
+		</div>
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+	</form>
+	</div>
+	<br class="clear" />';
+}
+
+// List all attachments awaiting approval.
+function template_unapproved_attachments()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	// Show all the attachments still oustanding.
+	echo '
+	<div id="modcenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['mc_unapproved_attachments'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['mc_unapproved_attachments_desc'], '
+		</div>';
+
+	template_show_list('mc_unapproved_attach');
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+function template_viewmodreport()
+{
+	global $context, $scripturl, $txt;
+
+	echo '
+	<div id="modcenter">
+		<form action="', $scripturl, '?action=moderate;area=reports;report=', $context['report']['id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', sprintf($txt['mc_viewmodreport'], $context['report']['message_link'], $context['report']['author']['link']), '
+				</h3>
+			</div>
+			<div class="title_bar">
+				<h3 class="titlebg">
+					<span class="floatleft">
+						', sprintf($txt['mc_modreport_summary'], $context['report']['num_reports'], $context['report']['last_updated']), '
+					</span>
+					<span class="floatright">';
+
+		// Make the buttons.
+		$close_button = create_button('close.png', $context['report']['closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', $context['report']['closed'] ? 'mc_reportedp_open' : 'mc_reportedp_close', 'class="centericon"');
+		$ignore_button = create_button('ignore.png', 'mc_reportedp_ignore', 'mc_reportedp_ignore', 'class="centericon"');
+		$unignore_button = create_button('ignore.png', 'mc_reportedp_unignore', 'mc_reportedp_unignore', 'class="centericon"');
+
+		echo '
+						<a href="', $scripturl, '?action=moderate;area=reports;ignore=', (int) !$context['report']['ignore'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '" ', !$context['report']['ignore'] ? 'onclick="return confirm(\'' . $txt['mc_reportedp_ignore_confirm'] . '\');"' : '', '>', $context['report']['ignore'] ? $unignore_button : $ignore_button, '</a>
+						<a href="', $scripturl, '?action=moderate;area=reports;close=', (int) !$context['report']['closed'], ';rid=', $context['report']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $close_button, '</a>
+					</span>
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					', $context['report']['body'], '
+				</div>
+			</div>
+			<br />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mc_modreport_whoreported_title'], '</h3>
+			</div>';
+
+	foreach ($context['report']['comments'] as $comment)
+		echo '
+			<div class="windowbg">
+				<div class="content">
+					<p class="smalltext">', sprintf($txt['mc_modreport_whoreported_data'], $comment['member']['link'] . (empty($comment['member']['id']) && !empty($comment['member']['ip']) ? ' (' . $comment['member']['ip'] . ')' : ''), $comment['time']), '</p>
+					<p>', $comment['message'], '</p>
+				</div>
+			</div>';
+
+	echo '
+			<br />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mc_modreport_mod_comments'], '</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">';
+
+	if (empty($context['report']['mod_comments']))
+		echo '
+					<p class="centertext">', $txt['mc_modreport_no_mod_comment'], '</p>';
+
+	foreach ($context['report']['mod_comments'] as $comment)
+		echo
+					'<p>', $comment['member']['link'], ': ', $comment['message'], ' <em class="smalltext">(', $comment['time'], ')</em></p>';
+
+	echo '
+					<textarea rows="2" cols="60" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 60%; min-width: 60%' : 'width: 60%') . ';" name="mod_comment"></textarea>
+					<div>
+						<input type="submit" name="add_comment" value="', $txt['mc_modreport_add_mod_comment'], '" class="button_submit" />
+					</div>
+				</div>
+			</div>
+			<br />';
+
+	$alt = false;
+
+	template_show_list('moderation_actions_list');
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Callback function for showing a watched users post in the table.
+function template_user_watch_post_callback($post)
+{
+	global $scripturl, $context, $txt, $delete_button;
+
+	// We'll have a delete please bob.
+	if (empty($delete_button))
+		$delete_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
+
+	$output_html = '
+					<div>
+						<div class="floatleft">
+							<strong><a href="' . $scripturl . '?topic=' . $post['id_topic'] . '.' . $post['id'] . '#msg' . $post['id'] . '">' . $post['subject'] . '</a></strong> ' . $txt['mc_reportedp_by'] . ' <strong>' . $post['author_link'] . '</strong>
+						</div>
+						<div class="floatright">';
+
+	if ($post['can_delete'])
+		$output_html .= '
+							<a href="' . $scripturl . '?action=moderate;area=userwatch;sa=post;delete=' . $post['id'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(\'' . $txt['mc_watched_users_delete_post'] . '\');">' . $delete_button . '</a>
+							<input type="checkbox" name="delete[]" value="' . $post['id'] . '" class="input_check" />';
+
+	$output_html .= '
+						</div>
+					</div><br />
+					<div class="smalltext">
+						&#171; ' . $txt['mc_watched_users_posted'] . ': ' . $post['poster_time'] . ' &#187;
+					</div>
+					<hr />
+					' . $post['body'];
+
+	return $output_html;
+}
+
+// Moderation settings
+function template_moderation_settings()
+{
+	global $settings, $options, $context, $txt, $scripturl;
+
+	echo '
+	<div id="modcenter">
+		<form action="', $scripturl, '?action=moderate;area=settings" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['mc_prefs_title'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['mc_prefs_desc'], '
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['mc_prefs_homepage'], ':</strong>
+						</dt>
+						<dd>';
+
+	foreach ($context['homepage_blocks'] as $k => $v)
+		echo '
+							<label for="mod_homepage_', $k, '"><input type="checkbox" id="mod_homepage_', $k, '" name="mod_homepage[', $k, ']"', in_array($k, $context['mod_settings']['user_blocks']) ? ' checked="checked"' : '', ' class="input_check" /> ', $v, '</label><br />';
+
+	echo '
+						</dd>';
+
+	// If they can moderate boards they have more options!
+	if ($context['can_moderate_boards'])
+	{
+		echo '
+						<dt>
+							<strong><label for="mod_show_reports">', $txt['mc_prefs_show_reports'], '</label>:</strong>
+						</dt>
+						<dd>
+							<input type="checkbox" id="mod_show_reports" name="mod_show_reports" ', $context['mod_settings']['show_reports'] ? 'checked="checked"' : '', ' class="input_check" />
+						</dd>
+						<dt>
+							<strong><label for="mod_notify_report">', $txt['mc_prefs_notify_report'], '</label>:</strong>
+						</dt>
+						<dd>
+							<select id="mod_notify_report" name="mod_notify_report">
+								<option value="0" ', $context['mod_settings']['notify_report'] == 0 ? 'selected="selected"' : '', '>', $txt['mc_prefs_notify_report_never'], '</option>
+								<option value="1" ', $context['mod_settings']['notify_report'] == 1 ? 'selected="selected"' : '', '>', $txt['mc_prefs_notify_report_moderator'], '</option>
+								<option value="2" ', $context['mod_settings']['notify_report'] == 2 ? 'selected="selected"' : '', '>', $txt['mc_prefs_notify_report_always'], '</option>
+							</select>
+						</dd>';
+
+	}
+
+	if ($context['can_moderate_approvals'])
+	{
+		echo '
+
+						<dt>
+							<strong><label for="mod_notify_approval">', $txt['mc_prefs_notify_approval'], '</label>:</strong>
+						</dt>
+						<dd>
+							<input type="checkbox" id="mod_notify_approval" name="mod_notify_approval" ', $context['mod_settings']['notify_approval'] ? 'checked="checked"' : '', ' class="input_check" />
+						</dd>';
+	}
+
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['mod-set_token_var'], '" value="', $context['mod-set_token'], '" />
+					<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Show a notice sent to a user.
+function template_show_notice()
+{
+	global $txt, $settings, $options, $context;
+
+	// We do all the HTML for this one!
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<title>', $context['page_title'], '</title>
+		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
+	</head>
+	<body>
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['show_notice'], '</h3>
+		</div>
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['show_notice_subject'], ': ', $context['notice_subject'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl>
+					<dt>
+						<strong>', $txt['show_notice_text'], ':</strong>
+					</dt>
+					<dd>
+						', $context['notice_body'], '
+					</dd>
+				</dl>
+			</div>
+		</div>
+	</body>
+</html>';
+
+}
+
+// Add or edit a warning template.
+function template_warn_template()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="modcenter">
+		<form action="', $scripturl, '?action=moderate;area=warnings;sa=templateedit;tid=', $context['id_template'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['mc_warning_template_desc'], '
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<div class="errorbox"', empty($context['warning_errors']) ? ' style="display: none"' : '', ' id="errors">
+						<dl>
+							<dt>
+								<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
+							</dt>
+							<dd class="error" id="error_list">
+								', empty($context['warning_errors']) ? '' : implode('<br />', $context['warning_errors']), '
+							</dd>
+						</dl>
+					</div>
+					<div id="box_preview"', !empty($context['template_preview']) ? '' : ' style="display:none"', '>
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['preview'] , '</strong>
+							</dt>
+							<dd id="template_preview">
+								', !empty($context['template_preview']) ? $context['template_preview'] : '', '
+							</dd>
+						</dl>
+					</div>
+					<dl class="settings">
+						<dt>
+							<strong><label for="template_title">', $txt['mc_warning_template_title'], '</label>:</strong>
+						</dt>
+						<dd>
+							<input type="text" id="template_title" name="template_title" value="', $context['template_data']['title'], '" size="30" class="input_text" />
+						</dd>
+						<dt>
+							<strong><label for="template_body">', $txt['profile_warning_notify_body'], '</label>:</strong><br />
+							<span class="smalltext">', $txt['mc_warning_template_body_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea id="template_body" name="template_body" rows="10" cols="45" class="smalltext">', $context['template_data']['body'], '</textarea>
+						</dd>
+					</dl>';
+
+	if ($context['template_data']['can_edit_personal'])
+		echo '
+					<input type="checkbox" name="make_personal" id="make_personal" ', $context['template_data']['personal'] ? 'checked="checked"' : '', ' class="input_check" />
+						<label for="make_personal">
+							<strong>', $txt['mc_warning_template_personal'], '</strong>
+						</label>
+						<br />
+						<span class="smalltext">', $txt['mc_warning_template_personal_desc'], '</span>
+						<br />';
+
+	echo '
+					<hr class="hrcolor" />
+					<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button_submit" />
+					<input type="submit" name="save" value="', $context['page_title'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['mod-wt_token_var'], '" value="', $context['mod-wt_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />
+	<script type="text/javascript"><!-- // --><![CDATA[
+		$(document).ready(function() {
+			$("#preview_button").click(function() {
+				return ajax_getTemplatePreview();
+			});
+		});
+
+		function ajax_getTemplatePreview ()
+		{
+			$.ajax({
+				type: "POST",
+				url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
+				data: {item: "warning_preview", title: $("#template_title").val(), body: $("#template_body").val(), user: $(\'input[name="u"]\').attr("value")},
+				context: document.body,
+				success: function(request){
+					$("#box_preview").css({display:""});
+					$("#template_preview").html($(request).find(\'body\').text());
+					if ($(request).find("error").text() != \'\')
+					{
+						$("#errors").css({display:""});
+						var errors_html = \'\';
+						var errors = $(request).find(\'error\').each(function() {
+							errors_html += $(this).text() + \'<br />\';
+						});
+
+						$(document).find("#error_list").html(errors_html);
+					}
+					else
+					{
+						$("#errors").css({display:"none"});
+						$("#error_list").html(\'\');
+					}
+				return false;
+				},
+			});
+			return false;
+		}
+	// ]]></script>';
+}
+
 ?>

+ 109 - 111
Themes/default/MoveTopic.template.php

@@ -1,112 +1,110 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-/**
- * Show an interface for selecting which board to move a post to.
- */
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="move_topic" class="lower_padding">
-		<form action="', $scripturl, '?action=movetopic2;current_board=' . $context['current_board'] . ';topic=', $context['current_topic'], '.0" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['move_topic'], '</h3>
-			</div>
-			<div class="windowbg centertext">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="move_topic">
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['move_to'], ':</strong>
-							</dt>
-							<dd>
-								<select name="toboard">';
-
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-									<optgroup label="', $category['name'], '">';
-
-		foreach ($category['boards'] as $board)
-			echo '
-										<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', $board['id'] == $context['current_board'] ? ' disabled="disabled"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level']-1) . '=&gt; ' : '', $board['name'], '</option>';
-		echo '
-									</optgroup>';
-	}
-
-	echo '
-								</select>
-							</dd>';
-
-	// Disable the reason textarea when the postRedirect checkbox is unchecked...
-	echo '
-						</dl>
-						<label for="reset_subject"><input type="checkbox" name="reset_subject" id="reset_subject" onclick="document.getElementById(\'subjectArea\').style.display = this.checked ? \'block\' : \'none\';" class="input_check" /> ', $txt['moveTopic2'], '.</label><br />
-						<fieldset id="subjectArea" style="display: none;">
-							<dl class="settings">
-								<dt><strong>', $txt['moveTopic3'], ':</strong></dt>
-								<dd><input type="text" name="custom_subject" size="30" value="', $context['subject'], '" class="input_text" /></dd>
-							</dl>
-							<label for="enforce_subject"><input type="checkbox" name="enforce_subject" id="enforce_subject" class="input_check" /> ', $txt['moveTopic4'], '.</label>
-						</fieldset>
-						<label for="postRedirect"><input type="checkbox" name="postRedirect" id="postRedirect" ', $context['is_approved'] ? 'checked="checked"' : '', ' onclick="', $context['is_approved'] ? '' : 'if (this.checked && !confirm(\'' . $txt['move_topic_unapproved_js'] . '\')) return false; ', 'document.getElementById(\'reasonArea\').style.display = this.checked ? \'block\' : \'none\';" class="input_check" /> ', $txt['moveTopic1'], '.</label>
-						<fieldset id="reasonArea" style="margin-top: 1ex;', $context['is_approved'] ? '' : 'display: none;', '">
-							<dl class="settings">
-								<dt>
-									', $txt['moved_why'], '
-								</dt>
-								<dd>
-									<textarea name="reason" rows="3" cols="40">', $txt['movetopic_default'], '</textarea>
-								</dd>
-								<dt>
-									<label for="redirect_topic">', $txt['movetopic_redirect'], '</label>
-								</dt>
-								<dd>
-									<input type="checkbox" name="redirect_topic" id="redirect_topic" checked="checked" class="input_check" />
-								</dd>
-								<dt>
-									', $txt['movetopic_expires'], '
-								</dt>
-								<dd>
-									<select name="redirect_expires">
-										<option value="0" selected="selected">', $txt['never'], '</option>
-										<option value="1440">', $txt['one_day'], '</option>
-										<option value="10080">', $txt['one_week'], '</option>
-										<option value="20160">', $txt['two_weeks'], '</option>
-										<option value="43200">', $txt['one_month'], '</option>
-										<option value="86400">', $txt['two_months'], '</option>
-									</select>
-								</dd>
-							</dl>
-						</fieldset>
-						<input type="submit" value="', $txt['move_topic'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
-						<br class="clear_right" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	if ($context['back_to_topic'])
-		echo '
-			<input type="hidden" name="goback" value="1" />';
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
-		</form>
-	</div>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+/**
+ * Show an interface for selecting which board to move a post to.
+ */
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="move_topic" class="lower_padding">
+		<form action="', $scripturl, '?action=movetopic2;current_board=' . $context['current_board'] . ';topic=', $context['current_topic'], '.0" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['move_topic'], '</h3>
+			</div>
+			<div class="windowbg centertext">
+				<div class="content">
+					<div class="move_topic">
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['move_to'], ':</strong>
+							</dt>
+							<dd>
+								<select name="toboard">';
+
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+									<optgroup label="', $category['name'], '">';
+
+		foreach ($category['boards'] as $board)
+			echo '
+										<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', $board['id'] == $context['current_board'] ? ' disabled="disabled"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level']-1) . '=&gt; ' : '', $board['name'], '</option>';
+		echo '
+									</optgroup>';
+	}
+
+	echo '
+								</select>
+							</dd>';
+
+	// Disable the reason textarea when the postRedirect checkbox is unchecked...
+	echo '
+						</dl>
+						<label for="reset_subject"><input type="checkbox" name="reset_subject" id="reset_subject" onclick="document.getElementById(\'subjectArea\').style.display = this.checked ? \'block\' : \'none\';" class="input_check" /> ', $txt['moveTopic2'], '.</label><br />
+						<fieldset id="subjectArea" style="display: none;">
+							<dl class="settings">
+								<dt><strong>', $txt['moveTopic3'], ':</strong></dt>
+								<dd><input type="text" name="custom_subject" size="30" value="', $context['subject'], '" class="input_text" /></dd>
+							</dl>
+							<label for="enforce_subject"><input type="checkbox" name="enforce_subject" id="enforce_subject" class="input_check" /> ', $txt['moveTopic4'], '.</label>
+						</fieldset>
+						<label for="postRedirect"><input type="checkbox" name="postRedirect" id="postRedirect" ', $context['is_approved'] ? 'checked="checked"' : '', ' onclick="', $context['is_approved'] ? '' : 'if (this.checked && !confirm(\'' . $txt['move_topic_unapproved_js'] . '\')) return false; ', 'document.getElementById(\'reasonArea\').style.display = this.checked ? \'block\' : \'none\';" class="input_check" /> ', $txt['moveTopic1'], '.</label>
+						<fieldset id="reasonArea" style="margin-top: 1ex;', $context['is_approved'] ? '' : 'display: none;', '">
+							<dl class="settings">
+								<dt>
+									', $txt['moved_why'], '
+								</dt>
+								<dd>
+									<textarea name="reason" rows="3" cols="40">', $txt['movetopic_default'], '</textarea>
+								</dd>
+								<dt>
+									<label for="redirect_topic">', $txt['movetopic_redirect'], '</label>
+								</dt>
+								<dd>
+									<input type="checkbox" name="redirect_topic" id="redirect_topic" checked="checked" class="input_check" />
+								</dd>
+								<dt>
+									', $txt['movetopic_expires'], '
+								</dt>
+								<dd>
+									<select name="redirect_expires">
+										<option value="0" selected="selected">', $txt['never'], '</option>
+										<option value="1440">', $txt['one_day'], '</option>
+										<option value="10080">', $txt['one_week'], '</option>
+										<option value="20160">', $txt['two_weeks'], '</option>
+										<option value="43200">', $txt['one_month'], '</option>
+										<option value="86400">', $txt['two_months'], '</option>
+									</select>
+								</dd>
+							</dl>
+						</fieldset>
+						<input type="submit" value="', $txt['move_topic'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
+						<br class="clear_right" />
+					</div>
+				</div>
+			</div>';
+
+	if ($context['back_to_topic'])
+		echo '
+			<input type="hidden" name="goback" value="1" />';
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
+		</form>
+	</div>';
+}
+
 ?>

+ 48 - 52
Themes/default/Notify.template.php

@@ -1,53 +1,49 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $txt['notify'], '</span>
-			</h3>
-		</div>
-		<span class="upperframe"><span></span></span>
-		<div class="roundframe centertext">
-			<p>', $context['notification_set'] ? $txt['notify_deactivate'] : $txt['notify_request'], '</p>
-			<p>
-				<strong><a href="', $scripturl, '?action=notify;sa=', $context['notification_set'] ? 'off' : 'on', ';topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $context['topic_href'], '">', $txt['no'], '</a></strong>
-			</p>
-		</div>
-		<span class="lowerframe"><span></span></span>';
-}
-
-function template_notify_board()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $txt['notify'], '</span>
-			</h3>
-		</div>
-		<span class="upperframe"><span></span></span>
-		<div class="roundframe centertext">
-			<p>', $context['notification_set'] ? $txt['notifyboard_turnoff'] : $txt['notifyboard_turnon'], '</p>
-			<p>
-				<strong><a href="', $scripturl, '?action=notifyboard;sa=', $context['notification_set'] ? 'off' : 'on', ';board=', $context['current_board'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $context['board_href'], '">', $txt['no'], '</a></strong>
-			</p>
-		</div>
-		<span class="lowerframe"><span></span></span>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $txt['notify'], '
+			</h3>
+		</div>
+		<div class="roundframe centertext">
+			<p>', $context['notification_set'] ? $txt['notify_deactivate'] : $txt['notify_request'], '</p>
+			<p>
+				<strong><a href="', $scripturl, '?action=notify;sa=', $context['notification_set'] ? 'off' : 'on', ';topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $context['topic_href'], '">', $txt['no'], '</a></strong>
+			</p>
+		</div>';
+}
+
+function template_notify_board()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $txt['notify'], '
+			</h3>
+		</div>
+		<div class="roundframe centertext">
+			<p>', $context['notification_set'] ? $txt['notifyboard_turnoff'] : $txt['notifyboard_turnon'], '</p>
+			<p>
+				<strong><a href="', $scripturl, '?action=notifyboard;sa=', $context['notification_set'] ? 'off' : 'on', ';board=', $context['current_board'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $context['board_href'], '">', $txt['no'], '</a></strong>
+			</p>
+		</div>';
+}
+
 ?>

+ 1826 - 1860
Themes/default/Packages.template.php

@@ -1,1861 +1,1827 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_main()
-{
-	global $context, $settings, $options;
-}
-
-function template_view_package()
-{
-	global $context, $settings, $options, $txt, $scripturl, $smcFunc;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt[($context['uninstalling'] ? 'un' : '') . 'install_mod'], '</h3>
-		</div>
-		<div class="information">';
-
-	if ($context['is_installed'])
-		echo '
-			<strong>', $txt['package_installed_warning1'], '</strong><br />
-			<br />
-			', $txt['package_installed_warning2'], '<br />
-			<br />';
-
-	echo $txt['package_installed_warning3'], '
-		</div>';
-
-	// Do errors exist in the install? If so light them up like a christmas tree.
-	if ($context['has_failure'])
-	{
-		echo '
-		<div class="errorbox">
-			', $txt['package_will_fail_title'], '<br />
-			', $txt['package_will_fail_warning'], 
-			!empty($context['failure_details']) ? '<br /><br /><strong>' . $context['failure_details'] . '</strong>' : '', '
-		</div>';
-	}
-
-	// Display the package readme if one exists
-	if (isset($context['package_readme']))
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['package_' . ($context['uninstalling'] ? 'un' : '') . 'install_readme'], '</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					', $context['package_readme'], '
-					<span class="floatright">', $txt['package_available_readme_language'], '
-						<select name="readme_language" id="readme_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', ';package=', $context['filename'], ';readme=\' + this.options[this.selectedIndex].value + \';license=\' + get_selected(\'license_language\'));">';
-							foreach ($context['readmes'] as $a => $b)
-								echo '<option value="', $b, '"', $a === 'selected' ? ' selected="selected"' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
-			echo '
-						</select>
-					</span>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />';
-	}
-	
-	// Did they specify a license to display?
-	if (isset($context['package_license']))
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['package_install_license'], '</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					', $context['package_license'], '
-					<span class="floatright">', $txt['package_available_license_language'], '
-						<select name="license_language" id="license_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=install', ';package=', $context['filename'], ';license=\' + this.options[this.selectedIndex].value + \';readme=\' + get_selected(\'readme_language\'));">';
-							foreach ($context['licenses'] as $a => $b)
-								echo '<option value="', $b, '"', $a === 'selected' ? ' selected="selected"' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
-			echo '
-						</select>
-					</span>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />';
-	}
-	
-	echo '
-		<form action="', $scripturl, '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', $context['ftp_needed'] ? '' : '2', ';package=', $context['filename'], ';pid=', $context['install_id'], '" onsubmit="submitonce(this);" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['package_install_actions'], ' &quot;', $context['package_name'], '&quot;
-				</h3>
-			</div>';
-
-	// Are there data changes to be removed?
-	if ($context['uninstalling'] && !empty($context['database_changes']))
-	{
-		echo '
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<label for="do_db_changes"><input type="checkbox" name="do_db_changes" id="do_db_changes" class="input_check" />', $txt['package_db_uninstall'], '</label> [<a href="#" onclick="return swap_database_changes();">', $txt['package_db_uninstall_details'], '</a>]
-					<div id="db_changes_div">
-						', $txt['package_db_uninstall_actions'], ':
-						<ul>';
-
-		foreach ($context['database_changes'] as $change)
-			echo '
-							<li>', $change, '</li>';
-		echo '
-						</ul>
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	echo '
-			<div class="information">';
-
-	if (empty($context['actions']) && empty($context['database_changes']))
-		echo '
-				<br />
-				<div class="errorbox">
-					', $txt['corrupt_compatible'], '
-				</div>
-			</div>';
-	else
-	{
-		echo '
-					', $txt['perform_actions'], '
-			</div>
-			<table class="table_grid" width="100%">
-			<thead>
-				<tr class="catbg">
-					<th class="first_th" scope="col" width="20"></th>
-					<th scope="col" width="30"></th>
-					<th scope="col" class="lefttext">', $txt['package_install_type'], '</th>
-					<th scope="col" class="lefttext" width="50%">', $txt['package_install_action'], '</th>
-					<th class="last_th lefttext" scope="col" class="lefttext" width="20%">', $txt['package_install_desc'], '</th>
-				</tr>
-			</thead>
-			<tbody>';
-
-		$alternate = true;
-		$i = 1;
-		$action_num = 1;
-		$js_operations = array();
-		foreach ($context['actions'] as $packageaction)
-		{
-			// Did we pass or fail?  Need to now for later on.
-			$js_operations[$action_num] = isset($packageaction['failed']) ? $packageaction['failed'] : 0;
-
-			echo '
-				<tr class="windowbg', $alternate ? '' : '2', '">
-					<td>', isset($packageaction['operations']) ? '<img id="operation_img_' . $action_num . '" src="' . $settings['images_url'] . '/selected_open.png" alt="*" style="display: none;" />' : '', '</td>
-					<td>', $i++, '.</td>
-					<td>', $packageaction['type'], '</td>
-					<td>', $packageaction['action'], '</td>
-					<td>', $packageaction['description'], '</td>
-				</tr>';
-
-			// Is there water on the knee? Operation!
-			if (isset($packageaction['operations']))
-			{
-				echo '
-				<tr id="operation_', $action_num, '">
-					<td colspan="5" class="windowbg3">
-						<table border="0" cellpadding="3" cellspacing="0" width="100%">';
-
-				// Show the operations.
-				$alternate2 = true;
-				$operation_num = 1;
-				foreach ($packageaction['operations'] as $operation)
-				{
-					// Determine the position text.
-					$operation_text = $operation['position'] == 'replace' ? 'operation_replace' : ($operation['position'] == 'before' ? 'operation_after' : 'operation_before');
-
-					echo '
-							<tr class="windowbg', $alternate2 ? '' : '2', '">
-								<td width="0"></td>
-								<td width="30" class="smalltext"><a href="' . $scripturl . '?action=admin;area=packages;sa=showoperations;operation_key=', $operation['operation_key'], ';package=', $_REQUEST['package'], ';filename=', $operation['filename'], ($operation['is_boardmod'] ? ';boardmod' : ''), (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'uninstall' ? ';reverse' : ''), '" onclick="return reqWin(this.href, 680, 400, false);"><img src="', $settings['default_images_url'], '/admin/package_ops.png" alt="" /></a></td>
-								<td width="30" class="smalltext">', $operation_num, '.</td>
-								<td width="23%" class="smalltext">', $txt[$operation_text], '</td>
-								<td width="50%" class="smalltext">', $operation['action'], '</td>
-								<td width="20%" class="smalltext">', $operation['description'], !empty($operation['ignore_failure']) ? ' (' . $txt['operation_ignore'] . ')' : '', '</td>
-							</tr>';
-
-					$operation_num++;
-					$alternate2 = !$alternate2;
-				}
-
-				echo '
-						</table>
-					</td>
-				</tr>';
-
-				// Increase it.
-				$action_num++;
-			}
-			$alternate = !$alternate;
-		}
-					echo '
-			</tbody>
-			</table>
-			';
-
-		// What if we have custom themes we can install into? List them too!
-		if (!empty($context['theme_actions']))
-		{
-			echo '
-			<br />
-			<div class="cat_bar">
-				<h3 class="catbg">
-					', $context['uninstalling'] ? $txt['package_other_themes_uninstall'] : $txt['package_other_themes'], '
-				</h3>
-			</div>
-			<div id="custom_changes">
-				<div class="information">
-					', $txt['package_other_themes_desc'], '
-				</div>
-				<table class="table_grid" width="100%">';
-
-			// Loop through each theme and display it's name, and then it's details.
-			foreach ($context['theme_actions'] as $id => $theme)
-			{
-				// Pass?
-				$js_operations[$action_num] = !empty($theme['has_failure']);
-
-				echo '
-					<tr class="catbg">
-						<td></td>
-						<td align="center">';
-				if (!empty($context['themes_locked']))
-					echo '
-							<input type="hidden" name="custom_theme[]" value="', $id, '" />';
-				echo '
-							<input type="checkbox" name="custom_theme[]" id="custom_theme_', $id, '" value="', $id, '" class="input_check" onclick="', (!empty($theme['has_failure']) ? 'if (this.form.custom_theme_' . $id . '.checked && !confirm(\'' . $txt['package_theme_failure_warning'] . '\')) return false;' : ''), 'invertAll(this, this.form, \'dummy_theme_', $id, '\', true);" ', !empty($context['themes_locked']) ? 'disabled="disabled" checked="checked"' : '', '/>
-						</td>
-						<td colspan="3">
-							', $theme['name'], '
-						</td>
-					</tr>';
-
-				foreach ($theme['actions'] as $action)
-				{
-					echo '
-					<tr class="windowbg', $alternate ? '' : '2', '">
-						<td>', isset($packageaction['operations']) ? '<img id="operation_img_' . $action_num . '" src="' . $settings['images_url'] . '/selected_open.png" alt="*" style="display: none;" />' : '', '</td>
-						<td width="30" align="center">
-							<input type="checkbox" name="theme_changes[]" value="', !empty($action['value']) ? $action['value'] : '', '" id="dummy_theme_', $id, '" class="input_check" ', (!empty($action['not_mod']) ? '' : 'disabled="disabled"'), ' ', !empty($context['themes_locked']) ? 'checked="checked"' : '', '/>
-						</td>
-						<td>', $action['type'], '</td>
-						<td width="50%">', $action['action'], '</td>
-						<td width="20%"><strong>', $action['description'], '</strong></td>
-					</tr>';
-
-					// Is there water on the knee? Operation!
-					if (isset($action['operations']))
-					{
-						echo '
-					<tr id="operation_', $action_num, '">
-						<td colspan="5" class="windowbg3">
-							<table border="0" cellpadding="3" cellspacing="0" width="100%">';
-
-						$alternate2 = true;
-						$operation_num = 1;
-						foreach ($action['operations'] as $operation)
-						{
-							// Determine the possition text.
-							$operation_text = $operation['position'] == 'replace' ? 'operation_replace' : ($operation['position'] == 'before' ? 'operation_after' : 'operation_before');
-
-							echo '
-								<tr class="windowbg', $alternate2 ? '' : '2', '">
-									<td width="0"></td>
-									<td width="30" class="smalltext"><a href="' . $scripturl . '?action=admin;area=packages;sa=showoperations;operation_key=', $operation['operation_key'], ';package=', $_REQUEST['package'], ';filename=', $operation['filename'], ($operation['is_boardmod'] ? ';boardmod' : ''), (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'uninstall' ? ';reverse' : ''), '" onclick="return reqWin(this.href, 600, 400, false);"><img src="', $settings['default_images_url'], '/admin/package_ops.png" alt="" /></a></td>
-									<td width="30" class="smalltext">', $operation_num, '.</td>
-									<td width="23%" class="smalltext">', $txt[$operation_text], '</td>
-									<td width="50%" class="smalltext">', $operation['action'], '</td>
-									<td width="20%" class="smalltext">', $operation['description'], !empty($operation['ignore_failure']) ? ' (' . $txt['operation_ignore'] . ')' : '', '</td>
-								</tr>';
-							$operation_num++;
-							$alternate2 = !$alternate2;
-						}
-
-						echo '
-							</table>
-						</td>
-					</tr>';
-
-						// Increase it.
-						$action_num++;
-					}
-				}
-
-				$alternate = !$alternate;
-			}
-
-			echo '
-				</table>
-			</div>';
-		}
-	}
-
-	// Are we effectively ready to install?
-	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes'])))
-	{
-		echo '
-			<div class="righttext padding">
-				<input type="submit" value="', $context['uninstalling'] ? $txt['package_uninstall_now'] : $txt['package_install_now'], '" onclick="return ', !empty($context['has_failure']) ? '(submitThisOnce(this) &amp;&amp; confirm(\'' . ($context['uninstalling'] ? $txt['package_will_fail_popup_uninstall'] : $txt['package_will_fail_popup']) . '\'))' : 'submitThisOnce(this)', ';" class="button_submit" />
-			</div>';
-	}
-	// If we need ftp information then demand it!
-	elseif ($context['ftp_needed'])
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['package_ftp_necessary'], '</h3>
-			</div>
-			<div>
-				', template_control_chmod(), '
-			</div>';
-	}
-		echo '
-
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />', (isset($context['form_sequence_number']) && !$context['ftp_needed']) ? '
-			<input type="hidden" name="seqnum" value="' . $context['form_sequence_number'] . '" />' : '', '
-		</form>
-	</div>
-	<br class="clear" />';
-
-	// Toggle options.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var aOperationElements = new Array();';
-
-		// Operations.
-		if (!empty($js_operations))
-		{
-			foreach ($js_operations as $key => $operation)
-			{
-				echo '
-			aOperationElements[', $key, '] = new smc_Toggle({
-				bToggleEnabled: true,
-				bCurrentlyCollapsed: ', $operation ? 'false' : 'true', ',
-				aSwappableContainers: [
-					\'operation_', $key, '\'
-				],
-				aSwapImages: [
-					{
-						sId: \'operation_img_', $key, '\',
-						srcExpanded: smf_images_url + \'/selected_open.png\',
-						altExpanded: \'*\',
-						srcCollapsed: smf_images_url + \'/selected.png\',
-						altCollapsed: \'*\'
-					}
-				]
-			});';
-			}
-		}
-
-	echo '
-	// ]]></script>';
-	
-	// Get the currently selected item from a select list
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-	function get_selected(id)
-	{
-		var aSelected = document.getElementById(id);
-		for (var i = 0; i < aSelected.options.length; i++)
-		{
-			if (aSelected.options[i].selected == true)
-				return aSelected.options[i].value;
-		}
-		return aSelected.options[0];
-	}
-	// ]]></script>';
-
-	// And a bit more for database changes.
-	if (!empty($context['database_changes']))
-		echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var database_changes_area = document.getElementById(\'db_changes_div\');
-		var db_vis = false;
-		database_changes_area.style.display = "none";
-	// ]]></script>';
-}
-
-function template_extract_package()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	if (!empty($context['redirect_url']))
-	{
-		echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		setTimeout("doRedirect();", ', empty($context['redirect_timeout']) ? '5000' : $context['redirect_timeout'], ');
-
-		function doRedirect()
-		{
-			window.location = "', $context['redirect_url'], '";
-		}
-	// ]]></script>';
-	}
-
-	echo '
-	<div id="admincenter">';
-
-	if (empty($context['redirect_url']))
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting'], '</h3>
-			</div>
-			<div class="information">', $txt['package_installed_extract'], '</div>';
-	}
-	else
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['package_installed_redirecting'], '</h3>
-			</div>';
-
-	echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">';
-
-	// If we are going to redirect we have a slightly different agenda.
-	if (!empty($context['redirect_url']))
-	{
-		echo '
-				', $context['redirect_text'], '<br /><br />
-				<a href="', $context['redirect_url'], '">', $txt['package_installed_redirect_go_now'], '</a> | <a href="', $scripturl, '?action=admin;area=packages;sa=browse">', $txt['package_installed_redirect_cancel'], '</a>';
-	}
-	elseif ($context['uninstalling'])
-		echo '
-				', $txt['package_uninstall_done'];
-	elseif ($context['install_finished'])
-	{
-		if ($context['extract_type'] == 'avatar')
-			echo '
-				', $txt['avatars_extracted'];
-		elseif ($context['extract_type'] == 'language')
-			echo '
-				', $txt['language_extracted'];
-		else
-			echo '
-				', $txt['package_installed_done'];
-	}
-	else
-		echo '
-				', $txt['corrupt_compatible'];
-
-	echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	// Show the "restore permissions" screen?
-	if (function_exists('template_show_list') && !empty($context['restore_file_permissions']['rows']))
-	{
-		echo '<br />';
-		template_show_list('restore_file_permissions');
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-function template_list()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['list_file'], '</h3>
-		</div>
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['files_archive'], ' ', $context['filename'], ':</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<ol>';
-
-	foreach ($context['files'] as $fileinfo)
-		echo '
-					<li><a href="', $scripturl, '?action=admin;area=packages;sa=examine;package=', $context['filename'], ';file=', $fileinfo['filename'], '" title="', $txt['view'], '">', $fileinfo['filename'], '</a> (', $fileinfo['size'], ' ', $txt['package_bytes'], ')</li>';
-
-	echo '
-				</ol>
-				<br />
-				<a href="', $scripturl, '?action=admin;area=packages">[ ', $txt['back'], ' ]</a>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_examine()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['package_examine_file'], '</h3>
-		</div>
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['package_file_contents'], ' ', $context['filename'], ':</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<pre class="file_content">', $context['filedata'], '</pre>
-				<a href="', $scripturl, '?action=admin;area=packages;sa=list;package=', $context['package'], '">[ ', $txt['list_files'], ' ]</a>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_browse()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings, $forum_version;
-
-	echo '
-	<div id="admincenter">';
-
-	if ($context['sub_action'] == 'browse')
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=latest_packages" onclick="return reqWin(this.href);" class="help"><img class="icon" src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a> ', $txt['packages_latest'], '</span>
-			</h3>
-		</div>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<div id="packagesLatest">', $txt['packages_latest_fetch'], '</div>
-			</div>
-			<span class="botslice clear_right"><span></span></span>
-		</div>
-
-		<script type="text/javascript"><!-- // --><![CDATA[
-			window.smfForum_scripturl = "', $scripturl, '";
-			window.smfForum_sessionid = "', $context['session_id'], '";
-			window.smfForum_sessionvar = "', $context['session_var'], '";';
-
-		// Make a list of already installed mods so nothing is listed twice ;).
-		echo '
-			window.smfInstalledPackages = ["', implode('", "', $context['installed_mods']), '"];
-			window.smfVersion = "', $context['forum_version'], '";
-		// ]]></script>';
-
-		if (empty($modSettings['disable_smf_js']))
-			echo '
-		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-packages.js"></script>';
-
-		echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var tempOldOnload;
-			smfSetLatestPackages();
-		// ]]></script>';
-
-		echo '
-		<br class="clear" />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['browse_packages'], '</h3>
-		</div>';
-	}
-
-	$mods_available = false;
-	foreach ($context['modification_types'] as $type)
-	{
-		if (!empty($context['available_' . $type]))
-		{
-			template_show_list('packages_lists_' . $type);
-			$mods_available = true;
-		}
-	}
-
-	if (!$mods_available)
-		echo '
-		<div class="information">', $context['sub_action'] == 'browse' ? $txt['no_packages'] : $txt['no_mods_installed'], '</div>';
-
-	// the advanced (emulation) box, collapsed by default
-	echo '
-		<br class="clear" />
-		<form action="', $scripturl, '?action=admin;area=packages;sa=', $context['sub_action'], '" method="get">
-			<div id="advanced_box" >
-				<div class="cat_bar">
-					<h3 class="catbg">
-						<img id="advanced_panel_toggle" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png" alt="*" />
-						<a href="#" id="advanced_panel_link">', $txt['package_advanced_button'], '</a>
-					</h3>
-				</div>
-				<div id="advanced_panel_div" class="windowbg">
-					<span class="topslice"><span></span></span>
-					<div class="content">
-						<p>
-							', $txt['package_emulate_desc'], '
-						</p>
-						<dl class="settings">
-							<dt>
-								<strong>', $txt['package_emulate'], ':</strong><br />
-								<span class="smalltext">
-									<a href="#" onclick="document.getElementById(\'ve\').value = \'', $forum_version, '\';document.getElementsByName(\'version_emulate\')[0].value = \'', $forum_version, '\';return false">', $txt['package_emulate_revert'], '</a>
-								</span>
-							</dt>
-							<dd>
-								<input type="text" name="version_emulate" id="ve" value="', $context['forum_version'], '" size="25" class="input_text" />
-							</dd>
-						</dl>
-						<div class="righttext padding">
-							<input type="submit" value="', $txt['package_apply'], '" class="button_submit" />
-						</div>
-					</div>
-					<span class="botslice"><span></span></span>
-				</div>
-			</div>
-			<input type="hidden" name="action" value="admin" />
-			<input type="hidden" name="area" value="packages" />
-			<input type="hidden" name="sa" value="', $context['sub_action'], '" />
-		</form>';
-	
-	echo '
-	</div>
-	<br class="clear" />
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oAdvancedPanelToggle = new smc_Toggle({
-			bToggleEnabled: true,
-			bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
-			aSwappableContainers: [
-				\'advanced_panel_div\'
-			],
-			aSwapImages: [
-				{
-					sId: \'advanced_panel_toggle\',
-					srcExpanded: smf_images_url + \'/collapse.png\',
-					altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
-					srcCollapsed: smf_images_url + \'/expand.png\',
-					altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
-				}
-			],
-			aSwapLinks: [
-				{
-					sId: \'advanced_panel_link\',
-					msgExpanded: ', JavaScriptEscape($txt['package_advanced_button']), ',
-					msgCollapsed: ', JavaScriptEscape($txt['package_advanced_button']), '
-				}
-			],
-			oThemeOptions: {
-				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
-				sOptionName: \'admin_preferences\',
-				sSessionVar: smf_session_var,
-				sSessionId: smf_session_id,
-				sThemeId: \'1\'
-			}
-		});
-	// ]]></script>
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-			var oAddVersionSuggest = new smc_AutoSuggest({
-			sSelf: \'oAddVersionSuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sControlId: \'ve\',
-			sSearchType: \'versions\',
-			bItemList: false
-		});
-	// ]]></script>';
-}
-
-function template_servers()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	if (!empty($context['package_ftp']['error']))
-			echo '
-					<div class="errorbox">
-						<tt>', $context['package_ftp']['error'], '</tt>
-					</div>';
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['download_new_package'], '</h3>
-		</div>';
-
-	if ($context['package_download_broken'])
-	{
-		echo '
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['package_ftp_necessary'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>
-					', $txt['package_ftp_why_download'], '
-				</p>
-				<form action="', $scripturl, '?action=admin;area=packages;get" method="post" accept-charset="', $context['character_set'], '">
-					<dl class="settings">
-						<dt>
-							<label for="ftp_server">', $txt['package_ftp_server'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="30" name="ftp_server" id="ftp_server" value="', $context['package_ftp']['server'], '" class="input_text" />
-							<label for="ftp_port">', $txt['package_ftp_port'], ':&nbsp;</label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', $context['package_ftp']['port'], '" class="input_text" />
-						</dd>
-						<dt>
-							<label for="ftp_username">', $txt['package_ftp_username'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="50" name="ftp_username" id="ftp_username" value="', $context['package_ftp']['username'], '" style="width: 99%;" class="input_text" />
-						</dd>
-						<dt>
-							<label for="ftp_password">', $txt['package_ftp_password'], ':</label>
-						</dt>
-						<dd>
-							<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
-						</dd>
-						<dt>
-							<label for="ftp_path">', $txt['package_ftp_path'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $context['package_ftp']['path'], '" style="width: 99%;" class="input_text" />
-						</dd>
-					</dl>
-					<div class="righttext">
-						<input type="submit" value="', $txt['package_proceed'], '" class="button_submit" />
-					</div>
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<fieldset>
-					<legend>' . $txt['package_servers'] . '</legend>
-					<ul class="package_servers">';
-	foreach ($context['servers'] as $server)
-		echo '
-						<li class="flow_auto">
-							<span class="floatleft">' . $server['name'] . '</span>
-							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=remove;server=' . $server['id'] . ';', $context['session_var'], '=', $context['session_id'], '">[ ' . $txt['delete'] . ' ]</a></span>
-							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $server['id'] . '">[ ' . $txt['package_browse'] . ' ]</a></span>
-						</li>';
-	echo '
-					</ul>
-				</fieldset>
-				<fieldset>
-					<legend>' . $txt['add_server'] . '</legend>
-					<form action="' . $scripturl . '?action=admin;area=packages;get;sa=add" method="post" accept-charset="', $context['character_set'], '">
-						<dl class="settings">
-							<dt>
-								<strong>' . $txt['server_name'] . ':</strong>
-							</dt>
-							<dd>
-								<input type="text" name="servername" size="44" value="SMF" class="input_text" />
-							</dd>
-							<dt>
-								<strong>' . $txt['serverurl'] . ':</strong>
-							</dt>
-							<dd>
-								<input type="text" name="serverurl" size="44" value="http://" class="input_text" />
-							</dd>
-						</dl>
-						<div class="righttext">
-							<input type="submit" value="' . $txt['add_server'] . '" class="button_submit" />
-							<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
-						</div>
-					</form>
-				</fieldset>
-				<fieldset>
-					<legend>', $txt['package_download_by_url'], '</legend>
-					<form action="', $scripturl, '?action=admin;area=packages;get;sa=download;byurl;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-						<dl class="settings">
-							<dt>
-								<strong>' . $txt['serverurl'] . ':</strong>
-							</dt>
-							<dd>
-								<input type="text" name="package" size="44" value="http://" class="input_text" />
-							</dd>
-							<dt>
-								<strong>', $txt['package_download_filename'], ':</strong>
-							</dt>
-							<dd>
-								<input type="text" name="filename" size="44" class="input_text" /><br />
-								<span class="smalltext">', $txt['package_download_filename_info'], '</span>
-							</dd>
-						</dl>
-						<div class="righttext">
-							<input type="submit" value="', $txt['download'], '" class="button_submit" />
-						</div>
-					</form>
-				</fieldset>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<br />
-		<div class="cat_bar">
-			<h3 class="catbg">' . $txt['package_upload_title'] . '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="' . $scripturl . '?action=admin;area=packages;get;sa=upload" method="post" accept-charset="', $context['character_set'], '" enctype="multipart/form-data" style="margin-bottom: 0;">
-					<dl class="settings">
-						<dt>
-							<strong>' . $txt['package_upload_select'] . ':</strong>
-						</dt>
-						<dd>
-							<input type="file" name="package" size="38" class="input_file" />
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" value="' . $txt['package_upload'] . '" class="button_submit" />
-					<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
-					<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_package_confirm()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $context['page_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $context['confirm_message'], '</p>
-				<a href="', $context['proceed_href'], '">[ ', $txt['package_confirm_proceed'], ' ]</a> <a href="JavaScript:history.go(-1);">[ ', $txt['package_confirm_go_back'], ' ]</a>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_package_list()
-{
-	global $context, $settings, $options, $txt, $scripturl, $smcFunc;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">' . $context['page_title'] . '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">';
-
-	// No packages, as yet.
-	if (empty($context['package_list']))
-		echo '
-				<ul>
-					<li>', $txt['no_packages'], '</li>
-				</ul>';
-	// List out the packages...
-	else
-	{
-		echo '
-				<ul id="package_list">';
-		foreach ($context['package_list'] as $i => $packageSection)
-		{
-			echo '
-					<li>
-						<strong><img id="ps_img_', $i, '" src="', $settings['images_url'], '/upshrink.png" alt="*" style="display: none;" /> ', $packageSection['title'], '</strong>';
-
-			if (!empty($packageSection['text']))
-				echo '
-						<div class="information">', $packageSection['text'], '</div>';
-
-			echo '
-						<', $context['list_type'], ' id="package_section_', $i, '" class="packages">';
-
-			$alt = false;
-
-			foreach ($packageSection['items'] as $id => $package)
-			{
-				echo '
-							<li>';
-				// Textual message. Could be empty just for a blank line...
-				if ($package['is_text'])
-					echo '
-								', empty($package['name']) ? '&nbsp;' : $package['name'];
-				// This is supposed to be a rule..
-				elseif ($package['is_line'])
-					echo '
-							<hr class="hrcolor" />';
-				// A remote link.
-				elseif ($package['is_remote'])
-				{
-					echo '
-							<strong>', $package['link'], '</strong>';
-				}
-				// A title?
-				elseif ($package['is_heading'] || $package['is_title'])
-				{
-					echo '
-							<strong>', $package['name'], '</strong>';
-				}
-				// Otherwise, it's a package.
-				else
-				{
-					// 1. Some mod [ Download ].
-					echo '
-							<strong><img id="ps_img_', $i, '_pkg_', $id, '" src="', $settings['images_url'], '/upshrink.png" alt="*" style="display: none;" /> ', $package['can_install'] ? '<strong>' . $package['name'] . '</strong> <a href="' . $package['download']['href'] . '">[ ' . $txt['download'] . ' ]</a>': $package['name'];
-
-					// Mark as installed and current?
-					if ($package['is_installed'] && !$package['is_newer'])
-						echo '<img src="', $settings['images_url'], '/icons/package_', $package['is_current'] ? 'installed' : 'old', '.png" width="12" height="11" class="centericon" style="margin-left: 2ex;" alt="', $package['is_current'] ? $txt['package_installed_current'] : $txt['package_installed_old'], '" />';
-
-					echo '
-							</strong>
-							<ul id="package_section_', $i, '_pkg_', $id, '" class="package_section">';
-
-					// Show the mod type?
-					if ($package['type'] != '')
-						echo '
-								<li class="package_section">', $txt['package_type'], ':&nbsp; ', $smcFunc['ucwords']($smcFunc['strtolower']($package['type'])), '</li>';
-					// Show the version number?
-					if ($package['version'] != '')
-						echo '
-								<li class="package_section">', $txt['mod_version'], ':&nbsp; ', $package['version'], '</li>';
-					// How 'bout the author?
-					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link']))
-						echo '
-								<li class="package_section">', $txt['mod_author'], ':&nbsp; ', $package['author']['link'], '</li>';
-					// The homepage....
-					if ($package['author']['website']['link'] != '')
-						echo '
-								<li class="package_section">', $txt['author_website'], ':&nbsp; ', $package['author']['website']['link'], '</li>';
-
-					// Desciption: bleh bleh!
-					// Location of file: http://someplace/.
-					echo '
-								<li class="package_section">', $txt['file_location'], ':&nbsp; <a href="', $package['href'], '">', $package['href'], '</a></li>
-								<li class="package_section"><div class="information">', $txt['package_description'], ':&nbsp; ', $package['description'], '</div></li>
-							</ul>';
-				}
-				$alt = !$alt;
-				echo '
-						</li>';
-			}
-			echo '
-					</', $context['list_type'], '>
-						</li>';
-		}
-		echo '
-				</ul>';
-
-	}
-
-	echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<div class="padding smalltext floatleft">
-			', $txt['package_installed_key'], '
-			<img src="', $settings['images_url'], '/icons/package_installed.png" alt="" class="centericon" style="margin-left: 1ex;" /> ', $txt['package_installed_current'], '
-			<img src="', $settings['images_url'], '/icons/package_old.png" alt="" class="centericon" style="margin-left: 2ex;" /> ', $txt['package_installed_old'], '
-		</div>
-	</div>
-	<br class="clear" />
-
-		';
-		// Now go through and turn off all the sections.
-		if (!empty($context['package_list']))
-		{
-			$section_count = count($context['package_list']);
-			echo '
-			<script type="text/javascript"><!-- // --><![CDATA[';
-			foreach ($context['package_list'] as $section => $ps)
-			{
-				echo '
-				var oPackageServerToggle_', $section, ' = new smc_Toggle({
-					bToggleEnabled: true,
-					bCurrentlyCollapsed: ', count($ps['items']) == 1 || $section_count == 1 ? 'false' : 'true', ',
-					aSwappableContainers: [
-						\'package_section_', $section, '\'
-					],
-					aSwapImages: [
-						{
-							sId: \'ps_img_', $section, '\',
-							srcExpanded: smf_images_url + \'/upshrink.png\',
-							altExpanded: \'*\',
-							srcCollapsed: smf_images_url + \'/upshrink2.png\',
-							altCollapsed: \'*\'
-						}
-					]
-				});';
-
-				foreach ($ps['items'] as $id => $package)
-				{
-					if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote'])
-						echo '
-				var oPackageToggle_', $section, '_pkg_', $id, ' = new smc_Toggle({
-					bToggleEnabled: true,
-					bCurrentlyCollapsed: true,
-					aSwappableContainers: [
-						\'package_section_', $section, '_pkg_', $id, '\'
-					],
-					aSwapImages: [
-						{
-							sId: \'ps_img_', $section, '_pkg_', $id, '\',
-							srcExpanded: smf_images_url + \'/upshrink.png\',
-							altExpanded: \'*\',
-							srcCollapsed: smf_images_url + \'/upshrink2.png\',
-							altCollapsed: \'*\'
-						}
-					]
-				});';
-				}
-			}
-			echo '
-			// ]]></script>';
-		}
-}
-
-function template_downloaded()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $context['page_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', (empty($context['package_server']) ? $txt['package_uploaded_successfully'] : $txt['package_downloaded_successfully']), '</p>
-				<ul class="reset">
-					<li class="reset"><span class="floatleft"><strong>', $context['package']['name'], '</strong></span>
-						<span class="package_server floatright">', $context['package']['list_files']['link'], '</span>
-						<span class="package_server floatright">', $context['package']['install']['link'], '</span>
-					</li>
-				</ul>
-				<br /><br />
-				<p><a href="', $scripturl, '?action=admin;area=packages;get', (isset($context['package_server']) ? ';sa=browse;server=' . $context['package_server'] : ''), '">[ ', $txt['back'], ' ]</a></p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_install_options()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['package_install_options'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['package_install_options_ftp_why'], '
-		</div>
-
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<form action="', $scripturl, '?action=admin;area=packages;sa=options" method="post" accept-charset="', $context['character_set'], '">
-					<dl class="settings">
-						<dt>
-							<label for="pack_server"><strong>', $txt['package_install_options_ftp_server'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="pack_server" id="pack_server" value="', $context['package_ftp_server'], '" size="30" class="input_text" />
-						</dd>
-						<dt>
-							<label for="pack_port"><strong>', $txt['package_install_options_ftp_port'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="pack_port" id="pack_port" size="3" value="', $context['package_ftp_port'], '" class="input_text" />
-						</dd>
-						<dt>
-							<label for="pack_user"><strong>', $txt['package_install_options_ftp_user'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" name="pack_user" id="pack_user" value="', $context['package_ftp_username'], '" size="30" class="input_text" />
-						</dd>
-						<dt>
-							<label for="package_make_backups">', $txt['package_install_options_make_backups'], '</label>
-						</dt>
-						<dd>
-							<input type="checkbox" name="package_make_backups" id="package_make_backups" value="1" class="input_check"', $context['package_make_backups'] ? ' checked="checked"' : '', ' />
-						</dd>
-						<dt>
-							<label for="package_make_full_backups">', $txt['package_install_options_make_full_backups'], '</label>
-						</dt>
-						<dd>
-							<input type="checkbox" name="package_make_full_backups" id="package_make_full_backups" value="1" class="input_check"', $context['package_make_full_backups'] ? ' checked="checked"' : '', ' />
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_control_chmod()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Nothing to do? Brilliant!
-	if (empty($context['package_ftp']))
-		return false;
-
-	if (empty($context['package_ftp']['form_elements_only']))
-	{
-		echo '
-				', sprintf($txt['package_ftp_why'], 'document.getElementById(\'need_writable_list\').style.display = \'\'; return false;'), '<br />
-				<div id="need_writable_list" class="smalltext">
-					', $txt['package_ftp_why_file_list'], '
-					<ul style="display: inline;">';
-		if (!empty($context['notwritable_files']))
-			foreach ($context['notwritable_files'] as $file)
-				echo '
-						<li>', $file, '</li>';
-
-		echo '
-					</ul>
-				</div>';
-	}
-
-	echo '
-				<div class="bordercolor" id="ftp_error_div" style="', (!empty($context['package_ftp']['error']) ? '' : 'display:none;'), 'padding: 1px; margin: 1ex;"><div class="windowbg2" id="ftp_error_innerdiv" style="padding: 1ex;">
-					<tt id="ftp_error_message">', !empty($context['package_ftp']['error']) ? $context['package_ftp']['error'] : '', '</tt>
-				</div></div>';
-
-	if (!empty($context['package_ftp']['destination']))
-		echo '
-				<form action="', $context['package_ftp']['destination'], '" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;">';
-
-	echo '
-					<fieldset>
-					<dl class="settings">
-						<dt>
-							<label for="ftp_server">', $txt['package_ftp_server'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="30" name="ftp_server" id="ftp_server" value="', $context['package_ftp']['server'], '" class="input_text" />
-							<label for="ftp_port">', $txt['package_ftp_port'], ':&nbsp;</label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', $context['package_ftp']['port'], '" class="input_text" />
-						</dd>
-						<dt>
-							<label for="ftp_username">', $txt['package_ftp_username'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="50" name="ftp_username" id="ftp_username" value="', $context['package_ftp']['username'], '" style="width: 98%;" class="input_text" />
-						</dd>
-						<dt>
-							<label for="ftp_password">', $txt['package_ftp_password'], ':</label>
-						</dt>
-						<dd>
-							<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 98%;" class="input_password" />
-						</dd>
-						<dt>
-							<label for="ftp_path">', $txt['package_ftp_path'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $context['package_ftp']['path'], '" style="width: 98%;" class="input_text" />
-						</dd>
-					</dl>
-					</fieldset>';
-
-	if (empty($context['package_ftp']['form_elements_only']))
-		echo '
-
-					<div class="righttext" style="margin: 1ex;">
-						<span id="test_ftp_placeholder_full"></span>
-						<input type="submit" value="', $txt['package_proceed'], '" class="button_submit" />
-					</div>';
-
-	if (!empty($context['package_ftp']['destination']))
-		echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				</form>';
-
-	// Hide the details of the list.
-	if (empty($context['package_ftp']['form_elements_only']))
-		echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			document.getElementById(\'need_writable_list\').style.display = \'none\';
-		// ]]></script>';
-
-	// Quick generate the test button.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		// Generate a "test ftp" button.
-		var generatedButton = false;
-		function generateFTPTest()
-		{
-			// Don\'t ever call this twice!
-			if (generatedButton)
-				return false;
-			generatedButton = true;
-
-			// No XML?
-			if (!window.XMLHttpRequest || (!document.getElementById("test_ftp_placeholder") && !document.getElementById("test_ftp_placeholder_full")))
-				return false;
-
-			var ftpTest = document.createElement("input");
-			ftpTest.type = "button";
-			ftpTest.onclick = testFTP;
-
-			if (document.getElementById("test_ftp_placeholder"))
-			{
-				ftpTest.value = "', $txt['package_ftp_test'], '";
-				document.getElementById("test_ftp_placeholder").appendChild(ftpTest);
-			}
-			else
-			{
-				ftpTest.value = "', $txt['package_ftp_test_connection'], '";
-				document.getElementById("test_ftp_placeholder_full").appendChild(ftpTest);
-			}
-		}
-		function testFTPResults(oXMLDoc)
-		{
-			ajax_indicator(false);
-
-			// This assumes it went wrong!
-			var wasSuccess = false;
-			var message = "', addcslashes($txt['package_ftp_test_failed'], "'"), '";
-
-			var results = oXMLDoc.getElementsByTagName(\'results\')[0].getElementsByTagName(\'result\');
-			if (results.length > 0)
-			{
-				if (results[0].getAttribute(\'success\') == 1)
-					wasSuccess = true;
-				message = results[0].firstChild.nodeValue;
-			}
-
-			document.getElementById("ftp_error_div").style.display = "";
-			document.getElementById("ftp_error_div").style.backgroundColor = wasSuccess ? "green" : "red";
-			document.getElementById("ftp_error_innerdiv").style.backgroundColor = wasSuccess ? "#DBFDC7" : "#FDBDBD";
-
-			setInnerHTML(document.getElementById("ftp_error_message"), message);
-		}
-		generateFTPTest();
-	// ]]></script>';
-
-	// Make sure the button gets generated last.
-	$context['insert_after_template'] .= '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		generateFTPTest();
-	// ]]></script>';
-}
-
-function template_ftp_required()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<fieldset>
-			<legend>
-				', $txt['package_ftp_necessary'], '
-			</legend>
-			<div class="ftp_details">
-				', template_control_chmod(), '
-			</div>
-		</fieldset>';
-}
-
-function template_view_operations()
-{
-	global $context, $txt, $settings;
-
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<title>', $txt['operation_title'], '</title>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
-		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/admin.css?alp21" />
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?alp21"></script>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/theme.js?alp21"></script>
-	</head>
-	<body>
-		<div class="padding windowbg">
-			<div class="padding">
-				', $context['operations']['search'], '
-			</div>
-			<div class="padding">
-				', $context['operations']['replace'], '
-			</div>
-		</div>
-	</body>
-</html>';
-}
-
-function template_file_permissions()
-{
-	global $txt, $scripturl, $context, $settings;
-
-	// This will handle expanding the selection.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oRadioColors = {
-			0: "#D1F7BF",
-			1: "#FFBBBB",
-			2: "#FDD7AF",
-			3: "#C2C6C0",
-			4: "#EEEEEE"
-		}
-		var oRadioValues = {
-			0: "read",
-			1: "writable",
-			2: "execute",
-			3: "custom",
-			4: "no_change"
-		}
-		function dynamicAddMore()
-		{
-			ajax_indicator(true);
-
-			getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=admin;area=packages;fileoffset=\' + (parseInt(this.offset) + ', $context['file_limit'], ') + \';onlyfind=\' + escape(this.path) + \';sa=perms;xml;', $context['session_var'], '=', $context['session_id'], '\', onNewFolderReceived);
-		}
-
-		// Getting something back?
-		function onNewFolderReceived(oXMLDoc)
-		{
-			ajax_indicator(false);
-
-			var fileItems = oXMLDoc.getElementsByTagName(\'folders\')[0].getElementsByTagName(\'folder\');
-
-			// No folders, no longer worth going further.
-			if (fileItems.length < 1)
-			{
-				if (oXMLDoc.getElementsByTagName(\'roots\')[0].getElementsByTagName(\'root\')[0])
-				{
-					var rootName = oXMLDoc.getElementsByTagName(\'roots\')[0].getElementsByTagName(\'root\')[0].firstChild.nodeValue;
-					var itemLink = document.getElementById(\'link_\' + rootName);
-
-					// Move the children up.
-					for (i = 0; i <= itemLink.childNodes.length; i++)
-						itemLink.parentNode.insertBefore(itemLink.childNodes[0], itemLink);
-
-					// And remove the link.
-					itemLink.parentNode.removeChild(itemLink);
-				}
-				return false;
-			}
-			var tableHandle = false;
-			var isMore = false;
-			var ident = "";
-			var my_ident = "";
-			var curLevel = 0;
-
-			for (var i = 0; i < fileItems.length; i++)
-			{
-				if (fileItems[i].getAttribute(\'more\') == 1)
-				{
-					isMore = true;
-					var curOffset = fileItems[i].getAttribute(\'offset\');
-				}
-
-				if (fileItems[i].getAttribute(\'more\') != 1 && document.getElementById("insert_div_loc_" + fileItems[i].getAttribute(\'ident\')))
-				{
-					ident = fileItems[i].getAttribute(\'ident\');
-					my_ident = fileItems[i].getAttribute(\'my_ident\');
-					curLevel = fileItems[i].getAttribute(\'level\') * 5;
-					curPath = fileItems[i].getAttribute(\'path\');
-
-					// Get where we\'re putting it next to.
-					tableHandle = document.getElementById("insert_div_loc_" + fileItems[i].getAttribute(\'ident\'));
-
-					var curRow = document.createElement("tr");
-					curRow.className = "windowbg";
-					curRow.id = "content_" + my_ident;
-					curRow.style.display = "";
-					var curCol = document.createElement("td");
-					curCol.className = "smalltext";
-					curCol.width = "40%";
-
-					// This is the name.
-					var fileName = document.createTextNode(fileItems[i].firstChild.nodeValue);
-
-					// Start by wacking in the spaces.
-					setInnerHTML(curCol, repeatString("&nbsp;", curLevel));
-
-					// Create the actual text.
-					if (fileItems[i].getAttribute(\'folder\') == 1)
-					{
-						var linkData = document.createElement("a");
-						linkData.name = "fol_" + my_ident;
-						linkData.id = "link_" + my_ident;
-						linkData.href = \'#\';
-						linkData.path = curPath + "/" + fileItems[i].firstChild.nodeValue;
-						linkData.ident = my_ident;
-						linkData.onclick = dynamicExpandFolder;
-
-						var folderImage = document.createElement("img");
-						folderImage.src = \'', addcslashes($settings['default_images_url'], "\\"), '/board.png\';
-						linkData.appendChild(folderImage);
-
-						linkData.appendChild(fileName);
-						curCol.appendChild(linkData);
-					}
-					else
-						curCol.appendChild(fileName);
-
-					curRow.appendChild(curCol);
-
-					// Right, the permissions.
-					curCol = document.createElement("td");
-					curCol.className = "smalltext";
-
-					var writeSpan = document.createElement("span");
-					writeSpan.style.color = fileItems[i].getAttribute(\'writable\') ? "green" : "red";
-					setInnerHTML(writeSpan, fileItems[i].getAttribute(\'writable\') ? \'', $txt['package_file_perms_writable'], '\' : \'', $txt['package_file_perms_not_writable'], '\');
-					curCol.appendChild(writeSpan);
-
-					if (fileItems[i].getAttribute(\'permissions\'))
-					{
-						var permData = document.createTextNode("\u00a0(', $txt['package_file_perms_chmod'], ': " + fileItems[i].getAttribute(\'permissions\') + ")");
-						curCol.appendChild(permData);
-					}
-
-					curRow.appendChild(curCol);
-
-					// Now add the five radio buttons.
-					for (j = 0; j < 5; j++)
-					{
-						curCol = document.createElement("td");
-						curCol.style.backgroundColor = oRadioColors[j];
-						curCol.align = "center";
-
-						var curInput = createNamedElement("input", "permStatus[" + curPath + "/" + fileItems[i].firstChild.nodeValue + "]", j == 4 ? \'checked="checked"\' : "");
-						curInput.type = "radio";
-						curInput.checked = "checked";
-						curInput.value = oRadioValues[j];
-
-						curCol.appendChild(curInput);
-						curRow.appendChild(curCol);
-					}
-
-					// Put the row in.
-					tableHandle.parentNode.insertBefore(curRow, tableHandle);
-
-					// Put in a new dummy section?
-					if (fileItems[i].getAttribute(\'folder\') == 1)
-					{
-						var newRow = document.createElement("tr");
-						newRow.id = "insert_div_loc_" + my_ident;
-						newRow.style.display = "none";
-						tableHandle.parentNode.insertBefore(newRow, tableHandle);
-						var newCol = document.createElement("td");
-						newCol.colspan = 2;
-						newRow.appendChild(newCol);
-					}
-				}
-			}
-
-			// Is there some more to remove?
-			if (document.getElementById("content_" + ident + "_more"))
-			{
-				document.getElementById("content_" + ident + "_more").parentNode.removeChild(document.getElementById("content_" + ident + "_more"));
-			}
-
-			// Add more?
-			if (isMore && tableHandle)
-			{
-				// Create the actual link.
-				var linkData = document.createElement("a");
-				linkData.href = \'#fol_\' + my_ident;
-				linkData.path = curPath;
-				linkData.offset = curOffset;
-				linkData.onclick = dynamicAddMore;
-
-				linkData.appendChild(document.createTextNode(\'', $txt['package_file_perms_more_files'], '\'));
-
-				curRow = document.createElement("tr");
-				curRow.className = "windowbg";
-				curRow.id = "content_" + ident + "_more";
-				tableHandle.parentNode.insertBefore(curRow, tableHandle);
-				curCol = document.createElement("td");
-				curCol.className = "smalltext";
-				curCol.width = "40%";
-
-				setInnerHTML(curCol, repeatString("&nbsp;", curLevel));
-				curCol.appendChild(document.createTextNode(\'\\u00ab \'));
-				curCol.appendChild(linkData);
-				curCol.appendChild(document.createTextNode(\' \\u00bb\'));
-
-				curRow.appendChild(curCol);
-				curCol = document.createElement("td");
-				curCol.className = "smalltext";
-				curRow.appendChild(curCol);
-			}
-
-			// Keep track of it.
-			var curInput = createNamedElement("input", "back_look[]");
-			curInput.type = "hidden";
-			curInput.value = curPath;
-
-			curCol.appendChild(curInput);
-		}
-	// ]]></script>';
-
-		echo '
-	<div class="information">
-		<div>
-			<strong>', $txt['package_file_perms_warning'], ':</strong>
-			<div class="smalltext">
-				<ol style="margin-top: 2px; margin-bottom: 2px">
-					', $txt['package_file_perms_warning_desc'], '
-				</ol>
-			</div>
-		</div>
-	</div>
-
-	<form action="', $scripturl, '?action=admin;area=packages;sa=perms;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
-		<div class="title_bar">
-			<h3 class="titlebg">
-				<span class="floatleft">', $txt['package_file_perms'], '</span><span class="fperm floatright">', $txt['package_file_perms_new_status'], '</span>
-			</h3>
-		</div>
-		<table width="100%" class="table_grid">
-			<thead>
-				<tr class="catbg">
-					<th class="first_th lefttext" width="30%">&nbsp;', $txt['package_file_perms_name'], '&nbsp;</th>
-					<th width="30%" class="lefttext">', $txt['package_file_perms_status'], '</th>
-					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_read'], '</span></th>
-					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_write'], '</span></th>
-					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_execute'], '</span></th>
-					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_custom'], '</span></th>
-					<th class="last_th" align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_no_change'], '</span></th>
-				</tr>
-			</thead>';
-
-	foreach ($context['file_tree'] as $name => $dir)
-	{
-		echo '
-			<tbody>
-				<tr class="windowbg2">
-					<td width="30%"><strong>';
-
-				if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
-					echo '
-						<img src="', $settings['default_images_url'], '/board.png" alt="*" />';
-
-				echo '
-						', $name, '
-					</strong></td>
-					<td width="30%">
-						<span style="color: ', ($dir['perms']['chmod'] ? 'green' : 'red'), '">', ($dir['perms']['chmod'] ? $txt['package_file_perms_writable'] : $txt['package_file_perms_not_writable']), '</span>
-						', ($dir['perms']['perms'] ? '&nbsp;(' . $txt['package_file_perms_chmod'] . ': ' . substr(sprintf('%o', $dir['perms']['perms']), -4) . ')' : ''), '
-					</td>
-					<td align="center" class="perm_read" width="8%"><input type="radio" name="permStatus[', $name, ']" value="read" class="input_radio" /></td>
-					<td align="center" class="perm_write" width="8%"><input type="radio" name="permStatus[', $name, ']" value="writable" class="input_radio" /></td>
-					<td align="center" class="perm_execute" width="8%"><input type="radio" name="permStatus[', $name, ']" value="execute" class="input_radio" /></td>
-					<td align="center" class="perm_custom" width="8%"><input type="radio" name="permStatus[', $name, ']" value="custom" class="input_radio" /></td>
-					<td align="center" class="perm_nochange" width="8%"><input type="radio" name="permStatus[', $name, ']" value="no_change" checked="checked" class="input_radio" /></td>
-				</tr>
-			</tbody>';
-
-		if (!empty($dir['contents']))
-			template_permission_show_contents($name, $dir['contents'], 1);
-	}
-
-	echo '
-
-		</table>
-		<br />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['package_file_perms_change'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<fieldset>
-					<dl>
-						<dt>
-							<input type="radio" name="method" value="individual" checked="checked" id="method_individual" class="input_radio" />
-							<label for="method_individual"><strong>', $txt['package_file_perms_apply'], '</strong></label>
-						</dt>
-						<dd>
-							<em class="smalltext">', $txt['package_file_perms_custom'], ': <input type="text" name="custom_value" value="0755" maxlength="4" size="5" class="input_text" />&nbsp;<a href="', $scripturl, '?action=helpadmin;help=chmod_flags" onclick="return reqWin(this.href);" class="help">(?)</a></em>
-						</dd>
-						<dt>
-							<input type="radio" name="method" value="predefined" id="method_predefined" class="input_radio" />
-							<label for="method_predefined"><strong>', $txt['package_file_perms_predefined'], ':</strong></label>
-							<select name="predefined" onchange="document.getElementById(\'method_predefined\').checked = \'checked\';">
-								<option value="restricted" selected="selected">', $txt['package_file_perms_pre_restricted'], '</option>
-								<option value="standard">', $txt['package_file_perms_pre_standard'], '</option>
-								<option value="free">', $txt['package_file_perms_pre_free'], '</option>
-							</select>
-						</dt>
-						<dd>
-							<em class="smalltext">', $txt['package_file_perms_predefined_note'], '</em>
-						</dd>
-					</dl>
-				</fieldset>';
-
-	// Likely to need FTP?
-	if (empty($context['ftp_connected']))
-		echo '
-				<p>
-					', $txt['package_file_perms_ftp_details'], ':
-				</p>
-				', template_control_chmod(), '
-				<div class="information">', $txt['package_file_perms_ftp_retain'], '</div>';
-
-	echo '
-				<span id="test_ftp_placeholder_full"></span>
-				<hr class="hrcolor" />
-				<input type="hidden" name="action_changes" value="1" />
-				<input type="submit" value="', $txt['package_file_perms_go'], '" name="go" class="button_submit" />
-				<br class="clear_right" />
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	// Any looks fors we've already done?
-	foreach ($context['look_for'] as $path)
-		echo '
-			<input type="hidden" name="back_look[]" value="', $path, '" />';
-	echo '
-	</form><br />';
-}
-
-function template_permission_show_contents($ident, $contents, $level, $has_more = false)
-{
-	global $settings, $txt, $scripturl, $context;
-	$js_ident = preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident);
-	// Have we actually done something?
-	$drawn_div = false;
-
-	foreach ($contents as $name => $dir)
-	{
-		if (isset($dir['perms']))
-		{
-			if (!$drawn_div)
-			{
-				$drawn_div = true;
-				echo '
-			</table>
-			<table border="0" width="100%" class="table_grid" id="', $js_ident, '">';
-			}
-
-			$cur_ident = preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident . '/' . $name);
-			echo '
-			<tr class="windowbg" id="content_', $cur_ident, '">
-				<td class="smalltext" width="30%">' . str_repeat('&nbsp;', $level * 5), '
-					', (!empty($dir['type']) && $dir['type'] == 'dir_recursive') || !empty($dir['list_contents']) ? '<a id="link_' . $cur_ident . '" href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident . '/' . $name) . ';back_look=' . $context['back_look_data'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . $cur_ident . '" onclick="return expandFolder(\'' . $cur_ident . '\', \'' . addcslashes($ident . '/' . $name, "'\\") . '\');">' : '';
-
-			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
-				echo '
-					<img src="', $settings['default_images_url'], '/board.png" alt="*" />';
-
-			echo '
-					', $name, '
-					', (!empty($dir['type']) && $dir['type'] == 'dir_recursive') || !empty($dir['list_contents']) ? '</a>' : '', '
-				</td>
-				<td class="smalltext">
-					<span class="', ($dir['perms']['chmod'] ? 'success' : 'error'), '">', ($dir['perms']['chmod'] ? $txt['package_file_perms_writable'] : $txt['package_file_perms_not_writable']), '</span>
-					', ($dir['perms']['perms'] ? '&nbsp;(' . $txt['package_file_perms_chmod'] . ': ' . substr(sprintf('%o', $dir['perms']['perms']), -4) . ')' : ''), '
-				</td>
-				<td align="center" width="8%" class="perm_read"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="read" class="input_radio" /></td>
-				<td align="center" width="8%" class="perm_write"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="writable" class="input_radio" /></td>
-				<td align="center" width="8%" class="perm_execute"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="execute" class="input_radio" /></td>
-				<td align="center" width="8%" class="perm_custom"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="custom" class="input_radio" /></td>
-				<td align="center" width="8%" class="perm_nochange"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="no_change" checked="checked" class="input_radio" /></td>
-			</tr>
-			<tr id="insert_div_loc_' . $cur_ident . '" style="display: none;"><td></td></tr>';
-
-			if (!empty($dir['contents']))
-			{
-				template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
-
-			}
-		}
-	}
-
-	// We have more files to show?
-	if ($has_more)
-		echo '
-	<tr class="windowbg" id="content_', $js_ident, '_more">
-		<td class="smalltext" width="40%">' . str_repeat('&nbsp;', $level * 5), '
-			&#171; <a href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident) . ';fileoffset=', ($context['file_offset'] + $context['file_limit']), ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident) . '">', $txt['package_file_perms_more_files'], '</a> &#187;
-		</td>
-		<td colspan="6"></td>
-	</tr>';
-
-	if ($drawn_div)
-	{
-		// Hide anything too far down the tree.
-		$isFound = false;
-		foreach ($context['look_for'] as $tree)
-		{
-			if (substr($tree, 0, strlen($ident)) == $ident)
-				$isFound = true;
-		}
-
-		if ($level > 1 && !$isFound)
-			echo '
-		</table><script type="text/javascript"><!-- // --><![CDATA[
-			expandFolder(\'', $js_ident, '\', \'\');
-		// ]]></script>
-		<table border="0" width="100%" class="table_grid">
-			<tr style="display: none;"><td></td></tr>';
-	}
-}
-
-function template_action_permissions()
-{
-	global $txt, $scripturl, $context, $settings;
-
-	$countDown = 3;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=packages;sa=perms;', $context['session_var'], '=', $context['session_id'], '" id="perm_submit" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['package_file_perms_applying'], '</h3>
-			</div>';
-
-	if (!empty($context['skip_ftp']))
-		echo '
-			<div class="errorbox">
-				', $txt['package_file_perms_skipping_ftp'], '
-			</div>';
-
-	// How many have we done?
-	$remaining_items = count($context['method'] == 'individual' ? $context['to_process'] : $context['directory_list']);
-	$progress_message = sprintf($context['method'] == 'individual' ? $txt['package_file_perms_items_done'] : $txt['package_file_perms_dirs_done'], $context['total_items'] - $remaining_items, $context['total_items']);
-	$progress_percent = round(($context['total_items'] - $remaining_items) / $context['total_items'] * 100, 1);
-
-	echo '
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div>
-						<strong>', $progress_message, '</strong><br /><br />
-						<div class="progress_bar">
-							<div class="full_bar">', $progress_percent, '%</div>
-							<div class="blue_percent" style="width: ', $progress_percent, '%;">&nbsp;</div>
-						</div>
-					</div>';
-
-	// Second progress bar for a specific directory?
-	if ($context['method'] != 'individual' && !empty($context['total_files']))
-	{
-		$file_progress_message = sprintf($txt['package_file_perms_files_done'], $context['file_offset'], $context['total_files']);
-		$file_progress_percent = round($context['file_offset'] / $context['total_files'] * 100, 1);
-
-		echo '
-					<br />
-					<div>
-						<strong>', $file_progress_message, '</strong><br /><br />
-						<div class="progress_bar">
-							<div class="full_bar">', $file_progress_percent, '%</div>
-							<div class="green_percent" style="width: ', $file_progress_percent, '%;">&nbsp;</div>
-						</div>
-					</div>';
-	}
-
-	echo '
-					<br />';
-
-	// Put out the right hidden data.
-	if ($context['method'] == 'individual')
-		echo '
-					<input type="hidden" name="custom_value" value="', $context['custom_value'], '" />
-					<input type="hidden" name="totalItems" value="', $context['total_items'], '" />
-					<input type="hidden" name="toProcess" value="', base64_encode(serialize($context['to_process'])), '" />';
-	else
-		echo '
-					<input type="hidden" name="predefined" value="', $context['predefined_type'], '" />
-					<input type="hidden" name="fileOffset" value="', $context['file_offset'], '" />
-					<input type="hidden" name="totalItems" value="', $context['total_items'], '" />
-					<input type="hidden" name="dirList" value="', base64_encode(serialize($context['directory_list'])), '" />
-					<input type="hidden" name="specialFiles" value="', base64_encode(serialize($context['special_files'])), '" />';
-
-	// Are we not using FTP for whatever reason.
-	if (!empty($context['skip_ftp']))
-		echo '
-					<input type="hidden" name="skip_ftp" value="1" />';
-
-	// Retain state.
-	foreach ($context['back_look_data'] as $path)
-		echo '
-					<input type="hidden" name="back_look[]" value="', $path, '" />';
-
-	echo '
-					<input type="hidden" name="method" value="', $context['method'], '" />
-					<input type="hidden" name="action_changes" value="1" />
-					<div class="righttext padding">
-						<input type="submit" name="go" id="cont" value="', $txt['not_done_continue'], '" class="button_submit" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-
-	// Just the countdown stuff
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var countdown = ', $countDown, ';
-		doAutoSubmit();
-
-		function doAutoSubmit()
-		{
-			if (countdown == 0)
-				document.forms.perm_submit.submit();
-			else if (countdown == -1)
-				return;
-
-			document.getElementById(\'cont\').value = "', $txt['not_done_continue'], ' (" + countdown + ")";
-			countdown--;
-
-			setTimeout("doAutoSubmit();", 1000);
-		}
-	// ]]></script>';
-
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_main()
+{
+	global $context, $settings, $options;
+}
+
+function template_view_package()
+{
+	global $context, $settings, $options, $txt, $scripturl, $smcFunc;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt[($context['uninstalling'] ? 'un' : '') . 'install_mod'], '</h3>
+		</div>
+		<div class="information">';
+
+	if ($context['is_installed'])
+		echo '
+			<strong>', $txt['package_installed_warning1'], '</strong><br />
+			<br />
+			', $txt['package_installed_warning2'], '<br />
+			<br />';
+
+	echo $txt['package_installed_warning3'], '
+		</div>';
+
+	// Do errors exist in the install? If so light them up like a christmas tree.
+	if ($context['has_failure'])
+	{
+		echo '
+		<div class="errorbox">
+			', $txt['package_will_fail_title'], '<br />
+			', $txt['package_will_fail_warning'], 
+			!empty($context['failure_details']) ? '<br /><br /><strong>' . $context['failure_details'] . '</strong>' : '', '
+		</div>';
+	}
+
+	// Display the package readme if one exists
+	if (isset($context['package_readme']))
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['package_' . ($context['uninstalling'] ? 'un' : '') . 'install_readme'], '</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					', $context['package_readme'], '
+					<span class="floatright">', $txt['package_available_readme_language'], '
+						<select name="readme_language" id="readme_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', ';package=', $context['filename'], ';readme=\' + this.options[this.selectedIndex].value + \';license=\' + get_selected(\'license_language\'));">';
+							foreach ($context['readmes'] as $a => $b)
+								echo '<option value="', $b, '"', $a === 'selected' ? ' selected="selected"' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
+			echo '
+						</select>
+					</span>
+				</div>
+			</div>
+			<br />';
+	}
+	
+	// Did they specify a license to display?
+	if (isset($context['package_license']))
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['package_install_license'], '</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					', $context['package_license'], '
+					<span class="floatright">', $txt['package_available_license_language'], '
+						<select name="license_language" id="license_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=install', ';package=', $context['filename'], ';license=\' + this.options[this.selectedIndex].value + \';readme=\' + get_selected(\'readme_language\'));">';
+							foreach ($context['licenses'] as $a => $b)
+								echo '<option value="', $b, '"', $a === 'selected' ? ' selected="selected"' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
+			echo '
+						</select>
+					</span>
+				</div>
+			</div>
+			<br />';
+	}
+	
+	echo '
+		<form action="', $scripturl, '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', $context['ftp_needed'] ? '' : '2', ';package=', $context['filename'], ';pid=', $context['install_id'], '" onsubmit="submitonce(this);" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['package_install_actions'], ' &quot;', $context['package_name'], '&quot;
+				</h3>
+			</div>';
+
+	// Are there data changes to be removed?
+	if ($context['uninstalling'] && !empty($context['database_changes']))
+	{
+		echo '
+			<div class="windowbg2">
+				<div class="content">
+					<label for="do_db_changes"><input type="checkbox" name="do_db_changes" id="do_db_changes" class="input_check" />', $txt['package_db_uninstall'], '</label> [<a href="#" onclick="return swap_database_changes();">', $txt['package_db_uninstall_details'], '</a>]
+					<div id="db_changes_div">
+						', $txt['package_db_uninstall_actions'], ':
+						<ul>';
+
+		foreach ($context['database_changes'] as $change)
+			echo '
+							<li>', $change, '</li>';
+		echo '
+						</ul>
+					</div>
+				</div>
+			</div>';
+	}
+
+	echo '
+			<div class="information">';
+
+	if (empty($context['actions']) && empty($context['database_changes']))
+		echo '
+				<br />
+				<div class="errorbox">
+					', $txt['corrupt_compatible'], '
+				</div>
+			</div>';
+	else
+	{
+		echo '
+					', $txt['perform_actions'], '
+			</div>
+			<table class="table_grid" width="100%">
+			<thead>
+				<tr class="catbg">
+					<th class="first_th" scope="col" width="20"></th>
+					<th scope="col" width="30"></th>
+					<th scope="col" class="lefttext">', $txt['package_install_type'], '</th>
+					<th scope="col" class="lefttext" width="50%">', $txt['package_install_action'], '</th>
+					<th class="last_th lefttext" scope="col" class="lefttext" width="20%">', $txt['package_install_desc'], '</th>
+				</tr>
+			</thead>
+			<tbody>';
+
+		$alternate = true;
+		$i = 1;
+		$action_num = 1;
+		$js_operations = array();
+		foreach ($context['actions'] as $packageaction)
+		{
+			// Did we pass or fail?  Need to now for later on.
+			$js_operations[$action_num] = isset($packageaction['failed']) ? $packageaction['failed'] : 0;
+
+			echo '
+				<tr class="windowbg', $alternate ? '' : '2', '">
+					<td>', isset($packageaction['operations']) ? '<img id="operation_img_' . $action_num . '" src="' . $settings['images_url'] . '/selected_open.png" alt="*" style="display: none;" />' : '', '</td>
+					<td>', $i++, '.</td>
+					<td>', $packageaction['type'], '</td>
+					<td>', $packageaction['action'], '</td>
+					<td>', $packageaction['description'], '</td>
+				</tr>';
+
+			// Is there water on the knee? Operation!
+			if (isset($packageaction['operations']))
+			{
+				echo '
+				<tr id="operation_', $action_num, '">
+					<td colspan="5" class="windowbg3">
+						<table border="0" cellpadding="3" cellspacing="0" width="100%">';
+
+				// Show the operations.
+				$alternate2 = true;
+				$operation_num = 1;
+				foreach ($packageaction['operations'] as $operation)
+				{
+					// Determine the position text.
+					$operation_text = $operation['position'] == 'replace' ? 'operation_replace' : ($operation['position'] == 'before' ? 'operation_after' : 'operation_before');
+
+					echo '
+							<tr class="windowbg', $alternate2 ? '' : '2', '">
+								<td width="0"></td>
+								<td width="30" class="smalltext"><a href="' . $scripturl . '?action=admin;area=packages;sa=showoperations;operation_key=', $operation['operation_key'], ';package=', $_REQUEST['package'], ';filename=', $operation['filename'], ($operation['is_boardmod'] ? ';boardmod' : ''), (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'uninstall' ? ';reverse' : ''), '" onclick="return reqWin(this.href, 680, 400, false);"><img src="', $settings['default_images_url'], '/admin/package_ops.png" alt="" /></a></td>
+								<td width="30" class="smalltext">', $operation_num, '.</td>
+								<td width="23%" class="smalltext">', $txt[$operation_text], '</td>
+								<td width="50%" class="smalltext">', $operation['action'], '</td>
+								<td width="20%" class="smalltext">', $operation['description'], !empty($operation['ignore_failure']) ? ' (' . $txt['operation_ignore'] . ')' : '', '</td>
+							</tr>';
+
+					$operation_num++;
+					$alternate2 = !$alternate2;
+				}
+
+				echo '
+						</table>
+					</td>
+				</tr>';
+
+				// Increase it.
+				$action_num++;
+			}
+			$alternate = !$alternate;
+		}
+					echo '
+			</tbody>
+			</table>
+			';
+
+		// What if we have custom themes we can install into? List them too!
+		if (!empty($context['theme_actions']))
+		{
+			echo '
+			<br />
+			<div class="cat_bar">
+				<h3 class="catbg">
+					', $context['uninstalling'] ? $txt['package_other_themes_uninstall'] : $txt['package_other_themes'], '
+				</h3>
+			</div>
+			<div id="custom_changes">
+				<div class="information">
+					', $txt['package_other_themes_desc'], '
+				</div>
+				<table class="table_grid" width="100%">';
+
+			// Loop through each theme and display it's name, and then it's details.
+			foreach ($context['theme_actions'] as $id => $theme)
+			{
+				// Pass?
+				$js_operations[$action_num] = !empty($theme['has_failure']);
+
+				echo '
+					<tr class="catbg">
+						<td></td>
+						<td align="center">';
+				if (!empty($context['themes_locked']))
+					echo '
+							<input type="hidden" name="custom_theme[]" value="', $id, '" />';
+				echo '
+							<input type="checkbox" name="custom_theme[]" id="custom_theme_', $id, '" value="', $id, '" class="input_check" onclick="', (!empty($theme['has_failure']) ? 'if (this.form.custom_theme_' . $id . '.checked && !confirm(\'' . $txt['package_theme_failure_warning'] . '\')) return false;' : ''), 'invertAll(this, this.form, \'dummy_theme_', $id, '\', true);" ', !empty($context['themes_locked']) ? 'disabled="disabled" checked="checked"' : '', '/>
+						</td>
+						<td colspan="3">
+							', $theme['name'], '
+						</td>
+					</tr>';
+
+				foreach ($theme['actions'] as $action)
+				{
+					echo '
+					<tr class="windowbg', $alternate ? '' : '2', '">
+						<td>', isset($packageaction['operations']) ? '<img id="operation_img_' . $action_num . '" src="' . $settings['images_url'] . '/selected_open.png" alt="*" style="display: none;" />' : '', '</td>
+						<td width="30" align="center">
+							<input type="checkbox" name="theme_changes[]" value="', !empty($action['value']) ? $action['value'] : '', '" id="dummy_theme_', $id, '" class="input_check" ', (!empty($action['not_mod']) ? '' : 'disabled="disabled"'), ' ', !empty($context['themes_locked']) ? 'checked="checked"' : '', '/>
+						</td>
+						<td>', $action['type'], '</td>
+						<td width="50%">', $action['action'], '</td>
+						<td width="20%"><strong>', $action['description'], '</strong></td>
+					</tr>';
+
+					// Is there water on the knee? Operation!
+					if (isset($action['operations']))
+					{
+						echo '
+					<tr id="operation_', $action_num, '">
+						<td colspan="5" class="windowbg3">
+							<table border="0" cellpadding="3" cellspacing="0" width="100%">';
+
+						$alternate2 = true;
+						$operation_num = 1;
+						foreach ($action['operations'] as $operation)
+						{
+							// Determine the possition text.
+							$operation_text = $operation['position'] == 'replace' ? 'operation_replace' : ($operation['position'] == 'before' ? 'operation_after' : 'operation_before');
+
+							echo '
+								<tr class="windowbg', $alternate2 ? '' : '2', '">
+									<td width="0"></td>
+									<td width="30" class="smalltext"><a href="' . $scripturl . '?action=admin;area=packages;sa=showoperations;operation_key=', $operation['operation_key'], ';package=', $_REQUEST['package'], ';filename=', $operation['filename'], ($operation['is_boardmod'] ? ';boardmod' : ''), (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'uninstall' ? ';reverse' : ''), '" onclick="return reqWin(this.href, 600, 400, false);"><img src="', $settings['default_images_url'], '/admin/package_ops.png" alt="" /></a></td>
+									<td width="30" class="smalltext">', $operation_num, '.</td>
+									<td width="23%" class="smalltext">', $txt[$operation_text], '</td>
+									<td width="50%" class="smalltext">', $operation['action'], '</td>
+									<td width="20%" class="smalltext">', $operation['description'], !empty($operation['ignore_failure']) ? ' (' . $txt['operation_ignore'] . ')' : '', '</td>
+								</tr>';
+							$operation_num++;
+							$alternate2 = !$alternate2;
+						}
+
+						echo '
+							</table>
+						</td>
+					</tr>';
+
+						// Increase it.
+						$action_num++;
+					}
+				}
+
+				$alternate = !$alternate;
+			}
+
+			echo '
+				</table>
+			</div>';
+		}
+	}
+
+	// Are we effectively ready to install?
+	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes'])))
+	{
+		echo '
+			<div class="righttext padding">
+				<input type="submit" value="', $context['uninstalling'] ? $txt['package_uninstall_now'] : $txt['package_install_now'], '" onclick="return ', !empty($context['has_failure']) ? '(submitThisOnce(this) &amp;&amp; confirm(\'' . ($context['uninstalling'] ? $txt['package_will_fail_popup_uninstall'] : $txt['package_will_fail_popup']) . '\'))' : 'submitThisOnce(this)', ';" class="button_submit" />
+			</div>';
+	}
+	// If we need ftp information then demand it!
+	elseif ($context['ftp_needed'])
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['package_ftp_necessary'], '</h3>
+			</div>
+			<div>
+				', template_control_chmod(), '
+			</div>';
+	}
+		echo '
+
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />', (isset($context['form_sequence_number']) && !$context['ftp_needed']) ? '
+			<input type="hidden" name="seqnum" value="' . $context['form_sequence_number'] . '" />' : '', '
+		</form>
+	</div>
+	<br class="clear" />';
+
+	// Toggle options.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var aOperationElements = new Array();';
+
+		// Operations.
+		if (!empty($js_operations))
+		{
+			foreach ($js_operations as $key => $operation)
+			{
+				echo '
+			aOperationElements[', $key, '] = new smc_Toggle({
+				bToggleEnabled: true,
+				bCurrentlyCollapsed: ', $operation ? 'false' : 'true', ',
+				aSwappableContainers: [
+					\'operation_', $key, '\'
+				],
+				aSwapImages: [
+					{
+						sId: \'operation_img_', $key, '\',
+						srcExpanded: smf_images_url + \'/selected_open.png\',
+						altExpanded: \'*\',
+						srcCollapsed: smf_images_url + \'/selected.png\',
+						altCollapsed: \'*\'
+					}
+				]
+			});';
+			}
+		}
+
+	echo '
+	// ]]></script>';
+	
+	// Get the currently selected item from a select list
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+	function get_selected(id)
+	{
+		var aSelected = document.getElementById(id);
+		for (var i = 0; i < aSelected.options.length; i++)
+		{
+			if (aSelected.options[i].selected == true)
+				return aSelected.options[i].value;
+		}
+		return aSelected.options[0];
+	}
+	// ]]></script>';
+
+	// And a bit more for database changes.
+	if (!empty($context['database_changes']))
+		echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var database_changes_area = document.getElementById(\'db_changes_div\');
+		var db_vis = false;
+		database_changes_area.style.display = "none";
+	// ]]></script>';
+}
+
+function template_extract_package()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	if (!empty($context['redirect_url']))
+	{
+		echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		setTimeout("doRedirect();", ', empty($context['redirect_timeout']) ? '5000' : $context['redirect_timeout'], ');
+
+		function doRedirect()
+		{
+			window.location = "', $context['redirect_url'], '";
+		}
+	// ]]></script>';
+	}
+
+	echo '
+	<div id="admincenter">';
+
+	if (empty($context['redirect_url']))
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting'], '</h3>
+			</div>
+			<div class="information">', $txt['package_installed_extract'], '</div>';
+	}
+	else
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['package_installed_redirecting'], '</h3>
+			</div>';
+
+	echo '
+		<div class="windowbg">
+			<div class="content">';
+
+	// If we are going to redirect we have a slightly different agenda.
+	if (!empty($context['redirect_url']))
+	{
+		echo '
+				', $context['redirect_text'], '<br /><br />
+				<a href="', $context['redirect_url'], '">', $txt['package_installed_redirect_go_now'], '</a> | <a href="', $scripturl, '?action=admin;area=packages;sa=browse">', $txt['package_installed_redirect_cancel'], '</a>';
+	}
+	elseif ($context['uninstalling'])
+		echo '
+				', $txt['package_uninstall_done'];
+	elseif ($context['install_finished'])
+	{
+		if ($context['extract_type'] == 'avatar')
+			echo '
+				', $txt['avatars_extracted'];
+		elseif ($context['extract_type'] == 'language')
+			echo '
+				', $txt['language_extracted'];
+		else
+			echo '
+				', $txt['package_installed_done'];
+	}
+	else
+		echo '
+				', $txt['corrupt_compatible'];
+
+	echo '
+			</div>
+		</div>';
+
+	// Show the "restore permissions" screen?
+	if (function_exists('template_show_list') && !empty($context['restore_file_permissions']['rows']))
+	{
+		echo '<br />';
+		template_show_list('restore_file_permissions');
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+function template_list()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['list_file'], '</h3>
+		</div>
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['files_archive'], ' ', $context['filename'], ':</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<ol>';
+
+	foreach ($context['files'] as $fileinfo)
+		echo '
+					<li><a href="', $scripturl, '?action=admin;area=packages;sa=examine;package=', $context['filename'], ';file=', $fileinfo['filename'], '" title="', $txt['view'], '">', $fileinfo['filename'], '</a> (', $fileinfo['size'], ' ', $txt['package_bytes'], ')</li>';
+
+	echo '
+				</ol>
+				<br />
+				<a href="', $scripturl, '?action=admin;area=packages">[ ', $txt['back'], ' ]</a>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_examine()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['package_examine_file'], '</h3>
+		</div>
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['package_file_contents'], ' ', $context['filename'], ':</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<pre class="file_content">', $context['filedata'], '</pre>
+				<a href="', $scripturl, '?action=admin;area=packages;sa=list;package=', $context['package'], '">[ ', $txt['list_files'], ' ]</a>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_browse()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings, $forum_version;
+
+	echo '
+	<div id="admincenter">';
+
+	if ($context['sub_action'] == 'browse')
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=helpadmin;help=latest_packages" onclick="return reqWin(this.href);" class="help"><img class="icon" src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /></a> ', $txt['packages_latest'], '
+			</h3>
+		</div>
+		<div class="windowbg2">
+			<div class="content">
+				<div id="packagesLatest">', $txt['packages_latest_fetch'], '</div>
+			</div>
+		</div>
+
+		<script type="text/javascript"><!-- // --><![CDATA[
+			window.smfForum_scripturl = "', $scripturl, '";
+			window.smfForum_sessionid = "', $context['session_id'], '";
+			window.smfForum_sessionvar = "', $context['session_var'], '";';
+
+		// Make a list of already installed mods so nothing is listed twice ;).
+		echo '
+			window.smfInstalledPackages = ["', implode('", "', $context['installed_mods']), '"];
+			window.smfVersion = "', $context['forum_version'], '";
+		// ]]></script>';
+
+		if (empty($modSettings['disable_smf_js']))
+			echo '
+		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-packages.js"></script>';
+
+		echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var tempOldOnload;
+			smfSetLatestPackages();
+		// ]]></script>';
+
+		echo '
+		<br class="clear" />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['browse_packages'], '</h3>
+		</div>';
+	}
+
+	$mods_available = false;
+	foreach ($context['modification_types'] as $type)
+	{
+		if (!empty($context['available_' . $type]))
+		{
+			template_show_list('packages_lists_' . $type);
+			$mods_available = true;
+		}
+	}
+
+	if (!$mods_available)
+		echo '
+		<div class="information">', $context['sub_action'] == 'browse' ? $txt['no_packages'] : $txt['no_mods_installed'], '</div>';
+
+	// the advanced (emulation) box, collapsed by default
+	echo '
+		<br class="clear" />
+		<form action="', $scripturl, '?action=admin;area=packages;sa=', $context['sub_action'], '" method="get">
+			<div id="advanced_box" >
+				<div class="cat_bar">
+					<h3 class="catbg">
+						<img id="advanced_panel_toggle" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png" alt="*" />
+						<a href="#" id="advanced_panel_link">', $txt['package_advanced_button'], '</a>
+					</h3>
+				</div>
+				<div id="advanced_panel_div" class="windowbg">
+					<div class="content">
+						<p>
+							', $txt['package_emulate_desc'], '
+						</p>
+						<dl class="settings">
+							<dt>
+								<strong>', $txt['package_emulate'], ':</strong><br />
+								<span class="smalltext">
+									<a href="#" onclick="document.getElementById(\'ve\').value = \'', $forum_version, '\';document.getElementsByName(\'version_emulate\')[0].value = \'', $forum_version, '\';return false">', $txt['package_emulate_revert'], '</a>
+								</span>
+							</dt>
+							<dd>
+								<input type="text" name="version_emulate" id="ve" value="', $context['forum_version'], '" size="25" class="input_text" />
+							</dd>
+						</dl>
+						<div class="righttext padding">
+							<input type="submit" value="', $txt['package_apply'], '" class="button_submit" />
+						</div>
+					</div>
+				</div>
+			</div>
+			<input type="hidden" name="action" value="admin" />
+			<input type="hidden" name="area" value="packages" />
+			<input type="hidden" name="sa" value="', $context['sub_action'], '" />
+		</form>';
+	
+	echo '
+	</div>
+	<br class="clear" />
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oAdvancedPanelToggle = new smc_Toggle({
+			bToggleEnabled: true,
+			bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
+			aSwappableContainers: [
+				\'advanced_panel_div\'
+			],
+			aSwapImages: [
+				{
+					sId: \'advanced_panel_toggle\',
+					srcExpanded: smf_images_url + \'/collapse.png\',
+					altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
+					srcCollapsed: smf_images_url + \'/expand.png\',
+					altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
+				}
+			],
+			aSwapLinks: [
+				{
+					sId: \'advanced_panel_link\',
+					msgExpanded: ', JavaScriptEscape($txt['package_advanced_button']), ',
+					msgCollapsed: ', JavaScriptEscape($txt['package_advanced_button']), '
+				}
+			],
+			oThemeOptions: {
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
+				sOptionName: \'admin_preferences\',
+				sSessionVar: smf_session_var,
+				sSessionId: smf_session_id,
+				sThemeId: \'1\'
+			}
+		});
+	// ]]></script>
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+			var oAddVersionSuggest = new smc_AutoSuggest({
+			sSelf: \'oAddVersionSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sControlId: \'ve\',
+			sSearchType: \'versions\',
+			bItemList: false
+		});
+	// ]]></script>';
+}
+
+function template_servers()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	if (!empty($context['package_ftp']['error']))
+			echo '
+					<div class="errorbox">
+						<tt>', $context['package_ftp']['error'], '</tt>
+					</div>';
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['download_new_package'], '</h3>
+		</div>';
+
+	if ($context['package_download_broken'])
+	{
+		echo '
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['package_ftp_necessary'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>
+					', $txt['package_ftp_why_download'], '
+				</p>
+				<form action="', $scripturl, '?action=admin;area=packages;get" method="post" accept-charset="', $context['character_set'], '">
+					<dl class="settings">
+						<dt>
+							<label for="ftp_server">', $txt['package_ftp_server'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="30" name="ftp_server" id="ftp_server" value="', $context['package_ftp']['server'], '" class="input_text" />
+							<label for="ftp_port">', $txt['package_ftp_port'], ':&nbsp;</label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', $context['package_ftp']['port'], '" class="input_text" />
+						</dd>
+						<dt>
+							<label for="ftp_username">', $txt['package_ftp_username'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="50" name="ftp_username" id="ftp_username" value="', $context['package_ftp']['username'], '" style="width: 99%;" class="input_text" />
+						</dd>
+						<dt>
+							<label for="ftp_password">', $txt['package_ftp_password'], ':</label>
+						</dt>
+						<dd>
+							<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
+						</dd>
+						<dt>
+							<label for="ftp_path">', $txt['package_ftp_path'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $context['package_ftp']['path'], '" style="width: 99%;" class="input_text" />
+						</dd>
+					</dl>
+					<div class="righttext">
+						<input type="submit" value="', $txt['package_proceed'], '" class="button_submit" />
+					</div>
+				</form>
+			</div>
+		</div>';
+	}
+
+	echo '
+		<div class="windowbg2">
+			<div class="content">
+				<fieldset>
+					<legend>' . $txt['package_servers'] . '</legend>
+					<ul class="package_servers">';
+	foreach ($context['servers'] as $server)
+		echo '
+						<li class="flow_auto">
+							<span class="floatleft">' . $server['name'] . '</span>
+							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=remove;server=' . $server['id'] . ';', $context['session_var'], '=', $context['session_id'], '">[ ' . $txt['delete'] . ' ]</a></span>
+							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $server['id'] . '">[ ' . $txt['package_browse'] . ' ]</a></span>
+						</li>';
+	echo '
+					</ul>
+				</fieldset>
+				<fieldset>
+					<legend>' . $txt['add_server'] . '</legend>
+					<form action="' . $scripturl . '?action=admin;area=packages;get;sa=add" method="post" accept-charset="', $context['character_set'], '">
+						<dl class="settings">
+							<dt>
+								<strong>' . $txt['server_name'] . ':</strong>
+							</dt>
+							<dd>
+								<input type="text" name="servername" size="44" value="SMF" class="input_text" />
+							</dd>
+							<dt>
+								<strong>' . $txt['serverurl'] . ':</strong>
+							</dt>
+							<dd>
+								<input type="text" name="serverurl" size="44" value="http://" class="input_text" />
+							</dd>
+						</dl>
+						<div class="righttext">
+							<input type="submit" value="' . $txt['add_server'] . '" class="button_submit" />
+							<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
+						</div>
+					</form>
+				</fieldset>
+				<fieldset>
+					<legend>', $txt['package_download_by_url'], '</legend>
+					<form action="', $scripturl, '?action=admin;area=packages;get;sa=download;byurl;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+						<dl class="settings">
+							<dt>
+								<strong>' . $txt['serverurl'] . ':</strong>
+							</dt>
+							<dd>
+								<input type="text" name="package" size="44" value="http://" class="input_text" />
+							</dd>
+							<dt>
+								<strong>', $txt['package_download_filename'], ':</strong>
+							</dt>
+							<dd>
+								<input type="text" name="filename" size="44" class="input_text" /><br />
+								<span class="smalltext">', $txt['package_download_filename_info'], '</span>
+							</dd>
+						</dl>
+						<div class="righttext">
+							<input type="submit" value="', $txt['download'], '" class="button_submit" />
+						</div>
+					</form>
+				</fieldset>
+			</div>
+		</div>
+		<br />
+		<div class="cat_bar">
+			<h3 class="catbg">' . $txt['package_upload_title'] . '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<form action="' . $scripturl . '?action=admin;area=packages;get;sa=upload" method="post" accept-charset="', $context['character_set'], '" enctype="multipart/form-data" style="margin-bottom: 0;">
+					<dl class="settings">
+						<dt>
+							<strong>' . $txt['package_upload_select'] . ':</strong>
+						</dt>
+						<dd>
+							<input type="file" name="package" size="38" class="input_file" />
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" value="' . $txt['package_upload'] . '" class="button_submit" />
+					<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
+					<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_package_confirm()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $context['page_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $context['confirm_message'], '</p>
+				<a href="', $context['proceed_href'], '">[ ', $txt['package_confirm_proceed'], ' ]</a> <a href="JavaScript:history.go(-1);">[ ', $txt['package_confirm_go_back'], ' ]</a>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_package_list()
+{
+	global $context, $settings, $options, $txt, $scripturl, $smcFunc;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">' . $context['page_title'] . '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">';
+
+	// No packages, as yet.
+	if (empty($context['package_list']))
+		echo '
+				<ul>
+					<li>', $txt['no_packages'], '</li>
+				</ul>';
+	// List out the packages...
+	else
+	{
+		echo '
+				<ul id="package_list">';
+		foreach ($context['package_list'] as $i => $packageSection)
+		{
+			echo '
+					<li>
+						<strong><img id="ps_img_', $i, '" src="', $settings['images_url'], '/upshrink.png" alt="*" style="display: none;" /> ', $packageSection['title'], '</strong>';
+
+			if (!empty($packageSection['text']))
+				echo '
+						<div class="information">', $packageSection['text'], '</div>';
+
+			echo '
+						<', $context['list_type'], ' id="package_section_', $i, '" class="packages">';
+
+			$alt = false;
+
+			foreach ($packageSection['items'] as $id => $package)
+			{
+				echo '
+							<li>';
+				// Textual message. Could be empty just for a blank line...
+				if ($package['is_text'])
+					echo '
+								', empty($package['name']) ? '&nbsp;' : $package['name'];
+				// This is supposed to be a rule..
+				elseif ($package['is_line'])
+					echo '
+							<hr class="hrcolor" />';
+				// A remote link.
+				elseif ($package['is_remote'])
+				{
+					echo '
+							<strong>', $package['link'], '</strong>';
+				}
+				// A title?
+				elseif ($package['is_heading'] || $package['is_title'])
+				{
+					echo '
+							<strong>', $package['name'], '</strong>';
+				}
+				// Otherwise, it's a package.
+				else
+				{
+					// 1. Some mod [ Download ].
+					echo '
+							<strong><img id="ps_img_', $i, '_pkg_', $id, '" src="', $settings['images_url'], '/upshrink.png" alt="*" style="display: none;" /> ', $package['can_install'] ? '<strong>' . $package['name'] . '</strong> <a href="' . $package['download']['href'] . '">[ ' . $txt['download'] . ' ]</a>': $package['name'];
+
+					// Mark as installed and current?
+					if ($package['is_installed'] && !$package['is_newer'])
+						echo '<img src="', $settings['images_url'], '/icons/package_', $package['is_current'] ? 'installed' : 'old', '.png" width="12" height="11" class="centericon" style="margin-left: 2ex;" alt="', $package['is_current'] ? $txt['package_installed_current'] : $txt['package_installed_old'], '" />';
+
+					echo '
+							</strong>
+							<ul id="package_section_', $i, '_pkg_', $id, '" class="package_section">';
+
+					// Show the mod type?
+					if ($package['type'] != '')
+						echo '
+								<li class="package_section">', $txt['package_type'], ':&nbsp; ', $smcFunc['ucwords']($smcFunc['strtolower']($package['type'])), '</li>';
+					// Show the version number?
+					if ($package['version'] != '')
+						echo '
+								<li class="package_section">', $txt['mod_version'], ':&nbsp; ', $package['version'], '</li>';
+					// How 'bout the author?
+					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link']))
+						echo '
+								<li class="package_section">', $txt['mod_author'], ':&nbsp; ', $package['author']['link'], '</li>';
+					// The homepage....
+					if ($package['author']['website']['link'] != '')
+						echo '
+								<li class="package_section">', $txt['author_website'], ':&nbsp; ', $package['author']['website']['link'], '</li>';
+
+					// Desciption: bleh bleh!
+					// Location of file: http://someplace/.
+					echo '
+								<li class="package_section">', $txt['file_location'], ':&nbsp; <a href="', $package['href'], '">', $package['href'], '</a></li>
+								<li class="package_section"><div class="information">', $txt['package_description'], ':&nbsp; ', $package['description'], '</div></li>
+							</ul>';
+				}
+				$alt = !$alt;
+				echo '
+						</li>';
+			}
+			echo '
+					</', $context['list_type'], '>
+						</li>';
+		}
+		echo '
+				</ul>';
+
+	}
+
+	echo '
+			</div>
+		</div>
+		<div class="padding smalltext floatleft">
+			', $txt['package_installed_key'], '
+			<img src="', $settings['images_url'], '/icons/package_installed.png" alt="" class="centericon" style="margin-left: 1ex;" /> ', $txt['package_installed_current'], '
+			<img src="', $settings['images_url'], '/icons/package_old.png" alt="" class="centericon" style="margin-left: 2ex;" /> ', $txt['package_installed_old'], '
+		</div>
+	</div>
+	<br class="clear" />
+
+		';
+		// Now go through and turn off all the sections.
+		if (!empty($context['package_list']))
+		{
+			$section_count = count($context['package_list']);
+			echo '
+			<script type="text/javascript"><!-- // --><![CDATA[';
+			foreach ($context['package_list'] as $section => $ps)
+			{
+				echo '
+				var oPackageServerToggle_', $section, ' = new smc_Toggle({
+					bToggleEnabled: true,
+					bCurrentlyCollapsed: ', count($ps['items']) == 1 || $section_count == 1 ? 'false' : 'true', ',
+					aSwappableContainers: [
+						\'package_section_', $section, '\'
+					],
+					aSwapImages: [
+						{
+							sId: \'ps_img_', $section, '\',
+							srcExpanded: smf_images_url + \'/upshrink.png\',
+							altExpanded: \'*\',
+							srcCollapsed: smf_images_url + \'/upshrink2.png\',
+							altCollapsed: \'*\'
+						}
+					]
+				});';
+
+				foreach ($ps['items'] as $id => $package)
+				{
+					if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote'])
+						echo '
+				var oPackageToggle_', $section, '_pkg_', $id, ' = new smc_Toggle({
+					bToggleEnabled: true,
+					bCurrentlyCollapsed: true,
+					aSwappableContainers: [
+						\'package_section_', $section, '_pkg_', $id, '\'
+					],
+					aSwapImages: [
+						{
+							sId: \'ps_img_', $section, '_pkg_', $id, '\',
+							srcExpanded: smf_images_url + \'/upshrink.png\',
+							altExpanded: \'*\',
+							srcCollapsed: smf_images_url + \'/upshrink2.png\',
+							altCollapsed: \'*\'
+						}
+					]
+				});';
+				}
+			}
+			echo '
+			// ]]></script>';
+		}
+}
+
+function template_downloaded()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $context['page_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', (empty($context['package_server']) ? $txt['package_uploaded_successfully'] : $txt['package_downloaded_successfully']), '</p>
+				<ul class="reset">
+					<li class="reset"><span class="floatleft"><strong>', $context['package']['name'], '</strong></span>
+						<span class="package_server floatright">', $context['package']['list_files']['link'], '</span>
+						<span class="package_server floatright">', $context['package']['install']['link'], '</span>
+					</li>
+				</ul>
+				<br /><br />
+				<p><a href="', $scripturl, '?action=admin;area=packages;get', (isset($context['package_server']) ? ';sa=browse;server=' . $context['package_server'] : ''), '">[ ', $txt['back'], ' ]</a></p>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_install_options()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['package_install_options'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['package_install_options_ftp_why'], '
+		</div>
+
+		<div class="windowbg">
+			<div class="content">
+				<form action="', $scripturl, '?action=admin;area=packages;sa=options" method="post" accept-charset="', $context['character_set'], '">
+					<dl class="settings">
+						<dt>
+							<label for="pack_server"><strong>', $txt['package_install_options_ftp_server'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="pack_server" id="pack_server" value="', $context['package_ftp_server'], '" size="30" class="input_text" />
+						</dd>
+						<dt>
+							<label for="pack_port"><strong>', $txt['package_install_options_ftp_port'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="pack_port" id="pack_port" size="3" value="', $context['package_ftp_port'], '" class="input_text" />
+						</dd>
+						<dt>
+							<label for="pack_user"><strong>', $txt['package_install_options_ftp_user'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" name="pack_user" id="pack_user" value="', $context['package_ftp_username'], '" size="30" class="input_text" />
+						</dd>
+						<dt>
+							<label for="package_make_backups">', $txt['package_install_options_make_backups'], '</label>
+						</dt>
+						<dd>
+							<input type="checkbox" name="package_make_backups" id="package_make_backups" value="1" class="input_check"', $context['package_make_backups'] ? ' checked="checked"' : '', ' />
+						</dd>
+						<dt>
+							<label for="package_make_full_backups">', $txt['package_install_options_make_full_backups'], '</label>
+						</dt>
+						<dd>
+							<input type="checkbox" name="package_make_full_backups" id="package_make_full_backups" value="1" class="input_check"', $context['package_make_full_backups'] ? ' checked="checked"' : '', ' />
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_control_chmod()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Nothing to do? Brilliant!
+	if (empty($context['package_ftp']))
+		return false;
+
+	if (empty($context['package_ftp']['form_elements_only']))
+	{
+		echo '
+				', sprintf($txt['package_ftp_why'], 'document.getElementById(\'need_writable_list\').style.display = \'\'; return false;'), '<br />
+				<div id="need_writable_list" class="smalltext">
+					', $txt['package_ftp_why_file_list'], '
+					<ul style="display: inline;">';
+		if (!empty($context['notwritable_files']))
+			foreach ($context['notwritable_files'] as $file)
+				echo '
+						<li>', $file, '</li>';
+
+		echo '
+					</ul>
+				</div>';
+	}
+
+	echo '
+				<div class="bordercolor" id="ftp_error_div" style="', (!empty($context['package_ftp']['error']) ? '' : 'display:none;'), 'padding: 1px; margin: 1ex;"><div class="windowbg2" id="ftp_error_innerdiv" style="padding: 1ex;">
+					<tt id="ftp_error_message">', !empty($context['package_ftp']['error']) ? $context['package_ftp']['error'] : '', '</tt>
+				</div></div>';
+
+	if (!empty($context['package_ftp']['destination']))
+		echo '
+				<form action="', $context['package_ftp']['destination'], '" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;">';
+
+	echo '
+					<fieldset>
+					<dl class="settings">
+						<dt>
+							<label for="ftp_server">', $txt['package_ftp_server'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="30" name="ftp_server" id="ftp_server" value="', $context['package_ftp']['server'], '" class="input_text" />
+							<label for="ftp_port">', $txt['package_ftp_port'], ':&nbsp;</label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', $context['package_ftp']['port'], '" class="input_text" />
+						</dd>
+						<dt>
+							<label for="ftp_username">', $txt['package_ftp_username'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="50" name="ftp_username" id="ftp_username" value="', $context['package_ftp']['username'], '" style="width: 98%;" class="input_text" />
+						</dd>
+						<dt>
+							<label for="ftp_password">', $txt['package_ftp_password'], ':</label>
+						</dt>
+						<dd>
+							<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 98%;" class="input_password" />
+						</dd>
+						<dt>
+							<label for="ftp_path">', $txt['package_ftp_path'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $context['package_ftp']['path'], '" style="width: 98%;" class="input_text" />
+						</dd>
+					</dl>
+					</fieldset>';
+
+	if (empty($context['package_ftp']['form_elements_only']))
+		echo '
+
+					<div class="righttext" style="margin: 1ex;">
+						<span id="test_ftp_placeholder_full"></span>
+						<input type="submit" value="', $txt['package_proceed'], '" class="button_submit" />
+					</div>';
+
+	if (!empty($context['package_ftp']['destination']))
+		echo '
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				</form>';
+
+	// Hide the details of the list.
+	if (empty($context['package_ftp']['form_elements_only']))
+		echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			document.getElementById(\'need_writable_list\').style.display = \'none\';
+		// ]]></script>';
+
+	// Quick generate the test button.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		// Generate a "test ftp" button.
+		var generatedButton = false;
+		function generateFTPTest()
+		{
+			// Don\'t ever call this twice!
+			if (generatedButton)
+				return false;
+			generatedButton = true;
+
+			// No XML?
+			if (!window.XMLHttpRequest || (!document.getElementById("test_ftp_placeholder") && !document.getElementById("test_ftp_placeholder_full")))
+				return false;
+
+			var ftpTest = document.createElement("input");
+			ftpTest.type = "button";
+			ftpTest.onclick = testFTP;
+
+			if (document.getElementById("test_ftp_placeholder"))
+			{
+				ftpTest.value = "', $txt['package_ftp_test'], '";
+				document.getElementById("test_ftp_placeholder").appendChild(ftpTest);
+			}
+			else
+			{
+				ftpTest.value = "', $txt['package_ftp_test_connection'], '";
+				document.getElementById("test_ftp_placeholder_full").appendChild(ftpTest);
+			}
+		}
+		function testFTPResults(oXMLDoc)
+		{
+			ajax_indicator(false);
+
+			// This assumes it went wrong!
+			var wasSuccess = false;
+			var message = "', addcslashes($txt['package_ftp_test_failed'], "'"), '";
+
+			var results = oXMLDoc.getElementsByTagName(\'results\')[0].getElementsByTagName(\'result\');
+			if (results.length > 0)
+			{
+				if (results[0].getAttribute(\'success\') == 1)
+					wasSuccess = true;
+				message = results[0].firstChild.nodeValue;
+			}
+
+			document.getElementById("ftp_error_div").style.display = "";
+			document.getElementById("ftp_error_div").style.backgroundColor = wasSuccess ? "green" : "red";
+			document.getElementById("ftp_error_innerdiv").style.backgroundColor = wasSuccess ? "#DBFDC7" : "#FDBDBD";
+
+			setInnerHTML(document.getElementById("ftp_error_message"), message);
+		}
+		generateFTPTest();
+	// ]]></script>';
+
+	// Make sure the button gets generated last.
+	$context['insert_after_template'] .= '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		generateFTPTest();
+	// ]]></script>';
+}
+
+function template_ftp_required()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<fieldset>
+			<legend>
+				', $txt['package_ftp_necessary'], '
+			</legend>
+			<div class="ftp_details">
+				', template_control_chmod(), '
+			</div>
+		</fieldset>';
+}
+
+function template_view_operations()
+{
+	global $context, $txt, $settings;
+
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<title>', $txt['operation_title'], '</title>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
+		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/admin.css?alp21" />
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?alp21"></script>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/theme.js?alp21"></script>
+	</head>
+	<body>
+		<div class="padding windowbg">
+			<div class="padding">
+				', $context['operations']['search'], '
+			</div>
+			<div class="padding">
+				', $context['operations']['replace'], '
+			</div>
+		</div>
+	</body>
+</html>';
+}
+
+function template_file_permissions()
+{
+	global $txt, $scripturl, $context, $settings;
+
+	// This will handle expanding the selection.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oRadioColors = {
+			0: "#D1F7BF",
+			1: "#FFBBBB",
+			2: "#FDD7AF",
+			3: "#C2C6C0",
+			4: "#EEEEEE"
+		}
+		var oRadioValues = {
+			0: "read",
+			1: "writable",
+			2: "execute",
+			3: "custom",
+			4: "no_change"
+		}
+		function dynamicAddMore()
+		{
+			ajax_indicator(true);
+
+			getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=admin;area=packages;fileoffset=\' + (parseInt(this.offset) + ', $context['file_limit'], ') + \';onlyfind=\' + escape(this.path) + \';sa=perms;xml;', $context['session_var'], '=', $context['session_id'], '\', onNewFolderReceived);
+		}
+
+		// Getting something back?
+		function onNewFolderReceived(oXMLDoc)
+		{
+			ajax_indicator(false);
+
+			var fileItems = oXMLDoc.getElementsByTagName(\'folders\')[0].getElementsByTagName(\'folder\');
+
+			// No folders, no longer worth going further.
+			if (fileItems.length < 1)
+			{
+				if (oXMLDoc.getElementsByTagName(\'roots\')[0].getElementsByTagName(\'root\')[0])
+				{
+					var rootName = oXMLDoc.getElementsByTagName(\'roots\')[0].getElementsByTagName(\'root\')[0].firstChild.nodeValue;
+					var itemLink = document.getElementById(\'link_\' + rootName);
+
+					// Move the children up.
+					for (i = 0; i <= itemLink.childNodes.length; i++)
+						itemLink.parentNode.insertBefore(itemLink.childNodes[0], itemLink);
+
+					// And remove the link.
+					itemLink.parentNode.removeChild(itemLink);
+				}
+				return false;
+			}
+			var tableHandle = false;
+			var isMore = false;
+			var ident = "";
+			var my_ident = "";
+			var curLevel = 0;
+
+			for (var i = 0; i < fileItems.length; i++)
+			{
+				if (fileItems[i].getAttribute(\'more\') == 1)
+				{
+					isMore = true;
+					var curOffset = fileItems[i].getAttribute(\'offset\');
+				}
+
+				if (fileItems[i].getAttribute(\'more\') != 1 && document.getElementById("insert_div_loc_" + fileItems[i].getAttribute(\'ident\')))
+				{
+					ident = fileItems[i].getAttribute(\'ident\');
+					my_ident = fileItems[i].getAttribute(\'my_ident\');
+					curLevel = fileItems[i].getAttribute(\'level\') * 5;
+					curPath = fileItems[i].getAttribute(\'path\');
+
+					// Get where we\'re putting it next to.
+					tableHandle = document.getElementById("insert_div_loc_" + fileItems[i].getAttribute(\'ident\'));
+
+					var curRow = document.createElement("tr");
+					curRow.className = "windowbg";
+					curRow.id = "content_" + my_ident;
+					curRow.style.display = "";
+					var curCol = document.createElement("td");
+					curCol.className = "smalltext";
+					curCol.width = "40%";
+
+					// This is the name.
+					var fileName = document.createTextNode(fileItems[i].firstChild.nodeValue);
+
+					// Start by wacking in the spaces.
+					setInnerHTML(curCol, repeatString("&nbsp;", curLevel));
+
+					// Create the actual text.
+					if (fileItems[i].getAttribute(\'folder\') == 1)
+					{
+						var linkData = document.createElement("a");
+						linkData.name = "fol_" + my_ident;
+						linkData.id = "link_" + my_ident;
+						linkData.href = \'#\';
+						linkData.path = curPath + "/" + fileItems[i].firstChild.nodeValue;
+						linkData.ident = my_ident;
+						linkData.onclick = dynamicExpandFolder;
+
+						var folderImage = document.createElement("img");
+						folderImage.src = \'', addcslashes($settings['default_images_url'], "\\"), '/board.png\';
+						linkData.appendChild(folderImage);
+
+						linkData.appendChild(fileName);
+						curCol.appendChild(linkData);
+					}
+					else
+						curCol.appendChild(fileName);
+
+					curRow.appendChild(curCol);
+
+					// Right, the permissions.
+					curCol = document.createElement("td");
+					curCol.className = "smalltext";
+
+					var writeSpan = document.createElement("span");
+					writeSpan.style.color = fileItems[i].getAttribute(\'writable\') ? "green" : "red";
+					setInnerHTML(writeSpan, fileItems[i].getAttribute(\'writable\') ? \'', $txt['package_file_perms_writable'], '\' : \'', $txt['package_file_perms_not_writable'], '\');
+					curCol.appendChild(writeSpan);
+
+					if (fileItems[i].getAttribute(\'permissions\'))
+					{
+						var permData = document.createTextNode("\u00a0(', $txt['package_file_perms_chmod'], ': " + fileItems[i].getAttribute(\'permissions\') + ")");
+						curCol.appendChild(permData);
+					}
+
+					curRow.appendChild(curCol);
+
+					// Now add the five radio buttons.
+					for (j = 0; j < 5; j++)
+					{
+						curCol = document.createElement("td");
+						curCol.style.backgroundColor = oRadioColors[j];
+						curCol.align = "center";
+
+						var curInput = createNamedElement("input", "permStatus[" + curPath + "/" + fileItems[i].firstChild.nodeValue + "]", j == 4 ? \'checked="checked"\' : "");
+						curInput.type = "radio";
+						curInput.checked = "checked";
+						curInput.value = oRadioValues[j];
+
+						curCol.appendChild(curInput);
+						curRow.appendChild(curCol);
+					}
+
+					// Put the row in.
+					tableHandle.parentNode.insertBefore(curRow, tableHandle);
+
+					// Put in a new dummy section?
+					if (fileItems[i].getAttribute(\'folder\') == 1)
+					{
+						var newRow = document.createElement("tr");
+						newRow.id = "insert_div_loc_" + my_ident;
+						newRow.style.display = "none";
+						tableHandle.parentNode.insertBefore(newRow, tableHandle);
+						var newCol = document.createElement("td");
+						newCol.colspan = 2;
+						newRow.appendChild(newCol);
+					}
+				}
+			}
+
+			// Is there some more to remove?
+			if (document.getElementById("content_" + ident + "_more"))
+			{
+				document.getElementById("content_" + ident + "_more").parentNode.removeChild(document.getElementById("content_" + ident + "_more"));
+			}
+
+			// Add more?
+			if (isMore && tableHandle)
+			{
+				// Create the actual link.
+				var linkData = document.createElement("a");
+				linkData.href = \'#fol_\' + my_ident;
+				linkData.path = curPath;
+				linkData.offset = curOffset;
+				linkData.onclick = dynamicAddMore;
+
+				linkData.appendChild(document.createTextNode(\'', $txt['package_file_perms_more_files'], '\'));
+
+				curRow = document.createElement("tr");
+				curRow.className = "windowbg";
+				curRow.id = "content_" + ident + "_more";
+				tableHandle.parentNode.insertBefore(curRow, tableHandle);
+				curCol = document.createElement("td");
+				curCol.className = "smalltext";
+				curCol.width = "40%";
+
+				setInnerHTML(curCol, repeatString("&nbsp;", curLevel));
+				curCol.appendChild(document.createTextNode(\'\\u00ab \'));
+				curCol.appendChild(linkData);
+				curCol.appendChild(document.createTextNode(\' \\u00bb\'));
+
+				curRow.appendChild(curCol);
+				curCol = document.createElement("td");
+				curCol.className = "smalltext";
+				curRow.appendChild(curCol);
+			}
+
+			// Keep track of it.
+			var curInput = createNamedElement("input", "back_look[]");
+			curInput.type = "hidden";
+			curInput.value = curPath;
+
+			curCol.appendChild(curInput);
+		}
+	// ]]></script>';
+
+		echo '
+	<div class="information">
+		<div>
+			<strong>', $txt['package_file_perms_warning'], ':</strong>
+			<div class="smalltext">
+				<ol style="margin-top: 2px; margin-bottom: 2px">
+					', $txt['package_file_perms_warning_desc'], '
+				</ol>
+			</div>
+		</div>
+	</div>
+
+	<form action="', $scripturl, '?action=admin;area=packages;sa=perms;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">
+		<div class="title_bar">
+			<h3 class="titlebg">
+				<span class="floatleft">', $txt['package_file_perms'], '</span><span class="fperm floatright">', $txt['package_file_perms_new_status'], '</span>
+			</h3>
+		</div>
+		<table width="100%" class="table_grid">
+			<thead>
+				<tr class="catbg">
+					<th class="first_th lefttext" width="30%">&nbsp;', $txt['package_file_perms_name'], '&nbsp;</th>
+					<th width="30%" class="lefttext">', $txt['package_file_perms_status'], '</th>
+					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_read'], '</span></th>
+					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_write'], '</span></th>
+					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_execute'], '</span></th>
+					<th align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_custom'], '</span></th>
+					<th class="last_th" align="center" width="8%"><span class="filepermissions">', $txt['package_file_perms_status_no_change'], '</span></th>
+				</tr>
+			</thead>';
+
+	foreach ($context['file_tree'] as $name => $dir)
+	{
+		echo '
+			<tbody>
+				<tr class="windowbg2">
+					<td width="30%"><strong>';
+
+				if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
+					echo '
+						<img src="', $settings['default_images_url'], '/board.png" alt="*" />';
+
+				echo '
+						', $name, '
+					</strong></td>
+					<td width="30%">
+						<span style="color: ', ($dir['perms']['chmod'] ? 'green' : 'red'), '">', ($dir['perms']['chmod'] ? $txt['package_file_perms_writable'] : $txt['package_file_perms_not_writable']), '</span>
+						', ($dir['perms']['perms'] ? '&nbsp;(' . $txt['package_file_perms_chmod'] . ': ' . substr(sprintf('%o', $dir['perms']['perms']), -4) . ')' : ''), '
+					</td>
+					<td align="center" class="perm_read" width="8%"><input type="radio" name="permStatus[', $name, ']" value="read" class="input_radio" /></td>
+					<td align="center" class="perm_write" width="8%"><input type="radio" name="permStatus[', $name, ']" value="writable" class="input_radio" /></td>
+					<td align="center" class="perm_execute" width="8%"><input type="radio" name="permStatus[', $name, ']" value="execute" class="input_radio" /></td>
+					<td align="center" class="perm_custom" width="8%"><input type="radio" name="permStatus[', $name, ']" value="custom" class="input_radio" /></td>
+					<td align="center" class="perm_nochange" width="8%"><input type="radio" name="permStatus[', $name, ']" value="no_change" checked="checked" class="input_radio" /></td>
+				</tr>
+			</tbody>';
+
+		if (!empty($dir['contents']))
+			template_permission_show_contents($name, $dir['contents'], 1);
+	}
+
+	echo '
+
+		</table>
+		<br />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['package_file_perms_change'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<fieldset>
+					<dl>
+						<dt>
+							<input type="radio" name="method" value="individual" checked="checked" id="method_individual" class="input_radio" />
+							<label for="method_individual"><strong>', $txt['package_file_perms_apply'], '</strong></label>
+						</dt>
+						<dd>
+							<em class="smalltext">', $txt['package_file_perms_custom'], ': <input type="text" name="custom_value" value="0755" maxlength="4" size="5" class="input_text" />&nbsp;<a href="', $scripturl, '?action=helpadmin;help=chmod_flags" onclick="return reqWin(this.href);" class="help">(?)</a></em>
+						</dd>
+						<dt>
+							<input type="radio" name="method" value="predefined" id="method_predefined" class="input_radio" />
+							<label for="method_predefined"><strong>', $txt['package_file_perms_predefined'], ':</strong></label>
+							<select name="predefined" onchange="document.getElementById(\'method_predefined\').checked = \'checked\';">
+								<option value="restricted" selected="selected">', $txt['package_file_perms_pre_restricted'], '</option>
+								<option value="standard">', $txt['package_file_perms_pre_standard'], '</option>
+								<option value="free">', $txt['package_file_perms_pre_free'], '</option>
+							</select>
+						</dt>
+						<dd>
+							<em class="smalltext">', $txt['package_file_perms_predefined_note'], '</em>
+						</dd>
+					</dl>
+				</fieldset>';
+
+	// Likely to need FTP?
+	if (empty($context['ftp_connected']))
+		echo '
+				<p>
+					', $txt['package_file_perms_ftp_details'], ':
+				</p>
+				', template_control_chmod(), '
+				<div class="information">', $txt['package_file_perms_ftp_retain'], '</div>';
+
+	echo '
+				<span id="test_ftp_placeholder_full"></span>
+				<hr class="hrcolor" />
+				<input type="hidden" name="action_changes" value="1" />
+				<input type="submit" value="', $txt['package_file_perms_go'], '" name="go" class="button_submit" />
+				<br class="clear_right" />
+			</div>
+		</div>';
+
+	// Any looks fors we've already done?
+	foreach ($context['look_for'] as $path)
+		echo '
+			<input type="hidden" name="back_look[]" value="', $path, '" />';
+	echo '
+	</form><br />';
+}
+
+function template_permission_show_contents($ident, $contents, $level, $has_more = false)
+{
+	global $settings, $txt, $scripturl, $context;
+	$js_ident = preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident);
+	// Have we actually done something?
+	$drawn_div = false;
+
+	foreach ($contents as $name => $dir)
+	{
+		if (isset($dir['perms']))
+		{
+			if (!$drawn_div)
+			{
+				$drawn_div = true;
+				echo '
+			</table>
+			<table border="0" width="100%" class="table_grid" id="', $js_ident, '">';
+			}
+
+			$cur_ident = preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident . '/' . $name);
+			echo '
+			<tr class="windowbg" id="content_', $cur_ident, '">
+				<td class="smalltext" width="30%">' . str_repeat('&nbsp;', $level * 5), '
+					', (!empty($dir['type']) && $dir['type'] == 'dir_recursive') || !empty($dir['list_contents']) ? '<a id="link_' . $cur_ident . '" href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident . '/' . $name) . ';back_look=' . $context['back_look_data'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . $cur_ident . '" onclick="return expandFolder(\'' . $cur_ident . '\', \'' . addcslashes($ident . '/' . $name, "'\\") . '\');">' : '';
+
+			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
+				echo '
+					<img src="', $settings['default_images_url'], '/board.png" alt="*" />';
+
+			echo '
+					', $name, '
+					', (!empty($dir['type']) && $dir['type'] == 'dir_recursive') || !empty($dir['list_contents']) ? '</a>' : '', '
+				</td>
+				<td class="smalltext">
+					<span class="', ($dir['perms']['chmod'] ? 'success' : 'error'), '">', ($dir['perms']['chmod'] ? $txt['package_file_perms_writable'] : $txt['package_file_perms_not_writable']), '</span>
+					', ($dir['perms']['perms'] ? '&nbsp;(' . $txt['package_file_perms_chmod'] . ': ' . substr(sprintf('%o', $dir['perms']['perms']), -4) . ')' : ''), '
+				</td>
+				<td align="center" width="8%" class="perm_read"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="read" class="input_radio" /></td>
+				<td align="center" width="8%" class="perm_write"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="writable" class="input_radio" /></td>
+				<td align="center" width="8%" class="perm_execute"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="execute" class="input_radio" /></td>
+				<td align="center" width="8%" class="perm_custom"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="custom" class="input_radio" /></td>
+				<td align="center" width="8%" class="perm_nochange"><input type="radio" name="permStatus[', $ident . '/' . $name, ']" value="no_change" checked="checked" class="input_radio" /></td>
+			</tr>
+			<tr id="insert_div_loc_' . $cur_ident . '" style="display: none;"><td></td></tr>';
+
+			if (!empty($dir['contents']))
+			{
+				template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
+
+			}
+		}
+	}
+
+	// We have more files to show?
+	if ($has_more)
+		echo '
+	<tr class="windowbg" id="content_', $js_ident, '_more">
+		<td class="smalltext" width="40%">' . str_repeat('&nbsp;', $level * 5), '
+			&#171; <a href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident) . ';fileoffset=', ($context['file_offset'] + $context['file_limit']), ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident) . '">', $txt['package_file_perms_more_files'], '</a> &#187;
+		</td>
+		<td colspan="6"></td>
+	</tr>';
+
+	if ($drawn_div)
+	{
+		// Hide anything too far down the tree.
+		$isFound = false;
+		foreach ($context['look_for'] as $tree)
+		{
+			if (substr($tree, 0, strlen($ident)) == $ident)
+				$isFound = true;
+		}
+
+		if ($level > 1 && !$isFound)
+			echo '
+		</table><script type="text/javascript"><!-- // --><![CDATA[
+			expandFolder(\'', $js_ident, '\', \'\');
+		// ]]></script>
+		<table border="0" width="100%" class="table_grid">
+			<tr style="display: none;"><td></td></tr>';
+	}
+}
+
+function template_action_permissions()
+{
+	global $txt, $scripturl, $context, $settings;
+
+	$countDown = 3;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=packages;sa=perms;', $context['session_var'], '=', $context['session_id'], '" id="perm_submit" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['package_file_perms_applying'], '</h3>
+			</div>';
+
+	if (!empty($context['skip_ftp']))
+		echo '
+			<div class="errorbox">
+				', $txt['package_file_perms_skipping_ftp'], '
+			</div>';
+
+	// How many have we done?
+	$remaining_items = count($context['method'] == 'individual' ? $context['to_process'] : $context['directory_list']);
+	$progress_message = sprintf($context['method'] == 'individual' ? $txt['package_file_perms_items_done'] : $txt['package_file_perms_dirs_done'], $context['total_items'] - $remaining_items, $context['total_items']);
+	$progress_percent = round(($context['total_items'] - $remaining_items) / $context['total_items'] * 100, 1);
+
+	echo '
+			<div class="windowbg">
+				<div class="content">
+					<div>
+						<strong>', $progress_message, '</strong><br /><br />
+						<div class="progress_bar">
+							<div class="full_bar">', $progress_percent, '%</div>
+							<div class="blue_percent" style="width: ', $progress_percent, '%;">&nbsp;</div>
+						</div>
+					</div>';
+
+	// Second progress bar for a specific directory?
+	if ($context['method'] != 'individual' && !empty($context['total_files']))
+	{
+		$file_progress_message = sprintf($txt['package_file_perms_files_done'], $context['file_offset'], $context['total_files']);
+		$file_progress_percent = round($context['file_offset'] / $context['total_files'] * 100, 1);
+
+		echo '
+					<br />
+					<div>
+						<strong>', $file_progress_message, '</strong><br /><br />
+						<div class="progress_bar">
+							<div class="full_bar">', $file_progress_percent, '%</div>
+							<div class="green_percent" style="width: ', $file_progress_percent, '%;">&nbsp;</div>
+						</div>
+					</div>';
+	}
+
+	echo '
+					<br />';
+
+	// Put out the right hidden data.
+	if ($context['method'] == 'individual')
+		echo '
+					<input type="hidden" name="custom_value" value="', $context['custom_value'], '" />
+					<input type="hidden" name="totalItems" value="', $context['total_items'], '" />
+					<input type="hidden" name="toProcess" value="', base64_encode(serialize($context['to_process'])), '" />';
+	else
+		echo '
+					<input type="hidden" name="predefined" value="', $context['predefined_type'], '" />
+					<input type="hidden" name="fileOffset" value="', $context['file_offset'], '" />
+					<input type="hidden" name="totalItems" value="', $context['total_items'], '" />
+					<input type="hidden" name="dirList" value="', base64_encode(serialize($context['directory_list'])), '" />
+					<input type="hidden" name="specialFiles" value="', base64_encode(serialize($context['special_files'])), '" />';
+
+	// Are we not using FTP for whatever reason.
+	if (!empty($context['skip_ftp']))
+		echo '
+					<input type="hidden" name="skip_ftp" value="1" />';
+
+	// Retain state.
+	foreach ($context['back_look_data'] as $path)
+		echo '
+					<input type="hidden" name="back_look[]" value="', $path, '" />';
+
+	echo '
+					<input type="hidden" name="method" value="', $context['method'], '" />
+					<input type="hidden" name="action_changes" value="1" />
+					<div class="righttext padding">
+						<input type="submit" name="go" id="cont" value="', $txt['not_done_continue'], '" class="button_submit" />
+					</div>
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+
+	// Just the countdown stuff
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var countdown = ', $countDown, ';
+		doAutoSubmit();
+
+		function doAutoSubmit()
+		{
+			if (countdown == 0)
+				document.forms.perm_submit.submit();
+			else if (countdown == -1)
+				return;
+
+			document.getElementById(\'cont\').value = "', $txt['not_done_continue'], ' (" + countdown + ")";
+			countdown--;
+
+			setTimeout("doAutoSubmit();", 1000);
+		}
+	// ]]></script>';
+
+}
+
 ?>

+ 1824 - 1856
Themes/default/PersonalMessage.template.php

@@ -1,1857 +1,1825 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-
-// This is the main sidebar for the personal messages section.
-function template_pm_above()
-{
-	global $context, $settings, $options, $txt;
-
-	echo '
-	<div id="personal_messages">';
-
-	// Show the capacity bar, if available.
-	if (!empty($context['limit_bar']))
-		echo '
-		<div class="title_bar">
-			<h3 class="titlebg">
-				<span class="floatleft">', $txt['pm_capacity'], ':</span>
-				<span class="floatleft capacity_bar">
-					<span class="', $context['limit_bar']['percent'] > 85 ? 'full' : ($context['limit_bar']['percent'] > 40 ? 'filled' : 'empty'), '" style="width: ', $context['limit_bar']['percent'] / 10, 'em;"></span>
-				</span>
-				<span class="floatright', $context['limit_bar']['percent'] > 90 ? ' alert' : '', '">', $context['limit_bar']['text'], '</span>
-			</h3>
-		</div>';
-
-	// Message sent? Show a small indication.
-	if (isset($context['pm_sent']))
-		echo '
-		<div class="infobox">
-			', $txt['pm_sent'], '
-		</div>';
-}
-
-// Just the end of the index bar, nothing special.
-function template_pm_below()
-{
-	global $context, $settings, $options;
-
-	echo '
-	</div>';
-}
-
-function template_folder()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// The every helpful javascript!
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var allLabels = {};
-		var currentLabels = {};
-		function loadLabelChoices()
-		{
-			var listing = document.forms.pmFolder.elements;
-			var theSelect = document.forms.pmFolder.pm_action;
-			var add, remove, toAdd = {length: 0}, toRemove = {length: 0};
-
-			if (theSelect.childNodes.length == 0)
-				return;
-
-			// This is done this way for internationalization reasons.
-			if (!(\'-1\' in allLabels))
-			{
-				for (var o = 0; o < theSelect.options.length; o++)
-					if (theSelect.options[o].value.substr(0, 4) == "rem_")
-						allLabels[theSelect.options[o].value.substr(4)] = theSelect.options[o].text;
-			}
-
-			for (var i = 0; i < listing.length; i++)
-			{
-				if (listing[i].name != "pms[]" || !listing[i].checked)
-					continue;
-
-				var alreadyThere = [], x;
-				for (x in currentLabels[listing[i].value])
-				{
-					if (!(x in toRemove))
-					{
-						toRemove[x] = allLabels[x];
-						toRemove.length++;
-					}
-					alreadyThere[x] = allLabels[x];
-				}
-
-				for (x in allLabels)
-				{
-					if (!(x in alreadyThere))
-					{
-						toAdd[x] = allLabels[x];
-						toAdd.length++;
-					}
-				}
-			}
-
-			while (theSelect.options.length > 2)
-				theSelect.options[2] = null;
-
-			if (toAdd.length != 0)
-			{
-				theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_apply'], '", "");
-				setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_apply'], '");
-				theSelect.options[theSelect.options.length - 1].disabled = true;
-
-				for (i in toAdd)
-				{
-					if (i != "length")
-						theSelect.options[theSelect.options.length] = new Option(toAdd[i], "add_" + i);
-				}
-			}
-
-			if (toRemove.length != 0)
-			{
-				theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_remove'], '", "");
-				setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_remove'], '");
-				theSelect.options[theSelect.options.length - 1].disabled = true;
-
-				for (i in toRemove)
-				{
-					if (i != "length")
-						theSelect.options[theSelect.options.length] = new Option(toRemove[i], "rem_" + i);
-				}
-			}
-		}
-	// ]]></script>';
-
-	echo '
-<form class="flow_hidden" action="', $scripturl, '?action=pm;sa=pmactions;', $context['display_mode'] == 2 ? 'conversation;' : '', 'f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '" method="post" accept-charset="', $context['character_set'], '" name="pmFolder">';
-
-	// If we are not in single display mode show the subjects on the top!
-	if ($context['display_mode'] != 1)
-	{
-		template_subject_list();
-		echo '<div class="clear_right"><br /></div>';
-	}
-
-	// Got some messages to display?
-	if ($context['get_pmessage']('message', true))
-	{
-		// Show the helpful titlebar - generally.
-		if ($context['display_mode'] != 1)
-			echo '
-				<div class="cat_bar">
-					<h3 class="catbg">
-						<span id="author">', $txt['author'], '</span>
-						<span id="topic_title">', $txt[$context['display_mode'] == 0 ? 'messages' : 'conversation'], '</span>
-					</h3>
-				</div>';
-
-		// Show a few buttons if we are in conversation mode and outputting the first message.
-		if ($context['display_mode'] == 2)
-		{
-			// Show the conversation buttons.
-			echo '
-					<div class="pagesection">';
-
-			template_button_strip($context['conversation_buttons'], 'right');
-
-			echo '
-					</div>';
-		}
-
-		while ($message = $context['get_pmessage']('message'))
-		{
-			$window_class = $message['alternate'] == 0 ? 'windowbg' : 'windowbg2';
-
-			echo '
-	<div class="', $window_class, ' clear">
-		<span class="topslice"><span></span></span>
-		<div class="poster">
-			<a id="msg', $message['id'], '"></a>
-			<h4>';
-
-			// Show online and offline buttons?
-			if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
-				echo '
-				<img src="', $message['member']['online']['image_href'], '" alt="', $message['member']['online']['text'], '" />';
-
-			echo '
-				', $message['member']['link'], '
-			</h4>
-			<ul class="reset smalltext" id="msg_', $message['id'], '_extra_info">';
-
-			// Show the member's custom title, if they have one.
-			if (isset($message['member']['title']) && $message['member']['title'] != '')
-				echo '
-				<li class="title">', $message['member']['title'], '</li>';
-
-			// Show the member's primary group (like 'Administrator') if they have one.
-			if (isset($message['member']['group']) && $message['member']['group'] != '')
-				echo '
-				<li class="membergroup">', $message['member']['group'], '</li>';
-
-			// Don't show these things for guests.
-			if (!$message['member']['is_guest'])
-			{
-				// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
-				if ((empty($settings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
-					echo '
-				<li class="postgroup">', $message['member']['post_group'], '</li>';
-				echo '
-				<li class="icons">', $message['member']['group_icons'], '</li>';
-
-				// Show avatars, images, etc.?
-				if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
-					echo '
-				<li class="avatar">
-					<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">
-						', $message['member']['avatar']['image'], '
-					</a>
-				</li>';
-
-				// Show how many posts they have made.
-				if (!isset($context['disabled_fields']['posts']))
-					echo '
-				<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
-
-				// Is karma display enabled?  Total or +/-?
-				if ($modSettings['karmaMode'] == '1')
-					echo '
-				<li class="karma">', $modSettings['karmaLabel'], ' ', $message['member']['karma']['good'] - $message['member']['karma']['bad'], '</li>';
-				elseif ($modSettings['karmaMode'] == '2')
-					echo '
-				<li class="karma">', $modSettings['karmaLabel'], ' +', $message['member']['karma']['good'], '/-', $message['member']['karma']['bad'], '</li>';
-
-				// Is this user allowed to modify this member's karma?
-				if ($message['member']['karma']['allow'])
-					echo '
-				<li class="karma_allow">
-					<a href="', $scripturl, '?action=modifykarma;sa=applaud;uid=', $message['member']['id'], ';f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pm=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $modSettings['karmaApplaudLabel'], '</a> <a href="', $scripturl, '?action=modifykarma;sa=smite;uid=', $message['member']['id'], ';f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pm=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $modSettings['karmaSmiteLabel'], '</a>
-				</li>';
-
-				// Show the member's gender icon?
-				if (!empty($settings['show_gender']) && $message['member']['gender']['image'] != '' && !isset($context['disabled_fields']['gender']))
-					echo '
-				<li class="gender">', $txt['gender'], ': ', $message['member']['gender']['image'], '</li>';
-
-				// Show their personal text?
-				if (!empty($settings['show_blurb']) && $message['member']['blurb'] != '')
-					echo '
-				<li class="blurb">', $message['member']['blurb'], '</li>';
-
-				// Any custom fields to show as icons?
-				if (!empty($message['member']['custom_fields']))
-				{
-					$shown = false;
-					foreach ($message['member']['custom_fields'] as $custom)
-					{
-						if ($custom['placement'] != 1 || empty($custom['value']))
-							continue;
-						if (empty($shown))
-						{
-							$shown = true;
-							echo '
-				<li class="im_icons">
-					<ul>';
-						}
-						echo '
-						<li>', $custom['value'], '</li>';
-					}
-					if ($shown)
-					echo '
-					</ul>
-				</li>';
-				}
-
-				// This shows the popular messaging icons.
-				if ($message['member']['has_messenger'] && $message['member']['can_view_profile'])
-					echo '
-				<li class="im_icons">
-					<ul>', !isset($context['disabled_fields']['icq']) && !empty($message['member']['icq']['link']) ? '
-						<li>' . $message['member']['icq']['link'] . '</li>' : '', !isset($context['disabled_fields']['msn']) && !empty($message['member']['msn']['link']) ? '
-						<li>' . $message['member']['msn']['link'] . '</li>' : '', !isset($context['disabled_fields']['aim']) && !empty($message['member']['aim']['link']) ? '
-						<li>' . $message['member']['aim']['link'] . '</li>' : '', !isset($context['disabled_fields']['yim']) && !empty($message['member']['yim']['link']) ? '
-						<li>' . $message['member']['yim']['link'] . '</li>' : '', '
-					</ul>
-				</li>';
-
-				// Show the profile, website, email address, and personal message buttons.
-				if ($message['member']['show_profile_buttons'])
-				{
-					echo '
-				<li class="profile">
-					<ul>';
-
-					// Show the profile button
-					if ($message['member']['can_view_profile'])
-						echo '
-						<li><a href="', $message['member']['href'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="' . $txt['view_profile'] . '" title="' . $txt['view_profile'] . '" />' : $txt['view_profile']), '</a></li>';
-
-					// Don't show an icon if they haven't specified a website.
-					if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website']))
-						echo '
-						<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/www_sm.png" alt="' . $message['member']['website']['title'] . '" />' : $txt['www']), '</a></li>';
-
-					// Don't show the email address if they want it hidden.
-					if (in_array($message['member']['show_email'], array('yes', 'yes_permission_override', 'no_through_forum')) && $context['can_send_email'])
-						echo '
-						<li><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $message['member']['id'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . '" />' : $txt['email']), '</a></li>';
-
-					// Since we know this person isn't a guest, you *can* message them.
-					if ($context['can_send_pm'])
-						echo '
-						<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . '.png" alt="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '" />' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
-
-					echo '
-					</ul>
-				</li>';
-				}
-
-				// Any custom fields for standard placement?
-				if (!empty($message['member']['custom_fields']))
-				{
-					foreach ($message['member']['custom_fields'] as $custom)
-						if (empty($custom['placement']) || empty($custom['value']))
-							echo '
-				<li class="custom">', $custom['title'], ': ', $custom['value'], '</li>';
-				}
-
-				// Are we showing the warning status?
-				if ($message['member']['can_see_warning'])
-				echo '
-				<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<img src="', $settings['images_url'], '/warning_', $message['member']['warning_status'], '.png" alt="', $txt['user_warn_' . $message['member']['warning_status']], '" />', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
-			}
-
-			// Done with the information about the poster... on to the post itself.
-			echo '
-			</ul>
-		</div>
-		<div class="postarea">
-			<div class="flow_hidden">
-				<div class="keyinfo">
-					<h5 id="subject_', $message['id'], '">
-						', $message['subject'], '
-					</h5>';
-
-			// Show who the message was sent to.
-			echo '
-					<span class="smalltext">&#171; <strong> ', $txt['sent_to'], ':</strong> ';
-
-			// People it was sent directly to....
-			if (!empty($message['recipients']['to']))
-				echo implode(', ', $message['recipients']['to']);
-			// Otherwise, we're just going to say "some people"...
-			elseif ($context['folder'] != 'sent')
-				echo '(', $txt['pm_undisclosed_recipients'], ')';
-
-			echo '
-						<strong> ', $txt['on'], ':</strong> ', $message['time'], ' &#187;
-					</span>';
-
-			// If we're in the sent items, show who it was sent to besides the "To:" people.
-			if (!empty($message['recipients']['bcc']))
-				echo '
-					<br /><span class="smalltext">&#171; <strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' &#187;</span>';
-
-			if (!empty($message['is_replied_to']))
-				echo '
-					<br /><span class="smalltext">&#171; ', $txt['pm_is_replied_to'], ' &#187;</span>';
-
-			echo '
-				</div>
-				<ul class="reset smalltext quickbuttons">';
-
-			// Show reply buttons if you have the permission to send PMs.
-			if ($context['can_send_pm'])
-			{
-				// You can't really reply if the member is gone.
-				if (!$message['member']['is_guest'])
-				{
-					// Is there than more than one recipient you can reply to?
-					if ($message['number_recipients'] > 1 && $context['display_mode'] != 2)
-						echo '
-					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=all" class="reply_all_button">', $txt['reply_to_all'], '</a></li>';
-
-					echo '
-					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '" class="reply_button">', $txt['reply'], '</a></li>
-					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote', $context['folder'] == 'sent' ? '' : ';u=' . $message['member']['id'], '" class="quote_button">', $txt['quote'], '</a></li>';
-				}
-				// This is for "forwarding" - even if the member is gone.
-				else
-					echo '
-					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote" class="quote_button">', $txt['reply_quote'], '</a></li>';
-			}
-			echo '
-					<li><a href="', $scripturl, '?action=pm;sa=pmactions;pm_actions[', $message['id'], ']=delete;f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', addslashes($txt['remove_message']), '?\');" class="remove_button">', $txt['delete'], '</a></li>';
-
-			if (empty($context['display_mode']))
-				echo '
-					<li class="inline_mod_check"><input type="checkbox" name="pms[]" id="deletedisplay', $message['id'], '" value="', $message['id'], '" onclick="document.getElementById(\'deletelisting', $message['id'], '\').checked = this.checked;" class="input_check" /></li>';
-
-			echo '
-				</ul>
-			</div>
-			<div class="post">
-				<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
-				<div class="smalltext reportlinks">
-					', (!empty($modSettings['enableReportPM']) && $context['folder'] != 'sent' ? '<div class="righttext"><a href="' . $scripturl . '?action=pm;sa=report;l=' . $context['current_label_id'] . ';pmsg=' . $message['id'] . '">' . $txt['pm_report_to_admin'] . '</a></div>' : '');
-
-			echo '
-				</div>';
-
-			// Are there any custom profile fields for above the signature?
-			if (!empty($message['member']['custom_fields']))
-			{
-				$shown = false;
-				foreach ($message['member']['custom_fields'] as $custom)
-				{
-					if ($custom['placement'] != 2 || empty($custom['value']))
-						continue;
-					if (!$shown)
-					{
-						$shown = true;
-						echo '
-				<div class="custom_fields_above_signature">
-					<ul class="reset nolist">';
-					}
-					echo '
-						<li>', $custom['value'], '</li>';
-				}
-				if ($shown)
-					echo '
-					</ul>
-				</div>';
-			}
-
-			// Show the member's signature?
-			if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
-				echo '
-				<div class="signature">', $message['member']['signature'], '</div>';
-
-			// Add an extra line at the bottom if we have labels enabled.
-			if ($context['folder'] != 'sent' && !empty($context['currently_using_labels']) && $context['display_mode'] != 2)
-			{
-				echo '
-				<div class="labels righttext">';
-				// Add the label drop down box.
-				if (!empty($context['currently_using_labels']))
-				{
-					echo '
-					<select name="pm_actions[', $message['id'], ']" onchange="if (this.options[this.selectedIndex].value) form.submit();">
-						<option value="">', $txt['pm_msg_label_title'], ':</option>
-						<option value="" disabled="disabled">---------------</option>';
-
-					// Are there any labels which can be added to this?
-					if (!$message['fully_labeled'])
-					{
-						echo '
-						<option value="" disabled="disabled">', $txt['pm_msg_label_apply'], ':</option>';
-						foreach ($context['labels'] as $label)
-							if (!isset($message['labels'][$label['id']]))
-								echo '
-							<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
-					}
-					// ... and are there any that can be removed?
-					if (!empty($message['labels']) && (count($message['labels']) > 1 || !isset($message['labels'][-1])))
-					{
-						echo '
-						<option value="" disabled="disabled">', $txt['pm_msg_label_remove'], ':</option>';
-						foreach ($message['labels'] as $label)
-							echo '
-							<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
-					}
-					echo '
-					</select>
-					<noscript>
-						<input type="submit" value="', $txt['pm_apply'], '" class="button_submit" />
-					</noscript>';
-				}
-				echo '
-				</div>';
-			}
-
-			echo '
-			</div>
-			<br class="clear" />
-		</div>
-		<div class="moderatorbar">
-		</div>
-		<span class="botslice"><span></span></span>
-	</div>';
-		}
-
-		if (empty($context['display_mode']))
-			echo '
-
-	<div class="pagesection">
-		<div class="floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
-		<div class="floatright"><input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" style="font-weight: normal;" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button_submit" /></div>
-	</div>';
-
-		// Show a few buttons if we are in conversation mode and outputting the first message.
-		elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons']))
-		{
-			echo '
-
-	<div class="pagesection">';
-
-			template_button_strip($context['conversation_buttons'], 'right');
-
-			echo '
-	</div>';
-		}
-
-		echo '
-		<br />';
-	}
-
-	// Individual messages = buttom list!
-	if ($context['display_mode'] == 1)
-	{
-		template_subject_list();
-		echo '<br />';
-	}
-
-	echo '
-	<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-</form>';
-}
-
-// Just list all the personal message subjects - to make templates easier.
-function template_subject_list()
-{
-	global $context, $options, $settings, $modSettings, $txt, $scripturl;
-
-	echo '
-	<table width="100%" class="table_grid">
-	<thead>
-		<tr class="catbg">
-			<th align="center" width="4%" class="first_th">
-				<a href="', $scripturl, '?action=pm;view;f=', $context['folder'], ';start=', $context['start'], ';sort=', $context['sort_by'], ($context['sort_direction'] == 'up' ? '' : ';desc'), ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), '"><img src="', $settings['images_url'], '/im_switch.png" alt="', $txt['pm_change_view'], '" title="', $txt['pm_change_view'], '" width="16" height="16" /></a>
-			</th>
-			<th class="lefttext" width="22%">
-				<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=date', $context['sort_by'] == 'date' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['date'], $context['sort_by'] == 'date' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a>
-			</th>
-			<th class="lefttext" width="46%">
-				<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a>
-			</th>
-			<th class="lefttext">
-				<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', ($context['from_or_to'] == 'from' ? $txt['from'] : $txt['to']), $context['sort_by'] == 'name' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a>
-			</th>
-			<th align="center" width="4%" class="last_th">
-				<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />
-			</th>
-		</tr>
-	</thead>
-	<tbody>';
-	if (!$context['show_delete'])
-		echo '
-		<tr class="windowbg2">
-			<td colspan="5">', $txt['msg_alert_none'], '</td>
-		</tr>';
-	$next_alternate = false;
-
-	while ($message = $context['get_pmessage']('subject'))
-	{
-		echo '
-		<tr class="', $next_alternate ? 'windowbg' : 'windowbg2', '">
-			<td align="center" width="4%">
-			<script type="text/javascript"><!-- // --><![CDATA[
-				currentLabels[', $message['id'], '] = {';
-
-		if (!empty($message['labels']))
-		{
-			$first = true;
-			foreach ($message['labels'] as $label)
-			{
-				echo $first ? '' : ',', '
-				"', $label['id'], '": "', $label['name'], '"';
-				$first = false;
-			}
-		}
-
-		echo '
-				};
-			// ]]></script>
-				', $message['is_replied_to'] ? '<img src="' . $settings['images_url'] . '/icons/pm_replied.png" style="margin-right: 4px;" alt="' . $txt['pm_replied'] . '" />' : '<img src="' . $settings['images_url'] . '/icons/pm_read.png" style="margin-right: 4px;" alt="' . $txt['pm_read'] . '" />', '</td>
-			<td>', $message['time'], '</td>
-			<td>', ($context['display_mode'] != 0 && $context['current_pm'] == $message['id'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*" />' : ''), '<a href="', ($context['display_mode'] == 0 || $context['current_pm'] == $message['id'] ? '' : ($scripturl . '?action=pm;pmid=' . $message['id'] . ';kstart;f=' . $context['folder'] . ';start=' . $context['start'] . ';sort=' . $context['sort_by'] . ($context['sort_direction'] == 'up' ? ';' : ';desc') . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''))), '#msg', $message['id'], '">', $message['subject'], $message['is_unread'] ? '&nbsp;<span class="new_posts">' . $txt['new'] . '</span>' : '', '</a></td>
-			<td>', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '</td>
-			<td align="center" width="4%"><input type="checkbox" name="pms[]" id="deletelisting', $message['id'], '" value="', $message['id'], '"', $message['is_selected'] ? ' checked="checked"' : '', ' onclick="if (document.getElementById(\'deletedisplay', $message['id'], '\')) document.getElementById(\'deletedisplay', $message['id'], '\').checked = this.checked;" class="input_check" /></td>
-		</tr>';
-			$next_alternate = !$next_alternate;
-	}
-
-	echo '
-	</tbody>
-	</table>
-	<div class="pagesection">
-		<div class="floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
-		<div class="floatright">&nbsp;';
-
-	if ($context['show_delete'])
-	{
-		if (!empty($context['currently_using_labels']) && $context['folder'] != 'sent')
-		{
-			echo '
-				<select name="pm_action" onchange="if (this.options[this.selectedIndex].value) this.form.submit();" onfocus="loadLabelChoices();">
-					<option value="">', $txt['pm_sel_label_title'], ':</option>
-					<option value="" disabled="disabled">---------------</option>';
-
-			echo '
-					<option value="" disabled="disabled">', $txt['pm_msg_label_apply'], ':</option>';
-					
-			foreach ($context['labels'] as $label)
-			{
-				if ($label['id'] != $context['current_label_id'])
-					echo '
-					<option value="add_', $label['id'], '">&nbsp;', $label['name'], '</option>';
-			}
-			
-			echo '
-					<option value="" disabled="disabled">', $txt['pm_msg_label_remove'], ':</option>';
-					
-			foreach ($context['labels'] as $label)
-			{
-				echo '
-					<option value="rem_', $label['id'], '">&nbsp;', $label['name'], '</option>';
-			}
-			
-			echo '
-				</select>
-				<noscript>
-					<input type="submit" value="', $txt['pm_apply'], '" class="button_submit" />
-				</noscript>';
-		}
-
-		echo '
-				<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button_submit" />';
-	}
-
-	echo '
-				</div>
-	</div>';
-}
-
-function template_search()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_search_title'], '</h3>
-		</div>';
-
-	if (!empty($context['search_errors']))
-	{
-		echo '
-		<div class="errorbox">
-			', implode('<br />', $context['search_errors']['messages']), '
-		</div>';
-	}
-
-	if ($context['simple_search'])
-	{
-		echo '
-		<fieldset id="simple_search">
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<div id="search_term_input">
-					<strong>', $txt['pm_search_text'], ':</strong>
-					<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40" class="input_text" />
-					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit" />
-				</div>
-				<a href="', $scripturl, '?action=pm;sa=search;advanced" onclick="this.href += \';search=\' + escape(document.forms.searchform.search.value);">', $txt['pm_search_advanced'], '</a>
-				<input type="hidden" name="advanced" value="0" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</fieldset>';
-	}
-
-	// Advanced search!
-	else
-	{
-		echo '
-		<fieldset id="advanced_search">
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<input type="hidden" name="advanced" value="1" />
-				<span class="enhanced">
-					<strong>', $txt['pm_search_text'], ':</strong>
-					<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40" class="input_text" />
-					<script type="text/javascript"><!-- // --><![CDATA[
-						createEventListener(window);
-						window.addEventListener("load", initSearch, false);
-					// ]]></script>
-					<select name="searchtype">
-						<option value="1"', empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['pm_search_match_all'], '</option>
-						<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['pm_search_match_any'], '</option>
-					</select>
-				</span>
-				<dl id="search_options">
-					<dt>', $txt['pm_search_user'], ':</dt>
-					<dd><input type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40" class="input_text" /></dd>
-					<dt>', $txt['pm_search_order'], ':</dt>
-					<dd>
-						<select name="sort">
-							<option value="relevance|desc">', $txt['pm_search_orderby_relevant_first'], '</option>
-							<option value="id_pm|desc">', $txt['pm_search_orderby_recent_first'], '</option>
-							<option value="id_pm|asc">', $txt['pm_search_orderby_old_first'], '</option>
-						</select>
-					</dd>
-					<dt class="options">', $txt['pm_search_options'], ':</dt>
-					<dd class="options">
-						<label for="show_complete"><input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['pm_search_show_complete'], '</label><br />
-						<label for="subject_only"><input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['pm_search_subject_only'], '</label>
-					</dd>
-					<dt class="between">', $txt['pm_search_post_age'], ':</dt>
-					<dd>', $txt['pm_search_between'], ' <input type="text" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="5" class="input_text" />&nbsp;', $txt['pm_search_between_and'], '&nbsp;<input type="text" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="5" class="input_text" /> ', $txt['pm_search_between_days'], '</dd>
-				</dl>';
-		if (!$context['currently_using_labels'])
-			echo '
-				<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit floatright" />';
-			echo '
-				<br class="clear_right" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</fieldset>';
-
-		// Do we have some labels setup? If so offer to search by them!
-		if ($context['currently_using_labels'])
-		{
-			echo '
-		<fieldset class="labels">
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<div class="title_bar">
-					<h4 class="titlebg">
-						<img id="advanced_panel_toggle" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png"  alt="*" /><a href="#" id="advanced_panel_link">', $txt['pm_search_choose_label'], '</a>
-					</h4>
-				</div>
-				<div id="advanced_panel_div">
-				<ul id="searchLabelsExpand" class="reset" >';
-
-			foreach ($context['search_labels'] as $label)
-				echo '
-					<li>
-						<label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '" ', $label['checked'] ? 'checked="checked"' : '', ' class="input_check" />
-						', $label['name'], '</label>
-					</li>';
-
-			echo '
-				</ul>
-				</div>
-				<p>
-					<span class="floatleft"><input type="checkbox" name="all" id="check_all" value="" ', $context['check_all'] ? 'checked="checked"' : '', ' onclick="invertAll(this, this.form, \'searchlabel\');" class="input_check" /><em> <label for="check_all">', $txt['check_all'], '</label></em></span>
-					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit" />
-				</p><br class="clear_right" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</fieldset>';
-
-			// Some javascript for the advanced toggling
-			echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var oAdvancedPanelToggle = new smc_Toggle({
-				bToggleEnabled: true,
-				bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
-				aSwappableContainers: [
-					\'advanced_panel_div\'
-				],
-				aSwapImages: [
-					{
-						sId: \'advanced_panel_toggle\',
-						srcExpanded: smf_images_url + \'/collapse.png\',
-						altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
-						srcCollapsed: smf_images_url + \'/expand.png\',
-						altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
-					}
-				],
-				aSwapLinks: [
-					{
-						sId: \'advanced_panel_link\',
-						msgExpanded: ', JavaScriptEscape($txt['pm_search_choose_label']), ',
-						msgCollapsed: ', JavaScriptEscape($txt['pm_search_choose_label']), '
-					}
-				],
-				oThemeOptions: {
-					bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
-					sOptionName: \'admin_preferences\',
-					sSessionVar: smf_session_var,
-					sSessionId: smf_session_id,
-					sThemeId: \'1\'
-				}
-			});
-		// ]]></script>';
-		}
-	}
-
-	echo '
-	</form>';
-}
-
-function template_search_results()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_search_results'], '</h3>
-		</div>
-		<div class="pagesection">
-			<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
-		</div>';
-
-	// complete results ?
-	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
-		echo '
-	<table width="100%" class="table_grid">
-	<thead>
-		<tr class="catbg">
-			<th class="lefttext first_th" width="30%">', $txt['date'], '</th>
-			<th class="lefttext" width="50%">', $txt['subject'], '</th>
-			<th class="lefttext last_th" width="20%">', $txt['from'], '</th>
-		</tr>
-	</thead>
-	<tbody>';
-
-	$alternate = true;
-	// Print each message out...
-	foreach ($context['personal_messages'] as $message)
-	{
-		// We showing it all?
-		if (!empty($context['search_params']['show_complete']))
-		{
-			echo '
-			<div class="title_bar">
-				<h3 class="titlebg">
-					<span class="floatright">', $txt['search_on'], ': ', $message['time'], '</span>
-					<span class="floatleft">', $message['counter'], '&nbsp;&nbsp;<a href="', $message['href'], '">', $message['subject'], '</a></span>
-				</h3>
-			</div>
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['from'], ': ', $message['member']['link'], ', ', $txt['to'], ': ';
-
-				// Show the recipients.
-				// @todo This doesn't deal with the sent item searching quite right for bcc.
-				if (!empty($message['recipients']['to']))
-					echo implode(', ', $message['recipients']['to']);
-				// Otherwise, we're just going to say "some people"...
-				elseif ($context['folder'] != 'sent')
-					echo '(', $txt['pm_undisclosed_recipients'], ')';
-
-					echo '
-				</h3>
-			</div>
-			<div class="windowbg', $alternate ? '2': '', '">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					', $message['body'], '
-					<p class="pm_reply righttext middletext">';
-
-				if ($context['can_send_pm'])
-				{
-					$quote_button = create_button('quote.png', 'reply_quote', 'reply_quote', 'class="centericon"');
-					$reply_button = create_button('im_reply.png', 'reply', 'reply', 'class="centericon"');
-					// You can only reply if they are not a guest...
-					if (!$message['member']['is_guest'])
-						echo '
-								<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=', $context['folder'] == 'sent' ? '' : $message['member']['id'], '">', $quote_button , '</a>', $context['menu_separator'], '
-								<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '">', $reply_button , '</a> ', $context['menu_separator'];
-					// This is for "forwarding" - even if the member is gone.
-					else
-						echo '
-								<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote">', $quote_button , '</a>', $context['menu_separator'];
-				}
-
-				echo '
-					</p>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-		}
-		// Otherwise just a simple list!
-		else
-		{
-			// @todo No context at all of the search?
-			echo '
-			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" valign="top">
-				<td>', $message['time'], '</td>
-				<td>', $message['link'], '</td>
-				<td>', $message['member']['link'], '</td>
-			</tr>';
-		}
-
-		$alternate = !$alternate;
-	}
-
-	// Finish off the page...
-	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
-		echo '
-		</tbody>
-		</table>';
-
-	// No results?
-	if (empty($context['personal_messages']))
-		echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p class="centertext">', $txt['pm_search_none_found'], '</p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	echo '
-		<div class="pagesection">
-			<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
-		</div>';
-
-}
-
-function template_send()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// Show which messages were sent successfully and which failed.
-	if (!empty($context['send_log']))
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['pm_send_report'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-				if (!empty($context['send_log']['sent']))
-					foreach ($context['send_log']['sent'] as $log_entry)
-						echo '<span class="error">', $log_entry, '</span><br />';
-				if (!empty($context['send_log']['failed']))
-					foreach ($context['send_log']['failed'] as $log_entry)
-						echo '<span class="error">', $log_entry, '</span><br />';
-				echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />';
-	}
-
-	// Show the preview of the personal message.
-	echo '
-		<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="post" id="preview_body">
-						', empty($context['preview_message']) ? '<br />' : $context['preview_message'], '
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div><br />';
-
-	// Main message editing box.
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/im_newmsg.png" class="icon" alt="', $txt['new_message'], '" title="', $txt['new_message'], '" />&nbsp;', $txt['new_message'], '</span>
-			</h3>
-		</div>';
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=send2" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'message\']);">
-		<div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe"><br class="clear" />';
-
-	// If there were errors for sending the PM, show them.
-	echo '
-				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
-					<dl>
-						<dt>
-							<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
-						</dt>
-						<dd class="error" id="error_list">
-							', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
-						</dd>
-					</dl>
-				</div>';
-
-	echo '
-				<dl id="post_header">';
-
-	// To and bcc. Include a button to search for members.
-	echo '
-					<dt>
-						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), ' id="caption_to">', $txt['pm_to'], ':</span>
-					</dt>';
-
-	// Autosuggest will be added by the JavaScript later on.
-	echo '
-					<dd id="pm_to" class="clear_right">
-						<input type="text" name="to" id="to_control" value="', $context['to_value'], '" tabindex="', $context['tabindex']++, '" size="40" style="width: 130px;" class="input_text" />';
-
-	// A link to add BCC, only visible with JavaScript enabled.
-	echo '
-						<span class="smalltext" id="bcc_link_container" style="display: none;"></span>';
-
-	// A div that'll contain the items found by the autosuggest.
-	echo '
-						<div id="to_item_list_container"></div>';
-
-	echo '
-					</dd>';
-
-	// This BCC row will be hidden by default if JavaScript is enabled.
-	echo '
-					<dt  class="clear_left" id="bcc_div">
-						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), ' id="caption_bbc">', $txt['pm_bcc'], ':</span>
-					</dt>
-					<dd id="bcc_div2">
-						<input type="text" name="bcc" id="bcc_control" value="', $context['bcc_value'], '" tabindex="', $context['tabindex']++, '" size="40" style="width: 130px;" class="input_text" />
-						<div id="bcc_item_list_container"></div>
-					</dd>';
-
-	// The subject of the PM.
-	echo '
-					<dt class="clear_left">
-						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
-					</dt>
-					<dd id="pm_subject">
-						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="60" maxlength="60"',isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', '/>
-					</dd>
-				</dl><hr class="clear" />';
-
-	// Showing BBC?
-	if ($context['show_bbc'])
-	{
-		echo '
-				<div id="bbcBox_message"></div>';
-	}
-
-	// What about smileys?
-	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
-		echo '
-				<div id="smileyBox_message"></div>';
-
-	// Show BBC buttons, smileys and textbox.
-	echo '
-				', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
-
-	// Require an image to be typed to save spamming?
-	if ($context['require_verification'])
-	{
-		echo '
-				<div class="post_verification">
-					<strong>', $txt['pm_visual_verification_label'], ':</strong>
-					', template_control_verification($context['visual_verification_id'], 'all'), '
-				</div>';
-	}
-
-	// Send, Preview, spellcheck buttons.
-	echo '
-				<p>
-					<label for="outbox"><input type="checkbox" name="outbox" id="outbox" value="1" tabindex="', $context['tabindex']++, '"', $context['copy_to_outbox'] ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['pm_save_outbox'], '</label>
-				</p>
-				<hr class="hrcolor" />
-				<span id="shortcuts" class="smalltext">
-					', isBrowser('is_firefox') ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '
-				</span>
-				<span id="post_confirm_strip" class="righttext">
-					', template_control_richedit_buttons($context['post_box_name']), '
-				</span>
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
-				<input type="hidden" name="replied_to" value="', !empty($context['quoted_message']['id']) ? $context['quoted_message']['id'] : 0, '" />
-				<input type="hidden" name="pm_head" value="', !empty($context['quoted_message']['pm_head']) ? $context['quoted_message']['pm_head'] : 0, '" />
-				<input type="hidden" name="f" value="', isset($context['folder']) ? $context['folder'] : '', '" />
-				<input type="hidden" name="l" value="', isset($context['current_label_id']) ? $context['current_label_id'] : -1, '" />
-				<br class="clear_right" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-	</form>';
-
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[';
-	// The functions used to preview a personal message without loading a new page.
-	echo '
-			var txt_preview_title = "', $txt['preview_title'], '";
-			var txt_preview_fetch = "', $txt['preview_fetch'], '";
-			function previewPost()
-			{';
-	if (isBrowser('is_firefox'))
-		echo '
-				// Firefox doesn\'t render <marquee> that have been put it using javascript
-				if (document.forms.postmodify.elements[', JavaScriptEscape($context['post_box_name']), '].value.indexOf(\'[move]\') != -1)
-				{
-					return submitThisOnce(document.forms.postmodify);
-				}';
-	echo '
-				if (window.XMLHttpRequest)
-				{
-					// Opera didn\'t support setRequestHeader() before 8.01.
-					// @todo Remove support for old browsers
-					if (\'opera\' in window)
-					{
-						var test = new XMLHttpRequest();
-						if (!(\'setRequestHeader\' in test))
-							return submitThisOnce(document.forms.postmodify);
-					}
-					// @todo Currently not sending poll options and option checkboxes.
-					var x = new Array();
-					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'to\', \'bcc\'];
-					var numericFields = [\'recipient_to[]\', \'recipient_bcc[]\'];
-					var checkboxFields = [\'outbox\'];
-
-					for (var i = 0, n = textFields.length; i < n; i++)
-						if (textFields[i] in document.forms.postmodify)
-						{
-							// Handle the WYSIWYG editor.
-							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
-								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
-							else
-								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
-						}
-					for (var i = 0, n = numericFields.length; i < n; i++)
-						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
-							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
-					for (var i = 0, n = checkboxFields.length; i < n; i++)
-						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
-							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
-
-					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=pm;sa=send2;preview;xml\', x.join(\'&\'), onDocSent);
-
-					document.getElementById(\'preview_section\').style.display = \'\';
-					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
-					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
-
-					return false;
-				}
-				else
-					return submitThisOnce(document.forms.postmodify);
-			}
-			function onDocSent(XMLDoc)
-			{
-				if (!XMLDoc)
-				{
-					document.forms.postmodify.preview.onclick = new function ()
-					{
-						return true;
-					}
-					document.forms.postmodify.preview.click();
-				}
-
-				// Show the preview section.
-				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
-				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
-
-				var bodyText = \'\';
-				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
-					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
-
-				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
-				document.getElementById(\'preview_body\').className = \'post\';
-
-				// Show a list of errors (if any).
-				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
-				var errorList = new Array();
-				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
-					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
-				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
-				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
-
-				// Adjust the color of captions if the given data is erroneous.
-				var captions = errors.getElementsByTagName(\'caption\');
-				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
-					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
-						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
-
-				if (errors.getElementsByTagName(\'post_error\').length == 1)
-					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
-				else if (document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
-				{
-					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
-						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
-					else
-						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
-				}
-				location.hash = \'#\' + \'preview_section\';
-			}';
-
-	echo '
-		// ]]></script>';
-
-	// Show the message you're replying to.
-	if ($context['reply'])
-		echo '
-	<br />
-	<br />
-	<div class="cat_bar">
-		<h3 class="catbg">', $txt['subject'], ': ', $context['quoted_message']['subject'], '</h3>
-	</div>
-	<div class="windowbg2">
-		<span class="topslice"><span></span></span>
-		<div class="content">
-			<div class="clear">
-				<span class="smalltext floatright">', $txt['on'], ': ', $context['quoted_message']['time'], '</span>
-				<strong>', $txt['from'], ': ', $context['quoted_message']['member']['name'], '</strong>
-			</div><hr />
-			', $context['quoted_message']['body'], '
-		</div>
-		<span class="botslice"><span></span></span>
-	</div><br class="clear" />';
-
-	echo '
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/PersonalMessage.js?alp21"></script>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var oPersonalMessageSend = new smf_PersonalMessageSend({
-				sSelf: \'oPersonalMessageSend\',
-				sSessionId: smf_session_id,
-				sSessionVar: smf_session_var,
-				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-				sToControlId: \'to_control\',
-				aToRecipients: [';
-	foreach ($context['recipients']['to'] as $i => $member)
-		echo '
-					{
-						sItemId: ', JavaScriptEscape($member['id']), ',
-						sItemName: ', JavaScriptEscape($member['name']), '
-					}', $i == count($context['recipients']['to']) - 1 ? '' : ',';
-
-	echo '
-				],
-				aBccRecipients: [';
-	foreach ($context['recipients']['bcc'] as $i => $member)
-		echo '
-					{
-						sItemId: ', JavaScriptEscape($member['id']), ',
-						sItemName: ', JavaScriptEscape($member['name']), '
-					}', $i == count($context['recipients']['bcc']) - 1 ? '' : ',';
-
-	echo '
-				],
-				sBccControlId: \'bcc_control\',
-				sBccDivId: \'bcc_div\',
-				sBccDivId2: \'bcc_div2\',
-				sBccLinkId: \'bcc_link\',
-				sBccLinkContainerId: \'bcc_link_container\',
-				bBccShowByDefault: ', empty($context['recipients']['bcc']) && empty($context['bcc_value']) ? 'false' : 'true', ',
-				sShowBccLinkTemplate: ', JavaScriptEscape('
-					<a href="#" id="bcc_link">' . $txt['make_bcc'] . '</a> <a href="' . $scripturl . '?action=helpadmin;help=pm_bcc" onclick="return reqWin(this.href);">(?)</a>'
-				), '
-			});
-		';
-
-	echo '
-		// ]]></script>';
-}
-
-// This template asks the user whether they wish to empty out their folder/messages.
-function template_ask_delete()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', ($context['delete_all'] ? $txt['delete_message'] : $txt['delete_all']), '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['delete_all_confirm'], '</p><br />
-				<strong><a href="', $scripturl, '?action=pm;sa=removeall2;f=', $context['folder'], ';', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="javascript:history.go(-1);">', $txt['no'], '</a></strong>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-}
-
-// This template asks the user what messages they want to prune.
-function template_prune()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=prune" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['pm_prune_warning'], '\');">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_prune'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['pm_prune_desc1'], ' <input type="text" name="age" size="3" value="14" class="input_text" /> ', $txt['pm_prune_desc2'], '</p>
-				<div class="righttext">
-					<input type="submit" value="', $txt['delete'], '" class="button_submit" />
-				</div>
-				<br class="clear" />
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-	</form>';
-}
-
-// Here we allow the user to setup labels, remove labels and change rules for labels (i.e, do quite a bit)
-function template_labels()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_manage_labels'], '</h3>
-		</div>
-		<div class="description">
-			', $txt['pm_labels_desc'], '
-		</div>
-		<table width="100%" class="table_grid">
-		<thead>
-			<tr class="catbg">
-				<th class="lefttext first_th">
-					', $txt['pm_label_name'], '
-				</th>
-				<th class="centertext last_th" width="4%">';
-
-	if (count($context['labels']) > 2)
-		echo '
-					<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />';
-
-	echo '
-				</th>
-			</tr>
-		</thead>
-		<tbody>';
-	if (count($context['labels']) < 2)
-		echo '
-			<tr class="windowbg2">
-				<td colspan="2" align="center">', $txt['pm_labels_no_exist'], '</td>
-			</tr>';
-	else
-	{
-		$alternate = true;
-		foreach ($context['labels'] as $label)
-		{
-			if ($label['id'] == -1)
-				continue;
-
-				echo '
-			<tr class="', $alternate ? 'windowbg2' : 'windowbg', '">
-				<td>
-					<input type="text" name="label_name[', $label['id'], ']" value="', $label['name'], '" size="30" maxlength="30" class="input_text" />
-				</td>
-				<td width="4%" align="center"><input type="checkbox" class="input_check" name="delete_label[', $label['id'], ']" /></td>
-			</tr>';
-
-			$alternate = !$alternate;
-		}
-	}
-	echo '
-		</tbody>
-		</table>';
-
-	if (!count($context['labels']) < 2)
-		echo '
-		<div class="padding righttext">
-			<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" />
-			<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" onclick="return confirm(\'', $txt['pm_labels_delete'], '\');" class="button_submit" />
-		</div>';
-
-	echo '
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-	</form>
-	<br class="clear" />
-	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '" style="margin-top: 1ex;">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_label_add_new'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">
-					<dt>
-						<strong><label for="add_label">', $txt['pm_label_name'], '</label>:</strong>
-					</dt>
-					<dd>
-						<input type="text" id="add_label" name="label" value="" size="30" maxlength="30" class="input_text" />
-					</dd>
-				</dl>
-				<hr class="hrcolor" />
-				<input type="submit" name="add" value="', $txt['pm_label_add_new'], '" class="button_submit" />
-				<br class="clear_right" />
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-	</form><br />';
-}
-
-// Template for reporting a personal message.
-function template_report_message()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=report;l=', $context['current_label_id'], '" method="post" accept-charset="', $context['character_set'], '">
-		<input type="hidden" name="pmsg" value="', $context['pm_id'], '" />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
-		</div>
-		<div class="description">
-			', $txt['pm_report_desc'], '
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">';
-
-	// If there is more than one admin on the forum, allow the user to choose the one they want to direct to.
-	// @todo Why?
-	if ($context['admin_count'] > 1)
-	{
-		echo '
-					<dt>
-						<strong>', $txt['pm_report_admins'], ':</strong>
-					</dt>
-					<dd>
-						<select name="id_admin">
-							<option value="0">', $txt['pm_report_all_admins'], '</option>';
-		foreach ($context['admins'] as $id => $name)
-			echo '
-							<option value="', $id, '">', $name, '</option>';
-		echo '
-						</select>
-					</dd>';
-	}
-
-	echo '
-					<dt>
-						<strong>', $txt['pm_report_reason'], ':</strong>
-					</dt>
-					<dd>
-						<textarea name="reason" rows="4" cols="70" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 80%; min-width: 80%' : 'width: 80%') . ';"></textarea>
-					</dd>
-				</dl>
-				<div class="righttext">
-					<input type="submit" name="report" value="', $txt['pm_report_message'], '" class="button_submit" />
-				</div>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-	</form>';
-}
-
-// Little template just to say "Yep, it's been submitted"
-function template_report_message_complete()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['pm_report_done'], '</p>
-				<a href="', $scripturl, '?action=pm;l=', $context['current_label_id'], '">', $txt['pm_report_return'], '</a>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-}
-
-// Manage rules.
-function template_rules()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=manrules" method="post" accept-charset="', $context['character_set'], '" name="manRules" id="manrules">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_manage_rules'], '</h3>
-		</div>
-		<div class="description">
-			', $txt['pm_manage_rules_desc'], '
-		</div>
-		<table width="100%" class="table_grid">
-		<thead>
-			<tr class="catbg">
-				<th class="lefttext first_th">
-					', $txt['pm_rule_title'], '
-				</th>
-				<th width="4%" class="centertext last_th">';
-
-	if (!empty($context['rules']))
-		echo '
-					<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />';
-
-	echo '
-				</th>
-			</tr>
-		</thead>
-		<tbody>';
-
-	if (empty($context['rules']))
-		echo '
-			<tr class="windowbg2">
-				<td colspan="2" align="center">
-					', $txt['pm_rules_none'], '
-				</td>
-			</tr>';
-
-	$alternate = false;
-	foreach ($context['rules'] as $rule)
-	{
-		echo '
-			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
-				<td>
-					<a href="', $scripturl, '?action=pm;sa=manrules;add;rid=', $rule['id'], '">', $rule['name'], '</a>
-				</td>
-				<td width="4%" align="center">
-					<input type="checkbox" name="delrule[', $rule['id'], ']" class="input_check" />
-				</td>
-			</tr>';
-		$alternate = !$alternate;
-	}
-
-	echo '
-		</tbody>
-		</table>
-		<div class="righttext">
-			<a class="button_link" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>';
-
-	if (!empty($context['rules']))
-		echo '
-			[<a href="', $scripturl, '?action=pm;sa=manrules;apply;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['pm_js_apply_rules_confirm'], '\');">', $txt['pm_apply_rules'], '</a>]';
-
-	if (!empty($context['rules']))
-		echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" onclick="return confirm(\'', $txt['pm_js_delete_rule_confirm'], '\');" class="button_submit smalltext" />';
-
-	echo '
-		</div>
-	</form>';
-
-}
-
-// Template for adding/editing a rule.
-function template_add_rule()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-			var criteriaNum = 0;
-			var actionNum = 0;
-			var groups = new Array()
-			var labels = new Array()';
-
-	foreach ($context['groups'] as $id => $title)
-		echo '
-			groups[', $id, '] = "', addslashes($title), '";';
-
-	foreach ($context['labels'] as $label)
-		if ($label['id'] != -1)
-			echo '
-			labels[', ($label['id'] + 1), '] = "', addslashes($label['name']), '";';
-
-	echo '
-			function addCriteriaOption()
-			{
-				if (criteriaNum == 0)
-				{
-					for (var i = 0; i < document.forms.addrule.elements.length; i++)
-						if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
-							criteriaNum++;
-				}
-				criteriaNum++
-
-				setOuterHTML(document.getElementById("criteriaAddHere"), \'<br /><select name="ruletype[\' + criteriaNum + \']" id="ruletype\' + criteriaNum + \'" onchange="updateRuleDef(\' + criteriaNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_criteria_pick']), ':<\' + \'/option><option value="mid">', addslashes($txt['pm_rule_mid']), '<\' + \'/option><option value="gid">', addslashes($txt['pm_rule_gid']), '<\' + \'/option><option value="sub">', addslashes($txt['pm_rule_sub']), '<\' + \'/option><option value="msg">', addslashes($txt['pm_rule_msg']), '<\' + \'/option><option value="bud">', addslashes($txt['pm_rule_bud']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="defdiv\' + criteriaNum + \'" style="display: none;"><input type="text" name="ruledef[\' + criteriaNum + \']" id="ruledef\' + criteriaNum + \'" onkeyup="rebuildRuleDesc();" value="" class="input_text" /><\' + \'/span><span id="defseldiv\' + criteriaNum + \'" style="display: none;"><select name="ruledefgroup[\' + criteriaNum + \']" id="ruledefgroup\' + criteriaNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_group']), '<\' + \'/option>';
-
-	foreach ($context['groups'] as $id => $group)
-		echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
-
-	echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\');
-			}
-
-			function addActionOption()
-			{
-				if (actionNum == 0)
-				{
-					for (var i = 0; i < document.forms.addrule.elements.length; i++)
-						if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
-							actionNum++;
-				}
-				actionNum++
-
-				setOuterHTML(document.getElementById("actionAddHere"), \'<br /><select name="acttype[\' + actionNum + \']" id="acttype\' + actionNum + \'" onchange="updateActionDef(\' + actionNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_action']), ':<\' + \'/option><option value="lab">', addslashes($txt['pm_rule_label']), '<\' + \'/option><option value="del">', addslashes($txt['pm_rule_delete']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="labdiv\' + actionNum + \'" style="display: none;"><select name="labdef[\' + actionNum + \']" id="labdef\' + actionNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_label']), '<\' + \'/option>';
-
-	foreach ($context['labels'] as $label)
-		if ($label['id'] != -1)
-			echo '<option value="', ($label['id'] + 1), '">', addslashes($label['name']), '<\' + \'/option>';
-
-	echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\');
-			}
-
-			// Rebuild the rule description!
-			function rebuildRuleDesc()
-			{
-				// Start with nothing.
-				var text = "";
-				var joinText = "";
-				var actionText = "";
-				var hadBuddy = false;
-				var foundCriteria = false;
-				var foundAction = false;
-				var curNum, curVal, curDef;
-
-				for (var i = 0; i < document.forms.addrule.elements.length; i++)
-				{
-					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
-					{
-						if (foundCriteria)
-							joinText = document.getElementById("logic").value == \'and\' ? ', JavaScriptEscape(' ' . $txt['pm_readable_and'] . ' '), ' : ', JavaScriptEscape(' ' . $txt['pm_readable_or'] . ' '), ';
-						else
-							joinText = \'\';
-						foundCriteria = true;
-
-						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
-						curVal = document.forms.addrule.elements[i].value;
-						if (curVal == "gid")
-							curDef = document.getElementById("ruledefgroup" + curNum).value.php_htmlspecialchars();
-						else if (curVal != "bud")
-							curDef = document.getElementById("ruledef" + curNum).value.php_htmlspecialchars();
-						else
-							curDef = "";
-
-						// What type of test is this?
-						if (curVal == "mid" && curDef)
-							text += joinText + ', JavaScriptEscape($txt['pm_readable_member']), '.replace("{MEMBER}", curDef);
-						else if (curVal == "gid" && curDef && groups[curDef])
-							text += joinText + ', JavaScriptEscape($txt['pm_readable_group']), '.replace("{GROUP}", groups[curDef]);
-						else if (curVal == "sub" && curDef)
-							text += joinText + ', JavaScriptEscape($txt['pm_readable_subject']), '.replace("{SUBJECT}", curDef);
-						else if (curVal == "msg" && curDef)
-							text += joinText + ', JavaScriptEscape($txt['pm_readable_body']), '.replace("{BODY}", curDef);
-						else if (curVal == "bud" && !hadBuddy)
-						{
-							text += joinText + ', JavaScriptEscape($txt['pm_readable_buddy']), ';
-							hadBuddy = true;
-						}
-					}
-					if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
-					{
-						if (foundAction)
-							joinText = ', JavaScriptEscape(' ' . $txt['pm_readable_and'] . ' '), ';
-						else
-							joinText = "";
-						foundAction = true;
-
-						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
-						curVal = document.forms.addrule.elements[i].value;
-						if (curVal == "lab")
-							curDef = document.getElementById("labdef" + curNum).value.php_htmlspecialchars();
-						else
-							curDef = "";
-
-						// Now pick the actions.
-						if (curVal == "lab" && curDef && labels[curDef])
-							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_label']), '.replace("{LABEL}", labels[curDef]);
-						else if (curVal == "del")
-							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_delete']), ';
-					}
-				}
-
-				// If still nothing make it default!
-				if (text == "" || !foundCriteria)
-					text = "', $txt['pm_rule_not_defined'], '";
-				else
-				{
-					if (actionText != "")
-						text += ', JavaScriptEscape(' ' . $txt['pm_readable_then'] . ' '), ' + actionText;
-					text = ', JavaScriptEscape($txt['pm_readable_start']), ' + text + ', JavaScriptEscape($txt['pm_readable_end']), ';
-				}
-
-				// Set the actual HTML!
-				setInnerHTML(document.getElementById("ruletext"), text);
-			}
-	// ]]></script>';
-
-	echo '
-	<form action="', $scripturl, '?action=pm;sa=manrules;save;rid=', $context['rid'], '" method="post" accept-charset="', $context['character_set'], '" name="addrule" id="addrule" class="flow_hidden">
-		<div class="cat_bar">
-			<h3 class="catbg">', $context['rid'] == 0 ? $txt['pm_add_rule'] : $txt['pm_edit_rule'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="addrules">
-					<dt class="floatleft">
-						<strong>', $txt['pm_rule_name'], ':</strong><br />
-						<span class="smalltext">', $txt['pm_rule_name_desc'], '</span>
-					</dt>
-					<dd class="floatleft">
-						<input type="text" name="rule_name" value="', empty($context['rule']['name']) ? $txt['pm_rule_name_default'] : $context['rule']['name'], '" size="50" class="input_text" />
-					</dd>
-				</dl>
-				<fieldset>
-					<legend>', $txt['pm_rule_criteria'], '</legend>';
-
-	// Add a dummy criteria to allow expansion for none js users.
-	$context['rule']['criteria'][] = array('t' => '', 'v' => '');
-
-	// For each criteria print it out.
-	$isFirst = true;
-	foreach ($context['rule']['criteria'] as $k => $criteria)
-	{
-		if (!$isFirst && $criteria['t'] == '')
-			echo '<div id="removeonjs1">';
-		elseif (!$isFirst)
-			echo '<br />';
-
-		echo '
-					<select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();">
-						<option value="">', $txt['pm_rule_criteria_pick'], ':</option>
-						<option value="mid" ', $criteria['t'] == 'mid' ? 'selected="selected"' : '', '>', $txt['pm_rule_mid'], '</option>
-						<option value="gid" ', $criteria['t'] == 'gid' ? 'selected="selected"' : '', '>', $txt['pm_rule_gid'], '</option>
-						<option value="sub" ', $criteria['t'] == 'sub' ? 'selected="selected"' : '', '>', $txt['pm_rule_sub'], '</option>
-						<option value="msg" ', $criteria['t'] == 'msg' ? 'selected="selected"' : '', '>', $txt['pm_rule_msg'], '</option>
-						<option value="bud" ', $criteria['t'] == 'bud' ? 'selected="selected"' : '', '>', $txt['pm_rule_bud'], '</option>
-					</select>
-					<span id="defdiv', $k, '" ', !in_array($criteria['t'], array('gid', 'bud')) ? '' : 'style="display: none;"', '>
-						<input type="text" name="ruledef[', $k, ']" id="ruledef', $k, '" onkeyup="rebuildRuleDesc();" value="', in_array($criteria['t'], array('mid', 'sub', 'msg')) ? $criteria['v'] : '', '" class="input_text" />
-					</span>
-					<span id="defseldiv', $k, '" ', $criteria['t'] == 'gid' ? '' : 'style="display: none;"', '>
-						<select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();">
-							<option value="">', $txt['pm_rule_sel_group'], '</option>';
-
-		foreach ($context['groups'] as $id => $group)
-			echo '
-							<option value="', $id, '" ', $criteria['t'] == 'gid' && $criteria['v'] == $id ? 'selected="selected"' : '', '>', $group, '</option>';
-		echo '
-						</select>
-					</span>';
-
-		// If this is the dummy we add a means to hide for non js users.
-		if ($isFirst)
-			$isFirst = false;
-		elseif ($criteria['t'] == '')
-			echo '</div>';
-	}
-
-	echo '
-					<span id="criteriaAddHere"></span><br />
-					<a href="#" onclick="addCriteriaOption(); return false;" id="addonjs1" style="display: none;">(', $txt['pm_rule_criteria_add'], ')</a>
-					<br /><br />
-					', $txt['pm_rule_logic'], ':
-					<select name="rule_logic" id="logic" onchange="rebuildRuleDesc();">
-						<option value="and" ', $context['rule']['logic'] == 'and' ? 'selected="selected"' : '', '>', $txt['pm_rule_logic_and'], '</option>
-						<option value="or" ', $context['rule']['logic'] == 'or' ? 'selected="selected"' : '', '>', $txt['pm_rule_logic_or'], '</option>
-					</select>
-				</fieldset>
-				<fieldset>
-					<legend>', $txt['pm_rule_actions'], '</legend>';
-
-	// As with criteria - add a dummy action for "expansion".
-	$context['rule']['actions'][] = array('t' => '', 'v' => '');
-
-	// Print each action.
-	$isFirst = true;
-	foreach ($context['rule']['actions'] as $k => $action)
-	{
-		if (!$isFirst && $action['t'] == '')
-			echo '<div id="removeonjs2">';
-		elseif (!$isFirst)
-			echo '<br />';
-
-		echo '
-					<select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();">
-						<option value="">', $txt['pm_rule_sel_action'] , ':</option>
-						<option value="lab" ', $action['t'] == 'lab' ? 'selected="selected"' : '', '>', $txt['pm_rule_label'] , '</option>
-						<option value="del" ', $action['t'] == 'del' ? 'selected="selected"' : '', '>', $txt['pm_rule_delete'] , '</option>
-					</select>
-					<span id="labdiv', $k, '">
-						<select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();">
-							<option value="">', $txt['pm_rule_sel_label'], '</option>';
-		foreach ($context['labels'] as $label)
-			if ($label['id'] != -1)
-				echo '
-							<option value="', ($label['id'] + 1), '" ', $action['t'] == 'lab' && $action['v'] == $label['id'] ? 'selected="selected"' : '', '>', $label['name'], '</option>';
-
-		echo '
-						</select>
-					</span>';
-
-		if ($isFirst)
-			$isFirst = false;
-		elseif ($action['t'] == '')
-			echo '
-				</div>';
-	}
-
-	echo '
-					<span id="actionAddHere"></span><br />
-					<a href="#" onclick="addActionOption(); return false;" id="addonjs2" style="display: none;">(', $txt['pm_rule_add_action'], ')</a>
-				</fieldset>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div><br class="clear" />
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['pm_rule_description'], '</h3>
-		</div>
-		<div class="information">
-			<div id="ruletext">', $txt['pm_rule_js_disabled'], '</div>
-		</div>
-		<div class="righttext">
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="submit" name="save" value="', $txt['pm_rule_save'], '" class="button_submit" />
-		</div>
-	</form>';
-
-	// Now setup all the bits!
-		echo '
-	<script type="text/javascript"><!-- // --><![CDATA[';
-
-	foreach ($context['rule']['criteria'] as $k => $c)
-		echo '
-			updateRuleDef(', $k, ');';
-
-	foreach ($context['rule']['actions'] as $k => $c)
-		echo '
-			updateActionDef(', $k, ');';
-
-	echo '
-			rebuildRuleDesc();';
-
-	// If this isn't a new rule and we have JS enabled remove the JS compatibility stuff.
-	if ($context['rid'])
-		echo '
-			document.getElementById("removeonjs1").style.display = "none";
-			document.getElementById("removeonjs2").style.display = "none";';
-
-	echo '
-			document.getElementById("addonjs1").style.display = "";
-			document.getElementById("addonjs2").style.display = "";';
-
-	echo '
-		// ]]></script>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+
+// This is the main sidebar for the personal messages section.
+function template_pm_above()
+{
+	global $context, $settings, $options, $txt;
+
+	echo '
+	<div id="personal_messages">';
+
+	// Show the capacity bar, if available.
+	if (!empty($context['limit_bar']))
+		echo '
+		<div class="title_bar">
+			<h3 class="titlebg">
+				<span class="floatleft">', $txt['pm_capacity'], ':</span>
+				<span class="floatleft capacity_bar">
+					<span class="', $context['limit_bar']['percent'] > 85 ? 'full' : ($context['limit_bar']['percent'] > 40 ? 'filled' : 'empty'), '" style="width: ', $context['limit_bar']['percent'] / 10, 'em;"></span>
+				</span>
+				<span class="floatright', $context['limit_bar']['percent'] > 90 ? ' alert' : '', '">', $context['limit_bar']['text'], '</span>
+			</h3>
+		</div>';
+
+	// Message sent? Show a small indication.
+	if (isset($context['pm_sent']))
+		echo '
+		<div class="infobox">
+			', $txt['pm_sent'], '
+		</div>';
+}
+
+// Just the end of the index bar, nothing special.
+function template_pm_below()
+{
+	global $context, $settings, $options;
+
+	echo '
+	</div>';
+}
+
+function template_folder()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// The every helpful javascript!
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var allLabels = {};
+		var currentLabels = {};
+		function loadLabelChoices()
+		{
+			var listing = document.forms.pmFolder.elements;
+			var theSelect = document.forms.pmFolder.pm_action;
+			var add, remove, toAdd = {length: 0}, toRemove = {length: 0};
+
+			if (theSelect.childNodes.length == 0)
+				return;
+
+			// This is done this way for internationalization reasons.
+			if (!(\'-1\' in allLabels))
+			{
+				for (var o = 0; o < theSelect.options.length; o++)
+					if (theSelect.options[o].value.substr(0, 4) == "rem_")
+						allLabels[theSelect.options[o].value.substr(4)] = theSelect.options[o].text;
+			}
+
+			for (var i = 0; i < listing.length; i++)
+			{
+				if (listing[i].name != "pms[]" || !listing[i].checked)
+					continue;
+
+				var alreadyThere = [], x;
+				for (x in currentLabels[listing[i].value])
+				{
+					if (!(x in toRemove))
+					{
+						toRemove[x] = allLabels[x];
+						toRemove.length++;
+					}
+					alreadyThere[x] = allLabels[x];
+				}
+
+				for (x in allLabels)
+				{
+					if (!(x in alreadyThere))
+					{
+						toAdd[x] = allLabels[x];
+						toAdd.length++;
+					}
+				}
+			}
+
+			while (theSelect.options.length > 2)
+				theSelect.options[2] = null;
+
+			if (toAdd.length != 0)
+			{
+				theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_apply'], '", "");
+				setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_apply'], '");
+				theSelect.options[theSelect.options.length - 1].disabled = true;
+
+				for (i in toAdd)
+				{
+					if (i != "length")
+						theSelect.options[theSelect.options.length] = new Option(toAdd[i], "add_" + i);
+				}
+			}
+
+			if (toRemove.length != 0)
+			{
+				theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_remove'], '", "");
+				setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_remove'], '");
+				theSelect.options[theSelect.options.length - 1].disabled = true;
+
+				for (i in toRemove)
+				{
+					if (i != "length")
+						theSelect.options[theSelect.options.length] = new Option(toRemove[i], "rem_" + i);
+				}
+			}
+		}
+	// ]]></script>';
+
+	echo '
+<form class="flow_hidden" action="', $scripturl, '?action=pm;sa=pmactions;', $context['display_mode'] == 2 ? 'conversation;' : '', 'f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '" method="post" accept-charset="', $context['character_set'], '" name="pmFolder">';
+
+	// If we are not in single display mode show the subjects on the top!
+	if ($context['display_mode'] != 1)
+	{
+		template_subject_list();
+		echo '<div class="clear_right"><br /></div>';
+	}
+
+	// Got some messages to display?
+	if ($context['get_pmessage']('message', true))
+	{
+		// Show the helpful titlebar - generally.
+		if ($context['display_mode'] != 1)
+			echo '
+				<div class="cat_bar">
+					<h3 class="catbg">
+						<span id="author">', $txt['author'], '</span>
+						<span id="topic_title">', $txt[$context['display_mode'] == 0 ? 'messages' : 'conversation'], '</span>
+					</h3>
+				</div>';
+
+		// Show a few buttons if we are in conversation mode and outputting the first message.
+		if ($context['display_mode'] == 2)
+		{
+			// Show the conversation buttons.
+			echo '
+					<div class="pagesection">';
+
+			template_button_strip($context['conversation_buttons'], 'right');
+
+			echo '
+					</div>';
+		}
+
+		while ($message = $context['get_pmessage']('message'))
+		{
+			$window_class = $message['alternate'] == 0 ? 'windowbg' : 'windowbg2';
+
+			echo '
+	<div class="', $window_class, ' clear">
+		<div class="poster">
+			<a id="msg', $message['id'], '"></a>
+			<h4>';
+
+			// Show online and offline buttons?
+			if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
+				echo '
+				<img src="', $message['member']['online']['image_href'], '" alt="', $message['member']['online']['text'], '" />';
+
+			echo '
+				', $message['member']['link'], '
+			</h4>
+			<ul class="reset smalltext" id="msg_', $message['id'], '_extra_info">';
+
+			// Show the member's custom title, if they have one.
+			if (isset($message['member']['title']) && $message['member']['title'] != '')
+				echo '
+				<li class="title">', $message['member']['title'], '</li>';
+
+			// Show the member's primary group (like 'Administrator') if they have one.
+			if (isset($message['member']['group']) && $message['member']['group'] != '')
+				echo '
+				<li class="membergroup">', $message['member']['group'], '</li>';
+
+			// Don't show these things for guests.
+			if (!$message['member']['is_guest'])
+			{
+				// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
+				if ((empty($settings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
+					echo '
+				<li class="postgroup">', $message['member']['post_group'], '</li>';
+				echo '
+				<li class="icons">', $message['member']['group_icons'], '</li>';
+
+				// Show avatars, images, etc.?
+				if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
+					echo '
+				<li class="avatar">
+					<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">
+						', $message['member']['avatar']['image'], '
+					</a>
+				</li>';
+
+				// Show how many posts they have made.
+				if (!isset($context['disabled_fields']['posts']))
+					echo '
+				<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
+
+				// Is karma display enabled?  Total or +/-?
+				if ($modSettings['karmaMode'] == '1')
+					echo '
+				<li class="karma">', $modSettings['karmaLabel'], ' ', $message['member']['karma']['good'] - $message['member']['karma']['bad'], '</li>';
+				elseif ($modSettings['karmaMode'] == '2')
+					echo '
+				<li class="karma">', $modSettings['karmaLabel'], ' +', $message['member']['karma']['good'], '/-', $message['member']['karma']['bad'], '</li>';
+
+				// Is this user allowed to modify this member's karma?
+				if ($message['member']['karma']['allow'])
+					echo '
+				<li class="karma_allow">
+					<a href="', $scripturl, '?action=modifykarma;sa=applaud;uid=', $message['member']['id'], ';f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pm=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $modSettings['karmaApplaudLabel'], '</a> <a href="', $scripturl, '?action=modifykarma;sa=smite;uid=', $message['member']['id'], ';f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pm=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $modSettings['karmaSmiteLabel'], '</a>
+				</li>';
+
+				// Show the member's gender icon?
+				if (!empty($settings['show_gender']) && $message['member']['gender']['image'] != '' && !isset($context['disabled_fields']['gender']))
+					echo '
+				<li class="gender">', $txt['gender'], ': ', $message['member']['gender']['image'], '</li>';
+
+				// Show their personal text?
+				if (!empty($settings['show_blurb']) && $message['member']['blurb'] != '')
+					echo '
+				<li class="blurb">', $message['member']['blurb'], '</li>';
+
+				// Any custom fields to show as icons?
+				if (!empty($message['member']['custom_fields']))
+				{
+					$shown = false;
+					foreach ($message['member']['custom_fields'] as $custom)
+					{
+						if ($custom['placement'] != 1 || empty($custom['value']))
+							continue;
+						if (empty($shown))
+						{
+							$shown = true;
+							echo '
+				<li class="im_icons">
+					<ul>';
+						}
+						echo '
+						<li>', $custom['value'], '</li>';
+					}
+					if ($shown)
+					echo '
+					</ul>
+				</li>';
+				}
+
+				// This shows the popular messaging icons.
+				if ($message['member']['has_messenger'] && $message['member']['can_view_profile'])
+					echo '
+				<li class="im_icons">
+					<ul>', !isset($context['disabled_fields']['icq']) && !empty($message['member']['icq']['link']) ? '
+						<li>' . $message['member']['icq']['link'] . '</li>' : '', !isset($context['disabled_fields']['msn']) && !empty($message['member']['msn']['link']) ? '
+						<li>' . $message['member']['msn']['link'] . '</li>' : '', !isset($context['disabled_fields']['aim']) && !empty($message['member']['aim']['link']) ? '
+						<li>' . $message['member']['aim']['link'] . '</li>' : '', !isset($context['disabled_fields']['yim']) && !empty($message['member']['yim']['link']) ? '
+						<li>' . $message['member']['yim']['link'] . '</li>' : '', '
+					</ul>
+				</li>';
+
+				// Show the profile, website, email address, and personal message buttons.
+				if ($message['member']['show_profile_buttons'])
+				{
+					echo '
+				<li class="profile">
+					<ul>';
+
+					// Show the profile button
+					if ($message['member']['can_view_profile'])
+						echo '
+						<li><a href="', $message['member']['href'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="' . $txt['view_profile'] . '" title="' . $txt['view_profile'] . '" />' : $txt['view_profile']), '</a></li>';
+
+					// Don't show an icon if they haven't specified a website.
+					if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website']))
+						echo '
+						<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/www_sm.png" alt="' . $message['member']['website']['title'] . '" />' : $txt['www']), '</a></li>';
+
+					// Don't show the email address if they want it hidden.
+					if (in_array($message['member']['show_email'], array('yes', 'yes_permission_override', 'no_through_forum')) && $context['can_send_email'])
+						echo '
+						<li><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $message['member']['id'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . '" />' : $txt['email']), '</a></li>';
+
+					// Since we know this person isn't a guest, you *can* message them.
+					if ($context['can_send_pm'])
+						echo '
+						<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . '.png" alt="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '" />' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
+
+					echo '
+					</ul>
+				</li>';
+				}
+
+				// Any custom fields for standard placement?
+				if (!empty($message['member']['custom_fields']))
+				{
+					foreach ($message['member']['custom_fields'] as $custom)
+						if (empty($custom['placement']) || empty($custom['value']))
+							echo '
+				<li class="custom">', $custom['title'], ': ', $custom['value'], '</li>';
+				}
+
+				// Are we showing the warning status?
+				if ($message['member']['can_see_warning'])
+				echo '
+				<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<img src="', $settings['images_url'], '/warning_', $message['member']['warning_status'], '.png" alt="', $txt['user_warn_' . $message['member']['warning_status']], '" />', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
+			}
+
+			// Done with the information about the poster... on to the post itself.
+			echo '
+			</ul>
+		</div>
+		<div class="postarea">
+			<div class="flow_hidden">
+				<div class="keyinfo">
+					<h5 id="subject_', $message['id'], '">
+						', $message['subject'], '
+					</h5>';
+
+			// Show who the message was sent to.
+			echo '
+					<span class="smalltext">&#171; <strong> ', $txt['sent_to'], ':</strong> ';
+
+			// People it was sent directly to....
+			if (!empty($message['recipients']['to']))
+				echo implode(', ', $message['recipients']['to']);
+			// Otherwise, we're just going to say "some people"...
+			elseif ($context['folder'] != 'sent')
+				echo '(', $txt['pm_undisclosed_recipients'], ')';
+
+			echo '
+						<strong> ', $txt['on'], ':</strong> ', $message['time'], ' &#187;
+					</span>';
+
+			// If we're in the sent items, show who it was sent to besides the "To:" people.
+			if (!empty($message['recipients']['bcc']))
+				echo '
+					<br /><span class="smalltext">&#171; <strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' &#187;</span>';
+
+			if (!empty($message['is_replied_to']))
+				echo '
+					<br /><span class="smalltext">&#171; ', $txt['pm_is_replied_to'], ' &#187;</span>';
+
+			echo '
+				</div>
+				<ul class="reset smalltext quickbuttons">';
+
+			// Show reply buttons if you have the permission to send PMs.
+			if ($context['can_send_pm'])
+			{
+				// You can't really reply if the member is gone.
+				if (!$message['member']['is_guest'])
+				{
+					// Is there than more than one recipient you can reply to?
+					if ($message['number_recipients'] > 1 && $context['display_mode'] != 2)
+						echo '
+					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=all" class="reply_all_button">', $txt['reply_to_all'], '</a></li>';
+
+					echo '
+					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '" class="reply_button">', $txt['reply'], '</a></li>
+					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote', $context['folder'] == 'sent' ? '' : ';u=' . $message['member']['id'], '" class="quote_button">', $txt['quote'], '</a></li>';
+				}
+				// This is for "forwarding" - even if the member is gone.
+				else
+					echo '
+					<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote" class="quote_button">', $txt['reply_quote'], '</a></li>';
+			}
+			echo '
+					<li><a href="', $scripturl, '?action=pm;sa=pmactions;pm_actions[', $message['id'], ']=delete;f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', addslashes($txt['remove_message']), '?\');" class="remove_button">', $txt['delete'], '</a></li>';
+
+			if (empty($context['display_mode']))
+				echo '
+					<li class="inline_mod_check"><input type="checkbox" name="pms[]" id="deletedisplay', $message['id'], '" value="', $message['id'], '" onclick="document.getElementById(\'deletelisting', $message['id'], '\').checked = this.checked;" class="input_check" /></li>';
+
+			echo '
+				</ul>
+			</div>
+			<div class="post">
+				<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
+				<div class="smalltext reportlinks">
+					', (!empty($modSettings['enableReportPM']) && $context['folder'] != 'sent' ? '<div class="righttext"><a href="' . $scripturl . '?action=pm;sa=report;l=' . $context['current_label_id'] . ';pmsg=' . $message['id'] . '">' . $txt['pm_report_to_admin'] . '</a></div>' : '');
+
+			echo '
+				</div>';
+
+			// Are there any custom profile fields for above the signature?
+			if (!empty($message['member']['custom_fields']))
+			{
+				$shown = false;
+				foreach ($message['member']['custom_fields'] as $custom)
+				{
+					if ($custom['placement'] != 2 || empty($custom['value']))
+						continue;
+					if (!$shown)
+					{
+						$shown = true;
+						echo '
+				<div class="custom_fields_above_signature">
+					<ul class="reset nolist">';
+					}
+					echo '
+						<li>', $custom['value'], '</li>';
+				}
+				if ($shown)
+					echo '
+					</ul>
+				</div>';
+			}
+
+			// Show the member's signature?
+			if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
+				echo '
+				<div class="signature">', $message['member']['signature'], '</div>';
+
+			// Add an extra line at the bottom if we have labels enabled.
+			if ($context['folder'] != 'sent' && !empty($context['currently_using_labels']) && $context['display_mode'] != 2)
+			{
+				echo '
+				<div class="labels righttext">';
+				// Add the label drop down box.
+				if (!empty($context['currently_using_labels']))
+				{
+					echo '
+					<select name="pm_actions[', $message['id'], ']" onchange="if (this.options[this.selectedIndex].value) form.submit();">
+						<option value="">', $txt['pm_msg_label_title'], ':</option>
+						<option value="" disabled="disabled">---------------</option>';
+
+					// Are there any labels which can be added to this?
+					if (!$message['fully_labeled'])
+					{
+						echo '
+						<option value="" disabled="disabled">', $txt['pm_msg_label_apply'], ':</option>';
+						foreach ($context['labels'] as $label)
+							if (!isset($message['labels'][$label['id']]))
+								echo '
+							<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
+					}
+					// ... and are there any that can be removed?
+					if (!empty($message['labels']) && (count($message['labels']) > 1 || !isset($message['labels'][-1])))
+					{
+						echo '
+						<option value="" disabled="disabled">', $txt['pm_msg_label_remove'], ':</option>';
+						foreach ($message['labels'] as $label)
+							echo '
+							<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
+					}
+					echo '
+					</select>
+					<noscript>
+						<input type="submit" value="', $txt['pm_apply'], '" class="button_submit" />
+					</noscript>';
+				}
+				echo '
+				</div>';
+			}
+
+			echo '
+			</div>
+			<br class="clear" />
+		</div>
+		<div class="moderatorbar">
+		</div>
+	</div>';
+		}
+
+		if (empty($context['display_mode']))
+			echo '
+
+	<div class="pagesection">
+		<div class="floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
+		<div class="floatright"><input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" style="font-weight: normal;" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button_submit" /></div>
+	</div>';
+
+		// Show a few buttons if we are in conversation mode and outputting the first message.
+		elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons']))
+		{
+			echo '
+
+	<div class="pagesection">';
+
+			template_button_strip($context['conversation_buttons'], 'right');
+
+			echo '
+	</div>';
+		}
+
+		echo '
+		<br />';
+	}
+
+	// Individual messages = buttom list!
+	if ($context['display_mode'] == 1)
+	{
+		template_subject_list();
+		echo '<br />';
+	}
+
+	echo '
+	<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+</form>';
+}
+
+// Just list all the personal message subjects - to make templates easier.
+function template_subject_list()
+{
+	global $context, $options, $settings, $modSettings, $txt, $scripturl;
+
+	echo '
+	<table width="100%" class="table_grid">
+	<thead>
+		<tr class="catbg">
+			<th align="center" width="4%" class="first_th">
+				<a href="', $scripturl, '?action=pm;view;f=', $context['folder'], ';start=', $context['start'], ';sort=', $context['sort_by'], ($context['sort_direction'] == 'up' ? '' : ';desc'), ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), '"><img src="', $settings['images_url'], '/im_switch.png" alt="', $txt['pm_change_view'], '" title="', $txt['pm_change_view'], '" width="16" height="16" /></a>
+			</th>
+			<th class="lefttext" width="22%">
+				<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=date', $context['sort_by'] == 'date' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['date'], $context['sort_by'] == 'date' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a>
+			</th>
+			<th class="lefttext" width="46%">
+				<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a>
+			</th>
+			<th class="lefttext">
+				<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', ($context['from_or_to'] == 'from' ? $txt['from'] : $txt['to']), $context['sort_by'] == 'name' ? ' <img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a>
+			</th>
+			<th align="center" width="4%" class="last_th">
+				<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />
+			</th>
+		</tr>
+	</thead>
+	<tbody>';
+	if (!$context['show_delete'])
+		echo '
+		<tr class="windowbg2">
+			<td colspan="5">', $txt['msg_alert_none'], '</td>
+		</tr>';
+	$next_alternate = false;
+
+	while ($message = $context['get_pmessage']('subject'))
+	{
+		echo '
+		<tr class="', $next_alternate ? 'windowbg' : 'windowbg2', '">
+			<td align="center" width="4%">
+			<script type="text/javascript"><!-- // --><![CDATA[
+				currentLabels[', $message['id'], '] = {';
+
+		if (!empty($message['labels']))
+		{
+			$first = true;
+			foreach ($message['labels'] as $label)
+			{
+				echo $first ? '' : ',', '
+				"', $label['id'], '": "', $label['name'], '"';
+				$first = false;
+			}
+		}
+
+		echo '
+				};
+			// ]]></script>
+				', $message['is_replied_to'] ? '<img src="' . $settings['images_url'] . '/icons/pm_replied.png" style="margin-right: 4px;" alt="' . $txt['pm_replied'] . '" />' : '<img src="' . $settings['images_url'] . '/icons/pm_read.png" style="margin-right: 4px;" alt="' . $txt['pm_read'] . '" />', '</td>
+			<td>', $message['time'], '</td>
+			<td>', ($context['display_mode'] != 0 && $context['current_pm'] == $message['id'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*" />' : ''), '<a href="', ($context['display_mode'] == 0 || $context['current_pm'] == $message['id'] ? '' : ($scripturl . '?action=pm;pmid=' . $message['id'] . ';kstart;f=' . $context['folder'] . ';start=' . $context['start'] . ';sort=' . $context['sort_by'] . ($context['sort_direction'] == 'up' ? ';' : ';desc') . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''))), '#msg', $message['id'], '">', $message['subject'], $message['is_unread'] ? '&nbsp;<span class="new_posts">' . $txt['new'] . '</span>' : '', '</a></td>
+			<td>', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '</td>
+			<td align="center" width="4%"><input type="checkbox" name="pms[]" id="deletelisting', $message['id'], '" value="', $message['id'], '"', $message['is_selected'] ? ' checked="checked"' : '', ' onclick="if (document.getElementById(\'deletedisplay', $message['id'], '\')) document.getElementById(\'deletedisplay', $message['id'], '\').checked = this.checked;" class="input_check" /></td>
+		</tr>';
+			$next_alternate = !$next_alternate;
+	}
+
+	echo '
+	</tbody>
+	</table>
+	<div class="pagesection">
+		<div class="floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>
+		<div class="floatright">&nbsp;';
+
+	if ($context['show_delete'])
+	{
+		if (!empty($context['currently_using_labels']) && $context['folder'] != 'sent')
+		{
+			echo '
+				<select name="pm_action" onchange="if (this.options[this.selectedIndex].value) this.form.submit();" onfocus="loadLabelChoices();">
+					<option value="">', $txt['pm_sel_label_title'], ':</option>
+					<option value="" disabled="disabled">---------------</option>';
+
+			echo '
+					<option value="" disabled="disabled">', $txt['pm_msg_label_apply'], ':</option>';
+					
+			foreach ($context['labels'] as $label)
+			{
+				if ($label['id'] != $context['current_label_id'])
+					echo '
+					<option value="add_', $label['id'], '">&nbsp;', $label['name'], '</option>';
+			}
+			
+			echo '
+					<option value="" disabled="disabled">', $txt['pm_msg_label_remove'], ':</option>';
+					
+			foreach ($context['labels'] as $label)
+			{
+				echo '
+					<option value="rem_', $label['id'], '">&nbsp;', $label['name'], '</option>';
+			}
+			
+			echo '
+				</select>
+				<noscript>
+					<input type="submit" value="', $txt['pm_apply'], '" class="button_submit" />
+				</noscript>';
+		}
+
+		echo '
+				<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button_submit" />';
+	}
+
+	echo '
+				</div>
+	</div>';
+}
+
+function template_search()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_search_title'], '</h3>
+		</div>';
+
+	if (!empty($context['search_errors']))
+	{
+		echo '
+		<div class="errorbox">
+			', implode('<br />', $context['search_errors']['messages']), '
+		</div>';
+	}
+
+	if ($context['simple_search'])
+	{
+		echo '
+		<fieldset id="simple_search">
+			<div class="roundframe">
+				<div id="search_term_input">
+					<strong>', $txt['pm_search_text'], ':</strong>
+					<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40" class="input_text" />
+					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit" />
+				</div>
+				<a href="', $scripturl, '?action=pm;sa=search;advanced" onclick="this.href += \';search=\' + escape(document.forms.searchform.search.value);">', $txt['pm_search_advanced'], '</a>
+				<input type="hidden" name="advanced" value="0" />
+			</div>
+		</fieldset>';
+	}
+
+	// Advanced search!
+	else
+	{
+		echo '
+		<fieldset id="advanced_search">
+			<div class="roundframe">
+				<input type="hidden" name="advanced" value="1" />
+				<span class="enhanced">
+					<strong>', $txt['pm_search_text'], ':</strong>
+					<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40" class="input_text" />
+					<script type="text/javascript"><!-- // --><![CDATA[
+						createEventListener(window);
+						window.addEventListener("load", initSearch, false);
+					// ]]></script>
+					<select name="searchtype">
+						<option value="1"', empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['pm_search_match_all'], '</option>
+						<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['pm_search_match_any'], '</option>
+					</select>
+				</span>
+				<dl id="search_options">
+					<dt>', $txt['pm_search_user'], ':</dt>
+					<dd><input type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40" class="input_text" /></dd>
+					<dt>', $txt['pm_search_order'], ':</dt>
+					<dd>
+						<select name="sort">
+							<option value="relevance|desc">', $txt['pm_search_orderby_relevant_first'], '</option>
+							<option value="id_pm|desc">', $txt['pm_search_orderby_recent_first'], '</option>
+							<option value="id_pm|asc">', $txt['pm_search_orderby_old_first'], '</option>
+						</select>
+					</dd>
+					<dt class="options">', $txt['pm_search_options'], ':</dt>
+					<dd class="options">
+						<label for="show_complete"><input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['pm_search_show_complete'], '</label><br />
+						<label for="subject_only"><input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['pm_search_subject_only'], '</label>
+					</dd>
+					<dt class="between">', $txt['pm_search_post_age'], ':</dt>
+					<dd>', $txt['pm_search_between'], ' <input type="text" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="5" class="input_text" />&nbsp;', $txt['pm_search_between_and'], '&nbsp;<input type="text" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="5" class="input_text" /> ', $txt['pm_search_between_days'], '</dd>
+				</dl>';
+		if (!$context['currently_using_labels'])
+			echo '
+				<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit floatright" />';
+			echo '
+				<br class="clear_right" />
+			</div>
+		</fieldset>';
+
+		// Do we have some labels setup? If so offer to search by them!
+		if ($context['currently_using_labels'])
+		{
+			echo '
+		<fieldset class="labels">
+			<div class="roundframe">
+				<div class="title_bar">
+					<h4 class="titlebg">
+						<img id="advanced_panel_toggle" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/', empty($context['show_advanced_options']) ? 'collapse' : 'expand', '.png"  alt="*" /><a href="#" id="advanced_panel_link">', $txt['pm_search_choose_label'], '</a>
+					</h4>
+				</div>
+				<div id="advanced_panel_div">
+				<ul id="searchLabelsExpand" class="reset" >';
+
+			foreach ($context['search_labels'] as $label)
+				echo '
+					<li>
+						<label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '" ', $label['checked'] ? 'checked="checked"' : '', ' class="input_check" />
+						', $label['name'], '</label>
+					</li>';
+
+			echo '
+				</ul>
+				</div>
+				<p>
+					<span class="floatleft"><input type="checkbox" name="all" id="check_all" value="" ', $context['check_all'] ? 'checked="checked"' : '', ' onclick="invertAll(this, this.form, \'searchlabel\');" class="input_check" /><em> <label for="check_all">', $txt['check_all'], '</label></em></span>
+					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit" />
+				</p><br class="clear_right" />
+			</div>
+		</fieldset>';
+
+			// Some javascript for the advanced toggling
+			echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var oAdvancedPanelToggle = new smc_Toggle({
+				bToggleEnabled: true,
+				bCurrentlyCollapsed: ', empty($context['show_advanced_options']) ? 'true' : 'false', ',
+				aSwappableContainers: [
+					\'advanced_panel_div\'
+				],
+				aSwapImages: [
+					{
+						sId: \'advanced_panel_toggle\',
+						srcExpanded: smf_images_url + \'/collapse.png\',
+						altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
+						srcCollapsed: smf_images_url + \'/expand.png\',
+						altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
+					}
+				],
+				aSwapLinks: [
+					{
+						sId: \'advanced_panel_link\',
+						msgExpanded: ', JavaScriptEscape($txt['pm_search_choose_label']), ',
+						msgCollapsed: ', JavaScriptEscape($txt['pm_search_choose_label']), '
+					}
+				],
+				oThemeOptions: {
+					bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
+					sOptionName: \'admin_preferences\',
+					sSessionVar: smf_session_var,
+					sSessionId: smf_session_id,
+					sThemeId: \'1\'
+				}
+			});
+		// ]]></script>';
+		}
+	}
+
+	echo '
+	</form>';
+}
+
+function template_search_results()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_search_results'], '</h3>
+		</div>
+		<div class="pagesection">
+			<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
+		</div>';
+
+	// complete results ?
+	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
+		echo '
+	<table width="100%" class="table_grid">
+	<thead>
+		<tr class="catbg">
+			<th class="lefttext first_th" width="30%">', $txt['date'], '</th>
+			<th class="lefttext" width="50%">', $txt['subject'], '</th>
+			<th class="lefttext last_th" width="20%">', $txt['from'], '</th>
+		</tr>
+	</thead>
+	<tbody>';
+
+	$alternate = true;
+	// Print each message out...
+	foreach ($context['personal_messages'] as $message)
+	{
+		// We showing it all?
+		if (!empty($context['search_params']['show_complete']))
+		{
+			echo '
+			<div class="title_bar">
+				<h3 class="titlebg">
+					<span class="floatright">', $txt['search_on'], ': ', $message['time'], '</span>
+					<span class="floatleft">', $message['counter'], '&nbsp;&nbsp;<a href="', $message['href'], '">', $message['subject'], '</a></span>
+				</h3>
+			</div>
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['from'], ': ', $message['member']['link'], ', ', $txt['to'], ': ';
+
+				// Show the recipients.
+				// @todo This doesn't deal with the sent item searching quite right for bcc.
+				if (!empty($message['recipients']['to']))
+					echo implode(', ', $message['recipients']['to']);
+				// Otherwise, we're just going to say "some people"...
+				elseif ($context['folder'] != 'sent')
+					echo '(', $txt['pm_undisclosed_recipients'], ')';
+
+					echo '
+				</h3>
+			</div>
+			<div class="windowbg', $alternate ? '2': '', '">
+				<div class="content">
+					', $message['body'], '
+					<p class="pm_reply righttext">';
+
+				if ($context['can_send_pm'])
+				{
+					$quote_button = create_button('quote.png', 'reply_quote', 'reply_quote', 'class="centericon"');
+					$reply_button = create_button('im_reply.png', 'reply', 'reply', 'class="centericon"');
+					// You can only reply if they are not a guest...
+					if (!$message['member']['is_guest'])
+						echo '
+								<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=', $context['folder'] == 'sent' ? '' : $message['member']['id'], '">', $quote_button , '</a>', $context['menu_separator'], '
+								<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '">', $reply_button , '</a> ', $context['menu_separator'];
+					// This is for "forwarding" - even if the member is gone.
+					else
+						echo '
+								<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote">', $quote_button , '</a>', $context['menu_separator'];
+				}
+
+				echo '
+					</p>
+				</div>
+			</div>';
+		}
+		// Otherwise just a simple list!
+		else
+		{
+			// @todo No context at all of the search?
+			echo '
+			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" valign="top">
+				<td>', $message['time'], '</td>
+				<td>', $message['link'], '</td>
+				<td>', $message['member']['link'], '</td>
+			</tr>';
+		}
+
+		$alternate = !$alternate;
+	}
+
+	// Finish off the page...
+	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
+		echo '
+		</tbody>
+		</table>';
+
+	// No results?
+	if (empty($context['personal_messages']))
+		echo '
+		<div class="windowbg">
+			<div class="content">
+				<p class="centertext">', $txt['pm_search_none_found'], '</p>
+			</div>
+		</div>';
+
+	echo '
+		<div class="pagesection">
+			<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
+		</div>';
+
+}
+
+function template_send()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// Show which messages were sent successfully and which failed.
+	if (!empty($context['send_log']))
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['pm_send_report'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">';
+				if (!empty($context['send_log']['sent']))
+					foreach ($context['send_log']['sent'] as $log_entry)
+						echo '<span class="error">', $log_entry, '</span><br />';
+				if (!empty($context['send_log']['failed']))
+					foreach ($context['send_log']['failed'] as $log_entry)
+						echo '<span class="error">', $log_entry, '</span><br />';
+				echo '
+				</div>
+			</div>
+			<br />';
+	}
+
+	// Show the preview of the personal message.
+	echo '
+		<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<div class="post" id="preview_body">
+						', empty($context['preview_message']) ? '<br />' : $context['preview_message'], '
+					</div>
+				</div>
+			</div>
+		</div><br />';
+
+	// Main message editing box.
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/im_newmsg.png" class="icon" alt="', $txt['new_message'], '" title="', $txt['new_message'], '" />&nbsp;', $txt['new_message'], '
+			</h3>
+		</div>';
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=send2" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'message\']);">
+		<div>
+			<div class="roundframe"><br class="clear" />';
+
+	// If there were errors for sending the PM, show them.
+	echo '
+				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
+					<dl>
+						<dt>
+							<strong id="error_serious">', $txt['error_while_submitting'] , '</strong>
+						</dt>
+						<dd class="error" id="error_list">
+							', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
+						</dd>
+					</dl>
+				</div>';
+
+	echo '
+				<dl id="post_header">';
+
+	// To and bcc. Include a button to search for members.
+	echo '
+					<dt>
+						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), ' id="caption_to">', $txt['pm_to'], ':</span>
+					</dt>';
+
+	// Autosuggest will be added by the JavaScript later on.
+	echo '
+					<dd id="pm_to" class="clear_right">
+						<input type="text" name="to" id="to_control" value="', $context['to_value'], '" tabindex="', $context['tabindex']++, '" size="40" style="width: 130px;" class="input_text" />';
+
+	// A link to add BCC, only visible with JavaScript enabled.
+	echo '
+						<span class="smalltext" id="bcc_link_container" style="display: none;"></span>';
+
+	// A div that'll contain the items found by the autosuggest.
+	echo '
+						<div id="to_item_list_container"></div>';
+
+	echo '
+					</dd>';
+
+	// This BCC row will be hidden by default if JavaScript is enabled.
+	echo '
+					<dt  class="clear_left" id="bcc_div">
+						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), ' id="caption_bbc">', $txt['pm_bcc'], ':</span>
+					</dt>
+					<dd id="bcc_div2">
+						<input type="text" name="bcc" id="bcc_control" value="', $context['bcc_value'], '" tabindex="', $context['tabindex']++, '" size="40" style="width: 130px;" class="input_text" />
+						<div id="bcc_item_list_container"></div>
+					</dd>';
+
+	// The subject of the PM.
+	echo '
+					<dt class="clear_left">
+						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
+					</dt>
+					<dd id="pm_subject">
+						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="60" maxlength="60"',isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', '/>
+					</dd>
+				</dl><hr class="clear" />';
+
+	// Showing BBC?
+	if ($context['show_bbc'])
+	{
+		echo '
+				<div id="bbcBox_message"></div>';
+	}
+
+	// What about smileys?
+	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
+		echo '
+				<div id="smileyBox_message"></div>';
+
+	// Show BBC buttons, smileys and textbox.
+	echo '
+				', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
+
+	// Require an image to be typed to save spamming?
+	if ($context['require_verification'])
+	{
+		echo '
+				<div class="post_verification">
+					<strong>', $txt['pm_visual_verification_label'], ':</strong>
+					', template_control_verification($context['visual_verification_id'], 'all'), '
+				</div>';
+	}
+
+	// Send, Preview, spellcheck buttons.
+	echo '
+				<p>
+					<label for="outbox"><input type="checkbox" name="outbox" id="outbox" value="1" tabindex="', $context['tabindex']++, '"', $context['copy_to_outbox'] ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['pm_save_outbox'], '</label>
+				</p>
+				<hr class="hrcolor" />
+				<span id="shortcuts" class="smalltext">
+					', isBrowser('is_firefox') ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '
+				</span>
+				<span id="post_confirm_strip" class="righttext">
+					', template_control_richedit_buttons($context['post_box_name']), '
+				</span>
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
+				<input type="hidden" name="replied_to" value="', !empty($context['quoted_message']['id']) ? $context['quoted_message']['id'] : 0, '" />
+				<input type="hidden" name="pm_head" value="', !empty($context['quoted_message']['pm_head']) ? $context['quoted_message']['pm_head'] : 0, '" />
+				<input type="hidden" name="f" value="', isset($context['folder']) ? $context['folder'] : '', '" />
+				<input type="hidden" name="l" value="', isset($context['current_label_id']) ? $context['current_label_id'] : -1, '" />
+				<br class="clear_right" />
+			</div>
+		</div>
+	</form>';
+
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[';
+	// The functions used to preview a personal message without loading a new page.
+	echo '
+			var txt_preview_title = "', $txt['preview_title'], '";
+			var txt_preview_fetch = "', $txt['preview_fetch'], '";
+			function previewPost()
+			{';
+	if (isBrowser('is_firefox'))
+		echo '
+				// Firefox doesn\'t render <marquee> that have been put it using javascript
+				if (document.forms.postmodify.elements[', JavaScriptEscape($context['post_box_name']), '].value.indexOf(\'[move]\') != -1)
+				{
+					return submitThisOnce(document.forms.postmodify);
+				}';
+	echo '
+				if (window.XMLHttpRequest)
+				{
+					// Opera didn\'t support setRequestHeader() before 8.01.
+					// @todo Remove support for old browsers
+					if (\'opera\' in window)
+					{
+						var test = new XMLHttpRequest();
+						if (!(\'setRequestHeader\' in test))
+							return submitThisOnce(document.forms.postmodify);
+					}
+					// @todo Currently not sending poll options and option checkboxes.
+					var x = new Array();
+					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'to\', \'bcc\'];
+					var numericFields = [\'recipient_to[]\', \'recipient_bcc[]\'];
+					var checkboxFields = [\'outbox\'];
+
+					for (var i = 0, n = textFields.length; i < n; i++)
+						if (textFields[i] in document.forms.postmodify)
+						{
+							// Handle the WYSIWYG editor.
+							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
+								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
+							else
+								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
+						}
+					for (var i = 0, n = numericFields.length; i < n; i++)
+						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
+							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
+					for (var i = 0, n = checkboxFields.length; i < n; i++)
+						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
+							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
+
+					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=pm;sa=send2;preview;xml\', x.join(\'&\'), onDocSent);
+
+					document.getElementById(\'preview_section\').style.display = \'\';
+					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
+					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
+
+					return false;
+				}
+				else
+					return submitThisOnce(document.forms.postmodify);
+			}
+			function onDocSent(XMLDoc)
+			{
+				if (!XMLDoc)
+				{
+					document.forms.postmodify.preview.onclick = new function ()
+					{
+						return true;
+					}
+					document.forms.postmodify.preview.click();
+				}
+
+				// Show the preview section.
+				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
+				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
+
+				var bodyText = \'\';
+				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
+					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
+
+				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
+				document.getElementById(\'preview_body\').className = \'post\';
+
+				// Show a list of errors (if any).
+				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
+				var errorList = new Array();
+				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
+					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
+				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
+				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
+
+				// Adjust the color of captions if the given data is erroneous.
+				var captions = errors.getElementsByTagName(\'caption\');
+				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
+					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
+						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
+
+				if (errors.getElementsByTagName(\'post_error\').length == 1)
+					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
+				else if (document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
+				{
+					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
+						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
+					else
+						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
+				}
+				location.hash = \'#\' + \'preview_section\';
+			}';
+
+	echo '
+		// ]]></script>';
+
+	// Show the message you're replying to.
+	if ($context['reply'])
+		echo '
+	<br />
+	<br />
+	<div class="cat_bar">
+		<h3 class="catbg">', $txt['subject'], ': ', $context['quoted_message']['subject'], '</h3>
+	</div>
+	<div class="windowbg2">
+		<div class="content">
+			<div class="clear">
+				<span class="smalltext floatright">', $txt['on'], ': ', $context['quoted_message']['time'], '</span>
+				<strong>', $txt['from'], ': ', $context['quoted_message']['member']['name'], '</strong>
+			</div><hr />
+			', $context['quoted_message']['body'], '
+		</div>
+	</div><br class="clear" />';
+
+	echo '
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/PersonalMessage.js?alp21"></script>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var oPersonalMessageSend = new smf_PersonalMessageSend({
+				sSelf: \'oPersonalMessageSend\',
+				sSessionId: smf_session_id,
+				sSessionVar: smf_session_var,
+				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+				sToControlId: \'to_control\',
+				aToRecipients: [';
+	foreach ($context['recipients']['to'] as $i => $member)
+		echo '
+					{
+						sItemId: ', JavaScriptEscape($member['id']), ',
+						sItemName: ', JavaScriptEscape($member['name']), '
+					}', $i == count($context['recipients']['to']) - 1 ? '' : ',';
+
+	echo '
+				],
+				aBccRecipients: [';
+	foreach ($context['recipients']['bcc'] as $i => $member)
+		echo '
+					{
+						sItemId: ', JavaScriptEscape($member['id']), ',
+						sItemName: ', JavaScriptEscape($member['name']), '
+					}', $i == count($context['recipients']['bcc']) - 1 ? '' : ',';
+
+	echo '
+				],
+				sBccControlId: \'bcc_control\',
+				sBccDivId: \'bcc_div\',
+				sBccDivId2: \'bcc_div2\',
+				sBccLinkId: \'bcc_link\',
+				sBccLinkContainerId: \'bcc_link_container\',
+				bBccShowByDefault: ', empty($context['recipients']['bcc']) && empty($context['bcc_value']) ? 'false' : 'true', ',
+				sShowBccLinkTemplate: ', JavaScriptEscape('
+					<a href="#" id="bcc_link">' . $txt['make_bcc'] . '</a> <a href="' . $scripturl . '?action=helpadmin;help=pm_bcc" onclick="return reqWin(this.href);">(?)</a>'
+				), '
+			});
+		';
+
+	echo '
+		// ]]></script>';
+}
+
+// This template asks the user whether they wish to empty out their folder/messages.
+function template_ask_delete()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', ($context['delete_all'] ? $txt['delete_message'] : $txt['delete_all']), '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $txt['delete_all_confirm'], '</p><br />
+				<strong><a href="', $scripturl, '?action=pm;sa=removeall2;f=', $context['folder'], ';', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="javascript:history.go(-1);">', $txt['no'], '</a></strong>
+			</div>
+		</div>';
+}
+
+// This template asks the user what messages they want to prune.
+function template_prune()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=prune" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['pm_prune_warning'], '\');">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_prune'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $txt['pm_prune_desc1'], ' <input type="text" name="age" size="3" value="14" class="input_text" /> ', $txt['pm_prune_desc2'], '</p>
+				<div class="righttext">
+					<input type="submit" value="', $txt['delete'], '" class="button_submit" />
+				</div>
+				<br class="clear" />
+			</div>
+		</div>
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+	</form>';
+}
+
+// Here we allow the user to setup labels, remove labels and change rules for labels (i.e, do quite a bit)
+function template_labels()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_manage_labels'], '</h3>
+		</div>
+		<div class="description">
+			', $txt['pm_labels_desc'], '
+		</div>
+		<table width="100%" class="table_grid">
+		<thead>
+			<tr class="catbg">
+				<th class="lefttext first_th">
+					', $txt['pm_label_name'], '
+				</th>
+				<th class="centertext last_th" width="4%">';
+
+	if (count($context['labels']) > 2)
+		echo '
+					<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />';
+
+	echo '
+				</th>
+			</tr>
+		</thead>
+		<tbody>';
+	if (count($context['labels']) < 2)
+		echo '
+			<tr class="windowbg2">
+				<td colspan="2" align="center">', $txt['pm_labels_no_exist'], '</td>
+			</tr>';
+	else
+	{
+		$alternate = true;
+		foreach ($context['labels'] as $label)
+		{
+			if ($label['id'] == -1)
+				continue;
+
+				echo '
+			<tr class="', $alternate ? 'windowbg2' : 'windowbg', '">
+				<td>
+					<input type="text" name="label_name[', $label['id'], ']" value="', $label['name'], '" size="30" maxlength="30" class="input_text" />
+				</td>
+				<td width="4%" align="center"><input type="checkbox" class="input_check" name="delete_label[', $label['id'], ']" /></td>
+			</tr>';
+
+			$alternate = !$alternate;
+		}
+	}
+	echo '
+		</tbody>
+		</table>';
+
+	if (!count($context['labels']) < 2)
+		echo '
+		<div class="padding righttext">
+			<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" />
+			<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" onclick="return confirm(\'', $txt['pm_labels_delete'], '\');" class="button_submit" />
+		</div>';
+
+	echo '
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+	</form>
+	<br class="clear" />
+	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '" style="margin-top: 1ex;">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_label_add_new'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">
+					<dt>
+						<strong><label for="add_label">', $txt['pm_label_name'], '</label>:</strong>
+					</dt>
+					<dd>
+						<input type="text" id="add_label" name="label" value="" size="30" maxlength="30" class="input_text" />
+					</dd>
+				</dl>
+				<hr class="hrcolor" />
+				<input type="submit" name="add" value="', $txt['pm_label_add_new'], '" class="button_submit" />
+				<br class="clear_right" />
+			</div>
+		</div>
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+	</form><br />';
+}
+
+// Template for reporting a personal message.
+function template_report_message()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=report;l=', $context['current_label_id'], '" method="post" accept-charset="', $context['character_set'], '">
+		<input type="hidden" name="pmsg" value="', $context['pm_id'], '" />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
+		</div>
+		<div class="description">
+			', $txt['pm_report_desc'], '
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">';
+
+	// If there is more than one admin on the forum, allow the user to choose the one they want to direct to.
+	// @todo Why?
+	if ($context['admin_count'] > 1)
+	{
+		echo '
+					<dt>
+						<strong>', $txt['pm_report_admins'], ':</strong>
+					</dt>
+					<dd>
+						<select name="id_admin">
+							<option value="0">', $txt['pm_report_all_admins'], '</option>';
+		foreach ($context['admins'] as $id => $name)
+			echo '
+							<option value="', $id, '">', $name, '</option>';
+		echo '
+						</select>
+					</dd>';
+	}
+
+	echo '
+					<dt>
+						<strong>', $txt['pm_report_reason'], ':</strong>
+					</dt>
+					<dd>
+						<textarea name="reason" rows="4" cols="70" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 80%; min-width: 80%' : 'width: 80%') . ';"></textarea>
+					</dd>
+				</dl>
+				<div class="righttext">
+					<input type="submit" name="report" value="', $txt['pm_report_message'], '" class="button_submit" />
+				</div>
+			</div>
+		</div>
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+	</form>';
+}
+
+// Little template just to say "Yep, it's been submitted"
+function template_report_message_complete()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $txt['pm_report_done'], '</p>
+				<a href="', $scripturl, '?action=pm;l=', $context['current_label_id'], '">', $txt['pm_report_return'], '</a>
+			</div>
+		</div>';
+}
+
+// Manage rules.
+function template_rules()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=manrules" method="post" accept-charset="', $context['character_set'], '" name="manRules" id="manrules">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_manage_rules'], '</h3>
+		</div>
+		<div class="description">
+			', $txt['pm_manage_rules_desc'], '
+		</div>
+		<table width="100%" class="table_grid">
+		<thead>
+			<tr class="catbg">
+				<th class="lefttext first_th">
+					', $txt['pm_rule_title'], '
+				</th>
+				<th width="4%" class="centertext last_th">';
+
+	if (!empty($context['rules']))
+		echo '
+					<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />';
+
+	echo '
+				</th>
+			</tr>
+		</thead>
+		<tbody>';
+
+	if (empty($context['rules']))
+		echo '
+			<tr class="windowbg2">
+				<td colspan="2" align="center">
+					', $txt['pm_rules_none'], '
+				</td>
+			</tr>';
+
+	$alternate = false;
+	foreach ($context['rules'] as $rule)
+	{
+		echo '
+			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+				<td>
+					<a href="', $scripturl, '?action=pm;sa=manrules;add;rid=', $rule['id'], '">', $rule['name'], '</a>
+				</td>
+				<td width="4%" align="center">
+					<input type="checkbox" name="delrule[', $rule['id'], ']" class="input_check" />
+				</td>
+			</tr>';
+		$alternate = !$alternate;
+	}
+
+	echo '
+		</tbody>
+		</table>
+		<div class="righttext">
+			<a class="button_link" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>';
+
+	if (!empty($context['rules']))
+		echo '
+			[<a href="', $scripturl, '?action=pm;sa=manrules;apply;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['pm_js_apply_rules_confirm'], '\');">', $txt['pm_apply_rules'], '</a>]';
+
+	if (!empty($context['rules']))
+		echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" onclick="return confirm(\'', $txt['pm_js_delete_rule_confirm'], '\');" class="button_submit smalltext" />';
+
+	echo '
+		</div>
+	</form>';
+
+}
+
+// Template for adding/editing a rule.
+function template_add_rule()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+			var criteriaNum = 0;
+			var actionNum = 0;
+			var groups = new Array()
+			var labels = new Array()';
+
+	foreach ($context['groups'] as $id => $title)
+		echo '
+			groups[', $id, '] = "', addslashes($title), '";';
+
+	foreach ($context['labels'] as $label)
+		if ($label['id'] != -1)
+			echo '
+			labels[', ($label['id'] + 1), '] = "', addslashes($label['name']), '";';
+
+	echo '
+			function addCriteriaOption()
+			{
+				if (criteriaNum == 0)
+				{
+					for (var i = 0; i < document.forms.addrule.elements.length; i++)
+						if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
+							criteriaNum++;
+				}
+				criteriaNum++
+
+				setOuterHTML(document.getElementById("criteriaAddHere"), \'<br /><select name="ruletype[\' + criteriaNum + \']" id="ruletype\' + criteriaNum + \'" onchange="updateRuleDef(\' + criteriaNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_criteria_pick']), ':<\' + \'/option><option value="mid">', addslashes($txt['pm_rule_mid']), '<\' + \'/option><option value="gid">', addslashes($txt['pm_rule_gid']), '<\' + \'/option><option value="sub">', addslashes($txt['pm_rule_sub']), '<\' + \'/option><option value="msg">', addslashes($txt['pm_rule_msg']), '<\' + \'/option><option value="bud">', addslashes($txt['pm_rule_bud']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="defdiv\' + criteriaNum + \'" style="display: none;"><input type="text" name="ruledef[\' + criteriaNum + \']" id="ruledef\' + criteriaNum + \'" onkeyup="rebuildRuleDesc();" value="" class="input_text" /><\' + \'/span><span id="defseldiv\' + criteriaNum + \'" style="display: none;"><select name="ruledefgroup[\' + criteriaNum + \']" id="ruledefgroup\' + criteriaNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_group']), '<\' + \'/option>';
+
+	foreach ($context['groups'] as $id => $group)
+		echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
+
+	echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\');
+			}
+
+			function addActionOption()
+			{
+				if (actionNum == 0)
+				{
+					for (var i = 0; i < document.forms.addrule.elements.length; i++)
+						if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
+							actionNum++;
+				}
+				actionNum++
+
+				setOuterHTML(document.getElementById("actionAddHere"), \'<br /><select name="acttype[\' + actionNum + \']" id="acttype\' + actionNum + \'" onchange="updateActionDef(\' + actionNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_action']), ':<\' + \'/option><option value="lab">', addslashes($txt['pm_rule_label']), '<\' + \'/option><option value="del">', addslashes($txt['pm_rule_delete']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="labdiv\' + actionNum + \'" style="display: none;"><select name="labdef[\' + actionNum + \']" id="labdef\' + actionNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_label']), '<\' + \'/option>';
+
+	foreach ($context['labels'] as $label)
+		if ($label['id'] != -1)
+			echo '<option value="', ($label['id'] + 1), '">', addslashes($label['name']), '<\' + \'/option>';
+
+	echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\');
+			}
+
+			// Rebuild the rule description!
+			function rebuildRuleDesc()
+			{
+				// Start with nothing.
+				var text = "";
+				var joinText = "";
+				var actionText = "";
+				var hadBuddy = false;
+				var foundCriteria = false;
+				var foundAction = false;
+				var curNum, curVal, curDef;
+
+				for (var i = 0; i < document.forms.addrule.elements.length; i++)
+				{
+					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
+					{
+						if (foundCriteria)
+							joinText = document.getElementById("logic").value == \'and\' ? ', JavaScriptEscape(' ' . $txt['pm_readable_and'] . ' '), ' : ', JavaScriptEscape(' ' . $txt['pm_readable_or'] . ' '), ';
+						else
+							joinText = \'\';
+						foundCriteria = true;
+
+						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
+						curVal = document.forms.addrule.elements[i].value;
+						if (curVal == "gid")
+							curDef = document.getElementById("ruledefgroup" + curNum).value.php_htmlspecialchars();
+						else if (curVal != "bud")
+							curDef = document.getElementById("ruledef" + curNum).value.php_htmlspecialchars();
+						else
+							curDef = "";
+
+						// What type of test is this?
+						if (curVal == "mid" && curDef)
+							text += joinText + ', JavaScriptEscape($txt['pm_readable_member']), '.replace("{MEMBER}", curDef);
+						else if (curVal == "gid" && curDef && groups[curDef])
+							text += joinText + ', JavaScriptEscape($txt['pm_readable_group']), '.replace("{GROUP}", groups[curDef]);
+						else if (curVal == "sub" && curDef)
+							text += joinText + ', JavaScriptEscape($txt['pm_readable_subject']), '.replace("{SUBJECT}", curDef);
+						else if (curVal == "msg" && curDef)
+							text += joinText + ', JavaScriptEscape($txt['pm_readable_body']), '.replace("{BODY}", curDef);
+						else if (curVal == "bud" && !hadBuddy)
+						{
+							text += joinText + ', JavaScriptEscape($txt['pm_readable_buddy']), ';
+							hadBuddy = true;
+						}
+					}
+					if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
+					{
+						if (foundAction)
+							joinText = ', JavaScriptEscape(' ' . $txt['pm_readable_and'] . ' '), ';
+						else
+							joinText = "";
+						foundAction = true;
+
+						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
+						curVal = document.forms.addrule.elements[i].value;
+						if (curVal == "lab")
+							curDef = document.getElementById("labdef" + curNum).value.php_htmlspecialchars();
+						else
+							curDef = "";
+
+						// Now pick the actions.
+						if (curVal == "lab" && curDef && labels[curDef])
+							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_label']), '.replace("{LABEL}", labels[curDef]);
+						else if (curVal == "del")
+							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_delete']), ';
+					}
+				}
+
+				// If still nothing make it default!
+				if (text == "" || !foundCriteria)
+					text = "', $txt['pm_rule_not_defined'], '";
+				else
+				{
+					if (actionText != "")
+						text += ', JavaScriptEscape(' ' . $txt['pm_readable_then'] . ' '), ' + actionText;
+					text = ', JavaScriptEscape($txt['pm_readable_start']), ' + text + ', JavaScriptEscape($txt['pm_readable_end']), ';
+				}
+
+				// Set the actual HTML!
+				setInnerHTML(document.getElementById("ruletext"), text);
+			}
+	// ]]></script>';
+
+	echo '
+	<form action="', $scripturl, '?action=pm;sa=manrules;save;rid=', $context['rid'], '" method="post" accept-charset="', $context['character_set'], '" name="addrule" id="addrule" class="flow_hidden">
+		<div class="cat_bar">
+			<h3 class="catbg">', $context['rid'] == 0 ? $txt['pm_add_rule'] : $txt['pm_edit_rule'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="addrules">
+					<dt class="floatleft">
+						<strong>', $txt['pm_rule_name'], ':</strong><br />
+						<span class="smalltext">', $txt['pm_rule_name_desc'], '</span>
+					</dt>
+					<dd class="floatleft">
+						<input type="text" name="rule_name" value="', empty($context['rule']['name']) ? $txt['pm_rule_name_default'] : $context['rule']['name'], '" size="50" class="input_text" />
+					</dd>
+				</dl>
+				<fieldset>
+					<legend>', $txt['pm_rule_criteria'], '</legend>';
+
+	// Add a dummy criteria to allow expansion for none js users.
+	$context['rule']['criteria'][] = array('t' => '', 'v' => '');
+
+	// For each criteria print it out.
+	$isFirst = true;
+	foreach ($context['rule']['criteria'] as $k => $criteria)
+	{
+		if (!$isFirst && $criteria['t'] == '')
+			echo '<div id="removeonjs1">';
+		elseif (!$isFirst)
+			echo '<br />';
+
+		echo '
+					<select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();">
+						<option value="">', $txt['pm_rule_criteria_pick'], ':</option>
+						<option value="mid" ', $criteria['t'] == 'mid' ? 'selected="selected"' : '', '>', $txt['pm_rule_mid'], '</option>
+						<option value="gid" ', $criteria['t'] == 'gid' ? 'selected="selected"' : '', '>', $txt['pm_rule_gid'], '</option>
+						<option value="sub" ', $criteria['t'] == 'sub' ? 'selected="selected"' : '', '>', $txt['pm_rule_sub'], '</option>
+						<option value="msg" ', $criteria['t'] == 'msg' ? 'selected="selected"' : '', '>', $txt['pm_rule_msg'], '</option>
+						<option value="bud" ', $criteria['t'] == 'bud' ? 'selected="selected"' : '', '>', $txt['pm_rule_bud'], '</option>
+					</select>
+					<span id="defdiv', $k, '" ', !in_array($criteria['t'], array('gid', 'bud')) ? '' : 'style="display: none;"', '>
+						<input type="text" name="ruledef[', $k, ']" id="ruledef', $k, '" onkeyup="rebuildRuleDesc();" value="', in_array($criteria['t'], array('mid', 'sub', 'msg')) ? $criteria['v'] : '', '" class="input_text" />
+					</span>
+					<span id="defseldiv', $k, '" ', $criteria['t'] == 'gid' ? '' : 'style="display: none;"', '>
+						<select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();">
+							<option value="">', $txt['pm_rule_sel_group'], '</option>';
+
+		foreach ($context['groups'] as $id => $group)
+			echo '
+							<option value="', $id, '" ', $criteria['t'] == 'gid' && $criteria['v'] == $id ? 'selected="selected"' : '', '>', $group, '</option>';
+		echo '
+						</select>
+					</span>';
+
+		// If this is the dummy we add a means to hide for non js users.
+		if ($isFirst)
+			$isFirst = false;
+		elseif ($criteria['t'] == '')
+			echo '</div>';
+	}
+
+	echo '
+					<span id="criteriaAddHere"></span><br />
+					<a href="#" onclick="addCriteriaOption(); return false;" id="addonjs1" style="display: none;">(', $txt['pm_rule_criteria_add'], ')</a>
+					<br /><br />
+					', $txt['pm_rule_logic'], ':
+					<select name="rule_logic" id="logic" onchange="rebuildRuleDesc();">
+						<option value="and" ', $context['rule']['logic'] == 'and' ? 'selected="selected"' : '', '>', $txt['pm_rule_logic_and'], '</option>
+						<option value="or" ', $context['rule']['logic'] == 'or' ? 'selected="selected"' : '', '>', $txt['pm_rule_logic_or'], '</option>
+					</select>
+				</fieldset>
+				<fieldset>
+					<legend>', $txt['pm_rule_actions'], '</legend>';
+
+	// As with criteria - add a dummy action for "expansion".
+	$context['rule']['actions'][] = array('t' => '', 'v' => '');
+
+	// Print each action.
+	$isFirst = true;
+	foreach ($context['rule']['actions'] as $k => $action)
+	{
+		if (!$isFirst && $action['t'] == '')
+			echo '<div id="removeonjs2">';
+		elseif (!$isFirst)
+			echo '<br />';
+
+		echo '
+					<select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();">
+						<option value="">', $txt['pm_rule_sel_action'] , ':</option>
+						<option value="lab" ', $action['t'] == 'lab' ? 'selected="selected"' : '', '>', $txt['pm_rule_label'] , '</option>
+						<option value="del" ', $action['t'] == 'del' ? 'selected="selected"' : '', '>', $txt['pm_rule_delete'] , '</option>
+					</select>
+					<span id="labdiv', $k, '">
+						<select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();">
+							<option value="">', $txt['pm_rule_sel_label'], '</option>';
+		foreach ($context['labels'] as $label)
+			if ($label['id'] != -1)
+				echo '
+							<option value="', ($label['id'] + 1), '" ', $action['t'] == 'lab' && $action['v'] == $label['id'] ? 'selected="selected"' : '', '>', $label['name'], '</option>';
+
+		echo '
+						</select>
+					</span>';
+
+		if ($isFirst)
+			$isFirst = false;
+		elseif ($action['t'] == '')
+			echo '
+				</div>';
+	}
+
+	echo '
+					<span id="actionAddHere"></span><br />
+					<a href="#" onclick="addActionOption(); return false;" id="addonjs2" style="display: none;">(', $txt['pm_rule_add_action'], ')</a>
+				</fieldset>
+			</div>
+		</div><br class="clear" />
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['pm_rule_description'], '</h3>
+		</div>
+		<div class="information">
+			<div id="ruletext">', $txt['pm_rule_js_disabled'], '</div>
+		</div>
+		<div class="righttext">
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="submit" name="save" value="', $txt['pm_rule_save'], '" class="button_submit" />
+		</div>
+	</form>';
+
+	// Now setup all the bits!
+		echo '
+	<script type="text/javascript"><!-- // --><![CDATA[';
+
+	foreach ($context['rule']['criteria'] as $k => $c)
+		echo '
+			updateRuleDef(', $k, ');';
+
+	foreach ($context['rule']['actions'] as $k => $c)
+		echo '
+			updateActionDef(', $k, ');';
+
+	echo '
+			rebuildRuleDesc();';
+
+	// If this isn't a new rule and we have JS enabled remove the JS compatibility stuff.
+	if ($context['rid'])
+		echo '
+			document.getElementById("removeonjs1").style.display = "none";
+			document.getElementById("removeonjs2").style.display = "none";';
+
+	echo '
+			document.getElementById("addonjs1").style.display = "";
+			document.getElementById("addonjs2").style.display = "";';
+
+	echo '
+		// ]]></script>';
+}
+
 ?>

+ 156 - 158
Themes/default/Poll.template.php

@@ -1,159 +1,157 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Some javascript for adding more options.
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var pollOptionNum = 0;
-			var pollOptionId = ', $context['last_choice_id'], ';
-
-			function addPollOption()
-			{
-				if (pollOptionNum == 0)
-				{
-					for (var i = 0; i < document.forms.postmodify.elements.length; i++)
-						if (document.forms.postmodify.elements[i].id.substr(0, 8) == "options-")
-							pollOptionNum++;
-				}
-				pollOptionNum++
-				pollOptionId++
-
-				setOuterHTML(document.getElementById("pollMoreOptions"), \'<li><label for="options-\' + pollOptionId + \'" ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['option'], ' \' + pollOptionNum + \'</label>: <input type="text" name="options[\' + (pollOptionId) + \']" id="options-\' + (pollOptionId) + \'" value="" size="80" maxlength="255" class="input_text" /></li><li id="pollMoreOptions"></li\');
-			}
-		// ]]></script>';
-
-	// Start the main poll form.
-	echo '
-	<div id="edit_poll">
-		<form action="' . $scripturl . '?action=editpoll2', $context['is_edit'] ? '' : ';add', ';topic=' . $context['current_topic'] . '.' . $context['start'] . '" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this); smc_saveEntities(\'postmodify\', [\'question\'], \'options-\');" name="postmodify" id="postmodify">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>';
-
-	if (!empty($context['poll_error']['messages']))
-		echo '
-			<div class="errorbox">
-				<dl class="poll_error">
-					<dt>
-						', $context['is_edit'] ? $txt['error_while_editing_poll'] : $txt['error_while_adding_poll'], ':
-					</dt>
-					<dt>
-						', empty($context['poll_error']['messages']) ? '' : implode('<br />', $context['poll_error']['messages']), '
-					</dt>
-				</dl>
-			</div>';
-
-	echo '
-			<div>
-			<span class="upperframe"><span></span></span>
-				<div class="roundframe">
-					<input type="hidden" name="poll" value="', $context['poll']['id'], '" />
-					<fieldset id="poll_main">
-						<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], ':</span></legend>
-						<input type="text" name="question" size="80" value="', $context['poll']['question'], '" class="input_text" />
-						<ul class="poll_main">';
-
-	foreach ($context['choices'] as $choice)
-	{
-		echo '
-							<li>
-								<label for="options-', $choice['id'], '" ', (isset($context['poll_error']['poll_few']) ? ' class="error"' : ''), '>', $txt['option'], ' ', $choice['number'], '</label>:
-								<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" class="input_text" size="80" maxlength="255" />';
-
-		// Does this option have a vote count yet, or is it new?
-		if ($choice['votes'] != -1)
-			echo ' (', $choice['votes'], ' ', $txt['votes'], ')';
-
-		echo '
-							</li>';
-	}
-
-	echo '
-							<li id="pollMoreOptions"></li>
-						</ul>
-						<strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
-					</fieldset>
-					<fieldset id="poll_options">
-						<legend>', $txt['poll_options'], ':</legend>
-						<dl class="settings poll_options">';
-
-	if ($context['can_moderate_poll'])
-	{
-		echo '
-							<dt>
-								<label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
-							</dt>
-							<dd>
-								<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll']['max_votes'], '" class="input_text" />
-							</dd>
-							<dt>
-								<label for="poll_expire">', $txt['poll_run'], ':</label><br />
-								<em class="smalltext">', $txt['poll_run_limit'], '</em>
-							</dt>
-							<dd>
-								<input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll']['expiration'], '" onchange="this.form.poll_hide[2].disabled = isEmptyText(this) || this.value == 0; if (this.form.poll_hide[2].checked) this.form.poll_hide[1].checked = true;" maxlength="4" class="input_text" /> ', $txt['days_word'], '
-							</dd>
-							<dt>
-								<label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
-							</dt>
-							<dd>
-								<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-
-		if ($context['poll']['guest_vote_allowed'])
-			echo '
-							<dt>
-								<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
-							</dt>
-							<dd>
-								<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll']['guest_vote']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-	}
-
-	echo '
-							<dt>
-								', $txt['poll_results_visibility'], ':
-							</dt>
-							<dd>
-								<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll']['hide_results'] == 0 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br />
-								<input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll']['hide_results'] == 1 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br />
-								<input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll']['hide_results'] == 2 ? ' checked="checked"' : '', empty($context['poll']['expiration']) ? 'disabled="disabled"' : '', ' class="input_radio" /> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
-							</dd>
-						</dl>
-					</fieldset>';
-	// If this is an edit, we can allow them to reset the vote counts.
-	if ($context['is_edit'])
-		echo '
-					<fieldset id="poll_reset">
-						<legend>', $txt['reset_votes'], '</legend>
-						<input type="checkbox" name="resetVoteCount" value="on" class="input_check" /> ' . $txt['reset_votes_check'] . '
-					</fieldset>';
-	echo '
-					<div class="righttext padding">
-						<input type="submit" name="post" value="', $txt['save'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
-					</div>
-					<br class="clear" />
-				</div>
-				<span class="lowerframe"><span></span></span>
-			</div>
-			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
-			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
-		</form>
-	</div>
-';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Some javascript for adding more options.
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var pollOptionNum = 0;
+			var pollOptionId = ', $context['last_choice_id'], ';
+
+			function addPollOption()
+			{
+				if (pollOptionNum == 0)
+				{
+					for (var i = 0; i < document.forms.postmodify.elements.length; i++)
+						if (document.forms.postmodify.elements[i].id.substr(0, 8) == "options-")
+							pollOptionNum++;
+				}
+				pollOptionNum++
+				pollOptionId++
+
+				setOuterHTML(document.getElementById("pollMoreOptions"), \'<li><label for="options-\' + pollOptionId + \'" ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['option'], ' \' + pollOptionNum + \'</label>: <input type="text" name="options[\' + (pollOptionId) + \']" id="options-\' + (pollOptionId) + \'" value="" size="80" maxlength="255" class="input_text" /></li><li id="pollMoreOptions"></li\');
+			}
+		// ]]></script>';
+
+	// Start the main poll form.
+	echo '
+	<div id="edit_poll">
+		<form action="' . $scripturl . '?action=editpoll2', $context['is_edit'] ? '' : ';add', ';topic=' . $context['current_topic'] . '.' . $context['start'] . '" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this); smc_saveEntities(\'postmodify\', [\'question\'], \'options-\');" name="postmodify" id="postmodify">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>';
+
+	if (!empty($context['poll_error']['messages']))
+		echo '
+			<div class="errorbox">
+				<dl class="poll_error">
+					<dt>
+						', $context['is_edit'] ? $txt['error_while_editing_poll'] : $txt['error_while_adding_poll'], ':
+					</dt>
+					<dt>
+						', empty($context['poll_error']['messages']) ? '' : implode('<br />', $context['poll_error']['messages']), '
+					</dt>
+				</dl>
+			</div>';
+
+	echo '
+			<div>
+				<div class="roundframe">
+					<input type="hidden" name="poll" value="', $context['poll']['id'], '" />
+					<fieldset id="poll_main">
+						<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], ':</span></legend>
+						<input type="text" name="question" size="80" value="', $context['poll']['question'], '" class="input_text" />
+						<ul class="poll_main">';
+
+	foreach ($context['choices'] as $choice)
+	{
+		echo '
+							<li>
+								<label for="options-', $choice['id'], '" ', (isset($context['poll_error']['poll_few']) ? ' class="error"' : ''), '>', $txt['option'], ' ', $choice['number'], '</label>:
+								<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" class="input_text" size="80" maxlength="255" />';
+
+		// Does this option have a vote count yet, or is it new?
+		if ($choice['votes'] != -1)
+			echo ' (', $choice['votes'], ' ', $txt['votes'], ')';
+
+		echo '
+							</li>';
+	}
+
+	echo '
+							<li id="pollMoreOptions"></li>
+						</ul>
+						<strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
+					</fieldset>
+					<fieldset id="poll_options">
+						<legend>', $txt['poll_options'], ':</legend>
+						<dl class="settings poll_options">';
+
+	if ($context['can_moderate_poll'])
+	{
+		echo '
+							<dt>
+								<label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
+							</dt>
+							<dd>
+								<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll']['max_votes'], '" class="input_text" />
+							</dd>
+							<dt>
+								<label for="poll_expire">', $txt['poll_run'], ':</label><br />
+								<em class="smalltext">', $txt['poll_run_limit'], '</em>
+							</dt>
+							<dd>
+								<input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll']['expiration'], '" onchange="this.form.poll_hide[2].disabled = isEmptyText(this) || this.value == 0; if (this.form.poll_hide[2].checked) this.form.poll_hide[1].checked = true;" maxlength="4" class="input_text" /> ', $txt['days_word'], '
+							</dd>
+							<dt>
+								<label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
+							</dt>
+							<dd>
+								<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+
+		if ($context['poll']['guest_vote_allowed'])
+			echo '
+							<dt>
+								<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
+							</dt>
+							<dd>
+								<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll']['guest_vote']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+	}
+
+	echo '
+							<dt>
+								', $txt['poll_results_visibility'], ':
+							</dt>
+							<dd>
+								<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll']['hide_results'] == 0 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br />
+								<input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll']['hide_results'] == 1 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br />
+								<input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll']['hide_results'] == 2 ? ' checked="checked"' : '', empty($context['poll']['expiration']) ? 'disabled="disabled"' : '', ' class="input_radio" /> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
+							</dd>
+						</dl>
+					</fieldset>';
+	// If this is an edit, we can allow them to reset the vote counts.
+	if ($context['is_edit'])
+		echo '
+					<fieldset id="poll_reset">
+						<legend>', $txt['reset_votes'], '</legend>
+						<input type="checkbox" name="resetVoteCount" value="on" class="input_check" /> ' . $txt['reset_votes_check'] . '
+					</fieldset>';
+	echo '
+					<div class="righttext padding">
+						<input type="submit" name="post" value="', $txt['save'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
+					</div>
+					<br class="clear" />
+				</div>
+			</div>
+			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
+			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
+		</form>
+	</div>
+';
+}
+
 ?>

+ 1081 - 1091
Themes/default/Post.template.php

@@ -1,1092 +1,1082 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// The main template for the post page.
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings, $counter;
-
-	// Start the javascript... and boy is there a lot.
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[';
-
-	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
-	if (isBrowser('is_firefox'))
-		echo '
-			window.addEventListener("pageshow", reActivate, false);';
-
-	// Start with message icons - and any missing from this theme.
-	echo '
-			var icon_urls = {';
-	foreach ($context['icons'] as $icon)
-		echo '
-				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
-	echo '
-			};';
-
-	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
-	if ($context['make_poll'])
-		echo '
-			var pollOptionNum = 0, pollTabIndex;
-			var pollOptionId = ', $context['last_choice_id'], ';
-			function addPollOption()
-			{
-				if (pollOptionNum == 0)
-				{
-					for (var i = 0, n = document.forms.postmodify.elements.length; i < n; i++)
-						if (document.forms.postmodify.elements[i].id.substr(0, 8) == \'options-\')
-						{
-							pollOptionNum++;
-							pollTabIndex = document.forms.postmodify.elements[i].tabIndex;
-						}
-				}
-				pollOptionNum++
-				pollOptionId++
-
-				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<li><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>: <input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text" /></li><li id="pollMoreOptions"></li>'), ');
-			}';
-
-	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
-	if ($context['make_event'])
-		echo '
-			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
-
-	// End of the javascript, start the form and display the link tree.
-	echo '
-		// ]]></script>
-		<form action="', $scripturl, '?action=', $context['destination'], ';', empty($context['current_board']) ? '' : 'board=' . $context['current_board'], '" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="', ($context['becomes_approved'] ? '' : 'alert(\'' . $txt['js_post_will_require_approval'] . '\');'), 'submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'', $context['post_box_name'], '\', \'guestname\', \'evtitle\', \'question\'], \'options\');" enctype="multipart/form-data">';
-
-	// If the user wants to see how their message looks - the preview section is where it's at!
-	echo '
-			<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
-				<div class="cat_bar">
-					<h3 class="catbg">
-						<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
-					</h3>
-				</div>
-				<div class="windowbg">
-					<span class="topslice"><span></span></span>
-					<div class="content">
-						<div class="post" id="preview_body">
-							', empty($context['preview_message']) ? '<br />' : $context['preview_message'], '
-						</div>
-					</div>
-					<span class="botslice"><span></span></span>
-				</div>
-			</div><br />';
-
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
-		echo '
-			<input type="hidden" name="eventid" value="', $context['event']['id'], '" />';
-
-	// Start the main table.
-	echo '
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>
-			<div>
-				<span class="upperframe"><span></span></span>
-				<div class="roundframe">', isset($context['current_topic']) ? '
-					<input type="hidden" name="topic" value="' . $context['current_topic'] . '" />' : '';
-
-	// If an error occurred, explain what happened.
-	echo '
-					<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
-						<dl>
-							<dt>
-								<strong id="error_serious">', $txt['error_while_submitting'], '</strong>
-							</dt>
-							<dd class="error" id="error_list">
-								', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
-							</dd>
-						</dl>
-					</div>';
-
-	// If this won't be approved let them know!
-	if (!$context['becomes_approved'])
-	{
-		echo '
-					<p class="information">
-						<em>', $txt['wait_for_approval'], '</em>
-						<input type="hidden" name="not_approved" value="1" />
-					</p>';
-	}
-
-	// If it's locked, show a message to warn the replyer.
-	echo '
-					<p class="information"', $context['locked'] ? '' : ' style="display: none"', ' id="lock_warning">
-						', $txt['topic_locked_no_reply'], '
-					</p>';
-
-	// The post header... important stuff
-	echo '
-					<dl id="post_header">';
-
-	// Guests have to put in their name and email...
-	if (isset($context['name']) && isset($context['email']))
-	{
-		echo '
-						<dt>
-							<span', isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '', ' id="caption_guestname">', $txt['name'], ':</span>
-						</dt>
-						<dd>
-							<input type="text" name="guestname" size="25" value="', $context['name'], '" tabindex="', $context['tabindex']++, '" class="input_text" />
-						</dd>';
-
-		if (empty($modSettings['guest_post_no_email']))
-			echo '
-						<dt>
-							<span', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '', ' id="caption_email">', $txt['email'], ':</span>
-						</dt>
-						<dd>
-							<input type="text" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" />
-						</dd>';
-	}
-
-	// Now show the subject box for this post.
-	echo '
-						<dt class="clear">
-							<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
-						</dt>
-						<dd>
-							<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80"', isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', '/>
-						</dd>
-						<dt class="clear_left">
-							', $txt['message_icon'], ':
-						</dt>
-						<dd>
-							<select name="icon" id="icon" onchange="showimage()">';
-
-	// Loop through each message icon allowed, adding it to the drop down list.
-	foreach ($context['icons'] as $icon)
-		echo '
-								<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected="selected"' : '', '>', $icon['name'], '</option>';
-
-	echo '
-							</select>
-							<img src="', $context['icon_url'], '" name="icons" hspace="15" alt="" />
-						</dd>
-					</dl><hr class="clear" />';
-
-	// Are you posting a calendar event?
-	if ($context['make_event'])
-	{
-		echo '
-					<div id="post_event">
-						<fieldset id="event_main">
-							<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', ' id="caption_evtitle">', $txt['calendar_event_title'], '</span></legend>
-							<input type="text" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '" class="input_text" />
-							<div class="smalltext" style="white-space: nowrap;">
-								<input type="hidden" name="calendar" value="1" />', $txt['calendar_year'], '
-								<select name="year" id="year" tabindex="', $context['tabindex']++, '" onchange="generateDays();">';
-
-		// Show a list of all the years we allow...
-		for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
-			echo '
-									<option value="', $year, '"', $year == $context['event']['year'] ? ' selected="selected"' : '', '>', $year, '&nbsp;</option>';
-
-		echo '
-								</select>
-								', $txt['calendar_month'], '
-								<select name="month" id="month" onchange="generateDays();">';
-
-		// There are 12 months per year - ensure that they all get listed.
-		for ($month = 1; $month <= 12; $month++)
-			echo '
-									<option value="', $month, '"', $month == $context['event']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '&nbsp;</option>';
-
-		echo '
-								</select>
-								', $txt['calendar_day'], '
-								<select name="day" id="day">';
-
-		// This prints out all the days in the current month - this changes dynamically as we switch months.
-		for ($day = 1; $day <= $context['event']['last_day']; $day++)
-			echo '
-									<option value="', $day, '"', $day == $context['event']['day'] ? ' selected="selected"' : '', '>', $day, '&nbsp;</option>';
-
-		echo '
-								</select>
-							</div>
-						</fieldset>';
-
-		if (!empty($modSettings['cal_allowspan']) || ($context['event']['new'] && $context['is_new_post']))
-		{
-			echo '
-						<fieldset id="event_options">
-							<legend>', $txt['calendar_event_options'], '</legend>
-							<div class="event_options smalltext">
-								<ul class="event_options">';
-
-			// If events can span more than one day then allow the user to select how long it should last.
-			if (!empty($modSettings['cal_allowspan']))
-			{
-				echo '
-									<li>
-										', $txt['calendar_numb_days'], '
-										<select name="span">';
-
-				for ($days = 1; $days <= $modSettings['cal_maxspan']; $days++)
-					echo '
-											<option value="', $days, '"', $days == $context['event']['span'] ? ' selected="selected"' : '', '>', $days, '&nbsp;</option>';
-
-				echo '
-										</select>
-									</li>';
-			}
-
-			// If this is a new event let the user specify which board they want the linked post to be put into.
-			if ($context['event']['new'] && $context['is_new_post'])
-			{
-				echo '
-									<li>
-										', $txt['calendar_post_in'], '
-										<select name="board">';
-				foreach ($context['event']['categories'] as $category)
-				{
-					echo '
-											<optgroup label="', $category['name'], '">';
-					foreach ($category['boards'] as $board)
-						echo '
-												<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
-					echo '
-											</optgroup>';
-				}
-				echo '
-										</select>
-									</li>';
-			}
-
-			echo '
-								</ul>
-							</div>
-						</fieldset>';
-		}
-
-		echo '
-					</div>';
-	}
-
-	// If this is a poll then display all the poll options!
-	if ($context['make_poll'])
-	{
-		echo '
-					<div id="edit_poll">
-						<fieldset id="poll_main">
-							<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], '</span></legend>
-							<input type="text" name="question" value="', isset($context['question']) ? $context['question'] : '', '" tabindex="', $context['tabindex']++, '" size="80" class="input_text" />
-							<ul class="poll_main">';
-
-		// Loop through all the choices and print them out.
-		foreach ($context['choices'] as $choice)
-		{
-			echo '
-								<li>
-									<label for="options-', $choice['id'], '">', $txt['option'], ' ', $choice['number'], '</label>:
-									<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="255" class="input_text" />
-								</li>';
-		}
-
-		echo '
-								<li id="pollMoreOptions"></li>
-							</ul>
-							<strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
-						</fieldset>
-						<fieldset id="poll_options">
-							<legend>', $txt['poll_options'], '</legend>
-							<dl class="settings poll_options">
-								<dt>
-									<label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
-								</dt>
-								<dd>
-									<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll_options']['max_votes'], '" class="input_text" />
-								</dd>
-								<dt>
-									<label for="poll_expire">', $txt['poll_run'], ':</label><br />
-									<em class="smalltext">', $txt['poll_run_limit'], '</em>
-								</dt>
-								<dd>
-									<input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll_options']['expire'], '" onchange="pollOptions();" maxlength="4" class="input_text" /> ', $txt['days_word'], '
-								</dd>
-								<dt>
-									<label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
-								</dt>
-								<dd>
-									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked="checked"' : '', ' class="input_check" />
-								</dd>';
-
-		if ($context['poll_options']['guest_vote_enabled'])
-			echo '
-								<dt>
-									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
-								</dt>
-								<dd>
-									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked="checked"' : '', ' class="input_check" />
-								</dd>';
-
-		echo '
-								<dt>
-									', $txt['poll_results_visibility'], ':
-								</dt>
-								<dd>
-									<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll_options']['hide'] == 0 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br />
-									<input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll_options']['hide'] == 1 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br />
-									<input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll_options']['hide'] == 2 ? ' checked="checked"' : '', empty($context['poll_options']['expire']) ? 'disabled="disabled"' : '', ' class="input_radio" /> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
-								</dd>
-							</dl>
-						</fieldset>
-					</div>';
-	}
-
-	// Show the actual posting area...
-	if ($context['show_bbc'])
-	{
-		echo '
-					<div id="bbcBox_message"></div>';
-	}
-
-	// What about smileys?
-	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
-		echo '
-					<div id="smileyBox_message"></div>';
-
-	echo '
-					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
-
-	// If this message has been edited in the past - display when it was.
-	if (isset($context['last_modified']))
-		echo '
-					<div class="padding smalltext">
-						<strong>', $txt['last_edit'], ':</strong>
-						', $context['last_modified'], '
-					</div>';
-
-	// If the admin has enabled the hiding of the additional options - show a link and image for it.
-	if (!empty($settings['additional_options_collapsable']))
-		echo '
-					<div id="postAdditionalOptionsHeader" class="title_bar">
-						<h4 class="titlebg">
-							<img id="postMoreExpand" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/collapse.png" alt="-" /> <strong><a href="#" id="postMoreExpandLink">', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
-						</h4>
-					</div>';
-
-	// Display the check boxes for all the standard options - if they are available to the user!
-	echo '
-					<div id="postMoreOptions" class="smalltext">
-						<ul class="post_options">
-							', $context['can_notify'] ? '<li><input type="hidden" name="notify" value="0" /><label for="check_notify"><input type="checkbox" name="notify" id="check_notify"' . ($context['notify'] || !empty($options['auto_notify']) ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['notify_replies'] . '</label></li>' : '', '
-							', $context['can_lock'] ? '<li><input type="hidden" name="lock" value="0" /><label for="check_lock"><input type="checkbox" name="lock" id="check_lock"' . ($context['locked'] ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['lock_topic'] . '</label></li>' : '', '
-							<li><label for="check_back"><input type="checkbox" name="goback" id="check_back"' . ($context['back_to_topic'] || !empty($options['return_to_post']) ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['back_to_topic'] . '</label></li>
-							', $context['can_sticky'] ? '<li><input type="hidden" name="sticky" value="0" /><label for="check_sticky"><input type="checkbox" name="sticky" id="check_sticky"' . ($context['sticky'] ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['sticky_after'] . '</label></li>' : '', '
-							<li><label for="check_smileys"><input type="checkbox" name="ns" id="check_smileys"', $context['use_smileys'] ? '' : ' checked="checked"', ' value="NS" class="input_check" /> ', $txt['dont_use_smileys'], '</label></li>', '
-							', $context['can_move'] ? '<li><input type="hidden" name="move" value="0" /><label for="check_move"><input type="checkbox" name="move" id="check_move" value="1" class="input_check" ' . (!empty($context['move']) ? 'checked="checked" ' : '') . '/> ' . $txt['move_after2'] . '</label></li>' : '', '
-							', $context['can_announce'] && $context['is_first_post'] ? '<li><label for="check_announce"><input type="checkbox" name="announce_topic" id="check_announce" value="1" class="input_check" ' . (!empty($context['announce']) ? 'checked="checked" ' : '') . '/> ' . $txt['announce_topic'] . '</label></li>' : '', '
-							', $context['show_approval'] ? '<li><label for="approve"><input type="checkbox" name="approve" id="approve" value="2" class="input_check" ' . ($context['show_approval'] === 2 ? 'checked="checked"' : '') . ' /> ' . $txt['approve_this_post'] . '</label></li>' : '', '
-						</ul>
-					</div>';
-
-	// If this post already has attachments on it - give information about them.
-	if (!empty($context['current_attachments']))
-	{
-		echo '
-					<dl id="postAttachment">
-						<dt>
-							', $txt['attached'], ':
-						</dt>
-						<dd class="smalltext">
-							<input type="hidden" name="attach_del[]" value="0" />
-							', $txt['uncheck_unwatchd_attach'], ':
-						</dd>';
-		foreach ($context['current_attachments'] as $attachment)
-			echo '
-						<dd class="smalltext">
-							<label for="attachment_', $attachment['id'], '"><input type="checkbox" id="attachment_', $attachment['id'], '" name="attach_del[]" value="', $attachment['id'], '"', empty($attachment['unchecked']) ? ' checked="checked"' : '', ' class="input_check" /> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
-							!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
-						</dd>';
-
-		if (!empty($context['files_in_session_warning']))
-			echo '
-						<dd class="smalltext">', $context['files_in_session_warning'], '</dd>';
-
-		echo '
-					</dl>';
-	}
-
-	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
-	if ($context['can_post_attachment'])
-	{
-		echo '
-					<dl id="postAttachment2">';
-		
-		// But, only show them if they haven't reached a limit. Or a mod author hasn't hidden them.
-		if ($context['num_allowed_attachments'] > 0 || !empty($context['dont_show_them']))
-		{
-			echo '
-						<dt>
-							', $txt['attach'], ':
-						</dt>
-						<dd class="smalltext">
-							', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '" />'), '
-							<input type="file" size="60" name="attachment[]" id="attachment1" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
-
-			// Show more boxes if they aren't approaching that limit.
-			if ($context['num_allowed_attachments'] > 1)
-				echo '
-							<script type="text/javascript"><!-- // --><![CDATA[
-								var allowed_attachments = ', $context['num_allowed_attachments'], ';
-								var current_attachment = 1;
-
-								function addAttachment()
-								{
-									allowed_attachments = allowed_attachments - 1;
-									current_attachment = current_attachment + 1;
-									if (allowed_attachments <= 0)
-										return alert("', $txt['more_attachments_error'], '");
-
-									setOuterHTML(document.getElementById("moreAttachments"), \'<dd class="smalltext"><input type="file" size="60" name="attachment[]" id="attachment\' + current_attachment + \'" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\\\'attachment\' + current_attachment + \'\\\');">', $txt['clean_attach'], '<\/a>)\' + \'<\/dd><dd class="smalltext" id="moreAttachments"><a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')<\' + \'/a><\' + \'/dd>\');
-
-									return true;
-								}
-							// ]]></script>
-						</dd>
-						<dd class="smalltext" id="moreAttachments"><a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')</a></dd>';
-			else
-				echo '
-						</dd>';
-		}
-
-		// Add any template changes for an alternative upload system here.
-		call_integration_hook('integrate_upload_template', array());
-
-		echo '
-						<dd class="smalltext">';
-
-		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
-		if (!empty($modSettings['attachmentCheckExtensions']))
-			echo '
-							', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br />';
-
-		if (!empty($context['attachment_restrictions']))
-			echo '
-							', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br />';
-
-		if ($context['num_allowed_attachments'] == 0)
-			echo '
-							', $txt['attach_limit_nag'], '<br />';
-
-		if (!$context['can_post_attachment_unapproved'])
-			echo '
-							<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br />';
-
-		echo '
-						</dd>
-					</dl>';
-	}
-
-	// Is visual verification enabled?
-	if ($context['require_verification'])
-	{
-		echo '
-					<div class="post_verification">
-						<span', !empty($context['post_error']['need_qr_verification']) ? ' class="error"' : '', '>
-							<strong>', $txt['verification'], ':</strong>
-						</span>
-						', template_control_verification($context['visual_verification_id'], 'all'), '
-					</div>';
-	}
-
-	// Finally, the submit buttons.
-	echo '
-					<hr class="hrcolor" />
-					<span class="smalltext" >
-						', isBrowser('is_firefox') ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '
-					</span>
-					<span id="post_confirm_buttons">
-						', template_control_richedit_buttons($context['post_box_name']);
-
-	// Option to delete an event if user is editing one.
-	if ($context['make_event'] && !$context['event']['new'])
-		echo '
-						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" onclick="return confirm(\'', $txt['event_delete_confirm'], '\');" class="button_submit" />';
-
-	echo '
-					</span>
-					<br class="clear_right" />
-				</div>
-				<span class="lowerframe"><span></span></span>
-			</div>
-			<br class="clear" />';
-
-	// Assuming this isn't a new topic pass across the last message id.
-	if (isset($context['topic_last_message']))
-		echo '
-			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '" />';
-
-	echo '
-			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '" />
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
-		</form>';
-
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[';
-
-	// The functions used to preview a posts without loading a new page.
-	echo '
-			var current_board = ', empty($context['current_board']) ? 'null' : $context['current_board'], ';
-			var make_poll = ', $context['make_poll'] ? 'true' : 'false', ';
-			var txt_preview_title = "', $txt['preview_title'], '";
-			var txt_preview_fetch = "', $txt['preview_fetch'], '";
-			var new_replies = new Array();
-			var reply_counter = ', empty($counter) ? 0 : $counter, ';
-			function previewPost()
-			{';
-	if (isBrowser('is_firefox'))
-		echo '
-				// Firefox doesn\'t render <marquee> that have been put it using javascript
-				if (document.forms.postmodify.elements[', JavaScriptEscape($context['post_box_name']), '].value.indexOf(\'[move]\') != -1)
-				{
-					return submitThisOnce(document.forms.postmodify);
-				}';
-	echo '
-				if (window.XMLHttpRequest)
-				{
-					// Opera didn\'t support setRequestHeader() before 8.01.
-					if (\'opera\' in window)
-					{
-						var test = new XMLHttpRequest();
-						if (!(\'setRequestHeader\' in test))
-							return submitThisOnce(document.forms.postmodify);
-					}
-					// @todo Currently not sending poll options and option checkboxes.
-					var x = new Array();
-					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'icon\', \'guestname\', \'email\', \'evtitle\', \'question\', \'topic\'];
-					var numericFields = [
-						\'board\', \'topic\', \'last_msg\',
-						\'eventid\', \'calendar\', \'year\', \'month\', \'day\',
-						\'poll_max_votes\', \'poll_expire\', \'poll_change_vote\', \'poll_hide\'
-					];
-					var checkboxFields = [
-						\'ns\'
-					];
-
-					for (var i = 0, n = textFields.length; i < n; i++)
-						if (textFields[i] in document.forms.postmodify)
-						{
-							// Handle the WYSIWYG editor.
-							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
-								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
-							else
-								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
-						}
-					for (var i = 0, n = numericFields.length; i < n; i++)
-						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
-							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
-					for (var i = 0, n = checkboxFields.length; i < n; i++)
-						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
-							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
-
-					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=post2\' + (current_board ? \';board=\' + current_board : \'\') + (make_poll ? \';poll\' : \'\') + \';preview;xml\', x.join(\'&\'), onDocSent);
-
-					document.getElementById(\'preview_section\').style.display = \'\';
-					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
-					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
-
-					return false;
-				}
-				else
-					return submitThisOnce(document.forms.postmodify);
-			}
-			function onDocSent(XMLDoc)
-			{
-				if (!XMLDoc)
-				{
-					document.forms.postmodify.preview.onclick = new function ()
-					{
-						return true;
-					}
-					document.forms.postmodify.preview.click();
-				}
-
-				// Show the preview section.
-				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
-				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
-
-				var bodyText = \'\';
-				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
-					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
-
-				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
-				document.getElementById(\'preview_body\').className = \'post\';
-
-				// Show a list of errors (if any).
-				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
-				var errorList = new Array();
-				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
-					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
-				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
-				document.getElementById(\'errors\').className = errors.getAttribute(\'serious\') == 1 ? \'errorbox\' : \'noticebox\';
-				document.getElementById(\'error_serious\').style.display = numErrors == 0 ? \'none\' : \'\';
-				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
-
-				// Show a warning if the topic has been locked.
-				document.getElementById(\'lock_warning\').style.display = errors.getAttribute(\'topic_locked\') == 1 ? \'\' : \'none\';
-
-				// Adjust the color of captions if the given data is erroneous.
-				var captions = errors.getElementsByTagName(\'caption\');
-				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
-					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
-						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
-
-				if (errors.getElementsByTagName(\'post_error\').length == 1)
-					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
-				else if (document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
-				{
-					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
-						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
-					else
-						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
-				}
-
-				// Set the new last message id.
-				if (\'last_msg\' in document.forms.postmodify)
-					document.forms.postmodify.last_msg.value = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'last_msg\')[0].firstChild.nodeValue;
-
-				// Remove the new image from old-new replies!
-				for (i = 0; i < new_replies.length; i++)
-					document.getElementById(\'image_new_\' + new_replies[i]).style.display = \'none\';
-				new_replies = new Array();
-
-				var ignored_replies = new Array(), ignoring;
-				var newPosts = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'new_posts\')[0] ? XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'new_posts\')[0].getElementsByTagName(\'post\') : {length: 0};
-				var numNewPosts = newPosts.length;
-				if (numNewPosts != 0)
-				{
-					var newPostsHTML = \'<span id="new_replies"><\' + \'/span>\';
-					for (var i = 0; i < numNewPosts; i++)
-					{
-						new_replies[new_replies.length] = newPosts[i].getAttribute("id");
-
-						ignoring = false;
-						if (newPosts[i].getElementsByTagName("is_ignored")[0].firstChild.nodeValue != 0)
-							ignored_replies[ignored_replies.length] = ignoring = newPosts[i].getAttribute("id");
-
-						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \' core_posts"><span class="topslice"><span></span></span><div class="content" id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
-
-	if ($context['can_quote'])
-		echo '
-						newPostsHTML += \'<ul class="reset smalltext quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>',$txt['bbc_quote'],'</span><\' + \'/a></li></ul>\';';
-
-	echo '
-						newPostsHTML += \'<br class="clear" />\';
-
-						if (ignoring)
-							newPostsHTML += \'<div id="msg_\' + newPosts[i].getAttribute("id") + \'_ignored_prompt" class="smalltext">', $txt['ignoring_user'], '<a href="#" id="msg_\' + newPosts[i].getAttribute("id") + \'_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a></div>\';
-
-						newPostsHTML += \'<div class="list_posts smalltext" id="msg_\' + newPosts[i].getAttribute("id") + \'_body">\' + newPosts[i].getElementsByTagName("message")[0].firstChild.nodeValue + \'<\' + \'/div></div><span class="botslice"><span></span></span></div>\';
-					}
-					setOuterHTML(document.getElementById(\'new_replies\'), newPostsHTML);
-				}
-
-				var numIgnoredReplies = ignored_replies.length;
-				if (numIgnoredReplies != 0)
-				{
-					for (var i = 0; i < numIgnoredReplies; i++)
-					{
-						aIgnoreToggles[ignored_replies[i]] = new smc_Toggle({
-							bToggleEnabled: true,
-							bCurrentlyCollapsed: true,
-							aSwappableContainers: [
-								\'msg_\' + ignored_replies[i] + \'_body\',
-								\'msg_\' + ignored_replies[i] + \'_quote\',
-							],
-							aSwapLinks: [
-								{
-									sId: \'msg_\' + ignored_replies[i] + \'_ignored_link\',
-									msgExpanded: \'\',
-									msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
-								}
-							]
-						});
-					}
-				}
-
-				location.hash = \'#\' + \'preview_section\';
-
-				if (typeof(smf_codeFix) != \'undefined\')
-					smf_codeFix();
-			}';
-
-	// Code for showing and hiding additional options.
-	if (!empty($settings['additional_options_collapsable']))
-		echo '
-			var oSwapAdditionalOptions = new smc_Toggle({
-				bToggleEnabled: true,
-				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
-				funcOnBeforeCollapse: function () {
-					document.getElementById(\'additional_options\').value = \'0\';
-				},
-				funcOnBeforeExpand: function () {
-					document.getElementById(\'additional_options\').value = \'1\';
-				},
-				aSwappableContainers: [
-					\'postMoreOptions\',
-					\'postAttachment\',
-					\'postAttachment2\',
-					\'postAttachment3\'
-				],
-				aSwapImages: [
-					{
-						sId: \'postMoreExpand\',
-						srcExpanded: smf_images_url + \'/collapse.png\',
-						altExpanded: \'-\',
-						srcCollapsed: smf_images_url + \'/expand.png\',
-						altCollapsed: \'+\'
-					}
-				],
-				aSwapLinks: [
-					{
-						sId: \'postMoreExpandLink\',
-						msgExpanded: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), ',
-						msgCollapsed: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), '
-					}
-				]
-			});';
-
-	echo '
-		// ]]></script>';
-
-	// If the user is replying to a topic show the previous posts.
-	if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
-	{
-		echo '
-		<div id="recent" class="flow_hidden main_section">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['topic_summary'], '</h3>
-			</div>
-			<span id="new_replies"></span>';
-
-		$ignored_posts = array();
-		foreach ($context['previous_posts'] as $post)
-		{
-			$ignoring = false;
-			if (!empty($post['is_ignored']))
-				$ignored_posts[] = $ignoring = $post['id'];
-
-			echo '
-				<div class="', $post['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
-				<span class="topslice"><span></span></span>
-				<div class="content" id="msg', $post['id'], '">
-					<div class="floatleft">
-						<h5>', $txt['posted_by'], ': ', $post['poster'], '</h5>
-						<span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> ', $post['time'], '&nbsp;&#187;</span>
-					</div>';
-
-			if ($context['can_quote'])
-			{
-				echo '
-					<ul class="reset smalltext quickbuttons" id="msg_', $post['id'], '_quote">
-						<li><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');" class="quote_button"><span>',$txt['bbc_quote'],'</span></a></li>
-					</ul>';
-			}
-
-			echo '
-					<br class="clear" />';
-
-			if ($ignoring)
-			{
-				echo '
-					<div id="msg_', $post['id'], '_ignored_prompt" class="smalltext">
-						', $txt['ignoring_user'], '
-						<a href="#" id="msg_', $post['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
-					</div>';
-			}
-
-			echo '
-					<div class="list_posts smalltext" id="msg_', $post['id'], '_body">', $post['message'], '</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-		}
-
-		echo '
-		</div>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var aIgnoreToggles = new Array();';
-
-		foreach ($ignored_posts as $post_id)
-		{
-			echo '
-			aIgnoreToggles[', $post_id, '] = new smc_Toggle({
-				bToggleEnabled: true,
-				bCurrentlyCollapsed: true,
-				aSwappableContainers: [
-					\'msg_', $post_id, '_body\',
-					\'msg_', $post_id, '_quote\',
-				],
-				aSwapLinks: [
-					{
-						sId: \'msg_', $post_id, '_ignored_link\',
-						msgExpanded: \'\',
-						msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
-					}
-				]
-			});';
-		}
-
-		echo '
-			function insertQuoteFast(messageid)
-			{
-				if (window.XMLHttpRequest)
-					getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';xml;pb=', $context['post_box_name'], ';mode=\' + (oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled ? 1 : 0), onDocReceived);
-				else
-					reqWin(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';pb=', $context['post_box_name'], ';mode=\' + (oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled ? 1 : 0), 240, 90);
-				return true;
-			}
-			function onDocReceived(XMLDoc)
-			{
-				var text = \'\';
-				for (var i = 0, n = XMLDoc.getElementsByTagName(\'quote\')[0].childNodes.length; i < n; i++)
-					text += XMLDoc.getElementsByTagName(\'quote\')[0].childNodes[i].nodeValue;
-				oEditorHandle_', $context['post_box_name'], '.insertText(text, false, true);
-			}
-		// ]]></script>';
-	}
-}
-
-// The template for the spellchecker.
-function template_spellcheck()
-{
-	global $context, $settings, $options, $txt;
-
-	// The style information that makes the spellchecker look... like the forum hopefully!
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<title>', $txt['spell_check'], '</title>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
-		<style type="text/css">
-			body, td
-			{
-				font-size: small;
-				margin: 0;
-				background: #f0f0f0;
-				color: #000;
-				padding: 10px;
-			}
-			.highlight
-			{
-				color: red;
-				font-weight: bold;
-			}
-			#spellview
-			{
-				border-style: outset;
-				border: 1px solid black;
-				padding: 5px;
-				width: 95%;
-				height: 314px;
-				overflow: auto;
-				background: #ffffff;
-			}';
-
-	// As you may expect - we need a lot of javascript for this... load it form the separate files.
-	echo '
-		</style>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var spell_formname = window.opener.spell_formname;
-			var spell_fieldname = window.opener.spell_fieldname;
-		// ]]></script>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/spellcheck.js"></script>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			', $context['spell_js'], '
-		// ]]></script>
-	</head>
-	<body onload="nextWord(false);">
-		<form action="#" method="post" accept-charset="', $context['character_set'], '" name="spellingForm" id="spellingForm" onsubmit="return false;" style="margin: 0;">
-			<div id="spellview">&nbsp;</div>
-			<table border="0" cellpadding="4" cellspacing="0" width="100%"><tr class="windowbg">
-				<td width="50%" valign="top">
-					', $txt['spellcheck_change_to'], '<br />
-					<input type="text" name="changeto" style="width: 98%;" class="input_text" />
-				</td>
-				<td width="50%">
-					', $txt['spellcheck_suggest'], '<br />
-					<select name="suggestions" style="width: 98%;" size="5" onclick="if (this.selectedIndex != -1) this.form.changeto.value = this.options[this.selectedIndex].text;" ondblclick="replaceWord();">
-					</select>
-				</td>
-			</tr></table>
-			<div class="righttext" style="padding: 4px;">
-				<input type="button" name="change" value="', $txt['spellcheck_change'], '" onclick="replaceWord();" class="button_submit" />
-				<input type="button" name="changeall" value="', $txt['spellcheck_change_all'], '" onclick="replaceAll();" class="button_submit" />
-				<input type="button" name="ignore" value="', $txt['spellcheck_ignore'], '" onclick="nextWord(false);" class="button_submit" />
-				<input type="button" name="ignoreall" value="', $txt['spellcheck_ignore_all'], '" onclick="nextWord(true);" class="button_submit" />
-			</div>
-		</form>
-	</body>
-</html>';
-}
-
-function template_quotefast()
-{
-	global $context, $settings, $options, $txt;
-
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<title>', $txt['retrieving_quote'], '</title>
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
-	</head>
-	<body>
-		', $txt['retrieving_quote'], '
-		<div id="temporary_posting_area" style="display: none;"></div>
-		<script type="text/javascript"><!-- // --><![CDATA[';
-
-	if ($context['close_window'])
-		echo '
-			window.close();';
-	else
-	{
-		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
-		echo '
-			var quote = \'', $context['quote']['text'], '\';
-			var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");
-
-			if (\'DOMParser\' in window && !(\'opera\' in window))
-			{
-				var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
-				quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
-			}
-			else if (\'innerText\' in stage)
-			{
-				setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
-				quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
-			}
-
-			if (\'opera\' in window)
-				quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");
-
-			window.opener.oEditorHandle_', $context['post_box_name'], '.InsertText(quote);
-
-			window.focus();
-			setTimeout("window.close();", 400);';
-	}
-	echo '
-		// ]]></script>
-	</body>
-</html>';
-}
-
-function template_announce()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="announcement">
-		<form action="', $scripturl, '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['announce_title'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['announce_desc'], '
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>
-						', $txt['announce_this_topic'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0">', $context['topic_subject'], '</a>
-					</p>
-					<ul class="reset">';
-
-	foreach ($context['groups'] as $group)
-		echo '
-						<li>
-							<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked="checked" class="input_check" /> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
-						</li>';
-
-	echo '
-						<li>
-							<label for="checkall"><input type="checkbox" id="checkall" class="input_check" onclick="invertAll(this, this.form);" checked="checked" /> <em>', $txt['check_all'], '</em></label>
-						</li>
-					</ul>
-					<hr class="hrcolor" />
-					<div id="confirm_buttons">
-						<input type="submit" value="', $txt['post'], '" class="button_submit" />
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="topic" value="', $context['current_topic'], '" />
-						<input type="hidden" name="move" value="', $context['move'], '" />
-						<input type="hidden" name="goback" value="', $context['go_back'], '" />
-					</div>
-				</div>
-				<br class="clear_right" />
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br />';
-}
-
-function template_announcement_send()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="announcement">
-		<form action="' . $scripturl . '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['announce_sending'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0" target="_blank" class="new_win">', $context['topic_subject'], '</a></p>
-					<div class="progress_bar">
-						<div class="full_bar">', $context['percentage_done'], '% ', $txt['announce_done'], '</div>
-						<div class="green_percent" style="width: ', $context['percentage_done'], '%;">&nbsp;</div>
-					</div>
-					<hr class="hrcolor" />
-					<div id="confirm_buttons">
-						<input type="submit" name="b" value="', $txt['announce_continue'], '" class="button_submit" />
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="topic" value="', $context['current_topic'], '" />
-						<input type="hidden" name="move" value="', $context['move'], '" />
-						<input type="hidden" name="goback" value="', $context['go_back'], '" />
-						<input type="hidden" name="start" value="', $context['start'], '" />
-						<input type="hidden" name="membergroups" value="', $context['membergroups'], '" />
-					</div>
-				</div>
-				<br class="clear_right" />
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br />
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var countdown = 2;
-			doAutoSubmit();
-
-			function doAutoSubmit()
-			{
-				if (countdown == 0)
-					document.forms.autoSubmit.submit();
-				else if (countdown == -1)
-					return;
-
-				document.forms.autoSubmit.b.value = "', $txt['announce_continue'], ' (" + countdown + ")";
-				countdown--;
-
-				setTimeout("doAutoSubmit();", 1000);
-			}
-		// ]]></script>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// The main template for the post page.
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings, $counter;
+
+	// Start the javascript... and boy is there a lot.
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[';
+
+	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
+	if (isBrowser('is_firefox'))
+		echo '
+			window.addEventListener("pageshow", reActivate, false);';
+
+	// Start with message icons - and any missing from this theme.
+	echo '
+			var icon_urls = {';
+	foreach ($context['icons'] as $icon)
+		echo '
+				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
+	echo '
+			};';
+
+	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
+	if ($context['make_poll'])
+		echo '
+			var pollOptionNum = 0, pollTabIndex;
+			var pollOptionId = ', $context['last_choice_id'], ';
+			function addPollOption()
+			{
+				if (pollOptionNum == 0)
+				{
+					for (var i = 0, n = document.forms.postmodify.elements.length; i < n; i++)
+						if (document.forms.postmodify.elements[i].id.substr(0, 8) == \'options-\')
+						{
+							pollOptionNum++;
+							pollTabIndex = document.forms.postmodify.elements[i].tabIndex;
+						}
+				}
+				pollOptionNum++
+				pollOptionId++
+
+				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<li><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>: <input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text" /></li><li id="pollMoreOptions"></li>'), ');
+			}';
+
+	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
+	if ($context['make_event'])
+		echo '
+			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
+
+	// End of the javascript, start the form and display the link tree.
+	echo '
+		// ]]></script>
+		<form action="', $scripturl, '?action=', $context['destination'], ';', empty($context['current_board']) ? '' : 'board=' . $context['current_board'], '" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="', ($context['becomes_approved'] ? '' : 'alert(\'' . $txt['js_post_will_require_approval'] . '\');'), 'submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'', $context['post_box_name'], '\', \'guestname\', \'evtitle\', \'question\'], \'options\');" enctype="multipart/form-data">';
+
+	// If the user wants to see how their message looks - the preview section is where it's at!
+	echo '
+			<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
+				<div class="cat_bar">
+					<h3 class="catbg">
+						<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
+					</h3>
+				</div>
+				<div class="windowbg">
+					<div class="content">
+						<div class="post" id="preview_body">
+							', empty($context['preview_message']) ? '<br />' : $context['preview_message'], '
+						</div>
+					</div>
+				</div>
+			</div><br />';
+
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
+		echo '
+			<input type="hidden" name="eventid" value="', $context['event']['id'], '" />';
+
+	// Start the main table.
+	echo '
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>
+			<div>
+				<div class="roundframe">', isset($context['current_topic']) ? '
+					<input type="hidden" name="topic" value="' . $context['current_topic'] . '" />' : '';
+
+	// If an error occurred, explain what happened.
+	echo '
+					<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
+						<dl>
+							<dt>
+								<strong id="error_serious">', $txt['error_while_submitting'], '</strong>
+							</dt>
+							<dd class="error" id="error_list">
+								', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
+							</dd>
+						</dl>
+					</div>';
+
+	// If this won't be approved let them know!
+	if (!$context['becomes_approved'])
+	{
+		echo '
+					<p class="information">
+						<em>', $txt['wait_for_approval'], '</em>
+						<input type="hidden" name="not_approved" value="1" />
+					</p>';
+	}
+
+	// If it's locked, show a message to warn the replyer.
+	echo '
+					<p class="information"', $context['locked'] ? '' : ' style="display: none"', ' id="lock_warning">
+						', $txt['topic_locked_no_reply'], '
+					</p>';
+
+	// The post header... important stuff
+	echo '
+					<dl id="post_header">';
+
+	// Guests have to put in their name and email...
+	if (isset($context['name']) && isset($context['email']))
+	{
+		echo '
+						<dt>
+							<span', isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '', ' id="caption_guestname">', $txt['name'], ':</span>
+						</dt>
+						<dd>
+							<input type="text" name="guestname" size="25" value="', $context['name'], '" tabindex="', $context['tabindex']++, '" class="input_text" />
+						</dd>';
+
+		if (empty($modSettings['guest_post_no_email']))
+			echo '
+						<dt>
+							<span', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '', ' id="caption_email">', $txt['email'], ':</span>
+						</dt>
+						<dd>
+							<input type="text" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" />
+						</dd>';
+	}
+
+	// Now show the subject box for this post.
+	echo '
+						<dt class="clear">
+							<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
+						</dt>
+						<dd>
+							<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80"', isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', '/>
+						</dd>
+						<dt class="clear_left">
+							', $txt['message_icon'], ':
+						</dt>
+						<dd>
+							<select name="icon" id="icon" onchange="showimage()">';
+
+	// Loop through each message icon allowed, adding it to the drop down list.
+	foreach ($context['icons'] as $icon)
+		echo '
+								<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected="selected"' : '', '>', $icon['name'], '</option>';
+
+	echo '
+							</select>
+							<img src="', $context['icon_url'], '" name="icons" hspace="15" alt="" />
+						</dd>
+					</dl><hr class="clear" />';
+
+	// Are you posting a calendar event?
+	if ($context['make_event'])
+	{
+		echo '
+					<div id="post_event">
+						<fieldset id="event_main">
+							<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', ' id="caption_evtitle">', $txt['calendar_event_title'], '</span></legend>
+							<input type="text" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '" class="input_text" />
+							<div class="smalltext" style="white-space: nowrap;">
+								<input type="hidden" name="calendar" value="1" />', $txt['calendar_year'], '
+								<select name="year" id="year" tabindex="', $context['tabindex']++, '" onchange="generateDays();">';
+
+		// Show a list of all the years we allow...
+		for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
+			echo '
+									<option value="', $year, '"', $year == $context['event']['year'] ? ' selected="selected"' : '', '>', $year, '&nbsp;</option>';
+
+		echo '
+								</select>
+								', $txt['calendar_month'], '
+								<select name="month" id="month" onchange="generateDays();">';
+
+		// There are 12 months per year - ensure that they all get listed.
+		for ($month = 1; $month <= 12; $month++)
+			echo '
+									<option value="', $month, '"', $month == $context['event']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '&nbsp;</option>';
+
+		echo '
+								</select>
+								', $txt['calendar_day'], '
+								<select name="day" id="day">';
+
+		// This prints out all the days in the current month - this changes dynamically as we switch months.
+		for ($day = 1; $day <= $context['event']['last_day']; $day++)
+			echo '
+									<option value="', $day, '"', $day == $context['event']['day'] ? ' selected="selected"' : '', '>', $day, '&nbsp;</option>';
+
+		echo '
+								</select>
+							</div>
+						</fieldset>';
+
+		if (!empty($modSettings['cal_allowspan']) || ($context['event']['new'] && $context['is_new_post']))
+		{
+			echo '
+						<fieldset id="event_options">
+							<legend>', $txt['calendar_event_options'], '</legend>
+							<div class="event_options smalltext">
+								<ul class="event_options">';
+
+			// If events can span more than one day then allow the user to select how long it should last.
+			if (!empty($modSettings['cal_allowspan']))
+			{
+				echo '
+									<li>
+										', $txt['calendar_numb_days'], '
+										<select name="span">';
+
+				for ($days = 1; $days <= $modSettings['cal_maxspan']; $days++)
+					echo '
+											<option value="', $days, '"', $days == $context['event']['span'] ? ' selected="selected"' : '', '>', $days, '&nbsp;</option>';
+
+				echo '
+										</select>
+									</li>';
+			}
+
+			// If this is a new event let the user specify which board they want the linked post to be put into.
+			if ($context['event']['new'] && $context['is_new_post'])
+			{
+				echo '
+									<li>
+										', $txt['calendar_post_in'], '
+										<select name="board">';
+				foreach ($context['event']['categories'] as $category)
+				{
+					echo '
+											<optgroup label="', $category['name'], '">';
+					foreach ($category['boards'] as $board)
+						echo '
+												<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
+					echo '
+											</optgroup>';
+				}
+				echo '
+										</select>
+									</li>';
+			}
+
+			echo '
+								</ul>
+							</div>
+						</fieldset>';
+		}
+
+		echo '
+					</div>';
+	}
+
+	// If this is a poll then display all the poll options!
+	if ($context['make_poll'])
+	{
+		echo '
+					<div id="edit_poll">
+						<fieldset id="poll_main">
+							<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], '</span></legend>
+							<input type="text" name="question" value="', isset($context['question']) ? $context['question'] : '', '" tabindex="', $context['tabindex']++, '" size="80" class="input_text" />
+							<ul class="poll_main">';
+
+		// Loop through all the choices and print them out.
+		foreach ($context['choices'] as $choice)
+		{
+			echo '
+								<li>
+									<label for="options-', $choice['id'], '">', $txt['option'], ' ', $choice['number'], '</label>:
+									<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="255" class="input_text" />
+								</li>';
+		}
+
+		echo '
+								<li id="pollMoreOptions"></li>
+							</ul>
+							<strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
+						</fieldset>
+						<fieldset id="poll_options">
+							<legend>', $txt['poll_options'], '</legend>
+							<dl class="settings poll_options">
+								<dt>
+									<label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
+								</dt>
+								<dd>
+									<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll_options']['max_votes'], '" class="input_text" />
+								</dd>
+								<dt>
+									<label for="poll_expire">', $txt['poll_run'], ':</label><br />
+									<em class="smalltext">', $txt['poll_run_limit'], '</em>
+								</dt>
+								<dd>
+									<input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll_options']['expire'], '" onchange="pollOptions();" maxlength="4" class="input_text" /> ', $txt['days_word'], '
+								</dd>
+								<dt>
+									<label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
+								</dt>
+								<dd>
+									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked="checked"' : '', ' class="input_check" />
+								</dd>';
+
+		if ($context['poll_options']['guest_vote_enabled'])
+			echo '
+								<dt>
+									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
+								</dt>
+								<dd>
+									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked="checked"' : '', ' class="input_check" />
+								</dd>';
+
+		echo '
+								<dt>
+									', $txt['poll_results_visibility'], ':
+								</dt>
+								<dd>
+									<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll_options']['hide'] == 0 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br />
+									<input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll_options']['hide'] == 1 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br />
+									<input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll_options']['hide'] == 2 ? ' checked="checked"' : '', empty($context['poll_options']['expire']) ? 'disabled="disabled"' : '', ' class="input_radio" /> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
+								</dd>
+							</dl>
+						</fieldset>
+					</div>';
+	}
+
+	// Show the actual posting area...
+	if ($context['show_bbc'])
+	{
+		echo '
+					<div id="bbcBox_message"></div>';
+	}
+
+	// What about smileys?
+	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
+		echo '
+					<div id="smileyBox_message"></div>';
+
+	echo '
+					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
+
+	// If this message has been edited in the past - display when it was.
+	if (isset($context['last_modified']))
+		echo '
+					<div class="padding smalltext">
+						<strong>', $txt['last_edit'], ':</strong>
+						', $context['last_modified'], '
+					</div>';
+
+	// If the admin has enabled the hiding of the additional options - show a link and image for it.
+	if (!empty($settings['additional_options_collapsable']))
+		echo '
+					<div id="postAdditionalOptionsHeader" class="title_bar">
+						<h4 class="titlebg">
+							<img id="postMoreExpand" class="panel_toggle" style="display: none;" src="', $settings['images_url'], '/collapse.png" alt="-" /> <strong><a href="#" id="postMoreExpandLink">', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
+						</h4>
+					</div>';
+
+	// Display the check boxes for all the standard options - if they are available to the user!
+	echo '
+					<div id="postMoreOptions" class="smalltext">
+						<ul class="post_options">
+							', $context['can_notify'] ? '<li><input type="hidden" name="notify" value="0" /><label for="check_notify"><input type="checkbox" name="notify" id="check_notify"' . ($context['notify'] || !empty($options['auto_notify']) ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['notify_replies'] . '</label></li>' : '', '
+							', $context['can_lock'] ? '<li><input type="hidden" name="lock" value="0" /><label for="check_lock"><input type="checkbox" name="lock" id="check_lock"' . ($context['locked'] ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['lock_topic'] . '</label></li>' : '', '
+							<li><label for="check_back"><input type="checkbox" name="goback" id="check_back"' . ($context['back_to_topic'] || !empty($options['return_to_post']) ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['back_to_topic'] . '</label></li>
+							', $context['can_sticky'] ? '<li><input type="hidden" name="sticky" value="0" /><label for="check_sticky"><input type="checkbox" name="sticky" id="check_sticky"' . ($context['sticky'] ? ' checked="checked"' : '') . ' value="1" class="input_check" /> ' . $txt['sticky_after'] . '</label></li>' : '', '
+							<li><label for="check_smileys"><input type="checkbox" name="ns" id="check_smileys"', $context['use_smileys'] ? '' : ' checked="checked"', ' value="NS" class="input_check" /> ', $txt['dont_use_smileys'], '</label></li>', '
+							', $context['can_move'] ? '<li><input type="hidden" name="move" value="0" /><label for="check_move"><input type="checkbox" name="move" id="check_move" value="1" class="input_check" ' . (!empty($context['move']) ? 'checked="checked" ' : '') . '/> ' . $txt['move_after2'] . '</label></li>' : '', '
+							', $context['can_announce'] && $context['is_first_post'] ? '<li><label for="check_announce"><input type="checkbox" name="announce_topic" id="check_announce" value="1" class="input_check" ' . (!empty($context['announce']) ? 'checked="checked" ' : '') . '/> ' . $txt['announce_topic'] . '</label></li>' : '', '
+							', $context['show_approval'] ? '<li><label for="approve"><input type="checkbox" name="approve" id="approve" value="2" class="input_check" ' . ($context['show_approval'] === 2 ? 'checked="checked"' : '') . ' /> ' . $txt['approve_this_post'] . '</label></li>' : '', '
+						</ul>
+					</div>';
+
+	// If this post already has attachments on it - give information about them.
+	if (!empty($context['current_attachments']))
+	{
+		echo '
+					<dl id="postAttachment">
+						<dt>
+							', $txt['attached'], ':
+						</dt>
+						<dd class="smalltext">
+							<input type="hidden" name="attach_del[]" value="0" />
+							', $txt['uncheck_unwatchd_attach'], ':
+						</dd>';
+		foreach ($context['current_attachments'] as $attachment)
+			echo '
+						<dd class="smalltext">
+							<label for="attachment_', $attachment['id'], '"><input type="checkbox" id="attachment_', $attachment['id'], '" name="attach_del[]" value="', $attachment['id'], '"', empty($attachment['unchecked']) ? ' checked="checked"' : '', ' class="input_check" /> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
+							!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
+						</dd>';
+
+		if (!empty($context['files_in_session_warning']))
+			echo '
+						<dd class="smalltext">', $context['files_in_session_warning'], '</dd>';
+
+		echo '
+					</dl>';
+	}
+
+	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
+	if ($context['can_post_attachment'])
+	{
+		echo '
+					<dl id="postAttachment2">';
+		
+		// But, only show them if they haven't reached a limit. Or a mod author hasn't hidden them.
+		if ($context['num_allowed_attachments'] > 0 || !empty($context['dont_show_them']))
+		{
+			echo '
+						<dt>
+							', $txt['attach'], ':
+						</dt>
+						<dd class="smalltext">
+							', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '" />'), '
+							<input type="file" size="60" name="attachment[]" id="attachment1" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
+
+			// Show more boxes if they aren't approaching that limit.
+			if ($context['num_allowed_attachments'] > 1)
+				echo '
+							<script type="text/javascript"><!-- // --><![CDATA[
+								var allowed_attachments = ', $context['num_allowed_attachments'], ';
+								var current_attachment = 1;
+
+								function addAttachment()
+								{
+									allowed_attachments = allowed_attachments - 1;
+									current_attachment = current_attachment + 1;
+									if (allowed_attachments <= 0)
+										return alert("', $txt['more_attachments_error'], '");
+
+									setOuterHTML(document.getElementById("moreAttachments"), \'<dd class="smalltext"><input type="file" size="60" name="attachment[]" id="attachment\' + current_attachment + \'" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\\\'attachment\' + current_attachment + \'\\\');">', $txt['clean_attach'], '<\/a>)\' + \'<\/dd><dd class="smalltext" id="moreAttachments"><a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')<\' + \'/a><\' + \'/dd>\');
+
+									return true;
+								}
+							// ]]></script>
+						</dd>
+						<dd class="smalltext" id="moreAttachments"><a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')</a></dd>';
+			else
+				echo '
+						</dd>';
+		}
+
+		// Add any template changes for an alternative upload system here.
+		call_integration_hook('integrate_upload_template', array());
+
+		echo '
+						<dd class="smalltext">';
+
+		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
+		if (!empty($modSettings['attachmentCheckExtensions']))
+			echo '
+							', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br />';
+
+		if (!empty($context['attachment_restrictions']))
+			echo '
+							', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br />';
+
+		if ($context['num_allowed_attachments'] == 0)
+			echo '
+							', $txt['attach_limit_nag'], '<br />';
+
+		if (!$context['can_post_attachment_unapproved'])
+			echo '
+							<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br />';
+
+		echo '
+						</dd>
+					</dl>';
+	}
+
+	// Is visual verification enabled?
+	if ($context['require_verification'])
+	{
+		echo '
+					<div class="post_verification">
+						<span', !empty($context['post_error']['need_qr_verification']) ? ' class="error"' : '', '>
+							<strong>', $txt['verification'], ':</strong>
+						</span>
+						', template_control_verification($context['visual_verification_id'], 'all'), '
+					</div>';
+	}
+
+	// Finally, the submit buttons.
+	echo '
+					<hr class="hrcolor" />
+					<span class="smalltext" >
+						', isBrowser('is_firefox') ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '
+					</span>
+					<span id="post_confirm_buttons">
+						', template_control_richedit_buttons($context['post_box_name']);
+
+	// Option to delete an event if user is editing one.
+	if ($context['make_event'] && !$context['event']['new'])
+		echo '
+						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" onclick="return confirm(\'', $txt['event_delete_confirm'], '\');" class="button_submit" />';
+
+	echo '
+					</span>
+					<br class="clear_right" />
+				</div>
+			</div>
+			<br class="clear" />';
+
+	// Assuming this isn't a new topic pass across the last message id.
+	if (isset($context['topic_last_message']))
+		echo '
+			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '" />';
+
+	echo '
+			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '" />
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
+		</form>';
+
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[';
+
+	// The functions used to preview a posts without loading a new page.
+	echo '
+			var current_board = ', empty($context['current_board']) ? 'null' : $context['current_board'], ';
+			var make_poll = ', $context['make_poll'] ? 'true' : 'false', ';
+			var txt_preview_title = "', $txt['preview_title'], '";
+			var txt_preview_fetch = "', $txt['preview_fetch'], '";
+			var new_replies = new Array();
+			var reply_counter = ', empty($counter) ? 0 : $counter, ';
+			function previewPost()
+			{';
+	if (isBrowser('is_firefox'))
+		echo '
+				// Firefox doesn\'t render <marquee> that have been put it using javascript
+				if (document.forms.postmodify.elements[', JavaScriptEscape($context['post_box_name']), '].value.indexOf(\'[move]\') != -1)
+				{
+					return submitThisOnce(document.forms.postmodify);
+				}';
+	echo '
+				if (window.XMLHttpRequest)
+				{
+					// Opera didn\'t support setRequestHeader() before 8.01.
+					if (\'opera\' in window)
+					{
+						var test = new XMLHttpRequest();
+						if (!(\'setRequestHeader\' in test))
+							return submitThisOnce(document.forms.postmodify);
+					}
+					// @todo Currently not sending poll options and option checkboxes.
+					var x = new Array();
+					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'icon\', \'guestname\', \'email\', \'evtitle\', \'question\', \'topic\'];
+					var numericFields = [
+						\'board\', \'topic\', \'last_msg\',
+						\'eventid\', \'calendar\', \'year\', \'month\', \'day\',
+						\'poll_max_votes\', \'poll_expire\', \'poll_change_vote\', \'poll_hide\'
+					];
+					var checkboxFields = [
+						\'ns\'
+					];
+
+					for (var i = 0, n = textFields.length; i < n; i++)
+						if (textFields[i] in document.forms.postmodify)
+						{
+							// Handle the WYSIWYG editor.
+							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
+								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
+							else
+								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
+						}
+					for (var i = 0, n = numericFields.length; i < n; i++)
+						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
+							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
+					for (var i = 0, n = checkboxFields.length; i < n; i++)
+						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
+							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
+
+					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=post2\' + (current_board ? \';board=\' + current_board : \'\') + (make_poll ? \';poll\' : \'\') + \';preview;xml\', x.join(\'&\'), onDocSent);
+
+					document.getElementById(\'preview_section\').style.display = \'\';
+					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
+					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
+
+					return false;
+				}
+				else
+					return submitThisOnce(document.forms.postmodify);
+			}
+			function onDocSent(XMLDoc)
+			{
+				if (!XMLDoc)
+				{
+					document.forms.postmodify.preview.onclick = new function ()
+					{
+						return true;
+					}
+					document.forms.postmodify.preview.click();
+				}
+
+				// Show the preview section.
+				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
+				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
+
+				var bodyText = \'\';
+				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
+					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
+
+				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
+				document.getElementById(\'preview_body\').className = \'post\';
+
+				// Show a list of errors (if any).
+				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
+				var errorList = new Array();
+				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
+					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
+				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
+				document.getElementById(\'errors\').className = errors.getAttribute(\'serious\') == 1 ? \'errorbox\' : \'noticebox\';
+				document.getElementById(\'error_serious\').style.display = numErrors == 0 ? \'none\' : \'\';
+				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
+
+				// Show a warning if the topic has been locked.
+				document.getElementById(\'lock_warning\').style.display = errors.getAttribute(\'topic_locked\') == 1 ? \'\' : \'none\';
+
+				// Adjust the color of captions if the given data is erroneous.
+				var captions = errors.getElementsByTagName(\'caption\');
+				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
+					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
+						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
+
+				if (errors.getElementsByTagName(\'post_error\').length == 1)
+					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
+				else if (document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
+				{
+					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
+						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
+					else
+						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
+				}
+
+				// Set the new last message id.
+				if (\'last_msg\' in document.forms.postmodify)
+					document.forms.postmodify.last_msg.value = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'last_msg\')[0].firstChild.nodeValue;
+
+				// Remove the new image from old-new replies!
+				for (i = 0; i < new_replies.length; i++)
+					document.getElementById(\'image_new_\' + new_replies[i]).style.display = \'none\';
+				new_replies = new Array();
+
+				var ignored_replies = new Array(), ignoring;
+				var newPosts = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'new_posts\')[0] ? XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'new_posts\')[0].getElementsByTagName(\'post\') : {length: 0};
+				var numNewPosts = newPosts.length;
+				if (numNewPosts != 0)
+				{
+					var newPostsHTML = \'<span id="new_replies"><\' + \'/span>\';
+					for (var i = 0; i < numNewPosts; i++)
+					{
+						new_replies[new_replies.length] = newPosts[i].getAttribute("id");
+
+						ignoring = false;
+						if (newPosts[i].getElementsByTagName("is_ignored")[0].firstChild.nodeValue != 0)
+							ignored_replies[ignored_replies.length] = ignoring = newPosts[i].getAttribute("id");
+
+						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \' core_posts"><div class="content" id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
+
+	if ($context['can_quote'])
+		echo '
+						newPostsHTML += \'<ul class="reset smalltext quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>',$txt['bbc_quote'],'</span><\' + \'/a></li></ul>\';';
+
+	echo '
+						newPostsHTML += \'<br class="clear" />\';
+
+						if (ignoring)
+							newPostsHTML += \'<div id="msg_\' + newPosts[i].getAttribute("id") + \'_ignored_prompt" class="smalltext">', $txt['ignoring_user'], '<a href="#" id="msg_\' + newPosts[i].getAttribute("id") + \'_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a></div>\';
+
+						newPostsHTML += \'<div class="list_posts smalltext" id="msg_\' + newPosts[i].getAttribute("id") + \'_body">\' + newPosts[i].getElementsByTagName("message")[0].firstChild.nodeValue + \'<\' + \'/div></div></div>\';
+					}
+					setOuterHTML(document.getElementById(\'new_replies\'), newPostsHTML);
+				}
+
+				var numIgnoredReplies = ignored_replies.length;
+				if (numIgnoredReplies != 0)
+				{
+					for (var i = 0; i < numIgnoredReplies; i++)
+					{
+						aIgnoreToggles[ignored_replies[i]] = new smc_Toggle({
+							bToggleEnabled: true,
+							bCurrentlyCollapsed: true,
+							aSwappableContainers: [
+								\'msg_\' + ignored_replies[i] + \'_body\',
+								\'msg_\' + ignored_replies[i] + \'_quote\',
+							],
+							aSwapLinks: [
+								{
+									sId: \'msg_\' + ignored_replies[i] + \'_ignored_link\',
+									msgExpanded: \'\',
+									msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
+								}
+							]
+						});
+					}
+				}
+
+				location.hash = \'#\' + \'preview_section\';
+
+				if (typeof(smf_codeFix) != \'undefined\')
+					smf_codeFix();
+			}';
+
+	// Code for showing and hiding additional options.
+	if (!empty($settings['additional_options_collapsable']))
+		echo '
+			var oSwapAdditionalOptions = new smc_Toggle({
+				bToggleEnabled: true,
+				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
+				funcOnBeforeCollapse: function () {
+					document.getElementById(\'additional_options\').value = \'0\';
+				},
+				funcOnBeforeExpand: function () {
+					document.getElementById(\'additional_options\').value = \'1\';
+				},
+				aSwappableContainers: [
+					\'postMoreOptions\',
+					\'postAttachment\',
+					\'postAttachment2\',
+					\'postAttachment3\'
+				],
+				aSwapImages: [
+					{
+						sId: \'postMoreExpand\',
+						srcExpanded: smf_images_url + \'/collapse.png\',
+						altExpanded: \'-\',
+						srcCollapsed: smf_images_url + \'/expand.png\',
+						altCollapsed: \'+\'
+					}
+				],
+				aSwapLinks: [
+					{
+						sId: \'postMoreExpandLink\',
+						msgExpanded: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), ',
+						msgCollapsed: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), '
+					}
+				]
+			});';
+
+	echo '
+		// ]]></script>';
+
+	// If the user is replying to a topic show the previous posts.
+	if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
+	{
+		echo '
+		<div id="recent" class="flow_hidden main_section">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['topic_summary'], '</h3>
+			</div>
+			<span id="new_replies"></span>';
+
+		$ignored_posts = array();
+		foreach ($context['previous_posts'] as $post)
+		{
+			$ignoring = false;
+			if (!empty($post['is_ignored']))
+				$ignored_posts[] = $ignoring = $post['id'];
+
+			echo '
+				<div class="', $post['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
+				<div class="content" id="msg', $post['id'], '">
+					<div class="floatleft">
+						<h5>', $txt['posted_by'], ': ', $post['poster'], '</h5>
+						<span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> ', $post['time'], '&nbsp;&#187;</span>
+					</div>';
+
+			if ($context['can_quote'])
+			{
+				echo '
+					<ul class="reset smalltext quickbuttons" id="msg_', $post['id'], '_quote">
+						<li><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');" class="quote_button"><span>',$txt['bbc_quote'],'</span></a></li>
+					</ul>';
+			}
+
+			echo '
+					<br class="clear" />';
+
+			if ($ignoring)
+			{
+				echo '
+					<div id="msg_', $post['id'], '_ignored_prompt" class="smalltext">
+						', $txt['ignoring_user'], '
+						<a href="#" id="msg_', $post['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
+					</div>';
+			}
+
+			echo '
+					<div class="list_posts smalltext" id="msg_', $post['id'], '_body">', $post['message'], '</div>
+				</div>
+			</div>';
+		}
+
+		echo '
+		</div>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var aIgnoreToggles = new Array();';
+
+		foreach ($ignored_posts as $post_id)
+		{
+			echo '
+			aIgnoreToggles[', $post_id, '] = new smc_Toggle({
+				bToggleEnabled: true,
+				bCurrentlyCollapsed: true,
+				aSwappableContainers: [
+					\'msg_', $post_id, '_body\',
+					\'msg_', $post_id, '_quote\',
+				],
+				aSwapLinks: [
+					{
+						sId: \'msg_', $post_id, '_ignored_link\',
+						msgExpanded: \'\',
+						msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
+					}
+				]
+			});';
+		}
+
+		echo '
+			function insertQuoteFast(messageid)
+			{
+				if (window.XMLHttpRequest)
+					getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';xml;pb=', $context['post_box_name'], ';mode=\' + (oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled ? 1 : 0), onDocReceived);
+				else
+					reqWin(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';pb=', $context['post_box_name'], ';mode=\' + (oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled ? 1 : 0), 240, 90);
+				return true;
+			}
+			function onDocReceived(XMLDoc)
+			{
+				var text = \'\';
+				for (var i = 0, n = XMLDoc.getElementsByTagName(\'quote\')[0].childNodes.length; i < n; i++)
+					text += XMLDoc.getElementsByTagName(\'quote\')[0].childNodes[i].nodeValue;
+				oEditorHandle_', $context['post_box_name'], '.insertText(text, false, true);
+			}
+		// ]]></script>';
+	}
+}
+
+// The template for the spellchecker.
+function template_spellcheck()
+{
+	global $context, $settings, $options, $txt;
+
+	// The style information that makes the spellchecker look... like the forum hopefully!
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<title>', $txt['spell_check'], '</title>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
+		<style type="text/css">
+			body, td
+			{
+				font-size: small;
+				margin: 0;
+				background: #f0f0f0;
+				color: #000;
+				padding: 10px;
+			}
+			.highlight
+			{
+				color: red;
+				font-weight: bold;
+			}
+			#spellview
+			{
+				border-style: outset;
+				border: 1px solid black;
+				padding: 5px;
+				width: 95%;
+				height: 314px;
+				overflow: auto;
+				background: #ffffff;
+			}';
+
+	// As you may expect - we need a lot of javascript for this... load it form the separate files.
+	echo '
+		</style>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var spell_formname = window.opener.spell_formname;
+			var spell_fieldname = window.opener.spell_fieldname;
+		// ]]></script>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/spellcheck.js"></script>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			', $context['spell_js'], '
+		// ]]></script>
+	</head>
+	<body onload="nextWord(false);">
+		<form action="#" method="post" accept-charset="', $context['character_set'], '" name="spellingForm" id="spellingForm" onsubmit="return false;" style="margin: 0;">
+			<div id="spellview">&nbsp;</div>
+			<table border="0" cellpadding="4" cellspacing="0" width="100%"><tr class="windowbg">
+				<td width="50%" valign="top">
+					', $txt['spellcheck_change_to'], '<br />
+					<input type="text" name="changeto" style="width: 98%;" class="input_text" />
+				</td>
+				<td width="50%">
+					', $txt['spellcheck_suggest'], '<br />
+					<select name="suggestions" style="width: 98%;" size="5" onclick="if (this.selectedIndex != -1) this.form.changeto.value = this.options[this.selectedIndex].text;" ondblclick="replaceWord();">
+					</select>
+				</td>
+			</tr></table>
+			<div class="righttext" style="padding: 4px;">
+				<input type="button" name="change" value="', $txt['spellcheck_change'], '" onclick="replaceWord();" class="button_submit" />
+				<input type="button" name="changeall" value="', $txt['spellcheck_change_all'], '" onclick="replaceAll();" class="button_submit" />
+				<input type="button" name="ignore" value="', $txt['spellcheck_ignore'], '" onclick="nextWord(false);" class="button_submit" />
+				<input type="button" name="ignoreall" value="', $txt['spellcheck_ignore_all'], '" onclick="nextWord(true);" class="button_submit" />
+			</div>
+		</form>
+	</body>
+</html>';
+}
+
+function template_quotefast()
+{
+	global $context, $settings, $options, $txt;
+
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<title>', $txt['retrieving_quote'], '</title>
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
+	</head>
+	<body>
+		', $txt['retrieving_quote'], '
+		<div id="temporary_posting_area" style="display: none;"></div>
+		<script type="text/javascript"><!-- // --><![CDATA[';
+
+	if ($context['close_window'])
+		echo '
+			window.close();';
+	else
+	{
+		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
+		echo '
+			var quote = \'', $context['quote']['text'], '\';
+			var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");
+
+			if (\'DOMParser\' in window && !(\'opera\' in window))
+			{
+				var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
+				quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
+			}
+			else if (\'innerText\' in stage)
+			{
+				setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
+				quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
+			}
+
+			if (\'opera\' in window)
+				quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");
+
+			window.opener.oEditorHandle_', $context['post_box_name'], '.InsertText(quote);
+
+			window.focus();
+			setTimeout("window.close();", 400);';
+	}
+	echo '
+		// ]]></script>
+	</body>
+</html>';
+}
+
+function template_announce()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="announcement">
+		<form action="', $scripturl, '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['announce_title'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['announce_desc'], '
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<p>
+						', $txt['announce_this_topic'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0">', $context['topic_subject'], '</a>
+					</p>
+					<ul class="reset">';
+
+	foreach ($context['groups'] as $group)
+		echo '
+						<li>
+							<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked="checked" class="input_check" /> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
+						</li>';
+
+	echo '
+						<li>
+							<label for="checkall"><input type="checkbox" id="checkall" class="input_check" onclick="invertAll(this, this.form);" checked="checked" /> <em>', $txt['check_all'], '</em></label>
+						</li>
+					</ul>
+					<hr class="hrcolor" />
+					<div id="confirm_buttons">
+						<input type="submit" value="', $txt['post'], '" class="button_submit" />
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="topic" value="', $context['current_topic'], '" />
+						<input type="hidden" name="move" value="', $context['move'], '" />
+						<input type="hidden" name="goback" value="', $context['go_back'], '" />
+					</div>
+				</div>
+				<br class="clear_right" />
+			</div>
+		</form>
+	</div>
+	<br />';
+}
+
+function template_announcement_send()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="announcement">
+		<form action="' . $scripturl . '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
+			<div class="windowbg2">
+				<div class="content">
+					<p>', $txt['announce_sending'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0" target="_blank" class="new_win">', $context['topic_subject'], '</a></p>
+					<div class="progress_bar">
+						<div class="full_bar">', $context['percentage_done'], '% ', $txt['announce_done'], '</div>
+						<div class="green_percent" style="width: ', $context['percentage_done'], '%;">&nbsp;</div>
+					</div>
+					<hr class="hrcolor" />
+					<div id="confirm_buttons">
+						<input type="submit" name="b" value="', $txt['announce_continue'], '" class="button_submit" />
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="topic" value="', $context['current_topic'], '" />
+						<input type="hidden" name="move" value="', $context['move'], '" />
+						<input type="hidden" name="goback" value="', $context['go_back'], '" />
+						<input type="hidden" name="start" value="', $context['start'], '" />
+						<input type="hidden" name="membergroups" value="', $context['membergroups'], '" />
+					</div>
+				</div>
+				<br class="clear_right" />
+			</div>
+		</form>
+	</div>
+	<br />
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var countdown = 2;
+			doAutoSubmit();
+
+			function doAutoSubmit()
+			{
+				if (countdown == 0)
+					document.forms.autoSubmit.submit();
+				else if (countdown == -1)
+					return;
+
+				document.forms.autoSubmit.b.value = "', $txt['announce_continue'], ' (" + countdown + ")";
+				countdown--;
+
+				setTimeout("doAutoSubmit();", 1000);
+			}
+		// ]]></script>';
+}
+
 ?>

+ 2966 - 3012
Themes/default/Profile.template.php

@@ -1,3013 +1,2967 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Template for the profile side bar - goes before any other profile template.
-function template_profile_above()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/profile.js"></script>';
-
-	// Prevent Chrome from auto completing fields when viewing/editing other members profiles
-	if (isBrowser('is_chrome') && !$context['user']['is_owner'])
-		echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		disableAutoComplete();
-	// ]]></script>';
-
-	// If an error occurred while trying to save previously, give the user a clue!
-	echo '
-					', template_error_message();
-
-	// If the profile was update successfully, let the user know this.
-	if (!empty($context['profile_updated']))
-		echo '
-					<div class="infobox">
-						', $context['profile_updated'], '
-					</div>';
-}
-
-// Template for closing off table started in profile_above.
-function template_profile_below()
-{
-}
-
-// This template displays users details without any option to edit them.
-function template_summary()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// Display the basic information about the user
-	echo '
-<div id="profileview" class="flow_auto">
-	<div class="cat_bar">
-		<h3 class="catbg">
-			<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['summary'], '</span>
-		</h3>
-	</div>
-	<div id="basicinfo">
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content flow_auto">
-				<div class="username"><h4>', $context['member']['name'], ' <span class="position">', (!empty($context['member']['group']) ? $context['member']['group'] : $context['member']['post_group']), '</span></h4></div>
-				', $context['member']['avatar']['image'], '
-				<ul class="reset">';
-	// @TODO fix the <ul> when no fields are visible
-	// What about if we allow email only via the forum??
-	if ($context['member']['show_email'] === 'yes' || $context['member']['show_email'] === 'no_through_forum' || $context['member']['show_email'] === 'yes_permission_override' && $context['can_send_email'])
-		echo '
-					<li><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $context['member']['id'], '" title="', $context['member']['show_email'] == 'yes' || $context['member']['show_email'] == 'yes_permission_override' ? $context['member']['email'] : '', '" rel="nofollow"><img src="', $settings['images_url'], '/email_sm.png" alt="', $txt['email'], '" /></a></li>';
-
-	// Don't show an icon if they haven't specified a website.
-	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website']))
-		echo '
-					<li><a href="', $context['member']['website']['url'], '" title="' . $context['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/www_sm.png" alt="' . $context['member']['website']['title'] . '" />' : $txt['www']), '</a></li>';
-
-	// Are there any custom profile fields for the summary?
-	if (!empty($context['custom_fields']))
-	{
-		foreach ($context['custom_fields'] as $field)
-			if (($field['placement'] == 1 || empty($field['output_html'])) && !empty($field['value']))
-				echo '
-					<li class="custom_field">', $field['output_html'], '</li>';
-	}
-
-	echo '
-				', !isset($context['disabled_fields']['icq']) && !empty($context['member']['icq']['link']) ? '<li>' . $context['member']['icq']['link'] . '</li>' : '', '
-				', !isset($context['disabled_fields']['msn']) && !empty($context['member']['msn']['link']) ? '<li>' . $context['member']['msn']['link'] . '</li>' : '', '
-				', !isset($context['disabled_fields']['aim']) && !empty($context['member']['aim']['link']) ? '<li>' . $context['member']['aim']['link'] . '</li>' : '', '
-				', !isset($context['disabled_fields']['yim']) && !empty($context['member']['yim']['link']) ? '<li>' . $context['member']['yim']['link'] . '</li>' : '', '
-			</ul>
-			<span id="userstatus">', $context['can_send_pm'] ? '<a href="' . $context['member']['online']['href'] . '" title="' . $context['member']['online']['label'] . '" rel="nofollow">' : '', $settings['use_image_buttons'] ? '<img src="' . $context['member']['online']['image_href'] . '" alt="' . $context['member']['online']['text'] . '" class="centericon" />' : $context['member']['online']['text'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? '<span class="smalltext"> ' . $context['member']['online']['text'] . '</span>' : '';
-
-	// Can they add this member as a buddy?
-	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner'])
-		echo '
-				<br /><a href="', $scripturl, '?action=buddy;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($context['member']['is_buddy'] ? 'remove' : 'add')], ']</a>';
-
-	echo '
-				</span>';
-
-	echo '
-				<p id="infolinks">';
-
-	if (!$context['user']['is_owner'] && $context['can_send_pm'])
-		echo '
-					<a href="', $scripturl, '?action=pm;sa=send;u=', $context['id_member'], '">', $txt['profile_sendpm_short'], '</a><br />';
-	echo '
-					<a href="', $scripturl, '?action=profile;area=showposts;u=', $context['id_member'], '">', $txt['showPosts'], '</a><br />
-					<a href="', $scripturl, '?action=profile;area=statistics;u=', $context['id_member'], '">', $txt['statPanel'], '</a>
-				</p>';
-
-	echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<div id="detailedinfo">
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl>';
-
-	if ($context['user']['is_owner'] || $context['user']['is_admin'])
-		echo '
-					<dt>', $txt['username'], ': </dt>
-					<dd>', $context['member']['username'], '</dd>';
-
-	if (!isset($context['disabled_fields']['posts']))
-		echo '
-					<dt>', $txt['profile_posts'], ': </dt>
-					<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';
-
-	if ($context['can_send_email'])
-	{
-		// Only show the email address fully if it's not hidden - and we reveal the email.
-		if ($context['member']['show_email'] == 'yes')
-			echo '
-						<dt>', $txt['email'], ': </dt>
-						<dd><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $context['member']['id'], '">', $context['member']['email'], '</a></dd>';
-
-		// ... Or if the one looking at the profile is an admin they can see it anyway.
-		elseif ($context['member']['show_email'] == 'yes_permission_override')
-			echo '
-						<dt>', $txt['email'], ': </dt>
-						<dd><em><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $context['member']['id'], '">', $context['member']['email'], '</a></em></dd>';
-	}
-
-	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title']))
-		echo '
-					<dt>', $txt['custom_title'], ': </dt>
-					<dd>', $context['member']['title'], '</dd>';
-
-	if (!empty($context['member']['blurb']))
-		echo '
-					<dt>', $txt['personal_text'], ': </dt>
-					<dd>', $context['member']['blurb'], '</dd>';
-
-	// If karma enabled show the members karma.
-	if ($modSettings['karmaMode'] == '1')
-		echo '
-					<dt>', $modSettings['karmaLabel'], ' </dt>
-					<dd>', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '</dd>';
-
-	elseif ($modSettings['karmaMode'] == '2')
-		echo '
-					<dt>', $modSettings['karmaLabel'], ' </dt>
-					<dd>+', $context['member']['karma']['good'], '/-', $context['member']['karma']['bad'], '</dd>';
-
-	if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
-		echo '
-					<dt>', $txt['gender'], ': </dt>
-					<dd>', $context['member']['gender']['name'], '</dd>';
-
-	echo '
-					<dt>', $txt['age'], ':</dt>
-					<dd>', $context['member']['age'] . ($context['member']['today_is_birthday'] ? ' &nbsp; <img src="' . $settings['images_url'] . '/cake.png" alt="" />' : ''), '</dd>';
-
-	if (!isset($context['disabled_fields']['location']) && !empty($context['member']['location']))
-		echo '
-					<dt>', $txt['location'], ':</dt>
-					<dd>', $context['member']['location'], '</dd>';
-
-	echo '
-				</dl>';
-
-	// Any custom fields for standard placement?
-	if (!empty($context['custom_fields']))
-	{
-		$shown = false;
-		foreach ($context['custom_fields'] as $field)
-		{
-			if ($field['placement'] != 0 || empty($field['output_html']))
-				continue;
-
-			if (empty($shown))
-			{
-				echo '
-				<dl>';
-				$shown = true;
-			}
-
-			echo '
-					<dt>', $field['name'], ':</dt>
-					<dd>', $field['output_html'], '</dd>';
-		}
-
-		if (!empty($shown))
-			echo '
-				</dl>';
-	}
-
-	echo '
-				<dl class="noborder">';
-
-	// Can they view/issue a warning?
-	if ($context['can_view_warning'] && $context['member']['warning'])
-	{
-		echo '
-					<dt>', $txt['profile_warning_level'], ': </dt>
-					<dd>
-						<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=', $context['can_issue_warning'] ? 'issuewarning' : 'viewwarning', '">', $context['member']['warning'], '%</a>';
-
-		// Can we provide information on what this means?
-		if (!empty($context['warning_status']))
-			echo '
-						<span class="smalltext">(', $context['warning_status'], ')</span>';
-
-		echo '
-					</dd>';
-	}
-
-	// Is this member requiring activation and/or banned?
-	if (!empty($context['activate_message']) || !empty($context['member']['bans']))
-	{
-
-		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
-		if (!empty($context['activate_message']))
-			echo '
-					<dt class="clear"><span class="alert">', $context['activate_message'], '</span>&nbsp;(<a href="' . $scripturl . '?action=profile;save;area=activateaccount;u=' . $context['id_member'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '"', ($context['activate_type'] == 4 ? ' onclick="return confirm(\'' . $txt['profileConfirm'] . '\');"' : ''), '>', $context['activate_link_text'], '</a>)</dt>';
-
-		// If the current member is banned, show a message and possibly a link to the ban.
-		if (!empty($context['member']['bans']))
-		{
-			echo '
-					<dt class="clear"><span class="alert">', $txt['user_is_banned'], '</span>&nbsp;[<a href="#" onclick="document.getElementById(\'ban_info\').style.display = document.getElementById(\'ban_info\').style.display == \'none\' ? \'\' : \'none\';return false;">' . $txt['view_ban'] . '</a>]</dt>
-					<dt class="clear" id="ban_info" style="display: none;">
-						<strong>', $txt['user_banned_by_following'], ':</strong>';
-
-			foreach ($context['member']['bans'] as $ban)
-				echo '
-						<br /><span class="smalltext">', $ban['explanation'], '</span>';
-
-			echo '
-					</dt>';
-		}
-	}
-
-	echo '
-					<dt>', $txt['date_registered'], ': </dt>
-					<dd>', $context['member']['registered'], '</dd>';
-
-	// If the person looking is allowed, they can check the members IP address and hostname.
-	if ($context['can_see_ip'])
-	{
-		if (!empty($context['member']['ip']))
-		echo '
-					<dt>', $txt['ip'], ': </dt>
-					<dd><a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip'], '</a></dd>';
-
-		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip']))
-			echo '
-					<dt>', $txt['hostname'], ': </dt>
-					<dd>', $context['member']['hostname'], '</dd>';
-	}
-
-	echo '
-					<dt>', $txt['local_time'], ':</dt>
-					<dd>', $context['member']['local_time'], '</dd>';
-
-	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language']))
-		echo '
-					<dt>', $txt['language'], ':</dt>
-					<dd>', $context['member']['language'], '</dd>';
-
-	echo '
-					<dt>', $txt['lastLoggedIn'], ': </dt>
-					<dd>', $context['member']['last_login'], '</dd>
-				</dl>';
-
-	// Are there any custom profile fields for the summary?
-	if (!empty($context['custom_fields']))
-	{
-		$shown = false;
-		foreach ($context['custom_fields'] as $field)
-		{
-			if ($field['placement'] != 2 || empty($field['output_html']))
-				continue;
-			if (empty($shown))
-			{
-				$shown = true;
-				echo '
-				<div class="custom_fields_above_signature">
-					<ul class="reset nolist">';
-			}
-			echo '
-						<li>', $field['output_html'], '</li>';
-		}
-		if ($shown)
-				echo '
-					</ul>
-				</div>';
-	}
-
-	// Show the users signature.
-	if ($context['signature_enabled'] && !empty($context['member']['signature']))
-		echo '
-				<div class="signature">
-					<h5>', $txt['signature'], ':</h5>
-					', $context['member']['signature'], '
-				</div>';
-
-	echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-<div class="clear"></div>
-</div>';
-}
-
-// Template for showing all the posts of the user, in chronological order.
-function template_showPosts()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', (!isset($context['attachments']) && empty($context['is_topics']) ? $txt['showMessages'] : (!empty($context['is_topics']) ? $txt['showTopics'] : $txt['showAttachments'])), ' - ', $context['member']['name'], '
-			</h3>
-		</div>
-		<div class="pagesection">
-			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
-		</div>';
-
-	// Button shortcuts
-	$quote_button = create_button('quote.png', 'reply_quote', 'quote', 'class="centericon"');
-	$reply_button = create_button('reply_sm.png', 'reply', 'reply', 'class="centericon"');
-	$remove_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
-	$notify_button = create_button('notify_sm.png', 'notify_replies', 'notify', 'class="centericon"');
-
-	// Are we displaying posts or attachments?
-	if (!isset($context['attachments']))
-	{
-		// For every post to be displayed, give it its own div, and show the important details of the post.
-		foreach ($context['posts'] as $post)
-		{
-			echo '
-		<div class="topic">
-			<div class="', $post['alternate'] == 0 ? 'windowbg2' : 'windowbg', ' core_posts">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<div class="counter">', $post['counter'], '</div>
-					<div class="topic_details">
-						<h5><strong><a href="', $scripturl, '?board=', $post['board']['id'], '.0">', $post['board']['name'], '</a> / <a href="', $scripturl, '?topic=', $post['topic'], '.', $post['start'], '#msg', $post['id'], '">', $post['subject'], '</a></strong></h5>
-						<span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> ', $post['time'], '&nbsp;&#187;</span>
-					</div>
-					<div class="list_posts">';
-
-			if (!$post['approved'])
-				echo '
-					<div class="approve_post">
-						<em>', $txt['post_awaiting_approval'], '</em>
-					</div>';
-
-			echo '
-					', $post['body'], '
-					</div>
-				</div>';
-
-			if ($post['can_reply'] || $post['can_mark_notify'] || $post['can_delete'])
-				echo '
-				<div class="floatright">
-					<ul class="reset smalltext quickbuttons">';
-
-			// If they *can* reply?
-			if ($post['can_reply'])
-				echo '
-						<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '" class="reply_button"><span>', $txt['reply'], '</span></a></li>';
-
-			// If they *can* quote?
-			if ($post['can_quote'])
-				echo '
-						<li><a href="', $scripturl . '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '" class="quote_button"><span>', $txt['quote'], '</span></a></li>';
-
-			// Can we request notification of topics?
-			if ($post['can_mark_notify'])
-				echo '
-						<li><a href="', $scripturl, '?action=notify;topic=', $post['topic'], '.', $post['start'], '" class="notify_button"><span>', $txt['notify'], '</span></a></li>';
-
-			// How about... even... remove it entirely?!
-			if ($post['can_delete'])
-				echo '
-						<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';profile;u=', $context['member']['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['remove_message'], '?\');" class="remove_button"><span>', $txt['remove'], '</span></a></li>';
-
-			if ($post['can_reply'] || $post['can_mark_notify'] || $post['can_delete'])
-				echo '
-					</ul>
-				</div>';
-
-			echo '
-				<br class="clear" />
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>';
-		}
-	}
-	else
-	{
-		echo '
-		<table border="0" width="100%" cellspacing="1" cellpadding="2" class="table_grid" align="center">
-			<thead>
-				<tr class="titlebg">
-					<th class="first_th lefttext" scope="col" width="25%">
-						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=filename', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'filename' ? ';asc' : ''), '">
-							', $txt['show_attach_filename'], '
-							', ($context['sort_order'] == 'filename' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
-						</a>
-					</th>
-					<th scope="col" width="12%">
-						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=downloads', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'downloads' ? ';asc' : ''), '">
-							', $txt['show_attach_downloads'], '
-							', ($context['sort_order'] == 'downloads' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
-						</a>
-					</th>
-					<th class="lefttext" scope="col" width="30%">
-						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=subject', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'subject' ? ';asc' : ''), '">
-							', $txt['message'], '
-							', ($context['sort_order'] == 'subject' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
-						</a>
-					</th>
-					<th class="last_th lefttext" scope="col">
-						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=posted', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'posted' ? ';asc' : ''), '">
-						', $txt['show_attach_posted'], '
-						', ($context['sort_order'] == 'posted' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
-						</a>
-					</th>
-				</tr>
-			</thead>
-			<tbody>';
-
-		// Looks like we need to do all the attachments instead!
-		$alternate = false;
-		foreach ($context['attachments'] as $attachment)
-		{
-			echo '
-				<tr class="', $attachment['approved'] ? ($alternate ? 'windowbg' : 'windowbg2') : 'approvebg', '">
-					<td><a href="', $scripturl, '?action=dlattach;topic=', $attachment['topic'], '.0;attach=', $attachment['id'], '">',	$attachment['filename'], '</a>', !$attachment['approved'] ? '&nbsp;<em>(' . $txt['awaiting_approval'] . ')</em>' : '', '</td>
-					<td align="center">', $attachment['downloads'], '</td>
-					<td><a href="', $scripturl, '?topic=', $attachment['topic'], '.msg', $attachment['msg'], '#msg', $attachment['msg'], '" rel="nofollow">', $attachment['subject'], '</a></td>
-					<td>', $attachment['posted'], '</td>
-				</tr>';
-			$alternate = !$alternate;
-		}
-
-	// No posts? Just end the table with a informative message.
-	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts'])))
-		echo '
-				<tr>
-					<td class="tborder windowbg2 padding centertext" colspan="4">
-						', isset($context['attachments']) ? $txt['show_attachments_none'] : ($context['is_topics'] ? $txt['show_topics_none'] : $txt['show_posts_none']), '
-					</td>
-				</tr>';
-
-		echo '
-			</tbody>
-		</table>';
-	}
-	// Show more page numbers.
-	echo '
-		<div class="pagesection" style="margin-bottom: 0;">
-			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
-		</div>';
-}
-
-// Template for showing all the buddies of the current user.
-function template_editBuddies()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
-	$buddy_fields = array('icq', 'aim', 'yim', 'msn');
-
-	echo '
-		<div class="title_bar">
-			<h3 class="titlebg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/online.png" alt="" class="icon" />', $txt['editBuddies'], '</span>
-			</h3>
-		</div>
-		<table border="0" width="100%" cellspacing="1" cellpadding="4" class="table_grid" align="center">
-			<tr class="catbg">
-				<th class="first_th" scope="col" width="20%">', $txt['name'], '</th>
-				<th scope="col">', $txt['status'], '</th>';
-	if ($context['can_send_email'])
-		echo '
-				<th scope="col">', $txt['email'], '</th>';
-
-	// don't show them if they are disabled
-	foreach ($buddy_fields as $key => $column)
-	{
-		if (!isset($disabled_fields[$column]))
-			echo '
-				<th scope="col">', $txt[$column], '</th>';
-	}
-
-	echo '
-				<th class="last_th" scope="col"></th>
-			</tr>';
-
-	// If they don't have any buddies don't list them!
-	if (empty($context['buddies']))
-		echo '
-			<tr class="windowbg2">
-				<td colspan="8" align="center"><strong>', $txt['no_buddies'], '</strong></td>
-			</tr>';
-
-	// Now loop through each buddy showing info on each.
-	$alternate = false;
-	foreach ($context['buddies'] as $buddy)
-	{
-		echo '
-			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
-				<td>', $buddy['link'], '</td>
-				<td align="center"><a href="', $buddy['online']['href'], '"><img src="', $buddy['online']['image_href'], '" alt="', $buddy['online']['label'], '" title="', $buddy['online']['label'], '" /></a></td>';
-		if ($context['can_send_email'])
-			echo '
-				<td align="center">', ($buddy['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $buddy['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $buddy['name'] . '" /></a>'), '</td>';
-
-		// If these are off, don't show them
-		foreach ($buddy_fields as $key => $column)
-		{
-			if (!isset($disabled_fields[$column]))
-				echo '
-					<td align="center">', $buddy[$column]['link'], '</td>';
-		}
-
-		echo '
-				<td align="center"><a href="', $scripturl, '?action=profile;area=lists;sa=buddies;u=', $context['id_member'], ';remove=', $buddy['id'], ';', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/icons/delete.png" alt="', $txt['buddy_remove'], '" title="', $txt['buddy_remove'], '" /></a></td>
-			</tr>';
-
-		$alternate = !$alternate;
-	}
-
-	echo '
-		</table>';
-
-	// Add a new buddy?
-	echo '
-	<br />
-	<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=buddies" method="post" accept-charset="', $context['character_set'], '">
-		<div class="tborder add_buddy">
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['buddy_add'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<dl class="settings">
-					<dt>
-						<label for="new_buddy"><strong>', $txt['who_member'], ':</strong></label>
-					</dt>
-					<dd>
-						<input type="text" name="new_buddy" id="new_buddy" size="30" class="input_text" />
-					</dd>
-				</dl>';
-
-	if (!empty($context['token_check']))
-		echo '
-				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	echo '
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="submit" value="', $txt['buddy_add_button'], '" class="button_submit" />
-				<br class="clear_right" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-	</form>
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oAddBuddySuggest = new smc_AutoSuggest({
-			sSelf: \'oAddBuddySuggest\',
-			sSessionId: smf_session_id,
-			sSessionVar: smf_session_var,
-			sSuggestId: \'new_buddy\',
-			sControlId: \'new_buddy\',
-			sSearchType: \'member\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			bItemList: false
-		});
-	// ]]></script>';
-}
-
-// Template for showing the ignore list of the current user.
-function template_editIgnoreList()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-		<div class="title_bar">
-			<h3 class="titlebg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['editIgnoreList'], '</span>
-			</h3>
-		</div>
-		<table border="0" width="100%" cellspacing="1" cellpadding="4" class="table_grid" align="center">
-			<tr class="catbg">
-				<th class="first_th" scope="col" width="20%">', $txt['name'], '</th>
-				<th scope="col">', $txt['status'], '</th>';
-	if ($context['can_send_email'])
-		echo '
-				<th scope="col">', $txt['email'], '</th>';
-	echo '
-				<th scope="col">', $txt['icq'], '</th>
-				<th scope="col">', $txt['aim'], '</th>
-				<th scope="col">', $txt['yim'], '</th>
-				<th scope="col">', $txt['msn'], '</th>
-				<th class="last_th" scope="col"></th>
-			</tr>';
-
-	// If they don't have anyone on their ignore list, don't list it!
-	if (empty($context['ignore_list']))
-		echo '
-			<tr class="windowbg2">
-				<td colspan="8" align="center"><strong>', $txt['no_ignore'], '</strong></td>
-			</tr>';
-
-	// Now loop through each buddy showing info on each.
-	$alternate = false;
-	foreach ($context['ignore_list'] as $member)
-	{
-		echo '
-			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
-				<td>', $member['link'], '</td>
-				<td align="center"><a href="', $member['online']['href'], '"><img src="', $member['online']['image_href'], '" alt="', $member['online']['label'], '" title="', $member['online']['label'], '" /></a></td>';
-		if ($context['can_send_email'])
-			echo '
-				<td align="center">', ($member['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $member['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $member['name'] . '" /></a>'), '</td>';
-		echo '
-				<td align="center">', $member['icq']['link'], '</td>
-				<td align="center">', $member['aim']['link'], '</td>
-				<td align="center">', $member['yim']['link'], '</td>
-				<td align="center">', $member['msn']['link'], '</td>
-				<td align="center"><a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/icons/delete.png" alt="', $txt['ignore_remove'], '" title="', $txt['ignore_remove'], '" /></a></td>
-			</tr>';
-
-		$alternate = !$alternate;
-	}
-
-	echo '
-		</table>';
-
-	// Add to the ignore list?
-	echo '
-	<br />
-	<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore" method="post" accept-charset="', $context['character_set'], '">
-		<div class="tborder add_buddy">
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['ignore_add'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<dl class="settings">
-					<dt>
-						<label for="new_buddy"><strong>', $txt['who_member'], ':</strong></label>
-					</dt>
-					<dd>
-						<input type="text" name="new_ignore" id="new_ignore" size="25" class="input_text" />
-					</dd>
-				</dl>';
-
-	if (!empty($context['token_check']))
-		echo '
-				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	echo '
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="submit" value="', $txt['ignore_add_button'], '" class="button_submit" />
-				<br class="clear_right" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-	</form>
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-	<script type="text/javascript"><!-- // --><![CDATA[
-		var oAddIgnoreSuggest = new smc_AutoSuggest({
-			sSelf: \'oAddIgnoreSuggest\',
-			sSessionId: \'', $context['session_id'], '\',
-			sSessionVar: \'', $context['session_var'], '\',
-			sSuggestId: \'new_ignore\',
-			sControlId: \'new_ignore\',
-			sSearchType: \'member\',
-			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
-			bItemList: false
-		});
-	// ]]></script>';
-}
-
-// This template shows an admin information on a users IP addresses used and errors attributed to them.
-function template_trackActivity()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// The first table shows IP information about the user.
-	echo '
-			<div class="title_bar">
-				<h3 class="titlebg"><strong>', $txt['view_ips_by'], ' ', $context['member']['name'], '</strong></h3>
-			</div>';
-
-	// The last IP the user used.
-	echo '
-			<div id="tracking" class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="noborder">
-						<dt>', $txt['most_recent_ip'], ':
-							', (empty($context['last_ip2']) ? '' : '<br />
-							<span class="smalltext">(<a href="' . $scripturl . '?action=helpadmin;help=whytwoip" onclick="return reqWin(this.href);">' . $txt['why_two_ip_address'] . '</a>)</span>'), '
-						</dt>
-						<dd>
-							<a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
-
-	// Second address detected?
-	if (!empty($context['last_ip2']))
-		echo '
-							, <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip2'], ';u=', $context['member']['id'], '">', $context['last_ip2'], '</a>';
-
-	echo '
-						</dd>';
-
-	// Lists of IP addresses used in messages / error messages.
-	echo '
-						<dt>', $txt['ips_in_messages'], ':</dt>
-						<dd>
-							', (count($context['ips']) > 0 ? implode(', ', $context['ips']) : '(' . $txt['none'] . ')'), '
-						</dd>
-						<dt>', $txt['ips_in_errors'], ':</dt>
-						<dd>
-							', (count($context['ips']) > 0 ? implode(', ', $context['error_ips']) : '(' . $txt['none'] . ')'), '
-						</dd>';
-
-	// List any members that have used the same IP addresses as the current member.
-	echo '
-						<dt>', $txt['members_in_range'], ':</dt>
-						<dd>
-							', (count($context['members_in_range']) > 0 ? implode(', ', $context['members_in_range']) : '(' . $txt['none'] . ')'), '
-						</dd>
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br class="clear" />';
-
-	// Show the track user list.
-	template_show_list('track_user_list');
-}
-
-// The template for trackIP, allowing the admin to see where/who a certain IP has been used.
-function template_trackIP()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// This function always defaults to the last IP used by a member but can be set to track any IP.
-	// The first table in the template gives an input box to allow the admin to enter another IP to track.
-	echo '
-	<div class="tborder">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['trackIP'], '</h3>
-		</div>
-		<span class="upperframe"><span></span></span>
-		<div class="roundframe">
-			<form action="', $context['base_url'], '" method="post" accept-charset="', $context['character_set'], '">
-				<dl class="settings">
-					<dt>
-						<label for="searchip"><strong>', $txt['enter_ip'], ':</strong></label>
-					</dt>
-					<dd>
-						<input type="text" name="searchip" value="', $context['ip'], '" class="input_text" />
-					</dd>
-				</dl>
-				<input type="submit" value="', $txt['trackIP'], '" class="button_submit" />
-				<br class="clear_right" />
-			</form>
-		</div>
-		<span class="lowerframe"><span></span></span>
-	</div>
-	<br class="clear" />';
-
-	// The table inbetween the first and second table shows links to the whois server for every region.
-	if ($context['single_ip'])
-	{
-		echo '
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['whois_title'], ' ', $context['ip'], '</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="padding">';
-			foreach ($context['whois_servers'] as $server)
-				echo '
-					<a href="', $server['url'], '" target="_blank" class="new_win"', isset($context['auto_whois_server']) && $context['auto_whois_server']['name'] == $server['name'] ? ' style="font-weight: bold;"' : '', '>', $server['name'], '</a><br />';
-			echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		<br class="clear" />';
-	}
-
-	// The second table lists all the members who have been logged as using this IP address.
-	echo '
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['members_from_ip'], ' ', $context['ip'], '</h3>
-		</div>';
-	if (empty($context['ips']))
-		echo '
-		<p class="windowbg2 description"><em>', $txt['no_members_from_ip'], '</em></p>';
-	else
-	{
-		echo '
-		<table class="table_grid" cellspacing="0" width="100%">
-			<thead>
-				<tr class="catbg">
-					<th class="first_th" scope="col">', $txt['ip_address'], '</th>
-					<th class="last_th" scope="col">', $txt['display_name'], '</th>
-				</tr>
-			</thead>
-			<tbody>';
-
-		// Loop through each of the members and display them.
-		foreach ($context['ips'] as $ip => $memberlist)
-			echo '
-				<tr>
-					<td class="windowbg2"><a href="', $context['base_url'], ';searchip=', $ip, '">', $ip, '</a></td>
-					<td class="windowbg2">', implode(', ', $memberlist), '</td>
-				</tr>';
-
-		echo '
-			</tbody>
-		</table>
-		<br />';
-	}
-
-	template_show_list('track_message_list');
-
-	echo '<br />';
-
-	template_show_list('track_user_list');
-}
-
-function template_showPermissions()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['showPermissions'], '</span>
-			</h3>
-		</div>';
-
-	if ($context['member']['has_all_permissions'])
-	{
-		echo '
-		<p class="windowbg description">', $txt['showPermissions_all'], '</p>';
-	}
-	else
-	{
-		echo '
-		<p class="description">',$txt['showPermissions_help'],'</p>
-		<div id="permissions" class="flow_hidden">';
-
-		if (!empty($context['no_access_boards']))
-		{
-			echo '
-				<div class="cat_bar">
-					<h3 class="catbg">', $txt['showPermissions_restricted_boards'], '</h3>
-				</div>
-				<div class="windowbg smalltext">
-					<span class="topslice"><span></span></span>
-					<div class="content">', $txt['showPermissions_restricted_boards_desc'], ':<br />';
-				foreach ($context['no_access_boards'] as $no_access_board)
-					echo '
-						<a href="', $scripturl, '?board=', $no_access_board['id'], '.0">', $no_access_board['name'], '</a>', $no_access_board['is_last'] ? '' : ', ';
-				echo '
-					</div>
-					<span class="botslice"><span></span></span>
-				</div>';
-		}
-
-		// General Permissions section.
-		echo '
-				<div class="tborder">
-					<div class="cat_bar">
-						<h3 class="catbg">', $txt['showPermissions_general'], '</h3>
-					</div>';
-		if (!empty($context['member']['permissions']['general']))
-		{
-			echo '
-					<table class="table_grid" width="100%" cellspacing="0">
-						<thead>
-							<tr class="titlebg">
-								<th class="lefttext first_th" scope="col" width="50%">', $txt['showPermissions_permission'], '</th>
-								<th class="lefttext last_th" scope="col" width="50%">', $txt['showPermissions_status'], '</th>
-							</tr>
-						</thead>
-						<tbody>';
-
-			foreach ($context['member']['permissions']['general'] as $permission)
-			{
-				echo '
-							<tr>
-								<td class="windowbg" title="', $permission['id'], '">
-									', $permission['is_denied'] ? '<del>' . $permission['name'] . '</del>' : $permission['name'], '
-								</td>
-								<td class="windowbg2 smalltext">';
-
-				if ($permission['is_denied'])
-					echo '
-									<span class="alert">', $txt['showPermissions_denied'], ':&nbsp;', implode(', ', $permission['groups']['denied']),'</span>';
-				else
-					echo '
-									', $txt['showPermissions_given'], ':&nbsp;', implode(', ', $permission['groups']['allowed']);
-
-					echo '
-								</td>
-							</tr>';
-			}
-			echo '
-						</tbody>
-					</table>
-				</div><br />';
-		}
-		else
-			echo '
-			<p class="windowbg2 description">', $txt['showPermissions_none_general'], '</p>';
-
-		// Board permission section.
-		echo '
-			<div class="tborder">
-				<form action="' . $scripturl . '?action=profile;u=', $context['id_member'], ';area=permissions#board_permissions" method="post" accept-charset="', $context['character_set'], '">
-					<div class="cat_bar">
-						<h3 class="catbg"><span class="ie6_header floatleft">
-							<a id="board_permissions"></a>', $txt['showPermissions_select'], ':
-							<select name="board" onchange="if (this.options[this.selectedIndex].value) this.form.submit();">
-								<option value="0"', $context['board'] == 0 ? ' selected="selected"' : '', '>', $txt['showPermissions_global'], '&nbsp;</option>';
-				if (!empty($context['boards']))
-					echo '
-								<option value="" disabled="disabled">---------------------------</option>';
-
-				// Fill the box with any local permission boards.
-				foreach ($context['boards'] as $board)
-					echo '
-								<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['name'], ' (', $board['profile_name'], ')</option>';
-
-				echo '
-							</select></span>
-						</h3>
-					</div>
-				</form>';
-		if (!empty($context['member']['permissions']['board']))
-		{
-			echo '
-				<table class="table_grid" width="100%" cellspacing="0">
-					<thead>
-						<tr class="titlebg">
-							<th class="lefttext first_th" scope="col" width="50%">', $txt['showPermissions_permission'], '</th>
-							<th class="lefttext last_th" scope="col" width="50%">', $txt['showPermissions_status'], '</th>
-						</tr>
-					</thead>
-					<tbody>';
-			foreach ($context['member']['permissions']['board'] as $permission)
-			{
-				echo '
-						<tr>
-							<td class="windowbg" title="', $permission['id'], '">
-								', $permission['is_denied'] ? '<del>' . $permission['name'] . '</del>' : $permission['name'], '
-							</td>
-							<td class="windowbg2 smalltext">';
-
-				if ($permission['is_denied'])
-				{
-					echo '
-								<span class="alert">', $txt['showPermissions_denied'], ':&nbsp;', implode(', ', $permission['groups']['denied']), '</span>';
-				}
-				else
-				{
-					echo '
-								', $txt['showPermissions_given'], ': &nbsp;', implode(', ', $permission['groups']['allowed']);
-				}
-				echo '
-							</td>
-						</tr>';
-			}
-			echo '
-					</tbody>
-				</table>';
-		}
-		else
-			echo '
-			<p class="windowbg2 description">', $txt['showPermissions_none_board'], '</p>';
-	echo '
-			</div>
-		</div>';
-	}
-}
-
-// Template for user statistics, showing graphs and the like.
-function template_statPanel()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// First, show a few text statistics such as post/topic count.
-	echo '
-	<div id="profileview">
-		<div id="generalstats">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/stats_info.png" alt="" class="icon" />
-					', $txt['statPanel_generalStats'], ' - ', $context['member']['name'], '
-					</span>
-				</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl>
-						<dt>', $txt['statPanel_total_time_online'], ':</dt>
-						<dd>', $context['time_logged_in'], '</dd>
-						<dt>', $txt['statPanel_total_posts'], ':</dt>
-						<dd>', $context['num_posts'], ' ', $txt['statPanel_posts'], '</dd>
-						<dt>', $txt['statPanel_total_topics'], ':</dt>
-						<dd>', $context['num_topics'], ' ', $txt['statPanel_topics'], '</dd>
-						<dt>', $txt['statPanel_users_polls'], ':</dt>
-						<dd>', $context['num_polls'], ' ', $txt['statPanel_polls'], '</dd>
-						<dt>', $txt['statPanel_users_votes'], ':</dt>
-						<dd>', $context['num_votes'], ' ', $txt['statPanel_votes'], '</dd>
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>';
-
-	// This next section draws a graph showing what times of day they post the most.
-	echo '
-		<div id="activitytime" class="flow_hidden">
-			<div class="cat_bar">
-				<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/stats_history.png" alt="" class="icon" />', $txt['statPanel_activityTime'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	// If they haven't post at all, don't draw the graph.
-	if (empty($context['posts_by_time']))
-		echo '
-					<span class="centertext">', $txt['statPanel_noPosts'], '</span>';
-	// Otherwise do!
-	else
-	{
-		echo '
-					<ul class="activity_stats flow_hidden">';
-
-		// The labels.
-		foreach ($context['posts_by_time'] as $time_of_day)
-		{
-			echo '
-						<li', $time_of_day['is_last'] ? ' class="last"' : '', '>
-							<div class="bar" style="padding-top: ', ((int) (100 - $time_of_day['relative_percent'])), 'px;" title="', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '">
-								<div style="height: ', (int) $time_of_day['relative_percent'], 'px;">
-									<span>', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '</span>
-								</div>
-							</div>
-							<span class="stats_hour">', $time_of_day['hour_format'], '</span>
-						</li>';
-		}
-
-		echo '
-
-					</ul>';
-	}
-
-	echo '
-					<span class="clear" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>';
-
-	// Two columns with the most popular boards by posts and activity (activity = users posts / total posts).
-	echo '
-		<div class="flow_hidden">
-			<div id="popularposts">
-				<div class="cat_bar">
-					<h3 class="catbg">
-						<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/stats_replies.png" alt="" class="icon" />', $txt['statPanel_topBoards'], '</span>
-					</h3>
-				</div>
-				<div class="windowbg2">
-					<span class="topslice"><span></span></span>
-					<div class="content">';
-
-	if (empty($context['popular_boards']))
-		echo '
-						<span class="centertext">', $txt['statPanel_noPosts'], '</span>';
-
-	else
-	{
-		echo '
-						<dl>';
-
-		// Draw a bar for every board.
-		foreach ($context['popular_boards'] as $board)
-		{
-			echo '
-							<dt>', $board['link'], '</dt>
-							<dd>
-								<div class="profile_pie" style="background-position: -', ((int) ($board['posts_percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_memberposts'], $board['posts'], $board['total_posts_member'], $board['posts_percent']), '">
-									', sprintf($txt['statPanel_topBoards_memberposts'], $board['posts'], $board['total_posts_member'], $board['posts_percent']), '
-								</div>
-								<span>', empty($context['hide_num_posts']) ? $board['posts'] : '', '</span>
-							</dd>';
-		}
-
-		echo '
-						</dl>';
-	}
-	echo '
-					</div>
-					<span class="botslice"><span></span></span>
-				</div>
-			</div>';
-	echo '
-			<div id="popularactivity">
-				<div class="cat_bar">
-					<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/stats_replies.png" alt="" class="icon" />', $txt['statPanel_topBoardsActivity'], '</span>
-					</h3>
-				</div>
-				<div class="windowbg2">
-					<span class="topslice"><span></span></span>
-					<div class="content">';
-
-	if (empty($context['board_activity']))
-		echo '
-						<span>', $txt['statPanel_noPosts'], '</span>';
-	else
-	{
-		echo '
-						<dl>';
-
-		// Draw a bar for every board.
-		foreach ($context['board_activity'] as $activity)
-		{
-			echo '
-							<dt>', $activity['link'], '</dt>
-							<dd>
-								<div class="profile_pie" style="background-position: -', ((int) ($activity['percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '">
-									', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '
-								</div>
-								<span>', $activity['percent'], '%</span>
-							</dd>';
-		}
-
-		echo '
-						</dl>';
-	}
-	echo '
-					</div>
-					<span class="botslice"><span></span></span>
-				</div>
-			</div>
-		</div>';
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-// Template for editing profile options.
-function template_edit_options()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// The main header!
-	echo '
-		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : $scripturl . '?action=profile;area=' . $context['menu_item_selected'] . ';u=' . $context['id_member']), '" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data" onsubmit="return checkProfileSubmit();">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />';
-
-		// Don't say "Profile" if this isn't the profile...
-		if (!empty($context['profile_header_text']))
-			echo '
-					', $context['profile_header_text'];
-		else
-			echo '
-					', $txt['profile'];
-
-		echo '
-					</span>
-				</h3>
-			</div>';
-
-	// Have we some description?
-	if ($context['page_desc'])
-		echo '
-			<p class="windowbg description">', $context['page_desc'], '</p>';
-
-	echo '
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	// Any bits at the start?
-	if (!empty($context['profile_prehtml']))
-		echo '
-					<div>', $context['profile_prehtml'], '</div>';
-
-	if (!empty($context['profile_fields']))
-		echo '
-					<dl>';
-
-	// Start the big old loop 'of love.
-	$lastItem = 'hr';
-	foreach ($context['profile_fields'] as $key => $field)
-	{
-		// We add a little hack to be sure we never get more than one hr in a row!
-		if ($lastItem == 'hr' && $field['type'] == 'hr')
-			continue;
-
-		$lastItem = $field['type'];
-		if ($field['type'] == 'hr')
-		{
-			echo '
-					</dl>
-					<hr width="100%" size="1" class="hrcolor clear" />
-					<dl>';
-		}
-		elseif ($field['type'] == 'callback')
-		{
-			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
-			{
-				$callback_func = 'template_profile_' . $field['callback_func'];
-				$callback_func();
-			}
-		}
-		else
-		{
-			echo '
-						<dt>
-							<strong', !empty($field['is_error']) ? ' class="error"' : '', '>', $field['type'] !== 'label' ? '<label for="' . $key . '">' : '', $field['label'], $field['type'] !== 'label' ? '</label>' : '', '</strong>';
-
-			// Does it have any subtext to show?
-			if (!empty($field['subtext']))
-				echo '
-							<br />
-							<span class="smalltext">', $field['subtext'], '</span>';
-
-			echo '
-						</dt>
-						<dd>';
-
-			// Want to put something infront of the box?
-			if (!empty($field['preinput']))
-				echo '
-							', $field['preinput'];
-
-			// What type of data are we showing?
-			if ($field['type'] == 'label')
-				echo '
-							', $field['value'];
-
-			// Maybe it's a text box - very likely!
-			elseif (in_array($field['type'], array('int', 'float', 'text', 'password')))
-				echo '
-							<input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' class="input_', $field['type'] == 'password' ? 'password' : 'text', '" />';
-
-			// You "checking" me out? ;)
-			elseif ($field['type'] == 'check')
-				echo '
-							<input type="hidden" name="', $key, '" value="0" /><input type="checkbox" name="', $key, '" id="', $key, '" ', !empty($field['value']) ? ' checked="checked"' : '', ' value="1" class="input_check" ', $field['input_attr'], ' />';
-
-			// Always fun - select boxes!
-			elseif ($field['type'] == 'select')
-			{
-				echo '
-							<select name="', $key, '" id="', $key, '">';
-
-				if (isset($field['options']))
-				{
-					// Is this some code to generate the options?
-					if (!is_array($field['options']))
-						$field['options'] = eval($field['options']);
-					// Assuming we now have some!
-					if (is_array($field['options']))
-						foreach ($field['options'] as $value => $name)
-							echo '
-								<option value="', $value, '" ', $value == $field['value'] ? 'selected="selected"' : '', '>', $name, '</option>';
-				}
-
-				echo '
-							</select>';
-			}
-
-			// Something to end with?
-			if (!empty($field['postinput']))
-				echo '
-							', $field['postinput'];
-
-			echo '
-						</dd>';
-		}
-	}
-
-	if (!empty($context['profile_fields']))
-		echo '
-					</dl>';
-
-	// Are there any custom profile fields - if so print them!
-	if (!empty($context['custom_fields']))
-	{
-		if ($lastItem != 'hr')
-			echo '
-					<hr width="100%" size="1" class="hrcolor clear" />';
-
-		echo '
-					<dl>';
-
-		foreach ($context['custom_fields'] as $field)
-		{
-			echo '
-						<dt>
-							<strong>', $field['name'], ': </strong><br />
-							<span class="smalltext">', $field['desc'], '</span>
-						</dt>
-						<dd>
-							', $field['input_html'], '
-						</dd>';
-		}
-
-		echo '
-					</dl>';
-
-	}
-
-	// Any closing HTML?
-	if (!empty($context['profile_posthtml']))
-		echo '
-					<div>', $context['profile_posthtml'], '</div>';
-
-	// Only show the password box if it's actually needed.
-	if ($context['require_password'])
-		echo '
-					<dl>
-						<dt>
-							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '><label for="oldpasswrd">', $txt['current_password'], ': </label></strong><br />
-							<span class="smalltext">', $txt['required_security_reasons'], '</span>
-						</dt>
-						<dd>
-							<input type="password" name="oldpasswrd" id="oldpasswrd" size="20" style="margin-right: 4ex;" class="input_password" />
-						</dd>
-					</dl>';
-
-	echo '
-					<hr class="hrcolor" />';
-
-	// The button shouldn't say "Change profile" unless we're changing the profile...
-	if (!empty($context['submit_button_text']))
-		echo '
-					<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button_submit" />';
-	else
-		echo '
-					<input type="submit" name="save" value="', $txt['change_profile'], '" class="button_submit" />';
-
-	if (!empty($context['token_check']))
-		echo '
-					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="u" value="', $context['id_member'], '" />
-					<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />
-		</form>';
-
-	// Some javascript!
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			function checkProfileSubmit()
-			{';
-
-	// If this part requires a password, make sure to give a warning.
-	if ($context['require_password'])
-		echo '
-				// Did you forget to type your password?
-				if (document.forms.creator.oldpasswrd.value == "")
-				{
-					alert("', $txt['required_security_reasons'], '");
-					return false;
-				}';
-
-	// Any onsubmit javascript?
-	if (!empty($context['profile_onsubmit_javascript']))
-		echo '
-				', $context['profile_javascript'];
-
-	echo '
-			}';
-
-	// Any totally custom stuff?
-	if (!empty($context['profile_javascript']))
-		echo '
-			', $context['profile_javascript'];
-
-	echo '
-		// ]]></script>';
-
-	// Any final spellchecking stuff?
-	if (!empty($context['show_spellchecking']))
-		echo '
-		<form name="spell_form" id="spell_form" method="post" accept-charset="', $context['character_set'], '" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spellstring" value="" /></form>';
-}
-
-// Personal Message settings.
-function template_profile_pm_settings()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-								<dt>
-									<label for="pm_prefs">', $txt['pm_display_mode'], ':</label>
-								</dt>
-								<dd>
-									<select name="pm_prefs" id="pm_prefs" onchange="if (this.value == 2 &amp;&amp; !document.getElementById(\'copy_to_outbox\').checked) alert(\'', $txt['pm_recommend_enable_outbox'], '\');">
-										<option value="0"', $context['display_mode'] == 0 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_all'], '</option>
-										<option value="1"', $context['display_mode'] == 1 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_one'], '</option>
-										<option value="2"', $context['display_mode'] == 2 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_linked'], '</option>
-									</select>
-								</dd>
-								<dt>
-									<label for="view_newest_pm_first">', $txt['recent_pms_at_top'], '</label>
-								</dt>
-								<dd>
-										<input type="hidden" name="default_options[view_newest_pm_first]" value="0" />
-										<input type="checkbox" name="default_options[view_newest_pm_first]" id="view_newest_pm_first" value="1"', !empty($context['member']['options']['view_newest_pm_first']) ? ' checked="checked"' : '', ' class="input_check" />
-								</dd>
-						</dl>
-						<hr />
-						<dl>
-								<dt>
-										<label for="pm_receive_from">', $txt['pm_receive_from'], '</label>
-								</dt>
-								<dd>
-										<select name="pm_receive_from" id="pm_receive_from">
-												<option value="0"', empty($context['receive_from']) || (empty($modSettings['enable_buddylist']) && $context['receive_from'] < 3) ? ' selected="selected"' : '', '>', $txt['pm_receive_from_everyone'], '</option>';
-
-	if (!empty($modSettings['enable_buddylist']))
-		echo '
-												<option value="1"', !empty($context['receive_from']) && $context['receive_from'] == 1 ? ' selected="selected"' : '', '>', $txt['pm_receive_from_ignore'], '</option>
-												<option value="2"', !empty($context['receive_from']) && $context['receive_from'] == 2 ? ' selected="selected"' : '', '>', $txt['pm_receive_from_buddies'], '</option>';
-
-	echo '
-												<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected="selected"' : '', '>', $txt['pm_receive_from_admins'], '</option>
-										</select>
-								</dd>
-								<dt>
-										<label for="pm_email_notify">', $txt['email_notify'], '</label>
-								</dt>
-								<dd>
-										<select name="pm_email_notify" id="pm_email_notify">
-												<option value="0"', empty($context['send_email']) ? ' selected="selected"' : '', '>', $txt['email_notify_never'], '</option>
-												<option value="1"', !empty($context['send_email']) && ($context['send_email'] == 1 || (empty($modSettings['enable_buddylist']) && $context['send_email'] > 1)) ? ' selected="selected"' : '', '>', $txt['email_notify_always'], '</option>';
-
-	if (!empty($modSettings['enable_buddylist']))
-		echo '
-												<option value="2"', !empty($context['send_email']) && $context['send_email'] > 1 ? ' selected="selected"' : '', '>', $txt['email_notify_buddies'], '</option>';
-
-	echo '
-										</select>
-								</dd>
-								<dt>
-										<label for="popup_messages">', $txt['popup_messages'], '</label>
-								</dt>
-								<dd>
-										<input type="hidden" name="default_options[popup_messages]" value="0" />
-										<input type="checkbox" name="default_options[popup_messages]" id="popup_messages" value="1"', !empty($context['member']['options']['popup_messages']) ? ' checked="checked"' : '', ' class="input_check" />
-								</dd>
-						</dl>
-						<hr />
-						<dl>
-								<dt>
-										<label for="copy_to_outbox"> ', $txt['copy_to_outbox'], '</label>
-								</dt>
-								<dd>
-										<input type="hidden" name="default_options[copy_to_outbox]" value="0" />
-										<input type="checkbox" name="default_options[copy_to_outbox]" id="copy_to_outbox" value="1"', !empty($context['member']['options']['copy_to_outbox']) ? ' checked="checked"' : '', ' class="input_check" />
-								</dd>
-								<dt>
-										<label for="pm_remove_inbox_label">', $txt['pm_remove_inbox_label'], '</label>
-								</dt>
-								<dd>
-										<input type="hidden" name="default_options[pm_remove_inbox_label]" value="0" />
-										<input type="checkbox" name="default_options[pm_remove_inbox_label]" id="pm_remove_inbox_label" value="1"', !empty($context['member']['options']['pm_remove_inbox_label']) ? ' checked="checked"' : '', ' class="input_check" />
-								</dd>';
-
-}
-
-// Template for showing theme settings. Note: template_options() actually adds the theme specific options.
-function template_profile_theme_settings()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	echo '
-							<dt>
-								<label for="show_board_desc">', $txt['board_desc_inside'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[show_board_desc]" value="0" />
-								<input type="checkbox" name="default_options[show_board_desc]" id="show_board_desc" value="1"', !empty($context['member']['options']['show_board_desc']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-							<dt>
-								<label for="show_children">', $txt['show_children'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[show_children]" value="0" />
-								<input type="checkbox" name="default_options[show_children]" id="show_children" value="1"', !empty($context['member']['options']['show_children']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-							<dt>
-								<label for="use_sidebar_menu">', $txt['use_sidebar_menu'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[use_sidebar_menu]" value="0" />
-								<input type="checkbox" name="default_options[use_sidebar_menu]" id="use_sidebar_menu" value="1"', !empty($context['member']['options']['use_sidebar_menu']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-							<dt>
-								<label for="show_no_avatars">', $txt['show_no_avatars'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[show_no_avatars]" value="0" />
-								<input type="checkbox" name="default_options[show_no_avatars]" id="show_no_avatars" value="1"', !empty($context['member']['options']['show_no_avatars']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-							<dt>
-								<label for="show_no_signatures">', $txt['show_no_signatures'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[show_no_signatures]" value="0" />
-								<input type="checkbox" name="default_options[show_no_signatures]" id="show_no_signatures" value="1"', !empty($context['member']['options']['show_no_signatures']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-
-	if ($settings['allow_no_censored'])
-		echo '
-							<dt>
-								<label for="show_no_censored">' . $txt['show_no_censored'] . '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[show_no_censored]" value="0" />
-								<input type="checkbox" name="default_options[show_no_censored]" id="show_no_censored" value="1"' . (!empty($context['member']['options']['show_no_censored']) ? ' checked="checked"' : '') . ' class="input_check" />
-							</dd>';
-
-	echo '
-							<dt>
-								<label for="return_to_post">', $txt['return_to_post'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[return_to_post]" value="0" />
-								<input type="checkbox" name="default_options[return_to_post]" id="return_to_post" value="1"', !empty($context['member']['options']['return_to_post']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>
-							<dt>
-								<label for="no_new_reply_warning">', $txt['no_new_reply_warning'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[no_new_reply_warning]" value="0" />
-								<input type="checkbox" name="default_options[no_new_reply_warning]" id="no_new_reply_warning" value="1"', !empty($context['member']['options']['no_new_reply_warning']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-
-	if (!empty($modSettings['enable_buddylist']))
-		echo '
-							<dt>
-								<label for="posts_apply_ignore_list">', $txt['posts_apply_ignore_list'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[posts_apply_ignore_list]" value="0" />
-								<input type="checkbox" name="default_options[posts_apply_ignore_list]" id="posts_apply_ignore_list" value="1"', !empty($context['member']['options']['posts_apply_ignore_list']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-
-	echo '
-							<dt>
-								<label for="view_newest_first">', $txt['recent_posts_at_top'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[view_newest_first]" value="0" />
-								<input type="checkbox" name="default_options[view_newest_first]" id="view_newest_first" value="1"', !empty($context['member']['options']['view_newest_first']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-
-	// Choose WYSIWYG settings?
-	if (empty($modSettings['disable_wysiwyg']))
-		echo '
-							<dt>
-								<label for="wysiwyg_default">', $txt['wysiwyg_default'], '</label>
-							</dt>
-							<dd>
-								<input type="hidden" name="default_options[wysiwyg_default]" value="0" />
-								<input type="checkbox" name="default_options[wysiwyg_default]" id="wysiwyg_default" value="1"', !empty($context['member']['options']['wysiwyg_default']) ? ' checked="checked"' : '', ' class="input_check" />
-							</dd>';
-
-	if (empty($modSettings['disableCustomPerPage']))
-	{
-		echo '
-							<dt>
-								<label for="topics_per_page">', $txt['topics_per_page'], '</label>
-							</dt>
-							<dd>
-								<select name="default_options[topics_per_page]" id="topics_per_page">
-									<option value="0"', empty($context['member']['options']['topics_per_page']) ? ' selected="selected"' : '', '>', $txt['per_page_default'], ' (', $modSettings['defaultMaxTopics'], ')</option>
-									<option value="5"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 5 ? ' selected="selected"' : '', '>5</option>
-									<option value="10"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 10 ? ' selected="selected"' : '', '>10</option>
-									<option value="25"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 25 ? ' selected="selected"' : '', '>25</option>
-									<option value="50"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 50 ? ' selected="selected"' : '', '>50</option>
-								</select>
-							</dd>
-							<dt>
-								<label for="messages_per_page">', $txt['messages_per_page'], '</label>
-							</dt>
-							<dd>
-								<select name="default_options[messages_per_page]" id="messages_per_page">
-									<option value="0"', empty($context['member']['options']['messages_per_page']) ? ' selected="selected"' : '', '>', $txt['per_page_default'], ' (', $modSettings['defaultMaxMessages'], ')</option>
-									<option value="5"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 5 ? ' selected="selected"' : '', '>5</option>
-									<option value="10"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 10 ? ' selected="selected"' : '', '>10</option>
-									<option value="25"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 25 ? ' selected="selected"' : '', '>25</option>
-									<option value="50"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 50 ? ' selected="selected"' : '', '>50</option>
-								</select>
-							</dd>';
-	}
-
-	if (!empty($modSettings['cal_enabled']))
-		echo '
-							<dt>
-								<label for="calendar_start_day">', $txt['calendar_start_day'], ':</label>
-							</dt>
-							<dd>
-								<select name="default_options[calendar_start_day]" id="calendar_start_day">
-									<option value="0"', empty($context['member']['options']['calendar_start_day']) ? ' selected="selected"' : '', '>', $txt['days'][0], '</option>
-									<option value="1"', !empty($context['member']['options']['calendar_start_day']) && $context['member']['options']['calendar_start_day'] == 1 ? ' selected="selected"' : '', '>', $txt['days'][1], '</option>
-									<option value="6"', !empty($context['member']['options']['calendar_start_day']) && $context['member']['options']['calendar_start_day'] == 6 ? ' selected="selected"' : '', '>', $txt['days'][6], '</option>
-								</select>
-							</dd>';
-
-	echo '
-							<dt>
-								<label for="display_quick_reply">', $txt['display_quick_reply'], '</label>
-							</dt>
-							<dd>
-								<select name="default_options[display_quick_reply]" id="display_quick_reply">
-									<option value="0"', empty($context['member']['options']['display_quick_reply']) ? ' selected="selected"' : '', '>', $txt['display_quick_reply1'], '</option>
-									<option value="1"', !empty($context['member']['options']['display_quick_reply']) && $context['member']['options']['display_quick_reply'] == 1 ? ' selected="selected"' : '', '>', $txt['display_quick_reply2'], '</option>
-									<option value="2"', !empty($context['member']['options']['display_quick_reply']) && $context['member']['options']['display_quick_reply'] == 2 ? ' selected="selected"' : '', '>', $txt['display_quick_reply3'], '</option>
-									<option value="3"', !empty($context['member']['options']['display_quick_reply']) && $context['member']['options']['display_quick_reply'] == 3 ? ' selected="selected"' : '', '>', $txt['display_quick_reply4'], '</option>
-								</select>
-							</dd>
-							<dt>
-								<label for="display_quick_mod">', $txt['display_quick_mod'], '</label>
-							</dt>
-							<dd>
-								<select name="default_options[display_quick_mod]" id="display_quick_mod">
-									<option value="0"', empty($context['member']['options']['display_quick_mod']) ? ' selected="selected"' : '', '>', $txt['display_quick_mod_none'], '</option>
-									<option value="1"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] == 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_check'], '</option>
-									<option value="2"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] != 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_image'], '</option>
-								</select>
-							</dd>';
-}
-
-function template_notification()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	// The main containing header.
-	echo '
-		<form action="', $scripturl, '?action=profile;area=notification;save" method="post" accept-charset="', $context['character_set'], '" id="notify_options" class="flow_hidden">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['profile'], '</span>
-				</h3>
-			</div>
-			<p class="windowbg description">', $txt['notification_info'], '</p>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-
-	// Allow notification on announcements to be disabled?
-	if (!empty($modSettings['allow_disableAnnounce']))
-		echo '
-						<dt>
-							<label for="notify_announcements">', $txt['notify_important_email'], '</label>
-						</dt>
-						<dd>
-							<input type="hidden" name="notify_announcements" value="0" />
-							<input type="checkbox" id="notify_announcements" name="notify_announcements"', !empty($context['member']['notify_announcements']) ? ' checked="checked"' : '', ' class="input_check" />
-						</dd>';
-
-	// More notification options.
-	echo '
-						<dt>
-							<label for="auto_notify">', $txt['auto_notify'], '</label>
-						</dt>
-						<dd>
-							<input type="hidden" name="default_options[auto_notify]" value="0" />
-							<input type="checkbox" id="auto_notify" name="default_options[auto_notify]" value="1"', !empty($context['member']['options']['auto_notify']) ? ' checked="checked"' : '', ' class="input_check" />
-						</dd>';
-
-	if (empty($modSettings['disallow_sendBody']))
-		echo '
-						<dt>
-							<label for="notify_send_body">', $txt['notify_send_body'], '</label>
-						</dt>
-						<dd>
-							<input type="hidden" name="notify_send_body" value="0" />
-							<input type="checkbox" id="notify_send_body" name="notify_send_body"', !empty($context['member']['notify_send_body']) ? ' checked="checked"' : '', ' class="input_check" />
-						</dd>';
-
-	echo '
-						<dt>
-							<label for="notify_regularity">', $txt['notify_regularity'], ':</label>
-						</dt>
-						<dd>
-							<select name="notify_regularity" id="notify_regularity">
-								<option value="0"', $context['member']['notify_regularity'] == 0 ? ' selected="selected"' : '', '>', $txt['notify_regularity_instant'], '</option>
-								<option value="1"', $context['member']['notify_regularity'] == 1 ? ' selected="selected"' : '', '>', $txt['notify_regularity_first_only'], '</option>
-								<option value="2"', $context['member']['notify_regularity'] == 2 ? ' selected="selected"' : '', '>', $txt['notify_regularity_daily'], '</option>
-								<option value="3"', $context['member']['notify_regularity'] == 3 ? ' selected="selected"' : '', '>', $txt['notify_regularity_weekly'], '</option>
-							</select>
-						</dd>
-						<dt>
-							<label for="notify_types">', $txt['notify_send_types'], ':</label>
-						</dt>
-						<dd>
-							<select name="notify_types" id="notify_types">
-								<option value="1"', $context['member']['notify_types'] == 1 ? ' selected="selected"' : '', '>', $txt['notify_send_type_everything'], '</option>
-								<option value="2"', $context['member']['notify_types'] == 2 ? ' selected="selected"' : '', '>', $txt['notify_send_type_everything_own'], '</option>
-								<option value="3"', $context['member']['notify_types'] == 3 ? ' selected="selected"' : '', '>', $txt['notify_send_type_only_replies'], '</option>
-								<option value="4"', $context['member']['notify_types'] == 4 ? ' selected="selected"' : '', '>', $txt['notify_send_type_nothing'], '</option>
-							</select>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<div>
-						<input id="notify_submit" type="submit" value="', $txt['notify_save'], '" class="button_submit" />
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="u" value="', $context['id_member'], '" />
-						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
-					</div>
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-		<br />';
-
-	template_show_list('topic_notification_list');
-
-	echo '
-		<br />';
-
-	template_show_list('board_notification_list');
-}
-
-// Template for choosing group membership.
-function template_groupMembership()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// The main containing header.
-	echo '
-		<form action="', $scripturl, '?action=profile;area=groupmembership;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['profile'], '</span>
-				</h3>
-			</div>
-			<p class="description">', $txt['groupMembership_info'], '</p>';
-
-	// Do we have an update message?
-	if (!empty($context['update_message']))
-		echo '
-			<div class="infobox">
-				', $context['update_message'], '.
-			</div>';
-
-	// Requesting membership to a group?
-	if (!empty($context['group_request']))
-	{
-		echo '
-			<div class="groupmembership">
-				<div class="cat_bar">
-					<h3 class="catbg">', $txt['request_group_membership'], '</h3>
-				</div>
-				<span class="upperframe"><span></span></span>
-				<div class="roundframe"><div class="innerframe">
-					', $txt['request_group_membership_desc'], ':
-					<textarea name="reason" rows="4" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 99%; min-width: 99%' : 'width: 99%') . ';"></textarea>
-					<div class="righttext" style="margin: 0.5em 0.5% 0 0.5%;">
-						<input type="hidden" name="gid" value="', $context['group_request']['id'], '" />
-						<input type="submit" name="req" value="', $txt['submit_request'], '" class="button_submit" />
-					</div>
-				</div></div>
-				<span class="lowerframe"><span></span></span>
-			</div>';
-	}
-	else
-	{
-		echo '
-			<table border="0" width="100%" cellspacing="0" cellpadding="4" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th" scope="col" ', $context['can_edit_primary'] ? ' colspan="2"' : '', '>', $txt['current_membergroups'], '</th>
-						<th class="last_th" scope="col"></th>
-					</tr>
-				</thead>
-				<tbody>';
-
-		$alternate = true;
-		foreach ($context['groups']['member'] as $group)
-		{
-			echo '
-					<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" id="primdiv_', $group['id'], '">';
-
-				if ($context['can_edit_primary'])
-					echo '
-						<td width="4%">
-							<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '" ', $group['is_primary'] ? 'checked="checked"' : '', ' onclick="highlightSelected(\'primdiv_' . $group['id'] . '\');" ', $group['can_be_primary'] ? '' : 'disabled="disabled"', ' class="input_radio" />
-						</td>';
-
-				echo '
-						<td>
-							<label for="primary_', $group['id'], '"><strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br /><span class="smalltext">' . $group['desc'] . '</span>' : ''), '</label>
-						</td>
-						<td width="15%" class="righttext">';
-
-				// Can they leave their group?
-				if ($group['can_leave'])
-					echo '
-							<a href="' . $scripturl . '?action=profile;save;u=' . $context['id_member'] . ';area=groupmembership;' . $context['session_var'] . '=' . $context['session_id'] . ';gid=' . $group['id'] . ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">' . $txt['leave_group'] . '</a>';
-				echo '
-						</td>
-					</tr>';
-			$alternate = !$alternate;
-		}
-
-		echo '
-				</tbody>
-			</table>';
-
-		if ($context['can_edit_primary'])
-			echo '
-			<div class="padding righttext">
-				<input type="submit" value="', $txt['make_primary'], '" class="button_submit" />
-			</div>';
-
-		// Any groups they can join?
-		if (!empty($context['groups']['available']))
-		{
-			echo '
-			<br />
-			<table border="0" width="100%" cellspacing="0" cellpadding="4" class="table_grid">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th" scope="col">
-							', $txt['available_groups'], '
-						</th>
-						<th class="last_th" scope="col"></th>
-					</tr>
-				</thead>
-				<tbody>';
-
-			$alternate = true;
-			foreach ($context['groups']['available'] as $group)
-			{
-				echo '
-					<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
-						<td>
-							<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br /><span class="smalltext">' . $group['desc'] . '</span>' : ''), '
-						</td>
-						<td width="15%" class="lefttext">';
-
-				if ($group['type'] == 3)
-					echo '
-							<a href="', $scripturl, '?action=profile;save;u=', $context['id_member'], ';area=groupmembership;', $context['session_var'], '=', $context['session_id'], ';gid=', $group['id'], ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">', $txt['join_group'], '</a>';
-				elseif ($group['type'] == 2 && $group['pending'])
-					echo '
-							', $txt['approval_pending'];
-				elseif ($group['type'] == 2)
-					echo '
-							<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=groupmembership;request=', $group['id'], '">', $txt['request_group'], '</a>';
-
-//				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-				echo '
-						</td>
-					</tr>';
-				$alternate = !$alternate;
-			}
-			echo '
-				</tbody>
-			</table>';
-		}
-
-		// Javascript for the selector stuff.
-		echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-		var prevClass = "";
-		var prevDiv = "";
-		function highlightSelected(box)
-		{
-			if (prevClass != "")
-			{
-				prevDiv.className = prevClass;
-			}
-			prevDiv = document.getElementById(box);
-			prevClass = prevDiv.className;
-
-			prevDiv.className = "highlight2";
-		}';
-		if (isset($context['groups']['member'][$context['primary_group']]))
-			echo '
-		highlightSelected("primdiv_' . $context['primary_group'] . '");';
-		echo '
-	// ]]></script>';
-	}
-
-	if (!empty($context['token_check']))
-		echo '
-				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	echo '
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-				<input type="hidden" name="u" value="', $context['id_member'], '" />
-			</form>';
-}
-
-function template_ignoreboards()
-{
-	global $context, $txt, $settings, $scripturl;
-	// The main containing header.
-	echo '
-	<form action="', $scripturl, '?action=profile;area=ignoreboards;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['profile'], '</span>
-			</h3>
-		</div>
-		<p class="description">', $txt['ignoreboards_info'], '</p>
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content flow_hidden">
-				<ul class="ignoreboards floatleft">';
-
-	$i = 0;
-	$limit = ceil($context['num_boards'] / 2);
-	foreach ($context['categories'] as $category)
-	{
-		if ($i == $limit)
-		{
-			echo '
-				</ul>
-				<ul class="ignoreboards floatright">';
-
-			$i++;
-		}
-
-		echo '
-					<li class="category">
-						<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'creator\'); return false;">', $category['name'], '</a>
-						<ul>';
-
-		foreach ($category['boards'] as $board)
-		{
-			if ($i == $limit)
-				echo '
-						</ul>
-					</li>
-				</ul>
-				<ul class="ignoreboards floatright">
-					<li class="category">
-						<ul>';
-
-			echo '
-							<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
-								<label for="ignore_brd', $board['id'], '"><input type="checkbox" id="ignore_brd', $board['id'], '" name="ignore_brd[', $board['id'], ']" value="', $board['id'], '"', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> ', $board['name'], '</label>
-							</li>';
-
-			$i++;
-		}
-
-		echo '
-						</ul>
-					</li>';
-	}
-
-	echo '
-				</ul>
-				<br class="clear" />';
-
-	// Show the standard "Save Settings" profile button.
-	template_profile_save();
-
-	echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</form>
-	<br />';
-}
-
-// Simple load some theme variables common to several warning templates.
-function template_load_warning_variables()
-{
-	global $modSettings, $context;
-
-	$context['warningBarWidth'] = 200;
-	// Setup the colors - this is a little messy for theming.
-	$context['colors'] = array(
-		0 => 'green',
-		$modSettings['warning_watch'] => 'darkgreen',
-		$modSettings['warning_moderate'] => 'orange',
-		$modSettings['warning_mute'] => 'red',
-	);
-
-	// Work out the starting color.
-	$context['current_color'] = $context['colors'][0];
-	foreach ($context['colors'] as $limit => $color)
-		if ($context['member']['warning'] >= $limit)
-			$context['current_color'] = $color;
-}
-
-// Show all warnings of a user?
-function template_viewWarning()
-{
-	global $context, $txt, $scripturl, $settings;
-
-	template_load_warning_variables();
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />
-				', sprintf($txt['profile_viewwarning_for_user'], $context['member']['name']), '
-				</span>
-			</h3>
-		</div>
-		<p class="description">', $txt['viewWarning_help'], '</p>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">
-					<dt>
-						<strong>', $txt['profile_warning_name'], ':</strong>
-					</dt>
-					<dd>
-						', $context['member']['name'], '
-					</dd>
-					<dt>
-						<strong>', $txt['profile_warning_level'], ':</strong>
-					</dt>
-					<dd>
-						<div>
-							<div>
-								<div style="font-size: 8pt; height: 12pt; width: ', $context['warningBarWidth'], 'px; border: 1px solid black; background-color: white; padding: 1px; position: relative;">
-									<div id="warning_text" style="padding-top: 1pt; width: 100%; z-index: 2; color: black; position: absolute; text-align: center; font-weight: bold;">', $context['member']['warning'], '%</div>
-									<div id="warning_progress" style="width: ', $context['member']['warning'], '%; height: 12pt; z-index: 1; background-color: ', $context['current_color'], ';">&nbsp;</div>
-								</div>
-							</div>
-						</div>
-					</dd>';
-
-		// There's some impact of this?
-		if (!empty($context['level_effects'][$context['current_level']]))
-			echo '
-					<dt>
-						<strong>', $txt['profile_viewwarning_impact'], ':</strong>
-					</dt>
-					<dd>
-						', $context['level_effects'][$context['current_level']], '
-					</dd>';
-
-		echo '
-				</dl>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-	template_show_list('view_warnings');
-}
-
-// Show a lovely interface for issuing warnings.
-function template_issueWarning()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	template_load_warning_variables();
-
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		function setWarningBarPos(curEvent, isMove, changeAmount)
-		{
-			barWidth = ', $context['warningBarWidth'], ';
-
-			// Are we passing the amount to change it by?
-			if (changeAmount)
-			{
-				if (document.getElementById(\'warning_level\').value == \'SAME\')
-					percent = ', $context['member']['warning'], ' + changeAmount;
-				else
-					percent = parseInt(document.getElementById(\'warning_level\').value) + changeAmount;
-			}
-			// If not then it\'s a mouse thing.
-			else
-			{
-				if (!curEvent)
-					var curEvent = window.event;
-
-				// If it\'s a movement check the button state first!
-				if (isMove)
-				{
-					if (!curEvent.button || curEvent.button != 1)
-						return false
-				}
-
-				// Get the position of the container.
-				contain = document.getElementById(\'warning_contain\');
-				position = 0;
-				while (contain != null)
-				{
-					position += contain.offsetLeft;
-					contain = contain.offsetParent;
-				}
-
-				// Where is the mouse?
-				if (curEvent.pageX)
-				{
-					mouse = curEvent.pageX;
-				}
-				else
-				{
-					mouse = curEvent.clientX;
-					mouse += document.documentElement.scrollLeft != "undefined" ? document.documentElement.scrollLeft : document.body.scrollLeft;
-				}
-
-				// Is this within bounds?
-				if (mouse < position || mouse > position + barWidth)
-					return;
-
-				percent = Math.round(((mouse - position) / barWidth) * 100);
-
-				// Round percent to the nearest 5 - by kinda cheating!
-				percent = Math.round(percent / 5) * 5;
-			}
-
-			// What are the limits?
-			minLimit = ', $context['min_allowed'], ';
-			maxLimit = ', $context['max_allowed'], ';
-
-			percent = Math.max(percent, minLimit);
-			percent = Math.min(percent, maxLimit);
-
-			size = barWidth * (percent/100);
-
-			setInnerHTML(document.getElementById(\'warning_text\'), percent + "%");
-			document.getElementById(\'warning_text\').innerHTML = percent + "%";
-			document.getElementById(\'warning_level\').value = percent;
-			document.getElementById(\'warning_progress\').style.width = size + "px";
-
-			// Get the right color.
-			color = "black"';
-
-	foreach ($context['colors'] as $limit => $color)
-		echo '
-			if (percent >= ', $limit, ')
-				color = "', $color, '";';
-
-	echo '
-			document.getElementById(\'warning_progress\').style.backgroundColor = color;
-
-			// Also set the right effect.
-			effectText = "";';
-
-	foreach ($context['level_effects'] as $limit => $text)
-		echo '
-			if (percent >= ', $limit, ')
-				effectText = "', $text, '";';
-
-	echo '
-			setInnerHTML(document.getElementById(\'cur_level_div\'), effectText);
-		}
-
-		// Disable notification boxes as required.
-		function modifyWarnNotify()
-		{
-			disable = !document.getElementById(\'warn_notify\').checked;
-			document.getElementById(\'warn_sub\').disabled = disable;
-			document.getElementById(\'warn_body\').disabled = disable;
-			document.getElementById(\'warn_temp\').disabled = disable;
-			document.getElementById(\'new_template_link\').style.display = disable ? \'none\' : \'\';
-			document.getElementById(\'preview_button\').style.display = disable ? \'none\' : \'\';
-		}
-
-		function changeWarnLevel(amount)
-		{
-			setWarningBarPos(false, false, amount);
-		}
-
-		// Warn template.
-		function populateNotifyTemplate()
-		{
-			index = document.getElementById(\'warn_temp\').value;
-			if (index == -1)
-				return false;
-
-			// Otherwise see what we can do...';
-
-	foreach ($context['notification_templates'] as $k => $type)
-		echo '
-			if (index == ', $k, ')
-				document.getElementById(\'warn_body\').value = "', strtr($type['body'], array('"' => "'", "\n" => '\\n', "\r" => '')), '";';
-
-	echo '
-		}
-
-	// ]]></script>';
-
-	echo '
-	<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=issuewarning" method="post" class="flow_hidden" accept-charset="', $context['character_set'], '">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />
-				', $context['user']['is_owner'] ? $txt['profile_warning_level'] : $txt['profile_issue_warning'], '
-				</span>
-			</h3>
-		</div>';
-
-	if (!$context['user']['is_owner'])
-		echo '
-		<p class="description">', $txt['profile_warning_desc'], '</p>';
-
-	echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl class="settings">';
-
-	if (!$context['user']['is_owner'])
-		echo '
-					<dt>
-						<strong>', $txt['profile_warning_name'], ':</strong>
-					</dt>
-					<dd>
-						<strong>', $context['member']['name'], '</strong>
-					</dd>';
-
-	echo '
-					<dt>
-						<strong>', $txt['profile_warning_level'], ':</strong>';
-
-	// Is there only so much they can apply?
-	if ($context['warning_limit'])
-		echo '
-						<br /><span class="smalltext">', sprintf($txt['profile_warning_limit_attribute'], $context['warning_limit']), '</span>';
-
-	echo '
-					</dt>
-					<dd>
-						<div id="warndiv1" style="display: none;">
-							<div>
-								<span class="floatleft" style="padding: 0 0.5em"><a href="#" onclick="changeWarnLevel(-5); return false;">[-]</a></span>
-								<div class="floatleft" id="warning_contain" style="font-size: 8pt; height: 12pt; width: ', $context['warningBarWidth'], 'px; border: 1px solid black; background-color: white; padding: 1px; position: relative;" onmousedown="setWarningBarPos(event, true);" onmousemove="setWarningBarPos(event, true);" onclick="setWarningBarPos(event);">
-									<div id="warning_text" style="padding-top: 1pt; width: 100%; z-index: 2; color: black; position: absolute; text-align: center; font-weight: bold;">', $context['member']['warning'], '%</div>
-									<div id="warning_progress" style="width: ', $context['member']['warning'], '%; height: 12pt; z-index: 1; background-color: ', $context['current_color'], ';">&nbsp;</div>
-								</div>
-								<span class="floatleft" style="padding: 0 0.5em"><a href="#" onclick="changeWarnLevel(5); return false;">[+]</a></span>
-								<div class="clear_left smalltext">', $txt['profile_warning_impact'], ': <span id="cur_level_div">', $context['level_effects'][$context['current_level']], '</span></div>
-							</div>
-							<input type="hidden" name="warning_level" id="warning_level" value="SAME" />
-						</div>
-						<div id="warndiv2">
-							<input type="text" name="warning_level_nojs" size="6" maxlength="4" value="', $context['member']['warning'], '" class="input_text" />&nbsp;', $txt['profile_warning_max'], '
-							<div class="smalltext">', $txt['profile_warning_impact'], ':<br />';
-	// For non-javascript give a better list.
-	foreach ($context['level_effects'] as $limit => $effect)
-		echo '
-							', sprintf($txt['profile_warning_effect_text'], $limit, $effect), '<br />';
-
-	echo '
-							</div>
-						</div>
-					</dd>';
-
-	if (!$context['user']['is_owner'])
-	{
-		echo '
-					<dt>
-						<strong>', $txt['profile_warning_reason'], ':</strong><br />
-						<span class="smalltext">', $txt['profile_warning_reason_desc'], '</span>
-					</dt>
-					<dd>
-						<input type="text" name="warn_reason" id="warn_reason" value="', $context['warning_data']['reason'], '" size="50" style="width: 80%;" class="input_text" />
-					</dd>
-				</dl>
-				<hr />
-				<div id="box_preview"', !empty($context['warning_data']['body_preview']) ? '' : ' style="display:none"', '>
-					<dl class="settings">
-						<dt>
-							<strong>', $txt['preview'] , '</strong>
-						</dt>
-						<dd id="body_preview">
-							', !empty($context['warning_data']['body_preview']) ? $context['warning_data']['body_preview'] : '', '
-						</dd>
-					</dl>
-					<hr />
-				</div>
-				<dl class="settings">
-					<dt>
-						<strong><label for="warn_notify">', $txt['profile_warning_notify'], ':</label></strong>
-					</dt>
-					<dd>
-						<input type="checkbox" name="warn_notify" id="warn_notify" onclick="modifyWarnNotify();" ', $context['warning_data']['notify'] ? 'checked="checked"' : '', ' class="input_check" />
-					</dd>
-					<dt>
-						<strong><label for="warn_sub">', $txt['profile_warning_notify_subject'], ':</label></strong>
-					</dt>
-					<dd>
-						<input type="text" name="warn_sub" id="warn_sub" value="', empty($context['warning_data']['notify_subject']) ? $txt['profile_warning_notify_template_subject'] : $context['warning_data']['notify_subject'], '" size="50" style="width: 80%;" class="input_text" />
-					</dd>
-					<dt>
-						<strong><label for="warn_temp">', $txt['profile_warning_notify_body'], ':</label></strong>
-					</dt>
-					<dd>
-						<select name="warn_temp" id="warn_temp" disabled="disabled" onchange="populateNotifyTemplate();" style="font-size: x-small;">
-							<option value="-1">', $txt['profile_warning_notify_template'], '</option>
-							<option value="-1">------------------------------</option>';
-
-		foreach ($context['notification_templates'] as $id_template => $template)
-			echo '
-							<option value="', $id_template, '">', $template['title'], '</option>';
-
-		echo '
-						</select>
-						<span class="smalltext" id="new_template_link" style="display: none;">[<a href="', $scripturl, '?action=moderate;area=warnings;sa=templateedit;tid=0" target="_blank" class="new_win">', $txt['profile_warning_new_template'], '</a>]</span><br />
-						<textarea name="warn_body" id="warn_body" cols="40" rows="8" style="min-width: 50%; max-width: 99%;">', $context['warning_data']['notify_body'], '</textarea>
-					</dd>';
-	}
-	echo '
-				</dl>
-				<div class="righttext">';
-
-	if (!empty($context['token_check']))
-		echo '
-					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button_submit" />
-					<input type="submit" name="save" value="', $context['user']['is_owner'] ? $txt['change_profile'] : $txt['profile_warning_issue'], '" class="button_submit" />
-				</div>
-				<br class="clear" />
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</form>';
-
-	// Previous warnings?
-	template_show_list('view_warnings');
-
-	// Do our best to get pretty javascript enabled.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		document.getElementById(\'warndiv1\').style.display = "";
-		document.getElementById(\'preview_button\').style.display = "none";
-		document.getElementById(\'warndiv2\').style.display = "none";';
-
-	if (!$context['user']['is_owner'])
-		echo '
-		modifyWarnNotify();
-		$(document).ready(function() {
-			$("#preview_button").click(function() {
-				return ajax_getTemplatePreview();
-			});
-		});
-
-		function ajax_getTemplatePreview ()
-		{
-			$.ajax({
-				type: "POST",
-				url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
-				data: {item: "warning_preview", title: $("#warn_sub").val(), body: $("#warn_body").val(), issuing: true},
-				context: document.body,
-				success: function(request){
-					$("#box_preview").css({display:""});
-					$("#body_preview").html($(request).find(\'body\').text());
-					if ($(request).find("error").text() != \'\')
-					{
-						$("#profile_error").css({display:""});
-						var errors_html = \'<span>\' + $("#profile_error").find("span").html() + \'</span>\' + \'<ul class="list_errors" class="reset">\';
-						var errors = $(request).find(\'error\').each(function() {
-							errors_html += \'<li>\' + $(this).text() + \'</li>\';
-						});
-						errors_html += \'</ul>\';
-
-						$("#profile_error").html(errors_html);
-					}
-					else
-					{
-						$("#profile_error").css({display:"none"});
-						$("#error_list").html(\'\');
-					}
-				return false;
-				},
-			});
-			return false;
-		}';
-
-	echo '
-	// ]]></script>';
-}
-
-// Template to show for deleting a users account - now with added delete post capability!
-function template_deleteAccount()
-{
-	global $context, $settings, $options, $scripturl, $txt, $scripturl;
-
-	// The main containing header.
-	echo '
-		<form action="', $scripturl, '?action=profile;area=deleteaccount;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
-			<div class="title_bar">
-				<h3 class="titlebg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['deleteAccount'], '</span>
-				</h3>
-			</div>';
-
-	// If deleting another account give them a lovely info box.
-	if (!$context['user']['is_owner'])
-		echo '
-			<p class="windowbg2 description">', $txt['deleteAccount_desc'], '</p>';
-	echo '
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	// If they are deleting their account AND the admin needs to approve it - give them another piece of info ;)
-	if ($context['needs_approval'])
-		echo '
-					<div class="errorbox">', $txt['deleteAccount_approval'], '</div>';
-
-	// If the user is deleting their own account warn them first - and require a password!
-	if ($context['user']['is_owner'])
-	{
-		echo '
-					<div class="alert">', $txt['own_profile_confirm'], '</div>
-					<div>
-						<strong', (isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : ''), '>', $txt['current_password'], ': </strong>
-						<input type="password" name="oldpasswrd" size="20" class="input_password" />&nbsp;&nbsp;&nbsp;&nbsp;
-						<input type="submit" value="', $txt['yes'], '" class="button_submit" />';
-
-		if (!empty($context['token_check']))
-			echo '
-				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-		echo '
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="u" value="', $context['id_member'], '" />
-						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
-					</div>';
-	}
-	// Otherwise an admin doesn't need to enter a password - but they still get a warning - plus the option to delete lovely posts!
-	else
-	{
-		echo '
-					<div class="alert">', $txt['deleteAccount_warning'], '</div>';
-
-		// Only actually give these options if they are kind of important.
-		if ($context['can_delete_posts'])
-			echo '
-					<div>
-						', $txt['deleteAccount_posts'], ':
-						<select name="remove_type">
-							<option value="none">', $txt['deleteAccount_none'], '</option>
-							<option value="posts">', $txt['deleteAccount_all_posts'], '</option>
-							<option value="topics">', $txt['deleteAccount_topics'], '</option>
-						</select>
-					</div>';
-
-		echo '
-					<div>
-						<label for="deleteAccount"><input type="checkbox" name="deleteAccount" id="deleteAccount" value="1" class="input_check" onclick="if (this.checked) return confirm(\'', $txt['deleteAccount_confirm'], '\');" /> ', $txt['deleteAccount_member'], '.</label>
-					</div>
-					<div>
-						<input type="submit" value="', $txt['delete'], '" class="button_submit" />';
-
-		if (!empty($context['token_check']))
-			echo '
-				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-		echo '
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="u" value="', $context['id_member'], '" />
-						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
-					</div>';
-	}
-	echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<br />
-		</form>';
-}
-
-// Template for the password box/save button stuck at the bottom of every profile page.
-function template_profile_save()
-{
-	global $context, $settings, $options, $txt;
-
-	echo '
-
-					<hr width="100%" size="1" class="hrcolor clear" />';
-
-	// Only show the password box if it's actually needed.
-	if ($context['require_password'])
-		echo '
-					<dl>
-						<dt>
-							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br />
-							<span class="smalltext">', $txt['required_security_reasons'], '</span>
-						</dt>
-						<dd>
-							<input type="password" name="oldpasswrd" size="20" style="margin-right: 4ex;" class="input_password" />
-						</dd>
-					</dl>';
-
-	echo '
-					<div class="righttext">
-						<input type="submit" value="', $txt['change_profile'], '" class="button_submit" />
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-						<input type="hidden" name="u" value="', $context['id_member'], '" />
-						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
-					</div>';
-}
-
-// Small template for showing an error message upon a save problem in the profile.
-function template_error_message()
-{
-	global $context, $txt;
-
-	echo '
-		<div class="errorbox" ', empty($context['post_errors']) ? 'style="display:none" ' : '', 'id="profile_error">';
-
-	if (!empty($context['post_errors']))
-	{
-		echo '
-			<span>', !empty($context['custom_error_title']) ? $context['custom_error_title'] : $txt['profile_errors_occurred'], ':</span>
-			<ul id="list_errors">';
-
-		// Cycle through each error and display an error message.
-		foreach ($context['post_errors'] as $error)
-			echo '
-				<li>', isset($txt['profile_error_' . $error]) ? $txt['profile_error_' . $error] : $error, '</li>';
-
-		echo '
-			</ul>';
-	}
-
-	echo '
-		</div>';
-}
-
-// Display a load of drop down selectors for allowing the user to change group.
-function template_profile_group_manage()
-{
-	global $context, $txt, $scripturl;
-
-	echo '
-							<dt>
-								<strong>', $txt['primary_membergroup'], ': </strong><br />
-								<span class="smalltext">[<a href="', $scripturl, '?action=helpadmin;help=moderator_why_missing" onclick="return reqWin(this.href);">', $txt['moderator_why_missing'], '</a>]</span>
-							</dt>
-							<dd>
-								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
-		
-		// Fill the select box with all primary member groups that can be assigned to a member.
-		foreach ($context['member_groups'] as $member_group)
-			if (!empty($member_group['can_be_primary']))
-				echo '
-									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected="selected"' : '', '>
-										', $member_group['name'], '
-									</option>';
-		echo '
-								</select>
-							</dd>
-							<dt>
-								<strong>', $txt['additional_membergroups'], ':</strong>
-							</dt>
-							<dd>
-								<span id="additional_groupsList">
-									<input type="hidden" name="additional_groups[]" value="0" />';
-
-		// For each membergroup show a checkbox so members can be assigned to more than one group.
-		foreach ($context['member_groups'] as $member_group)
-			if ($member_group['can_be_additional'])
-				echo '
-									<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked="checked"' : '', ' class="input_check" /> ', $member_group['name'], '</label><br />';
-		echo '
-								</span>
-								<a href="javascript:void(0);" onclick="document.getElementById(\'additional_groupsList\').style.display = \'block\'; document.getElementById(\'additional_groupsLink\').style.display = \'none\'; return false;" id="additional_groupsLink" style="display: none;">', $txt['additional_membergroups_show'], '</a>
-								<script type="text/javascript"><!-- // --><![CDATA[
-									document.getElementById("additional_groupsList").style.display = "none";
-									document.getElementById("additional_groupsLink").style.display = "";
-								// ]]></script>
-							</dd>';
-
-}
-
-// Callback function for entering a birthdate!
-function template_profile_birthdate()
-{
-	global $txt, $context;
-
-	// Just show the pretty box!
-	echo '
-							<dt>
-								<strong>', $txt['dob'], ':</strong><br />
-								<span class="smalltext">', $txt['dob_year'], ' - ', $txt['dob_month'], ' - ', $txt['dob_day'], '</span>
-							</dt>
-							<dd>
-								<input type="text" name="bday3" size="4" maxlength="4" value="', $context['member']['birth_date']['year'], '" class="input_text" /> -
-								<input type="text" name="bday1" size="2" maxlength="2" value="', $context['member']['birth_date']['month'], '" class="input_text" /> -
-								<input type="text" name="bday2" size="2" maxlength="2" value="', $context['member']['birth_date']['day'], '" class="input_text" />
-							</dd>';
-}
-
-// Show the signature editing box?
-function template_profile_signature_modify()
-{
-	global $txt, $context, $settings, $scripturl;
-
-	echo '
-							<dt id="current_signature"', !isset($context['member']['current_signature']) ? ' style="display:none"' : '', '>
-								<strong>', $txt['current_signature'], ':</strong>
-							</dt>
-							<dd id="current_signature_display"', !isset($context['member']['current_signature']) ? ' style="display:none"' : '', '>
-								', isset($context['member']['current_signature']) ? $context['member']['current_signature'] : '', '<hr />
-							</dd>';
-	echo '
-							<dt id="preview_signature"', !isset($context['member']['signature_preview']) ? ' style="display:none"' : '', '>
-								<strong>', $txt['signature_preview'], ':</strong>
-							</dt>
-							<dd id="preview_signature_display"', !isset($context['member']['signature_preview']) ? ' style="display:none"' : '', '>
-								', isset($context['member']['signature_preview']) ? $context['member']['signature_preview'] : '', '<hr />
-							</dd>';
-
-	echo '
-							<dt>
-								<strong>', $txt['signature'], ':</strong><br />
-								<span class="smalltext">', $txt['sig_info'], '</span><br />
-								<br />';
-
-	if ($context['show_spellchecking'])
-		echo '
-								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button_submit" />';
-
-		echo '
-							</dt>
-							<dd>
-								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50" style="min-width: 50%; max-width: 99%;">', $context['member']['signature'], '</textarea><br />';
-
-	// If there is a limit at all!
-	if (!empty($context['signature_limits']['max_length']))
-		echo '
-								<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br />';
-
-	if (!empty($context['show_preview_button']))
-		echo '
-						<input type="submit" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '" class="button_submit" />';
-
-	if ($context['signature_warning'])
-		echo '
-								<span class="smalltext">', $context['signature_warning'], '</span>';
-
-	// Load the spell checker?
-	if ($context['show_spellchecking'])
-		echo '
-								<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/spellcheck.js"></script>';
-
-	// Some javascript used to count how many characters have been used so far in the signature.
-	echo '
-								<script type="text/javascript"><!-- // --><![CDATA[
-									var maxLength = ', $context['signature_limits']['max_length'], ';
-
-									$(document).ready(function() {
-										calcCharLeft();
-										$("#preview_button").click(function() {
-											return ajax_getSignaturePreview(true);
-										});
-									});
-								// ]]></script>
-							</dd>';
-}
-
-function template_profile_avatar_select()
-{
-	global $context, $txt, $modSettings;
-
-	// Start with the upper menu
-	echo '
-							<dt>
-								<strong id="personal_picture"><label for="avatar_upload_box">', $txt['personal_picture'], '</label></strong>
-								<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_none" value="none"' . ($context['member']['avatar']['choice'] == 'none' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_none"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['no_avatar'] . '</label><br />
-								', !empty($context['member']['avatar']['allow_server_stored']) ? '<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_server_stored" value="server_stored"' . ($context['member']['avatar']['choice'] == 'server_stored' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_server_stored"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['choose_avatar_gallery'] . '</label><br />' : '', '
-								', !empty($context['member']['avatar']['allow_external']) ? '<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_external" value="external"' . ($context['member']['avatar']['choice'] == 'external' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_external"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['my_own_pic'] . '</label><br />' : '', '
-								', !empty($context['member']['avatar']['allow_upload']) ? '<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_upload" value="upload"' . ($context['member']['avatar']['choice'] == 'upload' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_upload"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['avatar_will_upload'] . '</label>' : '', '
-							</dt>
-							<dd>';
-
-	// If users are allowed to choose avatars stored on the server show selection boxes to choice them from.
-	if (!empty($context['member']['avatar']['allow_server_stored']))
-	{
-		echo '
-								<div id="avatar_server_stored">
-									<div>
-										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');">';
-		// This lists all the file catergories.
-		foreach ($context['avatars'] as $avatar)
-			echo '
-											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected="selected"' : ''), '>', $avatar['name'], '</option>';
-		echo '
-										</select>
-									</div>
-									<div>
-										<select name="file" id="file" size="10" style="display: none;" onchange="showAvatar()" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');" disabled="disabled"><option></option></select>
-									</div>
-									<div><img name="avatar" id="avatar" src="', !empty($context['member']['avatar']['allow_external']) && $context['member']['avatar']['choice'] == 'external' ? $context['member']['avatar']['external'] : $modSettings['avatar_url'] . '/blank.png', '" alt="Do Nothing" /></div>
-									<script type="text/javascript"><!-- // --><![CDATA[
-										var files = ["' . implode('", "', $context['avatar_list']) . '"];
-										var avatar = document.getElementById("avatar");
-										var cat = document.getElementById("cat");
-										var selavatar = "' . $context['avatar_selected'] . '";
-										var avatardir = "' . $modSettings['avatar_url'] . '/";
-										var size = avatar.alt.substr(3, 2) + " " + avatar.alt.substr(0, 2) + String.fromCharCode(117, 98, 116);
-										var file = document.getElementById("file");
-										var maxHeight = ', !empty($modSettings['avatar_max_height_external']) ? $modSettings['avatar_max_height_external'] : 0, ';
-										var maxWidth = ', !empty($modSettings['avatar_max_width_external']) ? $modSettings['avatar_max_width_external'] : 0, ';
-
-										if (avatar.src.indexOf("blank.png") > -1)
-											changeSel(selavatar);
-										else
-											previewExternalAvatar(avatar.src)
-
-									// ]]></script>
-								</div>';
-	}
-
-	// If the user can link to an off server avatar, show them a box to input the address.
-	if (!empty($context['member']['avatar']['allow_external']))
-	{
-		echo '
-								<div id="avatar_external">
-									<div class="smalltext">', $txt['avatar_by_url'], '</div>
-									<input type="text" name="userpicpersonal" size="45" value="', $context['member']['avatar']['external'], '" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'external\');" onchange="if (typeof(previewExternalAvatar) != \'undefined\') previewExternalAvatar(this.value);" class="input_text" />
-								</div>';
-	}
-
-	// If the user is able to upload avatars to the server show them an upload box.
-	if (!empty($context['member']['avatar']['allow_upload']))
-	{
-		echo '
-								<div id="avatar_upload">
-									<input type="file" size="44" name="attachment" id="avatar_upload_box" value="" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'upload\');" class="input_file" />
-									', ($context['member']['avatar']['id_attach'] > 0 ? '<br /><br /><img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&amp;') . 'time=' . time() . '" alt="" /><input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '" />' : ''), '
-								</div>';
-	}
-
-	echo '
-								<script type="text/javascript"><!-- // --><![CDATA[
-									', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "' . ($context['member']['avatar']['choice'] == 'server_stored' ? '' : 'none') . '";' : '', '
-									', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "' . ($context['member']['avatar']['choice'] == 'external' ? '' : 'none') . '";' : '', '
-									', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "' . ($context['member']['avatar']['choice'] == 'upload' ? '' : 'none') . '";' : '', '
-
-									function swap_avatar(type)
-									{
-										switch(type.id)
-										{
-											case "avatar_choice_server_stored":
-												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "";' : '', '
-												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "none";' : '', '
-												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "none";' : '', '
-												break;
-											case "avatar_choice_external":
-												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "none";' : '', '
-												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "";' : '', '
-												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "none";' : '', '
-												break;
-											case "avatar_choice_upload":
-												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "none";' : '', '
-												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "none";' : '', '
-												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "";' : '', '
-												break;
-											case "avatar_choice_none":
-												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "none";' : '', '
-												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "none";' : '', '
-												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "none";' : '', '
-												break;
-										}
-									}
-								// ]]></script>
-							</dd>';
-}
-
-// Callback for modifying karam.
-function template_profile_karma_modify()
-{
-	global $context, $modSettings, $txt;
-
-		echo '
-							<dt>
-								<strong>', $modSettings['karmaLabel'], '</strong>
-							</dt>
-							<dd>
-								', $modSettings['karmaApplaudLabel'], ' <input type="text" name="karma_good" size="4" value="', $context['member']['karma']['good'], '" onchange="setInnerHTML(document.getElementById(\'karmaTotal\'), this.value - this.form.karma_bad.value);" style="margin-right: 2ex;" class="input_text" /> ', $modSettings['karmaSmiteLabel'], ' <input type="text" name="karma_bad" size="4" value="', $context['member']['karma']['bad'], '" onchange="this.form.karma_good.onchange();" class="input_text" /><br />
-								(', $txt['total'], ': <span id="karmaTotal">', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '</span>)
-							</dd>';
-}
-
-
-// Select the time format!
-function template_profile_timeformat_modify()
-{
-	global $context, $modSettings, $txt, $scripturl, $settings;
-
-	echo '
-							<dt>
-								<strong><label for="easyformat">', $txt['time_format'], ':</label></strong><br />
-								<a href="', $scripturl, '?action=helpadmin;help=time_format" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="floatleft" /></a>
-								<span class="smalltext">&nbsp;<label for="time_format">', $txt['date_format'], '</label></span>
-							</dt>
-							<dd>
-								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;" style="margin-bottom: 4px;">';
-	// Help the user by showing a list of common time formats.
-	foreach ($context['easy_timeformats'] as $time_format)
-		echo '
-									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected="selected"' : '', '>', $time_format['title'], '</option>';
-	echo '
-								</select><br />
-								<input type="text" name="time_format" id="time_format" value="', $context['member']['time_format'], '" size="30" class="input_text" />
-							</dd>';
-}
-
-// Time offset?
-function template_profile_timeoffset_modify()
-{
-	global $txt, $context;
-
-	echo '
-							<dt>
-								<strong', (isset($context['modify_error']['bad_offset']) ? ' class="error"' : ''), '><label for="time_offset">', $txt['time_offset'], ':</label></strong><br />
-								<span class="smalltext">', $txt['personal_time_offset'], '</span>
-							</dt>
-							<dd>
-								<input type="text" name="time_offset" id="time_offset" size="5" maxlength="5" value="', $context['member']['time_offset'], '" class="input_text" /> ', $txt['hours'], ' [<a href="javascript:void(0);" onclick="currentDate = new Date(', $context['current_forum_time_js'], '); document.getElementById(\'time_offset\').value = autoDetectTimeOffset(currentDate); return false;">', $txt['timeoffset_autodetect'], '</a>]<br />', $txt['current_time'], ': <em>', $context['current_forum_time'], '</em>
-							</dd>';
-}
-
-// Theme?
-function template_profile_theme_pick()
-{
-	global $txt, $context, $scripturl;
-
-	echo '
-							<dt>
-								<strong>', $txt['current_theme'], ':</strong>
-							</dt>
-							<dd>
-								', $context['member']['theme']['name'], ' [<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['change'], '</a>]
-							</dd>';
-}
-
-// Smiley set picker.
-function template_profile_smiley_pick()
-{
-	global $txt, $context, $modSettings, $settings;
-
-	echo '
-							<dt>
-								<strong><label for="smiley_set">', $txt['smileys_current'], ':</label></strong>
-							</dt>
-							<dd>
-								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.gif\';">';
-	foreach ($context['smiley_sets'] as $set)
-		echo '
-									<option value="', $set['id'], '"', $set['selected'] ? ' selected="selected"' : '', '>', $set['name'], '</option>';
-	echo '
-								</select> <img id="smileypr" class="centericon" src="', $context['member']['smiley_set']['id'] != 'none' ? $modSettings['smileys_url'] . '/' . ($context['member']['smiley_set']['id'] != '' ? $context['member']['smiley_set']['id'] : (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'])) . '/smiley.gif' : $settings['images_url'] . '/blank.png', '" alt=":)"  style="padding-left: 20px;" />
-							</dd>';
-}
-
-// Change the way you login to the forum.
-function template_authentication_method()
-{
-	global $context, $settings, $options, $scripturl, $modSettings, $txt;
-
-	// The main header!
-	echo '
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
-		<form action="', $scripturl, '?action=profile;area=authentication;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['authentication'], '</span>
-				</h3>
-			</div>
-			<p class="windowbg description">', $txt['change_authentication'], '</p>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl>
-						<dt>
-							<input type="radio" onclick="updateAuthMethod();" name="authenticate" value="openid" id="auth_openid"', $context['auth_method'] == 'openid' ? ' checked="checked"' : '', ' class="input_radio" /><label for="auth_openid"><strong>', $txt['authenticate_openid'], '</strong></label>&nbsp;<em><a href="', $scripturl, '?action=helpadmin;help=register_openid" onclick="return reqWin(this.href);" class="help">(?)</a></em><br />
-							<input type="radio" onclick="updateAuthMethod();" name="authenticate" value="passwd" id="auth_pass"', $context['auth_method'] == 'password' ? ' checked="checked"' : '', ' class="input_radio" /><label for="auth_pass"><strong>', $txt['authenticate_password'], '</strong></label>
-						</dt>
-						<dd>
-							<dl id="auth_openid_div">
-								<dt>
-									<em>', $txt['authenticate_openid_url'], ':</em>
-								</dt>
-								<dd>
-									<input type="text" name="openid_identifier" id="openid_url" size="30" tabindex="', $context['tabindex']++, '" value="', $context['member']['openid_uri'], '" class="input_text openid_login" />
-								</dd>
-							</dl>
-							<dl id="auth_pass_div">
-								<dt>
-									<em>', $txt['choose_pass'], ':</em>
-								</dt>
-								<dd>
-									<input type="password" name="passwrd1" id="smf_autov_pwmain" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
-									<span id="smf_autov_pwmain_div" style="display: none;"><img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" /></span>
-								</dd>
-								<dt>
-									<em>', $txt['verify_pass'], ':</em>
-								</dt>
-								<dd>
-									<input type="password" name="passwrd2" id="smf_autov_pwverify" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
-									<span id="smf_autov_pwverify_div" style="display: none;"><img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_valid.png" alt="*" /></span>
-								</dd>
-							</dl>
-						</dd>
-					</dl>';
-
-	if ($context['require_password'])
-		echo '
-					<hr width="100%" size="1" class="hrcolor clear" />
-					<dl>
-						<dt>
-							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br />
-							<span class="smalltext">', $txt['required_security_reasons'], '</span>
-						</dt>
-						<dd>
-							<input type="password" name="oldpasswrd" tabindex="', $context['tabindex']++, '" size="20" style="margin-right: 4ex;" class="input_password" />
-						</dd>
-					</dl>';
-
-	echo '
-					<hr class="hrcolor" />';
-
-	if (!empty($context['token_check']))
-		echo '
-					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
-
-	echo '
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="u" value="', $context['id_member'], '" />
-					<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
-					<input type="submit" value="', $txt['change_profile'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>';
-
-	// The password stuff.
-	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-	var regTextStrings = {
-		"password_short": "', $txt['registration_password_short'], '",
-		"password_reserved": "', $txt['registration_password_reserved'], '",
-		"password_numbercase": "', $txt['registration_password_numbercase'], '",
-		"password_no_match": "', $txt['registration_password_no_match'], '",
-		"password_valid": "', $txt['registration_password_valid'], '"
-	};
-	var verificationHandle = new smfRegister("creator", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
-	var currentAuthMethod = \'passwd\';
-	updateAuthMethod();
-	// ]]></script>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Template for the profile side bar - goes before any other profile template.
+function template_profile_above()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/profile.js"></script>';
+
+	// Prevent Chrome from auto completing fields when viewing/editing other members profiles
+	if (isBrowser('is_chrome') && !$context['user']['is_owner'])
+		echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		disableAutoComplete();
+	// ]]></script>';
+
+	// If an error occurred while trying to save previously, give the user a clue!
+	echo '
+					', template_error_message();
+
+	// If the profile was update successfully, let the user know this.
+	if (!empty($context['profile_updated']))
+		echo '
+					<div class="infobox">
+						', $context['profile_updated'], '
+					</div>';
+}
+
+// Template for closing off table started in profile_above.
+function template_profile_below()
+{
+}
+
+// This template displays users details without any option to edit them.
+function template_summary()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// Display the basic information about the user
+	echo '
+<div id="profileview" class="flow_auto">
+	<div class="cat_bar">
+		<h3 class="catbg">
+			<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['summary'], '
+		</h3>
+	</div>
+	<div id="basicinfo">
+		<div class="windowbg">
+			<div class="content flow_auto">
+				<div class="username"><h4>', $context['member']['name'], ' <span class="position">', (!empty($context['member']['group']) ? $context['member']['group'] : $context['member']['post_group']), '</span></h4></div>
+				', $context['member']['avatar']['image'], '
+				<ul class="reset">';
+	// @TODO fix the <ul> when no fields are visible
+	// What about if we allow email only via the forum??
+	if ($context['member']['show_email'] === 'yes' || $context['member']['show_email'] === 'no_through_forum' || $context['member']['show_email'] === 'yes_permission_override' && $context['can_send_email'])
+		echo '
+					<li><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $context['member']['id'], '" title="', $context['member']['show_email'] == 'yes' || $context['member']['show_email'] == 'yes_permission_override' ? $context['member']['email'] : '', '" rel="nofollow"><img src="', $settings['images_url'], '/email_sm.png" alt="', $txt['email'], '" /></a></li>';
+
+	// Don't show an icon if they haven't specified a website.
+	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website']))
+		echo '
+					<li><a href="', $context['member']['website']['url'], '" title="' . $context['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/www_sm.png" alt="' . $context['member']['website']['title'] . '" />' : $txt['www']), '</a></li>';
+
+	// Are there any custom profile fields for the summary?
+	if (!empty($context['custom_fields']))
+	{
+		foreach ($context['custom_fields'] as $field)
+			if (($field['placement'] == 1 || empty($field['output_html'])) && !empty($field['value']))
+				echo '
+					<li class="custom_field">', $field['output_html'], '</li>';
+	}
+
+	echo '
+				', !isset($context['disabled_fields']['icq']) && !empty($context['member']['icq']['link']) ? '<li>' . $context['member']['icq']['link'] . '</li>' : '', '
+				', !isset($context['disabled_fields']['msn']) && !empty($context['member']['msn']['link']) ? '<li>' . $context['member']['msn']['link'] . '</li>' : '', '
+				', !isset($context['disabled_fields']['aim']) && !empty($context['member']['aim']['link']) ? '<li>' . $context['member']['aim']['link'] . '</li>' : '', '
+				', !isset($context['disabled_fields']['yim']) && !empty($context['member']['yim']['link']) ? '<li>' . $context['member']['yim']['link'] . '</li>' : '', '
+			</ul>
+			<span id="userstatus">', $context['can_send_pm'] ? '<a href="' . $context['member']['online']['href'] . '" title="' . $context['member']['online']['label'] . '" rel="nofollow">' : '', $settings['use_image_buttons'] ? '<img src="' . $context['member']['online']['image_href'] . '" alt="' . $context['member']['online']['text'] . '" class="centericon" />' : $context['member']['online']['text'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? '<span class="smalltext"> ' . $context['member']['online']['text'] . '</span>' : '';
+
+	// Can they add this member as a buddy?
+	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner'])
+		echo '
+				<br /><a href="', $scripturl, '?action=buddy;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($context['member']['is_buddy'] ? 'remove' : 'add')], ']</a>';
+
+	echo '
+				</span>';
+
+	echo '
+				<p id="infolinks">';
+
+	if (!$context['user']['is_owner'] && $context['can_send_pm'])
+		echo '
+					<a href="', $scripturl, '?action=pm;sa=send;u=', $context['id_member'], '">', $txt['profile_sendpm_short'], '</a><br />';
+	echo '
+					<a href="', $scripturl, '?action=profile;area=showposts;u=', $context['id_member'], '">', $txt['showPosts'], '</a><br />
+					<a href="', $scripturl, '?action=profile;area=statistics;u=', $context['id_member'], '">', $txt['statPanel'], '</a>
+				</p>';
+
+	echo '
+			</div>
+		</div>
+	</div>
+	<div id="detailedinfo">
+		<div class="windowbg2">
+			<div class="content">
+				<dl>';
+
+	if ($context['user']['is_owner'] || $context['user']['is_admin'])
+		echo '
+					<dt>', $txt['username'], ': </dt>
+					<dd>', $context['member']['username'], '</dd>';
+
+	if (!isset($context['disabled_fields']['posts']))
+		echo '
+					<dt>', $txt['profile_posts'], ': </dt>
+					<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';
+
+	if ($context['can_send_email'])
+	{
+		// Only show the email address fully if it's not hidden - and we reveal the email.
+		if ($context['member']['show_email'] == 'yes')
+			echo '
+						<dt>', $txt['email'], ': </dt>
+						<dd><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $context['member']['id'], '">', $context['member']['email'], '</a></dd>';
+
+		// ... Or if the one looking at the profile is an admin they can see it anyway.
+		elseif ($context['member']['show_email'] == 'yes_permission_override')
+			echo '
+						<dt>', $txt['email'], ': </dt>
+						<dd><em><a href="', $scripturl, '?action=emailuser;sa=email;uid=', $context['member']['id'], '">', $context['member']['email'], '</a></em></dd>';
+	}
+
+	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title']))
+		echo '
+					<dt>', $txt['custom_title'], ': </dt>
+					<dd>', $context['member']['title'], '</dd>';
+
+	if (!empty($context['member']['blurb']))
+		echo '
+					<dt>', $txt['personal_text'], ': </dt>
+					<dd>', $context['member']['blurb'], '</dd>';
+
+	// If karma enabled show the members karma.
+	if ($modSettings['karmaMode'] == '1')
+		echo '
+					<dt>', $modSettings['karmaLabel'], ' </dt>
+					<dd>', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '</dd>';
+
+	elseif ($modSettings['karmaMode'] == '2')
+		echo '
+					<dt>', $modSettings['karmaLabel'], ' </dt>
+					<dd>+', $context['member']['karma']['good'], '/-', $context['member']['karma']['bad'], '</dd>';
+
+	if (!isset($context['disabled_fields']['gender']) && !empty($context['member']['gender']['name']))
+		echo '
+					<dt>', $txt['gender'], ': </dt>
+					<dd>', $context['member']['gender']['name'], '</dd>';
+
+	echo '
+					<dt>', $txt['age'], ':</dt>
+					<dd>', $context['member']['age'] . ($context['member']['today_is_birthday'] ? ' &nbsp; <img src="' . $settings['images_url'] . '/cake.png" alt="" />' : ''), '</dd>';
+
+	if (!isset($context['disabled_fields']['location']) && !empty($context['member']['location']))
+		echo '
+					<dt>', $txt['location'], ':</dt>
+					<dd>', $context['member']['location'], '</dd>';
+
+	echo '
+				</dl>';
+
+	// Any custom fields for standard placement?
+	if (!empty($context['custom_fields']))
+	{
+		$shown = false;
+		foreach ($context['custom_fields'] as $field)
+		{
+			if ($field['placement'] != 0 || empty($field['output_html']))
+				continue;
+
+			if (empty($shown))
+			{
+				echo '
+				<dl>';
+				$shown = true;
+			}
+
+			echo '
+					<dt>', $field['name'], ':</dt>
+					<dd>', $field['output_html'], '</dd>';
+		}
+
+		if (!empty($shown))
+			echo '
+				</dl>';
+	}
+
+	echo '
+				<dl class="noborder">';
+
+	// Can they view/issue a warning?
+	if ($context['can_view_warning'] && $context['member']['warning'])
+	{
+		echo '
+					<dt>', $txt['profile_warning_level'], ': </dt>
+					<dd>
+						<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=', $context['can_issue_warning'] ? 'issuewarning' : 'viewwarning', '">', $context['member']['warning'], '%</a>';
+
+		// Can we provide information on what this means?
+		if (!empty($context['warning_status']))
+			echo '
+						<span class="smalltext">(', $context['warning_status'], ')</span>';
+
+		echo '
+					</dd>';
+	}
+
+	// Is this member requiring activation and/or banned?
+	if (!empty($context['activate_message']) || !empty($context['member']['bans']))
+	{
+
+		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
+		if (!empty($context['activate_message']))
+			echo '
+					<dt class="clear"><span class="alert">', $context['activate_message'], '</span>&nbsp;(<a href="' . $scripturl . '?action=profile;save;area=activateaccount;u=' . $context['id_member'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '"', ($context['activate_type'] == 4 ? ' onclick="return confirm(\'' . $txt['profileConfirm'] . '\');"' : ''), '>', $context['activate_link_text'], '</a>)</dt>';
+
+		// If the current member is banned, show a message and possibly a link to the ban.
+		if (!empty($context['member']['bans']))
+		{
+			echo '
+					<dt class="clear"><span class="alert">', $txt['user_is_banned'], '</span>&nbsp;[<a href="#" onclick="document.getElementById(\'ban_info\').style.display = document.getElementById(\'ban_info\').style.display == \'none\' ? \'\' : \'none\';return false;">' . $txt['view_ban'] . '</a>]</dt>
+					<dt class="clear" id="ban_info" style="display: none;">
+						<strong>', $txt['user_banned_by_following'], ':</strong>';
+
+			foreach ($context['member']['bans'] as $ban)
+				echo '
+						<br /><span class="smalltext">', $ban['explanation'], '</span>';
+
+			echo '
+					</dt>';
+		}
+	}
+
+	echo '
+					<dt>', $txt['date_registered'], ': </dt>
+					<dd>', $context['member']['registered'], '</dd>';
+
+	// If the person looking is allowed, they can check the members IP address and hostname.
+	if ($context['can_see_ip'])
+	{
+		if (!empty($context['member']['ip']))
+		echo '
+					<dt>', $txt['ip'], ': </dt>
+					<dd><a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip'], '</a></dd>';
+
+		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip']))
+			echo '
+					<dt>', $txt['hostname'], ': </dt>
+					<dd>', $context['member']['hostname'], '</dd>';
+	}
+
+	echo '
+					<dt>', $txt['local_time'], ':</dt>
+					<dd>', $context['member']['local_time'], '</dd>';
+
+	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language']))
+		echo '
+					<dt>', $txt['language'], ':</dt>
+					<dd>', $context['member']['language'], '</dd>';
+
+	echo '
+					<dt>', $txt['lastLoggedIn'], ': </dt>
+					<dd>', $context['member']['last_login'], '</dd>
+				</dl>';
+
+	// Are there any custom profile fields for the summary?
+	if (!empty($context['custom_fields']))
+	{
+		$shown = false;
+		foreach ($context['custom_fields'] as $field)
+		{
+			if ($field['placement'] != 2 || empty($field['output_html']))
+				continue;
+			if (empty($shown))
+			{
+				$shown = true;
+				echo '
+				<div class="custom_fields_above_signature">
+					<ul class="reset nolist">';
+			}
+			echo '
+						<li>', $field['output_html'], '</li>';
+		}
+		if ($shown)
+				echo '
+					</ul>
+				</div>';
+	}
+
+	// Show the users signature.
+	if ($context['signature_enabled'] && !empty($context['member']['signature']))
+		echo '
+				<div class="signature">
+					<h5>', $txt['signature'], ':</h5>
+					', $context['member']['signature'], '
+				</div>';
+
+	echo '
+			</div>
+		</div>
+	</div>
+<div class="clear"></div>
+</div>';
+}
+
+// Template for showing all the posts of the user, in chronological order.
+function template_showPosts()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', (!isset($context['attachments']) && empty($context['is_topics']) ? $txt['showMessages'] : (!empty($context['is_topics']) ? $txt['showTopics'] : $txt['showAttachments'])), ' - ', $context['member']['name'], '
+			</h3>
+		</div>
+		<div class="pagesection">
+			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
+		</div>';
+
+	// Button shortcuts
+	$quote_button = create_button('quote.png', 'reply_quote', 'quote', 'class="centericon"');
+	$reply_button = create_button('reply_sm.png', 'reply', 'reply', 'class="centericon"');
+	$remove_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
+	$notify_button = create_button('notify_sm.png', 'notify_replies', 'notify', 'class="centericon"');
+
+	// Are we displaying posts or attachments?
+	if (!isset($context['attachments']))
+	{
+		// For every post to be displayed, give it its own div, and show the important details of the post.
+		foreach ($context['posts'] as $post)
+		{
+			echo '
+		<div class="topic">
+			<div class="', $post['alternate'] == 0 ? 'windowbg2' : 'windowbg', ' core_posts">
+				<div class="content">
+					<div class="counter">', $post['counter'], '</div>
+					<div class="topic_details">
+						<h5><strong><a href="', $scripturl, '?board=', $post['board']['id'], '.0">', $post['board']['name'], '</a> / <a href="', $scripturl, '?topic=', $post['topic'], '.', $post['start'], '#msg', $post['id'], '">', $post['subject'], '</a></strong></h5>
+						<span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> ', $post['time'], '&nbsp;&#187;</span>
+					</div>
+					<div class="list_posts">';
+
+			if (!$post['approved'])
+				echo '
+					<div class="approve_post">
+						<em>', $txt['post_awaiting_approval'], '</em>
+					</div>';
+
+			echo '
+					', $post['body'], '
+					</div>
+				</div>';
+
+			if ($post['can_reply'] || $post['can_mark_notify'] || $post['can_delete'])
+				echo '
+				<div class="floatright">
+					<ul class="reset smalltext quickbuttons">';
+
+			// If they *can* reply?
+			if ($post['can_reply'])
+				echo '
+						<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '" class="reply_button"><span>', $txt['reply'], '</span></a></li>';
+
+			// If they *can* quote?
+			if ($post['can_quote'])
+				echo '
+						<li><a href="', $scripturl . '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '" class="quote_button"><span>', $txt['quote'], '</span></a></li>';
+
+			// Can we request notification of topics?
+			if ($post['can_mark_notify'])
+				echo '
+						<li><a href="', $scripturl, '?action=notify;topic=', $post['topic'], '.', $post['start'], '" class="notify_button"><span>', $txt['notify'], '</span></a></li>';
+
+			// How about... even... remove it entirely?!
+			if ($post['can_delete'])
+				echo '
+						<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';profile;u=', $context['member']['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['remove_message'], '?\');" class="remove_button"><span>', $txt['remove'], '</span></a></li>';
+
+			if ($post['can_reply'] || $post['can_mark_notify'] || $post['can_delete'])
+				echo '
+					</ul>
+				</div>';
+
+			echo '
+				<br class="clear" />
+			</div>
+		</div>';
+		}
+	}
+	else
+	{
+		echo '
+		<table border="0" width="100%" cellspacing="1" cellpadding="2" class="table_grid" align="center">
+			<thead>
+				<tr class="titlebg">
+					<th class="first_th lefttext" scope="col" width="25%">
+						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=filename', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'filename' ? ';asc' : ''), '">
+							', $txt['show_attach_filename'], '
+							', ($context['sort_order'] == 'filename' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
+						</a>
+					</th>
+					<th scope="col" width="12%">
+						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=downloads', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'downloads' ? ';asc' : ''), '">
+							', $txt['show_attach_downloads'], '
+							', ($context['sort_order'] == 'downloads' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
+						</a>
+					</th>
+					<th class="lefttext" scope="col" width="30%">
+						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=subject', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'subject' ? ';asc' : ''), '">
+							', $txt['message'], '
+							', ($context['sort_order'] == 'subject' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
+						</a>
+					</th>
+					<th class="last_th lefttext" scope="col">
+						<a href="', $scripturl, '?action=profile;u=', $context['current_member'], ';area=showposts;sa=attach;sort=posted', ($context['sort_direction'] == 'down' && $context['sort_order'] == 'posted' ? ';asc' : ''), '">
+						', $txt['show_attach_posted'], '
+						', ($context['sort_order'] == 'posted' ? '<img src="' . $settings['images_url'] . '/sort_' . ($context['sort_direction'] == 'down' ? 'down' : 'up') . '.png" alt="" />' : ''), '
+						</a>
+					</th>
+				</tr>
+			</thead>
+			<tbody>';
+
+		// Looks like we need to do all the attachments instead!
+		$alternate = false;
+		foreach ($context['attachments'] as $attachment)
+		{
+			echo '
+				<tr class="', $attachment['approved'] ? ($alternate ? 'windowbg' : 'windowbg2') : 'approvebg', '">
+					<td><a href="', $scripturl, '?action=dlattach;topic=', $attachment['topic'], '.0;attach=', $attachment['id'], '">',	$attachment['filename'], '</a>', !$attachment['approved'] ? '&nbsp;<em>(' . $txt['awaiting_approval'] . ')</em>' : '', '</td>
+					<td align="center">', $attachment['downloads'], '</td>
+					<td><a href="', $scripturl, '?topic=', $attachment['topic'], '.msg', $attachment['msg'], '#msg', $attachment['msg'], '" rel="nofollow">', $attachment['subject'], '</a></td>
+					<td>', $attachment['posted'], '</td>
+				</tr>';
+			$alternate = !$alternate;
+		}
+
+	// No posts? Just end the table with a informative message.
+	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts'])))
+		echo '
+				<tr>
+					<td class="tborder windowbg2 padding centertext" colspan="4">
+						', isset($context['attachments']) ? $txt['show_attachments_none'] : ($context['is_topics'] ? $txt['show_topics_none'] : $txt['show_posts_none']), '
+					</td>
+				</tr>';
+
+		echo '
+			</tbody>
+		</table>';
+	}
+	// Show more page numbers.
+	echo '
+		<div class="pagesection" style="margin-bottom: 0;">
+			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
+		</div>';
+}
+
+// Template for showing all the buddies of the current user.
+function template_editBuddies()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
+	$buddy_fields = array('icq', 'aim', 'yim', 'msn');
+
+	echo '
+		<div class="title_bar">
+			<h3 class="titlebg">
+				<img src="', $settings['images_url'], '/icons/online.png" alt="" class="icon" />', $txt['editBuddies'], '
+			</h3>
+		</div>
+		<table border="0" width="100%" cellspacing="1" cellpadding="4" class="table_grid" align="center">
+			<tr class="catbg">
+				<th class="first_th" scope="col" width="20%">', $txt['name'], '</th>
+				<th scope="col">', $txt['status'], '</th>';
+	if ($context['can_send_email'])
+		echo '
+				<th scope="col">', $txt['email'], '</th>';
+
+	// don't show them if they are disabled
+	foreach ($buddy_fields as $key => $column)
+	{
+		if (!isset($disabled_fields[$column]))
+			echo '
+				<th scope="col">', $txt[$column], '</th>';
+	}
+
+	echo '
+				<th class="last_th" scope="col"></th>
+			</tr>';
+
+	// If they don't have any buddies don't list them!
+	if (empty($context['buddies']))
+		echo '
+			<tr class="windowbg2">
+				<td colspan="8" align="center"><strong>', $txt['no_buddies'], '</strong></td>
+			</tr>';
+
+	// Now loop through each buddy showing info on each.
+	$alternate = false;
+	foreach ($context['buddies'] as $buddy)
+	{
+		echo '
+			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+				<td>', $buddy['link'], '</td>
+				<td align="center"><a href="', $buddy['online']['href'], '"><img src="', $buddy['online']['image_href'], '" alt="', $buddy['online']['label'], '" title="', $buddy['online']['label'], '" /></a></td>';
+		if ($context['can_send_email'])
+			echo '
+				<td align="center">', ($buddy['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $buddy['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $buddy['name'] . '" /></a>'), '</td>';
+
+		// If these are off, don't show them
+		foreach ($buddy_fields as $key => $column)
+		{
+			if (!isset($disabled_fields[$column]))
+				echo '
+					<td align="center">', $buddy[$column]['link'], '</td>';
+		}
+
+		echo '
+				<td align="center"><a href="', $scripturl, '?action=profile;area=lists;sa=buddies;u=', $context['id_member'], ';remove=', $buddy['id'], ';', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/icons/delete.png" alt="', $txt['buddy_remove'], '" title="', $txt['buddy_remove'], '" /></a></td>
+			</tr>';
+
+		$alternate = !$alternate;
+	}
+
+	echo '
+		</table>';
+
+	// Add a new buddy?
+	echo '
+	<br />
+	<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=buddies" method="post" accept-charset="', $context['character_set'], '">
+		<div class="tborder add_buddy">
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['buddy_add'], '</h3>
+			</div>
+			<div class="roundframe">
+				<dl class="settings">
+					<dt>
+						<label for="new_buddy"><strong>', $txt['who_member'], ':</strong></label>
+					</dt>
+					<dd>
+						<input type="text" name="new_buddy" id="new_buddy" size="30" class="input_text" />
+					</dd>
+				</dl>';
+
+	if (!empty($context['token_check']))
+		echo '
+				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	echo '
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="submit" value="', $txt['buddy_add_button'], '" class="button_submit" />
+				<br class="clear_right" />
+			</div>
+		</div>
+	</form>
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oAddBuddySuggest = new smc_AutoSuggest({
+			sSelf: \'oAddBuddySuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'new_buddy\',
+			sControlId: \'new_buddy\',
+			sSearchType: \'member\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			bItemList: false
+		});
+	// ]]></script>';
+}
+
+// Template for showing the ignore list of the current user.
+function template_editIgnoreList()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+		<div class="title_bar">
+			<h3 class="titlebg">
+				<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['editIgnoreList'], '
+			</h3>
+		</div>
+		<table border="0" width="100%" cellspacing="1" cellpadding="4" class="table_grid" align="center">
+			<tr class="catbg">
+				<th class="first_th" scope="col" width="20%">', $txt['name'], '</th>
+				<th scope="col">', $txt['status'], '</th>';
+	if ($context['can_send_email'])
+		echo '
+				<th scope="col">', $txt['email'], '</th>';
+	echo '
+				<th scope="col">', $txt['icq'], '</th>
+				<th scope="col">', $txt['aim'], '</th>
+				<th scope="col">', $txt['yim'], '</th>
+				<th scope="col">', $txt['msn'], '</th>
+				<th class="last_th" scope="col"></th>
+			</tr>';
+
+	// If they don't have anyone on their ignore list, don't list it!
+	if (empty($context['ignore_list']))
+		echo '
+			<tr class="windowbg2">
+				<td colspan="8" align="center"><strong>', $txt['no_ignore'], '</strong></td>
+			</tr>';
+
+	// Now loop through each buddy showing info on each.
+	$alternate = false;
+	foreach ($context['ignore_list'] as $member)
+	{
+		echo '
+			<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+				<td>', $member['link'], '</td>
+				<td align="center"><a href="', $member['online']['href'], '"><img src="', $member['online']['image_href'], '" alt="', $member['online']['label'], '" title="', $member['online']['label'], '" /></a></td>';
+		if ($context['can_send_email'])
+			echo '
+				<td align="center">', ($member['show_email'] == 'no' ? '' : '<a href="' . $scripturl . '?action=emailuser;sa=email;uid=' . $member['id'] . '" rel="nofollow"><img src="' . $settings['images_url'] . '/email_sm.png" alt="' . $txt['email'] . '" title="' . $txt['email'] . ' ' . $member['name'] . '" /></a>'), '</td>';
+		echo '
+				<td align="center">', $member['icq']['link'], '</td>
+				<td align="center">', $member['aim']['link'], '</td>
+				<td align="center">', $member['yim']['link'], '</td>
+				<td align="center">', $member['msn']['link'], '</td>
+				<td align="center"><a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '"><img src="', $settings['images_url'], '/icons/delete.png" alt="', $txt['ignore_remove'], '" title="', $txt['ignore_remove'], '" /></a></td>
+			</tr>';
+
+		$alternate = !$alternate;
+	}
+
+	echo '
+		</table>';
+
+	// Add to the ignore list?
+	echo '
+	<br />
+	<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore" method="post" accept-charset="', $context['character_set'], '">
+		<div class="tborder add_buddy">
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['ignore_add'], '</h3>
+			</div>
+			<div class="roundframe">
+				<dl class="settings">
+					<dt>
+						<label for="new_buddy"><strong>', $txt['who_member'], ':</strong></label>
+					</dt>
+					<dd>
+						<input type="text" name="new_ignore" id="new_ignore" size="25" class="input_text" />
+					</dd>
+				</dl>';
+
+	if (!empty($context['token_check']))
+		echo '
+				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	echo '
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="submit" value="', $txt['ignore_add_button'], '" class="button_submit" />
+				<br class="clear_right" />
+			</div>
+		</div>
+	</form>
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+	<script type="text/javascript"><!-- // --><![CDATA[
+		var oAddIgnoreSuggest = new smc_AutoSuggest({
+			sSelf: \'oAddIgnoreSuggest\',
+			sSessionId: \'', $context['session_id'], '\',
+			sSessionVar: \'', $context['session_var'], '\',
+			sSuggestId: \'new_ignore\',
+			sControlId: \'new_ignore\',
+			sSearchType: \'member\',
+			sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
+			bItemList: false
+		});
+	// ]]></script>';
+}
+
+// This template shows an admin information on a users IP addresses used and errors attributed to them.
+function template_trackActivity()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// The first table shows IP information about the user.
+	echo '
+			<div class="title_bar">
+				<h3 class="titlebg"><strong>', $txt['view_ips_by'], ' ', $context['member']['name'], '</strong></h3>
+			</div>';
+
+	// The last IP the user used.
+	echo '
+			<div id="tracking" class="windowbg2">
+				<div class="content">
+					<dl class="noborder">
+						<dt>', $txt['most_recent_ip'], ':
+							', (empty($context['last_ip2']) ? '' : '<br />
+							<span class="smalltext">(<a href="' . $scripturl . '?action=helpadmin;help=whytwoip" onclick="return reqWin(this.href);">' . $txt['why_two_ip_address'] . '</a>)</span>'), '
+						</dt>
+						<dd>
+							<a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
+
+	// Second address detected?
+	if (!empty($context['last_ip2']))
+		echo '
+							, <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip2'], ';u=', $context['member']['id'], '">', $context['last_ip2'], '</a>';
+
+	echo '
+						</dd>';
+
+	// Lists of IP addresses used in messages / error messages.
+	echo '
+						<dt>', $txt['ips_in_messages'], ':</dt>
+						<dd>
+							', (count($context['ips']) > 0 ? implode(', ', $context['ips']) : '(' . $txt['none'] . ')'), '
+						</dd>
+						<dt>', $txt['ips_in_errors'], ':</dt>
+						<dd>
+							', (count($context['ips']) > 0 ? implode(', ', $context['error_ips']) : '(' . $txt['none'] . ')'), '
+						</dd>';
+
+	// List any members that have used the same IP addresses as the current member.
+	echo '
+						<dt>', $txt['members_in_range'], ':</dt>
+						<dd>
+							', (count($context['members_in_range']) > 0 ? implode(', ', $context['members_in_range']) : '(' . $txt['none'] . ')'), '
+						</dd>
+					</dl>
+				</div>
+			</div>
+			<br class="clear" />';
+
+	// Show the track user list.
+	template_show_list('track_user_list');
+}
+
+// The template for trackIP, allowing the admin to see where/who a certain IP has been used.
+function template_trackIP()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// This function always defaults to the last IP used by a member but can be set to track any IP.
+	// The first table in the template gives an input box to allow the admin to enter another IP to track.
+	echo '
+	<div class="tborder">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['trackIP'], '</h3>
+		</div>
+		<div class="roundframe">
+			<form action="', $context['base_url'], '" method="post" accept-charset="', $context['character_set'], '">
+				<dl class="settings">
+					<dt>
+						<label for="searchip"><strong>', $txt['enter_ip'], ':</strong></label>
+					</dt>
+					<dd>
+						<input type="text" name="searchip" value="', $context['ip'], '" class="input_text" />
+					</dd>
+				</dl>
+				<input type="submit" value="', $txt['trackIP'], '" class="button_submit" />
+				<br class="clear_right" />
+			</form>
+		</div>
+	</div>
+	<br class="clear" />';
+
+	// The table inbetween the first and second table shows links to the whois server for every region.
+	if ($context['single_ip'])
+	{
+		echo '
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['whois_title'], ' ', $context['ip'], '</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="padding">';
+			foreach ($context['whois_servers'] as $server)
+				echo '
+					<a href="', $server['url'], '" target="_blank" class="new_win"', isset($context['auto_whois_server']) && $context['auto_whois_server']['name'] == $server['name'] ? ' style="font-weight: bold;"' : '', '>', $server['name'], '</a><br />';
+			echo '
+				</div>
+			</div>
+		<br class="clear" />';
+	}
+
+	// The second table lists all the members who have been logged as using this IP address.
+	echo '
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['members_from_ip'], ' ', $context['ip'], '</h3>
+		</div>';
+	if (empty($context['ips']))
+		echo '
+		<p class="windowbg2 description"><em>', $txt['no_members_from_ip'], '</em></p>';
+	else
+	{
+		echo '
+		<table class="table_grid" cellspacing="0" width="100%">
+			<thead>
+				<tr class="catbg">
+					<th class="first_th" scope="col">', $txt['ip_address'], '</th>
+					<th class="last_th" scope="col">', $txt['display_name'], '</th>
+				</tr>
+			</thead>
+			<tbody>';
+
+		// Loop through each of the members and display them.
+		foreach ($context['ips'] as $ip => $memberlist)
+			echo '
+				<tr>
+					<td class="windowbg2"><a href="', $context['base_url'], ';searchip=', $ip, '">', $ip, '</a></td>
+					<td class="windowbg2">', implode(', ', $memberlist), '</td>
+				</tr>';
+
+		echo '
+			</tbody>
+		</table>
+		<br />';
+	}
+
+	template_show_list('track_message_list');
+
+	echo '<br />';
+
+	template_show_list('track_user_list');
+}
+
+function template_showPermissions()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['showPermissions'], '
+			</h3>
+		</div>';
+
+	if ($context['member']['has_all_permissions'])
+	{
+		echo '
+		<p class="windowbg description">', $txt['showPermissions_all'], '</p>';
+	}
+	else
+	{
+		echo '
+		<p class="description">',$txt['showPermissions_help'],'</p>
+		<div id="permissions" class="flow_hidden">';
+
+		if (!empty($context['no_access_boards']))
+		{
+			echo '
+				<div class="cat_bar">
+					<h3 class="catbg">', $txt['showPermissions_restricted_boards'], '</h3>
+				</div>
+				<div class="windowbg smalltext">
+					<div class="content">', $txt['showPermissions_restricted_boards_desc'], ':<br />';
+				foreach ($context['no_access_boards'] as $no_access_board)
+					echo '
+						<a href="', $scripturl, '?board=', $no_access_board['id'], '.0">', $no_access_board['name'], '</a>', $no_access_board['is_last'] ? '' : ', ';
+				echo '
+					</div>
+				</div>';
+		}
+
+		// General Permissions section.
+		echo '
+				<div class="tborder">
+					<div class="cat_bar">
+						<h3 class="catbg">', $txt['showPermissions_general'], '</h3>
+					</div>';
+		if (!empty($context['member']['permissions']['general']))
+		{
+			echo '
+					<table class="table_grid" width="100%" cellspacing="0">
+						<thead>
+							<tr class="titlebg">
+								<th class="lefttext first_th" scope="col" width="50%">', $txt['showPermissions_permission'], '</th>
+								<th class="lefttext last_th" scope="col" width="50%">', $txt['showPermissions_status'], '</th>
+							</tr>
+						</thead>
+						<tbody>';
+
+			foreach ($context['member']['permissions']['general'] as $permission)
+			{
+				echo '
+							<tr>
+								<td class="windowbg" title="', $permission['id'], '">
+									', $permission['is_denied'] ? '<del>' . $permission['name'] . '</del>' : $permission['name'], '
+								</td>
+								<td class="windowbg2 smalltext">';
+
+				if ($permission['is_denied'])
+					echo '
+									<span class="alert">', $txt['showPermissions_denied'], ':&nbsp;', implode(', ', $permission['groups']['denied']),'</span>';
+				else
+					echo '
+									', $txt['showPermissions_given'], ':&nbsp;', implode(', ', $permission['groups']['allowed']);
+
+					echo '
+								</td>
+							</tr>';
+			}
+			echo '
+						</tbody>
+					</table>
+				</div><br />';
+		}
+		else
+			echo '
+			<p class="windowbg2 description">', $txt['showPermissions_none_general'], '</p>';
+
+		// Board permission section.
+		echo '
+			<div class="tborder">
+				<form action="' . $scripturl . '?action=profile;u=', $context['id_member'], ';area=permissions#board_permissions" method="post" accept-charset="', $context['character_set'], '">
+					<div class="cat_bar">
+						<h3 class="catbg">
+							<a id="board_permissions"></a>', $txt['showPermissions_select'], ':
+							<select name="board" onchange="if (this.options[this.selectedIndex].value) this.form.submit();">
+								<option value="0"', $context['board'] == 0 ? ' selected="selected"' : '', '>', $txt['showPermissions_global'], '&nbsp;</option>';
+				if (!empty($context['boards']))
+					echo '
+								<option value="" disabled="disabled">---------------------------</option>';
+
+				// Fill the box with any local permission boards.
+				foreach ($context['boards'] as $board)
+					echo '
+								<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['name'], ' (', $board['profile_name'], ')</option>';
+
+				echo '
+							</select>
+						</h3>
+					</div>
+				</form>';
+		if (!empty($context['member']['permissions']['board']))
+		{
+			echo '
+				<table class="table_grid" width="100%" cellspacing="0">
+					<thead>
+						<tr class="titlebg">
+							<th class="lefttext first_th" scope="col" width="50%">', $txt['showPermissions_permission'], '</th>
+							<th class="lefttext last_th" scope="col" width="50%">', $txt['showPermissions_status'], '</th>
+						</tr>
+					</thead>
+					<tbody>';
+			foreach ($context['member']['permissions']['board'] as $permission)
+			{
+				echo '
+						<tr>
+							<td class="windowbg" title="', $permission['id'], '">
+								', $permission['is_denied'] ? '<del>' . $permission['name'] . '</del>' : $permission['name'], '
+							</td>
+							<td class="windowbg2 smalltext">';
+
+				if ($permission['is_denied'])
+				{
+					echo '
+								<span class="alert">', $txt['showPermissions_denied'], ':&nbsp;', implode(', ', $permission['groups']['denied']), '</span>';
+				}
+				else
+				{
+					echo '
+								', $txt['showPermissions_given'], ': &nbsp;', implode(', ', $permission['groups']['allowed']);
+				}
+				echo '
+							</td>
+						</tr>';
+			}
+			echo '
+					</tbody>
+				</table>';
+		}
+		else
+			echo '
+			<p class="windowbg2 description">', $txt['showPermissions_none_board'], '</p>';
+	echo '
+			</div>
+		</div>';
+	}
+}
+
+// Template for user statistics, showing graphs and the like.
+function template_statPanel()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// First, show a few text statistics such as post/topic count.
+	echo '
+	<div id="profileview">
+		<div id="generalstats">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/stats_info.png" alt="" class="icon" />
+					', $txt['statPanel_generalStats'], ' - ', $context['member']['name'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<dl>
+						<dt>', $txt['statPanel_total_time_online'], ':</dt>
+						<dd>', $context['time_logged_in'], '</dd>
+						<dt>', $txt['statPanel_total_posts'], ':</dt>
+						<dd>', $context['num_posts'], ' ', $txt['statPanel_posts'], '</dd>
+						<dt>', $txt['statPanel_total_topics'], ':</dt>
+						<dd>', $context['num_topics'], ' ', $txt['statPanel_topics'], '</dd>
+						<dt>', $txt['statPanel_users_polls'], ':</dt>
+						<dd>', $context['num_polls'], ' ', $txt['statPanel_polls'], '</dd>
+						<dt>', $txt['statPanel_users_votes'], ':</dt>
+						<dd>', $context['num_votes'], ' ', $txt['statPanel_votes'], '</dd>
+					</dl>
+				</div>
+			</div>
+		</div>';
+
+	// This next section draws a graph showing what times of day they post the most.
+	echo '
+		<div id="activitytime" class="flow_hidden">
+			<div class="cat_bar">
+				<h3 class="catbg">
+				<img src="', $settings['images_url'], '/stats_history.png" alt="" class="icon" />', $txt['statPanel_activityTime'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">';
+
+	// If they haven't post at all, don't draw the graph.
+	if (empty($context['posts_by_time']))
+		echo '
+					<span class="centertext">', $txt['statPanel_noPosts'], '</span>';
+	// Otherwise do!
+	else
+	{
+		echo '
+					<ul class="activity_stats flow_hidden">';
+
+		// The labels.
+		foreach ($context['posts_by_time'] as $time_of_day)
+		{
+			echo '
+						<li', $time_of_day['is_last'] ? ' class="last"' : '', '>
+							<div class="bar" style="padding-top: ', ((int) (100 - $time_of_day['relative_percent'])), 'px;" title="', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '">
+								<div style="height: ', (int) $time_of_day['relative_percent'], 'px;">
+									<span>', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '</span>
+								</div>
+							</div>
+							<span class="stats_hour">', $time_of_day['hour_format'], '</span>
+						</li>';
+		}
+
+		echo '
+
+					</ul>';
+	}
+
+	echo '
+					<span class="clear" />
+				</div>
+			</div>
+		</div>';
+
+	// Two columns with the most popular boards by posts and activity (activity = users posts / total posts).
+	echo '
+		<div class="flow_hidden">
+			<div id="popularposts">
+				<div class="cat_bar">
+					<h3 class="catbg">
+						<img src="', $settings['images_url'], '/stats_replies.png" alt="" class="icon" />', $txt['statPanel_topBoards'], '
+					</h3>
+				</div>
+				<div class="windowbg2">
+					<div class="content">';
+
+	if (empty($context['popular_boards']))
+		echo '
+						<span class="centertext">', $txt['statPanel_noPosts'], '</span>';
+
+	else
+	{
+		echo '
+						<dl>';
+
+		// Draw a bar for every board.
+		foreach ($context['popular_boards'] as $board)
+		{
+			echo '
+							<dt>', $board['link'], '</dt>
+							<dd>
+								<div class="profile_pie" style="background-position: -', ((int) ($board['posts_percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_memberposts'], $board['posts'], $board['total_posts_member'], $board['posts_percent']), '">
+									', sprintf($txt['statPanel_topBoards_memberposts'], $board['posts'], $board['total_posts_member'], $board['posts_percent']), '
+								</div>
+								<span>', empty($context['hide_num_posts']) ? $board['posts'] : '', '</span>
+							</dd>';
+		}
+
+		echo '
+						</dl>';
+	}
+	echo '
+					</div>
+				</div>
+			</div>';
+	echo '
+			<div id="popularactivity">
+				<div class="cat_bar">
+					<h3 class="catbg">
+						<img src="', $settings['images_url'], '/stats_replies.png" alt="" class="icon" />', $txt['statPanel_topBoardsActivity'], '
+					</h3>
+				</div>
+				<div class="windowbg2">
+					<div class="content">';
+
+	if (empty($context['board_activity']))
+		echo '
+						<span>', $txt['statPanel_noPosts'], '</span>';
+	else
+	{
+		echo '
+						<dl>';
+
+		// Draw a bar for every board.
+		foreach ($context['board_activity'] as $activity)
+		{
+			echo '
+							<dt>', $activity['link'], '</dt>
+							<dd>
+								<div class="profile_pie" style="background-position: -', ((int) ($activity['percent'] / 5) * 20), 'px 0;" title="', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '">
+									', sprintf($txt['statPanel_topBoards_posts'], $activity['posts'], $activity['total_posts'], $activity['posts_percent']), '
+								</div>
+								<span>', $activity['percent'], '%</span>
+							</dd>';
+		}
+
+		echo '
+						</dl>';
+	}
+	echo '
+					</div>
+				</div>
+			</div>
+		</div>';
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+// Template for editing profile options.
+function template_edit_options()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// The main header!
+	echo '
+		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : $scripturl . '?action=profile;area=' . $context['menu_item_selected'] . ';u=' . $context['id_member']), '" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data" onsubmit="return checkProfileSubmit();">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />';
+
+		// Don't say "Profile" if this isn't the profile...
+		if (!empty($context['profile_header_text']))
+			echo '
+					', $context['profile_header_text'];
+		else
+			echo '
+					', $txt['profile'];
+
+		echo '
+				</h3>
+			</div>';
+
+	// Have we some description?
+	if ($context['page_desc'])
+		echo '
+			<p class="windowbg description">', $context['page_desc'], '</p>';
+
+	echo '
+			<div class="windowbg2">
+				<div class="content">';
+
+	// Any bits at the start?
+	if (!empty($context['profile_prehtml']))
+		echo '
+					<div>', $context['profile_prehtml'], '</div>';
+
+	if (!empty($context['profile_fields']))
+		echo '
+					<dl>';
+
+	// Start the big old loop 'of love.
+	$lastItem = 'hr';
+	foreach ($context['profile_fields'] as $key => $field)
+	{
+		// We add a little hack to be sure we never get more than one hr in a row!
+		if ($lastItem == 'hr' && $field['type'] == 'hr')
+			continue;
+
+		$lastItem = $field['type'];
+		if ($field['type'] == 'hr')
+		{
+			echo '
+					</dl>
+					<hr width="100%" size="1" class="hrcolor clear" />
+					<dl>';
+		}
+		elseif ($field['type'] == 'callback')
+		{
+			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
+			{
+				$callback_func = 'template_profile_' . $field['callback_func'];
+				$callback_func();
+			}
+		}
+		else
+		{
+			echo '
+						<dt>
+							<strong', !empty($field['is_error']) ? ' class="error"' : '', '>', $field['type'] !== 'label' ? '<label for="' . $key . '">' : '', $field['label'], $field['type'] !== 'label' ? '</label>' : '', '</strong>';
+
+			// Does it have any subtext to show?
+			if (!empty($field['subtext']))
+				echo '
+							<br />
+							<span class="smalltext">', $field['subtext'], '</span>';
+
+			echo '
+						</dt>
+						<dd>';
+
+			// Want to put something infront of the box?
+			if (!empty($field['preinput']))
+				echo '
+							', $field['preinput'];
+
+			// What type of data are we showing?
+			if ($field['type'] == 'label')
+				echo '
+							', $field['value'];
+
+			// Maybe it's a text box - very likely!
+			elseif (in_array($field['type'], array('int', 'float', 'text', 'password')))
+				echo '
+							<input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' class="input_', $field['type'] == 'password' ? 'password' : 'text', '" />';
+
+			// You "checking" me out? ;)
+			elseif ($field['type'] == 'check')
+				echo '
+							<input type="hidden" name="', $key, '" value="0" /><input type="checkbox" name="', $key, '" id="', $key, '" ', !empty($field['value']) ? ' checked="checked"' : '', ' value="1" class="input_check" ', $field['input_attr'], ' />';
+
+			// Always fun - select boxes!
+			elseif ($field['type'] == 'select')
+			{
+				echo '
+							<select name="', $key, '" id="', $key, '">';
+
+				if (isset($field['options']))
+				{
+					// Is this some code to generate the options?
+					if (!is_array($field['options']))
+						$field['options'] = eval($field['options']);
+					// Assuming we now have some!
+					if (is_array($field['options']))
+						foreach ($field['options'] as $value => $name)
+							echo '
+								<option value="', $value, '" ', $value == $field['value'] ? 'selected="selected"' : '', '>', $name, '</option>';
+				}
+
+				echo '
+							</select>';
+			}
+
+			// Something to end with?
+			if (!empty($field['postinput']))
+				echo '
+							', $field['postinput'];
+
+			echo '
+						</dd>';
+		}
+	}
+
+	if (!empty($context['profile_fields']))
+		echo '
+					</dl>';
+
+	// Are there any custom profile fields - if so print them!
+	if (!empty($context['custom_fields']))
+	{
+		if ($lastItem != 'hr')
+			echo '
+					<hr width="100%" size="1" class="hrcolor clear" />';
+
+		echo '
+					<dl>';
+
+		foreach ($context['custom_fields'] as $field)
+		{
+			echo '
+						<dt>
+							<strong>', $field['name'], ': </strong><br />
+							<span class="smalltext">', $field['desc'], '</span>
+						</dt>
+						<dd>
+							', $field['input_html'], '
+						</dd>';
+		}
+
+		echo '
+					</dl>';
+
+	}
+
+	// Any closing HTML?
+	if (!empty($context['profile_posthtml']))
+		echo '
+					<div>', $context['profile_posthtml'], '</div>';
+
+	// Only show the password box if it's actually needed.
+	if ($context['require_password'])
+		echo '
+					<dl>
+						<dt>
+							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '><label for="oldpasswrd">', $txt['current_password'], ': </label></strong><br />
+							<span class="smalltext">', $txt['required_security_reasons'], '</span>
+						</dt>
+						<dd>
+							<input type="password" name="oldpasswrd" id="oldpasswrd" size="20" style="margin-right: 4ex;" class="input_password" />
+						</dd>
+					</dl>';
+
+	echo '
+					<hr class="hrcolor" />';
+
+	// The button shouldn't say "Change profile" unless we're changing the profile...
+	if (!empty($context['submit_button_text']))
+		echo '
+					<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button_submit" />';
+	else
+		echo '
+					<input type="submit" name="save" value="', $txt['change_profile'], '" class="button_submit" />';
+
+	if (!empty($context['token_check']))
+		echo '
+					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	echo '
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="u" value="', $context['id_member'], '" />
+					<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<br />
+		</form>';
+
+	// Some javascript!
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			function checkProfileSubmit()
+			{';
+
+	// If this part requires a password, make sure to give a warning.
+	if ($context['require_password'])
+		echo '
+				// Did you forget to type your password?
+				if (document.forms.creator.oldpasswrd.value == "")
+				{
+					alert("', $txt['required_security_reasons'], '");
+					return false;
+				}';
+
+	// Any onsubmit javascript?
+	if (!empty($context['profile_onsubmit_javascript']))
+		echo '
+				', $context['profile_javascript'];
+
+	echo '
+			}';
+
+	// Any totally custom stuff?
+	if (!empty($context['profile_javascript']))
+		echo '
+			', $context['profile_javascript'];
+
+	echo '
+		// ]]></script>';
+
+	// Any final spellchecking stuff?
+	if (!empty($context['show_spellchecking']))
+		echo '
+		<form name="spell_form" id="spell_form" method="post" accept-charset="', $context['character_set'], '" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spellstring" value="" /></form>';
+}
+
+// Personal Message settings.
+function template_profile_pm_settings()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+								<dt>
+									<label for="pm_prefs">', $txt['pm_display_mode'], ':</label>
+								</dt>
+								<dd>
+									<select name="pm_prefs" id="pm_prefs" onchange="if (this.value == 2 &amp;&amp; !document.getElementById(\'copy_to_outbox\').checked) alert(\'', $txt['pm_recommend_enable_outbox'], '\');">
+										<option value="0"', $context['display_mode'] == 0 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_all'], '</option>
+										<option value="1"', $context['display_mode'] == 1 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_one'], '</option>
+										<option value="2"', $context['display_mode'] == 2 ? ' selected="selected"' : '', '>', $txt['pm_display_mode_linked'], '</option>
+									</select>
+								</dd>
+								<dt>
+									<label for="view_newest_pm_first">', $txt['recent_pms_at_top'], '</label>
+								</dt>
+								<dd>
+										<input type="hidden" name="default_options[view_newest_pm_first]" value="0" />
+										<input type="checkbox" name="default_options[view_newest_pm_first]" id="view_newest_pm_first" value="1"', !empty($context['member']['options']['view_newest_pm_first']) ? ' checked="checked"' : '', ' class="input_check" />
+								</dd>
+						</dl>
+						<hr />
+						<dl>
+								<dt>
+										<label for="pm_receive_from">', $txt['pm_receive_from'], '</label>
+								</dt>
+								<dd>
+										<select name="pm_receive_from" id="pm_receive_from">
+												<option value="0"', empty($context['receive_from']) || (empty($modSettings['enable_buddylist']) && $context['receive_from'] < 3) ? ' selected="selected"' : '', '>', $txt['pm_receive_from_everyone'], '</option>';
+
+	if (!empty($modSettings['enable_buddylist']))
+		echo '
+												<option value="1"', !empty($context['receive_from']) && $context['receive_from'] == 1 ? ' selected="selected"' : '', '>', $txt['pm_receive_from_ignore'], '</option>
+												<option value="2"', !empty($context['receive_from']) && $context['receive_from'] == 2 ? ' selected="selected"' : '', '>', $txt['pm_receive_from_buddies'], '</option>';
+
+	echo '
+												<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected="selected"' : '', '>', $txt['pm_receive_from_admins'], '</option>
+										</select>
+								</dd>
+								<dt>
+										<label for="pm_email_notify">', $txt['email_notify'], '</label>
+								</dt>
+								<dd>
+										<select name="pm_email_notify" id="pm_email_notify">
+												<option value="0"', empty($context['send_email']) ? ' selected="selected"' : '', '>', $txt['email_notify_never'], '</option>
+												<option value="1"', !empty($context['send_email']) && ($context['send_email'] == 1 || (empty($modSettings['enable_buddylist']) && $context['send_email'] > 1)) ? ' selected="selected"' : '', '>', $txt['email_notify_always'], '</option>';
+
+	if (!empty($modSettings['enable_buddylist']))
+		echo '
+												<option value="2"', !empty($context['send_email']) && $context['send_email'] > 1 ? ' selected="selected"' : '', '>', $txt['email_notify_buddies'], '</option>';
+
+	echo '
+										</select>
+								</dd>
+								<dt>
+										<label for="popup_messages">', $txt['popup_messages'], '</label>
+								</dt>
+								<dd>
+										<input type="hidden" name="default_options[popup_messages]" value="0" />
+										<input type="checkbox" name="default_options[popup_messages]" id="popup_messages" value="1"', !empty($context['member']['options']['popup_messages']) ? ' checked="checked"' : '', ' class="input_check" />
+								</dd>
+						</dl>
+						<hr />
+						<dl>
+								<dt>
+										<label for="copy_to_outbox"> ', $txt['copy_to_outbox'], '</label>
+								</dt>
+								<dd>
+										<input type="hidden" name="default_options[copy_to_outbox]" value="0" />
+										<input type="checkbox" name="default_options[copy_to_outbox]" id="copy_to_outbox" value="1"', !empty($context['member']['options']['copy_to_outbox']) ? ' checked="checked"' : '', ' class="input_check" />
+								</dd>
+								<dt>
+										<label for="pm_remove_inbox_label">', $txt['pm_remove_inbox_label'], '</label>
+								</dt>
+								<dd>
+										<input type="hidden" name="default_options[pm_remove_inbox_label]" value="0" />
+										<input type="checkbox" name="default_options[pm_remove_inbox_label]" id="pm_remove_inbox_label" value="1"', !empty($context['member']['options']['pm_remove_inbox_label']) ? ' checked="checked"' : '', ' class="input_check" />
+								</dd>';
+
+}
+
+// Template for showing theme settings. Note: template_options() actually adds the theme specific options.
+function template_profile_theme_settings()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	echo '
+							<dt>
+								<label for="show_board_desc">', $txt['board_desc_inside'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[show_board_desc]" value="0" />
+								<input type="checkbox" name="default_options[show_board_desc]" id="show_board_desc" value="1"', !empty($context['member']['options']['show_board_desc']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+							<dt>
+								<label for="show_children">', $txt['show_children'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[show_children]" value="0" />
+								<input type="checkbox" name="default_options[show_children]" id="show_children" value="1"', !empty($context['member']['options']['show_children']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+							<dt>
+								<label for="use_sidebar_menu">', $txt['use_sidebar_menu'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[use_sidebar_menu]" value="0" />
+								<input type="checkbox" name="default_options[use_sidebar_menu]" id="use_sidebar_menu" value="1"', !empty($context['member']['options']['use_sidebar_menu']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+							<dt>
+								<label for="show_no_avatars">', $txt['show_no_avatars'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[show_no_avatars]" value="0" />
+								<input type="checkbox" name="default_options[show_no_avatars]" id="show_no_avatars" value="1"', !empty($context['member']['options']['show_no_avatars']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+							<dt>
+								<label for="show_no_signatures">', $txt['show_no_signatures'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[show_no_signatures]" value="0" />
+								<input type="checkbox" name="default_options[show_no_signatures]" id="show_no_signatures" value="1"', !empty($context['member']['options']['show_no_signatures']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+
+	if ($settings['allow_no_censored'])
+		echo '
+							<dt>
+								<label for="show_no_censored">' . $txt['show_no_censored'] . '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[show_no_censored]" value="0" />
+								<input type="checkbox" name="default_options[show_no_censored]" id="show_no_censored" value="1"' . (!empty($context['member']['options']['show_no_censored']) ? ' checked="checked"' : '') . ' class="input_check" />
+							</dd>';
+
+	echo '
+							<dt>
+								<label for="return_to_post">', $txt['return_to_post'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[return_to_post]" value="0" />
+								<input type="checkbox" name="default_options[return_to_post]" id="return_to_post" value="1"', !empty($context['member']['options']['return_to_post']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>
+							<dt>
+								<label for="no_new_reply_warning">', $txt['no_new_reply_warning'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[no_new_reply_warning]" value="0" />
+								<input type="checkbox" name="default_options[no_new_reply_warning]" id="no_new_reply_warning" value="1"', !empty($context['member']['options']['no_new_reply_warning']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+
+	if (!empty($modSettings['enable_buddylist']))
+		echo '
+							<dt>
+								<label for="posts_apply_ignore_list">', $txt['posts_apply_ignore_list'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[posts_apply_ignore_list]" value="0" />
+								<input type="checkbox" name="default_options[posts_apply_ignore_list]" id="posts_apply_ignore_list" value="1"', !empty($context['member']['options']['posts_apply_ignore_list']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+
+	echo '
+							<dt>
+								<label for="view_newest_first">', $txt['recent_posts_at_top'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[view_newest_first]" value="0" />
+								<input type="checkbox" name="default_options[view_newest_first]" id="view_newest_first" value="1"', !empty($context['member']['options']['view_newest_first']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+
+	// Choose WYSIWYG settings?
+	if (empty($modSettings['disable_wysiwyg']))
+		echo '
+							<dt>
+								<label for="wysiwyg_default">', $txt['wysiwyg_default'], '</label>
+							</dt>
+							<dd>
+								<input type="hidden" name="default_options[wysiwyg_default]" value="0" />
+								<input type="checkbox" name="default_options[wysiwyg_default]" id="wysiwyg_default" value="1"', !empty($context['member']['options']['wysiwyg_default']) ? ' checked="checked"' : '', ' class="input_check" />
+							</dd>';
+
+	if (empty($modSettings['disableCustomPerPage']))
+	{
+		echo '
+							<dt>
+								<label for="topics_per_page">', $txt['topics_per_page'], '</label>
+							</dt>
+							<dd>
+								<select name="default_options[topics_per_page]" id="topics_per_page">
+									<option value="0"', empty($context['member']['options']['topics_per_page']) ? ' selected="selected"' : '', '>', $txt['per_page_default'], ' (', $modSettings['defaultMaxTopics'], ')</option>
+									<option value="5"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 5 ? ' selected="selected"' : '', '>5</option>
+									<option value="10"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 10 ? ' selected="selected"' : '', '>10</option>
+									<option value="25"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 25 ? ' selected="selected"' : '', '>25</option>
+									<option value="50"', !empty($context['member']['options']['topics_per_page']) && $context['member']['options']['topics_per_page'] == 50 ? ' selected="selected"' : '', '>50</option>
+								</select>
+							</dd>
+							<dt>
+								<label for="messages_per_page">', $txt['messages_per_page'], '</label>
+							</dt>
+							<dd>
+								<select name="default_options[messages_per_page]" id="messages_per_page">
+									<option value="0"', empty($context['member']['options']['messages_per_page']) ? ' selected="selected"' : '', '>', $txt['per_page_default'], ' (', $modSettings['defaultMaxMessages'], ')</option>
+									<option value="5"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 5 ? ' selected="selected"' : '', '>5</option>
+									<option value="10"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 10 ? ' selected="selected"' : '', '>10</option>
+									<option value="25"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 25 ? ' selected="selected"' : '', '>25</option>
+									<option value="50"', !empty($context['member']['options']['messages_per_page']) && $context['member']['options']['messages_per_page'] == 50 ? ' selected="selected"' : '', '>50</option>
+								</select>
+							</dd>';
+	}
+
+	if (!empty($modSettings['cal_enabled']))
+		echo '
+							<dt>
+								<label for="calendar_start_day">', $txt['calendar_start_day'], ':</label>
+							</dt>
+							<dd>
+								<select name="default_options[calendar_start_day]" id="calendar_start_day">
+									<option value="0"', empty($context['member']['options']['calendar_start_day']) ? ' selected="selected"' : '', '>', $txt['days'][0], '</option>
+									<option value="1"', !empty($context['member']['options']['calendar_start_day']) && $context['member']['options']['calendar_start_day'] == 1 ? ' selected="selected"' : '', '>', $txt['days'][1], '</option>
+									<option value="6"', !empty($context['member']['options']['calendar_start_day']) && $context['member']['options']['calendar_start_day'] == 6 ? ' selected="selected"' : '', '>', $txt['days'][6], '</option>
+								</select>
+							</dd>';
+
+	echo '
+							<dt>
+								<label for="display_quick_reply">', $txt['display_quick_reply'], '</label>
+							</dt>
+							<dd>
+								<select name="default_options[display_quick_reply]" id="display_quick_reply">
+									<option value="0"', empty($context['member']['options']['display_quick_reply']) ? ' selected="selected"' : '', '>', $txt['display_quick_reply1'], '</option>
+									<option value="1"', !empty($context['member']['options']['display_quick_reply']) && $context['member']['options']['display_quick_reply'] == 1 ? ' selected="selected"' : '', '>', $txt['display_quick_reply2'], '</option>
+									<option value="2"', !empty($context['member']['options']['display_quick_reply']) && $context['member']['options']['display_quick_reply'] == 2 ? ' selected="selected"' : '', '>', $txt['display_quick_reply3'], '</option>
+									<option value="3"', !empty($context['member']['options']['display_quick_reply']) && $context['member']['options']['display_quick_reply'] == 3 ? ' selected="selected"' : '', '>', $txt['display_quick_reply4'], '</option>
+								</select>
+							</dd>
+							<dt>
+								<label for="display_quick_mod">', $txt['display_quick_mod'], '</label>
+							</dt>
+							<dd>
+								<select name="default_options[display_quick_mod]" id="display_quick_mod">
+									<option value="0"', empty($context['member']['options']['display_quick_mod']) ? ' selected="selected"' : '', '>', $txt['display_quick_mod_none'], '</option>
+									<option value="1"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] == 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_check'], '</option>
+									<option value="2"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] != 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_image'], '</option>
+								</select>
+							</dd>';
+}
+
+function template_notification()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	// The main containing header.
+	echo '
+		<form action="', $scripturl, '?action=profile;area=notification;save" method="post" accept-charset="', $context['character_set'], '" id="notify_options" class="flow_hidden">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['profile'], '
+				</h3>
+			</div>
+			<p class="windowbg description">', $txt['notification_info'], '</p>
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">';
+
+	// Allow notification on announcements to be disabled?
+	if (!empty($modSettings['allow_disableAnnounce']))
+		echo '
+						<dt>
+							<label for="notify_announcements">', $txt['notify_important_email'], '</label>
+						</dt>
+						<dd>
+							<input type="hidden" name="notify_announcements" value="0" />
+							<input type="checkbox" id="notify_announcements" name="notify_announcements"', !empty($context['member']['notify_announcements']) ? ' checked="checked"' : '', ' class="input_check" />
+						</dd>';
+
+	// More notification options.
+	echo '
+						<dt>
+							<label for="auto_notify">', $txt['auto_notify'], '</label>
+						</dt>
+						<dd>
+							<input type="hidden" name="default_options[auto_notify]" value="0" />
+							<input type="checkbox" id="auto_notify" name="default_options[auto_notify]" value="1"', !empty($context['member']['options']['auto_notify']) ? ' checked="checked"' : '', ' class="input_check" />
+						</dd>';
+
+	if (empty($modSettings['disallow_sendBody']))
+		echo '
+						<dt>
+							<label for="notify_send_body">', $txt['notify_send_body'], '</label>
+						</dt>
+						<dd>
+							<input type="hidden" name="notify_send_body" value="0" />
+							<input type="checkbox" id="notify_send_body" name="notify_send_body"', !empty($context['member']['notify_send_body']) ? ' checked="checked"' : '', ' class="input_check" />
+						</dd>';
+
+	echo '
+						<dt>
+							<label for="notify_regularity">', $txt['notify_regularity'], ':</label>
+						</dt>
+						<dd>
+							<select name="notify_regularity" id="notify_regularity">
+								<option value="0"', $context['member']['notify_regularity'] == 0 ? ' selected="selected"' : '', '>', $txt['notify_regularity_instant'], '</option>
+								<option value="1"', $context['member']['notify_regularity'] == 1 ? ' selected="selected"' : '', '>', $txt['notify_regularity_first_only'], '</option>
+								<option value="2"', $context['member']['notify_regularity'] == 2 ? ' selected="selected"' : '', '>', $txt['notify_regularity_daily'], '</option>
+								<option value="3"', $context['member']['notify_regularity'] == 3 ? ' selected="selected"' : '', '>', $txt['notify_regularity_weekly'], '</option>
+							</select>
+						</dd>
+						<dt>
+							<label for="notify_types">', $txt['notify_send_types'], ':</label>
+						</dt>
+						<dd>
+							<select name="notify_types" id="notify_types">
+								<option value="1"', $context['member']['notify_types'] == 1 ? ' selected="selected"' : '', '>', $txt['notify_send_type_everything'], '</option>
+								<option value="2"', $context['member']['notify_types'] == 2 ? ' selected="selected"' : '', '>', $txt['notify_send_type_everything_own'], '</option>
+								<option value="3"', $context['member']['notify_types'] == 3 ? ' selected="selected"' : '', '>', $txt['notify_send_type_only_replies'], '</option>
+								<option value="4"', $context['member']['notify_types'] == 4 ? ' selected="selected"' : '', '>', $txt['notify_send_type_nothing'], '</option>
+							</select>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<div>
+						<input id="notify_submit" type="submit" value="', $txt['notify_save'], '" class="button_submit" />
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="u" value="', $context['id_member'], '" />
+						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
+					</div>
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+		<br />';
+
+	template_show_list('topic_notification_list');
+
+	echo '
+		<br />';
+
+	template_show_list('board_notification_list');
+}
+
+// Template for choosing group membership.
+function template_groupMembership()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// The main containing header.
+	echo '
+		<form action="', $scripturl, '?action=profile;area=groupmembership;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['profile'], '
+				</h3>
+			</div>
+			<p class="description">', $txt['groupMembership_info'], '</p>';
+
+	// Do we have an update message?
+	if (!empty($context['update_message']))
+		echo '
+			<div class="infobox">
+				', $context['update_message'], '.
+			</div>';
+
+	// Requesting membership to a group?
+	if (!empty($context['group_request']))
+	{
+		echo '
+			<div class="groupmembership">
+				<div class="cat_bar">
+					<h3 class="catbg">', $txt['request_group_membership'], '</h3>
+				</div>
+				<div class="roundframe">
+					', $txt['request_group_membership_desc'], ':
+					<textarea name="reason" rows="4" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 99%; min-width: 99%' : 'width: 99%') . ';"></textarea>
+					<div class="righttext" style="margin: 0.5em 0.5% 0 0.5%;">
+						<input type="hidden" name="gid" value="', $context['group_request']['id'], '" />
+						<input type="submit" name="req" value="', $txt['submit_request'], '" class="button_submit" />
+					</div>
+				</div>
+			</div>';
+	}
+	else
+	{
+		echo '
+			<table border="0" width="100%" cellspacing="0" cellpadding="4" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th" scope="col" ', $context['can_edit_primary'] ? ' colspan="2"' : '', '>', $txt['current_membergroups'], '</th>
+						<th class="last_th" scope="col"></th>
+					</tr>
+				</thead>
+				<tbody>';
+
+		$alternate = true;
+		foreach ($context['groups']['member'] as $group)
+		{
+			echo '
+					<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" id="primdiv_', $group['id'], '">';
+
+				if ($context['can_edit_primary'])
+					echo '
+						<td width="4%">
+							<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '" ', $group['is_primary'] ? 'checked="checked"' : '', ' onclick="highlightSelected(\'primdiv_' . $group['id'] . '\');" ', $group['can_be_primary'] ? '' : 'disabled="disabled"', ' class="input_radio" />
+						</td>';
+
+				echo '
+						<td>
+							<label for="primary_', $group['id'], '"><strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br /><span class="smalltext">' . $group['desc'] . '</span>' : ''), '</label>
+						</td>
+						<td width="15%" class="righttext">';
+
+				// Can they leave their group?
+				if ($group['can_leave'])
+					echo '
+							<a href="' . $scripturl . '?action=profile;save;u=' . $context['id_member'] . ';area=groupmembership;' . $context['session_var'] . '=' . $context['session_id'] . ';gid=' . $group['id'] . ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">' . $txt['leave_group'] . '</a>';
+				echo '
+						</td>
+					</tr>';
+			$alternate = !$alternate;
+		}
+
+		echo '
+				</tbody>
+			</table>';
+
+		if ($context['can_edit_primary'])
+			echo '
+			<div class="padding righttext">
+				<input type="submit" value="', $txt['make_primary'], '" class="button_submit" />
+			</div>';
+
+		// Any groups they can join?
+		if (!empty($context['groups']['available']))
+		{
+			echo '
+			<br />
+			<table border="0" width="100%" cellspacing="0" cellpadding="4" class="table_grid">
+				<thead>
+					<tr class="catbg">
+						<th class="first_th" scope="col">
+							', $txt['available_groups'], '
+						</th>
+						<th class="last_th" scope="col"></th>
+					</tr>
+				</thead>
+				<tbody>';
+
+			$alternate = true;
+			foreach ($context['groups']['available'] as $group)
+			{
+				echo '
+					<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+						<td>
+							<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br /><span class="smalltext">' . $group['desc'] . '</span>' : ''), '
+						</td>
+						<td width="15%" class="lefttext">';
+
+				if ($group['type'] == 3)
+					echo '
+							<a href="', $scripturl, '?action=profile;save;u=', $context['id_member'], ';area=groupmembership;', $context['session_var'], '=', $context['session_id'], ';gid=', $group['id'], ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">', $txt['join_group'], '</a>';
+				elseif ($group['type'] == 2 && $group['pending'])
+					echo '
+							', $txt['approval_pending'];
+				elseif ($group['type'] == 2)
+					echo '
+							<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=groupmembership;request=', $group['id'], '">', $txt['request_group'], '</a>';
+
+//				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+				echo '
+						</td>
+					</tr>';
+				$alternate = !$alternate;
+			}
+			echo '
+				</tbody>
+			</table>';
+		}
+
+		// Javascript for the selector stuff.
+		echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+		var prevClass = "";
+		var prevDiv = "";
+		function highlightSelected(box)
+		{
+			if (prevClass != "")
+			{
+				prevDiv.className = prevClass;
+			}
+			prevDiv = document.getElementById(box);
+			prevClass = prevDiv.className;
+
+			prevDiv.className = "highlight2";
+		}';
+		if (isset($context['groups']['member'][$context['primary_group']]))
+			echo '
+		highlightSelected("primdiv_' . $context['primary_group'] . '");';
+		echo '
+	// ]]></script>';
+	}
+
+	if (!empty($context['token_check']))
+		echo '
+				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	echo '
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+				<input type="hidden" name="u" value="', $context['id_member'], '" />
+			</form>';
+}
+
+function template_ignoreboards()
+{
+	global $context, $txt, $settings, $scripturl;
+	// The main containing header.
+	echo '
+	<form action="', $scripturl, '?action=profile;area=ignoreboards;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['profile'], '
+			</h3>
+		</div>
+		<p class="description">', $txt['ignoreboards_info'], '</p>
+		<div class="windowbg2">
+			<div class="content flow_hidden">
+				<ul class="ignoreboards floatleft">';
+
+	$i = 0;
+	$limit = ceil($context['num_boards'] / 2);
+	foreach ($context['categories'] as $category)
+	{
+		if ($i == $limit)
+		{
+			echo '
+				</ul>
+				<ul class="ignoreboards floatright">';
+
+			$i++;
+		}
+
+		echo '
+					<li class="category">
+						<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'creator\'); return false;">', $category['name'], '</a>
+						<ul>';
+
+		foreach ($category['boards'] as $board)
+		{
+			if ($i == $limit)
+				echo '
+						</ul>
+					</li>
+				</ul>
+				<ul class="ignoreboards floatright">
+					<li class="category">
+						<ul>';
+
+			echo '
+							<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
+								<label for="ignore_brd', $board['id'], '"><input type="checkbox" id="ignore_brd', $board['id'], '" name="ignore_brd[', $board['id'], ']" value="', $board['id'], '"', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> ', $board['name'], '</label>
+							</li>';
+
+			$i++;
+		}
+
+		echo '
+						</ul>
+					</li>';
+	}
+
+	echo '
+				</ul>
+				<br class="clear" />';
+
+	// Show the standard "Save Settings" profile button.
+	template_profile_save();
+
+	echo '
+			</div>
+		</div>
+	</form>
+	<br />';
+}
+
+// Simple load some theme variables common to several warning templates.
+function template_load_warning_variables()
+{
+	global $modSettings, $context;
+
+	$context['warningBarWidth'] = 200;
+	// Setup the colors - this is a little messy for theming.
+	$context['colors'] = array(
+		0 => 'green',
+		$modSettings['warning_watch'] => 'darkgreen',
+		$modSettings['warning_moderate'] => 'orange',
+		$modSettings['warning_mute'] => 'red',
+	);
+
+	// Work out the starting color.
+	$context['current_color'] = $context['colors'][0];
+	foreach ($context['colors'] as $limit => $color)
+		if ($context['member']['warning'] >= $limit)
+			$context['current_color'] = $color;
+}
+
+// Show all warnings of a user?
+function template_viewWarning()
+{
+	global $context, $txt, $scripturl, $settings;
+
+	template_load_warning_variables();
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />
+				', sprintf($txt['profile_viewwarning_for_user'], $context['member']['name']), '
+			</h3>
+		</div>
+		<p class="description">', $txt['viewWarning_help'], '</p>
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">
+					<dt>
+						<strong>', $txt['profile_warning_name'], ':</strong>
+					</dt>
+					<dd>
+						', $context['member']['name'], '
+					</dd>
+					<dt>
+						<strong>', $txt['profile_warning_level'], ':</strong>
+					</dt>
+					<dd>
+						<div>
+							<div>
+								<div style="font-size: 8pt; height: 12pt; width: ', $context['warningBarWidth'], 'px; border: 1px solid black; background-color: white; padding: 1px; position: relative;">
+									<div id="warning_text" style="padding-top: 1pt; width: 100%; z-index: 2; color: black; position: absolute; text-align: center; font-weight: bold;">', $context['member']['warning'], '%</div>
+									<div id="warning_progress" style="width: ', $context['member']['warning'], '%; height: 12pt; z-index: 1; background-color: ', $context['current_color'], ';">&nbsp;</div>
+								</div>
+							</div>
+						</div>
+					</dd>';
+
+		// There's some impact of this?
+		if (!empty($context['level_effects'][$context['current_level']]))
+			echo '
+					<dt>
+						<strong>', $txt['profile_viewwarning_impact'], ':</strong>
+					</dt>
+					<dd>
+						', $context['level_effects'][$context['current_level']], '
+					</dd>';
+
+		echo '
+				</dl>
+			</div>
+		</div>';
+
+	template_show_list('view_warnings');
+}
+
+// Show a lovely interface for issuing warnings.
+function template_issueWarning()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	template_load_warning_variables();
+
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		function setWarningBarPos(curEvent, isMove, changeAmount)
+		{
+			barWidth = ', $context['warningBarWidth'], ';
+
+			// Are we passing the amount to change it by?
+			if (changeAmount)
+			{
+				if (document.getElementById(\'warning_level\').value == \'SAME\')
+					percent = ', $context['member']['warning'], ' + changeAmount;
+				else
+					percent = parseInt(document.getElementById(\'warning_level\').value) + changeAmount;
+			}
+			// If not then it\'s a mouse thing.
+			else
+			{
+				if (!curEvent)
+					var curEvent = window.event;
+
+				// If it\'s a movement check the button state first!
+				if (isMove)
+				{
+					if (!curEvent.button || curEvent.button != 1)
+						return false
+				}
+
+				// Get the position of the container.
+				contain = document.getElementById(\'warning_contain\');
+				position = 0;
+				while (contain != null)
+				{
+					position += contain.offsetLeft;
+					contain = contain.offsetParent;
+				}
+
+				// Where is the mouse?
+				if (curEvent.pageX)
+				{
+					mouse = curEvent.pageX;
+				}
+				else
+				{
+					mouse = curEvent.clientX;
+					mouse += document.documentElement.scrollLeft != "undefined" ? document.documentElement.scrollLeft : document.body.scrollLeft;
+				}
+
+				// Is this within bounds?
+				if (mouse < position || mouse > position + barWidth)
+					return;
+
+				percent = Math.round(((mouse - position) / barWidth) * 100);
+
+				// Round percent to the nearest 5 - by kinda cheating!
+				percent = Math.round(percent / 5) * 5;
+			}
+
+			// What are the limits?
+			minLimit = ', $context['min_allowed'], ';
+			maxLimit = ', $context['max_allowed'], ';
+
+			percent = Math.max(percent, minLimit);
+			percent = Math.min(percent, maxLimit);
+
+			size = barWidth * (percent/100);
+
+			setInnerHTML(document.getElementById(\'warning_text\'), percent + "%");
+			document.getElementById(\'warning_text\').innerHTML = percent + "%";
+			document.getElementById(\'warning_level\').value = percent;
+			document.getElementById(\'warning_progress\').style.width = size + "px";
+
+			// Get the right color.
+			color = "black"';
+
+	foreach ($context['colors'] as $limit => $color)
+		echo '
+			if (percent >= ', $limit, ')
+				color = "', $color, '";';
+
+	echo '
+			document.getElementById(\'warning_progress\').style.backgroundColor = color;
+
+			// Also set the right effect.
+			effectText = "";';
+
+	foreach ($context['level_effects'] as $limit => $text)
+		echo '
+			if (percent >= ', $limit, ')
+				effectText = "', $text, '";';
+
+	echo '
+			setInnerHTML(document.getElementById(\'cur_level_div\'), effectText);
+		}
+
+		// Disable notification boxes as required.
+		function modifyWarnNotify()
+		{
+			disable = !document.getElementById(\'warn_notify\').checked;
+			document.getElementById(\'warn_sub\').disabled = disable;
+			document.getElementById(\'warn_body\').disabled = disable;
+			document.getElementById(\'warn_temp\').disabled = disable;
+			document.getElementById(\'new_template_link\').style.display = disable ? \'none\' : \'\';
+			document.getElementById(\'preview_button\').style.display = disable ? \'none\' : \'\';
+		}
+
+		function changeWarnLevel(amount)
+		{
+			setWarningBarPos(false, false, amount);
+		}
+
+		// Warn template.
+		function populateNotifyTemplate()
+		{
+			index = document.getElementById(\'warn_temp\').value;
+			if (index == -1)
+				return false;
+
+			// Otherwise see what we can do...';
+
+	foreach ($context['notification_templates'] as $k => $type)
+		echo '
+			if (index == ', $k, ')
+				document.getElementById(\'warn_body\').value = "', strtr($type['body'], array('"' => "'", "\n" => '\\n', "\r" => '')), '";';
+
+	echo '
+		}
+
+	// ]]></script>';
+
+	echo '
+	<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=issuewarning" method="post" class="flow_hidden" accept-charset="', $context['character_set'], '">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />
+				', $context['user']['is_owner'] ? $txt['profile_warning_level'] : $txt['profile_issue_warning'], '
+			</h3>
+		</div>';
+
+	if (!$context['user']['is_owner'])
+		echo '
+		<p class="description">', $txt['profile_warning_desc'], '</p>';
+
+	echo '
+		<div class="windowbg">
+			<div class="content">
+				<dl class="settings">';
+
+	if (!$context['user']['is_owner'])
+		echo '
+					<dt>
+						<strong>', $txt['profile_warning_name'], ':</strong>
+					</dt>
+					<dd>
+						<strong>', $context['member']['name'], '</strong>
+					</dd>';
+
+	echo '
+					<dt>
+						<strong>', $txt['profile_warning_level'], ':</strong>';
+
+	// Is there only so much they can apply?
+	if ($context['warning_limit'])
+		echo '
+						<br /><span class="smalltext">', sprintf($txt['profile_warning_limit_attribute'], $context['warning_limit']), '</span>';
+
+	echo '
+					</dt>
+					<dd>
+						<div id="warndiv1" style="display: none;">
+							<div>
+								<span class="floatleft" style="padding: 0 0.5em"><a href="#" onclick="changeWarnLevel(-5); return false;">[-]</a></span>
+								<div class="floatleft" id="warning_contain" style="font-size: 8pt; height: 12pt; width: ', $context['warningBarWidth'], 'px; border: 1px solid black; background-color: white; padding: 1px; position: relative;" onmousedown="setWarningBarPos(event, true);" onmousemove="setWarningBarPos(event, true);" onclick="setWarningBarPos(event);">
+									<div id="warning_text" style="padding-top: 1pt; width: 100%; z-index: 2; color: black; position: absolute; text-align: center; font-weight: bold;">', $context['member']['warning'], '%</div>
+									<div id="warning_progress" style="width: ', $context['member']['warning'], '%; height: 12pt; z-index: 1; background-color: ', $context['current_color'], ';">&nbsp;</div>
+								</div>
+								<span class="floatleft" style="padding: 0 0.5em"><a href="#" onclick="changeWarnLevel(5); return false;">[+]</a></span>
+								<div class="clear_left smalltext">', $txt['profile_warning_impact'], ': <span id="cur_level_div">', $context['level_effects'][$context['current_level']], '</span></div>
+							</div>
+							<input type="hidden" name="warning_level" id="warning_level" value="SAME" />
+						</div>
+						<div id="warndiv2">
+							<input type="text" name="warning_level_nojs" size="6" maxlength="4" value="', $context['member']['warning'], '" class="input_text" />&nbsp;', $txt['profile_warning_max'], '
+							<div class="smalltext">', $txt['profile_warning_impact'], ':<br />';
+	// For non-javascript give a better list.
+	foreach ($context['level_effects'] as $limit => $effect)
+		echo '
+							', sprintf($txt['profile_warning_effect_text'], $limit, $effect), '<br />';
+
+	echo '
+							</div>
+						</div>
+					</dd>';
+
+	if (!$context['user']['is_owner'])
+	{
+		echo '
+					<dt>
+						<strong>', $txt['profile_warning_reason'], ':</strong><br />
+						<span class="smalltext">', $txt['profile_warning_reason_desc'], '</span>
+					</dt>
+					<dd>
+						<input type="text" name="warn_reason" id="warn_reason" value="', $context['warning_data']['reason'], '" size="50" style="width: 80%;" class="input_text" />
+					</dd>
+				</dl>
+				<hr />
+				<div id="box_preview"', !empty($context['warning_data']['body_preview']) ? '' : ' style="display:none"', '>
+					<dl class="settings">
+						<dt>
+							<strong>', $txt['preview'] , '</strong>
+						</dt>
+						<dd id="body_preview">
+							', !empty($context['warning_data']['body_preview']) ? $context['warning_data']['body_preview'] : '', '
+						</dd>
+					</dl>
+					<hr />
+				</div>
+				<dl class="settings">
+					<dt>
+						<strong><label for="warn_notify">', $txt['profile_warning_notify'], ':</label></strong>
+					</dt>
+					<dd>
+						<input type="checkbox" name="warn_notify" id="warn_notify" onclick="modifyWarnNotify();" ', $context['warning_data']['notify'] ? 'checked="checked"' : '', ' class="input_check" />
+					</dd>
+					<dt>
+						<strong><label for="warn_sub">', $txt['profile_warning_notify_subject'], ':</label></strong>
+					</dt>
+					<dd>
+						<input type="text" name="warn_sub" id="warn_sub" value="', empty($context['warning_data']['notify_subject']) ? $txt['profile_warning_notify_template_subject'] : $context['warning_data']['notify_subject'], '" size="50" style="width: 80%;" class="input_text" />
+					</dd>
+					<dt>
+						<strong><label for="warn_temp">', $txt['profile_warning_notify_body'], ':</label></strong>
+					</dt>
+					<dd>
+						<select name="warn_temp" id="warn_temp" disabled="disabled" onchange="populateNotifyTemplate();" style="font-size: x-small;">
+							<option value="-1">', $txt['profile_warning_notify_template'], '</option>
+							<option value="-1">------------------------------</option>';
+
+		foreach ($context['notification_templates'] as $id_template => $template)
+			echo '
+							<option value="', $id_template, '">', $template['title'], '</option>';
+
+		echo '
+						</select>
+						<span class="smalltext" id="new_template_link" style="display: none;">[<a href="', $scripturl, '?action=moderate;area=warnings;sa=templateedit;tid=0" target="_blank" class="new_win">', $txt['profile_warning_new_template'], '</a>]</span><br />
+						<textarea name="warn_body" id="warn_body" cols="40" rows="8" style="min-width: 50%; max-width: 99%;">', $context['warning_data']['notify_body'], '</textarea>
+					</dd>';
+	}
+	echo '
+				</dl>
+				<div class="righttext">';
+
+	if (!empty($context['token_check']))
+		echo '
+					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	echo '
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button_submit" />
+					<input type="submit" name="save" value="', $context['user']['is_owner'] ? $txt['change_profile'] : $txt['profile_warning_issue'], '" class="button_submit" />
+				</div>
+				<br class="clear" />
+			</div>
+		</div>
+	</form>';
+
+	// Previous warnings?
+	template_show_list('view_warnings');
+
+	// Do our best to get pretty javascript enabled.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+		document.getElementById(\'warndiv1\').style.display = "";
+		document.getElementById(\'preview_button\').style.display = "none";
+		document.getElementById(\'warndiv2\').style.display = "none";';
+
+	if (!$context['user']['is_owner'])
+		echo '
+		modifyWarnNotify();
+		$(document).ready(function() {
+			$("#preview_button").click(function() {
+				return ajax_getTemplatePreview();
+			});
+		});
+
+		function ajax_getTemplatePreview ()
+		{
+			$.ajax({
+				type: "POST",
+				url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
+				data: {item: "warning_preview", title: $("#warn_sub").val(), body: $("#warn_body").val(), issuing: true},
+				context: document.body,
+				success: function(request){
+					$("#box_preview").css({display:""});
+					$("#body_preview").html($(request).find(\'body\').text());
+					if ($(request).find("error").text() != \'\')
+					{
+						$("#profile_error").css({display:""});
+						var errors_html = \'<span>\' + $("#profile_error").find("span").html() + \'</span>\' + \'<ul class="list_errors" class="reset">\';
+						var errors = $(request).find(\'error\').each(function() {
+							errors_html += \'<li>\' + $(this).text() + \'</li>\';
+						});
+						errors_html += \'</ul>\';
+
+						$("#profile_error").html(errors_html);
+					}
+					else
+					{
+						$("#profile_error").css({display:"none"});
+						$("#error_list").html(\'\');
+					}
+				return false;
+				},
+			});
+			return false;
+		}';
+
+	echo '
+	// ]]></script>';
+}
+
+// Template to show for deleting a users account - now with added delete post capability!
+function template_deleteAccount()
+{
+	global $context, $settings, $options, $scripturl, $txt, $scripturl;
+
+	// The main containing header.
+	echo '
+		<form action="', $scripturl, '?action=profile;area=deleteaccount;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
+			<div class="title_bar">
+				<h3 class="titlebg">
+					<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['deleteAccount'], '
+				</h3>
+			</div>';
+
+	// If deleting another account give them a lovely info box.
+	if (!$context['user']['is_owner'])
+		echo '
+			<p class="windowbg2 description">', $txt['deleteAccount_desc'], '</p>';
+	echo '
+			<div class="windowbg2">
+				<div class="content">';
+
+	// If they are deleting their account AND the admin needs to approve it - give them another piece of info ;)
+	if ($context['needs_approval'])
+		echo '
+					<div class="errorbox">', $txt['deleteAccount_approval'], '</div>';
+
+	// If the user is deleting their own account warn them first - and require a password!
+	if ($context['user']['is_owner'])
+	{
+		echo '
+					<div class="alert">', $txt['own_profile_confirm'], '</div>
+					<div>
+						<strong', (isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : ''), '>', $txt['current_password'], ': </strong>
+						<input type="password" name="oldpasswrd" size="20" class="input_password" />&nbsp;&nbsp;&nbsp;&nbsp;
+						<input type="submit" value="', $txt['yes'], '" class="button_submit" />';
+
+		if (!empty($context['token_check']))
+			echo '
+				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+		echo '
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="u" value="', $context['id_member'], '" />
+						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
+					</div>';
+	}
+	// Otherwise an admin doesn't need to enter a password - but they still get a warning - plus the option to delete lovely posts!
+	else
+	{
+		echo '
+					<div class="alert">', $txt['deleteAccount_warning'], '</div>';
+
+		// Only actually give these options if they are kind of important.
+		if ($context['can_delete_posts'])
+			echo '
+					<div>
+						', $txt['deleteAccount_posts'], ':
+						<select name="remove_type">
+							<option value="none">', $txt['deleteAccount_none'], '</option>
+							<option value="posts">', $txt['deleteAccount_all_posts'], '</option>
+							<option value="topics">', $txt['deleteAccount_topics'], '</option>
+						</select>
+					</div>';
+
+		echo '
+					<div>
+						<label for="deleteAccount"><input type="checkbox" name="deleteAccount" id="deleteAccount" value="1" class="input_check" onclick="if (this.checked) return confirm(\'', $txt['deleteAccount_confirm'], '\');" /> ', $txt['deleteAccount_member'], '.</label>
+					</div>
+					<div>
+						<input type="submit" value="', $txt['delete'], '" class="button_submit" />';
+
+		if (!empty($context['token_check']))
+			echo '
+				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+		echo '
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="u" value="', $context['id_member'], '" />
+						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
+					</div>';
+	}
+	echo '
+				</div>
+			</div>
+			<br />
+		</form>';
+}
+
+// Template for the password box/save button stuck at the bottom of every profile page.
+function template_profile_save()
+{
+	global $context, $settings, $options, $txt;
+
+	echo '
+
+					<hr width="100%" size="1" class="hrcolor clear" />';
+
+	// Only show the password box if it's actually needed.
+	if ($context['require_password'])
+		echo '
+					<dl>
+						<dt>
+							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br />
+							<span class="smalltext">', $txt['required_security_reasons'], '</span>
+						</dt>
+						<dd>
+							<input type="password" name="oldpasswrd" size="20" style="margin-right: 4ex;" class="input_password" />
+						</dd>
+					</dl>';
+
+	echo '
+					<div class="righttext">
+						<input type="submit" value="', $txt['change_profile'], '" class="button_submit" />
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+						<input type="hidden" name="u" value="', $context['id_member'], '" />
+						<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
+					</div>';
+}
+
+// Small template for showing an error message upon a save problem in the profile.
+function template_error_message()
+{
+	global $context, $txt;
+
+	echo '
+		<div class="errorbox" ', empty($context['post_errors']) ? 'style="display:none" ' : '', 'id="profile_error">';
+
+	if (!empty($context['post_errors']))
+	{
+		echo '
+			<span>', !empty($context['custom_error_title']) ? $context['custom_error_title'] : $txt['profile_errors_occurred'], ':</span>
+			<ul id="list_errors">';
+
+		// Cycle through each error and display an error message.
+		foreach ($context['post_errors'] as $error)
+			echo '
+				<li>', isset($txt['profile_error_' . $error]) ? $txt['profile_error_' . $error] : $error, '</li>';
+
+		echo '
+			</ul>';
+	}
+
+	echo '
+		</div>';
+}
+
+// Display a load of drop down selectors for allowing the user to change group.
+function template_profile_group_manage()
+{
+	global $context, $txt, $scripturl;
+
+	echo '
+							<dt>
+								<strong>', $txt['primary_membergroup'], ': </strong><br />
+								<span class="smalltext">[<a href="', $scripturl, '?action=helpadmin;help=moderator_why_missing" onclick="return reqWin(this.href);">', $txt['moderator_why_missing'], '</a>]</span>
+							</dt>
+							<dd>
+								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
+		
+		// Fill the select box with all primary member groups that can be assigned to a member.
+		foreach ($context['member_groups'] as $member_group)
+			if (!empty($member_group['can_be_primary']))
+				echo '
+									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected="selected"' : '', '>
+										', $member_group['name'], '
+									</option>';
+		echo '
+								</select>
+							</dd>
+							<dt>
+								<strong>', $txt['additional_membergroups'], ':</strong>
+							</dt>
+							<dd>
+								<span id="additional_groupsList">
+									<input type="hidden" name="additional_groups[]" value="0" />';
+
+		// For each membergroup show a checkbox so members can be assigned to more than one group.
+		foreach ($context['member_groups'] as $member_group)
+			if ($member_group['can_be_additional'])
+				echo '
+									<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked="checked"' : '', ' class="input_check" /> ', $member_group['name'], '</label><br />';
+		echo '
+								</span>
+								<a href="javascript:void(0);" onclick="document.getElementById(\'additional_groupsList\').style.display = \'block\'; document.getElementById(\'additional_groupsLink\').style.display = \'none\'; return false;" id="additional_groupsLink" style="display: none;">', $txt['additional_membergroups_show'], '</a>
+								<script type="text/javascript"><!-- // --><![CDATA[
+									document.getElementById("additional_groupsList").style.display = "none";
+									document.getElementById("additional_groupsLink").style.display = "";
+								// ]]></script>
+							</dd>';
+
+}
+
+// Callback function for entering a birthdate!
+function template_profile_birthdate()
+{
+	global $txt, $context;
+
+	// Just show the pretty box!
+	echo '
+							<dt>
+								<strong>', $txt['dob'], ':</strong><br />
+								<span class="smalltext">', $txt['dob_year'], ' - ', $txt['dob_month'], ' - ', $txt['dob_day'], '</span>
+							</dt>
+							<dd>
+								<input type="text" name="bday3" size="4" maxlength="4" value="', $context['member']['birth_date']['year'], '" class="input_text" /> -
+								<input type="text" name="bday1" size="2" maxlength="2" value="', $context['member']['birth_date']['month'], '" class="input_text" /> -
+								<input type="text" name="bday2" size="2" maxlength="2" value="', $context['member']['birth_date']['day'], '" class="input_text" />
+							</dd>';
+}
+
+// Show the signature editing box?
+function template_profile_signature_modify()
+{
+	global $txt, $context, $settings, $scripturl;
+
+	echo '
+							<dt id="current_signature"', !isset($context['member']['current_signature']) ? ' style="display:none"' : '', '>
+								<strong>', $txt['current_signature'], ':</strong>
+							</dt>
+							<dd id="current_signature_display"', !isset($context['member']['current_signature']) ? ' style="display:none"' : '', '>
+								', isset($context['member']['current_signature']) ? $context['member']['current_signature'] : '', '<hr />
+							</dd>';
+	echo '
+							<dt id="preview_signature"', !isset($context['member']['signature_preview']) ? ' style="display:none"' : '', '>
+								<strong>', $txt['signature_preview'], ':</strong>
+							</dt>
+							<dd id="preview_signature_display"', !isset($context['member']['signature_preview']) ? ' style="display:none"' : '', '>
+								', isset($context['member']['signature_preview']) ? $context['member']['signature_preview'] : '', '<hr />
+							</dd>';
+
+	echo '
+							<dt>
+								<strong>', $txt['signature'], ':</strong><br />
+								<span class="smalltext">', $txt['sig_info'], '</span><br />
+								<br />';
+
+	if ($context['show_spellchecking'])
+		echo '
+								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button_submit" />';
+
+		echo '
+							</dt>
+							<dd>
+								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50" style="min-width: 50%; max-width: 99%;">', $context['member']['signature'], '</textarea><br />';
+
+	// If there is a limit at all!
+	if (!empty($context['signature_limits']['max_length']))
+		echo '
+								<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br />';
+
+	if (!empty($context['show_preview_button']))
+		echo '
+						<input type="submit" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '" class="button_submit" />';
+
+	if ($context['signature_warning'])
+		echo '
+								<span class="smalltext">', $context['signature_warning'], '</span>';
+
+	// Load the spell checker?
+	if ($context['show_spellchecking'])
+		echo '
+								<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/spellcheck.js"></script>';
+
+	// Some javascript used to count how many characters have been used so far in the signature.
+	echo '
+								<script type="text/javascript"><!-- // --><![CDATA[
+									var maxLength = ', $context['signature_limits']['max_length'], ';
+
+									$(document).ready(function() {
+										calcCharLeft();
+										$("#preview_button").click(function() {
+											return ajax_getSignaturePreview(true);
+										});
+									});
+								// ]]></script>
+							</dd>';
+}
+
+function template_profile_avatar_select()
+{
+	global $context, $txt, $modSettings;
+
+	// Start with the upper menu
+	echo '
+							<dt>
+								<strong id="personal_picture"><label for="avatar_upload_box">', $txt['personal_picture'], '</label></strong>
+								<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_none" value="none"' . ($context['member']['avatar']['choice'] == 'none' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_none"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['no_avatar'] . '</label><br />
+								', !empty($context['member']['avatar']['allow_server_stored']) ? '<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_server_stored" value="server_stored"' . ($context['member']['avatar']['choice'] == 'server_stored' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_server_stored"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['choose_avatar_gallery'] . '</label><br />' : '', '
+								', !empty($context['member']['avatar']['allow_external']) ? '<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_external" value="external"' . ($context['member']['avatar']['choice'] == 'external' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_external"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['my_own_pic'] . '</label><br />' : '', '
+								', !empty($context['member']['avatar']['allow_upload']) ? '<input type="radio" onclick="swap_avatar(this); return true;" name="avatar_choice" id="avatar_choice_upload" value="upload"' . ($context['member']['avatar']['choice'] == 'upload' ? ' checked="checked"' : '') . ' class="input_radio" /><label for="avatar_choice_upload"' . (isset($context['modify_error']['bad_avatar']) ? ' class="error"' : '') . '>' . $txt['avatar_will_upload'] . '</label>' : '', '
+							</dt>
+							<dd>';
+
+	// If users are allowed to choose avatars stored on the server show selection boxes to choice them from.
+	if (!empty($context['member']['avatar']['allow_server_stored']))
+	{
+		echo '
+								<div id="avatar_server_stored">
+									<div>
+										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');">';
+		// This lists all the file catergories.
+		foreach ($context['avatars'] as $avatar)
+			echo '
+											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected="selected"' : ''), '>', $avatar['name'], '</option>';
+		echo '
+										</select>
+									</div>
+									<div>
+										<select name="file" id="file" size="10" style="display: none;" onchange="showAvatar()" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');" disabled="disabled"><option></option></select>
+									</div>
+									<div><img name="avatar" id="avatar" src="', !empty($context['member']['avatar']['allow_external']) && $context['member']['avatar']['choice'] == 'external' ? $context['member']['avatar']['external'] : $modSettings['avatar_url'] . '/blank.png', '" alt="Do Nothing" /></div>
+									<script type="text/javascript"><!-- // --><![CDATA[
+										var files = ["' . implode('", "', $context['avatar_list']) . '"];
+										var avatar = document.getElementById("avatar");
+										var cat = document.getElementById("cat");
+										var selavatar = "' . $context['avatar_selected'] . '";
+										var avatardir = "' . $modSettings['avatar_url'] . '/";
+										var size = avatar.alt.substr(3, 2) + " " + avatar.alt.substr(0, 2) + String.fromCharCode(117, 98, 116);
+										var file = document.getElementById("file");
+										var maxHeight = ', !empty($modSettings['avatar_max_height_external']) ? $modSettings['avatar_max_height_external'] : 0, ';
+										var maxWidth = ', !empty($modSettings['avatar_max_width_external']) ? $modSettings['avatar_max_width_external'] : 0, ';
+
+										if (avatar.src.indexOf("blank.png") > -1)
+											changeSel(selavatar);
+										else
+											previewExternalAvatar(avatar.src)
+
+									// ]]></script>
+								</div>';
+	}
+
+	// If the user can link to an off server avatar, show them a box to input the address.
+	if (!empty($context['member']['avatar']['allow_external']))
+	{
+		echo '
+								<div id="avatar_external">
+									<div class="smalltext">', $txt['avatar_by_url'], '</div>
+									<input type="text" name="userpicpersonal" size="45" value="', $context['member']['avatar']['external'], '" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'external\');" onchange="if (typeof(previewExternalAvatar) != \'undefined\') previewExternalAvatar(this.value);" class="input_text" />
+								</div>';
+	}
+
+	// If the user is able to upload avatars to the server show them an upload box.
+	if (!empty($context['member']['avatar']['allow_upload']))
+	{
+		echo '
+								<div id="avatar_upload">
+									<input type="file" size="44" name="attachment" id="avatar_upload_box" value="" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'upload\');" class="input_file" />
+									', ($context['member']['avatar']['id_attach'] > 0 ? '<br /><br /><img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&amp;') . 'time=' . time() . '" alt="" /><input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '" />' : ''), '
+								</div>';
+	}
+
+	echo '
+								<script type="text/javascript"><!-- // --><![CDATA[
+									', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "' . ($context['member']['avatar']['choice'] == 'server_stored' ? '' : 'none') . '";' : '', '
+									', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "' . ($context['member']['avatar']['choice'] == 'external' ? '' : 'none') . '";' : '', '
+									', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "' . ($context['member']['avatar']['choice'] == 'upload' ? '' : 'none') . '";' : '', '
+
+									function swap_avatar(type)
+									{
+										switch(type.id)
+										{
+											case "avatar_choice_server_stored":
+												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "";' : '', '
+												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "none";' : '', '
+												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "none";' : '', '
+												break;
+											case "avatar_choice_external":
+												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "none";' : '', '
+												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "";' : '', '
+												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "none";' : '', '
+												break;
+											case "avatar_choice_upload":
+												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "none";' : '', '
+												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "none";' : '', '
+												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "";' : '', '
+												break;
+											case "avatar_choice_none":
+												', !empty($context['member']['avatar']['allow_server_stored']) ? 'document.getElementById("avatar_server_stored").style.display = "none";' : '', '
+												', !empty($context['member']['avatar']['allow_external']) ? 'document.getElementById("avatar_external").style.display = "none";' : '', '
+												', !empty($context['member']['avatar']['allow_upload']) ? 'document.getElementById("avatar_upload").style.display = "none";' : '', '
+												break;
+										}
+									}
+								// ]]></script>
+							</dd>';
+}
+
+// Callback for modifying karam.
+function template_profile_karma_modify()
+{
+	global $context, $modSettings, $txt;
+
+		echo '
+							<dt>
+								<strong>', $modSettings['karmaLabel'], '</strong>
+							</dt>
+							<dd>
+								', $modSettings['karmaApplaudLabel'], ' <input type="text" name="karma_good" size="4" value="', $context['member']['karma']['good'], '" onchange="setInnerHTML(document.getElementById(\'karmaTotal\'), this.value - this.form.karma_bad.value);" style="margin-right: 2ex;" class="input_text" /> ', $modSettings['karmaSmiteLabel'], ' <input type="text" name="karma_bad" size="4" value="', $context['member']['karma']['bad'], '" onchange="this.form.karma_good.onchange();" class="input_text" /><br />
+								(', $txt['total'], ': <span id="karmaTotal">', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '</span>)
+							</dd>';
+}
+
+
+// Select the time format!
+function template_profile_timeformat_modify()
+{
+	global $context, $modSettings, $txt, $scripturl, $settings;
+
+	echo '
+							<dt>
+								<strong><label for="easyformat">', $txt['time_format'], ':</label></strong><br />
+								<a href="', $scripturl, '?action=helpadmin;help=time_format" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="floatleft" /></a>
+								<span class="smalltext">&nbsp;<label for="time_format">', $txt['date_format'], '</label></span>
+							</dt>
+							<dd>
+								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;" style="margin-bottom: 4px;">';
+	// Help the user by showing a list of common time formats.
+	foreach ($context['easy_timeformats'] as $time_format)
+		echo '
+									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected="selected"' : '', '>', $time_format['title'], '</option>';
+	echo '
+								</select><br />
+								<input type="text" name="time_format" id="time_format" value="', $context['member']['time_format'], '" size="30" class="input_text" />
+							</dd>';
+}
+
+// Time offset?
+function template_profile_timeoffset_modify()
+{
+	global $txt, $context;
+
+	echo '
+							<dt>
+								<strong', (isset($context['modify_error']['bad_offset']) ? ' class="error"' : ''), '><label for="time_offset">', $txt['time_offset'], ':</label></strong><br />
+								<span class="smalltext">', $txt['personal_time_offset'], '</span>
+							</dt>
+							<dd>
+								<input type="text" name="time_offset" id="time_offset" size="5" maxlength="5" value="', $context['member']['time_offset'], '" class="input_text" /> ', $txt['hours'], ' [<a href="javascript:void(0);" onclick="currentDate = new Date(', $context['current_forum_time_js'], '); document.getElementById(\'time_offset\').value = autoDetectTimeOffset(currentDate); return false;">', $txt['timeoffset_autodetect'], '</a>]<br />', $txt['current_time'], ': <em>', $context['current_forum_time'], '</em>
+							</dd>';
+}
+
+// Theme?
+function template_profile_theme_pick()
+{
+	global $txt, $context, $scripturl;
+
+	echo '
+							<dt>
+								<strong>', $txt['current_theme'], ':</strong>
+							</dt>
+							<dd>
+								', $context['member']['theme']['name'], ' [<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['change'], '</a>]
+							</dd>';
+}
+
+// Smiley set picker.
+function template_profile_smiley_pick()
+{
+	global $txt, $context, $modSettings, $settings;
+
+	echo '
+							<dt>
+								<strong><label for="smiley_set">', $txt['smileys_current'], ':</label></strong>
+							</dt>
+							<dd>
+								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.gif\';">';
+	foreach ($context['smiley_sets'] as $set)
+		echo '
+									<option value="', $set['id'], '"', $set['selected'] ? ' selected="selected"' : '', '>', $set['name'], '</option>';
+	echo '
+								</select> <img id="smileypr" class="centericon" src="', $context['member']['smiley_set']['id'] != 'none' ? $modSettings['smileys_url'] . '/' . ($context['member']['smiley_set']['id'] != '' ? $context['member']['smiley_set']['id'] : (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'])) . '/smiley.gif' : $settings['images_url'] . '/blank.png', '" alt=":)"  style="padding-left: 20px;" />
+							</dd>';
+}
+
+// Change the way you login to the forum.
+function template_authentication_method()
+{
+	global $context, $settings, $options, $scripturl, $modSettings, $txt;
+
+	// The main header!
+	echo '
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
+		<form action="', $scripturl, '?action=profile;area=authentication;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/profile_sm.png" alt="" class="icon" />', $txt['authentication'], '
+				</h3>
+			</div>
+			<p class="windowbg description">', $txt['change_authentication'], '</p>
+			<div class="windowbg2">
+				<div class="content">
+					<dl>
+						<dt>
+							<input type="radio" onclick="updateAuthMethod();" name="authenticate" value="openid" id="auth_openid"', $context['auth_method'] == 'openid' ? ' checked="checked"' : '', ' class="input_radio" /><label for="auth_openid"><strong>', $txt['authenticate_openid'], '</strong></label>&nbsp;<em><a href="', $scripturl, '?action=helpadmin;help=register_openid" onclick="return reqWin(this.href);" class="help">(?)</a></em><br />
+							<input type="radio" onclick="updateAuthMethod();" name="authenticate" value="passwd" id="auth_pass"', $context['auth_method'] == 'password' ? ' checked="checked"' : '', ' class="input_radio" /><label for="auth_pass"><strong>', $txt['authenticate_password'], '</strong></label>
+						</dt>
+						<dd>
+							<dl id="auth_openid_div">
+								<dt>
+									<em>', $txt['authenticate_openid_url'], ':</em>
+								</dt>
+								<dd>
+									<input type="text" name="openid_identifier" id="openid_url" size="30" tabindex="', $context['tabindex']++, '" value="', $context['member']['openid_uri'], '" class="input_text openid_login" />
+								</dd>
+							</dl>
+							<dl id="auth_pass_div">
+								<dt>
+									<em>', $txt['choose_pass'], ':</em>
+								</dt>
+								<dd>
+									<input type="password" name="passwrd1" id="smf_autov_pwmain" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
+									<span id="smf_autov_pwmain_div" style="display: none;"><img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" /></span>
+								</dd>
+								<dt>
+									<em>', $txt['verify_pass'], ':</em>
+								</dt>
+								<dd>
+									<input type="password" name="passwrd2" id="smf_autov_pwverify" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
+									<span id="smf_autov_pwverify_div" style="display: none;"><img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_valid.png" alt="*" /></span>
+								</dd>
+							</dl>
+						</dd>
+					</dl>';
+
+	if ($context['require_password'])
+		echo '
+					<hr width="100%" size="1" class="hrcolor clear" />
+					<dl>
+						<dt>
+							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br />
+							<span class="smalltext">', $txt['required_security_reasons'], '</span>
+						</dt>
+						<dd>
+							<input type="password" name="oldpasswrd" tabindex="', $context['tabindex']++, '" size="20" style="margin-right: 4ex;" class="input_password" />
+						</dd>
+					</dl>';
+
+	echo '
+					<hr class="hrcolor" />';
+
+	if (!empty($context['token_check']))
+		echo '
+					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '" />';
+
+	echo '
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="u" value="', $context['id_member'], '" />
+					<input type="hidden" name="sa" value="', $context['menu_item_selected'], '" />
+					<input type="submit" value="', $txt['change_profile'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>';
+
+	// The password stuff.
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+	var regTextStrings = {
+		"password_short": "', $txt['registration_password_short'], '",
+		"password_reserved": "', $txt['registration_password_reserved'], '",
+		"password_numbercase": "', $txt['registration_password_numbercase'], '",
+		"password_no_match": "', $txt['registration_password_no_match'], '",
+		"password_valid": "', $txt['registration_password_valid'], '"
+	};
+	var verificationHandle = new smfRegister("creator", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
+	var currentAuthMethod = \'passwd\';
+	updateAuthMethod();
+	// ]]></script>';
+}
+
 ?>

+ 2 - 5
Themes/default/Recent.template.php

@@ -18,7 +18,7 @@ function template_main()
 	<div id="recent" class="main_section">
 		<div class="cat_bar">
 			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/post/xx.png" alt="" class="icon" />',$txt['recent_posts'],'</span>
+				<img src="', $settings['images_url'], '/post/xx.png" alt="" class="icon" />',$txt['recent_posts'],'
 			</h3>
 		</div>
 		<div class="pagesection">
@@ -28,9 +28,7 @@ function template_main()
 	foreach ($context['posts'] as $post)
 	{
 		echo '
-			<div class="', $post['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
-				<span class="topslice"><span></span></span>
-				<div class="content">
+			<div class="', $post['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">ent">
 					<div class="counter">', $post['counter'], '</div>
 					<div class="topic_details">
 						<h5>', $post['board']['link'], ' / ', $post['link'], '</h5>
@@ -70,7 +68,6 @@ function template_main()
 				</div>';
 
 		echo '
-				<span class="botslice clear"><span></span></span>
 			</div>';
 
 	}

+ 684 - 702
Themes/default/Register.template.php

@@ -1,703 +1,685 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-/**
- * Before showing users a registration form, show them the registration agreement.
- */
-function template_registration_agreement()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-		<form action="', $scripturl, '?action=register" method="post" accept-charset="', $context['character_set'], '" id="registration">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['registration_agreement'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<p>', $context['agreement'], '</p>
-			</div>
-			<span class="lowerframe"><span></span></span>
-			<div id="confirm_buttons">';
-
-	// Age restriction in effect?
-	if ($context['show_coppa'])
-		echo '
-				<input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button_submit" /><br /><br />
-				<input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button_submit" />';
-	else
-		echo '
-				<input type="submit" name="accept_agreement" value="', $txt['agreement_agree'], '" class="button_submit" />';
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['register_token_var'], '" value="', $context['register_token'], '" />
-			</div>
-			<input type="hidden" name="step" value="1" />
-		</form>';
-
-}
-
-// Before registering - get their information.
-function template_registration_form()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			function verifyAgree()
-			{
-				if (currentAuthMethod == \'passwd\' && document.forms.registration.smf_autov_pwmain.value != document.forms.registration.smf_autov_pwverify.value)
-				{
-					alert("', $txt['register_passwords_differ_js'], '");
-					return false;
-				}
-
-				return true;
-			}
-
-			var currentAuthMethod = \'passwd\';
-		// ]]></script>';
-
-	// Any errors?
-	if (!empty($context['registration_errors']))
-	{
-		echo '
-		<div class="errorbox">
-			<span>', $txt['registration_errors_occurred'], '</span>
-			<ul class="reset">';
-
-		// Cycle through each error and display an error message.
-		foreach ($context['registration_errors'] as $error)
-				echo '
-				<li>', $error, '</li>';
-
-		echo '
-			</ul>
-		</div>';
-	}
-
-	echo '
-		<form action="', $scripturl, '?action=register2" method="post" accept-charset="', $context['character_set'], '" name="registration" id="registration" onsubmit="return verifyAgree();">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['registration_form'], '</h3>
-			</div>
-			<div class="title_bar">
-				<h4 class="titlebg">', $txt['required_info'], '</h4>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<fieldset class="content">
-					<dl class="register_form">
-						<dt><strong><label for="smf_autov_username">', $txt['username'], ':</label></strong></dt>
-						<dd>
-							<input type="text" name="user" id="smf_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" />
-							<span id="smf_autov_username_div" style="display: none;">
-								<a id="smf_autov_username_link" href="#">
-									<img id="smf_autov_username_img" src="', $settings['images_url'], '/icons/field_check.png" alt="*" />
-								</a>
-							</span>
-						</dd>
-						<dt><strong><label for="smf_autov_reserve1">', $txt['user_email_address'], ':</label></strong></dt>
-						<dd>
-							<input type="text" name="email" id="smf_autov_reserve1" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['email']) ? $context['email'] : '', '" class="input_text" />
-						</dd>
-						<dt><strong><label for="allow_email">', $txt['allow_user_email'], ':</label></strong></dt>
-						<dd>
-							<input type="checkbox" name="allow_email" id="allow_email" tabindex="', $context['tabindex']++, '" class="input_check" />
-						</dd>
-					</dl>';
-
-	// If OpenID is enabled, give the user a choice between password and OpenID.
-	if (!empty($modSettings['enableOpenID']))
-	{
-		echo '
-					<dl class="register_form" id="authentication_group">
-						<dt>
-							<strong>', $txt['authenticate_label'], ':</strong>
-							<a href="', $scripturl, '?action=helpadmin;help=register_openid" onclick="return reqWin(this.href);" class="help">(?)</a>
-						</dt>
-						<dd>
-							<label for="auth_pass" id="option_auth_pass">
-								<input type="radio" name="authenticate" value="passwd" id="auth_pass" tabindex="', $context['tabindex']++, '" ', empty($context['openid']) ? 'checked="checked" ' : '', ' onclick="updateAuthMethod();" class="input_radio" />
-								', $txt['authenticate_password'], '
-							</label>
-							<label for="auth_openid" id="option_auth_openid">
-								<input type="radio" name="authenticate" value="openid" id="auth_openid" tabindex="', $context['tabindex']++, '" ', !empty($context['openid']) ? 'checked="checked" ' : '', ' onclick="updateAuthMethod();" class="input_radio" />
-								', $txt['authenticate_openid'], '
-							</label>
-						</dd>
-					</dl>';
-	}
-
-	echo '
-					<dl class="register_form" id="password1_group">
-						<dt><strong><label for="smf_autov_pwmain">', ucwords($txt['choose_pass']), ':</label></strong></dt>
-						<dd>
-							<input type="password" name="passwrd1" id="smf_autov_pwmain" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
-							<span id="smf_autov_pwmain_div" style="display: none;">
-								<img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
-							</span>
-						</dd>
-					</dl>
-					<dl class="register_form" id="password2_group">
-						<dt><strong><label for="smf_autov_pwverify">', ucwords($txt['verify_pass']), ':</label></strong></dt>
-						<dd>
-							<input type="password" name="passwrd2" id="smf_autov_pwverify" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
-							<span id="smf_autov_pwverify_div" style="display: none;">
-								<img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_valid.png" alt="*" />
-							</span>
-						</dd>
-					</dl>';
-
-	// If OpenID is enabled, give the user a choice between password and OpenID.
-	if (!empty($modSettings['enableOpenID']))
-	{
-		echo '
-
-					<dl class="register_form" id="openid_group">
-						<dt><strong>', $txt['authenticate_openid_url'], ':</strong></dt>
-						<dd>
-							<input type="text" name="openid_identifier" id="openid_url" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['openid']) ? $context['openid'] : '', '" class="input_text openid_login" />
-						</dd>
-					</dl>';
-
-	}
-
-	echo '
-				</fieldset>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	// If we have either of these, show the extra group.
-	if (!empty($context['profile_fields']) || !empty($context['custom_fields']))
-	{
-		echo '
-			<div class="title_bar">
-				<h4 class="titlebg">', $txt['additional_information'], '</h4>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<fieldset class="content">
-					<dl class="register_form" id="custom_group">';
-	}
-
-	if (!empty($context['profile_fields']))
-	{
-		// Any fields we particularly want?
-		foreach ($context['profile_fields'] as $key => $field)
-		{
-			if ($field['type'] == 'callback')
-			{
-				if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
-				{
-					$callback_func = 'template_profile_' . $field['callback_func'];
-					$callback_func();
-				}
-			}
-			else
-			{
-					echo '
-						<dt>
-							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['label'], ':</strong>';
-
-				// Does it have any subtext to show?
-				if (!empty($field['subtext']))
-					echo '
-							<span class="smalltext">', $field['subtext'], '</span>';
-
-				echo '
-						</dt>
-						<dd>';
-
-				// Want to put something infront of the box?
-				if (!empty($field['preinput']))
-					echo '
-							', $field['preinput'];
-
-				// What type of data are we showing?
-				if ($field['type'] == 'label')
-					echo '
-							', $field['value'];
-
-				// Maybe it's a text box - very likely!
-				elseif (in_array($field['type'], array('int', 'float', 'text', 'password')))
-					echo '
-							<input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], ' class="input_', $field['type'] == 'password' ? 'password' : 'text', '" />';
-
-				// You "checking" me out? ;)
-				elseif ($field['type'] == 'check')
-					echo '
-							<input type="hidden" name="', $key, '" value="0" /><input type="checkbox" name="', $key, '" id="', $key, '" ', !empty($field['value']) ? ' checked="checked"' : '', ' value="1" tabindex="', $context['tabindex']++, '" class="input_check" ', $field['input_attr'], ' />';
-
-				// Always fun - select boxes!
-				elseif ($field['type'] == 'select')
-				{
-					echo '
-							<select name="', $key, '" id="', $key, '" tabindex="', $context['tabindex']++, '">';
-
-					if (isset($field['options']))
-					{
-						// Is this some code to generate the options?
-						if (!is_array($field['options']))
-							$field['options'] = eval($field['options']);
-						// Assuming we now have some!
-						if (is_array($field['options']))
-							foreach ($field['options'] as $value => $name)
-								echo '
-								<option value="', $value, '" ', $value == $field['value'] ? 'selected="selected"' : '', '>', $name, '</option>';
-					}
-
-					echo '
-							</select>';
-				}
-
-				// Something to end with?
-				if (!empty($field['postinput']))
-					echo '
-							', $field['postinput'];
-
-				echo '
-						</dd>';
-			}
-		}
-	}
-
-	// Are there any custom fields?
-	if (!empty($context['custom_fields']))
-	{
-		foreach ($context['custom_fields'] as $field)
-			echo '
-						<dt>
-							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['name'], ':</strong>
-							<span class="smalltext">', $field['desc'], '</span>
-						</dt>
-						<dd>', $field['input_html'], '</dd>';
-	}
-
-	// If we have either of these, close the list like a proper gent.
-	if (!empty($context['profile_fields']) || !empty($context['custom_fields']))
-	{
-		echo '
-					</dl>
-				</fieldset>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	if ($context['visual_verification'])
-	{
-		echo '
-			<div class="title_bar">
-				<h4 class="titlebg">', $txt['verification'], '</h4>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<fieldset class="content centertext">
-					', template_control_verification($context['visual_verification_id'], 'all'), '
-				</fieldset>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	echo '
-			<div id="confirm_buttons">';
-
-	// Age restriction in effect?
-	if (!$context['require_agreement'] && $context['show_coppa'])
-		echo '
-				<input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button_submit" /><br /><br />
-				<input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button_submit" />';
-	else
-		echo '
-				<input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />';
-	echo '
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['register_token_var'], '" value="', $context['register_token'], '" />
-			<input type="hidden" name="step" value="2" />
-		</form>
-		<br class="clear" />
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var regTextStrings = {
-				"username_valid": "', $txt['registration_username_available'], '",
-				"username_invalid": "', $txt['registration_username_unavailable'], '",
-				"username_check": "', $txt['registration_username_check'], '",
-				"password_short": "', $txt['registration_password_short'], '",
-				"password_reserved": "', $txt['registration_password_reserved'], '",
-				"password_numbercase": "', $txt['registration_password_numbercase'], '",
-				"password_no_match": "', $txt['registration_password_no_match'], '",
-				"password_valid": "', $txt['registration_password_valid'], '"
-			};
-			var verificationHandle = new smfRegister("registration", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
-			// Update the authentication status.
-			updateAuthMethod();
-		// ]]></script>';
-}
-
-// After registration... all done ;).
-function template_after()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Not much to see here, just a quick... "you're now registered!" or what have you.
-	echo '
-		<div id="registration_success">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['title'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<p class="content">', $context['description'], '</p>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>';
-}
-
-// Template for giving instructions about COPPA activation.
-function template_coppa()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Formulate a nice complicated message!
-	echo '
-			<div class="title_bar">
-				<h3 class="titlebg">', $context['page_title'], '</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $context['coppa']['body'], '</p>
-					<p>
-						<span><a href="', $scripturl, '?action=coppa;form;member=', $context['coppa']['id'], '" target="_blank" class="new_win">', $txt['coppa_form_link_popup'], '</a> | <a href="', $scripturl, '?action=coppa;form;dl;member=', $context['coppa']['id'], '">', $txt['coppa_form_link_download'], '</a></span>
-					</p>
-					<p>', $context['coppa']['many_options'] ? $txt['coppa_send_to_two_options'] : $txt['coppa_send_to_one_option'], '</p>';
-
-	// Can they send by post?
-	if (!empty($context['coppa']['post']))
-	{
-		echo '
-					<h4>1) ', $txt['coppa_send_by_post'], '</h4>
-					<div class="coppa_contact">
-						', $context['coppa']['post'], '
-					</div>';
-	}
-
-	// Can they send by fax??
-	if (!empty($context['coppa']['fax']))
-	{
-		echo '
-					<h4>', !empty($context['coppa']['post']) ? '2' : '1', ') ', $txt['coppa_send_by_fax'], '</h4>
-					<div class="coppa_contact">
-						', $context['coppa']['fax'], '
-					</div>';
-	}
-
-	// Offer an alternative Phone Number?
-	if ($context['coppa']['phone'])
-	{
-		echo '
-					<p>', $context['coppa']['phone'], '</p>';
-	}
-	echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-}
-
-// An easily printable form for giving permission to access the forum for a minor.
-function template_coppa_form()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	// Show the form (As best we can)
-	echo '
-		<table border="0" width="100%" cellpadding="3" cellspacing="0" class="tborder" align="center">
-			<tr>
-				<td align="left">', $context['forum_contacts'], '</td>
-			</tr><tr>
-				<td align="right">
-					<em>', $txt['coppa_form_address'], '</em>: ', $context['ul'], '<br />
-					', $context['ul'], '<br />
-					', $context['ul'], '<br />
-					', $context['ul'], '
-				</td>
-			</tr><tr>
-				<td align="right">
-					<em>', $txt['coppa_form_date'], '</em>: ', $context['ul'], '
-					<br /><br />
-				</td>
-			</tr><tr>
-				<td align="left">
-					', $context['coppa_body'], '
-				</td>
-			</tr>
-		</table>
-		<br />';
-}
-
-// Show a window containing the spoken verification code.
-function template_verification_sound()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<title>', $txt['visual_verification_sound'], '</title>
-		<meta name="robots" content="noindex" />
-		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
-		<style type="text/css">';
-
-	// Just show the help text and a "close window" link.
-	echo '
-		</style>
-	</head>
-	<body style="margin: 1ex;">
-		<div class="windowbg description" style="text-align: center;">';
-	if (isBrowser('is_ie'))
-		echo '
-			<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="audio/x-wav">
-				<param name="AutoStart" value="1" />
-				<param name="FileName" value="', $context['verification_sound_href'], '" />
-			</object>';
-	else
-		echo '
-			<object type="audio/x-wav" data="', $context['verification_sound_href'], '">
-				<a href="', $context['verification_sound_href'], '" rel="nofollow">', $context['verification_sound_href'], '</a>
-			</object>';
-	echo '
-		<br />
-		<a href="', $context['verification_sound_href'], ';sound" rel="nofollow">', $txt['visual_verification_sound_again'], '</a><br />
-		<a href="', $context['verification_sound_href'], '" rel="nofollow">', $txt['visual_verification_sound_direct'], '</a><br /><br />
-		<a href="javascript:self.close();">', $txt['visual_verification_sound_close'], '</a><br />
-		</div>
-	</body>
-</html>';
-}
-
-function template_admin_register()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['admin_browse_register_new'], '</h3>
-		</div>
-		<form class="windowbg2" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '" name="postForm" id="postForm">
-			<span class="topslice"><span></span></span>
-			<div class="content" id="register_screen">';
-
-	if (!empty($context['registration_done']))
-		echo '
-				<div class="infobox">
-					', $context['registration_done'], '
-				</div>';
-
-	echo '
-				<dl class="register_form" id="admin_register_form">
-					<dt>
-						<strong><label for="user_input">', $txt['admin_register_username'], ':</label></strong>
-						<span class="smalltext">', $txt['admin_register_username_desc'], '</span>
-					</dt>
-					<dd>
-						<input type="text" name="user" id="user_input" tabindex="', $context['tabindex']++, '" size="30" maxlength="25" class="input_text" />
-					</dd>
-					<dt>
-						<strong><label for="email_input">', $txt['admin_register_email'], ':</label></strong>
-						<span class="smalltext">', $txt['admin_register_email_desc'], '</span>
-					</dt>
-					<dd>
-						<input type="text" name="email" id="email_input" tabindex="', $context['tabindex']++, '" size="30" class="input_text" />
-					</dd>
-					<dt>
-						<strong><label for="password_input">', $txt['admin_register_password'], ':</label></strong>
-						<span class="smalltext">', $txt['admin_register_password_desc'], '</span>
-					</dt>
-					<dd>
-						<input type="password" name="password" id="password_input" tabindex="', $context['tabindex']++, '" size="30" class="input_password" onchange="onCheckChange();" />
-					</dd>';
-
-	if (!empty($context['member_groups']))
-	{
-		echo '
-					<dt>
-						<strong><label for="group_select">', $txt['admin_register_group'], ':</label></strong>
-						<span class="smalltext">', $txt['admin_register_group_desc'], '</span>
-					</dt>
-					<dd>
-						<select name="group" id="group_select" tabindex="', $context['tabindex']++, '">';
-
-		foreach ($context['member_groups'] as $id => $name)
-			echo '
-							<option value="', $id, '">', $name, '</option>';
-
-		echo '
-						</select>
-					</dd>';
-	}
-
-	echo '
-					<dt>
-						<strong><label for="emailPassword_check">', $txt['admin_register_email_detail'], ':</label></strong>
-						<span class="smalltext">', $txt['admin_register_email_detail_desc'], '</span>
-					</dt>
-					<dd>
-						<input type="checkbox" name="emailPassword" id="emailPassword_check" tabindex="', $context['tabindex']++, '" checked="checked" disabled="disabled" class="input_check" />
-					</dd>
-					<dt>
-						<strong><label for="emailActivate_check">', $txt['admin_register_email_activate'], ':</label></strong>
-					</dt>
-					<dd>
-						<input type="checkbox" name="emailActivate" id="emailActivate_check" tabindex="', $context['tabindex']++, '"', !empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? ' checked="checked"' : '', ' onclick="onCheckChange();" class="input_check" />
-					</dd>
-				</dl>
-				<hr class="hrcolor" />
-				<input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />
-				<input type="hidden" name="sa" value="register" />
-				<br class="clear_right" />
-			</div>
-			<span class="botslice"><span></span></span>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-regc_token_var'], '" value="', $context['admin-regc_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Form for editing the agreement shown for people registering to the forum.
-function template_edit_agreement()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Just a big box to edit the text file ;).
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['registration_agreement'], '</h3>
-		</div>';
-
-	// Warning for if the file isn't writable.
-	if (!empty($context['warning']))
-		echo '
-		<p class="error">', $context['warning'], '</p>';
-
-	echo '
-		<div class="windowbg2" id="registration_agreement">
-			<span class="topslice"><span></span></span>
-			<div class="content">';
-
-	// Is there more than one language to choose from?
-	if (count($context['editable_agreements']) > 1)
-	{
-		echo '
-				<div class="information">
-					<form action="', $scripturl, '?action=admin;area=regcenter" id="change_reg" method="post" accept-charset="', $context['character_set'], '" style="display: inline;">
-						<strong>', $txt['admin_agreement_select_language'], ':</strong>&nbsp;
-						<select name="agree_lang" onchange="document.getElementById(\'change_reg\').submit();" tabindex="', $context['tabindex']++, '">';
-
-		foreach ($context['editable_agreements'] as $file => $name)
-			echo '
-							<option value="', $file, '" ', $context['current_agreement'] == $file ? 'selected="selected"' : '', '>', $name, '</option>';
-
-		echo '
-						</select>
-						<div class="righttext">
-							<input type="hidden" name="sa" value="agreement" />
-							<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-							<input type="submit" name="change" value="', $txt['admin_agreement_select_language_change'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />
-						</div>
-					</form>
-				</div>';
-	}
-
-	echo '
-				<form action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '">';
-
-	// Show the actual agreement in an oversized text box.
-	echo '
-					<p class="agreement">
-						<textarea cols="70" rows="20" name="agreement" id="agreement">', $context['agreement'], '</textarea>
-					</p>
-					<p>
-						<label for="requireAgreement"><input type="checkbox" name="requireAgreement" id="requireAgreement"', $context['require_agreement'] ? ' checked="checked"' : '', ' tabindex="', $context['tabindex']++, '" value="1" class="input_check" /> ', $txt['admin_agreement'], '.</label>
-					</p>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['save'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />
-					<input type="hidden" name="agree_lang" value="', $context['current_agreement'], '" />
-					<input type="hidden" name="sa" value="agreement" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-rega_token_var'], '" value="', $context['admin-rega_token'], '" />
-					<br class="clear_right" />
-				</form>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<br class="clear" />';
-}
-
-function template_edit_reserved_words()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['admin_reserved_set'], '</h3>
-		</div>
-		<form id="registration_agreement" class="windowbg2" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<h4>', $txt['admin_reserved_line'], '</h4>
-				<p class="reserved_names">
-					<textarea cols="30" rows="6" name="reserved" id="reserved">', implode("\n", $context['reserved_words']), '</textarea>
-				</p>
-				<dl class="settings">
-					<dt>
-						<label for="matchword">', $txt['admin_match_whole'], '</label>
-					</dt>
-					<dd>
-						<input type="checkbox" name="matchword" id="matchword" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_word'] ? 'checked="checked"' : '', ' class="input_check" />
-					</dd>
-					<dt>
-						<label for="matchcase">', $txt['admin_match_case'], '</label>
-					</dt>
-					<dd>
-						<input type="checkbox" name="matchcase" id="matchcase" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_case'] ? 'checked="checked"' : '', ' class="input_check" />
-					</dd>
-					<dt>
-						<label for="matchuser">', $txt['admin_check_user'], '</label>
-					</dt>
-					<dd>
-						<input type="checkbox" name="matchuser" id="matchuser" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_user'] ? 'checked="checked"' : '', ' class="input_check" />
-					</dd>
-					<dt>
-						<label for="matchname">', $txt['admin_check_display'], '</label>
-					</dt>
-					<dd>
-						<input type="checkbox" name="matchname" id="matchname" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_name'] ? 'checked="checked"' : '', ' class="input_check" />
-					</dd>
-				</dl>
-				<hr class="hrcolor" />
-				<input type="submit" value="', $txt['save'], '" name="save_reserved_names" tabindex="', $context['tabindex']++, '" style="margin: 1ex;" class="button_submit" />
-				<br class="clear_right" />
-			</div>
-			<span class="botslice"><span></span></span>
-			<input type="hidden" name="sa" value="reservednames" />
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-regr_token_var'], '" value="', $context['admin-regr_token'], '" />
-		</form>
-		<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+/**
+ * Before showing users a registration form, show them the registration agreement.
+ */
+function template_registration_agreement()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+		<form action="', $scripturl, '?action=register" method="post" accept-charset="', $context['character_set'], '" id="registration">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['registration_agreement'], '</h3>
+			</div>
+			<div class="roundframe">
+				<p>', $context['agreement'], '</p>
+			</div>
+			<div id="confirm_buttons">';
+
+	// Age restriction in effect?
+	if ($context['show_coppa'])
+		echo '
+				<input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button_submit" /><br /><br />
+				<input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button_submit" />';
+	else
+		echo '
+				<input type="submit" name="accept_agreement" value="', $txt['agreement_agree'], '" class="button_submit" />';
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['register_token_var'], '" value="', $context['register_token'], '" />
+			</div>
+			<input type="hidden" name="step" value="1" />
+		</form>';
+
+}
+
+// Before registering - get their information.
+function template_registration_form()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			function verifyAgree()
+			{
+				if (currentAuthMethod == \'passwd\' && document.forms.registration.smf_autov_pwmain.value != document.forms.registration.smf_autov_pwverify.value)
+				{
+					alert("', $txt['register_passwords_differ_js'], '");
+					return false;
+				}
+
+				return true;
+			}
+
+			var currentAuthMethod = \'passwd\';
+		// ]]></script>';
+
+	// Any errors?
+	if (!empty($context['registration_errors']))
+	{
+		echo '
+		<div class="errorbox">
+			<span>', $txt['registration_errors_occurred'], '</span>
+			<ul class="reset">';
+
+		// Cycle through each error and display an error message.
+		foreach ($context['registration_errors'] as $error)
+				echo '
+				<li>', $error, '</li>';
+
+		echo '
+			</ul>
+		</div>';
+	}
+
+	echo '
+		<form action="', $scripturl, '?action=register2" method="post" accept-charset="', $context['character_set'], '" name="registration" id="registration" onsubmit="return verifyAgree();">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['registration_form'], '</h3>
+			</div>
+			<div class="title_bar">
+				<h4 class="titlebg">', $txt['required_info'], '</h4>
+			</div>
+			<div class="windowbg2">
+				<fieldset class="content">
+					<dl class="register_form">
+						<dt><strong><label for="smf_autov_username">', $txt['username'], ':</label></strong></dt>
+						<dd>
+							<input type="text" name="user" id="smf_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" />
+							<span id="smf_autov_username_div" style="display: none;">
+								<a id="smf_autov_username_link" href="#">
+									<img id="smf_autov_username_img" src="', $settings['images_url'], '/icons/field_check.png" alt="*" />
+								</a>
+							</span>
+						</dd>
+						<dt><strong><label for="smf_autov_reserve1">', $txt['user_email_address'], ':</label></strong></dt>
+						<dd>
+							<input type="text" name="email" id="smf_autov_reserve1" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['email']) ? $context['email'] : '', '" class="input_text" />
+						</dd>
+						<dt><strong><label for="allow_email">', $txt['allow_user_email'], ':</label></strong></dt>
+						<dd>
+							<input type="checkbox" name="allow_email" id="allow_email" tabindex="', $context['tabindex']++, '" class="input_check" />
+						</dd>
+					</dl>';
+
+	// If OpenID is enabled, give the user a choice between password and OpenID.
+	if (!empty($modSettings['enableOpenID']))
+	{
+		echo '
+					<dl class="register_form" id="authentication_group">
+						<dt>
+							<strong>', $txt['authenticate_label'], ':</strong>
+							<a href="', $scripturl, '?action=helpadmin;help=register_openid" onclick="return reqWin(this.href);" class="help">(?)</a>
+						</dt>
+						<dd>
+							<label for="auth_pass" id="option_auth_pass">
+								<input type="radio" name="authenticate" value="passwd" id="auth_pass" tabindex="', $context['tabindex']++, '" ', empty($context['openid']) ? 'checked="checked" ' : '', ' onclick="updateAuthMethod();" class="input_radio" />
+								', $txt['authenticate_password'], '
+							</label>
+							<label for="auth_openid" id="option_auth_openid">
+								<input type="radio" name="authenticate" value="openid" id="auth_openid" tabindex="', $context['tabindex']++, '" ', !empty($context['openid']) ? 'checked="checked" ' : '', ' onclick="updateAuthMethod();" class="input_radio" />
+								', $txt['authenticate_openid'], '
+							</label>
+						</dd>
+					</dl>';
+	}
+
+	echo '
+					<dl class="register_form" id="password1_group">
+						<dt><strong><label for="smf_autov_pwmain">', ucwords($txt['choose_pass']), ':</label></strong></dt>
+						<dd>
+							<input type="password" name="passwrd1" id="smf_autov_pwmain" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
+							<span id="smf_autov_pwmain_div" style="display: none;">
+								<img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
+							</span>
+						</dd>
+					</dl>
+					<dl class="register_form" id="password2_group">
+						<dt><strong><label for="smf_autov_pwverify">', ucwords($txt['verify_pass']), ':</label></strong></dt>
+						<dd>
+							<input type="password" name="passwrd2" id="smf_autov_pwverify" size="30" tabindex="', $context['tabindex']++, '" class="input_password" />
+							<span id="smf_autov_pwverify_div" style="display: none;">
+								<img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_valid.png" alt="*" />
+							</span>
+						</dd>
+					</dl>';
+
+	// If OpenID is enabled, give the user a choice between password and OpenID.
+	if (!empty($modSettings['enableOpenID']))
+	{
+		echo '
+
+					<dl class="register_form" id="openid_group">
+						<dt><strong>', $txt['authenticate_openid_url'], ':</strong></dt>
+						<dd>
+							<input type="text" name="openid_identifier" id="openid_url" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['openid']) ? $context['openid'] : '', '" class="input_text openid_login" />
+						</dd>
+					</dl>';
+
+	}
+
+	echo '
+				</fieldset>
+			</div>';
+
+	// If we have either of these, show the extra group.
+	if (!empty($context['profile_fields']) || !empty($context['custom_fields']))
+	{
+		echo '
+			<div class="title_bar">
+				<h4 class="titlebg">', $txt['additional_information'], '</h4>
+			</div>
+			<div class="windowbg2">
+				<fieldset class="content">
+					<dl class="register_form" id="custom_group">';
+	}
+
+	if (!empty($context['profile_fields']))
+	{
+		// Any fields we particularly want?
+		foreach ($context['profile_fields'] as $key => $field)
+		{
+			if ($field['type'] == 'callback')
+			{
+				if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
+				{
+					$callback_func = 'template_profile_' . $field['callback_func'];
+					$callback_func();
+				}
+			}
+			else
+			{
+					echo '
+						<dt>
+							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['label'], ':</strong>';
+
+				// Does it have any subtext to show?
+				if (!empty($field['subtext']))
+					echo '
+							<span class="smalltext">', $field['subtext'], '</span>';
+
+				echo '
+						</dt>
+						<dd>';
+
+				// Want to put something infront of the box?
+				if (!empty($field['preinput']))
+					echo '
+							', $field['preinput'];
+
+				// What type of data are we showing?
+				if ($field['type'] == 'label')
+					echo '
+							', $field['value'];
+
+				// Maybe it's a text box - very likely!
+				elseif (in_array($field['type'], array('int', 'float', 'text', 'password')))
+					echo '
+							<input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], ' class="input_', $field['type'] == 'password' ? 'password' : 'text', '" />';
+
+				// You "checking" me out? ;)
+				elseif ($field['type'] == 'check')
+					echo '
+							<input type="hidden" name="', $key, '" value="0" /><input type="checkbox" name="', $key, '" id="', $key, '" ', !empty($field['value']) ? ' checked="checked"' : '', ' value="1" tabindex="', $context['tabindex']++, '" class="input_check" ', $field['input_attr'], ' />';
+
+				// Always fun - select boxes!
+				elseif ($field['type'] == 'select')
+				{
+					echo '
+							<select name="', $key, '" id="', $key, '" tabindex="', $context['tabindex']++, '">';
+
+					if (isset($field['options']))
+					{
+						// Is this some code to generate the options?
+						if (!is_array($field['options']))
+							$field['options'] = eval($field['options']);
+						// Assuming we now have some!
+						if (is_array($field['options']))
+							foreach ($field['options'] as $value => $name)
+								echo '
+								<option value="', $value, '" ', $value == $field['value'] ? 'selected="selected"' : '', '>', $name, '</option>';
+					}
+
+					echo '
+							</select>';
+				}
+
+				// Something to end with?
+				if (!empty($field['postinput']))
+					echo '
+							', $field['postinput'];
+
+				echo '
+						</dd>';
+			}
+		}
+	}
+
+	// Are there any custom fields?
+	if (!empty($context['custom_fields']))
+	{
+		foreach ($context['custom_fields'] as $field)
+			echo '
+						<dt>
+							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['name'], ':</strong>
+							<span class="smalltext">', $field['desc'], '</span>
+						</dt>
+						<dd>', $field['input_html'], '</dd>';
+	}
+
+	// If we have either of these, close the list like a proper gent.
+	if (!empty($context['profile_fields']) || !empty($context['custom_fields']))
+	{
+		echo '
+					</dl>
+				</fieldset>
+			</div>';
+	}
+
+	if ($context['visual_verification'])
+	{
+		echo '
+			<div class="title_bar">
+				<h4 class="titlebg">', $txt['verification'], '</h4>
+			</div>
+			<div class="windowbg2">
+				<fieldset class="content centertext">
+					', template_control_verification($context['visual_verification_id'], 'all'), '
+				</fieldset>
+			</div>';
+	}
+
+	echo '
+			<div id="confirm_buttons">';
+
+	// Age restriction in effect?
+	if (!$context['require_agreement'] && $context['show_coppa'])
+		echo '
+				<input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button_submit" /><br /><br />
+				<input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button_submit" />';
+	else
+		echo '
+				<input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />';
+	echo '
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['register_token_var'], '" value="', $context['register_token'], '" />
+			<input type="hidden" name="step" value="2" />
+		</form>
+		<br class="clear" />
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var regTextStrings = {
+				"username_valid": "', $txt['registration_username_available'], '",
+				"username_invalid": "', $txt['registration_username_unavailable'], '",
+				"username_check": "', $txt['registration_username_check'], '",
+				"password_short": "', $txt['registration_password_short'], '",
+				"password_reserved": "', $txt['registration_password_reserved'], '",
+				"password_numbercase": "', $txt['registration_password_numbercase'], '",
+				"password_no_match": "', $txt['registration_password_no_match'], '",
+				"password_valid": "', $txt['registration_password_valid'], '"
+			};
+			var verificationHandle = new smfRegister("registration", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
+			// Update the authentication status.
+			updateAuthMethod();
+		// ]]></script>';
+}
+
+// After registration... all done ;).
+function template_after()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Not much to see here, just a quick... "you're now registered!" or what have you.
+	echo '
+		<div id="registration_success">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['title'], '</h3>
+			</div>
+			<div class="windowbg">
+				<p class="content">', $context['description'], '</p>
+			</div>
+		</div>';
+}
+
+// Template for giving instructions about COPPA activation.
+function template_coppa()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Formulate a nice complicated message!
+	echo '
+			<div class="title_bar">
+				<h3 class="titlebg">', $context['page_title'], '</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<p>', $context['coppa']['body'], '</p>
+					<p>
+						<span><a href="', $scripturl, '?action=coppa;form;member=', $context['coppa']['id'], '" target="_blank" class="new_win">', $txt['coppa_form_link_popup'], '</a> | <a href="', $scripturl, '?action=coppa;form;dl;member=', $context['coppa']['id'], '">', $txt['coppa_form_link_download'], '</a></span>
+					</p>
+					<p>', $context['coppa']['many_options'] ? $txt['coppa_send_to_two_options'] : $txt['coppa_send_to_one_option'], '</p>';
+
+	// Can they send by post?
+	if (!empty($context['coppa']['post']))
+	{
+		echo '
+					<h4>1) ', $txt['coppa_send_by_post'], '</h4>
+					<div class="coppa_contact">
+						', $context['coppa']['post'], '
+					</div>';
+	}
+
+	// Can they send by fax??
+	if (!empty($context['coppa']['fax']))
+	{
+		echo '
+					<h4>', !empty($context['coppa']['post']) ? '2' : '1', ') ', $txt['coppa_send_by_fax'], '</h4>
+					<div class="coppa_contact">
+						', $context['coppa']['fax'], '
+					</div>';
+	}
+
+	// Offer an alternative Phone Number?
+	if ($context['coppa']['phone'])
+	{
+		echo '
+					<p>', $context['coppa']['phone'], '</p>';
+	}
+	echo '
+				</div>
+			</div>';
+}
+
+// An easily printable form for giving permission to access the forum for a minor.
+function template_coppa_form()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	// Show the form (As best we can)
+	echo '
+		<table border="0" width="100%" cellpadding="3" cellspacing="0" class="tborder" align="center">
+			<tr>
+				<td align="left">', $context['forum_contacts'], '</td>
+			</tr><tr>
+				<td align="right">
+					<em>', $txt['coppa_form_address'], '</em>: ', $context['ul'], '<br />
+					', $context['ul'], '<br />
+					', $context['ul'], '<br />
+					', $context['ul'], '
+				</td>
+			</tr><tr>
+				<td align="right">
+					<em>', $txt['coppa_form_date'], '</em>: ', $context['ul'], '
+					<br /><br />
+				</td>
+			</tr><tr>
+				<td align="left">
+					', $context['coppa_body'], '
+				</td>
+			</tr>
+		</table>
+		<br />';
+}
+
+// Show a window containing the spoken verification code.
+function template_verification_sound()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<title>', $txt['visual_verification_sound'], '</title>
+		<meta name="robots" content="noindex" />
+		<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />
+		<style type="text/css">';
+
+	// Just show the help text and a "close window" link.
+	echo '
+		</style>
+	</head>
+	<body style="margin: 1ex;">
+		<div class="windowbg description" style="text-align: center;">';
+	if (isBrowser('is_ie'))
+		echo '
+			<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="audio/x-wav">
+				<param name="AutoStart" value="1" />
+				<param name="FileName" value="', $context['verification_sound_href'], '" />
+			</object>';
+	else
+		echo '
+			<object type="audio/x-wav" data="', $context['verification_sound_href'], '">
+				<a href="', $context['verification_sound_href'], '" rel="nofollow">', $context['verification_sound_href'], '</a>
+			</object>';
+	echo '
+		<br />
+		<a href="', $context['verification_sound_href'], ';sound" rel="nofollow">', $txt['visual_verification_sound_again'], '</a><br />
+		<a href="', $context['verification_sound_href'], '" rel="nofollow">', $txt['visual_verification_sound_direct'], '</a><br /><br />
+		<a href="javascript:self.close();">', $txt['visual_verification_sound_close'], '</a><br />
+		</div>
+	</body>
+</html>';
+}
+
+function template_admin_register()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['admin_browse_register_new'], '</h3>
+		</div>
+		<form class="windowbg2" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '" name="postForm" id="postForm">
+			<div class="content" id="register_screen">';
+
+	if (!empty($context['registration_done']))
+		echo '
+				<div class="infobox">
+					', $context['registration_done'], '
+				</div>';
+
+	echo '
+				<dl class="register_form" id="admin_register_form">
+					<dt>
+						<strong><label for="user_input">', $txt['admin_register_username'], ':</label></strong>
+						<span class="smalltext">', $txt['admin_register_username_desc'], '</span>
+					</dt>
+					<dd>
+						<input type="text" name="user" id="user_input" tabindex="', $context['tabindex']++, '" size="30" maxlength="25" class="input_text" />
+					</dd>
+					<dt>
+						<strong><label for="email_input">', $txt['admin_register_email'], ':</label></strong>
+						<span class="smalltext">', $txt['admin_register_email_desc'], '</span>
+					</dt>
+					<dd>
+						<input type="text" name="email" id="email_input" tabindex="', $context['tabindex']++, '" size="30" class="input_text" />
+					</dd>
+					<dt>
+						<strong><label for="password_input">', $txt['admin_register_password'], ':</label></strong>
+						<span class="smalltext">', $txt['admin_register_password_desc'], '</span>
+					</dt>
+					<dd>
+						<input type="password" name="password" id="password_input" tabindex="', $context['tabindex']++, '" size="30" class="input_password" onchange="onCheckChange();" />
+					</dd>';
+
+	if (!empty($context['member_groups']))
+	{
+		echo '
+					<dt>
+						<strong><label for="group_select">', $txt['admin_register_group'], ':</label></strong>
+						<span class="smalltext">', $txt['admin_register_group_desc'], '</span>
+					</dt>
+					<dd>
+						<select name="group" id="group_select" tabindex="', $context['tabindex']++, '">';
+
+		foreach ($context['member_groups'] as $id => $name)
+			echo '
+							<option value="', $id, '">', $name, '</option>';
+
+		echo '
+						</select>
+					</dd>';
+	}
+
+	echo '
+					<dt>
+						<strong><label for="emailPassword_check">', $txt['admin_register_email_detail'], ':</label></strong>
+						<span class="smalltext">', $txt['admin_register_email_detail_desc'], '</span>
+					</dt>
+					<dd>
+						<input type="checkbox" name="emailPassword" id="emailPassword_check" tabindex="', $context['tabindex']++, '" checked="checked" disabled="disabled" class="input_check" />
+					</dd>
+					<dt>
+						<strong><label for="emailActivate_check">', $txt['admin_register_email_activate'], ':</label></strong>
+					</dt>
+					<dd>
+						<input type="checkbox" name="emailActivate" id="emailActivate_check" tabindex="', $context['tabindex']++, '"', !empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? ' checked="checked"' : '', ' onclick="onCheckChange();" class="input_check" />
+					</dd>
+				</dl>
+				<hr class="hrcolor" />
+				<input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />
+				<input type="hidden" name="sa" value="register" />
+				<br class="clear_right" />
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-regc_token_var'], '" value="', $context['admin-regc_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Form for editing the agreement shown for people registering to the forum.
+function template_edit_agreement()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Just a big box to edit the text file ;).
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['registration_agreement'], '</h3>
+		</div>';
+
+	// Warning for if the file isn't writable.
+	if (!empty($context['warning']))
+		echo '
+		<p class="error">', $context['warning'], '</p>';
+
+	echo '
+		<div class="windowbg2" id="registration_agreement">
+			<div class="content">';
+
+	// Is there more than one language to choose from?
+	if (count($context['editable_agreements']) > 1)
+	{
+		echo '
+				<div class="information">
+					<form action="', $scripturl, '?action=admin;area=regcenter" id="change_reg" method="post" accept-charset="', $context['character_set'], '" style="display: inline;">
+						<strong>', $txt['admin_agreement_select_language'], ':</strong>&nbsp;
+						<select name="agree_lang" onchange="document.getElementById(\'change_reg\').submit();" tabindex="', $context['tabindex']++, '">';
+
+		foreach ($context['editable_agreements'] as $file => $name)
+			echo '
+							<option value="', $file, '" ', $context['current_agreement'] == $file ? 'selected="selected"' : '', '>', $name, '</option>';
+
+		echo '
+						</select>
+						<div class="righttext">
+							<input type="hidden" name="sa" value="agreement" />
+							<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+							<input type="submit" name="change" value="', $txt['admin_agreement_select_language_change'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />
+						</div>
+					</form>
+				</div>';
+	}
+
+	echo '
+				<form action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '">';
+
+	// Show the actual agreement in an oversized text box.
+	echo '
+					<p class="agreement">
+						<textarea cols="70" rows="20" name="agreement" id="agreement">', $context['agreement'], '</textarea>
+					</p>
+					<p>
+						<label for="requireAgreement"><input type="checkbox" name="requireAgreement" id="requireAgreement"', $context['require_agreement'] ? ' checked="checked"' : '', ' tabindex="', $context['tabindex']++, '" value="1" class="input_check" /> ', $txt['admin_agreement'], '.</label>
+					</p>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['save'], '" tabindex="', $context['tabindex']++, '" class="button_submit" />
+					<input type="hidden" name="agree_lang" value="', $context['current_agreement'], '" />
+					<input type="hidden" name="sa" value="agreement" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-rega_token_var'], '" value="', $context['admin-rega_token'], '" />
+					<br class="clear_right" />
+				</form>
+			</div>
+		</div>
+		<br class="clear" />';
+}
+
+function template_edit_reserved_words()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['admin_reserved_set'], '</h3>
+		</div>
+		<form id="registration_agreement" class="windowbg2" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '">
+			<div class="content">
+				<h4>', $txt['admin_reserved_line'], '</h4>
+				<p class="reserved_names">
+					<textarea cols="30" rows="6" name="reserved" id="reserved">', implode("\n", $context['reserved_words']), '</textarea>
+				</p>
+				<dl class="settings">
+					<dt>
+						<label for="matchword">', $txt['admin_match_whole'], '</label>
+					</dt>
+					<dd>
+						<input type="checkbox" name="matchword" id="matchword" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_word'] ? 'checked="checked"' : '', ' class="input_check" />
+					</dd>
+					<dt>
+						<label for="matchcase">', $txt['admin_match_case'], '</label>
+					</dt>
+					<dd>
+						<input type="checkbox" name="matchcase" id="matchcase" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_case'] ? 'checked="checked"' : '', ' class="input_check" />
+					</dd>
+					<dt>
+						<label for="matchuser">', $txt['admin_check_user'], '</label>
+					</dt>
+					<dd>
+						<input type="checkbox" name="matchuser" id="matchuser" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_user'] ? 'checked="checked"' : '', ' class="input_check" />
+					</dd>
+					<dt>
+						<label for="matchname">', $txt['admin_check_display'], '</label>
+					</dt>
+					<dd>
+						<input type="checkbox" name="matchname" id="matchname" tabindex="', $context['tabindex']++, '" ', $context['reserved_word_options']['match_name'] ? 'checked="checked"' : '', ' class="input_check" />
+					</dd>
+				</dl>
+				<hr class="hrcolor" />
+				<input type="submit" value="', $txt['save'], '" name="save_reserved_names" tabindex="', $context['tabindex']++, '" style="margin: 1ex;" class="button_submit" />
+				<br class="clear_right" />
+			</div>
+			<input type="hidden" name="sa" value="reservednames" />
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-regr_token_var'], '" value="', $context['admin-regr_token'], '" />
+		</form>
+		<br class="clear" />';
+}
+
 ?>

+ 196 - 204
Themes/default/Reminder.template.php

@@ -1,205 +1,197 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<br />
-	<form action="', $scripturl, '?action=reminder;sa=picktype" method="post" accept-charset="', $context['character_set'], '">
-		<div class="tborder login">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['authentication_reminder'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<p class="smalltext centertext">', $txt['password_reminder_desc'], '</p>
-				<dl>
-					<dt>', $txt['user_email'], ':</dt>
-					<dd><input type="text" name="user" size="30" class="input_text" /></dd>
-				</dl>
-				<input type="submit" value="', $txt['reminder_continue'], '" class="button_submit" />
-				<br class="clear" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		<input type="hidden" name="', $context['remind_token_var'], '" value="', $context['remind_token'], '" />
-	</form>';
-}
-
-function template_reminder_pick()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<br />
-	<form action="', $scripturl, '?action=reminder;sa=picktype" method="post" accept-charset="', $context['character_set'], '">
-		<div class="tborder login">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['authentication_reminder'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<p><strong>', $txt['authentication_options'], ':</strong></p>
-				<p>
-					<input type="radio" name="reminder_type" id="reminder_type_email" value="email" checked="checked" class="input_radio" /></dt>
-					<label for="reminder_type_email">', $txt['authentication_' . $context['account_type'] . '_email'], '</label></dd>
-				</p>
-				<p>
-					<input type="radio" name="reminder_type" id="reminder_type_secret" value="secret" class="input_radio" />
-					<label for="reminder_type_secret">', $txt['authentication_' . $context['account_type'] . '_secret'], '</label>
-				</p>
-				<input type="submit" value="', $txt['reminder_continue'], '" class="button_submit" />
-				<br class="clear" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-		
-		<input type="hidden" name="uid" value="', $context['current_member']['id'], '" />
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		<input type="hidden" name="', $context['remind_token_var'], '" value="', $context['remind_token'], '" />
-	</form>';
-}
-
-function template_sent()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<br />
-		<div class="tborder login" id="reminder_sent">
-			<div class="cat_bar">
-				<h3 class="catbg">' . $context['page_title'] . '</h3>
-			</div>
-			<p class="information">' . $context['description'] . '</p>
-		</div>';
-}
-
-function template_set_password()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	echo '
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
-	<br />
-	<form action="', $scripturl, '?action=reminder;sa=setpassword2" name="reminder_form" id="reminder_form" method="post" accept-charset="', $context['character_set'], '">
-		<div class="tborder login">
-			<div class="cat_bar">
-				<h3 class="catbg">', $context['page_title'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<dl>
-					<dt>', $txt['choose_pass'], ': </dt>
-					<dd>
-						<input type="password" name="passwrd1" id="smf_autov_pwmain" size="22" class="input_password" />
-						<span id="smf_autov_pwmain_div" style="display: none;">
-							<img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
-						</span>
-					</dd>
-					<dt>', $txt['verify_pass'], ': </dt>
-					<dd>
-						<input type="password" name="passwrd2" id="smf_autov_pwverify" size="22" class="input_password" />
-						<span id="smf_autov_pwverify_div" style="display: none;">
-							<img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
-						</span>
-					</dd>
-				</dl>
-				<p class="align_center"><input type="submit" value="', $txt['save'], '" class="button_submit" /></p>
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-		<input type="hidden" name="code" value="', $context['code'], '" />
-		<input type="hidden" name="u" value="', $context['memID'], '" />
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		<input type="hidden" name="', $context['remind-sp_token_var'], '" value="', $context['remind-sp_token'], '" />
-	</form>
-	<script type="text/javascript"><!-- // --><![CDATA[
-	var regTextStrings = {
-		"password_short": "', $txt['registration_password_short'], '",
-		"password_reserved": "', $txt['registration_password_reserved'], '",
-		"password_numbercase": "', $txt['registration_password_numbercase'], '",
-		"password_no_match": "', $txt['registration_password_no_match'], '",
-		"password_valid": "', $txt['registration_password_valid'], '"
-	};
-	var verificationHandle = new smfRegister("reminder_form", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
-// ]]></script>';
-}
-
-function template_ask()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	echo '
-	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
-	<br />
-	<form action="', $scripturl, '?action=reminder;sa=secret2" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
-		<div class="tborder login">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['authentication_reminder'], '</h3>
-			</div>
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<p class="smalltext">', $context['account_type'] == 'password' ? $txt['enter_new_password'] : $txt['openid_secret_reminder'], '</p>
-				<dl>
-					<dt>', $txt['secret_question'], ':</dt>
-					<dd>', $context['secret_question'], '</dd>
-					<dt>', $txt['secret_answer'], ':</dt>
-					<dd><input type="text" name="secret_answer" size="22" class="input_text" /></dd>';
-
-	if ($context['account_type'] == 'password')
-		echo '
-					<dt>', $txt['choose_pass'], ': </dt>
-					<dd>
-						<input type="password" name="passwrd1" id="smf_autov_pwmain" size="22" class="input_password" />
-						<span id="smf_autov_pwmain_div" style="display: none;">
-							<img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
-						</span>
-					</dd>
-					<dt>', $txt['verify_pass'], ': </dt>
-					<dd>
-						<input type="password" name="passwrd2" id="smf_autov_pwverify" size="22" class="input_password" />
-						<span id="smf_autov_pwverify_div" style="display: none;">
-							<img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_valid.png" alt="*" />
-						</span>
-					</dd>';
-
-	echo '
-				</dl>
-				<p class="align_center"><input type="submit" value="', $txt['save'], '" class="button_submit" /></p>
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</div>
-		<br class="clear" />
-		<input type="hidden" name="uid" value="', $context['remind_user'], '" />
-		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		<input type="hidden" name="', $context['remind-sai_token_var'], '" value="', $context['remind-sai_token'], '" />
-	</form>';
-
-	if ($context['account_type'] == 'password')
-		echo '
-<script type="text/javascript"><!-- // --><![CDATA[
-	var regTextStrings = {
-		"password_short": "', $txt['registration_password_short'], '",
-		"password_reserved": "', $txt['registration_password_reserved'], '",
-		"password_numbercase": "', $txt['registration_password_numbercase'], '",
-		"password_no_match": "', $txt['registration_password_no_match'], '",
-		"password_valid": "', $txt['registration_password_valid'], '"
-	};
-	var verificationHandle = new smfRegister("creator", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
-// ]]></script>';
-
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<br />
+	<form action="', $scripturl, '?action=reminder;sa=picktype" method="post" accept-charset="', $context['character_set'], '">
+		<div class="tborder login">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['authentication_reminder'], '</h3>
+			</div>
+			<div class="roundframe">
+				<p class="smalltext centertext">', $txt['password_reminder_desc'], '</p>
+				<dl>
+					<dt>', $txt['user_email'], ':</dt>
+					<dd><input type="text" name="user" size="30" class="input_text" /></dd>
+				</dl>
+				<input type="submit" value="', $txt['reminder_continue'], '" class="button_submit" />
+				<br class="clear" />
+			</div>
+		</div>
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		<input type="hidden" name="', $context['remind_token_var'], '" value="', $context['remind_token'], '" />
+	</form>';
+}
+
+function template_reminder_pick()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<br />
+	<form action="', $scripturl, '?action=reminder;sa=picktype" method="post" accept-charset="', $context['character_set'], '">
+		<div class="tborder login">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['authentication_reminder'], '</h3>
+			</div>
+			<div class="roundframe">
+				<p><strong>', $txt['authentication_options'], ':</strong></p>
+				<p>
+					<input type="radio" name="reminder_type" id="reminder_type_email" value="email" checked="checked" class="input_radio" /></dt>
+					<label for="reminder_type_email">', $txt['authentication_' . $context['account_type'] . '_email'], '</label></dd>
+				</p>
+				<p>
+					<input type="radio" name="reminder_type" id="reminder_type_secret" value="secret" class="input_radio" />
+					<label for="reminder_type_secret">', $txt['authentication_' . $context['account_type'] . '_secret'], '</label>
+				</p>
+				<input type="submit" value="', $txt['reminder_continue'], '" class="button_submit" />
+				<br class="clear" />
+			</div>
+		</div>
+		
+		<input type="hidden" name="uid" value="', $context['current_member']['id'], '" />
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		<input type="hidden" name="', $context['remind_token_var'], '" value="', $context['remind_token'], '" />
+	</form>';
+}
+
+function template_sent()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<br />
+		<div class="tborder login" id="reminder_sent">
+			<div class="cat_bar">
+				<h3 class="catbg">' . $context['page_title'] . '</h3>
+			</div>
+			<p class="information">' . $context['description'] . '</p>
+		</div>';
+}
+
+function template_set_password()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	echo '
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
+	<br />
+	<form action="', $scripturl, '?action=reminder;sa=setpassword2" name="reminder_form" id="reminder_form" method="post" accept-charset="', $context['character_set'], '">
+		<div class="tborder login">
+			<div class="cat_bar">
+				<h3 class="catbg">', $context['page_title'], '</h3>
+			</div>
+			<div class="roundframe">
+				<dl>
+					<dt>', $txt['choose_pass'], ': </dt>
+					<dd>
+						<input type="password" name="passwrd1" id="smf_autov_pwmain" size="22" class="input_password" />
+						<span id="smf_autov_pwmain_div" style="display: none;">
+							<img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
+						</span>
+					</dd>
+					<dt>', $txt['verify_pass'], ': </dt>
+					<dd>
+						<input type="password" name="passwrd2" id="smf_autov_pwverify" size="22" class="input_password" />
+						<span id="smf_autov_pwverify_div" style="display: none;">
+							<img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
+						</span>
+					</dd>
+				</dl>
+				<p class="align_center"><input type="submit" value="', $txt['save'], '" class="button_submit" /></p>
+			</div>
+		</div>
+		<input type="hidden" name="code" value="', $context['code'], '" />
+		<input type="hidden" name="u" value="', $context['memID'], '" />
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		<input type="hidden" name="', $context['remind-sp_token_var'], '" value="', $context['remind-sp_token'], '" />
+	</form>
+	<script type="text/javascript"><!-- // --><![CDATA[
+	var regTextStrings = {
+		"password_short": "', $txt['registration_password_short'], '",
+		"password_reserved": "', $txt['registration_password_reserved'], '",
+		"password_numbercase": "', $txt['registration_password_numbercase'], '",
+		"password_no_match": "', $txt['registration_password_no_match'], '",
+		"password_valid": "', $txt['registration_password_valid'], '"
+	};
+	var verificationHandle = new smfRegister("reminder_form", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
+// ]]></script>';
+}
+
+function template_ask()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	echo '
+	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/register.js"></script>
+	<br />
+	<form action="', $scripturl, '?action=reminder;sa=secret2" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
+		<div class="tborder login">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['authentication_reminder'], '</h3>
+			</div>
+			<div class="roundframe">
+				<p class="smalltext">', $context['account_type'] == 'password' ? $txt['enter_new_password'] : $txt['openid_secret_reminder'], '</p>
+				<dl>
+					<dt>', $txt['secret_question'], ':</dt>
+					<dd>', $context['secret_question'], '</dd>
+					<dt>', $txt['secret_answer'], ':</dt>
+					<dd><input type="text" name="secret_answer" size="22" class="input_text" /></dd>';
+
+	if ($context['account_type'] == 'password')
+		echo '
+					<dt>', $txt['choose_pass'], ': </dt>
+					<dd>
+						<input type="password" name="passwrd1" id="smf_autov_pwmain" size="22" class="input_password" />
+						<span id="smf_autov_pwmain_div" style="display: none;">
+							<img id="smf_autov_pwmain_img" src="', $settings['images_url'], '/icons/field_invalid.png" alt="*" />
+						</span>
+					</dd>
+					<dt>', $txt['verify_pass'], ': </dt>
+					<dd>
+						<input type="password" name="passwrd2" id="smf_autov_pwverify" size="22" class="input_password" />
+						<span id="smf_autov_pwverify_div" style="display: none;">
+							<img id="smf_autov_pwverify_img" src="', $settings['images_url'], '/icons/field_valid.png" alt="*" />
+						</span>
+					</dd>';
+
+	echo '
+				</dl>
+				<p class="align_center"><input type="submit" value="', $txt['save'], '" class="button_submit" /></p>
+			</div>
+		</div>
+		<br class="clear" />
+		<input type="hidden" name="uid" value="', $context['remind_user'], '" />
+		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		<input type="hidden" name="', $context['remind-sai_token_var'], '" value="', $context['remind-sai_token'], '" />
+	</form>';
+
+	if ($context['account_type'] == 'password')
+		echo '
+<script type="text/javascript"><!-- // --><![CDATA[
+	var regTextStrings = {
+		"password_short": "', $txt['registration_password_short'], '",
+		"password_reserved": "', $txt['registration_password_reserved'], '",
+		"password_numbercase": "', $txt['registration_password_numbercase'], '",
+		"password_no_match": "', $txt['registration_password_no_match'], '",
+		"password_valid": "', $txt['registration_password_valid'], '"
+	};
+	var verificationHandle = new smfRegister("creator", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings);
+// ]]></script>';
+
+}
+
 ?>

+ 246 - 248
Themes/default/Reports.template.php

@@ -1,249 +1,247 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// Choose which type of report to run?
-function template_report_type()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=reports" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['generate_reports'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['generate_reports_desc'], '
-			</div>
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['generate_reports_type'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="generate_report">';
-
-	// Go through each type of report they can run.
-	foreach ($context['report_types'] as $type)
-	{
-		echo '
-						<dt>
-							<input type="radio" id="rt_', $type['id'], '" name="rt" value="', $type['id'], '"', $type['is_first'] ? ' checked="checked"' : '', ' class="input_radio" />
-							<strong><label for="rt_', $type['id'], '">', $type['title'], '</label></strong>
-						</dt>';
-		if (isset($type['description']))
-			echo '
-						<dd>', $type['description'], '</dd>';
-	}
-		echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="continue" value="', $txt['generate_reports_continue'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// This is the standard template for showing reports in.
-function template_main()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<div class="title_bar">
-			<h3 class="titlebg">', $txt['results'], '</h3>
-		</div>
-		<div id="report_buttons">';
-
-	if (!empty($context['report_buttons']) && !empty($settings['use_tabs']))
-		template_button_strip($context['report_buttons'], 'right');
-
-	echo '
-		</div>';
-
-	// Go through each table!
-	foreach ($context['tables'] as $table)
-	{
-		echo '
-		<table class="table_grid" width="100%">';
-
-		if (!empty($table['title']))
-			echo '
-			<thead>
-				<tr class="catbg">
-					<th scope="col" colspan="', $table['column_count'], '">', $table['title'], '</th>
-				</tr>
-			</thead>
-			<tbody>';
-
-		// Now do each row!
-		$row_number = 0;
-		$alternate = false;
-		foreach ($table['data'] as $row)
-		{
-			if ($row_number == 0 && !empty($table['shading']['top']))
-				echo '
-				<tr class="windowbg table_caption">';
-			else
-				echo '
-				<tr class="', !empty($row[0]['separator']) ? 'catbg' : ($alternate ? 'windowbg' : 'windowbg2'), '" valign="top">';
-
-			// Now do each column.
-			$column_number = 0;
-
-			foreach ($row as $key => $data)
-			{
-				// If this is a special separator, skip over!
-				if (!empty($data['separator']) && $column_number == 0)
-				{
-					echo '
-					<td colspan="', $table['column_count'], '" class="smalltext">
-						', $data['v'], ':
-					</td>';
-					break;
-				}
-
-				// Shaded?
-				if ($column_number == 0 && !empty($table['shading']['left']))
-					echo '
-					<td align="', $table['align']['shaded'], '" class="table_caption"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '>
-						', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), '
-					</td>';
-				else
-					echo '
-					<td class="smalltext" align="', $table['align']['normal'], '"', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '>
-						', $data['v'], '
-					</td>';
-
-				$column_number++;
-			}
-
-			echo '
-				</tr>';
-
-			$row_number++;
-			$alternate = !$alternate;
-		}
-		echo '
-			</tbody>
-		</table>';
-	}
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-// Header of the print page!
-function template_print_above()
-{
-	global $context, $settings, $options, $txt;
-
-	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
-	<head>
-		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
-		<title>', $context['page_title'], '</title>
-		<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/report.css" />
-	</head>
-	<body>';
-}
-
-function template_print()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	// Go through each table!
-	foreach ($context['tables'] as $table)
-	{
-		echo '
-		<div style="overflow: visible;', $table['max_width'] != 'auto' ? ' width: ' . $table['max_width'] . 'px;' : '', '">
-			<table border="0" cellspacing="1" cellpadding="4" width="100%" class="bordercolor">';
-
-		if (!empty($table['title']))
-			echo '
-				<tr class="catbg">
-					<td colspan="', $table['column_count'], '">
-						', $table['title'], '
-					</td>
-				</tr>';
-
-		// Now do each row!
-		$alternate = false;
-		$row_number = 0;
-		foreach ($table['data'] as $row)
-		{
-			if ($row_number == 0 && !empty($table['shading']['top']))
-				echo '
-				<tr class="titlebg" valign="top">';
-			else
-				echo '
-				<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" valign="top">';
-
-			// Now do each column!!
-			$column_number = 0;
-			foreach ($row as $key => $data)
-			{
-				// If this is a special separator, skip over!
-				if (!empty($data['separator']) && $column_number == 0)
-				{
-					echo '
-					<td colspan="', $table['column_count'], '" class="catbg">
-						<strong>', $data['v'], ':</strong>
-					</td>';
-					break;
-				}
-
-				// Shaded?
-				if ($column_number == 0 && !empty($table['shading']['left']))
-					echo '
-					<td align="', $table['align']['shaded'], '" class="titlebg"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '>
-						', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), '
-					</td>';
-				else
-					echo '
-					<td align="', $table['align']['normal'], '"', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '>
-						', $data['v'], '
-					</td>';
-
-				$column_number++;
-			}
-
-			echo '
-				</tr>';
-
-			$row_number++;
-			$alternate = !$alternate;
-		}
-		echo '
-			</table>
-		</div><br />';
-	}
-}
-
-// Footer of the print page.
-function template_print_below()
-{
-	global $context, $settings, $options;
-
-	echo '
-		<div class="copyright">', theme_copyright(), '</div>
-	</body>
-</html>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// Choose which type of report to run?
+function template_report_type()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=reports" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['generate_reports'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['generate_reports_desc'], '
+			</div>
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['generate_reports_type'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="generate_report">';
+
+	// Go through each type of report they can run.
+	foreach ($context['report_types'] as $type)
+	{
+		echo '
+						<dt>
+							<input type="radio" id="rt_', $type['id'], '" name="rt" value="', $type['id'], '"', $type['is_first'] ? ' checked="checked"' : '', ' class="input_radio" />
+							<strong><label for="rt_', $type['id'], '">', $type['title'], '</label></strong>
+						</dt>';
+		if (isset($type['description']))
+			echo '
+						<dd>', $type['description'], '</dd>';
+	}
+		echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="continue" value="', $txt['generate_reports_continue'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// This is the standard template for showing reports in.
+function template_main()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<div class="title_bar">
+			<h3 class="titlebg">', $txt['results'], '</h3>
+		</div>
+		<div id="report_buttons">';
+
+	if (!empty($context['report_buttons']) && !empty($settings['use_tabs']))
+		template_button_strip($context['report_buttons'], 'right');
+
+	echo '
+		</div>';
+
+	// Go through each table!
+	foreach ($context['tables'] as $table)
+	{
+		echo '
+		<table class="table_grid" width="100%">';
+
+		if (!empty($table['title']))
+			echo '
+			<thead>
+				<tr class="catbg">
+					<th scope="col" colspan="', $table['column_count'], '">', $table['title'], '</th>
+				</tr>
+			</thead>
+			<tbody>';
+
+		// Now do each row!
+		$row_number = 0;
+		$alternate = false;
+		foreach ($table['data'] as $row)
+		{
+			if ($row_number == 0 && !empty($table['shading']['top']))
+				echo '
+				<tr class="windowbg table_caption">';
+			else
+				echo '
+				<tr class="', !empty($row[0]['separator']) ? 'catbg' : ($alternate ? 'windowbg' : 'windowbg2'), '" valign="top">';
+
+			// Now do each column.
+			$column_number = 0;
+
+			foreach ($row as $key => $data)
+			{
+				// If this is a special separator, skip over!
+				if (!empty($data['separator']) && $column_number == 0)
+				{
+					echo '
+					<td colspan="', $table['column_count'], '" class="smalltext">
+						', $data['v'], ':
+					</td>';
+					break;
+				}
+
+				// Shaded?
+				if ($column_number == 0 && !empty($table['shading']['left']))
+					echo '
+					<td align="', $table['align']['shaded'], '" class="table_caption"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '>
+						', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), '
+					</td>';
+				else
+					echo '
+					<td class="smalltext" align="', $table['align']['normal'], '"', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '>
+						', $data['v'], '
+					</td>';
+
+				$column_number++;
+			}
+
+			echo '
+				</tr>';
+
+			$row_number++;
+			$alternate = !$alternate;
+		}
+		echo '
+			</tbody>
+		</table>';
+	}
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+// Header of the print page!
+function template_print_above()
+{
+	global $context, $settings, $options, $txt;
+
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
+		<title>', $context['page_title'], '</title>
+		<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/report.css" />
+	</head>
+	<body>';
+}
+
+function template_print()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	// Go through each table!
+	foreach ($context['tables'] as $table)
+	{
+		echo '
+		<div style="overflow: visible;', $table['max_width'] != 'auto' ? ' width: ' . $table['max_width'] . 'px;' : '', '">
+			<table border="0" cellspacing="1" cellpadding="4" width="100%" class="bordercolor">';
+
+		if (!empty($table['title']))
+			echo '
+				<tr class="catbg">
+					<td colspan="', $table['column_count'], '">
+						', $table['title'], '
+					</td>
+				</tr>';
+
+		// Now do each row!
+		$alternate = false;
+		$row_number = 0;
+		foreach ($table['data'] as $row)
+		{
+			if ($row_number == 0 && !empty($table['shading']['top']))
+				echo '
+				<tr class="titlebg" valign="top">';
+			else
+				echo '
+				<tr class="', $alternate ? 'windowbg' : 'windowbg2', '" valign="top">';
+
+			// Now do each column!!
+			$column_number = 0;
+			foreach ($row as $key => $data)
+			{
+				// If this is a special separator, skip over!
+				if (!empty($data['separator']) && $column_number == 0)
+				{
+					echo '
+					<td colspan="', $table['column_count'], '" class="catbg">
+						<strong>', $data['v'], ':</strong>
+					</td>';
+					break;
+				}
+
+				// Shaded?
+				if ($column_number == 0 && !empty($table['shading']['left']))
+					echo '
+					<td align="', $table['align']['shaded'], '" class="titlebg"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '>
+						', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), '
+					</td>';
+				else
+					echo '
+					<td align="', $table['align']['normal'], '"', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '>
+						', $data['v'], '
+					</td>';
+
+				$column_number++;
+			}
+
+			echo '
+				</tr>';
+
+			$row_number++;
+			$alternate = !$alternate;
+		}
+		echo '
+			</table>
+		</div><br />';
+	}
+}
+
+// Footer of the print page.
+function template_print_below()
+{
+	global $context, $settings, $options;
+
+	echo '
+		<div class="copyright">', theme_copyright(), '</div>
+	</body>
+</html>';
+}
+
 ?>

+ 532 - 548
Themes/default/Search.template.php

@@ -1,549 +1,533 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl, $modSettings;
-
-	echo '
-	<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft">', !empty($settings['use_buttons']) ? '<img src="' . $settings['images_url'] . '/buttons/search.png" alt="" class="icon" />' : ' ', $txt['set_parameters'], '</span>
-			</h3>
-		</div>';
-
-	if (!empty($context['search_errors']))
-		echo '
-		<p class="errorbox">', implode('<br />', $context['search_errors']['messages']), '</p>';
-
-	// Simple Search?
-	if ($context['simple_search'])
-	{
-		echo '
-		<fieldset id="simple_search">
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<div id="search_term_input">
-					<strong>', $txt['search_for'], ':</strong>
-					<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
-					', $context['require_verification'] ? '' : '&nbsp;<input type="submit" name="s_search" value="' . $txt['search'] . '" class="button_submit" />
-				</div>';
-
-		if (empty($modSettings['search_simple_fulltext']))
-			echo '
-				<p class="smalltext">', $txt['search_example'], '</p>';
-
-		if ($context['require_verification'])
-			echo '
-				<div class="verification>
-					<strong>', $txt['search_visual_verification_label'], ':</strong>
-					<br />', template_control_verification($context['visual_verification_id'], 'all'), '<br />
-					<input id="submit" type="submit" name="s_search" value="' . $txt['search'] . '" class="button_submit" />
-				</div>';
-
-		echo '
-				<a href="', $scripturl, '?action=search;advanced" onclick="this.href += \';search=\' + escape(document.forms.searchform.search.value);">', $txt['search_advanced'], '</a>
-				<input type="hidden" name="advanced" value="0" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</fieldset>';
-	}
-
-	// Advanced search!
-	else
-	{
-		echo '
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<dl class="settings" id="search_options">
-					<dt class="righttext">
-						<strong><label for="searchfor">', $txt['search_for'], ':</label></strong>
-					</dt>
-					<dd>
-						<input type="text" name="search" id="searchfor" ', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />';
-		
-		if (empty($modSettings['search_simple_fulltext']))
-			echo '
-				<em class="smalltext">', $txt['search_example'], '</em>';
-				
-		echo '
-					</dd>
-
-					<dt class="righttext"><label for="searchtype">',
-						$txt['search_match'], ':</label>
-					</dt>
-					<dd>
-						<select name="searchtype" id="searchtype">
-							<option value="1"', empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['all_words'], '</option>
-							<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['any_words'], '</option>
-						</select>
-					</dd>
-					<dt class="righttext"><label for="userspec">',
-						$txt['by_user'], ':</label>
-					</dt>
-					<dd>
-						<input id="userspec" type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40" class="input_text" />
-					</dd>
-					<dt class="righttext"><label for="sort">', 
-						$txt['search_order'], ':</label>
-					</dt>
-					<dd>
-						<select id="sort" name="sort">
-							<option value="relevance|desc">', $txt['search_orderby_relevant_first'], '</option>
-							<option value="num_replies|desc">', $txt['search_orderby_large_first'], '</option>
-							<option value="num_replies|asc">', $txt['search_orderby_small_first'], '</option>
-							<option value="id_msg|desc">', $txt['search_orderby_recent_first'], '</option>
-							<option value="id_msg|asc">', $txt['search_orderby_old_first'], '</option>
-						</select>
-					</dd>
-					<dt class="righttext options">', 
-						$txt['search_options'], ':
-					</dt>
-					<dd class="options">
-						<label for="show_complete">', $txt['search_show_complete_messages'], '
-							<input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked="checked"' : '', ' class="input_check" />
-						</label><br />
-						<label for="subject_only">', $txt['search_subject_only'], '
-							<input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked="checked"' : '', ' class="input_check" />
-						</label>
-					</dd>
-					<dt class="righttext between">', 
-						$txt['search_post_age'], ':
-					</dt>
-					<dd><label for="minage">', 
-						$txt['search_between'], '</label><input type="text" name="minage" id="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="4" class="input_text" />&nbsp;<label for="maxage">', $txt['search_and'], '&nbsp;</label><input type="text" name="maxage" id="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="4" class="input_text" /> ', $txt['days_word'], '
-					</dd>
-				</dl>
-				</fieldset>
-				<script type="text/javascript"><!-- // --><![CDATA[
-					createEventListener(window);
-					window.addEventListener("load", initSearch, false);
-				// ]]></script>
-				<input type="hidden" name="advanced" value="1" />';
-
-		// Require an image to be typed to save spamming?
-		if ($context['require_verification'])
-		{
-			echo '
-				<p>
-					<strong>', $txt['verification'], ':</strong>
-					', template_control_verification($context['visual_verification_id'], 'all'), '
-				</p>';
-		}
-
-		// If $context['search_params']['topic'] is set, that means we're searching just one topic.
-		if (!empty($context['search_params']['topic']))
-			echo '
-				<p>', $txt['search_specific_topic'], ' &quot;', $context['search_topic']['link'], '&quot;.</p>
-				<input type="hidden" name="topic" value="', $context['search_topic']['id'], '" />';
-
-		echo '
-			</div>
-			<span class="lowerframe"><span></span></span>
-		';
-
-		if (empty($context['search_params']['topic']))
-		{
-			echo '
-		<fieldset class="flow_hidden">
-			<span class="upperframe"><span></span></span>
-			<div class="roundframe">
-				<div class="title_bar">
-					<h4 class="titlebg">
-						<span class="ie6_header floatright">
-							<a href="javascript:void(0);" onclick="expandCollapseBoards(); return false;"><img src="', $settings['images_url'], '/expand.png" id="expandBoardsIcon" alt=""  class="icon"/></a>
-						</span>
-						<span>
-							<a href="javascript:void(0);" onclick="expandCollapseBoards(); return false;"><strong>', $txt['choose_board'], '</strong></a>
-						</span>
-					</h4>
-				</div>
-				<div class="flow_auto" id="searchBoardsExpand"', $context['boards_check_all'] ? ' style="display: none;"' : '', '>
-					<ul class="ignoreboards floatleft">';
-
-	$i = 0;
-	$limit = ceil($context['num_boards'] / 2);
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-						<li class="category">
-							<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'searchform\'); return false;">', $category['name'], '</a>
-							<ul>';
-
-		foreach ($category['boards'] as $board)
-		{
-			if ($i == $limit)
-				echo '
-							</ul>
-						</li>
-					</ul>
-					<ul class="ignoreboards floatright">
-						<li class="category">
-							<ul>';
-
-			echo '
-								<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
-									<label for="brd', $board['id'], '"><input type="checkbox" id="brd', $board['id'], '" name="brd[', $board['id'], ']" value="', $board['id'], '"', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> ', $board['name'], '</label>
-								</li>';
-
-			$i ++;
-		}
-
-		echo '
-							</ul>
-						</li>';
-	}
-
-	echo '
-					</ul>
-				</div>
-				<br class="clear" />';
-
-			echo '
-				<div class="padding">
-					<input type="checkbox" name="all" id="check_all" value=""', $context['boards_check_all'] ? ' checked="checked"' : '', ' onclick="invertAll(this, this.form, \'brd\');" class="input_check floatleft" />
-					<label for="check_all" class="floatleft"><em>', $txt['check_all'], '</em></label>
-					<input type="submit" name="b_search" value="', $txt['search'], '" class="button_submit" />
-				</div>
-				<br class="clear_right" />
-			</div>
-			<span class="lowerframe"><span></span></span>
-		</fieldset>';
-		}
-	echo '
-		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var oAddMemberSuggest = new smc_AutoSuggest({
-				sSelf: \'oAddMemberSuggest\',
-				sSessionId: smf_session_id,
-				sSessionVar: smf_session_var,
-				sControlId: \'userspec\',
-				sSearchType: \'member\',
-				bItemList: false
-			});
-		// ]]></script>';
-	}
-
-	echo '
-	</form>';
-}
-
-function template_results()
-{
-	global $context, $settings, $options, $txt, $scripturl, $message;
-
-	if (isset($context['did_you_mean']) || empty($context['topics']))
-	{
-		echo '
-	<div id="search_results">
-		<div class="cat_bar">
-			<h3 class="catbg">
-				', $txt['search_adjust_query'], '
-			</h3>
-		</div>
-		<span class="upperframe"><span></span></span>
-		<div class="roundframe">';
-
-		// Did they make any typos or mistakes, perhaps?
-		if (isset($context['did_you_mean']))
-			echo '
-			<p>', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.</p>';
-
-		echo '
-			<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
-				<dl class="settings">
-					<dt class="righttext">
-						<strong>', $txt['search_for'], ':</strong>
-					</dt>
-					<dd>
-						<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
-					</dd>
-				</dl>
-				
-				<input type="submit" name="edit_search" value="', $txt['search_adjust_submit'], '" class="button_submit" />
-				<br class="clear_right" />
-				<input type="hidden" name="searchtype" value="', !empty($context['search_params']['searchtype']) ? $context['search_params']['searchtype'] : 0, '" />
-				<input type="hidden" name="userspec" value="', !empty($context['search_params']['userspec']) ? $context['search_params']['userspec'] : '', '" />
-				<input type="hidden" name="show_complete" value="', !empty($context['search_params']['show_complete']) ? 1 : 0, '" />
-				<input type="hidden" name="subject_only" value="', !empty($context['search_params']['subject_only']) ? 1 : 0, '" />
-				<input type="hidden" name="minage" value="', !empty($context['search_params']['minage']) ? $context['search_params']['minage'] : '0', '" />
-				<input type="hidden" name="maxage" value="', !empty($context['search_params']['maxage']) ? $context['search_params']['maxage'] : '9999', '" />
-				<input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '" />';
-
-		if (!empty($context['search_params']['brd']))
-			foreach ($context['search_params']['brd'] as $board_id)
-				echo '
-				<input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '" />';
-
-		echo '
-			</form>
-		</div>
-		<span class="lowerframe"><span></span></span>
-	</div><br />';
-	}
-
-	if ($context['compact'])
-	{
-		// Quick moderation set to checkboxes? Oh, how fun :/.
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
-			echo '
-	<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="topicForm">';
-
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="floatright">';
-					if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
-					echo '
-							<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="input_check" />';
-				echo '
-				</span>
-				<span class="ie6_header floatleft"><img src="' . $settings['images_url'] . '/buttons/search.png" alt="?" class="centericon" />&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'</span>
-			</h3>
-		</div>';
-		
-		// was anything even found?
-		if (!empty($context['topics']))
-		echo'
-		<div class="pagesection">
-			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
-		</div>';
-		else
-			echo '
-		<span class="upperframe"><span></span></span>
-			<div class="roundframe">', $txt['find_no_results'], '</div>
-		<span class="lowerframe"><span></span></span>';
-
-		// while we have results to show ...
-		while ($topic = $context['get_topics']())
-		{
-			$color_class = '';
-			if ($topic['is_sticky'])
-				$color_class = 'stickybg';
-			if ($topic['is_locked'])
-				$color_class .= 'lockedbg';
-
-			echo '
-			<div class="search_results_posts">
-			<div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
-				<span class="topslice"><span></span></span>
-				<div class="content flow_auto">';
-
-			foreach ($topic['matches'] as $message)
-			{
-				echo '
-					<div class="topic_details floatleft" style="width: 94%">
-						<div class="counter">', $message['counter'], '</div>
-						<h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.msg', $message['id'], '#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
-						<span class="smalltext">&#171;&nbsp;',$txt['by'],'&nbsp;<strong>', $message['member']['link'], '</strong>&nbsp;',$txt['on'],'&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
-					</div>';
-
-				if (!empty($options['display_quick_mod']))
-				{
-					echo '
-					<div class="floatright">';
-
-					if ($options['display_quick_mod'] == 1)
-					{
-						echo '
-						<input type="checkbox" name="topics[]" value="', $topic['id'], '" class="input_check" />';
-					}
-					else
-					{
-						if ($topic['quick_mod']['remove'])
-							echo '
-						<a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=remove;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_remove.png" width="16" alt="', $txt['remove_topic'], '" title="', $txt['remove_topic'], '" /></a>';
-
-						if ($topic['quick_mod']['lock'])
-							echo '
-						<a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=lock;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_lock.png" width="16" alt="', $txt['set_lock'], '" title="', $txt['set_lock'], '" /></a>';
-
-						if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
-							echo '
-						<br />';
-
-						if ($topic['quick_mod']['sticky'])
-							echo '
-						<a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=sticky;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_sticky.png" width="16" alt="', $txt['set_sticky'], '" title="', $txt['set_sticky'], '" /></a>';
-
-						if ($topic['quick_mod']['move'])
-							echo '
-						<a href="', $scripturl, '?action=movetopic;topic=', $topic['id'], '.0"><img src="', $settings['images_url'], '/icons/quick_move.png" width="16" alt="', $txt['move_topic'], '" title="', $txt['move_topic'], '" /></a>';
-					}
-
-					echo '
-					</div>';
-				}
-
-				if ($message['body_highlighted'] != '')
-					echo '
-					<br class="clear" />
-					<div class="list_posts double_height">', $message['body_highlighted'], '</div>';
-			}
-
-			echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>';
-
-		}
-		if (!empty($context['topics']))
-		echo '
-		<div class="pagesection">
-			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
-		</div>';
-
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
-		{
-			echo '
-			<div class="middletext titlebg2" style="padding: 4px;">
-				<div class="floatright">
-					<select name="qaction"', $context['can_move'] ? ' onchange="this.form.moveItTo.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
-						<option value="">--------</option>', $context['can_remove'] ? '
-						<option value="remove">' . $txt['quick_mod_remove'] . '</option>' : '', $context['can_lock'] ? '
-						<option value="lock">' . $txt['quick_mod_lock'] . '</option>' : '', $context['can_sticky'] ? '
-						<option value="sticky">' . $txt['quick_mod_sticky'] . '</option>' : '',	$context['can_move'] ? '
-						<option value="move">' . $txt['quick_mod_move'] . ': </option>' : '', $context['can_merge'] ? '
-						<option value="merge">' . $txt['quick_mod_merge'] . '</option>' : '', '
-						<option value="markread">', $txt['quick_mod_markread'], '</option>
-					</select>';
-
-			if ($context['can_move'])
-			{
-					echo '
-					<select id="moveItTo" name="move_to" disabled="disabled">';
-
-					foreach ($context['move_to_boards'] as $category)
-					{
-						echo '
-						<optgroup label="', $category['name'], '">';
-						foreach ($category['boards'] as $board)
-								echo '
-						<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
-						echo '
-						</optgroup>';
-					}
-					echo '
-					</select>';
-			}
-
-			echo '
-					<input type="hidden" name="redirect_url" value="', $scripturl . '?action=search2;params=' . $context['params'], '" />
-					<input type="submit" style="font-size: 0.8em;" value="', $txt['quick_mod_go'], '" onclick="return this.form.qaction.value != \'\' &amp;&amp; confirm(\'', $txt['quickmod_confirm'], '\');" class="button_submit" />
-				</div>
-				<br class="clear" />
-			</div>';
-		}
-
-
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
-			echo '
-			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
-		</form>';
-
-	}
-	else
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><img class="centericon" src="' . $settings['images_url'] . '/buttons/search.png" alt="?" />&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'</span>
-			</h3>
-		</div>
-		<div class="pagesection">
-			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
-		</div>';
-
-		if (empty($context['topics']))
-			echo '
-		<div class="information">(', $txt['search_no_results'], ')</div>';
-
-		while ($topic = $context['get_topics']())
-		{
-			foreach ($topic['matches'] as $message)
-			{
-				echo '
-			<div class="search_results_posts">
-				<div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
-					<span class="topslice"><span></span></span>
-					<div class="content">
-						<div class="counter">', $message['counter'], '</div>
-						<div class="topic_details">
-							<h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.', $message['start'], ';topicseen#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
-							<span class="smalltext">&#171;&nbsp;', $txt['message'], ' ', $txt['by'], ' <strong>', $message['member']['link'], ' </strong>', $txt['on'], '&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
-						</div>
-						<div class="list_posts">', $message['body_highlighted'], '</div>';
-
-				if ($topic['can_reply'] || $topic['can_mark_notify'])
-					echo '
-						<div class="quickbuttons_wrap">
-							<ul class="reset smalltext quickbuttons">';
-
-				// If they *can* reply?
-				if ($topic['can_reply'])
-					echo '
-								<li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'], '" class="reply_button">', $txt['reply'], '</a></li>';
-
-				// If they *can* quote?
-				if ($topic['can_quote'])
-					echo '
-								<li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'] . ';quote=' . $message['id'] . '" class="quote_button">', $txt['quote'], '</a></li>';
-
-				// Can we request notification of topics?
-				if ($topic['can_mark_notify'])
-					echo '
-								<li><a href="', $scripturl . '?action=notify;topic=' . $topic['id'] . '.' . $message['start'], '" class="notify_button">', $txt['notify'], '</a></li>';
-
-				if ($topic['can_reply'] || $topic['can_mark_notify'])
-					echo '
-							</ul>
-						</div>';
-				echo '
-						<br class="clear" />
-					</div>
-					<span class="botslice"><span></span></span>
-				</div>
-			</div>';
-			}
-		}
-
-		echo '
-		<div class="pagesection">
-			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
-		</div>';
-	}
-
-	// Show a jump to box for easy navigation.
-	echo '
-		<br class="clear" />
-		<div class="smalltext righttext" id="search_jump_to">&nbsp;</div>
-		<script type="text/javascript"><!-- // --><![CDATA[
-			if (typeof(window.XMLHttpRequest) != "undefined")
-				aJumpTo[aJumpTo.length] = new JumpTo({
-					sContainerId: "search_jump_to",
-					sJumpToTemplate: "<label class=\"smalltext\" for=\"%select_id%\">', $context['jump_to']['label'], ':<" + "/label> %dropdown_list%",
-					iCurBoardId: 0,
-					iCurBoardChildLevel: 0,
-					sCurBoardName: "', $context['jump_to']['board_name'], '",
-					sBoardChildLevelIndicator: "==",
-					sBoardPrefix: "=> ",
-					sCatSeparator: "-----------------------------",
-					sCatPrefix: "",
-					sGoButtonLabel: "', $txt['quick_mod_go'], '"
-				});
-		// ]]></script>';
-
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	echo '
+	<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', !empty($settings['use_buttons']) ? '<img src="' . $settings['images_url'] . '/buttons/search.png" alt="" class="icon" />' : ' ', $txt['set_parameters'], '
+			</h3>
+		</div>';
+
+	if (!empty($context['search_errors']))
+		echo '
+		<p class="errorbox">', implode('<br />', $context['search_errors']['messages']), '</p>';
+
+	// Simple Search?
+	if ($context['simple_search'])
+	{
+		echo '
+		<fieldset id="simple_search">
+			<div class="roundframe">
+				<div id="search_term_input">
+					<strong>', $txt['search_for'], ':</strong>
+					<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
+					', $context['require_verification'] ? '' : '&nbsp;<input type="submit" name="s_search" value="' . $txt['search'] . '" class="button_submit" />
+				</div>';
+
+		if (empty($modSettings['search_simple_fulltext']))
+			echo '
+				<p class="smalltext">', $txt['search_example'], '</p>';
+
+		if ($context['require_verification'])
+			echo '
+				<div class="verification>
+					<strong>', $txt['search_visual_verification_label'], ':</strong>
+					<br />', template_control_verification($context['visual_verification_id'], 'all'), '<br />
+					<input id="submit" type="submit" name="s_search" value="' . $txt['search'] . '" class="button_submit" />
+				</div>';
+
+		echo '
+				<a href="', $scripturl, '?action=search;advanced" onclick="this.href += \';search=\' + escape(document.forms.searchform.search.value);">', $txt['search_advanced'], '</a>
+				<input type="hidden" name="advanced" value="0" />
+			</div>
+		</fieldset>';
+	}
+
+	// Advanced search!
+	else
+	{
+		echo '
+			<div class="roundframe">
+				<dl class="settings" id="search_options">
+					<dt class="righttext">
+						<strong><label for="searchfor">', $txt['search_for'], ':</label></strong>
+					</dt>
+					<dd>
+						<input type="text" name="search" id="searchfor" ', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />';
+		
+		if (empty($modSettings['search_simple_fulltext']))
+			echo '
+				<em class="smalltext">', $txt['search_example'], '</em>';
+				
+		echo '
+					</dd>
+
+					<dt class="righttext"><label for="searchtype">',
+						$txt['search_match'], ':</label>
+					</dt>
+					<dd>
+						<select name="searchtype" id="searchtype">
+							<option value="1"', empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['all_words'], '</option>
+							<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['any_words'], '</option>
+						</select>
+					</dd>
+					<dt class="righttext"><label for="userspec">',
+						$txt['by_user'], ':</label>
+					</dt>
+					<dd>
+						<input id="userspec" type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40" class="input_text" />
+					</dd>
+					<dt class="righttext"><label for="sort">', 
+						$txt['search_order'], ':</label>
+					</dt>
+					<dd>
+						<select id="sort" name="sort">
+							<option value="relevance|desc">', $txt['search_orderby_relevant_first'], '</option>
+							<option value="num_replies|desc">', $txt['search_orderby_large_first'], '</option>
+							<option value="num_replies|asc">', $txt['search_orderby_small_first'], '</option>
+							<option value="id_msg|desc">', $txt['search_orderby_recent_first'], '</option>
+							<option value="id_msg|asc">', $txt['search_orderby_old_first'], '</option>
+						</select>
+					</dd>
+					<dt class="righttext options">', 
+						$txt['search_options'], ':
+					</dt>
+					<dd class="options">
+						<label for="show_complete">', $txt['search_show_complete_messages'], '
+							<input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked="checked"' : '', ' class="input_check" />
+						</label><br />
+						<label for="subject_only">', $txt['search_subject_only'], '
+							<input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked="checked"' : '', ' class="input_check" />
+						</label>
+					</dd>
+					<dt class="righttext between">', 
+						$txt['search_post_age'], ':
+					</dt>
+					<dd><label for="minage">', 
+						$txt['search_between'], '</label><input type="text" name="minage" id="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="4" class="input_text" />&nbsp;<label for="maxage">', $txt['search_and'], '&nbsp;</label><input type="text" name="maxage" id="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="4" class="input_text" /> ', $txt['days_word'], '
+					</dd>
+				</dl>
+				</fieldset>
+				<script type="text/javascript"><!-- // --><![CDATA[
+					createEventListener(window);
+					window.addEventListener("load", initSearch, false);
+				// ]]></script>
+				<input type="hidden" name="advanced" value="1" />';
+
+		// Require an image to be typed to save spamming?
+		if ($context['require_verification'])
+		{
+			echo '
+				<p>
+					<strong>', $txt['verification'], ':</strong>
+					', template_control_verification($context['visual_verification_id'], 'all'), '
+				</p>';
+		}
+
+		// If $context['search_params']['topic'] is set, that means we're searching just one topic.
+		if (!empty($context['search_params']['topic']))
+			echo '
+				<p>', $txt['search_specific_topic'], ' &quot;', $context['search_topic']['link'], '&quot;.</p>
+				<input type="hidden" name="topic" value="', $context['search_topic']['id'], '" />';
+
+		echo '
+			</div>
+		';
+
+		if (empty($context['search_params']['topic']))
+		{
+			echo '
+		<fieldset class="flow_hidden">
+			<div class="roundframe">
+				<div class="title_bar">
+					<h4 class="titlebg">
+						<a href="javascript:void(0);" onclick="expandCollapseBoards(); return false;"><img src="', $settings['images_url'], '/expand.png" id="expandBoardsIcon" alt=""  class="icon"/></a>
+						<span>
+							<a href="javascript:void(0);" onclick="expandCollapseBoards(); return false;"><strong>', $txt['choose_board'], '</strong></a>
+						</span>
+					</h4>
+				</div>
+				<div class="flow_auto" id="searchBoardsExpand"', $context['boards_check_all'] ? ' style="display: none;"' : '', '>
+					<ul class="ignoreboards floatleft">';
+
+	$i = 0;
+	$limit = ceil($context['num_boards'] / 2);
+	foreach ($context['categories'] as $category)
+	{
+		echo '
+						<li class="category">
+							<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'searchform\'); return false;">', $category['name'], '</a>
+							<ul>';
+
+		foreach ($category['boards'] as $board)
+		{
+			if ($i == $limit)
+				echo '
+							</ul>
+						</li>
+					</ul>
+					<ul class="ignoreboards floatright">
+						<li class="category">
+							<ul>';
+
+			echo '
+								<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
+									<label for="brd', $board['id'], '"><input type="checkbox" id="brd', $board['id'], '" name="brd[', $board['id'], ']" value="', $board['id'], '"', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> ', $board['name'], '</label>
+								</li>';
+
+			$i ++;
+		}
+
+		echo '
+							</ul>
+						</li>';
+	}
+
+	echo '
+					</ul>
+				</div>
+				<br class="clear" />';
+
+			echo '
+				<div class="padding">
+					<input type="checkbox" name="all" id="check_all" value=""', $context['boards_check_all'] ? ' checked="checked"' : '', ' onclick="invertAll(this, this.form, \'brd\');" class="input_check floatleft" />
+					<label for="check_all" class="floatleft"><em>', $txt['check_all'], '</em></label>
+					<input type="submit" name="b_search" value="', $txt['search'], '" class="button_submit" />
+				</div>
+				<br class="clear_right" />
+			</div>
+		</fieldset>';
+		}
+	echo '
+		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var oAddMemberSuggest = new smc_AutoSuggest({
+				sSelf: \'oAddMemberSuggest\',
+				sSessionId: smf_session_id,
+				sSessionVar: smf_session_var,
+				sControlId: \'userspec\',
+				sSearchType: \'member\',
+				bItemList: false
+			});
+		// ]]></script>';
+	}
+
+	echo '
+	</form>';
+}
+
+function template_results()
+{
+	global $context, $settings, $options, $txt, $scripturl, $message;
+
+	if (isset($context['did_you_mean']) || empty($context['topics']))
+	{
+		echo '
+	<div id="search_results">
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $txt['search_adjust_query'], '
+			</h3>
+		</div>
+		<div class="roundframe">';
+
+		// Did they make any typos or mistakes, perhaps?
+		if (isset($context['did_you_mean']))
+			echo '
+			<p>', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.</p>';
+
+		echo '
+			<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
+				<dl class="settings">
+					<dt class="righttext">
+						<strong>', $txt['search_for'], ':</strong>
+					</dt>
+					<dd>
+						<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
+					</dd>
+				</dl>
+				
+				<input type="submit" name="edit_search" value="', $txt['search_adjust_submit'], '" class="button_submit" />
+				<br class="clear_right" />
+				<input type="hidden" name="searchtype" value="', !empty($context['search_params']['searchtype']) ? $context['search_params']['searchtype'] : 0, '" />
+				<input type="hidden" name="userspec" value="', !empty($context['search_params']['userspec']) ? $context['search_params']['userspec'] : '', '" />
+				<input type="hidden" name="show_complete" value="', !empty($context['search_params']['show_complete']) ? 1 : 0, '" />
+				<input type="hidden" name="subject_only" value="', !empty($context['search_params']['subject_only']) ? 1 : 0, '" />
+				<input type="hidden" name="minage" value="', !empty($context['search_params']['minage']) ? $context['search_params']['minage'] : '0', '" />
+				<input type="hidden" name="maxage" value="', !empty($context['search_params']['maxage']) ? $context['search_params']['maxage'] : '9999', '" />
+				<input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '" />';
+
+		if (!empty($context['search_params']['brd']))
+			foreach ($context['search_params']['brd'] as $board_id)
+				echo '
+				<input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '" />';
+
+		echo '
+			</form>
+		</div>
+	</div><br />';
+	}
+
+	if ($context['compact'])
+	{
+		// Quick moderation set to checkboxes? Oh, how fun :/.
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
+			echo '
+	<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="topicForm">';
+
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<span class="floatright">';
+					if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
+					echo '
+							<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="input_check" />';
+				echo '
+				</span>
+				<img src="' . $settings['images_url'] . '/buttons/search.png" alt="?" class="centericon" />&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'
+			</h3>
+		</div>';
+		
+		// was anything even found?
+		if (!empty($context['topics']))
+		echo'
+		<div class="pagesection">
+			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
+		</div>';
+		else
+			echo '
+			<div class="roundframe">', $txt['find_no_results'], '</div>';
+
+		// while we have results to show ...
+		while ($topic = $context['get_topics']())
+		{
+			$color_class = '';
+			if ($topic['is_sticky'])
+				$color_class = 'stickybg';
+			if ($topic['is_locked'])
+				$color_class .= 'lockedbg';
+
+			echo '
+			<div class="search_results_posts">
+			<div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
+				<div class="content flow_auto">';
+
+			foreach ($topic['matches'] as $message)
+			{
+				echo '
+					<div class="topic_details floatleft" style="width: 94%">
+						<div class="counter">', $message['counter'], '</div>
+						<h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.msg', $message['id'], '#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
+						<span class="smalltext">&#171;&nbsp;',$txt['by'],'&nbsp;<strong>', $message['member']['link'], '</strong>&nbsp;',$txt['on'],'&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
+					</div>';
+
+				if (!empty($options['display_quick_mod']))
+				{
+					echo '
+					<div class="floatright">';
+
+					if ($options['display_quick_mod'] == 1)
+					{
+						echo '
+						<input type="checkbox" name="topics[]" value="', $topic['id'], '" class="input_check" />';
+					}
+					else
+					{
+						if ($topic['quick_mod']['remove'])
+							echo '
+						<a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=remove;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_remove.png" width="16" alt="', $txt['remove_topic'], '" title="', $txt['remove_topic'], '" /></a>';
+
+						if ($topic['quick_mod']['lock'])
+							echo '
+						<a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=lock;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_lock.png" width="16" alt="', $txt['set_lock'], '" title="', $txt['set_lock'], '" /></a>';
+
+						if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
+							echo '
+						<br />';
+
+						if ($topic['quick_mod']['sticky'])
+							echo '
+						<a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=sticky;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_sticky.png" width="16" alt="', $txt['set_sticky'], '" title="', $txt['set_sticky'], '" /></a>';
+
+						if ($topic['quick_mod']['move'])
+							echo '
+						<a href="', $scripturl, '?action=movetopic;topic=', $topic['id'], '.0"><img src="', $settings['images_url'], '/icons/quick_move.png" width="16" alt="', $txt['move_topic'], '" title="', $txt['move_topic'], '" /></a>';
+					}
+
+					echo '
+					</div>';
+				}
+
+				if ($message['body_highlighted'] != '')
+					echo '
+					<br class="clear" />
+					<div class="list_posts double_height">', $message['body_highlighted'], '</div>';
+			}
+
+			echo '
+				</div>
+			</div>
+		</div>';
+
+		}
+		if (!empty($context['topics']))
+		echo '
+		<div class="pagesection">
+			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
+		</div>';
+
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
+		{
+			echo '
+			<div class="titlebg2" style="padding: 4px;">
+				<div class="floatright">
+					<select name="qaction"', $context['can_move'] ? ' onchange="this.form.moveItTo.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
+						<option value="">--------</option>', $context['can_remove'] ? '
+						<option value="remove">' . $txt['quick_mod_remove'] . '</option>' : '', $context['can_lock'] ? '
+						<option value="lock">' . $txt['quick_mod_lock'] . '</option>' : '', $context['can_sticky'] ? '
+						<option value="sticky">' . $txt['quick_mod_sticky'] . '</option>' : '',	$context['can_move'] ? '
+						<option value="move">' . $txt['quick_mod_move'] . ': </option>' : '', $context['can_merge'] ? '
+						<option value="merge">' . $txt['quick_mod_merge'] . '</option>' : '', '
+						<option value="markread">', $txt['quick_mod_markread'], '</option>
+					</select>';
+
+			if ($context['can_move'])
+			{
+					echo '
+					<select id="moveItTo" name="move_to" disabled="disabled">';
+
+					foreach ($context['move_to_boards'] as $category)
+					{
+						echo '
+						<optgroup label="', $category['name'], '">';
+						foreach ($category['boards'] as $board)
+								echo '
+						<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
+						echo '
+						</optgroup>';
+					}
+					echo '
+					</select>';
+			}
+
+			echo '
+					<input type="hidden" name="redirect_url" value="', $scripturl . '?action=search2;params=' . $context['params'], '" />
+					<input type="submit" style="font-size: 0.8em;" value="', $txt['quick_mod_go'], '" onclick="return this.form.qaction.value != \'\' &amp;&amp; confirm(\'', $txt['quickmod_confirm'], '\');" class="button_submit" />
+				</div>
+				<br class="clear" />
+			</div>';
+		}
+
+
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
+			echo '
+			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
+		</form>';
+
+	}
+	else
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<img class="centericon" src="' . $settings['images_url'] . '/buttons/search.png" alt="?" />&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'
+			</h3>
+		</div>
+		<div class="pagesection">
+			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
+		</div>';
+
+		if (empty($context['topics']))
+			echo '
+		<div class="information">(', $txt['search_no_results'], ')</div>';
+
+		while ($topic = $context['get_topics']())
+		{
+			foreach ($topic['matches'] as $message)
+			{
+				echo '
+			<div class="search_results_posts">
+				<div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
+					<div class="content">
+						<div class="counter">', $message['counter'], '</div>
+						<div class="topic_details">
+							<h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.', $message['start'], ';topicseen#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
+							<span class="smalltext">&#171;&nbsp;', $txt['message'], ' ', $txt['by'], ' <strong>', $message['member']['link'], ' </strong>', $txt['on'], '&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
+						</div>
+						<div class="list_posts">', $message['body_highlighted'], '</div>';
+
+				if ($topic['can_reply'] || $topic['can_mark_notify'])
+					echo '
+						<div class="quickbuttons_wrap">
+							<ul class="reset smalltext quickbuttons">';
+
+				// If they *can* reply?
+				if ($topic['can_reply'])
+					echo '
+								<li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'], '" class="reply_button">', $txt['reply'], '</a></li>';
+
+				// If they *can* quote?
+				if ($topic['can_quote'])
+					echo '
+								<li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'] . ';quote=' . $message['id'] . '" class="quote_button">', $txt['quote'], '</a></li>';
+
+				// Can we request notification of topics?
+				if ($topic['can_mark_notify'])
+					echo '
+								<li><a href="', $scripturl . '?action=notify;topic=' . $topic['id'] . '.' . $message['start'], '" class="notify_button">', $txt['notify'], '</a></li>';
+
+				if ($topic['can_reply'] || $topic['can_mark_notify'])
+					echo '
+							</ul>
+						</div>';
+				echo '
+						<br class="clear" />
+					</div>
+				</div>
+			</div>';
+			}
+		}
+
+		echo '
+		<div class="pagesection">
+			<span>', $txt['pages'], ': ', $context['page_index'], '</span>
+		</div>';
+	}
+
+	// Show a jump to box for easy navigation.
+	echo '
+		<br class="clear" />
+		<div class="smalltext righttext" id="search_jump_to">&nbsp;</div>
+		<script type="text/javascript"><!-- // --><![CDATA[
+			if (typeof(window.XMLHttpRequest) != "undefined")
+				aJumpTo[aJumpTo.length] = new JumpTo({
+					sContainerId: "search_jump_to",
+					sJumpToTemplate: "<label class=\"smalltext\" for=\"%select_id%\">', $context['jump_to']['label'], ':<" + "/label> %dropdown_list%",
+					iCurBoardId: 0,
+					iCurBoardChildLevel: 0,
+					sCurBoardName: "', $context['jump_to']['board_name'], '",
+					sBoardChildLevelIndicator: "==",
+					sBoardPrefix: "=> ",
+					sCatSeparator: "-----------------------------",
+					sCatPrefix: "",
+					sGoButtonLabel: "', $txt['quick_mod_go'], '"
+				});
+		// ]]></script>';
+
+}
+
 ?>

+ 273 - 279
Themes/default/SendTopic.template.php

@@ -1,280 +1,274 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-//------------------------------------------------------------------------------
-/*	This template contains two humble sub templates - main. Its job is pretty
-	simple: it collects the information we need to actually send the topic.
-
-	The main sub template gets shown from:
-		'?action=emailuser;sa=sendtopic;topic=##.##'
-	And should submit to:
-		'?action=emailuser;sa=sendtopic;topic=' . $context['current_topic'] . '.' . $context['start']
-	It should send the following fields:
-		y_name: sender's name.
-		y_email: sender's email.
-		comment: any additional comment.
-		r_name: receiver's name.
-		r_email: receiver's email address.
-		send: this just needs to be set, as by the submit button.
-		sc: the session id, or $context['session_id'].
-
-	The report sub template gets shown from:
-		'?action=reporttm;topic=##.##;msg=##'
-	It should submit to:
-		'?action=reporttm;topic=' . $context['current_topic'] . '.' . $context['start']
-	It only needs to send the following fields:
-		comment: an additional comment to give the moderator.
-		sc: the session id, or $context['session_id'].
-*/
-
-// This is where we get information about who they want to send the topic to, etc.
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="send_topic">
-		<form action="', $scripturl, '?action=emailuser;sa=sendtopic;topic=', $context['current_topic'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $context['page_title'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-				<div class="content">
-					<fieldset id="sender" class="send_topic">
-						<dl class="settings send_topic">
-							<dt>
-								<label for="y_name"><strong>', $txt['sendtopic_sender_name'], ':</strong></label>
-							</dt>
-							<dd>
-								<input type="text" id="y_name" name="y_name" size="30" maxlength="40" value="', $context['user']['name'], '" class="input_text" />
-							</dd>
-							<dt>
-								<label for="y_email"><strong>', $txt['sendtopic_sender_email'], ':</strong></label>
-							</dt>
-							<dd>
-								<input type="text" id="y_email" name="y_email" size="30" maxlength="50" value="', $context['user']['email'], '" class="input_text" />
-							</dd>
-							<dt>
-								<label for="comment"><strong>', $txt['sendtopic_comment'], ':</strong></label>
-							</dt>
-							<dd>
-								<input type="text" id="comment" name="comment" size="30" maxlength="100" class="input_text" />
-							</dd>
-						</dl>
-					</fieldset>
-					<fieldset id="recipient" class="send_topic">
-						<dl class="settings send_topic">
-							<dt>
-								<label for="r_name"><strong>', $txt['sendtopic_receiver_name'], ':</strong></label>
-							</dt>
-							<dd>
-								<input type="text" id="r_name" name="r_name" size="30" maxlength="40" class="input_text" />
-							</dd>
-							<dt>
-								<label for="r_email"><strong>', $txt['sendtopic_receiver_email'], ':</strong></label>
-							</dt>
-							<dd>
-								<input type="text" id="r_email" name="r_email" size="30" maxlength="50" class="input_text" />
-							</dd>
-						</dl>
-					</fieldset>
-					<div class="righttext">
-						<input type="submit" name="send" value="', $txt['sendtopic_send'], '" class="button_submit" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Send an email to a user!
-function template_custom_email()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="send_topic">
-		<form action="', $scripturl, '?action=emailuser;sa=email" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $context['page_title'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings send_mail">
-						<dt>
-							<strong>', $txt['sendtopic_receiver_name'], ':</strong>
-						</dt>
-						<dd>
-							', $context['recipient']['link'], '
-						</dd>';
-
-	// Can the user see the persons email?
-	if ($context['can_view_receipient_email'])
-		echo '
-						<dt>
-							<strong>', $txt['sendtopic_receiver_email'], ':</strong>
-						</dt>
-						<dd>
-							', $context['recipient']['email_link'], '
-						</dd>
-					</dl>
-					<hr />
-					<dl class="settings send_mail">';
-
-	// If it's a guest we need their details.
-	if ($context['user']['is_guest'])
-		echo '
-						<dt>
-							<label for="y_name"><strong>', $txt['sendtopic_sender_name'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" id="y_name" name="y_name" size="24" maxlength="40" value="', $context['user']['name'], '" class="input_text" />
-						</dd>
-						<dt>
-							<label for="y_email"><strong>', $txt['sendtopic_sender_email'], ':</strong></label><br />
-							<span class="smalltext">', $txt['send_email_disclosed'], '</span>
-						</dt>
-						<dd>
-							<input type="text" id="y_mail" name="y_email" size="24" maxlength="50" value="', $context['user']['email'], '" class="input_text" />
-						</dt>';
-	// Otherwise show the user that we know their email.
-	else
-		echo '
-						<dt>
-							<strong>', $txt['sendtopic_sender_email'], ':</strong><br />
-							<span class="smalltext">', $txt['send_email_disclosed'], '</span>
-						</dt>
-						<dd>
-							<em>', $context['user']['email'], '</em>
-						</dd>';
-
-	echo '
-						<dt>
-							<label for="email_subject"><strong>', $txt['send_email_subject'], ':</strong></label>
-						</dt>
-						<dd>
-							<input type="text" id="email_subject" name="email_subject" size="50" maxlength="100" class="input_text" />
-						</dd>
-						<dt>
-							<label for="email_body"><strong>', $txt['message'], ':</strong></label>
-						</dt>
-						<dd>
-							<textarea id="email_body" name="email_body" rows="10" cols="20" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 90%; min-width: 90%' : 'width: 90%') . ';"></textarea>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="send" value="', $txt['sendtopic_send'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	foreach ($context['form_hidden_vars'] as $key => $value)
-		echo '
-			<input type="hidden" name="', $key, '" value="', $value, '" />';
-
-	echo '
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_report()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="report_topic">
-		<form action="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="msg" value="' . $context['message_id'] . '" />
-				<div class="cat_bar">
-					<h3 class="catbg">', $txt['report_to_mod'], '</h3>
-				</div>
-				<div class="windowbg">
-					<span class="topslice"><span></span></span>
-					<div class="content">';
-
-	if (!empty($context['post_errors']))
-	{
-		echo '
-				<div class="errorbox">
-					<ul>';
-
-		foreach ($context['post_errors'] as $error)
-			echo '
-						<li class="error">', $error, '</li>';
-
-		echo '
-					</ul>
-				</div>';
-	}
-
-	echo '
-						<p>', $txt['report_to_mod_func'], '</p>
-						<br />
-						<dl class="settings" id="report_post">';
-
-	if ($context['user']['is_guest'])
-	{
-		echo '
-							<dt>
-								<label for="email_address">', $txt['email'], '</label>:
-							</dt>
-							<dd>
-								<input type="text" id="email_address" name="email" value="', $context['email_address'], '" size="25" maxlength="255" />
-							</dd>';
-	}
-
-	echo '
-							<dt>
-								<label for="report_comment">', $txt['enter_comment'], '</label>:
-							</dt>
-							<dd>
-								<input type="text" id="report_comment" name="comment" size="50" value="', $context['comment_body'], '" maxlength="255" />
-							</dd>';
-
-	if ($context['require_verification'])
-	{
-		echo '
-							<dt>
-								', $txt['verification'], ':
-							</dt>
-							<dd>
-								', template_control_verification($context['visual_verification_id'], 'all'), '
-							</dd>';
-	}
-
-	echo '
-						</dl>
-						<div class="righttext">
-							<input type="submit" name="save" value="', $txt['rtm10'], '" style="margin-left: 1ex;" class="button_submit" />
-						</div>
-					</div>
-					<br class="clear" />
-					<span class="botslice"><span></span></span>
-				</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+//------------------------------------------------------------------------------
+/*	This template contains two humble sub templates - main. Its job is pretty
+	simple: it collects the information we need to actually send the topic.
+
+	The main sub template gets shown from:
+		'?action=emailuser;sa=sendtopic;topic=##.##'
+	And should submit to:
+		'?action=emailuser;sa=sendtopic;topic=' . $context['current_topic'] . '.' . $context['start']
+	It should send the following fields:
+		y_name: sender's name.
+		y_email: sender's email.
+		comment: any additional comment.
+		r_name: receiver's name.
+		r_email: receiver's email address.
+		send: this just needs to be set, as by the submit button.
+		sc: the session id, or $context['session_id'].
+
+	The report sub template gets shown from:
+		'?action=reporttm;topic=##.##;msg=##'
+	It should submit to:
+		'?action=reporttm;topic=' . $context['current_topic'] . '.' . $context['start']
+	It only needs to send the following fields:
+		comment: an additional comment to give the moderator.
+		sc: the session id, or $context['session_id'].
+*/
+
+// This is where we get information about who they want to send the topic to, etc.
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="send_topic">
+		<form action="', $scripturl, '?action=emailuser;sa=sendtopic;topic=', $context['current_topic'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $context['page_title'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<fieldset id="sender" class="send_topic">
+						<dl class="settings send_topic">
+							<dt>
+								<label for="y_name"><strong>', $txt['sendtopic_sender_name'], ':</strong></label>
+							</dt>
+							<dd>
+								<input type="text" id="y_name" name="y_name" size="30" maxlength="40" value="', $context['user']['name'], '" class="input_text" />
+							</dd>
+							<dt>
+								<label for="y_email"><strong>', $txt['sendtopic_sender_email'], ':</strong></label>
+							</dt>
+							<dd>
+								<input type="text" id="y_email" name="y_email" size="30" maxlength="50" value="', $context['user']['email'], '" class="input_text" />
+							</dd>
+							<dt>
+								<label for="comment"><strong>', $txt['sendtopic_comment'], ':</strong></label>
+							</dt>
+							<dd>
+								<input type="text" id="comment" name="comment" size="30" maxlength="100" class="input_text" />
+							</dd>
+						</dl>
+					</fieldset>
+					<fieldset id="recipient" class="send_topic">
+						<dl class="settings send_topic">
+							<dt>
+								<label for="r_name"><strong>', $txt['sendtopic_receiver_name'], ':</strong></label>
+							</dt>
+							<dd>
+								<input type="text" id="r_name" name="r_name" size="30" maxlength="40" class="input_text" />
+							</dd>
+							<dt>
+								<label for="r_email"><strong>', $txt['sendtopic_receiver_email'], ':</strong></label>
+							</dt>
+							<dd>
+								<input type="text" id="r_email" name="r_email" size="30" maxlength="50" class="input_text" />
+							</dd>
+						</dl>
+					</fieldset>
+					<div class="righttext">
+						<input type="submit" name="send" value="', $txt['sendtopic_send'], '" class="button_submit" />
+					</div>
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Send an email to a user!
+function template_custom_email()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="send_topic">
+		<form action="', $scripturl, '?action=emailuser;sa=email" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/email_sm.png" alt="" class="icon" />', $context['page_title'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings send_mail">
+						<dt>
+							<strong>', $txt['sendtopic_receiver_name'], ':</strong>
+						</dt>
+						<dd>
+							', $context['recipient']['link'], '
+						</dd>';
+
+	// Can the user see the persons email?
+	if ($context['can_view_receipient_email'])
+		echo '
+						<dt>
+							<strong>', $txt['sendtopic_receiver_email'], ':</strong>
+						</dt>
+						<dd>
+							', $context['recipient']['email_link'], '
+						</dd>
+					</dl>
+					<hr />
+					<dl class="settings send_mail">';
+
+	// If it's a guest we need their details.
+	if ($context['user']['is_guest'])
+		echo '
+						<dt>
+							<label for="y_name"><strong>', $txt['sendtopic_sender_name'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" id="y_name" name="y_name" size="24" maxlength="40" value="', $context['user']['name'], '" class="input_text" />
+						</dd>
+						<dt>
+							<label for="y_email"><strong>', $txt['sendtopic_sender_email'], ':</strong></label><br />
+							<span class="smalltext">', $txt['send_email_disclosed'], '</span>
+						</dt>
+						<dd>
+							<input type="text" id="y_mail" name="y_email" size="24" maxlength="50" value="', $context['user']['email'], '" class="input_text" />
+						</dt>';
+	// Otherwise show the user that we know their email.
+	else
+		echo '
+						<dt>
+							<strong>', $txt['sendtopic_sender_email'], ':</strong><br />
+							<span class="smalltext">', $txt['send_email_disclosed'], '</span>
+						</dt>
+						<dd>
+							<em>', $context['user']['email'], '</em>
+						</dd>';
+
+	echo '
+						<dt>
+							<label for="email_subject"><strong>', $txt['send_email_subject'], ':</strong></label>
+						</dt>
+						<dd>
+							<input type="text" id="email_subject" name="email_subject" size="50" maxlength="100" class="input_text" />
+						</dd>
+						<dt>
+							<label for="email_body"><strong>', $txt['message'], ':</strong></label>
+						</dt>
+						<dd>
+							<textarea id="email_body" name="email_body" rows="10" cols="20" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 90%; min-width: 90%' : 'width: 90%') . ';"></textarea>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="send" value="', $txt['sendtopic_send'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>';
+
+	foreach ($context['form_hidden_vars'] as $key => $value)
+		echo '
+			<input type="hidden" name="', $key, '" value="', $value, '" />';
+
+	echo '
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_report()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="report_topic">
+		<form action="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="msg" value="' . $context['message_id'] . '" />
+				<div class="cat_bar">
+					<h3 class="catbg">', $txt['report_to_mod'], '</h3>
+				</div>
+				<div class="windowbg">
+					<div class="content">';
+
+	if (!empty($context['post_errors']))
+	{
+		echo '
+				<div class="errorbox">
+					<ul>';
+
+		foreach ($context['post_errors'] as $error)
+			echo '
+						<li class="error">', $error, '</li>';
+
+		echo '
+					</ul>
+				</div>';
+	}
+
+	echo '
+						<p>', $txt['report_to_mod_func'], '</p>
+						<br />
+						<dl class="settings" id="report_post">';
+
+	if ($context['user']['is_guest'])
+	{
+		echo '
+							<dt>
+								<label for="email_address">', $txt['email'], '</label>:
+							</dt>
+							<dd>
+								<input type="text" id="email_address" name="email" value="', $context['email_address'], '" size="25" maxlength="255" />
+							</dd>';
+	}
+
+	echo '
+							<dt>
+								<label for="report_comment">', $txt['enter_comment'], '</label>:
+							</dt>
+							<dd>
+								<input type="text" id="report_comment" name="comment" size="50" value="', $context['comment_body'], '" maxlength="255" />
+							</dd>';
+
+	if ($context['require_verification'])
+	{
+		echo '
+							<dt>
+								', $txt['verification'], ':
+							</dt>
+							<dd>
+								', template_control_verification($context['visual_verification_id'], 'all'), '
+							</dd>';
+	}
+
+	echo '
+						</dl>
+						<div class="righttext">
+							<input type="submit" name="save" value="', $txt['rtm10'], '" style="margin-left: 1ex;" class="button_submit" />
+						</div>
+					</div>
+					<br class="clear" />
+				</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>';
+}
+
 ?>

+ 457 - 473
Themes/default/SplitTopics.template.php

@@ -1,474 +1,458 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-function template_ask()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="split_topics">
-		<form action="', $scripturl, '?action=splittopics;sa=execute;topic=', $context['current_topic'], '.0" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="at" value="', $context['message']['id'], '" />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['split'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p class="split_topics">
-						<strong><label for="subname">', $txt['subject_new_topic'], '</label>:</strong>
-						<input type="text" name="subname" id="subname" value="', $context['message']['subject'], '" size="25" class="input_text" />
-					</p>
-					<ul class="reset split_topics">
-						<li>
-							<input type="radio" id="onlythis" name="step2" value="onlythis" checked="checked" class="input_radio" /> <label for="onlythis">', $txt['split_this_post'], '</label>
-						</li>
-						<li>
-							<input type="radio" id="afterthis" name="step2" value="afterthis" class="input_radio" /> <label for="afterthis">', $txt['split_after_and_this_post'], '</label>
-						</li>
-						<li>
-							<input type="radio" id="selective" name="step2" value="selective" class="input_radio" /> <label for="selective">', $txt['select_split_posts'], '</label>
-						</li>
-					</ul>
-					<hr class="hrcolor" />
-					<input type="submit" value="', $txt['split'], '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			</div>
-		</form>
-	</div>';
-}
-
-function template_main()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="split_topics">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['split'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $txt['split_successful'], '</p>
-				<ul class="reset">
-					<li>
-						<a href="', $scripturl, '?board=', $context['current_board'], '.0">', $txt['message_index'], '</a>
-					</li>
-					<li>
-						<a href="', $scripturl, '?topic=', $context['old_topic'], '.0">', $txt['origin_topic'], '</a>
-					</li>
-					<li>
-						<a href="', $scripturl, '?topic=', $context['new_topic'], '.0">', $txt['new_topic'], '</a>
-					</li>
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>';
-}
-
-function template_select()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="split_topics">
-		<form action="', $scripturl, '?action=splittopics;sa=splitSelection;board=', $context['current_board'], '.0" method="post" accept-charset="', $context['character_set'], '">
-			<div id="not_selected" class="floatleft">
-				<div class="cat_bar">
-					<h3 class="catbg">', $txt['split'], ' - ', $txt['select_split_posts'], '</h3>
-				</div>
-				<div class="information">
-					', $txt['please_select_split'], '
-				</div>
-				<div class="pagesection">
-					<strong>', $txt['pages'], ':</strong> <span id="pageindex_not_selected">', $context['not_selected']['page_index'], '</span>
-				</div>
-				<ul id="messages_not_selected" class="split_messages smalltext reset">';
-
-	foreach ($context['not_selected']['messages'] as $message)
-		echo '
-					<li class="windowbg', $message['alternate'] ? '2' : '', '" id="not_selected_', $message['id'], '">
-						<span class="topslice"><span></span></span>
-						<div class="content">
-							<div class="message_header">
-								<a class="split_icon floatright" href="', $scripturl, '?action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=down;msg=', $message['id'], '" onclick="return select(\'down\', ', $message['id'], ');"><img src="', $settings['images_url'], '/split_select.png" alt="-&gt;" /></a>
-								<strong>', $message['subject'], '</strong> ', $txt['by'], ' <strong>', $message['poster'], '</strong><br />
-								<em>', $message['time'], '</em>
-							</div>
-							<div class="post">', $message['body'], '</div>
-						</div>
-						<span class="botslice"><span></span></span>
-					</li>';
-
-	echo '
-					<li class="dummy" />
-				</ul>
-			</div>
-			<div id="selected" class="floatright">
-				<div class="cat_bar">
-					<h3 class="catbg">
-						', $txt['split_selected_posts'], ' (<a href="', $scripturl, '?action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=reset;msg=0" onclick="return select(\'reset\', 0);">', $txt['split_reset_selection'], '</a>)
-					</h3>
-				</div>
-				<div class="information">
-					', $txt['split_selected_posts_desc'], '
-				</div>
-				<div class="pagesection">
-					<strong>', $txt['pages'], ':</strong> <span id="pageindex_selected">', $context['selected']['page_index'], '</span>
-				</div>
-				<ul id="messages_selected" class="split_messages smalltext reset">';
-
-	if (!empty($context['selected']['messages']))
-		foreach ($context['selected']['messages'] as $message)
-			echo '
-					<li class="windowbg', $message['alternate'] ? '2' : '', '" id="selected_', $message['id'], '">
-						<span class="topslice"><span></span></span>
-						<div class="content">
-							<div class="message_header">
-								<a class="split_icon floatleft" href="', $scripturl, '?action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=up;msg=', $message['id'], '" onclick="return select(\'up\', ', $message['id'], ');"><img src="', $settings['images_url'], '/split_deselect.png" alt="&lt;-" /></a>
-								<strong>', $message['subject'], '</strong> ', $txt['by'], ' <strong>', $message['poster'], '</strong><br />
-								<em>', $message['time'], '</em>
-							</div>
-							<div class="post">', $message['body'], '</div>
-						</div>
-						<span class="botslice"><span></span></span>
-					</li>';
-
-	echo '
-					<li class="dummy" />
-				</ul>
-			</div>
-			<br class="clear" />
-			<p>
-				<input type="hidden" name="topic" value="', $context['current_topic'], '" />
-				<input type="hidden" name="subname" value="', $context['new_subject'], '" />
-				<input type="submit" value="', $txt['split'], '" class="button_submit" />
-				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			</p>
-		</form>
-	</div>
-	<br class="clear" />
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var start = new Array();
-			start[0] = ', $context['not_selected']['start'], ';
-			start[1] = ', $context['selected']['start'], ';
-
-			function select(direction, msg_id)
-			{
-				if (window.XMLHttpRequest)
-				{
-					getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '." + start[0] + ";start2=" + start[1] + ";move=" + direction + ";msg=" + msg_id + ";xml", onDocReceived);
-					return false;
-				}
-				else
-					return true;
-			}
-			function onDocReceived(XMLDoc)
-			{
-				var i, j, pageIndex;
-				for (i = 0; i < 2; i++)
-				{
-					pageIndex = XMLDoc.getElementsByTagName("pageIndex")[i];
-					setInnerHTML(document.getElementById("pageindex_" + pageIndex.getAttribute("section")), pageIndex.firstChild.nodeValue);
-					start[i] = pageIndex.getAttribute("startFrom");
-				}
-				var numChanges = XMLDoc.getElementsByTagName("change").length;
-				var curChange, curSection, curAction, curId, curList, curData, newItem, sInsertBeforeId;
-				for (i = 0; i < numChanges; i++)
-				{
-					curChange = XMLDoc.getElementsByTagName("change")[i];
-					curSection = curChange.getAttribute("section");
-					curAction = curChange.getAttribute("curAction");
-					curId = curChange.getAttribute("id");
-					curList = document.getElementById("messages_" + curSection);
-					if (curAction == "remove")
-						curList.removeChild(document.getElementById(curSection + "_" + curId));
-					// Insert a message.
-					else
-					{
-						// By default, insert the element at the end of the list.
-						sInsertBeforeId = null;
-						// Loop through the list to try and find an item to insert after.
-						oListItems = curList.getElementsByTagName("LI");
-						for (j = 0; j < oListItems.length; j++)
-						{
-							if (parseInt(oListItems[j].id.substr(curSection.length + 1)) < curId)
-							{
-								// This would be a nice place to insert the row.
-								sInsertBeforeId = oListItems[j].id;
-								// We\'re done for now. Escape the loop.
-								j = oListItems.length + 1;
-							}
-						}
-
-						// Let\'s create a nice container for the message.
-						newItem = document.createElement("LI");
-						newItem.className = "windowbg2";
-						newItem.id = curSection + "_" + curId;
-						newItem.innerHTML = "<span class=\\"topslice\\"><span></span></span><div class=\\"content\\"><div class=\\"message_header\\"><a class=\\"split_icon float" + (curSection == "selected" ? "left" : "right") + "\\" href=\\"" + smf_prepareScriptUrl(smf_scripturl) + "action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=" + (curSection == "selected" ? "up" : "down") + ";msg=" + curId + "\\" onclick=\\"return select(\'" + (curSection == "selected" ? "up" : "down") + "\', " + curId + ");\\"><img src=\\"', $settings['images_url'], '/split_" + (curSection == "selected" ? "de" : "") + "select.png\\" alt=\\"" + (curSection == "selected" ? "&lt;-" : "-&gt;") + "\\" /></a><strong>" + curChange.getElementsByTagName("subject")[0].firstChild.nodeValue + "</strong> ', $txt['by'], ' <strong>" + curChange.getElementsByTagName("poster")[0].firstChild.nodeValue + "</strong><br /><em>" + curChange.getElementsByTagName("time")[0].firstChild.nodeValue + "</em></div><div class=\\"post\\">" + curChange.getElementsByTagName("body")[0].firstChild.nodeValue + "</div></div><span class=\\"botslice\\"><span></span></span>";
-
-						// So, where do we insert it?
-						if (typeof sInsertBeforeId == "string")
-							curList.insertBefore(newItem, document.getElementById(sInsertBeforeId));
-						else
-							curList.appendChild(newItem);
-					}
-				}
-				// After all changes, make sure the window backgrounds are still correct for both lists.
-				applyWindowClasses(document.getElementById("messages_selected"));
-				applyWindowClasses(document.getElementById("messages_not_selected"));
-			}
-		// ]]></script>';
-}
-
-function template_merge_done()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<div id="merge_topics">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['merge'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p>', $txt['merge_successful'], '</p>
-					<br />
-					<ul class="reset">
-						<li>
-							<a href="', $scripturl, '?board=', $context['target_board'], '.0">', $txt['message_index'], '</a>
-						</li>
-						<li>
-							<a href="', $scripturl, '?topic=', $context['target_topic'], '.0">', $txt['new_merged_topic'], '</a>
-						</li>
-					</ul>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</div>
-	<br class="clear" />';
-}
-
-function template_merge()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-		<div id="merge_topics">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['merge'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['merge_desc'], '
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings merge_topic">
-						<dt>
-							<strong>', $txt['topic_to_merge'], ':</strong>
-						</dt>
-						<dd>
-							', $context['origin_subject'], '
-						</dd>';
-
-	if (!empty($context['boards']) && count($context['boards']) > 1)
-	{
-			echo '
-						<dt>
-							<strong>', $txt['target_board'], ':</strong>
-						</dt>
-						<dd>
-							<form action="' . $scripturl . '?action=mergetopics;from=' . $context['origin_topic'] . ';targetboard=' . $context['target_board'] . ';board=' . $context['current_board'] . '.0" method="post" accept-charset="', $context['character_set'], '">
-								<input type="hidden" name="from" value="' . $context['origin_topic'] . '" />
-								<select name="targetboard" onchange="this.form.submit();">';
-			foreach ($context['boards'] as $board)
-				echo '
-									<option value="', $board['id'], '"', $board['id'] == $context['target_board'] ? ' selected="selected"' : '', '>', $board['category'], ' - ', $board['name'], '</option>';
-			echo '
-								</select>
-								<input type="submit" value="', $txt['go'], '" class="button_submit" />
-							</form>
-						</dd>';
-	}
-
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<dl class="settings merge_topic">
-						<dt>
-							<strong>', $txt['merge_to_topic_id'], ': </strong>
-						</dt>
-						<dd>
-							<form action="', $scripturl , '?action=mergetopics;sa=options" method="post" accept-charset="', $context['character_set'], '">
-								<input type="hidden" name="topics[]" value="', $context['origin_topic'], '" />
-								<input type="text" name="topics[]" class="input_text" />
-								<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-								<input type="submit" value="', $txt['merge'], '" class="button_submit" />
-							</form>
-						</dd>';
-
-		echo '
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div><br />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['target_topic'], '</h3>
-			</div>
-			<div class="pagesection">
-				<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<ul class="reset merge_topics">';
-
-		$merge_button = create_button('merge.png', 'merge', '');
-
-		foreach ($context['topics'] as $topic)
-			echo '
-						<li>
-							<a href="', $scripturl, '?action=mergetopics;sa=options;board=', $context['current_board'], '.0;from=', $context['origin_topic'], ';to=', $topic['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $merge_button, '</a>&nbsp;
-							<a href="', $scripturl, '?topic=', $topic['id'], '.0" target="_blank" class="new_win">', $topic['subject'], '</a> ', $txt['started_by'], ' ', $topic['poster']['link'], '
-						</li>';
-
-		echo '
-					</ul>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<div class="pagesection">
-				<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
-			</div>
-		</div>
-	<br class="clear" />';
-}
-
-function template_merge_extra_options()
-{
-	global $context, $settings, $options, $txt, $scripturl;
-
-	echo '
-	<div id="merge_topics">
-		<form action="', $scripturl, '?action=mergetopics;sa=execute;" method="post" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">', $txt['merge_topic_list'], '</h3>
-			</div>
-			<table width="100%" class="bordercolor table_grid">
-				<thead>
-					<tr class="catbg">
-						<th scope="col" class="first_th" align="center" width="10px">', $txt['merge_check'], '</th>
-						<th scope="col" class="lefttext">', $txt['subject'], '</th>
-						<th scope="col" class="lefttext">', $txt['started_by'], '</th>
-						<th scope="col" class="lefttext">', $txt['last_post'], '</th>
-						<th scope="col" class="last_th" width="20px">' . $txt['merge_include_notifications'] . '</th>
-					</tr>
-				</thead>
-				<tbody>';
-		foreach ($context['topics'] as $topic)
-			echo '
-					<tr class="windowbg2">
-						<td align="center">
-							<input type="checkbox" class="input_check" name="topics[]" value="' . $topic['id'] . '" checked="checked" />
-						</td>
-						<td>
-							<a href="' . $scripturl . '?topic=' . $topic['id'] . '.0" target="_blank" class="new_win">' . $topic['subject'] . '</a>
-						</td>
-						<td>
-							', $topic['started']['link'], '<br />
-							<span class="smalltext">', $topic['started']['time'], '</span>
-						</td>
-						<td>
-							' . $topic['updated']['link'] . '<br />
-							<span class="smalltext">', $topic['updated']['time'], '</span>
-						</td>
-						<td align="center">
-							<input type="checkbox" class="input_check" name="notifications[]" value="' . $topic['id'] . '" checked="checked" />
-						</td>
-					</tr>';
-		echo '
-				</tbody>
-			</table>
-			<br />
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	echo '
-					<fieldset id="merge_subject" class="merge_options">
-						<legend>', $txt['merge_select_subject'], '</legend>
-						<select name="subject" onchange="this.form.custom_subject.style.display = (this.options[this.selectedIndex].value != 0) ? \'none\': \'\' ;">';
-	foreach ($context['topics'] as $topic)
-		echo '
-							<option value="', $topic['id'], '"' . ($topic['selected'] ? ' selected="selected"' : '') . '>', $topic['subject'], '</option>';
-	echo '
-							<option value="0">', $txt['merge_custom_subject'], ':</option>
-						</select>
-						<br /><input type="text" name="custom_subject" size="60" id="custom_subject" class="input_text custom_subject" style="display: none;" />
-						<br />
-						<label for="enforce_subject"><input type="checkbox" class="input_check" name="enforce_subject" id="enforce_subject" value="1" /> ', $txt['merge_enforce_subject'], '</label>
-					</fieldset>';
-
-	if (!empty($context['boards']) && count($context['boards']) > 1)
-	{
-		echo '
-					<fieldset id="merge_board" class="merge_options">
-						<legend>', $txt['merge_select_target_board'], '</legend>
-						<ul class="reset">';
-		foreach ($context['boards'] as $board)
-			echo '
-							<li>
-								<input type="radio" name="board" value="' . $board['id'] . '"' . ($board['selected'] ? ' checked="checked"' : '') . ' class="input_radio" /> ' . $board['name'] . '
-							</li>';
-		echo '
-						</ul>
-					</fieldset>';
-	}
-	if (!empty($context['polls']))
-	{
-		echo '
-					<fieldset id="merge_poll" class="merge_options">
-						<legend>' . $txt['merge_select_poll'] . '</legend>
-						<ul class="reset">';
-		foreach ($context['polls'] as $poll)
-			echo '
-							<li>
-								<input type="radio" name="poll" value="' . $poll['id'] . '"' . ($poll['selected'] ? ' checked="checked"' : '') . ' class="input_radio" /> ' . $poll['question'] . ' (' . $txt['topic'] . ': <a href="' . $scripturl . '?topic=' . $poll['topic']['id'] . '.0" target="_blank" class="new_win">' . $poll['topic']['subject'] . '</a>)
-							</li>';
-		echo '
-							<li>
-								<input type="radio" name="poll" value="-1" class="input_radio" /> (' . $txt['merge_no_poll'] . ')
-							</li>
-						</ul>
-					</fieldset>';
-	}
-	echo '
-					<input type="submit" value="' . $txt['merge'] . '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="sa" value="execute" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+function template_ask()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="split_topics">
+		<form action="', $scripturl, '?action=splittopics;sa=execute;topic=', $context['current_topic'], '.0" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="at" value="', $context['message']['id'], '" />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['split'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p class="split_topics">
+						<strong><label for="subname">', $txt['subject_new_topic'], '</label>:</strong>
+						<input type="text" name="subname" id="subname" value="', $context['message']['subject'], '" size="25" class="input_text" />
+					</p>
+					<ul class="reset split_topics">
+						<li>
+							<input type="radio" id="onlythis" name="step2" value="onlythis" checked="checked" class="input_radio" /> <label for="onlythis">', $txt['split_this_post'], '</label>
+						</li>
+						<li>
+							<input type="radio" id="afterthis" name="step2" value="afterthis" class="input_radio" /> <label for="afterthis">', $txt['split_after_and_this_post'], '</label>
+						</li>
+						<li>
+							<input type="radio" id="selective" name="step2" value="selective" class="input_radio" /> <label for="selective">', $txt['select_split_posts'], '</label>
+						</li>
+					</ul>
+					<hr class="hrcolor" />
+					<input type="submit" value="', $txt['split'], '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			</div>
+		</form>
+	</div>';
+}
+
+function template_main()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="split_topics">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['split'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>', $txt['split_successful'], '</p>
+				<ul class="reset">
+					<li>
+						<a href="', $scripturl, '?board=', $context['current_board'], '.0">', $txt['message_index'], '</a>
+					</li>
+					<li>
+						<a href="', $scripturl, '?topic=', $context['old_topic'], '.0">', $txt['origin_topic'], '</a>
+					</li>
+					<li>
+						<a href="', $scripturl, '?topic=', $context['new_topic'], '.0">', $txt['new_topic'], '</a>
+					</li>
+				</ul>
+			</div>
+		</div>
+	</div>';
+}
+
+function template_select()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="split_topics">
+		<form action="', $scripturl, '?action=splittopics;sa=splitSelection;board=', $context['current_board'], '.0" method="post" accept-charset="', $context['character_set'], '">
+			<div id="not_selected" class="floatleft">
+				<div class="cat_bar">
+					<h3 class="catbg">', $txt['split'], ' - ', $txt['select_split_posts'], '</h3>
+				</div>
+				<div class="information">
+					', $txt['please_select_split'], '
+				</div>
+				<div class="pagesection">
+					<strong>', $txt['pages'], ':</strong> <span id="pageindex_not_selected">', $context['not_selected']['page_index'], '</span>
+				</div>
+				<ul id="messages_not_selected" class="split_messages smalltext reset">';
+
+	foreach ($context['not_selected']['messages'] as $message)
+		echo '
+					<li class="windowbg', $message['alternate'] ? '2' : '', '" id="not_selected_', $message['id'], '">
+						<div class="content">
+							<div class="message_header">
+								<a class="split_icon floatright" href="', $scripturl, '?action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=down;msg=', $message['id'], '" onclick="return select(\'down\', ', $message['id'], ');"><img src="', $settings['images_url'], '/split_select.png" alt="-&gt;" /></a>
+								<strong>', $message['subject'], '</strong> ', $txt['by'], ' <strong>', $message['poster'], '</strong><br />
+								<em>', $message['time'], '</em>
+							</div>
+							<div class="post">', $message['body'], '</div>
+						</div>
+					</li>';
+
+	echo '
+					<li class="dummy" />
+				</ul>
+			</div>
+			<div id="selected" class="floatright">
+				<div class="cat_bar">
+					<h3 class="catbg">
+						', $txt['split_selected_posts'], ' (<a href="', $scripturl, '?action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=reset;msg=0" onclick="return select(\'reset\', 0);">', $txt['split_reset_selection'], '</a>)
+					</h3>
+				</div>
+				<div class="information">
+					', $txt['split_selected_posts_desc'], '
+				</div>
+				<div class="pagesection">
+					<strong>', $txt['pages'], ':</strong> <span id="pageindex_selected">', $context['selected']['page_index'], '</span>
+				</div>
+				<ul id="messages_selected" class="split_messages smalltext reset">';
+
+	if (!empty($context['selected']['messages']))
+		foreach ($context['selected']['messages'] as $message)
+			echo '
+					<li class="windowbg', $message['alternate'] ? '2' : '', '" id="selected_', $message['id'], '">
+						<div class="content">
+							<div class="message_header">
+								<a class="split_icon floatleft" href="', $scripturl, '?action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=up;msg=', $message['id'], '" onclick="return select(\'up\', ', $message['id'], ');"><img src="', $settings['images_url'], '/split_deselect.png" alt="&lt;-" /></a>
+								<strong>', $message['subject'], '</strong> ', $txt['by'], ' <strong>', $message['poster'], '</strong><br />
+								<em>', $message['time'], '</em>
+							</div>
+							<div class="post">', $message['body'], '</div>
+						</div>
+					</li>';
+
+	echo '
+					<li class="dummy" />
+				</ul>
+			</div>
+			<br class="clear" />
+			<p>
+				<input type="hidden" name="topic" value="', $context['current_topic'], '" />
+				<input type="hidden" name="subname" value="', $context['new_subject'], '" />
+				<input type="submit" value="', $txt['split'], '" class="button_submit" />
+				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			</p>
+		</form>
+	</div>
+	<br class="clear" />
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var start = new Array();
+			start[0] = ', $context['not_selected']['start'], ';
+			start[1] = ', $context['selected']['start'], ';
+
+			function select(direction, msg_id)
+			{
+				if (window.XMLHttpRequest)
+				{
+					getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '." + start[0] + ";start2=" + start[1] + ";move=" + direction + ";msg=" + msg_id + ";xml", onDocReceived);
+					return false;
+				}
+				else
+					return true;
+			}
+			function onDocReceived(XMLDoc)
+			{
+				var i, j, pageIndex;
+				for (i = 0; i < 2; i++)
+				{
+					pageIndex = XMLDoc.getElementsByTagName("pageIndex")[i];
+					setInnerHTML(document.getElementById("pageindex_" + pageIndex.getAttribute("section")), pageIndex.firstChild.nodeValue);
+					start[i] = pageIndex.getAttribute("startFrom");
+				}
+				var numChanges = XMLDoc.getElementsByTagName("change").length;
+				var curChange, curSection, curAction, curId, curList, curData, newItem, sInsertBeforeId;
+				for (i = 0; i < numChanges; i++)
+				{
+					curChange = XMLDoc.getElementsByTagName("change")[i];
+					curSection = curChange.getAttribute("section");
+					curAction = curChange.getAttribute("curAction");
+					curId = curChange.getAttribute("id");
+					curList = document.getElementById("messages_" + curSection);
+					if (curAction == "remove")
+						curList.removeChild(document.getElementById(curSection + "_" + curId));
+					// Insert a message.
+					else
+					{
+						// By default, insert the element at the end of the list.
+						sInsertBeforeId = null;
+						// Loop through the list to try and find an item to insert after.
+						oListItems = curList.getElementsByTagName("LI");
+						for (j = 0; j < oListItems.length; j++)
+						{
+							if (parseInt(oListItems[j].id.substr(curSection.length + 1)) < curId)
+							{
+								// This would be a nice place to insert the row.
+								sInsertBeforeId = oListItems[j].id;
+								// We\'re done for now. Escape the loop.
+								j = oListItems.length + 1;
+							}
+						}
+
+						// Let\'s create a nice container for the message.
+						newItem = document.createElement("LI");
+						newItem.className = "windowbg2";
+						newItem.id = curSection + "_" + curId;
+						newItem.innerHTML = "<div class=\\"content\\"><div class=\\"message_header\\"><a class=\\"split_icon float" + (curSection == "selected" ? "left" : "right") + "\\" href=\\"" + smf_prepareScriptUrl(smf_scripturl) + "action=splittopics;sa=selectTopics;subname=', $context['topic']['subject'], ';topic=', $context['topic']['id'], '.', $context['not_selected']['start'], ';start2=', $context['selected']['start'], ';move=" + (curSection == "selected" ? "up" : "down") + ";msg=" + curId + "\\" onclick=\\"return select(\'" + (curSection == "selected" ? "up" : "down") + "\', " + curId + ");\\"><img src=\\"', $settings['images_url'], '/split_" + (curSection == "selected" ? "de" : "") + "select.png\\" alt=\\"" + (curSection == "selected" ? "&lt;-" : "-&gt;") + "\\" /></a><strong>" + curChange.getElementsByTagName("subject")[0].firstChild.nodeValue + "</strong> ', $txt['by'], ' <strong>" + curChange.getElementsByTagName("poster")[0].firstChild.nodeValue + "</strong><br /><em>" + curChange.getElementsByTagName("time")[0].firstChild.nodeValue + "</em></div><div class=\\"post\\">" + curChange.getElementsByTagName("body")[0].firstChild.nodeValue + "</div></div>";
+
+						// So, where do we insert it?
+						if (typeof sInsertBeforeId == "string")
+							curList.insertBefore(newItem, document.getElementById(sInsertBeforeId));
+						else
+							curList.appendChild(newItem);
+					}
+				}
+				// After all changes, make sure the window backgrounds are still correct for both lists.
+				applyWindowClasses(document.getElementById("messages_selected"));
+				applyWindowClasses(document.getElementById("messages_not_selected"));
+			}
+		// ]]></script>';
+}
+
+function template_merge_done()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<div id="merge_topics">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['merge'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<p>', $txt['merge_successful'], '</p>
+					<br />
+					<ul class="reset">
+						<li>
+							<a href="', $scripturl, '?board=', $context['target_board'], '.0">', $txt['message_index'], '</a>
+						</li>
+						<li>
+							<a href="', $scripturl, '?topic=', $context['target_topic'], '.0">', $txt['new_merged_topic'], '</a>
+						</li>
+					</ul>
+				</div>
+			</div>
+		</div>
+	<br class="clear" />';
+}
+
+function template_merge()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+		<div id="merge_topics">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['merge'], '</h3>
+			</div>
+			<div class="information">
+				', $txt['merge_desc'], '
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings merge_topic">
+						<dt>
+							<strong>', $txt['topic_to_merge'], ':</strong>
+						</dt>
+						<dd>
+							', $context['origin_subject'], '
+						</dd>';
+
+	if (!empty($context['boards']) && count($context['boards']) > 1)
+	{
+			echo '
+						<dt>
+							<strong>', $txt['target_board'], ':</strong>
+						</dt>
+						<dd>
+							<form action="' . $scripturl . '?action=mergetopics;from=' . $context['origin_topic'] . ';targetboard=' . $context['target_board'] . ';board=' . $context['current_board'] . '.0" method="post" accept-charset="', $context['character_set'], '">
+								<input type="hidden" name="from" value="' . $context['origin_topic'] . '" />
+								<select name="targetboard" onchange="this.form.submit();">';
+			foreach ($context['boards'] as $board)
+				echo '
+									<option value="', $board['id'], '"', $board['id'] == $context['target_board'] ? ' selected="selected"' : '', '>', $board['category'], ' - ', $board['name'], '</option>';
+			echo '
+								</select>
+								<input type="submit" value="', $txt['go'], '" class="button_submit" />
+							</form>
+						</dd>';
+	}
+
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<dl class="settings merge_topic">
+						<dt>
+							<strong>', $txt['merge_to_topic_id'], ': </strong>
+						</dt>
+						<dd>
+							<form action="', $scripturl , '?action=mergetopics;sa=options" method="post" accept-charset="', $context['character_set'], '">
+								<input type="hidden" name="topics[]" value="', $context['origin_topic'], '" />
+								<input type="text" name="topics[]" class="input_text" />
+								<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+								<input type="submit" value="', $txt['merge'], '" class="button_submit" />
+							</form>
+						</dd>';
+
+		echo '
+					</dl>
+				</div>
+			</div><br />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['target_topic'], '</h3>
+			</div>
+			<div class="pagesection">
+				<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<ul class="reset merge_topics">';
+
+		$merge_button = create_button('merge.png', 'merge', '');
+
+		foreach ($context['topics'] as $topic)
+			echo '
+						<li>
+							<a href="', $scripturl, '?action=mergetopics;sa=options;board=', $context['current_board'], '.0;from=', $context['origin_topic'], ';to=', $topic['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $merge_button, '</a>&nbsp;
+							<a href="', $scripturl, '?topic=', $topic['id'], '.0" target="_blank" class="new_win">', $topic['subject'], '</a> ', $txt['started_by'], ' ', $topic['poster']['link'], '
+						</li>';
+
+		echo '
+					</ul>
+				</div>
+			</div>
+			<div class="pagesection">
+				<strong>', $txt['pages'], ':</strong> ', $context['page_index'], '
+			</div>
+		</div>
+	<br class="clear" />';
+}
+
+function template_merge_extra_options()
+{
+	global $context, $settings, $options, $txt, $scripturl;
+
+	echo '
+	<div id="merge_topics">
+		<form action="', $scripturl, '?action=mergetopics;sa=execute;" method="post" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">', $txt['merge_topic_list'], '</h3>
+			</div>
+			<table width="100%" class="bordercolor table_grid">
+				<thead>
+					<tr class="catbg">
+						<th scope="col" class="first_th" align="center" width="10px">', $txt['merge_check'], '</th>
+						<th scope="col" class="lefttext">', $txt['subject'], '</th>
+						<th scope="col" class="lefttext">', $txt['started_by'], '</th>
+						<th scope="col" class="lefttext">', $txt['last_post'], '</th>
+						<th scope="col" class="last_th" width="20px">' . $txt['merge_include_notifications'] . '</th>
+					</tr>
+				</thead>
+				<tbody>';
+		foreach ($context['topics'] as $topic)
+			echo '
+					<tr class="windowbg2">
+						<td align="center">
+							<input type="checkbox" class="input_check" name="topics[]" value="' . $topic['id'] . '" checked="checked" />
+						</td>
+						<td>
+							<a href="' . $scripturl . '?topic=' . $topic['id'] . '.0" target="_blank" class="new_win">' . $topic['subject'] . '</a>
+						</td>
+						<td>
+							', $topic['started']['link'], '<br />
+							<span class="smalltext">', $topic['started']['time'], '</span>
+						</td>
+						<td>
+							' . $topic['updated']['link'] . '<br />
+							<span class="smalltext">', $topic['updated']['time'], '</span>
+						</td>
+						<td align="center">
+							<input type="checkbox" class="input_check" name="notifications[]" value="' . $topic['id'] . '" checked="checked" />
+						</td>
+					</tr>';
+		echo '
+				</tbody>
+			</table>
+			<br />
+			<div class="windowbg">
+				<div class="content">';
+
+	echo '
+					<fieldset id="merge_subject" class="merge_options">
+						<legend>', $txt['merge_select_subject'], '</legend>
+						<select name="subject" onchange="this.form.custom_subject.style.display = (this.options[this.selectedIndex].value != 0) ? \'none\': \'\' ;">';
+	foreach ($context['topics'] as $topic)
+		echo '
+							<option value="', $topic['id'], '"' . ($topic['selected'] ? ' selected="selected"' : '') . '>', $topic['subject'], '</option>';
+	echo '
+							<option value="0">', $txt['merge_custom_subject'], ':</option>
+						</select>
+						<br /><input type="text" name="custom_subject" size="60" id="custom_subject" class="input_text custom_subject" style="display: none;" />
+						<br />
+						<label for="enforce_subject"><input type="checkbox" class="input_check" name="enforce_subject" id="enforce_subject" value="1" /> ', $txt['merge_enforce_subject'], '</label>
+					</fieldset>';
+
+	if (!empty($context['boards']) && count($context['boards']) > 1)
+	{
+		echo '
+					<fieldset id="merge_board" class="merge_options">
+						<legend>', $txt['merge_select_target_board'], '</legend>
+						<ul class="reset">';
+		foreach ($context['boards'] as $board)
+			echo '
+							<li>
+								<input type="radio" name="board" value="' . $board['id'] . '"' . ($board['selected'] ? ' checked="checked"' : '') . ' class="input_radio" /> ' . $board['name'] . '
+							</li>';
+		echo '
+						</ul>
+					</fieldset>';
+	}
+	if (!empty($context['polls']))
+	{
+		echo '
+					<fieldset id="merge_poll" class="merge_options">
+						<legend>' . $txt['merge_select_poll'] . '</legend>
+						<ul class="reset">';
+		foreach ($context['polls'] as $poll)
+			echo '
+							<li>
+								<input type="radio" name="poll" value="' . $poll['id'] . '"' . ($poll['selected'] ? ' checked="checked"' : '') . ' class="input_radio" /> ' . $poll['question'] . ' (' . $txt['topic'] . ': <a href="' . $scripturl . '?topic=' . $poll['topic']['id'] . '.0" target="_blank" class="new_win">' . $poll['topic']['subject'] . '</a>)
+							</li>';
+		echo '
+							<li>
+								<input type="radio" name="poll" value="-1" class="input_radio" /> (' . $txt['merge_no_poll'] . ')
+							</li>
+						</ul>
+					</fieldset>';
+	}
+	echo '
+					<input type="submit" value="' . $txt['merge'] . '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="sa" value="execute" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 1141 - 1178
Themes/default/Themes.template.php

@@ -1,1179 +1,1142 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// The main sub template - for theme administration.
-function template_main()
-{
-	global $context, $settings, $options, $scripturl, $txt, $modSettings;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=theme;sa=admin" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" value="0" name="options[theme_allow]" />
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=themes" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a>
-					', $txt['themeadmin_title'], '
-					</span>
-				</h3>
-			</div>
-			<div class="information">
-				', $txt['themeadmin_explain'], '
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="options-theme_allow"> ', $txt['theme_allow'], '</label>
-						</dt>
-						<dd>
-							<input type="checkbox" name="options[theme_allow]" id="options-theme_allow" value="1"', !empty($modSettings['theme_allow']) ? ' checked="checked"' : '', ' class="input_check" />
-						</dd>
-						<dt>
-							<label for="known_themes_list">', $txt['themeadmin_selectable'], '</label>:
-						</dt>
-						<dd>
-							<div id="known_themes_list">';
-	foreach ($context['themes'] as $theme)
-		echo '
-								<label for="options-known_themes_', $theme['id'], '"><input type="checkbox" name="options[known_themes][]" id="options-known_themes_', $theme['id'], '" value="', $theme['id'], '"', $theme['known'] ? ' checked="checked"' : '', ' class="input_check" /> ', $theme['name'], '</label><br />';
-
-		echo '
-							</div>
-							<a href="javascript:void(0);" onclick="document.getElementById(\'known_themes_list\').style.display=\'block\'; document.getElementById(\'known_themes_link\').style.display = \'none\'; return false; " id="known_themes_link" style="display: none;">[ ', $txt['themeadmin_themelist_link'], ' ]</a>
-							<script type="text/javascript"><!-- // --><![CDATA[
-								document.getElementById("known_themes_list").style.display = "none";
-								document.getElementById("known_themes_link").style.display = "";
-							// ]]></script>
-						</dd>
-						<dt>
-							<label for="theme_guests">', $txt['theme_guests'], ':</label>
-						</dt>
-						<dd>
-							<select name="options[theme_guests]" id="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>
-							<span class="smalltext pick_theme"><a href="', $scripturl, '?action=theme;sa=pick;u=-1;', $context['session_var'], '=', $context['session_id'], '">', $txt['theme_select'], '</a></span>
-						</dd>
-						<dt>
-							<label for="theme_reset">', $txt['theme_reset'], '</label>:
-						</dt>
-						<dd>
-							<select name="theme_reset" id="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>
-							<span class="smalltext pick_theme"><a href="', $scripturl, '?action=theme;sa=pick;u=0;', $context['session_var'], '=', $context['session_id'], '">', $txt['theme_select'], '</a></span>
-						</dd>
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-tm_token_var'], '" value="', $context['admin-tm_token'], '" />
-		</form>';
-
-	// Link to simplemachines.org for latest themes and info!
-	echo '
-		<br />
-		<div class="cat_bar">
-			<h3 class="catbg">
-				<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=latest_themes" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['theme_latest'], '</span>
-			</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<div id="themeLatest">
-					', $txt['theme_latest_fetch'], '
-				</div>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-		<br />';
-
-	// Warn them if theme creation isn't possible!
-	if (!$context['can_create_new'])
-		echo '
-		<div class="errorbox">', $txt['theme_install_writable'], '</div>';
-
-		echo '
-		<form action="', $scripturl, '?action=admin;area=theme;sa=install" method="post" accept-charset="', $context['character_set'], '" enctype="multipart/form-data" onsubmit="return confirm(\'', $txt['theme_install_new_confirm'], '\');">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=theme_install" onclick="return reqWin(this.href);" class="help" id="theme_install"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['theme_install'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">';
-
-	// Here's a little box for installing a new theme.
-	// @todo Should the value="theme_gz" be there?!
-	if ($context['can_create_new'])
-		echo '
-						<dt>
-							<label for="theme_gz">', $txt['theme_install_file'], '</label>:
-						</dt>
-						<dd>
-							<input type="file" name="theme_gz" id="theme_gz" value="theme_gz" size="40" onchange="this.form.copy.disabled = this.value != \'\'; this.form.theme_dir.disabled = this.value != \'\';" class="input_file" />
-						</dd>';
-
-	echo '
-						<dt>
-							<label for="theme_dir">', $txt['theme_install_dir'], '</label>:
-						</dt>
-						<dd>
-							<input type="text" name="theme_dir" id="theme_dir" value="', $context['new_theme_dir'], '" size="40" style="width: 70%;" class="input_text" />
-						</dd>';
-
-	if ($context['can_create_new'])
-		echo '
-						<dt>
-							<label for="copy">', $txt['theme_install_new'], ':</label>
-						</dt>
-						<dd>
-							<input type="text" name="copy" id="copy" value="', $context['new_theme_name'], '" size="40" class="input_text" />
-						</dd>';
-
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['theme_install_go'], '" class="button_submit" />
-					</br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-tm_token_var'], '" value="', $context['admin-tm_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />
-
-		<script type="text/javascript"><!-- // --><![CDATA[
-			window.smfForum_scripturl = "', $scripturl, '";
-			window.smfForum_sessionid = "', $context['session_id'], '";
-			window.smfForum_sessionvar = "', $context['session_var'], '";
-			window.smfThemes_writable = ', $context['can_create_new'] ? 'true' : 'false', ';
-		// ]]></script>';
-
-	if (empty($modSettings['disable_smf_js']))
-		echo '
-		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-themes.js"></script>';
-
-	echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var tempOldOnload;
-			smfSetLatestThemes();
-		// ]]></script>';
-}
-
-function template_list_themes()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['themeadmin_list_heading'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['themeadmin_list_tip'], '
-		</div>';
-
-	// Show each theme.... with X for delete and a link to settings.
-	foreach ($context['themes'] as $theme)
-	{
-		echo '
-			<div class="title_bar">
-				<h3 class="titlebg">
-					<span class="floatleft"><strong><a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=list">', $theme['name'], '</a></strong>', !empty($theme['version']) ? ' <em>(' . $theme['version'] . ')</em>' : '', '</span>';
-
-			// You *cannot* delete the default theme. It's important!
-			if ($theme['id'] != 1)
-				echo '
-					<span class="floatright"><a href="', $scripturl, '?action=admin;area=theme;sa=remove;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';', $context['admin-tr_token_var'], '=', $context['admin-tr_token'], '" onclick="return confirm(\'', $txt['theme_remove_confirm'], '\');"><img src="', $settings['images_url'], '/icons/delete.png" alt="', $txt['theme_remove'], '" title="', $txt['theme_remove'], '" /></a></span>';
-
-			echo '
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings themes_list">
-						<dt>', $txt['themeadmin_list_theme_dir'], ':</dt>
-						<dd', $theme['valid_path'] ? '' : ' class="error"', '>', $theme['theme_dir'], $theme['valid_path'] ? '' : ' ' . $txt['themeadmin_list_invalid'], '</dd>
-						<dt>', $txt['themeadmin_list_theme_url'], ':</dt>
-						<dd>', $theme['theme_url'], '</dd>
-						<dt>', $txt['themeadmin_list_images_url'], ':</dt>
-						<dd>', $theme['images_url'], '</dd>
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	echo '
-
-		<form action="', $scripturl, '?action=admin;area=theme;', $context['session_var'], '=', $context['session_id'], ';sa=list" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['themeadmin_list_reset'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="reset_dir">', $txt['themeadmin_list_reset_dir'], '</label>:
-						</dt>
-						<dd>
-							<input type="text" name="reset_dir" id="reset_dir" value="', $context['reset_dir'], '" size="40" style="width: 80%;" class="input_text" />
-						</dd>
-						<dt>
-							<label for="reset_url">', $txt['themeadmin_list_reset_url'], '</label>:
-						</dt>
-						<dd>
-							<input type="text" name="reset_url" id="reset_url" value="', $context['reset_url'], '" size="40" style="width: 80%;" class="input_text" />
-						</dd>
-					</dl>
-					<input type="submit" name="save" value="', $txt['themeadmin_list_reset_go'], '" class="button_submit" />
-					<br class="clear_right" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<input type="hidden" name="', $context['admin-tl_token_var'], '" value="', $context['admin-tl_token'], '" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_reset_list()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['themeadmin_reset_title'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['themeadmin_reset_tip'], '
-		</div>';
-
-	// Show each theme.... with X for delete and a link to settings.
-	$alternate = false;
-
-	foreach ($context['themes'] as $theme)
-	{
-		$alternate = !$alternate;
-
-		echo '
-		<div class="title_bar">
-			<h3 class="titlebg">', $theme['name'], '</h3>
-		</div>
-		<div class="windowbg', $alternate ? '' : '2','">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<ul class="reset">
-					<li>
-						<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=reset">', $txt['themeadmin_reset_defaults'], '</a> <em class="smalltext">(', $theme['num_default_options'], ' ', $txt['themeadmin_reset_defaults_current'], ')</em>
-					</li>
-					<li>
-						<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=reset;who=1">', $txt['themeadmin_reset_members'], '</a>
-					</li>
-					<li>
-						<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=reset;who=2;', $context['admin-stor_token_var'], '=', $context['admin-stor_token'], '" onclick="return confirm(\'', $txt['themeadmin_reset_remove_confirm'], '\');">', $txt['themeadmin_reset_remove'], '</a> <em class="smalltext">(', $theme['num_members'], ' ', $txt['themeadmin_reset_remove_current'], ')</em>
-					</li>
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-function template_set_options()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_settings']['theme_id'], ';sa=reset" method="post" accept-charset="', $context['character_set'], '">
-			<input type="hidden" name="who" value="', $context['theme_options_reset'] ? 1 : 0, '" />
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['theme_options_title'], ' - ', $context['theme_settings']['name'], '</h3>
-			</div>
-			<div class="information">
-				', $context['theme_options_reset'] ? $txt['themeadmin_reset_options_info'] : $txt['theme_options_defaults'], '
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-	echo '
-					<dl class="settings">';
-
-	foreach ($context['options'] as $setting)
-	{
-		echo '
-						<dt ', $context['theme_options_reset'] ? 'style="width:50%"' : '', '>';
-						
-		// Show the change option box ?
-		if ($context['theme_options_reset'])
-			echo '
-							<span class="floatleft"><select name="', !empty($setting['default']) ? 'default_' : '', 'options_master[', $setting['id'], ']" onchange="this.form.options_', $setting['id'], '.disabled = this.selectedIndex != 1;">
-								<option value="0" selected="selected">', $txt['themeadmin_reset_options_none'], '</option>
-								<option value="1">', $txt['themeadmin_reset_options_change'], '</option>
-								<option value="2">', $txt['themeadmin_reset_options_default'], '</option>
-							</select>&nbsp;</span>';
-		
-		// display checkbox options
-		if ($setting['type'] == 'checkbox')
-		{
-			echo '
-							<label for="options_', $setting['id'], '">', $setting['label'], '</label>';
-			if (isset($setting['description']))
-				echo '
-							<br /><span class="smalltext">', $setting['description'], '</span>';
-		echo '
-						</dt>
-						<dd ', $context['theme_options_reset'] ? 'style="width:40%"' : '', '>
-							<input type="hidden" name="' . (!empty($setting['default']) ? 'default_' : '') . 'options[' . $setting['id'] . ']" value="0" />
-							<input type="checkbox" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="options_', $setting['id'], '"', !empty($setting['value']) ? ' checked="checked"' : '', $context['theme_options_reset'] ? ' disabled="disabled"' : '', ' value="1" class="input_check floatleft" />';
-		}
-		// how about selection lists, we all love them
-		elseif ($setting['type'] == 'list')
-		{
-			echo '
-							<label for="options_', $setting['id'], '">', $setting['label'], '</label>';
-			if (isset($setting['description']))
-				echo '
-							<br /><span class="smalltext">', $setting['description'], '</span>';
-		echo '
-						</dt>
-						<dd ', $context['theme_options_reset'] ? 'style="width:40%"' : '', '>
-							&nbsp;<select class="floatleft" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="options_', $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>';
-		}
-		// a textbox it is then
-		else
-		{
-			echo '
-							<label for="options_', $setting['id'], '">', $setting['label'], '</label>';
-			if (isset($setting['description']))
-				echo '
-							<br /><span class="smalltext">', $setting['description'], '</span>';
-		echo '
-						</dt>
-						<dd ', $context['theme_options_reset'] ? 'style="width:40%"' : '', '>
-							<input type="text" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="options_', $setting['id'], '" value="', $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', $context['theme_options_reset'] ? ' disabled="disabled"' : '', ' class="input_text" />';
-		}
-		
-		// end of this defintion 
-		echo '
-						</dd>';
-	}
-	
-	// close the option page up
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="submit" value="', $txt['save'], '" class="button_submit" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-function template_set_settings()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=theme;sa=list;th=', $context['theme_settings']['theme_id'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h3 class="titlebg">
-					<span class="ie6_header floatleft"><a href="', $scripturl, '?action=helpadmin;help=theme_settings" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a> ', $txt['theme_settings'], ' - ', $context['theme_settings']['name'], '</span>
-				</h3>
-			</div>';
-
-	// @todo Why can't I edit the default theme popup.
-	if ($context['theme_settings']['theme_id'] != 1)
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/config_sm.png" alt="" class="icon" /> ', $txt['theme_edit'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<ul class="reset">
-						<li>
-							<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_settings']['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit;filename=index.template.php">', $txt['theme_edit_index'], '</a>
-						</li>
-						<li>
-							<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_settings']['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit;directory=css">', $txt['theme_edit_style'], '</a>
-						</li>
-					</ul>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/config_sm.png" alt="" class="icon" /> ', $txt['theme_url_config'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="theme_name">', $txt['actual_theme_name'], '</label>
-						</dt>
-						<dd>
-							<input type="text" id="theme_name" name="options[name]" value="', $context['theme_settings']['name'], '" size="32" class="input_text" />
-						</dd>
-						<dt>
-							<label for="theme_url">', $txt['actual_theme_url'], '</label>
-						</dt>
-						<dd>
-							<input type="text" id="theme_url" name="options[theme_url]" value="', $context['theme_settings']['actual_theme_url'], '" size="50" style="max-width: 100%; width: 50ex;" class="input_text" />
-						</dd>
-						<dt>
-							<label for="images_url">', $txt['actual_images_url'], '</label>
-						</dt>
-						<dd>
-							<input type="text" id="images_url" name="options[images_url]" value="', $context['theme_settings']['actual_images_url'], '" size="50" style="max-width: 100%; width: 50ex;" class="input_text" />
-						</dd>
-						<dt>
-							<label for="theme_dir">', $txt['actual_theme_dir'], '</label>
-						</dt>
-						<dd>
-							<input type="text" id="theme_dir" name="options[theme_dir]" value="', $context['theme_settings']['actual_theme_dir'], '" size="50" style="max-width: 100%; width: 50ex;" class="input_text" />
-						</dd>
-					</dl>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-	// Do we allow theme variants?
-	if (!empty($context['theme_variants']))
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img class="icon" src="', $settings['images_url'], '/icons/config_sm.png" alt="" /> ', $txt['theme_variants'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg2">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings">
-						<dt>
-							<label for="variant">', $txt['theme_variants_default'], '</label>:
-						</dt>
-						<dd>
-							<select id="variant" name="options[default_variant]" onchange="changeVariant(this.value)">';
-
-		foreach ($context['theme_variants'] as $key => $variant)
-			echo '
-								<option value="', $key, '" ', $context['default_variant'] == $key ? 'selected="selected"' : '', '>', $variant['label'], '</option>';
-
-		echo '
-							</select>
-						</dd>
-						<dt>
-							<label for="disable_user_variant">', $txt['theme_variants_user_disable'], '</label>:
-						</dt>
-						<dd>
-							<input type="hidden" name="options[disable_user_variant]" value="0" />
-							<input type="checkbox" name="options[disable_user_variant]" id="disable_user_variant"', !empty($context['theme_settings']['disable_user_variant']) ? ' checked="checked"' : '', ' value="1" class="input_check" />
-						</dd>
-					</dl>
-					<img src="', $context['theme_variants'][$context['default_variant']]['thumbnail'], '" id="variant_preview" alt="" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	}
-
-	echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/config_sm.png" alt="" class="icon" /> ', $txt['theme_options'], '</span>
-				</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<dl class="settings flow_auto">';
-
-	foreach ($context['settings'] as $setting)
-	{
-		// Is this a separator?
-		if (empty($setting))
-		{
-			echo '
-					</dl>
-					<hr class="hrcolor" />
-					<dl class="settings flow_auto">';
-		}
-		// A checkbox?
-		elseif ($setting['type'] == 'checkbox')
-		{
-			echo '
-						<dt>
-							<label for="', $setting['id'], '">', $setting['label'], '</label>:';
-
-			if (isset($setting['description']))
-				echo '<br />
-							<span class="smalltext">', $setting['description'], '</span>';
-
-			echo '
-						</dt>
-						<dd>
-							<input type="hidden" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" value="0" />
-							<input type="checkbox" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($setting['value']) ? ' checked="checked"' : '', ' value="1" class="input_check" />
-						</dd>';
-		}
-		// A list with options?
-		elseif ($setting['type'] == 'list')
-		{
-			echo '
-						<dt>
-							<label for="', $setting['id'], '">', $setting['label'], '</label>:';
-
-			if (isset($setting['description']))
-				echo '<br />
-							<span class="smalltext">', $setting['description'], '</span>';
-
-			echo '
-						</dt>
-						<dd>
-							<select name="', !empty($setting['default']) ? 'default_' : '', '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>
-						</dd>';
-		}
-		// A regular input box, then?
-		else
-		{
-			echo '
-						<dt>
-							<label for="', $setting['id'], '">', $setting['label'], '</label>:';
-
-			if (isset($setting['description']))
-				echo '<br />
-							<span class="smalltext">', $setting['description'], '</span>';
-
-			echo '
-						</dt>
-						<dd>
-							<input type="text" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="', $setting['id'], '" value="', $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : (empty($setting['size']) ? ' size="40"' : ' size="' . $setting['size'] . '"'), ' class="input_text" />
-						</dd>';
-		}
-	}
-
-	echo '
-					</dl>
-					<hr class="hrcolor" />
-					<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" /><br />
-					<br class="clear_right" />
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-			<input type="hidden" name="', $context['admin-sts_token_var'], '" value="', $context['admin-sts_token'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-
-	if (!empty($context['theme_variants']))
-	{
-		echo '
-		<script type="text/javascript"><!-- // --><![CDATA[
-		var oThumbnails = {';
-
-		// All the variant thumbnails.
-		$count = 1;
-		foreach ($context['theme_variants'] as $key => $variant)
-		{
-			echo '
-			\'', $key, '\': \'', $variant['thumbnail'], '\'', (count($context['theme_variants']) == $count ? '' : ',');
-			$count++;
-		}
-
-		echo '
-		}
-		// ]]></script>';
-	}
-}
-
-// This template allows for the selection of different themes ;).
-function template_pick()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="pick_theme">
-		<form action="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">';
-
-	// Just go through each theme and show its information - thumbnail, etc.
-	foreach ($context['available_themes'] as $theme)
-	{
-		echo '
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], !empty($theme['variants']) ? ';vrt=' . $theme['selected_variant'] : '', '">', $theme['name'], '</a>
-				</h3>
-			</div>
-			<div class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
-				<span class="topslice"><span></span></span>
-				<div class="flow_hidden content">
-					<div class="floatright"><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '" id="theme_thumb_preview_', $theme['id'], '" title="', $txt['theme_preview'], '"><img src="', $theme['thumbnail_href'], '" id="theme_thumb_', $theme['id'], '" alt="" class="padding" /></a></div>
-					<p>', $theme['description'], '</p>';
-
-		if (!empty($theme['variants']))
-		{
-			echo '
-					<label for="variant', $theme['id'], '"><strong>', $theme['pick_label'], '</strong></label>:
-					<select id="variant', $theme['id'], '" name="vrt[', $theme['id'], ']" onchange="changeVariant', $theme['id'], '(this.value);">';
-
-			foreach ($theme['variants'] as $key => $variant)
-			{
-				echo '
-						<option value="', $key, '" ', $theme['selected_variant'] == $key ? 'selected="selected"' : '', '>', $variant['label'], '</option>';
-			}
-			echo '
-					</select>
-					<noscript>
-						<input type="submit" name="save[', $theme['id'], ']" value="', $txt['save'], '" class="button_submit" />
-					</noscript>';
-		}
-
-		echo '
-					<br />
-					<p>
-						<em class="smalltext">', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</em>
-					</p>
-					<br />
-					<ul class="reset">
-						<li>
-							<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], !empty($theme['variants']) ? ';vrt=' . $theme['selected_variant'] : '', '" id="theme_use_', $theme['id'], '">[', $txt['theme_set'], ']</a>
-						</li>
-						<li>
-							<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '" id="theme_preview_', $theme['id'], '">[', $txt['theme_preview'], ']</a>
-						</li>
-					</ul>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-
-		if (!empty($theme['variants']))
-		{
-			echo '
-			<script type="text/javascript"><!-- // --><![CDATA[
-			var sBaseUseUrl', $theme['id'], ' = smf_prepareScriptUrl(smf_scripturl) + \'action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '\';
-			var sBasePreviewUrl', $theme['id'], ' = smf_prepareScriptUrl(smf_scripturl) + \'action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '\';
-			var oThumbnails', $theme['id'], ' = {';
-
-			// All the variant thumbnails.
-			$count = 1;
-			foreach ($theme['variants'] as $key => $variant)
-			{
-				echo '
-				\'', $key, '\': \'', $variant['thumbnail'], '\'', (count($theme['variants']) == $count ? '' : ',');
-				$count++;
-			}
-
-			echo '
-			}
-
-			function changeVariant', $theme['id'], '(sVariant)
-			{
-				document.getElementById(\'theme_thumb_', $theme['id'], '\').src = oThumbnails', $theme['id'], '[sVariant];
-				document.getElementById(\'theme_use_', $theme['id'], '\').href = sBaseUseUrl', $theme['id'], ' + \';vrt=\' + sVariant;
-				document.getElementById(\'theme_thumb_preview_', $theme['id'], '\').href = sBasePreviewUrl', $theme['id'], ' + \';vrt=\' + sVariant + \';variant=\' + sVariant;
-				document.getElementById(\'theme_preview_', $theme['id'], '\').href = sBasePreviewUrl', $theme['id'], ' + \';vrt=\' + sVariant + \';variant=\' + sVariant;
-			}
-			// ]]></script>';
-		}
-	}
-
-	echo '
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// Okay, that theme was installed successfully!
-function template_installed()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Not much to show except a link back...
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $context['page_title'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>
-					<a href="', $scripturl, '?action=admin;area=theme;sa=list;th=', $context['installed_theme']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $context['installed_theme']['name'], '</a> ', $txt['theme_installed_message'], '
-				</p>
-				<p>
-					<a href="', $scripturl, '?action=admin;area=theme;sa=admin;', $context['session_var'], '=', $context['session_id'], '">', $txt['back'], '</a>
-				</p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_edit_list()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['themeadmin_edit_title'], '</h3>
-		</div>';
-
-	$alternate = false;
-
-	foreach ($context['themes'] as $theme)
-	{
-		$alternate = !$alternate;
-
-		echo '
-		<div class="title_bar">
-			<h3 class="titlebg">
-				<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit">', $theme['name'], '</a>', !empty($theme['version']) ? '
-				<em>(' . $theme['version'] . ')</em>' : '', '
-			</h3>
-		</div>
-		<div class="windowbg', $alternate ? '' : '2','">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<ul class="reset">
-					<li><a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit">', $txt['themeadmin_edit_browse'], '</a></li>', $theme['can_edit_style'] ? '
-					<li><a href="' . $scripturl . '?action=admin;area=theme;th=' . $theme['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=css">' . $txt['themeadmin_edit_style'] . '</a></li>' : '', '
-					<li><a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=copy">', $txt['themeadmin_edit_copy_template'], '</a></li>
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	echo '
-	</div>
-	<br class="clear" />';
-}
-
-function template_copy_template()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['themeadmin_edit_filename'], '</h3>
-		</div>
-		<div class="information">
-			', $txt['themeadmin_edit_copy_warning'], '
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<ul class="theme_options">';
-
-	$alternate = false;
-	foreach ($context['available_templates'] as $template)
-	{
-		$alternate = !$alternate;
-
-		echo '
-					<li class="reset flow_hidden windowbg', $alternate ? '2' : '', '">
-						<span class="floatleft">', $template['filename'], $template['already_exists'] ? ' <span class="error">(' . $txt['themeadmin_edit_exists'] . ')</span>' : '', '</span>
-						<span class="floatright">';
-
-		if ($template['can_copy'])
-			echo '<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=copy;template=', $template['value'], '" onclick="return confirm(\'', $template['already_exists'] ? $txt['themeadmin_edit_overwrite_confirm'] : $txt['themeadmin_edit_copy_confirm'], '\');">', $txt['themeadmin_edit_do_copy'], '</a>';
-		else
-			echo $txt['themeadmin_edit_no_copy'];
-
-		echo '
-						</span>
-					</li>';
-	}
-
-	echo '
-				</ul>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>
-	<br class="clear" />';
-}
-
-function template_edit_browse()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<table width="100%" class="table_grid tborder">
-		<thead>
-			<tr class="catbg">
-				<th class="lefttext first_th" scope="col" width="50%">', $txt['themeadmin_edit_filename'], '</th>
-				<th scope="col" width="35%">', $txt['themeadmin_edit_modified'], '</th>
-				<th class="last_th" scope="col" width="15%">', $txt['themeadmin_edit_size'], '</th>
-			</tr>
-		</thead>
-		<tbody>';
-
-	$alternate = false;
-
-	foreach ($context['theme_files'] as $file)
-	{
-		$alternate = !$alternate;
-
-		echo '
-			<tr class="windowbg', $alternate ? '2' : '', '">
-				<td>';
-
-		if ($file['is_editable'])
-			echo '<a href="', $file['href'], '"', $file['is_template'] ? ' style="font-weight: bold;"' : '', '>', $file['filename'], '</a>';
-
-		elseif ($file['is_directory'])
-			echo '<a href="', $file['href'], '" class="is_directory">', $file['filename'], '</a>';
-
-		else
-			echo $file['filename'];
-
-		echo '
-				</td>
-				<td class="righttext">', !empty($file['last_modified']) ? $file['last_modified'] : '', '</td>
-				<td class="righttext">', $file['size'], '</td>
-			</tr>';
-	}
-
-	echo '
-		</tbody>
-		</table>
-	</div>
-	<br class="clear" />';
-}
-
-// Wanna edit the stylesheet?
-function template_edit_style()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	if ($context['session_error'])
-		echo '
-	<div class="errorbox">
-		', $txt['error_session_timeout'], '
-	</div>';
-
-	// From now on no one can complain that editing css is difficult. If you disagree, go to www.w3schools.com.
-	echo '
-	<div id="admincenter">
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var previewData = "";
-			var previewTimeout;
-			var editFilename = ', JavaScriptEscape($context['edit_filename']), ';
-
-			// Load up a page, but apply our stylesheet.
-			function navigatePreview(url)
-			{
-				var myDoc = new XMLHttpRequest();
-				myDoc.onreadystatechange = function ()
-				{
-					if (myDoc.readyState != 4)
-						return;
-
-					if (myDoc.responseText != null && myDoc.status == 200)
-					{
-						previewData = myDoc.responseText;
-						document.getElementById("css_preview_box").style.display = "";
-
-						// Revert to the theme they actually use ;).
-						var tempImage = new Image();
-						tempImage.src = smf_prepareScriptUrl(smf_scripturl) + "action=admin;area=theme;sa=edit;theme=', $settings['theme_id'], ';preview;" + (new Date().getTime());
-
-						refreshPreviewCache = null;
-						refreshPreview(false);
-					}
-				};
-
-				var anchor = "";
-				if (url.indexOf("#") != -1)
-				{
-					anchor = url.substr(url.indexOf("#"));
-					url = url.substr(0, url.indexOf("#"));
-				}
-
-				myDoc.open("GET", url + (url.indexOf("?") == -1 ? "?" : ";") + "theme=', $context['theme_id'], '" + anchor, true);
-				myDoc.send(null);
-			}
-			navigatePreview(smf_scripturl);
-
-			var refreshPreviewCache;
-			function refreshPreview(check)
-			{
-				var identical = document.forms.stylesheetForm.entire_file.value == refreshPreviewCache;
-
-				// Don\'t reflow the whole thing if nothing changed!!
-				if (check && identical)
-					return;
-				refreshPreviewCache = document.forms.stylesheetForm.entire_file.value;
-				// Replace the paths for images.
-				refreshPreviewCache = refreshPreviewCache.replace(/url\(\.\.\/images/gi, "url(" + smf_images_url);
-
-				// Try to do it without a complete reparse.
-				if (identical)
-				{
-					try
-					{
-					';
-	if (isBrowser('is_ie'))
-		echo '
-						var sheets = frames["css_preview_box"].document.styleSheets;
-						for (var j = 0; j < sheets.length; j++)
-						{
-							if (sheets[j].id == "css_preview_box")
-								sheets[j].cssText = document.forms.stylesheetForm.entire_file.value;
-						}';
-	else
-		echo '
-						setInnerHTML(frames["css_preview_box"].document.getElementById("css_preview_sheet"), document.forms.stylesheetForm.entire_file.value);';
-	echo '
-					}
-					catch (e)
-					{
-						identical = false;
-					}
-				}
-
-				// This will work most of the time... could be done with an after-apply, maybe.
-				if (!identical)
-				{
-					var data = previewData + "";
-					var preview_sheet = document.forms.stylesheetForm.entire_file.value;
-					var stylesheetMatch = new RegExp(\'<link rel="stylesheet"[^>]+href="[^"]+\' + editFilename + \'[^>]*>\');
-
-					// Replace the paths for images.
-					preview_sheet = preview_sheet.replace(/url\(\.\.\/images/gi, "url(" + smf_images_url);
-					data = data.replace(stylesheetMatch, "<style type=\"text/css\" id=\"css_preview_sheet\">" + preview_sheet + "<" + "/style>");
-
-					frames["css_preview_box"].document.open();
-					frames["css_preview_box"].document.write(data);
-					frames["css_preview_box"].document.close();
-
-					// Next, fix all its links so we can handle them and reapply the new css!
-					frames["css_preview_box"].onload = function ()
-					{
-						var fixLinks = frames["css_preview_box"].document.getElementsByTagName("a");
-						for (var i = 0; i < fixLinks.length; i++)
-						{
-							if (fixLinks[i].onclick)
-								continue;
-							fixLinks[i].onclick = function ()
-							{
-								window.parent.navigatePreview(this.href);
-								return false;
-							};
-						}
-					};
-				}
-			}
-		// ]]></script>
-		<iframe id="css_preview_box" name="css_preview_box" src="about:blank" width="99%" height="300" frameborder="0" style="display: none; margin-bottom: 2ex; border: 1px solid black;"></iframe>';
-
-	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
-	echo '
-		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';sa=edit" method="post" accept-charset="', $context['character_set'], '" name="stylesheetForm" id="stylesheetForm">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['theme_edit'], ' - ', $context['edit_filename'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	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="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . '; font-family: monospace; margin-top: 1ex; white-space: pre;" onkeyup="setPreviewTimeout();" onchange="refreshPreview(true);">', $context['entire_file'], '</textarea><br />
-					<div class="padding righttext">
-						<input type="submit" name="save" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' style="margin-top: 1ex;" class="button_submit" />
-						<input type="button" value="', $txt['themeadmin_edit_preview'], '" onclick="refreshPreview(false);" class="button_submit" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-			<input type="hidden" name="filename" value="', $context['edit_filename'], '" />
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
-// This edits the template...
-function template_edit_template()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	if ($context['session_error'])
-		echo '
-	<div class="errorbox">
-		', $txt['error_session_timeout'], '
-	</div>';
-
-	if (isset($context['parse_error']))
-		echo '
-	<div class="errorbox">
-		', $txt['themeadmin_edit_error'], '
-			<div><tt>', $context['parse_error'], '</tt></div>
-	</div>';
-
-	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';sa=edit" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['theme_edit'], ' - ', $context['edit_filename'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">';
-
-	if (!$context['allow_save'])
-		echo '
-					', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '<br />';
-
-	foreach ($context['file_parts'] as $part)
-		echo '
-					<label for="on_line', $part['line'], '">', $txt['themeadmin_edit_on_line'], ' ', $part['line'], '</label>:<br />
-					<div class="centertext">
-						<textarea id="on_line', $part['line'] ,'" name="entire_file[]" cols="80" rows="', $part['lines'] > 14 ? '14' : $part['lines'], '" class="edit_file">', $part['data'], '</textarea>
-					</div>';
-
-	echo '
-					<div class="padding righttext">
-						<input type="submit" name="save" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' class="button_submit" />
-						<input type="hidden" name="filename" value="', $context['edit_filename'], '" />
-						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-					</div>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-		</form>
-	</div>';
-}
-
-function template_edit_file()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	if ($context['session_error'])
-		echo '
-	<div class="errorbox">
-		', $txt['error_session_timeout'], '
-	</div>';
-
-	//Is this file writeable?
-	if (!$context['allow_save'])
-		echo '
-	<div class="errorbox">
-		', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '
-	</div>';
-
-	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';sa=edit" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['theme_edit'], ' - ', $context['edit_filename'], '</h3>
-			</div>
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<textarea name="entire_file" id="entire_file" cols="80" rows="20" class="edit_file">', $context['entire_file'], '</textarea><br />
-					<input type="submit" name="save" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' class="button_submit" />
-					<input type="hidden" name="filename" value="', $context['edit_filename'], '" />
-					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
-
-	// Hopefully it exists.
-	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token']))
-		echo '
-					<input type="text" name="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token_var'], '" value="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'], '" />';
-
-	echo '
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>
-
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// The main sub template - for theme administration.
+function template_main()
+{
+	global $context, $settings, $options, $scripturl, $txt, $modSettings;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=theme;sa=admin" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" value="0" name="options[theme_allow]" />
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<a href="', $scripturl, '?action=helpadmin;help=themes" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a>
+					', $txt['themeadmin_title'], '
+				</h3>
+			</div>
+			<div class="information">
+				', $txt['themeadmin_explain'], '
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="options-theme_allow"> ', $txt['theme_allow'], '</label>
+						</dt>
+						<dd>
+							<input type="checkbox" name="options[theme_allow]" id="options-theme_allow" value="1"', !empty($modSettings['theme_allow']) ? ' checked="checked"' : '', ' class="input_check" />
+						</dd>
+						<dt>
+							<label for="known_themes_list">', $txt['themeadmin_selectable'], '</label>:
+						</dt>
+						<dd>
+							<div id="known_themes_list">';
+	foreach ($context['themes'] as $theme)
+		echo '
+								<label for="options-known_themes_', $theme['id'], '"><input type="checkbox" name="options[known_themes][]" id="options-known_themes_', $theme['id'], '" value="', $theme['id'], '"', $theme['known'] ? ' checked="checked"' : '', ' class="input_check" /> ', $theme['name'], '</label><br />';
+
+		echo '
+							</div>
+							<a href="javascript:void(0);" onclick="document.getElementById(\'known_themes_list\').style.display=\'block\'; document.getElementById(\'known_themes_link\').style.display = \'none\'; return false; " id="known_themes_link" style="display: none;">[ ', $txt['themeadmin_themelist_link'], ' ]</a>
+							<script type="text/javascript"><!-- // --><![CDATA[
+								document.getElementById("known_themes_list").style.display = "none";
+								document.getElementById("known_themes_link").style.display = "";
+							// ]]></script>
+						</dd>
+						<dt>
+							<label for="theme_guests">', $txt['theme_guests'], ':</label>
+						</dt>
+						<dd>
+							<select name="options[theme_guests]" id="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>
+							<span class="smalltext pick_theme"><a href="', $scripturl, '?action=theme;sa=pick;u=-1;', $context['session_var'], '=', $context['session_id'], '">', $txt['theme_select'], '</a></span>
+						</dd>
+						<dt>
+							<label for="theme_reset">', $txt['theme_reset'], '</label>:
+						</dt>
+						<dd>
+							<select name="theme_reset" id="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>
+							<span class="smalltext pick_theme"><a href="', $scripturl, '?action=theme;sa=pick;u=0;', $context['session_var'], '=', $context['session_id'], '">', $txt['theme_select'], '</a></span>
+						</dd>
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-tm_token_var'], '" value="', $context['admin-tm_token'], '" />
+		</form>';
+
+	// Link to simplemachines.org for latest themes and info!
+	echo '
+		<br />
+		<div class="cat_bar">
+			<h3 class="catbg">
+				<a href="', $scripturl, '?action=helpadmin;help=latest_themes" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['theme_latest'], '
+			</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<div id="themeLatest">
+					', $txt['theme_latest_fetch'], '
+				</div>
+			</div>
+		</div>
+		<br />';
+
+	// Warn them if theme creation isn't possible!
+	if (!$context['can_create_new'])
+		echo '
+		<div class="errorbox">', $txt['theme_install_writable'], '</div>';
+
+		echo '
+		<form action="', $scripturl, '?action=admin;area=theme;sa=install" method="post" accept-charset="', $context['character_set'], '" enctype="multipart/form-data" onsubmit="return confirm(\'', $txt['theme_install_new_confirm'], '\');">
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<a href="', $scripturl, '?action=helpadmin;help=theme_install" onclick="return reqWin(this.href);" class="help" id="theme_install"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="', $txt['help'], '" /></a> ', $txt['theme_install'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">';
+
+	// Here's a little box for installing a new theme.
+	// @todo Should the value="theme_gz" be there?!
+	if ($context['can_create_new'])
+		echo '
+						<dt>
+							<label for="theme_gz">', $txt['theme_install_file'], '</label>:
+						</dt>
+						<dd>
+							<input type="file" name="theme_gz" id="theme_gz" value="theme_gz" size="40" onchange="this.form.copy.disabled = this.value != \'\'; this.form.theme_dir.disabled = this.value != \'\';" class="input_file" />
+						</dd>';
+
+	echo '
+						<dt>
+							<label for="theme_dir">', $txt['theme_install_dir'], '</label>:
+						</dt>
+						<dd>
+							<input type="text" name="theme_dir" id="theme_dir" value="', $context['new_theme_dir'], '" size="40" style="width: 70%;" class="input_text" />
+						</dd>';
+
+	if ($context['can_create_new'])
+		echo '
+						<dt>
+							<label for="copy">', $txt['theme_install_new'], ':</label>
+						</dt>
+						<dd>
+							<input type="text" name="copy" id="copy" value="', $context['new_theme_name'], '" size="40" class="input_text" />
+						</dd>';
+
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['theme_install_go'], '" class="button_submit" />
+					</br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-tm_token_var'], '" value="', $context['admin-tm_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />
+
+		<script type="text/javascript"><!-- // --><![CDATA[
+			window.smfForum_scripturl = "', $scripturl, '";
+			window.smfForum_sessionid = "', $context['session_id'], '";
+			window.smfForum_sessionvar = "', $context['session_var'], '";
+			window.smfThemes_writable = ', $context['can_create_new'] ? 'true' : 'false', ';
+		// ]]></script>';
+
+	if (empty($modSettings['disable_smf_js']))
+		echo '
+		<script type="text/javascript" src="', $scripturl, '?action=viewsmfile;filename=latest-themes.js"></script>';
+
+	echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var tempOldOnload;
+			smfSetLatestThemes();
+		// ]]></script>';
+}
+
+function template_list_themes()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['themeadmin_list_heading'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['themeadmin_list_tip'], '
+		</div>';
+
+	// Show each theme.... with X for delete and a link to settings.
+	foreach ($context['themes'] as $theme)
+	{
+		echo '
+			<div class="title_bar">
+				<h3 class="titlebg">
+					<span class="floatleft"><strong><a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=list">', $theme['name'], '</a></strong>', !empty($theme['version']) ? ' <em>(' . $theme['version'] . ')</em>' : '', '</span>';
+
+			// You *cannot* delete the default theme. It's important!
+			if ($theme['id'] != 1)
+				echo '
+					<span class="floatright"><a href="', $scripturl, '?action=admin;area=theme;sa=remove;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';', $context['admin-tr_token_var'], '=', $context['admin-tr_token'], '" onclick="return confirm(\'', $txt['theme_remove_confirm'], '\');"><img src="', $settings['images_url'], '/icons/delete.png" alt="', $txt['theme_remove'], '" title="', $txt['theme_remove'], '" /></a></span>';
+
+			echo '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings themes_list">
+						<dt>', $txt['themeadmin_list_theme_dir'], ':</dt>
+						<dd', $theme['valid_path'] ? '' : ' class="error"', '>', $theme['theme_dir'], $theme['valid_path'] ? '' : ' ' . $txt['themeadmin_list_invalid'], '</dd>
+						<dt>', $txt['themeadmin_list_theme_url'], ':</dt>
+						<dd>', $theme['theme_url'], '</dd>
+						<dt>', $txt['themeadmin_list_images_url'], ':</dt>
+						<dd>', $theme['images_url'], '</dd>
+					</dl>
+				</div>
+			</div>';
+	}
+
+	echo '
+
+		<form action="', $scripturl, '?action=admin;area=theme;', $context['session_var'], '=', $context['session_id'], ';sa=list" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['themeadmin_list_reset'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="reset_dir">', $txt['themeadmin_list_reset_dir'], '</label>:
+						</dt>
+						<dd>
+							<input type="text" name="reset_dir" id="reset_dir" value="', $context['reset_dir'], '" size="40" style="width: 80%;" class="input_text" />
+						</dd>
+						<dt>
+							<label for="reset_url">', $txt['themeadmin_list_reset_url'], '</label>:
+						</dt>
+						<dd>
+							<input type="text" name="reset_url" id="reset_url" value="', $context['reset_url'], '" size="40" style="width: 80%;" class="input_text" />
+						</dd>
+					</dl>
+					<input type="submit" name="save" value="', $txt['themeadmin_list_reset_go'], '" class="button_submit" />
+					<br class="clear_right" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<input type="hidden" name="', $context['admin-tl_token_var'], '" value="', $context['admin-tl_token'], '" />
+				</div>
+			</div>
+
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_reset_list()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['themeadmin_reset_title'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['themeadmin_reset_tip'], '
+		</div>';
+
+	// Show each theme.... with X for delete and a link to settings.
+	$alternate = false;
+
+	foreach ($context['themes'] as $theme)
+	{
+		$alternate = !$alternate;
+
+		echo '
+		<div class="title_bar">
+			<h3 class="titlebg">', $theme['name'], '</h3>
+		</div>
+		<div class="windowbg', $alternate ? '' : '2','">
+			<div class="content">
+				<ul class="reset">
+					<li>
+						<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=reset">', $txt['themeadmin_reset_defaults'], '</a> <em class="smalltext">(', $theme['num_default_options'], ' ', $txt['themeadmin_reset_defaults_current'], ')</em>
+					</li>
+					<li>
+						<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=reset;who=1">', $txt['themeadmin_reset_members'], '</a>
+					</li>
+					<li>
+						<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=reset;who=2;', $context['admin-stor_token_var'], '=', $context['admin-stor_token'], '" onclick="return confirm(\'', $txt['themeadmin_reset_remove_confirm'], '\');">', $txt['themeadmin_reset_remove'], '</a> <em class="smalltext">(', $theme['num_members'], ' ', $txt['themeadmin_reset_remove_current'], ')</em>
+					</li>
+				</ul>
+			</div>
+		</div>';
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+function template_set_options()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_settings']['theme_id'], ';sa=reset" method="post" accept-charset="', $context['character_set'], '">
+			<input type="hidden" name="who" value="', $context['theme_options_reset'] ? 1 : 0, '" />
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['theme_options_title'], ' - ', $context['theme_settings']['name'], '</h3>
+			</div>
+			<div class="information">
+				', $context['theme_options_reset'] ? $txt['themeadmin_reset_options_info'] : $txt['theme_options_defaults'], '
+			</div>
+			<div class="windowbg2">
+				<div class="content">';
+	echo '
+					<dl class="settings">';
+
+	foreach ($context['options'] as $setting)
+	{
+		echo '
+						<dt ', $context['theme_options_reset'] ? 'style="width:50%"' : '', '>';
+						
+		// Show the change option box ?
+		if ($context['theme_options_reset'])
+			echo '
+							<span class="floatleft"><select name="', !empty($setting['default']) ? 'default_' : '', 'options_master[', $setting['id'], ']" onchange="this.form.options_', $setting['id'], '.disabled = this.selectedIndex != 1;">
+								<option value="0" selected="selected">', $txt['themeadmin_reset_options_none'], '</option>
+								<option value="1">', $txt['themeadmin_reset_options_change'], '</option>
+								<option value="2">', $txt['themeadmin_reset_options_default'], '</option>
+							</select>&nbsp;</span>';
+		
+		// display checkbox options
+		if ($setting['type'] == 'checkbox')
+		{
+			echo '
+							<label for="options_', $setting['id'], '">', $setting['label'], '</label>';
+			if (isset($setting['description']))
+				echo '
+							<br /><span class="smalltext">', $setting['description'], '</span>';
+		echo '
+						</dt>
+						<dd ', $context['theme_options_reset'] ? 'style="width:40%"' : '', '>
+							<input type="hidden" name="' . (!empty($setting['default']) ? 'default_' : '') . 'options[' . $setting['id'] . ']" value="0" />
+							<input type="checkbox" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="options_', $setting['id'], '"', !empty($setting['value']) ? ' checked="checked"' : '', $context['theme_options_reset'] ? ' disabled="disabled"' : '', ' value="1" class="input_check floatleft" />';
+		}
+		// how about selection lists, we all love them
+		elseif ($setting['type'] == 'list')
+		{
+			echo '
+							<label for="options_', $setting['id'], '">', $setting['label'], '</label>';
+			if (isset($setting['description']))
+				echo '
+							<br /><span class="smalltext">', $setting['description'], '</span>';
+		echo '
+						</dt>
+						<dd ', $context['theme_options_reset'] ? 'style="width:40%"' : '', '>
+							&nbsp;<select class="floatleft" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="options_', $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>';
+		}
+		// a textbox it is then
+		else
+		{
+			echo '
+							<label for="options_', $setting['id'], '">', $setting['label'], '</label>';
+			if (isset($setting['description']))
+				echo '
+							<br /><span class="smalltext">', $setting['description'], '</span>';
+		echo '
+						</dt>
+						<dd ', $context['theme_options_reset'] ? 'style="width:40%"' : '', '>
+							<input type="text" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="options_', $setting['id'], '" value="', $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', $context['theme_options_reset'] ? ' disabled="disabled"' : '', ' class="input_text" />';
+		}
+		
+		// end of this defintion 
+		echo '
+						</dd>';
+	}
+	
+	// close the option page up
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="submit" value="', $txt['save'], '" class="button_submit" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					<br class="clear_right" />
+				</div>
+			</div>
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+function template_set_settings()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=theme;sa=list;th=', $context['theme_settings']['theme_id'], '" method="post" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h3 class="titlebg">
+					<a href="', $scripturl, '?action=helpadmin;help=theme_settings" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="icon" /></a> ', $txt['theme_settings'], ' - ', $context['theme_settings']['name'], '
+				</h3>
+			</div>';
+
+	// @todo Why can't I edit the default theme popup.
+	if ($context['theme_settings']['theme_id'] != 1)
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/config_sm.png" alt="" class="icon" /> ', $txt['theme_edit'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<ul class="reset">
+						<li>
+							<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_settings']['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit;filename=index.template.php">', $txt['theme_edit_index'], '</a>
+						</li>
+						<li>
+							<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_settings']['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit;directory=css">', $txt['theme_edit_style'], '</a>
+						</li>
+					</ul>
+				</div>
+			</div>';
+
+	echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/config_sm.png" alt="" class="icon" /> ', $txt['theme_url_config'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="theme_name">', $txt['actual_theme_name'], '</label>
+						</dt>
+						<dd>
+							<input type="text" id="theme_name" name="options[name]" value="', $context['theme_settings']['name'], '" size="32" class="input_text" />
+						</dd>
+						<dt>
+							<label for="theme_url">', $txt['actual_theme_url'], '</label>
+						</dt>
+						<dd>
+							<input type="text" id="theme_url" name="options[theme_url]" value="', $context['theme_settings']['actual_theme_url'], '" size="50" style="max-width: 100%; width: 50ex;" class="input_text" />
+						</dd>
+						<dt>
+							<label for="images_url">', $txt['actual_images_url'], '</label>
+						</dt>
+						<dd>
+							<input type="text" id="images_url" name="options[images_url]" value="', $context['theme_settings']['actual_images_url'], '" size="50" style="max-width: 100%; width: 50ex;" class="input_text" />
+						</dd>
+						<dt>
+							<label for="theme_dir">', $txt['actual_theme_dir'], '</label>
+						</dt>
+						<dd>
+							<input type="text" id="theme_dir" name="options[theme_dir]" value="', $context['theme_settings']['actual_theme_dir'], '" size="50" style="max-width: 100%; width: 50ex;" class="input_text" />
+						</dd>
+					</dl>
+				</div>
+			</div>';
+
+	// Do we allow theme variants?
+	if (!empty($context['theme_variants']))
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img class="icon" src="', $settings['images_url'], '/icons/config_sm.png" alt="" /> ', $txt['theme_variants'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<dl class="settings">
+						<dt>
+							<label for="variant">', $txt['theme_variants_default'], '</label>:
+						</dt>
+						<dd>
+							<select id="variant" name="options[default_variant]" onchange="changeVariant(this.value)">';
+
+		foreach ($context['theme_variants'] as $key => $variant)
+			echo '
+								<option value="', $key, '" ', $context['default_variant'] == $key ? 'selected="selected"' : '', '>', $variant['label'], '</option>';
+
+		echo '
+							</select>
+						</dd>
+						<dt>
+							<label for="disable_user_variant">', $txt['theme_variants_user_disable'], '</label>:
+						</dt>
+						<dd>
+							<input type="hidden" name="options[disable_user_variant]" value="0" />
+							<input type="checkbox" name="options[disable_user_variant]" id="disable_user_variant"', !empty($context['theme_settings']['disable_user_variant']) ? ' checked="checked"' : '', ' value="1" class="input_check" />
+						</dd>
+					</dl>
+					<img src="', $context['theme_variants'][$context['default_variant']]['thumbnail'], '" id="variant_preview" alt="" />
+				</div>
+			</div>';
+	}
+
+	echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<img src="', $settings['images_url'], '/icons/config_sm.png" alt="" class="icon" /> ', $txt['theme_options'], '
+				</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<dl class="settings flow_auto">';
+
+	foreach ($context['settings'] as $setting)
+	{
+		// Is this a separator?
+		if (empty($setting))
+		{
+			echo '
+					</dl>
+					<hr class="hrcolor" />
+					<dl class="settings flow_auto">';
+		}
+		// A checkbox?
+		elseif ($setting['type'] == 'checkbox')
+		{
+			echo '
+						<dt>
+							<label for="', $setting['id'], '">', $setting['label'], '</label>:';
+
+			if (isset($setting['description']))
+				echo '<br />
+							<span class="smalltext">', $setting['description'], '</span>';
+
+			echo '
+						</dt>
+						<dd>
+							<input type="hidden" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" value="0" />
+							<input type="checkbox" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($setting['value']) ? ' checked="checked"' : '', ' value="1" class="input_check" />
+						</dd>';
+		}
+		// A list with options?
+		elseif ($setting['type'] == 'list')
+		{
+			echo '
+						<dt>
+							<label for="', $setting['id'], '">', $setting['label'], '</label>:';
+
+			if (isset($setting['description']))
+				echo '<br />
+							<span class="smalltext">', $setting['description'], '</span>';
+
+			echo '
+						</dt>
+						<dd>
+							<select name="', !empty($setting['default']) ? 'default_' : '', '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>
+						</dd>';
+		}
+		// A regular input box, then?
+		else
+		{
+			echo '
+						<dt>
+							<label for="', $setting['id'], '">', $setting['label'], '</label>:';
+
+			if (isset($setting['description']))
+				echo '<br />
+							<span class="smalltext">', $setting['description'], '</span>';
+
+			echo '
+						</dt>
+						<dd>
+							<input type="text" name="', !empty($setting['default']) ? 'default_' : '', 'options[', $setting['id'], ']" id="', $setting['id'], '" value="', $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : (empty($setting['size']) ? ' size="40"' : ' size="' . $setting['size'] . '"'), ' class="input_text" />
+						</dd>';
+		}
+	}
+
+	echo '
+					</dl>
+					<hr class="hrcolor" />
+					<input type="submit" name="save" value="', $txt['save'], '" class="button_submit" /><br />
+					<br class="clear_right" />
+				</div>
+			</div>
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+			<input type="hidden" name="', $context['admin-sts_token_var'], '" value="', $context['admin-sts_token'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+
+	if (!empty($context['theme_variants']))
+	{
+		echo '
+		<script type="text/javascript"><!-- // --><![CDATA[
+		var oThumbnails = {';
+
+		// All the variant thumbnails.
+		$count = 1;
+		foreach ($context['theme_variants'] as $key => $variant)
+		{
+			echo '
+			\'', $key, '\': \'', $variant['thumbnail'], '\'', (count($context['theme_variants']) == $count ? '' : ',');
+			$count++;
+		}
+
+		echo '
+		}
+		// ]]></script>';
+	}
+}
+
+// This template allows for the selection of different themes ;).
+function template_pick()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="pick_theme">
+		<form action="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="', $context['character_set'], '">';
+
+	// Just go through each theme and show its information - thumbnail, etc.
+	foreach ($context['available_themes'] as $theme)
+	{
+		echo '
+			<div class="cat_bar">
+				<h3 class="catbg">
+					<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], !empty($theme['variants']) ? ';vrt=' . $theme['selected_variant'] : '', '">', $theme['name'], '</a>
+				</h3>
+			</div>
+			<div class="', $theme['selected'] ? 'windowbg' : 'windowbg2', '">
+				<div class="flow_hidden content">
+					<div class="floatright"><a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '" id="theme_thumb_preview_', $theme['id'], '" title="', $txt['theme_preview'], '"><img src="', $theme['thumbnail_href'], '" id="theme_thumb_', $theme['id'], '" alt="" class="padding" /></a></div>
+					<p>', $theme['description'], '</p>';
+
+		if (!empty($theme['variants']))
+		{
+			echo '
+					<label for="variant', $theme['id'], '"><strong>', $theme['pick_label'], '</strong></label>:
+					<select id="variant', $theme['id'], '" name="vrt[', $theme['id'], ']" onchange="changeVariant', $theme['id'], '(this.value);">';
+
+			foreach ($theme['variants'] as $key => $variant)
+			{
+				echo '
+						<option value="', $key, '" ', $theme['selected_variant'] == $key ? 'selected="selected"' : '', '>', $variant['label'], '</option>';
+			}
+			echo '
+					</select>
+					<noscript>
+						<input type="submit" name="save[', $theme['id'], ']" value="', $txt['save'], '" class="button_submit" />
+					</noscript>';
+		}
+
+		echo '
+					<br />
+					<p>
+						<em class="smalltext">', $theme['num_users'], ' ', ($theme['num_users'] == 1 ? $txt['theme_user'] : $txt['theme_users']), '</em>
+					</p>
+					<br />
+					<ul class="reset">
+						<li>
+							<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], !empty($theme['variants']) ? ';vrt=' . $theme['selected_variant'] : '', '" id="theme_use_', $theme['id'], '">[', $txt['theme_set'], ']</a>
+						</li>
+						<li>
+							<a href="', $scripturl, '?action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '" id="theme_preview_', $theme['id'], '">[', $txt['theme_preview'], ']</a>
+						</li>
+					</ul>
+				</div>
+			</div>';
+
+		if (!empty($theme['variants']))
+		{
+			echo '
+			<script type="text/javascript"><!-- // --><![CDATA[
+			var sBaseUseUrl', $theme['id'], ' = smf_prepareScriptUrl(smf_scripturl) + \'action=theme;sa=pick;u=', $context['current_member'], ';th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '\';
+			var sBasePreviewUrl', $theme['id'], ' = smf_prepareScriptUrl(smf_scripturl) + \'action=theme;sa=pick;u=', $context['current_member'], ';theme=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], '\';
+			var oThumbnails', $theme['id'], ' = {';
+
+			// All the variant thumbnails.
+			$count = 1;
+			foreach ($theme['variants'] as $key => $variant)
+			{
+				echo '
+				\'', $key, '\': \'', $variant['thumbnail'], '\'', (count($theme['variants']) == $count ? '' : ',');
+				$count++;
+			}
+
+			echo '
+			}
+
+			function changeVariant', $theme['id'], '(sVariant)
+			{
+				document.getElementById(\'theme_thumb_', $theme['id'], '\').src = oThumbnails', $theme['id'], '[sVariant];
+				document.getElementById(\'theme_use_', $theme['id'], '\').href = sBaseUseUrl', $theme['id'], ' + \';vrt=\' + sVariant;
+				document.getElementById(\'theme_thumb_preview_', $theme['id'], '\').href = sBasePreviewUrl', $theme['id'], ' + \';vrt=\' + sVariant + \';variant=\' + sVariant;
+				document.getElementById(\'theme_preview_', $theme['id'], '\').href = sBasePreviewUrl', $theme['id'], ' + \';vrt=\' + sVariant + \';variant=\' + sVariant;
+			}
+			// ]]></script>';
+		}
+	}
+
+	echo '
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// Okay, that theme was installed successfully!
+function template_installed()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Not much to show except a link back...
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $context['page_title'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<p>
+					<a href="', $scripturl, '?action=admin;area=theme;sa=list;th=', $context['installed_theme']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $context['installed_theme']['name'], '</a> ', $txt['theme_installed_message'], '
+				</p>
+				<p>
+					<a href="', $scripturl, '?action=admin;area=theme;sa=admin;', $context['session_var'], '=', $context['session_id'], '">', $txt['back'], '</a>
+				</p>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_edit_list()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['themeadmin_edit_title'], '</h3>
+		</div>';
+
+	$alternate = false;
+
+	foreach ($context['themes'] as $theme)
+	{
+		$alternate = !$alternate;
+
+		echo '
+		<div class="title_bar">
+			<h3 class="titlebg">
+				<a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit">', $theme['name'], '</a>', !empty($theme['version']) ? '
+				<em>(' . $theme['version'] . ')</em>' : '', '
+			</h3>
+		</div>
+		<div class="windowbg', $alternate ? '' : '2','">
+			<div class="content">
+				<ul class="reset">
+					<li><a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=edit">', $txt['themeadmin_edit_browse'], '</a></li>', $theme['can_edit_style'] ? '
+					<li><a href="' . $scripturl . '?action=admin;area=theme;th=' . $theme['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=css">' . $txt['themeadmin_edit_style'] . '</a></li>' : '', '
+					<li><a href="', $scripturl, '?action=admin;area=theme;th=', $theme['id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=copy">', $txt['themeadmin_edit_copy_template'], '</a></li>
+				</ul>
+			</div>
+		</div>';
+	}
+
+	echo '
+	</div>
+	<br class="clear" />';
+}
+
+function template_copy_template()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['themeadmin_edit_filename'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['themeadmin_edit_copy_warning'], '
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<ul class="theme_options">';
+
+	$alternate = false;
+	foreach ($context['available_templates'] as $template)
+	{
+		$alternate = !$alternate;
+
+		echo '
+					<li class="reset flow_hidden windowbg', $alternate ? '2' : '', '">
+						<span class="floatleft">', $template['filename'], $template['already_exists'] ? ' <span class="error">(' . $txt['themeadmin_edit_exists'] . ')</span>' : '', '</span>
+						<span class="floatright">';
+
+		if ($template['can_copy'])
+			echo '<a href="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';', $context['session_var'], '=', $context['session_id'], ';sa=copy;template=', $template['value'], '" onclick="return confirm(\'', $template['already_exists'] ? $txt['themeadmin_edit_overwrite_confirm'] : $txt['themeadmin_edit_copy_confirm'], '\');">', $txt['themeadmin_edit_do_copy'], '</a>';
+		else
+			echo $txt['themeadmin_edit_no_copy'];
+
+		echo '
+						</span>
+					</li>';
+	}
+
+	echo '
+				</ul>
+			</div>
+		</div>
+	</div>
+	<br class="clear" />';
+}
+
+function template_edit_browse()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	echo '
+	<div id="admincenter">
+		<table width="100%" class="table_grid tborder">
+		<thead>
+			<tr class="catbg">
+				<th class="lefttext first_th" scope="col" width="50%">', $txt['themeadmin_edit_filename'], '</th>
+				<th scope="col" width="35%">', $txt['themeadmin_edit_modified'], '</th>
+				<th class="last_th" scope="col" width="15%">', $txt['themeadmin_edit_size'], '</th>
+			</tr>
+		</thead>
+		<tbody>';
+
+	$alternate = false;
+
+	foreach ($context['theme_files'] as $file)
+	{
+		$alternate = !$alternate;
+
+		echo '
+			<tr class="windowbg', $alternate ? '2' : '', '">
+				<td>';
+
+		if ($file['is_editable'])
+			echo '<a href="', $file['href'], '"', $file['is_template'] ? ' style="font-weight: bold;"' : '', '>', $file['filename'], '</a>';
+
+		elseif ($file['is_directory'])
+			echo '<a href="', $file['href'], '" class="is_directory">', $file['filename'], '</a>';
+
+		else
+			echo $file['filename'];
+
+		echo '
+				</td>
+				<td class="righttext">', !empty($file['last_modified']) ? $file['last_modified'] : '', '</td>
+				<td class="righttext">', $file['size'], '</td>
+			</tr>';
+	}
+
+	echo '
+		</tbody>
+		</table>
+	</div>
+	<br class="clear" />';
+}
+
+// Wanna edit the stylesheet?
+function template_edit_style()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	if ($context['session_error'])
+		echo '
+	<div class="errorbox">
+		', $txt['error_session_timeout'], '
+	</div>';
+
+	// From now on no one can complain that editing css is difficult. If you disagree, go to www.w3schools.com.
+	echo '
+	<div id="admincenter">
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var previewData = "";
+			var previewTimeout;
+			var editFilename = ', JavaScriptEscape($context['edit_filename']), ';
+
+			// Load up a page, but apply our stylesheet.
+			function navigatePreview(url)
+			{
+				var myDoc = new XMLHttpRequest();
+				myDoc.onreadystatechange = function ()
+				{
+					if (myDoc.readyState != 4)
+						return;
+
+					if (myDoc.responseText != null && myDoc.status == 200)
+					{
+						previewData = myDoc.responseText;
+						document.getElementById("css_preview_box").style.display = "";
+
+						// Revert to the theme they actually use ;).
+						var tempImage = new Image();
+						tempImage.src = smf_prepareScriptUrl(smf_scripturl) + "action=admin;area=theme;sa=edit;theme=', $settings['theme_id'], ';preview;" + (new Date().getTime());
+
+						refreshPreviewCache = null;
+						refreshPreview(false);
+					}
+				};
+
+				var anchor = "";
+				if (url.indexOf("#") != -1)
+				{
+					anchor = url.substr(url.indexOf("#"));
+					url = url.substr(0, url.indexOf("#"));
+				}
+
+				myDoc.open("GET", url + (url.indexOf("?") == -1 ? "?" : ";") + "theme=', $context['theme_id'], '" + anchor, true);
+				myDoc.send(null);
+			}
+			navigatePreview(smf_scripturl);
+
+			var refreshPreviewCache;
+			function refreshPreview(check)
+			{
+				var identical = document.forms.stylesheetForm.entire_file.value == refreshPreviewCache;
+
+				// Don\'t reflow the whole thing if nothing changed!!
+				if (check && identical)
+					return;
+				refreshPreviewCache = document.forms.stylesheetForm.entire_file.value;
+				// Replace the paths for images.
+				refreshPreviewCache = refreshPreviewCache.replace(/url\(\.\.\/images/gi, "url(" + smf_images_url);
+
+				// Try to do it without a complete reparse.
+				if (identical)
+				{
+					try
+					{
+					';
+	if (isBrowser('is_ie'))
+		echo '
+						var sheets = frames["css_preview_box"].document.styleSheets;
+						for (var j = 0; j < sheets.length; j++)
+						{
+							if (sheets[j].id == "css_preview_box")
+								sheets[j].cssText = document.forms.stylesheetForm.entire_file.value;
+						}';
+	else
+		echo '
+						setInnerHTML(frames["css_preview_box"].document.getElementById("css_preview_sheet"), document.forms.stylesheetForm.entire_file.value);';
+	echo '
+					}
+					catch (e)
+					{
+						identical = false;
+					}
+				}
+
+				// This will work most of the time... could be done with an after-apply, maybe.
+				if (!identical)
+				{
+					var data = previewData + "";
+					var preview_sheet = document.forms.stylesheetForm.entire_file.value;
+					var stylesheetMatch = new RegExp(\'<link rel="stylesheet"[^>]+href="[^"]+\' + editFilename + \'[^>]*>\');
+
+					// Replace the paths for images.
+					preview_sheet = preview_sheet.replace(/url\(\.\.\/images/gi, "url(" + smf_images_url);
+					data = data.replace(stylesheetMatch, "<style type=\"text/css\" id=\"css_preview_sheet\">" + preview_sheet + "<" + "/style>");
+
+					frames["css_preview_box"].document.open();
+					frames["css_preview_box"].document.write(data);
+					frames["css_preview_box"].document.close();
+
+					// Next, fix all its links so we can handle them and reapply the new css!
+					frames["css_preview_box"].onload = function ()
+					{
+						var fixLinks = frames["css_preview_box"].document.getElementsByTagName("a");
+						for (var i = 0; i < fixLinks.length; i++)
+						{
+							if (fixLinks[i].onclick)
+								continue;
+							fixLinks[i].onclick = function ()
+							{
+								window.parent.navigatePreview(this.href);
+								return false;
+							};
+						}
+					};
+				}
+			}
+		// ]]></script>
+		<iframe id="css_preview_box" name="css_preview_box" src="about:blank" width="99%" height="300" frameborder="0" style="display: none; margin-bottom: 2ex; border: 1px solid black;"></iframe>';
+
+	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
+	echo '
+		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';sa=edit" method="post" accept-charset="', $context['character_set'], '" name="stylesheetForm" id="stylesheetForm">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['theme_edit'], ' - ', $context['edit_filename'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">';
+
+	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="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 96%; min-width: 96%' : 'width: 96%') . '; font-family: monospace; margin-top: 1ex; white-space: pre;" onkeyup="setPreviewTimeout();" onchange="refreshPreview(true);">', $context['entire_file'], '</textarea><br />
+					<div class="padding righttext">
+						<input type="submit" name="save" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' style="margin-top: 1ex;" class="button_submit" />
+						<input type="button" value="', $txt['themeadmin_edit_preview'], '" onclick="refreshPreview(false);" class="button_submit" />
+					</div>
+				</div>
+			</div>
+			<input type="hidden" name="filename" value="', $context['edit_filename'], '" />
+			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
+// This edits the template...
+function template_edit_template()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	if ($context['session_error'])
+		echo '
+	<div class="errorbox">
+		', $txt['error_session_timeout'], '
+	</div>';
+
+	if (isset($context['parse_error']))
+		echo '
+	<div class="errorbox">
+		', $txt['themeadmin_edit_error'], '
+			<div><tt>', $context['parse_error'], '</tt></div>
+	</div>';
+
+	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';sa=edit" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['theme_edit'], ' - ', $context['edit_filename'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">';
+
+	if (!$context['allow_save'])
+		echo '
+					', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '<br />';
+
+	foreach ($context['file_parts'] as $part)
+		echo '
+					<label for="on_line', $part['line'], '">', $txt['themeadmin_edit_on_line'], ' ', $part['line'], '</label>:<br />
+					<div class="centertext">
+						<textarea id="on_line', $part['line'] ,'" name="entire_file[]" cols="80" rows="', $part['lines'] > 14 ? '14' : $part['lines'], '" class="edit_file">', $part['data'], '</textarea>
+					</div>';
+
+	echo '
+					<div class="padding righttext">
+						<input type="submit" name="save" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' class="button_submit" />
+						<input type="hidden" name="filename" value="', $context['edit_filename'], '" />
+						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
+					</div>
+				</div>
+			</div>
+		</form>
+	</div>';
+}
+
+function template_edit_file()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	if ($context['session_error'])
+		echo '
+	<div class="errorbox">
+		', $txt['error_session_timeout'], '
+	</div>';
+
+	//Is this file writeable?
+	if (!$context['allow_save'])
+		echo '
+	<div class="errorbox">
+		', $txt['theme_edit_no_save'], ': ', $context['allow_save_filename'], '
+	</div>';
+
+	// Just show a big box.... gray out the Save button if it's not saveable... (ie. not 777.)
+	echo '
+	<div id="admincenter">
+		<form action="', $scripturl, '?action=admin;area=theme;th=', $context['theme_id'], ';sa=edit" method="post" accept-charset="', $context['character_set'], '">
+			<div class="cat_bar">
+				<h3 class="catbg">', $txt['theme_edit'], ' - ', $context['edit_filename'], '</h3>
+			</div>
+			<div class="windowbg">
+				<div class="content">
+					<textarea name="entire_file" id="entire_file" cols="80" rows="20" class="edit_file">', $context['entire_file'], '</textarea><br />
+					<input type="submit" name="save" value="', $txt['theme_edit_save'], '"', $context['allow_save'] ? '' : ' disabled="disabled"', ' class="button_submit" />
+					<input type="hidden" name="filename" value="', $context['edit_filename'], '" />
+					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
+
+	// Hopefully it exists.
+	if (isset($context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token']))
+		echo '
+					<input type="text" name="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token_var'], '" value="', $context['admin-te-' . md5($context['theme_id'] . '-' . $context['edit_filename']) . '_token'], '" />';
+
+	echo '
+				</div>
+			</div>
+
+		</form>
+	</div>
+	<br class="clear" />';
+}
+
 ?>

+ 272 - 282
Themes/default/Who.template.php

@@ -1,283 +1,273 @@
-<?php
-/**
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
-
-// The only template in the file.
-function template_main()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	// Display the table header and linktree.
-	echo '
-	<div class="main_section" id="whos_online">
-		<form action="', $scripturl, '?action=who" method="post" id="whoFilter" accept-charset="', $context['character_set'], '">
-			<div class="title_bar">
-				<h4 class="titlebg margin_lower">', $txt['who_title'], '</h4>
-			</div>
-			<div class="topic_table" id="mlist">
-				<div class="pagesection">
-					<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>';
-		echo '
-					<div class="selectbox floatright">', $txt['who_show1'], '
-						<select name="show_top" onchange="document.forms.whoFilter.show.value = this.value; document.forms.whoFilter.submit();">';
-
-		foreach ($context['show_methods'] as $value => $label)
-			echo '
-							<option value="', $value, '" ', $value == $context['show_by'] ? ' selected="selected"' : '', '>', $label, '</option>';
-		echo '
-						</select>
-						<noscript>
-							<input type="submit" name="submit_top" value="', $txt['go'], '" class="button_submit" />
-						</noscript>
-					</div>
-				</div>
-				<table class="table_grid" cellspacing="0">
-					<thead>
-						<tr class="catbg">
-							<th scope="col" class="lefttext first_th" width="40%"><a href="', $scripturl, '?action=who;start=', $context['start'], ';show=', $context['show_by'], ';sort=user', $context['sort_direction'] != 'down' && $context['sort_by'] == 'user' ? '' : ';asc', '" rel="nofollow">', $txt['who_user'], $context['sort_by'] == 'user' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
-							<th scope="col" class="lefttext" width="10%"><a href="', $scripturl, '?action=who;start=', $context['start'], ';show=', $context['show_by'], ';sort=time', $context['sort_direction'] == 'down' && $context['sort_by'] == 'time' ? ';asc' : '', '" rel="nofollow">', $txt['who_time'], $context['sort_by'] == 'time' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
-							<th scope="col" class="lefttext last_th" width="50%">', $txt['who_action'], '</th>
-						</tr>
-					</thead>
-					<tbody>';
-
-	// For every member display their name, time and action (and more for admin).
-	$alternate = 0;
-
-	foreach ($context['members'] as $member)
-	{
-		// $alternate will either be true or false. If it's true, use "windowbg2" and otherwise use "windowbg".
-		echo '
-						<tr class="windowbg', $alternate ? '2' : '', '">
-							<td>';
-
-		// Guests don't have information like icq, msn, y!, and aim... and they can't be messaged.
-		if (!$member['is_guest'])
-		{
-			echo '
-								<span class="contact_info floatright">
-									', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['label'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" align="bottom" />' : $member['online']['text'], $context['can_send_pm'] ? '</a>' : '', '
-									', isset($context['disabled_fields']['icq']) ? '' : $member['icq']['link'] , ' ', isset($context['disabled_fields']['msn']) ? '' : $member['msn']['link'], ' ', isset($context['disabled_fields']['yim']) ? '' : $member['yim']['link'], ' ', isset($context['disabled_fields']['aim']) ? '' : $member['aim']['link'], '
-								</span>';
-		}
-
-		echo '
-								<span class="member', $member['is_hidden'] ? ' hidden' : '', '">
-									', $member['is_guest'] ? $member['name'] : '<a href="' . $member['href'] . '" title="' . $txt['profile_of'] . ' ' . $member['name'] . '"' . (empty($member['color']) ? '' : ' style="color: ' . $member['color'] . '"') . '>' . $member['name'] . '</a>', '
-								</span>';
-
-		if (!empty($member['ip']))
-			echo '
-								(<a href="' . $scripturl . '?action=', ($member['is_guest'] ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $member['id']), ';searchip=' . $member['ip'] . '">' . $member['ip'] . '</a>)';
-
-		echo '
-							</td>
-							<td nowrap="nowrap">', $member['time'], '</td>
-							<td>', $member['action'], '</td>
-						</tr>';
-
-		// Switch alternate to whatever it wasn't this time. (true -> false -> true -> false, etc.)
-		$alternate = !$alternate;
-	}
-
-	// No members?
-	if (empty($context['members']))
-	{
-		echo '
-						<tr class="windowbg2">
-							<td colspan="3" align="center">
-							', $txt['who_no_online_' . ($context['show_by'] == 'guests' || $context['show_by'] == 'spiders' ? $context['show_by'] : 'members')], '
-							</td>
-						</tr>';
-	}
-
-	echo '
-					</tbody>
-				</table>
-			</div>
-			<div class="pagesection">
-				<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>';
-
-	echo '
-				<div class="selectbox floatright">', $txt['who_show1'], '
-					<select name="show" onchange="document.forms.whoFilter.submit();">';
-
-	foreach ($context['show_methods'] as $value => $label)
-		echo '
-						<option value="', $value, '" ', $value == $context['show_by'] ? ' selected="selected"' : '', '>', $label, '</option>';
-	echo '
-					</select>
-					<noscript>
-						<input type="submit" value="', $txt['go'], '" class="button_submit" />
-					</noscript>
-				</div>
-			</div>
-		</form>
-	</div>';
-}
-
-function template_credits()
-{
-	global $context, $txt;
-
-	// The most important part - the credits :P.
-	echo '
-	<div class="main_section" id="credits">
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['credits'], '</h3>
-		</div>';
-
-	foreach ($context['credits'] as $section)
-	{
-		if (isset($section['pretext']))
-		echo '
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<p>', $section['pretext'], '</p>
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-
-		if (isset($section['title']))
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $section['title'], '</h3>
-		</div>';
-
-		echo '
-		<div class="windowbg2">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl>';
-
-		foreach ($section['groups'] as $group)
-		{
-			if (isset($group['title']))
-				echo '
-					<dt>
-						<strong>', $group['title'], '</strong>
-					</dt>
-					<dd>';
-
-			// Try to make this read nicely.
-			if (count($group['members']) <= 2)
-				echo implode(' ' . $txt['credits_and'] . ' ', $group['members']);
-			else
-			{
-				$last_peep = array_pop($group['members']);
-				echo implode(', ', $group['members']), ' ', $txt['credits_and'], ' ', $last_peep;
-			}
-
-			echo '
-					</dd>';
-		}
-
-		echo '
-				</dl>';
-
-		if (isset($section['posttext']))
-			echo '
-				<p class="posttext">', $section['posttext'], '</p>';
-
-		echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-	
-	// Other software and graphics
-	if (!empty($context['credits_software_graphics']))
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['credits_software_graphics'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">';
-		
-		if (!empty($context['credits_software_graphics']['graphics']))
-			echo '
-				<dl>
-					<dt><strong>', $txt['credits_graphics'], '</strong></dt>
-					<dd>', implode('</dd><dd>', $context['credits_software_graphics']['graphics']), '</dd>
-				</dl>';
-		
-		if (!empty($context['credits_software_graphics']['software']))
-			echo '
-				<dl>
-					<dt><strong>', $txt['credits_software'], '</strong></dt>
-					<dd>', implode('</dd><dd>', $context['credits_software_graphics']['software']), '</dd>
-				</dl>';
-	
-		echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-	
-	// How about Modifications, we all love em
-	if (!empty($context['credits_modifications']))
-	{
-		echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['credits_modifications'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">';
-				
-		echo '
-				<dl>
-					<dt><strong>', $txt['credits_modifications'], '</strong></dt>
-					<dd>', implode('</dd><dd>', $context['credits_modifications']), '</dd>
-				</dl>';
-		
-		echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>';
-	}
-
-	// SMF itself
-	echo '
-		<div class="cat_bar">
-			<h3 class="catbg">', $txt['credits_copyright'], '</h3>
-		</div>
-		<div class="windowbg">
-			<span class="topslice"><span></span></span>
-			<div class="content">
-				<dl>
-					<dt><strong>', $txt['credits_forum'], '</strong></dt>', '
-					<dd>', $context['copyrights']['smf'];
-
-	echo '
-					</dd>
-				</dl>';
-				
-	if (!empty($context['copyrights']['mods']))
-	{
-		echo '
-				<dl>
-					<dt><strong>', $txt['credits_modifications'], '</strong></dt>
-					<dd>', implode('</dd><dd>', $context['copyrights']['mods']), '</dd>
-				</dl>';
-	}
-
-	echo '
-			</div>
-			<span class="botslice"><span></span></span>
-		</div>
-	</div>';
-}
-
+<?php
+/**
+ * Simple Machines Forum (SMF)
+ *
+ * @package SMF
+ * @author Simple Machines
+ * @copyright 2011 Simple Machines
+ * @license http://www.simplemachines.org/about/smf/license.php BSD
+ *
+ * @version 2.1 Alpha 1
+ */
+
+// The only template in the file.
+function template_main()
+{
+	global $context, $settings, $options, $scripturl, $txt;
+
+	// Display the table header and linktree.
+	echo '
+	<div class="main_section" id="whos_online">
+		<form action="', $scripturl, '?action=who" method="post" id="whoFilter" accept-charset="', $context['character_set'], '">
+			<div class="title_bar">
+				<h4 class="titlebg margin_lower">', $txt['who_title'], '</h4>
+			</div>
+			<div class="topic_table" id="mlist">
+				<div class="pagesection">
+					<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>';
+		echo '
+					<div class="selectbox floatright">', $txt['who_show1'], '
+						<select name="show_top" onchange="document.forms.whoFilter.show.value = this.value; document.forms.whoFilter.submit();">';
+
+		foreach ($context['show_methods'] as $value => $label)
+			echo '
+							<option value="', $value, '" ', $value == $context['show_by'] ? ' selected="selected"' : '', '>', $label, '</option>';
+		echo '
+						</select>
+						<noscript>
+							<input type="submit" name="submit_top" value="', $txt['go'], '" class="button_submit" />
+						</noscript>
+					</div>
+				</div>
+				<table class="table_grid" cellspacing="0">
+					<thead>
+						<tr class="catbg">
+							<th scope="col" class="lefttext first_th" width="40%"><a href="', $scripturl, '?action=who;start=', $context['start'], ';show=', $context['show_by'], ';sort=user', $context['sort_direction'] != 'down' && $context['sort_by'] == 'user' ? '' : ';asc', '" rel="nofollow">', $txt['who_user'], $context['sort_by'] == 'user' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
+							<th scope="col" class="lefttext" width="10%"><a href="', $scripturl, '?action=who;start=', $context['start'], ';show=', $context['show_by'], ';sort=time', $context['sort_direction'] == 'down' && $context['sort_by'] == 'time' ? ';asc' : '', '" rel="nofollow">', $txt['who_time'], $context['sort_by'] == 'time' ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" />' : '', '</a></th>
+							<th scope="col" class="lefttext last_th" width="50%">', $txt['who_action'], '</th>
+						</tr>
+					</thead>
+					<tbody>';
+
+	// For every member display their name, time and action (and more for admin).
+	$alternate = 0;
+
+	foreach ($context['members'] as $member)
+	{
+		// $alternate will either be true or false. If it's true, use "windowbg2" and otherwise use "windowbg".
+		echo '
+						<tr class="windowbg', $alternate ? '2' : '', '">
+							<td>';
+
+		// Guests don't have information like icq, msn, y!, and aim... and they can't be messaged.
+		if (!$member['is_guest'])
+		{
+			echo '
+								<span class="contact_info floatright">
+									', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['label'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" align="bottom" />' : $member['online']['text'], $context['can_send_pm'] ? '</a>' : '', '
+									', isset($context['disabled_fields']['icq']) ? '' : $member['icq']['link'] , ' ', isset($context['disabled_fields']['msn']) ? '' : $member['msn']['link'], ' ', isset($context['disabled_fields']['yim']) ? '' : $member['yim']['link'], ' ', isset($context['disabled_fields']['aim']) ? '' : $member['aim']['link'], '
+								</span>';
+		}
+
+		echo '
+								<span class="member', $member['is_hidden'] ? ' hidden' : '', '">
+									', $member['is_guest'] ? $member['name'] : '<a href="' . $member['href'] . '" title="' . $txt['profile_of'] . ' ' . $member['name'] . '"' . (empty($member['color']) ? '' : ' style="color: ' . $member['color'] . '"') . '>' . $member['name'] . '</a>', '
+								</span>';
+
+		if (!empty($member['ip']))
+			echo '
+								(<a href="' . $scripturl . '?action=', ($member['is_guest'] ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $member['id']), ';searchip=' . $member['ip'] . '">' . $member['ip'] . '</a>)';
+
+		echo '
+							</td>
+							<td nowrap="nowrap">', $member['time'], '</td>
+							<td>', $member['action'], '</td>
+						</tr>';
+
+		// Switch alternate to whatever it wasn't this time. (true -> false -> true -> false, etc.)
+		$alternate = !$alternate;
+	}
+
+	// No members?
+	if (empty($context['members']))
+	{
+		echo '
+						<tr class="windowbg2">
+							<td colspan="3" align="center">
+							', $txt['who_no_online_' . ($context['show_by'] == 'guests' || $context['show_by'] == 'spiders' ? $context['show_by'] : 'members')], '
+							</td>
+						</tr>';
+	}
+
+	echo '
+					</tbody>
+				</table>
+			</div>
+			<div class="pagesection">
+				<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], '</div>';
+
+	echo '
+				<div class="selectbox floatright">', $txt['who_show1'], '
+					<select name="show" onchange="document.forms.whoFilter.submit();">';
+
+	foreach ($context['show_methods'] as $value => $label)
+		echo '
+						<option value="', $value, '" ', $value == $context['show_by'] ? ' selected="selected"' : '', '>', $label, '</option>';
+	echo '
+					</select>
+					<noscript>
+						<input type="submit" value="', $txt['go'], '" class="button_submit" />
+					</noscript>
+				</div>
+			</div>
+		</form>
+	</div>';
+}
+
+function template_credits()
+{
+	global $context, $txt;
+
+	// The most important part - the credits :P.
+	echo '
+	<div class="main_section" id="credits">
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['credits'], '</h3>
+		</div>';
+
+	foreach ($context['credits'] as $section)
+	{
+		if (isset($section['pretext']))
+		echo '
+		<div class="windowbg">
+			<div class="content">
+				<p>', $section['pretext'], '</p>
+			</div>
+		</div>';
+
+		if (isset($section['title']))
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $section['title'], '</h3>
+		</div>';
+
+		echo '
+		<div class="windowbg2">
+			<div class="content">
+				<dl>';
+
+		foreach ($section['groups'] as $group)
+		{
+			if (isset($group['title']))
+				echo '
+					<dt>
+						<strong>', $group['title'], '</strong>
+					</dt>
+					<dd>';
+
+			// Try to make this read nicely.
+			if (count($group['members']) <= 2)
+				echo implode(' ' . $txt['credits_and'] . ' ', $group['members']);
+			else
+			{
+				$last_peep = array_pop($group['members']);
+				echo implode(', ', $group['members']), ' ', $txt['credits_and'], ' ', $last_peep;
+			}
+
+			echo '
+					</dd>';
+		}
+
+		echo '
+				</dl>';
+
+		if (isset($section['posttext']))
+			echo '
+				<p class="posttext">', $section['posttext'], '</p>';
+
+		echo '
+			</div>
+		</div>';
+	}
+	
+	// Other software and graphics
+	if (!empty($context['credits_software_graphics']))
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['credits_software_graphics'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">';
+		
+		if (!empty($context['credits_software_graphics']['graphics']))
+			echo '
+				<dl>
+					<dt><strong>', $txt['credits_graphics'], '</strong></dt>
+					<dd>', implode('</dd><dd>', $context['credits_software_graphics']['graphics']), '</dd>
+				</dl>';
+		
+		if (!empty($context['credits_software_graphics']['software']))
+			echo '
+				<dl>
+					<dt><strong>', $txt['credits_software'], '</strong></dt>
+					<dd>', implode('</dd><dd>', $context['credits_software_graphics']['software']), '</dd>
+				</dl>';
+	
+		echo '
+			</div>
+		</div>';
+	}
+	
+	// How about Modifications, we all love em
+	if (!empty($context['credits_modifications']))
+	{
+		echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['credits_modifications'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">';
+				
+		echo '
+				<dl>
+					<dt><strong>', $txt['credits_modifications'], '</strong></dt>
+					<dd>', implode('</dd><dd>', $context['credits_modifications']), '</dd>
+				</dl>';
+		
+		echo '
+			</div>
+		</div>';
+	}
+
+	// SMF itself
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['credits_copyright'], '</h3>
+		</div>
+		<div class="windowbg">
+			<div class="content">
+				<dl>
+					<dt><strong>', $txt['credits_forum'], '</strong></dt>', '
+					<dd>', $context['copyrights']['smf'];
+
+	echo '
+					</dd>
+				</dl>';
+				
+	if (!empty($context['copyrights']['mods']))
+	{
+		echo '
+				<dl>
+					<dt><strong>', $txt['credits_modifications'], '</strong></dt>
+					<dd>', implode('</dd><dd>', $context['copyrights']['mods']), '</dd>
+				</dl>';
+	}
+
+	echo '
+			</div>
+		</div>
+	</div>';
+}
+
 ?>