bugfixes for biblio deletion
[koha.git] / newimember.pl
1 #!/usr/bin/perl
2 # Note: This file now uses standard 8-space tabs
3
4 # $Id$
5
6 #script to print confirmation screen,
7 #then if accepted calls itself to insert data
8 #modified 2002/12/16 by hdl@ifrance.com : Templating
9 #the "parent" is imemberentry.pl
10
11
12 # Copyright 2000-2003 Katipo Communications
13 #
14 # This file is part of Koha.
15 #
16 # Koha is free software; you can redistribute it and/or modify it under the
17 # terms of the GNU General Public License as published by the Free Software
18 # Foundation; either version 2 of the License, or (at your option) any later
19 # version.
20 #
21 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
22 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
23 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License along with
26 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
27 # Suite 330, Boston, MA  02111-1307 USA
28
29 use strict;
30 use C4::Output;
31 use C4::Input;
32 use C4::Auth;
33 use C4::Interface::CGI::Output;
34 use C4::Members;
35 use CGI;
36 use Date::Manip;
37 use HTML::Template;
38
39 my %env;
40 my $input = new CGI;
41 #get varibale that tells us whether to show confirmation page
42 #or insert data
43 my $insert=$input->param('insert');
44
45 my ($template, $loggedinuser, $cookie) = get_template_and_user({
46         template_name => "newimember.tmpl",
47         query => $input,
48         type => "intranet",
49         authnotrequired => 0,
50         flagsrequired => {borrowers => 1},
51         debug => 1,
52   });
53
54 #get rest of data
55 my %data;
56 my @names=$input->param;
57 foreach my $key (@names){
58   $data{$key}=$input->param($key);
59 }
60
61 my $missing=0;
62
63 my $string="The following compulsary fields have been left blank. Please push the back button
64 and try again<p>";
65 if ($data{'cardnumber_institution'} !~ /\S/){
66   $string.="Cardnumber<br>";
67   $missing=1;
68 }
69 if ($data{'institution_name'} !~ /\S/){
70   $string.="Institution Name<br>";
71   $missing=1;
72 }
73 if ($data{'address'} !~ /\S/){
74   $string.="Postal Address<br>";
75   $missing=1;
76 }
77 if ($data{'city'} !~ /\S/){
78   $string.="City<br>";
79   $missing=1;
80 }
81 if ($data{'contactname'} !~ /\S/){
82   $string.="Contact Name";
83   $missing=1;
84 }
85
86 $template->param( missingloop => ($missing==1));
87 $template->param( string => $string);
88 if ($missing !=1) {
89     $data{'cardnumber_institution'} = C4::Members::fixup_cardnumber
90             ($data{'cardnumber_institution'});
91
92     #check cardnumber is valid
93     my $nounique;
94     if ( $data{'type'} ne "Add" )    {
95         $nounique = 0;
96     } else {
97         $nounique = 1;
98     }
99     my $valid=checkdigit(\%env,$data{'cardnumber'}, $nounique);
100
101     $template->param( invalid => ($valid !=1));
102
103     if ($valid) {
104         my @inputs;
105         while (my ($key, $value) = each %data) {
106             push(@inputs, { 'key'       => $key,
107                             'value'     => CGI::escapeHTML($value) });
108         }
109         $template->param(inputsloop => \@inputs);
110     }
111 }
112 output_html_with_http_headers $input, $cookie, $template->output;
113
114
115 # Local Variables:
116 # tab-width: 8
117 # End: