From 535a01b81e6fe6455840bd3cebd1852568783803 Mon Sep 17 00:00:00 2001 From: juanSTIC Date: Tue, 2 Jan 2024 11:26:23 +0100 Subject: [PATCH 1/7] Imported branch --- .../Catcher/Donation/DonationMailer.php | 176 ++++++++++++--- .../EventInscriptionMailer.php | 209 +++++++++++++++--- .../Catcher/Include/Mailer/WebFormMailer.php | 58 ++++- 3 files changed, 374 insertions(+), 69 deletions(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php index 100a4863390..f5671a64d12 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php @@ -50,34 +50,53 @@ public function sendAdminMail($objWeb, $payment, $formParams, $donator, $candida break; case DonationBO::DONATOR_NEW: case DonationBO::DONATOR_UNIQUE: - $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + // $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); + $paymentMailer = new PaymentMailer(); + + // Function that verify if the form have the 'custom_assigned_email_template' input + if(!empty($_REQUEST['custom_assigned_email_template'])) { + if($this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $payment)) { + return; + } + // If the form doesn't have the input send the generic email + } else { + $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); + $html .= $paymentMailer->paymentToHTML($payment); + } + // End STIC 20230920 + break; } - $paymentMailer = new PaymentMailer(); - $html .= $paymentMailer->paymentToHTML($payment); - - // Link the attached form files to the mail - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Linking the attached documents of the form to the mail to be sent to the administrator ..."); - $documents = $donator->documents->tempBeans; - - if ($documents) { - $html .= ''; - $html .= $this->translate('LBL_ATTACHMENTS_WEBFORM'); - $html .= ''; - $html .= ''; - - foreach ($documents as $key => $value) { - $your_url = $GLOBALS['sugar_config']['site_url'] . "/index.php?module=Documents&action=DetailView&record=" . $value->id; - $html .= ''; - $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": File name: " . $value->document_name . " - File URL: " . $your_url); + // STIC 20231220 - ART - Enable custom email template for assigned user + // STIC#1224 + if(empty($_REQUEST['custom_assigned_email_template'])) { + // Link the attached form files to the mail + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Linking the attached documents of the form to the mail to be sent to the administrator ..."); + $documents = $donator->documents->tempBeans; + + if ($documents) { + $html .= ''; + $html .= $this->translate('LBL_ATTACHMENTS_WEBFORM'); + $html .= ''; + $html .= '
' . $value->document_name . '
'; + + foreach ($documents as $key => $value) { + $your_url = $GLOBALS['sugar_config']['site_url'] . "/index.php?module=Documents&action=DetailView&record=" . $value->id; + $html .= ''; + $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": File name: " . $value->document_name . " - File URL: " . $your_url); + } + $html .= '
' . $value->document_name . '


'; } - $html .= '

'; - } - $this->body = $html; - $this->subject = "{$payment->transaction_code} - {$this->subject}"; - return $this->send(); + $this->body = $html; + $this->subject = "{$payment->transaction_code} - {$this->subject}"; + return $this->send(); + } + // End STIC 20231220 } /** @@ -230,6 +249,38 @@ private function webObjectToHtml($objWeb, $formParams) return $html; } + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + /** + * Function to parse the email + * + * @param $templateId id of the template + * @param $payment data of the payment + * @param $replacementObjects array with the object + * @param $lang + * @return void + */ + public function parsingEmail($templateId, $payment, $replacementObjects, $lang){ + $payment = $replacementObjects[1]; + + // Function to get the object + if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { + $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); + foreach ($relatedBeans as $fpBean) { + $replacementObjects[] = $fpBean; + } + } + + // Parse the template + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template [{$templateId}]..."); + + if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { + $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); + return false; + } + } + // End STIC 20231205 - ART + /** * Send the notification email to the registered user */ @@ -251,23 +302,82 @@ public function sendUserMail($templateId, $objWeb, $payment, $lang = null) $replacementObjects = array(); $replacementObjects[0] = $objWeb; $replacementObjects[1] = $payment; - if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { - $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); - foreach ($relatedBeans as $fpBean) { - $replacementObjects[] = $fpBean; - } - } + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + // if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { + // $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); + // foreach ($relatedBeans as $fpBean) { + // $replacementObjects[] = $fpBean; + // } + // } // Parse the template - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template..."); + // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template [{$templateId}]..."); - if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { - $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); - return false; + // if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { + // $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); + // return false; + // } + + // Function to parse the email + $this->parsingEmail($templateId, $replacementObjects[1], $replacementObjects, $lang); + // End STIC 20231205 - ART + + // Send the mail + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail..."); + return $this->send(); + } + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + /** + * Send the notification email to the assigned user + * + * @param $templateId id of the template + * @param $objWeb data from the form + * @param $payment data of the payment + * @param $lang + * @return void + */ + public function sendAssignedUserMail($templateId, $objWeb, $payment, $lang = null) + { + // Reset the recipient list + $this->resetDest(); + + // Add the recipient + $user = BeanFactory::getBean('Users', $_REQUEST['assigned_user_id']); + // Use the primary address of the assigned user + $userEmail = $user->emailAddress->getPrimaryAddress($user); + + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Adding recipient [{$userEmail}] ..."); + $this->addMailsDest($userEmail); + + // Get the Contact from the CRM + include_once 'SticInclude/Utils.php'; + $contactBean = SticUtils::getRelatedBeanObject($payment, 'stic_payments_contacts'); + + // Build the array of objects to parse + $replacementObjects = array(); + $replacementObjects[0] = $objWeb; + $replacementObjects[1] = $payment; + $replacementObjects[2] = $user; + $replacementObjects[3] = $contactBean; + + // If there is an attached document it is added to the array + if(!empty($contactBean->documents)){ + $documents = $contactBean->documents->tempBeans; + foreach($documents as $key => $valueDocument) { + $replacementObjects[4] = $valueDocument; + } } + // Function to parse the email + $this->parsingEmail($templateId, $replacementObjects[1], $replacementObjects, $lang); + // Send the mail $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail..."); return $this->send(); } + // End STIC 20231205 - ART } diff --git a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php index 002422fb848..59d45f1869d 100644 --- a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php +++ b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php @@ -90,8 +90,26 @@ public function sendAdminMail() break; case EventInscriptionBO::CONTACT_NEW: case EventInscriptionBO::CONTACT_UNIQUE: - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); - $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); + // $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); + $paymentMailer = new PaymentMailer(); + + // Function that verify if the form have the 'custom_assigned_email_template' input + if(!empty($_REQUEST['custom_assigned_email_template'])) { + if($this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), null, $this->payment)) { + return; + } + // If the form doesn't have the input send the generic email + } else { + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); + $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); + $html .= $paymentMailer->paymentToHTML($this->payment); + } + // End STIC 20230920 + break; } @@ -131,24 +149,47 @@ public function sendAdminMail() break; case EventInscriptionBO::ACCOUNT_NEW: case EventInscriptionBO::ACCOUNT_UNIQUE: - $html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + //$html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); + $paymentMailer = new PaymentMailer(); + + // Function that verify if the form have the 'custom_assigned_email_template' input + if(!empty($_REQUEST['custom_assigned_email_template'])) { + if($this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), $accountObject, $this->payment)) { + return; + } + // If the form doesn't have the input send the generic email + } else { + $html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); + $html .= $paymentMailer->paymentToHTML($this->payment); + } + // End STIC 20230920 + break; case EventInscriptionBO::ACCOUNT_NO_DATA: $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": The form does not include organizational data."); } - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data ..."); - if ($this->payment == null) { - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data have not been included."); - } else { - $paymentMailer = new PaymentMailer(); - $html .= $paymentMailer->paymentToHTML($this->payment); - $this->subject = "{$this->payment->transaction_code} - {$this->subject}"; // If there is linked payment, include the payment number in the subject of the mail - } - $this->body = $html; - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); - return $this->send(); + // STIC 20231220 - ART - Enable custom email template for assigned user + // STIC#1224 + if(empty($_REQUEST['custom_assigned_email_template'])) { + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data ..."); + if ($this->payment == null) { + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data have not been included."); + } else { + $paymentMailer = new PaymentMailer(); + $html .= $paymentMailer->paymentToHTML($this->payment); + $this->subject = "{$this->payment->transaction_code} - {$this->subject}"; // If there is linked payment, include the payment number in the subject of the mail + } + $this->body = $html; + + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); + return $this->send(); + } + // End STIC 20231220 } /** @@ -174,6 +215,44 @@ public function sendUserMail($templateId, $lang = null) $lang); } + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + /** + * Function to parse the email + * + * @param $templateId id of the template + * @param $account data of the account + * @param $payment data of the payment + * @param $replacementObjects array with the object + * @param $lang + * @return void + */ + public function parsingEmail($templateId, $account, $payment, $replacementObjects, $lang){ + // Function to get the object + if (!empty($account)) { + $replacementObjects[] = $account; + } + + if (!empty($payment)) { + $replacementObjects[] = $payment; + if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { + $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); + foreach ($relatedBeans as $fpBean) { + $replacementObjects[] = $fpBean; + } + } + } + + // Parse the template + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template [{$templateId}]..."); + + if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { + $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); + return false; + } + } + // End STIC 20230921 - ART + /** * Send the notification email to the registered user */ @@ -197,31 +276,101 @@ protected function __sendUserMail($templateId, $objContactWeb, $event, $inscript $replacementObjects[1] = $event; $replacementObjects[2] = $inscription; - if (!empty($account)) { - $replacementObjects[] = $account; - } + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + // if (!empty($account)) { + // $replacementObjects[] = $account; + // } + + // if (!empty($payment)) { + // $replacementObjects[] = $payment; + // if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { + // $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); + // foreach ($relatedBeans as $fpBean) { + // $replacementObjects[] = $fpBean; + // } + // } + // } - if (!empty($payment)) { - $replacementObjects[] = $payment; - if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { - $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); - foreach ($relatedBeans as $fpBean) { - $replacementObjects[] = $fpBean; - } + // Parse the template + // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template ..."); + // if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { + // $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); + // return false; + // } + + // Function to parse the email + $this->parsingEmail($templateId, $account, $payment, $replacementObjects, $lang); + // End STIC 20230921 - ART + + // Send the mail + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); + return $this->send(); + } + + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + /** + * Send the notification email to the assigned user + * + * @param $templateId id of the template + * @param $objContactWeb data of the contact from the form + * @param $event data of the event + * @param $inscription data of the inscription + * @param $account data of the account if this exist + * @param $payment data of the payment + * @param $lang + * @return void + */ + protected function sendAssignedUserMail($templateId, $objWeb, $event, $inscription, $account = null, $payment, $lang = null) + { + // Reset the recipient list + $this->resetDest(); + + // Get the candidates from the form + $candidates = $this->eventInscriptionBO->getContactCandidates(); + $objWeb = array_pop($candidates); + + // Get the accounts of the candidates from the form + $candidates = $this->eventInscriptionBO->getAccountCandidates(); + $account = (!empty($candidates) ? array_pop($candidates) : null); + + // Add the recipient + $user = BeanFactory::getBean('Users', $_REQUEST['assigned_user_id']); + // Use the primary address of the assigned user + $userEmail = $user->emailAddress->getPrimaryAddress($user); + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Adding recipient [{$userEmail}] ..."); + $this->addMailsDest($userEmail); + + // Get the Contact from the CRM + include_once 'SticInclude/Utils.php'; + $contactBean = SticUtils::getRelatedBeanObject($payment, 'stic_payments_contacts'); + + // Build the array of objects to parse + $replacementObjects = array(); + $replacementObjects[0] = $objWeb; + $replacementObjects[1] = $event; + $replacementObjects[2] = $inscription; + $replacementObjects[3] = $user; + $replacementObjects[4] = $contactBean; + + // If there is an attached document it is added to the array + if(!empty($contactBean->documents)){ + $documents = $contactBean->documents->tempBeans; + foreach($documents as $key => $valueDocument) { + $replacementObjects[5] = $valueDocument; } } - // Parse the template - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template ..."); - if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { - $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); - return false; - } + // Function to parse the email + $this->parsingEmail($templateId, $account, $payment, $replacementObjects, $lang); // Send the mail $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); return $this->send(); } + // End STIC 20230920 /** * Prepare the necessary information for deferred mail delivery diff --git a/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php b/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php index f004cf57afd..9bcf3853364 100644 --- a/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php +++ b/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php @@ -312,6 +312,12 @@ public function getCampaingData($id, $link = true) */ public function parseEmailTemplateById($templateId, $replacementObjects, $lang = null) { + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // Calling the object from the form to parse the entire template + $objWeb = $replacementObjects[0]; + // End STIC 20231205 + if (empty($templateId)) { $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": No ID received."); return false; @@ -325,7 +331,11 @@ public function parseEmailTemplateById($templateId, $replacementObjects, $lang = $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Template with ID [{$templateId}] not found."); return false; } - return $this->parseEmailTemplate($template, $replacementObjects, $lang); + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // return $this->parseEmailTemplate($template, $replacementObjects, $lang); + return $this->parseEmailTemplate($template, $replacementObjects, $objWeb, $lang); + // End STIC 20231205 } /** @@ -338,6 +348,12 @@ public function parseEmailTemplateById($templateId, $replacementObjects, $lang = */ public function parseEmailTemplateByName($templateName, $replacementObjects, $lang = null, $type = 'email') { + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // Calling the object from the form to parse the entire template + $objWeb = $replacementObjects[0]; + // End STIC 20231205 + if (empty($templateName)) { $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": No name has been received."); return false; @@ -351,7 +367,11 @@ public function parseEmailTemplateByName($templateName, $replacementObjects, $la $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Template not found with name [{$templateName}]"); return false; } - return $this->parseEmailTemplate($template, $replacementObjects, $lang); + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // return $this->parseEmailTemplate($template, $replacementObjects, $lang); + return $this->parseEmailTemplate($template, $replacementObjects, $objWeb, $lang); + // End STIC 20231205 } /** @@ -361,8 +381,12 @@ public function parseEmailTemplateByName($templateName, $replacementObjects, $la * @param $replacementObjects Array of objects to be parsed * @return String Mail body in html */ - protected function parseEmailTemplate($template, $replacementObjects, $lang) + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // protected function parseEmailTemplate($template, $replacementObjects, $lang) { + protected function parseEmailTemplate($template, $replacementObjects, $objWeb, $lang) { + // End STIC 20231205 global $current_language, $app_list_strings, $app_strings; $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template ..."); @@ -385,11 +409,20 @@ protected function parseEmailTemplate($template, $replacementObjects, $lang) $app_strings = return_application_language($current_language); $app_list_strings = return_app_list_strings_language($current_language); - $parseArr = array("subject0" => $template->subject, "text0" => $template->body, "html0" => $template->body_html); + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // $parseArr = array("subject0" => $template->subject, "text0" => $template->body, "html0" => $template->body_html); + $parseArr = array("subject1" => $template->subject, "text1" => $template->body, "html1" => $template->body_html); + // End STIC 20231205 $replacementObjectsLength = (empty($replacementObjects) || !is_array($replacementObjects) ? 0 : count($replacementObjects)); - $j = 0; - for ($i = 0; $i < $replacementObjectsLength; $i++) { + // STIC 20231205 - ART - Enable custom email template for assigned user + // STIC#1224 + // $j = 0; + // for ($i = 0; $i < $replacementObjectsLength; $i++) { + $j = 1; + for ($i = 1; $i < $replacementObjectsLength ; $i++) { + // End STIC 20231205 $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing object [{$i}] [{$replacementObjects[$i]->module_dir}] ... "); $macro_nv = array(); $obj = $this->prepareBean2EmailTemplate($replacementObjects[$i]); @@ -401,6 +434,19 @@ protected function parseEmailTemplate($template, $replacementObjects, $lang) $parseArr["subject{$j}"] = $parseArr["subject{$i}"]; $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Result [{$i}] -> " . $parseArr["html{$j}"]); } + + // STIC 20230905 - ART - Enable custom email template for assigned user + // STIC#1224 + // Replace on the email template the param of form_contact to contact + $parseArr["html{$i}"] = str_replace('$form_contact', '$contact', $parseArr["html{$i}"]); + $obj = $this->prepareBean2EmailTemplate($objWeb); + $parseArr = $template->parse_email_template($parseArr, $obj->module_dir, $obj, $macro_nv); + + // Parse the entire email template again + $parseArr["text{$j}"] = $parseArr["text{$i}"]; + $parseArr["html{$j}"] = $parseArr["html{$i}"]; + $parseArr["subject{$j}"] = $parseArr["subject{$i}"]; + // End STIC 20231205 $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Recovering original language files ..."); $current_language = $prev_lang; From 29356f4f703568e39b8057584162688a3c4644d9 Mon Sep 17 00:00:00 2001 From: ainaraRT Date: Mon, 8 Jan 2024 12:04:50 +0000 Subject: [PATCH 2/7] function to send error if there isn't the custom template --- .../Catcher/Donation/DonationController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationController.php b/modules/stic_Web_Forms/Catcher/Donation/DonationController.php index e274d2eded6..ed49c64dea7 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationController.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationController.php @@ -117,10 +117,14 @@ protected function doAction() $payment = $this->fp->getResponseData(); // If the shipment has not gone ok it generates a trace - if (!$mailer->sendAdminMail($objWeb, $payment, $this->bo->getFormParams(), $donator, $candidates, $donatorResult)) { - $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Unable to send the email to the administrator."); + if (!$mailer->sendAdminMail($objWeb, $payment, $this->bo->getFormParams(), $donator, $candidates, $donatorResult)) { + // STIC 20240108 - ART - Enable custom email template for assigned user + // STIC#1224 + if(empty($_REQUEST['custom_assigned_email_template'])) { + // End STIC 20240108 + $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Unable to send the email to the administrator."); + } } - // If we are in an advanced version of the form send the notice to the user if ($this->version > 1) { $defParams = $this->bo->getDefParams(); From 8a38c5aa26a152b391963389876b62aea639c8b6 Mon Sep 17 00:00:00 2001 From: ainaraRT Date: Tue, 9 Jan 2024 10:43:13 +0000 Subject: [PATCH 3/7] return the function --- .../Catcher/Donation/DonationController.php | 7 +-- .../Catcher/Donation/DonationMailer.php | 49 ++++++++----------- .../EventInscriptionMailer.php | 38 ++++++-------- 3 files changed, 36 insertions(+), 58 deletions(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationController.php b/modules/stic_Web_Forms/Catcher/Donation/DonationController.php index ed49c64dea7..942145b24c2 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationController.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationController.php @@ -118,12 +118,7 @@ protected function doAction() // If the shipment has not gone ok it generates a trace if (!$mailer->sendAdminMail($objWeb, $payment, $this->bo->getFormParams(), $donator, $candidates, $donatorResult)) { - // STIC 20240108 - ART - Enable custom email template for assigned user - // STIC#1224 - if(empty($_REQUEST['custom_assigned_email_template'])) { - // End STIC 20240108 - $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Unable to send the email to the administrator."); - } + $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Unable to send the email to the administrator."); } // If we are in an advanced version of the form send the notice to the user if ($this->version > 1) { diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php index f5671a64d12..3a8e0aef650 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php @@ -58,45 +58,38 @@ public function sendAdminMail($objWeb, $payment, $formParams, $donator, $candida // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { - if($this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $payment)) { - return; - } + return $this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $payment); // If the form doesn't have the input send the generic email } else { $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); $html .= $paymentMailer->paymentToHTML($payment); } - // End STIC 20230920 + // End STIC 20240109 break; } - // STIC 20231220 - ART - Enable custom email template for assigned user - // STIC#1224 - if(empty($_REQUEST['custom_assigned_email_template'])) { - // Link the attached form files to the mail - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Linking the attached documents of the form to the mail to be sent to the administrator ..."); - $documents = $donator->documents->tempBeans; - - if ($documents) { - $html .= ''; - $html .= $this->translate('LBL_ATTACHMENTS_WEBFORM'); - $html .= ''; - $html .= ''; - - foreach ($documents as $key => $value) { - $your_url = $GLOBALS['sugar_config']['site_url'] . "/index.php?module=Documents&action=DetailView&record=" . $value->id; - $html .= ''; - $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": File name: " . $value->document_name . " - File URL: " . $your_url); - } - $html .= '
' . $value->document_name . '


