From 6f8985cc36d16f57236033ab6c538a728af7c2d4 Mon Sep 17 00:00:00 2001 From: jlb Date: Thu, 9 Jan 2003 16:28:02 +0000 Subject: [PATCH] script d'inscription/desinscription des adherents a une mailing-list (en test pour l'instant) --- scripts/adherents/adh2list.pl | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 scripts/adherents/adh2list.pl diff --git a/scripts/adherents/adh2list.pl b/scripts/adherents/adh2list.pl new file mode 100755 index 00000000000..ed8d4732f59 --- /dev/null +++ b/scripts/adherents/adh2list.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +# Copyright (C) 2002 Rodolphe Quiedeville +# +# 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 in the 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. + +# +# Remember to : export DBI_DSN="dbi:mysql:dbname=dolibarr" +# +use DBI; +use strict; +# get the command line option +use Getopt::Long; + +# command line option hash table +my %optctl=(); +# get command line options +GetOptions(\%optctl,"help!","host=s","db=s","user=s","pass=s","ml=s","type=s"); +if (defined $optctl{'help'}){ + &usage(); +} +my $host=$optctl{'host'}||'localhost'; +my $dbname=$optctl{'db'}||'dolibarr'; +my $user=$optctl{'user'}||'dolibarr'; +my $pass=$optctl{'pass'}||''; +my $type=$optctl{'type'}||'mysql'; +my $ml=$optctl{'ml'}||&usage(); +my @adh=(); +my @ml_adh=(); + +my $dbh = DBI->connect("dbi:$type:dbname=$dbname;host=$host",$user,$pass) || die $DBI::errstr ; + +my $sql = 'SELECT email FROM llx_adherent WHERE statut=1'; + +my $sth = $dbh->prepare("$sql") || die $dbh->errstr ; +$sth->execute; + +# get emails of adherents +while (my @row = $sth->fetchrow_array ){ + print int($row[0]); + push (@adh,$row[0]); +} + +# get emails of mailing-list suscribers +@ml_adh=`/usr/sbin/list_members $ml`; +chomp(@ml_adh); + +# do the diff +foreach my $adh (@adh){ + if (!grep(/^$adh$/,@ml_adh)){ + # user not subscribed + print "register $adh : echo $adh | /usr/sbin/add_members -n - $ml\n"; + } +} + +# unsubcribe user not adherent +foreach my $subs (@ml_adh){ + if (!grep(/^$subs$/,@adh)){ + # unsubscrib user + print "unsubscribe $subs : /usr/sbin/remove_members $ml $subs\n"; + } +} + +$dbh->disconnect(); + +sub usage{ + print "$0 [--help] [--host] [--db] [--user] [--pass] --ml=mailinglist\n"; + print " ml is for mailing-list. others options are for database"; + print ""; + exit (1); +}