html-link to the script for linking koha fields and marc-db
[koha.git] / newmember.pl
1 #!/usr/bin/perl
2
3 #script to print confirmation screen, then if accepted calls itself to insert data
4
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use C4::Output;
25 use C4::Input;
26 use CGI;
27 use Date::Manip;
28
29 my %env;
30 my $input = new CGI;
31 #get varibale that tells us whether to show confirmation page
32 #or insert data
33 my $insert=$input->param('insert');
34
35 #get rest of data
36 my %data;
37 my @names=$input->param;
38 foreach my $key (@names){                                                                                    
39   $data{$key}=$input->param($key);                                                                           
40 }  
41 print $input->header;
42 print startpage();
43 print startmenu('member');
44 my $main="#99cc33";
45 my $image="/images/background-mem.gif";
46 if ($insert eq ''){
47   my $ok=0;
48   #check that all compulsary fields are entered
49   my $string="The following compulsary fields have been left blank. Please push the back button
50   and try again<p>";
51   if ($data{'cardnumber'} eq ''){
52    
53      $string.=" Cardnumber<br>";
54     $ok=1;
55   } else {
56      #check cardnumber is valid
57      my $valid=checkdigit(\%env,$data{'cardnumber'});
58      if ($valid != 1){
59        $ok=1;
60        $string.=" Invalid Cardnumber<br>";
61      }
62   }
63   if ($data{'sex'} eq ''){
64     $string.=" Gender <br>";
65     $ok=1;
66   }
67   if ($data{'firstname'} eq ''){
68     $string.=" Given Names<br>";
69     $ok=1;
70   }
71   if ($data{'surname'} eq ''){
72     $string.=" Surname<br>";
73     $ok=1;
74   }
75   if ($data{'address'} eq ''){
76     $string.=" Postal Street Address<br>";
77     $ok=1;
78   }
79   if ($data{'city'} eq ''){
80     $string.=" Postal City<br>";
81     $ok=1;
82   }
83   if ($data{'contactname'} eq ''){
84     $string.=" Alternate Contact<br>";
85     $ok=1;
86   }
87   #we are printing confirmation page
88   print mkheadr(1,'Confirm Record');
89   if ($ok ==0){
90    print mktablehdr;
91    print mktablerow(2,$main,bold('NEW MEMBER'),"",$image);
92    my $name=$data{'title'}." ";
93    if ($data{'othernames'} ne ''){
94      $name.=$data{'othernames'}." ";
95    } else {
96      $name.=$data{'firstname'}." ";
97    }
98    $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
99    print mktablerow(2,'white',bold('Name'),$name);
100    print mktablerow(2,$main,bold('MEMBERSHIP DETAILS'),"",$image);
101    print mktablerow(2,'white',bold('Membership Number'),$data{'borrowernumber'});
102    print mktablerow(2,'white',bold('Cardnumber'),$data{'cardnumber'});
103    print mktablerow(2,'white',bold('Membership Category'),$data{'categorycode'});
104    print mktablerow(2,'white',bold('Area'),$data{'area'});
105    print mktablerow(2,'white',bold('Fee'),$data{'fee'});
106    if ($data{'joining'} eq ''){
107      $data{'joining'}=ParseDate('today');
108      $data{'joining'}=&UnixDate($data{'joining'},'%Y-%m-%d');
109    }
110    print mktablerow(2,'white',bold('Joining Date'),$data{'joining'});
111    if ($data{'expiry'} eq ''){
112      $data{'expiry'}=ParseDate('in 1 year');
113      $data{'expiry'}=&UnixDate($data{'expiry'},'%Y-%m-%d');
114    }
115    print mktablerow(2,'white',bold('Expiry Date'),$data{'expiry'});
116    print mktablerow(2,'white',bold('Joining Branch'),$data{'joinbranch'});
117    print mktablerow(2,$main,bold('PERSONAL DETAILS'),"",$image);
118    my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
119    print mktablerow(2,'white',bold('Ethnicity'),$ethnic);
120    $data{'dateofbirth'}=ParseDate($data{'dateofbirth'});
121    $data{'dateofbirth'}=UnixDate($data{'dateofbirth'},'%Y-%m-%d');
122    print mktablerow(2,'white',bold('Date of Birth'),$data{'dateofbirth'});
123    my $sex;
124    if ($data{'sex'} eq 'M'){
125      $sex="Male";
126    } else {
127      $sex="Female";
128    }
129    print mktablerow(2,'white',bold('Sex'),$sex);
130    print mktablerow(2,$main,bold('MEMBER ADDRESS'),"",$image);
131    my $postal=$data{'address'}."<br>".$data{'city'};
132    my $home;
133    if ($data{'streetaddress'} ne ''){
134      $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
135    } else {
136      $home=$postal;
137    }
138    print mktablerow(2,'white',bold('Postal Address'),$postal);
139    print mktablerow(2,'white',bold('Home Address'),$home);
140    print mktablerow(2,$main,bold('MEMBER CONTACT DETAILS'),"",$image);
141    print mktablerow(2,'white',bold('Phone (Home)'),$data{'phone'});
142    print mktablerow(2,'white',bold('Phone (Daytime)'),$data{'phoneday'});
143    print mktablerow(2,'white',bold('Fax'),$data{'faxnumber'});
144    print mktablerow(2,'white',bold('Email'),$data{'emailaddress'});
145    print mktablerow(2,$main,bold('ALTERNATIVE CONTACT DETAILS'),"",$image);
146    print mktablerow(2,'white',bold('Name'),$data{'contactname'});
147    print mktablerow(2,'white',bold('Phone'),$data{'altphone'});
148    print mktablerow(2,'white',bold('Relationship'),$data{'altrelationship'});
149    print mktablerow(2,'white',bold('Notes'),$data{'altnotes'});
150    print mktablerow(2,$main,bold('Notes'),"",$image);
151    print mktablerow(2,'white',bold('General Notes'),$data{'borrowernotes'});
152
153    print mktableft;
154    #set up form to post data thru for modification or insertion
155    my $i=0;
156    my @inputs;
157    while (my ($key, $value) = each %data) {
158      $value=~ s/\"/%22/g;
159      $inputs[$i]=["hidden","$key","$value"];       
160      $i++;
161    }
162    $inputs[$i]=["submit","submit","submit"];
163    print mkformnotable("/cgi-bin/koha/insertdata.pl",@inputs);
164   } else {
165     print $string;
166   }
167 }
168 #print $input->dump;
169
170 print mktablehdr;
171
172 print mktableft;
173 print endmenu('member');
174 print endpage();