Mutualize code for forms to send emails. Remove thousand line of code.

This commit is contained in:
Laurent Destailleur 2017-09-17 15:38:50 +02:00
parent e014ac6ea9
commit ab5724e7ff
29 changed files with 839 additions and 1410 deletions

View File

@ -11,9 +11,10 @@ NEW: complete_head_from_modules() in ldap_prepare_head()
WARNING: WARNING:
Following changes may create regression for some external modules, but were necessary to make Dolibarr better: Following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
* The methode "cloture" on contact were renamed into "closeAll". * The methode "cloture" on contact were renamed into "closeAll".
* The substitution key for reference of object is now __REF__ whatever is the object (it replaces __ORDERREF__,
__PROPALREF__, ...)
***** ChangeLog for 6.0.0 compared to 5.0.* ***** ***** ChangeLog for 6.0.0 compared to 5.0.* *****

View File

@ -740,15 +740,6 @@ if ($id)
print '</td>'; print '</td>';
print "</tr>"; print "</tr>";
if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates')
{
print '<tr><td colspan="8">* '.$langs->trans("AvailableVariables").": ";
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$tmp=FormMail::getAvailableSubstitKey('formemail');
print implode(', ', $tmp);
print '</td></tr>';
}
$colspan=count($fieldlist)+3; $colspan=count($fieldlist)+3;
if ($id == 4) $colspan++; if ($id == 4) $colspan++;

View File

@ -165,6 +165,8 @@ if (! empty($triggers))
if ($module == 'shipping') $module = 'expedition_bon'; if ($module == 'shipping') $module = 'expedition_bon';
if ($module == 'member') $module = 'adherent'; if ($module == 'member') $module = 'adherent';
if ($module == 'project') $module = 'projet'; if ($module == 'project') $module = 'projet';
if ($module == 'proposal_supplier') $module = 'supplier_proposal';
//print 'module='.$module.'<br>'; //print 'module='.$module.'<br>';
if (! empty($conf->$module->enabled)) if (! empty($conf->$module->enabled))
{ {

View File

@ -1224,7 +1224,6 @@ else
// Print mail content // Print mail content
print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic'); print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
dol_fiche_head(null, '', '', -1); dol_fiche_head(null, '', '', -1);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';

View File

@ -125,7 +125,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
if ($cancel) $action = ''; if ($cancel)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action='';
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
@ -638,16 +646,10 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
/*
* Send mail
*/
// Actions to send emails // Actions to send emails
$actiontypecode='AC_OTH_AUTO'; $actiontypecode='AC_OTH_AUTO';
$trigger_name='PROPAL_SENTBYMAIL'; $trigger_name='PROPAL_SENTBYMAIL';
$paramname='id'; $autocopy='MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
$mode='emailfromproposal';
$trackid='pro'.$object->id; $trackid='pro'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
@ -2361,123 +2363,13 @@ if ($action == 'create')
print '</div></div></div>'; print '</div></div></div>';
} }
/* // Presend form
* Action presend $modelmail='propal_send';
*/ $defaulttopic='SendPropalRef';
if ($action == 'presend') $diroutput = $conf->propal->dir_output;
{ $trackid = 'pro'.$object->id;
$object->fetch_projet();
$ref = dol_sanitizeFileName($object->ref); include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
}
// Build document if it not exists
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendPropalByMail'));
dol_fiche_head('');
// Create form object
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='pro'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'pro'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
$liste [$key] = $value;
$formmail->withto = GETPOST("sendto") ? GETPOST("sendto") : $liste;
$formmail->withtocc = $liste;
$formmail->withtoccc = (! empty($conf->global->MAIN_EMAIL_USECCC) ? $conf->global->MAIN_EMAIL_USECCC : false);
if (empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->trans('SendPropalRef', '__PROPREF__');
} else if (! empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->trans('SendPropalRef', '__PROPREF__ (__REFCLIENT__)');
}
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit['__PROPREF__'] = $object->ref; // For backward compatibility
// Find the good contact adress
$custcontact = '';
$contactarr = array();
$contactarr = $object->liste_contact(- 1, 'external');
if (is_array($contactarr) && count($contactarr) > 0) {
foreach ($contactarr as $contact) {
if ($contact ['libelle'] == $langs->trans('TypeContact_propal_external_CUSTOMER')) { // TODO Use code and not label
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
$custcontact = $contactstatic->getFullName($langs, 1);
}
}
if (! empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action'] = 'send';
$formmail->param['models'] = 'propal_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['id'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
print $formmail->get_form();
dol_fiche_end();
}
} }
// End of page // End of page

View File

@ -118,15 +118,10 @@ if (empty($reshook))
{ {
if ($cancel) if ($cancel)
{ {
if ($action != 'addlink' && $action != 'updateline') if (! empty($backtopage))
{ {
$urltogo=$backtopage?$backtopage:dol_buildpath('/commande/list.php',1); header("Location: ".$backtopage);
header("Location: ".$urltogo);
exit; exit;
}
if ($id > 0 || ! empty($ref)) {
$ret = $object->fetch($id,$ref);
$object->fetch_thirdparty();
} }
$action=''; $action='';
} }
@ -1256,13 +1251,13 @@ if (empty($reshook))
exit(); exit();
} }
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Actions to send emails // Actions to send emails
$trigger_name='ORDER_SENTBYMAIL'; $trigger_name='ORDER_SENTBYMAIL';
$paramname='id'; $paramname='id';
$mode='emailfromorder'; $autocopy='MAIN_MAIL_AUTOCOPY_ORDER_TO'; // used to know the automatic BCC to add
$trackid='ord'.$object->id; $trackid='ord'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
@ -2596,134 +2591,13 @@ if ($action == 'create' && $user->rights->commande->creer)
print '</div></div></div>'; print '</div></div></div>';
} }
/* // Presend form
* Action presend
*/
if ($action == 'presend')
{
$object->fetch_projet();
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
}
// Show email form
// By default if $action=='presend'
$titreform='SendOrderByMail';
$topicmail='';
if (empty($object->ref_client)) {
$topicmail = $outputlangs->trans('SendOrderRef', '__ORDERREF__');
} else if (! empty($object->ref_client)) {
$topicmail = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)');
}
$action='send';
$modelmail='order_send'; $modelmail='order_send';
$defaulttopic='SendOrderRef';
$diroutput = $conf->commande->dir_output;
$trackid = 'ord'.$object->id;
// Build document if it not exists include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans($titreform));
dol_fiche_head('');
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='ord'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
$liste [$key] = $value;
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
$formmail->withtocc = $liste;
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
$formmail->withtopic = $topicmail;
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit ['__ORDERREF__'] = $object->ref;
$custcontact = '';
$contactarr = array();
$contactarr = $object->liste_contact(- 1, 'external');
if (is_array($contactarr) && count($contactarr) > 0)
{
foreach ($contactarr as $contact)
{
if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
$custcontact = $contactstatic->getFullName($langs, 1);
}
}
if (! empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action'] = $action;
$formmail->param['models'] = $modelmail;
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['orderid'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
// Show form
print $formmail->get_form();
dol_fiche_end();
}
} }
} }

View File

