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=`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'
70 my $sth = $dbh->prepare($query);
73 while (my @array = $sth->fetchrow_array ()) {
74 push @results_array, \@array ;
76 $sth->execute() or die "Problems with the query '$query' in DB";
77 $sth->finish() or die "Problems with the query '$query' in DB";
78 $dbh->commit or die $dbh->errstr;
80 foreach my $newsnotapprob (@results_array) {
82 my ($group_name, $summary, $details) = @{$newsnotapprob};
83 my $title = "$group_name: $summary\n";
84 $emailformatted .= autoformat $title, { all => 1, left=>0, right=>78 };
85 $emailformatted .= "----------------------------------------------------------------------\n";
86 $emailformatted .= autoformat $details, { all => 1, left=>8, right=>78 };
87 $emailformatted .= "\n\n";
91 if ($debug) {print STDERR "Sending the news not approved.\n"};
92 $emailformatted .= "Please visit: http://$sys_default_domain/news/admin/";
93 $emailformatted .= "\n\n";
94 my %mail = ( To => "$server_admin",
95 From => "noreply\@$sys_default_domain",
96 Subject => "$sys_name pending news",
97 Message => $emailformatted
99 $mail{'Content-type'} = 'text/plain; charset="UTF-8"';
100 sendmail(%mail) or die $Mail::Sendmail::error;
103 if ($debug) {print STDERR "No news to approved.\n"};
106 if ($debug) {print STDERR "get_news_notapproved process finished ok\n"};
110 #-------------------------------------------------------------------------------
113 print STDERR "usage: get_news_notapproved.pl [--debug]\n";