diff --git a/ChangeLog b/ChangeLog index 69005b0c492..1235a85e097 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,9 +11,10 @@ NEW: complete_head_from_modules() in ldap_prepare_head() 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 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.* ***** diff --git a/htdocs/accountancy/admin/accountmodel.php b/htdocs/accountancy/admin/accountmodel.php index cf2b9080ee2..5c17f07183e 100644 --- a/htdocs/accountancy/admin/accountmodel.php +++ b/htdocs/accountancy/admin/accountmodel.php @@ -740,15 +740,6 @@ if ($id) print ''; print ""; - if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates') - { - print '* '.$langs->trans("AvailableVariables").": "; - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $tmp=FormMail::getAvailableSubstitKey('formemail'); - print implode(', ', $tmp); - print ''; - } - $colspan=count($fieldlist)+3; if ($id == 4) $colspan++; diff --git a/htdocs/admin/agenda.php b/htdocs/admin/agenda.php index fa2c11849fb..50676e4c3af 100644 --- a/htdocs/admin/agenda.php +++ b/htdocs/admin/agenda.php @@ -165,6 +165,8 @@ if (! empty($triggers)) if ($module == 'shipping') $module = 'expedition_bon'; if ($module == 'member') $module = 'adherent'; if ($module == 'project') $module = 'projet'; + if ($module == 'proposal_supplier') $module = 'supplier_proposal'; + //print 'module='.$module.'
'; if (! empty($conf->$module->enabled)) { diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index b2b7e9cf5cf..c40192723a8 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -1224,7 +1224,6 @@ else // Print mail content 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); print ''; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 18add332294..8fb2a102c22 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -125,7 +125,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e 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 @@ -638,16 +646,10 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; - - /* - * Send mail - */ - // Actions to send emails $actiontypecode='AC_OTH_AUTO'; $trigger_name='PROPAL_SENTBYMAIL'; - $paramname='id'; - $mode='emailfromproposal'; + $autocopy='MAIN_MAIL_AUTOCOPY_PROPOSAL_TO'; $trackid='pro'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; @@ -2361,123 +2363,13 @@ if ($action == 'create') print ''; } - /* - * Action presend - */ - if ($action == 'presend') - { - $object->fetch_projet(); + // Presend form + $modelmail='propal_send'; + $defaulttopic='SendPropalRef'; + $diroutput = $conf->propal->dir_output; + $trackid = 'pro'.$object->id; - $ref = dol_sanitizeFileName($object->ref); - 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 '
'; - print '
'; - print '
'; - 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(); - } + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } // End of page diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 040b1e200d8..4c49cef6820 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -118,16 +118,11 @@ if (empty($reshook)) { if ($cancel) { - if ($action != 'addlink' && $action != 'updateline') + if (! empty($backtopage)) { - $urltogo=$backtopage?$backtopage:dol_buildpath('/commande/list.php',1); - header("Location: ".$urltogo); + header("Location: ".$backtopage); exit; } - if ($id > 0 || ! empty($ref)) { - $ret = $object->fetch($id,$ref); - $object->fetch_thirdparty(); - } $action=''; } @@ -1256,13 +1251,13 @@ if (empty($reshook)) exit(); } - include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; - + // Actions when printing a doc from card + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Actions to send emails $trigger_name='ORDER_SENTBYMAIL'; $paramname='id'; - $mode='emailfromorder'; + $autocopy='MAIN_MAIL_AUTOCOPY_ORDER_TO'; // used to know the automatic BCC to add $trackid='ord'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; @@ -2596,134 +2591,13 @@ if ($action == 'create' && $user->rights->commande->creer) print ''; } - /* - * Action presend - */ - if ($action == 'presend') - { - $object->fetch_projet(); + // Presend form + $modelmail='order_send'; + $defaulttopic='SendOrderRef'; + $diroutput = $conf->commande->dir_output; + $trackid = 'ord'.$object->id; - $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'; - - // 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 '
'; - print '
'; - print '
'; - 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(); - } + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 1e387bcd3fa..a01f2de0f31 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -132,7 +132,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e 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 @@ -1957,20 +1965,17 @@ if (empty($reshook)) exit(); } - - /* - * Send mail - */ + // Actions when printing a doc from card + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Actions to send emails if (empty($id)) $id=$facid; $trigger_name='BILL_SENTBYMAIL'; $paramname='id'; - $mode='emailfrominvoice'; + $autocopy='MAIN_MAIL_AUTOCOPY_INVOICE_TO'; $trackid='inv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - // Actions to build doc $upload_dir = $conf->facture->dir_output; $permissioncreate=$user->rights->facture->creer; @@ -2003,8 +2008,6 @@ if (empty($reshook)) $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 ($action == 'addcontact') { $result = $object->fetch($id); @@ -4335,143 +4338,15 @@ else if ($id > 0 || ! empty($ref)) print ''; } - else - { - /* - * Action presend (or prerelance) - */ - $object->fetch_projet(); - // By default if $action=='presend' - $titreform = 'SendBillByMail'; - $topicmail = 'SendBillRef'; - $modelmail = 'facture_send'; + // Presend form + $modelmail='facture_send'; + $defaulttopic='SendBillRef'; + $diroutput = $conf->facture->dir_output; + $trackid = 'inv'.$object->id; - if ($action == 'prerelance') // For backward compatibility - { - $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 '
'; - print '
'; - print '
'; - 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(); - } + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } llxFooter(); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 0e8722d20b8..16c843466f9 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -2242,7 +2242,6 @@ else $formmail->withdeliveryreceipt = 1; $formmail->withcancel = 1; // Array of substitutions - $formmail->withsubstit='AvailableVariables'; $formmail->setSubstitFromObject($object); $datenextexpiration=''; foreach($object->lines as $line) diff --git a/htdocs/core/actions_fetchobject.inc.php b/htdocs/core/actions_fetchobject.inc.php index 7c25fbe7981..6a2d7196d0f 100644 --- a/htdocs/core/actions_fetchobject.inc.php +++ b/htdocs/core/actions_fetchobject.inc.php @@ -28,7 +28,7 @@ // $cancel must be defined // $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); if ($ret > 0) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index f2881544c54..b17c047860a 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -64,11 +64,9 @@ if (! $error && $massaction == 'confirm_presend') $langs->load("mails"); include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if (!$error && !isset($user->email)) - { - $error++; - setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings'); - } + $listofobjectid=array(); + $listofobjectthirdparties=array(); + $listofobjectref=array(); if (! $error) { @@ -76,12 +74,9 @@ if (! $error && $massaction == 'confirm_presend') if ($objecttmp->element == 'expensereport') $thirdparty=new User($db); $objecttmp=new $objectclass($db); - $listofobjectid=array(); - $listofobjectthirdparties=array(); - $listofobjectref=array(); 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); if ($result > 0) { @@ -93,10 +88,39 @@ if (! $error && $massaction == 'confirm_presend') $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) { $result = $thirdparty->fetch($thirdpartyid); @@ -112,12 +136,6 @@ if (! $error && $massaction == 'confirm_presend') $sendtoid = array(); // Define $sendto - $receiver=$_POST['receiver']; - if (! is_array($receiver)) - { - if ($receiver == '-1') $receiver=array(); - else $receiver=array($receiver); - } $tmparray=array(); if (trim($_POST['sendto'])) { @@ -433,10 +451,10 @@ if (! $error && $massaction == 'confirm_presend') //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file setEventMessages($resaction, null, 'warnings'); } - } - $action='list'; - $massaction=''; + $action='list'; + $massaction=''; + } } if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_search')) @@ -618,7 +636,7 @@ if ($action == 'remove_file') $action=''; } -// Validate records +// Validate records if (! $error && $massaction == 'validate' && $permtocreate) { if ($object->element == 'invoice_supplier' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) @@ -690,8 +708,19 @@ if (! $error && $massaction == 'delete' && $permtodelete) $result=$objecttmp->fetch($toselectid); if ($result > 0) { + // Refuse deletion for some status ? + /* + if ($objectclass == 'Facture' && $objecttmp->status == Facture::STATUS_DRAFT) + { + $langs->load("errors"); + $nbignored++; + $resaction.='
'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction',$object->ref).'

