From 3c7d99d60e8b0a9cfad70fd0f2e28035e8050b55 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 11 Aug 2017 05:05:31 +0000 Subject: [PATCH] Bug 4461: [FOLLOW-UP] Problem Report feature This patch: - uses a pull down menu to switch the recipient instead of tabs - if the library has no email or the administrator has no email, this error message has been moved to be down by the Submit button - includes use of branchreplyto and ReplytoDefault for branch email - disables use of the feature if the user is not logged in - adds a syspref to hide or show the feature - provides support for if JS is disabled Additional testing: - using the message_queue table, check that the correct recipient receives a problem report when switching in the drop down menu - check appropriate error message shows next to the submit button if an email is not provided. this should dynamically change as you select a different recipient from the drop down menu - check that when the library is the recipient, the feature sends the report to the branchreplyto, then the ReplytoDefault, then the branch email in that priority order - log out of the OPAC and confirm that you can't submit a report without logging in. the submit button should be disabled - disable the OPACReportProblem syspref. the Report a Problem link in the footer should be gone. if you force the URL (/cgi-bin/koha/opac-reportproblem.pl) the form should be hidden and replaced with an error message. - disable JS in your browser. confirm that you are still able to send problem reports to library and administrator. remove the administrator email address. confirm the error message shows next to the submit button and that clicking the submit button returns an error. check in the message_queue that the email was never sent. After this feature is passed: - i would like to add a staff-side feature where staff can see the problem reports and mark them as 'read'. i'll work on that once this gets through :) --- .../bug-4461_add-problem-reports-syspref.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 6 + .../bootstrap/en/includes/opac-bottom.inc | 8 +- .../bootstrap/en/modules/opac-reportproblem.tt | 132 +++++++++++---------- opac/opac-reportproblem.pl | 116 ++++++++++-------- 6 files changed, 147 insertions(+), 117 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-4461_add-problem-reports-syspref.sql diff --git a/installer/data/mysql/atomicupdate/bug-4461_add-problem-reports-syspref.sql b/installer/data/mysql/atomicupdate/bug-4461_add-problem-reports-syspref.sql new file mode 100644 index 0000000..ad8abc4 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-4461_add-problem-reports-syspref.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('OPACReportProblem', 1, NULL, "A feature for users to submit problem reports for OPAC pages.",'YesNo'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 0bd8cac..e4dc732 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -365,6 +365,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('opacreadinghistory','1','','If ON, enables display of Patron Circulation History in OPAC','YesNo'), ('OpacRenewalAllowed','0',NULL,'If ON, users can renew their issues directly from their OPAC account','YesNo'), ('OpacRenewalBranch','checkoutbranch','itemhomebranch|patronhomebranch|checkoutbranch|null','Choose how the branch for an OPAC renewal is recorded in statistics','Choice'), +('OPACReportProblem', 1, NULL, "A feature for users to submit problem reports for OPAC pages.",'YesNo'), ('OpacResetPassword','0','','Shows the ''Forgot your password?'' link in the OPAC','YesNo'), ('OPACResultsLibrary', 'homebranch', 'homebranch|holdingbranch', 'Defines whether the OPAC displays the holding or home branch in search results when using XSLT', 'Choice'), ('OPACResultsSidebar','','70|10','Define HTML to be included on the search results page, underneath the facets sidebar','Textarea'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index b6954ef..bcae28a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -345,6 +345,12 @@ OPAC: footer: "only footer" Features: - + - pref: OPACReportProblem + choices: + yes: Allow + no: "Don't allow" + - patrons to submit problem reports for OPAC pages. + - - pref: opacuserlogin choices: yes: Allow diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index 633847d..2f2f5a6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -16,9 +16,11 @@
- + [% IF ( Koha.Preference('OPACReportProblem') ) %] + + [% END %]

Powered by [% IF template.name.match('opac-main.tt') %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt index f36c745..f7c32cb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt @@ -26,92 +26,64 @@

[% END %]

Report a problem

- [% IF ( successfuladd ) %] -
Your problem report has been sent to the [% IF ( recipient == 'admin' ) %]Koha Administrator[% ELSE %] [% recipient %][% END %].
- [% END %] - [% IF ( nolibemail ) %] -
Your library has not provided an email address.
- [% END %] - [% IF ( noadminemail ) %] -
The Koha Administrator has not provided an email address.
- [% END %] - [% IF ( nolibemail && noadminemail ) %] -
Unable to send problem reports.
- [% END %] -
- -
+ [% IF ( Koha.Preference('OPACReportProblem') ) %] + [% UNLESS ( loggedinusername ) %] +
You must be logged in to send problem reports. Please log in and return to the page where you found a problem to send a problem report.
+ [% END %] + [% IF ( successfuladd ) %] +
Your problem report has been sent to the [% IF ( recipient == 'admin' ) %]Koha Administrator[% ELSE %] [% recipient %][% END %].
+ [% END %] + [% IF ( failedadd_admin ) %] +
Failed to send a problem report because the Koha Administrator has not provided an email address.
+ [% ELSIF ( failedadd_lib ) %] +
Failed to send a problem report because the library has not provided an email address.
+ [% END %] +
-
  1. - - - [% probpage | html %] -
  2. -
  3. - - - [% username | html %] -
  4. - - + +
  5. - - -
  6. -
-
-
- [% IF ( nolibemail ) %] - - [% ELSE %] - - [% END %] -
-
-
-
-
- - -
-
    -
  1. - + [% probpage | html %]
  2. - + [% username | html %] +
  3. - +
  4. - +
- [% IF ( noadminemail ) %] - + [% IF ( loggedinusername ) %] + + [% IF ( nolibemail ) %]Your library has not provided an email address.[% END %] + [% IF ( noadminemail ) %]The Koha Administrator has not provided an email address.[% END %] [% ELSE %] - + [% END %]
-
+ [% ELSE %] +
Your library has not activated this feature.
+ [% END %]
@@ -119,11 +91,43 @@ [% INCLUDE 'opac-bottom.inc' %] [% BLOCK jsinclude %] + + $("#recipient").change(function(){ + checkEmails(); + }); + function checkEmails(){ + if ( $("#recipient").val() == 'library' && nolibemail == 1 ){ + $("#submit").prop("disabled", true); + $("#nolibemail").show(); + $("#noadminemail").hide(); + } else if ( $("#recipient").val() == 'admin' && noadminemail == 1 ){ + $("#submit").prop("disabled", true); + $("#nolibemail").hide(); + $("#noadminemail").show(); + } else { + $("#submit").prop("disabled", false); + $("#nolibemail").hide(); + $("#noadminemail").hide(); + } + } + [% END %] + }); + [% END %] diff --git a/opac/opac-reportproblem.pl b/opac/opac-reportproblem.pl index b4ed191..b353d4c 100755 --- a/opac/opac-reportproblem.pl +++ b/opac/opac-reportproblem.pl @@ -27,6 +27,7 @@ use C4::Letters; use Koha::ProblemReport; use Koha::DateUtils; use Koha::Libraries; +use Koha::Patrons; my $input = new CGI; @@ -35,66 +36,81 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( template_name => "opac-reportproblem.tt", type => "opac", query => $input, - authnotrequired => 0, + authnotrequired => 1, } ); -my $problempage = $ENV{HTTP_REFERER}; -my $member = GetMember( borrowernumber => $borrowernumber ); -my $username = $member->{'userid'}; -my $branchcode = $member->{'branchcode'}; -my $library = Koha::Libraries->find($branchcode); -if ( $library->branchemail eq undef || ! $library->branchemail ) { - $template->param( nolibemail => 1 ); -} -my $koha_admin = C4::Context->preference('KohaAdminEmailAddress'); -if ( ! $koha_admin ) { - $template->param( noadminemail => 1 ); -} -my $recipient = $input->param('recipient') || 'library'; -$template->param( - username => $username, - probpage => $problempage, -); +if ( $borrowernumber ) { # if user is logged in -my $op = $input->param('op') || ''; -if ( $op eq 'addreport' ) { - my $subject = $input->param('subject'); - my $message = $input->param('message'); - my $place = $input->param('place'); - my $problem = Koha::ProblemReport->new({ title => $subject, content => $message, borrowernumber => $borrowernumber, branchcode => $branchcode, username => $username, problempage => $place, recipient => $recipient, reportdate => dt_from_string() })->store; + my $problempage = $ENV{HTTP_REFERER}; + my $member = Koha::Patrons->find( $borrowernumber ); + my $username = $member->userid; + my $branchcode = $member->branchcode; + my $library = Koha::Libraries->find($branchcode); + if ( ( !defined $library->branchreplyto ) && ( !defined C4::Context->preference('ReplytoDefault') ) && ( !defined $library->branchemail ) ) { + $template->param( nolibemail => 1 ); + } + my $koha_admin = C4::Context->preference('KohaAdminEmailAddress'); + if ( !$koha_admin ) { + $template->param( noadminemail => 1 ); + } + my $recipient = $input->param('recipient') || 'library'; $template->param( - recipient => $recipient, - successfuladd => 1, - probpage => $place, + username => $username, + probpage => $problempage, ); - my $problemreport = $problem->unblessed; - $problemreport->{code} = 'PROBLEM_REPORT'; - $problemreport->{content} .= "\nUsername: $username"; - $problemreport->{content} .= "\nProblem page: $place"; - my $transport = 'email'; + my $op = $input->param('op') || ''; + if ( $op eq 'addreport' ) { + # if user does not have JS enabled and the submit button is still enabled, the following lines ensure a report isn't submitted if the required recipient emails don't exist + if ( $recipient eq 'admin' && !$koha_admin ) { + $template->param( failedadd_admin => 1 ); + } elsif ( ( !defined $library->branchreplyto ) && ( !defined C4::Context->preference('ReplytoDefault') ) && ( !defined $library->branchemail ) ) { + $template->param( failedadd_lib => 1 ); + } else { + + my $subject = $input->param('subject'); + my $message = $input->param('message'); + my $place = $input->param('place'); + my $problem = Koha::ProblemReport->new({ title => $subject, content => $message, borrowernumber => $borrowernumber, branchcode => $branchcode, username => $username, problempage => $place, recipient => $recipient, reportdate => dt_from_string() })->store; + $template->param( + recipient => $recipient, + successfuladd => 1, + probpage => $place, + ); - my $from_address = $member->{email} || $member->{emailpro} || $member->{B_email} || $koha_admin; + my $problemreport = $problem->unblessed; + $problemreport->{code} = 'PROBLEM_REPORT'; + $problemreport->{content} .= "\nUsername: $username"; + $problemreport->{content} .= "\nProblem page: $place"; + my $transport = 'email'; - if ( $recipient eq 'admin' ) { - C4::Letters::EnqueueLetter({ - letter => $problemreport, - borrowernumber => $borrowernumber, - message_transport_type => $transport, - to_address => $koha_admin, - from_address => $from_address, - }); - } else { - my $to_address = $library->branchemail; - C4::Letters::EnqueueLetter({ - letter => $problemreport, - borrowernumber => $borrowernumber, - message_transport_type => $transport, - to_address => $to_address, - from_address => $from_address, - }); + my $from_address = $member->email || $member->emailpro || $member->B_email || $koha_admin; + + if ( $recipient eq 'admin' ) { + C4::Letters::EnqueueLetter({ + letter => $problemreport, + borrowernumber => $borrowernumber, + message_transport_type => $transport, + to_address => $koha_admin, + from_address => $from_address, + }); + } else { + my $to_address = $library->branchreplyto || C4::Context->preference('ReplytoDefault') || $library->branchemail; + C4::Letters::EnqueueLetter({ + letter => $problemreport, + borrowernumber => $borrowernumber, + message_transport_type => $transport, + to_address => $to_address, + from_address => $from_address, + }); + } + } } + +} else { # if no user logged in + my $problempage = $ENV{HTTP_REFERER}; + $template->param( probpage => $problempage ); } output_html_with_http_headers $input, $cookie, $template->output; -- 2.1.4