@param array $aMailData
@param array $aOpts
@param array $aRecs
@param array $aAttachments

@return Mail\Message
768320
public function createMessage(array $aMailData, array $aOpts, array $aRecs, array $aAttachments = [])
    {
        $oMessage = new Mail\Message();
        $oMessage->setEncoding('UTF-8');

        $this
            ->setFrom($oMessage, $aOpts)
            ->setTo($oMessage, $aRecs)
            ->addBcc($oMessage)
            ->setSubject($oMessage, $aMailData['subject'])
            ->setBody($oMessage, $aAttachments, $aMailData['html'], $aMailData['plain']);

        return $oMessage;
    }
169946
protected function LoadFromBasketPostProcessData($oBasket, &$aOrderData)
    {
        parent::LoadFromBasketPostProcessData($oBasket, $aOrderData);
        $oUser = TdbDataExtranetUser::GetInstance();
        $oShipping = $oUser->GetShippingAddress();
        $aOrderData['adr_shipping_is_dhl_packstation'] = $oShipping->fieldIsDhlPackstation;
    }
804116
public static function smrtr($haystack, $aMatch, $aDelimiter = array("{","}")) {
        $aCleaned = array();

        foreach ($aMatch as $key => $v) {
            $aCleaned[$aDelimiter[0].$key.$aDelimiter[1]] = $v;
        }

        return strtr($haystack, $aCleaned);
    }
423682
public function renderTemplate($sTpl, array $aVars, array $aOpts)
    {
        $aMailData = $this->getMailData($sTpl, $aVars);

        // Add Footer
        if (isset($aOpts['add_footer']) && $aOpts['add_footer']) {
            $templateNameData = explode('/', $sTpl);
            $sFooterTpl = sprintf('%s/email/_footer', $templateNameData[0]);

            $aFooterData = $this->getMailData($sFooterTpl, $aVars);

            $aMailData['html'] .= $aFooterData['html'];
            $aMailData['plain'] .= $aFooterData['plain'];
        }

        return $aMailData;
    }
957964
public function _updateUserData( array $aPostData )
    {
        if ( $oUser = $this->_updateUserProfileData( $aPostData ) ) {
            $this->_updateUserActiveShippingAddress( $oUser, $aPostData );
        }
    }
267759
protected function HandleNotifyMessageForPaymentState($sPaymentState, $aParameter, $oOrder)
    {
        if (!$oOrder->fieldOrderIsPaid) {
            if ('9' === $sPaymentState) {
                $oOrder->SetStatusPaid(true);
                $oOrder->SetStatusCanceled(false);
                $this->HandleNotifyOrderOnChange($oOrder, true, true, true);
                TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was activated and paid by notify (Status 9 paid)', 1, __FILE__, __LINE__);
            } elseif ('5' === $sPaymentState) {
                if ($oOrder->fieldCanceled || !$oOrder->fieldSystemOrderSaveCompleted) {
                    $oOrder->SetStatusCanceled(false);
                    $oOrder->SetStatusPaid(false);
                    TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was activated by notify and set to not paid (Status 5 reservation)', 1, __FILE__, __LINE__);
                    $this->HandleNotifyOrderOnChange($oOrder, false, !$oOrder->fieldSystemOrderSaveCompleted, true);
                }
            } else {
                if ('6' === $sPaymentState || '1' === $sPaymentState || '2' === $sPaymentState || '0' === $sPaymentState) {
                    $oOrder->SetStatusCanceled(true);
                    $oOrder->SetStatusPaid(false);
                    $this->HandleNotifyOrderOnChange($oOrder, false, false, true);
                    TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was canceled and set to not paid by notify (Status 0,1,2,6)', 1, __FILE__, __LINE__);
                }
            }
        } else {
            TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was already paid nothing to do)', 1, __FILE__, __LINE__);
        }
    }
1046236
public function getStatsChartData($aResponses)
    {
        //  Work out all the options and assign a value
        $aCharts = [];
        foreach ($aResponses as $oResponse) {
            if (!empty($oResponse->option)) {
                if (!array_key_exists($oResponse->option->label, $aCharts)) {
                    $aCharts[$oResponse->option->label] = [0, 0, 0, 0, 0];
                }
                $aCharts[$oResponse->option->label][$oResponse->data]++;
            }
        }

        $aOut = [];

        foreach ($aCharts as $sLabel => $aRows) {

            $aOut[] = [
                'title'   => $sLabel,
                'columns' => [
                    ['string', 'Label'],
                    ['number', 'Responses'],
                ],
                'rows'    => [
                    [$this->aLikertTerms[0], $aRows[0]],
                    [$this->aLikertTerms[1], $aRows[1]],
                    [$this->aLikertTerms[2], $aRows[2]],
                    [$this->aLikertTerms[3], $aRows[3]],
                    [$this->aLikertTerms[4], $aRows[4]],
                ],
            ];
        }

        return $aOut;
    }
