function template_blockedit()
{
    global $context, $settings, $txt, $scripturl, $boardurl;
    $newtitle = html_entity_decode(TPgetlangOption($context['TPortal']['blockedit']['lang'], $context['user']['language']));
    if (empty($newtitle)) {
        $newtitle = html_entity_decode($context['TPortal']['blockedit']['title']);
    }
    echo '
	<form accept-charset="', $context['character_set'], '" name="tpadmin_news" enctype="multipart/form-data" action="' . $scripturl . '?action=tpadmin" method="post" style="margin: 0px;" onsubmit="submitonce(this);">
		<input type="hidden" name="sc" value="', $context['session_id'], '" />
		<input name="tpadmin_form" type="hidden" value="blockedit">
		<input name="tpadmin_form_id" type="hidden" value="' . $context['TPortal']['blockedit']['id'] . '">
		<table class="admintable">
			<caption class="catbg">' . $txt['tp-editblock'] . '</caption>
			<tbody>
				<tr>
					<td style="padding: 0; border: none;">
						<table class="formtable" id="editblock">
							<caption class="titlebg">
								<a href="', $scripturl, '?action=tpadmin;sa=blocks">', $txt['tp-gobackallblocks'], '</a>
							</caption>
							<tr class="windowbg2">
								<td class="left">
									<input style="float: left;" type="submit" value="' . $txt['tp-send'] . '" />
									', $txt['tp-status'], ':
								</td>
								<td class="right"><img src="' . $settings['tp_images_url'] . '/TP', $context['TPortal']['blockedit']['off'] == 0 ? 'green' : 'red', '.gif" alt="" />
									<input type="radio" value="0" name="tp_block_off"', $context['TPortal']['blockedit']['off'] == 0 ? ' checked="checked"' : '', ' />' . $txt['tp-on'] . '
									<input type="radio" value="1" name="tp_block_off"', $context['TPortal']['blockedit']['off'] == 1 ? ' checked="checked"' : '', ' />' . $txt['tp-off'] . '
								</td>
							</tr><tr class="windowbg2">
								<td class="left">' . $txt['tp-title'] . ':</td>
								<td class="right"><input style="width: 94%" name="tp_block_title"  type="text" value="' . $newtitle . '">
							</tr><tr class="windowbg2">
								<td class="left">', $txt['tp-type'] . ':</td>
								<td class="right">
									<select size="1" onchange="document.getElementById(\'blocknotice\').style.display=\'\';" name="tp_block_type">
										<option value="0"', $context['TPortal']['blockedit']['type'] == '0' ? ' selected' : '', '>', $txt['tp-blocktype0'], '</option>
										<option value="1"', $context['TPortal']['blockedit']['type'] == '1' ? ' selected' : '', '>', $txt['tp-blocktype1'], '</option>
										<option value="2"', $context['TPortal']['blockedit']['type'] == '2' ? ' selected' : '', '>', $txt['tp-blocktype2'], '</option>
										<option value="3"', $context['TPortal']['blockedit']['type'] == '3' ? ' selected' : '', '>', $txt['tp-blocktype3'], '</option>
										<option value="4"', $context['TPortal']['blockedit']['type'] == '4' ? ' selected' : '', '>', $txt['tp-blocktype4'], '</option>
										<option value="5"', $context['TPortal']['blockedit']['type'] == '5' ? ' selected' : '', '>', $txt['tp-blocktype5'], '</option>
										<option value="6"', $context['TPortal']['blockedit']['type'] == '6' ? ' selected' : '', '>', $txt['tp-blocktype6'], '</option>
										<option value="7"', $context['TPortal']['blockedit']['type'] == '7' ? ' selected' : '', '>', $txt['tp-blocktype7'], '</option>
										<option value="9"', $context['TPortal']['blockedit']['type'] == '9' ? ' selected' : '', '>', $txt['tp-blocktype9'], '</option>
										<option value="10"', $context['TPortal']['blockedit']['type'] == '10' ? ' selected' : '', '>', $txt['tp-blocktype10'], '</option>
										<option value="11"', $context['TPortal']['blockedit']['type'] == '11' ? ' selected' : '', '>', $txt['tp-blocktype11'], '</option>
										<option value="12"', $context['TPortal']['blockedit']['type'] == '12' ? ' selected' : '', '>', $txt['tp-blocktype12'], '</option>
										<option value="13"', $context['TPortal']['blockedit']['type'] == '13' ? ' selected' : '', '>', $txt['tp-blocktype13'], '</option>
										<option value="14"', $context['TPortal']['blockedit']['type'] == '14' ? ' selected' : '', '>', $txt['tp-blocktype14'], '</option>
										<option value="15"', $context['TPortal']['blockedit']['type'] == '15' ? ' selected' : '', '>', $txt['tp-blocktype15'], '</option>
										<option value="16"', $context['TPortal']['blockedit']['type'] == '16' ? ' selected' : '', '>', $txt['tp-blocktype16'], '</option>
										<option value="18"', $context['TPortal']['blockedit']['type'] == '18' ? ' selected' : '', '>', $txt['tp-blocktype18'], '</option>
										<option value="19"', $context['TPortal']['blockedit']['type'] == '19' ? ' selected' : '', '>', $txt['tp-blocktype19'], '</option>
										<option value="20"', $context['TPortal']['blockedit']['type'] == '20' ? ' selected' : '', '>', $txt['tp-blocktype20'], '</option>';
    // theme hooks
    if (function_exists('ctheme_tp_blocks')) {
        ctheme_tp_blocks('listblocktypes');
    }
    echo '
									</select>
								</td>
							</tr><tr class="windowbg2">
								<td class="left"><td class="right">
									<div id="blocknotice" class="smallpadding error middletext" style="display: none;">', $txt['tp-blocknotice'], '</a>
										
									</div>
								</td>
							</tr><tr class="windowbg2">
								<td class="left">';
    if ($context['TPortal']['blockedit']['type'] == '5' || $context['TPortal']['blockedit']['type'] == '10' || $context['TPortal']['blockedit']['type'] == '11') {
        if ($context['TPortal']['blockedit']['type'] == '11') {
            echo '
						</td><td class="right">';
            if ($context['TPortal']['use_wysiwyg'] > 0) {
                TPwysiwyg('tp_block_body', $context['TPortal']['blockedit']['body'], true, 'qup_blockbody', 1, false);
            } else {
                echo $txt['tp-body'], ' <br /><textarea style="width: 94%;" name="tp_block_body" id="tp_block_body" rows="15" cols="40" wrap="auto">', $context['TPortal']['blockedit']['body'], '</textarea>';
            }
        } elseif ($context['TPortal']['blockedit']['type'] == '5') {
            echo '
						</td><td class="right">';
            TP_bbcbox($context['TPortal']['editor_id']);
        } else {
            echo $txt['tp-body'];
        }
        if ($context['TPortal']['blockedit']['type'] == '10') {
            echo '
						</td><td class="right">
						<textarea style="width: 94%;" name="tp_block_body" id="tp_block_body" rows="15" cols="40" wrap="auto">', $context['TPortal']['blockedit']['body'], '</textarea>
						<p><div class="tborder" style="padding: 1em;"><p style="padding: 0 0 5px 0; margin: 0;">', $txt['tp-blockcodes'], ':</p>
							<select name="tp_blockcode" id="tp_blockcode" size="8" style="margin-bottom: 5px; width: 100%" onchange="changeSnippet(this.selectedIndex);">
								<option value="0" selected="selected">', $txt['tp-none-'], '</option>';
            if (!empty($context['TPortal']['blockcodes'])) {
                foreach ($context['TPortal']['blockcodes'] as $bc) {
                    echo '
								<option value="', $bc['file'], '">', $bc['name'], '</option>';
                }
            }
            echo '
							</select>
							<input type="button" value="', $txt['tp-insert'], '" name="blockcode_save" onclick="submit();" />
							<input type="checkbox" value="' . $context['TPortal']['blockedit']['id'] . '" name="blockcode_overwrite" /> ', $txt['tp-blockcodes_overwrite'], '
						</div>
						</p><br />
					<div id="blockcodeinfo" class="description" >&nbsp;</div>
					<script type="text/javascript"><!-- // --><![CDATA[
						function changeSnippet(indx)
						{
							var snipp = new Array();
							var snippAuthor = new Array();
							var snippTitle = new Array();
							snipp[0] = "";
							snippAuthor[0] = "";
							snippTitle[0] = "";';
            $count = 1;
            foreach ($context['TPortal']['blockcodes'] as $bc) {
                $what = str_replace(array(",", ".", "/", "\n"), array("&#44;", "&#46;", "&#47;", ""), $bc['text']);
                echo '
							snipp[' . $count . '] = "<div>' . $what . '</div>";  
							snippTitle[' . $count . '] = "<h3 style=\\"margin: 0 0 5px 0; padding: 0;\\">' . $bc['name'] . ' <span style=\\"font-weight: normal;\\">' . $txt['tp-by'] . '</span> ' . $bc['author'] . '</h3>";  
							';
                $count++;
            }
            echo '

							setInnerHTML(document.getElementById("blockcodeinfo"), snippTitle[indx] + snipp[indx]);
						}
					// ]]></script>';
        }
    } elseif ($context['TPortal']['blockedit']['type'] == '12') {
        if (!is_numeric($context['TPortal']['blockedit']['body'])) {
            $context['TPortal']['blockedit']['body'] = 10;
        }
        echo $txt['tp-numberofrecenttopics'] . '</td><td class="right"><input style="width: 50px;" name="tp_block_body" value="' . $context['TPortal']['blockedit']['body'] . '">
					</td><tr class="windowbg2"><td class="left">' . $txt['tp-rssblock-showavatar'] . '</td><td class="right">
					<input name="tp_block_var1" type="radio" value="0" ', $context['TPortal']['blockedit']['var1'] == '0' ? ' checked' : '', '>' . $txt['tp-no'] . '
					<input name="tp_block_var1" type="radio" value="1" ', $context['TPortal']['blockedit']['var1'] == '1' || $context['TPortal']['blockedit']['var1'] == '' ? ' checked' : '', '>' . $txt['tp-yes'] . '<br />';
    } elseif ($context['TPortal']['blockedit']['type'] == '13') {
        // SSI block..which function?
        if (!in_array($context['TPortal']['blockedit']['body'], array('recentpoll', 'toppoll', 'topposters', 'topboards', 'topreplies', 'topviews', 'calendar'))) {
            $context['TPortal']['blockedit']['body'] = '';
        }
        echo '
						</td><td class="right">';
        echo '<input name="tp_block_body" type="radio" value="" ', $context['TPortal']['blockedit']['body'] == '' ? 'checked' : '', '>' . $txt['tp-none-'];
        echo '<br /><input name="tp_block_body" type="radio" value="topboards" ', $context['TPortal']['blockedit']['body'] == 'topboards' ? 'checked' : '', '>' . $txt['tp-ssi-topboards'];
        echo '<br /><input name="tp_block_body" type="radio" value="topposters" ', $context['TPortal']['blockedit']['body'] == 'topposters' ? 'checked' : '', '>' . $txt['tp-ssi-topposters'];
        echo '<br /><input name="tp_block_body" type="radio" value="topreplies" ', $context['TPortal']['blockedit']['body'] == 'topreplies' ? 'checked' : '', '>' . $txt['tp-ssi-topreplies'];
        echo '<br /><input name="tp_block_body" type="radio" value="topviews" ', $context['TPortal']['blockedit']['body'] == 'topviews' ? 'checked' : '', '>' . $txt['tp-ssi-topviews'];
        echo '<br /><input name="tp_block_body" type="radio" value="calendar" ', $context['TPortal']['blockedit']['body'] == 'calendar' ? 'checked' : '', '>' . $txt['tp-ssi-calendar'];
        echo '<hr />';
    } elseif ($context['TPortal']['blockedit']['type'] == '20') {
        // TP modules
        echo '
						</td><td class="right">';
        foreach ($context['TPortal']['tpmodules']['blockrender'] as $tpm) {
            echo '<br /><input name="tp_block_var1" type="radio" value="' . $tpm['id'] . '" ', $context['TPortal']['blockedit']['var1'] == $tpm['id'] ? 'checked' : '', '>' . $tpm['name'];
        }
    } elseif ($context['TPortal']['blockedit']['type'] == '14') {
        // Module block...choose module and module ID , check if module is active
        echo '
						</td><td class="right">';
        echo '<input name="tp_block_body" type="radio" value="dl-stats" ', $context['TPortal']['blockedit']['body'] == 'dl-stats' ? 'checked' : '', '>' . $txt['tp-module1'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats2" ', $context['TPortal']['blockedit']['body'] == 'dl-stats2' ? 'checked' : '', '>' . $txt['tp-module2'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats3" ', $context['TPortal']['blockedit']['body'] == 'dl-stats3' ? 'checked' : '', '>' . $txt['tp-module3'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats4" ', $context['TPortal']['blockedit']['body'] == 'dl-stats4' ? 'checked' : '', '>' . $txt['tp-module4'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats5" ', $context['TPortal']['blockedit']['body'] == 'dl-stats5' ? 'checked' : '', '>' . $txt['tp-module5'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats6" ', $context['TPortal']['blockedit']['body'] == 'dl-stats6' ? 'checked' : '', '>' . $txt['tp-module6'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats7" ', $context['TPortal']['blockedit']['body'] == 'dl-stats7' ? 'checked' : '', '>' . $txt['tp-module7'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats8" ', $context['TPortal']['blockedit']['body'] == 'dl-stats8' ? 'checked' : '', '>' . $txt['tp-module8'];
        echo '<br /><input name="tp_block_body" type="radio" value="dl-stats9" ', $context['TPortal']['blockedit']['body'] == 'dl-stats9' ? 'checked' : '', '>' . $txt['tp-module9'] . '<br />';
    } elseif ($context['TPortal']['blockedit']['type'] == '3') {
        // userbox type
        echo $txt['tp-showuserbox'] . '</td><td class="right">';
        if (isset($context['TPortal']['userbox']['avatar']) && $context['TPortal']['userbox']['avatar']) {
            echo '<input name="tp_userbox_options0" type="hidden" value="avatar">';
        }
        if (isset($context['TPortal']['userbox']['logged']) && $context['TPortal']['userbox']['logged']) {
            echo '<input name="tp_userbox_options1" type="hidden" value="logged">';
        }
        if (isset($context['TPortal']['userbox']['time']) && $context['TPortal']['userbox']['time']) {
            echo '<input name="tp_userbox_options2" type="hidden" value="time">';
        }
        if (isset($context['TPortal']['userbox']['unread']) && $context['TPortal']['userbox']['unread']) {
            echo '<input name="tp_userbox_options3" type="hidden" value="unread">';
        }
        echo '<input name="tp_userbox_options4" type="checkbox" value="stats" ', isset($context['TPortal']['userbox']['stats']) && $context['TPortal']['userbox']['stats'] ? 'checked' : '', '> ' . $txt['tp-userbox5'] . '<br />';
        echo '<input name="tp_userbox_options5" type="checkbox" value="online" ', isset($context['TPortal']['userbox']['online']) && $context['TPortal']['userbox']['online'] ? 'checked' : '', '> ' . $txt['tp-userbox6'] . '<br />';
        echo '<input name="tp_userbox_options6" type="checkbox" value="stats_all" ', isset($context['TPortal']['userbox']['stats_all']) && $context['TPortal']['userbox']['stats_all'] ? 'checked' : '', '> ' . $txt['tp-userbox7'] . '<br />
					';
    } elseif ($context['TPortal']['blockedit']['type'] == '1') {
        // userbox type
        echo $txt['tp-showuserbox2'] . '</td><td class="right">
					<input name="tp_userbox_options0" type="checkbox" value="avatar" ', isset($context['TPortal']['userbox']['avatar']) && $context['TPortal']['userbox']['avatar'] ? 'checked' : '', '> ' . $txt['tp-userbox1'] . '<br />';
        echo '<input name="tp_userbox_options1" type="checkbox" value="logged" ', isset($context['TPortal']['userbox']['logged']) && $context['TPortal']['userbox']['logged'] ? 'checked' : '', '> ' . $txt['tp-userbox2'] . '<br />';
        echo '<input name="tp_userbox_options2" type="checkbox" value="time" ', isset($context['TPortal']['userbox']['time']) && $context['TPortal']['userbox']['time'] ? 'checked' : '', '> ' . $txt['tp-userbox3'] . '<br />';
        echo '<input name="tp_userbox_options3" type="checkbox" value="unread" ', isset($context['TPortal']['userbox']['unread']) && $context['TPortal']['userbox']['unread'] ? 'checked' : '', '> ' . $txt['tp-userbox4'] . '<br />';
        if (isset($context['TPortal']['userbox']['stats']) && $context['TPortal']['userbox']['stats']) {
            echo '<input name="tp_userbox_options4" type="hidden" value="stats">';
        }
        if (isset($context['TPortal']['userbox']['online']) && $context['TPortal']['userbox']['online']) {
            echo '<input name="tp_userbox_options5" type="hidden" value="online">';
        }
        if (isset($context['TPortal']['userbox']['stats_all']) && $context['TPortal']['userbox']['stats_all']) {
            echo '<input name="tp_userbox_options6" type="hidden" value="stats_all">';
        }
    } elseif ($context['TPortal']['blockedit']['type'] == '15') {
        echo $txt['tp-rssblock'] . '
						</td><td class="right">';
        // RSS feed type
        echo '<input style="width: 95%" name="tp_block_body" value="' . $context['TPortal']['blockedit']['body'] . '"><br /><br />
						</td>
					<tr class="windowbg2">
						<td class="left">', $txt['tp-rssblock-useutf8'] . '<br /></td><td class="right">
					<input name="tp_block_var1" type="radio" value="1" ', $context['TPortal']['blockedit']['var1'] == '1' ? ' checked' : '', '>' . $txt['tp-utf8'] . '
					<input name="tp_block_var1" type="radio" value="0" ', $context['TPortal']['blockedit']['var1'] == '0' || $context['TPortal']['blockedit']['var1'] == '' ? ' checked' : '', '>' . $txt['tp-iso'] . '<br /><br />
					</td></tr>
						<tr class="windowbg2"><td class="left">' . $txt['tp-rssblock-showonlytitle'] . '</td><td class="right">
					<input name="tp_block_var2" type="radio" value="1" ', $context['TPortal']['blockedit']['var2'] == '1' ? ' checked' : '', '>' . $txt['tp-yes'] . '
					<input name="tp_block_var2" type="radio" value="0" ', $context['TPortal']['blockedit']['var2'] == '0' || $context['TPortal']['blockedit']['var2'] == '' ? ' checked' : '', '>' . $txt['tp-no'], '
					</td></tr>
						<tr class="windowbg2"><td class="left">' . $txt['tp-rssblock-maxwidth'] . '</td><td class="right">
					<input name="tp_block_var3" type="text" value="', $context['TPortal']['blockedit']['var3'], '"><br />';
    } elseif ($context['TPortal']['blockedit']['type'] == '16') {
        echo $txt['tp-sitemapmodules'] . '</td><td class="right"><ul>';
        if ($context['TPortal']['show_download'] == '1') {
            echo '<li>' . $txt['tp-dldownloads'] . '</li>';
        }
        echo '</ul>';
    } elseif ($context['TPortal']['blockedit']['type'] == '18') {
        // check to see if it is numeric
        if (!is_numeric($context['TPortal']['blockedit']['body'])) {
            $lblock['body'] = '';
        }
        echo $txt['tp-showarticle'], '</td><td class="right">
				<select name="tp_block_body">';
        foreach ($context['TPortal']['edit_articles'] as $art => $article) {
            echo '<option value="' . $article['id'] . '" ', $context['TPortal']['blockedit']['body'] == $article['id'] ? ' selected="selected"' : '', ' >' . html_entity_decode($article['subject']) . '</option>';
        }
        echo '</select>';
    } elseif ($context['TPortal']['blockedit']['type'] == '7') {
        // get the ids
        $myt = array();
        $thems = explode(",", $context['TPortal']['blockedit']['body']);
        foreach ($thems as $g => $gh) {
            $wh = explode("|", $gh);
            $myt[] = $wh[0];
        }
        echo '
						</td><td class="right">
				<input type="hidden" name="blockbody' . $context['TPortal']['blockedit']['id'] . '" value="' . $context['TPortal']['blockedit']['body'] . '" />
				<div  style="padding: 5px;">
					<div style="max-height: 25em; overflow: auto;">
							<input name="tp_theme-1" type="hidden" value="-1">
							<input type="hidden" value="1" name="tp_tpath-1">';
        foreach ($context['TPthemes'] as $tema) {
            echo '
							<img style="width: 35px; height: 35px;" alt="*" src="' . $tema['path'] . '/thumbnail.gif" /> <input name="tp_theme' . $tema['id'] . '" type="checkbox" value="' . $tema['name'] . '"';
            if (in_array($tema['id'], $myt)) {
                echo ' checked';
            }
            echo '>' . $tema['name'] . '<input type="hidden" value="' . $tema['path'] . '" name="tp_path' . $tema['id'] . '"><br />';
        }
        echo '</div><hr /><input type="checkbox" onclick="invertAll(this, this.form, \'tp_theme\');" />' . $txt['tp-checkall'], '
				</div>';
    } elseif ($context['TPortal']['blockedit']['type'] == '19') {
        // check to see if it is numeric
        if (!is_numeric($context['TPortal']['blockedit']['body'])) {
            $lblock['body'] = '';
        }
        if (!is_numeric($context['TPortal']['blockedit']['var1'])) {
            $lblock['var1'] = '15';
        }
        if ($context['TPortal']['blockedit']['var1'] == '0') {
            $lblock['var1'] = '15';
        }
        echo $txt['tp-showcategory'], '</td><td class="right">
				<select name="tp_block_body">';
        foreach ($context['TPortal']['catnames'] as $cat => $catname) {
            echo '<option value="' . $cat . '" ', $context['TPortal']['blockedit']['body'] == $cat ? ' selected' : '', ' >' . html_entity_decode($catname) . '</option>';
        }
        echo '</select><br /><br /><br />';
        echo $txt['tp-catboxheight'] . '
					<input name="tp_block_var1" size="4" type="text" value="', $context['TPortal']['blockedit']['var1'], '"> em<br />';
        echo $txt['tp-catboxauthor'] . '
                    <input name="tp_block_var2" type="radio" value="1" ', $context['TPortal']['blockedit']['var2'] == '1' ? 'checked' : '', '> ', $txt['tp-yes'], '
					<input name="tp_block_var2" type="radio" value="0" ', $context['TPortal']['blockedit']['var2'] == '0' ? 'checked' : '', '> ', $txt['tp-no'], '<br />';
    } elseif ($context['TPortal']['blockedit']['type'] == '9') {
        // check to see if it is numeric
        if (!is_numeric($context['TPortal']['blockedit']['body'])) {
            $lblock['body'] = '0';
        }
        echo $txt['tp-showmenus'], '</td><td class="right"> 
					<select name="tp_block_body">';
        foreach ($context['TPortal']['menus'] as $men) {
            echo '
						<option value="' . $men['id'] . '" ', $context['TPortal']['blockedit']['body'] == $men['id'] ? ' selected' : '', ' >' . $men['name'] . '</option>';
        }
        echo '
					</select><br />', $txt['tp-showmenustyle'], ' <br />
					<input name="tp_block_var1" type="radio" value="0" ', $context['TPortal']['blockedit']['var1'] == '' || $context['TPortal']['blockedit']['var1'] == '0' ? ' checked' : '', ' ><img src="', $boardurl, '/tp-images/icons/TPdivider2.gif" alt="" /><br />
					<input name="tp_block_var1" type="radio" value="1" ', $context['TPortal']['blockedit']['var1'] == '1' ? ' checked' : '', ' ><img src="', $boardurl, '/tp-images/icons/bullet3.gif" alt="" /><br />
					<input name="tp_block_var1" type="radio" value="2" ', $context['TPortal']['blockedit']['var1'] == '2' ? ' checked' : '', ' >' . $txt['tp-none-'] . '<br />
					';
    } elseif ($context['TPortal']['blockedit']['type'] == '6') {
        echo $txt['tp-rssblock-showavatar'] . '</td><td class="right">
					<input name="tp_block_var1" type="radio" value="0" ', $context['TPortal']['blockedit']['var1'] == '0' ? ' checked' : '', '>' . $txt['tp-no'] . '
					<input name="tp_block_var1" type="radio" value="1" ', $context['TPortal']['blockedit']['var1'] == '1' || $context['TPortal']['blockedit']['var1'] == '' ? ' checked' : '', '>' . $txt['tp-yes'] . '<br />';
    } elseif ($context['TPortal']['blockedit']['type'] > '50' && function_exists('ctheme_tp_blocks')) {
        ctheme_tp_blocks('blockoptions');
    } else {
        echo '
			</td><td class="right">';
    }
    echo '
								</td>
							</tr><tr>
							<td class="left windowbg2">' . $txt['tp-blockstylehelp'] . ':</td>
							<td class="right">
			<div style="overflow: hidden; padding: 5px;">';
    if (function_exists('ctheme_tp_getblockstyles')) {
        $types = ctheme_tp_getblockstyles();
    } else {
        $types = tp_getblockstyles();
    }
    foreach ($types as $blo => $bl) {
        echo '
			<div style="float: left; width: 160px; height: 100px; margin: 5px;">
				<div class="smalltext" style="padding: 4px 0;"><input name="tp_block_var4" type="radio" value="' . $blo . '" ', $context['TPortal']['blockedit']['var4'] == $blo ? 'checked' : '', '><span', $context['TPortal']['blockedit']['var4'] == $blo ? ' style="color: red;">' : '>', $bl['class'], '</span>
				</div>' . $bl['code_title_left'] . 'title' . $bl['code_title_right'] . '
				' . $bl['code_top'] . 'body' . $bl['code_bottom'] . '
			</div>';
    }
    echo '
			</div>
								</td>
							</tr><tr class="windowbg2">
								<td class="left">' . $txt['tp-blockframehelp'] . ':</td>
								<td class="right">
				<input name="tp_block_frame" type="radio" value="theme" ', $context['TPortal']['blockedit']['frame'] == 'theme' ? 'checked' : '', '> ' . $txt['tp-useframe'] . '<br />
				<input name="tp_block_frame" type="radio" value="frame" ', $context['TPortal']['blockedit']['frame'] == 'frame' ? 'checked' : '', '> ' . $txt['tp-useframe2'] . ' <br />
				<input name="tp_block_frame" type="radio" value="title" ', $context['TPortal']['blockedit']['frame'] == 'title' ? 'checked' : '', '> ' . $txt['tp-usetitle'] . ' <br />
				<input name="tp_block_frame" type="radio" value="none" ', $context['TPortal']['blockedit']['frame'] == 'none' ? 'checked' : '', '> ' . $txt['tp-noframe'] . '<br />';
    echo '			</td>
							</tr><tr class="windowbg2">
								<td class="left"></td>
								<td class="right">
				<input name="tp_block_visible" type="radio" value="1" ', $context['TPortal']['blockedit']['visible'] == '' || $context['TPortal']['blockedit']['visible'] == '1' ? 'checked' : '', '> ' . $txt['tp-allowupshrink'] . '<br />
				<input name="tp_block_visible" type="radio" value="0" ', $context['TPortal']['blockedit']['visible'] == '0' ? 'checked' : '', '> ' . $txt['tp-notallowupshrink'] . '<br />
							</td>
							</tr><tr class="windowbg2">
							<td class="left"> ' . $txt['tp-membergrouphelp'] . '</td><td class="right">
							<div style="padding: 5px; overflow: auto; max-height: 10em;">';
    // loop through and set membergroups
    $tg = explode(',', $context['TPortal']['blockedit']['access']);
    if (!empty($context['TPmembergroups'])) {
        foreach ($context['TPmembergroups'] as $mg) {
            if ($mg['posts'] == '-1' && $mg['id'] != '1') {
                echo '<input name="tp_group' . $mg['id'] . '" type="checkbox" value="' . $context['TPortal']['blockedit']['id'] . '"';
                if (in_array($mg['id'], $tg)) {
                    echo ' checked';
                }
                echo '> ' . $mg['name'] . ' <br />';
            }
        }
    }
    // if none is chosen, have a control value
    echo '</div><hr /><input type="checkbox" onclick="invertAll(this, this.form, \'tp_group\');" />' . $txt['tp-checkall'] . '<br /><br />';
    //edit membergroups
    echo '
			</td></tr><tr class="windowbg2"><td class="left">' . $txt['tp-editgrouphelp'] . '</td><td class="right">
					<div style="padding: 5px; max-height: 10em; overflow: auto;">';
    $tg = explode(',', $context['TPortal']['blockedit']['editgroups']);
    foreach ($context['TPmembergroups'] as $mg) {
        if ($mg['posts'] == '-1' && $mg['id'] != '1' && $mg['id'] != '-1' && $mg['id'] != '0') {
            echo '<input name="tp_editgroup' . $mg['id'] . '" type="checkbox" value="' . $context['TPortal']['blockedit']['id'] . '"';
            if (in_array($mg['id'], $tg)) {
                echo ' checked';
            }
            echo '> ' . $mg['name'] . ' <br />';
        }
    }
    // if none is chosen, have a control value
    echo '</div><hr /><input type="checkbox" onclick="invertAll(this, this.form, \'tp_editgroup\');" />' . $txt['tp-checkall'];
    echo '
						</td>
					</tr><tr class="windowbg2"><td class="left">' . $txt['tp-langhelp'] . '</td><td class="right">';
    foreach ($context['TPortal']['langfiles'] as $langlist => $lang) {
        if ($lang != $context['user']['language'] && $lang != '') {
            echo '<input name="tp_lang_' . $lang . '" type="text" value="', !empty($context['TPortal']['blockedit']['langfiles'][$lang]) ? html_entity_decode($context['TPortal']['blockedit']['langfiles'][$lang], ENT_QUOTES) : html_entity_decode($context['TPortal']['blockedit']['title'], ENT_QUOTES), '"> ' . $lang . '<br />';
        }
    }
    echo '
						</td>
					</tr>';
    if ($context['TPortal']['blockedit']['bar'] != 4) {
        // extended visible options
        echo '
					<tr class="windowbg2">
						<td class="left">' . $txt['tp-access2help'] . '</td><td class="right">
						', tp_hidepanel('blockopts', true), '
				', empty($context['TPortal']['blockedit']['access22']) ? '<div class="tborder error" style="margin: 1em 0; padding: 4px 4px 4px 20px;">' . $txt['tp-noaccess'] . '</div>' : '', ' 
						<fieldset class="tborder" id="blockopts" ', in_array('blockopts', $context['tp_panels']) ? ' style="display: none;"' : '', '>
						<input type="hidden" name="TPadmin_blocks_vo" value="' . $mg['id'] . '" />';
        if (!empty($context['TPortal']['return_url'])) {
            echo '
							<input type="hidden" name="fromblockpost" value="' . $context['TPortal']['return_url'] . '" />';
        }
        echo '
							<table class="admintable windowbg2">
								<tr class="windowbg2">
									<td width="50%" valign="top"><h4>' . $txt['tp-actions'] . ':</h4>
											<input name="actiontype1" type="checkbox" value="allpages" ', in_array('allpages', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-allpages'] . '<br /><br />
											<input name="actiontype2" type="checkbox" value="frontpage" ', in_array('frontpage', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-frontpage'] . '<br />
											<input name="actiontype3" type="checkbox" value="forumall" ', in_array('forumall', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-forumall'] . '<br />
											<input name="actiontype4" type="checkbox" value="forum" ', in_array('forum', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-forumfront'] . '<br />
											<input name="actiontype5" type="checkbox" value="recent" ', in_array('recent', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-recent'] . '<br />
											<input name="actiontype6" type="checkbox" value="unread" ', in_array('unread', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-unread'] . '<br />
											<input name="actiontype7" type="checkbox" value="unreadreplies" ', in_array('unreadreplies', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-unreadreplies'] . '<br />
											<input name="actiontype8" type="checkbox" value="profile" ', in_array('profile', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['profile'] . '<br />
											<input name="actiontype9" type="checkbox" value="pm" ', in_array('pm', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['pm_short'] . '<br />
									</td><td valign="bottom">		
											<input name="actiontype10" type="checkbox" value="calendar" ', in_array('calendar', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['calendar'] . '<br />
											<input name="actiontype11" type="checkbox" value="admin" ', in_array('admin', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['admin'] . '<br />
											<input name="actiontype12" type="checkbox" value="login" ', in_array('login', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['login'] . '<br />
											<input name="actiontype13" type="checkbox" value="logout" ', in_array('logout', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['logout'] . '<br />
											<input name="actiontype14" type="checkbox" value="register" ', in_array('register', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['register'] . '<br />
											<input name="actiontype15" type="checkbox" value="post" ', in_array('post', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['post'] . '<br />
											<input name="actiontype16" type="checkbox" value="stats" ', in_array('stats', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-stats'] . '<br />
											<input name="actiontype17" type="checkbox" value="search" ', in_array('search', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['search'] . '<br />
											<input name="actiontype18" type="checkbox" value="mlist" ', in_array('mlist', $context['TPortal']['blockedit']['access2']['action']) ? 'checked="checked"' : '', '>' . $txt['tp-memberlist'] . '<br /><br />';
        // add the custom ones you added
        $count = 19;
        foreach ($context['TPortal']['blockedit']['access2']['action'] as $po => $p) {
            if (!in_array($p, array('allpages', 'frontpage', 'forumall', 'forum', 'recent', 'unread', 'unreadreplies', 'profile', 'pm', 'calendar', 'admin', 'login', 'logout', 'register', 'post', 'stats', 'mlist'))) {
                echo '<input name="actiontype' . $count . '" type="checkbox" value="' . $p . '" checked="checked">' . $p . '<br />';
                $count++;
            }
        }
        echo '
							<p>' . $txt['tp-customactions'] . '</p>
								<input style="width: 90%;" type="text" name="custotype0" value="">
								</td>
								</tr>
								<tr class="windowbg2">
									<td valign="top"><h4>Boards:</h4><div class="tp_largelist">';
        $a = 1;
        if (!empty($context['TPortal']['boards'])) {
            echo '<input type="checkbox" name="boardtype', $a, '" value="-1" ', in_array('-1', $context['TPortal']['blockedit']['access2']['board']) ? 'checked="checked"' : '', '>' . $txt['tp-allboards'] . '<br /><br />';
            $a++;
            foreach ($context['TPortal']['boards'] as $bb) {
                echo '
											<input type="checkbox" name="boardtype', $a, '" value="' . $bb['id'] . '" ', in_array($bb['id'], $context['TPortal']['blockedit']['access2']['board']) ? 'checked="checked"' : '', '>' . $bb['name'] . '<br />';
                $a++;
            }
        }
        echo '
									</div></td>
									<td valign="top"><h4>' . $txt['tp-articles'] . ':</h4><div class="tp_largelist">';
        $a = 1;
        foreach ($context['TPortal']['edit_articles'] as $bb) {
            echo '
										<input type="checkbox" name="articletype', $a, '" value="' . $bb['id'] . '" ', in_array($bb['id'], $context['TPortal']['blockedit']['access2']['page']) ? 'checked="checked"' : '', '>' . html_entity_decode($bb['subject'], ENT_QUOTES) . '<br />';
            $a++;
        }
        echo '
									</div></td>
								</tr>
								<tr class="windowbg2">
									<td valign="top"><h4>' . $txt['tp-artcat'] . ':</h4><div class="tp_largelist">';
        $a = 1;
        if (isset($context['TPortal']['article_categories'])) {
            foreach ($context['TPortal']['article_categories'] as $bb) {
                echo '
											<input type="checkbox" name="categorytype' . $a . '" value="' . $bb['id'] . '" ', in_array($bb['id'], $context['TPortal']['blockedit']['access2']['cat']) ? 'checked="checked"' : '', '>' . $bb['name'] . '<br />';
                $a++;
            }
        }
        echo '
									</div></td>
									<td valign="top"><h4>' . $txt['tp-lang'] . ':</h4>';
        // alert if the settings is off, supply link if allowed
        if (empty($context['TPortal']['uselangoption'])) {
            echo '
					<p class="error">', $txt['tp-uselangoption2'], ' ', allowedTo('tp_settings') ? '<a href="' . $scripturl . '?action=tpadmin;sa=settings#uselangoption">[' . $txt['tp-settings'] . ']</a>' : '', '</p>';
        }
        $a = 1;
        foreach ($context['TPortal']['langfiles'] as $bb => $lang) {
            echo '
											<input type="checkbox" name="langtype' . $a . '" value="' . $lang . '" ', in_array($lang, $context['TPortal']['blockedit']['access2']['lang']) ? 'checked="checked"' : '', '>' . $lang . '<br />';
            $a++;
        }
        echo '
									</td>
								</tr>
								<tr class="windowbg2">
									<td>
									<h4>' . $txt['tp-dlmanager'] . ':</h4><div class="tp_largelist">';
        $a = 1;
        if (!empty($context['TPortal']['dlcats'])) {
            $a++;
            foreach ($context['TPortal']['dlcats'] as $bb) {
                echo '
								<input type="checkbox" name="dlcattype', $a, '" value="' . $bb['id'] . '" ', in_array($bb['id'], $context['TPortal']['blockedit']['access2']['dlcat']) ? 'checked="checked"' : '', '>' . $bb['name'] . '<br />';
                $a++;
            }
        }
        echo '
									</div></td>
									<td valign="top">
									<h4>' . $txt['tp-modules'] . '</h4><div class="tp_largelist">';
        $a = 1;
        if (!empty($context['TPortal']['tpmods'])) {
            $a++;
            foreach ($context['TPortal']['tpmods'] as $bb) {
                echo '
								<input type="checkbox" name="tpmodtype', $a, '" value="' . $bb['subquery'] . '" ', in_array($bb['subquery'], $context['TPortal']['blockedit']['access2']['tpmod']) ? 'checked="checked"' : '', '>' . $bb['title'] . '<br />';
                $a++;
            }
        }
        echo '
									</fieldset></td>
								</tr>
							</table>
						</div>
						</td>
					 </tr>';
    }
    echo '
						</table>
					</td>
				</tr>
			</tbody>
			<tfoot>
				<tr class="windowbg2">
					<td class="windowbg3"><input type="submit" value="' . $txt['tp-send'] . '" name="' . $txt['tp-send'] . '">
					</td>
				</tr>
			</tfoot>
		</table>
	</form>';
}
/**
 * @package TinyPortal
 * @version 1.1
 * @author IchBin - http://www.tinyportal.net
 * @founder Bloc
 * @license MPL 2.0
 *
 * The contents of this file are subject to the Mozilla Public License Version 2.0
 * (the "License"); you may not use this package except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Copyright (C) 2015 - The TinyPortal Team
 *
 */
