Просмотр файла Creator edition/index.php

Размер файла: 79.46Kb
<?php              // <- Do not Remove this line
// ----------------------------------------------
// ----------------------------------------------
// ----------Sentertainment.net Presents---------
// -----------Unofficial IPB WAP Script----------
// ----------------------------------------------
// ----------------------------------------------
//                   Release v1.96
//                 -Russian Edition-
//
// ============SIMPLIFIED TERMS OF USE===========
// THIS HEADER MAY NOT BE CHANGED OR REMOVED
// WITHOUT PERMISSION FROM THE ORIGINAL CREATOR
// AND "THE CODING BY SENTERTAINMENT" THAT THIS
// SCRIPT DISPLAYS MAY NOT BE REMOVED.
// THIS SCRIPT MAY ONLY BE REDISTRIBUTED AS IS,
// DISTRIBUTION OF DERIVITED COPIES IS PROHIBITED!
// This script is in no affiliation with Invision
// or any of it's members and 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.
// If any of these terms are not to your needs,
// then permission from the author is required
// before any of these terms may be broken.
//
//
// INSTRUCTIONS:
// Just Fill out all required info to meet your
// Forum's settings and place this file anywhere
// you please on your server.  Unrestricted file
// access for this script may be required for
// Attachments to work.
//
//
// ===================CREDITS====================
// ------Giving Credit Where Credit 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.
//
// I would also like to thank all of those who gave
// reccomendations and support for this project!
//
// All the rest goes to me! :P
// oh, and Buy the script if you like it! ;)
//
//
//
// Contact:
// [email protected]
// http://www.sentertainment.net/


// ----------------------------------------------
// -------------Database Login Info--------------
// ----------------------------------------------

#error_reporting (E_ALL ^ E_NOTICE);

$dbuser = "root";                     // Forum SQL Database Access Username
$dbpass = "";                         // Forum SQL Database Access Password
$dbname = "itforums";                 // Forum SQL Database Name
$dbserver = "localhost";              // Database Server (Usualy "localhost")

// ----------------------------------------------
// ----------------Forum Settings----------------
// ----------------------------------------------
$furl = "forums.internet-technologies.ru";         // Forum URL (Without "http://www.")
$uploadsdir = "uploads/";             // Forum Uploads Directory
$boardtype = 1;                       // *Feature Not Yet Complete* Board type; 1 = IPB, 2 = phpBB
$boardtitle = "Сайт об Интернет Технологиях";          // Script Display Title
$boardname = "Приветствуем вас на нашем форуме";  // Board Display Name; Set to "<img src=\"imageurl\" alt=\"\"/>" to use an image!
$forumpostsperpage = 5;               // Number of topics to show per page (Forum View)
$topicpostsperpage = 3;               // Number of posts to show per page (Topic View)
$pagecreation = 0;                    // Show Page Creation Time; 1=True, 0=False
$msgcharlimit = 50;                   // Character Limit for forum views
$topiccharlimit = 300;                // Character Limit for topic views
$tableprefix = "internet_";           // 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 = 0;                         // 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
$post_emoticons = 1;                  // Allow Posting emoticons; 1 = Yes, 0 = No
$emoticon_dir = "html/emoticons/";    // Directory for emoticons (in forum directory)
$post_limit = 30;                     // Seconds until a new post can be created, set to 0 to turn off
$add_views = 1;                       // Add to view counter when viewing a topic; 1 = Yes, 0 = No
$in_topic = 1;                        // Add in-topic location to Session information, only works when enabled on IPB
$in_forum = 1;                        // Add in-forum location to Session information, only works when enabled on IPB
$cat_vis = 1;                         // Respect Category Visibilitly; 2 = Do not show any hidden, 1 = Do Not show Disabled, 0 = Show all hidden
$lng_pack = "lngRussian.php";         // Set to location of WAP IPB Script language pack, leave blank for English
// Post Message, Signature for WAP Posts; [phone] will be converted to device ID
$post_sig = "<br><br><span style=\'color:blue\'><i>*Сообщение отправлено через WAP: <br>[phone]</i></span>";
// 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.

/**** Add by Creator ****/
$memgroup = 2; // Номер группы гостя в таблице *****_groups
$guestname = 'Гость';




