Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Monday, January 18, 2021

File: [Platon] / wolboard / wolboard.php (download)

Revision 1.1.1.1 (vendor branch), Fri Mar 15 00:09:03 2002 UTC (18 years, 10 months ago) by karas9


Changes since 1.1: +0 -0 lines

WolBoard - web message board. It is able to store data in DB or files.
(the license has not yet been chosen, so don't distribute or change the sources without explicit permission of the author)

<? 
/*
    Module:    WolBoard.php3
    
    Author:    Martin Karas a.k.a. Wolcano
    Date:    14.03.2002
    Mail:    wolcano@pobox.sk
    Version:    v4.4


    Description:    Simple message-board. Uses two external files to store
    data - messages, usernames and e-mails. Main functions are show_data_form,
    show_messages. Other runtime information (new user creation form, etc) are
    shown not using function calls.
    

    TODO:
        * zmena hesla/e-mailu usera
        * zmazanie usera (suicide)
        * moznost nastavit si pocet messages pre kazdeho usera zvlast
        * OPTIONS_DIALOG (autorefresh, pagesize, nick, pass, email...all)
        * stalost nastaveni uzivatela (cookies?)
        * plne implementovat pracu s DB/PEAR


    External files specification:
    $message_file :== (<message_line><eoln>)*
        <message_line> :== <unix_time>:<username>:<message> ||
            <unix_time>:<username>:<deleted_message>
        <deleted_message> :== *<message>

    $user_file :== (<user_line><eoln>)*
        <user_line> :== <username>:<email>:<md5sum_of_password>

    Database specification:
    create table messages <unknown for now>

    create table users <unknown>


    Input parameters:
        $pagesize    - # of messages  per page
        $page        - #th page
        $autorefresh    - refresh time (secs)
//        $admin        - user mantainance
        $style        - message view style (0 = board, 1 = chat)
        $time        - message time index
        $nick        - 
        $pass        - 
        $message    - 
        $header        - shows only header
        $body        - show only body
        $bodyframe    - target body frame
        $headerframe    - targer header frame
        $disablepart    - Wont show some parts of the whole document
            (0 - none, 1 - body, 2 - head, 3 - both)
        $setframes    - 1 - create frames
            0 - disable frames (?? :))

        $createuser    - (internal)
        $deleteok    - (internal)
        $newnick    - (internal)
        $archive    - archive file prefix
        $archive_no    - index of archived file
        $submit_type

        CHANGE LOG:
        * 4.4 - PEAR basic implementation (not functional fully)
        * 4.3 - starting MySQL DB implementation
        * 4.2 - started documentation
              - removed autosubmit on nick change
              - changed default autorefresh to 5 mins
              *FIX* now rawurldecoding username (previously rawurlencoded)
        * 4.1 - undocumented :)
*/


    // IMPORTANT CONSTANTS (change if needed)
    $WB_version = "4.4";
    $WB_name = "Wol's Message Board";
    $strip_slashes = 1;
    $DEFAULT_HEAD_FRAME = "";
    $DEFAULT_BODY_FRAME = "";
    $use_virtual_delete = 1;    //use delete flagging instead of real delete
    $root_name = "root";
    $root_md5_password = "896ae34257056a6edb7643e3db85bb21";

    // Filesystem defaults
    $message_file = "board_messages.txt";
    $user_file = "board_emails.txt";
    $move_old_mesages = 1;
    $old_messages_folder = "history/";
    $hist_file_prefix = "board_hist_file_"; // used in REGEXPs! alphabeticals only
    $max_msgs_in_one_file = 200;
    $min_msgs_in_board = 50;

    // Database defaults
    $use_db = 0;
    $db_message_table = "wolboard_messages";
    $db_user_table = "wolboard_users";
    $db_host = "db.host.sk";
    $db_database = "syndrome";
    $db_user = "syndrome";// THIS HAS TO BE CHANGED TO "syndrome"
    $db_pass = "kofola";



    // FUNCTIONS
    
    function good($a) {
        return (isset($a)
         && (
            (is_string($a) && ($a != "")) ||
            (!is_string($a) && ($a != 0))
            )
        );
    }
    
    function link_replace($link, $paramname, $paramvalue) {
        $link = eregi_replace("&$", "", $link);
        $link = eregi_replace("&?$paramname=[^&]*", "", $link);
        if ($paramvalue)
            $link .= "&$paramname=$paramvalue";
        return $link;
    }

    function show_array($a) {
        echo "<table border=1>\n";
        $keys = array_keys($a);

        for($i = 0; $i < sizeof($a); $i++) {
            echo "<tr>\n";
            echo "<td>";
            echo $keys[$i]."</td>\n<td>";

            if ((is_array($a[$keys[$i]])) && ($keys[$i] !== "GLOBALS")) {
                show_array($a[$keys[$i]]);
            }
            else {
                echo $a[$keys[$i]];
            };
            echo "</td>\n</tr>\n";
        }
        echo "</table>";
    }

    function array_copy($a, $i, $n = "x") {
        if (($n == "x") || ($n > (sizeof($a) - $i)))
            $n = sizeof($a) - $i;
            
        for($j = 0; $j < $n; $j++) {
            $ret[$j] = $a[$j + $i];
        }

        return $ret;
    }

    function array_chunk($a, $n) {
        if (!is_array($a))
            return $a;
        $splits = sizeof($a) / $n;
        for($i = 0; $i < $splits; $i++) {
            $ret[$i] = array_copy($a, $i*$n, $n);
        }
        return $ret;
    }

    function w_chk($n, $v) {
        return ($v?"$n=$v&":"");
    }

    function create_link() {
         global $pagesize, $page, $autorefresh, $admin, $style, 
             $time, $nick, $pass, $message, $createuser, $deleteok,
            $autorefresh, $disablepart, $frameset, $headframe,
            $bodyframe, $archive, $archive_no;
        return eregi_replace("&$", "",
            w_chk("nick", $nick).
            w_chk("pagesize", $pagesize).
            w_chk("page", $page).
//            w_chk("time", $time).
//            w_chk("pass", $pass).
//            w_chk("message", $message).
//            w_chk("deleteok", $deleteok).
//            w_chk("createuser", $createuser).
//            w_chk("newnick", $newnick).
            w_chk("autorefresh", $autorefresh).
            w_chk("style", $style).
            w_chk("admin", $admin).
            w_chk("disablepart", $disablepart).
            w_chk("frameset", $frameset).
            w_chk("headframe", $headframe).
            w_chk("bodyframe", $bodyframe).
            w_chk("archive", $archive).
            w_chk("archive_no", $archive_no)
        );
    }

    function wait_read_lock($f, $max_wait = 9999) {
        $start = time();
        while ((!flock($f, 1)) && ($start + $max_wait < time()))
            sleep(1);
        return ($start + $max_wait < time())?
            1:0;
    }

    function wait_write_lock($f, $max_wait = 9999) {
        $start = time();
        while ((!flock($f, 2)) && ($start + $max_wait < time()))
            sleep(1);
    }

    function release_lock($f) {
        flock($f, 3);
        return 1;
    }

    function show_options($optnames, $optvalues, $selected) {
        if (!is_array($optvalues))
            return 0;

        $found = 0;
        $ret = "";
        for($i = 0; $i < sizeof($optvalues); $i++) {
            $ret .= "<option";
            if (good($optvalues[$i])) {
                $ret .= " value=".$optvalues[$i];
                if ($optvalues[$i] == $selected) {
                    $found++;
                    $ret .= " selected";
                }
            }
            $ret .= ">";
            if (good($optnames[$i]))
                $ret .= $optnames[$i];
            $ret .= "</option>\n";
        }
        if ((!$found) && ($selected != ""))
            $ret .= "<option value=$selected selected>Custom</option>\n";
        echo $ret;
    }

    function get_user($str, $i = 0) {
        $tmp = strtok(trim($str), ":");
        if ($i)
            // (1) from $MESSAGE_FILE
            return strtok(":");
        else
            // (0) from $USER_FILE
            return $tmp;
    }
    
    function get_users($usr_file, $use_db = 0, $db_conn = 0) {
        if ($use_db)
            // Working with files
            $fp = fopen($usr_file, "r");
            wait_read_lock($fp);
            $ret = file($usr_file);
            for($i = 0; $i < sizeof($ret); $i++) {
                $ret[$i] = trim($ret[$i]);
                $ret[$i] = get_user($ret[$i], 0);
            }
            release_lock($fp);
            return $ret;
        }
        else {
            // Working with DB
            $res = $db_conn->query("select nick from $usr_file where nick <> ''");
            $i = 0;
            while ($tmp = $res->fetchRow()) {
                $ret[$i] = $tmp[0];
                $i++;
            }
            $db_conn->free;
            return $ret;
        }
    }
    
    function format_time($time, $style = 0) {
        switch($style) {
            case 1:
                return date("H:i:s", $time);
            default:
                return date("H:i:s - d. M Y", $time);
        }
    }

    function get_time($str) {
        return strtok(trim($str), ":");
    }
    
    function get_pass($str) {
        return rawurldecode(trim(strtr(strrchr($str, ":"), ":", ";")));
    }

    function get_email($str) {
        if (ereg("[^:]*:([^:]*):", $str, $regs))
            return $regs[1];
        else
            return "";
    }
    
    function write_mail($usr_file, $user, $mail = "", $pass = "", $use_db = 0, $db_conn) {
        $pass = md5(rawurlencode($pass));
        if (!$use_db) {
            // Working with files
            $fp = fopen($usr_file, "a");
            if (!wait_write_lock($fp))
                return false;
            fwrite($fp, strtr($user, ":", ";").":".strtr($mail, ":", ";").
                ":".$pass."\n");
            release_lock($fp);
            fclose($fp);
            return true;
        }
        else {
            // Working with DB
            $user = addslashes($user);
            $mail = addslashes($mail);
            $res = $db_conn->query("insert into $usr_file values".
                "('$user', '$mail', '$pass', '', '', '')");//!!!TODO
            return (DB::isError($res));
        }
    }

    function change_mail($usr_file, $user, $newmail = "", $pass = "",
        $use_db = 0, $db_conn = 0) {
        function set_mail($usr_line, $newmail) {
            $ret = strtok($usr_line, ":");
            strtok(":");
            $ret .= $newmail.":".strtok(":");
            return $ret;
        }

        //check if valid data is sent
        //we dont want to run for now
        if (true)//!!!!!!!!
            return 0;

        if (!$use_db) {
            // Using files
            $fp = fopen($usr_file, "w+");
            wait_write_lock($fp);
            $tmp = files($usr_file);
            $i = 0;
            $found = false;
            while (($i < length($tmp)) && (!$found)) {
                $u = get_user($tmp[$i]);
                if ($u == $user) {
                    $tmp[$i] = set_mail($tmp[$i], $newmail);
                    $found = true;
                }
                $i++;
            }
    
            if ($found) {
                fwrite($fp, $u);
                release_lock($fp);
                fclose($fp);
                return 1;
            }
            else 
                return 0;
        }
        else {
            // Using DB
            //!!!TODO
            // "update $usr_file set mail = '$newmail' where name = '$user' and pass = '$pass'"
            return 0;
        }
    }
    
    function delete_mail($usr_file, $user = "", $mail = "", $pass = "",
        $use_db = 0, $db_conn = 0) {
        //!!!! TODO
        if (!$use_db) {
            // Use files
            return 0;    
        }
        else {
            // Use DB
            //    "update $usr_file set mail = ''".
            //        where name = '$user' and pass = '$pass' and mail = '$mail'"
            return 0;    
        }
    }
    
    function get_emails($usr_file, $use_db = 0, $db_conn = 0) {
        if (!$use_db) {
            // Use files
            $fp = fopen($usr_file, "r");
            wait_read_lock($fp);
            $f = file($usr_file);
            for($i = 0; $i < sizeof($f); $i++)
                $ret[get_user($f[$i], 0)] = get_email($f[$i]);
    
            release_lock($fp);
            return $ret;
        }
        else {
            // Use DB
            // TODO
            //    "select * from $usr_file where status = 1"
            return "";
        }
    }

    function read_messages($msg_file, $usr_file, $full = 0, $use_db = 0,
        $db_messages = 0, $db_users = 0) {
        if (!$use_db) {
            $mails = get_emails($usr_file, 0);
            $mfp = fopen($msg_file, "r");
            wait_read_lock($mfp);
            $f = file($msg_file);
            $n = 0;
            for ($i = 0; $i < sizeof($f); $i++) {
                if ($f[$i] != "") {
                    if ((!$full) && ereg("[^:]*:[^:]*:\*", $f[$i], $regs))
                        continue;
                    $ret[$n]["time"] = strtok($f[$i], ":");
                    $ret[$n]["name"] = rawurldecode(strtok(":"));
                    $ret[$n]["message"] = trim(rawurldecode(strtok(":")));
                    $ret[$n]["email"] = $mails[$ret[$n]["name"]];
                    $n++;
                }
            }
            release_lock($mfp);
            return $ret;
        }
        else {
            // Use DB
            if ($full)
                $q = board_db_query("select autor_id, ".
                    "text, created from $msg_file");
            else
                $q = board_db_query("select autor_id, ".
                    "text, created from $msg_file where flags = 0");
            // TODO
        }
    }

    function need_to_split($a, $max, $min) {
        if ((sizeof($a) - $max) <= $min)
            return false;
        else
            return true;
    }

    function split_messages_to_more_files($msgs, $max_len, $min_len,
    $hist_dir, $hist_file_prefix = "board_hist_file_", $index_style = 0) {
        if (!need_to_split($msgs, $max_len, $min_len))
            return $msgs;
        $full = array_chunk($msgs, $max_len);

        $d = opendir($hist_dir);
        $i = -1;
        $max_num = -1;
        // looking for previous save of maximum index (and count of saves)
        while (($file = readdir($d)) !== false) {
            if (ereg("^$hist_file_prefix([0-9]*)", $file, $regs)) {
                $i++;
                if ($max_num < $regs[1])
                    $max_num = $regs[1];
            }
        }
        closedir($d);

        switch($index_style) {
            case "0":
                $new_index = $max_num + 1;
                break;
            case "1":
                $new_index = ++$i;
                break;
        }
        
        for($i = 0; $i < (sizeof($full) - 1); $i++) {
            $new_file = $hist_dir.$hist_file_prefix.($new_index + $i);
            $fp = fopen($new_file, "a");
            wait_write_lock($fp);
            fwrite($fp, implode($full[$i], ""));
            release_lock($fp);
        }
        $msgs = $full[sizeof($full) - 1];
        
        return $msgs;
    }
        
    function write_message($msg_file, $user = "Anonym", $text = "<no message>", 
        $time = 0, $old_messages_folder, $max_msgs_in_one_file,
        $min_msgs_in_board, $hist_file_prefix, $use_db = 0, $db_conn = 0) {

        if (($time == 0) || !ereg("^[0-9]*$", $time))
            $time = time();
        $user = rawurlencode($user);
        $text = trim($text);
        $text = str_replace("ignorant", "ign-co? (c) Wol", $text); //some fun :)
        if ($text[0] == '*')    // this is used as the deleted flag prefix
            $text = " ".$text;

        if (!$use_db) {
            // Use files
            $new_msg = 
                $time.":".
                $user.":".
                rawurlencode(nl2br(htmlspecialchars($text)))."\n";
            $msgs = file($msg_file);
            $msgs[] = $new_msg;
    
            if (need_to_split($msgs, $max_msgs_in_one_file, $min_msgs_in_board)) {
                $fp = fopen($msg_file, "w");
                wait_write_lock($fp);
                sort($msgs);
                $msgs = split_messages_to_more_files(
                    $msgs,
                    $max_msgs_in_one_file,
                    $min_msgs_in_board,
                    $old_messages_folder,
                    $hist_file_prefix,
                    0
                );
                $msgs = implode($msgs, "");
                if (trim($msgs) == "")
                    $msgs = "";
                fwrite($fp, $msgs);
            }
            else {
                unset($msgs);
                $fp = fopen($msg_file, "a");
                wait_write_lock($fp);
                fwrite($fp, $new_msg);
            }
    
            release_lock($fp);
            fclose($fp);
            return 1;
        }
        else {
            // Use DB
            // TOdO
            //    "insert into $msg_file values (".
            //    "'$user', '$text', '$time', '', '')"
            return 0;
        }
    }
    

    function delete_message($msg_file, $usr_file, $user, $time, $pass,
        $use_virtual_delete, $use_db = 0, $db_messages = 0, $db_users = 0) {
        if (!$use_db) {
            // Use files
            $found = false;
            $i = 0;
            $fp = fopen($usr_file, "r");
            wait_read_lock($fp);
            $p = file($usr_file);
            release_lock($fp);
            if ($user != "") {
                while ((!$found) && ($i < sizeof($p))) {
                    if ($user == get_user($p[$i], 0))
                        $found = true;
                    $i++;
                };
            }
            else
                $found = true;
    
            if (!$found) 
                return 1;
    
            if (!(($user == "") && ($pass == "")))
                if (get_pass($p[--$i]) != md5($pass))
                    return 2;
            
            $fp = fopen($msg_file, "r");
            wait_read_lock($fp);
            $f = file($msg_file);
            $found = false;
            $i = 0;
            while (!$found && ($i < sizeof($f))) {
                if (get_user($f[$i], 1) == $user && get_time($f[$i]) == $time)
                    $found = true;
                $i++;
            }
            if (!$found)
                return 3;
            $i--;

            if ($use_virtual_delete) {
                // if already marked as deleted then delete it really
                if (ereg("[^:]*:[^:]*:\*.*", $f[$i], $regs))
                    $f[$i] = $f[sizeof($f) - 1];
                // if not marked, mark it :)
                else
                    $f[$i] = ereg_replace("([^:]*:[^:]*:)(.*)", "\\1*\\2", $f[$i]);
            }
            else {
                if (sizeof($f) > 0) {
                    $f[$i] = $f[sizeof($f) - 1];
                }
                else
                    $f = array();
            }
    
            // we supppose the array to be sorted (sorting while insert)
            //sort($f);
            
            release_lock($fp);
            
            $fp = fopen($msg_file, "w");
            wait_write_lock($fp);
            if (is_array($f))
                fwrite($fp, trim(implode($f, ""))."\n");
            else
                if (trim($f) != "")
                    fwrite($fp, trim($f)."\n");
            release_lock($fp);
            fclose($fp);
    
            return 0;
        }
        else {
            // Use DB
            // TODO
            // if ! "select count(*) from $usr_file where name = '$user' and pass = '$pass'"
            // if $use_virtual_delete
            //    "select message, id from $msg_file where name = '$user' and time='$time'"
            // else
            //    "delete from $msg_file where name = '$user' and time='$time'"
            return -1;
        }
    }

    function show_data_form($user_file, $self, $nick,
        $style, $WB_name, $autorefresh, $pagesize, $use_db = 0, $db_conn = 0) {
        global $headframe;
        global $bodyframe;
        global $show_body;
        global $frameset;
?>
<center>
<font color="#C0C0C0" face="Courier" size=5><b><?echo $WB_name?></b></font><br>
Current time is <?echo format_time(time())?>.
<br>
<table border=0>
<form name=data method=POST action="<?
    echo "$self?";
    $tmp = link_replace(create_link(), "page", "");
    if (good($frameset))
        $tmp = link_replace($tmp, "disablepart", "2");
    echo $tmp;
?>" target="<?echo $bodyframe?>">
<tr>
    <td align=center valign=middle rowspan=3>
        <textarea name="message" cols=30 rows=5></textarea></td>
    <td align=center valign=middle><font face="Arial" color=#ffcc00 size=3>Nick</font></td>
    <td align=left valign=middle>
        <select name="nick">
            <option value="Anonym">&lt;choose&gt;</option>
<?
            
        $nicknames = get_users($user_file $use_db, $db_conn);
        sort($nicknames);
        show_options(
            $nicknames,
            $nicknames,
            $nick);
?>
        </select>
    </td>
</tr>
<tr>
    <td valign=middle align=center colspan=2 rowspan=1><input type=submit name=submit_type value="Send"<?
    echo "showing=$show_body";
    if (!$show_body)    //!!!!!!!!!!!!TOTO NEJDE - JS clearovanie textarea v combo prikaze, aspon nie v tomto zdrojaku :(
        echo " onClick=\"javascript:submit();message.value=''\"";

?>></td>
</tr>
<tr></tr>
<tr>
    <td align=center>
        <a href="<?echo $self."?".link_replace(create_link(), "createuser", "1")?>">New nick</a>
    </td>
    <td align=right><?
    if (!$style)
        echo "Board\t /</td><td><a href=$self?".
            link_replace(create_link(), "style", "1").">Chat</a></td>";
    else
        echo "<a href=$self?".link_replace(create_link(), "style", "0").
            ">Board</a> /</td><td>Chat</td>";
?>
</tr>
<tr>
    <td align=center colspan=1>Autorefresh time:
        <select name=autorefresh onChange="javascript:form.submit()">
<?
    show_options(
        array("10 secs","30 secs", "1 min", "5 min", "10 min", "30 min", "infinite"), 
        array("10", "30", "60", "300", "600", "1800", "999999999"),
        $autorefresh);
?>
        </select>
    </td><td align=center colspan=1>Page size:
        <select name=pagesize onChange="javascript:form.submit()">
<?
    show_options(
        array("10", "25", "50", "100", "all"),
        array("10", "25", "50", "100", "999999"),
        $pagesize);
?>
        </select>
    </td><td align=center><a href="boardframes.html" target=_top>Switch </a><a href="boardframes.html" target=_blank>to</a> <a href="boardframes.html" target=_parent>frames</a></td>
</tr>
</form>
</table>
</center>
<?
        return 1;
    }

    function show_page_walk($currentpage, $pagesize, $nummsgs, $firstmsg, $lastmsg) {
        global $self;
        $lastpage = ceil($nummsgs / $pagesize);

        echo "<center>Messages ".($firstmsg + 1)."-".
            ($lastmsg + 1)." of $nummsgs<br>";

        // REWIND to begin
        if ($firstmsg == 0)
            echo "&lt;&lt;";
        else 
            echo "<a href=$self?".link_replace(create_link(), "page", "1").">&lt;&lt;</a>";
        echo " ";

        // PREVIOUS PAGE
        if ($firstmsg == 0)
            echo "&lt;";
        else 
            echo "<a href=$self?".link_replace(create_link(), "page", ($currentpage-1)).">&lt;</a>";
        
        echo " ";

        // OTHER PAGES
        for ($i = 1; $i <= $lastpage; $i++) {
            echo ($i == $currentpage)?"$i ":"<a href=$self?".
                link_replace(create_link(), "page", $i).">".$i."</a> ";
        }

        // NEXT PAGE
        if ($lastmsg >= ($nummsgs - 1))
            echo "&gt;";
        else 
            echo "<a href=$self?".
                link_replace(create_link(), "page", ($currentpage+1)).
                ">&gt;</a>";

        echo " ";

        // REWIND PAGE to end
        if ($lastmsg >= ($nummsgs - 1))
            echo "&gt;&gt;";
        else 
            echo "<a href=$self?".
                link_replace(create_link(), "page", $lastpage).
                ">&gt;&gt;</a>";
        
        echo "</center>\n";
    }

    function show_nonrefresh_head() {
        global $WB_name, $WB_version;
?>
<html>
<head>
<title><?echo "$WB_name v$WB_version"?></title>
</head>
<body bgcolor="black" text="#C0C0C0" link="#888ff" alink="#888ff" vlink="#888ff">
<?
    }

    function show_delete_dialog($nick, $time) {
        global $self;
        echo "\n<center><font color=#C0C0C0 face=Courier size=4><b>Delete message</font></b><br><br>";
        echo "\n<center>\n<form name=deletemessage method=post action=$self?".
            link_replace(link_replace(create_link(), "deleteok", 1),
                "time", $time).">\n";
        echo "<table align=center>\n";
        echo "\t\n<tr>\n\t\t<td>Nick:</td><td><input type=text value=\"$nick\" readonly></td></tr>\n";
        echo "\t\n<tr>\n\t\t<td>Message No.:</td><td><input type=text value=\"$time\" readonly></td></tr>\n";
        echo "\t\n<tr>\n\t\t<td>Password:</td><td><input type=password name=pass></td></tr>\n";
        echo "\t\n<tr>\n\t\t<td colspan=2 align=center><input type=submit name=submit_type value=Delete>\n</td></tr>\n";
        echo "\t<tr><td align=center colspan=2><a href=$self?".
            create_link().
            ">cancel</a></td></tr>\n";
        echo "</table>\n";
        echo "</form>\n</center>\n";
    }
    
    function show_createuser_dialog($newnick, $email) {
        global $self;
        echo "\n<center><font color=#C0C0C0 face=Courier size=4><b>Create new user</font></b><br><br>";
        echo "<table size=90% align=center>\n";
        
        echo "\n<form name=createuser method=post action=$self?". 
            link_replace(link_replace(
                create_link(), "createok", 1), "createuser", 1
            ).
            ">\n";
        echo "\t<tr>\n\t\t<td>New Nick:</td><td><input type=text name=newnick maxsize=16 value=$newnick></td>\n";
        echo "\t<tr><td>E-mail:</td><td><input type=text name=mail value=$email></td>\n\t</tr>\n";
        echo "\t<tr><td>Password:</td><td><input type=password name=pass></td>\n\t</tr>\n";
        echo "\t<tr><td align=center colspan=2><input type=submit name=submit_type value=Create></td>\n\t</tr>\n";
        echo "\t<tr><td align=center colspan=2><a href=$self?".
            link_replace(create_link(), "createuser", "").
            ">cancel</a></td></tr>\n";
        echo "</form>\n</table>\n</center>\n";
    }

    function show_message($message, $style = 0) {
        global $self;
        switch($style) {
            case 1:
            // Chat message line
                echo "<tr><td valign=top>";
                echo "<a href=$self?".
                    link_replace(
                        link_replace(
                            create_link(), "time", $message["time"]
                            ),
                        "nick",
                        $message["name"]).
                    ">".format_time($message["time"], 1)."</a>_";
                if ($message["email"] != "")
                    echo "<a href=\"mailto:".$message["email"].
                        "\""." class=\"amsg\">".
                        $message["name"]."</a>";
                else 
                    echo $message["name"];
                echo ":</td><td>".$message["message"];
                echo "</td></tr>\n";
                break;
            default:
            // Board message style
                echo "<tr><td>";
                if ($message["email"] != "")
                    echo "<a href=\"mailto:" .
                        $message["email"] .
                        "\" class=\"amsg\">\n";
                echo "\t" . $message["name"] . "\n";
                echo "</a>\n\t - ";
                echo "\t" . format_time($message["time"])."\n";
                echo "\t\t - <a href=$self?" .
                    link_replace(
                        link_replace(
                            create_link(), "time", $message["time"]
                            ),
                        "nick",
                        $message["name"]).
                    ">delete</a>\n";
                echo "<br>";
                echo "\t" . $message["message"] . "\n";
                echo "</td></tr>\n";
                break;
        }
    }

    function show_messages($message_file, $user_file, $page, $pagesize,
        $msg_style = 0, $show_all = 0, $use_db = 0, $db_messages = 0, $db_users = 0) {

        $messages = read_messages($message_file, $user_file, $show_all,
            $use_db, $db_messages, $db_users);
        $n = sizeof($messages);
        global $self;//!!!!! TODO
        
        if ($n <= 0) {
            echo "<center><font color=red><b>No messages YeT !</b></font></center>";
        }
        else {
            if ($page < 1)
                $page = 1;
            if ($page >= ($n / $pagesize))
                $page = ceil($n / $pagesize);
            
            $first = $pagesize * ($page - 1);
            $last = ($pagesize * $page) - 1;
            
            if ($first < 0) 
                $first = 0;
            if ($first > $n)
                $first = $n - 1;
        
            if ($last > ($n - 1)) 
                $last = $n - 1;
            if ($last < $first)
                $last = $first;
    
            show_page_walk($page, $pagesize, $n, $first, $last);
    
            echo "<table width=100%>";
            for ($i = $first; $i <= $last; $i++) {
                show_message($messages[sizeof($messages) - 1 - $i], $msg_style);
            }
            echo "</table>";
    
            show_page_walk($page, $pagesize, $n, $first, $last);
        }
    }