function template_main()
{
    global $context, $settings, $options, $txt, $scripturl, $modSettings, $boarddir, $boardurl;
    // setup the screen
    echo '
<div id="dl_adminbox">
	<form accept-charset="', $context['character_set'], '"  name="dl_admin" action="' . $scripturl . '?action=tpmod;dl=admin" enctype="multipart/form-data" method="post" onsubmit="submitonce(this);">	';
    if ($context['TPortal']['dlsub'] == 'admin') {
        echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
			<tr class="catbg">
				<td>x</td>
				<td>' . $txt['tp-dlname'] . '</td>
				<td>' . $txt['tp-dlicon'] . '</td>
				<td>' . $txt['tp-dlfiles'] . '</td>
				<td>' . $txt['tp-dlsubmitted'] . '</td>
				<td>' . $txt['tp-dledit'] . '</td>
			</tr>';
        // output all the categories, sort after childs
        if (isset($context['TPortal']['admcats']) && count($context['TPortal']['admcats']) > 0) {
            foreach ($context['TPortal']['admcats'] as $cat) {
                if ($cat['parent'] == 0) {
                    echo '
			<tr>
				<td valign="top" class="windowbg"><input name="tp_dlcatpos' . $cat['id'] . '" size="2" type="text" value="' . $cat['pos'] . '"></td>
				<td class="windowbg" valign="top"><img src="' . $settings['tp_images_url'] . '/TPboard.gif" alt="" align="top" border="0" style="margin: 0;" /> <a href="' . $cat['href'] . '">' . $cat['name'] . '</a></td>
				<td class="windowbg" valign="top">', !empty($cat['icon']) ? '<img src="' . $cat['icon'] . '" alt="" />' : '', '</td>
				<td class="windowbg" valign="top">' . $cat['items'] . '</td>
				<td class="windowbg" valign="top">' . $cat['submitted'] . '</td>
				<td class="windowbg" valign="top">
					<a href="', $scripturl, '?action=tpmod;dl=cat', $cat['id'], '"><img title="' . $txt['tp-preview'] . '" src="' . $settings['tp_images_url'] . '/TPfilter.gif" alt="" /></a>
					<a href="' . $cat['href2'] . '"><img title="' . $txt['tp-edit'] . '" border="0" src="' . $settings['tp_images_url'] . '/TPconfig_sm.gif" alt="' . $txt['tp-edit'] . '"  /></a>
					<a href="' . $cat['href3'] . '" onclick="javascript:return confirm(\'' . $txt['tp-confirmdelete'] . '\')"><img title="delete" border="0" src="' . $settings['tp_images_url'] . '/TPdelete2.gif" alt=""  /></a>
				</td>
			</tr>';
                }
            }
        }
        echo '
			<tr>
				<td colspan="6" align="center" class="windowbg"><input name="dlsend" type="submit" value="' . $txt['tp-submit'] . '"></td>
			</tr>';
    } elseif ($context['TPortal']['dlsub'] == 'adminsettings') {
        echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
			<tr class="titlebg">
				<td colspan="2">' . $txt['tp-dlsettings'] . '</td>
			</tr>
			<tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlallowedtypes'] . ' :
				</td>
				<td>
					<input style="width: 95%;" name="tp_dl_allowed_types" type="text" value="' . $context['TPortal']['dl_allowed_types'] . '">
				</td>

			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dluselatest'] . ' :
				</td>
				<td>
					<input name="tp_dl_showrecent" type="radio" value="1" ', $context['TPortal']['dl_showlatest'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dl_showrecent" type="radio" value="0" ', $context['TPortal']['dl_showlatest'] == '0' ? 'checked' : '', '>' . $txt['tp-sayno'] . '
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlusestats'] . ' :
				</td>
				<td>
					<input name="tp_dl_showstats" type="radio" value="1" ', $context['TPortal']['dl_showstats'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dl_showstats" type="radio" value="0" ', $context['TPortal']['dl_showstats'] == '0' ? 'checked' : '', '>' . $txt['tp-sayno'] . '
				</td>
			</tr><tr class="windowbg2">
				<td align="right" valign="top" width="35%">
					' . $txt['tp-dlwysiwyg'] . ' :
				</td>
				<td>
					<input name="tp_dl_wysiwyg" type="radio" value="" ', $context['TPortal']['dl_wysiwyg'] == '' ? 'checked' : '', '>' . $txt['tp-no'] . '<br />
					<input name="tp_dl_wysiwyg" type="radio" value="html" ', $context['TPortal']['dl_wysiwyg'] == 'html' ? 'checked' : '', '>' . $txt['tp-yes'] . ', HTML<br />
					<input name="tp_dl_wysiwyg" type="radio" value="bbc" ', $context['TPortal']['dl_wysiwyg'] == 'bbc' ? 'checked' : '', '>' . $txt['tp-yes'] . ', BBC
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlusecategorytext'] . ' :
				</td>
				<td>
					<input name="tp_dl_showcategorytext" type="radio" value="1" ', $context['TPortal']['dl_showcategorytext'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dl_showcategorytext" type="radio" value="0" ', $context['TPortal']['dl_showcategorytext'] == '0' ? 'checked' : '', '>' . $txt['tp-sayno'] . '
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlusefeatured'] . ' :
				</td>
				<td>
					<input name="tp_dl_showfeatured" type="radio" value="1" ', $context['TPortal']['dl_showfeatured'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dl_showfeatured" type="radio" value="0" ', $context['TPortal']['dl_showfeatured'] == '0' ? 'checked' : '', '>' . $txt['tp-sayno'] . '
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlfeatured'] . ' :
				</td>
				<td>
					<select name="tp_dl_featured" size="7">';
        foreach ($context['TPortal']['all_dlitems'] as $item) {
            echo '<option value="' . $item['id'] . '"', $context['TPortal']['dl_featured'] == $item['id'] ? ' selected="selected"' : '', '>' . $item['name'] . '</option>';
        }
        echo '
					</select>
				</td>
			</tr><tr class="windowbg">
				<td colspan="2">
					' . $txt['tp-dlintrotext'] . ' ';
        if ($context['TPortal']['dl_wysiwyg'] == 'html') {
            TPwysiwyg('tp_dl_introtext', $context['TPortal']['dl_introtext'], true, 'qup_tp_dl_introtext', isset($context['TPortal']['usersettings']['wysiwyg']) ? $context['TPortal']['usersettings']['wysiwyg'] : 0);
        } elseif ($context['TPortal']['dl_wysiwyg'] == 'bbc') {
            TP_bbcbox($context['TPortal']['editor_id']);
        } else {
            echo '<textarea name="tp_dl_introtext" style="width: 99%; height: 300px;">' . $context['TPortal']['dl_introtext'] . '</textarea>';
        }
        echo '</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlusescreenshot'] . ' :
				</td>
				<td>
					<input name="tp_dl_usescreenshot" type="radio" value="1" ', $context['TPortal']['dl_usescreenshot'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dl_usescreenshot" type="radio" value="0" ', $context['TPortal']['dl_usescreenshot'] == '0' ? 'checked' : '', '>' . $txt['tp-sayno'] . '
				</td>
			</tr><tr class="windowbg2">
				<td align="right" valign="top" width="35%">
					' . $txt['tp-dlscreenshotsizes'] . ' :
				</td>
				<td>
					<input name="tp_dl_screenshotsize0" type="text" size="3" maxsize="3" value="' . $context['TPortal']['dl_screenshotsize'][0] . '"> x <input name="tp_dl_screenshotsize1" type="text" size="3" maxsize="3" value="' . $context['TPortal']['dl_screenshotsize'][1] . '"> px<br />
					<input name="tp_dl_screenshotsize2" type="text" size="3" maxsize="3" value="' . $context['TPortal']['dl_screenshotsize'][2] . '"> x <input name="tp_dl_screenshotsize3" type="text" size="3" maxsize="3" value="' . $context['TPortal']['dl_screenshotsize'][3] . '"> px<br />
					<input name="tp_dl_screenshotsize4" type="text" size="3" maxsize="3" value="' . $context['TPortal']['dl_screenshotsize'][4] . '"> x <input name="tp_dl_screenshotsize5" type="text" size="3" maxsize="3" value="' . $context['TPortal']['dl_screenshotsize'][5] . '"> px<br />
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlmustapprove'] . ' :
				</td>
				<td>
					<input name="tp_dl_approveonly" type="radio" value="1" ', $context['TPortal']['dl_approve'] == '1' ? 'checked' : '', '>' . $txt['tp-approveyes'] . '&nbsp;&nbsp;
					<input name="tp_dl_approveonly" type="radio" value="0" ', $context['TPortal']['dl_approve'] == '0' ? 'checked' : '', '>' . $txt['tp-approveno'] . '
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlcreatetopic'] . ' :
				</td>
				<td>
					<input name="tp_dl_createtopic" type="radio" value="1" ', $context['TPortal']['dl_createtopic'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dl_createtopic" type="radio" value="0" ', $context['TPortal']['dl_createtopic'] == '0' ? 'checked' : '', '>' . $txt['tp-no'] . '
				</td>
			</tr><tr class="windowbg">
				<td colspan="2">
					<h4 style="margin-bottom: 0;">' . $txt['tp-dlcreatetopicboards'] . '</h4>
				', tp_hidepanel('dl_createboard'), '
				<div class="dl_perm" id="dl_createboard" ', in_array('dl_createboard', $context['tp_panels']) ? ' style="display: none;"' : '', '>
					';
        $brds = explode(",", $context['TPortal']['dl_createtopic_boards']);
        foreach ($context['TPortal']['boards'] as $brd) {
            echo '<div class="perm"><input type="checkbox" value="' . $brd['id'] . '" name="tp_dlboards' . $brd['id'] . '" ', in_array($brd['id'], $brds) ? ' checked="checked"' : '', ' />' . $brd['name'] . '</div>';
        }
        echo '<br style="clear: both;" />
					</div>
				</td>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlallowedsize'] . ' :
				</td>
				<td>
					<input name="tp_dluploadsize" type="text" value="' . $context['TPortal']['dl_max_upload_size'] . '"> Kb
				</td>
            	</tr><tr>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlshowlatest'] . '
				</td>
				<td>
					<input name="tp_dlshowlatest" type="radio" value="1" ', $context['TPortal']['dl_showlatest'] == '1' ? 'checked' : '', '>' . $txt['tp-yes'] . '&nbsp;&nbsp;
					<input name="tp_dlshowlatest" type="radio" value="0" ', $context['TPortal']['dl_showlatest'] == '0' ? 'checked' : '', '>' . $txt['tp-sayno'] . '
				</td>
            	</tr><tr>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dluseformat'] . '
				</td>
				<td>
					<input name="tp_dl_fileprefix" type="radio" value="K" ', $context['TPortal']['dl_fileprefix'] == 'K' ? 'checked' : '', '>Kb<br />
					<input name="tp_dl_fileprefix" type="radio" value="M" ', $context['TPortal']['dl_fileprefix'] == 'M' ? 'checked' : '', '>Mb<br />
					<input name="tp_dl_fileprefix" type="radio" value="G" ', $context['TPortal']['dl_fileprefix'] == 'G' ? 'checked' : '', '>Gb<br />
				</td>
            	</tr><tr>
			</tr><tr class="windowbg2">
				<td align="right" width="35%">
					' . $txt['tp-dlvisualoptions'] . '
				</td>
				<td>
					<input name="tp_dl_visual_options1" type="checkbox" value="left" ', isset($context['TPortal']['dl_left']) ? 'checked' : '', '>' . $txt['tp-leftbar'] . '<br />
					<input name="tp_dl_visual_options2" type="checkbox" value="right" ', isset($context['TPortal']['dl_right']) ? 'checked' : '', '>' . $txt['tp-rightbar'] . '<br />
					<input name="tp_dl_visual_options3" type="checkbox" value="center" ', isset($context['TPortal']['dl_center']) ? 'checked' : '', '>' . $txt['tp-centerbar'] . '<br />
					<input name="tp_dl_visual_options4" type="checkbox" value="top" ', isset($context['TPortal']['dl_top']) ? 'checked' : '', '>' . $txt['tp-topbar'] . '<br />
					<input name="tp_dl_visual_options5" type="checkbox" value="bottom" ', isset($context['TPortal']['dl_bottom']) ? 'checked' : '', '>' . $txt['tp-bottombar'] . '<br />
					<input name="tp_dl_visual_options6" type="checkbox" value="lower" ', isset($context['TPortal']['dl_lower']) ? 'checked' : '', '>' . $txt['tp-lowerbar'] . '<br />
					<input name="tp_dl_visual_options7" type="checkbox" value="showtop" ', isset($context['TPortal']['dl_showtop']) ? 'checked' : '', '>' . $txt['tp-showtop'] . '<br />
					<input name="tp_dl_visual_options8" type="hidden" value="not">
				</td>
            	</tr>
            <tr class="windowbg2"><td colspan="2" align="center">
				', $txt['tp-chosentheme'], ' <select size="1" name="tp_dltheme">';
        echo '<option value="0" ', $context['TPortal']['dlmanager_theme'] == '0' ? 'selected' : '', '>' . $txt['tp-noneicon'] . '</option>';
        foreach ($context['TPthemes'] as $them) {
            echo '<option value="' . $them['id'] . '" ', $them['id'] == $context['TPortal']['dlmanager_theme'] ? 'selected' : '', '>' . $them['name'] . '</option>';
        }
        echo '
				</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center" class="windowbg">
					<input type="hidden" name="dlsettings" value="1" />
					<input name="dlsend" type="submit" value="' . $txt['tp-submit'] . '">
				</td>
			</tr>';
    } elseif (substr($context['TPortal']['dlsub'], 0, 8) == 'admincat') {
        $mycat = substr($context['TPortal']['dlsub'], 8);
        // output any subcats
        echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
			<tr class="catbg">
				<td colspan="2">' . $txt['tp-dlname'] . '</td>
				<td>' . $txt['tp-dlicon'] . '</td>
				<td colspan="2">' . $txt['tp-dlviews'] . '</td>
				<td colspan="2">' . $txt['tp-dlfile'] . '</td>
				<td>' . $txt['tp-dlfilesize'] . '</td>
			</tr>';
        if (isset($context['TPortal']['admcats']) && count($context['TPortal']['admcats']) > 0) {
            foreach ($context['TPortal']['admcats'] as $cat) {
                if ($cat['parent'] == $mycat) {
                    echo '
			<tr>
				<td class="windowbg"><input name="tp_dlcatpos' . $cat['id'] . '" size="2" type="text" value="' . $cat['pos'] . '">
				<input type="hidden" name="admineditcatval" value="' . $cat['parent'] . '" /></td>
				<td class="windowbg" valign="top"><img src="' . $settings['tp_images_url'] . '/TPboard.gif" alt="" align="top" border="0" style="margin: 0;" /> <a href="' . $cat['href'] . '">' . $cat['name'] . '</a></td>
				<td class="windowbg" valign="top">', !empty($cat['icon']) ? '<img src="' . $cat['icon'] . '" alt="" />' : '', '</td>
				<td class="windowbg" valign="top" align="center">' . $cat['items'] . '</td>
				<td class="windowbg" valign="top" align="center">' . $cat['submitted'] . '</td>
				<td class="windowbg" colspan="3" valign="top">
					<a href="', $scripturl, '?action=tpmod;dl=cat', $cat['id'], '"><img title="' . $txt['tp-preview'] . '" src="' . $settings['tp_images_url'] . '/TPfilter.gif" alt="" /></a>
					<a href="' . $cat['href2'] . '"><img title="' . $txt['tp-edit'] . '" border="0" src="' . $settings['tp_images_url'] . '/TPconfig_sm.gif" alt="' . $txt['tp-edit'] . '"  /></a>
					<a href="' . $cat['href3'] . '" onclick="javascript:return confirm(\'' . $txt['tp-confirmdelete'] . '\')"><img title="delete" border="0" src="' . $settings['tp_images_url'] . '/TPdelete.gif" alt=""  /></a>
				</td>
			</tr>';
                }
            }
        }
        if (isset($context['TPortal']['dl_admitems']) && count($context['TPortal']['dl_admitems']) > 0) {
            foreach ($context['TPortal']['dl_admitems'] as $cat) {
                echo '
			<tr>
				<td colspan="2" class="windowbg2">
					<a href="', $scripturl, '?action=tpmod;dl=item', $cat['id'], '"><img title="' . $txt['tp-preview'] . '" src="' . $settings['tp_images_url'] . '/TPfilter.gif" alt="" /></a>
					<a href="' . $cat['href'] . '">' . $cat['name'] . '</a></td>
				<td class="windowbg2">', !empty($cat['icon']) ? '<img src="' . $cat['icon'] . '" alt="" />' : '', '</td>
				<td class="windowbg2" align="center">' . $cat['views'] . '</td>
				<td class="windowbg2" align="center">' . $cat['downloads'] . '</td>
				<td class="windowbg2">' . $cat['file'] . '</td>
				<td class="windowbg2">' . $cat['author'] . '</td>
				<td class="windowbg2">
				' . $cat['filesize'] . 'kb</td>
			</tr>';
            }
        }
        echo '
			<tr>
				<td colspan="8" align="center" class="windowbg"><input name="dlsend" type="submit" value="' . $txt['tp-submit'] . '"></td>
			</tr>';
    } elseif (substr($context['TPortal']['dlsub'], 0, 9) == 'adminitem') {
        if (isset($context['TPortal']['dl_admitems']) && count($context['TPortal']['dl_admitems']) > 0) {
            foreach ($context['TPortal']['dl_admitems'] as $cat) {
                echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder" style="table-layout: fixed;">
			<tr>
				<td class="windowbg2" align="right" width="25%">
					<a href="' . $scripturl . '?action=tpmod;dl=item' . $cat['id'] . '">[' . $txt['tp-preview'] . ']</a>
					' . $txt['tp-dluploadtitle'] . '</td>
				<td valign="top" class="windowbg2"><input style="width: 30ex;" name="dladmin_name' . $cat['id'] . '" type="text" value="' . $cat['name'] . '">
				</td>
			<tr>
				<td valign="top" class="windowbg2" colspan="2">
					<br />';
                if ($context['TPortal']['dl_wysiwyg'] == 'html') {
                    TPwysiwyg('dladmin_text' . $cat['id'], $cat['description'], true, 'qup_dladmin_text', isset($context['TPortal']['usersettings']['wysiwyg']) ? $context['TPortal']['usersettings']['wysiwyg'] : 0);
                } elseif ($context['TPortal']['dl_wysiwyg'] == 'bbc') {
                    TP_bbcbox($context['TPortal']['editor_id']);
                } else {
                    echo '<textarea name="dladmin_text' . $cat['id'] . '" style="width: 99%; height: 300px;">' . $cat['description'] . '</textarea>';
                }
                echo '
				</td>
			</tr><tr>
				<td class="windowbg2" align="right">' . $txt['tp-dluploadicon'] . '</td>
				<td valign="top" class="windowbg2">
					<select size="1" name="dladmin_icon' . $cat['id'] . '" onchange="dlcheck(this.value)">';
                echo '
						<option value="blank.gif">' . $txt['tp-noneicon'] . '</option>';
                // output the icons
                $selicon = substr($cat['icon'], strrpos($cat['icon'], '/') + 1);
                foreach ($context['TPortal']['dlicons'] as $dlicon => $value) {
                    echo '
						<option ', $selicon == $value ? 'selected="selected" ' : '', 'value="' . $value . '">' . $value . '</option>';
                }
                echo '
					</select>
					<br /><br /><img name="dlicon" src="' . $cat['icon'] . '" alt="" />
					<script type="text/javascript">
					function dlcheck(icon)
						{
							document.dlicon.src= "' . $boardurl . '/tp-downloads/icons/" + icon
						}
					</script>
				</td>
			</tr><tr>
				<td class="windowbg2" align="right">' . $txt['tp-dlviews'] . ':</td>
				<td valign="top" class="windowbg2">' . $cat['views'] . ' / ' . $cat['downloads'] . '</td>
			</tr><tr>
				<td class="windowbg2" valign="top" align="right">' . $txt['tp-dlfilename'] . '</td>
				<td valign="top" class="windowbg2">';
                if ($cat['file'] == '- empty item -' || $cat['file'] == '- empty item - ftp') {
                    if ($cat['file'] == '- empty item - ftp') {
                        echo '<div style="padding: 5px 0 5px 0; font-weight: bold;">' . $txt['tp-onlyftpstrays'] . '</div>';
                    }
                    echo '
					<select size="1" name="dladmin_file' . $cat['id'] . '">
						<option value="">' . $txt['tp-noneicon'] . '</option>';
                    foreach ($context['TPortal']['tp-downloads'] as $file) {
                        if ($cat['file'] == '- empty item - ftp') {
                            // check the file against
                            if (!in_array($file['file'], $context['TPortal']['dl_allitems'])) {
                                echo '
						<option value="' . $file['file'] . '">' . $file['file'] . ' - ' . $file['size'] . 'Kb</option>';
                            }
                        } else {
                            echo '
				  		<option value="' . $file['file'] . '">' . $file['file'] . ' - ' . $file['size'] . 'Kb</option>';
                        }
                    }
                    echo '
					</select>';
                } else {
                    echo '<input name="dladmin_file' . $cat['id'] . '" type="text" style="margin-bottom: 0.5em" value="' . $cat['file'] . '">';
                }
                echo '<br /><a href="' . $scripturl . '?action=tpmod;dl=get' . $cat['id'] . '">[' . $txt['tp-download'] . ']</a>
				</td>
			</tr>
			<tr>
				<td class="windowbg2" valign="top" align="right">' . $txt['tp-uploadnewfileexisting'] . ':</td>
				<td class="windowbg2">
					<input name="tp_dluploadfile_edit" style="width: 90%;" type="file" value="">
					<input name="tp_dluploadfile_editID" type="hidden" value="' . $cat['id'] . '">
				</td>
			</tr><tr>
				<td class="windowbg2" align="right">&nbsp;</td>
				<td valign="top" class="windowbg2"><input style="vertical-align: middle;" name="dladmin_delete' . $cat['id'] . '" type="checkbox" value="ON" onclick="javascript:return confirm(\'' . $txt['tp-confirm'] . '\')"> <b>' . $txt['tp-dldelete'] . '</b>
				</td>
			</tr><tr>
				<td class="windowbg2" align="right">&nbsp;</td>
				<td valign="top" class="windowbg2">
				<input name="dladmin_size' . $cat['id'] . '" readonly type="text" value="' . $cat['filesize'] * 1024 . '">bytes
				</td>
			</tr><tr>
			</tr><tr>
				<td class="windowbg2" align="right">' . $txt['tp-uploadedby'] . ':</td>
				<td valign="top" class="windowbg2">' . $context['TPortal']['admcurrent']['member'] . '</td>
			</tr>
					', $cat['approved'] == '0' ? '
			<tr>
				<td class="windowbg2" align="right"><img title="' . $txt['tp-approve'] . '" border="0" src="' . $settings['tp_images_url'] . '/TPthumbup.gif" alt="' . $txt['tp-dlapprove'] . '"  /> </td>
				<td valign="top" class="windowbg2">
					<input style="vertical-align: middle;" name="dl_admin_approve' . $cat['id'] . '" type="checkbox" value="ON"><b>' . $txt['tp-dlapprove'] . '</b>
				</td>' : '', ' ';
            }
        }
        // any extra files?
        if (isset($cat['subitem']) && sizeof($cat['subitem']) > 0) {
            echo '
			</tr><tr>
				<td class="windowbg2" align="right">' . $txt['tp-dlmorefiles'] . '</td>
				<td class="windowbg2">';
            foreach ($cat['subitem'] as $sub) {
                echo '<div><b><a href="', $sub['href'], '">', $sub['name'], '</a></b> (', $sub['file'], ')
						', $sub['filesize'], ' &nbsp;&nbsp;<br /><input style="vertical-align: middle;" name="dladmin_delete' . $sub['id'] . '" type="checkbox" value="ON" onclick="javascript:return confirm(\'' . $txt['tp-confirm'] . '\')"> ' . $txt['tp-dldelete'] . '
						&nbsp;&nbsp;<input style="vertical-align: middle;" name="dladmin_subitem' . $sub['id'] . '" type="checkbox" value="0"> ' . $txt['tp-dlattachloose'] . '
						<br /><br /></div>';
            }
            echo '
				</td>';
        } else {
            echo '
			</tr><tr>
				<td class="windowbg2" align="right"><b>' . $txt['tp-dlmorefiles2'] . '</b></td>
				<td class="windowbg2">
					<select size="1" name="dladmin_subitem' . $cat['id'] . '" style="margin-top: 4px;">
						<option value="0" selected>' . $txt['tp-no'] . '</option>';
            foreach ($context['TPortal']['admitems'] as $subs) {
                echo '
						<option value="' . $subs['id'] . '">' . $txt['tp-yes'] . ', ' . $subs['name'] . '</option>';
            }
            echo '
					</select></td>';
        }
        // which category?
        echo '
			</tr><tr>
				<td class="windowbg2" align="right">' . $txt['tp-dluploadcategory'] . '</td>
				<td class="windowbg2">
					<select size="1" name="dladmin_category' . $cat['id'] . '" style="margin-top: 4px;">';
        foreach ($context['TPortal']['admuploadcats'] as $ucats) {
            echo '
						<option value="' . $ucats['id'] . '" ', $ucats['id'] == abs($cat['category']) ? 'selected' : '', '>', !empty($ucats['indent']) ? str_repeat("-", $ucats['indent']) : '', ' ' . $ucats['name'] . '</option>';
        }
        echo '
					</select>
			     </td>
			</tr>
			<tr>
				<td class="windowbg2" align="right">' . $txt['tp-uploadnewpic'] . ':</td>
				<td class="windowbg2">
					<input name="tp_dluploadpic_edit" style="width: 90%;" type="file" value="">
					<input name="tp_dluploadpic_editID" type="hidden" value="' . $cat['id'] . '">
					</td>
			</tr>
			<tr>
				<td class="windowbg2" valign="top" align="right">' . $txt['tp-uploadnewpicexisting'] . ':</td>
				<td class="windowbg2">
					<input name="tp_dluploadpic_link" size="60" type="text" value="' . $cat['screenshot'] . '"><br /><br />
					<div style="overflow: auto;">', $cat['sshot'] != '' ? '<img src="' . $cat['sshot'] . '" alt="" />' : '&nbsp;', '</div></td>
			</tr>
			<tr>
				<td colspan="2" class="windowbg"><input name="dlsend" type="submit" value="' . $txt['tp-submit'] . '"></td>
			</tr>
			';
    } elseif ($context['TPortal']['dlsub'] == 'adminsubmission') {
        echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
			<tr class="titlebg">
				<td>' . $txt['tp-dlname'] . '</td>
				<td>' . $txt['tp-dlfilename'] . '</td>
				<td>' . $txt['tp-created'] . '</td>
				<td>' . $txt['tp-uploadedby'] . '</td>
				<td>' . $txt['tp-dlfilesize'] . '</td>
			</tr>';
        if (isset($context['TPortal']['dl_admitems']) && count($context['TPortal']['dl_admitems']) > 0) {
            foreach ($context['TPortal']['dl_admitems'] as $cat) {
                echo '
			<tr>
				<td class="windowbg2"><a href="' . $cat['href'] . '">' . $cat['name'] . '</a></td>
				<td class="windowbg2">' . $cat['file'] . '</td>
				<td class="windowbg2">' . $cat['date'] . '</td>
				<td class="windowbg2">' . $cat['author'] . '</td>
				<td class="windowbg2">' . $cat['filesize'] . 'kb</td>
			</tr>';
            }
        }
    } elseif ($context['TPortal']['dlsub'] == 'adminftp') {
        echo '<div class="tborder"><div class="titlebg" style="padding: 1ex;">' . $txt['tp-ftpstrays'] . '</div>
					<div class="windowbg" style="padding: 2ex;" class="smalltext">' . $txt['tp-assignftp'] . '</div>
					<div class="windowbg2" style="padding: 5px;">';
        // alert if new files were added recently
        if (!empty($_GET['ftpcat'])) {
            echo '<div style="margin-bottom: 1ex; text-align: center; border: dotted 2px red; padding: 2ex;"><b><a href="' . $scripturl . '?action=tpmod;dl=admincat' . $_GET['ftpcat'] . '">' . $txt['tp-adminftp_newfiles'] . '</a></b><br /></div>';
        }
        if (count($context['TPortal']['tp-downloads']) > 0) {
            $ccount = 0;
            foreach ($context['TPortal']['tp-downloads'] as $file) {
                if (!in_array($file['file'], $context['TPortal']['dl_allitems'])) {
                    echo '<div><input name="assign-ftp-checkbox' . $ccount . '" type="checkbox" value="' . $file['file'] . '"> ' . substr($file['file'], 0, 40) . '', strlen($file['file']) > 40 ? '..' : '', '  [' . $file['size'] . ' Kb]  - <b><a href="' . $scripturl . '?action=tpmod;dl=upload;ftp=' . $file['id'] . '">' . $txt['tp-dlmakeitem'] . '</a></b></div>';
                }
                $ccount++;
            }
            echo '<div style="padding: 5px;"><span class="smalltext">
			 ' . $txt['tp-newcatassign'] . ' <input name="assign-ftp-newcat" type="text" value=""> ';
            // the parent category - or the one to use
            // which parent category?
            echo $txt['tp-assigncatparent'] . '</span>
					<select size="1" name="assign-ftp-cat" style="margin-top: 4px;">
						<option value="0" selected>' . $txt['tp-nocategory'] . '</option>';
            if (count($context['TPortal']['admuploadcats']) > 0) {
                foreach ($context['TPortal']['admuploadcats'] as $ucats) {
                    echo '
						<option value="' . $ucats['id'] . '">', !empty($ucats['indent']) ? str_repeat("-", $ucats['indent']) : '', ' ' . $ucats['name'] . '</option>';
                }
            } else {
                echo '
						<option value="0">' . $txt['tp-none-'] . '</option>';
            }
            echo '
					</select><hr />';
            echo '<input name="ftpdlsend" type="submit" value="' . $txt['tp-submit'] . '">
						</div>';
        }
        echo '</div></div>';
    } elseif (substr($context['TPortal']['dlsub'], 0, 12) == 'admineditcat') {
        if (isset($context['TPortal']['admcats']) && count($context['TPortal']['admcats']) > 0) {
            foreach ($context['TPortal']['admcats'] as $cat) {
                echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
			<tr>
				<td valign="top" class="windowbg2">
					', $txt['tp-dluploadtitle'], '<br />
					<input style="width: 30ex;" name="dladmin_name' . $cat['id'] . '" type="text" value="' . $cat['name'] . '">
					<br />', $txt['tp-shortname'], '<br />
					<input style="width: 30ex;" name="dladmin_link' . $cat['id'] . '" type="text" value="' . $cat['shortname'] . '">
					<br />';
                if ($context['TPortal']['dl_wysiwyg'] == 'html') {
                    TPwysiwyg('dladmin_text' . $cat['id'], html_entity_decode($cat['description'], ENT_QUOTES), true, 'qup_dladmin_text', isset($context['TPortal']['usersettings']['wysiwyg']) ? $context['TPortal']['usersettings']['wysiwyg'] : 0);
                } elseif ($context['TPortal']['dl_wysiwyg'] == 'bbc') {
                    TP_bbcbox($context['TPortal']['editor_id']);
                } else {
                    echo '<textarea name="dladmin_text' . $cat['id'] . '" style="width: 99%; height: 300px;">' . html_entity_decode($cat['description'], ENT_QUOTES) . '</textarea>';
                }
                echo '
				</td>
				<td valign="top" class="windowbg2">
					<select size="1" name="dladmin_icon' . $cat['id'] . '" onchange="dlcheck(this.value)">
						<option value="blank.gif" selected>' . $txt['tp-chooseicon'] . '</option>
						<option value="blank.gif">' . $txt['tp-noneicon'] . '</option>';
                // output the icons
                $selicon = substr($cat['icon'], strrpos($cat['icon'], '/') + 1);
                foreach ($context['TPortal']['dlicons'] as $dlicon => $value) {
                    echo '
						<option ', $selicon == $value ? 'selected="selected" ' : '', 'value="' . $value . '">' . $value . '</option>';
                }
                echo '
					</select>
					<br /><br /><img name="dlicon" src="' . $cat['icon'] . '" alt="" />
					<script type="text/javascript">
						function dlcheck(icon)
						{
							document.dlicon.src= "' . $boardurl . '/tp-downloads/icons/" + icon
						}
					</script>
				<br /><b>' . $txt['tp-dlparent'] . ':</b><br />';
                // which parent category?
                echo '
					<select size="1" name="dladmin_parent' . $cat['id'] . '" style="margin-top: 4px;">
						<option value="0" ', $cat['parent'] == 0 ? 'selected' : '', '>' . $txt['tp-nocategory'] . '</option>';
                if (count($context['TPortal']['admuploadcats']) > 0) {
                    foreach ($context['TPortal']['admuploadcats'] as $ucats) {
                        if ($ucats['id'] != $cat['id']) {
                            echo '
						<option value="' . $ucats['id'] . '" ', $ucats['id'] == $cat['parent'] ? 'selected' : '', '>', !empty($ucats['indent']) ? str_repeat("-", $ucats['indent']) : '', ' ' . $ucats['name'] . '</option>';
                        }
                    }
                } else {
                    echo '
						<option value="0">' . $txt['tp-none-'] . '</option>';
                }
            }
            echo '
					</select><hr /><b>' . $txt['tp-dlaccess'] . ':</b>
					<div style="max-height: 30em; overflow: auto;">';
            // access groups
            // loop through and set membergroups
            if (!empty($cat['access'])) {
                $tg = explode(',', $cat['access']);
            } else {
                $tg = array();
            }
            foreach ($context['TPortal']['dlgroups'] as $mg) {
                if ($mg['posts'] == '-1' && $mg['id'] != '1') {
                    echo '
					<input name="dladmin_group' . $mg['id'] . '" type="checkbox" value="' . $cat['id'] . '"';
                    if (in_array($mg['id'], $tg)) {
                        echo ' checked';
                    }
                    echo '> ' . $mg['name'] . ' <br />';
                }
            }
            // if none is chosen, have a control value
            echo '<br /></div><input type="checkbox" onclick="invertAll(this, this.form, \'dladmin_group\');" />' . $txt['tp-checkall'] . '
					<input name="dladmin_group-2" type="hidden" value="' . $cat['id'] . '">';
            echo '
		     	</td>
		     </tr>';
        }
        echo '
			<tr>
				<td colspan="5" class="windowbg"><input name="dlsend" type="submit" value="' . $txt['tp-submit'] . '"></td>
			</tr>';
    } elseif ($context['TPortal']['dlsub'] == 'adminaddcat') {
        echo '
		<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
			<tr>
				<td valign="top" class="windowbg2"><b>' . $txt['tp-title'] . ':</b> <input style="width: 70%;" name="newdladmin_name" type="text" value="">
					<br /><br /><b>' . $txt['tp-body'] . ':</b><br />';
        if ($context['TPortal']['dl_wysiwyg'] == 'html') {
            TPwysiwyg('newdladmin_text', '', true, 'qup_dladmin_text', isset($context['TPortal']['usersettings']['wysiwyg']) ? $context['TPortal']['usersettings']['wysiwyg'] : 0);
        } elseif ($context['TPortal']['dl_wysiwyg'] == 'bbc') {
            TP_bbcbox($context['TPortal']['editor_id']);
        } else {
            echo '<textarea name="newdladmin_text" style="width: 99%; height: 300px;"></textarea>';
        }
        echo '</td>
				<td valign="top" class="windowbg2" width="30%" colspan="2"><b>' . $txt['tp-icon'] . ':</b>
					<select size="1" name="newdladmin_icon" onchange="dlcheck(this.value)">';
        echo '
				<option value="blank.gif" selected>' . $txt['tp-noneicon'] . '</option>';
        // output the icons
        foreach ($context['TPortal']['dlicons'] as $dlicon => $value) {
            echo '
						<option value="' . $value . '">' . substr($value, 0, strlen($value) - 4) . '</option>';
        }
        echo '
					</select>
					<br /><br /><img name="dlicon" src="' . $boardurl . '/tp-downloads/icons/blank.gif" alt="" />
				<script type="text/javascript">
					function dlcheck(icon)
					{
						document.dlicon.src= "' . $boardurl . '/tp-downloads/icons/" + icon
					}
				</script>
				<br /><br /><b>' . $txt['tp-dlparent'] . ':</b><br />';
        // which parent category?
        echo '
					<select size="1" name="newdladmin_parent" style="margin-top: 4px;">
						<option value="0" selected>' . $txt['tp-nocategory'] . '</option>';
        foreach ($context['TPortal']['admuploadcats'] as $ucats) {
            echo '
			     		<option value="' . $ucats['id'] . '">', !empty($ucats['indent']) ? str_repeat("-", $ucats['indent']) : '', ' ' . $ucats['name'] . '</option>';
        }
        echo '
					</select>
		<hr /><b>' . $txt['tp-dlaccess'] . ':</b><br />';
        // access groups
        // loop through and set membergroups
        if (!empty($cat['access'])) {
            $tg = explode(',', $cat['access']);
        } else {
            $tg = array();
        }
        foreach ($context['TPortal']['dlgroups'] as $mg) {
            if ($mg['posts'] == '-1' && $mg['id'] != '1') {
                echo '
					<input name="newdladmin_group' . $mg['id'] . '" type="checkbox" value="1"';
                if (in_array($mg['id'], $tg)) {
                    echo ' checked';
                }
                echo '> ' . $mg['name'] . ' <br />';
            }
        }
        // if none is chosen, have a control value
        echo '<br /><input type="checkbox" onclick="invertAll(this, this.form, \'newdladmin_group\');" />' . $txt['tp-checkall'] . '
					<input name="dladmin_group-2" type="hidden" value="1"></td>
			</tr>';
        echo '
			<tr>
				<td colspan="6" class="windowbg"><input name="newdlsend" type="submit" value="' . $txt['tp-submit'] . '"></td>
			</tr>';
    }
    echo '
		</table>
	</form>