@ -132,7 +132,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
if ($cancel) $action=''; if ($cancel)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action='';
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
@ -1957,20 +1965,17 @@ if (empty($reshook))
exit(); exit();
} }
// Actions when printing a doc from card
/* include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
* Send mail
*/
// Actions to send emails // Actions to send emails
if (empty($id)) $id=$facid; if (empty($id)) $id=$facid;
$trigger_name='BILL_SENTBYMAIL'; $trigger_name='BILL_SENTBYMAIL';
$paramname='id'; $paramname='id';
$mode='emailfrominvoice'; $autocopy='MAIN_MAIL_AUTOCOPY_INVOICE_TO';
$trackid='inv'.$object->id; $trackid='inv'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Actions to build doc // Actions to build doc
$upload_dir = $conf->facture->dir_output; $upload_dir = $conf->facture->dir_output;
$permissioncreate=$user->rights->facture->creer; $permissioncreate=$user->rights->facture->creer;
@ -2003,8 +2008,6 @@ if (empty($reshook))
$action = 'edit_extras'; $action = 'edit_extras';
} }
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) { if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) {
if ($action == 'addcontact') { if ($action == 'addcontact') {
$result = $object->fetch($id); $result = $object->fetch($id);
@ -4335,143 +4338,15 @@ else if ($id > 0 || ! empty($ref))
print '</div></div></div>'; print '</div></div></div>';
} }
else
{
/*
* Action presend (or prerelance)
*/
$object->fetch_projet();
// By default if $action=='presend' // Presend form
$titreform = 'SendBillByMail';
$topicmail = 'SendBillRef';
$modelmail='facture_send'; $modelmail='facture_send';
$defaulttopic='SendBillRef';
$diroutput = $conf->facture->dir_output;
$trackid = 'inv'.$object->id;
if ($action == 'prerelance') // For backward compatibility include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
{
$titrefrom = 'SendReminderBillByMail';
$topicmail = 'SendReminderBillRef';
$modelmail = 'facture_relance';
$action = 'relance';
} else
$action = 'send';
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('bills');
}
// Build document if it not exists
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model','alpha') ? GETPOST('model','alpha') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans($titreform));
// Cree l'objet formulaire mail
dol_fiche_head();
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype','alpha')?GETPOST('fromtype','alpha'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='inv'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'inv'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
$liste [$key] = $value;
}
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste; // List suggested for send to
$formmail->withtocc = $liste; // List suggested for CC
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
if (empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->transnoentities($topicmail, '__REF__');
} else if (! empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->transnoentities($topicmail, '__REF__ (__REFCLIENT__)');
}
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object, $outputlangs);
$formmail->substit['__INVREF__'] = $object->ref;
// Find the good contact adress
$custcontact = '';
$contactarr = array();
$contactarr = $object->liste_contact(- 1, 'external');
if (is_array($contactarr) && count($contactarr) > 0) {
foreach ($contactarr as $contact) {
if ($contact['libelle'] == $langs->trans('TypeContact_facture_external_BILLING')) { // TODO Use code and not label
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
$custcontact = $contactstatic->getFullName($langs, 1);
}
}
if (! empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
}
}
// Tableau des parametres complementaires du post
$formmail->param['action'] = $action;
$formmail->param['models'] = $modelmail;
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['facid'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
print $formmail->get_form();
dol_fiche_end();
}
} }
llxFooter(); llxFooter();

View File

@ -2242,7 +2242,6 @@ else
$formmail->withdeliveryreceipt = 1; $formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1; $formmail->withcancel = 1;
// Array of substitutions // Array of substitutions
$formmail->withsubstit='AvailableVariables';
$formmail->setSubstitFromObject($object); $formmail->setSubstitFromObject($object);
$datenextexpiration=''; $datenextexpiration='';
foreach($object->lines as $line) foreach($object->lines as $line)

View File

