diff --git a/override/modules/blocknewsletter/blocknewsletter.php b/override/modules/blocknewsletter/blocknewsletter.php index 35e5e7d3..f20d8c1d 100644 --- a/override/modules/blocknewsletter/blocknewsletter.php +++ b/override/modules/blocknewsletter/blocknewsletter.php @@ -135,9 +135,17 @@ class BlockNewsletterOverride extends BlockNewsletter $cmsCategory = false; $genericPdf = false; + $register_status = $this->isNewsletterRegistered($_POST['email']); $email = pSQL($_POST['email']); - if ($register_status > 0){ + + + // test pour savoir si on doit envoye le guide PDF + $already_send = false; + + // je suis deja enregistre + if ($register_status > 0) { + // envoi le code promo if ($code = Configuration::get('NW_VOUCHER_CODE') && !$cmsCategory && !$genericPdf) { if (!$this->isNewsletterCmsPsRegistered($email, 9999, $register_status, false)) { if ($this->registerNewsletterCmsPs($email, 9999, $register_status)) { @@ -149,66 +157,80 @@ class BlockNewsletterOverride extends BlockNewsletter return $this->error = $this->l('This email address is already registered.'); } - } elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory != false) { + } + // envoi le pdf de la categorie + elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory != false) { // enregistrement pour la categorie si pas enregistré if ($this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status)) { // $this->valid = $this->l('You will recieve your PDF.'); $this->valid = 'Vous allez reçevoir votre PDF.'; $this->sendConfirmationEmail($email, $cmsCategory); + $already_send = true; } else { return $this->error = $this->l('An error occurred during the subscription process.'); } - } elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $genericPdf != false) { + } + // envoi le pdf générique + elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $genericPdf != false) { // $this->valid = $this->l('You will recieve your PDF.'); $this->valid = 'Vous allez reçevoir votre PDF.'; $this->sendConfirmationEmail($email, false, $genericPdf); + $already_send = true; } else { return $this->error = $this->l('This email address is already registered.'); } } + + // je suis pas register premiere fois if (!$this->isRegistered($register_status)) { - if (Configuration::get('NW_VERIFICATION_EMAIL')) - { - // create an unactive entry in the newsletter database - if ($register_status == self::GUEST_NOT_REGISTERED) { - $this->registerGuest($email, false); - } - - if (!$token = $this->getToken($email, $register_status)) { - return $this->error = $this->l('An error occurred during the subscription process.'); - } - - $this->sendVerificationEmail($email, $token); - - return $this->valid = $this->l('A verification email has been sent. Please check your inbox.'); + if ($this->register($email, $register_status)) { + $this->valid = $this->l('You have successfully subscribed to this newsletter.'); } else { - if ($this->register($email, $register_status)) { - $this->valid = $this->l('You have successfully subscribed to this newsletter.'); + return $this->error = $this->l('An error occurred during the subscription process.'); + } + + // envoi mail code promo ou pdf + $register_status = $this->isNewsletterRegistered($email); + if ($code = Configuration::get('NW_VOUCHER_CODE') && !$cmsCategory && !$genericPdf) { + if ($this->isNewsletterCmsPsRegistered($email, 9999, $register_status)) { + $this->sendVoucher($email, Configuration::get('NW_VOUCHER_CODE')); + } + + } + // envoi le pdf de la categorie + elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory != false) { + if($this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status)){ + $this->sendConfirmationEmail($email, $cmsCategory); + $already_send = true; } else { return $this->error = $this->l('An error occurred during the subscription process.'); - } - - $register_status = $this->isNewsletterRegistered($email); - if ($code = Configuration::get('NW_VOUCHER_CODE') && !$cmsCategory && !$genericPdf) { - if ($this->isNewsletterCmsPsRegistered($email, 9999, $register_status)) { - $this->sendVoucher($email, Configuration::get('NW_VOUCHER_CODE')); - } + } - } elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory != false) { - - if($this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status)){ - $this->sendConfirmationEmail($email, $cmsCategory); - } else { - return $this->error = $this->l('An error occurred during the subscription process.'); - } - - } elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $genericPdf != false) { - $this->sendConfirmationEmail($email, false, $genericPdf); - } + } + // envoi le pdf générique + elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $genericPdf != false) { + $this->sendConfirmationEmail($email, false, $genericPdf); + $already_send = true; } + /*}*/ } + + // si pas encore envoyé j'envoi le PDF (du coup il part tout le temps) + if(!$already_send) { + $content = ''; + if (glob(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf')) { + $content = file_get_contents(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf'); + } + $genericPdf = array( + 'content' => $content, + 'name' => 'Tout-pratique.pdf', + 'mine' => 'application/pdf' + ); + $this->sendConfirmationEmail($email, false, $genericPdf); + } + } }