5 ###################################################
7 $dbname = "phpgroupware";
8 $dbhost = "192.168.0.2";
10 $dbuser = "phpgroupware";
11 $dbpass = "phpgroupware";
12 %hometeaching_data = ();
13 %membership_data = ();
16 $monthname2num{'Jan'} = '01';
17 $monthname2num{'Feb'} = '02';
18 $monthname2num{'Mar'} = '03';
19 $monthname2num{'Apr'} = '04';
20 $monthname2num{'May'} = '05';
21 $monthname2num{'Jun'} = '06';
22 $monthname2num{'Jul'} = '07';
23 $monthname2num{'Aug'} = '08';
24 $monthname2num{'Sep'} = '09';
25 $monthname2num{'Oct'} = '10';
26 $monthname2num{'Nov'} = '11';
27 $monthname2num{'Dec'} = '12';
29 ######################################################################
31 ######################################################################
34 my ($filename, $hashref) = @_;
36 open(FILE,$filename) || die "-E- Could not open $filename for reading\n";
38 my $found_header = 0; my $index = 0;
42 @data = split /\",/, $line;
43 if(!$found_header) { @header = @data; $found_header = 1; }
45 foreach $i (0..$#data-1) {
47 $header[$i] =~ s/\"//g;
48 $hashref->{$index}{$header[$i]} = $data[$i];
49 #print "$index: $i: $header[$i]: $data[$i]\n";
58 ######################################################################
63 foreach $key (sort {$a <=> $b} keys %$hashref) {
64 print "Index: $key\n";
65 foreach $field (keys %{$hashref->{$key}}) {
66 print "$field: $hashref->{$key}{$field}\n";
72 ######################################################################
75 #+-------+--------------------+------+-----+---------+-------+
76 #| Field | Type | Null | Key | Default | Extra |
77 #+-------+--------------------+------+-----+---------+-------+
78 #| aaronic | int(16) unsigned | | PRI | 0 | A |
79 #| name | varchar(60) | YES | | NULL | |
80 #| phone | varchar(12) | YES | | NULL | |
81 #| valid | tinyint(1) | YES | | NULL | |
82 #+-------+--------------------+------+-----+---------+-------+
83 sub update_eq_aaronic_table
85 print "-> Updating eq_aaronic table\n";
86 foreach $index (keys %membership_data)
88 $hashref = $membership_data{$index};
89 foreach $key (keys %$hashref) {
90 if($key =~ /Priesthood/i &&
91 ($membership_data{$index}{$key} =~ /^Teacher\s*$/i ||
92 $membership_data{$index}{$key} =~ /^Priest\s*$/i)) {
93 $aaronic_name = $membership_data{$index}{'Preferred Name'};
94 $phone = $membership_data{$index}{'Phone 1'};
95 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
96 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
97 $sth = $dbh->prepare("select * from eq_aaronic where name='$aaronic_name'");
98 $sth->execute or die "-E- DB error: $DBI::errstr\n";
100 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
101 my $rows = scalar @data;
103 # No existing records found for this aaronic, make a new entry
104 print " Adding new Aaronic: $aaronic_name\n";
105 $sth = $dbh->prepare("insert into eq_aaronic values (NULL,'$aaronic_name','$phone',1)");
106 $sth->execute or die "-E- DB error: $DBI::errstr\n";
107 } elsif($rows == 1) {
108 # An existing record was found for this aaronic, update it if it is valid
109 if($data[0]->{valid} == 1) {
110 print " Updating existing aaronic: $aaronic_name\n";
111 $sth = $dbh->prepare("update eq_aaronic set phone='$phone' where name='$aaronic_name'");
112 $sth->execute or die "-E- DB error: $DBI::errstr\n";
115 # More than one record was found. Error! This shouldn't happen.
116 print " -E- More than one record found ($rows) for aaronic name: $aaronic_name\n";
125 #+------------+------------------+------+-----+---------+-------+
126 #| Field | Type | Null | Key | Default | Extra |
127 #+------------+------------------+------+-----+---------+-------+
128 #| elder | int(16) unsigned | | PRI | 0 | A |
129 #| name | varchar(60) | YES | | NULL | |
130 #| phone | varchar(12) | YES | | NULL | |
131 #| valid | tinyint(1) | YES | | NULL | |
132 #+------------+------------------+------+-----+---------+-------+
133 sub update_eq_elder_table
135 print "-> Updating eq_elder table\n";
137 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
138 $sth = $dbh->prepare("update eq_elder set valid=0");
139 $sth->execute or die "-E- DB error: $DBI::errstr\n";
141 foreach $index (keys %membership_data)
143 $hashref = $membership_data{$index};
144 foreach $key (keys %$hashref) {
145 if($key =~ /Priesthood/i && $membership_data{$index}{$key} =~ /Elder/i) {
146 $elder_name = $membership_data{$index}{'Preferred Name'};
147 $phone = $membership_data{$index}{'Phone 1'};
148 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
149 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
150 $sth = $dbh->prepare("select * from eq_elder where name='$elder_name'");
151 $sth->execute or die "-E- DB error: $DBI::errstr\n";
153 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
154 my $rows = scalar @data;
156 # No existing records found for this elder, make a new entry
157 print " Adding new Elder: $elder_name\n";
158 $sth = $dbh->prepare("insert into eq_elder values (NULL,'$elder_name','$phone',1)");
159 $sth->execute or die "-E- DB error: $DBI::errstr\n";
160 } elsif($rows == 1) {
161 # An existing record was found for this elder, update it
162 print " Updating existing Elder: $elder_name\n";
163 $sth = $dbh->prepare("update eq_elder set valid=1 where name='$elder_name'");
164 $sth->execute or die "-E- DB error: $DBI::errstr\n";
166 $sth = $dbh->prepare("update eq_elder set phone='$phone' where name='$elder_name'");
168 $sth = $dbh->prepare("update eq_elder set phone=NULL where name='$elder_name'");
170 $sth->execute or die "-E- DB error: $DBI::errstr\n";
172 # More than one record was found. Error! This shouldn't happen.
173 print " -E- More than one record found ($rows) for Elder: $elder_name\n";
182 #+------------+------------------+------+-----+---------+-------+
183 #| Field | Type | Null | Key | Default | Extra |
184 #+------------+------------------+------+-----+---------+-------+
185 #| district | int(16) unsigned | | PRI | 0 | |
186 #| name | varchar(30) | YES | | NULL | |
187 #| supervisor | int(16) unsigned | YES | | NULL | |
188 #| valid | tinyint(1) | YES | | NULL | |
189 #+------------+------------------+------+-----+---------+-------+
190 sub update_eq_district_table
192 # Districts should be created by hand. This subroutine only
193 # updates the supervisor's ID in each district.
194 print "-> Updating eq_district table\n";
195 $sth = $dbh->prepare("select * from eq_district");
196 $sth->execute or die "-E- DB error: $DBI::errstr\n";
197 while($sqlhashref = $sth->fetchrow_hashref) {
198 $supervisor_name = $sqlhashref->{name};
199 $district = $sqlhashref->{district};
200 $sth2 = $dbh->prepare("select * from eq_elder where name='$supervisor_name'");
201 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
202 $sqlhashref2 = $sth2->fetchrow_hashref;
203 $supervisor_id = $sqlhashref2->{elder};
205 $sth2 = $dbh->prepare("update eq_district set supervisor='$supervisor_id' where district='$district'");
206 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
213 #+---------------+------------------+------+-----+---------+-------+
214 #| Field | Type | Null | Key | Default | Extra |
215 #+---------------+------------------+------+-----+---------+-------+
216 #| companionship | int(16) unsigned | | | 0 | |
217 #| elder | int(16) unsigned | YES | | NULL | |
218 #| aaronic | int(16) unsigned | YES | | NULL | |
219 #| district | int(16) unsigned | YES | | NULL | |
220 #| valid | tinyint(1) | YES | | NULL | |
221 #+---------------+------------------+------+-----+---------+-------+
222 sub update_eq_companionship_table
224 print "-> Updating eq_companionship table\n";
226 # First, mark all existing companionships as invalid in case they have been dissolved
227 $sth = $dbh->prepare("update eq_companionship set valid=0");
228 $sth->execute or die "-E- DB error: $DBI::errstr\n";
229 # Second, mark all the aaronic invalid. We'll only mark the ones as valid that are assigned to hometeach
230 $sth = $dbh->prepare("update eq_aaronic set valid=0");
231 $sth->execute or die "-E- DB error: $DBI::errstr\n";
233 foreach $index (keys %hometeaching_data)
235 $hashref = $hometeaching_data{$index};
236 foreach $key (keys %$hashref) {
237 if($key =~ /Quorum/i && $hometeaching_data{$index}{$key} =~ /Elders/i) {
238 foreach $field ("Home Teacher 1","Home Teacher 2") {
239 $elder_name = $hometeaching_data{$index}{$field};
240 if($elder_name eq "") { next; }
241 $sth2 = $dbh->prepare("select * from eq_elder where name='$elder_name'");
242 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
243 $sqlhashref2 = $sth2->fetchrow_hashref;
244 $elder = $sqlhashref2->{elder};
247 $sth2 = $dbh->prepare("select * from eq_aaronic where name='$elder_name'");
248 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
249 $sqlhashref2 = $sth2->fetchrow_hashref;
250 $aaronic = $sqlhashref2->{aaronic};
252 if($aaronic eq "") { print "-W- Unable to find $elder_name in eq_elder or eq_aaronic tables\n"; }
254 $id = $hometeaching_data{$index}{'Comp ID'};
255 $district = $hometeaching_data{$index}{'HT District'};
256 $sth = $dbh->prepare("select * from eq_companionship where elder='$elder' and aaronic='$aaronic' and companionship='$id'");
257 $sth->execute or die "-E- DB error: $DBI::errstr\n";
259 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
260 my $rows = scalar @data;
262 # No existing records found for this companionship, make a new entry
263 print " Adding Elder to companionship: $elder_name -> $id\n";
264 $sth = $dbh->prepare("insert into eq_companionship values ($id,'$elder','$aaronic','$district',1)");
265 $sth->execute or die "-E- DB error: $DBI::errstr\n";
267 # An existing companionship was found for this companionship, update it
268 $sth2 = $dbh->prepare("select * from eq_companionship where district='$district' and companionship='$id'");
269 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
270 if($elder ne "NULL") {
271 print " Updating Companionship with Elder: $elder_name ($elder) -> $id\n";
272 $sth = $dbh->prepare("update eq_companionship set district='$district' where elder='$elder' and companionship='$id'");
273 $sth->execute or die "-E- DB error 'district': $DBI::errstr\n";
274 $sth = $dbh->prepare("update eq_companionship set elder='$elder' where elder='$elder' and companionship='$id'");
275 $sth->execute or die "-E- DB error 'elder': $DBI::errstr\n";
276 $sth = $dbh->prepare("update eq_companionship set valid=1 where elder='$elder' and companionship='$id'");
277 $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n";
279 print " Updating Companionship with Aaronic: $elder_name ($aaronic) -> $id\n";
280 $sth = $dbh->prepare("update eq_companionship set district='$district' where aaronic='$aaronic' and companionship='$id'");
281 $sth->execute or die "-E- DB error: $DBI::errstr\n";
282 $sth = $dbh->prepare("update eq_companionship set aaronic='$aaronic' where aaronic='$aaronic' and companionship='$id'");
283 $sth->execute or die "-E- DB error: $DBI::errstr\n";
284 $sth = $dbh->prepare("update eq_companionship set valid=1 where aaronic='$aaronic' and companionship='$id'");
285 $sth->execute or die "-E- DB error: $DBI::errstr\n";
286 $sth = $dbh->prepare("update eq_aaronic set valid=1 where aaronic='$aaronic'");
287 $sth->execute or die "-E- DB error: $DBI::errstr\n";
299 #+---------------+------------------+------+-----+---------+-------+
300 #| Field | Type | Null | Key | Default | Extra |
301 #+---------------+------------------+------+-----+---------+-------+
302 #| family | int(16) unsigned | | PRI | 0 | A |
303 #| hofh_id | int(16) unsigned | YES | | NULL | |
304 #| name | varchar(30) | YES | | NULL | |
305 #| companionship | int(16) unsigned | YES | | NULL | |
306 #| valid | tinyint(1) | YES | | NULL | |
307 #+---------------+------------------+------+-----+---------+-------+
308 sub update_eq_family_table
310 print "-> Updating eq_family table\n";
312 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
313 $sth = $dbh->prepare("update eq_family set valid=0");
314 $sth->execute or die "-E- DB error: $DBI::errstr\n";
316 foreach $index (keys %membership_data)
318 $hashref = $membership_data{$index};
319 foreach $key (keys %$hashref) {
320 if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Head of Household/i) {
321 $family_name = $membership_data{$index}{'Preferred Name'};
322 $family_name =~ s/\'/\\'/g; #'
323 $id = $membership_data{$index}{'HofH ID'};
325 # Find out how many families match this family's name
326 $sth = $dbh->prepare("select * from eq_family where name='$family_name'");
327 $sth->execute or die "-E- DB error: $DBI::errstr\n";
329 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
330 my $rows = scalar @data;
333 # No existing records found for this family, make a new entry
334 print " Adding new Family: $family_name\n";
335 $sth = $dbh->prepare("insert into eq_family values (NULL,$id,'$family_name','0',1)");
336 $sth->execute or die "-E- DB error: $DBI::errstr\n";
337 } elsif($rows == 1) {
338 # An existing record was found for this family, update it
339 print " Updating existing family: $family_name\n";
340 $sth = $dbh->prepare("update eq_family set hofh_id=$id where name='$family_name'");
341 $sth->execute or die "-E- DB error: $DBI::errstr\n";
342 $sth = $dbh->prepare("update eq_family set valid=1 where name='$family_name'");
343 $sth->execute or die "-E- DB error: $DBI::errstr\n";
345 # More than one record was found. Error! This shouldn't happen.
346 print " -E- More than one record found ($rows) for family name: $family_name\n";
348 # Now update the hometeaching field for this family
349 foreach $index (keys %hometeaching_data)
351 $hashref = $hometeaching_data{$index};
352 foreach $key (keys %$hashref) {
353 if($hometeaching_data{$index}{'Household'} =~ /(\S+)\s+(\S+),\s+(\S+)\s+(.*)/) {
354 print "I: Adjusting hometeaching match from: $hometeaching_data{$index}{'Household'} to $1, $3 $4\n";
355 $hometeaching_data{$index}{'Household'} = "$1, $3 $4";
357 if($key =~ /Quorum/i &&
358 $hometeaching_data{$index}{$key} =~ /Elders/i &&
359 $hometeaching_data{$index}{'Household'} =~ /$family_name/ &&
360 $data[0]->{companionship} != $hometeaching_data{$index}{'Comp ID'}
363 print " Updating hometeaching assignment for $family_name family\n";
364 $companionship = $hometeaching_data{$index}{'Comp ID'};
365 $sth = $dbh->prepare("update eq_family set companionship='$companionship' where name='$family_name'");
366 $sth->execute or die "-E- DB error: $DBI::errstr\n";
377 #+----------+------------------+------+-----+---------+-------+
378 #| Field | Type | Null | Key | Default | Extra |
379 #+----------+------------------+------+-----+---------+-------+
380 #| parent | int(16) unsigned | | PRI | 0 | A |
381 #| family | int(16) unsigned | YES | | NULL | |
382 #| name | varchar(30) | YES | | NULL | |
383 #| birthday | date | YES | | NULL | |
384 #| valid | tinyint(1) | YES | | NULL | |
385 #+----------+------------------+------+-----+---------+-------+
386 sub update_eq_parent_table
388 print "-> Updating eq_parent table\n";
390 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
391 $sth = $dbh->prepare("update eq_parent set valid=0");
392 $sth->execute or die "-E- DB error: $DBI::errstr\n";
394 foreach $index (keys %membership_data)
396 $hashref = $membership_data{$index};
397 foreach $key (keys %$hashref) {
398 if($key =~ /HH Position/i &&
399 $membership_data{$index}{$key} =~ /Head of Household/i ||
400 $membership_data{$index}{$key} =~ /Spouse/i
402 # Get some information from the hash about this parent
403 $parent_name = $membership_data{$index}{'Preferred Name'};
404 $parent_name =~ s/\'/\\'/g; #'
405 $birthday = $membership_data{$index}{'Birth'};
406 $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
407 $hofh_id = $membership_data{$index}{'HofH ID'};
408 $phone = $membership_data{$index}{'Phone 1'};
409 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
410 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
411 $address = $membership_data{$index}{'Street 1'};
412 if($membership_data{$index}{'Street 2'} ne "") {
413 $address .= " " . $membership_data{$index}{'Street 2'};
416 # Find the family id for this parent's HofH_ID.
417 $sth = $dbh->prepare("select * from eq_family where hofh_id='$hofh_id'");
418 $sth->execute or die "-E- DB error: $DBI::errstr\n";
419 $sqlhashref = $sth->fetchrow_hashref();
420 $family_id = $sqlhashref->{'family'};
422 # Find out how many parents match this parent's name
423 $sth = $dbh->prepare("select * from eq_parent where name='$parent_name'");
424 $sth->execute or die "-E- DB error: $DBI::errstr\n";
426 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
427 my $rows = scalar @data;
430 # No existing records found for this parent, make a new entry
431 print " Adding new Parent: $parent_name\n";
432 $sth = $dbh->prepare("insert into eq_parent values (NULL,$family_id,'$parent_name','$year-$month-$day','$phone','$address',1)");
433 $sth->execute or die "-E- DB error: $DBI::errstr\n";
434 } elsif($rows == 1) {
435 # An existing record was found for this parent, update it
436 print " Updating existing parent: $parent_name\n";
437 $sth = $dbh->prepare("update eq_parent set family='$family_id' where name='$parent_name'");
438 $sth->execute or die "-E- DB error: $DBI::errstr\n";
439 $sth = $dbh->prepare("update eq_parent set birthday='$year-$month-$day' where name='$parent_name'");
440 $sth->execute or die "-E- DB error: $DBI::errstr\n";
441 $sth = $dbh->prepare("update eq_parent set phone='$phone' where name='$parent_name'");
442 $sth->execute or die "-E- DB error: $DBI::errstr\n";
443 $sth = $dbh->prepare("update eq_parent set address='$address' where name='$parent_name'");
444 $sth->execute or die "-E- DB error: $DBI::errstr\n";
445 $sth = $dbh->prepare("update eq_parent set valid=1 where name='$parent_name'");
446 $sth->execute or die "-E- DB error: $DBI::errstr\n";
448 # More than one record was found. Error! This shouldn't happen.
449 print " -E- More than one record found with same parent name: $parent_name\n";
458 #+----------+------------------+------+-----+---------+-------+
459 #| Field | Type | Null | Key | Default | Extra |
460 #+----------+------------------+------+-----+---------+-------+
461 #| child | int(16) unsigned | | PRI | 0 | A |
462 #| family | int(16) unsigned | YES | | NULL | |
463 #| name | varchar(30) | YES | | NULL | |
464 #| birthday | date | YES | | NULL | |
465 #| valid | tinyint(1) | YES | | NULL | |
466 #+----------+------------------+------+-----+---------+-------+
467 sub update_eq_child_table
469 print "-> Updating eq_child table\n";
471 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
472 $sth = $dbh->prepare("update eq_child set valid=0");
473 $sth->execute or die "-E- DB error: $DBI::errstr\n";
475 foreach $index (keys %membership_data)
477 $hashref = $membership_data{$index};
478 foreach $key (keys %$hashref) {
479 if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Other/i ) {
480 $child_name = $membership_data{$index}{'Full Name'};
481 $child_name =~ s/\'/\\'/g; #'
482 $birthday = $membership_data{$index}{'Birth'};
483 $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
484 $id = $membership_data{$index}{'Indiv ID'};
485 $hofh_id = $membership_data{$index}{'HofH ID'};
487 # Find the family id for this child's HofH_ID.
488 $sth = $dbh->prepare("select * from eq_family where hofh_id='$hofh_id'");
489 $sth->execute or die "-E- DB error: $DBI::errstr\n";
490 $sqlhashref = $sth->fetchrow_hashref();
491 $family_id = $sqlhashref->{'family'};
493 # Find out how many children have the same name for the same family
494 $sth = $dbh->prepare("select * from eq_child where name='$child_name'");
495 $sth->execute or die "-E- DB error: $DBI::errstr\n";
497 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
498 my $rows = scalar @data;
501 # No existing records found for this child, make a new entry
502 print " Adding new Child: $child_name\n";
503 $sth = $dbh->prepare("insert into eq_child values (NULL,$family_id,'$child_name','$year-$month-$day',1)");
504 $sth->execute or die "-E- DB error: $DBI::errstr\n";
505 } elsif($rows == 1) {
506 # An existing record was found for this child, update it
507 print " Updating existing child: $child_name\n";
508 $sth = $dbh->prepare("update eq_child set family='$family_id' where name='$child_name'");
509 $sth->execute or die "-E- DB error: $DBI::errstr\n";
510 $sth = $dbh->prepare("update eq_child set birthday='$year-$month-$day' where name='$child_name'");
511 $sth->execute or die "-E- DB error: $DBI::errstr\n";
512 $sth = $dbh->prepare("update eq_child set valid=1 where name='$child_name'");
513 $sth->execute or die "-E- DB error: $DBI::errstr\n";
515 # More than one record was found. Error! This shouldn't happen.
516 print " -E- More than one record found ($rows) with same child name: $child_name\n";
524 ######################################################################
525 sub check_for_changed_ids
527 # If the Indiv ID & HofH ID has changed between data sets, we could have problems
528 my ($oldhashref, $newhashref) = @_;
529 my $found_problem = 0;
531 foreach $oldindex (keys %$oldhashref)
533 $indiv_id = $oldhashref->{$oldindex}{'Indiv ID'};
534 $hofh_id = $oldhashref->{$oldindex}{'HofH ID'};
535 $full_name = $oldhashref->{$oldindex}{'Full Name'};
536 $hh_position = $oldhashref->{$oldindex}{'HH Position'};
537 if($hh_position =~ /Other/i) { next; }
539 foreach $newindex (keys %$newhashref)
541 if($newhashref->{$newindex}{'Full Name'} eq $full_name &&
542 $indiv_id != $newhashref->{$newindex}{'Indiv ID'})
544 print "-W- Indiv ID for $full_name changed from $indiv_id to $newhashref->{$newindex}{'Indiv ID'}\n";
548 if($newhashref->{$newindex}{'Full Name'} eq $full_name &&
549 $hofh_id != $newhashref->{$newindex}{'HofH ID'})
551 print "-W- HofH ID for $full_name changed from $hofh_id to $newhashref->{$newindex}{'HofH ID'}\n";
557 return $found_problem;
560 ######################################################################
562 ######################################################################
564 ###################################################
565 # Open a connection to the database
566 $dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{
568 PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
570 ###################################################
571 # Check old directory against new directory to ensure
572 # that the Indiv ID & HofH ID have not changed between updates
574 print "-> Comparing old data files to new ones: $opt_o => $opt_n\n";
575 my %old_membership_data = ();
576 my %new_membership_data = ();
577 &csv_to_hash("$opt_o/Membership.csv",\%old_membership_data);
578 &csv_to_hash("$opt_n/Membership.csv",\%new_membership_data);
580 $changed_ids=&check_for_changed_ids(\%old_membership_data, \%new_membership_data);
584 print "-E- Some Indiv IDs and HofH IDs have changed for Head of Households between \n";
585 print " $opt_o and $opt_n data sets.\n";
586 print " This script is not currently setup to handle this properly.\n";
588 print " Exiting without updating...\n\n";
593 ###################################################
594 # Process command line options
595 if(defined $opt_n) { $datadir = $opt_n; }
596 else { $datadir = shift(@ARGV); }
597 print "-> Processing all ward data files in $datadir\n";
599 ###################################################
600 # Parse Ward Data Files
601 &csv_to_hash("$datadir/Membership.csv",\%membership_data);
602 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
605 print "-> Membership Data Dump\n\n";
606 &print_hash(\%membership_data);
607 print "-> HomeTeaching Data Dump\n\n";
608 &print_hash(\%hometeaching_data);
611 if($opt_s) { $dbh->disconnect(); exit; }
613 # Now update the various eq DB tables
614 &update_eq_elder_table();
615 &update_eq_aaronic_table();
616 &update_eq_district_table();
617 &update_eq_companionship_table();
618 &update_eq_family_table();
619 &update_eq_parent_table();
620 &update_eq_child_table();
622 ###################################################
623 # Disconnect from the database
626 ######################################################################