@ -28,7 +28,7 @@
// $cancel must be defined // $cancel must be defined
// $id or $ref must be defined (object is loaded in this file with fetch) // $id or $ref must be defined (object is loaded in this file with fetch)
if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtask', 'add')))) && empty($cancel)) if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0))
{ {
$ret = $object->fetch($id, $ref); $ret = $object->fetch($id, $ref);
if ($ret > 0) if ($ret > 0)

View File

@ -64,11 +64,9 @@ if (! $error && $massaction == 'confirm_presend')
$langs->load("mails"); $langs->load("mails");
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if (!$error && !isset($user->email)) $listofobjectid=array();
{ $listofobjectthirdparties=array();
$error++; $listofobjectref=array();
setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
}
if (! $error) if (! $error)
{ {
@ -76,12 +74,9 @@ if (! $error && $massaction == 'confirm_presend')
if ($objecttmp->element == 'expensereport') $thirdparty=new User($db); if ($objecttmp->element == 'expensereport') $thirdparty=new User($db);
$objecttmp=new $objectclass($db); $objecttmp=new $objectclass($db);
$listofobjectid=array();
$listofobjectthirdparties=array();
$listofobjectref=array();
foreach($toselect as $toselectid) foreach($toselect as $toselectid)
{ {
$objecttmp=new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use $objecttmp=new $objectclass($db); // we must create new instance because instance is saved into $listofobjectref array for future use
$result=$objecttmp->fetch($toselectid); $result=$objecttmp->fetch($toselectid);
if ($result > 0) if ($result > 0)
{ {
@ -93,10 +88,39 @@ if (! $error && $massaction == 'confirm_presend')
$listofobjectref[$thirdpartyid][$toselectid]=$objecttmp; $listofobjectref[$thirdpartyid][$toselectid]=$objecttmp;
} }
} }
//var_dump($listofobjectthirdparties);exit; }
// Check mandatory parameters
if (empty($user->email))
{
$error++;
setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
$massaction='presend';
}
// Loop on each thirdparty $receiver=$_POST['receiver'];
if (! is_array($receiver))
{
if (empty($receiver) || $receiver == '-1') $receiver=array();
else $receiver=array($receiver);
}
if (count($receiver) == 0 && count($listofobjectthirdparties) == 1) // if only one recipient, receiver is mandatory
{
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings');
$massaction='presend';
}
if (! GETPOST('subject','none'))
{
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTopic")), null, 'warnings');
$massaction='presend';
}
// Loop on each recipient/thirdparty
if (! $error)
{
foreach ($listofobjectthirdparties as $thirdpartyid) foreach ($listofobjectthirdparties as $thirdpartyid)
{ {
$result = $thirdparty->fetch($thirdpartyid); $result = $thirdparty->fetch($thirdpartyid);
@ -112,12 +136,6 @@ if (! $error && $massaction == 'confirm_presend')
$sendtoid = array(); $sendtoid = array();
// Define $sendto // Define $sendto
$receiver=$_POST['receiver'];
if (! is_array($receiver))
{
if ($receiver == '-1') $receiver=array();
else $receiver=array($receiver);
}
$tmparray=array(); $tmparray=array();
if (trim($_POST['sendto'])) if (trim($_POST['sendto']))
{ {
@ -433,11 +451,11 @@ if (! $error && $massaction == 'confirm_presend')
//setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file
setEventMessages($resaction, null, 'warnings'); setEventMessages($resaction, null, 'warnings');
} }
}
$action='list'; $action='list';
$massaction=''; $massaction='';
} }
}
if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_search')) if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_search'))
{ {
@ -690,8 +708,19 @@ if (! $error && $massaction == 'delete' && $permtodelete)
$result=$objecttmp->fetch($toselectid); $result=$objecttmp->fetch($toselectid);
if ($result > 0) if ($result > 0)
{ {
// Refuse deletion for some status ?
/*
if ($objectclass == 'Facture' && $objecttmp->status == Facture::STATUS_DRAFT)
{
$langs->load("errors");
$nbignored++;
$resaction.='<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction',$object->ref).'</div><br>';
continue;
}*/
if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
else $result = $objecttmp->delete($user); else $result = $objecttmp->delete($user);
if ($result <= 0) if ($result <= 0)
{ {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');

View File

@ -24,7 +24,7 @@
// $mysoc must be defined // $mysoc must be defined
// $id must be defined // $id must be defined
// $paramname must be defined // $paramname must be defined
// $mode must be defined // $mode must be defined (used to know the automatic BCC to add)
// $trigger_name must be set (can be '') // $trigger_name must be set (can be '')
// $actiontypecode can be set // $actiontypecode can be set
// $object and $uobject may be defined // $object and $uobject may be defined
@ -268,12 +268,12 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$message=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); $message=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
$sendtobcc= GETPOST('sendtoccc'); $sendtobcc= GETPOST('sendtoccc');
if ($mode == 'emailfromproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); // Autocomplete the $sendtobcc
if ($mode == 'emailfromorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO...
if ($mode == 'emailfrominvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); if (! empty($autocopy))
if ($mode == 'emailfromsupplierproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)); {
if ($mode == 'emailfromsupplierorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)); $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc?", ":"").$conf->global->$autocopy));
if ($mode == 'emailfromsupplierinvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); }
$deliveryreceipt = $_POST['deliveryreceipt']; $deliveryreceipt = $_POST['deliveryreceipt'];

View File

@ -343,7 +343,7 @@ class FormMail extends Form
if (count($modelmail_array)>0) if (count($modelmail_array)>0)
{ {
$out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n"; $out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
$out.= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1); $out.= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100');
if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1); if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
$out.= ' &nbsp; '; $out.= ' &nbsp; ';
$out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">'; $out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">';
@ -370,7 +370,7 @@ class FormMail extends Form
$out.= '<table class="border" width="100%">'."\n"; $out.= '<table class="border" width="100%">'."\n";
// Substitution array // Substitution array
if (! empty($this->withsubstit)) if (! empty($this->withsubstit)) // Unset of set ->withsubstit=0 to disable this.
{ {
$out.= '<tr><td colspan="2" align="right">'; $out.= '<tr><td colspan="2" align="right">';
//$out.='<div class="floatright">'; //$out.='<div class="floatright">';
@ -380,7 +380,7 @@ class FormMail extends Form
$help.=$key.' -> '.$langs->trans(dol_string_nohtmltag($val)).'<br>'; $help.=$key.' -> '.$langs->trans(dol_string_nohtmltag($val)).'<br>';
} }
if (is_numeric($this->withsubstit)) $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $help, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage if (is_numeric($this->withsubstit)) $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $help, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage
else $out.= $form->textwithpicto($langs->trans($this->withsubstit), $help, 1, 'help', '', 0, 2, 'substittooltip'); // New usage else $out.= $form->textwithpicto($langs->trans('AvailableVariables'), $help, 1, 'help', '', 0, 2, 'substittooltip'); // New usage
$out.= "</td></tr>\n"; $out.= "</td></tr>\n";
//$out.='</div>'; //$out.='</div>';
} }
@ -746,24 +746,31 @@ class FormMail extends Form
} }
// Complete substitution array // Complete substitution array
if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_ADD_PAYMENT_URL)) $paymenturl='';
if (! empty($conf->global->PAYMENT_ADD_PAYMENT_URL) // Option to enable to add online link into __PERSONALIZED__
|| (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_ADD_PAYMENT_URL))
)
{ {
require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php'; if (empty($this->substit['__REF__']))
{
//$paymenturl='LinkToPayOnlineNotAvailableInThisContext';
$paymenturl='';
}
else
{
// Set the online payment message and url link into __PERSONALIZED__ key
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
$langs->load('paypal'); $langs->load('paypal');
$typeforonlinepayment='free';
// Set the paypal message and url link into __PERSONALIZED__ key if ($this->param["models"]=='order_send') $typeforonlinepayment='order'; // TODO use detection on something else than template
if ($this->param["models"]=='order_send') if ($this->param["models"]=='facture_send') $typeforonlinepayment='invoice'; // TODO use detection on something else than template
{ $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
$url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']?$this->substit['__ORDERREF__']:$this->substit['__REF__']); //$paymenturl=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url));
$this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url)); $paymenturl=$url;
}
if ($this->param["models"]=='facture_send')
{
$url=getPaypalPaymentUrl(0,'invoice',$this->substit['__REF__']);
$this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url));
} }
} }
$this->substit['__PERSONALIZED__']=$paymenturl;
$this->substit['__ONLINE_PAYMENT_URL__']='YY'.$paymenturl;
//Add lines substitution key from each line //Add lines substitution key from each line
$lines = ''; $lines = '';
@ -849,7 +856,7 @@ class FormMail extends Form
{ {
$out.= '<script type="text/javascript" language="javascript">'; $out.= '<script type="text/javascript" language="javascript">';
$out.= 'jQuery(document).ready(function () {'; $out.= 'jQuery(document).ready(function () {';
$out.= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is calle at every key pressed ! */ $out.= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
var code = e.keyCode || e.which; var code = e.keyCode || e.which;
if (code == 13) { if (code == 13) {
e.preventDefault(); e.preventDefault();

View File

@ -130,7 +130,7 @@ function limitChars(textarea, limit, infodiv)
print "<table class=\"border centpercent\">\n"; print "<table class=\"border centpercent\">\n";
// Substitution array // Substitution array
if ($this->withsubstit) if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
{ {
print "<tr><td colspan=\"2\">"; print "<tr><td colspan=\"2\">";
$help=""; $help="";

View File

@ -5258,7 +5258,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
} }
} }
$substitutionarray['__ONLINE_PAYMENT_XXX__'] = 'todo'; $substitutionarray['__ONLINE_PAYMENT_URL__'] = 'LinkToPayOnlineIfApplicable';
} }
if (empty($exclude) || ! in_array('objectamount', $exclude)) if (empty($exclude) || ! in_array('objectamount', $exclude))
{ {

View File

@ -117,7 +117,7 @@ function showOnlinePaymentUrl($type,$ref)
* @param int $mode 0=True url, 1=Url formated with colors * @param int $mode 0=True url, 1=Url formated with colors
* @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...)
* @param string $ref Ref of object * @param string $ref Ref of object
* @param int $amount Amount * @param int $amount Amount (required for $type='free' only)
* @param string $freetag Free tag * @param string $freetag Free tag
* @return string Url string * @return string Url string
*/ */

View File

@ -0,0 +1,206 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/*
* Code to ouput content when action is presend
*
* $trackid must be defined
* $modelmail
* $defaulttopic
* $diroutput
*/
if ($action == 'presend')
{
$langs->load("mails");
$titreform='SendMail';
$object->fetch_projet();
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
//
if ($object->element == 'invoice_supplier')
{
$fileparams = dol_most_recent_file($diroutput . '/' . get_exdir($object->id,2,0,0,$object,$object->element).$ref, preg_quote($ref,'/').'([^\-])+');
}
$file = $fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
{
$newlang = $_REQUEST['lang_id'];
}
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
{
$newlang = $object->thirdparty->default_lang;
}
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
}
$topicmail='';
if (empty($object->ref_client)) {
$topicmail = $outputlangs->trans($defaulttopic, '__REF__');
} else if (! empty($object->ref_client)) {
$topicmail = $outputlangs->trans($defaulttopic, '__REF__ (__REFCLIENT__)');
}
// Build document if it not exists
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans($titreform));
dol_fiche_head('');
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if ($formmail->fromtype === 'user')
{
$formmail->fromid = $user->id;
}
$formmail->trackid=$trackid;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
if ($object->element == 'expensereport')
{
$fuser = new User($db);
$fuser->fetch($object->fk_user_author);
$liste['thirdparty'] = $fuser->getFullName($langs)." &lt;".$fuser->email."&gt;";
}
elseif ($object->element == 'societe')
{
foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
$liste[$key] = $value;
}
}
else
{
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
$liste[$key] = $value;
}
}
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
$formmail->withtocc = $liste;
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
$formmail->withtopic = $topicmail;
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Make substitution in email content
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
$substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '<img src="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-read.php?tag=' . $object->thirdparty->tag . '&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) . '" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '';
$substitutionarray['__PERSONALIZED__'] = '';
$substitutionarray['__CONTACTCIVNAME__'] = '';
// Add specific substitution for contracts
if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))
{
$datenextexpiration = '';
foreach ($object->lines as $line)
{
if ($line->statut != 4)
continue;
if ($line->date_fin_prevue > $datenextexpiration)
$datenextexpiration = $line->date_fin_prevue;
}
$substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc');
$substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard');
}
// Choose one contact for the __CONTACTCIVNAME__ TODO Really not reliable.
/*
$custcontact = '';
$contactarr = array();
$contactarr = $object->liste_contact(-1, 'external');
if (is_array($contactarr) && count($contactarr) > 0)
{
foreach ($contactarr as $contact)
{
if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
$custcontact = $contactstatic->getFullName($langs, 1);
}
}
if (! empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
}
}*/
$parameters = array(
'mode' => 'formemail'
);
complete_substitutions_array($substitutionarray, $outputlangs, $object, $parameters);
// Tableau des substitutions
$formmail->substit = $substitutionarray;
// Tableau des parametres complementaires
$formmail->param['action'] = 'send';
$formmail->param['models'] = $modelmail;
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['id'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
// Show form
print $formmail->get_form();
dol_fiche_end();
}

