Qual: La gnration des petits formulaires d'envoi de mail unitaire fonctionne sur un modle objet (class html.formmail.class.php).

Cela permettra de les remplacer plus facillement par une interface plus sophistique  terme.
This commit is contained in:
Laurent Destailleur 2005-01-11 20:26:22 +00:00
parent 2290ff6380
commit 8ec40b3320
5 changed files with 342 additions and 172 deletions

View File

@ -23,9 +23,9 @@
*
*/
/*!
\file htdocs/comm/mailing.php
\brief Page pour faire des mailing
/** \file htdocs/comm/mailing.php
\brief Page pour faire des mailing
\todo A virer quand remplacer completement par ecrans en /comm/mailing
*/
require("./pre.inc.php");
@ -45,6 +45,7 @@ require("./propal_model_pdf.class.php");
require("../propal.class.php");
require("../actioncomm.class.php");
require("../lib/CMailFile.class.php");
require("../html.formmail.class.php");
/*
* Sécurité accés client
@ -71,7 +72,7 @@ if ($_GET["action"] != 'mailing')
{
print $langs->trans("MailingDesc")."<br><br>";
$form = new Form($db);
$formmail = new FormMail($db);
print "<form method=\"post\" action=\"mailing.php?action=mailing\" name=\"mailing\">";
@ -88,7 +89,7 @@ if ($_GET["action"] != 'mailing')
print "</table>";
// Affiche la partie mail topic + message + file
$form->mail_topicmessagefile(1,1,1,$defaultmessage);
$formmail->mail_topicmessagefile(1,1,1,$defaultmessage);
print "<br><center><input class=\"flat\" type=\"submit\" value=\"".$langs->trans("Send")."\"></center>\n";

View File

@ -153,7 +153,7 @@ if ($_GET["action"] == 'modif' && $user->rights->propale->creer)
}
if ($_POST["addligne"] == 'Ajouter' && $user->rights->propale->creer)
if ($_POST["addligne"] == $langs->trans("Add") && $user->rights->propale->creer)
{
/*
* Ajout d'une ligne produit dans la propale
@ -167,7 +167,7 @@ if ($_POST["addligne"] == 'Ajouter' && $user->rights->propale->creer)
}
}
if ($_POST["addproduct"] == 'Ajouter' && $user->rights->propale->creer)
if ($_POST["addproduct"] == $langs->trans("Add") && $user->rights->propale->creer)
{
/*
* Ajout d'une ligne produit dans la propale
@ -619,9 +619,10 @@ if ($_GET["propalid"])
$filepath[1] = $_FILES['addedfile']['tmp_name'];
$filename[1] = $_FILES['addedfile']['name'];
$mimetype[1] = $_FILES['addedfile']['type'];
$replyto = $_POST["replytoname"]. " <".$_POST["replytomail"].">";
$from = $_POST["fromname"] . " <".$_POST["frommail"] .">";
$replyto = $_POST["replytoname"]. " <".$_POST["replytomail"].">";
$mailfile = new CMailFile($subject,$_POST["sendto"],$replyto,$_POST["message"],$filepath,$mimetype,$filename,$sendtocc);
$mailfile = new CMailFile($subject,$_POST["sendto"],$from,$_POST["message"],$filepath,$mimetype,$filename,$sendtocc);
if (! $mailfile->sendfile() )
{
@ -797,32 +798,28 @@ if ($_GET["propalid"])
print '<input type="hidden" name="max_file_size" value="2000000">';
print_titre("Envoyer la propale par mail");
$form=new Form($db);
// Formulaire envoi mail
print '<table class="border" width="100%">';
// Destinataire
print "<tr><td width=\"180\">Destinataire</td>";
print "<td colspan=\"6\" align=\"left\"><input size=\"50\" name=\"sendto\" value=\"" . ucfirst(strtolower($obj->firstname)) . " " . ucfirst(strtolower($obj->name)) . " <$obj->email>\"></td></tr>";
// Créé l'objet formulaire mail
include_once("../html.formmail.class.php");
$formmail = new FormMail($db);
$formmail->fromname = $user->fullname;
$formmail->frommail = $user->email;
$formmail->withfrom=1;
// $formmail->withto=array_merge(array("&nbsp;"),$soc->contact_email_array());
$formmail->withto=ucfirst(strtolower($obj->firstname)) . " " . ucfirst(strtolower($obj->name)) . " <$obj->email>";
$formmail->withcc=1;
$formmail->withtopic=1;
$formmail->withfile=1;
$formmail->withbody=1;
// Tableau des substitutions
$formmail->substit["__PROPREF__"]=$propal->ref;
// Tableau des paramètres complémentaires
$formmail->param["action"]="send";
$formmail->param["models"]="propal_send";
$formmail->param["propalid"]=$propal->id;
$formmail->param["returnurl"]=DOL_URL_ROOT."/comm/propal.php?propalid=$propal->id";
// CC
print '<tr><td>Copie à</td>';
print '<td colspan="6" align="left"><input size="50" name="sendtocc"></td></tr>';
// Sender
/*
print "<tr><td>Expediteur</td><td colspan=\"5\">$from_name</td><td>$from_mail</td></tr>";
print "<tr><td>Reply-to</td><td colspan=\"5\">$replytoname</td>";
print "<td>$replytomail</td></tr>";
print "<tr><td valign=\"top\">Joindre un fichier en plus de la propale<br>(conditions générales de ventes ...)</td><td colspan=\"6\"><input type=\"file\" name=\"addedfile\" size=\"40\" maxlength=\"80\"></td></tr>";
print "<tr><td valign=\"top\">Message</td><td colspan=\"6\"><textarea rows=\"5\" cols=\"40\" name=\"message\">$message</textarea></td></tr>";
print "</table>";
*/
$form->mail_topicmessagefile(0,1,1,$message);
print "<input type=\"submit\" value=\"".$langs->trans("Send")."\">";
print "</form>";
$formmail->show_form();
}
}

