New: Add template of emails into dictionnary.

This commit is contained in:
Laurent Destailleur 2014-10-30 17:16:51 +01:00
parent a5700c8f44
commit 38a939771c
3 changed files with 53 additions and 10 deletions

View File

@ -70,7 +70,7 @@ $hookmanager->initHooks(array('admin'));
// Put here declaration of dictionaries properties // Put here declaration of dictionaries properties
// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,23,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24); $taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,23,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,0,25);
// Name of SQL tables of dictionaries // Name of SQL tables of dictionaries
$tabname=array(); $tabname=array();
@ -98,6 +98,7 @@ $tabname[21]= MAIN_DB_PREFIX."c_availability";
$tabname[22]= MAIN_DB_PREFIX."c_input_reason"; $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
$tabname[23]= MAIN_DB_PREFIX."c_revenuestamp"; $tabname[23]= MAIN_DB_PREFIX."c_revenuestamp";
$tabname[24]= MAIN_DB_PREFIX."c_type_resource"; $tabname[24]= MAIN_DB_PREFIX."c_type_resource";
$tabname[25]= MAIN_DB_PREFIX."c_email_templates";
// Dictionary labels // Dictionary labels
$tablib=array(); $tablib=array();
@ -125,6 +126,7 @@ $tablib[21]= "DictionaryAvailability";
$tablib[22]= "DictionarySource"; $tablib[22]= "DictionarySource";
$tablib[23]= "DictionaryRevenueStamp"; $tablib[23]= "DictionaryRevenueStamp";
$tablib[24]= "DictionaryResourceType"; $tablib[24]= "DictionaryResourceType";
$tablib[25]= "DictionaryEMailTemplates";
// Requests to extract data // Requests to extract data
$tabsql=array(); $tabsql=array();
@ -152,6 +154,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[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
$tabsql[23]= "SELECT t.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[23]= "SELECT t.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[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";
// Criteria to sort dictionaries // Criteria to sort dictionaries
$tabsqlsort=array(); $tabsqlsort=array();
@ -179,6 +182,7 @@ $tabsqlsort[21]="code ASC, label ASC";
$tabsqlsort[22]="code ASC, label ASC"; $tabsqlsort[22]="code ASC, label ASC";
$tabsqlsort[23]="country ASC, taux ASC"; $tabsqlsort[23]="country ASC, taux ASC";
$tabsqlsort[24]="code ASC,label ASC"; $tabsqlsort[24]="code ASC,label ASC";
$tabsqlsort[25]="label ASC";
// Nom des champs en resultat de select pour affichage du dictionnaire // Nom des champs en resultat de select pour affichage du dictionnaire
$tabfield=array(); $tabfield=array();
@ -206,6 +210,7 @@ $tabfield[21]= "code,label";
$tabfield[22]= "code,label"; $tabfield[22]= "code,label";
$tabfield[23]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note"; $tabfield[23]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[24]= "code,label"; $tabfield[24]= "code,label";
$tabfield[25]= "label,type_template,private,position,topic,content";
// Nom des champs d'edition pour modification d'un enregistrement // Nom des champs d'edition pour modification d'un enregistrement
$tabfieldvalue=array(); $tabfieldvalue=array();
@ -233,6 +238,7 @@ $tabfieldvalue[21]= "code,label";
$tabfieldvalue[22]= "code,label"; $tabfieldvalue[22]= "code,label";
$tabfieldvalue[23]= "country,taux,accountancy_code_sell,accountancy_code_buy,note"; $tabfieldvalue[23]= "country,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[24]= "code,label"; $tabfieldvalue[24]= "code,label";
$tabfieldvalue[25]= "label,type_template,private,position,topic,content";
// Nom des champs dans la table pour insertion d'un enregistrement // Nom des champs dans la table pour insertion d'un enregistrement
$tabfieldinsert=array(); $tabfieldinsert=array();
@ -260,6 +266,7 @@ $tabfieldinsert[21]= "code,label";
$tabfieldinsert[22]= "code,label"; $tabfieldinsert[22]= "code,label";
$tabfieldinsert[23]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note"; $tabfieldinsert[23]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldinsert[24]= "code,label"; $tabfieldinsert[24]= "code,label";
$tabfieldinsert[25]= "label,type_template,private,position,topic,content";
// Nom du rowid si le champ n'est pas de type autoincrement // Nom du rowid si le champ n'est pas de type autoincrement
// Example: "" if id field is "rowid" and has autoincrement on // Example: "" if id field is "rowid" and has autoincrement on
@ -288,7 +295,8 @@ $tabrowid[20]= "";
$tabrowid[21]= "rowid"; $tabrowid[21]= "rowid";
$tabrowid[22]= "rowid"; $tabrowid[22]= "rowid";
$tabrowid[23]= ""; $tabrowid[23]= "";
$tabrowid[23]= ""; $tabrowid[24]= "";
$tabrowid[25]= "";
// Condition to show dictionary in setup page // Condition to show dictionary in setup page
$tabcond=array(); $tabcond=array();
@ -316,6 +324,7 @@ $tabcond[21]= ! empty($conf->propal->enabled);
$tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled)); $tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled));
$tabcond[23]= true; $tabcond[23]= true;
$tabcond[24]= ! empty($conf->resource->enabled); $tabcond[24]= ! empty($conf->resource->enabled);
$tabcond[25]= true; // && ! empty($conf->global->MAIN_EMAIL_EDIT_TEMPLATE_FROM_DIC);
// List of help for fields // List of help for fields
$tabhelp=array(); $tabhelp=array();
@ -343,6 +352,7 @@ $tabhelp[21] = array();
$tabhelp[22] = array(); $tabhelp[22] = array();
$tabhelp[23] = array(); $tabhelp[23] = array();
$tabhelp[24] = array(); $tabhelp[24] = array();
$tabhelp[25] = array();
// List of check for fields (NOT USED YET) // List of check for fields (NOT USED YET)
$tabfieldcheck=array(); $tabfieldcheck=array();
@ -370,6 +380,7 @@ $tabfieldcheck[21] = array();
$tabfieldcheck[22] = array(); $tabfieldcheck[22] = array();
$tabfieldcheck[23] = array(); $tabfieldcheck[23] = array();
$tabfieldcheck[24] = array(); $tabfieldcheck[24] = array();
$tabfieldcheck[25] = array();
// Complete all arrays with entries found into modules // Complete all arrays with entries found into modules
complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck); complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
@ -442,7 +453,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$ok=1; $ok=1;
foreach ($listfield as $f => $value) foreach ($listfield as $f => $value)
{ {
if ($value == 'country' && in_array($tablib[$id],array('DictionaryRegion','DictionaryCompanyType'))) continue; // For some pages, country is not mandatory if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType'))) continue; // For some pages, country is not mandatory
if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryRegion','DictionaryCompanyType'))) continue; // For some pages, country is not mandatory if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryRegion','DictionaryCompanyType'))) continue; // For some pages, country is not mandatory
if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue; if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue; if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
@ -489,7 +500,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />'; $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
}*/ }*/
} }
if (isset($_POST["country"]) && $_POST["country"]=='0') if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
{ {
if (in_array($tablib[$id],array('DictionaryCompanyType'))) if (in_array($tablib[$id],array('DictionaryCompanyType')))
{ {
@ -533,6 +544,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$sql.= $tabfieldinsert[$id]; $sql.= $tabfieldinsert[$id];
$sql.=",active)"; $sql.=",active)";
$sql.= " VALUES("; $sql.= " VALUES(";
// List of values // List of values
if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert)) if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
$sql.= $newid.","; $sql.= $newid.",";
@ -846,6 +858,13 @@ if ($id)
if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); } if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); } if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); } if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
if ($id == 2) // Special cas for state page
{
if ($fieldlist[$field]=='region_id') { $valuetoshow='&nbsp;'; $showfield=1; }
if ($fieldlist[$field]=='region') { $valuetoshow=$langs->trans("Country").'/'.$langs->trans("Region"); $showfield=1; }
}
if ($valuetoshow != '') if ($valuetoshow != '')
{ {
print '<td align="'.$align.'">'; print '<td align="'.$align.'">';
@ -856,12 +875,14 @@ if ($id)
} }
if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1; if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
} }
if ($id == 4) print '<td></td>';
print '<td colspan="4">'; print '<td colspan="4">';
print '<input type="hidden" name="id" value="'.$id.'">'; print '<input type="hidden" name="id" value="'.$id.'">';
print '&nbsp;</td>'; print '&nbsp;</td>';
print '</tr>'; print '</tr>';
// Line to type new values // Line to enter new values
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
$obj = new stdClass(); $obj = new stdClass();
@ -880,16 +901,25 @@ if ($id)
$reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
$error=$hookmanager->error; $errors=$hookmanager->errors; $error=$hookmanager->error; $errors=$hookmanager->errors;
if ($id == 3)
{
unset($fieldlist[2]);
}
if (empty($reshook)) fieldList($fieldlist,$obj); if (empty($reshook)) fieldList($fieldlist,$obj);
if ($id == 4) print '<td></td>';
print '<td colspan="3" align="right"><input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'"></td>'; print '<td colspan="3" align="right"><input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'"></td>';
print "</tr>"; print "</tr>";
$colspan=count($fieldlist)+2;
if ($id == 4) $colspan++;;
if (! empty($alabelisused)) // Si un des champs est un libelle if (! empty($alabelisused)) // Si un des champs est un libelle
{ {
print '<tr><td colspan="'.(count($fieldlist)+2).'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>'; print '<tr><td colspan="'.$colspan.'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
} }
print '<tr><td colspan="'.(count($fieldlist)+2).'">&nbsp;</td></tr>'; print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>';
} }
print '</form>'; print '</form>';
@ -965,6 +995,7 @@ if ($id)
if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); } if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); } if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); } if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
// Affiche nom du champ // Affiche nom du champ
if ($showfield) if ($showfield)
{ {
@ -1302,7 +1333,7 @@ $db->close();
/** /**
* Show field * Show fields in insert/edit mode
* *
* @param array $fieldlist Array of fields * @param array $fieldlist Array of fields
* @param Object $obj If we show a particular record, obj is filled with record fields * @param Object $obj If we show a particular record, obj is filled with record fields
@ -1322,14 +1353,22 @@ function fieldList($fieldlist,$obj='',$tabname='')
foreach ($fieldlist as $field => $value) foreach ($fieldlist as $field => $value)
{ {
if ($fieldlist[$field] == 'country') { if ($fieldlist[$field] == 'country') {
if (in_array('region_id',$fieldlist)) { print '<td>'.join(',',$fieldlist).'&nbsp;</td>'; continue; } // For state page, we do not show the country input (we link to region, not country) if (in_array('region_id',$fieldlist))
{
print '<td>';
//print join(',',$fieldlist);
print '</td>';
continue;
} // For state page, we do not show the country input (we link to region, not country)
print '<td>'; print '<td>';
print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), 'country', '', 28); print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), 'country', '', 28);
print '</td>'; print '</td>';
} }
elseif ($fieldlist[$field] == 'country_id') { elseif ($fieldlist[$field] == 'country_id') {
$country_id = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0); $country_id = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0);
print '<td>';
print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">'; print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
print '</td>';
} }
elseif ($fieldlist[$field] == 'region') { elseif ($fieldlist[$field] == 'region') {
print '<td>'; print '<td>';
@ -1338,7 +1377,9 @@ function fieldList($fieldlist,$obj='',$tabname='')
} }
elseif ($fieldlist[$field] == 'region_id') { elseif ($fieldlist[$field] == 'region_id') {
$region_id = (! empty($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:0); $region_id = (! empty($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:0);
print '<td>';
print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">'; print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
print '</td>';
} }
elseif ($fieldlist[$field] == 'lang') { elseif ($fieldlist[$field] == 'lang') {
print '<td>'; print '<td>';
@ -1377,7 +1418,7 @@ function fieldList($fieldlist,$obj='',$tabname='')
print '<input type="text" class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" size="3" name="'.$fieldlist[$field].'">'; print '<input type="text" class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" size="3" name="'.$fieldlist[$field].'">';
print '</td>'; print '</td>';
} }
elseif ($fieldlist[$field] == 'libelle_facture') { elseif (in_array($fieldlist[$field], array('libelle_facture','content'))) {
print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'</textarea></td>'; print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'</textarea></td>';
} }
elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) { elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {

View File

@ -1026,6 +1026,7 @@ create table llx_c_email_templates
tms timestamp, tms timestamp,
label varchar(255), -- Label of predefined email label varchar(255), -- Label of predefined email
position smallint, -- Position position smallint, -- Position
active tinyint DEFAULT 1 NOT NULL,
topic text, -- Predefined topic topic text, -- Predefined topic
content text -- Predefined text content text -- Predefined text
) ENGINE=innodb; ) ENGINE=innodb;

View File

@ -30,6 +30,7 @@ create table llx_c_email_templates
tms timestamp, tms timestamp,
label varchar(255), -- Label of predefined email label varchar(255), -- Label of predefined email
position smallint, -- Position position smallint, -- Position
active tinyint DEFAULT 1 NOT NULL,
topic text, -- Predefined topic topic text, -- Predefined topic
content text -- Predefined text content text -- Predefined text
)ENGINE=innodb; )ENGINE=innodb;