View File

@ -67,10 +67,7 @@ if ($formmail->fromtype === 'user')
{ {
$formmail->fromid = $user->id; $formmail->fromid = $user->id;
} }
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set
{
$formmail->trackid = $trackid; $formmail->trackid = $trackid;
}
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{ {
include DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; include DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';

View File

@ -349,7 +349,10 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("interventions"); $langs->load("interventions");
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref);
}
// Parameters $object->sendtoid defined by caller // Parameters $object->sendtoid defined by caller
//$object->sendtoid=0; //$object->sendtoid=0;
@ -419,6 +422,54 @@ class InterfaceActionsAuto extends DolibarrTriggers
// Parameters $object->sendtoid defined by caller // Parameters $object->sendtoid defined by caller
//$object->sendtoid=0; //$object->sendtoid=0;
} }
elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE')
{
$langs->load("agenda");
$langs->load("other");
$langs->load("propal");
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->sendtoid=0;
}
elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL')
{
$langs->load("agenda");
$langs->load("other");
$langs->load("propal");
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
}
// Parameters $object->sendtoid defined by caller
//$object->sendtoid=0;
}
elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED')
{
$langs->load("agenda");
$langs->load("other");
$langs->load("propal");
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
$object->sendtoid=0;
}
elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED')
{
$langs->load("agenda");
$langs->load("other");
$langs->load("propal");
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
$object->sendtoid=0;
}
elseif ($action == 'ORDER_SUPPLIER_CREATE') elseif ($action == 'ORDER_SUPPLIER_CREATE')
{ {
$langs->load("agenda"); $langs->load("agenda");

View File

@ -127,7 +127,13 @@ if (empty($reshook))
{ {
if ($cancel) if ($cancel)
{ {
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action=''; $action='';
$fk_projet=''; $fk_projet='';
$date_start=''; $date_start='';
$date_end=''; $date_end='';
@ -1260,6 +1266,15 @@ if (empty($reshook))
} }
} }
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Actions to send emails
$trigger_name='EXPENSEREPORT_SENTBYMAIL';
$autocopy='MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
$trackid='exp'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Actions to build doc // Actions to build doc
$upload_dir = $conf->expensereport->dir_output; $upload_dir = $conf->expensereport->dir_output;
$permissioncreate = $user->rights->expensereport->creer; $permissioncreate = $user->rights->expensereport->creer;
@ -2201,6 +2216,14 @@ if ($action != 'create' && $action != 'edit')
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
$object->fetch($id, $ref); $object->fetch($id, $ref);
// Send
if ($object->fk_statut > ExpenseReport::STATUS_DRAFT) {
//if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expensereport->expensereport_advance->send)) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendByMail') . '</a></div>';
//} else
// print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('SendByMail') . '</a></div>';
}
/* Si l'état est "Brouillon" /* Si l'état est "Brouillon"
* ET user à droit "creer/supprimer" * ET user à droit "creer/supprimer"
@ -2354,6 +2377,13 @@ print '</div>';
//$conf->global->DOL_URL_ROOT_DOCUMENT_PHP=dol_buildpath('/expensereport/documentwrapper.php',1); //$conf->global->DOL_URL_ROOT_DOCUMENT_PHP=dol_buildpath('/expensereport/documentwrapper.php',1);
// Select mail models is same action as presend
if (GETPOST('modelselected')) {
$action = 'presend';
}
if ($action != 'presend')
{
print '<div class="fichehalfleft">'; print '<div class="fichehalfleft">';
/* /*
@ -2395,6 +2425,16 @@ if ($action != 'create' && $action != 'edit' && ($id || $ref))
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
} }
} }
}
// Presend form
$modelmail='expensereport';
$defaulttopic='SendExpenseReportRef';
$diroutput = $conf->expensereport->dir_output;
$trackid = 'exp'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
llxFooter(); llxFooter();

View File

@ -714,16 +714,19 @@ if (empty($reshook))
exit; exit;
} }
/* // Actions when printing a doc from card
* Send mail include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
*/
// Actions to send emails // Actions to send emails
$paramname='id'; $trigger_name='FICHINTER_SENTBYMAIL';
$mode='emailfromintervention'; $autocopy='MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
$trackid='int'.$object->id; $trackid='int'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Actions to build doc
$upload_dir = $conf->ficheinter->dir_output;
$permissioncreate = $user->rights->ficheinter->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
if ($action == 'update_extras') if ($action == 'update_extras')
{ {
@ -752,11 +755,6 @@ if (empty($reshook))
if ($error) $action = 'edit_extras'; if ($error) $action = 'edit_extras';
} }
// Actions to build doc
$upload_dir = $conf->ficheinter->dir_output;
$permissioncreate = $user->rights->ficheinter->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer)
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
@ -1714,124 +1712,18 @@ else if ($id > 0 || ! empty($ref))
} }
/* // Select mail models is same action as presend
* Action presend
*/
if (GETPOST('modelselected')) { if (GETPOST('modelselected')) {
$action = 'presend'; $action = 'presend';
} }
if ($action == 'presend')
{
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file=$fileparams['fullname'];
// Define output language // Presend form
$outputlangs = $langs; $modelmail='fichinter_send';
$newlang = ''; $defaulttopic='SendInterventionRef';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $diroutput = $conf->ficheinter->dir_output;
$newlang = $_REQUEST['lang_id']; $trackid = 'int'.$object->id;
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang)) include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('interventions');
}
// Build document if it not exists
if (! $file || ! is_readable($file))
{
$result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0)
{
dol_print_error($db,$result);
exit;
}
$fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file=$fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendInterventionByMail'));
dol_fiche_head('');
// Create form object
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='int'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'int'.$object->id);
}
$formmail->withfrom=1;
$liste=array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
$formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
$formmail->withtocc=$liste;
$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
$formmail->withtopic=$outputlangs->trans('SendInterventionRef','__FICHINTERREF__');
$formmail->withfile=2;
$formmail->withbody=1;
$formmail->withdeliveryreceipt=1;
$formmail->withcancel=1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit['__FICHINTERREF__']=$object->ref;
//Find the good contact adress
$custcontact='';
$contactarr=array();
$contactarr=$object->liste_contact(-1,'external');
if (is_array($contactarr) && count($contactarr)>0) {
foreach($contactarr as $contact) {
if ($contact['libelle']==$langs->trans('TypeContact_fichinter_external_CUSTOMER')) {
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contactstatic=new Contact($db);
$contactstatic->fetch($contact['id']);
$custcontact=$contactstatic->getFullName($langs,1);
}
}
if (!empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action']='send';
$formmail->param['models']='fichinter_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['fichinter_id']=$object->id;
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
// Init list of files
if (GETPOST("mode")=='init')
{
$formmail->clear_attached_files();
$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
}
print $formmail->get_form();
dol_fiche_end();
}
} }

View File

