Просмотр файла WAP.php

Размер файла: 55.17Kb
<?php              // <- Do not Remove this line
// ----------------------------------------------
// ----------------------------------------------
// ----------Sentertainment.net Presents---------
// -----------Unofficial IPB WAP Script----------
// ----------------------------------------------
// ----------------------------------------------
//                   Release v1.8
//
// ============SIMPLIFIED TERMS OF USE===========
// ----Under Basic GNU General Public License----
// Extra:
// This script is in no affiliation with Invision
// or any of it's members and this script may not
// be sold in any form.
// As request by the author of this code, we ask
// (not rquire) that in the event of modding this
// code, that you send your modded copy to the
// author for open-source development.
// If any of these terms are not to your needs,
// then permission from the author is before any
// terms of use may be broken.
// THIS HEADER MAY NOT BE CHANGED OR REMOVED
// WITHOUT PERMISSION FROM THE ORIGINAL CREATORS
//
//
// INSTRUCTIONS:
// Just Fill out all required info to meet your Forums
// and place this file anywhere you please on your
// server.  Unrestricted fil access to this script
// may be required for Attachments to work.
//
//
// ===================CREDITS====================
// --------Giving Credit Where it is Due!--------
//
// TeraByte:
// Brought unnoticed Nav Error to my attention!
//
// Israel de Souza Rocha of PHPClasses.org:
// Had a simple translation procedure by leeching
// off Google! (I used his code)
//
// Palach:
// Saw a bug that I thought I had fixed long ago.
//
// All the rest goes to me! ;)


// ----------------------------------------------
// -------------Database Login Info--------------
// ----------------------------------------------
$dbuser = "bart";              // Forum SQL Database Access Username
$dbpass = "bart";                  // Forum SQL Database Access Password
$dbname = "bart";          // Forum SQL Database Name
$dbserver = "localhost";              // Database Server (Usualy "localhost")


// ----------------------------------------------
// ----------------Forum Settings----------------
// ----------------------------------------------
$furl = "softoplanet.ru/";         // Forum URL (Without "http://www.")
$uploadsdir = "uploads/";             // Forum Uploads Directory
$boardtype = 1;                       // *Feature Not Yet Complete* Board type; 1 = IPB, 2 = phpBB
$boardtitle = "Site Forums";          // Script Display Title
$boardname = "Welcome to My Forums";  // Board Display Name
$forumpostsperpage = 5;               // Number of topics to show per page (Forum View)
$topicpostsperpage = 3;               // Number of posts to show per page (Topic View)
$pagecreation = 1;                    // Show Page Creation Time; 1=True, 0=False
$msgcharlimit = 75;                   // Character Limit for forum views
$topiccharlimit = 300;                // Character Limit for topic views
$tableprefix = "1ibf_";                // Table name prefix ex: ibf_posts
$enattach = 1;                        // Enable Attachments; 1 = Yes, 0 = No
$resimgview = 1;                      // Disable Images if current Member seetings have them disabled; 1 = Yes, 0 = No
$enemoticons = 1;                     // Enable Emoticons & Images; 1 = Yes, 0 = No
$autowap = 1;                         // Detect WAP access automatically; Display WAP Access Only
$showses = 1;                         // Show Session count (Current Visistors); 1 = Yes, 0 = No
$sesmin = 30;                         // Counts visitors within * min; Only works when $showses is enabled
$loginsesmin = 10;                    // Login sessions last * min when idle
$manageses = 0;                       // Allow Script to Manage (Delete) Old Sessions
$sesdeltime = 60;                     // Deletes Sessions within * min; Only works when $manageses is enabled
$viewdetails = 1;                     // Show Last Post Details in Forum Views; 1 = Yes, 0 = No
$allowlogin = 1;                      // Allow Memebers to Login (Show Login Info & Pages); 1 = Yes, 0 = No
$permview = 1;                        // Display Forums According to User Permissions; 1 = Yes, 0 = No
$navmode = 0;                         // Forum Navigation; 1 = Radio Buttons, 0 = Hyperlinks
$forumviewnavmode = 0;                // Forum View Navigation (Radio Buttons May result in Error if over 15 forums)
$followperms = 1;                     // Respect IPB Read/Write/Reply/Edit Permissions; 1 = Yes, 0 = No
$showpinned = 1;                      // Show pinned topics in forum view; 1 = Yes, 0 = No
$allowreply = 1;                      // Allow Posting replies via WAP; 1 = Yes, 0 = No
$allownewtopics = 1;                  // Allow Posting new topics via WAP; 1 = Yes, 0 = No
// Original IPB Database Driver required for making posts
$ipb_db_driver = "/IPB Directory/sources/Drivers/mySQL.php";
// Tanslation Languages: en-English, de-Gernan, es-Spanish, fr-French, it-Italian, pt-Portuguese
$trans_text = 0;                      // Allow Translation of forums (Show Language menu); 1 = Yes, 0 = No
$trans_lang_from = "en";              // Language to Translate from.


// Below this line is forum specific data already set for
// Invision Power Boards.

// ------------------Table Info------------------
If ($boardtype == 1) {
        // Deafult IPB Configuration
        $poststable = "posts";
        $categoriestable = "categories";
        $forumstable = "forums";
        $topicstable = "topics";
        $sessionstable = "sessions";
        $memberstable = "members";
  
        $tid_column = "tid";
        $pid_column = "pid";
        $topic_id_column = "topic_id";
        $member_id_column = "member_id";
        $member_name_column = "member_name";
        $forum_id_column = "forum_id";
        $ip_address_column = "ip_address";
        $running_time_column = "running_time";
        $post_id_column = "post_id";
        $category_column = "category";
        $name_column = "name";
        $position_column = "position";
        $last_post_column = "last_post";
        $title_column = "title";
        $post_column = "post";
        $post_date_column = "post_date";
        $posts_column = "posts";
        $views_column = "views";
        $author_name_column = "author_name";
        $pinned_column = "pinned";
} else {
        // No Support for phpBB yet! :(
}


