[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 #!/usr/bin/perl 2 3 # Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 # 19 # $Id: import-csv.pl,v 1.1 2004/02/07 18:06:43 rodolphe Exp $ 20 # $Source: /cvsroot/dolibarr/dolibarr/scripts/import-csv.pl,v $ 21 22 $SYSLOG_LEVEL = 'local3'; 23 24 use strict; 25 use vars qw($SYSLOG_LEVEL); 26 use DBI; 27 use Net::SMTP; 28 use Text::Wrap; 29 use Getopt::Long; 30 use Sys::Syslog qw(:DEFAULT setlogsock); 31 Getopt::Long::Configure("bundling"); 32 33 my($debug,$verbose, $help) = (0,0,0); 34 35 exit unless GetOptions("v+", \$verbose, "debug", \$debug, "help", \$help); 36 37 print_help() if $help; 38 39 my($dbh, $sth, $hsr, $sthi, $i, $sqli, $sql, $stha, $digest); 40 41 print "Running in verbose mode level $verbose\n" if $verbose>0; 42 43 my $sl = Sys::Syslog::setlogsock('unix'); 44 $sl = Sys::Syslog::openlog('send-newsletter.pl', 'pid', $SYSLOG_LEVEL); 45 $sl = Sys::Syslog::syslog('info', 'Start'); 46 47 print "Start\n" if $verbose>0; 48 49 print "DBI connection : open\n" if $verbose>3; 50 $dbh = DBI->connect() || die $DBI::errstr; 51 52 my $file = "/tmp/importf.csv"; 53 my @line; 54 my $i = 0; 55 my ($civ, $rubrique,$civilite,$nom,$prenom,$num,$type,$voie,$complement,$cp,$ville,$tel,$fax,$mobile,$email,$web,$commentaire); 56 open (FH, "<$file") || die "can't open $file: $!"; 57 while (<FH>) 58 { 59 $civ = 0; 60 $civilite = ''; 61 62 s|\'|\\\'|g; 63 @line = split /\t/, $_; 64 $rubrique = $line[0]; 65 $civilite = $line[1]; 66 $nom = $line[2]; 67 $prenom = $line[3]; 68 $num = $line[4]; 69 $type = $line[5]; 70 $voie = $line[6]; 71 $complement = $line[7]; 72 $cp = $line[8]; 73 $ville = $line[9]; 74 $tel = $line[10]; 75 $fax = $line[11]; 76 $mobile = $line[12]; 77 $email = $line[13]; 78 $web = $line[14]; 79 $commentaire = $line[15]; 80 81 if ($i > 0 ) 82 { 83 my $sql = "INSERT INTO llx_societe (datec, client, nom, address,cp,ville,tel,fax,url,note,rubrique,fk_user_creat) "; 84 $sql .= "VALUES (now(),2,'$nom $prenom','$num $type $voie\n$complement','$cp','$ville','$tel','$fax','$web','$commentaire','$rubrique',1)"; 85 86 $stha = $dbh->prepare($sql); 87 $stha->execute; 88 89 $sql = "SELECT MAX(idp) as co FROM llx_societe"; 90 $sth = $dbh->prepare("$sql") || die $dbh->errstr ; 91 if ( $sth->execute ) { 92 if ( $sth->rows ) { 93 $hsr = $sth->fetchrow_hashref; 94 } 95 $sth->finish; 96 } 97 98 if ($civilite = 'Mme') 99 { 100 $civ = 2 ; 101 } 102 if ($civilite = 'M') 103 { 104 $civ = 1 ; 105 } 106 107 if ($civ > 0) 108 { 109 my $sql = "INSERT INTO llx_socpeople (datec, fk_soc, name, firstname,phone,fax,email, fk_user) "; 110 $sql .= "VALUES (now(),".$hsr->{"co"}.",'$nom', '$prenom','$tel','$fax','$email',1)"; 111 112 $stha = $dbh->prepare($sql); 113 $stha->execute; 114 } 115 116 117 } 118 print $i . " "; 119 $i++; 120 } 121 close (FH); 122 123 print "DBI connection : close\n" if $verbose>3; 124 125 if ($dbh) 126 { 127 $dbh->disconnect; 128 } 129 130 print "End\n" if $verbose>0; 131 # 132 # 133 # 134 135 136 $sl = Sys::Syslog::syslog('info', 'End'); 137 138 Sys::Syslog::closelog(); 139 140 # 141 # 142 # 143 # 144 # 145 sub print_help { 146 print "Usage send-newsletter.pl [-v]\n"; 147 exit 0; 148 } 149 150 151 __END__ 152 # Below is the documentation for the script. 153 154 =head1 NAME 155 156 send-newsletter.pl - 157 158 =head1 SYNOPSIS 159 160 send-newsletter.pl [-v] 161 162 =head1 DESCRIPTION 163 164 send-newsletter.pl send newsletter from DB 165 166 =head1 OPTIONS 167 168 =over 169 170 =back 171 172 =head1 AUTHOR 173 174 Rodolphe Quiedeville (rodolphe@quiedeville.org) 175 176 =cut 177
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |