Bug 3350 - fail on queued emails w/ no address
[koha.git] / admin / biblio_framework.pl
1 #!/usr/bin/perl
2 # NOTE: 4-character tabs
3
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)
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use warnings;
26 use CGI;
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30
31 sub StringSearch  {
32         my $dbh = C4::Context->dbh;
33         my $sth=$dbh->prepare("Select * from biblio_framework where (frameworkcode like ?) order by frameworktext");
34         $sth->execute((shift || '') . '%');
35     return $sth->fetchall_arrayref({});
36 }
37
38 my $input = new CGI;
39 my $script_name   = "/cgi-bin/koha/admin/biblio_framework.pl";
40 my $frameworkcode = $input->param('frameworkcode') || '';
41 my $offset        = $input->param('offset') || 0;
42 my $op            = $input->param('op') || '';
43 my $pagesize      = 20;
44
45 my ($template, $borrowernumber, $cookie)
46     = get_template_and_user({template_name => "admin/biblio_framework.tmpl",
47                              query => $input,
48                              type => "intranet",
49                              authnotrequired => 0,
50                              flagsrequired => {parameters => 1},
51                              debug => 1,
52                              });
53
54 $template->param( script_name  => $script_name);
55 $template->param(($op||'else') => 1);
56
57 my $dbh = C4::Context->dbh;
58 ################## ADD_FORM ##################################
59 # called by default. Used to create form to add or  modify a record
60 if ($op eq 'add_form') {
61         #start the page and read in includes
62         #---- if primkey exists, it's a modify action, so read values to modify...
63         my $data;
64         if ($frameworkcode) {
65                 my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?");
66                 $sth->execute($frameworkcode);
67                 $data=$sth->fetchrow_hashref;
68         }
69         $template->param(
70         frameworkcode => $frameworkcode,
71         frameworktext => $data->{'frameworktext'},
72     );
73                                                                                                         # END $OP eq ADD_FORM
74 ################## ADD_VALIDATE ##################################
75 # called by add_form, used to insert/modify data in DB
76 } elsif ($op eq 'add_validate') {
77     if ($input->param('modif')) {
78         my $sth=$dbh->prepare("UPDATE biblio_framework SET frameworktext=? WHERE frameworkcode=?");
79         $sth->execute($input->param('frameworktext'),$input->param('frameworkcode'));
80     } else {
81         my $sth=$dbh->prepare("INSERT into biblio_framework (frameworkcode,frameworktext) values (?,?)");
82         $sth->execute($input->param('frameworkcode'),$input->param('frameworktext'));
83     }
84         print $input->redirect($script_name);   # FIXME: unnecessary redirect
85         exit;
86                                                                                                         # END $OP eq ADD_VALIDATE
87 ################## DELETE_CONFIRM ##################################
88 # called by default form, used to confirm deletion of data in DB
89 } elsif ($op eq 'delete_confirm') {
90         # Check both categoryitem and biblioitems, see Bug 199
91     my $sth = $dbh->prepare("select count(*) as total from marc_tag_structure where frameworkcode=?");
92     $sth->execute($frameworkcode);
93     my $total = $sth->fetchrow_hashref->{total};
94
95         $sth = $dbh->prepare("select * from biblio_framework where frameworkcode=?");
96         $sth->execute($frameworkcode);
97         my $data = $sth->fetchrow_hashref;
98
99         $template->param(
100         frameworkcode => $frameworkcode,
101         frameworktext => $data->{'frameworktext'},
102         total => $total
103     );
104                                                                                                         # END $OP eq DELETE_CONFIRM
105 ################## DELETE_CONFIRMED ##################################
106 # called by delete_confirm, used to effectively confirm deletion of data in DB
107 } elsif ($op eq 'delete_confirmed') {
108     if ($frameworkcode) { 
109                 my $sth=$dbh->prepare("delete from marc_tag_structure where frameworkcode=?");
110                 $sth->execute($frameworkcode);
111                 $sth=$dbh->prepare("delete from marc_subfield_structure where frameworkcode=?");
112                 $sth->execute($frameworkcode);
113                 $sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
114                 $sth->execute($frameworkcode);
115         }
116         print $input->redirect($script_name);   # FIXME: unnecessary redirect
117         exit;
118                                                                                                         # END $OP eq DELETE_CONFIRMED
119 ################## DEFAULT ##################################
120 } else { # DEFAULT
121         my $results = StringSearch($frameworkcode);
122     my $count = scalar(@$results);
123         my @loop_data;
124         for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
125                 push @loop_data, {
126             frameworkcode => $results->[$i]{'frameworkcode'},
127             frameworktext => $results->[$i]{'frameworktext'},
128         };
129         }
130         $template->param(loop => \@loop_data);
131         if ($offset>0) {
132                 my $prevpage = $offset-$pagesize;
133                 $template->param(previous => "$script_name?offset=".$prevpage);
134         }
135         if ($offset+$pagesize<$count) {
136                 my $nextpage =$offset+$pagesize;
137                 $template->param(next => "$script_name?offset=".$nextpage);
138         }
139 } #---- END $OP eq DEFAULT
140
141 output_html_with_http_headers $input, $cookie, $template->output;
142