<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003-2004 myPHPNuke Development Team                   |
// | Copyright (c) 2003-2004 Kiril Threndor                               |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: Kiril Threndor <mpnx@dev.illearth.net>                       |
// +----------------------------------------------------------------------+
// $Id: theme_functions.php,v 1.6.2.4 2004/07/07 17:49:42 kirilt Exp $


/**
 * Topic Navigation
 *
 * This function provide a basic topic navigation dropdown
 */

function topicNav() // Generates Topic Nav. Dropdown
{
    global $mpnTables, $topic;

    echo "<form action='search.php' method='get'>\n";

        echo "<p class='forms'>\n\n";

            echo "<label>" . translate( 'Topics' ) . ":&nbsp;</label>\n";

            $sql = "SELECT topicid, topictext FROM " . $mpnTables['topics'] . " ORDER BY topictext";
            $result = mysql_query( $sql );

            echo "<select name='topic' onchange='submit()'>";

            echo "<option value=''>" . translate( 'All Topics' ) . "</option>\n";

            while ( list ( $topicid, $topics ) = mysql_fetch_row( $result ) )
            {
                $sel = ( $topicid == $topic ) ? ( 'selected' ) : ( '' );

                echo "<option $sel value='$topicid'>$topics</option>\n";
            }

            echo "</select>\n";

        echo "</p>\n\n";

    echo "</form>\n";

    mysql_free_result( $result );

} // End Function topicNav()

/**
 * Search News
 *
 * Generates a search form for news articles
 */

function searchNews()
{
    echo "<form action='search.php' method='post'>\n";

        echo "<p class='forms'>\n\n";

            echo "<label>" . translate( 'Search' ) . ":&nbsp;</label>\n";
            echo "<input type='text' name='query' size='14' />\n";
            echo "<input class='button' value='" . translate( 'Go' ) . "' type='submit' />\n";

        echo "</p>\n\n";

    echo "</form>\n";

} // End Function searchNews()

/**
 * Current Date And Time
 *
 * Generates a locale specific time and date stamp
 */

function getDateTime() // Display Current Date
{
    echo strftime( translate( 'forumdatestring3' ), _MPN_TIMESTAMP );

}  // End Function

/**
 * Current Date
 *
 * Generates a locale specific date stamp
 */

function getCurrDate() // Display Current Date
{
    echo strftime( translate( 'datestring4' ), _MPN_TIMESTAMP );

} // End Function

/**
 * Load The Site Logo
 */

function getLogo()
{
    global $sitename;

    $link_logo = _T_THEME_URI . 'images/' . _T_THEME_LOGO;

    echo "<a href='" . _MPN_ROOT_URI . "'><img class='logo' src='$link_logo' alt='" . translate( 'Welcome To' ) . "&nbsp;$sitename' /></a>\n";

} // End Function

/**
 * Welcome Users And Provide PM Notification For Registered Users
 */

function welcomeUser()
{
    global $mpnTables, $phpEx;

    if ( ! empty( $_COOKIE['user'] ) )
    {
        $tmp = cookiedecode( $_COOKIE['user'] );

        // Query DB

        $sql = "SELECT msg_id FROM " . $mpnTables['priv_msgs'] . " WHERE to_userid = '$tmp[0]' && read_msg = '0'";
        $result = mysql_query( $sql );
        $new_messages = mysql_num_rows( $result );

        mysql_free_result( $result );

        // Print Welcome

        echo "" . translate( 'Welcome' ) . "&nbsp;<a href='./user.$phpEx' title='" . translate( 'Go To Your Account Settings' ) . "'>$tmp[1]</a>";

        if ( $new_messages > 0 )
        {
            echo "&nbsp;<a href='./viewpmsg.$phpEx'><img src='./images/forum/icons/inbox.gif' alt='" . translate( 'You Have' ) . " $new_messages " . translate( 'New Messages' ) . "' /></a>\n";
        }
    }
    else
    {
        echo "<a href='./user.$phpEx'>" . translate( 'Create An Account' ) . "</a>\n";
    }

} // End Function

/**
 * Custom Block Array
 *
 * Generates Theme Requested Block Array From DB
 */