// Activate Language Pack, load file if set; load buit-in language if not set.
// Load English as failsafe for missing parts in language pack
$strViewFullPost = "View Full Post";
$strLogin = "Login";
$strLogout = "Logout";
$strWelcome = "Welcome";
$strWAP_Only = "<p><b>Форум доступен только через WAP!</b><br/><br/>Нажмите <a href=\"http://www.{$furl}\">здесь</a>, если желаете посетить наш HTTP-форум.";
$strViewForums = "View Forums:";
$strLast5 = "Last $forumpostsperpage Active Topics";
$strCategories = "Categories";
$strForums = "Forums";
$strEnglish = "English";
$strFrench = "French";
$strGerman = "German";
$strSpanish = "Spanish";
$strItalian = "Italian";
$strPortugese = "Portugese";
$strVisitorsOnline = "visitors online:";
$strMembers = "Members";
$strGuests = "Guests";
$strWAP = "WAP";
$strHome = "Home";
$strCardCreated1 = "Card Created in";
$strCardCreated2 = " Sec.";
$strNoPermTopic = "You do not have permission to view this topic.";
$strNoPermForum = "You do not have permission to view this forum.";
$strNoPermCategory = "You do not have permission to view this category.";
$strLastPost = "Last Post:";
$strUser = "User:";
$strPost = "Post:";
$strPrev = "Prev";
$strNext = "Next";
$strUsername = "Username:";
$strPassword = "Password:";
$strBack = "Back";
$strLoginSuccessful = "Login Successful";
$strLoggedInAs = "Logged in as";
$strTimeOut = "Session will timeout when idle for more than {$loginsesmin} minutes.";
$strBadLogin = "Bad Username/Password";
$strLogoutComplete = "Logout Complete";
$strPinned = "Pinned:";
$strTopic = "Topic:";
$strFloodControl = "{$post_limit} sec. flood control.";
$strNewThread = "New Thread";
$strAttached = "Attached:";
$strReply = "Reply";
$strFullPostView = "Full Post View";
$strReplyToTopic = "Reply to Topic";
$strReply2 = "Reply:";
$strPostReply = "Post Reply";
$strReplyError = "Error:<br/>Unable to reply.";
$strNewTopic = "New Topic";
$strPost2 = "Post";
$strNewTopic2 = "New Topic:";
$strTitle2 = "Title:";
$strTitle = "Title";
$strDesc2 = "Desc:";
$strDesc = "Desc";
$strPostSuccessful = "Post Successful";
$strReplySuccessful = "Reply Successful";
$strViewFullPost = "View Full Post";
$strnavstart = "";
$strnavend = "";


// Get Language pack
If ($lng_pack !== null) {
        include($lng_pack);
}

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

// ------------------Table Info------------------
If ($boardtype == 1) {
        // Deafult IPB Configuration
        $poststable = "posts";
        $categoriestable = "forums";
        $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--------
// ----------------------------------------------
// ----------------------------------------------
header("Cache-Control: no-store, no-cache, must-revalidate");
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($strWAP_Only);
                exit;
        }
}

// 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();
}

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

$phone = split(" ", $HTTP_USER_AGENT);
$phone = $phone[0];

// 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];
}

If (!$fid_title_desc_topicpost==Null) {
        $array_fid_title_desc_topicpost = split("_", $fid_title_desc_topicpost);
        $fid = $array_fid_title_desc_topicpost[0];
        $title = $array_fid_title_desc_topicpost[1];
        $desc = $array_fid_title_desc_topicpost[2];
        $topicpost = $array_fid_title_desc_topicpost[3];
}

// 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><br/>";
        } else {
                $keepstr = "<br><i></br><br/>";
        }
        $boardcode = str_replace(":/mlink:", "\">MOBILE LINK</a>", str_replace(":mlink:", "<a href=\"", strip_tags($boardcode, $keepstr)));

        $boardcode=str_replace("<br />", "<br/>", $boardcode);
        $boardcode=str_replace("<br>", "<br/>", $boardcode);
        $boardcode=str_replace("</br>", "<br/>", $boardcode);

        $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);
                $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 = str_replace("&#092;", "\\", $html);
        $html = str_replace("&#34;", "\"", $html);
        $html = str_replace("&#60;", "<", $html);
        $html = str_replace("&#62;", ">", $html);
        $html = html_entity_decode($html, ENT_QUOTES);
        return $html;
}

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

function conv_num_image($number) {
        if (function_exists('conv_num')) {
                $number = conv_num($number);
        }
        return $number;
}

// 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;
        global $strViewFullPost;
        $varx = 0;
        $newmsgtext = "";
        if ($topiccharlimit < strlen($msgtext)) {
                $msgtext = strip_tags($msgtext, "<br/><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\">{$strViewFullPost}</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 permission_array FROM " . $tableprefix . $forumstable . " WHERE id='{$fid}'"));
        $perminfo = unserialize($perminfo['permission_array']);
        $forumperms=$perminfo[$perm.'_perms'];

        If ($forumperms == "*") {
                $retval = true;
        } elseif ($followperms == 0) {
   //             $retval = true;
                  $retval = false;
        } 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 New Thread