@ -134,7 +134,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
if ($cancel) $action=''; if ($cancel)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action='';
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
@ -904,11 +912,21 @@ if (empty($reshook))
} }
} }
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Actions to send emails
$trigger_name='ORDER_SUPPLIER_SENTBYMAIL';
$autocopy='MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
$trackid='sor'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Actions to build doc // Actions to build doc
$upload_dir = $conf->fournisseur->commande->dir_output; $upload_dir = $conf->fournisseur->commande->dir_output;
$permissioncreate = $user->rights->fournisseur->commande->creer; $permissioncreate = $user->rights->fournisseur->commande->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
if ($action == 'update_extras') if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
@ -946,9 +964,6 @@ if (empty($reshook))
} }
} }
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
/* /*
* Create an order * Create an order
*/ */
@ -1158,18 +1173,6 @@ if (empty($reshook))
} }
} }
/*
* Send mail
*/
// Actions to send emails
$trigger_name='ORDER_SUPPLIER_SENTBYMAIL';
$paramname='id';
$mode='emailfromsupplierorder';
$trackid='sor'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel','alpha')) if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel','alpha'))
{ {
$ws_url = $object->thirdparty->webservices_url; $ws_url = $object->thirdparty->webservices_url;
@ -2143,343 +2146,6 @@ elseif (! empty($object->id))
dol_fiche_end(); dol_fiche_end();
/*
* Action presend
*/
if (GETPOST('modelselected')) {
$action = 'presend';
}
if ($action == 'presend')
{
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file=$fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
}
// Build document if it not exists
if (! $file || ! is_readable($file))
{
$result= $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0)
{
dol_print_error($db,$result);
exit;
}
$fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file=$fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendOrderByMail'));
dol_fiche_head('');
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='sor'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'sor'.$object->id);
}
$formmail->withfrom=1;
$liste=array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
$formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
$formmail->withtocc=$liste;
$formmail->withtoccc=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false);
$formmail->withtopic=$outputlangs->trans('SendOrderRef','__REF__');
$formmail->withfile=2;
$formmail->withbody=1;
$formmail->withdeliveryreceipt=1;
$formmail->withcancel=1;
$object->fetch_projet();
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit['__ORDERREF__']=$object->ref; // For backward compatibility
$formmail->substit['__ORDERSUPPLIERREF__']=$object->ref_supplier; // For backward compatibility
$formmail->substit['__SUPPLIERORDERREF__']=$object->ref_supplier;
//Find the good contact adress
$custcontact='';
$contactarr=array();
$contactarr=$object->liste_contact(-1,'external');
if (is_array($contactarr) && count($contactarr)>0) {
foreach($contactarr as $contact) {
if ($contact['libelle']==$langs->trans('TypeContact_order_supplier_external_BILLING')) {
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contactstatic=new Contact($db);
$contactstatic->fetch($contact['id']);
$custcontact=$contactstatic->getFullName($langs,1);
}
}
if (!empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action']='send';
$formmail->param['models']='order_supplier_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['orderid']=$object->id;
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
// Init list of files
if (GETPOST("mode")=='init')
{
$formmail->clear_attached_files();
$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
}
// Show form
print $formmail->get_form();
dol_fiche_end();
}
/*
* Action webservice
*/
elseif ($action == 'webservice' && GETPOST('mode', 'alpha') != "send" && ! GETPOST('cancel','alpha'))
{
$mode = GETPOST('mode', 'alpha');
$ws_url = $object->thirdparty->webservices_url;
$ws_key = $object->thirdparty->webservices_key;
$ws_user = GETPOST('ws_user','alpha');
$ws_password = GETPOST('ws_password','alpha');
// NS and Authentication parameters
$ws_ns = 'http://www.dolibarr.org/ns/';
$ws_authentication = array(
'dolibarrkey'=>$ws_key,
'sourceapplication'=>'DolibarrWebServiceClient',
'login'=>$ws_user,
'password'=>$ws_password,
'entity'=>''
);
print load_fiche_titre($langs->trans('CreateRemoteOrder'),'');
//Is everything filled?
if (empty($ws_url) || empty($ws_key)) {
setEventMessages($langs->trans("ErrorWebServicesFieldsRequired"), null, 'errors');
$mode = "init";
$error_occurred = true; //Don't allow to set the user/pass if thirdparty fields are not filled
} else if ($mode != "init" && (empty($ws_user) || empty($ws_password))) {
setEventMessages($langs->trans("ErrorFieldsRequired"), null, 'errors');
$mode = "init";
}
if ($mode == "init")
{
//Table/form header
print '<table class="border" width="100%">';
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="webservice">';
print '<input type="hidden" name="mode" value="check">';
if ($error_occurred)
{
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
}
else
{
$textinput_size = "50";
// Webservice url
print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td colspan="3">'.dol_print_url($ws_url).'</td></tr>';
//Remote User
print '<tr><td>'.$langs->trans("User").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_user"></td></tr>';
//Remote Password
print '<tr><td>'.$langs->trans("Password").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_password"></td></tr>';
//Submit button
print '<tr><td align="center" colspan="2">';
print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("CreateRemoteOrder").'">';
print ' &nbsp; &nbsp; ';
//Cancel button
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>';
}
//End table/form
print '</form>';
print '</table>';
}
elseif ($mode == "check")
{
$ws_entity = '';
$ws_thirdparty = '';
$error_occurred = false;
//Create SOAP client and connect it to user
$soapclient_user = new nusoap_client($ws_url."/webservices/server_user.php");
$soapclient_user->soap_defencoding='UTF-8';
$soapclient_user->decodeUTF8(false);
//Get the thirdparty associated to user
$ws_parameters = array('authentication'=>$ws_authentication, 'id' => '', 'ref'=>$ws_user);
$result_user = $soapclient_user->call("getUser", $ws_parameters, $ws_ns, '');
$user_status_code = $result_user["result"]["result_code"];
if ($user_status_code == "OK")
{
//Fill the variables
$ws_entity = $result_user["user"]["entity"];
$ws_authentication['entity'] = $ws_entity;
$ws_thirdparty = $result_user["user"]["fk_thirdparty"];
if (empty($ws_thirdparty))
{
setEventMessages($langs->trans("RemoteUserMissingAssociatedSoc"), null, 'errors');
$error_occurred = true;
}
else
{
//Create SOAP client and connect it to product/service
$soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php");
$soapclient_product->soap_defencoding='UTF-8';
$soapclient_product->decodeUTF8(false);
// Iterate each line and get the reference that uses the supplier of that product/service
$i = 0;
foreach ($object->lines as $line) {
$i = $i + 1;
$ref_supplier = $line->ref_supplier;
$line_id = $i."º) ".$line->product_ref.": ";
if (empty($ref_supplier)) {
continue;
}
$ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $ref_supplier);
$result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
if (!$result_product)
{
setEventMessages($line_id.$langs->trans("SOAPError")." ".$soapclient_product->error_str." - ".$soapclient_product->response, null, 'errors');
$error_occurred = true;
break;
}
// Check the result code
$status_code = $result_product["result"]["result_code"];
if (empty($status_code)) //No result, check error str
{
setEventMessages($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", null, 'errors');
}
else if ($status_code != "OK") //Something went wrong
{
if ($status_code == "NOT_FOUND")
{
setEventMessages($line_id.$langs->trans("SupplierMissingRef")." '".$ref_supplier."'", null, 'warnings');
}
else
{
setEventMessages($line_id.$langs->trans("ResponseNonOK")." '".$status_code."' - '".$result_product["result"]["result_label"]."'", null, 'errors');
$error_occurred = true;
break;
}
}
// Ensure that price is equal and warn user if it's not
$supplier_price = price($result_product["product"]["price_net"]); //Price of client tab in supplier dolibarr
$local_price = NULL; //Price of supplier as stated in product suppliers tab on this dolibarr, NULL if not found
$product_fourn = new ProductFournisseur($db);
$product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
if (count($product_fourn_list)>0)
{
foreach($product_fourn_list as $product_fourn_line)
{
//Only accept the line where the supplier is the same at this order and has the same ref
if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
$local_price = price($product_fourn_line->fourn_price);
}
}
}
if ($local_price != NULL && $local_price != $supplier_price) {
setEventMessages($line_id.$langs->trans("RemotePriceMismatch")." ".$supplier_price." - ".$local_price, null, 'warnings');
}
// Check if is in sale
if (empty($result_product["product"]["status_tosell"])) {
setEventMessages($line_id.$langs->trans("ProductStatusNotOnSellShort")." '".$ref_supplier."'", null, 'warnings');
}
}
}
}
elseif ($user_status_code == "PERMISSION_DENIED")
{
setEventMessages($langs->trans("RemoteUserNotPermission"), null, 'errors');
$error_occurred = true;
}
elseif ($user_status_code == "BAD_CREDENTIALS")
{
setEventMessages($langs->trans("RemoteUserBadCredentials"), null, 'errors');
$error_occurred = true;
}
else
{
setEventMessages($langs->trans("ResponseNonOK")." '".$user_status_code."'", null, 'errors');
$error_occurred = true;
}
//Form
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="webservice">';
print '<input type="hidden" name="mode" value="send">';
print '<input type="hidden" name="ws_user" value="'.$ws_user.'">';
print '<input type="hidden" name="ws_password" value="'.$ws_password.'">';
print '<input type="hidden" name="ws_entity" value="'.$ws_entity.'">';
print '<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.'">';
if ($error_occurred)
{
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
}
else
{
print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("Confirm").'">';
print ' &nbsp; &nbsp; ';
}
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</form>';
}
}
/*
* Show buttons
*/
else
{
/** /**
* Boutons actions * Boutons actions
*/ */
@ -2700,7 +2366,7 @@ elseif (! empty($object->id))
} }
print "</div>"; print "</div>";
}
if ($user->rights->fournisseur->commande->commander && $object->statut == 2 && $action == 'makeorder') if ($user->rights->fournisseur->commande->commander && $object->statut == 2 && $action == 'makeorder')
@ -2756,6 +2422,7 @@ elseif (! empty($object->id))
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright"><div class="ficheaddleft">'; print '</div><div class="fichehalfright"><div class="ficheaddleft">';
if ($user->rights->fournisseur->commande->receptionner && ($object->statut == 3 || $object->statut == 4)) if ($user->rights->fournisseur->commande->receptionner && ($object->statut == 3 || $object->statut == 4))
{ {
// Set status to received (action=livraison) // Set status to received (action=livraison)
@ -2794,13 +2461,232 @@ elseif (! empty($object->id))
$formactions=new FormActions($db); $formactions=new FormActions($db);
$somethingshown = $formactions->showactions($object,'order_supplier',$socid,1,'listaction'.($genallowed?'largetitle':'')); $somethingshown = $formactions->showactions($object,'order_supplier',$socid,1,'listaction'.($genallowed?'largetitle':''));
print '</div></div></div>';
print '</div></div></div>';}
} }
print '</td></tr></table>'; /*
* Action webservice
*/
if ($action == 'webservice' && GETPOST('mode', 'alpha') != "send" && ! GETPOST('cancel','alpha'))
{
$mode = GETPOST('mode', 'alpha');
$ws_url = $object->thirdparty->webservices_url;
$ws_key = $object->thirdparty->webservices_key;
$ws_user = GETPOST('ws_user','alpha');
$ws_password = GETPOST('ws_password','alpha');
// NS and Authentication parameters
$ws_ns = 'http://www.dolibarr.org/ns/';
$ws_authentication = array(
'dolibarrkey'=>$ws_key,
'sourceapplication'=>'DolibarrWebServiceClient',
'login'=>$ws_user,
'password'=>$ws_password,
'entity'=>''
);
print load_fiche_titre($langs->trans('CreateRemoteOrder'),'');
//Is everything filled?
if (empty($ws_url) || empty($ws_key)) {
setEventMessages($langs->trans("ErrorWebServicesFieldsRequired"), null, 'errors');
$mode = "init";
$error_occurred = true; //Don't allow to set the user/pass if thirdparty fields are not filled
} else if ($mode != "init" && (empty($ws_user) || empty($ws_password))) {
setEventMessages($langs->trans("ErrorFieldsRequired"), null, 'errors');
$mode = "init";
}
if ($mode == "init")
{
//Table/form header
print '<table class="border" width="100%">';
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="webservice">';
print '<input type="hidden" name="mode" value="check">';
if ($error_occurred)
{
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
}
else
{
$textinput_size = "50";
// Webservice url
print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td colspan="3">'.dol_print_url($ws_url).'</td></tr>';
//Remote User
print '<tr><td>'.$langs->trans("User").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_user"></td></tr>';
//Remote Password
print '<tr><td>'.$langs->trans("Password").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_password"></td></tr>';
//Submit button
print '<tr><td align="center" colspan="2">';
print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("CreateRemoteOrder").'">';
print ' &nbsp; &nbsp; ';
//Cancel button
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>';
}
//End table/form
print '</form>';
print '</table>';
}
elseif ($mode == "check")
{
$ws_entity = '';
$ws_thirdparty = '';
$error_occurred = false;
//Create SOAP client and connect it to user
$soapclient_user = new nusoap_client($ws_url."/webservices/server_user.php");
$soapclient_user->soap_defencoding='UTF-8';
$soapclient_user->decodeUTF8(false);
//Get the thirdparty associated to user
$ws_parameters = array('authentication'=>$ws_authentication, 'id' => '', 'ref'=>$ws_user);
$result_user = $soapclient_user->call("getUser", $ws_parameters, $ws_ns, '');
$user_status_code = $result_user["result"]["result_code"];
if ($user_status_code == "OK")
{
//Fill the variables
$ws_entity = $result_user["user"]["entity"];
$ws_authentication['entity'] = $ws_entity;
$ws_thirdparty = $result_user["user"]["fk_thirdparty"];
if (empty($ws_thirdparty))
{
setEventMessages($langs->trans("RemoteUserMissingAssociatedSoc"), null, 'errors');
$error_occurred = true;
}
else
{
//Create SOAP client and connect it to product/service
$soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php");
$soapclient_product->soap_defencoding='UTF-8';
$soapclient_product->decodeUTF8(false);
// Iterate each line and get the reference that uses the supplier of that product/service
$i = 0;
foreach ($object->lines as $line) {
$i = $i + 1;
$ref_supplier = $line->ref_supplier;
$line_id = $i."º) ".$line->product_ref.": ";
if (empty($ref_supplier)) {
continue;
}
$ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $ref_supplier);
$result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
if (!$result_product)
{
setEventMessages($line_id.$langs->trans("SOAPError")." ".$soapclient_product->error_str." - ".$soapclient_product->response, null, 'errors');
$error_occurred = true;
break;
}
// Check the result code
$status_code = $result_product["result"]["result_code"];
if (empty($status_code)) //No result, check error str
{
setEventMessages($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", null, 'errors');
}
else if ($status_code != "OK") //Something went wrong
{
if ($status_code == "NOT_FOUND")
{
setEventMessages($line_id.$langs->trans("SupplierMissingRef")." '".$ref_supplier."'", null, 'warnings');
}
else
{
setEventMessages($line_id.$langs->trans("ResponseNonOK")." '".$status_code."' - '".$result_product["result"]["result_label"]."'", null, 'errors');
$error_occurred = true;
break;
}
}
// Ensure that price is equal and warn user if it's not
$supplier_price = price($result_product["product"]["price_net"]); //Price of client tab in supplier dolibarr
$local_price = NULL; //Price of supplier as stated in product suppliers tab on this dolibarr, NULL if not found
$product_fourn = new ProductFournisseur($db);
$product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
if (count($product_fourn_list)>0)
{
foreach($product_fourn_list as $product_fourn_line)
{
//Only accept the line where the supplier is the same at this order and has the same ref
if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
$local_price = price($product_fourn_line->fourn_price);
}
}
}
if ($local_price != NULL && $local_price != $supplier_price) {
setEventMessages($line_id.$langs->trans("RemotePriceMismatch")." ".$supplier_price." - ".$local_price, null, 'warnings');
}
// Check if is in sale
if (empty($result_product["product"]["status_tosell"])) {
setEventMessages($line_id.$langs->trans("ProductStatusNotOnSellShort")." '".$ref_supplier."'", null, 'warnings');
}
}
}
}
elseif ($user_status_code == "PERMISSION_DENIED")
{
setEventMessages($langs->trans("RemoteUserNotPermission"), null, 'errors');
$error_occurred = true;
}
elseif ($user_status_code == "BAD_CREDENTIALS")
{
setEventMessages($langs->trans("RemoteUserBadCredentials"), null, 'errors');
$error_occurred = true;
}
else
{
setEventMessages($langs->trans("ResponseNonOK")." '".$user_status_code."'", null, 'errors');
$error_occurred = true;
}
//Form
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="webservice">';
print '<input type="hidden" name="mode" value="send">';
print '<input type="hidden" name="ws_user" value="'.$ws_user.'">';
print '<input type="hidden" name="ws_password" value="'.$ws_password.'">';
print '<input type="hidden" name="ws_entity" value="'.$ws_entity.'">';
print '<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.'">';
if ($error_occurred)
{
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
}
else
{
print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("Confirm").'">';
print ' &nbsp; &nbsp; ';
}
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</form>';
}
}
// Select mail models is same action as presend
if (GETPOST('modelselected')) {
$action = 'presend';
}
// Presend form
$modelmail='supplier_order_send';
$defaulttopic='SendOrderRef';
$diroutput = $conf->fournisseur->commande->dir_output;
$trackid = 'sor'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
}
} }
// End of page // End of page

