Default use the pretty CSS, not the programmer one ... programmers can
[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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 require Exporter;
22 use CGI;
23
24 use C4::Output;
25 use C4::Context;
26 use C4::Auth;
27 use C4::Output;
28
29 use C4::Koha;
30
31 sub plugin_parameters {
32 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
33 return "";
34 }
35
36 sub plugin_javascript {
37 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
38 my $function_name= "328".(int(rand(100000))+1);
39 my $res="
40 <script>
41 function Focus$function_name(subfield_managed) {
42 return 1;
43 }
44
45 function Blur$function_name(subfield_managed) {
46         return 1;
47 }
48
49 function Clic$function_name(i) {
50         defaultvalue=document.f.field_value[i].value;
51         newin=window.open(\"plugin_launcher.pl?plugin_name=labs_theses.pl&cat_auth=LABTHE&index=\"+i+\"&result=\"+defaultvalue,\"unimarc field 328\",'width=700,height=700,toolbar=false,scrollbars=yes');
52
53 }
54 </script>
55 ";
56
57 return ($function_name,$res);
58 }
59
60 sub plugin {
61         my ($input) = @_;
62         my $dbh=C4::Context->dbh;
63         my $query = new CGI;
64         my $op = $query->param('op');
65         my $cat_auth=$query->param('cat_auth');
66
67         my $startfrom=$query->param('startfrom');
68         $startfrom=0 if(!defined $startfrom);
69         my ($template, $loggedinuser, $cookie);
70         my $resultsperpage;
71         my $search = $query->param('search');
72         
73         if ($op eq "do_search") {
74         
75                 $resultsperpage= $query->param('resultsperpage');
76                 $resultsperpage = 19 if(!defined $resultsperpage);
77 #               my $upperlimit=$startfrom+$resultsperpage;
78                 # builds tag and subfield arrays
79                 my $strquery = "SELECT authorised_value, lib from authorised_values where category = ? and lib like ?";
80 #               $strquery .= " LIMIT $startfrom,$upperlimit";
81                 
82                 warn 'category : '.$cat_auth.' recherche :'.$search;
83                 warn "$strquery";
84                 $search=~s/\*/%/g;
85                 my $sth = $dbh->prepare($strquery);
86                 $sth->execute($cat_auth,$search);
87                 $search=~s/%/\*/g;
88                 
89                 
90                 my @results;
91                 my $total;
92                 while (my $data = $sth->fetchrow_hashref){
93                         my $libjs=$data->{'lib'};
94                         $libjs=~s#\'#\\\'#g;
95                         my $authjs=$data->{'authorised_value'};
96                         $authjs=~s#\'#\\\'#g;
97                         push @results, {'libjs'=>$libjs,
98                                                         'lib'=>$data->{'lib'},
99                                                         'authjs'=>$authjs,
100                                                         'auth_value'=>$data->{'authorised_value'}} 
101                                                         unless (($total<$startfrom) or ($total>$startfrom+$resultsperpage));
102                         $total++;
103                 }
104                 
105                 ($template, $loggedinuser, $cookie)
106                         = get_template_and_user({template_name => "value_builder/labs_theses.tmpl",
107                                         query => $query,
108                                         type => 'intranet',
109                                         authnotrequired => 1,
110                                         debug => 1,
111                                         });
112         
113                 # multi page display gestion
114                 my $displaynext=0;
115                 my $displayprev=$startfrom;
116                 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
117                         $displaynext = 1;
118                 }
119         
120                 my @numbers = ();
121         
122                 if ($total>$resultsperpage)
123                 {
124                         for (my $i=1; (($i<$total/$resultsperpage+1) && ($i<16)); $i++)
125                         {
126                                         my $highlight=0;
127                                         ($startfrom==($i-1)) && ($highlight=1);
128                                         push @numbers, { number => $i,
129                                                 highlight => $highlight ,
130                                                 search=> $search,
131                                                 startfrom => $resultsperpage*($i-1)};
132                         }
133                 }
134         
135                 my $from = $startfrom+1;
136                 my $to;
137         
138                 if($total < (($startfrom+1)*$resultsperpage))
139                 {
140                         $to = $total;
141                 } else {
142                         $to = (($startfrom+1)*$resultsperpage);
143                 }
144                 $template->param(catresult => \@results,
145                                                 cat_auth=>$cat_auth,
146                                                 index => $query->param('index')."",
147                                                                 startfrom=> $startfrom,
148                                                                 displaynext=> $displaynext,
149                                                                 displayprev=> $displayprev,
150                                                                 resultsperpage => $resultsperpage,
151                                                                 startfromnext => $startfrom+$resultsperpage,
152                                                                 startfromprev => $startfrom-$resultsperpage,
153                                                                 search=>$search,
154                                                                 total=>$total,
155                                                                 from=>$from,
156                                                                 to=>$to,
157                                                                 numbers=>\@numbers,
158                                                                 resultlist=>1
159                                                                 );
160         
161         } else {
162                 ($template, $loggedinuser, $cookie)
163                         = get_template_and_user({template_name => "value_builder/labs_theses.tmpl",
164                                                 query => $query,
165                                                 type => "intranet",
166                                                 authnotrequired => 1,
167                                         });
168                 
169                 $template->param(
170                                                 'search'=>$query->param('search'),
171                 );
172                 $template->param(
173                                                 'index'=>''.$query->param('index')
174                 ) if ($query->param('index'));
175                 warn 'index : '.$query->param('index');
176                 $template->param(
177                                                 'cat_auth'=>$cat_auth
178                 ) if ($cat_auth);
179         }       
180         output_html_with_http_headers $query, $cookie, $template->output ;
181 }
182
183 1;