* Copyright (C) 2005 Laurent Destailleur * * 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$ * */ /** \file htdocs/comm/mailing/fiche.php \brief Fiche mailing, onglet général \version $Revision$ */ require("./pre.inc.php"); $langs->load("mails"); $message = ''; llxHeader("","","Fiche Mailing"); // Action envoi mailing pour tous if ($_GET["action"] == 'sendall') { // Pour des raisons de sécurité, on ne permet pas cette fonction via l'IHM, // on affiche donc juste un message $message='
'.$langs->trans("MailingNeedCommand").'
'; $message.="php ./scripts/mailing-send.php ".$_GET["id"]; $_GET["action"]=''; } // Action envoi test mailing if ($_POST["action"] == 'send') { $mil = new Mailing($db); $mil->id = $_POST["mailid"]; $mil->fromname = $_POST["fromname"]; $mil->frommail = $_POST["frommail"]; $mil->sendto = $_POST["sendto"]; $mil->titre = $_POST["titre"]; $mil->sujet = $_POST["subject"]; $mil->body = $_POST["message"]; if ($mil->sendto && $mil->sujet && $mil->body) { // \todo Utiliser la class DolibarrMail ou CMailFile pour envoyer le mail $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"; $m=mail($mil->sendto, $mil->sujet, $mil->body, $headers); if($m) { $message='
'.$langs->trans("ResultOk").'
'; } else { $message='
'.$langs->trans("ResultKo").'
'; } $_GET["action"]=''; $_GET["id"]=$mil->id; } else { $message='
'.$langs->trans("ErrorUnknown").'
'; } } // Action ajout mailing if ($_POST["action"] == 'add') { $mil = new Mailing($db); $mil->email_from = $_POST["from"]; $mil->titre = $_POST["titre"]; $mil->sujet = $_POST["sujet"]; $mil->body = $_POST["body"]; if ($mil->create($user) >= 0) { Header("Location: fiche.php?id=".$mil->id); } else { $message='
'.$mil->error.'
'; $_GET["action"]="create"; } } // Action mise a jour mailing if ($_POST["action"] == 'update') { $mil = new Mailing($db); $mil->id = $_POST["id"]; $mil->email_from = $_POST["from"]; $mil->titre = $_POST["titre"]; $mil->sujet = $_POST["sujet"]; $mil->body = $_POST["body"]; if ($mil->update()) { Header("Location: fiche.php?id=".$mil->id); } } // Action confirmation validation if ($_POST["action"] == 'confirm_valide') { if ($_POST["confirm"] == 'yes') { $mil = new Mailing($db); if ($mil->fetch($_GET["id"]) == 0) { $mil->valid($user); Header("Location: fiche.php?id=".$mil->id); } else { dolibarr_print_error($db); } } else { Header("Location: fiche.php?id=".$_GET["id"]); } } if ($_POST["action"] == 'confirm_approve') { if ($_POST["confirm"] == 'yes') { $mil = new Mailing($db); if ($mil->fetch($_GET["id"]) == 0) { $mil->approve($user); Header("Location: fiche.php?id=".$mil->id); } else { dolibarr_print_error($db); } } else { Header("Location: fiche.php?id=".$_GET["id"]); } } // Action confirmation suppression if ($_POST["action"] == 'confirm_delete') { if ($_POST["confirm"] == 'yes') { $mil = new Mailing($db); $mil->id = $_GET["id"]; if ($mil->delete($mil->id)) { Header("Location: index.php"); } } } if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; } /* * Mailing en mode création * */ $mil = new Mailing($db); if ($_GET["action"] == 'create') { print '
'."\n"; print ''; print_titre($langs->trans("NewMailing")); if ($message) print "$message
"; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("MailFrom").'
'.$langs->trans("MailTitle").'
'.$langs->trans("MailTopic").'
'.$langs->trans("MailMessage").'
'; print '
'; } else { $html = new Form($db); if ($mil->fetch($_GET["id"]) == 0) { $h=0; $head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; $head[$h][1] = $langs->trans("MailCard"); $hselected = $h; $h++; $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id; $head[$h][1] = $langs->trans('MailRecipients'); $h++; /* $head[$h][0] = DOL_URL_ROOT."/comm/mailing/history.php?id=".$mil->id; $head[$h][1] = $langs->trans("MailHistory"); $h++; */ dolibarr_fiche_head($head, $hselected, $langs->trans("Mailing").": ".substr($mil->titre,0,20)); // Confirmation de la validation du mailing if ($_GET["action"] == 'valide') { $html->form_confirm("fiche.php?id=".$mil->id,$langs->trans("ValidMailing"),$langs->trans("ConfirmValidMailing"),"confirm_valide"); } // Confirmation de l'approbation du mailing if ($_GET["action"] == 'approve') { $html->form_confirm("fiche.php?id=".$mil->id,"Approuver le mailing","Confirmez-vous l'approbation du mailing ?","confirm_approve"); } // Confirmation de la suppression if ($_GET["action"] == 'delete') { $html->form_confirm("fiche.php?id=".$mil->id,$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete"); } if ($_GET["action"] != 'edit') { /* * Mailing en mode visu * */ print ''; print ''; print ''; print ''; print ''; $uc = new User($db, $mil->user_creat); $uc->fetch(); print ''; print ''; print ''; if ($mil->statut > 0) { $uv = new User($db, $mil->user_valid); $uv->fetch(); print ''; print ''; print ''; } if ($mil->statut > 1) { $ua = new User($db, $mil->user_appro); $ua->fetch(); print ''; print ''; print ''; } // Contenu du mail print ''; print ''; print '
'.$langs->trans("MailTitle").''.$mil->titre.'
'.$langs->trans("MailFrom").''.htmlentities($mil->email_from).'
'.$langs->trans("TotalNbOfDistinctRecipients").''.($mil->nbemail?$mil->nbemail:''.$langs->trans("NoTargetYet").'').'
'.$langs->trans("Status").''.$mil->statuts[$mil->statut].'
'.$langs->trans("CreatedBy").''.$uc->fullname.''.$langs->trans("DateCreation").''.strftime("%d %b %Y %H:%M", $mil->date_creat).'
'.$langs->trans("ValidatedBy").''.$uv->fullname.''.$langs->trans("Date").''.strftime("%d %b %Y %H:%M", $mil->date_valid).'
'.$langs->trans("ApprovedBy").''.$ua->fullname.''.$langs->trans("Date").''.strftime("%d %b %Y %H:%M", $mil->date_appro).'
'.$langs->trans("MailTopic").''.$mil->sujet.'
'.$langs->trans("MailMessage").''; print nl2br($mil->body).'

