New: Can remove attached files before sending emails

This commit is contained in:
Laurent Destailleur
2010-01-13 10:30:33 +00:00
parent e3cee0636b
commit 6ef542d940
9 changed files with 250 additions and 74 deletions

View File

@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,7 @@ $langs->load("companies");
$langs->load("products");
$langs->load("admin");
$langs->load("mails");
$langs->load("other");
if (!$user->admin)
accessforbidden();
@@ -63,7 +64,7 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update')
/*
* Add file
* Add file in email form
*/
if ($_POST['addfile'] || $_POST['addfilehtml'])
{
@@ -105,11 +106,49 @@ if ($_POST['addfile'] || $_POST['addfilehtml'])
if ($_POST['addfilehtml']) $_GET["action"]='testhtml';
}
/*
* Remove file in email form
*/
if (! empty($_POST['removedfile']) || ! empty($_POST['removedfilehtml']))
{
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
$keytodelete=isset($_POST['removedfile'])?$_POST['removedfile']:$_POST['removedfilehtml'];
$keytodelete--;
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
if ($keytodelete >= 0)
{
$pathtodelete=$listofpaths[$keytodelete];
$filetodelete=$listofnames[$keytodelete];
$result = dol_delete_file($pathtodelete,1);
if ($result >= 0)
{
$message = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db);
$formmail->remove_attached_files($keytodelete);
}
}
if ($_POST['removedfile']) $_GET["action"]='test';
if ($_POST['removedfilehtml']) $_GET["action"]='testhtml';
}
/*
* Send mail
*/
if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml')
&& ! $_POST['addfile'] && ! $_POST['addfilehtml'] && ! $_POST['cancel'])
&& ! $_POST['addfile'] && ! $_POST['addfilehtml'] && ! $_POST["removedfile"] && ! $_POST['cancel'])
{
$error=0;
@@ -543,7 +582,7 @@ else
$formmail->clear_attached_files();
}
$formmail->show_form('addfile');
$formmail->show_form('addfile','removefile');
print '<br>';
}
@@ -588,7 +627,7 @@ else
$formmail->clear_attached_files();
}
$formmail->show_form('addfilehtml');
$formmail->show_form('addfilehtml','removefilehtml');
print '<br>';
}

View File

@@ -63,7 +63,6 @@ $substitutionarrayfortest=array(
);
// Action clone object
if ($_POST["action"] == 'confirm_clone' && $_POST['confirm'] == 'yes')
{

View File

@@ -363,7 +363,7 @@ if ($_REQUEST['action'] == 'setstatut' && $user->rights->propale->cloturer)
/*
* Add file
* Add file in email form
*/
if ($_POST['addfile'])
{
@@ -405,10 +405,47 @@ if ($_POST['addfile'])
$_GET["action"]='presend';
}
/*
* Remove file in email form
*/
if (! empty($_POST['removedfile']))
{
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
$keytodelete=$_POST['removedfile'];
$keytodelete--;
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
if ($keytodelete >= 0)
{
$pathtodelete=$listofpaths[$keytodelete];
$filetodelete=$listofnames[$keytodelete];
$result = dol_delete_file($pathtodelete,1);
if ($result >= 0)
{
$message = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db);
$formmail->remove_attached_files($keytodelete);
}
}
$_GET["action"]='presend';
}
/*
* Send mail
*/
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['cancel'])
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{
$langs->load('mails');

View File

@@ -57,12 +57,8 @@ $result=restrictedArea($user,'commande',$comid,'');
$usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
// Recuperation de l'id de projet
$projetid = 0;
if ($_GET["projetid"])
{
$projetid = $_GET["projetid"];
}
$mesg=isset($_GET['mesg'])?$_GET['mesg']:'';
$projetid=isset($_GET['projetid'])?$_GET['projetid']:0;
/******************************************************************************/
@@ -703,7 +699,7 @@ if ($_REQUEST['action'] == 'remove_file')
}
/*
* Add file
* Add file in email form
*/
if ($_POST['addfile'])
{
@@ -744,10 +740,47 @@ if ($_POST['addfile'])
$_GET["action"]='presend';
}
/*
* Remove file in email form
*/
if (! empty($_POST['removedfile']))
{
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
$keytodelete=$_POST['removedfile'];
$keytodelete--;
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
if ($keytodelete >= 0)
{
$pathtodelete=$listofpaths[$keytodelete];
$filetodelete=$listofnames[$keytodelete];
$result = dol_delete_file($pathtodelete,1);
if ($result >= 0)
{
$message = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db);
$formmail->remove_attached_files($keytodelete);
}
}
$_GET["action"]='presend';
}
/*
* Send mail
*/
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['cancel'])
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{
$langs->load('mails');
@@ -853,8 +886,9 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['cancel'])
}
else
{
// Renvoie sur la fiche
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&msg='.urlencode($mesg));
// Redirect here
// This avoid sending mail twice if going out and then back to page
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&mesg='.urlencode($mesg));
exit;
}
}

View File

