#!/usr/bin/perl #------------------------------------------------------------------------------ # UltraThreads # Copyright (c) 2000 Kelvin Wu # # 2000.07 #------------------------------------------------------------------------------ use strict; # Imports use CGI::Carp qw(fatalsToBrowser); use DBI; use UTConfig; use UTLanguage; use UTMain; #------------------------------------------------------------------------------ # Get user connectDb(); my $user = authUser(); # Check if forum is closed printMessage("$lng{'forumClosedLb'}", "$lng{'forumClosed'}") if $cfg{'forumClosed'} && !$user->{'admin'}; # Print header my @buttons = (); printHeader($user, "", \@buttons); # Check if access should be denied checkBlock(); my $imgAlign = getBrowserAttr('middleImgAlign'); # Check private messages my $pmMsgIcon = (!$user->{'defaultUser'} && $user->{'pmNew'} && $cfg{'pm'}) ? "\"$lng{'forumPmNew1'}{'pmNew'} $lng{'forumPmNew2'}\">    \n" : ""; # Print greeting my $msg = $user->{'defaultUser'} ? "$lng{'forumNoLogin'}" : "$lng{'forumWelcome'} $user->{'userName'}"; print "
", "\n", "", "\n", "
$msg\n"; my $lastTime = $user->{'lastReadTime'} ? "(" . formatTime($user->{'lastReadTime'}) . ")" : ""; $user->{'defaultUser'} ? print "" : print "

