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