diff --git a/ChangeLog b/ChangeLog index 1f07b3dc1de..02fc78640df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,7 @@ For users: - New: [ task #1218 ] Can drag and drop an event from calendar to change its day. - New: Optimize size of image static resources. - New: Add hourly and daily amount on user card. Add weekly working hours and salary on user card. +- New: Content of predefined email come firstly from table llx_c_email_template, then translation key. - Upgrade phpexcel lib to 1.7.8 - Fix: [ bug #1487 ] PAYMENT_DELETE trigger does not intercept trigger action - Fix: [ bug #1470, #1472, #1473] User trigger problem @@ -79,7 +80,6 @@ New experimental module: Ari Elbaz Florian Henry Juanjo Menent - And to the contributors : Jeff Info 2000 euros Nord Anim 120 euros @@ -95,25 +95,25 @@ For developers: - New: Add a css style "cursorpointer". - New: Select list of users can return user into hierarchy. - New: getBrowserInfo can return type of layout of browser (classic/phone/tablet) -- New: Add hook "searchAgendaFrom". +- New: Add hook "searchAgendaFrom" and "beforePDFCreation". - New: Add trigger DON_UPDATE, DON_DELETE - New: Add country iso code on 3 chars into table of countries. - Qual: Removed hard coded rowid into data init of table llx_c_action_trigger. - LINEBILL_DELETE, LINK_DELETE, ORDER_SUPPLIER_DELETE, RESOURCE_DELETE trigger called before SQL delete - New: [ Task #1481 ] Add trigger BILL_SUPPLIER_UPDATE. - New: [ Task #1495 ] Add trigger LINECONTRACT_CREATE. -- New: Added hook "formConfirm" and "doActions" for supplier invoice card -- New: [ task #1511, #1426 ] Added hook "doActions" for supplier card and supplier order card -- New: renamed table llx_c_pays to llx_c_country & libelle field to label -- Qual: Renamed table llx_c_civilite into llx_c_civility - field civilite into label in the same table +- New: Added hook "formConfirm" and "doActions" for supplier invoice card. +- New: [ task #1511, #1426 ] Added hook "doActions" for supplier card and supplier order card. +- New: renamed table llx_c_pays to llx_c_country & libelle field to label. +- Qual: Renamed table llx_c_civilite into llx_c_civility, + field civilite into label in the same table, and field civilite into civility in other table -WARNING: Following change may create regression for some external modules, but was necessary to make +WARNING: Following changes may create regression for some external modules, but was necessary to make Dolibarr better: - Changed the way parameters are provided to scripts sync_xxx_ldap2dolibarr.php -- Some field into database wwere renamed from "libelle" to "label". +- Some field into database were renamed from "libelle" to "label". - Table llx_c_pays were renamed into llx_c_country. - Triggers *_BUILDDOC are removed. Building a doc is not a business event. For action after creation of a pdf or odt, hook "afterPDFCreation" or "afterODTCreation" must be used instead. diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 261754801a9..13edeb168fa 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -250,6 +250,21 @@ class FormMail if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]); if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]); + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $this->param['langsmodels']; + if (! empty($newlang)) + { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + $outputlangs->load('other'); + } + + // Get message template + $arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs); + + $out.= "\n\n"; if ($this->withform == 1) { @@ -439,7 +454,7 @@ class FormMail } $out.= "\n"; } - + // CCC if (! empty($this->withtoccc) || is_array($this->withtoccc)) { @@ -492,19 +507,23 @@ class FormMail // Topic if (! empty($this->withtopic)) { - $this->withtopic=make_substitutions($this->withtopic,$this->substit); + $defaulttopic=""; + if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['topic']) $defaulttopic=$arraydefaultmessage['topic']; + elseif (! is_numeric($this->withtopic)) $defaulttopic=$this->withtopic; + + $defaulttopic=make_substitutions($defaulttopic,$this->substit); $out.= ''; $out.= ''.$langs->trans("MailTopic").''; $out.= ''; if ($this->withtopicreadonly) { - $out.= $this->withtopic; - $out.= ''; + $out.= $defaulttopic; + $out.= ''; } else { - $out.= 'withtopic)?'':$this->withtopic)) .'" />'; + $out.= ''; } $out.= "\n"; } @@ -563,31 +582,8 @@ class FormMail if (! empty($this->withbody)) { $defaultmessage=""; - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) - $newlang = $this->param['langsmodels']; - - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - $outputlangs->load('other'); - } - - - // TODO A partir du type, proposer liste de messages dans table llx_c_email_template - if ($this->param["models"]=='facture_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoice"); } - elseif ($this->param["models"]=='facture_relance') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder"); } - elseif ($this->param["models"]=='propal_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendProposal"); } - elseif ($this->param["models"]=='order_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendOrder"); } - elseif ($this->param["models"]=='order_supplier_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder"); } - elseif ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } - elseif ($this->param["models"]=='shipping_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendShipping"); } - elseif ($this->param["models"]=='fichinter_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendFichInter"); } - elseif ($this->param["models"]=='thirdparty') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentThirdparty"); } - elseif (! is_numeric($this->withbody)) { $defaultmessage=$this->withbody; } + if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['content']) $defaultmessage=$arraydefaultmessage['content']; + elseif (! is_numeric($this->withbody)) $defaultmessage=$this->withbody; // Complete substitution array if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_ADD_PAYMENT_URL)) @@ -679,5 +675,65 @@ class FormMail return $out; } } + + + + /** + * Return template of email + * Search into table c_email_template + * + * @param DoliDB $db Database handler + * @param string $type_template Get message for key module + * @param string $user Use template public or limited to this user + * @para Translate $outputlangs Output lang object + * @return array array('topic'=>,'content'=>,..) + */ + private function getEMailTemplate($db, $type_template, $user, $outputlangs) + { + $ret=array(); + + $sql = "SELECT topic, content"; + $sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates'; + $sql.= " WHERE type_template='".$db->escape($type_template)."'"; + $sql.= " AND entity IN (".getEntity("c_email_templates").")"; + $sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")"; + // TODO Add field and where filter on language code + //print $sql; + + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) + { + $ret['topic']=$obj->topic; + $ret['content']=$obj->content; + } + else + { + $defaultmessage=''; + if ($type_template=='facture_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoice"); } + elseif ($type_template=='facture_relance') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder"); } + elseif ($type_template=='propal_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendProposal"); } + elseif ($type_template=='order_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendOrder"); } + elseif ($type_template=='order_supplier_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder"); } + elseif ($type_template=='invoice_supplier_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } + elseif ($type_template=='shipping_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendShipping"); } + elseif ($type_template=='fichinter_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendFichInter"); } + elseif ($type_template=='thirdparty') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentThirdparty"); } + + $ret['topic']=''; + $ret['content']=$defaultmessage; + } + + $db->free($resql); + return $ret; + } + else + { + dol_print_error($db); + return -1; + } + } }