'; - } + // Link the attached form files to the mail + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Linking the attached documents of the form to the mail to be sent to the administrator ..."); + $documents = $donator->documents->tempBeans; - $this->body = $html; - $this->subject = "{$payment->transaction_code} - {$this->subject}"; - return $this->send(); + if ($documents) { + $html .= ''; + $html .= $this->translate('LBL_ATTACHMENTS_WEBFORM'); + $html .= ''; + $html .= ''; + + foreach ($documents as $key => $value) { + $your_url = $GLOBALS['sugar_config']['site_url'] . "/index.php?module=Documents&action=DetailView&record=" . $value->id; + $html .= ''; + $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": File name: " . $value->document_name . " - File URL: " . $your_url); + } + $html .= '
' . $value->document_name . '


'; } - // End STIC 20231220 + + $this->body = $html; + $this->subject = "{$payment->transaction_code} - {$this->subject}"; + return $this->send(); } /** diff --git a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php index 59d45f1869d..89d5de85990 100644 --- a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php +++ b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php @@ -99,16 +99,14 @@ public function sendAdminMail() // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { - if($this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), null, $this->payment)) { - return; - } + return $this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), null, $this->payment); // If the form doesn't have the input send the generic email } else { $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); $html .= $paymentMailer->paymentToHTML($this->payment); } - // End STIC 20230920 + // End STIC 20240109 break; } @@ -157,9 +155,7 @@ public function sendAdminMail() // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { - if($this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), $accountObject, $this->payment)) { - return; - } + return $this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), $accountObject, $this->payment); // If the form doesn't have the input send the generic email } else { $html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); @@ -172,24 +168,18 @@ public function sendAdminMail() $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": The form does not include organizational data."); } - - // STIC 20231220 - ART - Enable custom email template for assigned user - // STIC#1224 - if(empty($_REQUEST['custom_assigned_email_template'])) { - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data ..."); - if ($this->payment == null) { - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data have not been included."); - } else { - $paymentMailer = new PaymentMailer(); - $html .= $paymentMailer->paymentToHTML($this->payment); - $this->subject = "{$this->payment->transaction_code} - {$this->subject}"; // If there is linked payment, include the payment number in the subject of the mail - } - $this->body = $html; - - $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); - return $this->send(); + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data ..."); + if ($this->payment == null) { + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Payment data have not been included."); + } else { + $paymentMailer = new PaymentMailer(); + $html .= $paymentMailer->paymentToHTML($this->payment); + $this->subject = "{$this->payment->transaction_code} - {$this->subject}"; // If there is linked payment, include the payment number in the subject of the mail } - // End STIC 20231220 + $this->body = $html; + + $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); + return $this->send(); } /** From dcd4d814911c212e4416b795c9b0e3f0326d7935 Mon Sep 17 00:00:00 2001 From: ainaraRT Date: Wed, 10 Jan 2024 15:48:34 +0000 Subject: [PATCH 4/7] changed order from the function --- modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php | 5 +++-- .../Catcher/EventInscription/EventInscriptionMailer.php | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php index 3a8e0aef650..6beda7ad8a1 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php @@ -54,7 +54,6 @@ public function sendAdminMail($objWeb, $payment, $formParams, $donator, $candida // STIC 20230905 - ART - Enable custom email template for assigned user // STIC#1224 // $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); - $paymentMailer = new PaymentMailer(); // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { @@ -62,13 +61,15 @@ public function sendAdminMail($objWeb, $payment, $formParams, $donator, $candida // If the form doesn't have the input send the generic email } else { $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); - $html .= $paymentMailer->paymentToHTML($payment); } // End STIC 20240109 break; } + $paymentMailer = new PaymentMailer(); + $html .= $paymentMailer->paymentToHTML($payment); + // Link the attached form files to the mail $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Linking the attached documents of the form to the mail to be sent to the administrator ..."); $documents = $donator->documents->tempBeans; diff --git a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php index 89d5de85990..c72ebdcc7d0 100644 --- a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php +++ b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php @@ -95,7 +95,6 @@ public function sendAdminMail() // STIC#1224 // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); // $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); - $paymentMailer = new PaymentMailer(); // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { @@ -104,7 +103,6 @@ public function sendAdminMail() } else { $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); - $html .= $paymentMailer->paymentToHTML($this->payment); } // End STIC 20240109 @@ -151,7 +149,6 @@ public function sendAdminMail() // STIC 20230905 - ART - Enable custom email template for assigned user // STIC#1224 //$html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); - $paymentMailer = new PaymentMailer(); // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { @@ -159,7 +156,6 @@ public function sendAdminMail() // If the form doesn't have the input send the generic email } else { $html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); - $html .= $paymentMailer->paymentToHTML($this->payment); } // End STIC 20230920 From eba65d8f39bd1129ce9c2b473be733acb09f7ce3 Mon Sep 17 00:00:00 2001 From: ainaraRT Date: Tue, 16 Jan 2024 13:38:52 +0000 Subject: [PATCH 5/7] If there's a template for the user send the mail --- .../stic_Web_Forms/Catcher/Donation/DonationMailer.php | 8 ++++++-- .../EventInscription/EventInscriptionMailer.php | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php index 6beda7ad8a1..d039b0bee61 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php @@ -316,11 +316,15 @@ public function sendUserMail($templateId, $objWeb, $payment, $lang = null) // Function to parse the email $this->parsingEmail($templateId, $replacementObjects[1], $replacementObjects, $lang); - // End STIC 20231205 - ART // Send the mail $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail..."); - return $this->send(); + + // If there's a template for the user send the mail + if(!empty($templateId)) { + return $this->send(); + } + // End STIC 20240116 - ART } // STIC 20230905 - ART - Enable custom email template for assigned user diff --git a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php index c72ebdcc7d0..9fa50dc78a5 100644 --- a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php +++ b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php @@ -287,11 +287,15 @@ protected function __sendUserMail($templateId, $objContactWeb, $event, $inscript // Function to parse the email $this->parsingEmail($templateId, $account, $payment, $replacementObjects, $lang); - // End STIC 20230921 - ART - + // Send the mail $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); - return $this->send(); + + // If there's a template for the user send the mail + if(!empty($templateId)) { + return $this->send(); + } + // End STIC 20240116 - ART } From 79d918044835bbf61f8fd27d10eb953c51895feb Mon Sep 17 00:00:00 2001 From: ainaraRT Date: Wed, 17 Jan 2024 11:57:27 +0000 Subject: [PATCH 6/7] comments deleted --- .../Catcher/Donation/DonationMailer.php | 31 +------------- .../EventInscriptionMailer.php | 41 ------------------- .../Catcher/Include/Mailer/WebFormMailer.php | 32 +-------------- 3 files changed, 2 insertions(+), 102 deletions(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php index d039b0bee61..f1375f13289 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationMailer.php @@ -51,10 +51,6 @@ public function sendAdminMail($objWeb, $payment, $formParams, $donator, $candida case DonationBO::DONATOR_NEW: case DonationBO::DONATOR_UNIQUE: - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 - // $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); - // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { return $this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $payment); @@ -62,7 +58,6 @@ public function sendAdminMail($objWeb, $payment, $formParams, $donator, $candida } else { $html = $this->newDonationMail($objWeb, $payment, $formParams, $donator, $donatorResult == DonationBO::DONATOR_NEW); } - // End STIC 20240109 break; } @@ -243,8 +238,6 @@ private function webObjectToHtml($objWeb, $formParams) return $html; } - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 /** * Function to parse the email * @@ -273,7 +266,6 @@ public function parsingEmail($templateId, $payment, $replacementObjects, $lang){ return false; } } - // End STIC 20231205 - ART /** * Send the notification email to the registered user @@ -297,23 +289,6 @@ public function sendUserMail($templateId, $objWeb, $payment, $lang = null) $replacementObjects[0] = $objWeb; $replacementObjects[1] = $payment; - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 - // if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { - // $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); - // foreach ($relatedBeans as $fpBean) { - // $replacementObjects[] = $fpBean; - // } - // } - - // Parse the template - // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template [{$templateId}]..."); - - // if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { - // $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); - // return false; - // } - // Function to parse the email $this->parsingEmail($templateId, $replacementObjects[1], $replacementObjects, $lang); @@ -323,12 +298,9 @@ public function sendUserMail($templateId, $objWeb, $payment, $lang = null) // If there's a template for the user send the mail if(!empty($templateId)) { return $this->send(); - } - // End STIC 20240116 - ART + } } - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 /** * Send the notification email to the assigned user * @@ -377,5 +349,4 @@ public function sendAssignedUserMail($templateId, $objWeb, $payment, $lang = nul $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail..."); return $this->send(); } - // End STIC 20231205 - ART } diff --git a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php index 9fa50dc78a5..171a32eaba4 100644 --- a/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php +++ b/modules/stic_Web_Forms/Catcher/EventInscription/EventInscriptionMailer.php @@ -91,11 +91,6 @@ public function sendAdminMail() case EventInscriptionBO::CONTACT_NEW: case EventInscriptionBO::CONTACT_UNIQUE: - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 - // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); - // $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); - // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { return $this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), null, $this->payment); @@ -104,7 +99,6 @@ public function sendAdminMail() $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Generating information for CONTACT_NEW or CONTACT_UNIQUE"); $html .= $this->newObjectBodyHTML($objWeb, $formParams, $contactObject, $contactResult == EventInscriptionBO::CONTACT_NEW); } - // End STIC 20240109 break; } @@ -146,10 +140,6 @@ public function sendAdminMail() case EventInscriptionBO::ACCOUNT_NEW: case EventInscriptionBO::ACCOUNT_UNIQUE: - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 - //$html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); - // Function that verify if the form have the 'custom_assigned_email_template' input if(!empty($_REQUEST['custom_assigned_email_template'])) { return $this->sendAssignedUserMail($_REQUEST['custom_assigned_email_template'], $objWeb, $this->eventInscriptionBO->getEvent(), $this->eventInscriptionBO->getInscriptionObject(), $accountObject, $this->payment); @@ -157,7 +147,6 @@ public function sendAdminMail() } else { $html .= $this->newObjectBodyHTML($objWeb, $formParams, $accountObject, $accountResult == EventInscriptionBO::ACCOUNT_NEW); } - // End STIC 20230920 break; case EventInscriptionBO::ACCOUNT_NO_DATA: @@ -201,8 +190,6 @@ public function sendUserMail($templateId, $lang = null) $lang); } - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 /** * Function to parse the email * @@ -237,7 +224,6 @@ public function parsingEmail($templateId, $account, $payment, $replacementObject return false; } } - // End STIC 20230921 - ART /** * Send the notification email to the registered user @@ -262,29 +248,6 @@ protected function __sendUserMail($templateId, $objContactWeb, $event, $inscript $replacementObjects[1] = $event; $replacementObjects[2] = $inscription; - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 - // if (!empty($account)) { - // $replacementObjects[] = $account; - // } - - // if (!empty($payment)) { - // $replacementObjects[] = $payment; - // if ($payment->load_relationship('stic_payments_stic_payment_commitments')) { - // $relatedBeans = $payment->stic_payments_stic_payment_commitments->getBeans(); - // foreach ($relatedBeans as $fpBean) { - // $replacementObjects[] = $fpBean; - // } - // } - // } - - // Parse the template - // $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template ..."); - // if (false === parent::parseEmailTemplateById($templateId, $replacementObjects, $lang)) { - // $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Error parsing the template."); - // return false; - // } - // Function to parse the email $this->parsingEmail($templateId, $account, $payment, $replacementObjects, $lang); @@ -295,12 +258,9 @@ protected function __sendUserMail($templateId, $objContactWeb, $event, $inscript if(!empty($templateId)) { return $this->send(); } - // End STIC 20240116 - ART } - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 /** * Send the notification email to the assigned user * @@ -360,7 +320,6 @@ protected function sendAssignedUserMail($templateId, $objWeb, $event, $inscripti $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Sending mail ..."); return $this->send(); } - // End STIC 20230920 /** * Prepare the necessary information for deferred mail delivery diff --git a/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php b/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php index 9bcf3853364..64280bde7b2 100644 --- a/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php +++ b/modules/stic_Web_Forms/Catcher/Include/Mailer/WebFormMailer.php @@ -312,11 +312,8 @@ public function getCampaingData($id, $link = true) */ public function parseEmailTemplateById($templateId, $replacementObjects, $lang = null) { - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 // Calling the object from the form to parse the entire template $objWeb = $replacementObjects[0]; - // End STIC 20231205 if (empty($templateId)) { $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": No ID received."); @@ -331,11 +328,7 @@ public function parseEmailTemplateById($templateId, $replacementObjects, $lang = $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Template with ID [{$templateId}] not found."); return false; } - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 - // return $this->parseEmailTemplate($template, $replacementObjects, $lang); return $this->parseEmailTemplate($template, $replacementObjects, $objWeb, $lang); - // End STIC 20231205 } /** @@ -348,11 +341,8 @@ public function parseEmailTemplateById($templateId, $replacementObjects, $lang = */ public function parseEmailTemplateByName($templateName, $replacementObjects, $lang = null, $type = 'email') { - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 // Calling the object from the form to parse the entire template $objWeb = $replacementObjects[0]; - // End STIC 20231205 if (empty($templateName)) { $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": No name has been received."); @@ -367,11 +357,7 @@ public function parseEmailTemplateByName($templateName, $replacementObjects, $la $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Template not found with name [{$templateName}]"); return false; } - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 - // return $this->parseEmailTemplate($template, $replacementObjects, $lang); return $this->parseEmailTemplate($template, $replacementObjects, $objWeb, $lang); - // End STIC 20231205 } /** @@ -381,12 +367,8 @@ public function parseEmailTemplateByName($templateName, $replacementObjects, $la * @param $replacementObjects Array of objects to be parsed * @return String Mail body in html */ - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 - // protected function parseEmailTemplate($template, $replacementObjects, $lang) { protected function parseEmailTemplate($template, $replacementObjects, $objWeb, $lang) { - // End STIC 20231205 global $current_language, $app_list_strings, $app_strings; $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing template ..."); @@ -409,20 +391,11 @@ protected function parseEmailTemplate($template, $replacementObjects, $objWeb, $ $app_strings = return_application_language($current_language); $app_list_strings = return_app_list_strings_language($current_language); - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 - // $parseArr = array("subject0" => $template->subject, "text0" => $template->body, "html0" => $template->body_html); $parseArr = array("subject1" => $template->subject, "text1" => $template->body, "html1" => $template->body_html); - // End STIC 20231205 $replacementObjectsLength = (empty($replacementObjects) || !is_array($replacementObjects) ? 0 : count($replacementObjects)); - // STIC 20231205 - ART - Enable custom email template for assigned user - // STIC#1224 - // $j = 0; - // for ($i = 0; $i < $replacementObjectsLength; $i++) { $j = 1; for ($i = 1; $i < $replacementObjectsLength ; $i++) { - // End STIC 20231205 $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Parsing object [{$i}] [{$replacementObjects[$i]->module_dir}] ... "); $macro_nv = array(); $obj = $this->prepareBean2EmailTemplate($replacementObjects[$i]); @@ -434,9 +407,7 @@ protected function parseEmailTemplate($template, $replacementObjects, $objWeb, $ $parseArr["subject{$j}"] = $parseArr["subject{$i}"]; $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Result [{$i}] -> " . $parseArr["html{$j}"]); } - - // STIC 20230905 - ART - Enable custom email template for assigned user - // STIC#1224 + // Replace on the email template the param of form_contact to contact $parseArr["html{$i}"] = str_replace('$form_contact', '$contact', $parseArr["html{$i}"]); $obj = $this->prepareBean2EmailTemplate($objWeb); @@ -446,7 +417,6 @@ protected function parseEmailTemplate($template, $replacementObjects, $objWeb, $ $parseArr["text{$j}"] = $parseArr["text{$i}"]; $parseArr["html{$j}"] = $parseArr["html{$i}"]; $parseArr["subject{$j}"] = $parseArr["subject{$i}"]; - // End STIC 20231205 $GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": Recovering original language files ..."); $current_language = $prev_lang; From 37570d698e828f4f52803861e20882f42fdf1379 Mon Sep 17 00:00:00 2001 From: ainaraRT Date: Thu, 18 Jan 2024 08:56:13 +0000 Subject: [PATCH 7/7] wip --- modules/stic_Web_Forms/Catcher/Donation/DonationController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/stic_Web_Forms/Catcher/Donation/DonationController.php b/modules/stic_Web_Forms/Catcher/Donation/DonationController.php index 942145b24c2..e274d2eded6 100644 --- a/modules/stic_Web_Forms/Catcher/Donation/DonationController.php +++ b/modules/stic_Web_Forms/Catcher/Donation/DonationController.php @@ -117,9 +117,10 @@ protected function doAction() $payment = $this->fp->getResponseData(); // If the shipment has not gone ok it generates a trace - if (!$mailer->sendAdminMail($objWeb, $payment, $this->bo->getFormParams(), $donator, $candidates, $donatorResult)) { + if (!$mailer->sendAdminMail($objWeb, $payment, $this->bo->getFormParams(), $donator, $candidates, $donatorResult)) { $GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ": Unable to send the email to the administrator."); } + // If we are in an advanced version of the form send the notice to the user if ($this->version > 1) { $defParams = $this->bo->getDefParams();