#!/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: md_news.html,v 1.51 2002/06/06 14:58:02 inf Exp $ ####################################################### # # # MimerDesk: Home - MimerDesk news # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Hannes Muurinen # # # ####################################################### # Asetukset ################################## use strict; use vars qw ($APPLICATION $ACTIVEGRP $USER $UID $IP $LAST_ACT $FORWARDED $trans $TIME_USED $IDLE $form $ref $sth %month_names $htmlcolors $admin_status $GROUPACTIVOR $MD_NEWS $MD_NEWS_COMMENT $edit_on ); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; use Mail::Sendmail; sub print_template; sub news_beat; $APPLICATION = 'Home - News'; # Program ################################## my ($MONTH,$YEAR); read_config('../config/mimerdesk.cfg'); $htmlcolors = initialize('colors'); $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'}); #get the user id (has to be done this way until the authenticate function is modified to return also UID) lock_tables('READ', 'users'); ($ref) = db_select('UID','users',"nimi = '$USER'"); $UID = $ref->{'UID'}; db_end(); unlock_tables(); $trans = lib::MimerDesk->new_gettext(program => 'md_news',language => $config{'language'}); $MD_NEWS = 'md_news'; #database tables $MD_NEWS_COMMENT = 'md_news_comment'; if ($form->{'grouptool'} =~ /^\d+$/) { 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) { $form->{'grouptool'} = ''; 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(); # the db tables aren't set to group tables => the global admin can't access the group news if not group member.. should this be changed? } else { $MD_NEWS = "$form->{'grouptool'}_$MD_NEWS"; $MD_NEWS_COMMENT = "$form->{'grouptool'}_$MD_NEWS_COMMENT"; } } else { 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(); $form->{'grouptool'} = ''; } $edit_on = 1 if $admin_status =~ /N0/; if($GROUPACTIVOR) {$APPLICATION = $trans->gettext("Group - News");} else {$APPLICATION = $trans->gettext("Home - News");} %month_names = ( '01' => $trans->gettext("January"), '02' => $trans->gettext("February"), '03' => $trans->gettext("March"), '04' => $trans->gettext("April"), '05' => $trans->gettext("May"), '06' => $trans->gettext("June"), '07' => $trans->gettext("July"), '08' => $trans->gettext("August"), '09' => $trans->gettext("September"), '10' => $trans->gettext("October"), '11' => $trans->gettext("November"), '12' => $trans->gettext("December") ); ($MONTH,$YEAR) = check_form_date($form->{'month'},$form->{'year'},$form->{'newsID'}); my ($shown_text, $text_class); if($form->{'commID'} && $form->{'remove_comment'}) {($shown_text, $text_class) = remove_comment($form->{'commID'});} elsif($form->{'commID'} && $form->{'save_mod_comment'}) {($shown_text, $text_class) = modify_comment($form->{'commID'});} elsif($form->{'rnewsID'} && $form->{'remove_news'}) {($shown_text, $text_class) = remove_news($form->{'rnewsID'});} elsif($form->{'post_c'} && $form->{'newsID'}) {($shown_text, $text_class) = post_comment();} elsif($form->{'toggle_monitor'}) {($shown_text, $text_class) = toggle_monitoring($UID,$form->{'grouptool'});} elsif($form->{'toggle_comment_monitor'}) {($shown_text, $text_class) = toggle_monitoring($UID,$form->{'grouptool'},'comment');} print_template("$config{'theme'}_md_news", $MONTH, $YEAR, $form->{'newsID'}, $shown_text, $text_class); # Subs ################################## ################################## # Read template and process it # ################################## # 1. Print header # 2. Read template # 3. Get submitted month # 4. Query news database for topics of submitted month # 5. If something else than 'latest' queried, get the specified article based on article number # 6. Replace all "%27" with ' # 7. Get past months # 8. Start progressing template # 9. If <>, replace it with selected months topics. Order by newest # 10. Do all normal replacements sub print_template { my ($fulltemplate,$message_html); my $locat = qq[$config{'loc_server'}$config{'bin_dir'}/md_news.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}]; my ($template, $MONTH, $YEAR, $NEWSID, $shown_text, $text_class) = @_; $message_html = tagged('div', {align => 'center', class => $text_class, content => $shown_text}) if $shown_text; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = join "", ($ref->{'js_doClock'},$ref->{'js_help'},$ref->{'js_gotosite'}); $fulltemplate =~ s/<>/$stuff/ms; if($GROUPACTIVOR) { $fulltemplate = create_buttons($fulltemplate, 'Group', 'News', $form);} else{ $fulltemplate = create_buttons($fulltemplate, 'Home', 'News', $form);} $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; my($allnews, $month_topics, $months, $comments,$comment_form) = generate_news_data($MONTH,$YEAR,$NEWSID); my $current_month = tagged('a', {href => $locat."&month=$MONTH&year=$YEAR", class => 'blackTitleLink', content => "$month_names{$MONTH} $YEAR"}); $fulltemplate =~ s/<>/$allnews/m; $fulltemplate =~ s/<>/$month_topics/m; $fulltemplate =~ s/<>/$current_month/m; $fulltemplate =~ s/<>/$months

