3 #script to administer the aqbudget table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
49 my ($searchstring,$type)=@_;
50 my $dbh = C4
::Context
->dbh;
51 $searchstring=~ s/\'/\\\'/g;
52 my @data=split(' ',$searchstring);
54 my $sth=$dbh->prepare("Select * from letter where (code like ?) order by module,code");
55 $sth->execute("$data[0]%");
58 while (my $data=$sth->fetchrow_hashref){
63 return ($cnt,\
@results);
67 my $searchfield=$input->param('searchfield');
68 my $offset=$input->param('offset');
69 my $script_name="/cgi-bin/koha/admin/letter.pl";
70 my $code=$input->param('code');
71 my $module = $input->param('module');
73 my $op = $input->param('op');
74 $searchfield=~ s/\,//g;
75 my $dbh = C4
::Context
->dbh;
77 my ($template, $borrowernumber, $cookie)
78 = get_template_and_user
({template_name
=> "tools/letter.tmpl",
82 flagsrequired
=> {tools
=> 1},
87 $template->param(script_name
=> $script_name, $op => 1); # we show only the TMPL_VAR names $op
89 $template->param(script_name
=> $script_name, else => 1); # we show only the TMPL_VAR names $op
92 $template->param(action
=> $script_name);
93 ################## ADD_FORM ##################################
94 # called by default. Used to create form to add or modify a record
95 if ($op eq 'add_form') {
96 #---- if primkey exists, it's a modify action, so read values to modify...
99 my $sth=$dbh->prepare("select * from letter where module=? and code=?");
100 $sth->execute($module,$code);
101 $letter=$sth->fetchrow_hashref;
106 foreach(qw(LibrarianFirstname LibrarianSurname LibrarianEmailaddress)) {
107 my %line = ('value' => $_, 'text' => $_);
108 push @SQLfieldname, \
%line;
111 foreach(qw(branches biblio biblioitems)) {
112 my $sth2=$dbh->prepare("SHOW COLUMNS from $_");
114 my %line = ('value' => "", 'text' => '---' . uc($_) . '---');
115 push @SQLfieldname, \
%line;
116 while ((my $field) = $sth2->fetchrow_array) {
117 %line = ('value' => "$_.".$field, 'text' => "$_.".$field);
118 push @SQLfieldname, \
%line;
122 my %line = ('value' => "", 'text' => '---ITEMS---');
123 push @SQLfieldname, \
%line;
124 %line = ('value' => "items.content", 'text' => 'items.content');
125 push @SQLfieldname, \
%line;
127 my $sth2=$dbh->prepare("SHOW COLUMNS from borrowers");
129 %line = ('value' => "", 'text' => '---BORROWERS---');
130 push @SQLfieldname, \
%line;
131 while ((my $field) = $sth2->fetchrow_array) {
132 %line = ('value' => "borrowers.".$field, 'text' => "borrowers.".$field);
133 push @SQLfieldname, \
%line;
136 $template->param(modify
=> 1);
137 $template->param(code
=> $letter->{code
});
139 $template->param(adding
=> 1);
141 $template->param(name
=> $letter->{name
},
142 title
=> $letter->{title
},
143 content
=> $letter->{content
},
144 $letter->{module
} => 1,
145 SQLfieldname
=> \
@SQLfieldname,);
146 # END $OP eq ADD_FORM
147 ################## ADD_VALIDATE ##################################
148 # called by add_form, used to insert/modify data in DB
149 } elsif ($op eq 'add_validate') {
150 my $dbh = C4
::Context
->dbh;
151 if ($query->param('add')){
152 # need to do an insert
153 my $sth=$dbh->prepare("INSERT INTO letter (module,code,name,title,content) VALUES (?,?,?,?,?)");
154 $sth->execute(map {$input->param('module')} qw(code name title content));
159 my $sth=$dbh->prepare("UPDATE letter SET module=?,name=?,title=?,content=? WHERE code=?");
160 $sth->execute(map {$input->param('module')} qw(name title content code));
163 print $input->redirect("letter.pl");
165 ################## DELETE_CONFIRM ##################################
166 # called by default form, used to confirm deletion of data in DB
167 } elsif ($op eq 'delete_confirm') {
168 my $dbh = C4
::Context
->dbh;
169 my $sth=$dbh->prepare("select * from letter where code=?");
170 $sth->execute($code);
171 my $data=$sth->fetchrow_hashref;
173 $template->param(code
=> $code);
174 foreach(qw(module name content)) {
175 $template->param($_ => $data->{$_});
177 ################## DELETE_CONFIRMED ##################################
178 # called by delete_confirm, used to effectively confirm deletion of data in DB
179 } elsif ($op eq 'delete_confirmed') {
180 my $dbh = C4
::Context
->dbh;
181 my $code=uc($input->param('code'));
182 my $module=$input->param('module');
183 my $sth=$dbh->prepare("delete from letter where module=? and code=?");
184 $sth->execute($module,$code);
186 print $input->redirect("letter.pl");
188 ################## DEFAULT ##################################
190 if ($searchfield ne '') {
191 $template->param(search
=> 1);
192 $template->param(searchfield
=> $searchfield);
194 my ($count,$results)=StringSearch
($searchfield,'web');
197 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
198 $toggle = ($toggle eq 'white') ?
"#ffffcc" : "white" ;
200 $row_data{toggle
} = $toggle;
201 foreach (qw(module code name)) {
202 $row_data{$_} = $results->[$i]{$_};
204 push(@loop_data, \
%row_data);
206 $template->param(letter
=> \
@loop_data);
207 } #---- END $OP eq DEFAULT
209 output_html_with_http_headers
$input, $cookie, $template->output;