function new_topic($fid, $title, $desc, $post) {
        global $REMOTE_ADDR;
        global $username;
        global $memid;
        global $tid;
        global $tableprefix;
        global $post_sig;
        global $HTTP_USER_AGENT;
        If (function_exists('lngPost')) {
                $title = lngPost($title);
                $desc = lngPost($desc);
                $post = lngPost($post);
        }

        If (post_time()) {
        $last_tid = mysql_fetch_array(mysql_query("SELECT tid FROM " . $tableprefix . "topics ORDER BY tid DESC LIMIT 1"));
        $last_tid = $last_tid['tid'];
        $tid = $last_tid + 1;
        $time = time();
        $phone = split(" ", $HTTP_USER_AGENT);
        $phone = $phone[0];
        $post = $post . str_replace("[phone]", $phone, $post_sig);

        // Create new topic
        mysql_query("INSERT INTO " . $tableprefix . "topics SET tid = $tid, " .
                "title = '$title', " .
                "description = '$desc', " .
                "state = 'open', " .
                "posts = 0, " .
                "starter_id = '$memid', " .
                "start_date = '$time', " .
                "last_poster_id = '$memid', " .
                "last_post = '$time', " .
                "icon_id = 0, " .
                "starter_name = '$username', " .
                "last_poster_name = '$username', " .
                "poll_state = 0, " .
                "last_vote = 0, " .
                "views = 0, " .
                "forum_id = '$fid', " .
                "approved = 1, " .
                "author_mode = 1, " .
                "pinned = 0, " .
                "total_votes = 0");

        // Add post
        mysql_query("INSERT INTO " . $tableprefix . "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 = 1");

        mysql_query("UPDATE " . $tableprefix . "forums SET last_title='$title', ".
                "last_id='$tid', ".
                "last_post='$time', ".
                "last_poster_name='$username', ".
                "last_poster_id='$memid', ".
                "topics=topics+1, ".
                "posts=posts+1 ".
                "WHERE id='$fid'") or die(mysql_error());

        /****************** Обновление кеша форума ****************************/
        $result=mysql_query("SELECT cs_key, cs_value "
                            ."FROM ".$tableprefix."cache_store "
                            ."WHERE cs_key='forum_cache' OR cs_key='stats'");
        while($cache=mysql_fetch_array($result))
        {
             if($cache['cs_key']=='forum_cache')
             {
                $cache=unserialize($cache['cs_value']);
                $cache[$fid]['last_title']=$title;
                $cache[$fid]['last_post']=$time;
                $cache[$fid]['last_poster_name']=$username;
                $cache[$fid]['last_poster_id']=$memid;
                $cache[$fid]['topics']++;
                $cache[$fid]['posts']++;
                $cache=serialize($cache);
                mysql_query("UPDATE ".$tableprefix."cache_store SET cs_value='".$cache."' WHERE cs_key='forum_cache'");
             }
             elseif($cache['cs_key']=='stats')
             {
                     $cache=unserialize($cache['cs_value']);
                     $cache['total_topics']++;
                     $cache['total_replies']++;
                     $cache=serialize($cache);
                     mysql_query("UPDATE ".$tableprefix."cache_store SET cs_value='".$cache."' WHERE cs_key='stats'");
             }
        }
        /***************** /Обновление кеша форума ****************************/

        mysql_query("UPDATE " . $tableprefix . "members SET posts=posts+1 WHERE id='$memid'");
        }
}

// Post Reply
function reply($post) {
        global $REMOTE_ADDR;
        global $username;
        global $memid;
        global $tid;
        global $fid;
        global $tableprefix;
        global $post_sig;
        global $phone;
        If (function_exists('lngPost')) {
                $post = lngPost($post);
        }
        If (post_time()) {
        $time = time();
        $post = $post . str_replace("[phone]", $phone, $post_sig);

        mysql_query("INSERT INTO " . $tableprefix . "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 " . $tableprefix . "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 " . $tableprefix . "topics SET last_poster_id='$memid', ".
                "last_poster_name='$username', ".
                "last_post='$time', ".
                "posts=posts+1 ".
                "WHERE tid='$tid'");

        /****************** Обновление кеша форума ****************************/
        $result=mysql_query("SELECT cs_key, cs_value "
                            ."FROM ".$tableprefix."cache_store "
                            ."WHERE cs_key='forum_cache' OR cs_key='stats'");
        while($cache=mysql_fetch_array($result))
        {
             if($cache['cs_key']=='forum_cache')
             {
                $cache=unserialize($cache['cs_value']);
                $cache[$fid]['last_post']=$time;
                $cache[$fid]['last_poster_name']=$username;
                $cache[$fid]['last_poster_id']=$memid;
                $cache[$fid]['posts']++;
                $cache=serialize($cache);
                mysql_query("UPDATE ".$tableprefix."cache_store SET cs_value='".$cache."' WHERE cs_key='forum_cache'");
             }
             elseif($cache['cs_key']=='stats')
             {
                     $cache=unserialize($cache['cs_value']);
                     $cache['total_replies']++;
                     $cache=serialize($cache);
                     mysql_query("UPDATE ".$tableprefix."cache_store SET cs_value='".$cache."' WHERE cs_key='stats'");
            }
        }
        /***************** /Обновление кеша форума ****************************/

        mysql_query("UPDATE " . $tableprefix . "members SET posts=posts+1 WHERE id='$memid'");
        }
}

function parse_emoticons($code) {
        global $furl;
        global $emoticon_dir;
        global $post_emoticons;
        global $tableprefix;
        global $phone;
        If ($post_emoticons==1) {
                $emoticons = mysql_query("SELECT * FROM " . $tableprefix . "emoticons");
                while ($emoticon = mysql_fetch_array($emoticons)) {
                        $code = str_replace($emoticon['typed'], "<!--emo&" . $emoticon['typed'] . "--><img src=\'http://" . $furl . $emoticon_dir . $emoticon['image'] . "\' border=\'0\' style=\'vertical-align:middle\' alt=\'" . $emoticon['image'] . "\'/><!--endemo-->", $code);
                }
        }

        return $code;
}

function post_time() {
        global $post_limit;
        global $username;
        global $tableprefix;
        $last_post = mysql_fetch_array(mysql_query("SELECT `post_date` FROM `" . $tableprefix . "posts` WHERE author_name='$username' ORDER BY `post_date` DESC LIMIT 1"));
        $last_post = $last_post['post_date'];
        If ((time() - $last_post) < $post_limit) {
                return false;
        } else {
                return true;
        }
}

// 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"));


