diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index 2f700d09466..f93e282be10 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -447,42 +447,15 @@ if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST
$mil = new Mailing($db);
$mil->fetch($_POST["id"]);
- $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1);
-
$isupload=0;
// If upload file
- $i='';
- if (! empty($_POST["addfile".$i]) && ! empty($conf->global->MAIN_UPLOAD_DOC))
+ if (! empty($_POST["addfile"]) && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
$isupload=1;
+ $upload_dir = $conf->mailing->dir_output."/".get_exdir($mil->id,2,0,1);
- if (! is_dir($upload_dir)) create_exdir($upload_dir);
-
- if (is_dir($upload_dir))
- {
- $resupload = dol_move_uploaded_file($_FILES['addedfile'.$i]['tmp_name'], $upload_dir . "/" . $_FILES['addedfile'.$i]['name'],1,0,$_FILES['addedfile'.$i]['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- $mesg = '
';
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index b0cfcd70e29..b48aedf053c 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -381,43 +381,14 @@ if ($_POST['addfile'])
{
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- // Set tmp user directory
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
- if (! empty($_FILES['addedfile']['tmp_name']))
- {
- if (create_exdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0,$_FILES['addedfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- $mesg = ''.$langs->trans("FileTransferComplete").'
';
+ $mesg=dol_add_file_process($upload_dir,0,0);
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- // Add file in list of files in session
- $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- $mesg = ''.$langs->trans("ErrorFileNotUploaded").'
';
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus").'
';
- }
- else // Known error
- {
- $mesg = ''.$langs->trans($resupload).'
';
- }
- }
- }
- }
$_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -425,36 +396,16 @@ if ($_POST['addfile'])
*/
if (! empty($_POST['removedfile']))
{
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
- $keytodelete=$_POST['removedfile'];
- $keytodelete--;
+ $mesg=dol_remove_file_process($_POST['removedfile'],0);
- $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.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->remove_attached_files($keytodelete);
- }
- }
$_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -999,10 +950,11 @@ $html = new Form($db);
$formfile = new FormFile($db);
$companystatic=new Societe($db);
-$now=gmmktime();
+$now=dol_now();
+
+$id = $_REQUEST['propalid']?$_REQUEST['propalid']:$_REQUEST['id'];
+$ref= $_REQUEST['ref'];
-$id = $_GET['propalid']?$_GET['propalid']:$_GET['id'];
-$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
/*
@@ -2036,7 +1988,7 @@ if ($id > 0 || ! empty($ref))
$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;
+ $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?propalid='.$propal->id;
// Init list of files
if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
@@ -2059,7 +2011,7 @@ else
* *
****************************************************************************/
- $now=gmmktime();
+ $now=dol_now();
$sortorder=$_GET['sortorder'];
$sortfield=$_GET['sortfield'];
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index d59829e83f5..e729d1cec2e 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -274,11 +274,11 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->commande->creer)
$ret=$com->fetch($_GET['id']);
if ($ret > 0)
{
- $com->insert_discount($_POST["remise_id"]);
+ $com->insert_discount($_POST["remise_id"]);
}
else
{
- dol_print_error($db,$com->error);
+ dol_print_error($db,$com->error);
}
}
}
@@ -754,7 +754,7 @@ if ($_REQUEST['action'] == 'builddoc') // In get or post
}
}
-// Efface les fichiers
+// Remove file in doc form
if ($_REQUEST['action'] == 'remove_file')
{
$com = new Commande($db);
@@ -775,41 +775,14 @@ if ($_POST['addfile'])
{
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- // Set tmp user directory
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
- if (create_exdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0,$_FILES['addedfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- $mesg = ''.$langs->trans("FileTransferComplete").'
';
-
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- // Add file in list of files in session
- $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- $mesg = ''.$langs->trans("ErrorFileNotUploaded").'
';
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus").'
';
- }
- else // Known error
- {
- $mesg = ''.$langs->trans($resupload).'
';
- }
- }
- }
+ $mesg=dol_add_file_process($upload_dir,0,0);
$_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -817,36 +790,16 @@ if ($_POST['addfile'])
*/
if (! empty($_POST['removedfile']))
{
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
- $keytodelete=$_POST['removedfile'];
- $keytodelete--;
+ $mesg=dol_remove_file_process($_POST['removedfile'],0);
- $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.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->remove_attached_files($keytodelete);
- }
- }
$_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -858,6 +811,8 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
$commande= new Commande($db);
$result=$commande->fetch($_POST['orderid']);
+ $result=$commande->fetch_client();
+
if ($result)
{
$ref = dol_sanitizeFileName($commande->ref);
@@ -865,8 +820,6 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
if (is_readable($file))
{
- $commande->fetch_client();
-
if ($_POST['sendto'])
{
// Le destinataire a ete fourni via le champ libre
@@ -1318,10 +1271,11 @@ else
/* Mode vue et edition */
/* */
/* *************************************************************************** */
- $now=gmmktime();
+ $now=dol_now();
+
+ $id = $_REQUEST['id'];
+ $ref= $_REQUEST['ref'];
- $id = $_GET['id'];
- $ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
if ($mesg) print $mesg.'
';
@@ -2302,7 +2256,7 @@ else
$formmail->param['action']='send';
$formmail->param['models']='order_send';
$formmail->param['orderid']=$commande->id;
- $formmail->param['returnurl']=DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id;
+ $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$commande->id;
// Init list of files
if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 1fecad061cf..66be466a92b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1092,42 +1092,14 @@ if ($_POST['addfile'])
{
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- // Set tmp user directory
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
- if (! is_dir($upload_dir)) create_exdir($upload_dir);
-
- if (is_dir($upload_dir))
- {
- $resupload = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0, $_FILES['addedfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- $mesg = ''.$langs->trans("FileTransferComplete").'
';
-
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- $mesg = ''.$langs->trans("ErrorFileNotUploaded").'
';
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus").'
';
- }
- else // Known error
- {
- $mesg = ''.$langs->trans($resupload).'
';
- }
- }
- }
+ $mesg=dol_add_file_process($upload_dir,0,0);
$_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -1135,36 +1107,16 @@ if ($_POST['addfile'])
*/
if (! empty($_POST['removedfile']))
{
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/';
- $keytodelete=$_POST['removedfile'];
- $keytodelete--;
+ $mesg=dol_remove_file_process($_POST['removedfile'],0);
- $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.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->remove_attached_files($keytodelete);
- }
- }
$_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -1176,6 +1128,8 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a
$fac = new Facture($db,'',$_POST['facid']);
$result=$fac->fetch($_POST['facid']);
+ $result=$fac->fetch_client();
+
if ($result)
{
$ref = dol_sanitizeFileName($fac->ref);
@@ -1183,8 +1137,6 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a
if (is_readable($file))
{
- $fac->fetch_client();
-
if ($_POST['sendto'])
{
// Le destinataire a ete fourni via le champ libre
@@ -1939,8 +1891,9 @@ else
$now=dol_now();
- $id = $_GET['facid'];
- $ref= $_GET['ref'];
+ $id = $_REQUEST['facid'];
+ $ref= $_REQUEST['ref'];
+
if ($id > 0 || ! empty($ref))
{
if ($mesg) print $mesg.'
';
@@ -3464,7 +3417,7 @@ else
$formmail->param['action']=$action;
$formmail->param['models']=$modelmail;
$formmail->param['facid']=$fac->id;
- $formmail->param['returnurl']=DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
+ $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$fac->id;
// Init list of files
if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php
index 616063b586d..35bd5742a90 100644
--- a/htdocs/core/class/html.formactions.class.php
+++ b/htdocs/core/class/html.formactions.class.php
@@ -104,8 +104,10 @@ class FormActions
$sql.= ' WHERE a.fk_user_author = u.rowid';
if ($socid) $sql .= ' AND a.fk_soc = '.$socid;
if ($typeelement == 'invoice') $sql.= ' AND a.fk_facture = '.$object->id;
+ if ($typeelement == 'supplier_invoice') $sql.= ' AND a.fk_supplier_invoice = '.$object->id;
if ($typeelement == 'propal') $sql.= ' AND a.propalrowid = '.$object->id;
if ($typeelement == 'order') $sql.= ' AND a.fk_commande = '.$object->id;
+ if ($typeelement == 'supplier_order') $sql.= ' AND a.fk_supplier_order = '.$object->id;
if ($typeelement == 'project') $sql.= ' AND a.fk_project = '.$object->id;
dol_syslog("FormActions::showactions sql=".$sql);
@@ -116,10 +118,12 @@ class FormActions
if ($num)
{
if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
+ if ($typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnSupplierBill');
if ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
if ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
+ if ($typeelement == 'supplier_order') $title=$langs->trans('ActionsOnSupplierOrder');
if ($typeelement == 'project') $title=$langs->trans('ActionsOnProject');
-
+
print_titre($title);
$i = 0; $total = 0; $var=true;
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index 6a417714737..4b5501e2d37 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -22,8 +22,8 @@
/**
* \file htdocs/fourn/commande/fiche.php
- * \ingroup commande
- * \brief Fiche commande
+ * \ingroup supplier, order
+ * \brief Card supplier order
* \version $Id$
*/
@@ -461,7 +461,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post
}
}
-// Delete file
+// Delete file in doc form
if ($action=='remove_file')
{
$commande = new CommandeFournisseur($db);
@@ -510,6 +510,195 @@ if ($_GET["action"] == 'create')
}
}
+/*
+ * Add file in email form
+ */
+if ($_POST['addfile'])
+{
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir = $vardir.'/temp/';
+
+ $mesg=dol_add_file_process($upload_dir,0,0);
+
+ $_GET["action"]='presend';
+ $_POST["action"]='presend';
+}
+
+/*
+ * Remove file in email form
+ */
+if (! empty($_POST['removedfile']))
+{
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+
+ // Set tmp user directory
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir = $vardir.'/temp/';
+
+ $mesg=dol_remove_file_process($_POST['removedfile'],0);
+
+ $_GET["action"]='presend';
+ $_POST["action"]='presend';
+}
+
+/*
+ * Send mail
+ */
+if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
+{
+ $langs->load('mails');
+
+ $commande= new Commande($db);
+ $result=$commande->fetch($_POST['orderid']);
+ $result=$commande->fetch_client();
+
+ if ($result)
+ {
+ $ref = dol_sanitizeFileName($commande->ref);
+ $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+
+ if (is_readable($file))
+ {
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'])
+ {
+ // Le destinataire a ete fourni via la liste deroulante
+ if ($_POST['receiver'] < 0) // Id du tiers
+ {
+ $sendto = $commande->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $commande->client->contact_get_email($_POST['receiver']);
+ $sendtoid = $_POST['receiver'];
+ }
+ }
+
+ if (strlen($sendto))
+ {
+ $langs->load("commercial");
+
+ $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
+ $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
+ $message = $_POST['message'];
+ $sendtocc = $_POST['sendtocc'];
+ $deliveryreceipt = $_POST['deliveryreceipt'];
+
+ if ($_POST['action'] == 'send')
+ {
+ if (strlen($_POST['subject'])) $subject=$_POST['subject'];
+ else $subject = $langs->transnoentities('Order').' '.$commande->ref;
+ $actiontypecode='AC_COM';
+ $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
+ if ($message)
+ {
+ $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
+ $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
+ $actionmsg.=$message;
+ }
+ $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ }
+
+ // Create form object
+ include_once('../core/class/html.formmail.class.php');
+ $formmail = new FormMail($db);
+
+ $attachedfiles=$formmail->get_attached_files();
+ $filepath = $attachedfiles['paths'];
+ $filename = $attachedfiles['names'];
+ $mimetype = $attachedfiles['mimes'];
+
+ // Send mail
+ require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
+ if ($mailfile->error)
+ {
+ $mesg=''.$mailfile->error.'
';
+ }
+ else
+ {
+ $result=$mailfile->sendfile();
+ if ($result)
+ {
+ $mesg=''.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
';
+
+ $error=0;
+
+ // Initialisation donnees
+ $commande->sendtoid=$sendtoid;
+ $commande->actiontypecode=$actiontypecode;
+ $commande->actionmsg = $actionmsg;
+ $commande->actionmsg2= $actionmsg2;
+ $commande->orderrowid=$commande->id;
+
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('ORDER_SENTBYMAIL',$commande,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // Fin appel triggers
+
+ if ($error)
+ {
+ dol_print_error($db);
+ }
+ else
+ {
+ // 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;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg='';
+ if ($mailfile->error)
+ {
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.='
'.$mailfile->error;
+ }
+ else
+ {
+ $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+ }
+ $mesg.='
';
+ }
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').' !
';
+ $_GET["action"]='presend';
+ dol_syslog('Recipient email is empty');
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorCantReadFile',$file).'
';
+ dol_syslog('Failed to read file: '.$file);
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
';
+ dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
+ }
+}
+
/*
* View
@@ -520,6 +709,8 @@ llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur");
$html = new Form($db);
$formfile = new FormFile($db);
$formorder = new FormOrder($db);
+$productstatic = new Product($db);
+
/* *************************************************************************** */
/* */
@@ -527,12 +718,11 @@ $formorder = new FormOrder($db);
/* */
/* *************************************************************************** */
-$now=gmmktime();
-
-$productstatic = new Product($db);
+$now=dol_now();
$id = $_REQUEST['id'];
$ref= $_REQUEST['ref'];
+
if ($id > 0 || ! empty($ref))
{
//if ($mesg) print $mesg.'
';
@@ -1023,133 +1213,216 @@ if ($id > 0 || ! empty($ref))
print '';
- /**
- * Boutons actions
- */
- if ($user->societe_id == 0 && $_GET['action'] != 'editline' && $_GET['action'] != 'delete')
+ if ($_GET['action'] != 'presend')
{
- print '';
- if ($commande->statut == 0 && $num > 0)
+ /**
+ * Boutons actions
+ */
+ if ($user->societe_id == 0 && $_GET['action'] != 'editline' && $_GET['action'] != 'delete')
{
- if ($user->rights->fournisseur->commande->valider)
+ print '
";
}
- if ($commande->statut == 2)
+
+ print '
| ';
+ print ''; // ancre
+
+ /*
+ * Documents generes
+ */
+ $comfournref = dol_sanitizeFileName($commande->ref);
+ $file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf';
+ $relativepath = $comfournref.'/'.$comfournref.'.pdf';
+ $filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref;
+ $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
+ $genallowed=$user->rights->fournisseur->commande->creer;
+ $delallowed=$user->rights->fournisseur->commande->supprimer;
+
+ $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
+
+ print ' | ';
+
+ if ( $user->rights->fournisseur->commande->commander && ($commande->statut == 2 || $commande->statut == 6))
{
- if ($user->rights->fournisseur->commande->annuler)
- {
- print ''.$langs->trans("CancelOrder").'';
- }
+ /**
+ * Commander (action=commande)
+ */
+ print ' ';
+ print '';
}
- if ($user->rights->fournisseur->commande->annuler)
+ if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 ))
{
- print ''.$langs->trans("Delete").'';
+ /**
+ * Receptionner (action=livraison)
+ */
+ print ' ';
+ print '\n";
}
- print "";
+ // List of actions on element
+ // include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
+ // $formactions=new FormActions($db);
+ // $somethingshown=$formactions->showactions($commande,'supplier_order',$socid);
+
+
+ print ' |
';
}
- print '
| ';
- print ''; // ancre
/*
- * Documents generes
+ * Action presend
+ *
*/
- $comfournref = dol_sanitizeFileName($commande->ref);
- $file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf';
- $relativepath = $comfournref.'/'.$comfournref.'.pdf';
- $filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref;
- $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
- $genallowed=$user->rights->fournisseur->commande->creer;
- $delallowed=$user->rights->fournisseur->commande->supprimer;
-
- $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
-
-
- print ' | ';
-
-
- if ( $user->rights->fournisseur->commande->commander && ($commande->statut == 2 || $commande->statut == 6))
+ if ($_GET['action'] == 'presend')
{
- /**
- * Commander (action=commande)
- */
+ $ref = dol_sanitizeFileName($commande->ref);
+ $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+
print ' ';
- print '';
+ // Init list of files
+ if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
+ {
+ $formmail->clear_attached_files();
+ $formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
+ }
+
+ // Show form
+ $formmail->show_form();
+
+ print ' ';
}
- if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 ))
- {
- /**
- * Receptionner (action=livraison)
- */
- print ' ';
- print '\n";
- }
print ' |
';
+
}
else
{
diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php
index d50cc8fc8d4..1761821c75f 100644
--- a/htdocs/lib/files.lib.php
+++ b/htdocs/lib/files.lib.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2008-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
@@ -448,4 +448,111 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
}
+/**
+ * Get and save an upload file (for example after submitting a new file a mail form).
+ * All information used are in db, conf, langs, user and _FILES.
+ *
+ * @param upload_dir Directory to store upload files
+ * @param allowoverwrite 1=Allow overwrite existing file
+ * @param donotupdatesession 1=Do no edit _SESSION variable
+ * @return string Message with result of upload and store.
+ */
+function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=0)
+{
+ global $db,$user,$conf,$langs,$_FILES;
+
+ $mesg='';
+
+ if (! empty($_FILES['addedfile']['tmp_name']))
+ {
+ if (create_exdir($upload_dir) >= 0)
+ {
+ $resupload = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],$allowoverwrite,0, $_FILES['addedfile']['error']);
+ if (is_numeric($resupload) && $resupload > 0)
+ {
+ $mesg = ''.$langs->trans("FileTransferComplete").'
';
+
+ if (empty($donotupdatesession))
+ {
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
+ $formmail = new FormMail($db);
+ $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
+ }
+ }
+ else
+ {
+ $langs->load("errors");
+ if ($resupload < 0) // Unknown error
+ {
+ $mesg = ''.$langs->trans("ErrorFileNotUploaded").'
';
+ }
+ else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
+ {
+ $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus").'
';
+ }
+ else // Known error
+ {
+ $mesg = ''.$langs->trans($resupload).'
';
+ }
+ }
+ }
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg = ''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("File")).'
';
+ }
+
+ return $mesg;
+}
+
+
+/**
+ * Remove an uploaded file (for example after submitting a new file a mail form).
+ * All information used are in db, conf, langs, user and _FILES.
+ *
+ * @param filenb File nb to delete
+ * @param donotupdatesession 1=Do no edit _SESSION variable
+ * @return string Message with result of upload and store.
+ */
+function dol_remove_file_process($filenb,$donotupdatesession=0)
+{
+ global $db,$user,$conf,$langs,$_FILES;
+
+ $mesg='';
+
+ $keytodelete=$filenb;
+ $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)
+ {
+ $langs->load("other");
+
+ $mesg = ''.$langs->trans("FileWasRemoved",$filetodelete).'
';
+ //print_r($_FILES);
+
+ if (empty($donotupdatesession))
+ {
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
+ $formmail = new FormMail($db);
+ $formmail->remove_attached_files($keytodelete);
+ }
+ }
+ }
+
+ return $mesg;
+}
+
?>