@@ -1126,7 +1126,7 @@ if ($_GET['action'] == 'down' && $user->rights->facture->creer)
}
/*
* Add file
* Add file in email form
*/
if ($_POST['addfile'])
{
@@ -1167,10 +1167,47 @@ if ($_POST['addfile'])
$_GET["action"]='presend';
}
/*
* Remove file in email form
*/
if (! empty($_POST['removedfile']))
{
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
$keytodelete=$_POST['removedfile'];
$keytodelete--;
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
if ($keytodelete >= 0)
{
$pathtodelete=$listofpaths[$keytodelete];
$filetodelete=$listofnames[$keytodelete];
$result = dol_delete_file($pathtodelete,1);
if ($result >= 0)
{
$message = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db);
$formmail->remove_attached_files($keytodelete);
}
}
$_GET["action"]='presend';
}
/*
* Send mail
*/
if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['addfile'] && ! $_POST['cancel'])
if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{
$langs->load('mails');
@@ -3587,6 +3624,7 @@ else
print '<br>';
}
// Deprecated
if ($_GET['action'] == 'prerelance')
{
$ref = dol_sanitizeFileName($fac->ref);

View File

@@ -1,5 +1,5 @@
<?PHP
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2005-2010 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
@@ -136,6 +136,31 @@ class FormMail
}
}
/**
* Remove a file from the list of attached files (stored in SECTION array)
*
* @param unknown_type $file
*/
function remove_attached_files($keytodelete)
{
$listofpaths=array();
$listofnames=array();
$listofmimes=array();
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
if ($keytodelete >= 0)
{
unset ($listofpaths[$keytodelete]);
unset ($listofnames[$keytodelete]);
unset ($listofmimes[$keytodelete]);
$_SESSION["listofpaths"]=join(';',$listofpaths);
$_SESSION["listofnames"]=join(';',$listofnames);
$_SESSION["listofmimes"]=join(';',$listofmimes);
//var_dump($_SESSION['listofpaths']);
}
}
/**
* Return list of attached files (stored in SECTION array)
*
@@ -153,11 +178,12 @@ class FormMail
}
/**
* \brief Affiche la partie de formulaire pour saisie d'un mail en fonction des proprietes
* \brief Show the form to input an email
* \param addfileaction Name of action when posting file attachments
* \param removefileaction Name of action when removing file attachments
* \remarks this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
*/
function show_form($addfileaction='addfile')
function show_form($addfileaction='addfile',$removefileaction='removefile')
{
global $conf, $langs, $user;
@@ -412,7 +438,9 @@ class FormMail
{
foreach($listofpaths as $key => $val)
{
print img_mime($listofnames[$key]).' '.$listofnames[$key].'<br>';
print img_mime($listofnames[$key]).' '.$listofnames[$key];
print ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key+1).'" name="removedfile">';
print '<br>';
}
}
else
@@ -422,7 +450,7 @@ class FormMail
if ($this->withfile == 2) // Can add other files
{
//print '<td><td align="right">';
print "<input type=\"file\" class=\"flat\" name=\"addedfile\" value=\"".$langs->trans("Upload")."\"/>";
print '<input type="file" class="flat" name="addedfile" value="'.$langs->trans("Upload").'"/>';
print ' ';
print '<input type="submit" class="button" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'">';
//print '</td></tr></table>';
@@ -495,14 +523,15 @@ class FormMail
}
/*
/**
* \brief Affiche la partie de formulaire pour saisie d'un mail
* \param withtopic 1 pour proposer a la saisie le sujet
* \param withbody 1 pour proposer a la saisie le corps du message
* \param withfile 1 pour proposer a la saisie l'ajout d'un fichier joint
* \todo Fonction a virer quand fichier /comm/mailing.php vire (= quand ecran dans /comm/mailing prets)
*/
function mail_topicmessagefile($withtopic=1,$withbody=1,$withfile=1,$defaultbody) {
function mail_topicmessagefile($withtopic=1,$withbody=1,$withfile=1,$defaultbody)
{
global $langs;
$langs->load("other");

View File

@@ -60,8 +60,8 @@ ModifiedBy=Modified by %s
ValidatedBy=Validated by %s
CanceledBy=Canceled by %s
ClosedBy=Closed by %s
FileWasRemoved=File was deleted
DirWasRemoved=Directory was removed
FileWasRemoved=File %s was removed
DirWasRemoved=Directory %s was removed
FeatureNotYetAvailableShort=Available in a next version
FeatureNotYetAvailable=Feature not yet available in this version
FeatureExperimental=Experimental feature. Not stable in this version

View File

@@ -60,8 +60,8 @@ ModifiedBy=Modifié par %s
ValidatedBy=Validé par %s
CanceledBy=Annulé par %s
ClosedBy=Cloturé par %s
FileWasRemoved=Le fichier a été supprimé
DirWasRemoved=Le répertoire a été supprimé
FileWasRemoved=Le fichier %s a été supprimé
DirWasRemoved=Le répertoire %s a été supprimé
FeatureNotYetAvailableShort=Disponible dans une prochaine version
FeatureNotYetAvailable=Fonctionnalité pas encore disponible dans cette version
FeatureExperimental=Fonctionnalité expérimentale. Non stable dans cette version

View File

@@ -2252,7 +2252,7 @@ function print_fleche_navigation($page,$file,$options='',$nextpage,$betweenarrow
* \brief Remove a file or several files with a mask
* \param file File to delete or mask of file to delete
* \param disableglob Disable usage of glob like *
* \param boolean True if file deleted, False if error
* \param boolean True if file is deleted, False if error
*/
function dol_delete_file($file,$disableglob=0)
{