6 ###################################################
8 $dbname = "phpgroupware";
9 $dbhost = "192.168.0.2"; # This can be an IP address or a name
11 $dbuser = "phpgroupware"; # This may require an additional '\@localhost'
12 $dbpass = "phpgroupware";
13 ###################################################
15 %hometeaching_data = ();
16 %membership_data = ();
19 $monthname2num{'Jan'} = '01';
20 $monthname2num{'Feb'} = '02';
21 $monthname2num{'Mar'} = '03';
22 $monthname2num{'Apr'} = '04';
23 $monthname2num{'May'} = '05';
24 $monthname2num{'Jun'} = '06';
25 $monthname2num{'Jul'} = '07';
26 $monthname2num{'Aug'} = '08';
27 $monthname2num{'Sep'} = '09';
28 $monthname2num{'Oct'} = '10';
29 $monthname2num{'Nov'} = '11';
30 $monthname2num{'Dec'} = '12';
32 ######################################################################
34 ######################################################################
37 my ($filename, $hashref) = @_;
39 open(FILE,$filename) || die "-E- Could not open $filename for reading\n";
41 my $found_header = 0; my $index = 0;
45 @data = split /\",/, $line;
46 if(!$found_header) { @header = @data; $found_header = 1; }
48 foreach $i (0..$#data-1) {
50 $header[$i] =~ s/\"//g;
51 $hashref->{$index}{$header[$i]} = $data[$i];
52 #print "$index: $i: $header[$i]: $data[$i]\n";
61 ######################################################################
66 foreach $key (sort {$a <=> $b} keys %$hashref) {
67 print "Index: $key\n";
68 foreach $field (keys %{$hashref->{$key}}) {
69 print "$field: $hashref->{$key}{$field}\n";
75 ######################################################################
80 foreach $key (sort {$a <=> $b} keys %$hashref) {
83 foreach $field (keys %{$hashref->{$key}}) {
84 if($field =~ /Full Name/) { $name = $hashref->{$key}{$field}; }
85 if($field =~ /Birth/) { $birthday = $hashref->{$key}{$field}; }
87 if($name ne "" && $birthday ne "") { printf "%-30s %-10s\n",$name,$birthday; }
91 ######################################################################
93 ######################################################################
95 ###################################################
96 # Open a connection to the database
97 $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$dbpass,{
99 PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
101 ###################################################
102 # Process command line options
103 if(defined $opt_n) { $datadir = $opt_n; }
104 else { $datadir = shift(@ARGV); }
105 print "-> Processing all ward data files in $datadir\n";
107 ###################################################
108 # Parse Ward Data Files
109 &csv_to_hash("$datadir/Membership.csv",\%membership_data);
110 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
113 print "-> Membership Data Dump\n\n";
114 &print_hash(\%membership_data);
115 print "-> HomeTeaching Data Dump\n\n";
116 &print_hash(\%hometeaching_data);
119 if($opt_b) { &print_birthdays(\%membership_data); }
121 if($opt_s) { $dbh->disconnect(); exit; }
123 ###################################################
124 # Disconnect from the database
127 ######################################################################