From b838eea102b3232d792c49955c10f94452215c96 Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Wed, 4 Feb 2015 15:33:52 -0500
Subject: [PATCH] Blueprint email normalization, ajax handler for blueprint.

---
 .../VuFind/src/VuFind/Controller/AjaxController.php   | 11 ++++++++++-
 themes/blueprint/templates/cart/email.phtml           |  3 +++
 themes/blueprint/templates/search/email.phtml         |  3 +++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php
index c72f6133c98..f4ace4ae512 100644
--- a/module/VuFind/src/VuFind/Controller/AjaxController.php
+++ b/module/VuFind/src/VuFind/Controller/AjaxController.php
@@ -1086,10 +1086,19 @@ class AjaxController extends AbstractBase
         // Attempt to send the email:
         try {
             $view = $this->createEmailViewModel();
-            $this->getServiceLocator()->get('VuFind\Mailer')->sendLink(
+            $mailer = $this->getServiceLocator()->get('VuFind\Mailer');
+            $mailer->sendLink(
                 $view->to, $view->from, $view->message, $url,
                 $this->getViewRenderer(), $this->params()->fromPost('subject')
             );
+            if ($this->params()->fromPost('ccself')
+                && $view->from != $view->to
+            ) {
+                $mailer->sendLink(
+                    $view->from, $view->from, $view->message, $url,
+                    $this->getViewRenderer(), $this->params()->fromPost('subject')
+                );
+            }
             return $this->output(
                 $this->translate('email_success'), self::STATUS_OK
             );
diff --git a/themes/blueprint/templates/cart/email.phtml b/themes/blueprint/templates/cart/email.phtml
index 33f8ca5d0ba..e7f3976cc32 100644
--- a/themes/blueprint/templates/cart/email.phtml
+++ b/themes/blueprint/templates/cart/email.phtml
@@ -23,4 +23,7 @@
     <textarea id="email_message" name="message" rows="3" cols="40"><?=isset($this->message) ? $this->message : ''?></textarea>
     <br/>
     <input class="button" type="submit" name="submit" value="<?=$this->transEsc('Send')?>"/>
+    <? if ($this->disableFrom && $this->userEmailInFrom): ?>
+      <input type="checkbox" id="ccme" name="ccself"/><label for="ccme"><?=$this->translate('send_email_copy_to_me'); ?></label>
+    <? endif; ?>
 </form>
diff --git a/themes/blueprint/templates/search/email.phtml b/themes/blueprint/templates/search/email.phtml
index a87c97f8d60..e026683a8e1 100644
--- a/themes/blueprint/templates/search/email.phtml
+++ b/themes/blueprint/templates/search/email.phtml
@@ -19,4 +19,7 @@
     <textarea id="email_message" name="message" rows="3" cols="40"><?=isset($this->message) ? $this->message : ''?></textarea>
     <br/>
     <input class="button" type="submit" name="submit" value="<?=$this->transEsc('Send')?>"/>
+    <? if ($this->disableFrom && $this->userEmailInFrom): ?>
+      <input type="checkbox" id="ccme" name="ccself"/><label for="ccme"><?=$this->translate('send_email_copy_to_me'); ?></label>
+    <? endif; ?>
 </form>
-- 
GitLab