$sesid = substr("wap" . $REMOTE_ADDR . $phone, 0, 32);
If (mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id='{$sesid}'")) > 0) {
        mysql_query("UPDATE " . $tableprefix . $sessionstable . " SET browser='{$HTTP_USER_AGENT}', id='{$sesid}', $ip_address_column='{$REMOTE_ADDR}', running_time='" . time() . "' WHERE id='{$sesid}' LIMIT 1");
} else {
        mysql_query("INSERT INTO " . $tableprefix . $sessionstable . " SET browser='{$HTTP_USER_AGENT}', login_type=0, id='{$sesid}', $ip_address_column='{$REMOTE_ADDR}', running_time='" . time() . "'");
}
$login_out = "";
If ($allowlogin==1) {

        $sesinfo = mysql_fetch_array(mysql_query("SELECT m.restrict_post, m.view_img, "
                                                 ."s.id, s.member_name, s.member_id, s.ip_address, s.browser, s.running_time, "
                                                 ."s.login_type, s.member_group "
                                                 ."FROM ".$tableprefix.$sessionstable." s INNER JOIN ".$tableprefix.$memberstable." m "
                                                 ."ON s.member_id=m.id "
                                                 ."WHERE s.id='{$sesid}' "
                                                 ."AND s.".$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){
                $login_out = "<a href=\"$PHP_SELF?action=login#view\">{$strLogin}</a>";
                $loginstr = "{$strWelcome}<br/><b>$username</b> (" .$login_out . ")<br/><br/>";
        } else {
                $login_out = "<a href=\"$PHP_SELF?action=logout#view\">{$strLogout}</a>";
                $loginstr = "{$strWelcome}<br/><b>$username</b> (" .$login_out . ")<br/><br/>";
        }
        $login_out = "<br/>" . $login_out;
} else {
        $loginstr = "";
}

If ($in_forum==1) {
        If (!$fid==null) {
                mysql_query("UPDATE " . $tableprefix . $sessionstable . " SET in_forum=$fid, location='SF,,' WHERE id='{$sesid}' LIMIT 1");
        } else {
                If ($tid==null) {
                        mysql_query("UPDATE " . $tableprefix . $sessionstable . " SET in_forum=0, location='idx,,' WHERE id='{$sesid}' LIMIT 1");
                }
        }
}
If ($in_topic==1){
        If (!$tid==null) {
                mysql_query("UPDATE " . $tableprefix . $sessionstable . " SET in_topic=$tid, location='ST,,' WHERE id='{$sesid}' LIMIT 1");
        } else {
                mysql_query("UPDATE " . $tableprefix . $sessionstable . " SET in_topic=0 WHERE id='{$sesid}' LIMIT 1");
        }
}
}

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

If ($navmode == 1) {
$mainnavstr = <<<EOF
{$strViewForums}
<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>{$strLast5}</option>
<option><onevent type="onpick"><go href="$PHP_SELF#view" method="post"><postfield name="action" value="categories"/></go></onevent>{$strCategories}</option>
<option><onevent type="onpick"><go href="$PHP_SELF#view" method="post"><postfield name="action" value="forums"/></go></onevent>{$strForums}</option>
</select><br/><br/>
EOF;
} else {
$mainnavstr = <<<EOF
{$strViewForums}<br/>
<a href="$PHP_SELF?action=last5#view">{$strLast5}</a><br/>
<a href="$PHP_SELF?action=categories#view">{$strCategories}</a><br/>
<a href="$PHP_SELF?action=forums#view">{$strForums}</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">{$strEnglish}</a>, <a href="$PHP_SELF?lng=fr">{$strFrench}</a>, <a href="$PHP_SELF?lng=de">{$strGerman}</a>, <a href="$PHP_SELF?lng=es">{$strSpanish}</a>, <a href="$PHP_SELF?lng=it">{$strItalian}</a>, <a href="$PHP_SELF?lng=pt">{$strPortugese}</a><br/>
EOF;
} else {
$translate_menu = "";
}

$disstr = <<<EOF
<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1_1.dtd">

<wml>
<card id="index" title="{$boardtitle}">
<p align="center"><b>{$boardname}</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 id NOT LIKE 'wap%' 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 id NOT LIKE 'wap%' AND $running_time_column >" . (time() - (60 * $sesmin)) . ""));
                $wap = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id LIKE 'wap%' AND $running_time_column >" . (time() - (60 * $sesmin)) . ""));
                $wapmembers = mysql_num_rows(mysql_query("SELECT * FROM " . $tableprefix . $sessionstable . " WHERE id LIKE 'wap%' AND $member_id_column > 0 AND $running_time_column > " . (time() - (60 * $sesmin)) . ""));
                $wapguests = $wap - $wapmembers;
$disstr1 = <<<EOF
<b>$users</b> {$strVisitorsOnline}<br/>
$members {$strMembers}, $guests {$strGuests}, $wap {$strWAP} ($wapmembers, $wapguests)
<br/>
$translate_menu
EOF;
                } else {
                        $disstr1 = "";
        }