View File

@ -114,7 +114,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
if ($cancel) $action=''; if ($cancel)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action='';
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
@ -1211,14 +1219,13 @@ if (empty($reshook))
} }
} }
/* // Actions when printing a doc from card
* Send mail include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
*/
// Actions to send emails // Actions to send emails
$trigger_name='BILL_SUPPLIER_SENTBYMAIL'; $trigger_name='BILL_SUPPLIER_SENTBYMAIL';
$paramname='id'; $paramname='id';
$mode='emailfromsupplierinvoice'; $autocopy='MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
$trackid='sin'.$object->id; $trackid='sin'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
@ -2823,124 +2830,18 @@ else
} }
} }
/* // Select mail models is same action as presend
* Show mail form
*/
if (GETPOST('modelselected')) { if (GETPOST('modelselected')) {
$action = 'presend'; $action = 'presend';
} }
if ($action == 'presend')
{
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref, preg_quote($ref,'/').'([^\-])+');
$file=$fileparams['fullname'];
// Define output language // Presend form
$outputlangs = $langs; $modelmail='supplier_order_send';
$newlang = ''; $defaulttopic='SendBillRef';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $diroutput = $conf->fournisseur->facture->dir_output;
$newlang = $_REQUEST['lang_id']; $trackid = 'sin'.$object->id;
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang)) include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('bills');
}
// Build document if it not exists
if (! $file || ! is_readable($file))
{
$result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result < 0)
{
dol_print_error($db,$object->error,$object->errors);
exit;
}
$fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref, preg_quote($ref,'/').'([^\-])+');
$file=$fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendBillByMail'));
dol_fiche_head('');
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='sin'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'sin'.$object->id);
}
$formmail->withfrom=1;
$liste=array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
$formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
$formmail->withtocc=$liste;
$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
$formmail->withtopic=$outputlangs->trans('SendBillRef','__REF__');
$formmail->withfile=2;
$formmail->withbody=1;
$formmail->withdeliveryreceipt=1;
$formmail->withcancel=1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit['__SUPPLIERINVREF__']=$object->ref;
//Find the good contact adress
$custcontact='';
$contactarr=array();
$contactarr=$object->liste_contact(-1,'external');
if (is_array($contactarr) && count($contactarr)>0) {
foreach($contactarr as $contact) {
if ($contact['libelle']==$langs->trans('TypeContact_invoice_supplier_external_BILLING')) {
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contactstatic=new Contact($db);
$contactstatic->fetch($contact['id']);
$custcontact=$contactstatic->getFullName($langs,1);
}
}
if (!empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action']='send';
$formmail->param['models']='invoice_supplier_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['facid']=$object->id;
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
// Init list of files
if (GETPOST("mode")=='init')
{
$formmail->clear_attached_files();
$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
}
// Show form
print $formmail->get_form();
dol_fiche_end();
}
} }
} }

