remove a bunch of unconditional debug warns
[koha.git] / cataloguing / value_builder / labs_theses.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 #use warnings; FIXME - Bug 2505
22
23 use CGI;
24
25 use C4::Output;
26 use C4::Context;
27 use C4::Auth;
28 use C4::Output;
29
30 use C4::Koha;
31
32 sub plugin_parameters {
33 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
34 return "";
35 }
36
37 sub plugin_javascript {
38 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
39 my $function_name= "328".(int(rand(100000))+1);
40 my $res="
41 <script type=\"text/javascript\">
42 //<![CDATA[
43
44 function Focus$function_name(subfield_managed) {
45 return 1;
46 }
47
48 function Blur$function_name(subfield_managed) {
49         return 1;
50 }
51
52 function Clic$function_name(i) {
53         defaultvalue=document.f.field_value[i].value;
54         newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=labs_theses.pl&cat_auth=LABTHE&index=\"+i+\"&result=\"+defaultvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
55
56 }
57 //]]>
58 </script>
59 ";
60
61 return ($function_name,$res);
62 }
63
64 sub plugin {
65         my ($input) = @_;
66         my $dbh=C4::Context->dbh;
67         my $query = new CGI;
68         my $op = $query->param('op');
69         my $cat_auth=$query->param('cat_auth');
70
71         my $startfrom=$query->param('startfrom');
72         $startfrom=0 if(!defined $startfrom);
73         my ($template, $loggedinuser, $cookie);
74         my $resultsperpage;
75         my $search = $query->param('search');
76
77         if ($op eq "do_search") {
78
79                 $resultsperpage= $query->param('resultsperpage');
80                 $resultsperpage = 19 if(!defined $resultsperpage);
81 #               my $upperlimit=$startfrom+$resultsperpage;
82                 # builds tag and subfield arrays
83                 my $strquery = "SELECT authorised_value, lib from authorised_values where category = ? and lib like ?";
84 #               $strquery .= " LIMIT $startfrom,$upperlimit";
85
86                 $search=~s/\*/%/g;
87                 my $sth = $dbh->prepare($strquery);
88                 $sth->execute($cat_auth,$search);
89                 $search=~s/%/\*/g;
90
91
92                 my @results;
93                 my $total;
94                 while (my $data = $sth->fetchrow_hashref){
95                         my $libjs=$data->{'lib'};
96                         $libjs=~s#\'#\\\'#g;
97                         my $authjs=$data->{'authorised_value'};
98                         $authjs=~s#\'#\\\'#g;
99                         push @results, {'libjs'=>$libjs,
100                                                         'lib'=>$data->{'lib'},
101                                                         'authjs'=>$authjs,
102                                                         'auth_value'=>$data->{'authorised_value'}}
103                                                         unless (($total<$startfrom) or ($total>$startfrom+$resultsperpage));
104                         $total++;
105                 }
106
107                 ($template, $loggedinuser, $cookie)
108                         = get_template_and_user({template_name => "value_builder/labs_theses.tmpl",
109                                         query => $query,
110                                         type => 'intranet',
111                                         authnotrequired => 1,
112                                         debug => 1,
113                                         });
114
115                 # multi page display gestion
116                 my $displaynext=0;
117                 my $displayprev=$startfrom;
118                 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
119                         $displaynext = 1;
120                 }
121
122                 my @numbers = ();
123
124                 if ($total>$resultsperpage)
125                 {
126                         for (my $i=1; (($i<$total/$resultsperpage+1) && ($i<16)); $i++)
127                         {
128                                         my $highlight=0;
129                                         ($startfrom==($i-1)) && ($highlight=1);
130                                         push @numbers, { number => $i,
131                                                 highlight => $highlight ,
132                                                 search=> $search,
133                                                 startfrom => $resultsperpage*($i-1)};
134                         }
135                 }
136
137                 my $from = $startfrom+1;
138                 my $to;
139
140                 if($total < (($startfrom+1)*$resultsperpage))
141                 {
142                         $to = $total;
143                 } else {
144                         $to = (($startfrom+1)*$resultsperpage);
145                 }
146                 $template->param(catresult => \@results,
147                                                 cat_auth=>$cat_auth,
148                                                 index => $query->param('index')."",
149                                                                 startfrom=> $startfrom,
150                                                                 displaynext=> $displaynext,
151                                                                 displayprev=> $displayprev,
152                                                                 resultsperpage => $resultsperpage,
153                                                                 startfromnext => $startfrom+$resultsperpage,
154                                                                 startfromprev => $startfrom-$resultsperpage,
155                                                                 search=>$search,
156                                                                 total=>$total,
157                                                                 from=>$from,
158                                                                 to=>$to,
159                                                                 numbers=>\@numbers,
160                                                                 resultlist=>1
161                                                                 );
162
163         } else {
164                 ($template, $loggedinuser, $cookie)
165                         = get_template_and_user({template_name => "value_builder/labs_theses.tmpl",
166                                                 query => $query,
167                                                 type => "intranet",
168                                                 authnotrequired => 1,
169                                         });
170
171                 $template->param(
172                                                 'search'=>$query->param('search'),
173                 );
174                 $template->param(
175                                                 'index'=>''.$query->param('index')
176                 ) if ($query->param('index'));
177                 $template->param(
178                                                 'cat_auth'=>$cat_auth
179                 ) if ($cat_auth);
180         }
181         output_html_with_http_headers $query, $cookie, $template->output ;
182 }
183
184 1;