function customBlockArray()
{
    global $mpnTables;

    $out = '';

    if ( _T_BLOCK_FORMAT == 4 ) // Show Only Custom, Include A File, Login, Theme Options Blocks
    {
        $cond = "visible = '1' && ( special = '0' || special = '8' || special > '22' )";
    }
    else
    {
        $cond = "visible = '1'";
    }

    $sql = array
           (
                1 => "SELECT title, side FROM " . $mpnTables['blocks'] . " WHERE $cond",
                2 => "SELECT title, admin FROM " . $mpnTables['blocks'] . " WHERE $cond",
                3 => "SELECT title, category FROM " . $mpnTables['blocks'] . " WHERE $cond",
                4 => "SELECT title, admin FROM " . $mpnTables['blocks'] . " WHERE $cond"
           );

    $result = mysql_query( $sql[_T_BLOCK_FORMAT] );

    while ( $row = mysql_fetch_row( $result ) )
    {
        $out .= join( ':' , $row ) . "||";
    }

    mysql_free_result( $result );

    return $out;

} // End Function

/**
 * Format The Side Blocks
*
 * Determines which CSS class should be applied to the blocks
 */

function formatSideBlocks( $title ) // Assign CSS Classes To The Blocks
{
    $blockArray_in = explode( '||' , _T_BLOCK_ARRAY );

    switch ( _T_BLOCK_FORMAT )
    {
        // Format Blocks By Side (Left & Right)

        case 1:

            if ( $title == translate( 'Related Links' ) )
            {
                return ( 'leftside' );
            }

            foreach ( $blockArray_in AS $v )
            {
                if ( $v == "$title:0" )
                {
                    return ( 'rightside' );
                }
            }

            return ( 'leftside' );

        break;

        // Format Blocks By Type, Show All Custom Blocks And Login Block

        case 2:

            if ( $title == translate( 'Related Links' ) )
            {
                return ( 'typeAll' );
            }

            foreach ( $blockArray_in AS $v )
            {
                if ( $v == "$title:0" ) { return ( 'typeAll'   ); }

                if ( $v == "$title:1" ) { return ( 'typeUser'  ); }

                if ( $v == "$title:2" ) { return ( 'typeAdmin' ); }
            }

            return ( 'typeAll' );

        break;

        // Format Blocks By Category

        case 3:

            if ( $title == translate( 'Related Links' ) )
            {
                return ( 'catRight' );
            }

            foreach ( $blockArray_in AS $v )
            {
                if ( $v == "$title:0" ) { return ( 'catNone'  ); }

                if ( $v == "$title:1" ) { return ( 'catMain'  ); }

                if ( $v == "$title:2" ) { return ( 'catAdmin' ); }

                if ( $v == "$title:3" ) { return ( 'catLeft'  ); }

                if ( $v == "$title:4" ) { return ( 'catRight' ); }

                if ( $v == "$title:5" ) { return ( 'catUser'  ); }
            }

            return ( 'catNone' );

        break;

        // Format Blocks By Type, Show All Custom Blocks And Login Block

        case 4:

            if ( $title == translate( 'Related Links' ) )
            {
                return ( 'typeAll' );
            }

            foreach ( $blockArray_in AS $v )
            {
                if ( $v == "$title:0" ) { return ( 'typeAll' ); }

                if ( $v == "$title:1" ) { return ( 'typeUser' ); }

                if ( $v == "$title:2" ) { return ( 'typeAdmin' ); }
            }

            return ( 'invisi' ); // Hide The Block

        break;
    }

    return $blockcell;

}   // End Function formatSideBlocks()

/**
 * Format The Center Blocks
 *
 * Determines which CSS class should be applied to the blocks
 */

function formatCentBlocks() // Assign CSS Classes To The Blocks
{
    switch ( _T_BLOCK_FORMAT )
    {
        // Format Blocks By Side (Left & Right)

        case 1:

            $cbclasses = array( 'cbForum1', 'cbRnews1', 'cbRtop1', 'cbMm1' );

            return $cbclasses;

        break;

        // Format Blocks By Type, Show All Custom Blocks And Login Block

        case 2:

            $cbclasses = array( 'cbForum2', 'cbRnews2', 'cbRtop2', 'cbMm2' );

            return $cbclasses;

        break;

        // Format Blocks By Category

        case 3:

            $cbclasses = array( 'cbForum3', 'cbRnews3', 'cbRtop3', 'cbMm3' );

            return $cbclasses;

        break;

        // Format Blocks By Type, Show All Custom Blocks And Login Block

        case 4:

            $cbclasses = array( 'cbForum4', 'cbRnews4', 'cbRtop4', 'cbMm4' );

            return $cbclasses;

        break;
    }

} // End Function formatCenterBlocks()


