<?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                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: chatboxII.php,v 1.7.2.3 2004/08/27 15:51:16 kirilt Exp $



######################################################################
# ChatBox II
# =============
#
# Copyright (C) 2001 by Gerard Samuel (trini0@optonline.net)
#
# Based on code found in myPHPNuke
# Ingo van Peeren (ingo@beginner-ag.de)
# Michael Yarbrough (http://www.comediccadavers.com/)
######################################################################
# This program is free software. You can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
######################################################################


include("extention.inc");
function viewsmile($message) {
        $ipth = "<img src=\"images/forum/smilies/";
    $message = str_replace(":D", "".$ipth."icon_biggrin.gif\" />", $message);
    $message = str_replace(":-D", "".$ipth."icon_biggrin.gif\" />", $message);
        $message = str_replace(":grin:", "".$ipth."icon_biggrin.gif\" />", $message);
        $message = str_replace(":)", "".$ipth."icon_smile.gif\" />", $message);
        $message = str_replace(":-)", "".$ipth."icon_smile.gif\" />", $message);
        $message = str_replace(":smile:", "".$ipth."icon_smile.gif\" />", $message);
        $message = str_replace(":(", "".$ipth."icon_frown.gif\" />", $message);
        $message = str_replace(":-(", "".$ipth."icon_frown.gif\" />", $message);
        $message = str_replace(":sad:", "".$ipth."icon_frown.gif\" />", $message);
        $message = str_replace(":O", "".$ipth."icon_eek.gif\" />", $message);
        $message = str_replace(":-O", "".$ipth."icon_eek.gif\" />", $message);
        $message = str_replace(":eek:", "".$ipth."icon_eek.gif\" />", $message);
        $message = str_replace(":-?", "".$ipth."icon_confused.gif\" />", $message);
        $message = str_replace(":???:", "".$ipth."icon_confused.gif\" />", $message);
        $message = str_replace("8)", "".$ipth."icon_cool.gif\" />", $message);
        $message = str_replace("8-)", "".$ipth."icon_cool.gif\" />", $message);
        $message = str_replace(":cool:", "".$ipth."icon_cool.gif\" />", $message);
        $message = str_replace(":lol:", "".$ipth."icon_lol.gif\" />", $message);
        $message = str_replace(":x", "".$ipth."icon_mad.gif\" />", $message);
        $message = str_replace(":-x", "".$ipth."icon_mad.gif\" />", $message);
        $message = str_replace(":mad:", "".$ipth."icon_mad.gif\" />", $message);
        $message = str_replace(":P", "".$ipth."icon_razz.gif\" />", $message);
    $message = str_replace(":-P", "".$ipth."icon_razz.gif\" />", $message);
        $message = str_replace(":razz:", "".$ipth."icon_razz.gif\" />", $message);
        $message = str_replace(":oops:", "".$ipth."icon_redface.gif\" />", $message);
        $message = str_replace(":cry:", "".$ipth."icon_cry.gif\" />", $message);
        $message = str_replace(":evil:", "".$ipth."icon_evil.gif\" />", $message);
        $message = str_replace(":roll:", "".$ipth."icon_rolleyes.gif\" />", $message);
        $message = str_replace(":wink:", "".$ipth."icon_wink.gif\" />", $message);
        $message = str_replace(";)", "".$ipth."icon_wink.gif\" />", $message);
        $message = str_replace(":pint:", "".$ipth."icon_drink.gif\" />", $message);
        $message = str_replace(":hammer:", "".$ipth."icon_hammer.gif\" />", $message);
        $message = str_replace(":idea:", "".$ipth."icon_idea.gif\" />", $message);
    return($message);
}
function makeChatBoxII()
{
    global $mpnTables, $mpn_display_chatboxII, $sitename, $phpEx;

    /*$win_page = 'chat.php';
    $win_name = $sitename . translate( 'Chat' );
    $win_para = 'width=550,height=500,toolbar=0,location=1,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0';
    $text = translate( 'Click here to open the chatbox' );
    $link = '<a class="subtitle1" href="javascript:popWindow( \'' . $win_page . '\', \'' . $win_name . '\', \'' . $win_para . '\' );" title="' . $text . '">' . $text . '</a>' . "\n";*/

    $jsfunc = "
<script type=\"text/javascript\">
<!--
    function newWindow()
    {
        open(\"chat.$phpEx\", \"a".time()."\", \"height=500,width=550,screenX=0,screenY=20,top=20,left=0,resizable=no,toolbar=no,scrollbars=no,location=no,directories=no,status=no,menubar=no,copyhistory=no\");
    }
-->
</script>\n";

    if ($mpn_display_chatboxII == 1)
    {
        $thing = $jsfunc;

        $thing .= "<div class='center'>\n";
        $thing .= "<div class='centchatbox'>\n";
        $thing .= "<div class='chatmsg'>";
    }
   else
    {
        global $title1, $position, $content1;

        $title = build_title($title1,translate("ChatBoxII"));
        $boxstuff = build_content( $position, $content1 );
        $boxstuff .= $jsfunc;
        $boxstuff .= "<div class='blkchatbox'>\n";
        $boxstuff .= "<div class='chatmsg'>";
    }

    $query = "SELECT count(date) FROM ".$mpnTables['chatboxII']."";
    $result = mysql_query($query);
    $max = mysql_result($result, 0);
    if ($max <= 7) {
        $min = 0;
    } else {
        $min = $max - 7;
    }

    $sql = 'SELECT username, message FROM ' . $mpnTables['chatboxII'] . ' ORDER BY date LIMIT ' . (int)$min . ', ' . (int)$max;
    $result = mysql_query( $sql );


    if ( $result )
    {
        while(list($username, $message) = mysql_fetch_array($result)) {
            if ($username != "" || $message != "") {
                if ($mpn_display_chatboxII == 1) {
                    $thing .= "<a href=\"user.php?op=userinfo&amp;uname=".$username."\"><b>".$username."</b></a>";
                }
                if ($mpn_display_chatboxII == 2) {
                    $boxstuff .= "<a href=\"user.php?op=userinfo&amp;uname=".$username."\"><b>".$username."</b></a>";
                }
                $message = viewsmile($message);
                if ($mpn_display_chatboxII == 1) {
                    $thing .= "&nbsp;&gt;&nbsp;&nbsp;" . $message . "<br />\n";
                }
                if ($mpn_display_chatboxII == 2) {
                    $boxstuff .= "&nbsp;&gt;&nbsp;&nbsp;" . $message . "<br />\n";
                }
            }
        }
    }

    if ($mpn_display_chatboxII == 1) {
       $thing .= "</div><br /><br /><hr size=2 width=90% color=navy><a href=\"javascript:newWindow()\"><b>".translate("Click here to open the chatbox")."...</b></a></form>";
    }
    if ($mpn_display_chatboxII == 2) {
        $boxstuff .= "</div><hr size=2 width=90% color=navy><a href=\"javascript:newWindow()\"><b>".translate("Click here to open the chatbox")."...</b></a></form>";
    }

    $sql = 'SELECT count(DISTINCT username) FROM ' . $mpnTables['chatboxII'] . ' WHERE date >= ' . (time()-(60*2));
    $result = mysql_query( $sql );

    $numofchatters = ( $result ) ? ( mysql_result($result, 0) ) : ( 0 );

    if ($mpn_display_chatboxII == 1) {
        $thing .= "<br /><br". translate("There")." ";
        if ($numofchatters == 1) {
            $thing .= translate("is")." <font color='red'>1</font> ". translate("person chatting right now").".";
        } else {
            $thing .= translate("are")." <font color='red'>".$numofchatters."</font> ".translate("people chatting right now").".";
        }
    }

    if ($mpn_display_chatboxII == 2) {
        $boxstuff .= "<br /><br". translate("There")." ";
        if ($numofchatters == 1) {
            $boxstuff .= translate("is")." <font color='red'>1</font> ". translate("person chatting right now").".";
        } else {
            $boxstuff .= translate("are")." <font color='red'>".$numofchatters."</font> ".translate("people chatting right now").".";
        }
    }
    if ($mpn_display_chatboxII == 1)
    {
        $thing .= "</div></div>\n";
        themecenterposts("ChatBox II", $thing);
    }
    if ($mpn_display_chatboxII == 2)
    {
        $boxstuff .= "</div>\n";
        $boxstuff = build_content($position,$content1,$boxstuff);
        themesidebox($title, $boxstuff);
    }
}

?>