Patch from Joe Atzberger to remove $Id$ and $Log$ from scripts
[koha.git] / members / memberentry.pl
1 #!/usr/bin/perl
2
3 # Copyright 2006 SAN OUEST PROVENCE et Paul POULAIN
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 # pragma
21 use strict;
22
23 # external modules
24 use Date::Calc qw/Today/;
25 use CGI;
26 use Digest::MD5 qw(md5_base64);
27
28 # internal modules
29 use C4::Auth;
30 use C4::Context;
31 use C4::Output;
32 use C4::Members;
33 use C4::Koha;
34 use C4::Dates;
35 use C4::Input;
36 use C4::Log;
37 use C4::Branch; # GetBranches
38
39 my $input = new CGI;
40 my %data;
41
42 my $dbh = C4::Context->dbh;
43
44 <<<<<<< HEAD:members/memberentry.pl
45
46
47 =======
48 my $step=$input->param('step') || 0;
49 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
50 my ($template, $loggedinuser, $cookie)
51     = get_template_and_user({template_name => "members/memberentrygen.tmpl",
52            query => $input,
53            type => "intranet",
54            authnotrequired => 0,
55            flagsrequired => {borrowers => 1},
56            debug => 1,
57            });
58 my $guarantorid=$input->param('guarantorid');
59 my $borrowernumber=$input->param('borrowernumber');
60 my $actionType=$input->param('actionType') || '';
61 my $modify=$input->param('modify');
62 my $delete=$input->param('delete');
63 my $op=$input->param('op');
64 my $destination=$input->param('destination');
65 my $cardnumber=$input->param('cardnumber');
66 my $check_member=$input->param('check_member');
67 my $name_city=$input->param('name_city');
68 my $nodouble=$input->param('nodouble');
69 my $select_city=$input->param('select_city');
70 my $nok=$input->param('nok');
71 my $guarantorinfo=$input->param('guarantorinfo');
72 my $step=$input->param('step') || 0;
73 my @errors;
74 my $default_city;
75 # $check_categorytype contains the value of duplicate borrowers category type to redirect in good template in step =2
76 my $check_categorytype=$input->param('check_categorytype');
77 # NOTE: Alert for ethnicity and ethnotes fields, they are unvalided in all borrowers form
78 my $borrower_data;
79
80 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
81
82 #function  to automatic setup the mandatory  fields (visual with css)
83 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
84 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
85 foreach (@field_check) {
86                 $template->param( "mandatory$_" => 1);    
87 }
88 $template->param(   "add"  => 1) if (  $op eq 'add');
89 $template->param("checked" => 1) if ($nodouble eq 1);
90 my $categorycode=$input->param('categorycode');
91 ($borrower_data=GetMember($borrowernumber,'borrowernumber')) if ($op eq 'modify' or $op eq 'save');
92 $categorycode=$borrower_data->{'categorycode'} unless $categorycode;
93 my $category_type = $input->param('category_type');
94 unless ($category_type or !($categorycode)){
95   my $borrowercategory= GetBorrowercategory($categorycode);
96   $category_type = $borrowercategory->{'category_type'};
97 }
98 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
99
100 # if a add or modify is requested => check validity of data.
101 %data= %$borrower_data if ($borrower_data);
102
103 my %newdata;
104 if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') {
105     my @names= ($borrower_data && $op ne 'save') ? keys %$borrower_data : $input->param();
106     foreach my $key (@names) {
107         $newdata{$key} = $input->param($key) if ($input->param($key));
108         $newdata{$key} =~ s/\"/&quot;/gg unless ($key eq 'borrowernotes' or $key eq 'opacnote');
109     }
110     $newdata{'dateenrolled'}=format_date_in_iso($newdata{'dateenrolled'}) if ($newdata{dateenrolled});  
111     $newdata{'dateexpiry'}=format_date_in_iso($newdata{'dateexpiry'}) if ($newdata{dateexpiry});  
112     $newdata{'dateofbirth'}=format_date_in_iso($newdata{'dateofbirth'}) if ($newdata{dateofbirth});  
113 }
114
115 <<<<<<< HEAD:members/memberentry.pl
116 #############test for member being unique #############
117 if ($op eq 'insert'){
118         my $category_type_send=$category_type if ($category_type eq 'I'); 
119         my $check_category; # recover the category code of the doublon suspect borrowers
120         ($check_member,$check_category)= checkuniquemember($category_type_send,($newdata{'surname'}?$newdata{'surname'}:$data{'surname'}),($newdata{'firstname'}?$newdata{'firstname'}:$data{'firstname'}),($newdata{'dateofbirth'}?$newdata{'dateofbirth'}:$data{'dateofbirth'}));
121 =======
122
123   # WARN : some tests must be done whatever the step, because the librarian can click on any tab.
124   #############test for member being unique #############
125   if ($op eq 'insert'){
126           my $category_type_send=$category_type if ($category_type eq 'I'); 
127           my $check_category; # recover the category code of the doublon suspect borrowers
128           ($check_member,$check_category) = checkuniquemember(
129                                 $category_type_send,
130                                 ($newdata{'surname'  } ? $newdata{'surname'  } : $data{'surname'  }),
131                                 ($newdata{'firstname'} ? $newdata{'firstname'} : $data{'firstname'}),
132                                 ($newdata{'dateofbirth'} ? C4::Dates->new($newdata{'dateofbirth'})->output('iso') : $data{'dateofbirth'})
133                   );
134 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
135           
136   #   recover the category type if the borrowers is a doublon 
137         my $tmpborrowercategory=GetBorrowercategory($check_category);
138         $check_categorytype=$tmpborrowercategory->{'category_type'};
139 }
140
141   #recover all data from guarantor address phone ,fax... 
142 <<<<<<< HEAD:members/memberentry.pl
143 if (($category_type eq 'C' || $category_type eq 'P') and $guarantorid ne '' ){
144   my $guarantordata=GetMember($guarantorid);
145   $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
146   if (($data{'contactname'} eq '' or $data{'contactname'} ne $guarantordata->{'surname'})) {
147     $data{'contactfirstname'}=$guarantordata->{'firstname'}; 
148     $data{'contactname'}=$guarantordata->{'surname'};
149     $data{'contacttitle'}=$guarantordata->{'title'};  
150     map {$data{$_}=$guarantordata->{$_}}('streetnumber','address','streettype','address2','zipcode','city','phone','phonepro','mobile','fax','email','emailpro');
151 =======
152   if ($category_type eq 'C' and $guarantorid ne '' ){
153     my $guarantordata=GetMember($guarantorid);
154     $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
155     if (($data{'contactname'} eq '' or $data{'contactname'} ne $guarantordata->{'surname'})) {
156       $newdata{'contactfirstname'} = $guarantordata->{'firstname'}; 
157       $newdata{'contactname'     } = $guarantordata->{'surname'};
158       $newdata{'contacttitle'    } = $guarantordata->{'title'};  
159       map {$newdata{$_}=$guarantordata->{$_}}('streetnumber','address','streettype','address2','zipcode','city','phone','phonepro','mobile','fax','email','emailpro');
160           #  This use of map is improper (void context).  Should be foreach, probably.
161     }
162 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
163   }
164 }
165
166 <<<<<<< HEAD:members/memberentry.pl
167 ###############test to take the right zipcode and city name ##############
168 if ( $guarantorid eq ''){
169   if ($select_city){
170     my ($borrower_city,$borrower_zipcode)=&getzipnamecity($select_city);
171     $newdata{'city'}= $borrower_city;
172     $newdata{'zipcode'}=$borrower_zipcode;
173 =======
174   # CHECKS step by step
175 # STEP 1
176     if ($op eq 'insert' && checkcardnumber($cardnumber)){ 
177       push @errors, 'ERROR_cardnumber';
178       $nok = 1;
179     } 
180     ###############test to take the right zipcode and city name ##############
181     if ( $guarantorid eq ''){
182       if ($select_city){
183         my ($borrower_city,$borrower_zipcode)=&getzipnamecity($select_city);
184         $newdata{'city'   } = $borrower_city;
185         $newdata{'zipcode'} = $borrower_zipcode;
186         }
187     }
188     my $dateofbirthmandatory=0;
189     map {$dateofbirthmandatory=1 if $_ eq "dateofbirth"} @field_check;          # improper use of map (void context).  Probably "foreach" or even "grep" should be used.
190     if ($category_type ne 'I' && $newdata{dateofbirth} && $dateofbirthmandatory) {
191       my $age = GetAge(C4::Dates->new($data{dateofbirth})->output('iso'));
192       my $borrowercategory=GetBorrowercategory($data{'categorycode'});   
193       if (($age > $borrowercategory->{'upperagelimit'}) or ($age < $borrowercategory->{'dateofbirthrequired'})) {
194         push @errors, 'ERROR_age_limitations';
195         $nok = 1;
196       }
197     }
198
199 # STEP 2
200     if ( ($newdata{'userid'} eq '')){
201       my $onefirstnameletter=substr($data{'firstname'},0,1);
202       my $fivesurnameletter =substr($data{'surname'},0,5);
203       $newdata{'userid'}=lc($onefirstnameletter.$fivesurnameletter);
204     }
205 #   }
206 # STEP 3
207   if ($op eq 'insert'){
208           my $loginexist;
209           # Check if the userid is unique
210           if ( !Check_Userid($data{'userid'},$borrowernumber)) {
211                   push @errors, "ERROR_login_exist";
212                   $nok = $loginexist = 1;
213     } else {
214       $borrowernumber = &AddMember(%newdata);
215         if ($data{'organisations'}){            
216           # need to add the members organisations
217           my @orgs=split(/\|/,$data{'organisations'});
218           add_member_orgs($borrowernumber,\@orgs);
219         }
220 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
221     }
222 }
223 #builds default userid
224 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
225   my $onefirstnameletter=substr($data{'firstname'},0,1);
226   my $fivesurnameletter=substr($data{'surname'},0,9);
227   $newdata{'userid'}=lc($onefirstnameletter.$fivesurnameletter);
228 }
229   
230 my $loginexist=0;
231 if ($op eq 'save' || $op eq 'insert'){
232   if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ 
233     push @errors, 'ERROR_cardnumber';
234     $nok = 1;
235   } 
236   my $dateofbirthmandatory=0;
237   map {$dateofbirthmandatory=1 if $_ eq "dateofbirth"} @field_check;
238   if ($newdata{dateofbirth} && $dateofbirthmandatory) {
239     my $age = GetAge($newdata{dateofbirth});
240     my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});   
241     if (($age > $borrowercategory->{'upperagelimit'}) or ($age < $borrowercategory->{'dateofbirthrequired'})) {
242       push @errors, 'ERROR_age_limitations';
243       $nok = 1;
244     }
245   }
246   
247   if (C4::Context->preference("IndependantBranches")) {
248     my $userenv = C4::Context->userenv;
249     if ($userenv && $userenv->{flags} != 1){
250       warn "  $newdata{'branchcode'} : ".$userenv->{flags}.":".$userenv->{branch};
251       unless (!$newdata{'branchcode'} || $userenv->{branch} eq $newdata{'branchcode'}){
252         push @errors, "ERROR_branch";
253         $nok=1;
254       }
255     }
256   }
257   # Check if the userid is unique
258   if (($op eq 'insert' || $op eq 'save') && !Check_Userid($newdata{'userid'},$borrowernumber)) {
259     push @errors, "ERROR_login_exist";
260     $nok=1;
261     $loginexist=1; 
262   }
263 }
264
265 if ($op eq 'modify' || $op eq 'insert'){
266   unless ($newdata{'dateexpiry'}){
267     if ($newdata{'dateenrolled'}){
268       $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$newdata{'dateenrolled'});
269     } else {  
270       my $today= sprintf('%04d-%02d-%02d', Today());
271       $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$today) ;
272     }  
273   }
274 }
275
276                               
277
278 if ($op eq 'insert'){
279   # Check if the userid is unique
280   unless ($nok){
281     $borrowernumber = &AddMember(%newdata);
282     if ($data{'organisations'}){            
283       # need to add the members organisations
284       my @orgs=split(/\|/,$data{'organisations'});
285       add_member_orgs($borrowernumber,\@orgs);
286     }
287     if($destination eq "circ"){
288       print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
289     } else {
290       if ($loginexist == 0) {
291       print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
292       }
293     }
294   }
295 }
296 if ($op eq 'save'){
297         # test to know if another user have the same password and same login                                
298         unless ($nok){
299                 &ModMember(%newdata);    
300                 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
301         }
302 }
303
304 <<<<<<< HEAD:members/memberentry.pl
305 if ($delete){
306         print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
307 }
308
309 =======
310 ($delete) and print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
311 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
312 if ($nok){
313 <<<<<<< HEAD:members/memberentry.pl
314   $op="add" if ($op eq "insert");
315   $op="modify" if ($op eq "save");
316   %data=%newdata; 
317   $template->param( updtype => ($op eq "insert"?'I':'M'));
318   unless ($step){  
319     $template->param( step_1 => 1,step_2 => 1,step_3 => 1);
320   }  
321 =======
322   $op = "add"    if ($op eq "insert");
323   $op = "modify" if ($op eq "save"  );
324   %data = %newdata; 
325   $template->param( updtype => ($op eq "insert"?'I':'M'),step_1=>1,step_2=>1,step_3=>1,allsteps=>1);
326 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
327
328 if (C4::Context->preference("IndependantBranches")) {
329   my $userenv = C4::Context->userenv;
330   if ($userenv->{flags} != 1 && $data{branchcode}){
331     unless ($userenv->{branch} eq $data{'branchcode'}){
332       print $input->redirect("/cgi-bin/koha/members/members-home.pl");
333     }
334   }
335 }
336 if ($op eq 'add'){
337   $template->param( updtype => 'I',step_1=>1,step_2=>1,step_3=>1);
338
339 if ($op eq "modify")  {
340   $template->param( updtype => 'M',modify => 1 );
341   $template->param( step_1=>1,step_2=>1,step_3=>1) unless $step;
342 }
343 # my $cardnumber=$data{'cardnumber'};
344 $data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if $op eq 'add';
345 if ($data{'sex'} eq 'F'){
346   $template->param(female => 1);
347 } elsif ($data{'sex'} eq 'M'){
348     $template->param(male => 1);
349 } else {
350     $template->param(none => 1);
351 }
352
353 ##Now all the data to modify a member.
354 my ($categories,$labels)=ethnicitycategories();
355   
356 my $ethnicitycategoriescount=$#{$categories};
357 my $ethcatpopup;
358 if ($ethnicitycategoriescount>=0) {
359   $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
360         -id => 'ethnicity',
361         -tabindex=>'',
362         -values=>$categories,
363         -default=>$data{'ethnicity'},
364         -labels=>$labels);
365   $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
366 }
367   
368 <<<<<<< HEAD:members/memberentry.pl
369   
370 my $action="WHERE category_type=?";
371 ($categories,$labels)=GetborCatFromCatType($category_type,$action);
372 =======
373   my $action="WHERE category_type=?";
374   ($categories,$labels)=GetborCatFromCatType($category_type,$action);
375 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
376   
377 if(scalar(@$categories)){
378       #if you modify the borrowers you must have the right value for his category code
379   my $default_category=$newdata{'categorycode'} if ($op  eq 'modify');
380   my $catcodepopup = CGI::popup_menu(
381       -name=>'categorycode',
382   -id => 'categorycode',
383   -values=>$categories,
384     -labels=>$labels,
385   -default=>$default_category
386   );
387   $template->param(catcodepopup=>$catcodepopup);
388 }
389   #test in city
390 <<<<<<< HEAD:members/memberentry.pl
391 $select_city=getidcity($data{'city'}) if ($guarantorid ne '0');
392 ($default_city=$select_city) if ($step eq 0);
393 if ($select_city eq '' ){
394 my $selectcity=&getidcity($data{'city'});
395 $default_city=$selectcity;
396 }
397 my($cityid,$name_city)=GetCities();
398 $template->param( city_cgipopup => 1) if ($cityid );
399 my $citypopup = CGI::popup_menu(-name=>'select_city',
400         -id => 'select_city',
401         -values=>$cityid,
402         -labels=>$name_city,
403         -default=>$default_city
404         );  
405 =======
406   $select_city=getidcity($data{'city'}) if ($guarantorid ne '0');
407   ($default_city=$select_city) if ($step eq 0);
408   if ($select_city eq '' ){
409                   $default_city=getidcity($data{'city'});
410   }
411   my($cityid,$name_city)=GetCities();
412   $template->param( city_cgipopup => 1) if ($cityid );
413   my $citypopup = CGI::popup_menu(-name=>'select_city',
414           -id => 'select_city',
415           -values=>$cityid,
416           -labels=>$name_city,
417 #             -override => 1,
418           -default=>$default_city
419           );  
420 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
421   
422 <<<<<<< HEAD:members/memberentry.pl
423 my $default_roadtype;
424 $default_roadtype=$data{'streettype'} ;
425 my($roadtypeid,$road_type)=GetRoadTypes();
426   $template->param( road_cgipopup => 1) if ($roadtypeid );
427 my $roadpopup = CGI::popup_menu(-name=>'streettype',
428         -id => 'streettype',
429         -values=>$roadtypeid,
430           -labels=>$road_type,
431           -override => 1,
432         -default=>$default_roadtype
433         );  
434 =======
435   my $default_roadtype;
436   $default_roadtype=$data{'streettype'} ;
437   my($roadtypeid,$road_type)=GetRoadTypes();
438     $template->param( road_cgipopup => 1) if ($roadtypeid );
439   my $roadpopup = CGI::popup_menu(-name=>'streettype',
440           -id => 'streettype',
441           -values=>$roadtypeid,
442             -labels=>$road_type,
443             -override => 1,
444           -default=>$default_roadtype
445           );  
446 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
447
448 <<<<<<< HEAD:members/memberentry.pl
449 my $default_borrowertitle;
450 $default_borrowertitle=$data{'title'} ;
451 my($borrowertitle)=GetTitles();
452 my $borrotitlepopup = CGI::popup_menu(-name=>'title',
453               -id => 'btitle',
454               -values=>$borrowertitle,
455               -override => 1,
456               -default=>$default_borrowertitle
457         );    
458 =======
459   my $default_borrowertitle;
460   $default_borrowertitle=$data{'title'} ;
461   my($borrowertitle)=GetTitles();
462   my $borrotitlepopup = CGI::popup_menu(-name=>'title',
463                 -id => 'btitle',
464                 -values=>$borrowertitle,
465                 -override => 1,
466                 -default=>$default_borrowertitle
467   );    
468 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
469
470 <<<<<<< HEAD:members/memberentry.pl
471 =======
472   my @relshipdata;
473   foreach (map {$_ || ''} split /,|\|/, C4::Context->preference('BorrowerRelationship')) {
474     my %row = ('relationship' => $_);
475     if ($data{'relationship'} eq $_) {
476       $row{'selected'}=' selected';
477     } else {
478       $row{'selected'}='';
479     }
480     push(@relshipdata, \%row);
481   }
482   my %flags = ( 'gonenoaddress' => ['gonenoaddress', 'Gone no address '],
483           'lost'          => ['lost', 'Lost'],
484           'debarred'      => ['debarred', 'Debarred']);
485 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
486
487 <<<<<<< HEAD:members/memberentry.pl
488 my @relationships = split /,|\|/,C4::Context->preference('BorrowerRelationship');
489 my @relshipdata;
490 while (@relationships) {
491   my $relship = shift @relationships || '';
492   my %row = ('relationship' => $relship);
493   if ($data{'relationship'} eq $relship) {
494     $row{'selected'}=' selected';
495   } else {
496     $row{'selected'}='';
497 =======
498   my @flagdata;
499   foreach my $key (keys(%flags)) {
500                   my %row =  ('key'   => $key,
501                           'name'  => $flags{$key}[0],
502                           'html'  => $flags{$key}[1]);
503                   if ($data{$key}) {
504                         $row{'yes'}=' checked';
505                         $row{'no'}='';
506                   } else {
507                         $row{'yes'}='';
508                         $row{'no'}=' checked';
509                   }
510                   push(@flagdata, \%row);
511 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
512   }
513   push(@relshipdata, \%row);
514 }
515 my %flags = ( 'gonenoaddress' => ['gonenoaddress', 'Gone no address '],
516         'lost'          => ['lost', 'Lost'],
517         'debarred'      => ['debarred', 'Debarred']);
518
519 my @flagdata;
520 foreach (keys(%flags)) {
521 my $key = $_;
522 my %row =  ('key'   => $key,
523     'name'  => $flags{$key}[0],
524     'html'  => $flags{$key}[1]);
525 if ($data{$key}) {
526   $row{'yes'}=' checked';
527   $row{'no'}='';
528 } else {
529   $row{'yes'}='';
530   $row{'no'}=' checked';
531 }
532 push(@flagdata, \%row);
533 }
534
535 <<<<<<< HEAD:members/memberentry.pl
536 =======
537   ($modify) and $template->param( modify => 1 );
538 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
539
540 <<<<<<< HEAD:members/memberentry.pl
541 #get Branches
542 my @branches;
543 my @select_branch;
544 my %select_branches;
545
546 my $onlymine=(C4::Context->preference('IndependantBranches') && 
547               C4::Context->userenv && 
548               C4::Context->userenv->{flags} !=1  && 
549               C4::Context->userenv->{branch}?1:0);
550               
551 my $branches=GetBranches($onlymine);
552 my $default;
553
554 foreach my $branch (sort keys %$branches) {
555     push @select_branch,$branch;
556     $select_branches{$branch} = $branches->{$branch}->{'branchname'};
557     $default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && C4::Context->userenv->{'branch'});
558 }
559 =======
560   #Convert dateofbirth to correct format
561   my @branches;
562   my @select_branch;
563   my %select_branches;
564   my $branches=GetBranches();
565   my $default;
566   # -----------------------------------------------------
567   #  the value of ip from the branches hash table
568 #     my $select_ip;
569   # $ip is the ip of user when is connect to koha 
570 #     my $ip = $ENV{'REMOTE_ADDR'};
571   
572   # -----------------------------------------------------
573   foreach my $branch (keys %$branches) {
574     if ((not C4::Context->preference("IndependantBranches")) || (C4::Context->userenv->{'flags'} == 1)) {
575       push @select_branch, $branch;
576       $select_branches{$branch} = $branches->{$branch}->{'branchname'};
577     } else {
578       push @select_branch,$branch if ($branch eq C4::Context->userenv->{'branch'});
579       $select_branches{$branch} = $branches->{$branch}->{'branchname'} if ($branch eq C4::Context->userenv->{'branch'});
580     }
581     $default = C4::Context->userenv->{'branch'};
582   }
583 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
584 # --------------------------------------------------------------------------------------------------------
585   #in modify mod :default value from $CGIbranch comes from borrowers table
586   #in add mod: default value come from branches table (ip correspendence)
587 <<<<<<< HEAD:members/memberentry.pl
588 $default=$data{'branchcode'}  if ($op eq 'modify');
589 my $CGIbranch = CGI::scrolling_list(-id    => 'branchcode',
590             -name   => 'branchcode',
591             -values => \@select_branch,
592             -labels => \%select_branches,
593             -size   => 1,
594             -override => 1,  
595             -multiple =>0,
596             -default => $default,
597         );
598 my $CGIorganisations;
599 my $member_of_institution;
600 if (C4::Context->preference("memberofinstitution")){
601     my $organisations=get_institutions();
602     my @orgs;
603     my %org_labels;
604     foreach my $organisation (keys %$organisations) {
605         push @orgs,$organisation;
606         $org_labels{$organisation}=$organisations->{$organisation}->{'surname'};
607     }
608     $member_of_institution=1;
609     
610     $CGIorganisations = CGI::scrolling_list( -id => 'organisations',
611         -name     => 'organisations',
612         -labels   => \%org_labels,
613         -values   => \@orgs,
614         -size     => 5,
615         -multiple => 'true'
616
617         
618     );
619 }
620 =======
621   $default=$data{'branchcode'}  if ($op eq 'modify');
622   my $CGIbranch = CGI::scrolling_list(-id    => 'branchcode',
623              -name   => 'branchcode',
624              -values => \@select_branch,
625              -labels => \%select_branches,
626              -size   => 1,
627              -override => 1,  
628                    -multiple =>0,
629              -default => $default,
630           );
631   my $CGIorganisations;
632   my $member_of_institution;
633   if (C4::Context->preference("memberofinstitution")){
634      my $organisations=get_institutions();
635      my @orgs;
636      my %org_labels;
637      foreach my $organisation (keys %$organisations) {
638          push @orgs,$organisation;
639          $org_labels{$organisation}=$organisations->{$organisation}->{'surname'};
640      }
641      $member_of_institution=1;
642      
643      $CGIorganisations = CGI::scrolling_list( -id => 'organisations',
644          -name     => 'organisations',
645          -labels   => \%org_labels,
646          -values   => \@orgs,
647          -size     => 5,
648          -multiple => 'true'
649      );
650   }
651 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
652
653 # --------------------------------------------------------------------------------------------------------
654
655 <<<<<<< HEAD:members/memberentry.pl
656 my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data{'sort1'});
657 if ($CGIsort1) {
658   $template->param(CGIsort1 => $CGIsort1);
659 =======
660   my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data{'sort1'});
661   if ($CGIsort1) {
662     $template->param(CGIsort1 => $CGIsort1);
663   }
664 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
665   $template->param( sort1 => $data{'sort1'});
666 <<<<<<< HEAD:members/memberentry.pl
667 } else {
668   $template->param( sort1 => $data{'sort1'});
669 }
670 =======
671 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
672
673 <<<<<<< HEAD:members/memberentry.pl
674 my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data{'sort2'});
675 if ($CGIsort2) {
676   $template->param(CGIsort2 =>$CGIsort2);
677 } else {
678   $template->param( sort2 => $data{'sort2'});
679 }
680 if ($nok) {
681     foreach my $error (@errors) {
682         $template->param( $error => 1);
683     }
684     $template->param(nok => 1);
685 }
686   
687 =======
688   my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data{'sort2'});
689   if ($CGIsort2) {
690     $template->param(CGIsort2 => $CGIsort2);
691   } else {
692     $template->param( sort2 => $data{'sort2'});
693   }
694   # increase step to see next page
695   if ($nok) {
696       foreach (@errors, 'nok') {
697           $template->param( $_ => 1);
698       }
699   }
700 #   else {
701 #       $step++ if $op eq 'add';
702 #   }
703 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
704   #Formatting data for display    
705   
706 <<<<<<< HEAD:members/memberentry.pl
707 if ($data{'dateenrolled'} eq ''){
708   my $today= sprintf('%04d-%02d-%02d', Today());
709   $data{'dateenrolled'}=$today;
710 }
711 =======
712   if ($data{'dateenrolled'} eq ''){
713     my $today= sprintf('%04d-%02d-%02d', Today());
714     #insert ,in field "dateenrolled" , the current date
715     $data{'dateenrolled'}=$today;
716     $data{'dateexpiry'} = GetExpiryDate($data{'categorycode'},$today);
717   }
718   
719   $data{'surname'     } = uc($data{'surname'});
720   $data{'contactname' } = uc($data{'contactname'});
721   $data{'firstname'   } = ucfirst(lc $data{'firstname'});
722   $data{'contactfirstname'}= ucfirst(lc $data{'contactfirstname'});
723   $data{'dateenrolled'} = C4::Dates->new($data{'dateenrolled'})->output;
724   $data{'dateexpiry'  } = C4::Dates->new($data{'dateexpiry'  })->output;
725   $data{'dateofbirth' } = C4::Dates->new($data{'dateofbirth' })->output;
726 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
727
728 <<<<<<< HEAD:members/memberentry.pl
729 $data{'surname'}=uc($data{'surname'});
730 $data{'firstname'}=ucfirst(lc $data{'firstname'});
731 $data{'dateenrolled'}=format_date($data{'dateenrolled'});
732 $data{'dateexpiry'}=format_date($data{'dateexpiry'});
733 $data{'contactname'}=uc($data{'contactname'});
734 $data{'contactfirstname'}= ucfirst( lc $data{'contactfirstname'});
735 $data{'dateofbirth'} = format_date($data{'dateofbirth'});
736
737 $template->param( "showguarantor"  => 1) if ($category_type!~/A|I/);# associate with step to know where u are
738 $template->param( "showguarantor"  => 0) if ($category_type=~/A|I/);# associate with step to know where u are
739   warn "$step";
740 $template->param(%data);
741 $template->param( "step_$step"  => 1) if $step;# associate with step to know where u are
742 $template->param( "step"  => $step) if $step;# associate with step to know where u are
743 $template->param(
744   BorrowerMandatoryField => C4::Context->preference("BorrowerMandatoryField"),#field to test with javascript
745   category_type => $category_type,#to know the category type of the borrower
746   DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
747   select_city => $select_city,
748   "$category_type"  => 1,# associate with step to know where u are
749   destination   => $destination,#to know wher u come from and wher u must go in redirect
750   check_member    => $check_member,#to know if the borrower already exist(=>1) or not (=>0) 
751   flags   =>$data{'flags'},   
752   "op$op"   => 1,
753   nodouble  => $nodouble,
754   borrowernumber  => $borrowernumber,#register number
755   "contacttitle_".$data{'contacttitle'} => "SELECTED" ,
756   guarantorid => $guarantorid,
757   ethcatpopup => $ethcatpopup,
758   relshiploop => \@relshipdata,
759   citypopup => $citypopup,
760   roadpopup => $roadpopup,  
761   borrotitlepopup => $borrotitlepopup,
762   guarantorinfo   => $guarantorinfo,
763   flagloop  => \@flagdata,
764   dateformat      => display_date_format(),
765   check_categorytype =>$check_categorytype,#to recover the category type with checkcategorytype function
766   modify          => $modify,
767   nok     => $nok,#flag to konw if an error 
768   CGIbranch => $CGIbranch,
769   memberofinstution => $member_of_institution,
770   CGIorganisations => $CGIorganisations,
771 =======
772 #   warn "$step";
773   $template->param(%data);
774   $template->param(
775     BorrowerMandatoryField => C4::Context->preference("BorrowerMandatoryField"),#field to test with javascript
776     category_type => $category_type,#to know the category type of the borrower
777     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
778     select_city  => $select_city,
779     "step_$step" => 1,                  # associate with step to know where you are
780     "$category_type"  => 1,             # associate with step to know where you are
781     step    => $step,
782     destination   => $destination,      # for redirect
783     check_member  => $check_member,     # to know if the borrower already exist(=>1) or not (=>0) 
784     flags   => $data{'flags'},   
785     "op$op"   => 1,
786     nodouble  => $nodouble,
787     borrowernumber  => $borrowernumber, # register number
788     "contacttitle_".$data{'contacttitle'} => "SELECTED",
789     guarantorid => $guarantorid,
790     ethcatpopup => $ethcatpopup,
791     relshiploop => \@relshipdata,
792     citypopup   => $citypopup,
793     roadpopup   => $roadpopup,  
794     borrotitlepopup => $borrotitlepopup,
795     guarantorinfo   => $guarantorinfo,
796     flagloop   => \@flagdata,
797     dateformat => C4::Dates->visual(),
798     check_categorytype =>$check_categorytype, # to recover the category type with checkcategorytype function
799     modify     => $modify,
800     nok     => $nok,    # flag to know if an error 
801     CGIbranch => $CGIbranch,
802     memberofinstution => $member_of_institution,
803     CGIorganisations => $CGIorganisations,
804     );
805 >>>>>>> Removing CVS tags $Id$ and $Log$. Lots of files, not much change.:members/memberentry.pl
806   
807   );
808 output_html_with_http_headers $input, $cookie, $template->output;
809
810 # Local Variables:
811 # tab-width: 8
812 # End: