Moved the cardnumber generation logic out of memberentry.pl; new module
[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 # FIXME: $ok means "not ok", but $valid really means "valid"
62 my $ok=0;
63
64 my $string="The following compulsary fields have been left blank. Please push the back button
65 and try again<p>";
66 if ($data{'cardnumber_institution'} !~ /\S/){
67   $string.="Cardnumber<br>";
68   $ok=1;
69 }
70 if ($data{'institution_name'} !~ /\S/){
71   $string.="Institution Name<br>";
72   $ok=1;
73 }
74 if ($data{'address'} !~ /\S/){
75   $string.="Postal Address<br>";
76   $ok=1;
77 }
78 if ($data{'city'} !~ /\S/){
79   $string.="City<br>";
80   $ok=1;
81 }
82 if ($data{'contactname'} !~ /\S/){
83   $string.="Contact Name";
84   $ok=1;
85 }
86
87 $template->param( missingloop => ($ok==1));
88 $template->param( string => $string);
89 if ($ok !=1) {
90     $data{'cardnumber_institution'} = C4::Members::fixup_cardnumber
91             ($data{'cardnumber_institution'});
92
93     my $valid=checkdigit(\%env,$data{"cardnumber_institution"});
94
95     $template->param( invalid => ($valid !=1));
96
97     if ($valid) {
98         my @inputs;
99         while (my ($key, $value) = each %data) {
100             push(@inputs, { 'key'       => $key,
101                             'value'     => CGI::escapeHTML($value) });
102         }
103         $template->param(inputsloop => \@inputs);
104     }
105 }
106 output_html_with_http_headers $input, $cookie, $template->output;
107
108
109 # Local Variables:
110 # tab-width: 8
111 # End: