Initial revision
[wip/koha-chris_n.git] / newjmember.pl
1 #!/usr/bin/perl
2
3 #script to print confirmation screen, then if accepted calls itself to insert data
4
5 use strict;
6 use C4::Output;
7 use C4::Input;
8 use CGI;
9 use Date::Manip;
10
11 my %env;
12 my $input = new CGI;
13 #get varibale that tells us whether to show confirmation page
14 #or insert data
15 my $insert=$input->param('insert');
16 print $input->header;
17 #get rest of data
18 my %data;
19 my @names=$input->param;
20 foreach my $key (@names){                                                                                    
21   $data{$key}=$input->param($key);                                                                           
22 }  
23 my $ok=0;
24
25 my $string="The following compulsary fields have been left blank. Please push the back button
26 and try again<p>";                                                                                    
27 for (my $i=0;$i<3;$i++){
28   my $number=$data{"cardnumber_child_$i"};
29   my $firstname=$data{"firstname_child_$i"};
30   my $surname=$data{"surname_child_$i"};
31   my $dob=$data{"dateofbirth_child_$i"};
32   my $sex=$data{"sex_child_$i"};
33   if ($number eq ''){                                                                       
34     if ($i == 0){
35       $string.=" Cardnumber<br>";                                                                        
36       $ok=1;               
37     }
38   } else {
39     if ($firstname eq ''){                                                                         
40       $string.=" Given Names<br>";                                                                        
41       $ok=1;                                                                                              
42     }                                                                                                     
43     if ($surname eq ''){                                                                          
44       $string.=" Surname<br>";                                                                            
45       $ok=1;                                                                                              
46     }
47     if ($dob eq ''){                                                                          
48       $string.=" Date Of Birth<br>";                                                                            
49       $ok=1;                                                                                              
50     }
51     if ($sex eq ''){                                                                              
52       $string.=" Gender <br>";                                                                            
53       $ok=1;                                                                                              
54     } 
55     my $valid=checkdigit(\%env,$data{"cardnumber_child_$i"});                                                   
56     if ($valid != 1){                                                                                  
57       $ok=1;                                                                                           
58       $string.=" Invalid Cardnumber $number<br>";
59     }                                
60   }
61 }
62
63 print startpage();
64 print startmenu('member');
65
66 if ($ok == 0){
67   print mkheadr(1,'Confirm Record');
68   my $main="#99cc33";                                                                                     
69   my $image="/images/background-mem.gif"; 
70   for (my $i=0;$i<3;$i++){
71     if ($data{"cardnumber_child_$i"} ne ''){
72       print mktablehdr;                                                                                    
73       print mktablerow(2,$main,bold('NEW MEMBER'),"",$image);
74       my $name=$data{"firstname_child_$i"}.$data{"surname_child_$i"};
75       print mktablerow(2,'white',bold('Name'),$name);
76       print mktablerow(2,$main,bold('MEMBERSHIP DETAILS'),"",$image);
77       print mktablerow(2,'white',bold('Membership Number'),$data{"bornumber_child_$i"});
78       print mktablerow(2,'white',bold('Date of Birth'),$data{"dateofbirth_child_$i"});
79       my $sex;
80       if ($data{"sex_child_$i"} eq 'M'){
81          $sex="Male";
82       } else {
83          $sex="Female";
84       }
85       print mktablerow(2,'white',bold('Sex'),$sex);
86       print mktablerow(2,'white',bold('School'),$data{"school_child_$i"});
87       print mktablerow(2,'white',bold('General Notes'),$data{"altnotes_child_$i"});
88       
89       print mktableft;
90       print "<p>";
91     }
92   }
93   my $i=0;                                                                                             
94   my @inputs;                                                                                          
95   while (my ($key, $value) = each %data) {                                                             
96     $value=~ s/\"/%22/g;                                                                               
97     $inputs[$i]=["hidden","$key","$value"];                                                            
98     $i++;                                                                                              
99   }                                                                                                    
100   $inputs[$i]=["submit","submit","submit"];                                                            
101   print mkformnotable("/cgi-bin/koha/insertjdata.pl",@inputs);                                          
102   
103 } else {
104
105
106 #print $input->dump;
107 print $string;
108 }
109 print endmenu('member');
110 print endpage();