3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
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
20 =head1 tools/letter.pl
23 this script use an $op to know what to do.
24 if $op is empty or none of the above values,
25 - the default screen is build (with all records, or filtered datas).
26 - the user can clic on add, modify or delete record.
28 - if primkey exists, this is a modification,so we read the $primkey record
29 - builds the add/modify form
31 - the user has just send datas, so we create/modify the record
33 - we show the record having primkey=$primkey and ask for deletion validation form
35 - we delete the record having primkey=$primkey
47 my ( $searchstring, $type ) = @_;
48 my $dbh = C4
::Context
->dbh;
49 $searchstring =~ s/\'/\\\'/g;
50 my @data = split( ' ', $searchstring );
54 "Select * from letter where (code like ?) order by module,code");
55 $sth->execute("$data[0]%");
59 while ( my $data = $sth->fetchrow_hashref ) {
60 push( @results, $data );
64 return ( $cnt, \
@results );
68 my $searchfield = $input->param('searchfield');
69 my $offset = $input->param('offset');
70 my $script_name = "/cgi-bin/koha/tools/letter.pl";
71 my $code = $input->param('code');
72 my $module = $input->param('module');
73 my $content = $input->param('content');
75 my $op = $input->param('op');
76 $searchfield =~ s/\,//g;
77 my $dbh = C4
::Context
->dbh;
79 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
81 template_name
=> "tools/letter.tmpl",
85 flagsrequired
=> { tools
=> 1 },
92 script_name
=> $script_name,
94 ); # we show only the TMPL_VAR names $op
98 script_name
=> $script_name,
100 ); # we show only the TMPL_VAR names $op
103 $template->param( action
=> $script_name );
104 ################## ADD_FORM ##################################
105 # called by default. Used to create form to add or modify a record
106 if ( $op eq 'add_form' ) {
108 #---- if primkey exists, it's a modify action, so read values to modify...
111 my $sth = $dbh->prepare("select * from letter where module=? and code=?");
112 $sth->execute( $module, $code );
113 $letter = $sth->fetchrow_hashref;
119 push @SQLfieldname, { 'value' => "LibrarianFirstname", 'text' => 'LibrarianFirstname' };
120 push @SQLfieldname, { 'value' => "LibrarianSurname", 'text' => 'LibrarianSurname' };
121 push @SQLfieldname, { 'value' => "LibrarianEmailaddress", 'text' => 'LibrarianEmailaddress' };
122 my $sth2 = $dbh->prepare("SHOW COLUMNS from branches");
124 push @SQLfieldname, { 'value' => "", 'text' => '---BRANCHES---' };
126 while ( ( my $field ) = $sth2->fetchrow_array ) {
127 push @SQLfieldname, { 'value' => "branches." . $field, 'text' => "branches." . $field };
130 # add acquisition specific tables
131 if ( index( $module, "acquisition" ) > 0 ) {
132 $sth2 = $dbh->prepare("SHOW COLUMNS from aqbooksellers");
134 push @SQLfieldname, { 'value' => "", 'text' => '---BOOKSELLERS---' };
135 while ( ( my $field ) = $sth2->fetchrow_array ) {
136 push @SQLfieldname, {
137 'value' => "aqbooksellers." . $field,
138 'text' => "aqbooksellers." . $field
141 $sth2 = $dbh->prepare("SHOW COLUMNS from aqorders");
143 push @SQLfieldname, { 'value' => "", 'text' => '---ORDERS---' };
144 while ( ( my $field ) = $sth2->fetchrow_array ) {
145 push @SQLfieldname, {
146 'value' => "aqorders." . $field,
147 'text' => "aqorders." . $field
151 # add issues specific tables
153 elsif ( index( $module, "issues" ) > 0 ) {
154 $sth2 = $dbh->prepare("SHOW COLUMNS from aqbooksellers");
156 push @SQLfieldname, { 'value' => "", 'text' => '---BOOKSELLERS---' };
157 while ( ( my $field ) = $sth2->fetchrow_array ) {
158 push @SQLfieldname, {
159 'value' => "aqbooksellers." . $field,
160 'text' => "aqbooksellers." . $field
163 $sth2 = $dbh->prepare("SHOW COLUMNS from serial");
165 push @SQLfieldname, { 'value' => "", 'text' => '---SERIALS---' };
166 while ( ( my $field ) = $sth2->fetchrow_array ) {
167 push @SQLfieldname, { 'value' => "serial." . $field, 'text' => "serial." . $field };
169 $sth2 = $dbh->prepare("SHOW COLUMNS from subscription");
171 push @SQLfieldname, { 'value' => "", 'text' => '---SUBSCRIPTION---' };
172 while ( ( my $field ) = $sth2->fetchrow_array ) {
173 push @SQLfieldname, {
174 'value' => "subscription." . $field,
175 'text' => "subscription." . $field
178 push @SQLfieldname, { 'value' => "", 'text' => '---Biblio---' };
179 foreach(qw(title author serial)) {
180 push @SQLfieldname, { 'value' => "biblio.$_", 'text' => ucfirst($_) };
184 $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
186 push @SQLfieldname, { 'value' => "", 'text' => '---BIBLIO---' };
188 while ( ( my $field ) = $sth2->fetchrow_array ) {
190 push @SQLfieldname, { 'value' => "biblio." . $field, 'text' => "biblio." . $field };
192 $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
194 push @SQLfieldname, { 'value' => "", 'text' => '---BIBLIOITEMS---' };
195 while ( ( my $field ) = $sth2->fetchrow_array ) {
196 push @SQLfieldname, {
197 'value' => "biblioitems." . $field,
198 'text' => "biblioitems." . $field
201 push @SQLfieldname, { 'value' => "", 'text' => '---ITEMS---' };
202 push @SQLfieldname, { 'value' => "items.content", 'text' => 'items.content' };
204 $sth2 = $dbh->prepare("SHOW COLUMNS from borrowers");
206 push @SQLfieldname, { 'value' => "", 'text' => '---BORROWERS---' };
207 while ( ( my $field ) = $sth2->fetchrow_array ) {
208 push @SQLfieldname, {
209 'value' => "borrowers." . $field,
210 'text' => "borrowers." . $field
215 $template->param( modify
=> 1 );
216 $template->param( code
=> $letter->{code
} );
219 $template->param( adding
=> 1 );
222 name
=> $letter->{name
},
223 title
=> $letter->{title
},
224 content
=> ( $content ?
$content : $letter->{content
} ),
225 ( $module ?
$module : $letter->{module
} ) => 1,
226 SQLfieldname
=> \
@SQLfieldname,
228 ################## ADD_VALIDATE ##################################
229 # called by add_form, used to insert/modify data in DB
231 elsif ( $op eq 'add_validate' ) {
232 my $dbh = C4
::Context
->dbh;
235 "replace letter (module,code,name,title,content) values (?,?,?,?,?)");
237 $input->param('module'), $input->param('code'),
238 $input->param('name'), $input->param('title'),
239 $input->param('content')
242 print $input->redirect("letter.pl");
244 ################## DELETE_CONFIRM ##################################
245 # called by default form, used to confirm deletion of data in DB
247 elsif ( $op eq 'delete_confirm' ) {
248 my $dbh = C4
::Context
->dbh;
249 my $sth = $dbh->prepare("select * from letter where code=?");
250 $sth->execute($code);
251 my $data = $sth->fetchrow_hashref;
253 $template->param( code
=> $code );
254 foreach (qw(module name content)) {
255 $template->param( $_ => $data->{$_} );
257 ################## DELETE_CONFIRMED ##################################
258 # called by delete_confirm, used to effectively confirm deletion of data in DB
260 elsif ( $op eq 'delete_confirmed' ) {
261 my $dbh = C4
::Context
->dbh;
262 my $code = uc( $input->param('code') );
263 my $module = $input->param('module');
264 my $sth = $dbh->prepare("delete from letter where module=? and code=?");
265 $sth->execute( $module, $code );
267 print $input->redirect("/cgi-bin/koha/tools/letter.pl");
269 ################## DEFAULT ##################################
272 if ( $searchfield ne '' ) {
273 $template->param( search
=> 1 );
274 $template->param( searchfield
=> $searchfield );
276 my ( $count, $results ) = StringSearch
( $searchfield, 'web' );
281 $i < ( $offset + $pagesize < $count ?
$offset + $pagesize : $count ) ;
285 $toggle = ($toggle) ?
0 : 1;
287 $row_data{toggle
} = $toggle;
288 foreach (qw(module code name)) {
289 $row_data{$_} = $results->[$i]{$_};
291 push( @loop_data, \
%row_data );
293 $template->param( letter
=> \
@loop_data );
294 } #---- END $OP eq DEFAULT
296 output_html_with_http_headers
$input, $cookie, $template->output;