// ----------------------------------------------
// ----------------------------------------------
// ---------Do Not Change Below this line--------
// ----------------------------------------------
// ----------------------------------------------
If ($autowap == 1) {
        if(strpos(strtoupper($HTTP_ACCEPT),'VND.WAP.WML') > 0) {
                $brow = 'WML';
        } else {
                $browser=substr(trim($HTTP_USER_AGENT),0,4);
                if($browser=='Noki' || // Nokia phones and emulators
                        $browser=='Eric' || // Ericsson WAP phones and emulators
                        $browser=='WapI' || // Ericsson WapIDE 2.0
                        $browser=='MC21' || // Ericsson MC218
                        $browser=='AUR ' || // Ericsson R320
                        $browser=='R380' || // Ericsson R380
                        $browser=='UP.B' || // UP.Browser
                        $browser=='WinW' || // WinWAP browser
                        $browser=='UPG1' || // UP.SDK 4.0
                        $browser=='upsi' || // another kind of UP.Browser ??
                        $browser=='QWAP' || // unknown QWAPPER browser
                        $browser=='Jigs' || // unknown JigSaw browser
                        $browser=='Java' || // unknown Java based browser
                        $browser=='Alca' || // unknown Alcatel-BE3 browser (UP based?)
                        $browser=='MITS' || // unknown Mitsubishi browser
                        $browser=='MOT-' || // unknown browser (UP based?)
                        $browser=='My S' || // unknown Ericsson devkit browser ?
                        $browser=='WAPJ' || // Virtual WAPJAG www.wapjag.de
                        $browser=='fetc' || // fetchpage.cgi Perl script from www.wapcab.de
                        $browser=='ALAV' || // yet another unknown UP based browser ?
                        $browser=='Wapa') // another unknown browser (Web based 'Wapalyzer'?)
                {
                        $brow = 'WML';
                } else {
                        $brow = 'HTML';
                }
        }
        if($brow == 'HTML') {
                header("Content-type: text/html");
                echo("<p><b>WAP Access Only!</b><br/><br/>Click <a href=\"http://www." . $furl . "\">here</a> to visit the HTML enabled forums.");
                exit;
        }
}


// Send Header
If (!substr($pid, 0 , 1)=="f") {
        header("Content-type: text/vnd.wap.wml");
}

// Connect to Database
$dbcn = @mysql_connect($dbserver, $dbuser, $dbpass);
if (!$dbcn) {
        echo("Unable to connect to Database server");
        exit();
}
if (!@mysql_select_db($dbname) ) {
        echo("Unable to connect to Database");
        exit();
}

// Split Variables (Some devices can't handle multiple variables well)
If (!$tid_page==Null) {
        $array_tid_page = split("_", $tid_page);
        $tid = $array_tid_page[0];
        $page = $array_tid_page[1];
}
If (!$fid_page==Null) {
        $array_fid_page = split("_", $fid_page);
        $fid = $array_fid_page[0];
        $page = $array_fid_page[1];
}
If (!$page_action==Null) {
        $array_page_action = split("_", $page_action);
        $page = $array_page_action[0];
        $action = $array_page_action[1];
}
If (!$tid_pid_page==Null) {
        $array_tid_pid_page = split("_", $tid_pid_page);
        $ptid = $array_tid_pid_page[0];
        $ppid = $array_tid_pid_page[1];
        $ppage = $array_tid_pid_page[2];
}

If (!$tid_fid==Null) {
        $array_tid_fid = split("_", $tid_fid);
        $tid = $array_tid_fid[0];
        $fid = $array_tid_fid[1];
}

If (!$tid_fid_newreply==Null) {
        $array_tid_fid_newreply = split("_", $tid_fid_newreply);
        $tid = $array_tid_fid_newreply[0];
        $fid = $array_tid_fid_newreply[1];
        $newreply = $array_tid_fid_newreply[2];
}

If (!$tid_fid_newreply_reply==Null) {
        $array_tid_fid_newreply_reply = split("_", $tid_fid_newreply_reply);
        $tid = $array_tid_fid_newreply_reply[0];
        $fid = $array_tid_fid_newreply_reply[1];
        $newreply = $array_tid_fid_newreply_reply[2];
        $reply = $array_tid_fid_newreply_reply[3];
}

If (!$action_login==Null) {
        $array_action_login = split("_", $action_login);
        $action = $array_action_login[0];
        $LoginUsername = $array_action_login[1];
        $LoginPassword = $array_action_login[2];
}

// Convert HTML to WML Code
function html2wml($boardcode){
        global $enemoticons;
        $boardcode = str_replace("<i>", "", $boardcode);
        $boardcode = str_replace("</i>", "", $boardcode);
        $boardcode = str_replace("<!--QuoteEEnd-->", "</i>", $boardcode);
        $boardcode = str_replace("<!--QuoteEBegin-->", "<i>", $boardcode);
        If ($enemoticons == 1) {
                $keepstr = "<br><img><i><br>";
        } else {
                $keepstr = "<br><i><br>";
        }
        $boardcode = str_replace("</br>", "<br/>", str_replace("<br>", "<br/>", str_replace(":/mlink:", "\">MOBILE LINK</a>", str_replace(":mlink:", "<a href=\"", strip_tags($boardcode, $keepstr)))));
        $boardcode = str_replace("<br/><br/>", "<br/>", $boardcode);
        $boardcode = str_replace("<br/><br/>", "<br/>", $boardcode);
        $boardcode = html_entity_decode2($boardcode);
        $boardcode = wmlspecialchars($boardcode);
        $boardcode = str_replace(wmlspecialchars("<br/>"), "<br/>", $boardcode);
        $boardcode = str_replace(wmlspecialchars("<i>"), "<i>", $boardcode);
        $boardcode = str_replace(wmlspecialchars("</i>"), "</i>", $boardcode);
        If ($enemoticons == 1) {
                $boardcode = str_replace(wmlspecialchars("<img src='http://"), "<img src=\"http://", $boardcode);
                $boardcode = str_replace(wmlspecialchars("' border='0' style='vertical-align:middle' alt='"), "\" alt=\"", $boardcode);
                $boardcode = str_replace(wmlspecialchars("' border='0' alt='"), "\" alt=\"", $boardcode);
                $boardcode = str_replace(wmlspecialchars("' />"), "\" />", $boardcode);
        }
        return $boardcode;
}

// Convert Special Characters to WML
function wmlspecialchars($wml) {
        $wml = str_replace("&#036;", "$", $wml);
        $wml = str_replace("&#064;", "@", $wml);
        $wml = str_replace("&#39;", "'", $wml);
        $wml = str_replace("&#33;", "!", $wml);
        $wml = str_replace("$", "$$", $wml);
        $wml = str_replace("&", "&amp;", $wml);
        $wml = str_replace("<", "&lt;", $wml);
        $wml = str_replace(">", "&gt;", $wml);
        $wml = str_replace("'", "&apos;", $wml);
        $wml = str_replace("\"", "&quot;", $wml);
        $wml = str_replace("  ", "&nbsp; ", $wml);
        $wml = str_replace(" &nbsp;", "&nbsp;&nbsp;", $wml);
        return $wml;
}