View File

@ -50,8 +50,12 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_PAYED','Customer invoice payed','Executed when a customer invoice is payed','facture',7); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_PAYED','Customer invoice payed','Executed when a customer invoice is payed','facture',7);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_CANCEL','Customer invoice canceled','Executed when a customer invoice is conceled','facture',8); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_CANCEL','Customer invoice canceled','Executed when a customer invoice is conceled','facture',8);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_SENTBYMAIL','Customer invoice sent by mail','Executed when a customer invoice is sent by mail','facture',9); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_SENTBYMAIL','Customer invoice sent by mail','Executed when a customer invoice is sent by mail','facture',9);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_UNVALIDATE','Customer invoice unvalidated','Executed when a customer invoice status set back to draft','facture',10); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_UNVALIDATE','Customer invoice unvalidated','Executed when a customer invoice status set back to draft','facture',9);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_CREATE','Supplier order created','Executed when a supplier order is created','order_supplier',11); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_VALIDATE','Price request validated','Executed when a commercial proposal is validated','proposal_supplier',10);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_SENTBYMAIL','Price request sent by mail','Executed when a commercial proposal is sent by mail','proposal_supplier',10);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_SIGNED','Price request closed signed','Executed when a customer proposal is closed signed','proposal_supplier',10);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_REFUSED','Price request closed refused','Executed when a customer proposal is closed refused','proposal_supplier',10);
--insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_CREATE','Supplier order created','Executed when a supplier order is created','order_supplier',11);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_VALIDATE','Supplier order validated','Executed when a supplier order is validated','order_supplier',12); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_VALIDATE','Supplier order validated','Executed when a supplier order is validated','order_supplier',12);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_APPROVE','Supplier order request approved','Executed when a supplier order is approved','order_supplier',13); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_APPROVE','Supplier order request approved','Executed when a supplier order is approved','order_supplier',13);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_SUBMIT','Supplier order request submited','Executed when a supplier order is approved','order_supplier',13); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_SUBMIT','Supplier order request submited','Executed when a supplier order is approved','order_supplier',13);

View File

