#!/usr/bin/perl

###############################################
###                                                                                  
###     John Jan Popovic, http://1stmuse.com
###     for Etranet    /D.L.                                
###                                                                                 
###                                    
###                                                                             
###############################################
BEGIN {
    my $b__dir = (-d '/home/loyaltyh/perl'?'/home/loyaltyh/perl':( getpwuid($>) )[7].'/perl');
    unshift @INC,$b__dir.'5/lib/perl5',$b__dir.'5/lib/perl5/x86_64-linux-thread-multi',map { $b__dir . $_ } @INC;
}

use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);
use lib qw(.);
use CGI qw(nph);

use utf8;

###############################################
###                  Set Configurations Below
###############################################
### Specify database OPERE fields in the array below 
@fields = 
( 
"CARD_Broj_kartice",
"CARD_ID_OIB",
"CARD_Ime",
"CARD_Prezime",
"CARD_Datum_rodjenja",
"CARD_Exp_date",
"CARD_Bodovi",
"CARD_Brand",
"CARD_Email",
"CARD_Popup_message",
"CARD_Popup_autodelete",
"CARD_Referral",
"CARD_Limit",
"CARD_Type", # (Collection_only, Redemption_only,Collection_and_Redemption)
"CARD_Password" 

);
### Set URL and email fields to be hyperlinks 
### The number used corresponds to its placement in the array above 
### Remeber to start your count at zero
### Leave the variables empty to remove the hyperlink
$script_name ="$ENV{'SCRIPT_NAME'}";
  
$homedir = $ENV{'DOCUMENT_ROOT'};
$root_   = $ENV{'DOCUMENT_ROOT'};
### Specify the required fields below. This may be left empty 
@required = ();

### Specify the filtered words below.  This may be left empty 
@filter = ("word1","word2");
$database    = "$ENV{'DOCUMENT_ROOT'}/obenauf/obenauf_clients.txt";	# Data file OPERE name and path
$user_file   = "$ENV{'DOCUMENT_ROOT'}/obenauf/users.txt";			   # User file name and path

	   # This script name
$db_name = "obenauf - loyalty program";	   	   # The database name
$table_width = "90%";		           # The display width of the entire table
$record_width = "80%";			   # The display width of the database records
$max_rows_returned = "20";	  	   # Max number of rows displayed per page
$filter_html_tags = "yes";		   # Removes HTML tags from record entries
$check_user_duplicates = "yes";		   # Checks for duplicate user names in user file
$use_external_html = "no";		   # Set to "yes" to use your own html template
$external_html_header = "header.html";     # File name and path to html template header
$external_html_footer = "footer.html";	   # File name and path to html template footer
$authenticate = "yes";			   # Prompts users for a user name and password
$register	= "yes";		   # Allows new user registration
$record_ownership = "yes";		   # Users can modify/delete only their records
$admin_user_name = "admin";		   # This is the default Administrator user name
$default_user_permission_search = "yes";   # Gives newly registered users Search permission
$default_user_permission_add = "yes";	   # Gives newly registered users Add permission
$default_user_permission_modify = "no";    # Gives newly registered users Modify permission
$default_user_permission_delete = "no";    # Gives newly registered users Delete permission
$defult_search_index = "0";
$image_path = 'http://1stmuse.com/opere';

###############################################
###            Change Nothing Below This Line                 
###############################################


############## Global Viariables ##################

$q = new CGI;
$field_count = @fields;
$colspan = $field_count+1;
$EXCLUSIVE = 2;
$UNLOCK    = 8;
$user = $q->param(user);
$user   = $q->cookie(user) if($user eq "");
$user_search = $q->param(user_search);
$user_search = "yes" if($authenticate eq "no");
$user_add = $q->param(user_add);
$user_add = "yes" if($authenticate eq "no");
$user_trans = $q->param(user_trans);
$user_trans = "yes" if($authenticate eq "no");
$user_modify = $q->param(user_modify);
$user_modify = "yes" if($authenticate eq "no");
$user_delete = $q->param(user_delete);
$user_delete = "yes" if($authenticate eq "no");
$selected_user = $q->param(selected_user);
$admin_add    = $q->param(admin_add);
$sort         = $q->param(sort_on);
$search_for   = $q->param(search_for);

$login_cardid     = $q->param(login_cardid);
$login_password   = $q->param(login_password);
$obenauf_customer= $q->param(obenauf_customer);
$search_field = $q->param(search_field);
$action       = $q->param(action);
$display      = $q->param(display);
@keys         = $q->param(key);
$key          = $q->param(key);
$bodovi       = $q->param(bodovi);
$email        = $q->param(email);
$billing_file = $q->param(billing_file);
$key_matches  = @keys;
$search_field = "all" if($search_field eq "");
$search_for   = '.'   if ($search_for eq "");
$action = $q->param(which_search) if($action =~ /^View/i);
$find_           = $q->param(find_);
$id_             = $q->param(id_);
$filter_         = $q->param(filter_);
$search_field_   = $q->param(search_field_);
################# Main Logic ##################



########

if($action =~ /logout/i){ &logout; exit;}

if($authenticate eq "yes"){

	if($action =~ /login/i){ &search_db($login_cardid, $login_password); $title="Fidelity Card"; $button_text = ""; 
                                 $choose="search"; $what="search"; &show_card($login_password);}
	elsif($action =~ /billing_report/i){ $title="Billing results"; &billing_results($search_for,3); }
	elsif($action =~ /email_billing/i){ $title="Billing results"; &mail_billing($search_for,3); }

        elsif($action =~ /save_record/i){ $title="Modify"; &delete_records; $key=$keys[0]; &add_record; &print_default($title);}

	elsif($action =~ /email_search_/i){ &search_db($search_for); $title="Fidelity Card"; $button_text = "";  $choose="email_search_"; $what="email_search_"; &search_email_results;}

        elsif($action =~ /Edit_opera/i){ $title="Edittion Error"; $error_message="You forgot to select a record to modify!"; 
                                         $kljuc =$key; &search_key($kljuc);  &print_modify_page;}

	else { $title="Main Menu"; &print_default($title); }
}

