From e51344d4bbe5af468820f421fc24e146ba1593df Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 1 Dec 2016 00:54:07 +0000 Subject: [PATCH] [NOT READY FOR TESTING] Bug 17698: Make patron notes show up on staff dashboard Test plan will come when patch is complete Sponsored-by: Catalyst IT --- Koha/Issue.pm | 2 +- .../bug-17698_add-noteseen-column-to-issues.sql | 1 + installer/data/mysql/kohastructure.sql | 1 + issue_notes/issue-notes.pl | 113 +++++++++++++++++++++ .../prog/en/modules/circ/circulation-home.tt | 1 + .../intranet-tmpl/prog/en/modules/intranet-main.tt | 7 ++ .../prog/en/modules/issue_notes/issue-notes.tt | 57 +++++++++++ mainpage.pl | 3 + 8 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.sql create mode 100644 issue_notes/issue-notes.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/issue_notes/issue-notes.tt diff --git a/Koha/Issue.pm b/Koha/Issue.pm index dee0381..990a953 100644 --- a/Koha/Issue.pm +++ b/Koha/Issue.pm @@ -108,7 +108,7 @@ sub SetIssueNote { return; } - my $query = "UPDATE issues SET notedate=NOW(),note=? WHERE issue_id=?"; + my $query = "UPDATE issues SET notedate=NOW(),note=?,noteseen=0 WHERE issue_id=?"; my $sth = $dbh->prepare($query); return $sth->execute( $note, $issue_id ); } diff --git a/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.sql b/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.sql new file mode 100644 index 0000000..004acd1 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.sql @@ -0,0 +1 @@ +ALTER IGNORE TABLE issues ADD `noteseen` int(1) default NULL; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index a8ef821..99c085f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -861,6 +861,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues `onsite_checkout` int(1) NOT NULL default 0, -- in house use flag `note` mediumtext default NULL, -- issue note text `notedate` datetime default NULL, -- datetime of issue note (yyyy-mm-dd hh:mm::ss) + `noteseen` int(1) default NULL, -- describes whether issue note has been seen 1, not been seen 0 or doesn't exist null PRIMARY KEY (`issue_id`), KEY `issuesborridx` (`borrowernumber`), KEY `itemnumber_idx` (`itemnumber`), diff --git a/issue_notes/issue-notes.pl b/issue_notes/issue-notes.pl new file mode 100644 index 0000000..a0b6927 --- /dev/null +++ b/issue_notes/issue-notes.pl @@ -0,0 +1,113 @@ +#!/usr/bin/perl + +# Copyright 2016 Aleisha Amohia +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha 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 Koha; if not, see . + +use Modern::Perl; + +use strict; +use warnings; + +use CGI qw ( -utf8 ); +use CGI::Cookie; # need to check cookies before having CGI parse the POST request +use C4::Koha; +use C4::Context; +use C4::Biblio; +use C4::Output qw(:DEFAULT :ajax); +use C4::Auth; + +sub ajax_auth_cgi { # returns CGI object + my $needed_flags = shift; + my %cookies = fetch CGI::Cookie; + my $input = CGI->new; + my $sessid = $cookies{'CGISESSID'}->value; + my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); + if ($auth_status ne "ok") { + output_with_http_headers $input, undef, + "window.alert('Your CGI session cookie ($sessid) is not current. " . + "Please refresh the page and try again.');\n", 'js'; + exit 0; + } + return $input; +} + +if (is_ajax()) { + my $input = &ajax_auth_cgi({}) || CGI->new(); + my ($note, $js_reply); + if ($note = $input->param('seen')) { + $js_reply = ( markseen($note) ? 'success' : 'failure') . "_seen('$note');\n"; + } + output_with_http_headers $input, undef, $js_reply, 'js'; + exit; +} + +my $query = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "issue_notes/issue-notes.tt", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { circulation => 1 }, + debug => 1, + } +); + +my @notes = get_notes(); +my $pending_notes = Koha::Issues->search({ noteseen => 0 }); +#my $borrower = C4::Members::GetMember( borrowernumber => $notes->{'borrowernumber'} ); +#my $itemnumber = $notes->{'itemnumber'}; +#my $biblio = GetBiblioFromItemNumber($itemnumber); +$template->param( + notes => @notes, + pending => $pending_notes, +# title => $biblio->{'title'}, +# issuenote => $notes->{'note'}, +# barcode => $biblio->{'barcode'}, +# borrower => $borrower, +# date => $notes->{'notedate'}, +); + + +sub get_notes { + my $dbh = C4::Context->dbh; + my $q = "SELECT issues.borrowernumber AS borrowernumber, + issues.itemnumber AS itemnumber, + issues.note AS note, + issues.notedate AS notedate, + issues.noteseen AS noteseen, + borrowers.firstname AS firstname, + borrowers.surname AS surname, + items.barcode AS barcode, + biblio.title AS title, + biblio.author AS author + FROM issues + JOIN borrowers + ON issues.borrowernumber = borrowers.borrowernumber + JOIN items + ON issues.itemnumber = items.itemnumber + JOIN biblio + ON items.biblionumber = biblio.biblionumber + WHERE issues.note IS NOT NULL"; + my $sth = $dbh->prepare($q); + $sth->execute(); + return $sth->fetchall_arrayref({}); +} + + +output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt index 48f4f8d..d700ba0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt @@ -30,6 +30,7 @@
  • Fast cataloging
  • [% END %] [% END %] +
  • Issue notes
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt index 060ba39..b288d41 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -172,6 +172,13 @@ var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this news item? This [% END %] + [% IF Koha.Preference('AllowIssueNotes') && pending_issue_notes %] +
    + Issue notes pending: + [% pending_issue_notes %] +
    + [% END %] + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/issue_notes/issue-notes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/issue_notes/issue-notes.tt new file mode 100644 index 0000000..29cbf02 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/issue_notes/issue-notes.tt @@ -0,0 +1,57 @@ +[% USE Koha %] +[% USE KohaDates %] +[% USE Branches %] +[% INCLUDE 'doc-head-open.inc' %] +Home › Circulation › Issue Notes › Review Issue Notes +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables.inc' %] +[% INCLUDE 'calendar.inc' %] + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + +
    +
    +
    + +

    Issue notes

    + + [% IF ( notes ) %] + + + + + + + + + + + + + [% FOREACH note in notes %] + + + + + + + + + [% END %] + +
    NoteTitleBarcodeDateSet bySeen
    [% note.note %][% note.title %][% note.barcode %][% note.date %][% note.firstname %] [% note.surname %] ([% note.borrowernumber %])[% IF ( pending ) %][% ELSE %][% END %]
    + [% END %] + +
    +
    +
    + +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/mainpage.pl b/mainpage.pl index 7410247..b94d9b4 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -31,6 +31,7 @@ use Koha::Patron::Modifications; use Koha::Patron::Discharge; use Koha::Reviews; use Koha::ArticleRequests; +use Koha::Issues; my $query = new CGI; @@ -74,6 +75,7 @@ my $pending_article_requests = Koha::ArticleRequests->count( $branch ? ( branchcode => $branch ) : (), } ); +my $pending_issue_notes = Koha::Issues->search({ noteseen => 0 })->count; $template->param( pendingcomments => $pendingcomments, @@ -82,6 +84,7 @@ $template->param( pending_borrower_modifications => $pending_borrower_modifications, pending_discharge_requests => $pending_discharge_requests, pending_article_requests => $pending_article_requests, + pending_issue_notes => $pending_issue_notes, ); # -- 2.1.4