moving fields around toCVS: ----------------------------------------------------...
[koha_fer] / newjmember.pl
index 33427d8..b538a14 100755 (executable)
@@ -4,6 +4,7 @@
 
 #script to print confirmation screen, then if accepted calls itself to insert data
 # FIXME - Yes, but what does it _do_?
+# 2002/12/18 hdl@ifrance.comTemplating
 
 # Copyright 2000-2002 Katipo Communications
 #
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
+use C4::Auth;
+use C4::Context;
 use C4::Output;
 use C4::Input;
+use C4::Interface::CGI::Output;
+use C4::Interface::CGI::Template;
+use C4::Koha;
 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 => "newjmember.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>";
@@ -53,78 +69,62 @@ for (my $i=0;$i<3;$i++){
   if ($number eq ''){
     if ($i == 0){
       $string.=" Cardnumber<br>";
-      $ok=1;
+      $missing=1;
     }
   } else {
     if ($firstname eq ''){
       $string.=" Given Names<br>";
-      $ok=1;
+      $missing=1;
     }
     if ($surname eq ''){
       $string.=" Surname<br>";
-      $ok=1;
+      $missing=1;
     }
     if ($dob eq ''){
       $string.=" Date Of Birth<br>";
-      $ok=1;
+      $missing=1;
     }
     if ($sex eq ''){
       $string.=" Gender <br>";
-      $ok=1;
+      $missing=1;
     }
     my $valid=checkdigit(\%env,$data{"cardnumber_child_$i"});
     if ($valid != 1){
-      $ok=1;
       $string.=" Invalid Cardnumber $number<br>";
+      $missing=1;
     }
   }
 }
+       my @identsloop;
+       for (my $i=0;$i<3;$i++){
+               my %ident;
+#              $ident{'main'}=$main;
+#              $ident{'image'}=$image;
+               $ident{'cardchild'}=($data{"cardnumber_child_$i"} ne '');
+               if ($data{"cardnumber_child_$i"} ne ''){
+                       my $name=$data{"firstname_child_$i"} . " " . $data{"surname_child_$i"};
+                       $ident{'name'}=$name;
+                       $ident{'bornum'}=$data{"bornumber_child_$i"};
+                       $ident{'dob'}=$data{"dateofbirth_child_$i"};
+                       ($data{"sex_child_$i"} eq 'M') ? ($ident{'sex'}="Male") : ($ident{'sex'}="Female") ;
+                       $ident{'school'}=$data{"school_child_$i"};
+                       $ident{'notes'}=$data{"altnotes_child_$i"};
+                       push(@identsloop, \%ident);
+               }
+       }
+       my @inputsloop;
+       while (my ($key, $value) = each %data) {
+               $value=~ s/\"/%22/g;
+               my %line;
+               $line{'key'}=$key;
+               $line{'value'}=$value;
+               push(@inputsloop, \%line);
+       }
 
-print startpage();
-print startmenu('member');
-
-if ($ok == 0){
-  print mkheadr(1,'Confirm Record');
-  my $main="#99cc33";
-  my $image="/images/background-mem.gif";
-  for (my $i=0;$i<3;$i++){
-    if ($data{"cardnumber_child_$i"} ne ''){
-      print mktablehdr;
-      print mktablerow(2,$main,bold('NEW MEMBER'),"",$image);
-      my $name=$data{"firstname_child_$i"}.$data{"surname_child_$i"};
-      print mktablerow(2,'white',bold('Name'),$name);
-      print mktablerow(2,$main,bold('MEMBERSHIP DETAILS'),"",$image);
-      print mktablerow(2,'white',bold('Membership Number'),$data{"bornumber_child_$i"});
-      print mktablerow(2,'white',bold('Date of Birth'),$data{"dateofbirth_child_$i"});
-      my $sex;
-      if ($data{"sex_child_$i"} eq 'M'){
-         $sex="Male";
-      } else {
-         $sex="Female";
-      }
-      print mktablerow(2,'white',bold('Sex'),$sex);
-      print mktablerow(2,'white',bold('School'),$data{"school_child_$i"});
-      print mktablerow(2,'white',bold('General Notes'),$data{"altnotes_child_$i"});
-
-      print mktableft;
-      print "<p>";
-    }
-  }
-  my $i=0;
-  my @inputs;
-  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/insertjdata.pl",@inputs);
-
-} else {
+# FIXME IF main and image are not fetched by HTML::TEMPLATE get them into identsloop
+$template->param(      NOK => ($missing==1),
+                                                               identsloop => \@identsloop,
+                                                               inputsloop => \@inputsloop,
+                                                               string => $string);
 
-
-#print $input->dump;
-print $string;
-}
-print endmenu('member');
-print endpage();
+output_html_with_http_headers $input, $cookie, $template->output;