3 # get_news_notapproved.pl: script to get the news not yet approved
4 # by Vicente J. Ruiz Jurado (vjrj AT ourproject.org) Apr-2004
6 # depends: libgetopt-mixed-perl (Getopt::Long), libdbi-perl (DBI),
7 # libtext-autoformat-perl (Text::Autoformat)
8 # libmail-sendmail-perl (Mail::Sendmail)
12 use Getopt::Long qw(:config require_order);
17 require("/usr/share/gforge/lib/include.pl"); # Include all predefined functions
19 use vars qw/ $server_admin $sys_name $sys_default_domain /;
22 #-------------------------------------------------------------------------------
23 use vars qw/ $dbh / ; # Predeclaration of global vars
26 #-------------------------------------------------------------------------------
39 #-------------------------------------------------------------------------------
41 my $resultOptions = GetOptions(
45 unless (($debug && $resultOptions == 2) || ($resultOptions == 1)) {
50 # Start to get de News
51 #-------------------------------------------------------------------------------
53 if ($debug) {print STDERR "Getting the news not approved.\n"};
56 $dbh->{AutoCommit} = 0;
57 $dbh->{RaiseError} = 1;
59 my $old_date = time()-60*60*24*30;
60 my $query = "SELECT group_name,summary,details
61 FROM news_bytes n, groups g
63 AND n.group_id=g.group_id
64 AND n.post_date > '$old_date'
69 my $sth = $dbh->prepare($query);
72 while (my @array = $sth->fetchrow_array ()) {
73 push @results_array, \@array ;
75 $sth->execute() or die "Problems with the query '$query' in DB";
76 $sth->finish() or die "Problems with the query '$query' in DB";
77 $dbh->commit or die $dbh->errstr;
79 foreach my $newsnotapprob (@results_array) {
81 my ($group_name, $summary, $details) = @{$newsnotapprob};
82 my $title = "$group_name: $summary\n";
83 $emailformatted .= autoformat $title, { all => 1, left=>0, right=>78 };
84 $emailformatted .= "----------------------------------------------------------------------\n";
85 $emailformatted .= autoformat $details, { all => 1, left=>8, right=>78 };
86 $emailformatted .= "\n\n";
90 if ($debug) {print STDERR "Sending the news not approved.\n"};
91 $emailformatted .= "Please visit: http://$sys_default_domain/news/admin/";
92 $emailformatted .= "\n\n";
93 my %mail = ( To => "$server_admin",
94 From => "noreply\@$sys_default_domain",
95 Subject => "$sys_name pending news",
96 Message => $emailformatted
98 $mail{'Content-type'} = 'text/plain; charset="UTF-8"';
99 sendmail(%mail) or die $Mail::Sendmail::error;
102 if ($debug) {print STDERR "No news to approved.\n"};
105 if ($debug) {print STDERR "get_news_notapproved process finished ok\n"};
109 #-------------------------------------------------------------------------------
112 print STDERR "usage: get_news_notapproved.pl [--debug]\n";