function wml_entity_decode($wml) {
        $wml = str_replace("&amp;", "&", $wml);
        $wml = str_replace("&quot;", "\"", $wml);
        $wml = str_replace("&apos;", "'", $wml);
        $wml = str_replace("&gt;", ">", $wml);
        $wml = str_replace("&lt;", "<", $wml);
        $wml = str_replace("$$", "$", $wml);

        return $wml;
}

// Add-on to html_enity_decode for some characters
function html_entity_decode2($html) {
        $html = str_replace("&#036;", "$", $html);
        $html = str_replace("&#39;", "'", $html);
        $html = str_replace("&#33;", "!", $html);
        $html = str_replace("&#91;", "[", $html);
        $html = str_replace("&#93;", "]", $html);
        $html = html_entity_decode($html, ENT_QUOTES);
        return $html;
}

// Create Page Navigation
function topicpagenav($result, $page, $tid){
        global $PHP_SELF;
        global $topicpostsperpage;
        $returnstr = "";
        $num = (int)((mysql_num_rows($result) - 1)/ $topicpostsperpage);
        If (($page - 3)>0) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_0#viewtopic\">1</a>...";
        }
        If (($page - 3) > -1) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . ($page - 3) . "#viewtopic\">" . (intval($page) - 2) . "</a>";
        }
        If (($page - 2) > -1) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . ($page - 2) . "#viewtopic\">" . (intval($page) - 1) . "</a>";
        }
        If (($page - 1) > -1) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . ($page - 1) . "#viewtopic\">" . (intval($page)) . "</a>";
        }
        $returnstr = $returnstr . ($page + 1);
        If (($page) < $num) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . ($page + 1) . "#viewtopic\">" . (intval($page) + 2) . "</a>";
        }
        If (($page + 1) < $num) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . ($page + 2) . "#viewtopic\">" . (intval($page) + 3) . "</a>";
        }
        If (($page + 2) < $num) {
                $returnstr = $returnstr . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . ($page + 3) . "#viewtopic\">" . (intval($page) + 4) . "</a>";
        }
        If (($page + 3) < $num) {
                $returnstr = $returnstr . "...<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . $num . "#viewtopic\">" . ($num + 1) . "</a>";
        }
        return $returnstr;
}

// Limit text on Forum Views & Convert Lines
function docharlimit($msgtext){
        global $msgcharlimit;
        $msgtext = str_replace("<br/>", " ", $msgtext);
        $msgtext = str_replace("  ", "&nbsp; ", $msgtext);
        $msgtext = strip_tags($msgtext);
        $varx = 0;
        $newmsgtext = "";
        if ($msgcharlimit < strlen($msgtext)) {
                $msgwordarray = split(" ", $msgtext);
                $continuemsgtrim = true;
                while ($varx < count($msgwordarray) && $continuemsgtrim == true) {
                        If ($msgcharlimit > strlen($newmsgtext . " " . $msgwordarray[$varx + 1])) {
                                $newmsgtext = $newmsgtext . $msgwordarray[$varx + 1] . " ";
                        } else {
                                $continuemsgtrim = false;
                        }
                        $varx = $varx + 1;
                }
                $newmsgtext = substr($newmsgtext, 0, strlen($newmsgtext) - 1) . "...";
        } else {
                $newmsgtext = $msgtext;
        }

        return $newmsgtext;
}

function dosimplecharlimit($msgtext, $tid, $pid, $page){
        global $topiccharlimit;
        global $PHP_SELF;
        $varx = 0;
        $newmsgtext = "";
        if ($topiccharlimit < strlen($msgtext)) {
                $msgtext = strip_tags($msgtext, "<br/>");
                $msgwordarray = split(" ", $msgtext);
                $continuemsgtrim = true;
                while ($varx < count($msgwordarray) && $continuemsgtrim == true) {
                        If ($topiccharlimit > strlen($newmsgtext . " " . $msgwordarray[$varx + 1])) {
                                $newmsgtext = $newmsgtext . $msgwordarray[$varx + 1] . " ";
                        } else {
                                $continuemsgtrim = false;
                        }
                        $varx = $varx + 1;
                }
                $newmsgtext = substr($newmsgtext, 0, strlen($newmsgtext) - 1) . "...<br/><a href=\"" . $PHP_SELF . "?tid_pid_page=" . $tid . "_" . $pid . "_" . $page . "#viewtopic\">View Full Post</a>";
        } else {
                $newmsgtext = $msgtext;
        }

        return $newmsgtext;
}

function getperm($fid, $perm) {
        global $memgroup;
        global $tableprefix;
        global $forumstable;
        global $followperms;
        $group = mysql_fetch_array(mysql_query("SELECT g_perm_id FROM " . $tableprefix . "groups WHERE g_id='" . $memgroup . "'"));
        $permid = $group['g_perm_id'];
        $perminfo = mysql_fetch_array(mysql_query("SELECT " . $perm . "_perms FROM " . $tableprefix . $forumstable . " WHERE id='" . $fid . "'"));
        $forumperms = $perminfo[$perm . "_perms"];
        If ($forumperms == "*") {
                $retval = true;
        } elseif ($followperms == 0) {
                $retval = true;
        } else {
                $forumperms = split(",", $forumperms);
                $x = 0;
                $retval = false;
                while ($x < count($forumperms)) {
                        If ($permid == $forumperms[$x]) {
                                $retval = true;
                        }
                        $x = $x + 1;
                }
        }
        
        return $retval;
}

// Add language conversion for personal use (optional)
function convert_language($text) {
        global $lng;
        global $trans_lang_from;
        If (strlen(str_replace("\n", "", str_replace(" ", "", $text))) > 0) {
                usleep(120000); // Wait 1/2 Sec to prevent Google server flood (saves time)
                // The original language translation code is by Israel de Souza Rocha
                $f = @file("http://translate.google.com/translate_t?text=" . urlencode($text) . "&langpair=$trans_lang_from|$lng");
                if (!$f == false) {
                        foreach ( $f as $v ) {
                                if (strstr($v, '<textarea')) {
                                        $x = strstr($v, '<textarea');
                                }
                        }
                        $arr = explode('</textarea>', $x);
                        $arr = explode('wrap=PHYSICAL>', $arr[0]);
                        $text = $arr[1];
                }
        }
        flush();
        return $text;
}

function conv_lang($code) {
        $original = get_text($code);
        $new = replace_lang($code, $original);
        return $new;
}

