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 my $sth=$dbh->prepare("replace letter (module,code,name,title,content) values (?,?,?,?,?)");
152 $sth->execute(map {$input->param('module')} qw(code name title content));
154 print $input->redirect("letter.pl");
156 ################## DELETE_CONFIRM ##################################
157 # called by default form, used to confirm deletion of data in DB
158 } elsif ($op eq 'delete_confirm') {
159 my $dbh = C4::Context->dbh;
160 my $sth=$dbh->prepare("select * from letter where code=?");
161 $sth->execute($code);
162 my $data=$sth->fetchrow_hashref;
164 $template->param(code => $code);
165 foreach(qw(module name content)) {
166 $template->param($_ => $data->{$_});
168 ################## DELETE_CONFIRMED ##################################
169 # called by delete_confirm, used to effectively confirm deletion of data in DB
170 } elsif ($op eq 'delete_confirmed') {
171 my $dbh = C4::Context->dbh;
172 my $code=uc($input->param('code'));
173 my $module=$input->param('module');
174 my $sth=$dbh->prepare("delete from letter where module=? and code=?");
175 $sth->execute($module,$code);
177 print $input->redirect("letter.pl");
179 ################## DEFAULT ##################################
181 if ($searchfield ne '') {
182 $template->param(search => 1);
183 $template->param(searchfield => $searchfield);
185 my ($count,$results)=StringSearch($searchfield,'web');
188 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
189 $toggle = ($toggle eq 'white') ? "#ffffcc" : "white" ;
191 $row_data{toggle} = $toggle;
192 foreach (qw(module code name)) {
193 $row_data{$_} = $results->[$i]{$_};
195 push(@loop_data, \%row_data);
197 $template->param(letter => \@loop_data);
198 } #---- END $OP eq DEFAULT
200 output_html_with_http_headers $input, $cookie, $template->output;