2
0
forked from Wavyzz/dolibarr

Add info for opt out email

This commit is contained in:
Laurent Destailleur
2023-04-09 13:00:34 +02:00
parent 516232a190
commit 8f3bd5ab07
8 changed files with 61 additions and 40 deletions

View File

@@ -1005,13 +1005,6 @@ if ($action == 'create') {
}
print '</td></tr>';
// Even if unsubscribe
print '<tr><td class="titlefield">';
print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td><td>';
print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td></tr>';
// Other attributes. Fields from hook formObjectOptions and Extrafields.
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
@@ -1282,13 +1275,6 @@ if ($action == 'create') {
}
print '</td></tr>';
// Even if unsubscribe
print '<tr><td class="titlefield">';
print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td><td>';
print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td></tr>';
// Other attributes
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

View File

@@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
// Load translation files required by the page
$langs->load("mails");
@@ -345,7 +346,7 @@ if ($object->fetch($id) >= 0) {
}
}
if (empty($nbemail)) {
$nbemail .= ' '.img_warning('');//.' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
$nbemail .= ' '.img_warning($langs->trans('ToAddRecipientsChooseHere'));//.' <span class="warning">'.$langs->trans("NoTargetYet").'</span>';
}
if ($text) {
print $form->textwithpicto($nbemail, $text, 1, 'warning');
@@ -355,13 +356,6 @@ if ($object->fetch($id) >= 0) {
}
print '</td></tr>';
// Even if unsubscribe
print '<tr><td class="titlefield">';
print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td><td>';
print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td></tr>';
// Other attributes. Fields from hook formObjectOptions and Extrafields.
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
@@ -376,7 +370,7 @@ if ($object->fetch($id) >= 0) {
print '<br>';
$allowaddtarget = ($object->statut == 0);
$allowaddtarget = ($object->statut == $object::STATUS_DRAFT);
// Show email selectors
if ($allowaddtarget && $user->rights->mailing->creer) {
@@ -389,7 +383,11 @@ if ($object->fetch($id) >= 0) {
print '<div class="tagtd"></div>';
print '<div class="tagtd">'.$langs->trans("RecipientSelectionModules").'</div>';
print '<div class="tagtd" align="center">'.$langs->trans("NbOfUniqueEMails").'</div>';
print '<div class="tagtd left">'.$langs->trans("Filter").'</div>';
print '<div class="tagtd left">'.$langs->trans("Filters");
print ' &nbsp; &nbsp; <div class="floatright">'.$langs->trans("EvenUnsubscribe").' ';
print ajax_object_onoff($object, 'evenunsubscribe', 'evenunsubscribe', 'EvenUnsubscribe:switch_on:warning', 'EvenUnsubscribe', array(), 'small valignmiddle', '', 1);
print '</div>';
print '</div>';
print '<div class="tagtd">&nbsp;</div>';
print '</div>'; // End tr

View File

@@ -357,9 +357,10 @@ class Mailing extends CommonObject
* Get object from database
*
* @param int $rowid Id of emailing
* @param string $ref Title to search from title
* @return int <0 if KO, >0 if OK
*/
public function fetch($rowid)
public function fetch($rowid, $ref = '')
{
global $conf;
@@ -372,7 +373,12 @@ class Mailing extends CommonObject
$sql .= ", m.date_envoi";
$sql .= ", m.extraparams";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
$sql .= " WHERE m.rowid = ".(int) $rowid;
$sql .= " WHERE entity IN (".getEntity('mailing').")";
if ($ref) {
$sql .= " AND m.titre = '".$this->db->escape($ref)."'";
} else {
$sql .= " AND m.rowid = ".(int) $rowid;
}
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);

View File

@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2015-2022 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2015-2023 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
/**
* \file htdocs/core/ajax/objectonoff.php
* \brief File to set status for an object
* \brief File to set status for an object. Called when ajax_object_onoff() is used.
* This Ajax service is oftenly called when option MAIN_DIRECT_STATUS_UPDATE is set.
*/
@@ -45,6 +45,7 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
$action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage');
$id = GETPOST('id', 'int');
$element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule)
@@ -79,7 +80,7 @@ if (!empty($user->socid)) {
// We check permission.
// Check is done on $user->rights->element->create or $user->rights->element->subelement->create (because $action = 'set')
if (preg_match('/status$/', $field)) {
if (preg_match('/status$/', $field) || ($field == 'evenunsubscribe' && $object->table_element == 'mailing')) {
restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission);
} elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products
restrictedArea($user, 'produit|service', $object, 'product&product', '', '', 'rowid');
@@ -114,4 +115,9 @@ if (($action == 'set') && !empty($id)) {
http_response_code(500);
exit;
}
if ($backtopage) {
header('Location: '.$backtopage);
exit;
}
}

View File

@@ -690,29 +690,33 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof
}
/**
* On/off button to change status of an object
* This is called when MAIN_DIRECT_STATUS_UPDATE is set and it use tha ajax service objectonoff.php
* On/off button to change a property status of an object
* This uses the ajax service objectonoff.php (May be called when MAIN_DIRECT_STATUS_UPDATE is set for some pages)
*
* @param Object $object Object to set
* @param string $code Name of property in object : 'status' or 'status_buy' for product by example
* @param string $field Name of database field : 'tosell' or 'tobuy' for product by example
* @param string $text_on Text if on ('Text' or 'Text:css picto on')
* @param string $text_off Text if off ('Text' or 'Text:css picto on')
* @param string $text_on Text if on ('Text' or 'Text:Picto on:Css picto on')
* @param string $text_off Text if off ('Text' or 'Text:Picto off:Css picto off')
* @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
* @param string $morecss More CSS
* @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on same page for same property.
* @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on the same page for the same field.
* @param int $forcenojs Force the component to work as link post (without javascript) instead of ajax call
* @return string html for button on/off
*/
function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '')
function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '', $forcenojs = 0)
{
global $langs;
global $conf, $langs;
if (empty($htmlname)) {
$htmlname = $code;
}
//var_dump($object->module); var_dump($object->element);
$out = '<script>
$out = '';
if (!empty($conf->use_javascript_ajax)) {
$out .= '<script>
$(function() {
var input = '.json_encode($input).';
@@ -781,22 +785,36 @@ function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input =
});
});
</script>';
}
$switchon = 'switch_on';
$switchoff = 'switch_off';
$cssswitchon = '';
$cssswitchoff = '';
$tmparray = explode(':', $text_on);
if (!empty($tmparray[1])) {
$text_on = $tmparray[0];
$switchon = $tmparray[1];
if (!empty($tmparray[2])) {
$cssswitchon = $tmparray[2];
}
}
$tmparray = explode(':', $text_off);
if (!empty($tmparray[1])) {
$text_off = $tmparray[0];
$switchoff = $tmparray[1];
if (!empty($tmparray[2])) {
$cssswitchoff = $tmparray[2];
}
}
$out .= '<span id="set_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'">'.img_picto($langs->trans($text_off), $switchoff).'</span>';
$out .= '<span id="del_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'">'.img_picto($langs->trans($text_on), $switchon).'</span>';
if (empty($conf->use_javascript_ajax) || $forcenojs) {
$out .= '<a id="set_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'" href="'.DOL_URL_ROOT.'/core/ajax/objectonoff.php?action=set&token='.newToken().'&id='.((int) $object->id).'&element='.urlencode($object->element).'&field='.urlencode($field).'&value=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).'</a>';
$out .= '<a id="del_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'" href="'.DOL_URL_ROOT.'/core/ajax/objectonoff.php?action=set&token='.newToken().'&id='.((int) $object->id).'&element='.urlencode($object->element).'&field='.urlencode($field).'&value=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).'</a>';
} else {
$out .= '<span id="set_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'">'.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).'</span>';
$out .= '<span id="del_'.$htmlname.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'">'.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).'</span>';
}
return $out;
}