View File

@ -22,8 +22,7 @@
*
*/
/**
\file htdocs/compta/facture.php
/** \file htdocs/compta/facture.php
\ingroup facture
\brief Page de création d'une facture
\version $Revision$
@ -348,7 +347,6 @@ if ($_POST["action"] == 'send' || $_POST["action"] == 'relance')
if (is_readable($file))
{
if ($_POST["sendto"]) {
// Le destinataire a été fourni via le champ libre
$sendto = $_POST["sendto"];
@ -376,7 +374,8 @@ if ($_POST["action"] == 'send' || $_POST["action"] == 'relance')
$actionmsg2="Relance Facture par mail";
}
$message = $_POST["message"];
$replyto = $_POST["replytoname"] . " <".$_POST["replytomail"] .">";
$from = $_POST["fromname"] . " <".$_POST["frommail"] .">";
$replyto = $_POST["replytoname"]. " <".$_POST["replytomail"].">";
$filepath[0] = $file;
$filename[0] = $fac->ref.".pdf";
@ -384,10 +383,9 @@ if ($_POST["action"] == 'send' || $_POST["action"] == 'relance')
$filepath[1] = $_FILES['addedfile']['tmp_name'];
$filename[1] = $_FILES['addedfile']['name'];
$mimetype[1] = $_FILES['addedfile']['type'];
$replyto = $_POST["replytoname"]. " <".$_POST["replytomail"].">";
// Envoi de la facture
$mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath, $mimetype,$filename,$sendtocc);
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath, $mimetype,$filename,$sendtocc);
if ( $mailfile->sendfile() )
{
@ -397,7 +395,7 @@ if ($_POST["action"] == 'send' || $_POST["action"] == 'relance')
if (! $db->query($sql) )
{
dolibarr_print_error($db->error());
dolibarr_print_error($db);
}
else
{
@ -1331,108 +1329,67 @@ else
print '<tr><td colspan="2" align="center"><input type="submit" value="'.$langs->trans("Save").'"></td></tr></table></form></p>';
}
/*
*
* Affiche formulaire mail
*
*/
if ($_GET["action"] == 'presend')
{
print '<br>';
print_titre("Envoyer la facture par mail");
$langs->load("other");
$replytoname = $user->fullname;
$from_name = $replytoname;
// Créé l'objet formulaire mail
include_once("../html.formmail.class.php");
$formmail = new FormMail($db);
$formmail->fromname = $user->fullname;
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=array_merge(array("&nbsp;"),$soc->contact_email_array());
$formmail->withcc=1;
$formmail->withtopic=1;
$formmail->withfile=1;
$formmail->withbody=1;
// Tableau des substitutions
$formmail->substit["__FACREF__"]=$fac->ref;
// Tableau des paramètres complémentaires du post
$formmail->param["action"]="send";
$formmail->param["models"]="facture_send";
$formmail->param["facid"]=$fac->id;
$formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id";
$replytomail = $user->email;
$from_mail = $replytomail;
$form = new Form($db);
print "<form method=\"post\" ENCTYPE=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."\">\n";
print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<input type="hidden" name="action" value="send">';
print '<input type="hidden" name="replytoname" value="'.$replytoname.'">';
print '<input type="hidden" name="replytomail" value="'.$replytomail.'">';
print "<br>\n";
// From
print "<table class=\"border\" width=\"100%\">\n";
print " <tr><td width=\"180\">".$langs->trans("MailFrom")."</td><td>$from_name".($from_mail?" &lt;$from_mail&gt;":"")."</td></tr>\n";
print " <tr><td>".$langs->trans("MailReply")."</td><td>$replytoname".($replytomail?" &lt;$replytomail&gt;":"");
print "</td></tr>\n";
$formmail->show_form();
// To
print ' <tr><td width=\"180\">'.$langs->trans("MailTo").'</td><td>';
$form->select_array("receiver",$soc->contact_email_array());
print " ".$langs->trans("or")." <input size=\"30\" name=\"sendto\" value=\"$fac->email\"></td></tr>\n";
// CC
print ' <tr><td width=\"180\">'.$langs->trans("MailCC").'</td><td>';
print "<input size=\"30\" name=\"sendtocc\"></td></tr>\n";
// File
print " <tr><td valign=\"top\">" . $langs->trans("MailFile"). "</td><td><input type=\"file\" name=\"addedfile\" size=\"40\" maxlength=\"80\"></td></tr>\n";
print "</table>";
// Topic + Message
$defaultmessage="Veuillez trouver ci-joint la facture $fac->ref\n\nCordialement\n\n";
$form->mail_topicmessagefile(0,1,0,$defaultmessage);
print "<br><center><input class=\"flat\" type=\"submit\" value=\"".$langs->trans("Send")."\"></center>\n";
print "</form>\n";
print '<br>';
}
if ($_GET["action"] == 'prerelance')
{
print '<br>';
print_titre("Envoyer une relance par mail");
$langs->load("other");
// Créé l'objet formulaire mail
include_once("../html.formmail.class.php");
$formmail = new FormMail($db);
$formmail->fromname = $user->fullname;
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=array_merge(array("&nbsp;"),$soc->contact_email_array());
$formmail->withcc=1;
$formmail->withtopic=1;
$formmail->withfile=1;
$formmail->withbody=1;
// Tableau des substitutions
$formmail->substit["__FACREF__"]=$fac->ref;
// Tableau des paramètres complémentaires
$formmail->param["action"]="relance";
$formmail->param["models"]="facture_relance";
$formmail->param["facid"]=$fac->id;
$formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id";
$replytoname = $user->fullname;
$from_name = $replytoname;
$formmail->show_form();
$replytomail = $user->email;
$from_mail = $replytomail;
$form = new Form($db);
print "<form method=\"post\" ENCTYPE=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."\">\n";
print '<input type="hidden" name="facid" value="'.$fac->id.'">';
print '<input type="hidden" name="action" value="relance">';
print '<input type="hidden" name="replytoname" value="'.$replytoname.'">';
print '<input type="hidden" name="replytomail" value="'.$replytomail.'">';
print '<br>';
// From
print "<table class=\"border\" width=\"100%\">\n";
print " <tr><td width=\"180\">".$langs->trans("MailFrom")."</td><td>$from_name".($from_mail?" &lt;$from_mail&gt;":"")."</td></tr>\n";
print " <tr><td>".$langs->trans("MailReply")."</td><td>$replytoname".($replytomail?" &lt;$replytomail&gt;":"");
print "</td></tr>\n";
// To
print ' <tr><td width=\"180\">'.$langs->trans("MailTo").'</td><td>';
$form->select_array("receiver",$soc->contact_email_array());
print " ".$langs->trans("or")." <input size=\"30\" name=\"sendto\" value=\"$fac->email\"></td></tr>\n";
// CC
print ' <tr><td width=\"180\">'.$langs->trans("MailCC").'</td><td>';
print "<input size=\"30\" name=\"sendtocc\"></td></tr>\n";
// File
print " <tr><td valign=\"top\">" . $langs->trans("MailFile"). "</td><td><input type=\"file\" name=\"addedfile\" size=\"40\" maxlength=\"80\"></td></tr>\n";
print "</table>";
// Topic + Message
$defaultmessage="Nous apportons à votre connaissance que la facture ".$fac->ref." ne semble toujours pas avoir été réglée. La voici donc, pour rappel, en pièce jointe.\n\nCordialement\n\n";
$form->mail_topicmessagefile(0,1,0,$defaultmessage);
print "<br><center><input class=\"flat\" type=\"submit\" value=\"".$langs->trans("Send")."\"></center>\n";
print "</form\n";
print '<br>';
}
/*

View File

@ -872,53 +872,6 @@ class Form
}
}
/*
* \brief Affiche la partie de formulaire pour saisie d'un mail
* \param withtopic 1 pour proposer à la saisie le sujet
* \param withbody 1 pour proposer à la saisie le corps du message
* \param withfile 1 pour proposer à la saisie l'ajout d'un fichier joint
*/
function mail_topicmessagefile($withtopic=1,$withbody=1,$withfile=1,$defaultbody) {
global $langs;
$langs->load("other");
print "<table class=\"border\" width=\"100%\">";
// Topic
if ($withtopic)
{
print "<tr>";
print "<td width=\"180\">".$langs->trans("MailTopic")."</td>";
print "<td>";
print "<input type=\"text\" size=\"60\" name=\"subject\" value=\"\">";
print "</td></tr>";
}
// Message
if ($withbody)
{
print "<tr>";
print "<td width=\"180\" valign=\"top\">".$langs->trans("MailText")."</td>";
print "<td>";
print "<textarea rows=\"8\" cols=\"72\" name=\"message\">";
print $defaultbody;
print "</textarea>";
print "</td></tr>";
}
// Si fichier joint
if ($withfile)
{
print "<tr>";
print "<td width=\"180\">".$langs->trans("MailFile")."</td>";
print "<td>";
print "<input type=\"file\" name=\"addedfile\" value=\"".$langs->trans("Upload")."\"/>";
print "</td></tr>";
}
print "</table>";
}
}
?>

