Mutualize a lot of code

This commit is contained in:
Laurent Destailleur 2010-05-12 11:29:21 +00:00
parent f39d3cf574
commit fa8a201d04
7 changed files with 531 additions and 314 deletions

View File

@ -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 = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
}
else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
$mesg=dol_add_file_process($upload_dir,0,1);
}
if (! $isupload)
@ -934,6 +907,7 @@ else
* Mailing en mode edition
*/
if ($mesg) print $mesg."<br>";
if ($message) print $message."<br>";
print '<table class="border" width="100%">';

View File

@ -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 = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$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 = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
}
$_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 = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//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'];

View File

@ -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 = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
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 = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
$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 = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//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.'<br>';
@ -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')

View File

@ -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 = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
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 = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
$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 = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//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.'<br>';
@ -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')

View File

@ -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;

View File

@ -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='<div class="error">'.$mailfile->error.'</div>';
}
else
{
$result=$mailfile->sendfile();
if ($result)
{
$mesg='<div class="ok">'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.</div>';
$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='<div class="error">';
if ($mailfile->error)
{
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
$mesg.='<br>'.$mailfile->error;
}
else
{
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
$mesg.='</div>';
}
}
}
else
{
$langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
$_GET["action"]='presend';
dol_syslog('Recipient email is empty');
}
}
else
{
$langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
dol_syslog('Failed to read file: '.$file);
}
}
else
{
$langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'</div>';
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.'<br>';
@ -1023,133 +1213,216 @@ if ($id > 0 || ! empty($ref))
print '</div>';
/**
* Boutons actions
*/
if ($user->societe_id == 0 && $_GET['action'] != 'editline' && $_GET['action'] != 'delete')
if ($_GET['action'] != 'presend')
{
print '<div class="tabsAction">';
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 '<div class="tabsAction">';
// Validate
if ($commande->statut == 0 && $num > 0)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=valid"';
print '>'.$langs->trans('Validate').'</a>';
if ($user->rights->fournisseur->commande->valider)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=valid"';
print '>'.$langs->trans('Validate').'</a>';
}
}
}
if ($commande->statut == 1)
{
if ($user->rights->fournisseur->commande->approuver)
// Approve
if ($commande->statut == 1)
{
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>';
if ($user->rights->fournisseur->commande->approuver)
{
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>';
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
}
if ($user->rights->fournisseur->commande->annuler)
{
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
}
}
// Send
if ($commande->statut > 1)
{
if ($user->rights->fournisseur->commande->approuver)
{
$comref = dol_sanitizeFileName($commande->ref);
$file = $conf->fournisseur->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
if (file_exists($file))
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
}
}
}
// Cancel
if ($commande->statut == 2)
{
if ($user->rights->fournisseur->commande->annuler)
{
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
}
}
if ($user->rights->fournisseur->commande->annuler)
{
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
print "</div>";
}
if ($commande->statut == 2)
print '<table width="100%"><tr><td width="50%" valign="top">';
print '<a name="builddoc"></a>'; // 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 '</td><td valign="top" width="50%">';
if ( $user->rights->fournisseur->commande->commander && ($commande->statut == 2 || $commande->statut == 6))
{
if ($user->rights->fournisseur->commande->annuler)
{
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
}
/**
* Commander (action=commande)
*/
print '<br>';
print '<form name="commande" action="fiche.php?id='.$commande->id.'&amp;action=commande" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="commande">';
print '<table class="border" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("ToOrder").'</td></tr>';
print '<tr><td>'.$langs->trans("OrderDate").'</td><td>';
$date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
print $html->select_date($date_com,'','','','',"commande");
print '</td></tr>';
print '<tr><td>'.$langs->trans("OrderMode").'</td><td>';
$formorder->select_methodes_commande($_POST["methodecommande"],"methodecommande",1);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="30" type="text" name="comment" value="'.$_POST["comment"].'"></td></tr>';
print '<tr><td align="center" colspan="2"><input type="submit" class="button" name="'.$langs->trans("Activate").'"></td></tr>';
print '</table>';
print '</form>';
}
if ($user->rights->fournisseur->commande->annuler)
if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 ))
{
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
/**
* Receptionner (action=livraison)
*/
print '<br>';
print '<form action="fiche.php?id='.$commande->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="livraison">';
print '<table class="border" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Receive").'</td></tr>';
print '<tr><td>'.$langs->trans("DeliveryDate").'</td><td>';
print $html->select_date('','','','','',"commande");
print "</td></tr>\n";
print "<tr><td>".$langs->trans("Delivery")."</td><td>\n";
$liv = array();
$liv[''] = '&nbsp;';
$liv['tot'] = $langs->trans("TotalWoman");
$liv['par'] = $langs->trans("PartialWoman");
$liv['nev'] = $langs->trans("NeverReceived");
$liv['can'] = $langs->trans("Canceled");
print $html->select_array("type",$liv);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="30" type="text" name="comment"></td></tr>';
print '<tr><td align="center" colspan="2"><input type="submit" class="button" name="'.$langs->trans("Activate").'"></td></tr>';
print "</table>\n";
print "</form>\n";
}
print "</div>";
// 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 '</td></tr></table>';
}
print '<table width="100%"><tr><td width="50%" valign="top">';
print '<a name="builddoc"></a>'; // 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 '</td><td width="50%" valign="top">';
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 '<br>';
print '<form name="commande" action="fiche.php?id='.$commande->id.'&amp;action=commande" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="commande">';
print '<table class="border" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("ToOrder").'</td></tr>';
print '<tr><td>'.$langs->trans("OrderDate").'</td><td>';
$date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
print $html->select_date($date_com,'','','','',"commande");
print '</td></tr>';
print_titre($langs->trans('SendOrderByMail'));
print '<tr><td>'.$langs->trans("OrderMode").'</td><td>';
$formorder->select_methodes_commande($_POST["methodecommande"],"methodecommande",1);
print '</td></tr>';
// Cree l'objet formulaire mail
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
$formmail = new FormMail($db);
$formmail->fromtype = 'user';
$formmail->fromid = $user->id;
$formmail->fromname = $user->fullname;
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"];
$formmail->withtosocid=$soc->id;
$formmail->withtocc=1;
$formmail->withtoccsocid=0;
$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
$formmail->withtocccsocid=0;
$formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
$formmail->withfile=2;
$formmail->withbody=1;
$formmail->withdeliveryreceipt=1;
$formmail->withcancel=1;
// Tableau des substitutions
$formmail->substit['__ORDERREF__']=$commande->ref;
// Tableau des parametres complementaires
$formmail->param['action']='send';
$formmail->param['models']='supplier_order_send';
$formmail->param['orderid']=$commande->id;
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$commande->id;
print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="30" type="text" name="comment" value="'.$_POST["comment"].'"></td></tr>';
print '<tr><td align="center" colspan="2"><input type="submit" class="button" name="'.$langs->trans("Activate").'"></td></tr>';
print '</table>';
print '</form>';
// 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 '<br>';
}
if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 ))
{
/**
* Receptionner (action=livraison)
*/
print '<br>';
print '<form action="fiche.php?id='.$commande->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="livraison">';
print '<table class="border" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Receive").'</td></tr>';
print '<tr><td>'.$langs->trans("DeliveryDate").'</td><td>';
print $html->select_date('','','','','',"commande");
print "</td></tr>\n";
print "<tr><td>".$langs->trans("Delivery")."</td><td>\n";
$liv = array();
$liv[''] = '&nbsp;';
$liv['tot'] = $langs->trans("TotalWoman");
$liv['par'] = $langs->trans("PartialWoman");
$liv['nev'] = $langs->trans("NeverReceived");
$liv['can'] = $langs->trans("Canceled");
print $html->select_array("type",$liv);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="30" type="text" name="comment"></td></tr>';
print '<tr><td align="center" colspan="2"><input type="submit" class="button" name="'.$langs->trans("Activate").'"></td></tr>';
print "</table>\n";
print "</form>\n";
}
print '</td></tr></table>';
}
else
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2008-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
@ -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 = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
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 = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
}
else
{
$langs->load("errors");
$mesg = '<div class="warning">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("File")).'</div>';
}
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 = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
//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;
}
?>