Qual: Fusion des classes en doublons dolibarrmail et CMailFile dans la meme "CMailFile".

This commit is contained in:
Laurent Destailleur 2005-09-10 15:56:12 +00:00
parent 52fa54de23
commit 647731fdad
5 changed files with 133 additions and 119 deletions

View File

@ -65,26 +65,26 @@ if ($_POST["action"] == 'send')
if ($mil->sendto && $mil->sujet && $mil->body) if ($mil->sendto && $mil->sujet && $mil->body)
{ {
// \todo Utiliser la class DolibarrMail ou CMailFile pour envoyer le mail require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "From: ".$mil->fromname." <".$mil->frommail.">\r\n";
$headers .= "Reply-to:".$mil->fromname." <".$mil->frommail.">\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: Dolibarr ".DOL_VERSION."\r\n";
$errorlevel=error_reporting(0); $sendto = $mil->sendto;
$m=mail($mil->sendto, $mil->sujet, $mil->body, $headers); $from = $mil->fromname." <".$mil->frommail.">";
$arr_file = array();
$arr_mime = array();
$arr_name = array();
if($m) $mailfile = new CMailFile($mil->sujet,$sendto,$from,$mil->body,$arr_file,$arr_mime,$arr_name);
$result=$mailfile->sendfile();
if($result)
{ {
$message='<div class="ok">'.$langs->trans("ResultOk").'</div>'; $message='<div class="ok">'.$langs->trans("MailSuccessfulySent",$from,$sendto).'</div>';
} }
else else
{ {
$message='<div class="error">'.$langs->trans("ResultKo").'</div>'; $message='<div class="error">'.$langs->trans("ResultKo").'</div>';
} }
error_reporting($errorlevel);
$_GET["action"]=''; $_GET["action"]='';
$_GET["id"]=$mil->id; $_GET["id"]=$mil->id;

View File

@ -214,7 +214,7 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
*/ */
function _NotifyApprobator($user) function _NotifyApprobator($user)
{ {
require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"); require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
$this->ReadApprobators(); $this->ReadApprobators();
@ -253,10 +253,10 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
$sendto = $approb[2]; $sendto = $approb[2];
$mailfile = new DolibarrMail($subject, $mailfile = new CMailFile($subject,
$sendto, $sendto,
$from, $from,
$message); $message, array(), array(), array());
if ( $mailfile->sendfile() ) if ( $mailfile->sendfile() )
{ {
@ -345,7 +345,7 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
*/ */
function _NotifyCreator($user, $subject, $message) function _NotifyCreator($user, $subject, $message)
{ {
require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"); require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
$cc = new user($this->db, $this->user_author_id); $cc = new user($this->db, $this->user_author_id);
$cc->fetch(); $cc->fetch();
@ -353,10 +353,10 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
$sendto = $cc->email; $sendto = $cc->email;
$from = $user->email; $from = $user->email;
$mailfile = new DolibarrMail($subject, $mailfile = new CMailFile($subject,
$sendto, $sendto,
$from, $from,
$message); $message, array(), array(), array());
if ( $mailfile->sendfile() ) if ( $mailfile->sendfile() )
{ {
return 0; return 0;

View File

@ -1,5 +1,7 @@
#!/usr/bin/php
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -17,13 +19,28 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
* Envois la liste des factures impayées aux commerciaux
*
*/ */
require ("../htdocs/master.inc.php"); /**
require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"); \file scripts/factures-impayees-commerciaux.php
\ingroup facture
\brief Script d'envoi de mails résumé des imapyées par commerciaux
*/
// Test si mode batch
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
exit;
}
// Recupere root dolibarr
$path=eregi_replace('factures-impayees-commerciaux.php','',$_SERVER["PHP_SELF"]);
require($path."../htdocs/master.inc.php");
require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
$error = 0; $error = 0;
@ -47,48 +64,23 @@ if ( $db->query($sql) )
$total = ''; $total = '';
dolibarr_syslog("factures-impayees-commerciaux: "); dolibarr_syslog("factures-impayees-commerciaux: ");
if ($num)
{
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object(); $obj = $db->fetch_object();
if ($obj->email <> $oldemail) if ($obj->email <> $oldemail)
{ {
if (strlen($oldemail)) if (strlen($oldemail))
{ {
dolibarr_syslog("factures-impayees-commerciaux: send mail to $oldemail"); envoi_mail($oldemail,$message,$total);
$subject = "[Dolibarr] Liste des factures impayées";
$sendto = $oldemail;
$from = $oldemail;
$allmessage = "Liste des factures impayées à ce jour\n";
$allmessage .= "Cette liste ne comporte que les factures des sociétés dont vous êtes référencés comme commercial.\n";
$allmessage .= "\n";
$allmessage .= $message;
$allmessage .= "\n";
$allmessage .= "Total = ".price($total)."\n";
$mail = new DolibarrMail($subject,
$sendto,
$from,
$allmessage);
$mail->errors_to = $errorsto;
if ( $mail->sendfile() )
{
}
} }
$oldemail = $obj->email; $oldemail = $obj->email;
$message = ''; $message = '';
$total = 0; $total = 0;
} }
$message .= "Facture ".$obj->facnumber." : ".price($obj->total_ttc)." : ".$obj->nom."\n"; $message .= "Facture ".$obj->facnumber." : ".price($obj->total_ttc)." : ".$obj->nom."\n";
$total += $obj->total_ttc; $total += $obj->total_ttc;
@ -96,11 +88,34 @@ if ( $db->query($sql) )
$i++; $i++;
} }
/* On répète le code c'est mal */ // Si il reste des envois en buffer
dolibarr_syslog("factures-impayees-commerciaux: send mail to $oldemail"); if ($total)
{
envoi_mail($oldemail,$message,$total);
}
}
else
{
print "Aucune facture impayée avec des commerciaux directement rattachés\n";
}
}
else
{
dolibarr_print_error($db);
dolibarr_syslog("factures-impayees-commerciaux: Error");
}
function envoi_mail($oldemail,$message,$total)
{
global $conf;
$subject = "[Dolibarr] Liste des factures impayées"; $subject = "[Dolibarr] Liste des factures impayées";
$sendto = $oldemail; $sendto = $oldemail;
$from = $oldemail; $from = $conf->global->MAIN_EMAIL_FROM;
print "Envoi mail pour $oldemail, total: $total\n";
dolibarr_syslog("factures-impayees-commerciaux: send mail to $oldemail");
$allmessage = "Liste des factures impayées à ce jour\n"; $allmessage = "Liste des factures impayées à ce jour\n";
$allmessage .= "Cette liste ne comporte que les factures des sociétés dont vous êtes référencés comme commercial.\n"; $allmessage .= "Cette liste ne comporte que les factures des sociétés dont vous êtes référencés comme commercial.\n";
@ -109,21 +124,20 @@ if ( $db->query($sql) )
$allmessage .= "\n"; $allmessage .= "\n";
$allmessage .= "Total = ".price($total)."\n"; $allmessage .= "Total = ".price($total)."\n";
$mail = new DolibarrMail($subject, $mail = new CMailFile($subject,
$sendto, $sendto,
$from, $from,
$allmessage); $allmessage,array(),array(),array());
$mail->errors_to = $errorsto; $mail->errors_to = $errorsto;
if ( $mail->sendfile() ) $result=$mail->sendfile();
if ($result)
{ {
} }
}
else
{
dolibarr_syslog("factures-impayees-commerciaux: Error");
} }
?> ?>

View File

@ -1,5 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -28,7 +29,6 @@ require ("../htdocs/master.inc.php");
require_once (DOL_DOCUMENT_ROOT."/facture.class.php"); require_once (DOL_DOCUMENT_ROOT."/facture.class.php");
require_once (DOL_DOCUMENT_ROOT."/societe.class.php"); require_once (DOL_DOCUMENT_ROOT."/societe.class.php");
require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php");
$error = 0; $error = 0;

View File

@ -1,5 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,7 +30,6 @@ require_once (DOL_DOCUMENT_ROOT."/bon-prelevement.class.php");
require_once (DOL_DOCUMENT_ROOT."/facture.class.php"); require_once (DOL_DOCUMENT_ROOT."/facture.class.php");
require_once (DOL_DOCUMENT_ROOT."/societe.class.php"); require_once (DOL_DOCUMENT_ROOT."/societe.class.php");
require_once (DOL_DOCUMENT_ROOT."/paiement.class.php"); require_once (DOL_DOCUMENT_ROOT."/paiement.class.php");
require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php");
$error = 0; $error = 0;