/m; $fulltemplate =~ s/<>/$comments/m; $fulltemplate =~ s/<>/$comment_form/m; $fulltemplate =~ s/<>/$form->{'grouptool'}/m; $fulltemplate =~ s/<>/$NEWSID/m; $fulltemplate =~ s/<>/$form->{'commID'}/m; $fulltemplate =~ s/<>/$MONTH/m; $fulltemplate =~ s/<>/$YEAR/m; $fulltemplate =~ s/<>/$form->{'commentHeadline'}/m; $fulltemplate =~ s/<>/$form->{'commentText'}/m; $fulltemplate =~ s/<>/$message_html/m; $stuff = get_monitor_button($UID,$form->{'grouptool'}); $fulltemplate =~ s/<>/$stuff/m; $stuff = get_monitor_button($UID,$form->{'grouptool'},'comment'); $fulltemplate =~ s/<>/$stuff/m; if($edit_on) { $stuff = tagged('a', {href => "md_news_add.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}&oldmonth=$MONTH&oldyear=$YEAR", onMouseOver => 'doClock(); return true', class => 'content', content => image(src => '<>addarticle.gif', border => '0', alt => $trans->gettext("Add new news article"))}); } else { $stuff = ''; } $fulltemplate =~ s/<>/$stuff/m; $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_news_data # #---------------------------------------------------------------------------------------------------------------# # generate_news_data($month,$year,[$newsID]) # # # # Returns some (HTML) data in array. # # # # 1. The main table: # # * If $newsID is given, returns the whole news article with ID==$newsID. # # * If !$newsID, a table with summaries of the news of the given month/year is returned. # # # # 2. The headline list: # # * All the headlines of the given month/year are listed in here as links pointing to the corresponding # # news article. # # # # 3. The month list: # # * The news archive can be accessed here. All the months during which some news have been posted are # # listed here. The number of the news posted in that month is also written. The month names are links to # # corresponding monthly summary lists. # # # # 4. The news comment table: # # * If $newsID is given, returns the comments of the article in a table. # # * If !$newsID, empty variable is returned. # # # # 5. The news comment form: # # * If $newsID is given, returns a form with a textbox with which users can add new comments. # # * If !$newsID, empty variable is returned. # # # # # # Usage: # # ($main_table,$headline_list,$month_list,$comment_table,$comment_form) = generate_news_data(12,2001); # # ($main_table,$headline_list,$month_list,$comment_table,$comment_form) = generate_news_data(12,2001,57); # # # ################################################################################################################# sub generate_news_data { my (%count, $month_topics, $months, $allnews, %years, $comment_table, $form_template_ref, $title_text, %comment_count); my ($month,$year,$newsID) = @_; my $locat = qq[$config{'loc_server'}$config{'bin_dir'}/md_news.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}]; if(!$newsID) {$title_text = $trans->gettext("Headlines of the month");} else {$title_text = $trans->gettext("The article");} lock_tables('READ', $MD_NEWS, 'users', $MD_NEWS_COMMENT); if($newsID) { db_list("SELECT count(IDnumber) as number FROM $MD_NEWS_COMMENT where newsID = '$newsID'"); while (my $ref = $sth->fetchrow_hashref()) { $comment_count{$newsID} = $ref->{'number'}; } } else { my($next_month,$next_year) = ($month+1,$year); if ($next_month > 12) { $next_month -= 12; $next_year++; } my ($lower_border_epoch,$upper_border_epoch) = (local_date2utc_epoch(0,0,0,1,$month,$year),local_date2utc_epoch(0,0,0,1,$next_month,$next_year)); db_list("SELECT $MD_NEWS_COMMENT.newsID,count($MD_NEWS_COMMENT.IDnumber) as number FROM $MD_NEWS_COMMENT,$MD_NEWS where $MD_NEWS.epoch > '$lower_border_epoch' and $MD_NEWS.epoch < '$upper_border_epoch' and $MD_NEWS.IDnumber = $MD_NEWS_COMMENT.newsID group by $MD_NEWS_COMMENT.newsID"); while (my $ref = $sth->fetchrow_hashref()) { $comment_count{$ref->{'newsID'}} = $ref->{'number'}; } } db_list("SELECT $MD_NEWS.*, users.nimi, users.info FROM $MD_NEWS,users where $MD_NEWS.senderID = users.UID order by $MD_NEWS.epoch DESC"); while (my $ref = $sth->fetchrow_hashref()) { my ($sec,$min,$hour,$mday,$mon,$yea) = utc_epoch2date($ref->{'epoch'}); if (!$month || !$year) { $month = $mon; $year = $yea; } if (!(grep {$mon == $_} @{$years{$yea}})) # check if %years{@months} contains the $mon already {push (@{ $years{$yea} }, $mon);} $count{$yea, $mon} += 1; if ($mon == $month && $yea == $year) { $month_topics .= tagged('li',{content => tagged('a',{href => $locat."&month=$mon&year=$yea&newsID=$ref->{'IDnumber'}", class => 'contentLink', content => $ref->{'headline'} })}); my ($mod_but, $del_but); if ($edit_on) { $mod_but = tagged('a', {href => "md_news_add.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}&oldmonth=$MONTH&oldyear=$YEAR&newsID=$ref->{'IDnumber'}", onMouseOver => 'doClock(); return true', class => 'content', content => image(src => '<>edit.gif', border => '0', alt => $trans->gettext("Modify this news article"))}); $del_but = tagged('a', {href => "md_news.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}&month=$MONTH&year=$YEAR&rnewsID=$ref->{'IDnumber'}&remove_news=1", onMouseOver => 'doClock(); return true', class => 'content', content => image(src => '<>remove.gif', border => '0', alt => $trans->gettext("Remove this news article"))}); } $comment_count{$ref->{'IDnumber'}} = 0 if ($comment_count{$ref->{'IDnumber'}} eq ''); if (!$newsID) { $allnews .= news_beat($ref->{'summary'},$ref->{'epoch'},$ref->{'headline'}, $ref->{'IDnumber'}, $ref->{'category'}, $ref->{'nimi'}, $ref->{'info'},$mod_but, $del_but, 'add links','',$comment_count{$ref->{'IDnumber'}});} elsif ($newsID == $ref->{'IDnumber'}) { $allnews .= news_beat($ref->{'article'},$ref->{'epoch'},$ref->{'headline'}, $ref->{'IDnumber'}, $ref->{'category'}, $ref->{'nimi'}, $ref->{'info'},$mod_but, $del_but);} } } db_end(); unlock_tables(); foreach my $yea (sort {$b <=> $a} keys %years) { $months .= tagged('div',{class => 'blackTitleSec', content => $yea}).tag('br'); foreach my $mon (sort {$b <=> $a} @{$years{$yea}}) {$months .= '- '.tagged('a',{href => $locat."&month=$mon&year=$yea", class => "contentLink", content => "$month_names{$mon} ($count{$yea, $mon})"}).tag('br');} } if($newsID && $allnews) { lock_tables('READ', $MD_NEWS_COMMENT, 'users'); db_list("SELECT $MD_NEWS_COMMENT.*,users.nimi,users.info FROM $MD_NEWS_COMMENT,users where $MD_NEWS_COMMENT.newsID = '$newsID' and users.UID = $MD_NEWS_COMMENT.senderID order by $MD_NEWS_COMMENT.epoch"); while (my $ref = $sth->fetchrow_hashref()) { my ($mod_but, $del_but, $is_textfield); if ($edit_on || $ref->{'senderID'} == $UID) { $mod_but = tagged('a', {href => "md_news.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}&newsID=$newsID&commID=$ref->{'IDnumber'}&modify_comment=1", onMouseOver => 'doClock(); return true', class => 'content', content => image(src => '<>edit.gif', border => '0', alt => $trans->gettext("Modify this comment"))}); $del_but = tagged('a', {href => "md_news.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}&newsID=$newsID&commID=$ref->{'IDnumber'}&remove_comment=1", onMouseOver => 'doClock(); return true', class => 'content', content => image(src => '<>remove.gif', border => '0', alt => $trans->gettext("Remove this comment"))}); if($form->{'commID'} == $ref->{'IDnumber'} && $form->{'modify_comment'}) { $ref->{'headline'} = $form->{'mod_c_headline'} if $form->{'mod_c_headline'}; $ref->{'article'} = $form->{'mod_c_text'} if $form->{'mod_c_text'}; $ref->{'headline'} = textfield(name => 'mod_c_headline', size => 35, maxlength => 150, value => $ref->{'headline'}); $ref->{'article'} = textarea(name => 'mod_c_text', wrap => 'VIRTUAL', cols => 85, rows => 5, value => $ref->{'article'}) . tag('br') . picbutton(form => 'form1', name => 'save_mod_comment', image => 'save.gif', alt => $trans->gettext('Save modifications')); $is_textfield = 1; } } $comment_table .= news_beat($ref->{'article'},$ref->{'epoch'},$ref->{'headline'}, 0, '', $ref->{'nimi'}, $ref->{'info'},$mod_but, $del_but,'',$is_textfield); } db_end(); unlock_tables(); $comment_table = starttable(width => '95%',align => 'center',cellspacing => 1,cellpadding => 2,gridcolor => 'black'). startrow(). column(bgcolor => $htmlcolors->{'title'}, class => 'blackTitle', content => ' '. $trans->gettext("Comments") . " ($comment_count{$newsID})"). endrow(). $comment_table. endtable('hasgrid') if $comment_table; $form_template_ref = get_template("$config{'theme'}_md_news_comment_form"); } $allnews = startrow(). column(bgcolor => $htmlcolors->{'sectitle'}, class => 'content', content => ' '. sprintf($trans->gettext("No articles posted in %s"), local_date2date_string(0, 0, 0, 0, $month,$year, '%sm %y'))). endrow() if(!$allnews); $allnews = starttable(width => '95%',align => 'center',cellspacing => 1,cellpadding => 2,gridcolor => 'black'). startrow(). column(bgcolor => $htmlcolors->{'title'}, class => 'blackTitle', content => ' '. $title_text). endrow(). $allnews. endtable('hasgrid'); return ($allnews,$month_topics,$months,$comment_table,$form_template_ref->{"$config{'theme'}_md_news_comment_form"}); } ################################################################################################################# # news_beat # #---------------------------------------------------------------------------------------------------------------# # news_beat($text,$epoch,$headline,$newsID,$news_category,$sender_username,$sender_fullname, [$modify_button], [$delete_button], ['add link'], ['do not check html'],[$number_of_comments]) # # # # Returns news article table column with the given parameters. If the 'add links' argument is given # # "Read more..." link is added linking to the article $newsID . The headline is also made clickable. # # If the modify/delete buttons are given, they are added to the appropriate place. Note that this function # # doesn't check if the user has authorization to do the modifying/deleting -- it must be checked elsewhere. # # If the "don't check html" argument is given, the article and headline aren't checked. # # # # Usage: # # $part_of_HTML_table = news_beat($summary,$epoch,$headline,$newsID,$news_category,$sender_username,$sender_fullname, $modify_button, $delete_button, 1, 1) # # # ################################################################################################################# sub news_beat { my ($article,$epoch,$headline,$newsID,$category,$username,$fullname,$modify_button,$delete_button,$add_links,$dont_check_html,$comments_num) = @_; my $locat = qq[$config{'loc_server'}$config{'bin_dir'}/md_news.html?ID=$form->{'ID'}&auth=$form->{'auth'}&grouptool=$form->{'grouptool'}]; my ($read_more_text); #get the sender information # $senderID = prepare_fordb($senderID); # my($ref) = db_select('nimi,info','users',"UID = '$senderID'"); # my($username,$fullname) = ($ref->{'nimi'},$ref->{'info'}); # db_end(); $delete_button = tag('br').$delete_button if $delete_button; my @date_array = utc_epoch2date($epoch); my $date_string = local_date2date_string($date_array[0], $date_array[1], $date_array[2], $date_array[3], $date_array[4], $date_array[5], '%w %d %sm %y %h:%m'); ($article,$headline) = html_escape($article,$headline) if(!$dont_check_html); ($date_string,$username,$fullname,$read_more_text) = html_escape($date_string,$username,$fullname,$read_more_text); if ($add_links) { $read_more_text = tagged('a',{href => $locat."&month=$date_array[4]&year=$date_array[5]&newsID=$newsID", class => "contentLinkBlue", content => $trans->gettext("Read more..."). ' '. sprintf($trans->gettext('(%s comments)'),$comments_num)}). tag('br').tag('br'); $headline = tagged('a',{href => $locat."&month=$date_array[4]&year=$date_array[5]&newsID=$newsID", class => "blackTitleLink", content => $headline}); } $article = urlify($article) if(!$dont_check_html); $article = itag_replacer($article) if(!$dont_check_html); $article =~ s/\r?\n/
/mg if(!$dont_check_html); my $allnews2 = startrow(). column(bgcolor => $htmlcolors->{'sectitle'}, content => starttable(). startrow(). column(class => 'blackTitle',content => ' '.$headline). column(class => 'date',align => 'right', content => $date_string.' '.tag('br'). tagged('a', {href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$username", onMouseOver => 'doClock(); return true', class=> 'date', content => "$username ($fullname)"}). $delete_button.' '.$modify_button). endrow(). endtable() ). endrow(). startrow(). column(bgcolor => 'white',valign => 'top', class => 'content',content => tag('br'). tagged('blockquote',{content => $article. tag('br').tag('br'). $read_more_text }) ). endrow(); return $allnews2; } ################################################################################# # send_monitor_mail - sends email message to news monitorers # #-------------------------------------------------------------------------------# # send_monitor_mail($groupID,$epoch,$authorID,$subject,$message) # # # # Sends the news article to the news monitorers of group $groupID via e-mail. # # # # Usage: # # send_monitor_mail($groupID,$epoch,$authorID,$subject,$message) # # # ################################################################################# # # # (cut&pasted from boards.html and then modified and tweaked) # # # ################################################################################# sub send_monitor_mail { my (%mail,@monitors,$author,$news_board_name,$ref,%monitorer_email,%monitorer_name); my ($groupID,$epoch,$authorID,$subject,$message) = @_; $message = itag_remover($message); my $posted = utc_epoch2date_string($epoch, '%w %d %sm %y %h:%m'); lock_tables('READ','users','md_news_monitor','groups'); ($ref) = db_select('info','users',"UID = '$authorID'"); $author = $ref->{'info'}; if($groupID) { ($ref) = db_select('GRPNAME','groups',"GID = '$groupID'"); $news_board_name = "$ref->{'GRPNAME'} - News comments"; } else { $news_board_name = 'Public news'; } ($ref) = db_select('comment_monitorers','md_news_monitor',"GID = '$groupID'"); @monitors = split /,/, $ref->{'comment_monitorers'}; db_end(); # get the emails and names of the monitorers db_list("select email,info,UID from users where UID in ($ref->{'comment_monitorers'})"); while (my $ref = $sth->fetchrow_hashref()) { $monitorer_email{$ref->{'UID'}} = $ref->{'email'}; $monitorer_name{$ref->{'UID'}} = $ref->{'info'}; } db_end(); foreach (@monitors) { next if $monitorer_email{$_} !~ /\@.+\..+/; $Mail::Sendmail::mailcfg{'retries'} = 0; $mail{'From'} = "MimerDesk <$config{'monitor_mail'}>"; $mail{'To'} = "$monitorer_name{$_} <$monitorer_email{$_}>"; my $server = $config{'mail_server'}; $mail{'Smtp'} = $server if $server; $mail{'subject'} = "[$news_board_name] - $subject"; $mail{'message'} = "Read and comment this article at:\n$config{'loc_server'}$config{'bin_dir'}/index.html\n\n"; $mail{'message'} .= "Date: $posted\nAuthor: $author\nSubject: $subject\n\n$message\n\n"; $mail{'message'} .= "_________________________________________________________________________\n"; $mail{'message'} .= "You are receiving this e-mail because you have turned news comment \n"; $mail{'message'} .= "monitoring on. To stop monitoring comments, login to MimerDesk and select\nStop monitoring on the news board.\n"; if (sendmail(%mail)) {} else {write_log("Error sending message (news comment monitoring): $Mail::Sendmail::error", 'error');} } unlock_tables(); } ################################################################################# # post_comment - adds the article comment to the database # #-------------------------------------------------------------------------------# # post_comment() # # # # All the arguments are read from the form. # # Returns error/success message and it's text class. # # # # Usage: # # ($message, $message_class) = post_comment() # # # ################################################################################# sub post_comment { my($error_message,$ref,$epoch,%db); $error_message .= $trans->gettext("There's no comment headline!") .tag('br') if(!$form->{'commentHeadline'}); $error_message .= $trans->gettext("There's no comment text!") .tag('br') if(!$form->{'commentText'}); return($error_message,'error') if $error_message; $epoch = time(); ($epoch, $form->{'newsID'}, $form->{'commentText'}, $form->{'commentHeadline'},$UID) = prepare_fordb($epoch, $form->{'newsID'}, $form->{'commentText'}, $form->{'commentHeadline'},$UID); lock_tables('WRITE', $MD_NEWS_COMMENT); %db = ( newsID => $form->{'newsID'}, senderID => $UID, epoch => $epoch, headline => $form->{'commentHeadline'}, article => $form->{'commentText'} ); db_insert($MD_NEWS_COMMENT,\%db); db_end(); unlock_tables(); send_monitor_mail($form->{'grouptool'},$epoch,$UID,$form->{'commentHeadline'},$form->{'commentText'}); $form->{'commentHeadline'} = ''; $form->{'commentText'} = ''; return ($trans->gettext("Comment added."), 'success'); } ################################################################################# # remove_comment - removes pre-existing article from the database # #-------------------------------------------------------------------------------# # remove_comment($comment_ID) # # # # Removes the article with ID $comment_ID if the user has authorization to do # # so. Returns error/success -message. # # # # Usage: # # ($message, $message_class) = remove_comment($comment_ID) # # # ################################################################################# sub remove_comment { my($message,$msg_class); my $commentID = shift; ($commentID) = prepare_fordb($commentID); lock_tables('READ', $MD_NEWS_COMMENT); my ($ref) = db_select('senderID',$MD_NEWS_COMMENT,"IDnumber = '$commentID'"); unlock_tables(); if($edit_on || $ref->{'senderID'} == $UID) { lock_tables('WRITE', $MD_NEWS_COMMENT); db_delete($MD_NEWS_COMMENT, "IDnumber = '$commentID'"); db_end(); unlock_tables(); ($message,$msg_class) = ($trans->gettext('Comment removed.'), 'success'); } else { write_log("$USER tried to remove news comments (GroupID='$form->{'grouptool'}') without sufficient permissions!", 'warning'); ($message,$msg_class) = ($trans->gettext('You don\'t have rights to remove comments!'), 'error'); } return($message,$msg_class); } ################################################################################# # modify_comment - modifies pre-existing article in the database # #-------------------------------------------------------------------------------# # modify_comment($comment_ID) # # # # Modifies the article with ID $comment_ID if the user has authorization to do # # so. Returns error/success -message. # # # # Usage: # # ($message, $message_class) = modify_comment($comment_ID) # # # ################################################################################# sub modify_comment { my($message,$msg_class); my $commentID = shift; ($commentID, $form->{'mod_c_headline'}, $form->{'mod_c_text'}) = prepare_fordb($commentID, $form->{'mod_c_headline'}, $form->{'mod_c_text'}); $message .= $trans->gettext("There's no comment headline (modified comment)!") .tag('br') if(!$form->{'mod_c_headline'}); $message .= $trans->gettext("There's no comment text (modified comment)!") .tag('br') if(!$form->{'mod_c_text'}); if($message) { $form->{'modify_comment'} = 1; # display the modifying text box again return($message,'error'); } lock_tables('READ', $MD_NEWS_COMMENT); my ($ref) = db_select('senderID',$MD_NEWS_COMMENT,"IDnumber = '$commentID'"); unlock_tables(); if($edit_on || $ref->{'senderID'} == $UID) { lock_tables('WRITE', $MD_NEWS_COMMENT); my %db = ( headline => $form->{'mod_c_headline'}, article => $form->{'mod_c_text'} ); db_update($MD_NEWS_COMMENT,\%db, "IDnumber = '$commentID'"); db_end(); unlock_tables(); ($message,$msg_class) = ($trans->gettext('Modifications saved.'), 'success'); } else { write_log("$USER tried to modify news comments (GroupID='$form->{'grouptool'}') without sufficient permissions!", 'warning'); ($message,$msg_class) = ($trans->gettext('You don\'t have rights to modify comments!'), 'error'); } return($message,$msg_class); } ################################################################################# # remove_news - removes pre-existing article from the database # #-------------------------------------------------------------------------------# # remove_news($newsID) # # # # Removes the article with ID $newsID and comments related to it if the user # # has authorization to do so. Returns error/success -message. # # # # Usage: # # ($message, $message_class) = remove_news($newsID) # # # ################################################################################# sub remove_news { my($message,$msg_class); my $newsID = shift; ($newsID) = prepare_fordb($newsID); if($edit_on) { lock_tables('WRITE', $MD_NEWS, $MD_NEWS_COMMENT); db_delete($MD_NEWS, "IDnumber = '$newsID'"); db_delete($MD_NEWS_COMMENT, "newsID = '$newsID'"); db_end(); unlock_tables(); ($message,$msg_class) = ($trans->gettext('Article and comments removed.'), 'success'); } else { write_log("$USER tried to remove news article (GroupID='$form->{'grouptool'}') without sufficient permissions!", 'warning'); ($message,$msg_class) = ($trans->gettext('You don\'t have rights to remove news articles!'), 'error'); } return($message,$msg_class); } ################################################################################# # get_monitor_button - returns the monitoring button link # #-------------------------------------------------------------------------------# # get_monitor_button($userID, $groupID,['comment monitoring']) # # # # Returns a button. The returned button is either "Monitor news" # # or "Stop monitoring" depending on the user ($userID) and news board # # ($groupID). For public news $groupID == ''. # # If the optional argument is given, returns comment monitoring button. # # # # Usage: # # $button = get_monitor_button($userID,$form->{'grouptool'},1) # # # ################################################################################# sub get_monitor_button { my($ret_value,$db_column,$mon_pic,$stop_pic,$mon_alt,$stop_alt); my ($userID,$groupID,$comment) = @_; if($comment) { $db_column = 'comment_monitorers'; ($mon_pic,$stop_pic,$mon_alt,$stop_alt) = ('monitorcomments.gif','stopcommentmonitoring.gif',$trans->gettext("Start comment monitoring"),$trans->gettext("Stop comment monitoring")); } else { $db_column = 'monitorers'; ($mon_pic,$stop_pic,$mon_alt,$stop_alt) = ('monitornews.gif','stopnewsmonitoring.gif',$trans->gettext("Start news monitoring"),$trans->gettext("Stop news monitoring")); } lock_tables('READ', 'md_news_monitor'); my ($ref) = db_select($db_column,'md_news_monitor',"GID = '$form->{'grouptool'}'"); my @monitor_list = split /,/, $ref->{$db_column}; db_end(); unlock_tables(); if (grep {$_ eq $userID} @monitor_list) { $ret_value = image(src => "<>$stop_pic", border => '0', alt => $stop_alt);} else { $ret_value = image(src => "<>$mon_pic", border => '0', alt => $mon_alt);} return $ret_value; } ################################################################################# # toggle_monitoring - toggles monitoring on/off # #-------------------------------------------------------------------------------# # toggle_monitoring($userID,$groupID,['comment monitoring']) # # # # Toggles monitoring on/off for the user $userID in news board $groupID. For # # public news $groupID==''. Returns error/success message and it's message # # class. If the optional argument is given, toggles comment monitoring. # # # # Usage: # # ($message, $msg_class) = toggle_monitoring($userID,$form->{'grouptool'},1) # # # ################################################################################# sub toggle_monitoring { my ($ret_msg, $msg_class,$db_column); my ($userID,$groupID,$comment) = @_; $groupID = 0 if $groupID eq ''; if($comment) {$db_column = 'comment_monitorers';} else {$db_column = 'monitorers';} lock_tables('WRITE', 'md_news_monitor'); my ($ref) = db_select('*','md_news_monitor',"GID = '$groupID'"); my @monitor_list = split /,/, $ref->{$db_column}; db_insert('md_news_monitor',{monitorers => '',comment_monitorers => '',GID => $groupID}) if $ref->{'GID'} ne $groupID; # if db entry doesn't already exist, create new db_end(); if (!(grep {$_ eq $userID} @monitor_list)) { push @monitor_list, $userID; my $monitors = join ",", @monitor_list; db_update('md_news_monitor',{$db_column => $monitors}, "GID = '$groupID'"); db_end(); if($db_column eq 'monitorers') { write_log("$USER started to monitor news in group with ID '$groupID'",'notify'); $ret_msg = $trans->gettext("News monitoring was turned on in this news board."); } else { write_log("$USER started to monitor news comments in group with ID '$groupID'",'notify'); $ret_msg = $trans->gettext("Comment monitoring was turned on in this news board."); } $msg_class = 'success'; } else { my $monitors = join ",", grep {$_ ne $userID} @monitor_list; db_update('md_news_monitor',{$db_column => $monitors}, "GID = '$groupID'"); db_end(); write_log("$USER stopped monitoring news in group with ID '$groupID'",'notify'); $ret_msg = $trans->gettext("News monitoring was turned off in this news board."); if($db_column eq 'monitorers') { write_log("$USER stopped monitoring news in group with ID '$groupID'",'notify'); $ret_msg = $trans->gettext("News monitoring was turned off in this news board."); } else { write_log("$USER stopped monitoring news comments in group with ID '$groupID'",'notify'); $ret_msg = $trans->gettext("Comment monitoring was turned off in this news board."); } $msg_class = 'success'; } unlock_tables(); return ($ret_msg, $msg_class); } ################################################################################# # check_form_date - checks the form date and returns corrected values # #-------------------------------------------------------------------------------# # check_form_date($month,$year,[$newsID]) # # # # If $newsID is given, returns the posting month/year of the news article. # # If insufficient information is given, the current month/year is returned. # # Returns month and year. # # # # Usage: # # ($month, $year) = check_form_date($month,$year,$newsID) # # # ################################################################################# sub check_form_date { my ($nmonth, $nyear, $newsID) = @_; if($newsID) { lock_tables('READ', $MD_NEWS); my ($ref) = db_select('epoch',$MD_NEWS,"IDnumber = '$newsID'"); (undef,undef,undef,undef,$nmonth, $nyear) = utc_epoch2date($ref->{'epoch'}); db_end(); unlock_tables(); } elsif($nmonth > 12 || $nmonth < 1 || $nmonth !~ /^[0-9]+$/ || $nyear !~ /^[0-9]+$/) { (undef,undef,undef,undef,$nmonth, $nyear) = utc_epoch2date(time()); } return ($nmonth, $nyear); }