function get_text($code) {
        $new_code = str_replace("<wml>", "<>", $code);
        $new_code = str_replace("</wml>", "<>", $new_code);
        $new_code = str_replace("<card id=\"index\"", "<>", $new_code);
        $new_code = str_replace("<card id=\"view\"", "<>", $new_code);
        $new_code = str_replace("<card id=\"viewcategory\"", "<>", $new_code);
        $new_code = str_replace("<card id=\"viewforum\"", "<>", $new_code);
        $new_code = str_replace("<card id=\"viewtopic\"", "<>", $new_code);
        $new_code = str_replace(" title=\"{$boardtitle}\">", "<>", $new_code);
        $new_code = str_replace("<small>", "<>", $new_code);
        $new_code = str_replace("</small>", "<>", $new_code);
        $new_code = str_replace("</card>", "<>", $new_code);
        $new_code = str_replace("<small>", "<>", $new_code);
        $new_code = str_replace("<br/>", "<>", $new_code);
        $new_code = str_replace("<b>", "<>", $new_code);
        $new_code = str_replace("</b>", "<>", $new_code);
        $new_code = str_replace("<p>", "<>", $new_code);
        $new_code = str_replace("</p>", "<>", $new_code);
        $new_code = str_replace("<i>", "<>", $new_code);
        $new_code = str_replace("</i>", "<>", $new_code);
        $new_code = str_replace("<p align=\"center\">", "<>", $new_code);
        $new_code = str_replace("</a>", "<>", $new_code);
        $new_code = str_replace("\">", "<>", $new_code);
        $new_code = str_replace("<a", "<>", $new_code);
        $new_code = str_replace("<img", "<>", $new_code);
        $new_code = str_replace("<><>", "<>", $new_code);
        $new_code = str_replace("<><>", "<>", $new_code);
        $new_code = str_replace(", ", "<>", $new_code);
        $new_code = wml_entity_decode($new_code);
        $new_code = split("<>", $new_code);
        
        return $new_code;
}

function replace_lang($original_code, $original_text) {
        global $PHP_SELF;
        global $lng;
        $output = $original_code;
        $x = 0;
        while ($x < count($original_text)) {
                $str = $original_text[$x];
                if (!substr_count($str, " href=\"") > 0 && !substr_count($str, " src=\"") > 0 && $x>1) {
                        $output = str_replace($str, wmlspecialchars(convert_language($str)), $output);
                }
                $x = $x + 1;
        }
        $output = str_replace(chr(9), "", $output);
        $output = str_replace($PHP_SELF, $PHP_SELF . "?lng=$lng&", $output);
        $output = str_replace("&?", "&", $output);
        $output = str_replace("\"\">", "\">", $output);
        $output = str_replace("lng=$lng&lng=$lng", "lng=$lng", $output);
        $output = str_replace("lng=$lng&lng=", "lng=", $output);
        return $output;
}

// Post Reply
function reply($post) {
        global $REMOTE_ADDR;
        global $username;
        global $memid;
        global $tid;
        global $fid;
        $time = time();
        mysql_query("INSERT INTO ibf_posts SET append_edit = 0, " .
                "pid = '', " .
                "author_id = '$memid', " .
                "author_name = '$username', " .
                "use_sig = 1, " .
                "use_emo = 1, " .
                "ip_address = '$REMOTE_ADDR', " .
                "post_date = '$time', " .
                "icon_id = 0, " .
                "post = '$post', " .
                "queued = 0, " .
                "topic_id = '$tid', " .
                "forum_id = '$fid', " .
                "new_topic = 0");
        mysql_query("UPDATE ibf_forums SET last_title=last_title, ".
                "last_id='$tid', ".
                "last_post='$time', ".
                "last_poster_name='$username', ".
                "last_poster_id='$memid', ".
                "posts=posts+1 ".
                "WHERE id='$fid'");
        mysql_query("UPDATE ibf_topics SET last_poster_id='$memid', ".
                "last_poster_name='$username', ".
                "last_post='$time', ".
                "posts=posts+1 ".
                "WHERE tid='$tid'");
        mysql_query("UPDATE ibf_stats SET TOTAL_REPLIES=TOTAL_REPLIES+1");
        mysql_query("UPDATE ibf_members SET posts=posts+1 WHERE id='$memid'");
}

// Manage IPB Sessions
If ($manageses==1) {
        mysql_query("DELETE " . $tableprefix . $sessionstable . " WHERE running_time < '" . (time() - $sesdeltime) . "'");
}