View File

@@ -11328,6 +11328,12 @@ function getElementProperties($element_type)
$classpath = 'contrat/class';
$module = 'contrat';
$subelement = 'contrat';
} elseif ($element_type == 'mailing') {
$classpath = 'comm/mailing/class';
$module = 'mailing';
$classfile = 'mailing';
$classname = 'Mailing';
$subelement = '';
} elseif ($element_type == 'member') {
$classpath = 'adherents/class';
$module = 'adherent';
@@ -11424,7 +11430,6 @@ function fetchObjectByElement($element_id, $element_type, $element_ref = '')
$ret = 0;
$element_prop = getElementProperties($element_type);
//var_dump($element_prop);
if (is_array($element_prop) && isModEnabled($element_prop['module'])) {
dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');

View File

@@ -388,5 +388,6 @@ ALTER TABLE llx_bordereau_cheque ADD COLUMN label varchar(255) AFTER ref;
ALTER TABLE llx_c_email_templates add COLUMN defaultfortype smallint DEFAULT 0;
ALTER TABLE llx_mailing ADD COLUMN fk_user_modif integer AFTER fk_user_creat;
ALTER TABLE llx_mailing ADD COLUMN evenunsubscribe smallint DEFAULT 0;

View File

@@ -46,6 +46,7 @@ create table llx_mailing
date_envoi datetime, -- date d'envoi
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_user_creat integer, -- user creator
fk_user_modif integer, -- user of last modification
fk_user_valid integer, -- user validator
fk_user_appro integer, -- not used
extraparams varchar(255), -- for stock other parameters with json format