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 chomp($server_admin=`/usr/share/gforge/bin/forge_get_config admin_email`);
52 # Start to get de News
53 #-------------------------------------------------------------------------------
55 if ($debug) {print STDERR "Getting the news not approved.\n"};
58 $dbh->{AutoCommit} = 0;
59 $dbh->{RaiseError} = 1;
61 my $old_date = time()-60*60*24*30;
62 my $query = "SELECT group_name,summary,details
63 FROM news_bytes n, groups g
65 AND n.group_id=g.group_id
66 AND n.post_date > '$old_date'
71 my $sth = $dbh->prepare($query);
74 while (my @array = $sth->fetchrow_array ()) {
75 push @results_array, \@array ;
77 $sth->execute() or die "Problems with the query '$query' in DB";
78 $sth->finish() or die "Problems with the query '$query' in DB";
79 $dbh->commit or die $dbh->errstr;
81 foreach my $newsnotapprob (@results_array) {
83 my ($group_name, $summary, $details) = @{$newsnotapprob};
84 my $title = "$group_name: $summary\n";
85 $emailformatted .= autoformat $title, { all => 1, left=>0, right=>78 };
86 $emailformatted .= "----------------------------------------------------------------------\n";
87 $emailformatted .= autoformat $details, { all => 1, left=>8, right=>78 };
88 $emailformatted .= "\n\n";
92 if ($debug) {print STDERR "Sending the news not approved.\n"};
93 $emailformatted .= "Please visit: http://$sys_default_domain/news/admin/";
94 $emailformatted .= "\n\n";
95 my %mail = ( To => "$server_admin",
96 From => "noreply\@$sys_default_domain",
97 Subject => "$sys_name pending news",
98 Message => $emailformatted
100 $mail{'Content-type'} = 'text/plain; charset="UTF-8"';
101 sendmail(%mail) or die $Mail::Sendmail::error;
104 if ($debug) {print STDERR "No news to approved.\n"};
107 if ($debug) {print STDERR "get_news_notapproved process finished ok\n"};
111 #-------------------------------------------------------------------------------
114 print STDERR "usage: get_news_notapproved.pl [--debug]\n";