72860
public function send(array $data = [])
    {
        $params = array_merge($this->message, $data);
        foreach ($params as $key => $value) {
            if (in_array($key, $this->required, true) && empty($value) && empty($this->message[$key])) {
                throw new InvalidArgumentException("Attribute '$key' can not be empty!");
            }
            $params[$key] = empty($value) ? $this->message[$key] : $value;
        }
        $params['data'] = $this->formatData($params['data']);
        $this->message = $this->messageBackup;
        return $this->json(static::API_SEND_NOTICE, $params);
    }
327640
protected function formatMessage(array $data = [])
    {
        $params = array_merge($this->message, $data);

        foreach ($params as $key => $value) {
            if (in_array($key, $this->required, true) && empty($value) && empty($this->message[$key])) {
                throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key));
            }

            $params[$key] = empty($value) ? $this->message[$key] : $value;
        }

        $params['data'] = $this->formatData($params['data'] ?? []);

        return $params;
    }
648514
protected function AddOrderNotificationEmailComplexData($aMailData)
    {
        $aMailData['sArtikel'] = $this->Render('mailArticleList', 'Customer');
        $aMailData['sArticle'] = $aMailData['sArtikel'];
        $aMailData['sArtikel-text'] = $this->Render('mailArticleList.txt', 'Customer');
        $aMailData['sArticle-text'] = $aMailData['sArtikel-text'];
        $aMailData['sArtikel_text'] = $aMailData['sArtikel-text'];
        $aMailData['sArticle_text'] = $aMailData['sArtikel-text'];

        $aMailData['sRechnungsadresse'] = $this->Render('mailBillingAddress', 'Customer');
        $aMailData['sBillingaddress'] = $aMailData['sRechnungsadresse'];
        $aMailData['sRechnungsadresse-text'] = $this->Render('mailBillingAddress.txt', 'Customer');
        $aMailData['sBillingaddress-text'] = $aMailData['sRechnungsadresse-text'];
        $aMailData['sRechnungsadresse_text'] = $aMailData['sRechnungsadresse-text'];
        $aMailData['sBillingaddress_text'] = $aMailData['sRechnungsadresse-text'];

        $aMailData['sLieferadresse'] = $this->Render('mailShippingAddress', 'Customer');
        $aMailData['sShippingaddress'] = $aMailData['sLieferadresse'];
        $aMailData['sLieferadresse-text'] = $this->Render('mailShippingAddress.txt', 'Customer');
        $aMailData['sShippingaddress-text'] = $aMailData['sLieferadresse-text'];
        $aMailData['sLieferadresse_text'] = $aMailData['sLieferadresse-text'];
        $aMailData['sShippingaddress_text'] = $aMailData['sLieferadresse-text'];

        $aMailData['sZahlungsInfos'] = $this->Render('mailPaymentInfo', 'Customer');
        $aMailData['sPaymentInfos'] = $aMailData['sZahlungsInfos'];
        $aMailData['sZahlungsInfos-text'] = $this->Render('mailPaymentInfo.txt', 'Customer');
        $aMailData['sPaymentInfos-text'] = $aMailData['sZahlungsInfos-text'];
        $aMailData['sZahlungsInfos_text'] = $aMailData['sZahlungsInfos-text'];
        $aMailData['sPaymentInfos_text'] = $aMailData['sZahlungsInfos-text'];

        return $aMailData;
    }