// Get User Login & Set Persmissions
If (!substr($pid, 0 , 1)=="f") {
$allowpost = 1;
$memid = 0;
$guestinfo = mysql_fetch_array(mysql_query("SELECT mgroup, name FROM " . $tableprefix . $memberstable . " WHERE id=0 LIMIT 1"));
$memgroup = $guestinfo['mgroup'];
$guestname = $guestinfo['name'];
If (mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id='" . $REMOTE_ADDR . "'")) > 0) {
        mysql_query("UPDATE " . $tableprefix . $sessionstable . " SET id='" . $REMOTE_ADDR . "', $ip_address_column='" . $REMOTE_ADDR . "', running_time='" . time() . "' WHERE id='" . $REMOTE_ADDR . "' LIMIT 1");
} else {
        mysql_query("INSERT INTO " . $tableprefix . $sessionstable . " SET id='" . $REMOTE_ADDR . "', $ip_address_column='" . $REMOTE_ADDR . "', running_time='" . time() . "'");
}
If ($allowlogin==1) {
        $sesinfo = mysql_fetch_array(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id = '" . $REMOTE_ADDR . "' AND $running_time_column > '" . (time() - (60 * $loginsesmin)) . "'"));
        If (!$sesinfo[$member_name_column]=="") {
                $memid = $sesinfo['member_id'];
                If ($REMOTE_ADDR==$sesinfo[$ip_address_column]) {
                        $username = $sesinfo[$member_name_column];
                        If ($sesinfo['restrict_post'] > 0) {
                            $allowpost = 0;
                        }
                        If ($sesinfo['view_img'] == 0 && $resimgview == 1) {
                            $enemoticons = 0;
                        }
                        $loggedin = 1;
                        $memgroup = $sesinfo['member_group'];

                } else {
                        $username = $guestname;
                        $loggedin = 0;
                }
        } else {
                $username= $guestname;
                $loggedin = 0;
        }
        If ($loggedin==0){
                $loginstr = "Welcome<br/><b>$username</b> (<a href=\"$PHP_SELF?action=login#view\">Login</a>)<br/><br/>";
        } else {
                $loginstr = "Welcome<br/><b>$username</b> (<a href=\"$PHP_SELF?action=logout#view\">Logout</a>)<br/><br/>";
        }
} else {
        $loginstr = "";
}
}

// Finish coded header & Main Page
If (!substr($pid, 0 , 1)=="f") {

If ($navmode == 1) {
$mainnavstr = <<<EOF
View Forums:
<select name="action" value="0">
<option><onevent type="onpick"><go href="$PHP_SELF#view" method="post"><postfield name="action" value="last5"/><postfield name="p" value="0"/></go></onevent>Last $forumpostsperpage Active Topics</option>
<option><onevent type="onpick"><go href="$PHP_SELF#view" method="post"><postfield name="action" value="categories"/></go></onevent>Categories</option>
<option><onevent type="onpick"><go href="$PHP_SELF#view" method="post"><postfield name="action" value="forums"/></go></onevent>Forums</option>
</select><br/><br/>
EOF;
} else {
$mainnavstr = <<<EOF
View Forums:<br/>
<a href="$PHP_SELF?action=last5#view">Last $forumpostsperpage Active Topics</a><br/>
<a href="$PHP_SELF?action=categories#view">Categories</a><br/>
<a href="$PHP_SELF?action=forums#view">Forums</a><br/>
<br/><br/>
EOF;
}
// Tanslation Languages: en-English, de-Gernan, es-Spanish, fr-French, it-Italian, pt-Portuguese
If ($trans_text == 1) {
$translate_menu = <<<EOF
<br/><a href="$PHP_SELF?lng=en">English</a>, <a href="$PHP_SELF?lng=fr">French</a>, <a href="$PHP_SELF?lng=de">German</a>, <a href="$PHP_SELF?lng=es">Spanish</a>, <a href="$PHP_SELF?lng=it">Italian</a>, <a href="$PHP_SELF?lng=pt">Portugese</a><br/>
EOF;
} else {
$translate_menu = "";
}

$disstr = <<<EOF
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card id="index" title="{$boardtitle}">
<p align="center"><b>Sentertainment Forums</b><br/><br/>
$loginstr
$mainnavstr
EOF;
        
        // Show Session Counts
        If ($showses==1) {
                $users = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE $running_time_column >" . (time() - (60 * $sesmin)) . ""));
                $members = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE $ip_address_column <> id AND $member_id_column > 0 AND $running_time_column >" . (time() - (60 * $sesmin)) . ""));
                $guests = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE $member_id_column = 0 AND $ip_address_column <> id AND $running_time_column >" . (time() - (60 * $sesmin)) . ""));
                $wap = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id = $ip_address_column AND $running_time_column >" . (time() - (60 * $sesmin)) . ""));
                $wapmembers = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id = $ip_address_column AND $member_id_column > 0 AND $running_time_column > " . (time() - (60 * $sesmin)) . ""));
                $wapguests = $wap - $wapmembers;
$disstr1 = <<<EOF
<b>$users</b> visitors online:<br/>
$members Members, $guests Guests, $wap WAP ($wapmembers, $wapguests)
<br/>
$translate_menu
EOF;
                } else {
                        $disstr1 = "";
        }
$disstr2 = <<<EOF
<br/><small>
Coding by<br/>Sentertainment.net
</small></p>
</card>
<card id="view" title="{$boardtitle}">
EOF;
$display_output = $display_output . $disstr . $disstr1 . $disstr2;
}

if ($action=="") {
} else {
        If ($action=="forums") {
                $disstr = "";
                $t1 = microtime();
                $display_output = $display_output . "<p align=\"center\"><b>Forums</b><br/><br/>";
                If ($forumviewnavmode == 1) {
                        $display_output = $display_output . "<select name=\"id\" value=\"0\">";
                }
                $result = mysql_query("SELECT `$name_column`, `id` FROM `" . $tableprefix . $categoriestable . "` WHERE `id`>0 ORDER BY `$position_column`");
                while ($row = mysql_fetch_array($result)) {
                        If ($forumviewnavmode == 0) {
                                $display_output = $display_output . "<br/><b>" . $row[$name_column] . "</b><br/>";
                        }
                        $result2 = mysql_query("SELECT `$name_column`, `id` FROM `" . $tableprefix . $forumstable . "` WHERE `$category_column`=" . $row['id'] . " ORDER BY `position`");
                        while ($row2 = mysql_fetch_array($result2)) {
                                If (getperm($row2['id'], "read")) {
                                        If ($forumviewnavmode == 0) {
                                                $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?fid=" . $row2['id'] . "#viewforum\">" . wmlspecialchars(html_entity_decode2($row2[$name_column])) . "</a><br/>";
                                        } else {
                                                $display_output = $display_output . "<option><onevent type=\"onpick\"><go href=\"" . $PHP_SELF . "#viewforum\" method=\"post\"><postfield name=\"fid\" value=\"" . $row2['id'] . "\"/></go></onevent>" . wmlspecialchars(html_entity_decode2($row2[$name_column])) . "</option>";
                                        }
                                }
                        }
                }
                If ($forumviewnavmode == 1) {
                        $display_output = $display_output . "</select>";
                }
                $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2 - $t1), 0, 8) . " Sec.</p>";
                }
        }


        If ($action=="last5") {
                $t1 = microtime();
                $display_output = $display_output . "<p align=\"center\"><b>Last " . $forumpostsperpage . " Active Topics</b><br/></p>";
                $result = mysql_query("SELECT * FROM `" . $tableprefix . $topicstable . "` ORDER BY `$last_post_column` DESC LIMIT " . ($page* $forumpostsperpage) . "," . $forumpostsperpage);
                while ($row = mysql_fetch_array($result)) {
                        $result2 = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `$topic_id_column`=" . $row[$tid_column] . " ORDER BY `$post_date_column` DESC LIMIT 0,1");
                        $row2 = mysql_fetch_array($result2);
                        $topic = wmlspecialchars(html_entity_decode2($row[$title_column]));
                        If (getperm($row2['forum_id'], "read")) {
                                $boardcode = docharlimit(html2wml($row2[$post_column]));
                        } else {
                                $boardcode = "You do not have permission to view this topic";
                        }
                        if ($viewdetails == 1) {
                                $display_output = $display_output . "<p><b>Topic: </b><a href=\"" . $PHP_SELF . "?tid_page=" . $row2[$topic_id_column] . "_0#viewtopic\">" . $topic . "</a> (" . $row[$posts_column] . ", " . $row[$views_column] . ")<br/><b>Last Post:</b><br/><i>User:</i> " . $row2[$author_name_column] . "<br/><i>Post:</i> " . $boardcode . "<br/><br/></p>";
                        } else {
                                $display_output = $display_output . "<p><a href=\"" . $PHP_SELF . "?tid_page=" . $row2[$topic_id_column] . "_0#viewtopic\">" . $topic . "</a> (" . $row[$posts_column] . ", " . $row[$views_column] . ")<br/></p>";
                        }
                }
                $display_output = $display_output . "<p align=\"center\">";
                $p2 = $page + 1;
                $p3 = $page - 1;
                if (!$page==0) {
                        $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?page_action=" . $p3 . "_last5#view\">Prev</a> ";
                }
                $result = mysql_query("SELECT * FROM `" . $tableprefix . $topicstable . "` ORDER BY '$last_post_column' DESC LIMIT " . ($p2 * $forumpostsperpage) . "," . $forumpostsperpage);
                if ($result&&$row = mysql_fetch_array($result)) {
                        $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?page_action=" . $p2 . "_last5#view\">Next</a>";
                }
                $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";

                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2 - $t1), 0, 8) . " Sec.</p>";
                }
        }


        If ($action=="categories") {
                $t1 = microtime();
                $display_output = $display_output . "<p align=\"center\"><b>Categories</b><br/><br/>";
                If ($navmode == 1) {
                        $display_output = $display_output . "<select name=\"id\" value=\"0\">";
                }
                $result = mysql_query("SELECT `$name_column`, `id` FROM `" . $tableprefix . $categoriestable . "` WHERE `id`>0 ORDER BY `$position_column`");
                while ($row = mysql_fetch_array($result)) {
                        If ($navmode == 1) {
                                $display_output = $display_output . "<option><onevent type=\"onpick\"><go href=\"" . $PHP_SELF . "#viewcategory\" method=\"post\"><postfield name=\"id\" value=\"" . $row['id'] . "\"/></go></onevent>" . wmlspecialchars(html_entity_decode2($row[$name_column])) . "</option>";
                        } else {
                                $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?id=" . $row['id'] . "#viewcategory\">" . wmlspecialchars(html_entity_decode2($row[$name_column])) . "</a><br/>";
                        }
                }
                If ($navmode == 1) {
                        $display_output = $display_output . "</select>";
                }
                $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2 - $t1), 0, 8) . " Sec.</p>";
                }
        }
        If ($action=="login") {
$disstr = <<<EOF
<p align="center"><b>Login</b><br/><br/>
<do type="accept" label="Login">
<go href="$PHP_SELF?action=login2#view"  method="post">
<postfield name="LoginUsername" value="\$LoginUsername"/>
<postfield name="LoginPassword" value="\$LoginPassword"/>
</go>
</do>
Username:<br/>
<input type="text" name="LoginUsername"/><br/><br/>
Password:<br/>
<input type="password" name="LoginPassword"/><br/>
<a href="$PHP_SELF?action_login=login2_\$(LoginUsername)_\$(LoginPassword)#view">Login</a>
</p>
EOF;
                $display_output = $display_output . $disstr;
        }
        
        If ($action=="login2") {
                $display_output = $display_output . "<p align=\"center\"><b>Login</b><br/><br/>";
                $result = mysql_query("SELECT * FROM " . $tableprefix . $memberstable . " where $name_column = '" . $LoginUsername . "'");
                If (!$result) {
                        $display_output = $display_output . "Login Error<br/><br/><a href=\"$PHP_SELF?action=login#view\">Back</a>";
                }
                If (mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE member_name = '" . $LoginUsername . "' AND $member_id_column > 0")) > 0) {
                        $logintype = 1;
                } else {
                        $logintype = 0;
                }
                If ($row = mysql_fetch_array($result)) {
                        If ($row['password'] == md5($LoginPassword)) {
                                mysql_query("REPLACE INTO " . $tableprefix . $sessionstable . " SET id='" . $REMOTE_ADDR . "', $ip_address_column='" . $REMOTE_ADDR . "', $running_time_column='" . time() . "', $member_name_column='" . $row['name'] . "', $member_id_column='" . $row['id'] . "', browser = '" . $HTTP_USER_AGENT . "', member_group = '" . $row['mgroup'] . "', login_type = $logintype");
                                $display_output = $display_output . "Login Successful<br/><br/>Logged in as $LoginUsername,<br/>Session will timeout when idle for more than $loginsesmin minutes.<br/><br/><a href=\"" . $PHP_SELF . "\">Home</a>";
                        } else {
                                $display_output = $display_output . "Bad Username/Password<br/><br/><a href=\"$PHP_SELF?action=login#view\">Back</a>";
                        }
                } else {
                        $display_output = $display_output . "Bad Username/Password<br/><br/><a href=\"$PHP_SELF?action=login#view\">Back</a>";
                }
                $display_output = $display_output . "</p>";
        }
        
        If ($action=="logout") {
                $display_output = $display_output . "<p align=\"center\"><b>Logout</b><br/><br/>";
                mysql_query("REPLACE INTO " . $tableprefix . $sessionstable . " SET id='" . $REMOTE_ADDR . "', $ip_address_column='" . $REMOTE_ADDR . "', $running_time_column='" . time() . "'");
                $display_output = $display_output . "Logout Complete<br/><br/><a href=\"" . $PHP_SELF . "\">Home</a>";
                $display_output = $display_output . "</p>";
        }
}

