diff --git a/fid_bbi/config/vufind/EmailProfiles.ini b/fid_bbi/config/vufind/EmailProfiles.ini index f7427e8516dd51a8ba3ce06a2e6683607e7d1970..37d1e72ca8e8150c19a2f8a2e7fef7b3f19607fd 100644 --- a/fid_bbi/config/vufind/EmailProfiles.ini +++ b/fid_bbi/config/vufind/EmailProfiles.ini @@ -16,4 +16,15 @@ relative_path = ../../../local/config/vufind/EmailProfiles.ini ; Add DEV-specific customization after this header. ; ;##################### DO NOT DELETE THIS HEADER #################### -;#################################################################### \ No newline at end of file +;#################################################################### + +; Profile for report errors form. +[ReportErrors] +; Destination email address for reported errors. +to = fid@hab.de +to_name = "Katalog BBI" +; Return email address +from = noreply@hab.de +from_name = "Katalog BBI" +; Text snippet for email subject. +subject = "[Fehlermeldung - %s] %s" diff --git a/fid_bbi/languages/de.ini b/fid_bbi/languages/de.ini index 0a4f155d69ee0870e16f32d15968844bfd34ce97..ed3a8ea2302b305d2e14515bab869a9be35b6730 100644 --- a/fid_bbi/languages/de.ini +++ b/fid_bbi/languages/de.ini @@ -419,4 +419,11 @@ embed_searchbox_button = "Suche einbinden" embed_searchbox_help = "Folgenden HTML-Schnipsel in ihrer Website einbinden, um direkt auf %%bbi_url%% zu suchen" #15916 -bbi_error_message = "Bitte versuchen Sie es später noch einmal oder kontaktieren Sie %%system_email%%" \ No newline at end of file +bbi_error_message = "Bitte versuchen Sie es später noch einmal oder kontaktieren Sie %%system_email%%" + +; refs 15163 Report Errors in RecordView +ReportErrors ="Fehlermeldung" +report_errors_comment_blank = "Bitte beschreiben Sie den Fehler kurz." +reporterrors_response_requested = "Rückmeldung erwünscht?" +reporterrors_response_requested_subject = "Rückmeldung erwünscht" +report_errors_send_success = "Vielen Dank für Ihr Feedback." diff --git a/fid_bbi/languages/en.ini b/fid_bbi/languages/en.ini index 3fa49e10160febdf48536f13a9af8e63e5f18452..4b30e70234db7852990d6d15ca6b3b6846c8fc63 100644 --- a/fid_bbi/languages/en.ini +++ b/fid_bbi/languages/en.ini @@ -412,4 +412,11 @@ embed_searchbox_help = "Embed the following HTML snippet in your Website to sear Staff View = "Metadata" #15916 -bbi_error_message = "Please try again later or contact %%system_email%%" \ No newline at end of file +bbi_error_message = "Please try again later or contact %%system_email%%" + +; refs #15163 Report Errors in RecordView +ReportErrors ="Report Errors" +report_errors_comment_blank = "Please provide a brief error report." +reporterrors_response_requested = "Reply requested?" +reporterrors_response_requested_subject = "Reply requested" +report_errors_send_success = "Thank you for your feedback!" diff --git a/module/fid_bbi/config/module.config.php b/module/fid_bbi/config/module.config.php index c1459efb5ec490c527e21fe82b5d7f7d4f90334f..071441b40aee7dd65b8ab16a5f5c13f4cfe45172 100644 --- a/module/fid_bbi/config/module.config.php +++ b/module/fid_bbi/config/module.config.php @@ -25,12 +25,15 @@ $config = [ 'factories' => [ 'fid_bbi\Controller\FeedbackController' => 'VuFind\Controller\AbstractBaseFactory', 'fid_bbi\Controller\SearchController' => 'VuFind\Controller\AbstractBaseFactory', + 'fid_bbi\Controller\RecordController' => 'VuFind\Controller\AbstractBaseWithConfigFactory', ], 'aliases' => [ 'feedback' => 'fid_bbi\Controller\FeedbackController', 'Feedback' => 'fid_bbi\Controller\FeedbackController', 'Search' => 'fid_bbi\Controller\SearchController', 'search' => 'fid_bbi\Controller\SearchController', + 'Record' => 'fid_bbi\Controller\RecordController', + 'record' => 'fid_bbi\Controller\RecordController', ], ], 'vufind' => [ diff --git a/module/fid_bbi/src/fid_bbi/Controller/RecordController.php b/module/fid_bbi/src/fid_bbi/Controller/RecordController.php new file mode 100644 index 0000000000000000000000000000000000000000..8ca53522797856d023868fb867979bb5d192a13e --- /dev/null +++ b/module/fid_bbi/src/fid_bbi/Controller/RecordController.php @@ -0,0 +1,273 @@ +<?php +/** + * Record Controller + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * Copyright (C) Leipzig University Library 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @author André Lahmann <lahmann@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +namespace fid_bbi\Controller; + +use finc\Mailer\Mailer; +use VuFind\Exception\Mail as MailException; +use Zend\Log\LoggerAwareInterface as LoggerAwareInterface; +use Zend\Mail\Address; +use Zend\Validator\NotEmpty; +use Zend\Validator\StringLength; + +/** + * Record Controller + * + * @category VuFind + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @author André Lahmann <lahmann@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +class RecordController extends \finc\Controller\RecordController implements + LoggerAwareInterface +{ + use \VuFind\Log\LoggerAwareTrait; + + /** + * ReportErrors action - controller method + * + * @return \Zend\View\Model\ViewModel + */ + public function reportErrorsAction() + { + // Force login if necessary: + $config = $this->getConfig(); + if ((!isset($config->Mail->require_login) || $config->Mail->require_login) + && !$this->getUser() + ) { + return $this->forceLogin(); + } + + $params['email'] = null; + /* + * refs #15163: remove user data + */ +// if ($user = $this->getUser()) { +// $params['email'] = trim($user->email); +// } + + // Create view + $view = $this->createReportErrorsEmailViewModel($params); + + // Set up reCaptcha + //todo: testen! + $view->useRecaptcha = $this->recaptcha()->active('reportErrors'); + + // Process form submission + if ($this->formWasSubmitted('submit', $view->useRecaptcha)) { + // Collect the data submitted by form + $params['reply_requested'] = $view->reply_requested; + $params['email'] = !empty($view->email) ? $view->email : ''; + /* + * refs #15163: remove user data + */ +// if ($view->reply_requested) { +// if ($user) { +// $params['firstname'] = trim($user->firstname); +// $params['lastname'] = trim($user->lastname); +// } +// } + $params['comment'] = !empty($view->comment) ? $view->comment : ''; + $params['subject'] = !empty($view->subject) ? $view->subject : ''; + $params['eula'] = isset($view->eula) ? $view->eula : ''; + + // Validate data submitted by form + $validatorStrLength = new StringLength(['min' => 10]); + $validatorNotEmpty = new NotEmpty(); + + if (!$validatorStrLength->isValid($params['comment'])) { + $this->flashMessenger() + ->addMessage('report_errors_comment_blank', 'error'); + } elseif (!$validatorNotEmpty->isValid($params['eula'])) { + $this->flashMessenger() + ->addMessage('fid::error_eula_accepted', 'error'); + }else { + // All params are valid, set timestamp for current params set + $params['timestamp'] = date('d.m.Y H:i'); + + // Attempt to send the email and show an appropriate flash message: + try { + $this->sendReportErrorsEmail($params); + $this->flashMessenger()->addMessage('report_errors_send_success', 'success'); + return $this->redirectToRecord(); + } catch (MailException $e) { + $this->flashMessenger()->addMessage($e->getMessage(), 'error'); + } + } + } + + // Display the template: + $view->setTemplate('record/reporterrorsform'); + return $view; + } + + /** + * Create a new ViewModel to use as a PDA-Email form. + * + * @param array $params Parameters to pass to ViewModel constructor. + * + * @return ViewModel + */ + protected function createReportErrorsEmailViewModel($params = null) + { + // Build view: + $view = $this->createViewModel($params); + + // Send parameters back to view so form can be re-populated: + if ($this->getRequest()->isPost()) { + $view->email = $this->params()->fromPost('reporterrors_email'); + $view->reply_requested = ($this->params()->fromPost('reporterrors_checkbox') ? true : false); + $view->comment = $this->params()->fromPost('comment'); + $view->subject = $this->params()->fromPost('reporterrors_subject'); + $view->eula = $this->params()->fromPost('reporterrors_checkbox_eula'); + } + + // Collect the records metadata + $keyMethodMapper = [ + 'id' => 'getUniqueID', + 'author' => 'getDeduplicatedAuthors', + 'title' => 'getTitle', + 'title_short' => 'getShortTitle', + 'year' => 'getPublishDateSort', + 'isbn' => 'getISBNs' + ]; + $driver = $this->loadRecord(); + foreach ($keyMethodMapper as $var => $method) { + $view->$var = $driver->tryMethod($method); + } + + $view->author = !empty($view->author) ? + $this->getAuthors($view->author) : null; + + return $view; + } + + /** + * Formatted author data + * + * @param array $data author data + * + * @return array + */ + protected function getAuthors($data) + { + $formattedAuthors = []; + $types = [ + 'main', + 'secondary', + 'corporate', + 'corporate_secondary' + ]; + + foreach ($types as $type) { + if (!empty($data[$type])) { + foreach ($data[$type] as $key => $value) { + $formattedAuthors[] = $key; + } + } + } + return $formattedAuthors; + } + + /** + * Send PDA order via e-mail. + * + * @param array $params Data to be used for Email template + * + * @return void + * @throws MailException + */ + protected function sendReportErrorsEmail($params) + { + $emailProfile = $this->getEmailProfile('ReportErrors'); + $renderer = $this->getViewRenderer(); + + // Collect the records metadata + $keyMethodMapper = [ + 'id' => 'getUniqueID', + 'author' => 'getCombinedAuthors', + 'title' => 'getTitle', + 'title_short' => 'getShortTitle', + 'year' => 'getPublishDateSort', + 'isbn' => 'getISBNs' + ]; + $driver = $this->loadRecord(); + foreach ($keyMethodMapper as $var => $method) { + $params[$var] = $driver->tryMethod($method); + } + $params['driver'] = $driver; + + // Custom template for emails (html-only) + $bodyHtml = $renderer->render( + 'Email/reporterrors-html.phtml', + $params + ); + // Custom template for emails (text-only) + $bodyPlain = $renderer->render( + 'Email/reporterrors-plain.phtml', + $params + ); + + // Build the subject + $subject = (isset($emailProfile->subject)) + ? sprintf( + $emailProfile->subject, + $params['id'], + $params['subject'] + ) : $this->translate('ReportErrors'); + + // Set reply address and name if available + if ($params['reply_requested'] == true) { + $replyTo = !empty($params['email']) ? $params['email'] : $emailProfile->from; +// $replyToName +// = (isset($params['firstname']) && isset($params['lastname'])) && !empty($replyTo) +// ? $params['firstname'] . ' ' . $params['lastname'] +// : ''; +// $reply = new Address($replyTo, $replyToName); + $reply = new Address($replyTo); + } + + // Get mailer + $mailer = new Mailer( + $this->serviceLocator->get('VuFind\Mailer')->getTransport() + ); + + // Send the email + $mailer->sendTextHtml( + new Address($emailProfile->to), + new Address($emailProfile->from), + isset($reply) ? $reply : $emailProfile->from, + $subject, + $bodyHtml, + $bodyPlain + ); + } +} diff --git a/themes/fid_bbi/templates/Email/reporterrors-html.phtml b/themes/fid_bbi/templates/Email/reporterrors-html.phtml new file mode 100644 index 0000000000000000000000000000000000000000..f51e8b1e6c92eec029733b7107f0aba676f6e2e9 --- /dev/null +++ b/themes/fid_bbi/templates/Email/reporterrors-html.phtml @@ -0,0 +1,61 @@ +<?=$this->doctype('HTML5')?> +<html> +<head> + <?php /* <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> TEST IF THIS WORKS, fixme CK */ ?> + <title>Fehlermeldung durch Benutzer</title> +</head> +<body style="font-family: Arial, Verdana, sans-serif;"> +<h2 style="padding:10px 0;">Fehlermeldung durch Benutzer</h2> +<table width="800" border="0"> + <?php if ($reply_requested): ?> + <?php /*if (isset($lastname) && isset($firstname)): ?> + <tr> + <td width="30%">Name:</td> + <td width="70%"><strong><?=$lastname?>, <?=$firstname?></strong></td> + </tr> + <?php endif;*/ ?> + <?php if (isset($email)): ?> + <tr> + <td width="30%">Email:</td> + <td width="70%"><a href="mailto:<?=$email?>"><?=$email?></a></td> + </tr> + <tr> + <td width="100%" colspan="2"><strong>Um Rückmeldung wird gebeten.</strong></td> + </tr> + <?php endif; ?> + <?php endif; ?> + <?php if ($comment): ?> + <tr> + <td width="30%">Meldung des Benutzers::</td> + <td width="70%"><span style="font-size: 12px"><?=$comment?></span></td> + </tr> + <?php endif; ?> + <tr> + <td width="30%">Gemeldeter Titel:</td> + <td width="70%"> + <strong><?=$title?></strong><br/> + <?php if ($author): ?>von + <?php foreach ($author as $auth): ?> + <?=$auth?> + <?php endforeach; ?> + <?php endif; ?><br/><br/> + <?php if ($year): ?> + Erscheinungsjahr: <?=$year?> + <?php endif; ?><br/> + <?php if ($isbn): ?> + ISBN: <?=implode(', ', $isbn)?> + <?php endif; ?><br/> + <br/> + Link: <a href="<?=$this->serverUrl($this->recordLink()->getUrl($driver))?>" title="<?=$title?>"><?=$this->serverUrl($this->recordLink()->getUrl($driver))?></a><br/> + Katalog-ID: <a href="<?=$this->serverUrl($this->recordLink()->getUrl($driver))?>" + title="<?=$title?>"><?=$id?></a><br/> + </td> + </tr> + <tr valign="top"> + <td width="100%" colspan="2"> + Zeitpunkt der Meldung: <?=$timestamp?> + </td> + </tr> +</table> +</body> +</html> diff --git a/themes/fid_bbi/templates/Email/reporterrors-plain.phtml b/themes/fid_bbi/templates/Email/reporterrors-plain.phtml new file mode 100644 index 0000000000000000000000000000000000000000..98023ce3fc0fcfad33b193bf2c3e8ee3acc53b17 --- /dev/null +++ b/themes/fid_bbi/templates/Email/reporterrors-plain.phtml @@ -0,0 +1,47 @@ +<?php /* fid_bbi: copy of finc template */ ?> +== Fehlermeldung durch Benutzer == + +<?php if ($reply_requested): ?> + <?php /* if (isset($lastname) && isset($firstname)): ?> + +Name: <?=$lastname?>, <?=$firstname?> + + <?php endif;*/ ?> + <?php if (isset($email)): ?> + +Email: <?=$email?> + +Um Rückmeldung wird gebeten. + + + <?php endif; ?> +<?php endif; ?> + +Gemeldeter Titel: + +<?= $title ?> + +<?php if ($author): ?> + von <?php foreach ($author as $au): ?><?= $au ?> <?php endforeach; ?> +<?php endif; ?> + +<?php if ($year): ?> +Erscheinungsjahr: <?=$year?> +<?php endif; ?> + +<?php if ($isbn): ?> +ISBN: <?=implode(', ', $isbn)?> +<?php endif; ?> + +Link: <?= $this->serverUrl($this->recordLink()->getUrl($driver)) ?> + +------------------------------------------ + +<?php if ($comment): ?> + Meldung des Benutzers: + <?= $comment ?> +<?php endif; ?> + +------------------------------------------ + +Zeitpunkt der Meldung: <?= $timestamp ?> \ No newline at end of file diff --git a/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml b/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml index 9cb51529f5c982f826c5380bb05c1c2592e24be5..c822a09c91e03f3dc327c48f11bb3fa62aab8bf3 100644 --- a/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml +++ b/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml @@ -63,5 +63,8 @@ $cartId = $this->driver->getSourceIdentifier() . '|' . $this->driver->getUniqueI <li> <a href="<?=$this->url('record', ['action' => 'record', 'id' => $this->driver->getUniqueId()], ['force_canonical' => true])?>"><i class="fa fa-copy" aria-hidden="true"></i> <?=$this->transEsc('Permalink')?></a> </li> + <li> + <a class="feedbackLink item" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'ReportErrors')?>" rel="nofollow"><i class="fa fa-envelope" aria-hidden="true"></i> <?=$this->transEsc('ReportErrors')?></a> + </li> </ul> <!-- fid_bbi: recordDriver - DefaultRecord - toolbar - END --> diff --git a/themes/fid_bbi/templates/record/reporterrorsform.phtml b/themes/fid_bbi/templates/record/reporterrorsform.phtml new file mode 100644 index 0000000000000000000000000000000000000000..c7f0d12ba6a571a9b3f869f4ea091938892118fd --- /dev/null +++ b/themes/fid_bbi/templates/record/reporterrorsform.phtml @@ -0,0 +1,99 @@ +<!-- fid_bbi: record - reporterrorsform --> +<?php +// Set page title. +$this->headTitle($this->translate('ReportErrors')); + +// Set up breadcrumbs: +$this->layout()->breadcrumbs = '<li>' . $this->searchMemory()->getLastSearchLink($this->transEsc('Search'), '', '</li>') + . '<li>' . $this->recordLink()->getBreadcrumb($this->driver) . '</li>' + . '<li class="active">' . $this->transEsc('ReportErrors') . '</li>'; +?> +<h2><?=$this->transEsc('ReportErrors') ?>: <?=$this->escapeHtml($this->truncate($this->driver->getShortTitle() . ' ' . $this->driver->getSubTitle(), 90))?></h2> +<form name="reporterrors" method="post" action="<?=$this->recordLink()->getActionUrl($this->driver, 'ReportErrors')?>"> + <?=$this->flashmessages()?> + <?php /* fid_bbi: display some additional solr fields #15163 - GG */ ?> + <?php if (!empty($this->author)): ?> + <div class="form-group"> + <label class="control-label" for="author"><?=$this->transEsc("Authors/Corporations")?>:</label> + <input type="text" id="author" name="comment" class="form-control" disabled value="<?=implode('; ', $this->author)?>"/> + </div> + <?php endif; ?> + <?php if (!empty($this->title)): ?> + <div class="form-group"> + <label class="control-label" for="title"><?=$this->transEsc("Title")?>:</label> + <input type="text" id="title" name="title" class="form-control" disabled value="<?=$this->title?>"/> + </div> + <?php endif; ?> + <?php if (!empty($this->year)): ?> + <div class="form-group"> + <label class="control-label" for="year"><?=$this->transEsc("Dates of publication")?>:</label> + <input type="text" id="year" name="year" class="form-control" disabled value="<?=$this->year?>"/> + </div> + <?php endif; ?> + <?php if (!empty($this->isbn)): ?> + <div class="form-group"> + <label class="control-label" for="isbn"><?=$this->transEsc("ISBN")?>:</label> + <input type="text" id="isbn" name="isbn" class="form-control" disabled value="<?=implode('; ', $this->isbn)?>"/> + </div> + <?php endif; ?> + <?php if (!empty($this->id)): ?> + <div class="form-group"> + <label class="control-label" for="fincId"><?=$this->transEsc("ID")?>:</label> + <input type="text" id="fincId" name="fincId" class="form-control" disabled value="<?=$this->id?>"/> + </div> + <?php endif; ?> + <?php /* #15163 - END */ ?> + <div class="form-group"> + <label class="control-label" for="reporterrors_email"><?=$this->transEsc("Email")?>:</label> + <input type="email" id="reporterrors_email" name="reporterrors_email" class="form-control"<?php if (!empty($this->email)): ?> value="<?=$this->email?>"<?php endif; ?>/> + <div class="gutter-top gutter-btm <?php if (empty($this->email)): ?>hidden<?php endif; ?>" id="replyCheckbox"> + <label for="reporterrors_checkbox" class="control-label"><?=$this->transEsc("reporterrors_response_requested")?></label> + <input type="checkbox" id="reporterrors_checkbox" name="reporterrors_checkbox"<?=($this->reply_requested) ? ' checked' : ''?> /> + </div> + </div> + <?php /* fid_bbi: display some additional solr fields #15163 - GG */ ?> + <div class="form-group"> + <label class="control-label" for="reporterrors_subject"><?=$this->transEsc("email_subject")?>:</label> + <input type="text" id="reporterrors_subject" name="reporterrors_subject" class="form-control" <?php if (!empty($this->subject)): ?> value="<?=$this->subject?>"<?php endif; ?>/> + </div> + <?php /* #15163 - END */ ?> + <div class="form-group"> + <label class="control-label" for="comment"><?=$this->transEsc("Note")?>:</label> + <textarea id="comment" name="comment" class="form-control" required><?=(!empty($this->comment)) ? $this->comment : ''?></textarea> + </div> + <?php /* fid_bbi: display some additional solr fields #15163 - GG */ ?> + <div class="form-group eula"> + <div> + <input type="checkbox" id="reporterrors_checkbox_eula" name="reporterrors_checkbox_eula" value="1"> + <label for="reporterrors_checkbox_eula"> + <?= $this->translate("fid::policy_text") ?> + <?php $url = $this->url('fid/user/policy') ?> + <a data-lightbox href="<?= $url ?>"><?= $this->translate("fid::policy") ?></a> + <?= $this->translate("fid::terms_text") ?> + <?php $url = $this->url('fid/user/terms') ?> + <a data-lightbox href="<?= $url ?>"><?= $this->translate("fid::terms") ?></a>. + </label> + </div> + </div> + <?php /* #15163 - END */ ?> + <div class="form-group"> + <input type="submit" class="btn btn-primary" role="button" name="submit" value="<?=$this->transEsc('Send')?>"/> + </div> +</form> +<?php $script = <<<JS +$(document).ready(function () { + // show response email checkbox ReportErrors + $('input#reporterrors_email').on('keyup change', function () { + var emailcheck = /^[^0-9][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,}$/; + if (($(this).val().length > 0) && emailcheck.test($(this).val())) { + $('div#replyCheckbox').removeClass('hidden'); + } else { + $('div#replyCheckbox').addClass('hidden'); + $('input#reporterrors_checkbox').prop("checked", false); + } + }); +}); +JS; +?> +<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $script, 'SET'); ?> +<!-- fid_bbi: record - reporterrorsform - End -->