'; + continue; + }*/ + if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); else $result = $objecttmp->delete($user); + if ($result <= 0) { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 18c951c7763..144cba07779 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -24,7 +24,7 @@ // $mysoc must be defined // $id 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 '') // $actiontypecode can be set // $object and $uobject may be defined @@ -268,12 +268,12 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $message=preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); $sendtobcc= GETPOST('sendtoccc'); - if ($mode == 'emailfromproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); - if ($mode == 'emailfromorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); - if ($mode == 'emailfrominvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); - 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)); - if ($mode == 'emailfromsupplierinvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); + // Autocomplete the $sendtobcc + // $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 (! empty($autocopy)) + { + $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc?", ":"").$conf->global->$autocopy)); + } $deliveryreceipt = $_POST['deliveryreceipt']; diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index daf2f9b819f..366247560ac 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -343,7 +343,7 @@ class FormMail extends Form if (count($modelmail_array)>0) { $out.= '
'."\n"; - $out.= ''.$langs->trans('SelectMailModel').': '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1); + $out.= ''.$langs->trans('SelectMailModel').': '.$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); $out.= '   '; $out.= ''; @@ -370,7 +370,7 @@ class FormMail extends Form $out.= '
'."\n"; // Substitution array - if (! empty($this->withsubstit)) + if (! empty($this->withsubstit)) // Unset of set ->withsubstit=0 to disable this. { $out.= '\n"; //$out.=''; } @@ -746,24 +746,31 @@ class FormMail extends Form } // 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'; - - $langs->load('paypal'); - - // Set the paypal message and url link into __PERSONALIZED__ key - if ($this->param["models"]=='order_send') + if (empty($this->substit['__REF__'])) { - $url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']?$this->substit['__ORDERREF__']:$this->substit['__REF__']); - $this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url)); + //$paymenturl='LinkToPayOnlineNotAvailableInThisContext'; + $paymenturl=''; } - if ($this->param["models"]=='facture_send') + else { - $url=getPaypalPaymentUrl(0,'invoice',$this->substit['__REF__']); - $this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url)); + // Set the online payment message and url link into __PERSONALIZED__ key + require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + $langs->load('paypal'); + $typeforonlinepayment='free'; + if ($this->param["models"]=='order_send') $typeforonlinepayment='order'; // TODO use detection on something else than template + if ($this->param["models"]=='facture_send') $typeforonlinepayment='invoice'; // TODO use detection on something else than template + $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); + //$paymenturl=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url)); + $paymenturl=$url; } } + $this->substit['__PERSONALIZED__']=$paymenturl; + $this->substit['__ONLINE_PAYMENT_URL__']='YY'.$paymenturl; //Add lines substitution key from each line $lines = ''; @@ -849,7 +856,7 @@ class FormMail extends Form { $out.= '
'; //$out.='
'; @@ -380,7 +380,7 @@ class FormMail extends Form $help.=$key.' -> '.$langs->trans(dol_string_nohtmltag($val)).'
'; } 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.= "