/**
 * @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 template_submitarticle()
{
    global $context, $txt, $scripturl;
    echo '
	<form style="clear: both;" accept-charset="', $context['character_set'], '" name="TPadmin3" action="' . $scripturl . '?action=tpmod;sa=submitarticle2" method="post" enctype="multipart/form-data" onsubmit="submitonce(this);">
				<input name="TPadmin_submit" type="hidden" value="set">
				<input type="hidden" name="sc" value="', $context['session_id'], '" />
		<table width="100%" cellspacing="1" cellpadding="5" class="bordercolor">
			<tr class="windowbg2">
				<td valign="top" colspan="2" class="titlebg"> ' . $txt['tp-submitarticle'] . ' </td>
			</tr>
			<tr class="windowbg2">
				<td valign="top" align="right">' . $txt['tp-arttitle'] . ' </td>
				<td valign="top"><input style="width: 92%;" name="tp_article_title" type="text" value=""></td>
			</tr>
			<tr class="windowbg2">
				<td colspan="2" valign="top" >' . $txt['tp-artbodytext'] . ' <br />';
    $tp_use_wysiwyg = $context['TPortal']['show_wysiwyg'];
    if ($tp_use_wysiwyg > 0 && !isset($context['TPortal']['submitbbc'])) {
        TPwysiwyg('tp_article_body', '', true, 'qup_tp_article_body', $tp_use_wysiwyg);
    } elseif ($tp_use_wysiwyg == 0 && !isset($context['TPortal']['submitbbc'])) {
        echo '
					<textarea name="tp_article_body" id="tp_article_body" style="width: 95%; height: 300px;" wrap="auto"></textarea><br />';
    } elseif (isset($context['TPortal']['submitbbc'])) {
        TP_bbcbox($context['TPortal']['editor_id']);
    }
    echo '<br />' . $txt['tp-artintrotext'] . '<br />';
    if ($tp_use_wysiwyg > 0 && !isset($context['TPortal']['submitbbc'])) {
        TPwysiwyg('tp_article_intro', '', true, 'qup_tp_article_intro', $tp_use_wysiwyg, false);
    } elseif ($tp_use_wysiwyg == 0 && !isset($context['TPortal']['submitbbc'])) {
        echo '
					<textarea name="tp_article_intro" id="tp_article_intro" style="width: 95%; height: 300px;" wrap="auto"></textarea><br />';
    } elseif (isset($context['TPortal']['submitbbc'])) {
        echo '<textarea name="tp_article_intro" id="tp_article_intro" style="width: 80%; height: 200px;" wrap="auto"></textarea><br />';
    }
    echo '
					<input name="tp_article_frame" type="hidden" value="theme">
					<input name="newarticle" type="hidden" value="1">
					<input name="submittedarticle" type="hidden" value="', isset($context['TPortal']['submitbbc']) ? 'bbc' : 'html', '">
				</td>
			</tr>
			<tr class="windowbg">
				<td colspan="2" align="center"><input type="submit" value="' . $txt['tp-send'] . '" name="send">
					<input name="tp_article_frontpage" type="hidden" value="0">
					<input name="tp_article_date" type="hidden" value="', time(), '">
					<input name="tp_article_category" type="hidden" value="">
					<input name="tp_article_approved" type="hidden" value="0">
				</td>
			</tr>
		</table>
	</form>';
}
Exemplo n.º 3
0
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, $txt, $scripturl, $modSettings, $boardurl;
    // if dl manager is off, throw a error screen but don't log it.
    if ($context['TPortal']['show_download'] == 0 && !allowedTo('tp_dlmanager')) {
        fatal_error($txt['tp-dlmanageroff'], false);
    }
    echo '
	<div class="dl_container">
		<div class="title_bar">
			<h3 class="titlebg">', $txt['tp-downloads'], '	</h3>
		</div>
		<div>';
    $dlbuttons = array('frontdl' => array('text' => 'tp-downloads', 'image' => 'search.gif', 'lang' => true, 'url' => $scripturl . '?action=tpmod;dl'), 'search' => array('text' => 'tp-search', 'image' => 'search.gif', 'lang' => true, 'url' => $scripturl . '?action=tpmod;dl=search'), 'stats' => array('text' => 'tp-stats', 'image' => 'stats.gif', 'lang' => true, 'url' => $scripturl . '?action=tpmod;dl=stats'), 'upload' => array('text' => 'tp-dlupload', 'test' => 'can_tp_dlupload', 'image' => 'upload.gif', 'lang' => true, 'url' => $scripturl . '?action=tpmod;dl=upload'));
    if (in_array($context['TPortal']['dlaction'], array('frontdl', 'search', 'stats', 'upload'))) {
        $dlbuttons[$context['TPortal']['dlaction']]['active'] = true;
    } else {
        $dlbuttons['frontdl']['active'] = true;
    }
    echo '
		<div style="overflow: hidden; margin: 0 0 0.5em 0;">';
    template_button_strip($dlbuttons, 'right');
    echo '
		</div>';
    if ($context['TPortal']['dlaction'] == '' || $context['TPortal']['dlaction'] == 'cat') {
        if (!empty($context['TPortal']['dl_introtext'])) {
            echo '
			<div class="windowbg2" style="padding: 1em;">' . parse_bbc($context['TPortal']['dl_introtext']) . '</div>';
        }
        if (!empty($context['TPortal']['dl_showfeatured']) && !empty($context['TPortal']['featured'])) {
            echo '
				<div class="cat_bar">
					<h3 class="catbg">' . $txt['tp-dlfeatured'] . '</h3>
				</div>
				<div class="windowbg" style="overflow: hidden; padding: 1em;">';
            if (!empty($context['TPortal']['featured']['sshot'])) {
                echo '
				<div class="screenshot" style="margin: 4px 4px 4px 1em;float: right; width: ' . $context['TPortal']['dl_screenshotsize'][2] . 'px; height: ' . $context['TPortal']['dl_screenshotsize'][3] . 'px;background: url(' . $context['TPortal']['featured']['sshot'] . ') no-repeat;"></div>';
            }
            echo '
				<h4 class="h4dl"><a href="' . $scripturl . '?action=tpmod;dl=item' . $context['TPortal']['featured']['id'] . '">' . $context['TPortal']['featured']['name'] . '</a></h4>
				<span class="middletext">' . $txt['tp-uploadedby'] . ' <a href="' . $scripturl . '?action=profile;u=' . $context['TPortal']['featured']['authorID'] . '">' . $context['TPortal']['featured']['author'] . '</a></span>
				<p>' . $context['TPortal']['featured']['description'], '</p>
			</div>';
        }
        // render last added and most downloaded.
        echo '
		<span class="upperframe"><span></span></span>
        <div class="roundframe">
			<div class="">';
        if ($context['TPortal']['dl_showlatest'] == 1) {
            echo '
			<a href="javascript: void(0); " onclick="dlshowtab(\'dlrecent\');"><b>', $txt['tp-recentuploads'], $context['TPortal']['dlaction'] == 'cat' ? ' ' . $txt['tp-incategory'] . '&quot;' . $context['TPortal']['dlheader'] . '&quot;' : '', '</b></a>';
        }
        if ($context['TPortal']['dl_showstats'] == 1) {
            echo '
			 ', $context['TPortal']['dl_showlatest'] == 1 ? '&nbsp;|&nbsp; ' : '', '<a href="javascript: void(0);" onclick="dlshowtab(\'dlweekpop\');">', $txt['tp-mostpopweek'], $context['TPortal']['dlaction'] == 'cat' ? ' ' . $txt['tp-incategory'] . '&quot;' . $context['TPortal']['dlheader'] . '&quot;' : '', '</a>
			&nbsp;|&nbsp; <a href="javascript: void(0); " onclick="dlshowtab(\'dlpop\');">', $txt['tp-mostpop'], $context['TPortal']['dlaction'] == 'cat' ? ' ' . $txt['tp-incategory'] . '&quot;' . $context['TPortal']['dlheader'] . '&quot;' : '', '</a> ';
        }
        echo '
			</div>
        </div>
		<span class="lowerframe" style="margin-bottom: 5px;"><span></span></span>
		<div class="windowbg2">
			<span class="topslice"><span></span></span>
		<div style="padding: 1em;">';
        if ($context['TPortal']['dl_showlatest'] == 1) {
            echo '	
			<div id="dlrecent">
			<h4 class="h4dl">', $txt['tp-recentuploads'], $context['TPortal']['dlaction'] == 'cat' ? ' ' . $txt['tp-incategory'] . '&quot;' . $context['TPortal']['dlheader'] . '&quot;' : '', '</h4>';
            $count = 1;
            if (!empty($context['TPortal']['dl_last_added'])) {
                foreach ($context['TPortal']['dl_last_added'] as $last) {
                    echo '
			<div class="recentdl">';
                    if (!empty($last['screenshot'])) {
                        echo '<div style="margin-right: 15px; background: url(' . $last['screenshot'] . ') no-repeat; float: left; width: ' . $context['TPortal']['dl_screenshotsize'][0] . 'px; height: ' . $context['TPortal']['dl_screenshotsize'][1] . 'px;" class="windowbg3"></div>';
                    } else {
                        echo '<div style="margin-right: 15px; background: url(' . $settings['tp_images_url'] . '/TPnodl.png) 50% 50% no-repeat; float: left; width: ' . $context['TPortal']['dl_screenshotsize'][0] . 'px; height: ' . $context['TPortal']['dl_screenshotsize'][1] . 'px;" class="windowbg3"></div>';
                    }
                    echo '				
				<div class="dl_most_downloaded">
						<a href="' . $last['href'] . '"><b>' . $last['name'] . '</b></a> 
						<div class="smalltext"> ' . $txt['tp-uploadedby'] . ' ' . $last['author'] . ' ' . $last['date'] . '</div>
						<div class="smalltext">' . $last['downloads'] . ' ' . strtolower($txt['tp-downloads']) . '</div>
				</div>
			</div>';
                }
            }
            echo '	
			</div>';
        }
        if ($context['TPortal']['dl_showstats'] == 1) {
            echo '	
			<div id="dlweekpop" ', $context['TPortal']['dl_showlatest'] == 1 ? 'style="display: none;"' : '', '>
			<h4 class="h4dl">', $txt['tp-mostpopweek'], $context['TPortal']['dlaction'] == 'cat' ? ' ' . $txt['tp-incategory'] . '&quot;' . $context['TPortal']['dlheader'] . '&quot;' : '', '</h4>';
            $count = 1;
            if (!empty($context['TPortal']['dl_week_downloaded'])) {
                foreach ($context['TPortal']['dl_week_downloaded'] as $wost) {
                    echo '
				<div class="dl_most_downloaded">
					<div class="dl_number">' . $count . '.</div>
					<div class="dl_number_right">
						<a href="' . $wost['href'] . '"><b>' . $wost['name'] . '</b></a> 
						<div class="smalltext"> ' . $txt['tp-uploadedby'] . ' ' . $wost['author'] . ' ' . $wost['date'] . '</div>
						<div class="smalltext">' . $wost['downloads'] . ' ' . strtolower($txt['tp-downloads']) . '</div>
					</div>
				</div>';
                    $count++;
                }
            }
            echo '		
			</div>
			<div id="dlpop" style="display: none;">
			<h4 class="h4dl">', $txt['tp-mostpop'], $context['TPortal']['dlaction'] == 'cat' ? ' ' . $txt['tp-incategory'] . '&quot;' . $context['TPortal']['dlheader'] . '&quot;' : '', '</h4>';
            $count = 1;
            if (!empty($context['TPortal']['dl_most_downloaded'])) {
                foreach ($context['TPortal']['dl_most_downloaded'] as $wost) {
                    echo '
				<div class="dl_most_downloaded">
					<div class="dl_number">' . $count . '.</div>
					<div class="dl_number_right">
						<a href="' . $wost['href'] . '"><b>' . $wost['name'] . '</b></a> 
						<div class="smalltext"> ' . $txt['tp-uploadedby'] . ' ' . $wost['author'] . ' ' . $wost['date'] . '</div>
						<div class="smalltext">' . $wost['downloads'] . ' ' . strtolower($txt['tp-downloads']) . '</div>
					</div>
				</div>';
                    $count++;
                }
            }
        }
        echo '		
			</div>';
        echo '
		</div>
		<span class="botslice"><span></span></span>
	</div>

	<script type="text/javascript"><!-- // --><![CDATA[
		function dlshowtab( target )
		{
			document.getElementById(\'dlrecent\').style.display= \'none\';
			document.getElementById(\'dlpop\').style.display= \'none\';
			document.getElementById(\'dlweekpop\').style.display= \'none\';
			
			document.getElementById(target).style.display= \'\';
		}
	// ]]></script>
	<br />
	
	<div class="cat_bar">
		<h3 class="catbg">' . $txt['tp-categories'] . '</h3>
	</div>	
	<div class="windowbg">';
        //show all categories
        foreach ($context['TPortal']['dlcats'] as $dlcat) {
            // any subcategories?
            if (!empty($context['TPortal']['dlcatchilds']) && sizeof($context['TPortal']['dlcatchilds']) > 1) {
                $content = '';
                foreach ($context['TPortal']['dlcatchilds'] as $dlchild) {
                    if ($dlchild['parent'] == $dlcat['id']) {
                        $content .= '
					<li>
						<img style="margin: 0;" alt="" src="' . $settings['tp_images_url'] . '/TPboard.gif' . '" border="0" />
							<a href="' . $dlchild['href'] . '">' . $dlchild['name'] . '</a>';
                        if ($dlchild['files'] > 0) {
                            $content .= ' (' . $dlchild['files'] . ')';
                        }
                        $content .= '
					</li>';
                    }
                }
            }
            echo '
			<div class="dlcategory"', !empty($content) ? ' style="margin-bottom: 0;"' : '', '>
				<div style="overflow: visible;">
				<img style="float: left; margin: 0 10px 5px 0;" src="', !empty($dlcat['icon']) ? substr($dlcat['icon'], 0, 4) == 'http' ? $dlcat['icon'] : $boardurl . '/' . $dlcat['icon'] : $settings['images_url'] . '/board.gif', '" alt="" />
					<div class="details">', $dlcat['files'] > 0 ? $dlcat['files'] . ' ' . $txt['tp-dlfiles'] : '0 ' . $txt['tp-dlfiles'], '</div>
					<h4><a href="' . $dlcat['href'] . '">' . $dlcat['name'] . '</a></h4>
					<div class="post middletext">' . $dlcat['description'] . '</div>
				</div>
			</div>';
            if (!empty($content)) {
                echo '
			<div class="dlcategory" style="padding-left: 5em;"><ul class="tp-subcategories">' . $content . '</ul></div>';
            }
        }
        // show any files?
        if ($context['TPortal']['dlaction'] == 'cat' && sizeof($context['TPortal']['dlitem']) > 0) {
            echo '
		</div>
		<div style="padding: 0.5em 1em;">
			<div style="overflow: hidden;">';
            if (!empty($context['TPortal']['sortlinks'])) {
                echo '
				<div style="float: right;">' . $context['TPortal']['sortlinks'] . '</div>';
            } else {
                echo $txt['tp-dlfiles'];
            }
            if ($context['TPortal']['dlaction'] != 'item' && !empty($context['TPortal']['pageindex'])) {
                echo '<div style="padding-bottom: 0.3em;">' . $context['TPortal']['pageindex'] . '</div>';
            }
            echo '
			</div>
		</div>
		<div class="windowbg2" style="padding: 1em;">
			<div style="overflow: hidden;">';
            foreach ($context['TPortal']['dlitem'] as $dlitem) {
                echo '
				<div class="dlitemgrid">
					<h4 class="h4dl" style="padding-bottom: 0; font-size: 1.3em;"><a href="' . $dlitem['href'] . '">' . $dlitem['name'] . '</a></h4>
					<div  style="float: left; padding: 1em 1em 1em 0; ">', $dlitem['icon'] != '' ? '<img src="' . (substr($dlitem['icon'], 0, 4) == 'http' ? $dlitem['icon'] : $boardurl . '/' . $dlitem['icon']) . '" border="0" alt="' . $dlitem['name'] . '"  />' : '<img src="' . $settings['tp_images_url'] . '/TPnodl.png" alt="" />', '	</div>';
                unset($details);
                $details = array();
                $det2 = array();
                // edit the file?
                if (allowedTo('tp_dlmanager')) {
                    $details[] = '<a href="' . $scripturl . '?action=tpmod;dl=adminitem' . $dlitem['id'] . '">' . $txt['tp-edit'] . '</a>';
                } elseif ($dlitem['authorID'] == $context['user']['id']) {
                    $details[] = '<a href="' . $scripturl . '?action=tpmod;dl=useredit' . $dlitem['id'] . '">' . $txt['tp-edit'] . '</a>';
                }
                if (isset($dlitem['ingress'])) {
                    echo '
					<div class="dlpost">' . $dlitem['ingress'] . '</div>';
                }
                echo '
					<div class="post">', $dlitem['description'], '</div>';
                if (isset($dlitem['filesize'])) {
                    $details[] = $dlitem['filesize'];
                }
                $details[] = $dlitem['views'] . ' ' . $txt['tp-views'];
                $details[] = $dlitem['downloads'] . ' ' . $txt['tp-downloads'];
                $det2[] = $txt['tp-itemlastdownload'] . ' ' . timeformat($dlitem['date_last']);
                $det2[] = $dlitem['author'];
                echo '
					<div class="itemdetails smalltext">', implode(" | ", $details), '<br />', implode(" | ", $det2), '</div>
				<br /><br />
				</div>';
            }
            echo '
			</div>
		</div>
		<div class="windowbg" style="padding: 0.5em 1em;">
		';
            if ($context['TPortal']['dlaction'] != 'item' && !empty($context['TPortal']['pageindex'])) {
                echo $context['TPortal']['pageindex'];
            }
        }
        echo '
		</div>
	</div>';
    } elseif ($context['TPortal']['dlaction'] == 'item') {
        echo '
	<div class="tborder">
		<div >';
        foreach ($context['TPortal']['dlitem'] as $dlitem) {
            echo '
			<div class="windowbg">
				<span class="topslice"><span></span></span>
				<div class="content">
				<h4 class="h4dl">
				<a href="' . $dlitem['href'] . '">' . $dlitem['name'] . '</a>';
            // edit the file?
            if (allowedTo('tp_dlmanager')) {
                echo '&nbsp;&nbsp;<small>[<a href="', $scripturl, '?action=tpmod;dl=adminitem', $dlitem['id'], '">', $txt['tp-edit'], '</a>]</small>';
            } elseif ($dlitem['authorID'] == $context['user']['id']) {
                echo '&nbsp;&nbsp;<small>[<a href="', $scripturl, '?action=tpmod;dl=useredit', $dlitem['id'], '">', $txt['tp-edit'], '</a>]</small>';
            }
            echo '
				</h4><hr>
					<ul class="tp_details" style="line-height: 1.4em; font-size: 0.95em;">
						<li>', $txt['tp-dlfilesize'], ': ', isset($dlitem['filesize']) ? $dlitem['filesize'] : '', '</li>
						<li>' . $txt['tp-views'] . ': ' . $dlitem['views'] . ' </li>
						<li>' . $txt['tp-downloads'] . ': ' . $dlitem['downloads'] . ' </li>
						<li>', $txt['tp-created'] . ': ' . timeformat($dlitem['created']) . '</li>
						<li>', $txt['tp-itemlastdownload'], ': ' . timeformat($dlitem['date_last']) . '</li>
					</ul>	
					<div id="rating">' . $txt['tp-ratingaverage'] . ' ' . ($context['TPortal']['showstars'] ? str_repeat('<img src="' . $settings['tp_images_url'] . '/TPblue.gif" style="width: .7em; height: .7em; margin-right: 2px;" alt="" />', $dlitem['rating_average']) : $dlitem['rating_average']) . ' (' . $dlitem['rating_votes'] . ' ' . $txt['tp-ratingvotes'] . ')</div>';
            if ($dlitem['can_rate']) {
                echo '
					<form class="ratingoption" style="padding-left: 0;" name="tp_dlitem_rating" action="', $scripturl, '?action=tpmod;sa=rate_dlitem" method="post">
						', $txt['tp-ratedownload'], ' 
						<select size="1" name="tp_dlitem_rating">';
                for ($u = $context['TPortal']['maxstars']; $u > 0; $u--) {
                    echo '
							<option value="' . $u . '">' . $u . '</option>';
                }
                echo '
						</select>
						<input type="submit" name="tp_dlitem_rating_submit" value="', $txt['tp_rate'], '" />
						<input name="tp_dlitem_type" type="hidden" value="dlitem_rating" />
						<input name="tp_dlitem_id" type="hidden" value="' . $dlitem['id'] . '" />
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>
				';
            } else {
                echo '
					<div class="ratingoption"><em class="smalltext">' . $txt['tp-dlhaverated'] . '</em></div>';
            }
            echo '
					<hr />
					<div class="post">
						<p class="floatright" style="padding: 0 0 0.1em 1em;"><a href="' . $dlitem['href'] . '"><img src="' . $settings['tp_images_url'] . '/TPdownloadfile.gif" alt="' . $txt['tp-download'] . '" /></a></p>
						' . $dlitem['description'] . '
					</div>';
            // any extra files attached?
            if (isset($dlitem['subitem']) && is_array($dlitem['subitem'])) {
                echo '
					<div class="morefiles">
						<h4>' . $txt['tp-dlmorefiles'] . '</h4>
						<div class="post">
							<ul>';
                foreach ($dlitem['subitem'] as $sub) {
                    echo '
								<li><a href="', $sub['href'], '"><b>', $sub['name'], '</b></a>&nbsp;&nbsp;<span class="smalltext">', $sub['filesize'], ' / ', $sub['downloads'], ' ', $txt['tp-downloads'], ' / ', $sub['views'], ' ', $txt['tp-views'], '</span></li>';
                }
                echo '
							</ul>
						</div>
					</div>';
            }
        }
        // any screenshot?
        if (!empty($dlitem['sshot'])) {
            echo '
					<br /><img src="' . $dlitem['bigshot'] . '" style="max-width: 100%;" alt="" /></div>';
        }
        echo '
			<span class="botslice"><span></span></span>
				</div>
			</div>
			</div>
		</div>
	</div>';
    } elseif ($context['TPortal']['dlaction'] == 'upload') {
        // check that you can upload
        if (allowedTo('tp_dlmanager') || allowedTo('tp_dlupload')) {
            $show = true;
        } else {
            fatal_error($txt['tp-adminonly']);
        }
        echo '
	 <div class="tborder">
        <div class="title_bar">
            <h4 class="titlebg">' . $txt['tp-dlupload'] . '</h4>
        </div>
		<div class="windowbg">
			<span class="topslice"><span></span></span>
		 <table width="100%" border="0" cellspacing="0" cellpadding="8">
			<tr class="windowbg"><td>
				<form accept-charset="', $context['character_set'], '" name="tp_dlupload" id="tp_dlupload" action="' . $scripturl . '?action=tpmod;dl=upload" method="post" enctype="multipart/form-data" onsubmit="submitonce(this);">
				';
        if ($context['TPortal']['dl_approve'] == '1' && !allowedTo('tp_dlmanager')) {
            echo '<b>! ' . $txt['tp-warnsubmission'] . '</b><br />';
        }
        echo '<div style="text-align: center;" class="smalltext">' . $txt['tp-maxuploadsize'] . ': ' . $context['TPortal']['dl_max_upload_size'] . 'Kb</div><br />
					<table class="formtable">
						<tr>
							<td class="left" style="width: 130px;">' . $txt['tp-dluploadtitle'] . '</td>
							<td class="windbg">
								<input name="tp-dluploadtitle" type="text" value="-no title-" size="40">
							</td>
						</tr><tr>
							<td valign="top" align="right" class="windowbg">' . $txt['tp-dluploadcategory'] . '</td>
							<td class="windowbg">
								<select size="1" name="tp-dluploadcat">';
        foreach ($context['TPortal']['uploadcats'] as $ucats) {
            echo '
									<option value="' . $ucats['id'] . '">', !empty($ucats['indent']) ? str_repeat("-", $ucats['indent']) : '', ' ' . $ucats['name'] . '</option>';
        }
        echo '				</select>
							</td>
						</tr>
						<tr>
							<td align="right" class="windowbg">' . $txt['tp-dluploadtext'] . '</td>
							<td class="windowbg">';
        if ($context['TPortal']['dl_wysiwyg'] == 'html') {
            TPwysiwyg('tp_dluploadtext', '', true, 'qup_tp_dluploadtext', $context['TPortal']['show_wysiwyg'], false);
        } elseif ($context['TPortal']['dl_wysiwyg'] == 'bbc') {
            TP_bbcbox($context['TPortal']['editor_id']);
        } else {
            echo '<textarea name="tp_dluploadtext" rows=5 cols=50 wrap="on"></textarea>';
        }
        echo '			</td>
						</tr>
						<tr>
							<td height="40" align="right" class="windowbg">' . $txt['tp-dluploadfile'] . '</td>
							<td class="windowbg">';
        if (allowedTo('tp_dlmanager') && !isset($_GET['ftp']) || !allowedTo('tp_dlmanager')) {
            echo '<input name="tp-dluploadfile" id="tp-dluploadfile" type="file"> (' . $context['TPortal']['dl_allowed_types'] . ')';
        }
        // file already uploaded?
        if (allowedTo('tp_dlmanager') && !isset($_GET['ftp'])) {
            echo '<br /><input name="tp-dluploadnot" type="checkbox" value="ON"> ' . $txt['tp-dlnoupload'];
        } elseif (allowedTo('tp_dlmanager') && isset($_GET['ftp'])) {
            if (isset($_GET['ftp'])) {
                echo '<input name="tp-dluploadnot" type="hidden" value="ON"><input name="tp-dlupload_ftpstray" type="hidden" value="' . $_GET['ftp'] . '">
				<b>' . $txt['tp-dlmakeitem2'] . ':</b><br />' . $context['TPortal']['tp-downloads'][$_GET['ftp']]['file'];
            }
        }
        // make a new topic too?
        if (allowedTo('tp_dlcreatetopic') || !empty($context['TPortal']['dl_create_topic'])) {
            $allowed = explode(",", $context['TPortal']['dl_createtopic_boards']);
            if (empty($context['TPortal']['dl_createtopic_boards'])) {
                echo '
					</td></tr>
					<tr>
						<td height="40" valign="top" align="right" class="windbg2">' . $txt['tp-dlcreatetopic'] . '</td>
						<td class="windbg2">
							<div class="information">' . $txt['tp-dlmissingboards'] . '</div>';
            } else {
                echo '
						</td></tr>
						<tr>
							<td height="40" valign="top" align="right" class="windbg2">' . $txt['tp-dlcreatetopic'] . '</td>
							<td class="windbg2">
						<input type="checkbox" name="create_topic" /> ' . $txt['tp-dlcreatetopic'] . '<br />';
                if (allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics'])) {
                    echo '
						<input type="checkbox" name="create_topic_sticky" /> ' . $txt['tp-dlcreatetopic_sticky'] . '<br />';
                }
                if (allowedTo('announce_topic')) {
                    echo '
						<input type="checkbox" name="create_topic_announce" /> ' . $txt['tp-dlcreatetopic_announce'] . '<br />';
                }
                echo '
									<select size="1" name="create_topic_board" style="margin: 3px;">';
                foreach ($context['TPortal']['boards'] as $brd) {
                    if (in_array($brd['id'], $allowed)) {
                        echo '
										<option value="' . $brd['id'] . '">', $brd['name'] . '</option>';
                    }
                }
                echo '				</select> ', $txt['tp-dlchooseboard'], '
				<div style="padding: 5px;">
					<textarea name="create_topic_body" style="width: 100%; height: 200px;" rows=5 cols=50 wrap="on"></textarea>
				</div>';
            }
        }
        // can you attach it?
        if (!empty($context['TPortal']['attachitems'])) {
            echo '		</td>
						</tr>
						<tr>
							<td align="right" valign="top" class="windowbg">' . $txt['tp-dluploadattach'] . '</td>
							<td class="windowbg">
								<select size="1" name="tp_dluploadattach">
									<option value="0" selected>' . $txt['tp-none'] . '</option>';
            foreach ($context['TPortal']['attachitems'] as $att) {
                echo '
									<option value="' . $att['id'] . '">' . $att['name'] . '</option>';
            }
            echo '
								</select>';
        }
        echo '
							</td>
						</tr>
						<tr>
							<td align="right" valign="top" class="windowbg">' . $txt['tp-dluploadicon'] . '</td>
							<td class="windowbg">
								<select size="1" name="tp_dluploadicon" onchange="dlcheck(this.value)">
									<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>
								<img align="top" style="margin-left: 2ex;" name="dlicon" src="' . $settings['tp_images_url'] . '/TPblank.gif" alt="" />
							</td>
						</tr>
						<tr>
							<td align="right" class="windowbg">' . $txt['tp-dluploadpic'] . '</td>
							<td height="80" class="windowbg">
								<input name="tp_dluploadpic" id="tp_dluploadpic" type="file" size="60">
								<input name="tp-uploadcat" type="hidden" value="' . $context['TPortal']['dlitem'] . '">
								<input name="tp-uploaduser" type="hidden" value="' . $context['user']['id'] . '">
							</td>
						<tr class="windowbg">
							<td colspan="2" align="center">
								<input type="submit" name="tp-uploadsubmit" id="tp-uploadsubmit" value="' . $txt['tp-dosubmit'] . '">
							</td>
						</tr>
					</table>
				</form>
			</td>
		</tr>
	</table>
			<span class="botslice"><span></span></span>
		</div>	
	</div>
	<script type="text/javascript">
		function dlcheck(icon)
		{
			document.dlicon.src= "' . $boardurl . '/tp-downloads/icons/" + icon
		 }
	</script>';
    }
    // show the stats page...
    if ($context['TPortal']['dlaction'] == 'stats') {
        $maxcount = 10;
        echo '
	<div class="tborder">
		<div class="cat_bar">
			<h3 class="catbg">' . $txt['tp-downloadsection'] . ' - ' . $txt['tp-stats'] . '</h3>
		</div>
		<table width="100%" border="0" cellspacing="1" cellpadding="5" class="bordercolor">
			<tr class="titlebg">
				<td colspan="2">' . $maxcount . ' ' . $txt['tp-dlstatscats'] . '</td>
				<td colspan="2">' . $maxcount . ' ' . $txt['tp-dlstatsviews'] . '</td>
			</tr>
			<tr>
				<td class="windowbg2" ><img src="' . $settings['tp_images_url'] . '/TPboard.gif" alt="" /></td><td class="windowbg" valign="top" width="50%">';
        // top categories
        echo '<table width="100%" cellpadding="2" cellspacing="0">';
        $counter = 0;
        if (isset($context['TPortal']['topcats'][0]['items'])) {
            $maxval = $context['TPortal']['topcats'][0]['items'];
        }
        if (isset($context['TPortal']['topcats']) && count($context['TPortal']['topcats']) > 0) {
            foreach ($context['TPortal']['topcats'] as $cats) {
                if ($counter < $maxcount) {
                    echo '
						<tr>
							<td width="60%">
								' . $cats['link'] . '</td><td><img src="' . $settings['tp_images_url'] . '/TPbar.gif" height="15" alt="" width="', $cats['items'] > 0 ? ceil(100 * ($cats['items'] / $maxval)) : '1', '%" /></td><td  width="5%" style="padding-left: 2ex;">' . $cats['items'] . '
							</td>
						</tr>';
                    $counter++;
                }
            }
        } else {
            echo '
						<tr><td>&nbsp;</td></tr>';
        }
        echo '
					</table>';
        echo '
				</td>
				<td class="windowbg2">
					<img src="' . $settings['tp_images_url'] . '/TPinfo.gif" alt="" />
				</td>
				<td class="windowbg" valign="top" width="50%">';
        // top views
        echo '<table width="100%" cellpadding="2" cellspacing="0">';
        $counter = 0;
        if (isset($context['TPortal']['topviews'][0]['views'])) {
            $maxval = $context['TPortal']['topviews'][0]['views'];
        }
        if (isset($context['TPortal']['topviews']) && count($context['TPortal']['topviews']) > 0) {
            foreach ($context['TPortal']['topviews'] as $cats) {
                if ($counter < $maxcount) {
                    echo '
						<tr>
							<td width="60%">' . $cats['link'] . '</td>
							<td>
								<img src="' . $settings['tp_images_url'] . '/TPbar.gif" height="15" alt="" width="', $cats['views'] > 0 ? ceil(100 * ($cats['views'] / $maxval)) : '1', '%" />
							</td>
							<td  width="5%" style="padding-left: 2ex;">' . $cats['views'] . '</td>
						</tr>';
                    $counter++;
                }
            }
        } else {
            echo '
						<tr><td>&nbsp;</td></tr>';
        }
        echo '
					</table>';
        echo '
				</td>
			</tr>
			<tr class="titlebg">
				<td colspan="2">' . $maxcount . ' ' . $txt['tp-dlstatsdls'] . '</td>
				<td colspan="2">' . $maxcount . ' ' . $txt['tp-dlstatssize'] . '</td>
			</tr>
			<tr>
				<td class="windowbg2"><img src="' . $settings['tp_images_url'] . '/TPinfo2.gif" alt="" /></td>
				<td class="windowbg" valign="top">';
        // top downloads
        echo '
					<table width="100%" cellpadding="2" cellspacing="0">';
        $counter = 0;
        if (isset($context['TPortal']['topitems'][0]['downloads'])) {
            $maxval = $context['TPortal']['topitems'][0]['downloads'];
        }
        if (isset($context['TPortal']['topitems']) && count($context['TPortal']['topitems']) > 0) {
            foreach ($context['TPortal']['topitems'] as $cats) {
                if ($counter < $maxcount) {
                    echo '
						<tr>
							<td width="60%">' . $cats['link'] . '</td>
							<td><img src="' . $settings['tp_images_url'] . '/TPbar.gif" height="15" alt="" width="', $maxval > 0 ? ceil(100 * ($cats['downloads'] / $maxval)) : 0, '%" /></td>
							<td width="5%">' . $cats['downloads'] . '</td>
						</tr>';
                    $counter++;
                }
            }
        } else {
            echo '
						<tr><td>&nbsp;</td></tr>';
        }
        echo '
					</table>';
        echo '
				</td>
				<td class="windowbg2"><img src="' . $settings['tp_images_url'] . '/TPinfo2.gif" alt="" /></td>
				<td class="windowbg" valign="top">';
        // top filesize
        echo '
					<table width="100%" cellpadding="2" cellspacing="0">';
        $counter = 0;
        if (isset($context['TPortal']['topsize'][0]['size'])) {
            $maxval = $context['TPortal']['topsize'][0]['size'];
        }
        if (isset($context['TPortal']['topsize']) && count($context['TPortal']['topsize']) > 0) {
            foreach ($context['TPortal']['topsize'] as $cats) {
                if ($counter < $maxcount) {
                    echo '
						<tr>
							<td width="60%">' . $cats['link'] . '</td>
							<td><img src="' . $settings['tp_images_url'] . '/TPbar.gif" height="15" alt="" width="', ceil(100 * ($cats['size'] / $maxval)), '%" /></td>
							<td width="5%">' . floor($cats['size'] / 1000) . 'kb</td>
						</tr>';
                    $counter++;
                }
            }
        } else {
            echo '
						<tr><td>&nbsp;</td></tr>';
        }
        echo '
					</table>
				</td>
			</tr>
		</table>
	</div>
	</div>';
    }
    // how about user-editing?
    if ($context['TPortal']['dlaction'] == 'useredit') {
        foreach ($context['TPortal']['dl_useredit'] as $cat) {
            echo '
		<form accept-charset="', $context['character_set'], '" name="dl_useredit" action="' . $scripturl . '?action=tpmod;dl=admin" enctype="multipart/form-data" onsubmit="syncTextarea();" method="post">
			<table width="100%" cellspacing="1" cellpadding="7" class="tborder">
				<tr>
					<td colspan="2" class="titlebg">' . $txt['tp-useredit'] . '</td>
				</tr>
				<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'], html_entity_decode($cat['description'], ENT_QUOTES), true, 'qup_dladmin_text', $context['TPortal']['show_wysiwyg']);
            } 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>
				</tr><tr>
					<td class="windowbg2" valign="top" align="right">' . $txt['tp-dluploadicon'] . '</td>
					<td valign="top" class="windowbg2">
						<select size="1" name="dladmin_icon' . $cat['id'] . '" onchange="dlcheck(this.value)">
							<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="', substr($cat['icon'], 0, 4) == 'http' ? $cat['icon'] : $boardurl . '/' . $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">' . $cat['file'] . '
						<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">
					' . $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'] . '/TPexclamation.gif" alt="' . $txt['tp-dlapprove'] . '"  /> </td>
					<td valign="top" class="windowbg2"><b>' . $txt['tp-dlnotapprovedyet'] . '</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"><ul>	';
            foreach ($cat['subitem'] as $sub) {
                echo '<li><b><a href="', $sub['href'], '">', $sub['name'], '</a></b> (', $sub['file'], ')
							', $sub['filesize'], ' &nbsp;&nbsp;<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'] . '
							</li>';
            }
            echo '</ul>
					</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']['useritems'] 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']['uploadcats'] 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['sshot'] . '"><br /><br />
						<div style="overflow: auto;">', $cat['sshot'] != '' ? '<img src="' . (substr($cat['sshot'], 0, 4) == 'http' ? $cat['sshot'] : $boardurl . '/' . $cat['sshot']) . '" alt="" />' : '&nbsp;', '</div></td>
				</tr>
				<tr>
					<td colspan="2" class="windowbg">
						<input name="dlsend" type="submit" value="' . $txt['tp-submit'] . '">
						<input name="sc" type="hidden" value="' . $context['session_id'] . '">
						<input name="dl_useredit" type="hidden" value="' . $cat['id'] . '">
					</td>
				</tr>
			</table>
		</form>';
    }
    if ($context['TPortal']['dlaction'] == 'search') {
        echo '
		<div class="tborder">
			<div class="cat_bar">
				<h3 class="catbg">' . $txt['tp-downloadsection'] . ' - ' . $txt['tp-dlsearch'] . '</h3>
			</div>
			<div class="windowbg">
				<span class="topslice"><span></span></span>
				<table border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td >
							<form accept-charset="', $context['character_set'], '" id="dl_search_form" action="' . $scripturl . '?action=tpmod;dl=results" enctype="multipart/form-data" method="post">
								<table cellpadding="5" cellspacing="1" width="100%" >
									<tr>
										<td align="right">', $txt['tp-search'], ':</td>
										<td class="input_td">
											<input type="text" size="60" name="dl_search" id="dl_search" />
										</td>
									</tr>
									<tr>
										<td valign="top" align="right"></td>
										<td  class="input_td">
										<input type="checkbox" id="dl_searcharea_name" /> ', $txt['tp-searcharea-name'], '<br />
										<input type="checkbox" id="dl_searcharea_descr" /> ', $txt['tp-searcharea-descr'], '<br />
										</td>
									</tr>
									<tr>
										<td colspan="2" align="center">
											<input type="submit" value="', $txt['tp-search'], '" />
											<input type="hidden" name="sc" value="', $context['session_id'], '" />
										</td>
									</tr>
								</table>
							</form>
						</td>
					</tr>
				</table>
				<span class="botslice"><span></span></span>
			</div>
		</div>
		</div>';
    }
    if ($context['TPortal']['dlaction'] == 'results') {
        echo '
		<div class="tborder">
			<div class="cat_bar">
				<h3 class="catbg">', $txt['tp-dlsearchresults'], '
					' . $txt['tp-searchfor'] . '  &quot;' . $context['TPortal']['dlsearchterm'] . '&quot;
				</h3>
			</div>
			<form style="margin: 0; padding: 0;" accept-charset="', $context['character_set'], '"  id="dl_search_form" action="' . $scripturl . '?action=tpmod;dl=results" method="post">
				<div style="padding: 10px;" class="windowbg">
					<input type="text" style="font-size: 1em; margin-bottom: 0.5em; padding: 3px; width: 90%;" value="' . $context['TPortal']['dlsearchterm'] . '" name="dl_search" /><br />
					<input type="checkbox" name="dl_searcharea_name" checked="checked" /> ', $txt['tp-searcharea-name'], '
					<input type="checkbox" name="dl_searcharea_desc" checked="checked" /> ', $txt['tp-searcharea-descr'], '
					<input type="hidden" name="sc" value="', $context['session_id'], '" />
					<input type="submit" value="', $txt['tp-send'], '" />
				</div>
			</form>
				';
        $bb = 1;
        foreach ($context['TPortal']['dlsearchresults'] as $res) {
            echo '
			<h4 class="tpresults windowbg"><a href="' . $scripturl . '?action=tpmod;dl=item' . $res['id'] . '">' . $res['name'] . '</a></h4>
			<div class="windowbg tpresults" style="padding-top: 2px;">
				<div class="middletext">', $res['body'] . '</div>
				<div class="smalltext" style="padding-top: 0.4em;">', $txt['tp-by'] . ' ' . $res['author'] . ' - ', timeformat($res['date']), '</div>
			</div>';
            $bb++;
        }
        echo '
		</div>
		</div>';
    }
    echo '
	</div>';
}