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
46 use C4::Interface::CGI::Output;
51 my ($env,$searchstring,$type)=@_;
52 my $dbh = C4::Context->dbh;
53 $searchstring=~ s/\'/\\\'/g;
54 my @data=split(' ',$searchstring);
56 my $sth=$dbh->prepare("Select * from letter where (code like ?) order by module,code");
57 $sth->execute("$data[0]%");
60 while (my $data=$sth->fetchrow_hashref){
66 return ($cnt,\@results);
70 my $searchfield=$input->param('searchfield');
71 my $offset=$input->param('offset');
72 my $script_name="/cgi-bin/koha/admin/letter.pl";
73 my $code=$input->param('code');
75 my $op = $input->param('op');
76 $searchfield=~ s/\,//g;
77 my $dbh = C4::Context->dbh;
79 my ($template, $borrowernumber, $cookie)
80 = get_template_and_user({template_name => "parameters/letter.tmpl",
84 flagsrequired => {tools => 1},
89 $template->param(script_name => $script_name,
90 $op => 1); # we show only the TMPL_VAR names $op
92 $template->param(script_name => $script_name,
93 else => 1); # we show only the TMPL_VAR names $op
96 $template->param(action => $script_name);
97 ################## ADD_FORM ##################################
98 # called by default. Used to create form to add or modify a record
99 if ($op eq 'add_form') {
100 #---- if primkey exists, it's a modify action, so read values to modify...
103 my $sth=$dbh->prepare("select * from letter where code=?");
104 $sth->execute($code);
105 $letter=$sth->fetchrow_hashref;
110 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
112 my %line = ('value' => "", 'text' => '---BIBLIO---');
113 push @SQLfieldname, \%line;
114 while ((my $field) = $sth2->fetchrow_array) {
115 my %line = ('value' => "biblio.".$field, 'text' => "biblio.".$field);
116 push @SQLfieldname, \%line;
118 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
120 my %line = ('value' => "", 'text' => '---BIBLIOITEMS---');
121 push @SQLfieldname, \%line;
122 while ((my $field) = $sth2->fetchrow_array) {
123 my %line = ('value' => "biblioitems.".$field, 'text' => "biblioitems.".$field);
124 push @SQLfieldname, \%line;
126 my %line = ('value' => "", 'text' => '---ITEMS---');
127 push @SQLfieldname, \%line;
128 my %line = ('value' => "items.content", 'text' => 'items.content');
129 push @SQLfieldname, \%line;
131 my $sth2=$dbh->prepare("SHOW COLUMNS from borrowers");
133 my %line = ('value' => "", 'text' => '---BORROWERS---');
134 push @SQLfieldname, \%line;
135 while ((my $field) = $sth2->fetchrow_array) {
136 my %line = ('value' => "borrowers.".$field, 'text' => "borrowers.".$field);
137 push @SQLfieldname, \%line;
140 $template->param(modify => 1);
141 $template->param(code => $letter->{code});
143 $template->param(adding => 1);
145 $template->param(name => $letter->{name},title => $letter->{title},
146 content => $letter->{content},
147 SQLfieldname => \@SQLfieldname,);
148 # END $OP eq ADD_FORM
149 ################## ADD_VALIDATE ##################################
150 # called by add_form, used to insert/modify data in DB
151 } elsif ($op eq 'add_validate') {
152 my $dbh = C4::Context->dbh;
153 my $sth=$dbh->prepare("replace letter (module,code,name,title,content) values (?,?,?,?,?)");
154 $sth->execute($input->param('module'),$input->param('code'),$input->param('name'),$input->param('title'),$input->param('content'));
156 print $input->redirect("letter.pl");
158 # END $OP eq ADD_VALIDATE
159 ################## DELETE_CONFIRM ##################################
160 # called by default form, used to confirm deletion of data in DB
161 } elsif ($op eq 'delete_confirm') {
162 my $dbh = C4::Context->dbh;
163 my $sth=$dbh->prepare("select * from letter where code=?");
164 $sth->execute($code);
165 my $data=$sth->fetchrow_hashref;
167 $template->param(module => $data->{module});
168 $template->param(code => $code);
169 $template->param(name => $data->{'name'});
170 $template->param(content => $data->{'content'});
171 # END $OP eq DELETE_CONFIRM
172 ################## DELETE_CONFIRMED ##################################
173 # called by delete_confirm, used to effectively confirm deletion of data in DB
174 } elsif ($op eq 'delete_confirmed') {
175 my $dbh = C4::Context->dbh;
176 my $code=uc($input->param('code'));
177 my $module=$input->param('module');
178 my $sth=$dbh->prepare("delete from letter where module=? and code=?");
179 $sth->execute($module,$code);
181 print $input->redirect("letter.pl");
183 # END $OP eq DELETE_CONFIRMED
184 ################## DEFAULT ##################################
186 if ($searchfield ne '') {
187 $template->param(search => 1);
188 $template->param(searchfield => $searchfield);
191 my ($count,$results)=StringSearch($env,$searchfield,'web');
194 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
195 if ($toggle eq 'white'){
201 $row_data{toggle} = $toggle;
202 $row_data{module} = $results->[$i]{'module'};
203 $row_data{code} = $results->[$i]{'code'};
204 $row_data{name} = $results->[$i]{'name'};
205 push(@loop_data, \%row_data);
207 $template->param(letter => \@loop_data);
208 } #---- END $OP eq DEFAULT
210 output_html_with_http_headers $input, $cookie, $template->output;