road to 1.9.2 :
[koha_gimpoz] / newimember.pl
index 271b250..e24f947 100755 (executable)
@@ -1,11 +1,15 @@
 #!/usr/bin/perl
+# Note: This file now uses standard 8-space tabs
 
 # $Id$
 
-#script to print confirmation screen, then if accepted calls itself to insert data
+#script to print confirmation screen,
+#then if accepted calls itself to insert data
+#modified 2002/12/16 by hdl@ifrance.com : Templating
+#the "parent" is imemberentry.pl
 
 
-# Copyright 2000-2002 Katipo Communications
+# Copyright 2000-2003 Katipo Communications
 #
 # This file is part of Koha.
 #
 use strict;
 use C4::Output;
 use C4::Input;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Members;
 use CGI;
 use Date::Manip;
+use HTML::Template;
 
 my %env;
 my $input = new CGI;
 #get varibale that tells us whether to show confirmation page
 #or insert data
 my $insert=$input->param('insert');
-print $input->header;
+
+my ($template, $loggedinuser, $cookie) = get_template_and_user({
+       template_name => "newimember.tmpl",
+       query => $input,
+       type => "intranet",
+       authnotrequired => 0,
+       flagsrequired => {borrowers => 1},
+       debug => 1,
+  });
+
 #get rest of data
 my %data;
 my @names=$input->param;
 foreach my $key (@names){
   $data{$key}=$input->param($key);
 }
-my $ok=0;
+
+my $missing=0;
 
 my $string="The following compulsary fields have been left blank. Please push the back button
 and try again<p>";
-if ($data{'cardnumber_institution'} eq ''){
+if ($data{'cardnumber_institution'} !~ /\S/){
   $string.="Cardnumber<br>";
-  $ok=1;
+  $missing=1;
 }
-if ($data{'institution_name'} eq ''){
+if ($data{'institution_name'} !~ /\S/){
   $string.="Institution Name<br>";
-  $ok=1;
+  $missing=1;
 }
-if ($data{'address'} eq ''){
+if ($data{'address'} !~ /\S/){
   $string.="Postal Address<br>";
-  $ok=1;
+  $missing=1;
 }
-if ($data{'city'} eq ''){
+if ($data{'city'} !~ /\S/){
   $string.="City<br>";
-  $ok=1;
+  $missing=1;
 }
-if ($data{'contactname'} eq ''){
+if ($data{'contactname'} !~ /\S/){
   $string.="Contact Name";
-  $ok=1;
+  $missing=1;
 }
-#print $input->Dump;
-#print $string;
-print startmenu('member');
-if ($ok ==1){
-  print $string;
-} else {
-  my $valid=checkdigit(\%env,$data{"cardnumber_institution"});
-  if ($valid != 1){
-    print "Invalid cardnumber";
-  } else {
-
-     my @inputs;
-     my $i=0;
-     while (my ($key, $value) = each %data) {
-       $value=~ s/\"/%22/g;
-       $inputs[$i]=["hidden","$key","$value"];
-       $i++;
-     }
-     $inputs[$i]=["submit","submit","submit"];
-     print mkformnotable("/cgi-bin/koha/insertidata.pl",@inputs);
-  }
+
+$template->param( missingloop => ($missing==1));
+$template->param( string => $string);
+if ($missing !=1) {
+    $data{'cardnumber_institution'} = C4::Members::fixup_cardnumber
+           ($data{'cardnumber_institution'});
+
+    my $valid=checkdigit(\%env,$data{"cardnumber_institution"});
+
+    $template->param( invalid => ($valid !=1));
+
+    if ($valid) {
+       my @inputs;
+       while (my ($key, $value) = each %data) {
+           push(@inputs, { 'key'       => $key,
+                           'value'     => CGI::escapeHTML($value) });
+       }
+       $template->param(inputsloop => \@inputs);
+    }
 }
-print endmenu('member');
-print endpage();
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+# Local Variables:
+# tab-width: 8
+# End: