Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz> |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use strict; |
23 |
use warnings; |
24 |
|
25 |
use CGI qw ( -utf8 ); |
26 |
use CGI::Cookie; # need to check cookies before having CGI parse the POST request |
27 |
use C4::Koha; |
28 |
use C4::Context; |
29 |
use C4::Biblio; |
30 |
use C4::Output qw(:DEFAULT :ajax); |
31 |
use C4::Auth; |
32 |
|
33 |
sub ajax_auth_cgi { # returns CGI object |
34 |
my $needed_flags = shift; |
35 |
my %cookies = fetch CGI::Cookie; |
36 |
my $input = CGI->new; |
37 |
my $sessid = $cookies{'CGISESSID'}->value; |
38 |
my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); |
39 |
if ($auth_status ne "ok") { |
40 |
output_with_http_headers $input, undef, |
41 |
"window.alert('Your CGI session cookie ($sessid) is not current. " . |
42 |
"Please refresh the page and try again.');\n", 'js'; |
43 |
exit 0; |
44 |
} |
45 |
return $input; |
46 |
} |
47 |
|
48 |
if (is_ajax()) { |
49 |
my $input = &ajax_auth_cgi({}) || CGI->new(); |
50 |
my ($note, $js_reply); |
51 |
if ($note = $input->param('seen')) { |
52 |
$js_reply = ( markseen($note) ? 'success' : 'failure') . "_seen('$note');\n"; |
53 |
} |
54 |
output_with_http_headers $input, undef, $js_reply, 'js'; |
55 |
exit; |
56 |
} |
57 |
|
58 |
my $query = new CGI; |
59 |
|
60 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
61 |
{ |
62 |
template_name => "issue_notes/issue-notes.tt", |
63 |
query => $query, |
64 |
type => "intranet", |
65 |
authnotrequired => 0, |
66 |
flagsrequired => { circulation => 1 }, |
67 |
debug => 1, |
68 |
} |
69 |
); |
70 |
|
71 |
my @notes = get_notes(); |
72 |
my $pending_notes = Koha::Issues->search({ noteseen => 0 }); |
73 |
#my $borrower = C4::Members::GetMember( borrowernumber => $notes->{'borrowernumber'} ); |
74 |
#my $itemnumber = $notes->{'itemnumber'}; |
75 |
#my $biblio = GetBiblioFromItemNumber($itemnumber); |
76 |
$template->param( |
77 |
notes => @notes, |
78 |
pending => $pending_notes, |
79 |
# title => $biblio->{'title'}, |
80 |
# issuenote => $notes->{'note'}, |
81 |
# barcode => $biblio->{'barcode'}, |
82 |
# borrower => $borrower, |
83 |
# date => $notes->{'notedate'}, |
84 |
); |
85 |
|
86 |
|
87 |
sub get_notes { |
88 |
my $dbh = C4::Context->dbh; |
89 |
my $q = "SELECT issues.borrowernumber AS borrowernumber, |
90 |
issues.itemnumber AS itemnumber, |
91 |
issues.note AS note, |
92 |
issues.notedate AS notedate, |
93 |
issues.noteseen AS noteseen, |
94 |
borrowers.firstname AS firstname, |
95 |
borrowers.surname AS surname, |
96 |
items.barcode AS barcode, |
97 |
biblio.title AS title, |
98 |
biblio.author AS author |
99 |
FROM issues |
100 |
JOIN borrowers |
101 |
ON issues.borrowernumber = borrowers.borrowernumber |
102 |
JOIN items |
103 |
ON issues.itemnumber = items.itemnumber |
104 |
JOIN biblio |
105 |
ON items.biblionumber = biblio.biblionumber |
106 |
WHERE issues.note IS NOT NULL"; |
107 |
my $sth = $dbh->prepare($q); |
108 |
$sth->execute(); |
109 |
return $sth->fetchall_arrayref({}); |
110 |
} |
111 |
|
112 |
|
113 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |