X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=newmember.pl;h=cc0d4e264bf0e640e91d6d45c837715dd96009c5;hb=ec152517a735e6fc7e0f7d140101d79b2fd3bb91;hp=096e76314e2363584cd900de03548c53fc000192;hpb=1e67687742e36bbb90746ecdd78a0c6a63aad890;p=koha.git diff --git a/newmember.pl b/newmember.pl index 096e76314e..cc0d4e264b 100755 --- a/newmember.pl +++ b/newmember.pl @@ -1,7 +1,22 @@ #!/usr/bin/perl +# $Id$ + #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.com templating + +# 2003/01/20 acli@ada.dhs.org XXX it seems to do the following: +# * "insert" seems to do nothing; in 1.2.2 the script just returns a blank +# page (with the headers etc.) if "insert" has anything in it +# * $ok has the opposite meaning of what one expects; $ok == 1 means "not ok" +# * if ($ok == 0) considers the "ok" case; it displays a confirmation page +# for the user to "click to confirm that everything is entered correctly" +# * The "else" case for ($ok == 0) handles the "not ok" case; $string is the +# error message to display +# FIXME - What is the correct value of "flagsrequired"? +# FIXME - untranslatable strings here # Copyright 2000-2002 Katipo Communications # @@ -21,154 +36,157 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; -use C4::Output; +use C4::Auth; use C4::Input; +use C4::Interface::CGI::Output; use CGI; use Date::Manip; - +use HTML::Template; +use C4::Date; my %env; my $input = new CGI; -#get varibale that tells us whether to show confirmation page -#or insert data -my $insert=$input->param('insert'); #get rest of data my %data; my @names=$input->param; -foreach my $key (@names){ - $data{$key}=$input->param($key); -} -print $input->header; -print startpage(); -print startmenu('member'); -my $main="#99cc33"; -my $image="/images/background-mem.gif"; -if ($insert eq ''){ - my $ok=0; - #check that all compulsary fields are entered - my $string="The following compulsary fields have been left blank. Please push the back button - and try again

"; - if ($data{'cardnumber'} eq ''){ - - $string.=" Cardnumber
"; +foreach my $key (@names){ + $data{$key}=$input->param($key); +} + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "newmember.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1}, + }); + +# Check that all compulsary fields are entered +# If everything is ok, set $ok = 0 +# Otherwise set $ok = 1 and $string to the error message to display. + +my $ok=0; +my $string = "The following compulsary fields have been left blank. " + . "Please push the back button and try again