881071
public function execute($aGetVars, $aPostVars)
    {
        //  Ensure we have a driver
        if (empty($this->oDriver)) {
            throw new CompleteRequestException('No driver selected.', 1);
        }

        //  Ensure we have a payment
        if (empty($this->oPayment)) {
            throw new CompleteRequestException('No payment selected.', 1);
        }

        if (empty($this->oInvoice)) {
            throw new CompleteRequestException('No invoice selected.', 1);
        }

        //  Execute the completion
        $oCompleteResponse = $this->oDriver->complete(
            $this->oPayment,
            $this->oInvoice,
            $aGetVars,
            $aPostVars
        );

        //  Validate driver response
        if (empty($oCompleteResponse)) {
            throw new CompleteRequestException('Response from driver was empty.', 1);
        }

        if (!($oCompleteResponse instanceof CompleteResponse)) {
            throw new CompleteRequestException(
                'Response from driver must be an instance of \Nails\Invoice\Factory\CompleteResponse.',
                1
            );
        }

        //  Handle the response
        if ($oCompleteResponse->isProcessing()) {

            //  Driver has started processing the charge, but it hasn't been confirmed yet
            $this->setPaymentProcessing(
                $oCompleteResponse->getTxnId(),
                $oCompleteResponse->getFee()
            );

        } elseif ($oCompleteResponse->isComplete()) {

            //  Driver has confirmed that payment has been taken.
            $this->setPaymentComplete(
                $oCompleteResponse->getTxnId(),
                $oCompleteResponse->getFee()
            );

        } elseif ($oCompleteResponse->isFailed()) {

            /**
             * Payment failed
             */

            //  Update the payment
            $sPaymentClass = get_class($this->oPaymentModel);
            $bResult       = $this->oPaymentModel->update(
                $this->oPayment->id,
                [
                    'status'    => $sPaymentClass::STATUS_FAILED,
                    'fail_msg'  => $oCompleteResponse->getError()->msg,
                    'fail_code' => $oCompleteResponse->getError()->code,
                ]
            );

            if (empty($bResult)) {
                throw new CompleteRequestException('Failed to update existing payment.', 1);
            }
        }

        //  Lock the response so it cannot be altered
        $oCompleteResponse->lock();

        return $oCompleteResponse;
    }
1117491
public function getStatsChartData($aResponses)
    {
        $aOut = [
            'columns' => [
                ['string', 'Label'],
                ['number', 'Responses'],
            ],
            'rows'    => [],
        ];

        foreach ($aResponses as $oResponse) {

            if (!isset($aOut['rows'][$oResponse->text])) {
                $aOut['rows'][$oResponse->text] = [$oResponse->text, 0];
            }

            $aOut['rows'][$oResponse->text][1]++;
        }

        $aOut['rows'] = array_values($aOut['rows']);

        //  Return the details for a single chart (i.e only 1 item in this array)
        return [$aOut];
    }
421436
public function findEmailTemplate(array $templateData)
    {
        if (empty($templateData['EVENT_NAME'])) {
            throw new Exception('Empty email event type name');
        }

        $filter = ['TYPE_ID' => $templateData['EVENT_NAME']];
        if (!empty($templateData['LID'])) {
            $filter['SITE_ID'] = $templateData['LID'];
        }
        if (!empty($templateData['SUBJECT'])) {
            $filter['SUBJECT'] = $templateData['SUBJECT'];
        }

        $return = null;
        $rsMess = CEventMessage::GetList(
            ($by = 'site_id'),
            ($order = 'desc'),
            $filter
        );
        while ($template = $rsMess->fetch()) {
            if ($return) {
                throw new Exception("More than one template are found: {$templateData['EVENT_NAME']}");
            }
            $return = $template;
        }

        return $return;
    }
24471
public function processAttachments($emailMessageID, $data=null) {

        $attachmentPath      = $this->ImagesHelper->pathOfImagesUploadParentFolder() . "/".config('lasallecmsemail.attachment_path')."/";

        // INSERT into the "email_attachments" db table
        for ($i = 1; $i <= $data['number_of_attachments']; $i++) {
            $data = array_merge($data, $this->prepareAttachmentDataForInsert($emailMessageID, $i, $attachmentPath, $data));
            $this->email_attachmentRepository->insertNewRecord($data);

            $data['attachment-'.$i]->move($attachmentPath, $data['attachment-'.$i]->getClientOriginalName());
        }
    }