If (!substr($pid, 0 , 1)=="f") {
$disstr = <<<EOF
</card>
<card id="viewcategory" title="{$boardtitle}">
<p align="center">
EOF;
$display_output = $display_output . $disstr;
}

if (!$id==Null) {
        $t1_1 = microtime();
        $result = mysql_query("SELECT `$name_column` FROM `" . $tableprefix . $categoriestable . "` WHERE `id`=" . $id);
        $row = mysql_fetch_array($result);
        $display_output = $display_output . "<b>" . wmlspecialchars(html_entity_decode2($row[$name_column])) . "</b><br/><br/>";
        If ($forumviewnavmode == 1) {
                $display_output = $display_output . "<select name=\"fid\" value=\"0\">";
        }
        $result = mysql_query("SELECT `$name_column`, `id` FROM `" . $tableprefix . $forumstable . "` WHERE `$category_column`=" . $id . " ORDER BY `$position_column`");
        while ($row = mysql_fetch_array($result)) {
                If (getperm($row['id'], "read")) {
                        If ($forumviewnavmode == 1) {
                                $display_output = $display_output . "<option><onevent type=\"onpick\"><go href=\"" . $PHP_SELF . "#viewforum\" method=\"post\"><postfield name=\"fid\" value=\"" . $row['id'] . "\"/></go></onevent>" . wmlspecialchars(html_entity_decode2($row[$name_column])) . "</option>";
                        } else {
                                $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?fid=" . $row['id'] . "#viewforum\">" . wmlspecialchars(html_entity_decode2($row[$name_column])) . "</a><br/>";
                        }
                }
        }
        If ($forumviewnavmode == 1) {
                $display_output = $display_output . "</select>";
        }
        $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
        $t2_1 = microtime();
        if ($pagecreation==1) {
                $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2_1 - $t1_1), 0, 8) . " Sec.";
        }
}

