mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix permission to edit email template - Debug v20
This commit is contained in:
parent
403fcd234e
commit
8a257ac93f
|
|
@ -37,11 +37,11 @@
|
|||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langsArray = array("errors", "admin", "mails", "languages");
|
||||
|
|
@ -62,8 +62,7 @@ $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
|
|||
$mode = GETPOST('mode', 'aZ09');
|
||||
$optioncss = GETPOST('optioncss', 'alpha');
|
||||
|
||||
$id = GETPOSTINT('id');
|
||||
$rowid = GETPOST('rowid', 'alpha');
|
||||
$id = $rowid = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('rowid'));
|
||||
$search_label = GETPOST('search_label', 'alphanohtml'); // Must allow value like 'Abc Def' or '(MyTemplateName)'
|
||||
$search_type_template = GETPOST('search_type_template', 'alpha');
|
||||
$search_lang = GETPOST('search_lang', 'alpha');
|
||||
|
|
@ -254,8 +253,6 @@ if ($reshook == 0) {
|
|||
|
||||
$error = 0;
|
||||
|
||||
$id = 25;
|
||||
|
||||
$acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
|
||||
|
||||
// Security
|
||||
|
|
@ -264,8 +261,16 @@ if (!empty($user->socid)) {
|
|||
}
|
||||
|
||||
$permissiontoadd = 1;
|
||||
$permissiontodelete = 1;
|
||||
|
||||
$permissiontoedit = ($user->admin ? 1 : 0);
|
||||
$permissiontodelete = ($user->admin ? 1 : 0);
|
||||
if ($rowid > 0) {
|
||||
$tmpmailtemplate = new ModelMail($db);
|
||||
$tmpmailtemplate->fetch($rowid);
|
||||
if ($tmpmailtemplate->fk_user == $user->id) {
|
||||
$permissiontoedit = 1;
|
||||
$permissiontodelete = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -304,11 +309,11 @@ if (empty($reshook)) {
|
|||
}
|
||||
|
||||
// Actions add or modify an email template
|
||||
if ((GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) && $permissiontoadd) {
|
||||
$listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
|
||||
$listfieldinsert = explode(',', $tabfieldinsert[$id]);
|
||||
$listfieldmodify = explode(',', $tabfieldinsert[$id]);
|
||||
$listfieldvalue = explode(',', $tabfieldvalue[$id]);
|
||||
if ((GETPOST('actionadd', 'alpha') && $permissiontoadd) || (GETPOST('actionmodify', 'alpha') && $permissiontoedit)) {
|
||||
$listfield = explode(',', str_replace(' ', '', $tabfield[25]));
|
||||
$listfieldinsert = explode(',', $tabfieldinsert[25]);
|
||||
$listfieldmodify = explode(',', $tabfieldinsert[25]);
|
||||
$listfieldvalue = explode(',', $tabfieldvalue[25]);
|
||||
|
||||
// Check that all fields are filled
|
||||
$ok = 1;
|
||||
|
|
@ -360,9 +365,9 @@ if (empty($reshook)) {
|
|||
// If previous test is ok action is add, we add the line
|
||||
if ($ok && GETPOST('actionadd')) {
|
||||
// Add new entry
|
||||
$sql = "INSERT INTO ".$tabname[$id]." (";
|
||||
$sql = "INSERT INTO ".$tabname[25]." (";
|
||||
// List of fields
|
||||
$sql .= $tabfieldinsert[$id];
|
||||
$sql .= $tabfieldinsert[25];
|
||||
$sql .= ", active, enabled)";
|
||||
$sql .= " VALUES(";
|
||||
|
||||
|
|
@ -423,7 +428,7 @@ if (empty($reshook)) {
|
|||
$result = $db->query($sql);
|
||||
if ($result) { // Add is ok
|
||||
setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
|
||||
$_POST = array('id' => $id); // Clean $_POST array, we keep only id
|
||||
$_POST = array('id' => 25); // Clean $_POST array, we keep only id
|
||||
} else {
|
||||
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
||||
setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
|
||||
|
|
@ -446,7 +451,7 @@ if (empty($reshook)) {
|
|||
|
||||
if (!$error) {
|
||||
// Modify entry
|
||||
$sql = "UPDATE ".$tabname[$id]." SET ";
|
||||
$sql = "UPDATE ".$tabname[25]." SET ";
|
||||
// Modify value of fields
|
||||
$i = 0;
|
||||
foreach ($listfieldmodify as $field) {
|
||||
|
|
@ -532,7 +537,7 @@ if (empty($reshook)) {
|
|||
if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { // delete
|
||||
$rowidcol = "rowid";
|
||||
|
||||
$sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
|
||||
$sql = "DELETE from ".$tabname[25]." WHERE ".$rowidcol." = ".((int) $rowid);
|
||||
if (!$user->admin) { // A non admin user can only edit its own template
|
||||
$sql .= " AND fk_user = ".((int) $user->id);
|
||||
}
|
||||
|
|
@ -548,10 +553,10 @@ if (empty($reshook)) {
|
|||
}
|
||||
|
||||
// activate
|
||||
if ($action == $acts[0] && $permissiontoadd) {
|
||||
if ($action == $acts[0] && $permissiontoedit) {
|
||||
$rowidcol = "rowid";
|
||||
|
||||
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE rowid = ".((int) $rowid);
|
||||
$sql = "UPDATE ".$tabname[25]." SET active = 1 WHERE rowid = ".((int) $rowid);
|
||||
|
||||
$result = $db->query($sql);
|
||||
if (!$result) {
|
||||
|
|
@ -560,10 +565,10 @@ if (empty($reshook)) {
|
|||
}
|
||||
|
||||
// disable
|
||||
if ($action == $acts[1] && $permissiontoadd) {
|
||||
if ($action == $acts[1] && $permissiontoedit) {
|
||||
$rowidcol = "rowid";
|
||||
|
||||
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE rowid = ".((int) $rowid);
|
||||
$sql = "UPDATE ".$tabname[25]." SET active = 0 WHERE rowid = ".((int) $rowid);
|
||||
|
||||
$result = $db->query($sql);
|
||||
if (!$result) {
|
||||
|
|
@ -578,11 +583,10 @@ if (empty($reshook)) {
|
|||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
$formadmin = new FormAdmin($db);
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
$formadmin = new FormAdmin($db);
|
||||
|
||||
//$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
|
||||
$help_url = '';
|
||||
if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
|
||||
|
|
@ -698,11 +702,11 @@ if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu
|
|||
|
||||
// Confirm deletion of record
|
||||
if ($action == 'delete') {
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((int) $rowid).'&id='.((int) $id), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((int) $rowid), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
|
||||
}
|
||||
|
||||
|
||||
$fieldlist = explode(',', $tabfield[$id]);
|
||||
$fieldlist = explode(',', $tabfield[25]);
|
||||
|
||||
if ($action == 'create') {
|
||||
// If data was already input, we define them in obj to populate input fields.
|
||||
|
|
@ -719,7 +723,7 @@ if ($action == 'create') {
|
|||
$obj->content = GETPOST('content', 'restricthtml');
|
||||
|
||||
// Form to add a new line
|
||||
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
|
||||
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
|
||||
|
|
@ -778,13 +782,13 @@ if ($action == 'create') {
|
|||
}
|
||||
if ($valuetoshow != '') {
|
||||
print '<th class="'.$css.'">';
|
||||
if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
|
||||
print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
|
||||
} elseif (!empty($tabhelp[$id][$value])) {
|
||||
if (!empty($tabhelp[25][$value]) && preg_match('/^http(s*):/i', $tabhelp[25][$value])) {
|
||||
print '<a href="'.$tabhelp[25][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
|
||||
} elseif (!empty($tabhelp[25][$value])) {
|
||||
if (in_array($value, array('topic'))) {
|
||||
print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
|
||||
print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
|
||||
} else {
|
||||
print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
|
||||
print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2); // Tooltip on hover
|
||||
}
|
||||
} else {
|
||||
print $valuetoshow;
|
||||
|
|
@ -793,14 +797,13 @@ if ($action == 'create') {
|
|||
}
|
||||
}
|
||||
print '<th>';
|
||||
print '<input type="hidden" name="id" value="'.$id.'">';
|
||||
print '</th>';
|
||||
print '</tr>';
|
||||
|
||||
$tmpaction = 'create';
|
||||
$parameters = array(
|
||||
'fieldlist' => $fieldlist,
|
||||
'tabname' => $tabname[$id]
|
||||
'tabname' => $tabname[25]
|
||||
);
|
||||
$reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
|
||||
$error = $hookmanager->error;
|
||||
|
|
@ -812,9 +815,9 @@ if ($action == 'create') {
|
|||
|
||||
if (empty($reshook)) {
|
||||
if ($action == 'edit') {
|
||||
fieldList($fieldlist, $obj, $tabname[$id], 'hide');
|
||||
fieldList($fieldlist, $obj, $tabname[25], 'hide');
|
||||
} else {
|
||||
fieldList($fieldlist, $obj, $tabname[$id], 'add');
|
||||
fieldList($fieldlist, $obj, $tabname[25], 'add');
|
||||
}
|
||||
}
|
||||
// Action column
|
||||
|
|
@ -832,19 +835,19 @@ if ($action == 'create') {
|
|||
foreach ($fieldsforcontent as $tmpfieldlist) {
|
||||
// Topic of email
|
||||
if ($tmpfieldlist == 'topic') {
|
||||
print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
|
||||
print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
|
||||
}
|
||||
if ($tmpfieldlist == 'email_from') {
|
||||
print $form->textwithpicto($langs->trans("MailFrom"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist);
|
||||
print $form->textwithpicto($langs->trans("MailFrom"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist);
|
||||
}
|
||||
if ($tmpfieldlist == 'joinfiles') {
|
||||
print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
|
||||
print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
|
||||
}
|
||||
if ($tmpfieldlist == 'content') {
|
||||
print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
print $form->textwithpicto($langs->trans("Content"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
}
|
||||
if ($tmpfieldlist == 'content_lines') {
|
||||
print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
}
|
||||
|
||||
// Input field
|
||||
|
|
@ -892,7 +895,7 @@ if (!$resql) {
|
|||
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
|
||||
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
|
||||
|
||||
|
|
@ -901,7 +904,7 @@ print '<table class="noborder centpercent">';
|
|||
|
||||
$i = 0;
|
||||
|
||||
$param = '&id='.((int) $id);
|
||||
$param = '';
|
||||
if ($search_label) {
|
||||
$param .= '&search_label='.urlencode($search_label);
|
||||
}
|
||||
|
|
@ -1050,11 +1053,11 @@ foreach ($fieldlist as $field => $value) {
|
|||
|
||||
// Show fields
|
||||
if ($showfield) {
|
||||
if (!empty($tabhelp[$id][$value])) {
|
||||
if (!empty($tabhelp[25][$value])) {
|
||||
if (in_array($value, array('topic'))) {
|
||||
$valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
|
||||
$valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
|
||||
} else {
|
||||
$valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
|
||||
$valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
|
||||
}
|
||||
}
|
||||
$sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
|
||||
|
|
@ -1084,7 +1087,7 @@ if ($num) {
|
|||
print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
|
||||
|
||||
$tmpaction = 'edit';
|
||||
$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
|
||||
$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
|
||||
$reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
|
||||
$error = $hookmanager->error;
|
||||
$errors = $hookmanager->errors;
|
||||
|
|
@ -1103,7 +1106,7 @@ if ($num) {
|
|||
}
|
||||
// Show main fields
|
||||
if (empty($reshook)) {
|
||||
fieldList($fieldlist, $obj, $tabname[$id], $action);
|
||||
fieldList($fieldlist, $obj, $tabname[25], $action);
|
||||
}
|
||||
// Action column
|
||||
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
|
||||
|
|
@ -1136,23 +1139,23 @@ if ($num) {
|
|||
if ($showfield) {
|
||||
// Show line for topic, joinfiles and content
|
||||
if ($tmpfieldlist == 'topic') {
|
||||
print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
|
||||
print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
|
||||
print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').'>';
|
||||
print '<br>'."\n";
|
||||
}
|
||||
if ($tmpfieldlist == 'email_from') {
|
||||
print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
|
||||
print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
|
||||
print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').'>';
|
||||
print '<br>'."\n";
|
||||
}
|
||||
if ($tmpfieldlist == 'joinfiles') {
|
||||
print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
|
||||
print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
|
||||
print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, ($action != 'edit'), 0, 1);
|
||||
print '<br>'."\n";
|
||||
}
|
||||
|
||||
if ($tmpfieldlist == 'content') {
|
||||
print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
print $form->textwithpicto($langs->trans("Content"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
$okforextended = true;
|
||||
if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
|
||||
$okforextended = false;
|
||||
|
|
@ -1162,7 +1165,7 @@ if ($num) {
|
|||
}
|
||||
if ($tmpfieldlist == 'content_lines') {
|
||||
print '<br>'."\n";
|
||||
print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
|
||||
$okforextended = true;
|
||||
if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
|
||||
$okforextended = false;
|
||||
|
|
@ -1235,7 +1238,7 @@ if ($num) {
|
|||
}
|
||||
|
||||
$tmpaction = 'view';
|
||||
$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
|
||||
$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
|
||||
$reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
|
||||
|
||||
$error = $hookmanager->error;
|
||||
|
|
@ -1481,7 +1484,7 @@ function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
|
|||
if ($value == 'private' && $context != 'preview') {
|
||||
if (empty($user->admin)) {
|
||||
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
|
||||
print $form->selectyesno($value, '1', 1, false, 0, 1);
|
||||
print $form->selectyesno($value, GETPOSTISSET($value) ? GETPOSTINT($value) : (($context != 'add' && isset($obj->$value)) ? $obj->$value : '1'), 1, false, 0, 1);
|
||||
} else {
|
||||
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
|
||||
print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1, false, 0, 1);
|
||||
|
|
|
|||
|
|
@ -1990,13 +1990,61 @@ class FormMail extends Form
|
|||
}
|
||||
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
|
||||
/**
|
||||
* ModelMail
|
||||
*
|
||||
* Object of table llx_c_email_templates
|
||||
*
|
||||
* TODO Move this class into a file cemailtemplate.class.php
|
||||
*/
|
||||
class ModelMail
|
||||
class ModelMail extends CommonObject
|
||||
{
|
||||
/**
|
||||
* @var string ID to identify managed object.
|
||||
*/
|
||||
public $element = 'email_template';
|
||||
|
||||
/**
|
||||
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management (so extrafields know the link to the parent table).
|
||||
*/
|
||||
public $table_element = 'c_email_templates';
|
||||
|
||||
|
||||
// BEGIN MODULEBUILDER PROPERTIES
|
||||
/**
|
||||
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
*/
|
||||
public $fields=array(
|
||||
"rowid" => array("type"=>"integer", "label"=>"TechnicalID", "enabled"=>"1", 'position'=>10, 'notnull'=>1, "visible"=>"-1",),
|
||||
"module" => array("type"=>"varchar(32)", "label"=>"Module", "enabled"=>"1", 'position'=>20, 'notnull'=>0, "visible"=>"-1",),
|
||||
"type_template" => array("type"=>"varchar(32)", "label"=>"Typetemplate", "enabled"=>"1", 'position'=>25, 'notnull'=>0, "visible"=>"-1",),
|
||||
"lang" => array("type"=>"varchar(6)", "label"=>"Lang", "enabled"=>"1", 'position'=>30, 'notnull'=>0, "visible"=>"-1",),
|
||||
"private" => array("type"=>"smallint(6)", "label"=>"Private", "enabled"=>"1", 'position'=>35, 'notnull'=>1, "visible"=>"-1",),
|
||||
"fk_user" => array("type"=>"integer:User:user/class/user.class.php", "label"=>"Fkuser", "enabled"=>"1", 'position'=>40, 'notnull'=>0, "visible"=>"-1", "css"=>"maxwidth500 widthcentpercentminusxx", "csslist"=>"tdoverflowmax150",),
|
||||
"datec" => array("type"=>"datetime", "label"=>"DateCreation", "enabled"=>"1", 'position'=>45, 'notnull'=>0, "visible"=>"-1",),
|
||||
"tms" => array("type"=>"timestamp", "label"=>"DateModification", "enabled"=>"1", 'position'=>50, 'notnull'=>1, "visible"=>"-1",),
|
||||
"label" => array("type"=>"varchar(255)", "label"=>"Label", "enabled"=>"1", 'position'=>55, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1", "css"=>"minwidth300", "cssview"=>"wordbreak", "csslist"=>"tdoverflowmax150",),
|
||||
"position" => array("type"=>"smallint(6)", "label"=>"Position", "enabled"=>"1", 'position'=>60, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"active" => array("type"=>"integer", "label"=>"Active", "enabled"=>"1", 'position'=>65, 'notnull'=>1, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"topic" => array("type"=>"text", "label"=>"Topic", "enabled"=>"1", 'position'=>70, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"content" => array("type"=>"mediumtext", "label"=>"Content", "enabled"=>"1", 'position'=>75, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"content_lines" => array("type"=>"text", "label"=>"Contentlines", "enabled"=>"1", 'position'=>80, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"enabled" => array("type"=>"varchar(255)", "label"=>"Enabled", "enabled"=>"1", 'position'=>85, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"joinfiles" => array("type"=>"varchar(255)", "label"=>"Joinfiles", "enabled"=>"1", 'position'=>90, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"email_from" => array("type"=>"varchar(255)", "label"=>"Emailfrom", "enabled"=>"1", 'position'=>95, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"email_to" => array("type"=>"varchar(255)", "label"=>"Emailto", "enabled"=>"1", 'position'=>100, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"email_tocc" => array("type"=>"varchar(255)", "label"=>"Emailtocc", "enabled"=>"1", 'position'=>105, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"email_tobcc" => array("type"=>"varchar(255)", "label"=>"Emailtobcc", "enabled"=>"1", 'position'=>110, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
"defaultfortype" => array("type"=>"smallint(6)", "label"=>"Defaultfortype", "enabled"=>"1", 'position'=>115, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
|
||||
);
|
||||
public $rowid;
|
||||
public $type_template;
|
||||
public $datec;
|
||||
public $tms;
|
||||
public $active;
|
||||
public $enabled;
|
||||
public $defaultfortype;
|
||||
|
||||
/**
|
||||
* @var int ID
|
||||
*/
|
||||
|
|
@ -2044,4 +2092,71 @@ class ModelMail
|
|||
* @var int Position of template in a combo list
|
||||
*/
|
||||
public $position;
|
||||
// END MODULEBUILDER PROPERTIES
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct(DoliDB $db)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$this->db = $db;
|
||||
$this->ismultientitymanaged = 0;
|
||||
$this->isextrafieldmanaged = 1;
|
||||
|
||||
if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
|
||||
$this->fields['rowid']['visible'] = 0;
|
||||
}
|
||||
if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
|
||||
$this->fields['entity']['enabled'] = 0;
|
||||
}
|
||||
|
||||
// Example to show how to set values of fields definition dynamically
|
||||
/*if ($user->hasRight('test', 'mailtemplate', 'read')) {
|
||||
$this->fields['myfield']['visible'] = 1;
|
||||
$this->fields['myfield']['noteditable'] = 0;
|
||||
}*/
|
||||
|
||||
// Unset fields that are disabled
|
||||
foreach ($this->fields as $key => $val) {
|
||||
if (isset($val['enabled']) && empty($val['enabled'])) {
|
||||
unset($this->fields[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Translate some data of arrayofkeyval
|
||||
if (is_object($langs)) {
|
||||
foreach ($this->fields as $key => $val) {
|
||||
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
|
||||
foreach ($val['arrayofkeyval'] as $key2 => $val2) {
|
||||
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load object in memory from the database
|
||||
*
|
||||
* @param int $id Id object
|
||||
* @param string $ref Ref
|
||||
* @param int $noextrafields 0=Default to load extrafields, 1=No extrafields
|
||||
* @param int $nolines 0=Default to load extrafields, 1=No extrafields
|
||||
* @return int Return integer <0 if KO, 0 if not found, >0 if OK
|
||||
*/
|
||||
public function fetch($id, $ref = null, $noextrafields = 0, $nolines = 0)
|
||||
{
|
||||
$result = $this->fetchCommon($id, $ref, '', $noextrafields);
|
||||
if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
|
||||
$this->fetchLines($noextrafields);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,17 +35,17 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
|||
class MyObject extends CommonObject
|
||||
{
|
||||
/**
|
||||
* @var string ID of module.
|
||||
* @var string ID of module.
|
||||
*/
|
||||
public $module = 'mymodule';
|
||||
|
||||
/**
|
||||
* @var string ID to identify managed object.
|
||||
* @var string ID to identify managed object.
|
||||
*/
|
||||
public $element = 'myobject';
|
||||
|
||||
/**
|
||||
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management (so extrafields know the link to the parent table).
|
||||
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management (so extrafields know the link to the parent table).
|
||||
*/
|
||||
public $table_element = 'mymodule_myobject';
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ class MyObject extends CommonObject
|
|||
//public $element_for_permission = 'mymodule';
|
||||
|
||||
/**
|
||||
* @var string String with name of icon for myobject. Must be a 'fa-xxx' fontawesome code (or 'fa-xxx_fa_color_size') or 'myobject@mymodule' if picto is file 'img/object_myobject.png'.
|
||||
* @var string String with name of icon for myobject. Must be a 'fa-xxx' fontawesome code (or 'fa-xxx_fa_color_size') or 'myobject@mymodule' if picto is file 'img/object_myobject.png'.
|
||||
*/
|
||||
public $picto = 'fa-file';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user