@ -261,8 +261,16 @@ UPDATE llx_accounting_account SET pcg_type = 'EXPENSE' where pcg_type = 'CHARGE'
UPDATE llx_accounting_account SET pcg_type = 'INCOME' where pcg_type = 'VENTAS_E_INGRESOS'; UPDATE llx_accounting_account SET pcg_type = 'INCOME' where pcg_type = 'VENTAS_E_INGRESOS';
UPDATE llx_accounting_account SET pcg_type = 'EXPENSE' where pcg_type = 'COMPRAS_GASTOS'; UPDATE llx_accounting_account SET pcg_type = 'EXPENSE' where pcg_type = 'COMPRAS_GASTOS';
ALTER TABLE llx_c_action_trigger MODIFY COLUMN elementtype varchar(24) NOT NULL;
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTRACT_SENTBYMAIL','Contract sent by mail','Executed when a contract is sent by mail','contrat',18); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('CONTRACT_SENTBYMAIL','Contract sent by mail','Executed when a contract is sent by mail','contrat',18);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_VALIDATE','Price request validated','Executed when a commercial proposal is validated','proposal_supplier',10);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_SENTBYMAIL','Price request sent by mail','Executed when a commercial proposal is sent by mail','proposal_supplier',10);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_SIGNED','Price request closed signed','Executed when a customer proposal is closed signed','proposal_supplier',10);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_REFUSED','Price request closed refused','Executed when a customer proposal is closed refused','proposal_supplier',10);
CREATE TABLE llx_projet_task_comment ( CREATE TABLE llx_projet_task_comment (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
datec datetime DEFAULT NULL, datec datetime DEFAULT NULL,

View File

@ -22,7 +22,7 @@
create table llx_c_action_trigger create table llx_c_action_trigger
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
elementtype varchar(16) NOT NULL, elementtype varchar(24) NOT NULL,
code varchar(32) NOT NULL, code varchar(32) NOT NULL,
label varchar(128) NOT NULL, label varchar(128) NOT NULL,
description varchar(255), description varchar(255),

View File

@ -69,8 +69,8 @@ ActivateCheckReadKey=Key used to encrypt URL used for "Read Receipt" and "Unsubc
EMailSentToNRecipients=EMail sent to %s recipients. EMailSentToNRecipients=EMail sent to %s recipients.
EMailSentForNElements=EMail sent for %s elements. EMailSentForNElements=EMail sent for %s elements.
XTargetsAdded=<b>%s</b> recipients added into target list XTargetsAdded=<b>%s</b> recipients added into target list
OnlyPDFattachmentSupported=If the PDF document was already generated for the object to send, it will be attached to email. If not, no email will be sent (also, note that only pdf documents are supported as attachment in mass sending in this version). OnlyPDFattachmentSupported=If the PDF documents were already generated for the objects to send, they will be attached to email. If not, no email will be sent (also, note that only pdf documents are supported as attachment in mass sending in this version).
AllRecipientSelected=The %s thirdparties selected, and if an email is set. AllRecipientSelected=The %s unique recipients selected (1 email per recipient), and if an email is set.
ResultOfMailSending=Result of mass EMail sending ResultOfMailSending=Result of mass EMail sending
NbSelected=Nb selected NbSelected=Nb selected
NbIgnored=Nb ignored NbIgnored=Nb ignored

View File

@ -114,13 +114,11 @@ if (empty($reshook))
if ($cancel) if ($cancel)
{ {
if ($action != 'addlink') if (! empty($backtopage))
{ {
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1); header("Location: ".$backtopage);
header("Location: ".$urltogo);
exit; exit;
} }
if ($id > 0 || ! empty($ref)) $ret = $object->fetch($id,$ref);
$action=''; $action='';
} }
@ -215,6 +213,15 @@ if (empty($reshook))
else setEventMessages($object->error, null, 'errors'); else setEventMessages($object->error, null, 'errors');
} }
} }
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Actions to send emails
$trigger_name='MYOBJECT_SENTBYMAIL';
$autocopy='MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
$trackid='myobject'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
} }
@ -510,127 +517,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</div></div></div>'; print '</div></div></div>';
} }
// Presend form
$modelmail='myobject';
$defaulttopic='Information';
$diroutput = $conf->mymodule->dir_output;
$trackid = 'myobject'.$object->id;
/* include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
* Action presend
*/
/*
if ($action == 'presend')
{
$object->fetch_projet();
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
}
// Build document if it not exists
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendMyObjectByMail'));
dol_fiche_head('');
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='ord'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
$liste [$key] = $value;
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
$formmail->withtocc = $liste;
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
if (empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->trans('SendMyObjectRef', '__REF__');
} else if (! empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->trans('SendMyObjectRef', '__REF__ (__REFCLIENT__)');
}
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit ['__REF__'] = $object->ref;
$custcontact = '';
$contactarr = array();
$contactarr = $object->liste_contact(- 1, 'external');
if (is_array($contactarr) && count($contactarr) > 0)
{
foreach ($contactarr as $contact)
{
if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
$custcontact = $contactstatic->getFullName($langs, 1);
}
}
if (! empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action'] = 'send';
$formmail->param['models'] = 'myobject_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['myobjectid'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
// Show form
print $formmail->get_form();
dol_fiche_end();
}*/
} }

View File

@ -2485,7 +2485,6 @@ else
$formmail->withdeliveryreceipt=1; $formmail->withdeliveryreceipt=1;
$formmail->withcancel=1; $formmail->withcancel=1;
// Array of substitutions // Array of substitutions
$formmail->withsubstit='AvailableVariables';
$formmail->setSubstitFromObject($object); $formmail->setSubstitFromObject($object);
$formmail->substit['__THIRDPARTY_ID__']=$object->id; // substit in setSubstitFromObject was wrong for this one $formmail->substit['__THIRDPARTY_ID__']=$object->id; // substit in setSubstitFromObject was wrong for this one
$formmail->substit['__THIRDPARTY_NAME__']=$object->name; // substit in setSubstitFromObject was wrong for this one $formmail->substit['__THIRDPARTY_NAME__']=$object->name; // substit in setSubstitFromObject was wrong for this one

View File

@ -115,7 +115,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
if ($cancel) $action=''; if ($cancel)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action='';
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
@ -462,16 +470,19 @@ if (empty($reshook))
} }
} }
// Action for direct print // Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Actions to send emails // Actions to send emails
$trigger_name='SUPPLIER_PROPOSAL_SENTBYMAIL'; $trigger_name='PROPAL_SUPPLIER_SENTBYMAIL';
$paramname='id'; $autocopy='MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
$mode='emailfromsupplierproposal';
$trackid='spr'.$object->id; $trackid='spr'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Actions to build doc
$upload_dir = $conf->supplier_proposal->dir_output;
$permissioncreate = $user->rights->supplier_proposal->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
// Go back to draft // Go back to draft
@ -876,44 +887,6 @@ if (empty($reshook))
exit(); exit();
} }
// Generation doc (depuis lien ou depuis cartouche doc)
else if ($action == 'builddoc' && $user->rights->supplier_proposal->creer) {
if (GETPOST('model')) {
$object->setDocModel($user, GETPOST('model'));
}
// Define output language
$outputlangs = $langs;
if (! empty($conf->global->MAIN_MULTILANGS)) {
$outputlangs = new Translate("", $conf);
$newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
$outputlangs->setDefaultLang($newlang);
}
$ret = $object->fetch($id); // Reload to get new records
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0)
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}
// Remove file in doc form
else if ($action == 'remove_file' && $user->rights->supplier_proposal->creer) {
if ($object->id > 0) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$langs->load("other");
$upload_dir = $conf->supplier_proposal->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
$ret = dol_delete_file($file, 0, 0, 0, $object);
if ($ret)
setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
else
setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
}
}
// Set project // Set project
else if ($action == 'classin' && $user->rights->supplier_proposal->creer) { else if ($action == 'classin' && $user->rights->supplier_proposal->creer) {
$object->setProject($_POST['projectid']); $object->setProject($_POST['projectid']);
@ -1811,108 +1784,18 @@ if ($action == 'create')
print '</div></div></div>'; print '</div></div></div>';
} }
/* // Select mail models is same action as presend
* Action presend
*/
if (GETPOST('modelselected')) { if (GETPOST('modelselected')) {
$action = 'presend'; $action = 'presend';
} }
if ($action == 'presend')
{
$object->fetch_projet();
$ref = dol_sanitizeFileName($object->ref); // Presend form
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $modelmail='supplier_proposal_send';
$fileparams = dol_most_recent_file($conf->supplier_proposal->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); $defaulttopic='SendAskRef';
$file = $fileparams['fullname']; $diroutput = $conf->supplier_proposal->dir_output;
$trackid = 'spr'.$object->id;
// Define output language include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
$outputlangs->load('supplier_proposal');
}
// Build document if it not exists
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0)
{
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($conf->supplier_proposal->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendAskByMail'));
dol_fiche_head('');
// Create form object
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='spr'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'spr'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
$liste [$key] = $value;
$formmail->withto = GETPOST("sendto") ? GETPOST("sendto") : $liste;
$formmail->withtocc = $liste;
$formmail->withtoccc = (! empty($conf->global->MAIN_EMAIL_USECCC) ? $conf->global->MAIN_EMAIL_USECCC : false);
$formmail->withtopic = $outputlangs->trans('SendAskRef', '__SUPPLIERPROPREF__');
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit['__SUPPLIERPROPREF__'] = $object->ref;
// Tableau des parametres complementaires
$formmail->param['action'] = 'send';
$formmail->param['models'] = 'supplier_proposal_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['id'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
print $formmail->get_form();
dol_fiche_end();
}
} }
// End of page // End of page