Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
no warnings 'redefine'; |
6 |
|
7 |
use CGI; |
8 |
use C4::Auth; |
9 |
use C4::Output; |
10 |
use POSIX; |
11 |
use C4::ClassSource; |
12 |
use URI::Escape; |
13 |
use Data::Dumper; |
14 |
|
15 |
sub plugin_parameters { |
16 |
my ($dbh,$record,$tagslib,$i,$tabloop) = @_; |
17 |
return ""; |
18 |
} |
19 |
|
20 |
sub plugin_javascript { |
21 |
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; |
22 |
my $function_name= "328".(int(rand(100000))+1); |
23 |
my $res=" |
24 |
<script type=\"text/javascript\"> |
25 |
//<![CDATA[ |
26 |
|
27 |
function Focus$function_name(subfield_managed) { |
28 |
return 1; |
29 |
} |
30 |
|
31 |
function Blur$function_name(subfield_managed) { |
32 |
return 1; |
33 |
} |
34 |
|
35 |
function Clic$function_name(i) { |
36 |
q = document.getElementById('$field_number'); |
37 |
window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=cn_browser.pl&popup&q=\"+q.value,\"cnbrowser\",\"width=500,height=400,toolbar=false,scrollbars=yes\"); |
38 |
|
39 |
} |
40 |
|
41 |
//]]> |
42 |
</script> |
43 |
"; |
44 |
|
45 |
return ($function_name,$res); |
46 |
} |
47 |
|
48 |
|
49 |
sub plugin { |
50 |
my ($input) = @_; |
51 |
my $cgi = new CGI; |
52 |
my $params = $cgi->Vars; |
53 |
my $results_per_page = 30; |
54 |
my $current_page = $cgi->param('page') || 1; |
55 |
|
56 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ |
57 |
template_name => "tools/cn_browser.tt", |
58 |
query => $cgi, |
59 |
type => "intranet", |
60 |
authnotrequired => 0, |
61 |
flagsrequired => { tools => 'cn_browser', catalogue => 1 }, |
62 |
}); |
63 |
|
64 |
my $cn_sort; |
65 |
|
66 |
my $dbh = C4::Context->dbh; |
67 |
my $sth; |
68 |
my @cn; |
69 |
my $query; |
70 |
my $real_limit = $results_per_page / 2; |
71 |
my $rows_lt = 999; |
72 |
my $rows_gt = 999; |
73 |
my $search; |
74 |
my $lt = ''; |
75 |
my $gt = ''; |
76 |
my $q; |
77 |
|
78 |
if ($q = $cgi->param('q')) { |
79 |
$search = $q; |
80 |
} |
81 |
if ($cgi->param('lt')) { |
82 |
$lt = $cgi->param('lt'); |
83 |
$search = $lt; |
84 |
} |
85 |
if ($cgi->param('gt')) { |
86 |
$gt = $cgi->param('gt'); |
87 |
$search = $gt; |
88 |
} |
89 |
|
90 |
#Don't show half the results of show lt or gt |
91 |
$real_limit = $results_per_page if $search ne $q; |
92 |
$cn_sort = GetClassSort(undef, undef, $search); |
93 |
my $cn_sort_q = GetClassSort(undef, undef, $q); |
94 |
|
95 |
my $red = 0; |
96 |
if ($search ne $gt) { |
97 |
my $green = 0; |
98 |
#Results before the cn_sort |
99 |
$query = "SELECT b.title, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author |
100 |
FROM items AS i |
101 |
JOIN biblio AS b USING (biblionumber) |
102 |
LEFT OUTER JOIN branches ON (branches.branchcode = homebranch) |
103 |
WHERE cn_sort < '$cn_sort' |
104 |
AND itemcallnumber != '' |
105 |
ORDER BY cn_sort DESC, itemnumber |
106 |
LIMIT $real_limit;"; |
107 |
$sth = $dbh->prepare($query); |
108 |
$sth->execute(); |
109 |
while ( my $data = $sth->fetchrow_hashref ) { |
110 |
if ($data->{itemcallnumber} eq $q) { |
111 |
$data->{background} = 'red'; |
112 |
$red = 1; |
113 |
} |
114 |
elsif (($data->{cn_sort} lt $cn_sort_q) && !$green && !$red) { |
115 |
if ($#cn != -1) { |
116 |
unshift @cn, {'background' => 'green'}; |
117 |
} |
118 |
$green = 1; |
119 |
} |
120 |
unshift @cn, $data; |
121 |
} |
122 |
$rows_lt = $sth->rows; |
123 |
$sth->finish; |
124 |
} |
125 |
|
126 |
if ($search ne $lt) { |
127 |
my $green = 0; |
128 |
#Results after the cn_sort |
129 |
$query = "SELECT b.title, itemcallnumber, biblionumber, i.cn_sort, branchname, author |
130 |
FROM items AS i |
131 |
JOIN biblio AS b USING (biblionumber) |
132 |
LEFT OUTER JOIN branches ON (branches.branchcode = homebranch) |
133 |
WHERE i.cn_sort >= '$cn_sort' |
134 |
AND itemcallnumber != '' |
135 |
ORDER BY cn_sort, itemnumber |
136 |
LIMIT $real_limit"; |
137 |
$sth = $dbh->prepare($query); |
138 |
$sth->execute(); |
139 |
while ( my $data = $sth->fetchrow_hashref ) { |
140 |
if ($data->{itemcallnumber} eq $q) { |
141 |
$data->{background} = 'red'; |
142 |
$red = 1; |
143 |
} |
144 |
elsif (($data->{cn_sort} gt $cn_sort_q) && !$green && !$red) { |
145 |
push @cn, {'background' => 'green'}; |
146 |
$green = 1; |
147 |
} |
148 |
push @cn, $data; |
149 |
} |
150 |
$rows_gt = $sth->rows; |
151 |
if ($rows_gt == 0 && !$green && !$red){ |
152 |
push @cn, {'background' => 'green'}; |
153 |
} |
154 |
|
155 |
$sth->finish; |
156 |
} |
157 |
|
158 |
$template->param('q' => $q); |
159 |
$template->param('cn_loop' => \@cn) if $#cn != -1; |
160 |
$template->param('popup' => defined($cgi->param('popup'))); |
161 |
|
162 |
|
163 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
164 |
} |
165 |
|
166 |
1; |