Add email template for each line in object
This commit is contained in:
parent
d3176ec0ed
commit
522fb4cf7a
@ -188,7 +188,7 @@ $tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX
|
||||
$tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
|
||||
$tabsql[23]= "SELECT t.rowid as rowid, t.taux, c.label as country, c.code as country_code, t.fk_pays as country_id, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_revenuestamp as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
|
||||
$tabsql[24]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
|
||||
$tabsql[25]= "SELECT rowid as rowid, label, type_template, private, position, topic, content, active FROM ".MAIN_DB_PREFIX."c_email_templates WHERE entity IN (".getEntity('email_template',1).")";
|
||||
$tabsql[25]= "SELECT rowid as rowid, label, type_template, private, position, topic, content_lines, content, active FROM ".MAIN_DB_PREFIX."c_email_templates WHERE entity IN (".getEntity('email_template',1).")";
|
||||
$tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
|
||||
$tabsql[27]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_stcomm";
|
||||
$tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid";
|
||||
@ -262,7 +262,7 @@ $tabfield[21]= "code,label";
|
||||
$tabfield[22]= "code,label";
|
||||
$tabfield[23]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note";
|
||||
$tabfield[24]= "code,label";
|
||||
$tabfield[25]= "label,type_template,private,position,topic,content";
|
||||
$tabfield[25]= "label,type_template,private,position,topic,content_lines,content";
|
||||
$tabfield[26]= "code,label,short_label";
|
||||
$tabfield[27]= "code,libelle";
|
||||
$tabfield[28]= "code,label,affect,delay,newbymonth,country_id,country";
|
||||
@ -299,7 +299,7 @@ $tabfieldvalue[21]= "code,label";
|
||||
$tabfieldvalue[22]= "code,label";
|
||||
$tabfieldvalue[23]= "country,taux,accountancy_code_sell,accountancy_code_buy,note";
|
||||
$tabfieldvalue[24]= "code,label";
|
||||
$tabfieldvalue[25]= "label,type_template,private,position,topic,content";
|
||||
$tabfieldvalue[25]= "label,type_template,private,position,topic,content_lines,content";
|
||||
$tabfieldvalue[26]= "code,label,short_label";
|
||||
$tabfieldvalue[27]= "code,libelle";
|
||||
$tabfieldvalue[28]= "code,label,affect,delay,newbymonth,country";
|
||||
@ -336,7 +336,7 @@ $tabfieldinsert[21]= "code,label";
|
||||
$tabfieldinsert[22]= "code,label";
|
||||
$tabfieldinsert[23]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note";
|
||||
$tabfieldinsert[24]= "code,label";
|
||||
$tabfieldinsert[25]= "label,type_template,private,position,topic,content,entity";
|
||||
$tabfieldinsert[25]= "label,type_template,private,position,topic,content_lines,content,entity";
|
||||
$tabfieldinsert[26]= "code,label,short_label";
|
||||
$tabfieldinsert[27]= "code,libelle";
|
||||
$tabfieldinsert[28]= "code,label,affect,delay,newbymonth,fk_country";
|
||||
@ -449,7 +449,7 @@ $tabhelp[21] = array('code'=>$langs->trans("EnterAnyCode"));
|
||||
$tabhelp[22] = array('code'=>$langs->trans("EnterAnyCode"));
|
||||
$tabhelp[23] = array();
|
||||
$tabhelp[24] = array('code'=>$langs->trans("EnterAnyCode"));
|
||||
$tabhelp[25] = array('topic'=>$langs->trans('SeeSubstitutionVars'),'content'=>$langs->trans('SeeSubstitutionVars'),'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList"));
|
||||
$tabhelp[25] = array('topic'=>$langs->trans('SeeSubstitutionVars'),'content'=>$langs->trans('SeeSubstitutionVars'),'content_lines'=>$langs->trans('SeeSubstitutionVars'),'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList"));
|
||||
$tabhelp[26] = array('code'=>$langs->trans("EnterAnyCode"));
|
||||
$tabhelp[27] = array('code'=>$langs->trans("EnterAnyCode"));
|
||||
$tabhelp[28] = array('affect'=>$langs->trans("FollowedByACounter"),'delay'=>$langs->trans("MinimumNoticePeriod"), 'newbymonth'=>$langs->trans("NbAddedAutomatically"));
|
||||
@ -1062,6 +1062,7 @@ if ($id)
|
||||
if ($fieldlist[$field]=='custom_x') { $valuetoshow=$langs->trans("CustomX"); }
|
||||
if ($fieldlist[$field]=='custom_y') { $valuetoshow=$langs->trans("CustomY"); }
|
||||
if ($fieldlist[$field]=='content') { $valuetoshow=$langs->trans("Content"); }
|
||||
if ($fieldlist[$field]=='content_lines') { $valuetoshow=$langs->trans("ContentLines"); }
|
||||
if ($fieldlist[$field]=='percent') { $valuetoshow=$langs->trans("Percentage"); }
|
||||
if ($fieldlist[$field]=='affect') { $valuetoshow=$langs->trans("Info"); }
|
||||
if ($fieldlist[$field]=='delay') { $valuetoshow=$langs->trans("NoticePeriod"); }
|
||||
@ -1253,6 +1254,7 @@ if ($id)
|
||||
if ($fieldlist[$field]=='custom_x') { $valuetoshow=$langs->trans("CustomX"); }
|
||||
if ($fieldlist[$field]=='custom_y') { $valuetoshow=$langs->trans("CustomY"); }
|
||||
if ($fieldlist[$field]=='content') { $valuetoshow=$langs->trans("Content"); }
|
||||
if ($fieldlist[$field]=='content_lines') { $valuetoshow=$langs->trans("ContentLines"); }
|
||||
if ($fieldlist[$field]=='percent') { $valuetoshow=$langs->trans("Percentage"); }
|
||||
if ($fieldlist[$field]=='affect') { $valuetoshow=$langs->trans("Info"); }
|
||||
if ($fieldlist[$field]=='delay') { $valuetoshow=$langs->trans("NoticePeriod"); }
|
||||
@ -1770,6 +1772,24 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
|
||||
elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
|
||||
print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea></td>';
|
||||
}
|
||||
elseif (in_array($fieldlist[$field], array('content_lines')))
|
||||
{
|
||||
if ($tabname == MAIN_DB_PREFIX.'c_email_templates')
|
||||
{
|
||||
print '<td colspan="4"></td></tr><tr class="pair nohover"><td colspan="5">'; // To create an artificial CR for the current tr we are on
|
||||
}
|
||||
else print '<td>';
|
||||
if ($context != 'hide')
|
||||
{
|
||||
//print '<input type="text" size="100" class="flat" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
|
||||
$okforextended=true;
|
||||
if ($tabname == MAIN_DB_PREFIX.'c_email_templates' && empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
|
||||
$doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 100, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_1, '90%');
|
||||
print $doleditor->Create(1);
|
||||
}
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
}
|
||||
elseif (in_array($fieldlist[$field], array('content')))
|
||||
{
|
||||
if ($tabname == MAIN_DB_PREFIX.'c_email_templates')
|
||||
@ -1782,7 +1802,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
|
||||
//print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
|
||||
$okforextended=true;
|
||||
if ($tabname == MAIN_DB_PREFIX.'c_email_templates' && empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
|
||||
$doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_5, '90%');
|
||||
$doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_8, '90%');
|
||||
print $doleditor->Create(1);
|
||||
}
|
||||
else print ' ';
|
||||
|
||||
@ -77,6 +77,7 @@ class FormMail extends Form
|
||||
var $withfckeditor;
|
||||
|
||||
var $substit=array();
|
||||
var $substit_lines=array();
|
||||
var $param=array();
|
||||
|
||||
var $error;
|
||||
@ -712,6 +713,18 @@ class FormMail extends Form
|
||||
$this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url));
|
||||
}
|
||||
}
|
||||
|
||||
//Add lines substitution key from each line
|
||||
$lines = '';
|
||||
$defaultlines = $arraydefaultmessage['content_lines'];
|
||||
if (isset($defaultlines))
|
||||
{
|
||||
foreach ($this->substit_lines as $substit_line)
|
||||
{
|
||||
$lines .= make_substitutions($defaultlines,$substit_line)."\n";
|
||||
}
|
||||
}
|
||||
$this->substit['__LINES__']=$lines;
|
||||
|
||||
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
||||
|
||||
@ -820,7 +833,7 @@ class FormMail extends Form
|
||||
{
|
||||
$ret=array();
|
||||
|
||||
$sql = "SELECT label, topic, content, lang";
|
||||
$sql = "SELECT label, topic, content, content_lines, lang";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
|
||||
$sql.= " WHERE type_template='".$db->escape($type_template)."'";
|
||||
$sql.= " AND entity IN (".getEntity("c_email_templates").")";
|
||||
@ -840,6 +853,7 @@ class FormMail extends Form
|
||||
$ret['label']=$obj->label;
|
||||
$ret['topic']=$obj->topic;
|
||||
$ret['content']=$obj->content;
|
||||
$ret['content_lines']=$obj->content_lines;
|
||||
$ret['lang']=$obj->lang;
|
||||
}
|
||||
else
|
||||
@ -859,6 +873,7 @@ class FormMail extends Form
|
||||
$ret['label']='default';
|
||||
$ret['topic']='';
|
||||
$ret['content']=$defaultmessage;
|
||||
$ret['content_lines']='';
|
||||
$ret['lang']=$outputlangs->defaultlang;
|
||||
}
|
||||
|
||||
@ -922,7 +937,7 @@ class FormMail extends Form
|
||||
{
|
||||
$ret=array();
|
||||
|
||||
$sql = "SELECT rowid, label, topic, content, lang, position";
|
||||
$sql = "SELECT rowid, label, topic, content, content_lines, lang, position";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
|
||||
$sql.= " WHERE type_template='".$this->db->escape($type_template)."'";
|
||||
$sql.= " AND entity IN (".getEntity("c_email_templates").")";
|
||||
@ -944,6 +959,7 @@ class FormMail extends Form
|
||||
$line->label=$obj->label;
|
||||
$line->topic=$obj->topic;
|
||||
$line->content=$obj->content;
|
||||
$line->content_lines=$obj->content_lines;
|
||||
$line->lang=$obj->lang;
|
||||
$this->lines_model[]=$line;
|
||||
}
|
||||
@ -962,7 +978,7 @@ class FormMail extends Form
|
||||
/**
|
||||
* Set substit array from object
|
||||
*
|
||||
* @param Object $object Object to use
|
||||
* @param CommonObject $object Object to use
|
||||
* @param Translate $outputlangs Object lang
|
||||
* @return void
|
||||
*/
|
||||
@ -970,11 +986,11 @@ class FormMail extends Form
|
||||
{
|
||||
global $user;
|
||||
$this->substit['__REF__'] = $object->ref;
|
||||
$this->substit['__REFCLIENT__'] = $object->ref_client;
|
||||
$this->substit['__REFSUPPLIER__'] = $object->ref_supplier;
|
||||
$this->substit['__REFCLIENT__'] = isset($object->ref_client) ? $object->ref_client : '';
|
||||
$this->substit['__REFSUPPLIER__'] = isset($object->ref_supplier) ? $object->ref_supplier : '';
|
||||
|
||||
$this->substit['__DATE_YMD__'] = dol_print_date($object->date, 'day', 0, $outputlangs);
|
||||
$this->substit['__DATE_DUE_YMD__'] = dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs);
|
||||
$this->substit['__DATE_YMD__'] = isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '';
|
||||
$this->substit['__DATE_DUE_YMD__'] = isset($object->date_lim_reglement)? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '';
|
||||
$this->substit['__AMOUNT__'] = price($object->total_ttc);
|
||||
$this->substit['__AMOUNT_WO_TAX__'] = price($object->total_ht);
|
||||
|
||||
@ -988,6 +1004,42 @@ class FormMail extends Form
|
||||
$this->substit['__SIGNATURE__'] = $user->signature;
|
||||
$this->substit['__PERSONALIZED__'] = '';
|
||||
$this->substit['__CONTACTCIVNAME__'] = ''; // Will be replace just before sending
|
||||
|
||||
//Fill substit_lines with each object lines content
|
||||
if (is_array($object->lines))
|
||||
{
|
||||
foreach ($object->lines as $line)
|
||||
{
|
||||
$substit_line = array(
|
||||
'__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
|
||||
'__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
|
||||
'__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
|
||||
'__LABEL__' => isset($line->label) ? $line->label : '',
|
||||
'__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
|
||||
'__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
|
||||
'__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
|
||||
'__QUANTITY__' => $line->qty,
|
||||
'__SUBPRICE__' => price($line->subprice),
|
||||
'__AMOUNT__' => price($line->total_ttc),
|
||||
'__AMOUNT_WO_TAX__' => price($line->total_ht),
|
||||
//'__PRODUCT_EXTRAFIELD_FIELD__' Done dinamically
|
||||
);
|
||||
|
||||
// Create dinamic tags for __PRODUCT_EXTRAFIELD_FIELD__
|
||||
if (!empty($line->fk_product))
|
||||
{
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
$extralabels = $extrafields->fetch_name_optionals_label('product', true);
|
||||
$product = new Product($this->db);
|
||||
$product->fetch($line->fk_product, '', '', 1);
|
||||
$product->fetch_optionals($product->id, $extralabels);
|
||||
foreach ($extrafields->attribute_label as $key => $label) {
|
||||
$substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key];
|
||||
}
|
||||
}
|
||||
$this->substit_lines[] = $substit_line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1066,5 +1118,6 @@ class ModelMail
|
||||
public $label;
|
||||
public $topic;
|
||||
public $content;
|
||||
public $content_lines;
|
||||
public $lang;
|
||||
}
|
||||
|
||||
@ -40,3 +40,5 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
|
||||
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',30);
|
||||
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_DELETE','Product or service deleted','Executed when a product or sevice is deleted','product',30);
|
||||
|
||||
ALTER TABLE llx_c_email_templates ADD COLUMN content_lines text;
|
||||
|
||||
|
||||
@ -32,5 +32,6 @@ create table llx_c_email_templates
|
||||
position smallint, -- Position
|
||||
active tinyint DEFAULT 1 NOT NULL,
|
||||
topic text, -- Predefined topic
|
||||
content text -- Predefined text
|
||||
content text, -- Predefined text
|
||||
content_lines text -- Predefined lines
|
||||
)ENGINE=innodb;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user