'; print ""; if ($message) print "$message
"; /* * Boutons d'action */ if ($_GET["action"] == '') { print "\n\n
\n"; if ($mil->statut == 0) { print ''.$langs->trans("EditMailing").''; } //print ''.$langs->trans("PreviewMailing").''; print ''.$langs->trans("TestMailing").''; if ($mil->statut == 0 && $mil->nbemail > 0) { print ''.$langs->trans("ValidMailing").''; } if ($mil->statut == 1 && $mil->nbemail > 0) { print ''.$langs->trans("SendMailing").''; } if ($mil->statut <= 1) { print ''.$langs->trans("DeleteMailing").''; } print '

'; } if ($_GET["action"] == 'test') { print_titre($langs->trans("TestMailing")); // Créé l'objet formulaire mail include_once("../../html.formmail.class.php"); $formmail = new FormMail($db); $formmail->fromname = $mil->email_from; $formmail->frommail = $mil->email_from; $formmail->withfrom=1; $formmail->withto=$user->email; $formmail->withcc=0; $formmail->withtopic=$mil->sujet; $formmail->withtopicreadonly=1; $formmail->withfile=0; $formmail->withbody=$mil->body; $formmail->withbodyreadonly=1; // Tableau des substitutions $formmail->substit["__FACREF__"]=$fac->ref; // Tableau des paramètres complémentaires du post $formmail->param["action"]="send"; $formmail->param["models"]="body"; $formmail->param["mailid"]=$mil->id; $formmail->param["returnurl"]=DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; $formmail->show_form(); } } else { /* * Mailing en mode edition */ print '
'."\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("MailTitle").'
'.$langs->trans("MailFrom").'
'.$langs->trans("MailTopic").'
'.$langs->trans("MailMessage").'

'; print '
'; print ""; } } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>