changed note field in tc_accomplishment to notes
[eq/.git] / bin / parse_ward_data
index 7a3c07249ef4b5edafa6a21d19f7114a1f2fc153..2a5848e56720362a92a8d089d7bfffca2ed5218b 100755 (executable)
@@ -3,89 +3,56 @@
 use DBI;
 use Getopt::Std;
 
-###################################################
-# GLOBALS
-$dbname = "phpgroupware";
-$dbhost = "192.168.0.2"; # This can be an IP address or a name
-$dbport = 3306;
-$dbuser = "phpgroupware"; # This may require an additional '\@localhost'
-$dbpass = "phpgroupware"; 
-###################################################
+$mydir = `cd \$(dirname $0) 2>/dev/null; pwd`; chomp($mydir);
+unshift @INC,("$mydir/../setup");
+if( -f "$mydir/../setup/db_config.local") { require "db_config.local"; }
+else { require "db_config"; }
 
 %hometeaching_data = ();
 %membership_data = ();
-getopts('vsn:o:b');
-
-$monthname2num{'Jan'} = '01';
-$monthname2num{'Feb'} = '02';
-$monthname2num{'Mar'} = '03';
-$monthname2num{'Apr'} = '04';
-$monthname2num{'May'} = '05';
-$monthname2num{'Jun'} = '06';
-$monthname2num{'Jul'} = '07';
-$monthname2num{'Aug'} = '08';
-$monthname2num{'Sep'} = '09';
-$monthname2num{'Oct'} = '10';
-$monthname2num{'Nov'} = '11';
-$monthname2num{'Dec'} = '12';
+getopts('vsn:o');
 
 ######################################################################
 # SUBROUTINES
 ######################################################################
 sub csv_to_hash
 {
-    my ($filename, $hashref) = @_;
-
-    open(FILE,$filename) || die "-E- Could not open $filename for reading\n";
-
-    my $found_header = 0; my $index = 0;
-    while(<FILE>)
-    {
-       $line = $_;
-       @data = split /\",/, $line;
-       if(!$found_header) { @header = @data; $found_header = 1; }
-       else {
-           foreach $i (0..$#data-1) {
-               $data[$i] =~ s/\"//g;
-               $header[$i] =~ s/\"//g;
-               $hashref->{$index}{$header[$i]} = $data[$i];
-               #print "$index: $i: $header[$i]: $data[$i]\n";
-           }
-           $index++;
+       my ($filename, $hashref) = @_;
+
+       open(FILE,$filename) || die "-E- Could not open $filename for reading\n";
+
+       my $found_header = 0; my $index = 0;
+       while(<FILE>)
+       {
+               $line = $_;
+               @data = split /\",/, $line;
+               if(!$found_header) { @header = @data; $found_header = 1; }
+               else {
+                       foreach $i (0..$#data-1) {
+                               $data[$i] =~ s/\"//g;
+                               $header[$i] =~ s/\"//g;
+                               $hashref->{$index}{$header[$i]} = $data[$i];
+                               #print "$index: $i: $header[$i]: $data[$i]\n";
+                       }
+                       $index++;
+               }
        }
-    }
-    
-    close(FILE);
-}
-
-######################################################################
-sub print_hash
-{
-    my ($hashref) = @_;
 
-    foreach $key (sort {$a <=> $b} keys %$hashref) {
-       print "Index: $key\n";
-       foreach $field (keys %{$hashref->{$key}}) {
-           print "$field: $hashref->{$key}{$field}\n";
-       }
-       print "\n";
-    }
+       close(FILE);
 }
 
 ######################################################################
-sub print_birthdays
+sub print_hash
 {
-    my ($hashref) = @_;
-
-    foreach $key (sort {$a <=> $b} keys %$hashref) {
-       $name = "";
-       $birthday = "";
-       foreach $field (keys %{$hashref->{$key}}) {
-           if($field =~ /Full Name/) { $name = $hashref->{$key}{$field}; }
-           if($field =~ /Birth/) { $birthday = $hashref->{$key}{$field}; }
+       my ($hashref) = @_;
+
+       foreach $key (sort {$a <=> $b} keys %$hashref) {
+               print "Index: $key\n";
+               foreach $field (keys %{$hashref->{$key}}) {
+                       print "$field: $hashref->{$key}{$field}\n";
+               }
+               print "\n";
        }
-       if($name ne "" && $birthday ne "") { printf "%-30s %-10s\n",$name,$birthday; }
-    }
 }
 
 ######################################################################
@@ -110,14 +77,12 @@ print "-> Processing all ward data files in $datadir\n";
 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
 
 if($opt_v) {
-    print "-> Membership Data Dump\n\n";
-    &print_hash(\%membership_data);
-    print "-> HomeTeaching Data Dump\n\n";
-    &print_hash(\%hometeaching_data);
+       print "-> Membership Data Dump\n\n";
+       &print_hash(\%membership_data);
+       print "-> HomeTeaching Data Dump\n\n";
+       &print_hash(\%hometeaching_data);
 }
 
-if($opt_b) { &print_birthdays(\%membership_data); }
-
 if($opt_s) { $dbh->disconnect(); exit; }
 
 ###################################################