2
0
forked from Wavyzz/dolibarr

New: Content of predefined email come firstly from table

llx_c_email_template, then translation key.
This commit is contained in:
Laurent Destailleur
2014-09-17 01:12:59 +02:00
parent 83447243ae
commit a834796181
2 changed files with 95 additions and 39 deletions

View File

@@ -52,6 +52,7 @@ For users:
- New: [ task #1218 ] Can drag and drop an event from calendar to change its day. - New: [ task #1218 ] Can drag and drop an event from calendar to change its day.
- New: Optimize size of image static resources. - 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: 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 - Upgrade phpexcel lib to 1.7.8
- Fix: [ bug #1487 ] PAYMENT_DELETE trigger does not intercept trigger action - Fix: [ bug #1487 ] PAYMENT_DELETE trigger does not intercept trigger action
- Fix: [ bug #1470, #1472, #1473] User trigger problem - Fix: [ bug #1470, #1472, #1473] User trigger problem
@@ -79,7 +80,6 @@ New experimental module:
Ari Elbaz Ari Elbaz
Florian Henry Florian Henry
Juanjo Menent Juanjo Menent
And to the contributors : And to the contributors :
Jeff Info 2000 euros Jeff Info 2000 euros
Nord Anim 120 euros Nord Anim 120 euros
@@ -95,25 +95,25 @@ For developers:
- New: Add a css style "cursorpointer". - New: Add a css style "cursorpointer".
- New: Select list of users can return user into hierarchy. - New: Select list of users can return user into hierarchy.
- New: getBrowserInfo can return type of layout of browser (classic/phone/tablet) - 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 trigger DON_UPDATE, DON_DELETE
- New: Add country iso code on 3 chars into table of countries. - 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. - 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 - LINEBILL_DELETE, LINK_DELETE, ORDER_SUPPLIER_DELETE, RESOURCE_DELETE trigger called before SQL delete
- New: [ Task #1481 ] Add trigger BILL_SUPPLIER_UPDATE. - New: [ Task #1481 ] Add trigger BILL_SUPPLIER_UPDATE.
- New: [ Task #1495 ] Add trigger LINECONTRACT_CREATE. - New: [ Task #1495 ] Add trigger LINECONTRACT_CREATE.
- New: Added hook "formConfirm" and "doActions" for supplier invoice card - 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: [ 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 - New: renamed table llx_c_pays to llx_c_country & libelle field to label.
- Qual: Renamed table llx_c_civilite into llx_c_civility - Qual: Renamed table llx_c_civilite into llx_c_civility,
field civilite into label in the same table field civilite into label in the same table,
and field civilite into civility in other 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: Dolibarr better:
- Changed the way parameters are provided to scripts sync_xxx_ldap2dolibarr.php - 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. - 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 - 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. creation of a pdf or odt, hook "afterPDFCreation" or "afterODTCreation" must be used instead.

View File

@@ -250,6 +250,21 @@ class FormMail
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]); if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]); 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<!-- Debut form mail -->\n"; $out.= "\n<!-- Debut form mail -->\n";
if ($this->withform == 1) if ($this->withform == 1)
{ {
@@ -439,7 +454,7 @@ class FormMail
} }
$out.= "</td></tr>\n"; $out.= "</td></tr>\n";
} }
// CCC // CCC
if (! empty($this->withtoccc) || is_array($this->withtoccc)) if (! empty($this->withtoccc) || is_array($this->withtoccc))
{ {
@@ -492,19 +507,23 @@ class FormMail
// Topic // Topic
if (! empty($this->withtopic)) 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.= '<tr>'; $out.= '<tr>';
$out.= '<td width="180">'.$langs->trans("MailTopic").'</td>'; $out.= '<td width="180">'.$langs->trans("MailTopic").'</td>';
$out.= '<td>'; $out.= '<td>';
if ($this->withtopicreadonly) if ($this->withtopicreadonly)
{ {
$out.= $this->withtopic; $out.= $defaulttopic;
$out.= '<input type="hidden" size="60" id="subject" name="subject" value="'.$this->withtopic.'" />'; $out.= '<input type="hidden" size="60" id="subject" name="subject" value="'.$defaulttopic.'" />';
} }
else else
{ {
$out.= '<input type="text" size="60" id="subject" name="subject" value="'. (isset($_POST["subject"])?$_POST["subject"]:(is_numeric($this->withtopic)?'':$this->withtopic)) .'" />'; $out.= '<input type="text" size="60" id="subject" name="subject" value="'. (isset($_POST["subject"])?$_POST["subject"]:($defaulttopic?$defaulttopic:'')) .'" />';
} }
$out.= "</td></tr>\n"; $out.= "</td></tr>\n";
} }
@@ -563,31 +582,8 @@ class FormMail
if (! empty($this->withbody)) if (! empty($this->withbody))
{ {
$defaultmessage=""; $defaultmessage="";
if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['content']) $defaultmessage=$arraydefaultmessage['content'];
// Define output language elseif (! is_numeric($this->withbody)) $defaultmessage=$this->withbody;
$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; }
// Complete substitution array // Complete substitution array
if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_ADD_PAYMENT_URL)) if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_ADD_PAYMENT_URL))
@@ -679,5 +675,65 @@ class FormMail
return $out; 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;
}
}
} }