</div>';
}
function article_comments($render = true)
{
    global $scripturl, $txt, $settings, $context;
    if (in_array('comments', $context['TPortal']['article']['visual_options'])) {
        echo '
	<h2 class="titlebg" style="padding: 0 1em;">' . $txt['tp-comments'] . '  ' . tp_hidepanel('articlecomments', false, true, '5px 5px 0 5px') . '</h2>
	<div id="articlecomments"' . (in_array('articlecomments', $context['tp_panels']) ? ' style="display: none;"' : '') . '>
		<div class="windowbg2" style="padding: 1em 2em;">';
        $counter = 1;
        if (isset($context['TPortal']['article']['comment_posts'])) {
            foreach ($context['TPortal']['article']['comment_posts'] as $comment) {
                if ($comment['posterID'] == 0) {
                    echo '
				<div class="othercomment">
						<a id="comment' . $comment['id'] . '"></a>
						<strong>' . $counter++ . ') ' . $comment['subject'] . '</strong>
						<div class="middletext" style="padding-top: 0.5em;"> ' . $txt['tp-by'] . ' ' . $txt['guest_title'] . ' ' . $txt['on'] . ' ' . $comment['date'] . '</div>
						' . ($comment['is_new'] && $context['user']['is_logged'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="" />' : '') . '
						<div class="textcomment"><div class="body">' . $comment['text'] . '</div></div><br />';
                } else {
                    echo '
					<div class="' . ($context['TPortal']['article']['authorID'] != $comment['posterID'] ? 'mycomment' : 'othercomment') . '">
					<a id="comment' . $comment['id'] . '"></a>
					<span class="comment_author">' . (!empty($comment['avatar']['image']) ? $comment['avatar']['image'] : '') . '</span>
					<strong>' . $counter++ . ') ' . $comment['subject'] . '</strong>
					' . ($comment['is_new'] && $context['user']['is_logged'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="" />' : '') . '
					<div class="middletext" style="padding-top: 0.5em;"> ' . $txt['tp-by'] . ' <a href="' . $scripturl . '?action=profile;u=' . $comment['posterID'] . '">' . $comment['poster'] . '</a>
					' . $txt['on'] . ' ' . $comment['date'] . '</div>
					<div class="textcomment"><div class="body">' . $comment['text'] . '</div></div><br />';
                }
                // can we edit the comment or are the owner of it?
                if (allowedTo('tp_articles') || $comment['posterID'] == $context['user']['id'] && !$context['user']['is_guest']) {
                    echo '
						<div class="buttonlist align_right"><ul><li><a class="active" href="' . $scripturl . '?action=tpmod;sa=killcomment' . $comment['id'] . '" onclick="javascript:return confirm(\'' . $txt['tp-confirmdelete'] . '\')"><span>' . $txt['tp-delete'] . '</span></a></li></ul></div><br />';
                }
                echo '
				</div>';
            }
            echo '
			</div>';
        }
    }
    if (in_array('commentallow', $context['TPortal']['article']['visual_options']) && !empty($context['TPortal']['can_artcomment'])) {
        echo '
			<div class="windowbg" style="margin-top: 10px; padding: 1em;">
				<form accept-charset="' . $context['character_set'] . '"  name="tp_article_comment" action="' . $scripturl . '?action=tpmod;sa=comment" method="post" style="margin: 0; padding: 0;">
						<input name="tp_article_comment_title" type="text" style="width: 99%;" value="Re: ' . strip_tags($context['TPortal']['article']['subject']) . '">
						<textarea style="width: 99%; height: 8em;" name="tp_article_bodytext"></textarea>
';
        echo '
						<br />&nbsp;<input id="tp_article_comment_submit" type="submit" value="' . $txt['tp-submit'] . '">
						<input name="tp_article_type" type="hidden" value="article_comment">
						<input name="tp_article_id" type="hidden" value="' . $context['TPortal']['article']['id'] . '">
						<input type="hidden" name="sc" value="' . $context['session_id'] . '" />
				</form>
			</div>';
    } else {
        echo '
			<div style="padding: 1ex;" class="windowbg"><em>' . $txt['tp-cannotcomment'] . '</em></div>';
    }
    echo '
			</div>';
}