#!/usr/bin/perl # MimerDesk # Web based groupware and eLearning environment # www.mimerdesk.org # # Copyright (C) 2001 Ionstream Ltd. # www.ionstream.fi # # 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, or (at your option) # any later version. # # This program is distributed with a hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #$Id: boards.html,v 1.38 2002/07/20 19:26:29 inf Exp $ #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: Message Boards # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Teemu Arina # # Modified by: Hannes Muurinen # # # #_________________________________________# # Begin ################################## use strict; use vars qw ($APPLICATION $ACTIVEGRP $admin_status $USER $IP $font %colors $trans $imagedir $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $attachments $dir %filepics %message_types %message_types_eng @message_types $MBOARDS $BOARDCONFIG $GROUPACTIVOR); use lib::MimerDesk; use Mail::Sendmail; use File::Copy; use File::Path qw(rmtree); use Text::Wrap qw(wrap $columns); $columns = 80; # Message handling sub add_new_topic; sub reply_message; sub delete_message; sub edit_message; sub create_message; sub check_owner; # Forum handling sub add_forum; sub edit_forum; sub remove_forum; # Monitoring sub monitor_forum; sub send_monitor_mail; sub html_generator; # General sub template_tulostus; sub drop_downs; sub get_post_date; sub boardmap; sub replace_timezone; sub type_generator; sub create_legend; sub get_uploads; sub deletefile; sub list_attachments; sub get_extension; # Generators - messages sub reply_generator; sub new_generator; sub edit_generator; # Generators - views sub thread_generator; sub topic_generator; sub forum_generator; # Generators - forums sub addforum_generator; sub editforum_generator; sub rmforum_generator; $APPLICATION = 'Communication - Forums'; $font = '"Arial, Helvetica, sans-serif"'; my %filepics = ( default => 'rf-default.gif', # Images # Sounds jpg => 'rf-image.gif', wav => 'rf-audio.gif', gif => 'rf-image.gif', au => 'rf-audio.gif', png => 'rf-image.gif', aiff => 'rf-audio.gif', pcx => 'rf-image.gif', aif => 'rf-audio.gif', bmp => 'rf-image.gif', snd => 'rf-audio.gif', tiff => 'rf-image.gif', raw => 'rf-audio.gif', tif => 'rf-image.gif', xm => 'rf-audio.gif', tga => 'rf-image.gif', s3m => 'rf-audio.gif', xpm => 'rf-image.gif', it => 'rf-audio.gif', psd => 'rf-ps.gif', midi => 'rf-midi.gif', cdr => 'rf-corel.gif', mid => 'rf-midi.gif', cfl => 'rf-corel.gif', mp3 => 'rf-mp3.gif', bpt => 'rf-corel.gif', pls => 'rf-mp3.gif', cmv => 'rf-corel.gif', rd3 => 'rf-corel.gif', shw => 'rf-corel.gif', # Documents # Sourcecode html => 'rf-webdoc.gif', c => 'rf-source.gif', htm => 'rf-webdoc.gif', pl => 'rf-source.gif', xml => 'rf-webdoc.gif', py => 'rf-source.gif', css => 'rf-webdoc.gif', java => 'rf-source.gif', pdf => 'rf-acrobat.gif', sh => 'rf-source.gif', sgml => 'rf-text.gif', jar => 'rf-source.gif', latex => 'rf-text.gif', hxx => 'rf-source.gif', tex => 'rf-text.gif', h => 'rf-source.gif', lyx => 'rf-text.gif', hpp => 'rf-source.gif', txt => 'rf-text.gif', cpp => 'rf-source.gif', faq => 'rf-text.gif', cxx => 'rf-source.gif', nfo => 'rf-text.gif', js => 'rf-source.gif', ps => 'rf-acrobat.gif', awk => 'rf-source.gif', doc => 'rf-doc.gif', cfm => 'rf-source.gif', rtf => 'rf-rtf.gif', asm => 'rf-source.gif', xls => 'rf-xls.gif', pm => 'rf-source.gif', ppt => 'rf-ppt.gif', pps => 'rf-ppt.gif', ksp => 'rf-xls.gif', swf => 'rf-flash.gif', # Packages # Video zip => 'rf-zip.gif', ram => 'rf-real.gif', rar => 'rf-zip.gif', ra => 'rf-real.gif', arj => 'rf-zip.gif', avi => 'rf-video.gif', gz => 'rf-zip.gif', mpg => 'rf-video.gif', tar => 'rf-zip.gif', mpeg => 'rf-video.gif', bz2 => 'rf-zip.gif', mov => 'rf-video.gif', ace => 'rf-zip.gif', vfw => 'rf-video.gif', tgz => 'rf-zip.gif', # Other exe => 'rf-app.gif', class => 'rf-app.gif', com => 'rf-app.gif', bat => 'rf-app.gif', ini => 'rf-ini.gif', cfg => 'rf-ini.gif', mmp => 'rf-visio.gif', vss => 'rf-visio.gif', vsd => 'rf-visio.gif', vsw => 'rf-visio.gif', plt => 'rf-autocad.gif', ); %colors = ( message => '#FFFFFF', topic => '#FFFFFF', sender => '#ECEEF2', date => '#E4EEF3', buttons => '#F7FAFB', thread => '#F7FAFB', columns => '#F7FAFB', category => '#CEDFE8', picbox => '#FFFFFF', ); @message_types = qw(smallnormal smallquestion smallconclusion smallidea smalllink smallplan smallpriority smallinfo); $BOARDCONFIG = 'boardconfig'; $MBOARDS = 'mboards'; # Ohjelma ################################## read_config('../config/mimerdesk.cfg'); initialize(); $imagedir = $config{'loc_pictures'}; $imagedir =~ s/([^\/]*)$//; $imagedir .= 'files'; $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $trans = lib::MimerDesk->new_gettext(program => 'forums',language => $config{'language'}); $APPLICATION = $trans->gettext('Communication - Forums'); $attachments = $config{'file_dir'}.'/forums'; %message_types_eng = ( smallconclusion => 'Solution', smallidea => 'Idea', smallnormal => 'Normal', smallinfo => 'Announcement', smalllink => 'Hyperlink', smallplan => 'Plan', smallpriority => 'Urgent', smallquestion => 'Question', smallfolder => 'Forum', ); foreach (keys %message_types_eng) { $message_types{$_} = $trans->gettext($message_types_eng{$_}); } if ($form->{'grouptool'} =~ /^\d+$/) { my ($test); lock_tables('READ', 'groupusers'); db_list("SELECT RIGHTS,USER FROM groupusers where USER = '$USER' and GID = '$form->{'grouptool'}'"); while (my $ref = $sth->fetchrow_hashref()) { $admin_status = $ref->{'RIGHTS'}; $GROUPACTIVOR = $ref->{'USER'}; } db_end(); unlock_tables(); if (!$GROUPACTIVOR) { lock_tables('READ', 'users'); db_list("SELECT flags FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {$admin_status = $ref->{'flags'};} db_end(); unlock_tables(); $dir = 'public'; } else { $BOARDCONFIG = "$form->{'grouptool'}_$BOARDCONFIG"; $MBOARDS = "$form->{'grouptool'}_$MBOARDS"; $dir = 'groups/'.$form->{'grouptool'}; mkdir "$attachments/$dir", 0700 or write_log("Cannot create directory $attachments/$dir. $!") unless -d "$attachments/$dir"; } } else { lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {$admin_status = $ref->{'flags'};} db_end(); unlock_tables(); $dir = 'public'; } # Create board and mid from topic form value if defined ($form->{'board'}, $form->{'mid'}) = split /\./, $form->{'topic'} if $form->{'topic'} =~ /^\d+\.\d+$/; unlink($form->{'fileupload'}) if $form->{'fileupload'} && !$form->{'upload'}; if ($form->{'quit'}) {redirect("$config{'loc_server'}$config{'bin_dir'}/index.html?ID=$form->{'ID'}&auth=$form->{'auth'}&quit=quit");} # Identify the page elsif ($admin_status =~ /M0/ && $form->{'mode'} && $form->{'board'} == 0) { if ($form->{'mode'} eq 'addforum') {add_forum();} elsif ($form->{'mode'} eq 'rmforum') {remove_forum();} elsif ($form->{'mode'} eq 'editforum') {edit_forum();} } elsif (($form->{'board'} =~ /^\d+$/ || $form->{'toboard'} =~ /^\d+$/)) { while ($form->{'filename','tiedostonimi'} =~ s/\.\./\./gm) {} $form->{'filename','tiedostonimi'} =~ s/^\.+//; if ($form->{'upload'}) { unless (-d "$config{'uploads'}/$USER") { mkdir "$config{'uploads'}/$USER", 0700 or warn "Cannot create directory $config{'uploads'}/$USER. $!"; } my $message; if ($form->{'deletefile'} =~ /^\d$/) { $message = sprintf($trans->gettext('File %s deleted'),deletefile($form->{'deletefile'})); } else { if (!rename($form->{'fileupload'}, "$config{'uploads'}/$USER/$form->{'fileupload','tiedostonimi'}")) {$message = $trans->gettext('You must select a file to upload!');} else {$message = sprintf($trans->gettext("File %s uploaded"), $form->{'fileupload','tiedostonimi'});} } $form->{'board'} = $form->{'toboard'}; if ($form->{'forumpage'} eq 'reply') { lock_tables('READ',$MBOARDS); db_list("select topic,thread_id from $MBOARDS where id = '$form->{'tomid'}' and forum = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) { $form->{'mid'} = $ref->{'thread_id'} || $form->{'tomid'}; } db_end(); unlock_tables(); template_tulostus("$config{'theme'}_replythread", $message, $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } elsif ($form->{'forumpage'} eq 'edit') { lock_tables('READ',$MBOARDS); db_list("select topic,thread_id from $MBOARDS where id = '$form->{'tomid'}' and forum = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) { $form->{'mid'} = $ref->{'thread_id'} || $form->{'tomid'}; } db_end(); unlock_tables(); template_tulostus("$config{'theme'}_editthread", $message, $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } else { template_tulostus("$config{'theme'}_newtopic", $message, $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } } if ($form->{'mid'} =~ /^\d+$/) { if ($form->{'command'} eq 'reply') {template_tulostus("$config{'theme'}_replythread");} elsif ($form->{'command'} eq 'del' && $admin_status =~ /M0/) {delete_message();} elsif ($form->{'command'} eq 'edit' && ($admin_status =~ /M0/ || check_owner($USER,$form->{'board'},$form->{'mid'}))) {template_tulostus("$config{'theme'}_editthread");} else {template_tulostus("$config{'theme'}_thread");} } elsif ($form->{'command'} eq 'ntopic') {template_tulostus("$config{'theme'}_newtopic");} elsif ($form->{'command'} eq 'monitor') {monitor_forum($form->{'board'}, $USER);} elsif ($form->{'post'} && $form->{'tomid'}) {reply_message($form->{'toboard'},$form->{'tomid'});} elsif ($form->{'post'}) {add_new_topic($form->{'toboard'});} elsif ($form->{'edit'} && $form->{'tomid'} && ($admin_status =~ /M0/ || check_owner($USER,$form->{'toboard'},$form->{'tomid'}))) {edit_message($form->{'toboard'},$form->{'tomid'});} else {template_tulostus("$config{'theme'}_topics");} } else {template_tulostus("$config{'theme'}_boards");} ############################## # Check owner of the message # ############################## sub check_owner { my ($sender); my ($user, $toboard,$tomid) = @_; lock_tables('READ',$MBOARDS); db_list("SELECT sender FROM $MBOARDS where forum = '$toboard' and id = '$tomid'"); while (my $ref = $sth->fetchrow_hashref()) {$sender = $ref->{'sender'};} db_end(); unlock_tables(); $user eq $sender ? return 1 : return; } ################# # Add new topic # ################# sub add_new_topic { my ($board_name,$topic,$attachment); my $toboard = shift; $form->{'board'} = $toboard; lock_tables('READ',$BOARDCONFIG); db_list("SELECT forum FROM $BOARDCONFIG where id = '$toboard'"); while (my $ref = $sth->fetchrow_hashref()) {$board_name = $ref->{'forum'};} db_end(); unlock_tables(); template_tulostus("$config{'theme'}_boards") if !$board_name; if (!$form->{'message'}) { template_tulostus( "$config{'theme'}_newtopic", $trans->gettext('You must specify a message!'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } elsif (!$form->{'subject'}) { template_tulostus( "$config{'theme'}_newtopic", $trans->gettext('You must specify a topic!'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } ($form->{'message'},$form->{'subject'}) = prepare_fordb($form->{'message'},$form->{'subject'}); lock_tables('READ',$MBOARDS); db_list("select topic from $MBOARDS where topic = '$form->{'subject'}' and forum = '$toboard'"); while (my $ref = $sth->fetchrow_hashref()) {$topic = $ref->{'topic'};} db_end(); unlock_tables(); if ($topic) { foreach ($form->{'message'},$form->{'subject'}) { s/\\\\/\\/g; s/\\\'/\'/g; } template_tulostus( "$config{'theme'}_newtopic", $trans->gettext('You might be double-posting your message! If not, change the subject.'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } my $postdate = time(); if(!(grep {$_ eq $form->{'msgtype'}} @message_types)) {$form->{'msgtype'} = $message_types[0];} lock_tables('WRITE',$MBOARDS); db_list("insert into $MBOARDS (forum,msg,postdate,topic,sender,type) values ('$toboard','$form->{'message'}','$postdate','$form->{'subject'}','$USER','$form->{'msgtype'}')"); db_list("select LAST_INSERT_ID() as id"); while (my $ref = $sth->fetchrow_hashref()) {$form->{'mid'} = $ref->{'id'};} db_end(); unlock_tables(); if ($form->{'uploads'}) { $attachment = "Attachments: \n"; mkdir "$attachments/$dir/$form->{'mid'}", 0700 or warn "Cannot create directory $attachments/$dir/$form->{'mid'}. $!"; opendir(DIR, "$config{'uploads'}/$USER") or write_log("$USER: Error opening dir $config{'uploads'}/$USER. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} $attachment .= "$_\n"; rename("$config{'uploads'}/$USER/$_", "$attachments/$dir/$form->{'mid'}/$_"); } closedir DIR; lock_tables('WRITE',$MBOARDS); db_update($MBOARDS,{rate => 1},"id = '$form->{'mid'}'"); unlock_tables(); } foreach ($form->{'message'},$form->{'subject'}) { s/\\\\/\\/g; s/\\\'/\'/g; } #mark the new message as unread lock_tables('WRITE','unreadMSG','users','groupusers'); my $unreadMessageQuery = "insert into unreadMSG (msgID,msgTable,user) select '$form->{'mid'}','$MBOARDS', users.nimi from users"; $unreadMessageQuery .= ",groupusers where users.nimi = groupusers.USER and groupusers.GID = '$form->{'grouptool'}'" if $GROUPACTIVOR; db_list($unreadMessageQuery); db_end(); unlock_tables(); send_monitor_mail($toboard,$postdate,$USER,$form->{'subject'},$form->{'message'},$form->{'msgtype'},$attachment); template_tulostus("$config{'theme'}_thread"); } ############################### # Start/stop monitoring forum # ############################### sub monitor_forum { my (@monitors,$forum); my ($board,$user) = @_; lock_tables('WRITE',$BOARDCONFIG); db_list("select monitors,forum from $BOARDCONFIG where id = '$board'"); while (my $ref = $sth->fetchrow_hashref()) { @monitors = split /,/, $ref->{'monitors'}; $forum = $ref->{'forum'}; } db_end(); if (!(grep {$_ eq $user} @monitors)) { push @monitors, $user; my $monitors = join ",", @monitors; db_list("update $BOARDCONFIG set monitors = '$monitors' where id = '$board'"); db_end(); write_log("$USER started to monitor forum $forum",'notify'); } else { my $monitors = join ",", grep {$_ ne $user} @monitors; db_list("update $BOARDCONFIG set monitors = '$monitors' where id = '$board'"); db_end(); write_log("$USER stopped monitoring forum $forum",'notify'); } unlock_tables(); template_tulostus("$config{'theme'}_topics"); } ############################ # Send message with e-mail # ############################ sub send_monitor_mail { my (%mail,@monitors,$email,$info,$groupname); my ($board,$date,$author,$subject,$message,$type,$attachment) = @_; $message = itag_remover($message); my $posted = get_post_date($date); lock_tables('READ','users','groups',$BOARDCONFIG); db_list("select info from users where nimi = '$author'"); while (my $ref = $sth->fetchrow_hashref()) {$author = $ref->{'info'};} db_end(); if ($form->{'grouptool'}) { db_list("select GRPNAME from groups where GID = '$form->{'grouptool'}'"); while (my $ref = $sth->fetchrow_hashref()) {$groupname = $ref->{'GRPNAME'};} db_end(); } db_list("select monitors,forum from $BOARDCONFIG where id = '$board'"); while (my $ref = $sth->fetchrow_hashref()) { $board = $ref->{'forum'}; @monitors = split /,/, $ref->{'monitors'}; } db_end(); foreach (@monitors) { # Tweak this! db_list("select email,info from users where nimi = '$_'"); while (my $ref = $sth->fetchrow_hashref()) { $email = $ref->{'email'}; $info = $ref->{'info'}; } db_end(); next if $email !~ /\@.+\..+/; $Mail::Sendmail::mailcfg{'retries'} = 0; $mail{'From'} = "MimerDesk <$config{'monitor_mail'}>"; $mail{'To'} = "$info <$email>"; my $server = $config{'mail_server'}; $mail{'Smtp'} = $server if $server; $mail{'subject'} = "[$board] - $subject"; $mail{'message'} = "Read and respond to this message at:\n$config{'loc_server'}$config{'bin_dir'}/index.html\n\n"; $mail{'message'} .= "Date: $posted\n"; $mail{'message'} .= "Author: $author\n"; $mail{'message'} .= "Type: $message_types_eng{$type}\n"; $mail{'message'} .= "Group: $groupname\n" if $groupname; $mail{'message'} .= "Subject: $subject\n\n$message\n\n$attachment\n\n"; $mail{'message'} .= "_________________________________________________________________________\n"; $mail{'message'} .= "You are receiving this e-mail because you have turned forum monitoring on.\n"; $mail{'message'} .= "To stop monitoring this forum, login to MimerDesk and select Stop\nmonitoring on the messageboard.\n"; if (sendmail(%mail)) {} else {write_log("Error sending message: $Mail::Sendmail::error", 'error');} } unlock_tables(); } ################# # Reply message # ################# sub reply_message { my ($board_name,$topic,$filemid,$attachment); my $toboard = shift; my $tomid = shift; $form->{'board'} = $toboard; lock_tables('READ',$BOARDCONFIG,$MBOARDS); db_list("SELECT forum FROM $BOARDCONFIG where id = '$toboard'"); while (my $ref = $sth->fetchrow_hashref()) {$board_name = $ref->{'forum'};} db_end(); db_list("select topic,thread_id from $MBOARDS where id = '$tomid' and forum = '$toboard'"); while (my $ref = $sth->fetchrow_hashref()) { $topic = $ref->{'topic'}; $form->{'mid'} = $ref->{'thread_id'} || $tomid; } db_end(); unlock_tables(); if (!$form->{'message'}) { template_tulostus( "$config{'theme'}_replythread", $trans->gettext('You must specify a message!'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } elsif (!$form->{'subject'}) { template_tulostus( "$config{'theme'}_replythread", $trans->gettext('You must specify a topic!'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } template_tulostus("$config{'theme'}_boards") if !$topic || !$board_name; $form->{'message'} =~ s/\[quote\]\n/\[quote\]/gms; $form->{'message'} =~ s/\n\[\/quote\]/\[\/quote\]/gms; ($form->{'message'},$form->{'subject'}) = prepare_fordb($form->{'message'},$form->{'subject'}); my $postdate = time(); if(!(grep {$_ eq $form->{'msgtype'}} @message_types)) {$form->{'msgtype'} = $message_types[0];} lock_tables('WRITE',$MBOARDS); db_list("insert into $MBOARDS (forum,msg,postdate,topic,sender,thread_id,type,rate) values ('$toboard','$form->{'message'}','$postdate','$form->{'subject'}','$USER', '$form->{'mid'}','$form->{'msgtype'}','0')"); db_end(); db_list("select LAST_INSERT_ID() as id"); while (my $ref = $sth->fetchrow_hashref()) {$filemid = $ref->{'id'};} db_end(); unlock_tables(); if ($form->{'uploads'}) { $attachment = "Attachments: \n"; mkdir "$attachments/$dir/$filemid", 0700 or warn "Cannot create directory $attachments/$dir/$filemid. $!"; opendir(DIR, "$config{'uploads'}/$USER") or write_log("$USER: Error opening dir $config{'uploads'}/$USER. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} $attachment .= "$_\n"; rename("$config{'uploads'}/$USER/$_", "$attachments/$dir/$filemid/$_"); } closedir DIR; lock_tables('WRITE',$MBOARDS); db_update($MBOARDS,{rate => 1},"id = '$filemid'"); unlock_tables(); } foreach ($form->{'message'},$form->{'subject'}) { s/\\\\/\\/g; s/\\\'/\'/g; } #mark the new message as unread lock_tables('WRITE','unreadMSG','users','groupusers'); my $unreadMessageQuery = "insert into unreadMSG (msgID,msgTable,user) select '$filemid','$MBOARDS', users.nimi from users"; $unreadMessageQuery .= ",groupusers where users.nimi = groupusers.USER and groupusers.GID = '$form->{'grouptool'}'" if $GROUPACTIVOR; db_list($unreadMessageQuery); db_end(); unlock_tables(); send_monitor_mail($toboard,$postdate,$USER,$form->{'subject'},$form->{'message'},$form->{'msgtype'},$attachment); template_tulostus("$config{'theme'}_thread"); } ################ # Edit message # ################ sub edit_message { my ($board_name,$topic); my $toboard = shift; my $tomid = shift; $form->{'board'} = $toboard; lock_tables('READ',$BOARDCONFIG,$MBOARDS); db_list("SELECT forum FROM $BOARDCONFIG where id = '$toboard'"); while (my $ref = $sth->fetchrow_hashref()) {$board_name = $ref->{'forum'};} db_end(); db_list("select topic,thread_id from $MBOARDS where id = '$tomid' and forum = '$toboard'"); while (my $ref = $sth->fetchrow_hashref()) { $topic = $ref->{'topic'}; $form->{'mid'} = $ref->{'thread_id'} || $tomid; } db_end(); unlock_tables(); if (!$form->{'message'}) { template_tulostus( "$config{'theme'}_editthread", $trans->gettext('You must specify a message!'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } elsif (!$form->{'subject'}) { template_tulostus( "$config{'theme'}_editthread", $trans->gettext('You must specify a topic!'), $form->{'subject'}, $form->{'message'}, $form->{'msgtype'} ); } template_tulostus("$config{'theme'}_boards") if !$topic || !$board_name; ($form->{'message'},$form->{'subject'}) = prepare_fordb($form->{'message'},$form->{'subject'}); lock_tables('WRITE',$MBOARDS); db_list("update $MBOARDS set msg = '$form->{'message'}', topic = '$form->{'subject'}', rate = '0', type= '$form->{'msgtype'}' where id = '$tomid'"); db_end(); unlock_tables(); if ($form->{'uploads'}) { mkdir "$attachments/$dir/$tomid", 0700 or write_log("Cannot create directory $attachments/$dir/$tomid. $!") unless -d "$attachments/$dir/$tomid"; unlink <$attachments/$dir/$tomid/*>; opendir(DIR, "$config{'uploads'}/$USER") or write_log("$USER: Error opening dir $config{'uploads'}/$USER. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} rename("$config{'uploads'}/$USER/$_", "$attachments/$dir/$tomid/$_"); } closedir DIR; lock_tables('WRITE',$MBOARDS); db_update($MBOARDS,{rate => 1},"id = '$tomid'"); unlock_tables(); } else { mkdir "$attachments/$dir/$tomid", 0700 or write_log("Cannot create directory $attachments/$dir/$tomid. $!") unless -d "$attachments/$dir/$tomid"; unlink <$attachments/$dir/$tomid/*>; } template_tulostus("$config{'theme'}_thread"); } ################## # Delete message # ################## sub delete_message { my ($board_name, $topic,$remove_all,@ids); my $tomid = $form->{'mid'}; lock_tables('WRITE',$MBOARDS,'unreadMSG'); db_list("select thread_id from $MBOARDS where id = '$form->{'mid'}' and forum = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) { $form->{'mid'} = $ref->{'thread_id'} || $form->{'mid'}; if (!$ref->{'thread_id'}) {$remove_all = 1;} } db_end(); db_list("SELECT forum FROM $MBOARDS where id = '$tomid' and forum = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) {$board_name = $ref->{'forum'};} db_end(); if ($board_name) { db_delete($MBOARDS, "id = '$tomid' and forum = '$form->{'board'}'"); #delete also the records saying this is an unread message: db_delete('unreadMSG', "msgID = '$tomid' and msgTable = '$MBOARDS'"); unlock_tables(); rmtree("$attachments/$dir/$tomid/"); write_log("$USER removed message number $tomid", 'notify'); } if ($remove_all) { db_list("select id from $MBOARDS where thread_id = '$tomid'"); while (my $ref = $sth->fetchrow_hashref()) { rmtree("$attachments/$dir/$ref->{'id'}/"); push @ids, $ref->{'id'}; } db_end(); db_delete($MBOARDS, "thread_id = '$tomid'"); # is there an easy way to delete the unread message table? perhaps should add thread there too foreach (@ids) { db_delete('unreadMSG', "msgID = '$_' and msgTable = '$MBOARDS'"); } unlock_tables(); template_tulostus("$config{'theme'}_topics"); } template_tulostus("$config{'theme'}_thread"); } #"""""""""""""""# # Edit forum # #_______________# sub edit_forum { my($message, $ref, $rivi, $forum); $form->{'forum_name'} =~ s/<.*?>//gm; $form->{'forum_desc'} =~ s/<.*?>//gm; $form->{'category_name'} =~ s/<.*?>//gm; $form->{'category_name'} = substr $form->{'category_name'}, 0, 35; $form->{'forum_name'} = substr $form->{'forum_name'}, 0, 35; ($form->{'category'}, $form->{'forums'}, $form->{'category_name'}, $form->{'forum_name'}, $form->{'forum_desc'}) = prepare_fordb($form->{'category'}, $form->{'forums'}, $form->{'category_name'}, $form->{'forum_name'}, $form->{'forum_desc'}); if ($form->{'edit_forum'}) { if (length($form->{'category_name'}) < 3) {$message = $trans->gettext("You must specify a longer category name!");} elsif (length($form->{'forum_name'}) < 3) {$message = $trans->gettext("You must specify a longer forum name!");} elsif (length($form->{'forum_desc'}) < 5) {$message = $trans->gettext("You must specify a longer forum description!");} else { if ($form->{'forums'} eq '') {$message = $trans->gettext("ERROR: You must select a forum before trying to edit anything!");} else { lock_tables('READ', $BOARDCONFIG); db_list("SELECT forum FROM $BOARDCONFIG where id = '$form->{'forums'}'"); $ref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); if (keys %$ref > 0) { $forum = $ref->{'forum'}; lock_tables('READ', $BOARDCONFIG); db_list("SELECT forum,id FROM $BOARDCONFIG where forum = '$form->{'forum_name'}'"); $ref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); if (keys %$ref > 0 && $ref->{'id'} ne $form->{'forums'}) {$message = "ERROR: forum already exists.";} else { lock_tables('WRITE', $BOARDCONFIG); db_list("update $BOARDCONFIG set category = '$form->{'category_name'}', description = '$form->{'forum_desc'}', forum = '$form->{'forum_name'}' where id = '$form->{'forums'}'"); db_end(); unlock_tables(); $message = sprintf($trans->gettext("Forum %s has been successfully edited."),tag('I').$forum.endtag('I')); write_log("$USER edited forum named $forum", 'notify'); template_tulostus("$config{'theme'}_boards"); } } else { write_log("$USER tried to edit unknown forum $forum!", 'warning'); print_header(); print $trans->gettext("Don't even try it!"); exit; } } } } lock_tables('READ', $BOARDCONFIG); db_list("SELECT forum,category,description,id FROM $BOARDCONFIG group by category,forum"); while (my $ref = $sth->fetchrow_hashref()) { if ($ref->{'id'} eq $form->{'forums'}) { $rivi .= "\n"; $form->{'forum_desc'} = $ref->{'description'}; $form->{'forum_name'} = $ref->{'forum'}; $form->{'category_name'} = $ref->{'category'}; } else {$rivi .= "\n";} } db_end(); unlock_tables(); template_tulostus("$config{'theme'}_editforum", $message, $rivi); } #"""""""""""""""""""# # Remove a forum # #___________________# sub remove_forum { my($message, $ref, $rivi, $keys); if ($form->{'remove'}) { ($form->{'forums'}) = prepare_fordb($form->{'forums'}); if ($form->{'forums'} eq '') {$message = "ERROR: You must select a forum before trying to remove anything!";} else { lock_tables('READ', $BOARDCONFIG); db_list("SELECT forum FROM $BOARDCONFIG where id = '$form->{'forums'}'"); while (my $ref = $sth->fetchrow_hashref()) {$keys = $ref->{'forum'};} db_end(); unlock_tables(); if ($keys) { lock_tables('WRITE', $BOARDCONFIG, $MBOARDS); db_delete("$BOARDCONFIG", "id = '$form->{'forums'}'"); db_delete("$MBOARDS", "forum = '$form->{'forums'}'"); unlock_tables(); $message = sprintf($trans->gettext("Forum %s has been successfully removed"),tag('I').$keys.endtag('I')); write_log("$USER removed forum named $keys", 'notify'); template_tulostus("$config{'theme'}_boards"); } else { write_log("$USER tried to remove unknown forum id $form->{'forums'}!", 'warning'); print_header(); print $trans->gettext("Don't even try it!"); exit; } } } lock_tables('READ', $BOARDCONFIG); db_list("SELECT forum,id,category FROM $BOARDCONFIG group by category,forum"); while (my $ref = $sth->fetchrow_hashref()) {$rivi .= "\n";} db_end(); unlock_tables(); template_tulostus("$config{'theme'}_rmforum", $message, $rivi); } #""""""""""""""""# # Add a forum # #________________# sub add_forum { my($message, $categories, $old, $category); $form->{'category_name'} =~ s/<.*?>//gm; $form->{'forum_name'} =~ s/<.*?>//gm; $form->{'forum_desc'} =~ s/<.*?>//gm; $form->{'category_name'} = substr $form->{'category_name'}, 0, 35; $form->{'forum_name'} = substr $form->{'forum_name'}, 0, 35; my $test = $form->{'forum_name'}; if ($form->{'forum_add'}) { if ($form->{'category'} =~ /^\d+$/) { lock_tables('READ', $BOARDCONFIG); db_list("SELECT category FROM $BOARDCONFIG where id = '$form->{'category'}'"); while (my $ref = $sth->fetchrow_hashref()) {$category = $ref->{'category'};} db_end(); unlock_tables(); } else {$category = $form->{'category_name'};} my $test = $category; ($category, $form->{'forum_name'}, $form->{'forum_desc'}, $form->{'category'}) = prepare_fordb($category, $form->{'forum_name'}, $form->{'forum_desc'}, $form->{'category'}); if (length($category) < 3) {$message = $trans->gettext("You must specify a longer category name!");} elsif (length($form->{'forum_name'}) < 3) {$message = $trans->gettext("You must specify a longer forum name!");} elsif (length($form->{'forum_desc'}) < 5) {$message = $trans->gettext("You must specify a longer forum description!");} else { $form->{'forum_name'} =~ s/"//gm; lock_tables('READ', $BOARDCONFIG); db_list("SELECT forum FROM $BOARDCONFIG where forum = '$form->{'forum_name'}'"); $ref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); if (keys %$ref > 0) {$message = sprintf($trans->gettext("ERROR: Forum %s already exists."),$test);} else { lock_tables('WRITE', $BOARDCONFIG); my %specs = ( category => $category, forum => $form->{'forum_name'}, description => $form->{'forum_desc'}, moderator => 'system' ); db_insert("$BOARDCONFIG", \%specs); unlock_tables(); $message = sprintf($trans->gettext("Forum %s has been successfully added."),tagged('i',{content => $test})); write_log("$USER added forum named $test", 'notify'); template_tulostus("$config{'theme'}_boards"); } } } lock_tables('WRITE', $BOARDCONFIG); db_list("SELECT DISTINCT category,id FROM $BOARDCONFIG order by category"); while (my $ref = $sth->fetchrow_hashref()) { next if $old eq $ref->{'category'}; $categories .= qq[\n]; $old = $ref->{'category'}; } db_end(); unlock_tables(); template_tulostus("$config{'theme'}_addforum", $message, $categories); } ############################### # Lue template ja tulosta se # ############################### sub template_tulostus { my (@categories,$gen,$stuff,$ref,$fulltemplate,$template); $template = shift; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; if ($GROUPACTIVOR) {$fulltemplate = create_buttons($fulltemplate, 'Group', 'Forums', $form);} else {$fulltemplate = create_buttons($fulltemplate, 'Communication', 'Forums', $form);} $ref = get_template('js_doClock', 'js_help', 'js_forums', 'js_gotosite'); my $javascripts = $ref->{'js_doClock'}.$ref->{'js_help'}.$ref->{'js_forums'}.$ref->{'js_gotosite'}; $fulltemplate =~ s/<>/$javascripts/m; $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/m; if ($template eq "$config{'theme'}_boards") {$fulltemplate = forum_generator($fulltemplate);} elsif ($template eq "$config{'theme'}_topics") {$fulltemplate = topic_generator($fulltemplate);} elsif ($template eq "$config{'theme'}_thread") {$fulltemplate = thread_generator($fulltemplate);} elsif ($template eq "$config{'theme'}_newtopic") {$fulltemplate = new_generator($fulltemplate,$_[0],$_[1],$_[2],$_[3]);} elsif ($template eq "$config{'theme'}_addforum") {$fulltemplate = addforum_generator($fulltemplate,$_[0],$_[1]);} elsif ($template eq "$config{'theme'}_rmforum") {$fulltemplate = rmforum_generator($fulltemplate,$_[0],$_[1]);} elsif ($template eq "$config{'theme'}_editforum") {$fulltemplate = editforum_generator($fulltemplate,$_[0],$_[1]);} elsif ($template eq "$config{'theme'}_replythread") {$fulltemplate = reply_generator($fulltemplate,$_[0],$_[1],$_[2],$_[3]);} elsif ($template eq "$config{'theme'}_editthread") {$fulltemplate = edit_generator($fulltemplate,$_[0],$_[1],$_[2],$_[3]);} $fulltemplate = drop_downs($fulltemplate); $fulltemplate = boardmap($fulltemplate); $fulltemplate =~ s/<>/$form->{'board'}/mg; $fulltemplate =~ s/<>/$form->{'mid'}/mg; $fulltemplate =~ s/<>/$form->{'mid'}/mg; $fulltemplate =~ s/<>/$form->{'grouptool'}/mg; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } ####################### # Generate drop-downs # ####################### sub drop_downs { my ($gen,$lastcat); my $fulltemplate = shift; lock_tables('READ',$BOARDCONFIG,$MBOARDS); db_list("SELECT category,id,forum FROM $BOARDCONFIG where moderator = 'system' order by category, forum"); while (my $ref = $sth->fetchrow_hashref()) { ($ref->{'category'},$ref->{'forum'}) = html_escape($ref->{'category'},$ref->{'forum'}); if ($lastcat ne $ref->{'category'}) { $gen .= qq[\n]; $gen .= qq[\n]; } $lastcat = $ref->{'category'}; $gen .= qq[\n]; } db_end(); $gen .= qq[\n]; $fulltemplate =~ s/<>/$gen/m; $gen = ''; db_list("SELECT id,topic FROM $MBOARDS where forum = '$form->{'board'}' and thread_id is NULL order by postdate DESC"); while (my $ref = $sth->fetchrow_hashref()) { ($ref->{'topic'}) = html_escape($ref->{'topic'}); $gen .= qq[\n]; } db_end(); unlock_tables(); $fulltemplate =~ s/<>/$gen/; return $fulltemplate; } ################# # Get post date # ################# sub get_post_date { my ($min,$h,$mon,$day,$year); my $postdate = shift; if (!$postdate) {$postdate = "n/a";} else { my (undef,$min,$h,$day,$mon,$year,undef,undef,undef) = utc_epoch2date($postdate); $postdate = "$year/$mon/$day $h:$min"; } return $postdate; } ############### # Get uploads # ############### sub get_uploads { my ($uploads,$i,$size, $myext, $filepic); $uploads = tag('br'). starttable(width => '80%', cellspacing => 2); opendir(DIR, "$config{'uploads'}/$USER") or write_log("$USER: Error opening dir $config{'uploads'}/$USER. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} $myext = get_extension($_); if ($filepics{$myext}) {$filepic = $filepics{$myext};} else {$filepic = $filepics{'default'};} $i++; $size = -s "$config{'uploads'}/$USER/$_"; $uploads .= startrow(). column(class => 'blackTitle',content => "$i. ".image(src => "$imagedir/$filepic")). column(class => 'content',content => $_). column(class => 'content',content => $trans->gettext('Size: ').human_readable($size)). column(class => 'content',align => 'right', content => tagged('a',{href => "javascript:deleteFile($i)", content => image(src => "$config{'loc_pictures'}/delete.gif")})). endrow(); } closedir DIR; $uploads .= endtable().hiddenfield('uploads', $i).tag('br'); $uploads = undef if !$i; return $uploads; } #################### # List attachments # #################### sub list_attachments { my ($mid,$uploads,$size,$i,$myext, $filepic); $mid = shift; $uploads = tag('br').tag('br'). hrline(width => '98%'). starttable(width => '98%', cellspacing => 2, align => 'center'); opendir(DIR, "$attachments/$dir/$mid") or write_log("$USER: Error opening dir $attachments/$dir/$mid. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} $myext = get_extension($_); if ($filepics{$myext}) {$filepic = $filepics{$myext};} else {$filepic = $filepics{'default'};} $i++; $size = -s "$attachments/$dir/$mid/$_"; $uploads .= startrow(). column(class => 'content',content => tagged('b', {content => "$i. "}). image(src => "$imagedir/$filepic").' '.$_). column(class => 'content',content => 'Size: '.human_readable($size)); unless ($myext =~ /^(png|gif|jpeg|jpg|swf|html|txt|doc|xls|css|pdf|xml)$/) { $uploads .= column(class => 'content',align => 'right', content => tagged('a',{href => "boarddownload.html?ID=$form->{'ID'}&auth=$form->{'auth'}&mid=$mid&grouptool=$form->{'grouptool'}&file=$i&view=1", content => $trans->gettext('View')}).' '. tagged('a',{href => "boarddownload.html?ID=$form->{'ID'}&auth=$form->{'auth'}&mid=$mid&grouptool=$form->{'grouptool'}&file=$i", content => $trans->gettext('Download')})); } elsif ($myext eq 'mp3') { $uploads .= column(class => 'content',align => 'right', content => tagged('a',{href => "boarddownload.html?ID=$form->{'ID'}&auth=$form->{'auth'}&mid=$mid&grouptool=$form->{'grouptool'}&file=$i&stream=1", content => $trans->gettext('Stream')}).' '. tagged('a',{href => "boarddownload.html?ID=$form->{'ID'}&auth=$form->{'auth'}&mid=$mid&grouptool=$form->{'grouptool'}&file=$i", content => $trans->gettext('Download')})); } else { $uploads .= column(class => 'content',align => 'right', content => tagged('a',{href => "boarddownload.html?ID=$form->{'ID'}&auth=$form->{'auth'}&mid=$mid&grouptool=$form->{'grouptool'}&file=$i&view=1",target => '_blank', content => $trans->gettext('View')}).' '. tagged('a',{href => "boarddownload.html?ID=$form->{'ID'}&auth=$form->{'auth'}&mid=$mid&grouptool=$form->{'grouptool'}&file=$i", content => $trans->gettext('Download')})); } $uploads .= endrow(); } closedir DIR; $uploads .= endtable(); $uploads = undef if !$i; return $uploads; } ######################### # Get file extension # ######################### sub get_extension { my ($file) = @_; my @temppi; @temppi = split(/\./, $file); return lc $temppi[@temppi-1]; } ##################### # Delete attachment # ##################### sub deletefile { my ($uploads,$i,$size); my $filetodelete = shift; opendir(DIR, "$config{'uploads'}/$USER") or write_log("$USER: Error opening dir $config{'uploads'}/$USER. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} $i++; if ($i == $filetodelete) { closedir DIR; unlink("$config{'uploads'}/$USER/$_"); return $_; } } closedir DIR; return; } ###################### # Generate add forum # ###################### sub addforum_generator { my ($fulltemplate, $message, $categories) = @_; $fulltemplate =~ s/<>/$message/m; $fulltemplate =~ s/<>/$categories/m; $fulltemplate =~ s/<>/$form->{'category_name'}/m; $fulltemplate =~ s/<>/$form->{'forum_name'}/m; $fulltemplate =~ s/<>/$form->{'forum_desc'}/m; return $fulltemplate; } ####################### # Generate edit forum # ####################### sub editforum_generator { my ($fulltemplate, $message, $categories) = @_; $fulltemplate =~ s/<>/$message/m; $fulltemplate =~ s/<>/$categories/m; $fulltemplate =~ s/<>/$form->{'category_name'}/m; $fulltemplate =~ s/<>/$form->{'forum_name'}/m; $fulltemplate =~ s/<>/$form->{'forum_desc'}/m; return $fulltemplate; } ######################### # Generate remove forum # ######################### sub rmforum_generator { my ($fulltemplate, $message, $categories) = @_; $fulltemplate =~ s/<>/$message/m; $fulltemplate =~ s/<>/$categories/m; return $fulltemplate; } ################### # Generate thread # ################### # # 1. Display thread # 2. Display path to thread sub thread_generator { my ($gen,$type,@thread,$count_topics,$a_sender,$postdate,$thread_name,$id,$sender,$topic,$message, $buttons,$typed,$attachment); my $fulltemplate = shift; my $n = 1; my @msgidlist; lock_tables('READ',$MBOARDS,'users'); db_list("SELECT $MBOARDS.postdate,$MBOARDS.type,$MBOARDS.rate,$MBOARDS.topic,$MBOARDS.id,$MBOARDS.sender,$MBOARDS.topic,$MBOARDS.msg,users.info FROM $MBOARDS,users where $MBOARDS.forum = '$form->{'board'}' and $MBOARDS.id = '$form->{'mid'}' and $MBOARDS.sender = users.nimi"); while (my $ref = $sth->fetchrow_hashref()) {push @thread, $ref;} db_end(); unlock_tables(); foreach my $ref (@thread) { $attachment = undef; $postdate = $ref->{'postdate'}; $thread_name = $ref->{'topic'}; $id = $ref->{'id'}; $sender = $ref->{'info'}; $a_sender = $ref->{'sender'}; $typed = $ref->{'type'}; $topic = $ref->{'topic'}; $attachment = list_attachments($id) if $ref->{'rate'}; $message = $ref->{'msg'}; ($thread_name,$topic,$message) = html_escape($thread_name,$topic,$message); $message = create_message($message); $message .= $attachment; push @msgidlist, $ref->{'id'}; } $sender = tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$a_sender", content => $sender}); $fulltemplate =~ s/<>/$thread_name/m; $gen .= html_generator("start","category=$thread_name 4","end"); $postdate = get_post_date($postdate); $gen .= html_generator( "$form->{'board'}", "$id", "start", "postdate=$postdate","picbox=$typed", "topic2=$topic","buttons=|nodelete|$a_sender", "sender2=$sender","message=$message","end" ); @thread = (); lock_tables('READ',$MBOARDS,'users'); db_list("SELECT $MBOARDS.postdate,$MBOARDS.type,$MBOARDS.topic,$MBOARDS.rate,$MBOARDS.id,$MBOARDS.sender,$MBOARDS.topic,$MBOARDS.msg,users.info FROM $MBOARDS,users where $MBOARDS.thread_id = '$form->{'mid'}' and $MBOARDS.sender = users.nimi order by postdate"); while (my $ref = $sth->fetchrow_hashref()) {push @thread, $ref;} db_end(); unlock_tables(); foreach my $ref (@thread) { $attachment = undef; $n++; $postdate = $ref->{'postdate'}; $postdate = get_post_date($postdate); ($ref->{'topic'},$ref->{'msg'}) = html_escape($ref->{'topic'},$ref->{'msg'}); $ref->{'msg'} = create_message($ref->{'msg'}); $attachment = list_attachments($ref->{'id'}) if $ref->{'rate'}; $ref->{'msg'} .= $attachment; $ref->{'info'} = tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'sender'}", content => $ref->{'info'}}); $gen .= html_generator( "$form->{'board'}", "$ref->{'id'}", "start", "postdate=$postdate", "picbox=$ref->{'type'}", "topic2=$ref->{'topic'}","buttons=$ref->{'sender'}","sender2=$ref->{'info'}","message=$ref->{'msg'}","end" ); push @msgidlist, $ref->{'id'}; } lock_tables('WRITE','unreadMSG', $MBOARDS); my $msg_idlist = join ",", @msgidlist; $msg_idlist = '('.$msg_idlist.')'; db_list("update $MBOARDS set timesread = (timesread+1) where id in $msg_idlist") if $form->{'record'}; db_delete('unreadMSG',"user='$USER' and msgTable='$MBOARDS' and msgID in $msg_idlist"); db_end(); unlock_tables(); $gen .= html_generator("start","category=$thread_name 4","end"); if ($admin_status =~ /M0/) { $buttons .= qq[]; $buttons .= tagged('a',{href => "boards.html?board=$form->{'board'}&mid=$id&auth=$form->{'auth'}&ID=$form->{'ID'}&command=del&grouptool=$form->{'grouptool'}", onClick => qq[return confirm('].$trans->gettext("Do you really want to delete all messages in the current thread?").qq[');], content => image(src => "$config{'loc_pictures'}/deletethread.gif", alt => $trans->gettext('Delete thread') )}); } $fulltemplate = create_legend($fulltemplate); $fulltemplate =~ s/<>/$buttons/m; $fulltemplate =~ s/<>/$gen/m; $fulltemplate =~ s/<>/$n/m; return $fulltemplate; } ################## # Create message # ################## sub create_message { my $message = shift; my @message = split /\n/, $message; $message = join "
", @message; $message = urlify($message); $message = itag_replacer($message); return $message; } ################## # Generate reply # ################## sub reply_generator { my ($add,$message,$thread_name,$sender,$tomid, $postdate); my $fulltemplate = shift; if ($_[0]) { $form->{'mid'} = $form->{'tomid'} if $form->{'tomid'}; lock_tables('READ',$MBOARDS,'users'); db_list("SELECT $MBOARDS.topic,$MBOARDS.postdate,$MBOARDS.msg,$MBOARDS.thread_id,users.info FROM $MBOARDS,users where $MBOARDS.forum = '$form->{'board'}' and $MBOARDS.id = '$form->{'mid'}' and $MBOARDS.sender = users.nimi"); while (my $ref = $sth->fetchrow_hashref()) { $thread_name = $ref->{'topic'}; $message = $ref->{'msg'}; $postdate = get_post_date($ref->{'postdate'}); $sender = $ref->{'info'}; $tomid = $ref->{'thread_id'} || $form->{'mid'}; ($thread_name, $message) = html_escape($thread_name, $message); } db_end(); unlock_tables(); my $orig_message = create_message($message); $fulltemplate =~ s/<>/$orig_message/m; $fulltemplate =~ s/<>/$thread_name/m; $fulltemplate =~ s/<>/$sender/m; $fulltemplate =~ s/<>/$postdate/m; $fulltemplate =~ s/<>/$tomid/mg; $fulltemplate =~ s/<>/$thread_name/mg; $fulltemplate =~ s/<>/$_[0]/m; $fulltemplate =~ s/<>/$_[1]/m; $fulltemplate =~ s/<>/$_[2]/m; $fulltemplate = type_generator($fulltemplate,$_[3]); } else { lock_tables('READ',$MBOARDS,'users'); db_list("SELECT $MBOARDS.topic,$MBOARDS.postdate,$MBOARDS.msg,$MBOARDS.thread_id,users.info FROM $MBOARDS,users where $MBOARDS.forum = '$form->{'board'}' and $MBOARDS.id = '$form->{'mid'}' and $MBOARDS.sender = users.nimi"); while (my $ref = $sth->fetchrow_hashref()) { $thread_name = $ref->{'topic'}; $message = $ref->{'msg'}; $postdate = get_post_date($ref->{'postdate'}); $sender = $ref->{'info'}; $tomid = $ref->{'thread_id'} || $form->{'mid'}; ($thread_name, $message) = html_escape($thread_name, $message); } db_end(); unlock_tables(); if (-d "$config{'uploads'}/$USER") {unlink <$config{'uploads'}/$USER/*>;} my $orig_message = create_message($message); $message =~ s/ .+?\://mis; $message =~ s/\[QUOTE\].+?\[\/QUOTE\]//gmis; $fulltemplate = type_generator($fulltemplate); $fulltemplate =~ s/<>/$orig_message/m; $fulltemplate =~ s/<>/$thread_name/m; $fulltemplate =~ s/<>/$sender/m; $fulltemplate =~ s/<>/$postdate/m; $fulltemplate =~ s/<>//m; $fulltemplate =~ s/<>/$tomid/mg; $fulltemplate =~ s/<>/$thread_name/mg; $add = "Re: " if $thread_name !~ /^Re: /m; $fulltemplate =~ s/<>/$add$thread_name/m; $fulltemplate =~ s/<>/\n\ \;\ \;$sender:\n\[QUOTE\]$message\[\/QUOTE\]\n\n/m; } $fulltemplate =~ s/<>/get_uploads()/me; return $fulltemplate; } ################ # Generate edt # ################ sub edit_generator { my ($message,$thread_name,$sender,$tomid,$postdate, $type); my $fulltemplate = shift; if ($_[0]) { $form->{'mid'} = $form->{'tomid'} if $form->{'tomid'}; lock_tables('READ',$MBOARDS,'users'); db_list("SELECT $MBOARDS.topic,$MBOARDS.type,$MBOARDS.msg,$MBOARDS.postdate,$MBOARDS.thread_id,users.info FROM $MBOARDS,users where $MBOARDS.forum = '$form->{'board'}' and $MBOARDS.id = '$form->{'mid'}' and $MBOARDS.sender = users.nimi"); while (my $ref = $sth->fetchrow_hashref()) { $thread_name = $ref->{'topic'}; $message = $ref->{'msg'}; $type = $ref->{'type'}; $sender = $ref->{'info'}; $postdate = get_post_date($ref->{'postdate'}); $tomid = $ref->{'thread_id'} || $form->{'mid'}; ($thread_name, $message) = html_escape($thread_name, $message); } db_end(); unlock_tables(); my $orig_message = create_message($message); $fulltemplate =~ s/<>/$orig_message/m; $fulltemplate =~ s/<>/$thread_name/m; $fulltemplate =~ s/<>/$sender/m; $fulltemplate =~ s/<>/$postdate/m; $fulltemplate =~ s/<>/$tomid/mg; $fulltemplate =~ s/<>/$thread_name/mg; $fulltemplate =~ s/<>/$_[0]/m; $fulltemplate =~ s/<>/$_[1]/m; $fulltemplate =~ s/<>/$_[2]/m; $fulltemplate = type_generator($fulltemplate,$_[3]); } else { lock_tables('READ',$MBOARDS,'users'); db_list("SELECT $MBOARDS.topic,$MBOARDS.type,$MBOARDS.msg,$MBOARDS.postdate,$MBOARDS.thread_id,users.info FROM $MBOARDS,users where $MBOARDS.forum = '$form->{'board'}' and $MBOARDS.id = '$form->{'mid'}' and $MBOARDS.sender = users.nimi"); while (my $ref = $sth->fetchrow_hashref()) { $thread_name = $ref->{'topic'}; $message = $ref->{'msg'}; $type = $ref->{'type'}; $sender = $ref->{'info'}; $postdate = get_post_date($ref->{'postdate'}); $tomid = $ref->{'thread_id'} || $form->{'mid'}; ($thread_name, $message) = html_escape($thread_name, $message); } db_end(); unlock_tables(); unlink <$config{'uploads'}/$USER/*>; if (-d "$attachments/$dir/$form->{'mid'}") { opendir(DIR, "$attachments/$dir/$form->{'mid'}") or write_log("$USER: Error opening dir $attachments/$dir/$form->{'mid'}. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} copy("$attachments/$dir/$form->{'mid'}/$_","$config{'uploads'}/$USER/$_"); } closedir DIR; } my $orig_message = create_message($message); $fulltemplate =~ s/<>/$orig_message/m; $fulltemplate = type_generator($fulltemplate,$type); $fulltemplate =~ s/<>/$thread_name/m; $fulltemplate =~ s/<>/$sender/m; $fulltemplate =~ s/<>/$postdate/m; $fulltemplate =~ s/<>//m; $fulltemplate =~ s/<>/$tomid/mg; $fulltemplate =~ s/<>/$thread_name/mg; $fulltemplate =~ s/<>/$thread_name/m; $fulltemplate =~ s/<>/$message/m; } $fulltemplate =~ s/<>/get_uploads()/me; return $fulltemplate; } ######################### # Generate message type # ######################### sub type_generator { my ($i, $message_types, $checked); my ($fulltemplate, $selected) = @_; if (!$selected) {$selected = $message_types[0];} foreach (@message_types) { $i++; if ($_ eq $selected) {$checked = "checked";} else {$checked = undef;} if ($i > 4) { $message_types .= "\n\n"; $i = 0; } $message_types .=qq[ $message_types{$_}\n]; } $fulltemplate =~ s/<>/$message_types/m; return $fulltemplate; } #################### # Generates legend # #################### sub create_legend { my ($message_types, @types); my ($fulltemplate, $forums) = @_; if ($forums) {@types = ('smallfolder');} else {@types = @message_types} foreach (@types) { $message_types .=qq[
$message_types{$_}\n]; } $fulltemplate =~ s/<>/$message_types/m; return $fulltemplate; } ###################### # Generate new topic # ###################### sub new_generator { my $fulltemplate = shift; if (!$_[0]) { if (-d "$config{'uploads'}/$USER") { opendir(DIR, "$config{'uploads'}/$USER") or write_log("$USER: Error opening dir $config{'uploads'}/$USER. $!", 'error'); foreach (sort {uc($a) cmp uc($b)} readdir DIR) { if (/^\./) {next;} unlink("$config{'uploads'}/$USER/$_"); } closedir DIR; } } $fulltemplate =~ s/<>/$_[0]/m; $fulltemplate =~ s/<>/$_[1]/m; $fulltemplate =~ s/<>/$_[2]/m; $fulltemplate =~ s/<>/get_uploads()/me; $fulltemplate = type_generator($fulltemplate,$_[3]); return $fulltemplate; } ################### # Create boardmap # ################### sub boardmap { my ($boardmap); my $fulltemplate = shift; lock_tables('READ',$BOARDCONFIG); db_list("SELECT forum from $BOARDCONFIG where id = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) {$boardmap = $ref->{'forum'};} db_end(); unlock_tables(); $fulltemplate =~ s/<>/$boardmap/mg; return $fulltemplate; } ################### # Generate topics # ################### # # 1. Count number of topics # 2. Display topics in forum # 3. Display path to board # 4. Display number of topics sub topic_generator { my ($gen,%counter,%postsender,%timesread,@ids,$count_topics,$buttons,%last_post,%sender,%topic,$type,$boardmap, %posttype,%lastsender); my $fulltemplate = shift; lock_tables('READ',$BOARDCONFIG,'users',$MBOARDS); db_list("SELECT forum from $BOARDCONFIG where id = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) {$boardmap = $ref->{'forum'};} db_end(); $gen .= html_generator("start","category=$boardmap 7","end"); db_list("SELECT $MBOARDS.topic,$MBOARDS.type,$MBOARDS.timesread,$MBOARDS.id,$MBOARDS.postdate,users.info,users.nimi FROM $MBOARDS,users where $MBOARDS.forum = '$form->{'board'}' and $MBOARDS.thread_id is NULL and $MBOARDS.sender = users.nimi order by postdate DESC"); while (my $ref = $sth->fetchrow_hashref()) { $count_topics++; push @ids, $ref->{'id'}; $last_post{$ref->{'id'}} = $ref->{'postdate'}; $sender{$ref->{'id'}} = $ref->{'nimi'}; $timesread{$ref->{'id'}} = $ref->{'timesread'}; $topic{$ref->{'id'}} = $ref->{'topic'}; $postsender{$ref->{'id'}} = $ref->{'info'}; $posttype{$ref->{'id'}} = $ref->{'type'}; ($topic{$ref->{'id'}}) = html_escape($topic{$ref->{'id'}}); } db_end(); foreach (@ids) { # Too heavy. Tweak! db_list("SELECT $MBOARDS.postdate,users.info,users.nimi FROM $MBOARDS,users where $MBOARDS.thread_id = '$_' and $MBOARDS.sender = users.nimi order by postdate"); while (my $ref = $sth->fetchrow_hashref()) { $last_post{$_} = $ref->{'postdate'}; $lastsender{$_} = $ref->{'info'}; $counter{$_}++; } db_end(); $last_post{$_} = get_post_date($last_post{$_}); $counter{$_} = '0' unless $counter{$_}; $timesread{$_} = '0' unless $timesread{$_}; $postsender{$_} = tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$sender{$_}", content => $postsender{$_}}); $lastsender{$_} = $postsender{$_} unless $lastsender{$_}; $gen .= html_generator( "$form->{'board'}", "$_", "start", "picbox=","picbox=$posttype{$_}","topic=$topic{$_}", "sender=$postsender{$_}","misc=$counter{$_}","timesread=$timesread{$_}","date2=$last_post{$_}|$lastsender{$_}","end" ); } $gen .= html_generator("start","category=".$trans->gettext('No topics found')." 7","end") if !$count_topics; $gen .= html_generator("start","category=$boardmap 7","end") if $count_topics; db_list("SELECT monitors from $BOARDCONFIG where id = '$form->{'board'}'"); while (my $ref = $sth->fetchrow_hashref()) { if (grep {$_ eq $USER} split /,/, $ref->{'monitors'}) {$buttons = tagged('a',{href => "boards.html?board=$form->{'board'}&auth=$form->{'auth'}&ID=$form->{'ID'}&command=monitor&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/stopmonitoring.gif", alt => 'Stop monitoring')});} else {$buttons = tagged('a',{href => "boards.html?board=$form->{'board'}&auth=$form->{'auth'}&ID=$form->{'ID'}&command=monitor&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/monitorforum.gif", alt => $trans->gettext('Monitor forum') )});} } db_end(); unlock_tables(); $buttons .= ' '.' '.tagged('a',{href => "boards.html?board=$form->{'board'}&auth=$form->{'auth'}&ID=$form->{'ID'}&command=ntopic&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/newtopic.gif", alt => $trans->gettext('New topic') )}); $fulltemplate = create_legend($fulltemplate); $fulltemplate =~ s/<>/$gen/m; $fulltemplate =~ s/<>/$buttons/mg; $count_topics = "0" if !$count_topics; $fulltemplate =~ s/<>/$count_topics/m; return $fulltemplate; } ################### # Generate forums # ################### # # 1. Get list of categories and forum id's # 2. Get number of topics for all forums # 3. Get date of last post for all forums # 4. Display categories and forums # 5. Display number of posts # 6. Display number of topics sub forum_generator { my ($gen,@categories, @ids,$buttons,%timesread, $count_reads,%count_topics,%count_all,$count_posts,$count_topics,$count_categories,%sender,@boards, %last_post,$type); my $fulltemplate = shift; lock_tables('READ',$BOARDCONFIG,$MBOARDS,'users'); db_list("SELECT id,category FROM $BOARDCONFIG where moderator = 'system' order by category"); while (my $ref = $sth->fetchrow_hashref()) { push @categories, $ref->{'category'} if !(grep {$_ eq $ref->{'category'}} @categories); push @ids, $ref->{'id'}; } db_end(); foreach (@ids) { # Optimize! $count_topics{$_} = '0'; $timesread{$_} = '0'; db_list("SELECT $MBOARDS.postdate,$MBOARDS.timesread,$MBOARDS.thread_id,$MBOARDS.sender,$MBOARDS.forum,users.info FROM users,$MBOARDS where forum = '$_' and $MBOARDS.sender = users.nimi order by $MBOARDS.postdate"); while (my $ref = $sth->fetchrow_hashref()) { $count_all{$_}++; $count_topics{$_}++ unless $ref->{'thread_id'}; $timesread{$_} += $ref->{'timesread'} unless $ref->{'thread_id'}; $last_post{$_} = $ref->{'postdate'}; $sender{$_} = $ref->{'info'}; } db_end(); } unless (@categories) {$gen .= html_generator("start","category=".$trans->gettext('No forums available')." 6","end");} foreach (@categories) { $gen .= html_generator("start","category=$_ 6","end"); db_list("SELECT id,forum,description FROM $BOARDCONFIG where moderator = 'system' and category = '$_' order by forum"); while (my $ref = $sth->fetchrow_hashref()) { $count_categories++; $last_post{$ref->{'id'}} = get_post_date($last_post{$ref->{'id'}}); $last_post{$ref->{'id'}} =~ s/ - /
/; $count_all{$ref->{'id'}} = '0' unless $count_all{$ref->{'id'}}; ($ref->{'description'},$ref->{'forum'}) = html_escape($ref->{'description'},$ref->{'forum'}); $gen .= html_generator( "$ref->{'id'}","start","picbox=smallfolder","board=$ref->{'forum'}", "desc=$ref->{'description'}","misc=$count_topics{$ref->{'id'}}", "misc=$count_all{$ref->{'id'}}","timesread=$timesread{$ref->{'id'}}","date2=$last_post{$ref->{'id'}}|$sender{$ref->{'id'}}","end" ); } db_end(); } unlock_tables(); if ($admin_status =~ /M0/) { $buttons = tagged('a',{href => "boards.html?auth=$form->{'auth'}&ID=$form->{'ID'}&mode=addforum&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/addforum.gif", alt => $trans->gettext('Add forum') )}).'  '. tagged('a',{href => "boards.html?auth=$form->{'auth'}&ID=$form->{'ID'}&mode=rmforum&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/removeforum.gif", alt => $trans->gettext('Remove forum') )}).'  '. tagged('a',{href => "boards.html?auth=$form->{'auth'}&ID=$form->{'ID'}&mode=editforum&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/editforum.gif", alt => $trans->gettext('Edit forum') )}); } $fulltemplate = create_legend($fulltemplate, 'forums'); $fulltemplate =~ s/<>/$buttons/m; $fulltemplate =~ s/<>/$gen/m; $fulltemplate =~ s/<>/$count_categories/m; $count_posts += $count_all{$_} foreach keys %count_all; $fulltemplate =~ s/<>/$count_posts/m; $count_topics += $count_topics{$_} foreach keys %count_topics; $fulltemplate =~ s/<>/$count_topics/m; $count_reads += $timesread{$_} foreach keys %timesread; $fulltemplate =~ s/<>/$count_reads/m; return $fulltemplate; } ################## # HTML generator # ################## # # start - Start block # misc - Print column with misc data # category - Print category name # board - Print board name # desc - Print board description # date - Print last post of topic # date2 - Print last post of forum # postdate - Print date of the message # sender2 - Print sender information in thread # topic2 - Print topic in thread # topic - Print topic name # message - Print message # sender - Print sender name # end - End block # buttons - Buttons sub html_generator { my($string, $board, $mid,$date,$sender,$time); if ($_[0] =~ /^\d+/) {$board = shift;} if ($_[0] =~ /^\d+/) {$mid = shift;} foreach (@_) { if (/^start/) {$string .= qq[\n];} elsif (/^misc=(.*)/) {$string .= qq[ $1 \n];} elsif (/^timesread=(.*)/) {$string .= qq[ $1 \n];} elsif (/^picbox=(.*)/) {my $content = $1;$content = qq[$message_types{$content}] if $content;$string .= qq[ $content \n];} elsif (/^board=(.*)/) {$string .= qq[$1 
\n];} elsif (/^desc=(.*)/ms) {$string .= qq[$1\n];} elsif (/^date=(.*)/) {$string .= qq[$1 \n];} elsif (/^topic=(.*)/) {$string .= qq[$1 \n];} elsif (/^topic2=(.*)/) {$string .= qq[\n];} elsif (/^sender=(.*)/) {$string .= qq[\n];} elsif (/^sender2=(.*)/) {$string .= qq[\n];} elsif (/^message=(.*)/ms) {$string .= qq[\n];} elsif (/^postdate=(.*)/) {$string .= qq[\n];} elsif (/^end/) {$string .= qq[\n];} elsif (/^category=(.*) (\d+)$/) {$string .= qq[\n];} elsif (/^buttons=(.*)/) { my $senders = $1; $string .= qq[
$1 $1 
$1 
$1 
$1 
 »$1 ]; if ($admin_status =~ /M0/ && $senders !~ /^\|nodelete\|/) {$string .= tagged('a',{href => "boards.html?board=$board&mid=$mid&auth=$form->{'auth'}&ID=$form->{'ID'}&command=del&grouptool=$form->{'grouptool'}", onClick => "return confirm('".$trans->gettext("Do you really want to delete this message?")."');", content => image(src => "$config{'loc_pictures'}/delete.gif", align => 'absmiddle', alt => $trans->gettext('Delete') )}).' ';} if ($admin_status =~ /M0/ || $senders =~ /(\|nodelete\|)?$USER/) {$string .= tagged('a',{href => "boards.html?board=$board&mid=$mid&auth=$form->{'auth'}&ID=$form->{'ID'}&command=edit&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/edit.gif", align => 'absmiddle',alt => $trans->gettext('Edit') )}).' ';} $string .= tagged('a',{href => "boards.html?board=$board&mid=$mid&auth=$form->{'auth'}&ID=$form->{'ID'}&command=reply&grouptool=$form->{'grouptool'}", content => image(src => "$config{'loc_pictures'}/reply.gif", align => 'absmiddle', alt => $trans->gettext('Reply') )}).qq[
]; } elsif (/^date2=(.*)/) { ($date,$sender) = split /\|/, $1; $sender = "n/a" if !$sender; $string .= qq[].$trans->gettext("Date: ").qq[$date
].$trans->gettext("By: ").qq[$sender\n]; } } return $string; }