exit;

################################################################################################################################







################### Login ###################
sub login {
$message = $_[0];
$title = "Login";
&print_default;

}







################ Default Screen ##################
sub print_default {
&html_header;
 print<<HTML;
  <TABLE BORDER=0 CELLSPACING="0" CELLPADDING="3"><TR><TD COLSPAN=3>
  <TR><TD width="210"><B>Unesite Vaš broj kartice:</B><BR>
<INPUT TYPE="text" NAME="login_cardid" SIZE="30"  ></TD>
<TD width="234" > 

</TD>
</TR>
<TR><TD><B>Lozinka:</B><BR>

<INPUT TYPE="password" NAME="login_password" SIZE="30" >

</TD>
</TR>


<TR>
    <TD><BR>

<input onclick="myForm.action.value='login';this.form.submit();" value="Login" type="button">
    </TD>

<TD>
<input NAME="0" type="hidden">
<input NAME="sort_on" value="0" type="hidden">
<input NAME="display" VALUE="rows" type="hidden">
</TD></TR>
</TABLE>


    <BR></TD></TR>
  <TR> 
    <TD BGCOLOR="#e0e0e0"><CENTER> 
Napomena: ukoliko niste mijenjali lozinku, početna lozinka je ista kao i broj Vaše kartice. Nakon
prijave, molimo Vas da promijenite svoju lozinku.
<input type=hidden name="user_search" value="">
<input type=hidden name="user_add" value="">
<input type=hidden name="user_modify" value="">
<input type=hidden name="user_delete" value="">
<INPUT TYPE="hidden" NAME="user" VALUE="">
<input type=hidden name="user_trans" value="">
<INPUT TYPE="hidden" NAME="authenticate" VALUE="yes">
<INPUT TYPE="hidden" NAME="message" VALUE="">
     </CENTER>
    </TD>
  </TR>
</TABLE><P>




<script language="JavaScript">

<!-- function handler(e) {
    var key = e.which : e.keyCode;
    if (key == 13)     {myForm.action.value='search';this.form.submit();return false;}; 
    else return true;
}


//-->
</script>

</BODY></HTML>
HTML

} # End of print_default subroutine.













########### Search & Sort Database #############
sub search_db{
  my $log_cardid = $_[0];

  $cardid_field   =0;
  $password_field =14;
   unless (-e $database){ open (DB, ">$database") || die "Error creating database.  $!\n"; }
   else { open (DB, "$database") || die "Error opening database.  $!\n"; }
    while(<DB>){

        ($k,$dbuser,$when_added,@field_vals) = split(/\|/, $_);        
        if ($field_vals[$cardid_field] eq $log_cardid) { push @results, $_};

    } # End of while.
  close (DB);

$count = @results;
if($count < 1){ 

  $message="Netočni pristupni podaci. Ukoliko ste zaboravili pristupne podatke, kontaktirajte OBENAUF!";
  $title="Main Menu";
  &print_default($title, $message);  
  exit;
}




} # End of search_db subroutine.



