2020-10-02 11:59:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
namespace D3\Usermanager\Modules\Application\Model;
|
|
|
|
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
2020-12-21 10:44:49 +01:00
|
|
|
use D3\ModCfg\Application\Model\Log\d3LogInterface;
|
|
|
|
use D3\Usermanager\Application\Model\d3usermanager as Manager;
|
2021-03-15 15:17:45 +01:00
|
|
|
use D3\Usermanager\Application\Model\d3usermanager_renderererrorhandler;
|
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_smartyException;
|
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_templaterendererExceptionInterface;
|
2020-10-02 11:59:22 +02:00
|
|
|
use Doctrine\DBAL\DBALException;
|
|
|
|
use Exception;
|
2020-12-21 10:44:49 +01:00
|
|
|
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
|
|
|
|
use D3\ModCfg\Application\Model\d3str;
|
|
|
|
use Html2Text\Html2Text;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Content as Content;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Remark;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Shop as Shop;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\User as Item;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Config;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseException;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Core\Language;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Path\ModulePathResolver;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Path\ModulePathResolverInterface;
|
2021-03-15 15:17:45 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Smarty\Legacy\LegacySmartyEngine;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateEngineInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
class d3_oxemail_usermanager extends d3_oxemail_usermanager_parent
|
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
private $_sModId = 'd3usermanager';
|
2020-10-02 11:59:22 +02:00
|
|
|
protected $_sUserManagerInfoTemplate = 'd3usermanager_info_html.tpl';
|
|
|
|
protected $_sUserManagerInfoPlainTemplate = 'd3usermanager_info_plain.tpl';
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var Manager */
|
2020-10-02 11:59:22 +02:00
|
|
|
public $oUserManager;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* d3_oxemail_usermanager constructor.
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->setParameter('d3.usermanager.modcfgid', $this->_sModId);
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @return TemplateEngineInterface
|
|
|
|
*/
|
2021-05-07 11:22:58 +02:00
|
|
|
protected function _d3GetUserManagerTemplateEngine(): TemplateEngineInterface
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
/** @var TemplateRendererInterface $renderer */
|
|
|
|
$renderer = $this->d3getUserManagerDIContainer()
|
|
|
|
->get(TemplateRendererBridgeInterface::class)
|
|
|
|
->getTemplateRenderer();
|
|
|
|
return $renderer->getTemplateEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aManagerNotes
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return bool
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3sendUserManagerEmail($aManagerNotes): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
startProfile(__METHOD__);
|
|
|
|
|
|
|
|
$oShop = $this->_getShop();
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
/** @var Config $config */
|
|
|
|
$config = d3GetModCfgDIC()->get('d3ox.usermanager.'.Config::class);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$this->_setMailParams($oShop);
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->setViewData("aNotes", $aManagerNotes);
|
|
|
|
$this->setViewData("shopTemplateDir", $config->getTemplateDir(false));
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->setViewData("oShop", $oShop);
|
|
|
|
|
|
|
|
$this->_processViewArray();
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
/** @var LegacySmartyEngine $templateEngine */
|
2021-05-07 11:22:58 +02:00
|
|
|
$templateEngine = $this->_d3GetUserManagerTemplateEngine();
|
2021-03-15 15:17:45 +01:00
|
|
|
foreach ($this->getViewData() as $key => $value) {
|
|
|
|
$templateEngine->addGlobal($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_error_handler(
|
|
|
|
[d3GetModCfgDIC()->get(d3usermanager_renderererrorhandler::class), 'd3HandleTemplateEngineErrors']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->d3UMsetBody($templateEngine->render($this->_sUserManagerInfoTemplate));
|
|
|
|
$this->d3UMsetAltBody($templateEngine->render($this->_sUserManagerInfoPlainTemplate));
|
|
|
|
|
|
|
|
restore_error_handler();
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var d3LogInterface $oLog */
|
|
|
|
$oLog = d3GetModCfgDIC()->get('d3.usermanager.log');
|
|
|
|
$oLog->notice(
|
2020-10-02 11:59:22 +02:00
|
|
|
__CLASS__,
|
|
|
|
__FUNCTION__,
|
|
|
|
__LINE__,
|
|
|
|
'send job execution info mail',
|
|
|
|
$this->getBody()
|
|
|
|
);
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var Language $oLang */
|
|
|
|
$oLang = d3GetModCfgDIC()->get('d3ox.usermanager.'.Language::class);
|
|
|
|
$sSubject = $oLang->translateString('D3_USERMANAGER_MAIL_ORDERSUBJECT', 0);
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->setSubject($sSubject);
|
|
|
|
|
|
|
|
$sFullName = $oShop->__get('oxshops__oxname')->getRawValue();
|
|
|
|
$this->setRecipient($oShop->getFieldData('oxinfoemail'), $sFullName);
|
|
|
|
$this->setReplyTo($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
|
|
|
|
|
|
|
|
$blSuccess = $this->send();
|
|
|
|
|
|
|
|
stopProfile(__METHOD__);
|
|
|
|
|
|
|
|
return $blSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sOxId
|
2020-12-21 10:44:49 +01:00
|
|
|
* @return Item
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerUser($sOxId): Item
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
if (strstr($sOxId, '@@')) {
|
|
|
|
$aOxId = explode('@@', $sOxId);
|
|
|
|
$sOxId = $aOxId[0];
|
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var $oItem Item */
|
|
|
|
$oItem = d3GetModCfgDIC()->get('d3ox.usermanager.'.Item::class);
|
|
|
|
|
|
|
|
$oItem->load($sOxId);
|
|
|
|
return $oItem;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sOxId
|
2020-12-21 10:44:49 +01:00
|
|
|
* @return Manager
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3getUserManager($sOxId): Manager
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var $oManager Manager */
|
|
|
|
$oManager = d3GetModCfgDIC()->get(Manager::class);
|
|
|
|
$oManager->load($sOxId);
|
|
|
|
return $oManager;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return bool
|
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws DatabaseException
|
2020-10-02 11:59:22 +02:00
|
|
|
* @throws StandardException
|
|
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
|
|
* @throws d3_cfg_mod_exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function sendUserManagerMail(Manager $oManager): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->oUserManager = $oManager;
|
|
|
|
$aContent = $this->getUserManagerMailContent($oManager);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$oShop = $this->_getShop();
|
2021-03-15 15:17:45 +01:00
|
|
|
$this->d3UMsetBody($aContent['html']);
|
|
|
|
$this->d3UMsetAltBody($aContent['plain']);
|
|
|
|
$this->d3UMsetSubject($aContent['subject']);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->_d3SetUserManagerReplyAddress($oManager, $oShop);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$oRemark = $this->_d3SetUserManagerMailRecipients($oShop);
|
|
|
|
|
|
|
|
$blSuccess = $this->send();
|
|
|
|
|
|
|
|
if ($blSuccess && $oRemark) {
|
|
|
|
$oRemark->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $blSuccess;
|
|
|
|
}
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
/**
|
|
|
|
* @param $content
|
|
|
|
*
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
|
|
|
protected function d3UMsetBody($content)
|
|
|
|
{
|
|
|
|
$this->setBody($content);
|
|
|
|
|
|
|
|
if ((bool) strlen($content) && false === (bool) strlen($this->getBody())) {
|
2021-05-07 11:22:58 +02:00
|
|
|
$this->d3UserManagerThrowUnequalContentException();
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $content
|
|
|
|
*
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
|
|
|
protected function d3UMsetAltBody($content)
|
|
|
|
{
|
|
|
|
$this->setAltBody($content);
|
|
|
|
|
|
|
|
if ((bool) strlen($content) && false === (bool) strlen($this->getAltBody())) {
|
2021-05-07 11:22:58 +02:00
|
|
|
$this->d3UserManagerThrowUnequalContentException();
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $content
|
|
|
|
*
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
|
|
|
protected function d3UMsetSubject($content)
|
|
|
|
{
|
|
|
|
$this->setSubject($content);
|
|
|
|
|
|
|
|
if ((bool) strlen($content) && false === (bool) strlen($this->getSubject())) {
|
2021-05-07 11:22:58 +02:00
|
|
|
$this->d3UserManagerThrowUnequalContentException();
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
/**
|
|
|
|
* @param Shop $oShop
|
|
|
|
*
|
|
|
|
* @return null|Remark
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3SetUserManagerMailRecipients(Shop $oShop): ?Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$oRemark = null;
|
|
|
|
if ($this->_d3hasUserManagerCustomerRecipient()) {
|
|
|
|
$oRemark = $this->_d3sendUserManagerMailToCustomer($oShop);
|
|
|
|
} elseif ($this->_d3hasUserManagerOwnerRecipient()) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$oRemark = $this->_d3sendUserManagerMailToOwner($oShop);
|
2020-10-02 11:59:22 +02:00
|
|
|
} elseif ($this->_d3hasUserManagerCustomRecipient()) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$oRemark = $this->_d3sendUserManagerMailToCustom();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $oRemark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sVarName
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3getUserManagerMailOption($sVarName)
|
|
|
|
{
|
|
|
|
$aEditedValues = $this->oUserManager->getEditedValues();
|
2021-03-15 15:17:45 +01:00
|
|
|
return false === isset($aEditedValues[$sVarName]) || $aEditedValues[$sVarName] === false || $aEditedValues[$sVarName] === null ?
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->oUserManager->getValue($sVarName) :
|
|
|
|
$aEditedValues[$sVarName];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3hasUserManagerCustomerRecipient()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('blSendMailToCustomer');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3hasUserManagerOwnerRecipient()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('blSendMailToOwner');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3hasUserManagerCustomRecipient()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('blSendMailToCustom');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3getUserManagerCustomRecipientList()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('sSendMailToCustomAddress');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3_cfg_mod
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function d3GetUserManagerSet()
|
|
|
|
{
|
|
|
|
/** @var d3_cfg_mod $modcfg */
|
|
|
|
$modcfg = d3GetModCfgDIC()->get('d3.usermanager.modcfg');
|
|
|
|
return $modcfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Language
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerLanguageObject(): Language
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var Language $language */
|
|
|
|
$language = d3GetModCfgDIC()->get('d3ox.usermanager.'.Language::class);
|
|
|
|
return $language;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* required for unit tests, can't mock getConfig method
|
|
|
|
* @return Config
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerConfigObject(): Config
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
/** @var Config $config */
|
|
|
|
$config = d3GetModCfgDIC()->get('d3ox.usermanager.'.Config::class);
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
|
|
|
*
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return array
|
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
* @throws StandardException
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
|
|
* @throws d3_cfg_mod_exception
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws Exception
|
2021-03-15 15:17:45 +01:00
|
|
|
* @throws d3usermanager_templaterendererExceptionInterface
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function getUserManagerMailContent(Manager $oManager): array
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->oUserManager = $oManager;
|
2021-03-15 15:17:45 +01:00
|
|
|
$aContent = [];
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
$blTplFromAdmin = $oManager->getValue('sSendMailFromTheme') == 'admin';
|
|
|
|
|
|
|
|
$oConfig = $this->d3GetUserManagerConfigObject();
|
|
|
|
$oConfig->setAdminMode($blTplFromAdmin);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$oShop = $this->_getShop();
|
|
|
|
$this->_setMailParams($oShop);
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var TemplateRendererInterface $renderer */
|
|
|
|
$renderer = $this->d3getUserManagerDIContainer()
|
|
|
|
->get(TemplateRendererBridgeInterface::class)
|
|
|
|
->getTemplateRenderer();
|
|
|
|
$templateEngine = $renderer->getTemplateEngine();
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$this->setViewData("oShop", $oShop);
|
|
|
|
$this->setViewData("oViewConf", $this->getViewConfig());
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->setViewData("oUser", $oManager->getCurrentItem());
|
|
|
|
$this->setViewData("shopTemplateDir", $this->d3GetUserManagerConfigObject()->getTemplateDir(false));
|
|
|
|
$this->setViewData("charset", $this->d3GetUserManagerLanguageObject()->translateString("charset"));
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$this->setViewData("shop", $oShop);
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->setViewData("user", $oManager->getCurrentItem());
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
// ToDo: check in TWIG and change to a generic solution (e.g. path names in template name)
|
|
|
|
// Smarty only
|
|
|
|
if (method_exists($templateEngine, '__set')) {
|
|
|
|
$templateEngine->__set( 'template_dir', $this->getTemplateDir4UserManager( $oManager ) );
|
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->_processViewArray();
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
foreach ($this->getViewData() as $id => $value) {
|
|
|
|
$templateEngine->addGlobal($id, $value);
|
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
if (false == $this->d3GetUserManagerSet()->getLicenseConfigData('blUseMailSendOnly', 0)) {
|
|
|
|
$templateEngine = $this->d3SendMailHook($templateEngine);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
$aContent = $this->_d3GenerateUserManagerMailContent($aContent, $templateEngine);
|
|
|
|
$oConfig->setAdminMode(true);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
return $aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3str
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function getD3UserManagerStrObject(): d3str
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var d3str $d3str */
|
|
|
|
$d3str = d3GetModCfgDIC()->get(d3str::class);
|
|
|
|
return $d3str;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
|
|
|
*
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function getTemplateDir4UserManager($oManager): string
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
if ($oManager->getValue('sSendMailFromTheme') == 'module') {
|
|
|
|
$sModuleId = $oManager->getValue('sSendMailFromModulePath');
|
|
|
|
/** @var ModulePathResolver $pathResolver */
|
|
|
|
$pathResolver = $this->d3getUserManagerDIContainer()->get(ModulePathResolverInterface::class);
|
|
|
|
$sModulePath = $pathResolver->getFullModulePathFromConfiguration(
|
|
|
|
$sModuleId,
|
|
|
|
Registry::getConfig()->getShopId()
|
2020-10-02 11:59:22 +02:00
|
|
|
);
|
2020-12-21 10:44:49 +01:00
|
|
|
$sPath = $this->getD3UserManagerStrObject()->untrailingslashit($sModulePath);
|
2020-10-02 11:59:22 +02:00
|
|
|
} else {
|
2020-12-21 10:44:49 +01:00
|
|
|
$blAdmin = $oManager->getValue('sSendMailFromTheme') == 'admin';
|
|
|
|
$sPath = $this->d3GetUserManagerConfigObject()->getTemplateDir($blAdmin);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
return $sPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param TemplateEngineInterface $templateEngine
|
|
|
|
* @return TemplateEngineInterface
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3SendMailHook(TemplateEngineInterface $templateEngine): TemplateEngineInterface
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
// available objects:
|
|
|
|
// oxEmail: $this
|
2020-12-21 10:44:49 +01:00
|
|
|
// Template Engine: $templateEngine
|
2020-10-02 11:59:22 +02:00
|
|
|
// Usermanager profile: $this->oUserManager
|
2020-12-21 10:44:49 +01:00
|
|
|
// oxuser: inside template engine
|
|
|
|
|
|
|
|
return $templateEngine;
|
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore because visual CMS extension issue
|
|
|
|
* @return UtilsView
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerUtilsView(): UtilsView
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
/** @var UtilsView $utilsView */
|
|
|
|
$utilsView = d3GetModCfgDIC()->get('d3ox.usermanager.'.UtilsView::class);
|
|
|
|
return $utilsView;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Content
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerContentObject(): Content
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
/** @var Content $content */
|
|
|
|
$content = d3GetModCfgDIC()->get('d3ox.usermanager.'.Content::class);
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-15 15:17:45 +01:00
|
|
|
* @param array $aContent
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param TemplateEngineInterface $templateEngine
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return mixed
|
2021-03-15 15:17:45 +01:00
|
|
|
*
|
2020-10-02 11:59:22 +02:00
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws Exception
|
2021-03-15 15:17:45 +01:00
|
|
|
* @throws d3usermanager_templaterendererExceptionInterface
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3GenerateUserManagerMailContent(array $aContent, TemplateEngineInterface $templateEngine)
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$aEditedValues = $this->oUserManager->getEditedValues();
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
$oLang = $this->d3GetUserManagerLanguageObject();
|
2020-10-02 11:59:22 +02:00
|
|
|
$iUserLangId = $oLang->getTplLanguage();
|
2020-12-21 10:44:49 +01:00
|
|
|
$iCurrentTplLang = $oLang->getTplLanguage();
|
2020-10-02 11:59:22 +02:00
|
|
|
$iCurrentBaseLang = $oLang->getBaseLanguage();
|
2020-12-21 10:44:49 +01:00
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
$oLang->setTplLanguage($iUserLangId);
|
|
|
|
$oLang->setBaseLanguage($iUserLangId);
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
set_error_handler(
|
|
|
|
[d3GetModCfgDIC()->get(d3usermanager_renderererrorhandler::class), 'd3HandleTemplateEngineErrors']
|
|
|
|
);
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
if ($this->d3HasUserManagerEditorMailContent($aEditedValues)) {
|
|
|
|
$aContent = $aEditedValues['mail'];
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
if ($aContent['genplain']) {
|
|
|
|
$aContent['plain'] = $this->d3generateUserManagerPlainContent($aContent['html']);
|
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
} elseif ($this->oUserManager->getValue('sSendMailFromSource') == 'cms') {
|
2020-12-21 10:44:49 +01:00
|
|
|
$oUtilsView = $this->d3GetUserManagerUtilsView();
|
|
|
|
$oContent = $this->d3GetUserManagerContentObject();
|
|
|
|
$oContent->loadInLang($iUserLangId, $this->oUserManager->getValue('sSendMailFromContentname'));
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
$aContent['html'] = $oUtilsView->getRenderedContent(
|
2020-10-02 11:59:22 +02:00
|
|
|
$oContent->getFieldData('oxcontent'),
|
2021-03-15 15:17:45 +01:00
|
|
|
$this->getViewData(),
|
2020-10-02 11:59:22 +02:00
|
|
|
$oContent->getId() . 'oxcontent'
|
|
|
|
);
|
|
|
|
|
|
|
|
$aContent['subject'] = $oContent->getFieldData('oxtitle');
|
2020-12-21 10:44:49 +01:00
|
|
|
$oContent->loadInLang($iUserLangId, $this->oUserManager->getValue('sSendMailFromContentnamePlain'));
|
|
|
|
$aContent['plain'] = $oUtilsView->getRenderedContent(
|
2020-10-02 11:59:22 +02:00
|
|
|
$oContent->getFieldData('oxcontent'),
|
2021-03-15 15:17:45 +01:00
|
|
|
$this->getViewData(),
|
2020-10-02 11:59:22 +02:00
|
|
|
$oContent->getId() . 'oxcontent'
|
|
|
|
);
|
|
|
|
} elseif ($this->oUserManager->getValue('sSendMailFromSource') == 'template') {
|
2020-12-21 10:44:49 +01:00
|
|
|
$aContent['html'] = $templateEngine->render($this->oUserManager->getValue('sSendMailFromTemplatename'));
|
|
|
|
$aContent['plain'] = $templateEngine->render($this->oUserManager->getValue('sSendMailFromTemplatenamePlain'));
|
|
|
|
$aContent['subject'] = $templateEngine->render($this->oUserManager->getValue('sSendMailFromSubject'));
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
restore_error_handler();
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
$oLang->setTplLanguage($iCurrentTplLang);
|
2020-10-02 11:59:22 +02:00
|
|
|
$oLang->setBaseLanguage($iCurrentBaseLang);
|
|
|
|
|
|
|
|
return $aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aEditedValues
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3HasUserManagerEditorMailContent($aEditedValues): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
return $this->d3isUserManagerArrayEditorMailContent($aEditedValues) &&
|
2020-10-02 11:59:22 +02:00
|
|
|
$aEditedValues['mail']['subject'] &&
|
|
|
|
$aEditedValues['mail']['html'] &&
|
2020-12-21 10:44:49 +01:00
|
|
|
(
|
|
|
|
$aEditedValues['mail']['genplain'] ||
|
|
|
|
$aEditedValues['mail']['plain']
|
|
|
|
);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aEditedValues
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3isUserManagerArrayEditorMailContent($aEditedValues): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2021-03-15 15:17:45 +01:00
|
|
|
return is_array($aEditedValues) && isset($aEditedValues['mail']) && is_array($aEditedValues['mail']);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/**
|
|
|
|
* @param $html
|
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3generateUserManagerPlainContent($html): string
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->setParameter(Html2Text::class.'.args.html', $html);
|
|
|
|
|
|
|
|
/** @var Html2Text $html */
|
|
|
|
$html = d3GetModCfgDIC()->get(Html2Text::class);
|
|
|
|
return $html->getText();
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
/**
|
|
|
|
* @return Remark
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerRemark(): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
/** @var Remark $remark */
|
|
|
|
$remark = d3GetModCfgDIC()->get('d3ox.usermanager.'.Remark::class);
|
|
|
|
return $remark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Shop $oShop
|
|
|
|
*
|
|
|
|
* @return Remark
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3sendUserManagerMailToCustomer(Shop $oShop): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$sFullName = $this->oUserManager->getCurrentItem()->__get('oxuser__oxfname')->getRawValue() . " " .
|
|
|
|
$this->oUserManager->getCurrentItem()->__get('oxuser__oxlname')->getRawValue();
|
|
|
|
$this->setRecipient($this->oUserManager->getCurrentItem()->getFieldData('oxusername'), $sFullName);
|
|
|
|
|
|
|
|
if ($this->_d3hasUserManagerOwnerRecipient()) {
|
|
|
|
$this->addBCC($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->_d3HasUserManagerCustomMailAddresses()) {
|
|
|
|
foreach ($this->_d3getUserManagerCustomMailAddressList() as $sMailAdr) {
|
|
|
|
$this->addBCC(trim($sMailAdr), trim($sMailAdr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
return $this->d3generateUserManagerRemark();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Shop $oShop
|
2020-12-21 10:44:49 +01:00
|
|
|
*
|
|
|
|
* @return Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
* @throws d3ParameterNotFoundException
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3sendUserManagerMailToOwner(Shop $oShop): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$sFullName = $oShop->__get('oxshops__oxname')->getRawValue();
|
|
|
|
$this->setRecipient($oShop->getFieldData('oxinfoemail'), $sFullName);
|
|
|
|
|
|
|
|
if ($this->_d3HasUserManagerCustomMailAddresses()) {
|
|
|
|
foreach ($this->_d3getUserManagerCustomMailAddressList() as $sMailAdr) {
|
|
|
|
$this->addBCC(trim($sMailAdr), trim($sMailAdr));
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
return $this->d3generateUserManagerRemark();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3sendUserManagerMailToCustom(): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
if ($this->_d3HasUserManagerCustomMailAddresses()) {
|
|
|
|
foreach ($this->_d3getUserManagerCustomMailAddressList() as $sMailAdr) {
|
|
|
|
$this->setRecipient(trim($sMailAdr), trim($sMailAdr));
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
return $this->d3generateUserManagerRemark();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3getUserManagerCustomMailAddressList(): array
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$aMailAddressList = array();
|
|
|
|
|
|
|
|
foreach (explode(';', $this->_d3getUserManagerCustomRecipientList()) as $sAddress) {
|
|
|
|
if (strlen(trim($sAddress))) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$aMailAddressList[] = trim($sAddress);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $aMailAddressList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function _d3HasUserManagerCustomMailAddresses(): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
return $this->_d3hasUserManagerCustomRecipient() && $this->_d3getUserManagerCustomRecipientList();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
2020-10-02 11:59:22 +02:00
|
|
|
* @param Shop $oShop
|
|
|
|
*/
|
2020-12-21 10:44:49 +01:00
|
|
|
protected function _d3SetUserManagerReplyAddress(Manager $oManager, Shop $oShop)
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2021-03-15 15:17:45 +01:00
|
|
|
if (strlen(trim((string) $oManager->getValue('sSendMailReplyAddress')))) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->setFrom(trim($oManager->getValue('sSendMailReplyAddress')));
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->setReplyTo(
|
2021-03-15 15:17:45 +01:00
|
|
|
trim((string) $oManager->getValue('sSendMailReplyAddress')),
|
2020-10-02 11:59:22 +02:00
|
|
|
$oShop->__get('oxshops__oxname')->getRawValue()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->setReplyTo($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* add user history
|
|
|
|
* @return Remark
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3generateUserManagerRemark(): Remark
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
$oRemark = $this->d3GetUserManagerRemark();
|
|
|
|
$aRemarkContent = array(
|
|
|
|
'oxtext' => $this->d3GetUserManagerRemarkText(),
|
|
|
|
'oxparentid' => $this->oUserManager->getCurrentItem()->getId(),
|
|
|
|
'oxtype' => 'd3um',
|
|
|
|
);
|
|
|
|
$oRemark->assign( $aRemarkContent );
|
|
|
|
|
|
|
|
return $oRemark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerRemarkText(): string
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
return implode(
|
|
|
|
PHP_EOL.'---'.PHP_EOL,
|
|
|
|
[
|
|
|
|
'Recipients:',
|
|
|
|
implode(', ', array_keys($this->getAllRecipientAddresses())),
|
|
|
|
'HTML:',
|
|
|
|
$this->getBody(),
|
|
|
|
'Plain',
|
|
|
|
$this->getAltBody()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ContainerInterface
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3getUserManagerDIContainer(): ContainerInterface
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
return ContainerFactory::getInstance()->getContainer();
|
|
|
|
}
|
2021-03-15 15:17:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
2021-05-07 11:22:58 +02:00
|
|
|
protected function d3UserManagerThrowUnequalContentException() : void
|
2021-03-15 15:17:45 +01:00
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->setParameter(
|
|
|
|
d3usermanager_smartyException::class . '.args.message',
|
|
|
|
'empty mail content, possible file encoding error'
|
|
|
|
);
|
|
|
|
/** @var d3usermanager_smartyException $e */
|
|
|
|
$e = d3GetModCfgDIC()->get( d3usermanager_smartyException::class );
|
|
|
|
throw $e;
|
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|