@@ -, +, @@ --- Koha/Schema/Result/Issue.pm | 11 +- .../bug-17698_add-noteseen-column-to-issues.sql | 1 + ...-17698_add-permission-to-manage-issue-notes.sql | 1 + installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/userpermissions.sql | 1 + issue_notes/issue-notes.pl | 93 +++++----------- .../prog/en/modules/circ/circulation-home.tt | 2 +- .../intranet-tmpl/prog/en/modules/intranet-main.tt | 2 +- .../prog/en/modules/issue_notes/issue-notes.tt | 122 +++++++++++++++++++-- opac/opac-issue-note.pl | 2 +- opac/svc/patron_notes | 2 +- svc/issue_notes | 73 ++++++++++++ 12 files changed, 227 insertions(+), 84 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-issue-notes.sql create mode 100755 svc/issue_notes --- a/Koha/Schema/Result/Issue.pm +++ a/Koha/Schema/Result/Issue.pm @@ -112,6 +112,11 @@ __PACKAGE__->table("issues"); datetime_undef_if_invalid: 1 is_nullable: 1 +=head2 noteseen + + data_type: 'integer' + is_nullable: 1 + =cut __PACKAGE__->add_columns( @@ -170,6 +175,8 @@ __PACKAGE__->add_columns( datetime_undef_if_invalid => 1, is_nullable => 1, }, + "noteseen", + { data_type => "integer", is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -241,8 +248,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-01 02:20:55 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:a7FCuypwxtuE6oJjEnRJRg +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-12 02:41:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZF/YAX9BT1WrgCLUsXSqXQ __PACKAGE__->belongs_to( "borrower", --- a/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.sql +++ a/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.sql @@ -1, +1,2 @@ ALTER IGNORE TABLE issues ADD `noteseen` int(1) default NULL; +ALTER IGNORE TABLE old_issues ADD `noteseen` int(1) default NULL; --- a/installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-issue-notes.sql +++ a/installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-issue-notes.sql @@ -0,0 +1, @@ +INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'manage_issue_notes', 'Mark issue notes as seen/not seen'); --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1808,6 +1808,7 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r `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 `old_issuesborridx` (`borrowernumber`), KEY `old_issuesitemidx` (`itemnumber`), --- a/installer/data/mysql/userpermissions.sql +++ a/installer/data/mysql/userpermissions.sql @@ -5,6 +5,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'force_checkout', 'Force checkout if a limitation exists'), ( 1, 'manage_restrictions', 'Manage restrictions for accounts'), ( 1, 'self_checkout', 'Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID'), + ( 1, 'manage_issue_notes', 'Mark issue notes as seen/not seen'), ( 3, 'parameters_remaining_permissions', 'Remaining system parameters permissions'), ( 3, 'manage_circ_rules', 'Manage circulation rules'), ( 6, 'place_holds', 'Place holds for patrons'), --- a/issue_notes/issue-notes.pl +++ a/issue_notes/issue-notes.pl @@ -19,41 +19,13 @@ 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::Output; 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; -} +use C4::Biblio; +use Koha::Issues; my $query = new CGI; @@ -68,46 +40,35 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -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); +my $schema = Koha::Database->new()->schema(); +my @notes = $schema->resultset('Issue')->search({ 'me.note' => { '!=', undef } }, { prefetch => [ 'borrower', { item => 'biblionumber' } ] }); $template->param( - notes => @notes, - pending => $pending_notes, -# title => $biblio->{'title'}, -# issuenote => $notes->{'note'}, -# barcode => $biblio->{'barcode'}, -# borrower => $borrower, -# date => $notes->{'notedate'}, + notes => \@notes, ); +my $action; +foreach (qw( seen notseen )) { + $action = $_ if ( $query->param("mark_selected-$_") ); +} +$action ||= 'none'; + +my @issue_ids = $query->multi_param('issue_ids'); -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({}); +if ( $action eq 'seen' ) { + foreach my $issue_id ( @issue_ids ) { + my $issue = Koha::Issues->find($issue_id); + $issue->set({ noteseen => 1 })->store; + } +} elsif ( $action eq 'notseen' ) { + foreach my $issue_id ( @issue_ids ) { + my $issue = Koha::Issues->find($issue_id); + $issue->set({ noteseen => 0 })->store; + } } +$template->param( + selected_count => scalar(@issue_ids), + action => $action, +); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt @@ -30,7 +30,7 @@