If (!substr($pid, 0 , 1)=="f") {
$disstr = <<<EOF
</p>
</card>
<card id="viewforum" title="{$boardtitle}">
EOF;
$display_output = $display_output . $disstr;
}

if (!$fid==Null) {
        $t1_2 = microtime();
        $result = mysql_query("SELECT `$name_column` FROM `" . $tableprefix . $forumstable . "` WHERE `id`=" . $fid);
        $row = mysql_fetch_array($result);
        $display_output = $display_output . "<p align=\"center\"><b>" . wmlspecialchars(html_entity_decode2($row['name'])) . "</b><br/><br/>";
        If (getperm($fid, "read")) {
                $result = mysql_query("SELECT * FROM `" . $tableprefix . $topicstable . "` WHERE `$forum_id_column`=" . $fid . " AND `$pinned_column`=1 ORDER BY `$last_post_column` DESC");
                If ($showpinned==1) {
                        while ($row = mysql_fetch_array($result)) {
                                $topic = wmlspecialchars(html_entity_decode2($row[$title_column]));
                                $display_output = $display_output . "<i>Pinned: </i><a href=\"" . $PHP_SELF . "?tid_page=" . $row['tid'] . "_0#viewtopic\">" . $topic . "</a><br/>";
                        }
                }
                $display_output = $display_output . "<br/></p>";

                $result = mysql_query("SELECT * FROM `" . $tableprefix . $topicstable . "` WHERE `$forum_id_column`=" . $fid . " ORDER BY `$last_post_column` DESC LIMIT " . ($page* $forumpostsperpage) . "," . $forumpostsperpage);
                If (getperm($fid, "read")) {
                        while ($row = mysql_fetch_array($result)) {
                                $result2 = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `$topic_id_column`=" . $row['tid'] . " ORDER BY '$post_date_column' DESC LIMIT 0,1");
                                $row2 = mysql_fetch_array($result2);
                               $topic = wmlspecialchars(html_entity_decode2($row[$title_column]));
                                $boardcode = docharlimit(html2wml($row2[$post_column]));
                                if ($viewdetails == 1) {
                                        $display_output = $display_output . "<p><b>Topic: </b><a href=\"" . $PHP_SELF . "?tid_page=" . $row2[$topic_id_column] . "_0#viewtopic\">" . $topic . "</a> (" . $row[$posts_column] . ", " . $row[$views_column] . ")<br/><b>Last Post:</b><br/><i>User:</i> " . $row2[$author_name_column] . "<br/><i>Post:</i> " . $boardcode . "<br/><br/></p>";
                                } else {
                                        $display_output = $display_output . "<p><a href=\"" . $PHP_SELF . "?tid_page=" . $row2[$topic_id_column] . "_0#viewtopic\">" . $topic . "</a> (" . $row[$posts_column] . ", " . $row[$views_column] . ")<br/></p>";
                                }
                        }
                }
                $display_output = $display_output . "<p align=\"center\">";
                $p2 = $page + 1;
                $p3 = $page - 1;
                if (!$page==0) {
                        $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?fid_page=" . $fid . "_" . $p3 . "#viewforum\">Prev</a> ";
                }
                $result = mysql_query("SELECT * FROM `" . $tableprefix . $topicstable . "` ORDER BY '$last_post_column' DESC LIMIT " . ($p2 * $forumpostsperpage) . "," . $forumpostsperpage);
                if ($result&&$row = mysql_fetch_array($result)) {
                        $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?fid_page=" . $fid . "_" . $p2 . "#viewforum\">Next</a>";
                }
                $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2 - $t1), 0, 8) . " Sec.</p>";
                }
        } else {
                $display_output = $display_output . "<p>You do not have permission to view this forum.<br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
        }
}

If (!substr($pid, 0 , 1)=="f") {
$disstr = <<<EOF
</card>
<card id="viewtopic" title="{$boardtitle}">
EOF;
$display_output = $display_output . $disstr;
}

if (!$tid==Null) {
        $t1_3 = microtime();
        $result = mysql_query("SELECT `$title_column`, `forum_id` FROM `" . $tableprefix . $topicstable . "` WHERE `tid`=" . $tid);
        if (!$result) {
                exit();
        }
        $row = mysql_fetch_array($result);
        $topic_fid = $row["forum_id"];
        $display_output = $display_output . "<p align=\"center\"><b>Topic: " . wmlspecialchars(html_entity_decode2($row[$title_column])) . "</b><br/><br/></p>";
        $result = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `$topic_id_column`=" . $tid . " ORDER BY '$post_date_column' LIMIT " . ($page* $topicpostsperpage) . "," . $topicpostsperpage);
        $result2 = mysql_query("SELECT 'id' FROM `" . $tableprefix . $poststable . "` WHERE `$topic_id_column`=" . $tid . " ORDER BY '$post_date_column'");
        if (!$result) {
                exit();
        }
        If (getperm($topic_fid, "read")) {
                while ($row = mysql_fetch_array($result)) {
                        $boardcode = dosimplecharlimit(html2wml($row[$post_column]),$tid ,$row['pid'], $page);
                        if (!$row['attach_file']==null && $enattach == 1) {
                                $postfile = "<b>Attached:</b> <a href=\"" . $PHP_SELF . "?pid=f" . $row['pid'] . "\">" . $row['attach_file'] . "</a><br/>";
                        } else {
                                $postfile = "";
                        }
                        $display_output = $display_output . "<p><b>User:</b> " . $row[$author_name_column] . "<br/><b>Post:</b> " . $boardcode . "<br/>" . $postfile . "<br/></p>";
                }
        } else {
                $display_output = $display_output . "<p>You do not have permission to view this topic.<br/>";
        }
        $display_output = $display_output . "<p align=\"center\">";
        If ($allowreply==1 && $allowpost==1 && getperm($topic_fid, "reply")) {
                $display_output = $display_output . "<a href=\"$PHP_SELF?tid_fid=" . $tid . "_" . $topic_fid . "#reply\">Reply</a><br/>";
        } else {
                $display_output = $display_output . "Reply<br/>";
        }
        $p2 = $page + 1;
        $p3 = $page - 1;
        if (!$page==0) {
                $display_output = $display_output . "<a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . $p3 . "#viewtopic\">Prev</a> ";
        }
        $result = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `$topic_id_column`=" . $tid . " ORDER BY '$post_date_column' LIMIT " . ($p2 * $topicpostsperpage) . "," . $topicpostsperpage);
        if ($result&&$row = mysql_fetch_array($result)) {
                $display_output = $display_output . " <a href=\"" . $PHP_SELF . "?tid_page=" . $tid . "_" . $p2 . "#viewtopic\">Next</a>";
        }
        $display_output = $display_output . "<br/>" . topicpagenav($result2, $page, $tid);
        $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a>";
        $display_output = $display_output . "</p>";
        $t2_3 = microtime();
        if ($pagecreation==1) {
                $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2_3 - $t1_3), 0, 8) . " Sec.</p>";
        }
} elseif (!$ptid==null) {
        $t1_4 = microtime();
        $result = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `pid`=" . $ppid);
        $display_output = $display_output . "<p align=\"center\"><b>Full Post View</b><br/></p>";
        $row = mysql_fetch_array($result);
                $boardcode = html2wml($row[$post_column]);
                if (!$row['attach_file']==null && $enattach == 1) {
                        $postfile = "<b>Attached:</b> <a href=\"" . $PHP_SELF . "?pid=f" . $row['pid'] . "\">" . $row['attach_file'] . "</a><br/>";
                } else {
                        $postfile = "";
                }
                $display_output = $display_output . "<p>" . $boardcode . "<br/>" . $postfile . "<br/></p>";

        $display_output = $display_output . "<p align=\"center\">";
        $display_output = $display_output . "<br/>" . "<a href=\"" . $PHP_SELF . "?tid_page=" . $ptid . "_" . $ppage . "#viewtopic\">Back</a>";
        $display_output = $display_output . "<br/><a href=\"" . $PHP_SELF . "\">Home</a>";
        $display_output = $display_output . "</p>";
        $t2_4 = microtime();
        if ($pagecreation==1) {
                $display_output = $display_output . "<p align=\"center\"><br/>Card Created in<br/>" . substr(($t2_4 - $t1_4), 0, 8) . " Sec.</p>";
        }
}