function getThemeOptions( $inline = FALSE, $block = TRUE )
{
    global $Default_Theme;

    $style = ( $inline == (bool)TRUE ) ? ( 'makeinline' ) : ( 'empty' );
    $title_tag = ( $block == (bool)FALSE ) ? ( 'h3' ) : ( 'label' );
    $spacer = ( $inline == (bool)FALSE ) ? ( '<br /><br />' ) : ( '&nbsp;&nbsp;' );

    $userinfo = $GLOBALS['uinf'];
    $themelist = $_SERVER['F_LIB'] -> buildThemeArray( 1 );

    if ( ( empty( $themelist ) || sizeof( $themelist ) == 1 ) && ( defined( '_T_EXT_OPTIONS_' ) && ! _T_EXT_OPTIONS_ ) )
    {
        return '';
    }

    $content = '<form action="user.php" method="post">' . "\n";

        $content .= '<p class="forms">' . "\n";

            $content .= '<' . $title_tag . '>' . translate( 'Theme' ) . '</' . $title_tag . '>' . "\n";

            $content .= '<select class="' . $style . '" name="theme">' . "\n";

                if ( ! empty( $themelist ) )
                {
                    foreach( $themelist as $v )
                    {
                        $sel = ( ( $userinfo['theme'] == '' && $v == $Default_Theme ) || ( $userinfo['theme'] == $v ) )
                             ? ( 'selected="yes"' )
                             : ( NULL );

                        $content .= '<option ' . $sel . ' value="' . $v . '">' . $v . '</option>' . "\n";
                    }
                }
                else
                {
                    $content .= '<option value="' . $Default_Theme . '">' . $Default_Theme . '</option>' . "\n";
                }

            $content .= '</select>' . "\n";

            if ( defined( '_T_EXT_OPTIONS_' ) && _T_EXT_OPTIONS_ )
            {
                $opt1 = '';

                if ( defined( '_T_USE_TABLES' ) )
                {
                    if ( _T_ALLOW_NOBLOCKS )
                    {
                        $opt1 = array( 1 => translate( 'All Blocks' ), translate( 'Left Blocks Only' ), translate( 'No Blocks' ) );
                    }
                    else
                    {
                        $opt1 = array( 1 => translate( 'All Blocks' ), translate( 'Left Blocks Only' ) );
                    }
                }

                if ( $opt1 == '' )
                {
                    if ( _T_ALLOW_NOBLOCKS )
                    {
                        $opt1 = array( 1 => translate( 'All Blocks' ), translate( 'Left Blocks Only' ), translate( 'Right Blocks Only' ), translate( 'No Blocks' ) );
                    }
                    else
                    {
                        $opt1 = array( 1 => translate( 'All Blocks' ), translate( 'Left Blocks Only' ), translate( 'Right Blocks Only' ), translate( 'No Blocks' ) );
                    }
                }

                $opt2 = array( 1 => translate( 'Format 1' ), translate( 'Format 2' ), translate( 'Format 3' ), translate( 'Format 4' ) );

                $content .= $spacer . "\n";

                $content .= '<' . $title_tag . '>' . translate( 'Page Layout' ) . '</' . $title_tag . '>' . "\n";

                $content .= '<select class="' . $style . '" name="theme_layout">' . "\n";

                    foreach ( $opt1 as $key => $v )
                    {
                        $sel = ( $key == $userinfo['theme_layout'] || $key == _T_PAGE_LAYOUT )
                             ? ( 'selected="yes"' )
                             : ( NULL );

                        $content .= '<option ' . $sel . ' value="' . $key . '">' . $v . '</option>' . "\n";
                    }

                $content .= '</select>' . "\n";

                $content .= $spacer . "\n";

                $content .= '<' . $title_tag . '>' . translate( 'Block Style' ) . '</' . $title_tag . '>' . "\n";

                $content .= '<select class="' . $style . '" name="theme_format">' . "\n";

                    foreach ( $opt2 as $key => $v )
                    {
                        $sel = ( $key == $userinfo['theme_format'] || $key == _T_BLOCK_FORMAT )
                             ? ( 'selected="yes"' )
                             : ( NULL );

                        $content .= '<option ' . $sel . ' value="' . $key . '">' . $v . '</option>' . "\n";
                    }

                $content .= '</select>' . "\n";
            }

            $content .= '<input type="hidden" name="stripit_form" value="theme|theme_layout|theme_format" />' . "\n";
            $content .= '<input type="hidden" name="mpn_sectype" value="2" />' . "\n";
            $content .= '<input type="hidden" name="uid" value="' . $userinfo['uid'] . '">' . "\n";
            $content .= '<input type="hidden" name="op" value="savetheme">' . "\n";
            $content .= '<input type="hidden" name="redirect" value="' . $_SERVER['REQUEST_URI'] . '">' . "\n";

            $content .= $spacer . "\n";

            $content .= '<input class="button" type="submit" value="' . translate( 'Save Changes!' ) . '">' . "\n";

        $content .= '</p>' . "\n";

    $content .= '</form>';

    return $content;

} // End Function

?>