", " $lng{'forumNewPosts'} ", $lastTime; # Get number of members my $query = "SELECT COUNT(*) FROM ut_users"; my $sth = query($query); my $userNum = $sth->fetchrow_array(); $sth->finish; # Get number of posts my $postsTable = ""; if ($cfg{'showPostNum'}) { $query = "SELECT SUM(postNum+postNumBak) FROM ut_boards"; $sth = query($query); my $postNum = $sth->fetchrow_array(); $sth->finish; $postsTable = "\n" . "\n" . "
\n" . "\n" . "
" . "" . "$postNum  " . "
\n" . "
"; } print "
", "$pmMsgIcon
", "
\n", "$postsTable", "\n", "\n", "\n", "
\n", "\n", "
", "$lng{", "$userNum  ", "
\n", "
\n", "
\n", "
\n"; # Get categories $query = "SELECT * FROM ut_categories ORDER BY pos"; $sth = query($query); my $cats = $sth->fetchall_arrayref({}); $sth->finish; # Get boards $query = " SELECT ut_boards.*, ut_hiddenboards.userId IS NOT NULL AS hidden FROM ut_boards LEFT JOIN ut_hiddenboards ON ut_hiddenboards.userId = $user->{'id'} AND ut_hiddenboards.boardId = ut_boards.id WHERE ut_boards.active = 1 ORDER BY pos"; $sth = query($query); my $boards = $sth->fetchall_arrayref({}); $sth->finish; my %boards = (); for my $board (@$boards) { $boards{$board->{'id'}} = $board } # Get new posts unless ($user->{'defaultUser'}) { $query = " SELECT boardId, COUNT(*) FROM ut_posts WHERE postTime > $user->{'lastReadTime'} GROUP BY boardId"; $sth = query($query); while (my @data = $sth->fetchrow_array()) { ($boards{$data[0]}->{'newPostNum'}) = $data[1] if defined($boards{$data[0]}); } $sth->finish; } my $age = $user->{'defaultUser'} ? $cfg{'postsAge'} : $user->{'postsAge'}; # Print table header print tableStart($user), "\n", "$lng{'forumCatg'}\n", "$lng{'forumPosts'}\n", "$lng{'forumNew'}\n", "$lng{'forumLastPost'}\n", "$lng{'forumModerator'}\n", "\n\n"; # Get board moderators $query = " SELECT userId, boardId, id, userName FROM ut_admins, ut_users WHERE ut_admins.userId = ut_users.id ORDER BY userId"; $sth = query($query); my $boardMods = $sth->fetchall_arrayref({}); $sth->finish; my %mods = (); foreach my $mod (@$boardMods) { $mods{$mod->{'boardId'}} .= ", $mod->{'userName'}"; } # Print categories/boards for my $cat (@$cats) { my $firstBoard = 1; for my $board (@$boards) { next if $board->{'categoryId'} != $cat->{'id'}; next if $board->{'hidden'}; next unless boardVisible($user, $board, undef, undef, 1); # Prepare display strings my $newPostNumStr; if ($user->{'defaultUser'}) { $newPostNumStr= "-"; } else { $newPostNumStr= $board->{'newPostNum'} ? $board->{'newPostNum'} : 0; } my $lastPostTimeStr = $board->{'lastPostTime'} > 0 ? formatTime($board->{'lastPostTime'}) : " - "; my $lastPostNameStr = $board->{'lastPostId'} ? "$board->{'lastPostName'}" : "unknown"; my $img = $board->{'newPostNum'} ? "board_n" : "board"; # If first board in category, print category if ($firstBoard) { print "\n", "$cat->{'title'}\n", "\n\n"; $firstBoard = 0; } # Print board print "\n", "\n", "$board->{'title'}"; print "
$board->{'shortDesc'}\n", if $cfg{'showShortDesc'} && $board->{'shortDesc'}; $mods{$board->{'id'}} =~ s/^, //isg; my $boardPostsTotal = $board->{'postNum'} + $board->{'postNumBak'}; print "$boardPostsTotal\n", "$newPostNumStr\n", "$lastPostTimeStr
", "by $lastPostNameStr\n", "$mods{$board->{'id'}} \n", "\n"; print "\n"; } } print tableEnd($user); # Get open polls if ($cfg{'poll'}) { $query = "SELECT * FROM ut_polls WHERE goPublic = 1 AND open = 1 ORDER BY startDate"; $sth = query($query); my $polls = $sth->fetchall_arrayref({}); $sth->finish; # Print polls table header print "
\n", tableStart($user, "$lng{'forumPoll'}", 5); # Print polls for my $poll (@$polls) { next unless boardVisible($user, $boards{$poll->{'boardId'}}, undef, undef, 0); my $startDate = formatDate($poll->{'startDate'}); my $closeDate = formatDate($poll->{'closeDate'}); print "", "\n", "", "$poll->{'title'}
\n", "$poll->{'shortDesc'}\n", "\n", "$poll->{'voteNum'} $lng{'forumPollVotes'}\n", "\n", "from $startDate
to $closeDate\n", "\n", "$lng{'forumPollBy'} $poll->{'starterName'}\n", "\n", } print "\n", "$lng{'forumPollList'} ...\n", tableEnd($user); } # Update online users stats updateOnlineUsers($user, $lng{'forum_show'}); my $pmCell = (!$user->{'defaultUser'} and $cfg{'pm'}) ? 1 : 0; my $favCell = (!$user->{'defaultUser'} and $cfg{'favorites'}) ? 1 : 0; my $onlineCell = $cfg{'usersOnline'} ? 1 : 0; my $cellWidth = ($pmCell + $favCell + $onlineCell) ? int(100/($pmCell + $favCell + $onlineCell)) : 100; my $row1 = ""; my $row2 = ""; # Private messages if ($pmCell) { $row1 = "\n" . "$lng{'forumPm'}\n"; $row2 = "" . "\n" . "$lng{'forumPmChk'}.
" . "$lng{'forumPmNew1'} $user->{'pmNew'} $lng{'forumPmNew2'}\n"; } # Favorites if ($favCell) { $row1 .= "\n" . "$lng{'forumFavorites'}\n"; $row2 .= "" . "\n" . "$lng{'forumFavChk'}.\n"; } # Online users if ($onlineCell) { my $onlineUserNum = ""; if ($cfg{'showOnlineUserNum'}) { my $activeTime = time() - $cfg{'inactiveTime'} * 60; $query = "SELECT COUNT(*) FROM ut_online WHERE lastOnTime > $activeTime"; $sth = query($query); $onlineUserNum = $sth->fetchrow_array(); $sth->finish; $onlineUserNum = "
$lng{'forumOnline'}: $onlineUserNum"; } $row1 .= "\n" . "$lng{'forumOnline'}\n"; $row2 .= "" . "\n" . "$lng{'forumOnlineChk'}.$onlineUserNum\n"; } if ($pmCell || $favCell || $onlineCell) { print "
\n", tableStart($user, undef, undef, "95%", ""), "\n", $row1, "\n", $row2, "\n", tableEnd($user); } # Print legend print "
", "\n", "
", "  $lng{'forumLegendNor'}
", "  $lng{'forumLegendNew'}", "

\n"; # Print admin bar if ($user->{'admin'}) { my @adminBar = ( "cfg_general.cgi", "$lng{'forumAdmGen'}", 1, "cfg_style.cgi", "$lng{'forumAdmStyle'}", 1, "user_admin.cgi", "$lng{'forumAdmUsers'}", 1, "board_admin.cgi", "$lng{'forumAdmBoards'}", 1, "categ_admin.cgi", "$lng{'forumAdmCatgs'}", 1 ); printAdminBar($user, "$lng{'adminBarTitle'}", "", \@adminBar); my @adminBar2 = ( "topic_admin.cgi", "$lng{'forumAdmTopics'}", 1, "poll_admin.cgi", "$lng{'forumAdmPolls'}", 1, "misc_admin.cgi", "$lng{'forumAdmMisc'}", 1, "forum_dump.cgi", "$lng{'forumAdmDump'}", 1, ); printAdminBar($user, "", "", \@adminBar2); } elsif ($user->{'moderator'} || $user->{'superMod'}) { my @adminBar = ( "poll_admin.cgi", "$lng{'forumAdmPolls'}", 1, ); printAdminBar($user, "$lng{'adminBarTitle'}", "", \@adminBar); } unless ($user->{'defaultUser'}) { my $ip = $ENV{'REMOTE_ADDR'}; my $realIp = $ENV{'HTTP_X_FORWARDED_FOR'}; $realIp = "" if (($realIp eq "unknown") or ($ip eq $realIp)); my $now = time(); $query = " UPDATE ut_users SET lastOnTime = $now, lastIp = '$ip', lastRealIp = '$realIp' WHERE id = $user->{'id'}"; $dbh->do($query) or dbError(); } # Print popup box if new PM comes print "\n" if (!$user->{'defaultUser'} && $user->{'pmNew'} && $user->{'pmPopup'} && $cfg{'pm'}); # Print footer printFooter();