"; + +if ($data{'cardnumber'} eq ''){ + $string.=" Cardnumber
"; $ok=1; - } else { - #check cardnumber is valid - my $valid=checkdigit(\%env,$data{'cardnumber'}); - if ($valid != 1){ - $ok=1; - $string.=" Invalid Cardnumber
"; - } - } - if ($data{'sex'} eq ''){ +} else { + #check cardnumber is valid + my $valid=checkdigit(\%env,$data{'cardnumber'}); + if ($valid != 1){ + $ok=1; + $string.=" Invalid Cardnumber
"; + } +} +if ($data{'sex'} eq ''){ $string.=" Gender
"; $ok=1; - } - if ($data{'firstname'} eq ''){ +} +if ($data{'firstname'} eq ''){ $string.=" Given Names
"; $ok=1; - } - if ($data{'surname'} eq ''){ +} +if ($data{'surname'} eq ''){ $string.=" Surname
"; $ok=1; - } - if ($data{'address'} eq ''){ +} +if ($data{'address'} eq ''){ $string.=" Postal Street Address
"; $ok=1; - } - if ($data{'city'} eq ''){ +} +if ($data{'city'} eq ''){ $string.=" Postal City
"; $ok=1; - } - if ($data{'contactname'} eq ''){ +} +if ($data{'contactname'} eq ''){ $string.=" Alternate Contact
"; $ok=1; - } - #we are printing confirmation page - print mkheadr(1,'Confirm Record'); - if ($ok ==0){ - print mktablehdr; - print mktablerow(2,$main,bold('NEW MEMBER'),"",$image); - my $name=$data{'title'}." "; - if ($data{'othernames'} ne ''){ - $name.=$data{'othernames'}." "; - } else { - $name.=$data{'firstname'}." "; - } - $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})"; - print mktablerow(2,'white',bold('Name'),$name); - print mktablerow(2,$main,bold('MEMBERSHIP DETAILS'),"",$image); - print mktablerow(2,'white',bold('Membership Number'),$data{'borrowernumber'}); - print mktablerow(2,'white',bold('Cardnumber'),$data{'cardnumber'}); - print mktablerow(2,'white',bold('Membership Category'),$data{'categorycode'}); - print mktablerow(2,'white',bold('Area'),$data{'area'}); - print mktablerow(2,'white',bold('Fee'),$data{'fee'}); - if ($data{'joining'} eq ''){ - $data{'joining'}=ParseDate('today'); - $data{'joining'}=&UnixDate($data{'joining'},'%Y-%m-%d'); - } - print mktablerow(2,'white',bold('Joining Date'),$data{'joining'}); - if ($data{'expiry'} eq ''){ - $data{'expiry'}=ParseDate('in 1 year'); - $data{'expiry'}=&UnixDate($data{'expiry'},'%Y-%m-%d'); - } - print mktablerow(2,'white',bold('Expiry Date'),$data{'expiry'}); - print mktablerow(2,'white',bold('Joining Branch'),$data{'joinbranch'}); - print mktablerow(2,$main,bold('PERSONAL DETAILS'),"",$image); - my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'}; - print mktablerow(2,'white',bold('Ethnicity'),$ethnic); - $data{'dateofbirth'}=ParseDate($data{'dateofbirth'}); - $data{'dateofbirth'}=UnixDate($data{'dateofbirth'},'%Y-%m-%d'); - print mktablerow(2,'white',bold('Date of Birth'),$data{'dateofbirth'}); - my $sex; - if ($data{'sex'} eq 'M'){ - $sex="Male"; - } else { - $sex="Female"; - } - print mktablerow(2,'white',bold('Sex'),$sex); - print mktablerow(2,$main,bold('MEMBER ADDRESS'),"",$image); - my $postal=$data{'address'}."
".$data{'city'}; - my $home; - if ($data{'streetaddress'} ne ''){ - $home=$data{'streetaddress'}."
".$data{'streetcity'}; - } else { - $home=$postal; - } - print mktablerow(2,'white',bold('Postal Address'),$postal); - print mktablerow(2,'white',bold('Home Address'),$home); - print mktablerow(2,$main,bold('MEMBER CONTACT DETAILS'),"",$image); - print mktablerow(2,'white',bold('Phone (Home)'),$data{'phone'}); - print mktablerow(2,'white',bold('Phone (Daytime)'),$data{'phoneday'}); - print mktablerow(2,'white',bold('Fax'),$data{'faxnumber'}); - print mktablerow(2,'white',bold('Email'),$data{'emailaddress'}); - print mktablerow(2,$main,bold('ALTERNATIVE CONTACT DETAILS'),"",$image); - print mktablerow(2,'white',bold('Name'),$data{'contactname'}); - print mktablerow(2,'white',bold('Phone'),$data{'altphone'}); - print mktablerow(2,'white',bold('Relationship'),$data{'altrelationship'}); - print mktablerow(2,'white',bold('Notes'),$data{'altnotes'}); - print mktablerow(2,$main,bold('Notes'),"",$image); - print mktablerow(2,'white',bold('General Notes'),$data{'borrowernotes'}); - - print mktableft; - #set up form to post data thru for modification or insertion - 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/insertdata.pl",@inputs); - } else { - print $string; - } } -#print $input->dump; -print mktablehdr; +# Pass the ok/not ok status and the error message to the template +$template->param( OK=> ($ok==0), + string=> $string); + +# If things are ok, display the confirmation page +if ($ok == 0) { + my $name=$data{'title'}." "; + if ($data{'othernames'} ne ''){ + $name.=$data{'othernames'}." "; + } else { + $name.=$data{'firstname'}." "; + } + $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})"; + my $sex; + if ($data{'sex'} eq 'M'){ + $sex="Male"; + } else { + $sex="Female"; + } + if ($data{'joining'} eq ''){ + $data{'joining'}=ParseDate('today'); + $data{'joining'}=format_date($data{'joining'}); + } + if ($data{'expiry'} eq ''){ + $data{'expiry'}=ParseDate('in 1 year'); + $data{'expiry'}=format_date($data{'expiry'}); + } + my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'}; + my $postal=$data{'address'}."
".$data{'city'}; + my $home; + if ($data{'streetaddress'} ne ''){ + $home=$data{'streetaddress'}."
".$data{'streetcity'}; + } else { + $home=$postal; + } + my @inputsloop; + while (my ($key, $value) = each %data) { + $value=~ s/\"/%22/g; + my %line; + $line{'key'}=$key; + $line{'value'}=$value; + push(@inputsloop, \%line); + } + + #Get the fee + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode = ?"); + $sth->execute($data{'categorycode'}); + my ($fee) = $sth->fetchrow; + $sth->finish; + + $template->param(name => $name, + bornum => $data{'borrowernumber'}, + cardnum => $data{'cardnumber'}, + memcat => $data{'categorycode'}, + fee => $fee, + joindate => format_date($data{'joining'}), + expdate => format_date($data{'expiry'}), + branchcode => $data{'branchcode'}, + ethnic => $ethnic, + dob => format_date($data{'dateofbirth'}), + sex => $sex, + postal => $postal, + home => $home, + phone => $data{'phone'}, + phoneday => $data{'phoneday'}, + faxnumber => $data{'faxnumber'}, + emailaddress => $data{'emailaddress'}, + textmessaging => $data{'textmessaging'}, + contactname => $data{'contactname'}, + altphone => $data{'altphone'}, + altrelationship => $data{'altrelationship'}, + altnotes => $data{'altnotes'}, + bornotes => $data{'borrowernotes'}, + inputsloop => \@inputsloop); + +# If things are not ok, display the error message +} else { + # Nothing to do; the "OK" and "string" variables have already been set + ; +} + +output_html_with_http_headers $input, $cookie, $template->output; + -print mktableft; -print endmenu('member'); -print endpage();