The form to test email can now use all sending profiles.

This commit is contained in:
Laurent Destailleur 2017-11-25 18:52:47 +01:00
parent a529725c5c
commit 2fc5d9fefb
6 changed files with 64 additions and 91 deletions

View File

@ -727,7 +727,8 @@ else
$formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM); $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
$formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM); $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
$formmail->trackid=(($action == 'testhtml')?"testhtml":"test"); $formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
$formmail->withfromreadonly=0; $formmail->withfromreadonly=1;
$formmail->fromtype='all';
$formmail->withsubstit=0; $formmail->withsubstit=0;
$formmail->withfrom=1; $formmail->withfrom=1;
$formmail->witherrorsto=1; $formmail->witherrorsto=1;

View File

@ -46,7 +46,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
// Load traductions files requiredby by page // Load traductions files requiredby by page
$langs->loadLangs(array("errors","admin","mails","languages")); $langs->loadLangs(array("errors","admin","mails","languages"));
$action = GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; $action = GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST('massaction','alpha'); // The bulk action (combo box choice into lists) $massaction = GETPOST('massaction','alpha'); // The bulk action (combo box choice into lists)
$show_files = GETPOST('show_files','int'); // Show files area generated by bulk actions ? $show_files = GETPOST('show_files','int'); // Show files area generated by bulk actions ?
$confirm = GETPOST('confirm','alpha'); // Result of a confirmation $confirm = GETPOST('confirm','alpha'); // Result of a confirmation
@ -71,7 +71,7 @@ $pagenext = $page + 1;
// Initialize technical objects // Initialize technical objects
$object=new EmailSenderProfile($db); $object=new EmailSenderProfile($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
$diroutputmassaction=$conf->monmodule->dir_output . '/temp/massgeneration/'.$user->id; $diroutputmassaction=$conf->admin->dir_output . '/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('emailsenderprofilelist')); // Note that conf->hooks_modules contains array $hookmanager->initHooks(array('emailsenderprofilelist')); // Note that conf->hooks_modules contains array
// Fetch optionals attributes and labels // Fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label('emailsenderprofile'); $extralabels = $extrafields->fetch_name_optionals_label('emailsenderprofile');
@ -205,9 +205,10 @@ $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql.=$hookmanager->resPrint;
$sql=preg_replace('/, $/','', $sql); $sql=preg_replace('/, $/','', $sql);
$sql.= " FROM ".MAIN_DB_PREFIX."c_email_senderprofile as t"; $sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."emailsenderprofile_extrafields as ef on (t.rowid = ef.fk_object)"; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)";
$sql.= " WHERE t.entity IN (".getEntity('emailsenderprofile').")"; if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('emailsenderprofile').")";
else $sql.=" WHERE 1 = 1";
foreach($search as $key => $val) foreach($search as $key => $val)
{ {
$mode_search=(($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))?1:0); $mode_search=(($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))?1:0);
@ -223,7 +224,7 @@ foreach ($search_array_options as $key => $val)
$mode_search=0; $mode_search=0;
if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric
if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int
if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0')) if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1'))
{ {
$sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search); $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search);
} }
@ -259,7 +260,6 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql.= $db->plimit($limit+1, $offset); $sql.= $db->plimit($limit+1, $offset);
dol_syslog($script_file, LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
if (! $resql) if (! $resql)
{ {
@ -369,10 +369,9 @@ print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"")
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
foreach($object->fields as $key => $val) foreach($object->fields as $key => $val)
{ {
if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align=''; $align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
if ($key == 'status') $align.=($align?' ':'').'center'; if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($align?' '.$align:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>'; if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($align?' '.$align:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
} }
@ -403,16 +402,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$parameters=array('arrayfields'=>$arrayfields); $parameters=array('arrayfields'=>$arrayfields);
$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Rest of fields search
foreach($object->fields as $key => $val)
{
if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($align?' '.$align:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
}
// Action column // Action column
print '<td class="liste_titre" align="right">'; print '<td class="liste_titre" align="right">';
$searchpicto=$form->showFilterButtons(); $searchpicto=$form->showFilterButtons();
@ -426,10 +415,9 @@ print '</tr>'."\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
foreach($object->fields as $key => $val) foreach($object->fields as $key => $val)
{ {
if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align=''; $align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
if ($key == 'status') $align.=($align?' ':'').'center'; if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
} }
@ -451,16 +439,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$parameters=array('arrayfields'=>$arrayfields); $parameters=array('arrayfields'=>$arrayfields);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Rest of fields title
foreach($object->fields as $key => $val)
{
if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
}
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n"; print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
print '</tr>'."\n"; print '</tr>'."\n";
@ -493,40 +471,38 @@ while ($i < min($num, $limit))
print '<tr class="oddeven">'; print '<tr class="oddeven">';
foreach($object->fields as $key => $val) foreach($object->fields as $key => $val)
{ {
if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; $align='';
$align=''; if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; if ($key == 'status') $align.=($align?' ':'').'center';
if ($key == 'status') $align.=($align?' ':'').'center'; if (! empty($arrayfields['t.'.$key]['checked']))
if (! empty($arrayfields['t.'.$key]['checked'])) {
print '<td';
if ($align) print ' class="'.$align.'"';
print '>';
print $object->showOutputField($val, $key, $obj->$key, '');
print '</td>';
if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure']))
{ {
print '<td'.($align?' class="'.$align.'"':'').'>'; if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); $totalarray['val']['t.'.$key] += $obj->$key;
elseif ($key == 'ref') print $object->getNomUrl(1, '', 0, '', 1);
elseif ($key == 'status') print $object->getLibStatut(3);
else print $obj->$key;
print '</td>';
if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure']))
{
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
$totalarray['val']['t.'.$key] += $obj->$key;
}
} }
}
} }
// Extra fields // Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{ {
foreach($extrafields->attribute_label as $key => $val) foreach($extrafields->attribute_label as $key => $val)
{ {
if (! empty($arrayfields["ef.".$key]['checked'])) if (! empty($arrayfields["ef.".$key]['checked']))
{ {
print '<td';
$align=$extrafields->getAlignFlag($key); $align=$extrafields->getAlignFlag($key);
print '<td';
if ($align) print ' align="'.$align.'"'; if ($align) print ' align="'.$align.'"';
print '>'; print '>';
$tmpkey='options_'.$key; $tmpkey='options_'.$key;
print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); print $extrafields->showOutputField($key, $obj->$tmpkey, '');
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure'])) if (! empty($val['isameasure']))
@ -535,35 +511,12 @@ while ($i < min($num, $limit))
$totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey;
} }
} }
} }
} }
// Fields from hook // Fields from hook
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
$reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Rest of fields
foreach($object->fields as $key => $val)
{
if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked']))
{
print '<td'.($align?' class="'.$align.'"':'').'>';
if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour');
elseif ($key == 'status') print $object->getLibStatut(3);
else print $obj->$key;
print '</td>';
if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure']))
{
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
$totalarray['val']['t.'.$key] += $obj->$key;
}
}
}
// Action column // Action column
print '<td class="nowrap" align="center">'; print '<td class="nowrap" align="center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
@ -635,7 +588,7 @@ if (in_array('builddoc',$arrayofmassactions) && ($nbtotalofrecords === '' || $nb
$filedir=$diroutputmassaction; $filedir=$diroutputmassaction;
$genallowed=$user->rights->monmodule->read; $genallowed=$user->rights->monmodule->read;
$delallowed=$user->rights->monmodule->read; $delallowed=$user->rights->monmodule->create;
print $formfile->showdocuments('massfilesarea_monmodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); print $formfile->showdocuments('massfilesarea_monmodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
} }

View File

@ -243,8 +243,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$langs->load("commercial"); $langs->load("commercial");
$fromtype = GETPOST('fromtype'); $fromtype = GETPOST('fromtype','alpha');
if ($fromtype === 'user') { if ($fromtype === 'robot') {
$from = $conf->global->MAIN_MAIL_EMAIL_FROM .' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>';
}
elseif ($fromtype === 'user') {
$from = $user->getFullName($langs) .' <'.$user->email.'>'; $from = $user->getFullName($langs) .' <'.$user->email.'>';
} }
elseif ($fromtype === 'company') { elseif ($fromtype === 'company') {

View File

@ -417,6 +417,11 @@ class FormMail extends Form
//$out.='</div>'; //$out.='</div>';
} }
/*var_dump(! empty($this->withfromreadonly));
var_dump($this->withfrom);
var_dump($this->fromtype);
var_dump($this->fromname);*/
// From // From
if (! empty($this->withfrom)) if (! empty($this->withfrom))
{ {
@ -428,7 +433,8 @@ class FormMail extends Form
&& ! ($this->fromtype === 'company') && ! ($this->fromtype === 'company')
&& ! preg_match('/user_aliases/', $this->fromtype) && ! preg_match('/user_aliases/', $this->fromtype)
&& ! preg_match('/global_aliases/', $this->fromtype) && ! preg_match('/global_aliases/', $this->fromtype)
&& ! preg_match('/senderprofile/', $this->fromtype)) && ! preg_match('/senderprofile/', $this->fromtype)
&& ! ($this->fromtype === 'all'))
{ {
// Use this->fromname and this->frommail or error if not defined // Use this->fromname and this->frommail or error if not defined
$out.= $this->fromname; $out.= $this->fromname;
@ -447,6 +453,15 @@ class FormMail extends Form
} else { } else {
$liste = array(); $liste = array();
if ($this->fromtype === 'all')
{
$liste['robot'] = $this->fromname;
if ($this->frommail)
{
$liste['robot'] .= ' &lt;'.$this->frommail.'&gt;';
}
}
// Add user email // Add user email
if (empty($user->email)) if (empty($user->email))
{ {
@ -500,15 +515,16 @@ class FormMail extends Form
} }
} }
} }
// Using combo here make the '<email>' no more visible on list.
//$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200onsmartphone', 1, '', $disablebademails);
$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200onsmartphone', 0, '', $disablebademails); $out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200onsmartphone', 0, '', $disablebademails);
//$out.= ajax_combobox('fromtype');
} }
$out.= "</td></tr>\n"; $out.= "</td></tr>\n";
} }
else else
{ {
$out.= '<tr><td class="fieldrequired">'.$langs->trans("MailFrom")."</td><td>"; $out.= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>";
$out.= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />'; $out.= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />';
$out.= '&nbsp; &nbsp; '; $out.= '&nbsp; &nbsp; ';
$out.= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />&gt;'; $out.= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />&gt;';
@ -639,7 +655,7 @@ class FormMail extends Form
} }
else else
{ {
$out.= '<input size="'.(is_array($this->withtoccc)?"30":"60").'" id="sendtoccc" name="sendtoccc" value="'.((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))? (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:$this->withtoccc) : (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:"") ).'" />'; $out.= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))? (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:$this->withtoccc) : (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:"") ).'" />';
if (! empty($this->withtoccc) && is_array($this->withtoccc)) if (! empty($this->withtoccc) && is_array($this->withtoccc))
{ {
$out.= " ".$langs->trans("and")."/".$langs->trans("or")." "; $out.= " ".$langs->trans("and")."/".$langs->trans("or")." ";

View File

@ -1560,7 +1560,7 @@ function email_admin_prepare_head()
$head[$h][2] = 'templates'; $head[$h][2] = 'templates';
$h++; $h++;
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
{ {
$head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php"; $head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php";
$head[$h][1] = $langs->trans("EmailSenderProfiles"); $head[$h][1] = $langs->trans("EmailSenderProfiles");

View File

@ -138,7 +138,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
/* /*
* ACTIONS * Actions
* *
* Put here all code to do according to value of "$action" parameter * Put here all code to do according to value of "$action" parameter
*/ */
@ -183,9 +183,9 @@ if (empty($reshook))
/* /*
* VIEW * View
* *
* Put here all code to build page * Put here all code to render page
*/ */
$form=new Form($db); $form=new Form($db);