diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php index 7fcfcdd5e49..3b85ed81dc3 100644 --- a/htdocs/admin/mails.php +++ b/htdocs/admin/mails.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2007-2010 Laurent Destailleur * Copyright (C) 2009 Regis Houssin * * 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 = '
'.$langs->trans("FileWasRemoved",$filetodelete).'
'; + //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 '
'; } @@ -588,7 +627,7 @@ else $formmail->clear_attached_files(); } - $formmail->show_form('addfilehtml'); + $formmail->show_form('addfilehtml','removefilehtml'); print '
'; } diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index ba63e8a1dc3..0b913d1e9fc 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -63,7 +63,6 @@ $substitutionarrayfortest=array( ); - // Action clone object if ($_POST["action"] == 'confirm_clone' && $_POST['confirm'] == 'yes') { diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 82441464352..d61e0f7ac20 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -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 = '
'.$langs->trans("FileWasRemoved",$filetodelete).'
'; + //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'); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index fbb31c56516..376c9437c12 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -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 = '
'.$langs->trans("FileWasRemoved",$filetodelete).'
'; + //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; } } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index d11e6e2f764..f753a406b94 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -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 = '
'.$langs->trans("FileWasRemoved",$filetodelete).'
'; + //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 '
'; } + // Deprecated if ($_GET['action'] == 'prerelance') { $ref = dol_sanitizeFileName($fac->ref); diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php index a865390b0c6..042c510f7da 100644 --- a/htdocs/html.formmail.class.php +++ b/htdocs/html.formmail.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2010 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 @@ -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; @@ -189,7 +215,7 @@ class FormMail { print ""; $help=""; - foreach($this->substit as $key => $val) + foreach($this->substit as $key => $val) { $help.=$key.' -> '.$langs->trans($val).'
'; } @@ -412,7 +438,9 @@ class FormMail { foreach($listofpaths as $key => $val) { - print img_mime($listofnames[$key]).' '.$listofnames[$key].'
'; + print img_mime($listofnames[$key]).' '.$listofnames[$key]; + print ' '; + print '
'; } } else @@ -422,7 +450,7 @@ class FormMail if ($this->withfile == 2) // Can add other files { //print ''; - print "trans("Upload")."\"/>"; + print ''; print ' '; print ''; //print ''; @@ -458,7 +486,7 @@ class FormMail { if ($this->withfckeditor) { - // Editeur wysiwyg + // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('message',$defaultmessage,280,'dolibarr_notes','In',true); $doleditor->Create(); @@ -495,54 +523,55 @@ 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) { - global $langs; + /** + * \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) + { + global $langs; - $langs->load("other"); + $langs->load("other"); - print ""; + print "
"; - // Topic - if ($withtopic) - { - print ""; - print ""; - print ""; - } + // Topic + if ($withtopic) + { + print ""; + print ""; + print ""; + } - // Message - if ($withbody) - { - print ""; - print ""; - print ""; - } + // Message + if ($withbody) + { + print ""; + print ""; + print ""; + } - // Si fichier joint - if ($withfile) - { - print ""; - print ""; - print ""; - } + // Si fichier joint + if ($withfile) + { + print ""; + print ""; + print ""; + } - print "
".$langs->trans("MailTopic").""; - print ""; - print "
".$langs->trans("MailTopic").""; + print ""; + print "
".$langs->trans("MailText").""; - print ""; - print "
".$langs->trans("MailText").""; + print ""; + print "
".$langs->trans("MailFile").""; - print "trans("Upload")."\"/>"; - print "
".$langs->trans("MailFile").""; + print "trans("Upload")."\"/>"; + print "
"; - } + print ""; + } } diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 2e6799631e4..409745bccea 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -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 diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index f281a9c7e68..e2e0a2d8e6e 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -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 diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index eb306707a7e..f634d843422 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -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) {