#!/usr/bin/perl

use DBI;

require "/home/j204sc/bin/cgi-lib2.pl";          ## Perl Handling Sub-routines
require "/home/j204sc/bin/currency.pl";          ## Currency Format Sub-routine
require "/home/j204sc/bin/DEFAULT_FONTS";        ## Default Fonts
require "/home/j204sc/bin/ORACLE_CONNECTION";    ## Oracle DB Connection Routine

if ($dbh eq '') { print "$FA Connection to Oracle Failed."; exit; }

#**************************************************************#
#                                                              #
#  Job j204_cb_email4 will create the Batch Email List         #
#                                                              #
#**************************************************************#

$DATE1 = `date`;
chop $DATE1;

print <<ENDOFFILE;

**=====================================================**
** j204_cb_email4:  begin execution                    **
**=====================================================**
$DATE1

ENDOFFILE

###############
#  Section 1  #
###############

open(OUTPUT1, ">/home/j204sc/output/dialin.email.ids");

$sql_cmd = "
select distinct 
       a_phone_n
     , f_fypd     
     , a_badge_n
     , a_uid_x        
  from t204_cb_email_ids   
 where f_call_i = 'LDAP1'
order by 3, 1, 2
     ";


$stmt = $dbh->prepare("
    $sql_cmd
     ") or DBI::errstr;

$stmt->execute;

print <<ENDOFFILE;
 $sql_cmd
ENDOFFILE

$SP = '                                                                   ';
$SC   = ':';
$TYP  = '2';

$i = 0;

while ( @data = $stmt->fetchrow_array() ) {

$data[0] = substr($data[0]."        ",0,8);
$data[1] = substr($data[1]."      ",0,6);
$data[2] = substr($data[2]."        ",0,8);
$data[3] = substr($data[3]."                             ",0,30);

printf (OUTPUT1 "%s%s%s%s%s%s%s%s%s\n",$data[0],$SC,$data[1],$SC,$data[2],$SC,$data[3]);


$i = $i + 1;

  }

$stmt->finish;

close(OUTPUT1);

### END OF SECTION


$DATE1 = `date`;
chop $DATE1;

print <<ENDOFFILE;

Number of Records: $i  

*AIX*Successful exit -

**=====================================================**
** j204_cb_email4:  end execution                      **
**=====================================================**
$DATE1

ENDOFFILE

$dbh->disconnect;

exit;