View File

@ -0,0 +1,262 @@
<?PHP
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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/html.formmail.class.php
\brief Fichier de la classe permettant la génération du formulaire html d'envoi de mail unitaire
\version $Revision$
*/
include_once ("html.form.class.php");
/** \class FormMail
\brief Classe permettant la génération du formulaire html d'envoi de mail unitaire
\remarks Utilisation: $formail = new FormMail($db)
\remarks $formmail->proprietes=1 ou chaine ou tableau de valeurs
\remarks $formmail->show_form() affiche le formulaire
*/
class FormMail
{
var $db;
var $fromname;
var $frommail;
var $replytoname;
var $replytomail;
var $toname;
var $tomail;
var $withfrom;
var $withto;
var $withtocc;
var $withtopic;
var $withfile;
var $withbody;
var $withfromreadonly;
var $withreplytoreadonly;
var $withtoreadonly;
var $withtoccreadonly;
var $withtopicreadonly;
var $substit=array();
var $param=array();
var $errorstr;
/** \brief Constructeur
\param DB handler d'accès base de donnée
*/
function FormMail($DB)
{
$this->db = $DB;
$this->withfrom=1;
$this->withto=1;
$this->withtocc=1;
$this->withtopic=1;
$this->withfile=0;
$this->withbody=1;
$this->withfromreadonly=1;
$this->withreplytoreadonly=1;
$this->withtoreadonly=0;
$this->withtoccreadonly=0;
$this->withtopicreadonly=0;
return 1;
}
/*
* \brief Affiche la partie de formulaire pour saisie d'un mail en fonction des propriétés
*/
function show_form() {
global $langs;
$langs->load("other");
$form=new Form($DB);
print "\n<!-- Debut form mail -->\n";
print "<form method=\"post\" ENCTYPE=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
foreach ($this->param as $key=>$value) {
print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
}
print "<table class=\"border\" width=\"100%\">\n";
// From
if ($this->withfrom)
{
if ($this->withfromreadonly) {
print '<input type="hidden" name="fromname" value="'.$this->fromname.'">';
print '<input type="hidden" name="frommail" value="'.$this->frommail.'">';
print "<tr><td width=\"180\">".$langs->trans("MailFrom")."</td><td>".$this->fromname.($this->frommail?(" &lt;".$this->frommail."&gt;"):"")."</td></tr>\n";
print "</td></tr>\n";
}
}
// Replyto
if ($this->withreplyto)
{
if ($this->withreplytoreadonly) {
print '<input type="hidden" name="replyname" value="'.$this->replytoname.'">';
print '<input type="hidden" name="replymail" value="'.$this->replytomail.'">';
print "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail?(" &lt;".$this->replytomail."&gt;"):"");
print "</td></tr>\n";
}
}
// To
if ($this->withto || is_array($this->withto)) {
print '<tr><td width="180">'.$langs->trans("MailTo").'</td><td>';
if ($this->withtoreadonly) {
print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
} else {
print "<input size=\"30\" name=\"sendto\" value=\"".(! is_array($this->withto)?$this->withto:"")."\">";
if (is_array($this->withto))
{
print " ".$langs->trans("or")." ";
$form->select_array("receiver",$this->withto);
}
}
print "</td></tr>\n";
}
// CC
if ($this->withcc)
{
print '<tr><td width="180">'.$langs->trans("MailCC").'</td><td>';
if ($this->withtoccreadonly) {
print (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"";
} else {
print "<input size=\"30\" name=\"sendtocc\" value=\"".((! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"")."\">";
if (is_array($this->withtocc))
{
print " ".$langs->trans("or")." ";
$form->select_array("receivercc",$this->withtocc);
}
}
print "</td></tr>\n";
}
// Topic
if ($this->withtopic)
{
print "<tr>";
print "<td width=\"180\">".$langs->trans("MailTopic")."</td>";
print "<td>";
print "<input type=\"text\" size=\"60\" name=\"subject\" value=\"\">";
print "</td></tr>\n";
}
// Si fichier joint
if ($this->withfile)
{
print "<tr>";
print "<td width=\"180\">".$langs->trans("MailFile")."</td>";
print "<td>";
print "<input type=\"file\" name=\"addedfile\" value=\"".$langs->trans("Upload")."\"/>";
print "</td></tr>\n";
}
// Message
if ($this->withbody)
{
$defaultmessage="";
// \todo A partir du type, proposer liste de messages dans table llx_models
if ($this->param["models"]=='facture_send') { $defaultmessage="Veuillez trouver ci-joint la facture __FACREF__\n\nCordialement\n\n"; }
if ($this->param["models"]=='facture_relance') { $defaultmessage="Nous apportons à votre connaissance que la facture __FACREF__ ne semble toujours pas avoir été réglée. La voici donc, pour rappel, en pièce jointe.\n\nCordialement\n\n"; }
foreach ($this->substit as $key=>$value) {
$defaultmessage=ereg_replace($key,$value,$defaultmessage);
}
print "<tr>";
print "<td width=\"180\" valign=\"top\">".$langs->trans("MailText")."</td>";
print "<td>";
print "<textarea rows=\"8\" cols=\"72\" name=\"message\">";
print $defaultmessage;
print "</textarea>";
print "</td></tr>\n";
}
print "<tr><td align=center colspan=2><center><input class=\"flat\" type=\"submit\" value=\"".$langs->trans("Send")."\"></center></td></tr>\n";
print "</table>\n";
print "</form>\n";
print "<!-- Fin form mail -->\n";
}
/*
* \brief Affiche la partie de formulaire pour saisie d'un mail
* \param withtopic 1 pour proposer à la saisie le sujet
* \param withbody 1 pour proposer à la saisie le corps du message
* \param withfile 1 pour proposer à la saisie l'ajout d'un fichier joint
* \todo Fonction a virer quand fichier /comm/mailing.php viré (= quand ecran dans /comm/mailing prets)
*/
function mail_topicmessagefile($withtopic=1,$withbody=1,$withfile=1,$defaultbody) {
global $langs;
$langs->load("other");
print "<table class=\"border\" width=\"100%\">";
// Topic
if ($withtopic)
{
print "<tr>";
print "<td width=\"180\">".$langs->trans("MailTopic")."</td>";
print "<td>";
print "<input type=\"text\" size=\"60\" name=\"subject\" value=\"\">";
print "</td></tr>";
}
// Message
if ($withbody)
{
print "<tr>";
print "<td width=\"180\" valign=\"top\">".$langs->trans("MailText")."</td>";
print "<td>";
print "<textarea rows=\"8\" cols=\"72\" name=\"message\">";
print $defaultbody;
print "</textarea>";
print "</td></tr>";
}
// Si fichier joint
if ($withfile)
{
print "<tr>";
print "<td width=\"180\">".$langs->trans("MailFile")."</td>";
print "<td>";
print "<input type=\"file\" name=\"addedfile\" value=\"".$langs->trans("Upload")."\"/>";
print "</td></tr>";
}
print "</table>";
}
}
?>