64151
function _doCapt($oID, $amt = 0, $currency = 'USD') {
    global $db, $messageStack;
    $_POST['captamt'] = preg_replace('/[^0-9.%]/', '', $_POST['captamt']);

    //@TODO: Read current order status and determine best status to set this to
    $new_order_status = (int)MODULE_PAYMENT_LINKPOINT_API_ORDER_STATUS_ID;
    if ($new_order_status == 0) $new_order_status = 1;

    $proceedToCapture = true;
    $captureNote = strip_tags(zen_db_input($_POST['captnote']));
    if (isset($_POST['captconfirm']) && $_POST['captconfirm'] == 'on') {
    } else {
      $messageStack->add_session(MODULE_PAYMENT_LINKPOINT_API_TEXT_CAPTURE_CONFIRM_ERROR, 'error');
      $proceedToCapture = false;
    }

    $lp_trans_num = (isset($_POST['captauthid']) && $_POST['captauthid'] != '') ? strip_tags(zen_db_input($_POST['captauthid'])) : '';
    $sql = "select lp_trans_num, chargetotal from " . TABLE_LINKPOINT_API . " where order_id = " . (int)$oID . " and transaction_result = 'APPROVED' order by date_added";
    if ($lp_trans_num != '') $sql = "select lp_trans_num, chargetotal from " . TABLE_LINKPOINT_API . " where lp_trans_num = :trans_num: and transaction_result = 'APPROVED' order by date_added";
    $sql = $db->bindVars($sql, ':trans_num:', $lp_trans_num, 'string');
    $query = $db->Execute($sql);
    if ($query->RecordCount() < 1) {
      $messageStack->add_session(MODULE_PAYMENT_LINKPOINT_API_TEXT_NO_MATCHING_ORDER_FOUND, 'error');
      $proceedToCapture = false;
    }
    $captureAmt = (isset($_POST['captamt']) && $_POST['captamt'] != '') ? (float)strip_tags(zen_db_input($_POST['captamt'])) : $query->fields['chargetotal'];
    if (isset($_POST['btndocapture']) && $_POST['btndocapture'] == MODULE_PAYMENT_LINKPOINT_API_ENTRY_CAPTURE_BUTTON_TEXT) {
      if ($captureAmt == 0) {
        $messageStack->add_session(MODULE_PAYMENT_LINKPOINT_API_TEXT_INVALID_CAPTURE_AMOUNT, 'error');
        $proceedToCapture = false;
      }
    }
    /**
     * Submit capture request to Gateway
     */
    if ($proceedToCapture) {
      unset($myorder);
      $myorder["ordertype"] = 'POSTAUTH';
      $myorder["oid"] = $query->fields['lp_trans_num'];
      $myorder["chargetotal"] = number_format($captureAmt, 2, '.', '');
      $myorder["comments"]  = htmlentities($captureNote, ENT_QUOTES, 'UTF-8');

      $result = $this->_sendRequest($myorder);
      $response_alert = $result['r_approved'] . ' ' . $result['r_error'] . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
      $failure = ($result["r_approved"] != "APPROVED");
      if ($failure) {
        $messageStack->add_session($response_alert, 'error');
      } else {
        // Success, so save the results
        $this->_updateOrderStatus($oID, $new_order_status, 'FUNDS COLLECTED. Auth Code: ' . substr($result['r_code'], 0, 6) . ' - ' . 'Trans ID: ' . $result['r_tdate'] . "\n" . ' Amount: ' . number_format($captureAmt, 2) . "\n" . $captureNote);
        $messageStack->add_session(sprintf(MODULE_PAYMENT_LINKPOINT_API_TEXT_CAPT_INITIATED, $captureAmt, $result['r_tdate'], substr($result['r_code'], 0, 6)), 'success');
        return true;
      }
    }
    return false;
  }
1333398
public function deleteEmailTemplate(array $templateData)
    {
        if (!($template = $this->findEmailTemplate($templateData))) {
            throw new Exception("Email template for event {$templateData['EVENT_NAME']} not found");
        }

        $et = new CEventMessage;
        $res = $et->delete($template['ID']);

        if (!$res) {
            throw new Exception("Can't delete template({$template['ID']}) for type {$templateData['EVENT_NAME']}");
        }

        return ["Email template({$template['ID']}) for type {$templateData['EVENT_NAME']} deleted"];
    }
187126
public function UpdateShippingAddress($aAddressData)
    {
        $oOldAddress = clone $this->GetShippingAddress();
        $oOldBillingAddress = clone $this->GetBillingAddress();
        $bUpdated = parent::UpdateShippingAddress($aAddressData);

        $oNewAddress = $this->GetShippingAddress();
        if (false === $oNewAddress->hasSameDataInSqlData($oOldAddress)) {
            $this->hookChangedShippingAddress($oOldAddress, $oNewAddress);
        }
        $oNewBillingAddress = $this->GetBillingAddress();
        if (false === $oNewBillingAddress->hasSameDataInSqlData($oOldBillingAddress)) {
            $this->hookChangedBillingAddress($oOldBillingAddress, $oNewBillingAddress);
        }

        return $bUpdated;
    }