$disstr2 = <<<EOF
<br/><small>
Coding by<br/>Sentertainment.net<br/>
Debugged by<br/>
Internet-Technologies.Ru
</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>{$strForums}</b><br/><br/>";
                If ($forumviewnavmode == 1) {
                        $display_output = $display_output . "<select name=\"id\" value=\"0\">";
                }
                $result = mysql_query("SELECT `$name_column`, `id`, status FROM `" . $tableprefix . $categoriestable . "` WHERE `parent_id`=-1 ORDER BY `$position_column`");
                while ($row = mysql_fetch_array($result)) {

                        If ($row['status']==1 || $cat_vis==0 || (!$row['status']==0 && $cat_vis==1)) {

                                If ($forumviewnavmode == 0) {

                                        If (getperm($row['id'], "show")) {
                                            $display_output = $display_output . "<br/><b>" . $row[$name_column] . "</b><br/>";
                                        }

                                }

                                $result2 = mysql_query("SELECT `$name_column`, `id`, `topics`, `posts` FROM `" . $tableprefix . $forumstable . "` WHERE `parent_id`=" . $row['id'] . " ORDER BY `position`");
                                while ($row2 = mysql_fetch_array($result2))
                                {
                                        If (getperm($row2['id'], "show")) {
                                                If ($forumviewnavmode == 0)
                                                {
                                                        $display_output = $display_output . "<a href=\"{$PHP_SELF}?fid=" . $row2['id'] . "#viewforum\">" . wmlspecialchars(html_entity_decode2($row2[$name_column])).' ['.$row2['topics'].'|'. ($row2['posts']-$row2['topics']).']'."</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])).' ['.$row2['topics'].'|'. ($row2['posts']-$row2['topics']).']'."</option>";
                                                }

                                                $result3 = mysql_query("SELECT `$name_column`, `id`, `topics`, `posts` FROM `" . $tableprefix . $forumstable . "` WHERE `parent_id`=" . $row2['id'] . " ORDER BY `position`");
                                                while ($row3 = mysql_fetch_array($result3))
                                                {
                                                        If ($forumviewnavmode == 0)
                                                        {
                                                             $display_output = $display_output . "<a href=\"{$PHP_SELF}?fid=" . $row3['id'] . "#viewforum\"> - " . wmlspecialchars(html_entity_decode2($row3[$name_column])).' ['.$row3['topics'].'|'. ($row3['posts']-$row3['topics']).']'."</a><br/>";
                                                        }
                                                        else $display_output = $display_output . "<option><onevent type=\"onpick\"><go href=\"{$PHP_SELF}#viewforum\" method=\"post\"><postfield name=\"fid\" value=\"" . $row3['id'] . "\"/></go></onevent> -" . wmlspecialchars(html_entity_decode2($row3[$name_column])).' ['.$row3['topics'].'|'. ($row3['posts']-$row3['topics']).']'."</option>";
                                                }
                                        }
                                }
                        }
                }
                If ($forumviewnavmode == 1) {
                        $display_output = $display_output . "</select>";
                }
                $display_output = $display_output . "<br/><a href=\"{$PHP_SELF}\">{$strHome}</a><br/><br/>
                                                    <a href=\"$PHP_SELF?action=last5#view\">{$strLast5}</a></p>";
                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>{$strCardCreated1}<br/>" . substr(($t2 - $t1), 0, 8) . "{$strCardCreated2}</p>";
                }
        }


        If ($action=="last5") {
                $t1 = microtime();
                $display_output = $display_output . "<p align=\"center\"><b>{$strLast5}</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)) {

                        $query="SELECT * "
                               ."FROM ".$tableprefix.$poststable." "
                               ."WHERE $topic_id_column=".$row[$tid_column]. " "
                               ."ORDER BY $post_date_column DESC "
                               ."LIMIT 0,1";
                        $result2 = mysql_query($query);

                        $row2 = mysql_fetch_array($result2);
                        $topic = wmlspecialchars(html_entity_decode2($row[$title_column]));

                        If (getperm($row['forum_id'], "read")) {
                                $boardcode = docharlimit(html2wml($row2[$post_column]));
                        } else {
                                $boardcode = $strNoPermTopic;
                        }

                        if ($viewdetails == 1) {
                                $display_output = $display_output . "<p><b>{$strTopic} </b><a href=\"{$PHP_SELF}?tid_page=" . $row2[$topic_id_column] . "_0#viewtopic\">" . $topic . "</a> (" . $row[$posts_column] . ", " . $row[$views_column] . ")<br/><b>{$strLastPost}</b><br/>{$strUser} " . $row2[$author_name_column] . "<br/>{$strPost} " . $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\">{$strPrev}</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\">{$strNext}</a>";
                }
                $display_output = $display_output . "<br/><a href=\"{$PHP_SELF}\">{$strHome}</a><br/><br/>
                                                    <a href=\"$PHP_SELF?action=forums#view\">{$strForums}</a><br/>
                                                    <a href=\"$PHP_SELF?action=categories#view\">{$strCategories}</a></p>";

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


        If ($action=="categories") {
                $t1 = microtime();
                $display_output = $display_output . "<p align=\"center\"><b>{$strCategories}</b><br/><br/>";
                If ($navmode == 1) {
                        $display_output = $display_output . "<select name=\"id\" value=\"0\">";
                }

                $result = mysql_query("SELECT `$name_column`, `id`, `status` FROM `" . $tableprefix . $categoriestable . "` WHERE `parent_id`='-1' ORDER BY `$position_column`");

                while ($row = mysql_fetch_array($result)) {
                        If ($row['status']!==1 || $cat_vis==0 || (!$row['status']==0 && $cat_vis==1)) {
                                If ($navmode == 1) {

                                   // Если разрешено просматривать
                                   If (getperm($row['id'], "show"))
                                   {
                                      $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 {

                                        // Если разрешено просматривать
                                        If (getperm($row['id'], "show"))
                                        {
                                            $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}\">{$strHome}</a><br/><br/>
                                                    <a href=\"$PHP_SELF?action=last5#view\">{$strLast5}</a><br/>
                                                    <a href=\"$PHP_SELF?action=forums#view\">{$strForums}</a></p>";
                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>{$strCardCreated1}<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>
                {$strUsername}<br/>
                <input type="text" name="LoginUsername"/><br/><br/>
                {$strPassword}<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>{$strLogin}</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\">{$strBack}</a>";
              }
              If ($row = mysql_fetch_array($result)) {

                  /***************** Проверка пароля для IBF 2.х **************/
                  $member_id = $row['id'];
                  $result = mysql_query("SELECT * FROM " . $tableprefix . "members_converge where converge_id = '" . $member_id . "'");
                  $pass = mysql_fetch_array($result);
                  $md5_once_password = md5($LoginPassword);

                  function generate_compiled_passhash($salt, $md5_once_password)
                  {
                   return md5( md5( $salt ) . $md5_once_password );
                  }

                  $final_pass = generate_compiled_passhash( $pass['converge_pass_salt'], $md5_once_password );
                  /***************** /Проверка пароля для IBF 2.х **************/

                  If ($pass['converge_pass_hash'] == $final_pass)
                  {
                       mysql_query("REPLACE INTO " . $tableprefix . $sessionstable . " SET id='wap" . $REMOTE_ADDR  . $phone . "', $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 = -1");
                       $display_output = $display_output . "{$strLoginSuccessful}<br/><br/>{$strLoggedInAs} $LoginUsername,<br/>Current IP: " . $REMOTE_ADDR . "<br/>{$strTimeOut}<br/><br/><a href=\"" . $PHP_SELF . "\">{$strHome}</a>";
                  } else
                  {
                        $display_output = $display_output . "{$strBadLogin}<br/><br/>".$pr['converge_pass_hash'].'|'.$final_pass."<br/><a href=\"$PHP_SELF?action=login#view\">{$strBack}</a>";
                  }
              } else {
                      $display_output = $display_output . "{$strBadLogin}<br/><br/><a href=\"$PHP_SELF?action=login#view\">{$strBack}</a>";
              }
              $display_output = $display_output . "</p>";
      }


        If ($action=="logout") {
                $display_output = $display_output . "<p align=\"center\"><b>{$strLogout}</b><br/><br/>";
                mysql_query("REPLACE INTO " . $tableprefix . $sessionstable . " SET id='wap" . $REMOTE_ADDR . $phone . "', $ip_address_column='" . $REMOTE_ADDR . "', $running_time_column='" . time() . "'");
                $display_output = $display_output . "{$strLogoutComplete}<br/><br/><a href=\"{$PHP_SELF}\">{$strHome}</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) {
        $id=intval($id);

        $t1_1 = microtime();
        $result = mysql_query("SELECT `$name_column`, `status` FROM `" . $tableprefix . $categoriestable . "` WHERE `id`=" . $id . " AND `parent_id`='-1'");
        $row = mysql_fetch_array($result);
        If ((!$row['status']==0 && $cat_vis==1) || $cat_vis==0) {
                $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`, `topics`, `posts` FROM `" . $tableprefix . $forumstable . "` WHERE `parent_id`=" . $id . " ORDER BY `$position_column`");
                while ($row = mysql_fetch_array($result))
                {
                        If (getperm($row['id'], "show")) {
                                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])).' ['.$row['topics'].'|'.($row['posts']-$row['topics']).']'."</option>";
                                } else {
                                        $display_output = $display_output . "<a href=\"{$PHP_SELF}?fid=" . $row['id'] . "#viewforum\">" . wmlspecialchars(html_entity_decode2($row[$name_column])).' ['.$row['topics'].'|'.($row['posts']-$row['topics']).']'. "</a><br/>";
                                }

                                $result2 = mysql_query("SELECT `$name_column`, `id`, `topics`, `posts` FROM `" . $tableprefix . $forumstable . "` WHERE `parent_id`=" . $row['id'] . " ORDER BY `position`");
                                while ($row2 = mysql_fetch_array($result2))
                                {
                                        If ($forumviewnavmode == 0)
                                        {
                                             $display_output = $display_output . "<a href=\"{$PHP_SELF}?fid=" . $row2['id'] . "#viewforum\"> - " . wmlspecialchars(html_entity_decode2($row2[$name_column])).' ['.$row2['topics'].'|'.($row2['posts']-$row2['topics']).']'."</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])).'['.$row2['topics'].'|'.($row2['posts']-$row2['topics']).']'."</option>";
                                }
                        }
                }
                If ($forumviewnavmode == 1) {
                        $display_output = $display_output . "</select>";
                }
                $display_output = $display_output . "<br/><a href=\"{$PHP_SELF}\">{$strHome}</a><br/><br/>
                                                    <a href=\"$PHP_SELF?action=last5#view\">{$strLast5}</a><br/>
                                                    <a href=\"$PHP_SELF?action=forums#view\">{$strForums}</a><br/>
                                                    <a href=\"$PHP_SELF?action=categories#view\">{$strCategories}</a>";
                $t2_1 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>{$strCardCreated1}<br/>" . substr(($t2_1 - $t1_1), 0, 8) . " Sec.";
                }
        } else {
                $display_output = $display_output . "<p>{$strNoPermCategory}" . $login_out . "<br/><a href=\"{$PHP_SELF}\">{$strHome}</a></p>";
        }
}

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

if (!$fid==Null) {
        $fid=intval($fid);

        $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/>";

        $fid=intval($fid);

        If (getperm($fid, "read")) {
                If ($page==0) {
                        $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 . "{$strPinned} <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>{$strTopic} </b><a href=\"{$PHP_SELF}?tid_page=" . $row2[$topic_id_column] . "_0#viewtopic\">" . $topic . "</a> (" . $row[$posts_column] . ", " . $row[$views_column] . ")<br/><b>{$strLastPost}</b><br/>{$strUser} " . $row2[$author_name_column] . "<br/>{$strPost} " . $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 ($allownewtopics==1 && $allowpost==1 && getperm($fid, "start")) {
                        If (post_time()) {
                                $display_output = $display_output . "<a href=\"$PHP_SELF?fid={$fid}#newtopic\">{$strNewThread}</a><br/>";
                        } else {
                                $display_output = $display_output . "{$strFloodControl}<br/>";
                        }
                } else {
                        $display_output = $display_output . "{$strNewThread}<br/>";
                }
                if (!$page==0) {
                        $display_output = $display_output . "<a href=\"{$PHP_SELF}?fid_page={$fid}_" . $p3 . "#viewforum\">{$strPrev}</a> ";
                }
                $result = mysql_query("SELECT tid FROM `" . $tableprefix . $topicstable . "` WHERE forum_id='$fid' 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\">{$strNext}</a>";
                }
                $display_output = $display_output . "<br/><a href=\"{$PHP_SELF}\">{$strHome}</a><br/><br/>
                                                    <a href=\"$PHP_SELF?action=last5#view\">{$strLast5}</a><br/>
                                                    <a href=\"$PHP_SELF?action=forums#view\">{$strForums}</a><br/>
                                                    <a href=\"$PHP_SELF?action=categories#view\">{$strCategories}</a></p>";
                $t2 = microtime();
                if ($pagecreation==1) {
                        $display_output = $display_output . "<p align=\"center\"><br/>{$strCardCreated1}<br/>" . substr(($t2 - $t1), 0, 8) . "{$strCardCreated2}</p>";
                }
        } else {
                $display_output = $display_output . "<p>{$strNoPermForum}" . $login_out . "<br/><a href=\"{$PHP_SELF}\">{$strHome}</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) {
        $tid=intval($tid);

        $t1_3 = microtime();
        $result = mysql_query("SELECT `$title_column`, `forum_id` FROM `" . $tableprefix . $topicstable . "` WHERE `tid`=" . $tid);
        if (!$result) {
                exit();
        }
        If ($add_views==1 && $page==0) {
                mysql_query("UPDATE " . $tableprefix . "topics SET views=views+1 WHERE tid=" . $tid);
        }
        $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>{$strAttached}</b> <a href=\"{$PHP_SELF}?pid=f" . $row['pid'] . "\">" . $row['attach_file'] . "</a><br/>";
                        } else {
                                $postfile = "";
                        }
                        $display_output = $display_output . "<p><b>{$strUser}</b> " . $row[$author_name_column] . "<br/><b>{$strPost}</b> " . $boardcode . "<br/>" . $postfile . "<br/></p>";
                }
        } else {
                $display_output = $display_output . "<p align=\"center\">{$strNoPermTopic}" . $login_out . "<br/></p>";
        }
        $display_output = $display_output . "<p align=\"center\">";
        If ($allowreply==1 && $allowpost==1 && getperm($topic_fid, "reply")) {
                If (post_time()) {
                        $display_output = $display_output . "<a href=\"$PHP_SELF?tid_fid={$tid}_" . $topic_fid . "#reply\">{$strReply}</a><br/>";
                } else {
                        $display_output = $display_output . "{$strFloodControl}<br/>";
                }
        } else {
                $display_output = $display_output . "{$strReply}<br/>";
        }
        $p2 = $page + 1;
        $p3 = $page - 1;
        if (!$page==0) {
                $display_output = $display_output . "<a href=\"{$PHP_SELF}?tid_page={$tid}_" . $p3 . "#viewtopic\">{$strPrev}</a> ";
        }
        $result = mysql_query("SELECT pid 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\">{$strNext}</a>";
        }
        $display_output = $display_output . "<br/>" . topicpagenav($result2, $page, $tid);
        $display_output = $display_output . "<br/><a href=\"{$PHP_SELF}?fid={$topic_fid}#viewforum\">{$strBack}</a><br/><br/>
                                            <a href=\"{$PHP_SELF}\">{$strHome}</a><br/>
                                            <a href=\"$PHP_SELF?action=last5#view\">{$strLast5}</a><br/>
                                            <a href=\"$PHP_SELF?action=forums#view\">{$strForums}</a><br/>
                                            <a href=\"$PHP_SELF?action=categories#view\">{$strCategories}</a>";
        $display_output = $display_output . "</p>";
        $t2_3 = microtime();
        if ($pagecreation==1) {
                $display_output = $display_output . "<p align=\"center\"><br/>{$strCardCreated1}<br/>" . substr(($t2_3 - $t1_3), 0, 8) . "{$strCardCreated2}</p>";
        }
} elseif (!$ptid==null) {
        $tid=intval($ptid);

        $t1_4 = microtime();
        $result = mysql_query("SELECT * FROM `" . $tableprefix . $poststable . "` WHERE `pid`=" . $ppid);
        $display_output = $display_output . "<p align=\"center\"><b>{$strFullPostView}</b><br/></p>";
        $row = mysql_fetch_array($result);
                $boardcode = html2wml($row[$post_column]);
                if (!$row['attach_file']==null && $enattach == 1) {
                        $postfile = "<b>{$strAttached}</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\">{$strBack}</a><br/><br/>";
        $display_output = $display_output . "<a href=\"{$PHP_SELF}\">{$strHome}</a><br/>
                                            <a href=\"$PHP_SELF?action=last5#view\">{$strLast5}</a><br/>
                                            <a href=\"$PHP_SELF?action=forums#view\">{$strForums}</a><br/>
                                            <a href=\"$PHP_SELF?action=categories#view\">{$strCategories}</a>";
        $display_output = $display_output . "</p>";
        $t2_4 = microtime();
        if ($pagecreation==1) {
                $display_output = $display_output . "<p align=\"center\"><br/>{$strCardCreated1}<br/>" . substr(($t2_4 - $t1_4), 0, 8) . "{$strCardCreated2}</p>";
        }
}

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


If (!$fid==null && !$tid==null && $allowreply==1 && post_time()) {
        $disstr = "<p><do type=\"accept\" label=\"{$strReply}\"><go href=\"$PHP_SELF?tid_fid_newreply={$tid}_{$fid}_1#reply\" method=\"post\"><postfield name=\"reply\" value=\"$(reply)\"/></go></do>{$strReply2}<br/><input title=\"{$strReply}\" name=\"reply\"/><br/><a href=\"{$PHP_SELF}?tid_fid_newreply_reply={$tid}_{$fid}_1_\$(reply)#reply\">{$strPostReply}</a><br/><br/><a href=\"{$PHP_SELF}?tid={$tid}#viewtopic\">{$strBack}</a><br/><a href=\"$PHP_SELF\">{$strHome}</a></p>";
        If (!$reply==null) {

                $fid=intval($fid);

                if ($allowpost==1 && getperm($fid, "reply")) {
                        reply(parse_emoticons(htmlentities($reply)));
                        $disstr = "<p align=\"center\"><br/>{$strReplySuccessful}<br/><br/><a href=\"{$PHP_SELF}?tid={$tid}#viewtopic\">{$strBack}</a><br/><a href=\"{$PHP_SELF}\">{$strHome}</a></p>";
                } else {
                        $disstr = "<p><do type=\"accept\" label=\"{$strReply}\"><go href=\"{$PHP_SELF}?tid_fid_newreply={$tid}_{$fid}_1#reply\" method=\"post\"><postfield name=\"reply\" value=\"$(reply)\"/></go></do>{$strReplyError}<br/><br/>{$strReply2}<br/><input title=\"{$strReply}\" name=\"reply\"/><br/><a href=\"{$PHP_SELF}?tid_fid_newreply_reply={$tid}_{$fid}_1_\$(reply)#reply\">{$strPostReply}</a><br/><br/><a href=\"{$PHP_SELF}?tid={$tid}#viewtopic\">{$strBack}</a><br/><a href=\"{$PHP_SELF}\">{$strHome}</a></p>";
                }
        }
        $display_output = $display_output . $disstr;
}
$disstr = <<<EOF
</card>
EOF;
$display_output = $display_output . $disstr;
}

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


If (!$fid==null && $allownewtopics==1 && post_time()) {
        $disstr = "<p><do type=\"accept\" label=\"{$strPost2}\"><go href=\"$PHP_SELF?fid={$fid}#newtopic\" method=\"post\"><postfield name=\"title\" value=\"$(title)\"/><postfield name=\"desc\" value=\"$(desc)\"/><postfield name=\"topicpost\" value=\"$(topicpost)\"/></go></do>{$strNewTopic2}<br/><br/>{$strTitle2}<br/><input title=\"{$strTitle}\" name=\"title\"/><br/>{$strDesc2}<br/><input title=\"{$strDesc}\" name=\"desc\"/><br/>{$strPost}<br/><input title=\"{$strPost2}\" name=\"topicpost\"/><br/><a href=\"{$PHP_SELF}?fid_title_desc_topicpost={$fid}_\$(title)_\$(desc)_\$(topicpost)#newtopic\">{$strPost2}</a><br/><br/><a href=\"{$PHP_SELF}?fid={$fid}#viewforum\">{$strBack}</a><br/><a href=\"$PHP_SELF\">{$strHome}</a></p>";
        If (!$topicpost==null) {
                if ($allowpost==1 && getperm($fid, "start")) {
                        new_topic($fid, htmlentities($title), htmlentities($desc), parse_emoticons(htmlentities($topicpost)));
                        $disstr = "<p align=\"center\"><br/>{$strPostSuccessful}<br/><br/><a href=\"{$PHP_SELF}?fid={$fid}#viewforum\">{$strBack}</a><br/><a href=\"{$PHP_SELF}\">{$strHome}</a></p>";
                } else {
                        $disstr = "<p><do type=\"accept\" label=\"{$strPost2}\"><go href=\"$PHP_SELF?fid={$fid}#newtopic\" method=\"post\"><postfield name=\"title\" value=\"$(title)\"/><postfield name=\"desc\" value=\"$(desc)\"/><postfield name=\"topicpost\" value=\"$(topicpost)\"/></go></do>{$strReplyError}<br/><br/>{$strNewTopic2}<br/><br/>{$strTitle2}<br/><input title=\"{$strTitle}\" name=\"title\"/><br/>{$strDesc2}<br/><input title=\"{$strDesc}\" name=\"desc\"/><br/>{$strPost}<br/><input title=\"{$strPost2}\" name=\"topicpost\"/><br/><a href=\"{$PHP_SELF}?fid_title_desc_topicpost={$fid}_\$(title)_\$(desc)_\$(topicpost)#newtopic\">{$strPost2}</a><br/><br/><a href=\"{$PHP_SELF}?fid={$fid}#viewforum\">{$strBack}</a><br/><a href=\"$PHP_SELF\">{$strHome}</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 {
        If (function_exists('lngConvertOutput')) {
                $display_output = lngConvertOutput($display_output);
        }
        echo($display_output);
}
?>