If (!substr($pid, 0 , 1)=="f") {
$disstr = <<<EOF
</card>
<card id="reply" title="Reply to Topic">
EOF;
$display_output = $display_output . $disstr;


If (!$fid==null && !$tid==null) {
        $disstr = "<p><do type=\"accept\" label=\"Reply\"><go href=\"$PHP_SELF?tid_fid_newreply=" . $tid . "_" . $fid . "_1#reply\" method=\"post\"><postfield name=\"reply\" value=\"$(reply)\"/></go></do>Reply:<br/><input title=\"Reply\" name=\"reply\"/><br/><a href=" . $PHP_SELF . "?tid_fid_newreply_post=" . $tid . "_" . $fid . "_1_\$(reply)>Post Reply</a><br/><br/><a href=\"" . $PHP_SELF . "?tid=" . $tid . "#viewtopic\">Back</a><br/><a href=\"$PHP_SELF\">Home</a></p>";
        If (!$reply==null) {
                if ($allowpost==1 && getperm($fid, "reply")) {
                        reply($reply);
                        $disstr = "<p align=\"center\"><br/>Reply Successful<br/><br/><a href=\"" . $PHP_SELF . "?tid=" . $tid . "#viewtopic\">Back</a><br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
                } else {
                        $disstr = "<p><do type=\"accept\" label=\"Reply\"><go href=\"" . $PHP_SELF . "?tid_fid_newreply=" . $tid . "_" . $fid . "_1#reply\" method=\"post\"><postfield name=\"reply\" value=\"$(reply)\"/></go></do>Error:<br/>Unable to reply.<br/><br/>Reply:<br/><input title=\"Reply\" name=\"reply\"/><br/><a href=" . $PHP_SELF . "?tid_fid_newreply_post=" . $tid . "_" . $fid . "_1_\$(reply)>Post Reply</a><br/><br/><a href=\"" . $PHP_SELF . "?tid=" . $tid . "#viewtopic\">Back</a><br/><a href=\"" . $PHP_SELF . "\">Home</a></p>";
                }
        }
        $display_output = $display_output . $disstr;
}
$disstr = <<<EOF
</card>
</wml>
EOF;
$display_output = $display_output . $disstr;
}


// Send file if Attachment URL selected
if (substr($pid, 0 , 1)=="f" && $enattach == 1) {
        $pid = substr($pid, 1);
        $result = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `$pid_column`=" . $pid);
        $row = mysql_fetch_array($result);
        $filename = $row['attach_file'];
        $hardfilename = "http://www." . $furl . $uploadsdir . $row['attach_id'];
        $ext = strtolower(substr($filename, (strlen($filename) - 3), 3));
        $ext2 = strtolower(substr($filename, (strlen($filename) - 4), 4));
        $type = "text/vnd.wap.wml";
        // Find MIME Type by extension
        if ($ext=="jar") {
                $type = "application/java-archive";
        } elseif ($ext=="thm") {
                $type = "application/vnd.eri.thm";
        } elseif ($ext=="jad") {
                $type = "text/vnd.sun.j2me.app-descriptor";
        } elseif ($ext=="wbmp") {
                $type = "image/vnd.wap.wbmp";
        } elseif ($ext2=="midi"||$ext=="mid"||$ext=="kar") {
                $type = "audio/midi";
        } elseif ($ext=="gif") {
                $type = "image/gif";
        } elseif ($ext=="jpg"||$ext2=="jpeg"||$ext=="jpe") {
                $type = "image/jpeg";
        } elseif ($ext=="mmf") {
                $type = "application/vnd.smaf";
        } elseif ($ext=="mp3") {
                $type = "audio/x-mpeg";
        } elseif ($ext=="wav") {
                $type = "audio/x-wav";
        } elseif ($ext=="amr") {
                $type = "audio/amr";
        } elseif ($ext=="kws") {
                $type = "kws-audio/x-kws";
        } elseif ($ext=="sis") {
                $type = "application/x-epocinstall";
        } elseif ($ext=="zip") {
                $type = "application/zip";
        } elseif ($ext=="rar") {
                $type = "application/x-rar-compressed";
        }
  
        if (!function_exists('file_get_contents')) {
                $filecontents = implode('', file($hardfilename));
        } else {
                $filecontents = file_get_contents($hardfilename);
        }
        header( "Content-Type: " . $type . "\nContent-Disposition: inline; filename=\"". $filename ."\"\nContent-Length: ".(string)(array_sum(count_chars ($filecontents)) ) );
        $fh = fopen( $hardfilename, 'rb' );
        fpassthru( $fh );
        fclose( $fh );
}

If ($trans_text == 1 && !$lng == null) {
        echo(conv_lang($display_output));
} else {
        echo($display_output);
}
?>