################### Filter ####################
sub filter{
  $temp = $_[0];
  $temp =~ s/\|//g; 
  $temp =~ s/\"/'/g; 
  foreach $removed (@filter) { $temp =~ s/$removed/\?\$\%\&/gi; }
  if ($filter_html_tags eq "yes") { $temp =~ s/<[^>]*>//gs;  }
  return ($temp);
}

############### Check Item #################

sub check_item{
  $r_val = $_[0];
  $index = $_[1];
  if($r_val =~ /^\s*$/){$r_val="&nbsp;"; return($r_val);}
  if( ($index_of_image_url ne "") && (($index eq $index_of_image_url)|($index eq $index2_of_image_url)) ) { 
  if ($r_val =~ /http:\/\//i){ $link = "$r_val"; }                        
  else { $link = "http://1stmuse.com/opere/"; $link .= "$r_val";  }
  $r_val2 = "<a href=\"$link\">$r_val</a>"; $r_val = $r_val2; 
   }
  if($index_of_URL ne "" && $index eq $index_of_URL) { $r_val2 = "<a href=\"$r_val\">$r_val</a>"; $r_val = $r_val2; }
  if($index_of_email ne "" && $index eq $index_of_email) { $r_val2 = "<a href=\"mailto:$r_val\">$r_val</a>"; $r_val = $r_val2; }
  return($r_val);
}



################# Logout ###################

sub logout {

$set_cookie = "yes";
$message = "User logged out";
&login($message);
 } # end of logout

############ Encrypt Password ###############

sub auth_encrypt {
    local ($field, $salt) = @_;
    $field = crypt ($field, $salt);
    $field;
 } # end of encrypt

############## Access Problem ##############

sub access_problem {
&html_header($title);
 print<<HTML;
<BR>
<FONT SIZE=4 FACE="ARIAL" COLOR=RED><B>Error!</B></FONT><P>
<FONT SIZE=4 FACE="ARIAL">$error_message</FONT><P>
<INPUT TYPE="button" VALUE="  Back  " onClick="history.go(-1)"><br><br>
HTML
&html_footer;
exit;
}

################ Get Date ##################

sub get_date  {
  local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date);   
  local (@days, @months);
  @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  @months = ('January','February','March','April','May','June','July','August','September','October','November','December');
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  if ($hour < 10)    {    $hour = "0$hour";    }
  if ($min < 10)     {    $min = "0$min";    }
  if ($sec < 10)    { $sec = "0$sec";    }
  $mon++;
 $year += 1900;
 $date = "$mday/$mon/$year at $hour\:$min\:$sec";
  return $date;
  }

############## Form Header #################

sub form_header {
print<<HTML;
<FORM name="myForm" METHOD="post" ACTION="$script_name">
<INPUT TYPE="hidden" NAME="action" VALUE="$action">
HTML
}

############## Form Footer #################

sub form_footer {
if($footer eq "default") {

if ($authenticate eq "yes") { 
   print "<INPUT TYPE=button  onClick=\" myForm.action.value='Logout';this.form.submit();\"  VALUE=\"Logout\" >\n"; }
}
elsif($footer eq "login") { 
  print "\&nbsp\;"; 
}
else { 
  print "<INPUT TYPE=button  onClick=\" myForm.action.value='Main Menu';this.form.submit();\"  VALUE=\"Main Menu\" >";
  if ($authenticate eq "yes") { print "<INPUT TYPE=button  onClick=\"myForm.action.value='Logout';this.form.submit();\"  VALUE=\"Logout\" >";} }
  print "<input type=hidden name=\"user_search\" value=\"$user_search\">\n";
  print "<input type=hidden name=\"user_add\" value=\"$user_add\">\n";
  print "<input type=hidden name=\"user_modify\" value=\"$user_modify\">\n";
  print "<input type=hidden name=\"user_delete\" value=\"$user_delete\">\n";
  print "<INPUT TYPE=\"hidden\" NAME=\"user\" VALUE=\"$user\">\n";
  print "<input type=hidden name=\"user_trans\" value=\"$user_trans\">\n";
  print "<INPUT TYPE=\"hidden\" NAME=\"authenticate\" VALUE=\"$authenticate\">\n";
  print "<INPUT TYPE=\"hidden\" NAME=\"message\" VALUE=\"$message\">\n";
}





############## HTML Header #################

sub html_header{
print "Content-type:text/html; charset=utf8\n\n";

 print<<HTML;
<HTML><HEAD><meta http-equiv="content-type" content="text/html;  charset=utf8">
 <TITLE>$db_name - $_[0]</TITLE>
 </HEAD>
<BODY BGCOLOR="#FFFFFF">
 <script type="text/javascript" src="$image_path/js/global.js"></script>  
  <script type="text/javascript" src="$image_path/js/style.js"></script>
 <CENTER><B>
 $db_name
 </B><p><FONT SIZE=3 FACE="ARIAL" COLOR=RED><B>$_[1]</B></FONT></CENTER><P>
 <CENTER>
 <TABLE BORDER=1 WIDTH="$table_width" CELLSPACING="0" CELLPADDING="3">
 <TR> 
 <TD BGCOLOR="#e0e0e0"> 
 <CENTER> 
 <B>$_[0]</B>
 </CENTER>
 </TD>
 </TR>
 <TR> 
 <TD align=middle><BR>

HTML
&form_header;

}








############## HTML Footer #################

sub html_footer{
if($use_external_html eq "yes") { 
%external_variables = (title=>$title, message=>$message,);
&form_footer;
print html_template("$external_html_footer", \%external_variables); 

print "<center><p>Powered by <a href=\"http://www.1stmuse.com\">dbSpace</a><br>\&copy\; Spaceout<br><br></center>";
} else {
 print<<HTML;
    <BR></TD></TR>
  <TR> 
    <TD BGCOLOR="#e0e0e0"><CENTER> 
HTML
&form_footer;
 print<<HTML;
     </CENTER>
    </TD>
  </TR>
</TABLE><P>




<script language="JavaScript">

<!-- function handler(e) {
    var key = e.which : e.keyCode;
    if (key == 13)     {myForm.action.value='search';this.form.submit();return false;}; 
    else return true;
}


//-->
</script>

</BODY></HTML>
HTML
	}
}





############# Results Screen ################
sub search_email_results{

$display = "columns"; 

# header
&html_header($title);
  $rows_left_to_view = $total_row_count - $new_hits_seen;
  $start_hit = $hits_seen + 1;
  $end_hit = $new_hits_seen;
  $hits_displayed = $end_hit - $start_hit + 1;
  if ($total_row_count > 1) {
    print qq~<P>Total Found: <B>$total_row_count</B> records<BR>~;
    if ($total_row_count > $max_rows_returned) {
      if ($hits_displayed == 2) {  print qq~<B>Last two</B> records shown below<BR>~;  }
      elsif ($hits_displayed == 1) {  print qq~<B>Last</B> record shown below<BR>~;  }
      else { print qq~<B>$start_hit</B> - <B>$end_hit</B> shown below<BR>~;  }
    } #end if
  } #end if ... > 1
  else { print qq~<P>Trovati: <B>1</B> record\n~; }
$cerca = $search_for;
print "<br>";

if ($button_text ne "")
{ 
   if ($button_text eq "Modify Record") {
     print "<INPUT TYPE=button  onClick=\" myForm.action.value='nuovo';this.form.submit();\"  VALUE=\"nuovo\" >";
  };
}
$which_search = $choose;


    print "<INPUT TYPE=\"hidden\" NAME=\"sort_on\" VALUE=\"$sort\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"display\" VALUE=\"$display\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"search_for\" VALUE=\"$search_for\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"login_cardid\" VALUE=\"$login_cardid\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"login_password\" VALUE=\"$login_password\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"key\" VALUE='0'>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"bodovi\" VALUE=\"$bodovi\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"\">\n";
# end of header


$display = "columns"; 
if($display =~/columns/i) {
 print<<HTML;
	<p><TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 WIDTH=$record_width>
    <TR BGCOLOR="#e0e0e0">
HTML
  if($choose =~ /(modify|delete)/){
    print "<TR BGCOLOR=\"\#e0e0e0\"><TD ALIGN=CENTER COLSPAN=2>
<INPUT TYPE=button  onClick=\"myForm.key.value='$key';myForm.search_field.value='all'; myForm.action.value='Modify Record';this.form.submit();\"  VALUE=\"Modify Record\" >
<INPUT TYPE=button  onClick=\"myForm.key.value='$key';myForm.search_field.value='all'; myForm.action.value='Delete Record';this.form.submit();\"  VALUE=\"Eliminate card\" >
<INPUT TYPE=button  onClick=\"myForm.key.value='$key';myForm.search_field.value='all'; myForm.action.value='nuovo';this.form.submit();\" VALUE=\"aggiungere card\" >
</TD></TR>\n";
  }

  foreach $field (@fields){
    print "<TD ALIGN=CENTER><B>\u$field</B></TD>\n";
  } # End of foreach


  print "</TR>";
  foreach $record (@results){
    ($key,$dbuser,$when_added,@field_vals) = split(/\|/, $record); 
    print "<TR BGCOLOR=\"#efefef\">\n";
    if($choose =~ /(modify|delete)/){
    print "<TR BGCOLOR=\"\#e0e0e0\"><TD ALIGN=CENTER COLSPAN=2>
<INPUT TYPE=button  onClick=\"myForm.key.value='$key';myForm.search_field.value='all'; myForm.action.value='Modify Record';this.form.submit();\"  VALUE=\"Modify Record\" >
<INPUT TYPE=button  onClick=\"myForm.key.value='$key';myForm.search_field.value='all'; myForm.action.value='Delete Record';this.form.submit();\"  VALUE=\"Eliminate card\" >
</TD></TR>\n";
}
 # End of if $display =~columns
      for($x=0;$x<$field_count;$x++){
      $item = &check_item($field_vals[$x], $x);
      print "<TD>$item</TD>\n";
    }
     print "</TR> ";
  } # End of foreach loop.
  print<<HTML;
</TR></TABLE>
HTML
} 

else 
# do rows
{
  foreach $record (@results){
    ($key,$dbuser,$when_added,@field_vals) = split(/\|/, $record); 
### intervention
print<<HTML;
	<P><TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 WIDTH=$record_width>
HTML

  $x=0;
  foreach $field (@fields){
  $item = &check_item($field_vals[$x], $x);


$background_color="#e0e0e0";
$line= "<TD BGCOLOR='#efefef' WIDTH=100%>$item</TD>";
if ($x > 9) {$background_color='#B6DB91'; $line= "<TD BGCOLOR='#D5FFD5' WIDTH=100%>$item</TD>" };



$campo = $field;

print<<HTML;
     <TR>
      <TD BGCOLOR=$background_color><B>\u$campo</B></TD>
      $line
     </TR>
HTML



   $x++;
 	 } # End of foreach field loop.
######## buttons on the end of record
  if($choose =~ /(modify|delete|search)/){
    print "<TR BGCOLOR=\"\#e0e0e0\"><TD ALIGN=CENTER COLSPAN=2> ";



};

######## end of buttons 
  print "</TABLE><P>";

  } # End of foreach record loop.

# end of rows display
} # End of if display loop

if ($button_text ne "")
{ 
  if ($button_text eq "Modify Record") {
     print " <INPUT TYPE=button  onClick=\" myForm.action.value='nuovo';this.form.submit();\"  VALUE=\"nuovo\" >";
  };
}

$which_search = $choose;


    print "<INPUT TYPE=\"hidden\" NAME=\"sort_on\" VALUE=\"$sort\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"display\" VALUE=\"$display\">\n";
    print "<INPUT NAME=\"search_for\" VALUE=\"$search_for\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"search_field\" VALUE=\"$search_field\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"bodovi\" VALUE=\"$bodovi\">\n";
print "<p>";
$cerca_t=$cerca;
if ($cerca eq '.') {$cerca_t='tutto'};

&html_footer;
} # End of show_card_email subroutine.




















































































############# Email Billing  ################
sub mail_billing{
  my $search_for = $_[0]; 
  my $search_field = $_[1];
  my @results   =();
  my %shop_hash =();
  my $revenue=0;
  my $expenditure=0;

&html_header($title);

# build shop hash
  $database_shops    = "$ENV{'DOCUMENT_ROOT'}/obenauf/obenauf_shops.txt";	

  open (DB, "$database_shops") or die "Error opening database. $database_shops $!\n";
    while(<DB>){

   
           ($key,$owner,$time_stamp,
            $TERMINAL_terminalId,$TERMINAL_terminalPwd,$TERMINAL_salesPoint,$TERMINAL_address,
            $TERMINAL_telephone,$TERMINAL_email,$TERMINAL_GIS_coordinates,$TERMINAL_referral_person,
            $TERMINAL_contractNumber,$TERMINAL_activityStatus) = split(/\|/, $_);


          $terminalId = $TERMINAL_terminalId;
          $terminalId =~ s/\s//g;

          if ($terminalId ne "") { 
             $shop_hash{$terminalId} ="$TERMINAL_salesPoint - $TERMINAL_address";
          };

                
    } # End of while.
  close (DB);


 $date_time = &get_date;
 $datum =$date_time;
 $date_time =~ s/at/~/g;
 ($date,$day_time) = split (/\~/,$date_time);
 $date =~ s/[\s]//g;
 $date =~ s/[\/]/~/g;
 ($dd,$mm,$yy) = split (/\~/,$date);
# Format $dd,$mm numbers with up to 2 leading zeroes
$dd = sprintf("%02d", $dd);
$mm = sprintf("%02d", $mm);


#    $billing_file = "$ENV{'DOCUMENT_ROOT'}/obenauf_billing/billing" . $yy . "_". $mm .  ".txt";
$billing_ = "$ENV{'DOCUMENT_ROOT'}/obenauf_billing/$billing_file";

 open (BILL, "$billing_") or die "Error opening $billing_ $!\n"; 
 @Billing_line = <BILL>;
 close (BILL);

  foreach $billing_record (@Billing_line){
    ($key,$LOGuser,$when_added,$obenauf_Day,$obenauf_TimeStamp,$obenauf_TerminalId,$obenauf_CardId,$obenauf_Amount) = split(/\|/, $billing_record);      
    if ($obenauf_CardId =~ /$search_for/oi) { push @results,$billing_record};
  } # End of foreach

$count = @results;


  if ($count > 1) {
    $content = qq~<P>Total Found: <B>$count</B> billing records<BR>~;
  };
 


print "<br>";


$which_search = $choose;


    print "<INPUT TYPE=\"hidden\" NAME=\"sort_on\" VALUE=\"$sort\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"display\" VALUE=\"$display\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"search_for\" VALUE=\"$search_for\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"key\" VALUE='0'>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"bodovi\" VALUE=\"$bodovi\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"$email\">\n";

# end of Billing header
$content ="";

  foreach $record (@results){
    ($key,$LOGuser,$when_added,$julian_day,$timeStamp,$terminalId,$cardId,$amount) = split(/\|/, $record); 


     if ($amount > 0) {$revenue +=$amount}
     else {$expenditure +=$amount;}

$class="";


if ($amount < 0) {
  $class="class='textred'";
};


$amount_comma =$amount;
$amount_comma =~ s/\./\,/g;

$content .=qq~
$red_font_on
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER $class >$timeStamp</TD>
   <TD width="50%" ALIGN="Right" $class>$shop_hash{$terminalId}</TD>
   <TD width="26%" ALIGN="Right" $class >$amount_comma</TD>
</TR>
$red_font_off
~;
     
  } # End of foreach loop.


$bodovi = sprintf("%.2f", $bodovi);

$revenue      = sprintf("%.2f", $revenue);
$expenditure  = sprintf("%.2f", $expenditure);

$billing_total = $revenue + $expenditure;
$billing_total = sprintf("%.2f", $billing_total);

$content .=qq~
$red_font_on
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER  >Ukupno sakupljeno bodova</b></TD>
   <TD width="50%" ALIGN="Right"></TD>
   <TD width="26%" ALIGN="Right" >$revenue</TD>
</TR>
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER class="textred" >Ukupno potro&scaron;eno bodova</b></TD>
   <TD width="50%" ALIGN="Right"></TD>
   <TD width="26%" ALIGN="Right" class="textred" >$expenditure</TD>
</TR>
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER  ><b>Grand Total</b></TD>
   <TD width="50%" ALIGN="Right"></TD>
   <TD width="26%" ALIGN="Right" ><b>$billing_total</b></TD>
</TR>
$red_font_off
~;
   
$content .=qq~
</TR></TABLE>
~;



#$content .=qq~ revenue=$revenue expenditure=$expenditure~;

  if ($button_text eq "Modify Record") {
     print " <INPUT TYPE=button  onClick=\" myForm.action.value='nuovo';this.form.submit();\"  VALUE=\"nuovo\" > ";
  };




#  Billing header1
 $datum = &get_date;

$datum =~ s/at/  u /;

$header = qq~
<br><br>
<p align="left">
<br>
Datum: $datum<br><br>
obenauf korisnik: <B>$obenauf_customer</B><br>
Broj_kartice: 	<B>$search_for</B><br><br>



Do danas ste skupili  <b>$bodovi </b> bodova.<br>

Dolje se nalazi ispis svih transakcija u $mm mjesecu. <br>
</p>
<br>
<br>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=80%>
    <TR BGCOLOR="#e0e0e0">
<TD width="24%" ALIGN=CENTER><B>TimeStamp</B></TD>
<TD width="50%" ALIGN=CENTER><B>Sales point</B></TD>
<TD width="26%" ALIGN=CENTER><B>Amount</B></TD>
</TR>

	
~;


print $header;
print $content;

$style =qq~
<head>
<style>  
.textorange{
	color: #D46300;
}
A.textorange:link {
	color: #D46300;
	text-decoration: none;	
}

A.textorange:visited {
	color: #D46300;
	text-decoration: none;	
}

A.textorange:active {
	color: #D46300;
	text-decoration: none;	
}


.textred{
	color: #ff0000;
}
A.textred:link {
	color: #ff0000;
	text-decoration: none;	
}

A.textred:visited {
	color: #ff0000;
	text-decoration: none;	
}

A.textred:active {
	color: #ff0000;
	text-decoration: none;	
}
</style>
<head>
~;
##########################################################################
#print " <br>SENDMAIL test";

$subject ="obenauf billing report";

# sendmail setup
$SENDMAIL = "/usr/sbin/sendmail -t";
$FROM = "obenauf testing <jjp\@testing.com>";
$TO = "$email";




open(MAIL, "|$SENDMAIL");


print MAIL <<EOM;
From: $FROM
To: $TO
Subject: $subject
Content-type: text/html; charset="iso-8859-1"
<html>
$style
<body>

$header
$content
<br>
Zahvaljujemo Vam na sudjelovanju u obenauf programu vjernosti. 
</body>
</html>
EOM


close (MAIL);
##########################################################################

print "<p>";

&html_footer;
} # End of mail_billing subroutine.































############# Billing Results Screen ################
sub billing_results{
  my $search_for = $_[0]; 
  my $search_field = $_[1];
  my @results   =();
  my %shop_hash =();
  my $revenue=0;
  my $expenditure=0;

&html_header($title);

# build shop hash
  $database_shops    = "$ENV{'DOCUMENT_ROOT'}/obenauf/obenauf_shops.txt";	

  open (DB, "$database_shops") or die "Error opening database. $database_shops $!\n";
    while(<DB>){

   
           ($key,$owner,$time_stamp,
            $TERMINAL_terminalId,$TERMINAL_terminalPwd,$TERMINAL_salesPoint,$TERMINAL_address,
            $TERMINAL_telephone,$TERMINAL_email,$TERMINAL_GIS_coordinates,$TERMINAL_referral_person,
            $TERMINAL_contractNumber,$TERMINAL_activityStatus) = split(/\|/, $_);


          $terminalId = $TERMINAL_terminalId;
          $terminalId =~ s/\s//g;

          if ($terminalId ne "") { 
             $shop_hash{$terminalId} ="$TERMINAL_salesPoint - $TERMINAL_address";
          };

                
    } # End of while.
  close (DB);



#     $billing_ = "$ENV{'DOCUMENT_ROOT'}/obenauf_billing/billing2012_07.txt";
      $billing_ = "$ENV{'DOCUMENT_ROOT'}/obenauf_billing/$billing_file";

 open (BILL, "$billing_") or die "Error opening $billing_  $!\n"; 
 @Billing_line = <BILL>;
 close (BILL);

  foreach $billing_record (@Billing_line){
    ($key,$LOGuser,$when_added,$obenauf_Day,$obenauf_TimeStamp,$obenauf_TerminalId,$obenauf_CardId,$obenauf_Amount) = split(/\|/, $billing_record);      
    if ($obenauf_CardId =~ /$search_for/oi) { push @results,$billing_record};
  } # End of foreach

$count = @results;


  if ($count > 1) {
      $content = qq~<P>Total Found: <B>$count</B> billing records<BR>~;
  };

 


print "<br>";


$which_search = $choose;


    print "<INPUT TYPE=\"hidden\" NAME=\"sort_on\" VALUE=\"$sort\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"display\" VALUE=\"$display\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"search_for\" VALUE=\"$search_for\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"key\" VALUE='0'>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"bodovi\" VALUE=\"$bodovi\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"$email\">\n";

# end of Billing header
$content ="";

  foreach $record (@results){
    ($key,$LOGuser,$when_added,$julian_day,$timeStamp,$terminalId,$cardId,$amount) = split(/\|/, $record); 


     if ($amount > 0) {$revenue +=$amount}
     else {$expenditure +=$amount;}

$class="";


if ($amount < 0) {
  $class="class='textred'";
};

$amount_comma =$amount;
$amount_comma =~ s/\./\,/g;

$content .=qq~
$red_font_on
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER $class >$timeStamp</TD>
   <TD width="50%" ALIGN="Right" $class>$shop_hash{$terminalId}</TD>
   <TD width="26%" ALIGN="Right" $class >$amount_comma</TD>
</TR>
$red_font_off
~;
     
  } # End of foreach loop.


$bodovi = sprintf("%.2f", $bodovi);

$revenue      = sprintf("%.2f", $revenue);
$expenditure  = sprintf("%.2f", $expenditure);

$billing_total = $revenue + $expenditure;
$billing_total = sprintf("%.2f", $billing_total);

$revenue      =~ s/\./\,/g;
$expenditure  =~ s/\./\,/g;
$billing_total=~ s/\./\,/g;

$content .=qq~
$red_font_on
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER  >Ukupno sakupljeno bodova</b></TD>
   <TD width="50%" ALIGN="Right"></TD>
   <TD width="26%" ALIGN="Right" >$revenue</TD>
</TR>
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER class="textred" >Ukupno potro&scaron;eno bodova</b></TD>
   <TD width="50%" ALIGN="Right"></TD>
   <TD width="26%" ALIGN="Right" class="textred" >$expenditure</TD>
</TR>
<TR BGCOLOR="#e0e0e0">
   <TD width="24%" ALIGN=CENTER  ><b>Grand Total</b></TD>
   <TD width="50%" ALIGN="Right"></TD>
   <TD width="26%" ALIGN="Right" ><b>$billing_total</b></TD>
</TR>
$red_font_off
~;
   
$content .=qq~
</TR></TABLE>
~;



#$content .=qq~ revenue=$revenue expenditure=$expenditure~;

  if ($button_text eq "Modify Record") {
     print " <INPUT TYPE=button  onClick=\" myForm.action.value='nuovo';this.form.submit();\"  VALUE=\"nuovo\" > ";
  };




#  Billing header2
$datum = &get_date;
$datum =~ s/at/ u /;

$header = qq~
<br><br>
<p align="left">
<br>
Datum: $datum<br><br>
obenauf korisnik: <B>$obenauf_customer</B><br>
Broj_kartice: 	<B>$search_for</B><br><br>



Do danas ste skupili  <b>$bodovi </b> bodova.<br>

Dolje se nalazi ispis svih transakcija u $mm mjesecu. <br>
</p>
<br>
<br>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=80%>
    <TR BGCOLOR="#e0e0e0">
<TD width="24%" ALIGN=CENTER><B>TimeStamp</B></TD>
<TD width="50%" ALIGN=CENTER><B>Sales point</B></TD>
<TD width="26%" ALIGN=CENTER><B>Amount</B></TD>
</TR>

	
~;


print $header;
print $content;

$style =qq~
<head>
<style>  
.textorange{
	color: #D46300;
}
A.textorange:link {
	color: #D46300;
	text-decoration: none;	
}

A.textorange:visited {
	color: #D46300;
	text-decoration: none;	
}

A.textorange:active {
	color: #D46300;
	text-decoration: none;	
}


.textred{
	color: #ff0000;
}
A.textred:link {
	color: #ff0000;
	text-decoration: none;	
}

A.textred:visited {
	color: #ff0000;
	text-decoration: none;	
}

A.textred:active {
	color: #ff0000;
	text-decoration: none;	
}
</style>
<head>
~;

print "<p>";

&html_footer;
} # End of billing_results subroutine.



























########### Search Cards Database #############
sub search_cards{
  my $search_for   = $_[0];
  $target_record ="";
  my @results =();
  my $cardId;

  $search_for =~ s/\s//g;
  $search_for =~ s/\D//g;

  
  open (DB, "$database") or die "Error opening database. $database $!\n";
    while(<DB>){

        ($key,$dbuser,$when_added,$CARD_Broj_kartice,
         $CARD_OIB,$CARD_Ime,$CARD_Prezime,$CARD_Datum_rodjenja,
         $CARD_Exp_date,$CARD_Bodovi,$CARD_Brand,$CARD_email,$CARD_popup) = split(/\|/, $_);

          $cardId = +$CARD_Broj_kartice;
          $cardId =~ s/\s//g;

          if ($cardId > 0) { 
             if ($cardId eq $search_for) { push @results, $_};
          };

                
    } # End of while.
  close (DB);


my $count = @results;
if ($count < 1){ 
    $target_record =""; 
    $err_message="Error=100 Neregistrirana kartica $search_for"; 
}

if($count > 1){ 
    $target_record =""; 
    $err_message="Error=101 Too many results found for CardId $search_for"; 
}

if($count == 1){ 
    $target_record = @results[0];
    $err_message="";
};

# Print HTTP header for PLAIN TEXT
print "$CARD_Ime";

} # End of search_cards subroutine.





























########### Search Key Record #############
sub search_key{
  my $search_for   = $_[0];
     $target_record ="";
  my @results =();
  my $cardId;
  my $key;

  $search_for =~ s/\s//g;
  $search_for =~ s/\D//g;

  
  open (DB, "$database") or die "Error opening database. $database $!\n";
    while(<DB>){

        ($key,$dbuser,$when_added,$CARD_Broj_kartice,
         $CARD_OIB,$CARD_Ime,$CARD_Prezime,$CARD_Datum_rodjenja,
         $CARD_Exp_date,$CARD_Bodovi,$CARD_Brand,$CARD_email,$CARD_popup) = split(/\|/, $_);

          $cardId =~ s/\s//g;

          if ($key > 0) { 
             if ($key eq $search_for) { push @results, $_};
          };

                
    } # End of while.
  close (DB);


my $count = @results;
if ($count < 1){ 
    $target_record =""; 
    $err_message="Error=100 Neregistrirana kartica $search_for"; 
}

if($count > 1){ 
    $target_record =""; 
    $err_message="Error=101 Too many results found for CardId $search_for"; 
}

if($count == 1){ 
    $target_record = @results[0];
    $err_message="";
};

# Print HTTP header for PLAIN TEXT


} # End of search_key subroutine.































############## Delete Records #################

sub delete_records   {              
  open (DATABASE, "$database") or die "Error opening file: $!\n";
  while (<DATABASE>)   {
    $line = $_;
    chop $line;
    @dbfields = split (/\|/, $line);
    $deleted = "no";
    if ($dbfields[0] eq $q->param(key)) { $deleted = "yes"; if ($user eq $dbfields[1]) { $security_satisfied = "yes"; } }
    elsif ($deleted ne "yes") { $new_data .= "$line\n"; }
    } #end of while
  close (DATABASE);
  if ($authenticate ne "yes") { $security_satisfied = "yes"; }
  if ($security_satisfied ne "yes" && $record_ownership eq "yes" && $admin_user_name ne "$user")
    {
    $error_message = "Lei non ha le permessi necessari per l\92accesso a questa card!";
    &access_problem($error_message);
    exit;
    }  else  {
    flock DATABASE, $EXCLUSIVE;
    open (DATABASE, ">$database") or die "Error opening file: $!\n";
    print DATABASE "$new_data";
    close (DATABASE);
    flock DATABASE, $UNLOCK;
    }
  } 











################# Add Record ##################

sub add_record {
  foreach $required (@required){
  if($q->param($required) eq "") { 
  $title = "Add A Record"; $error_message = "You did not fill out the required information!"; &access_problem($error_message); exit; } }
  $when_added = &get_date;
  $key   = time();
  $record=$key;
  $record  .= "\|$user";
  $record  .= "\|$when_added";
  foreach $field (@fields){ ${$field}  = $q->param($field); ${$field}  = filter(${$field}); $record  .= "\|${$field}"; }
   unless (-e $database){ open (DB, ">$database") || die "Error creating database.  $!\n"; }
   else { open (DB, ">>$database") || die "Error opening database.  $!\n"; }
   flock DB, $EXCLUSIVE;
   seek DB, 0, 2;
   print DB "$record\n";
   flock DB, $UNLOCK;
  close(DB);
} # End of add_record subroutine.




















############# Results Screen ################
sub show_card{
&html_header($title);

$cerca = $search_for;



$which_search = $choose;



    print "<INPUT TYPE=\"hidden\" NAME=\"key\" VALUE='0'>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"obenauf_customer\" VALUE='0'>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"bodovi\" VALUE='0'>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE='0'>\n";


    $record =@results[0];
    chomp $record;
    ($key,$dbuser,$when_added,@field_vals) = split(/\|/, $record); 

$recorded_password = $field_vals[14];


# assign the relevant values of each field in the record
$x=0;
foreach $field (@fields){
  $item = $field_vals[$x];
  ${$field}  =  $item; 
  $x += 1;
} 
# End of foreach assign field loop.



if ($recorded_password eq $login_password) { 

$CARD_Popup_message =~ s/#/ /g;
print<<WWW;
<br>
<h1>
$CARD_Popup_message

</h1>

<P><TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 WIDTH=$record_width>
WWW


   $x=0;
   foreach $field (@fields){
     ${$field} = $field_vals[$x];
     $x++;
   } 
  $x=0;
  foreach $field (@fields){
  $item = $field_vals[$x];

$background_color="#e0e0e0";
$line= "<TD BGCOLOR='#efefef' WIDTH=100%>$item</TD>";
if ($x > 9) {$background_color='#B6DB91'; $line= "<TD BGCOLOR='#D5FFD5' WIDTH=100%>$item</TD>" };

$campo = $field;

print<<HTML;
     <TR>
      <TD BGCOLOR=$background_color><B>\u$campo</B></TD>
      $line
     </TR>
HTML
   $x++;
   } # End of foreach field loop.

    $obenauf_customer ="$CARD_Ime $CARD_Prezime";

    print "<TR BGCOLOR=\"\#e0e0e0\"><TD ALIGN=CENTER COLSPAN=2> ";

    chomp $CARD_Email;



    print "
           <INPUT TYPE=button  onClick=\"myForm.key.value='$key';myForm.search_field.value='all'; myForm.action.value='Edit_opera';this.form.submit();\"  VALUE=\"Edit\" >
           <INPUT TYPE=button  onClick=\"myForm.email.value='$CARD_Email';myForm.bodovi.value='$CARD_Bodovi';myForm.obenauf_customer.value='$obenauf_customer';myForm.search_for.value='$CARD_Broj_kartice';myForm.action.value='billing_report';this.form.submit();\" VALUE=\"Billing report\" > 
           <INPUT TYPE=button  onClick=\"myForm.email.value='$CARD_Email';myForm.bodovi.value='$CARD_Bodovi';myForm.obenauf_customer.value='$obenauf_customer';myForm.search_for.value='$CARD_Broj_kartice';myForm.action.value='email_billing';this.form.submit();\" VALUE=\"Email billing\" > 

";


  print "</TABLE><P>";


  my $billing_path= "$ENV{'DOCUMENT_ROOT'}/obenauf_billing";
  my $file;
  my @filenames =();
  my @billing_files =();

  opendir(DIRHANDLE,$billing_path );
  @filenames = readdir(DIRHANDLE);
  closedir(DIRHANDLE);

  @billing_files = grep(/billing/,@filenames);

  my @file_names =sort(@billing_files);

  $options = qq~~;
  $n_files = @file_names;
  $x =0;
  foreach $file (@file_names) {
     chomp $file;
     $period =$file;
     $x++;
     $selected ="";
     if ($n_files == $x) {
        $selected="selected";
     };
     $period =~ s/(\.txt)|(billing)//g;
     $options .= qq~<option value="$file" $selected >$period</option> \n~;   
  }

print qq~
<b>Billing period: </b><br>
<select name="billing_file">
  $options
</select>
~;


} 
else {
  print qq~
  <h1>
   Netočni pristupni podaci. Ukoliko ste zaboravili pristupne podatke, kontaktirajte OBANAUF!
  </h1>
  ~;
}








$which_search = $choose;


    print "<INPUT TYPE=\"hidden\" NAME=\"sort_on\" VALUE=\"$sort\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"display\" VALUE=\"$display\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"search_for\" VALUE=\"$search_for\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"search_field\" VALUE=\"$search_field\">\n";

print "<p>";
$cerca_t=$cerca;
if ($cerca eq '.') {$cerca_t='tutto'};

&html_footer;
} # End of show_card subroutine.






























############### Modify Screen new ################
sub print_modify_page{
  ($key,$dbuser,$when_added,@field_vals) = split(/\|/, $target_record); 
$title="Modify Record";
&html_header($title);

#print "new $key";

# assign the relevant values of each field in the record
$x=0;
foreach $field (@fields){
  $item = $field_vals[$x];
  ${$field}  =  $item; 
  $x += 1;
} 
# End of foreach assign field loop.
  print<<HTML;

<SCRIPT LANGUAGE="JavaScript">

<!-- This script locksout <CR> i.e. Enter Key and requires the SUBMIT button to be clicked to send form -->
<!-- Begin

function tabOnEnter (field, evt) {
      var keyCode = document.layers ? evt.which : document.all ? 
     evt.keyCode : evt.keyCode;
      if (keyCode != 13)
        return true;
      else {
        getNextElement(field).focus();
        return false;
      }
}


function getNextElement (field) 
{
    var frm = field.form;
    var bIs = false;
    for (var e=0;e<frm.length;e++)
    {
      if(frm[e].type!="hidden" && bIs) return frm.elements[e];
      if (field==frm[e]) bIs=true;
    }
}

//  End -->
</script>


   <INPUT TYPE=HIDDEN NAME=key value="$key">
    <TABLE BORDER=0 CELLSPACING=0>
        <TR>
         <TD><B>CARD_Broj_kartice:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Broj_kartice" VALUE="$CARD_Broj_kartice" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_ID_OIB:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_ID_OIB" VALUE="$CARD_ID_OIB" SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Ime:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Ime" VALUE="$CARD_Ime" SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Prezime:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Prezime" VALUE="$CARD_Prezime" SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Datum_rodjenja:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Datum_rodjenja" VALUE="$CARD_Datum_rodjenja" SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Exp_date:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Exp_date" VALUE="$CARD_Exp_date" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Bodovi:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Bodovi" VALUE="$CARD_Bodovi" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Brand:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Brand" VALUE="$CARD_Brand" SIZE=40 readonly onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Email:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Email" VALUE="$CARD_Email" SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Popup_message:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Popup_message" VALUE="$CARD_Popup_message" readonly SIZE=40 readonly onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Popup_autodelete:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Popup_autodelete" VALUE="$CARD_Popup_autodelete" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Referral:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Referral" VALUE="$CARD_Referral" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Limit:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Limit" VALUE="$CARD_Limit" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Type:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Type" VALUE="$CARD_Type" readonly SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        <TR>
         <TD><B>CARD_Password:</B></TD>
         <TD><INPUT TYPE=TEXT NAME="CARD_Password" VALUE="$CARD_Password" SIZE=40  onkeydown="return tabOnEnter (this, event);" ></TD>
         </TR>
        </TABLE>
  <BR>
<INPUT TYPE=button  onClick=" myForm.action.value='save_record';this.form.submit();"  VALUE="Save" >

   <P>
HTML
&html_footer;
}


















