Move setup of email for module module into email templates

This commit is contained in:
Laurent Destailleur
2018-03-23 16:09:46 +01:00
parent 171ad5dce2
commit 7363ae17ee
14 changed files with 206 additions and 173 deletions

View File

@@ -1321,14 +1321,15 @@ function complete_elementList_with_modules(&$elementList)
/**
* Show array with constants to edit
*
* @param array $tableau Array of constants
* @param array $tableau Array of constants array('key'=>type, ) where type can be 'string', 'text', 'textarea', 'html', 'yesno', 'emailtemplate:xxx', ...
* @param int $strictw3c 0=Include form into table (deprecated), 1=Form is outside table to respect W3C (no form into table), 2=No form nor button at all
* @param string $helptext Help
* @return void
*/
function form_constantes($tableau, $strictw3c=0, $helptext='')
{
global $db,$bc,$langs,$conf,$_Avery_Labels;
global $db,$bc,$langs,$conf,$user;
global $_Avery_Labels;
$form = new Form($db);
@@ -1343,11 +1344,20 @@ function form_constantes($tableau, $strictw3c=0, $helptext='')
print '</td>';
if (empty($strictw3c)) print '<td align="center" width="80">'.$langs->trans("Action").'</td>';
print "</tr>\n";
$var=true;
$listofparam=array();
foreach($tableau as $const) // Loop on each param
foreach($tableau as $key => $const) // Loop on each param
{
// $const is a const key like 'MYMODULE_ABC'
if (is_numeric($key)) {
$type = 'string';
}
else
{
$type = $const;
$const = $key;
}
$sql = "SELECT ";
$sql.= "rowid";
$sql.= ", ".$db->decrypt('name')." as name";
@@ -1355,7 +1365,7 @@ function form_constantes($tableau, $strictw3c=0, $helptext='')
$sql.= ", type";
$sql.= ", note";
$sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name')." = '".$const."'";
$sql.= " WHERE ".$db->decrypt('name')." = '".$db->escape($const)."'";
$sql.= " AND entity IN (0, ".$conf->entity.")";
$sql.= " ORDER BY name ASC, entity DESC";
$result = $db->query($sql);
@@ -1365,23 +1375,26 @@ function form_constantes($tableau, $strictw3c=0, $helptext='')
{
$obj = $db->fetch_object($result); // Take first result of select
// For avoid warning in strict mode
if (empty($obj)) {
$obj = (object) array('rowid'=>'','name'=>'','value'=>'','type'=>'','note'=>'');
if (empty($obj)) // If not yet into table
{
$obj = (object) array('rowid'=>'','name'=>$const,'value'=>'','type'=>$type,'note'=>'');
}
if (empty($strictw3c)) print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
if (empty($strictw3c))
{
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
}
print '<tr class="oddeven">';
// Show constant
print '<td>';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
if (empty($strictw3c)) print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="rowid'.(empty($strictw3c)?'':'[]').'" value="'.$obj->rowid.'">';
print '<input type="hidden" name="constname'.(empty($strictw3c)?'':'[]').'" value="'.$const.'">';
print '<input type="hidden" name="constnote'.(empty($strictw3c)?'':'[]').'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
print '<input type="hidden" name="constnote_'.$obj->name.'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
print '<input type="hidden" name="consttype_'.$obj->name.'" value="'.($obj->type?$obj->type:'string').'">';
print $langs->trans('Desc'.$const);
@@ -1428,34 +1441,57 @@ function form_constantes($tableau, $strictw3c=0, $helptext='')
}
print $form->selectarray('constvalue'.(empty($strictw3c)?'':'[]'),$arrayoflabels,($obj->value?$obj->value:'CARD'),1,0,0);
print '<input type="hidden" name="consttype" value="yesno">';
print '<input type="hidden" name="constnote'.(empty($strictw3c)?'':'[]').'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
print '</td>';
}
else
{
print '<td>';
if (in_array($const,array('ADHERENT_CARD_TEXT','ADHERENT_CARD_TEXT_RIGHT','ADHERENT_ETIQUETTE_TEXT')))
print '<input type="hidden" name="consttype'.(empty($strictw3c)?'':'[]').'" value="'.($obj->type?$obj->type:'string').'">';
print '<input type="hidden" name="constnote'.(empty($strictw3c)?'':'[]').'" value="'.nl2br(dol_escape_htmltag($obj->note)).'">';
if ($obj->type == 'textarea' || in_array($const,array('ADHERENT_CARD_TEXT','ADHERENT_CARD_TEXT_RIGHT','ADHERENT_ETIQUETTE_TEXT')))
{
print '<textarea class="flat" name="constvalue'.(empty($strictw3c)?'':'[]').'" cols="50" rows="5" wrap="soft">'."\n";
print $obj->value;
print "</textarea>\n";
print '<input type="hidden" name="consttype" value="texte">';
}
else if (in_array($const,array('ADHERENT_AUTOREGISTER_NOTIF_MAIL','ADHERENT_AUTOREGISTER_MAIL','ADHERENT_MAIL_VALID','ADHERENT_MAIL_COTIS','ADHERENT_MAIL_RESIL')))
elseif ($obj->type == 'html')
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('constvalue_'.$const.(empty($strictw3c)?'':'[]'),$obj->value,'',160,'dolibarr_notes','',false,false,$conf->fckeditor->enabled,ROWS_5,'90%');
$doleditor->Create();
print '<input type="hidden" name="consttype'.(empty($strictw3c)?'':'[]').'" value="texte">';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('constvalue_'.$const.(empty($strictw3c)?'':'[]'),$obj->value,'',160,'dolibarr_notes','',false,false,$conf->fckeditor->enabled,ROWS_5,'90%');
$doleditor->Create();
}
else if ($obj->type == 'yesno')
elseif ($obj->type == 'yesno')
{
print $form->selectyesno('constvalue'.(empty($strictw3c)?'':'[]'),$obj->value,1);
print '<input type="hidden" name="consttype'.(empty($strictw3c)?'':'[]').'" value="yesno">';
print $form->selectyesno('constvalue'.(empty($strictw3c)?'':'[]'),$obj->value,1);
}
else
elseif (preg_match('/emailtemplate/', $obj->type))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$tmp=explode(':', $obj->type);
$nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1); // We set lang=null to get in priority record with no lang
//$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
$arrayofmessagename=array();
if (is_array($formmail->lines_model))
{
foreach($formmail->lines_model as $modelmail)
{
//var_dump($modelmail);
$moreonlabel='';
if (! empty($arrayofmessagename[$modelmail->label])) $moreonlabel=' <span class="opacitymedium">('.$langs->trans("SeveralLangugeVariatFound").')</span>';
$arrayofmessagename[$modelmail->label]=$langs->trans(preg_replace('/\(|\)/','',$modelmail->label)).$moreonlabel;
}
}
//var_dump($arraydefaultmessage);
//var_dump($arrayofmessagename);
print $form->selectarray('constvalue_'.$obj->name, $arrayofmessagename, $obj->value, 'None', 1, 0, '', 0, 0, 0, '', '', 1);
}
else // type = 'string' ou 'chaine'
{
print '<input type="text" class="flat" size="48" name="constvalue'.(empty($strictw3c)?'':'[]').'" value="'.dol_escape_htmltag($obj->value).'">';
print '<input type="hidden" name="consttype'.(empty($strictw3c)?'':'[]').'" value="chaine">';
}
print '</td>';
}