| Livres | ';
@@ -142,9 +183,6 @@ else
/* ************************************************************************** */
print '
';
-print '| - | ';
-print '- | ';
-print '- | ';
if ($action == 'create')
{
@@ -154,7 +192,20 @@ else
{
print '[Editer] | ';
}
-print '- | ';
+
+print '- | ';
+print '- | ';
+print '- | ';
+
+if(sizeof($livres)==0 && $id)
+{
+ print '[Supprimer] | ';
+}
+else
+{
+ print '[Supprimer] | ';
+}
+
print ' ';
diff --git a/htdocs/boutique/client/index.php b/htdocs/boutique/client/index.php
index 039286790f2..d6792e7531c 100644
--- a/htdocs/boutique/client/index.php
+++ b/htdocs/boutique/client/index.php
@@ -37,12 +37,10 @@ if ($page == -1) { $page = 0 ; }
$limit = $conf->liste_limit;
$offset = $limit * $page ;
-print_barre_liste("Liste des notifications", $page, $PHP_SELF);
+print_barre_liste("Liste des clients", $page, $PHP_SELF);
-$sql = "SELECT c.customers_id, c.customers_lastname, c.customers_firstname";
-$sql .= " FROM ".DB_NAME_OSC.".products_notifications as n,".DB_NAME_OSC.".products_description as p";
-$sql .= ",".DB_NAME_OSC.".customers as c";
-$sql .= " WHERE n.customers_id = c.customers_id AND p.products_id=n.products_id";
+$sql = "SELECT c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_email_address, c.customers_newsletter";
+$sql .= " FROM ".DB_NAME_OSC.".customers as c";
$sql .= " ORDER BY $sortfield $sortorder ";
$sql .= $db->plimit( $limit ,$offset);
@@ -52,8 +50,10 @@ if ( $db->query($sql) )
$i = 0;
print "";
print "| ";
- print_liste_field_titre("Nom",$PHP_SELF, "e.nom");
- print " | ";
+ print_liste_field_titre("Prénom",$PHP_SELF, "c.customers_firstname");
+ print "";
+ print_liste_field_titre("Nom",$PHP_SELF, "c.customers_lastname");
+ print ' | Email | Newsletter | ';
print " \n";
$var=True;
while ($i < $num)
@@ -61,7 +61,10 @@ if ( $db->query($sql) )
$objp = $db->fetch_object( $i);
$var=!$var;
print "";
- print "| rowid\">$objp->nom | \n";
+ print ''.$objp->customers_firstname." | \n";
+ print ''.$objp->customers_lastname." | \n";
+ print "$objp->customers_email_address | \n";
+ print "$objp->customers_newsletter | \n";
print " \n";
$i++;
}
diff --git a/htdocs/boutique/editeur/editeur.class.php b/htdocs/boutique/editeur/editeur.class.php
index 8453be3d0d0..60e66b3ba72 100644
--- a/htdocs/boutique/editeur/editeur.class.php
+++ b/htdocs/boutique/editeur/editeur.class.php
@@ -130,25 +130,56 @@ class Editeur {
return $result;
}
+ /*
+ *
+ *
+ *
+ */
+ Function liste_livre()
+ {
+ $ga = array();
+ $sql = "SELECT a.rowid, a.title FROM llx_livre as a";
+ $sql .= " WHERE a.fk_editeur = ".$this->id;
+ $sql .= " ORDER BY a.title";
+ if ($this->db->query($sql) )
+ {
+ $nump = $this->db->num_rows();
+
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object($i);
+
+ $ga[$obj->rowid] = $obj->title;
+ $i++;
+ }
+ }
+ return $ga;
+ }
+ else
+ {
+ print $this->db->error();
+ }
+ }
/*
*
*
*/
- Function delete($user) {
+ Function delete() {
- $sql = "DELETE FROM ".DB_NAME_OSC.".products WHERE products_id = $idosc ";
+ $livres = $this->liste_livre();
+
+ if (sizeof($livres) == 0)
+ {
+ $sql = "DELETE FROM llx_editeur WHERE rowid = $this->id ";
+ $return = $this->db->query($sql) ;
+ }
- $sql = "DELETE FROM ".DB_NAME_OSC.".products_to_categories WHERE products_id = $idosc";
- $sql = "DELETE FROM ".DB_NAME_OSC.".products_description WHERE products_id = $idosc";
-
- $sql = "DELETE FROM llx_livre WHERE rowid = $id";
-
-
}
-
-
}
?>
diff --git a/htdocs/boutique/editeur/fiche.php b/htdocs/boutique/editeur/fiche.php
index 5c812afd26f..dd46feed371 100644
--- a/htdocs/boutique/editeur/fiche.php
+++ b/htdocs/boutique/editeur/fiche.php
@@ -22,8 +22,6 @@
require("./pre.inc.php");
-llxHeader();
-
$db = new Db();
if ($action == 'add') {
@@ -40,8 +38,8 @@ if ($action == 'addga') {
$editeur->linkga($id, $ga);
}
-
-if ($action == 'update' && !$cancel) {
+if ($action == 'update' && !$cancel)
+{
$editeur = new Editeur($db);
$editeur->nom = $nom;
@@ -49,6 +47,16 @@ if ($action == 'update' && !$cancel) {
$editeur->update($id, $user);
}
+if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes)
+{
+ $editeur = new Editeur($db);
+ $result = $editeur->fetch($id);
+ $editeur->delete();
+ Header("Location: index.php");
+}
+
+llxHeader();
+
/*
*
*
@@ -63,7 +71,7 @@ if ($action == 'create')
print '';
print '';
@@ -80,6 +88,39 @@ else
if ( $result )
{
+ $livres = $editeur->liste_livre();
+
+ /*
+ * Confirmation de la suppression de l'editeur
+ *
+ */
+
+ if ($action == 'delete')
+ {
+
+ print '\n";
+ }
+
+ /*
+ * Edition de la fiche
+ *
+ */
+
+
if ($action == 'edit')
{
print 'Edition de la fiche Editeur : '.$editeur->titre.' ';
@@ -89,7 +130,7 @@ else
print '';
print "";
- print '| Nom | | ';
+ print 'Nom | | ';
print ' | | ';
@@ -104,7 +145,16 @@ else
print '';
print "";
- print '| Nom | '.$editeur->nom.' | ';
+ print 'Nom | '.$editeur->nom.' | ';
+
+ print '| Livres | ';
+
+ foreach ($livres as $key => $value)
+ {
+ print ''.$value." \n";
+ }
+ print " | ";
+
print " ";
@@ -130,9 +180,6 @@ else
/* ************************************************************************** */
print '
';
-print '| - | ';
-print '- | ';
-print '- | ';
if ($action == 'create')
{
@@ -142,7 +189,21 @@ else
{
print '[Editer] | ';
}
-print '- | ';
+
+print '- | ';
+print '- | ';
+print '- | ';
+
+if(sizeof($livres)==0 && $id)
+{
+ print '[Supprimer] | ';
+}
+else
+{
+ print '[Supprimer] | ';
+}
+
+
print ' ';
diff --git a/htdocs/boutique/livre/fiche.php b/htdocs/boutique/livre/fiche.php
index c164a621bc7..895d62359e6 100644
--- a/htdocs/boutique/livre/fiche.php
+++ b/htdocs/boutique/livre/fiche.php
@@ -293,11 +293,6 @@ else
/* ************************************************************************** */
print '
';
-print '| - | ';
-
-print '[Update Osc] | ';
-
-print '- | ';
if ($action == 'create')
{
@@ -307,6 +302,10 @@ else
{
print '[Editer] | ';
}
+
+print '- | ';
+print '[Update Osc] | ';
+print '- | ';
print '- | ';
print ' ';
diff --git a/htdocs/boutique/livre/livre.class.php b/htdocs/boutique/livre/livre.class.php
index f48252b2b10..a4929b9f68a 100644
--- a/htdocs/boutique/livre/livre.class.php
+++ b/htdocs/boutique/livre/livre.class.php
@@ -335,6 +335,7 @@ class Livre {
{
$sql = "UPDATE ".DB_NAME_OSC.".products ";
$sql .= "SET products_model = '".$this->ref."'";
+ $sql .= ", products_image = '".strtolower($this->ref).".jpg'";
$sql .= ", products_price = ".$this->price."";
$sql .= " WHERE products_id = " . $this->oscid;
@@ -345,7 +346,7 @@ class Livre {
}
else
{
- print $this->db->error() . ' in ' . $sql;
+ print $this->db->error() . ' in ' . $sql;
}
}
else
@@ -409,11 +410,14 @@ class Livre {
$sql .= " WHERE rowid = " . $id;
- if ( $this->db->query($sql) ) {
- return 1;
- } else {
- print $this->db->error() . ' in ' . $sql;
- }
+ if ( $this->db->query($sql) )
+ {
+ return 1;
+ }
+ else
+ {
+ print $this->db->error() . ' in ' . $sql;
+ }
}
/*
*
diff --git a/htdocs/boutique/newsletter/fiche.php b/htdocs/boutique/newsletter/fiche.php
index e303f00ac2e..af10fca20e9 100644
--- a/htdocs/boutique/newsletter/fiche.php
+++ b/htdocs/boutique/newsletter/fiche.php
@@ -27,7 +27,11 @@ $db = new Db();
if ($action == 'add') {
$newsletter = new Newsletter($db);
- $newsletter->nom = $nom;
+ $newsletter->email_subject = $HTTP_POST_VARS["email_subject"];
+ $newsletter->email_from_name = $HTTP_POST_VARS["email_from_name"];
+ $newsletter->email_from_email = $HTTP_POST_VARS["email_from_email"];
+ $newsletter->email_replyto = $HTTP_POST_VARS["email_replyto"];
+ $newsletter->email_body = $HTTP_POST_VARS["email_body"];
$id = $newsletter->create($user);
}
@@ -42,7 +46,11 @@ if ($action == 'update' && !$cancel)
{
$newsletter = new Newsletter($db);
- $newsletter->nom = $nom;
+ $newsletter->email_subject = $HTTP_POST_VARS["email_subject"];
+ $newsletter->email_from_name = $HTTP_POST_VARS["email_from_name"];
+ $newsletter->email_from_email = $HTTP_POST_VARS["email_from_email"];
+ $newsletter->email_replyto = $HTTP_POST_VARS["email_replyto"];
+ $newsletter->email_body = $HTTP_POST_VARS["email_body"];
$newsletter->update($id, $user);
}
@@ -55,6 +63,21 @@ if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"]
Header("Location: index.php");
}
+if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes)
+{
+ $newsletter = new Newsletter($db);
+ $result = $newsletter->fetch($id);
+ $newsletter->validate($user);
+}
+
+if ($HTTP_POST_VARS["action"] == 'confirm_send' && $HTTP_POST_VARS["confirm"] == yes)
+{
+ $newsletter = new Newsletter($db);
+ $result = $newsletter->fetch($id);
+ $newsletter->send($user);
+}
+
+
llxHeader();
/*
@@ -70,14 +93,13 @@ if ($action == 'create')
print 'Nouvelle Newsletter ';
print '';
print '';
@@ -117,6 +139,41 @@ else
print ' ';
print "\n";
}
+
+ /*
+ * Confirmation de la validation
+ *
+ */
+ if ($action == 'valid')
+ {
+ $htmls = new Form($db);
+ $htmls->form_confirm($PHP_SELF.'?id='.$id,
+ "Valider une newsletter",
+ "Etes-vous sûr de vouloir valider cette newsletter ?");
+ }
+ /*
+ *
+ *
+ */
+ if ($action == 'send')
+ {
+
+ print '\n";
+ }
/*
* Edition de la fiche
@@ -132,9 +189,16 @@ else
print '';
print '';
- print "";
- print '| Nom | | ';
+ print ' | Emetteur nom | | ';
+ print '| Emetteur email | | ';
+ print '| Email de réponse | | ';
+
+ print "";
+ print '| Sujet | ';
+ print ' | ';
+
+ print ' | Texte | | ';
print '| | ';
@@ -144,23 +208,35 @@ else
}
+ /*
+ * Affichage de la fiche
+ *
+ */
+
print 'Fiche Newsletter : '.$newsletter->titre.' ';
print '';
- print "";
- print '| Nom | '.$newsletter->nom.' | ';
- print '| Livres | ';
-
- foreach ($livres as $key => $value)
- {
- print ''.$value." \n";
- }
- print " | ";
+ print '| Emetteur nom | '.$newsletter->email_from_name.' | ';
+ print '| Emetteur email | '.$newsletter->email_from_email.' | ';
+ print '| Email de réponse | '.$newsletter->email_replyto.' | ';
+ print '| Nom | '.$newsletter->email_subject.' | ';
+ print '| Texte | '.nl2br($newsletter->email_body).' | ';
print " ";
+ if ($newsletter->status == 3)
+ {
+ print " ";
+ print '';
+ print '| Début de l\'envoi | '.strftime("%d %B %Y %H:%M:%S",$newsletter->date_send_begin).' | ';
+ print 'Nombre de mails envoyés | '.$newsletter->nbsent.' | ';
+
+ print '| Fin de l\'envoi | '.strftime("%d %B %Y %H:%M:%S",$newsletter->date_send_end).' | ';
+ print 'Nombre de mails en erreur | '.$newsletter->nberror.' | ';
+ print " ";
+ }
}
else
@@ -183,27 +259,47 @@ else
/* ************************************************************************** */
print '
';
-print '| - | ';
if ($action == 'create')
{
print '- | ';
}
-else
+elseif ($newsletter->status == 0)
{
print '[Editer] | ';
}
+else
+{
+ print '- | ';
+}
+
+if ($newsletter->status == 0 && $id)
+{
+ print '[Valider] | ';
+}
+else
+{
+ print '- | ';
+}
+
+if ($newsletter->status == 1)
+{
+ print '[Envoyer] | ';
+}
+else
+{
+ print '- | ';
+}
-print '- | ';
print '- | ';
-if(sizeof($livres)==0 && $id)
+if($id && $newsletter->status == 0)
{
print '[Supprimer] | ';
}
else
{
- print '[Supprimer] | ';
+ print '- | ';
}
diff --git a/htdocs/boutique/newsletter/newsletter.class.php b/htdocs/boutique/newsletter/newsletter.class.php
new file mode 100644
index 00000000000..c8eeb7f7d72
--- /dev/null
+++ b/htdocs/boutique/newsletter/newsletter.class.php
@@ -0,0 +1,217 @@
+
+ *
+ * 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.
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+class Newsletter {
+ var $db ;
+
+ var $id ;
+ var $email_from_name;
+ var $email_from_email;
+ var $email_replyto;
+ var $email_body;
+ var $status;
+
+ Function Newsletter($DB, $id=0) {
+ $this->db = $DB;
+ $this->id = $id ;
+
+ $statustext[0] = "Rédaction";
+ $statustext[1] = "Validé";
+ $statustext[2] = "Envoi en cours";
+ $statustext[3] = "Envoyé";
+ $statustext[4] = "Non envoyé (erreur)";
+
+ }
+ /*
+ *
+ *
+ *
+ */
+ Function create($user) {
+
+ $sql = "INSERT INTO llx_newsletter (fk_user_author, datec, nbsent) VALUES (".$user->id.",now(), 0)";
+
+ if ($this->db->query($sql) )
+ {
+ $id = $this->db->last_insert_id();
+
+ if ( $this->update($id, $user) )
+ {
+ return $id;
+ }
+ }
+ }
+
+ /*
+ *
+ *
+ */
+ Function update($id, $user)
+ {
+
+ if (strlen(trim($this->email_replyto))==0)
+ {
+ $this->email_replyto = $this->email_from_email;
+ }
+ $this->target = 1;
+
+ $this->target_sql = $this->build_sql($this->target);
+
+ $sql = "UPDATE llx_newsletter ";
+ $sql .= " SET email_subject = '" . trim($this->email_subject) ."'";
+ $sql .= ", email_from_name = '" . trim($this->email_from_name) ."'";
+ $sql .= ", email_from_email = '" . trim($this->email_from_email) ."'";
+ $sql .= ", email_replyto = '" . trim($this->email_replyto) ."'";
+ $sql .= ", email_body= '" . trim($this->email_body) ."'";
+ $sql .= ", target = ".$this->target;
+ $sql .= ", sql_target = '".$this->target_sql."'";
+ $sql .= " WHERE rowid = " . $id;
+
+ if ( $this->db->query($sql) ) {
+ return 1;
+ } else {
+ print $this->db->error() . ' in ' . $sql;
+ }
+ }
+ /*
+ *
+ *
+ *
+ */
+ Function fetch ($id) {
+
+ $sql = "SELECT rowid, email_subject, email_from_name, email_from_email, email_replyto, email_body, target, sql_target, status, date_send_request,".$this->db->pdate("date_send_begin")." as date_send_begin,".$this->db->pdate("date_send_end")." as date_send_end, nbsent, nberror";
+ $sql .= " FROM llx_newsletter WHERE rowid=$id";
+
+ $result = $this->db->query($sql) ;
+
+ if ( $result )
+ {
+ $result = $this->db->fetch_array();
+
+ $this->id = $result["rowid"];
+ $this->email_subject = stripslashes($result["email_subject"]);
+ $this->email_from_name = stripslashes($result["email_from_name"]);
+ $this->email_from_email = stripslashes($result["email_from_email"]);
+ $this->email_replyto = stripslashes($result["email_replyto"]);
+ $this->email_body = stripslashes($result["email_body"]);
+ $this->status = $result["status"];
+ $this->nbsent = $result["nbsent"];
+ $this->nberror = $result["nberror"];
+ $this->date_send_end = $result["date_send_end"];
+ $this->date_send_begin = $result["date_send_begin"];
+
+ $this->status_text = $statustext[$this->status];
+
+ $this->db->free();
+ }
+ else
+ {
+ print $this->db->error();
+ }
+
+ return $result;
+ }
+ /*
+ *
+ *
+ *
+ */
+ Function liste_array ()
+ {
+ $ga = array();
+
+ $sql = "SELECT rowid, nom FROM llx_editeur ORDER BY nom";
+
+ if ($this->db->query($sql) )
+ {
+ $nump = $this->db->num_rows();
+
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object($i);
+
+ $ga[$obj->rowid] = $obj->nom;
+ $i++;
+ }
+ }
+ return $ga;
+ }
+ else
+ {
+ print $this->db->error();
+ }
+
+ }
+ /*
+ *
+ *
+ *
+ */
+ Function validate($user) {
+
+ $sql = "UPDATE llx_newsletter SET status=1, fk_user_valid = $user->id WHERE rowid = $this->id";
+ $return = $this->db->query($sql) ;
+
+ }
+ /*
+ *
+ *
+ */
+ Function send($user) {
+
+ $sql = "UPDATE llx_newsletter SET status=2, date_send_request=now() WHERE rowid = $this->id";
+ $return = $this->db->query($sql) ;
+
+ }
+ /*
+ *
+ *
+ */
+ Function build_sql($target)
+ {
+ if ($target == 1)
+ {
+
+ $sql = "SELECT c.customers_lastname as name, c.customers_firstname as firstname, c.customers_email_address as email";
+ $sql .= " FROM ".DB_NAME_OSC.".customers as c";
+ $sql .= " WHERE c.customers_newsletter=1";
+
+ }
+
+ return $sql;
+ }
+ /*
+ *
+ *
+ */
+ Function delete() {
+
+ $sql = "DELETE FROM llx_newsletter WHERE rowid = $this->id ";
+ $return = $this->db->query($sql) ;
+
+ }
+}
+?>
diff --git a/htdocs/boutique/notification/index.php b/htdocs/boutique/notification/index.php
index 98fe893b1fd..3de692a0bbe 100644
--- a/htdocs/boutique/notification/index.php
+++ b/htdocs/boutique/notification/index.php
@@ -26,7 +26,7 @@ llxHeader();
$db = new Db();
if ($sortfield == "") {
- $sortfield="lower(e.nom)";
+ $sortfield="lower(c.customers_lastname)";
}
if ($sortorder == "") {
$sortorder="ASC";
@@ -37,30 +37,37 @@ if ($page == -1) { $page = 0 ; }
$limit = $conf->liste_limit;
$offset = $limit * $page ;
-print_barre_liste("Liste des Editeurs", $page, $PHP_SELF);
+print_barre_liste("Liste des notifications", $page, $PHP_SELF);
-$sql = "SELECT e.rowid, e.nom FROM llx_editeur as e";
-
+$sql = "SELECT c.customers_id, c.customers_lastname, c.customers_firstname, p.products_name, p.products_id";
+$sql .= " FROM ".DB_NAME_OSC.".products_notifications as n,".DB_NAME_OSC.".products_description as p";
+$sql .= ",".DB_NAME_OSC.".customers as c";
+$sql .= " WHERE n.customers_id = c.customers_id AND p.products_id=n.products_id";
+$sql .= " AND p.language_id = ".OSC_LANGUAGE_ID;
$sql .= " ORDER BY $sortfield $sortorder ";
$sql .= $db->plimit( $limit ,$offset);
-if ( $db->query($sql) ) {
+if ( $db->query($sql) )
+{
$num = $db->num_rows();
$i = 0;
print "";
print "| ";
- print_liste_field_titre("Nom",$PHP_SELF, "e.nom");
+ print_liste_field_titre("Client",$PHP_SELF, "c.customers_lastname");
print " | ";
+ print "Produit | ";
print " \n";
$var=True;
- while ($i < $num) {
- $objp = $db->fetch_object( $i);
- $var=!$var;
- print "";
- print "| rowid\">$objp->nom | \n";
- print " \n";
- $i++;
- }
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object( $i);
+ $var=!$var;
+ print "";
+ print "| rowid\">$objp->customers_firstname $objp->customers_lastname | \n";
+ print ''.$objp->products_name." | ";
+ print " \n";
+ $i++;
+ }
print " ";
$db->free();
}
diff --git a/htdocs/lib/functions.inc.php3 b/htdocs/lib/functions.inc.php3
index 07b03f41ff6..e0ad366d639 100644
--- a/htdocs/lib/functions.inc.php3
+++ b/htdocs/lib/functions.inc.php3
@@ -254,7 +254,7 @@ function print_titre($titre)
*
*
*/
-function print_barre_liste($titre,$page,$file,$options='')
+function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='')
{
global $conf;
print '';
@@ -268,6 +268,18 @@ function print_barre_liste($titre,$page,$file,$options='')
print ''.$titre.' | ';
}
print '';
+
+ if (strlen($sortfield))
+ {
+ $options .= "&sortfield=$sortfield";
+ }
+
+ if (strlen($sortorder))
+ {
+ $options .= "&sortorder=$sortorder";
+ }
+
+
if ($page > 0)
{
print ' ';
diff --git a/scripts/newsletter-send.pl b/scripts/newsletter-send.pl
index 38cb9e826f2..82fbcd1b790 100755
--- a/scripts/newsletter-send.pl
+++ b/scripts/newsletter-send.pl
@@ -24,6 +24,7 @@ $SYSLOG_LEVEL = 'local3';
use strict;
use vars qw($SYSLOG_LEVEL);
use DBI;
+use Net::SMTP;
use Text::Wrap;
use Getopt::Long;
use Sys::Syslog qw(:DEFAULT setlogsock);
@@ -41,7 +42,7 @@ unless (defined $ENV{"DBI_DSN"}) {
}
-my($dbh, $sth, $sthi, $i, $sqli, $sql, $stha, $digest, $mesg);
+my($dbh, $sth, $sthi, $i, $sqli, $sql, $stha, $digest);
print "Running in verbose mode level $verbose\n" if $verbose>0;
@@ -49,9 +50,9 @@ my $sl = Sys::Syslog::setlogsock('unix');
$sl = Sys::Syslog::openlog('send-newsletter.pl', 'pid', $SYSLOG_LEVEL);
$sl = Sys::Syslog::syslog('info', 'Start');
-print "Start on " if $verbose>0;
+print "Start\n" if $verbose>0;
-print "Open DBI connection\n" if $verbose>3;
+print "DBI connection : open\n" if $verbose>3;
$dbh = DBI->connect() || die $DBI::errstr;
#
@@ -74,21 +75,19 @@ $dbh = DBI->connect() || die $DBI::errstr;
my $sqli = "SELECT rowid, email_subject, email_from_name, email_from_email, email_replyto, email_body, target, sql_target, status, date_send_request, date_send_begin, date_send_end, nbsent";
-$sqli .= " FROM llx_newsletter WHERE status=1 AND date_send_request < now()";
+$sqli .= " FROM llx_newsletter WHERE status=2 AND date_send_request < now()";
$sthi = $dbh->prepare($sqli);
$sthi->execute;
my ($hsri);
-while ( $hsri = $sthi->fetchrow_hashref )
-{
+while ( $hsri = $sthi->fetchrow_hashref ) {
#
# Update newsletter
#
- if (!$debug)
- {
- $stha = $dbh->prepare("UPDATE llx_newsletter SET date_send_begin=now() WHERE rwoid=" . $hsri->{"rowid"});
+ if (!$debug) {
+ $stha = $dbh->prepare("UPDATE llx_newsletter SET status=4,date_send_begin=now() WHERE rowid=" . $hsri->{"rowid"});
$stha->execute;
$stha->finish;
}
@@ -96,42 +95,62 @@ while ( $hsri = $sthi->fetchrow_hashref )
#
#
#
+ my ($fromemail, $from, $replyto, $subject, $mesg);
- $from = $hsri->{"email_from_name"} . "<" . $hsri->{"email_from_email"} . ">";
- $replyto = $hsri->{"email_replyto"};
- $mesg = $hsri->{"email_body"};
- $subject = $hsri->{"email_subject"};
- $sql = $hsri->{"sql_target"};
+ $from = $hsri->{"email_from_name"} . " <" . $hsri->{"email_from_email"} . ">";
+ $fromemail = $hsri->{"email_from_email"};
+ $replyto = $hsri->{"email_replyto"};
+ $mesg = $hsri->{"email_body"};
+ $subject = $hsri->{"email_subject"};
+ $sql = $hsri->{"sql_target"};
+
+ print "Message de : $from\n" if $verbose;
#
# Read dest
#
- if ($sql)
- {
+ if ($sql) {
$sth = $dbh->prepare($sql);
$sth->execute;
- my($nbdest) = (0);
+ my($nbdest, $nberror) = (0,0);
- while ( $hsr = $sth->fetchrow_hashref )
+ while (my $hsr = $sth->fetchrow_hashref )
{
if (length($hsr->{"email"}) > 0)
{
- my $firstname = $hsr->{"prenom"};
- my $name = $hsr->{"nom"};
+ my $firstname = $hsr->{"firstname"};
+ my $lastname = $hsr->{"name"};
+ my $email = "$firstname $lastname <".$hsr->{"email"}.">";
- my $gm = mail_it($hsr->{"email"},
- $from,
- $subject,
- $mesg,
- $replyto);
+
+ if (!$debug)
+ {
+
+ if (! mail_it($hsr->{"email"},
+ $email,
+ $fromemail,
+ $from,
+ $subject,
+ $mesg,
+ $replyto))
+ {
+ $nberror++;
+ print $nberror;
+
+ }
+
+ }
+ else
+ {
+ print "$nbdest : Mail $from -> ".$email."\n" if $verbose;
+ }
}
- $nbdest++;
-
+ $nbdest++;
}
$sth->finish;
@@ -141,18 +160,22 @@ while ( $hsri = $sthi->fetchrow_hashref )
#
if (!$debug)
{
- $stha = $dbh->prepare("UPDATE llx_newsletter SET status=3,date_send_end=now(), nbsent=$nbdest WHERE rowid=" . $hsri->{"rowid"});
+ $stha = $dbh->prepare("UPDATE llx_newsletter SET status=3,date_send_end=now(), nbsent=$nbdest, nberror=$nberror WHERE rowid=" . $hsri->{"rowid"});
$stha->execute;
$stha->finish;
}
+ } else {
+ print "No sql request";
}
}
$sthi->finish;
-print "Close DBI connection\n" if $verbose>3;
+print "DBI connection : close\n" if $verbose>3;
$dbh->disconnect;
+
+print "End\n" if $verbose>0;
#
#
#
@@ -162,7 +185,6 @@ $sl = Sys::Syslog::syslog('info', 'End');
Sys::Syslog::closelog();
-
#
#
#
@@ -174,7 +196,7 @@ sub print_help {
}
sub mail_it {
- my ($to, $from, $subject, $mesg, $replyto) = @_;
+ my ($toemail, $to, $fromemail, $from, $subject, $mesg, $replyto) = @_;
my ($smtp);
$mesg = wrap("","",$mesg);
@@ -183,24 +205,38 @@ sub mail_it {
Hello => 'localhost',
Timeout => 30);
- if ($smtp)
- {
- $smtp->mail($from);
- $smtp->to($to);
+ if ($smtp) {
+
+ print "Mail $from -> ".$to."\n" if $verbose;
+
+ if ($smtp->verify($toemail)) {
+
+ $smtp->mail($fromemail);
+ $smtp->to($toemail);
- $smtp->data();
- $smtp->datasend("From: $from\n");
- $smtp->datasend("Reply-To: $replyto\n") if $replyto;
- $smtp->datasend("Content-Type: text/plain; charset=\"iso-8859-1\"\n");
- $smtp->datasend("To: $to\n");
- $smtp->datasend("Subject: $subject\n");
- $smtp->datasend("X-Mailer: Dolibarr\n");
- $smtp->datasend("\n");
+ $smtp->data();
+ $smtp->datasend("From: $from\n");
+ $smtp->datasend("Reply-To: $replyto\n") if $replyto;
+ $smtp->datasend("Content-Type: text/plain; charset=\"iso-8859-1\"\n");
+ $smtp->datasend("To: $to\n");
+ $smtp->datasend("Subject: $subject\n");
+ $smtp->datasend("X-Mailer: Dolibarr\n");
+ $smtp->datasend("\n");
- $smtp->datasend($mesg);
+ $smtp->datasend($mesg);
+
+ $smtp->dataend();
+
+ return 1;
+
+ } else {
+ return 0;
+ }
- $smtp->dataend();
$smtp->quit;
+
+ } else {
+ return 0;
}
}
| |