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){
64 return ($cnt,\
@results);
68 my $searchfield=$input->param('searchfield');
69 my $offset=$input->param('offset');
70 my $script_name="/cgi-bin/koha/admin/letter.pl";
71 my $code=$input->param('code');
72 my $module = $input->param('module');
74 my $op = $input->param('op');
75 $searchfield=~ s/\,//g;
76 my $dbh = C4
::Context
->dbh;
78 my ($template, $borrowernumber, $cookie)
79 = get_template_and_user
({template_name
=> "tools/letter.tmpl",
83 flagsrequired
=> {tools
=> 1},
88 $template->param(script_name
=> $script_name,
89 $op => 1); # we show only the TMPL_VAR names $op
91 $template->param(script_name
=> $script_name,
92 else => 1); # we show only the TMPL_VAR names $op
95 $template->param(action
=> $script_name);
96 ################## ADD_FORM ##################################
97 # called by default. Used to create form to add or modify a record
98 if ($op eq 'add_form') {
99 #---- if primkey exists, it's a modify action, so read values to modify...
102 my $sth=$dbh->prepare("select * from letter where module=? and code=?");
103 $sth->execute($module,$code);
104 $letter=$sth->fetchrow_hashref;
109 my %line = ('value' => "LibrarianFirstname", 'text' => 'LibrarianFirstname');
110 push @SQLfieldname, \
%line;
111 my %line = ('value' => "LibrarianSurname", 'text' => 'LibrarianSurname');
112 push @SQLfieldname, \
%line;
113 my %line = ('value' => "LibrarianEmailaddress", 'text' => 'LibrarianEmailaddress');
114 push @SQLfieldname, \
%line;
115 my $sth2=$dbh->prepare("SHOW COLUMNS from branches");
117 my %line = ('value' => "", 'text' => '---BRANCHES---');
118 push @SQLfieldname, \
%line;
119 while ((my $field) = $sth2->fetchrow_array) {
120 my %line = ('value' => "branches.".$field, 'text' => "branches.".$field);
121 push @SQLfieldname, \
%line;
123 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
125 my %line = ('value' => "", 'text' => '---BIBLIO---');
127 push @SQLfieldname, \
%line;
128 while ((my $field) = $sth2->fetchrow_array) {
129 # note : %line is redefined, otherwise \%line contains the same value for every entry of the list
130 my %line = ('value' => "biblio.".$field, 'text' => "biblio.".$field);
131 push @SQLfieldname, \
%line;
133 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
135 my %line = ('value' => "", 'text' => '---BIBLIOITEMS---');
136 push @SQLfieldname, \
%line;
137 while ((my $field) = $sth2->fetchrow_array) {
138 my %line = ('value' => "biblioitems.".$field, 'text' => "biblioitems.".$field);
139 push @SQLfieldname, \
%line;
141 my %line = ('value' => "", 'text' => '---ITEMS---');
142 push @SQLfieldname, \
%line;
143 my %line = ('value' => "items.content", 'text' => 'items.content');
144 push @SQLfieldname, \
%line;
146 my $sth2=$dbh->prepare("SHOW COLUMNS from borrowers");
148 my %line = ('value' => "", 'text' => '---BORROWERS---');
149 push @SQLfieldname, \
%line;
150 while ((my $field) = $sth2->fetchrow_array) {
151 my %line = ('value' => "borrowers.".$field, 'text' => "borrowers.".$field);
152 push @SQLfieldname, \
%line;
155 $template->param(modify
=> 1);
156 $template->param(code
=> $letter->{code
});
158 $template->param(adding
=> 1);
160 $template->param(name
=> $letter->{name
},title
=> $letter->{title
},
161 content
=> $letter->{content
},
162 $letter->{module
} => 1,
163 SQLfieldname
=> \
@SQLfieldname,);
164 # END $OP eq ADD_FORM
165 ################## ADD_VALIDATE ##################################
166 # called by add_form, used to insert/modify data in DB
167 } elsif ($op eq 'add_validate') {
168 my $dbh = C4
::Context
->dbh;
169 my $sth=$dbh->prepare("replace letter (module,code,name,title,content) values (?,?,?,?,?)");
170 $sth->execute($input->param('module'),$input->param('code'),$input->param('name'),$input->param('title'),$input->param('content'));
172 print $input->redirect("letter.pl");
174 # END $OP eq ADD_VALIDATE
175 ################## DELETE_CONFIRM ##################################
176 # called by default form, used to confirm deletion of data in DB
177 } elsif ($op eq 'delete_confirm') {
178 my $dbh = C4
::Context
->dbh;
179 my $sth=$dbh->prepare("select * from letter where code=?");
180 $sth->execute($code);
181 my $data=$sth->fetchrow_hashref;
183 $template->param(module
=> $data->{module
});
184 $template->param(code
=> $code);
185 $template->param(name
=> $data->{'name'});
186 $template->param(content
=> $data->{'content'});
187 # END $OP eq DELETE_CONFIRM
188 ################## DELETE_CONFIRMED ##################################
189 # called by delete_confirm, used to effectively confirm deletion of data in DB
190 } elsif ($op eq 'delete_confirmed') {
191 my $dbh = C4
::Context
->dbh;
192 my $code=uc($input->param('code'));
193 my $module=$input->param('module');
194 my $sth=$dbh->prepare("delete from letter where module=? and code=?");
195 $sth->execute($module,$code);
197 print $input->redirect("letter.pl");
199 # END $OP eq DELETE_CONFIRMED
200 ################## DEFAULT ##################################
202 if ($searchfield ne '') {
203 $template->param(search
=> 1);
204 $template->param(searchfield
=> $searchfield);
206 my ($count,$results)=StringSearch
($searchfield,'web');
209 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
210 if ($toggle eq 'white'){
216 $row_data{toggle
} = $toggle;
217 $row_data{module
} = $results->[$i]{'module'};
218 $row_data{code
} = $results->[$i]{'code'};
219 $row_data{name
} = $results->[$i]{'name'};
220 push(@loop_data, \
%row_data);
222 $template->param(letter
=> \
@loop_data);
223 } #---- END $OP eq DEFAULT
225 output_html_with_http_headers
$input, $cookie, $template->output;