// ///////////////////////////////////////////////
// /////////// THIS IS MAIN FUNCTION /////////////
// ///////////////////////////////////////////////

    // DEFAULTS
    if ($use_db) {
        require_once "db.php";
        $db_messages = DB::connect("mysql://$db_user:$db_pass/$db_host/$db_message_table");
        $db_users = DB::connect("mysql://$db_user:$db_pass/$db_host/$db_user_table");
        if (DB::isError($db_messages)) {
            $use_db = 0;
        }
        if (DB::isError($db_users))
            if (!(DB::isError($db_messages)))
                $db_messages->disconnect();
            $use_db = 0;
        }
        if ($use_db) {
            $user_file = $db_users;
            $message_file = $db_messages;
        }
    }

    if (!good($self)) 
        $self = $PHP_SELF;

    if ($strip_slashes) {
        $message = stripslashes($message);
        $nick = stripslashes($nick);
        $pass = stripslashes($pass);
        $header = stripslashes($header);
        $body = stripslashes($body);
        $bodyframe = stripslashes($bodyframe);
        $headerframe = stripslashes($headerframe);
        $disablepart = stripslashes($disablepart);
        $setframes = stripslashes($setframes);
        $newnick = stripslashes($newnick);
    }
    
    if ($pagesize < 10)
        $pagesize = 50;
    settype($pagesize, integer);
    if ($autorefresh < 10)
        $autorefresh = 300;
    settype($autorefresh, integer);


    if (!good($disablepart) || ($disablepart>3) || ($disablepart<0))
        $disablepart = 0;
    
    if (!good($headframe))
        $headframe = $DEFAULT_HEAD_FRAME;

    if (!good($bodyframe))
        $bodyframe = $DEFAULT_BODY_FRAME;
    
    switch ($disablepart) {
        case 0:
            $show_body = true;
            $show_head = true;
            break;
        case 1:
            $show_head = true;
            $show_body = false;
            break;
        case 2:
            $show_head = false;
            $show_body = true;
            break;
        case 3:
            $show_body = false;
            $show_head = false;
            break;
    }

    if (!good($page)) 
        $page = 0;

    if (!isset($nick) && good($newnick))
        $nick = $newnick;
    
    if (!good($mail))
        $mail = get_email($nick);
    
    if (good($archive))
        $hist_file_prefix = $archive;

    if (good($archive_no) && !$use_db)
        $message_file = $old_messages_folder.$hist_file_prefix.$archive_no;

    //header ("Cache-Control: no-cache, must-revalidate");
    //header ("Pragma: no-cache");

    // CREATE NEW USER
    if ($createuser) {
        $mails = get_emails($user_file, $use_db, $db_users);

        if (good($newnick) && 
            ($mails[$newnick] == "") && 
            good($mail) && 
            good($createok) && 
            ($createok == 1))
            write_mail($user_file, $newnick, $mail, $pass, $use_db, $db_users);
        else {
            show_nonrefresh_head();
            show_createuser_dialog($newnick, $email);
            $show_body = false;
        }
    }

    // WRITE MESSAGE TO DB
    if (good($message) && good($submit_type))
        write_message($message_file, $nick, $message, 0,
            $old_messages_folder, $max_msgs_in_one_file,
            $min_msgs_in_board, $hist_file_prefix, $use_db, $db_messages);

    // DELETE MESSAGE FROM DB
    if (good($time)) {
        if (good($deleteok) && ($deleteok == 1)){
            switch(delete_message($message_file, $user_file, $nick,
                $time, $pass, $use_virtual_delete, $use_db, $db_messages, $db_users)) {
            // TOTO ESTE DOROBIT - SPRAVANIE SA 
            // SKRIPTU KED NASTANU PROBLEMY PRI DELETOVANI SPRAVY
                case 0: // All OK
//                    echo "<center>Message deleted succesfully<br></center>\n";
                    break;
                case 1: // No such user
//                    echo "<center>Error while deleting: There is no such user!<br></center>\n";
                    break;
                case 2: // Wrong password
//                    echo "<center>Error while deleting: Wrong password!<br></center>\n";
                    break;
                case 3: // No such message
//                    echo "<center>Error while deleting: No such message!<br></center>\n";
                    break;
                default:// Unknown error
//                    echo "<center>Fatal Error while deleting: unknown error code!</center><br>\n";
                    break;
            }
        } else {
            show_nonrefresh_head();
            show_delete_dialog($nick, $time);
            $show_body = false;
        }
    }

    // check for superuser view
    if (($nick == $root_name) && (md5($pass) == $root_md5_password))
        $superuser = 1;
    else
        $superuser = 0;

    // We don't want to show body, when other form is shown
    
?>
<html>
<head>
<title><?echo "$WB_name v$WB_version"?></title>
<?
    if ($show_head) {
?>
</head>
<body bgcolor=black text=#C0C0C0 link=#888ff alink=#888ff vlink=#888ff>
<?
        show_data_form($user_file, $self, $nick, $style, $WB_name,
            $autorefresh, $pagesize, $use_db, $db_users);
    }
    
    if ($show_body) {
        echo "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"$autorefresh URL=$self?".
            create_link()."\">\n";
?>
</head>
<body bgcolor=black text=#C0C0C0 link=#888ff alink=#888ff vlink=#888ff>
<?
        show_messages($message_file, $user_file, $page, $pagesize,
            $style, $superuser, $use_db, $db_messages, $db_users);
    }

    if ($use_db) {
        $user_file->disconnect();
        $message_file->disconnect();
    }
?>
</p>
</body>
</html>

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top