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 #| valid | tinyint(1) | YES | | NULL | |
81 #+-------+--------------------+------+-----+---------+-------+
82 sub update_eq_aaronic_table
84 print "-> Updating eq_aaronic table\n";
85 foreach $index (keys %membership_data)
87 $hashref = $membership_data{$index};
88 foreach $key (keys %$hashref) {
89 if($key =~ /Priesthood/i &&
90 ($membership_data{$index}{$key} =~ /^Teacher\s*$/i ||
91 $membership_data{$index}{$key} =~ /^Priest\s*$/i)) {
92 $aaronic_name = $membership_data{$index}{'Preferred Name'};
93 $sth = $dbh->prepare("select * from eq_aaronic where name='$aaronic_name'");
94 $sth->execute or die "-E- DB error: $DBI::errstr\n";
96 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
97 my $rows = scalar @data;
99 # No existing records found for this aaronic, make a new entry
100 print " Adding new Aaronic: $aaronic_name\n";
101 $sth = $dbh->prepare("insert into eq_aaronic values (NULL,'$aaronic_name',1)");
102 $sth->execute or die "-E- DB error: $DBI::errstr\n";
103 } elsif($rows == 1) {
104 # An existing record was found for this aaronic, update it if it is valid
105 if($data[0]->{valid} == 1) {
106 print " Updating existing aaronic: $aaronic_name\n";
109 # More than one record was found. Error! This shouldn't happen.
110 print " -E- More than one record found ($rows) for aaronic name: $aaronic_name\n";
119 #+------------+------------------+------+-----+---------+-------+
120 #| Field | Type | Null | Key | Default | Extra |
121 #+------------+------------------+------+-----+---------+-------+
122 #| elder | int(16) unsigned | | PRI | 0 | A |
123 #| name | varchar(60) | YES | | NULL | |
124 #| phone | varchar(12) | YES | | NULL | |
125 #| valid | tinyint(1) | YES | | NULL | |
126 #+------------+------------------+------+-----+---------+-------+
127 sub update_eq_elder_table
129 print "-> Updating eq_elder table\n";
131 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
132 $sth = $dbh->prepare("update eq_elder set valid=0");
133 $sth->execute or die "-E- DB error: $DBI::errstr\n";
135 foreach $index (keys %membership_data)
137 $hashref = $membership_data{$index};
138 foreach $key (keys %$hashref) {
139 if($key =~ /Priesthood/i && $membership_data{$index}{$key} =~ /Elder/i) {
140 $elder_name = $membership_data{$index}{'Preferred Name'};
141 $phone = $membership_data{$index}{'Phone 1'};
142 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
143 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
144 $sth = $dbh->prepare("select * from eq_elder where name='$elder_name'");
145 $sth->execute or die "-E- DB error: $DBI::errstr\n";
147 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
148 my $rows = scalar @data;
150 # No existing records found for this elder, make a new entry
151 print " Adding new Elder: $elder_name\n";
152 $sth = $dbh->prepare("insert into eq_elder values (NULL,'$elder_name','$phone',1)");
153 $sth->execute or die "-E- DB error: $DBI::errstr\n";
154 } elsif($rows == 1) {
155 # An existing record was found for this elder, update it
156 print " Updating existing Elder: $elder_name\n";
157 $sth = $dbh->prepare("update eq_elder set valid=1 where name='$elder_name'");
158 $sth->execute or die "-E- DB error: $DBI::errstr\n";
160 $sth = $dbh->prepare("update eq_elder set phone='$phone' where name='$elder_name'");
162 $sth = $dbh->prepare("update eq_elder set phone=NULL where name='$elder_name'");
164 $sth->execute or die "-E- DB error: $DBI::errstr\n";
166 # More than one record was found. Error! This shouldn't happen.
167 print " -E- More than one record found ($rows) for Elder: $elder_name\n";
176 #+------------+------------------+------+-----+---------+-------+
177 #| Field | Type | Null | Key | Default | Extra |
178 #+------------+------------------+------+-----+---------+-------+
179 #| district | int(16) unsigned | | PRI | 0 | |
180 #| name | varchar(30) | YES | | NULL | |
181 #| supervisor | int(16) unsigned | YES | | NULL | |
182 #| valid | tinyint(1) | YES | | NULL | |
183 #+------------+------------------+------+-----+---------+-------+
184 sub update_eq_district_table
186 # Districts should be created by hand. This subroutine only
187 # updates the supervisor's ID in each district.
188 print "-> Updating eq_district table\n";
189 $sth = $dbh->prepare("select * from eq_district");
190 $sth->execute or die "-E- DB error: $DBI::errstr\n";
191 while($sqlhashref = $sth->fetchrow_hashref) {
192 $supervisor_name = $sqlhashref->{name};
193 $district = $sqlhashref->{district};
194 $sth2 = $dbh->prepare("select * from eq_elder where name='$supervisor_name'");
195 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
196 $sqlhashref2 = $sth2->fetchrow_hashref;
197 $supervisor_id = $sqlhashref2->{elder};
199 $sth2 = $dbh->prepare("update eq_district set supervisor='$supervisor_id' where district='$district'");
200 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
207 #+---------------+------------------+------+-----+---------+-------+
208 #| Field | Type | Null | Key | Default | Extra |
209 #+---------------+------------------+------+-----+---------+-------+
210 #| companionship | int(16) unsigned | | | 0 | |
211 #| elder | int(16) unsigned | YES | | NULL | |
212 #| aaronic | int(16) unsigned | YES | | NULL | |
213 #| district | int(16) unsigned | YES | | NULL | |
214 #| valid | tinyint(1) | YES | | NULL | |
215 #+---------------+------------------+------+-----+---------+-------+
216 sub update_eq_companionship_table
218 print "-> Updating eq_companionship table\n";
220 # First, mark all existing companionships as invalid in case they have been dissolved
221 $sth = $dbh->prepare("update eq_companionship set valid=0");
222 $sth->execute or die "-E- DB error: $DBI::errstr\n";
223 # Second, mark all the aaronic invalid. We'll only mark the ones as valid that are assigned to hometeach
224 $sth = $dbh->prepare("update eq_aaronic set valid=0");
225 $sth->execute or die "-E- DB error: $DBI::errstr\n";
227 foreach $index (keys %hometeaching_data)
229 $hashref = $hometeaching_data{$index};
230 foreach $key (keys %$hashref) {
231 if($key =~ /Quorum/i && $hometeaching_data{$index}{$key} =~ /Elders/i) {
232 foreach $field ("Home Teacher 1","Home Teacher 2") {
233 $elder_name = $hometeaching_data{$index}{$field};
234 if($elder_name eq "") { next; }
235 $sth2 = $dbh->prepare("select * from eq_elder where name='$elder_name'");
236 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
237 $sqlhashref2 = $sth2->fetchrow_hashref;
238 $elder = $sqlhashref2->{elder};
241 $sth2 = $dbh->prepare("select * from eq_aaronic where name='$elder_name'");
242 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
243 $sqlhashref2 = $sth2->fetchrow_hashref;
244 $aaronic = $sqlhashref2->{aaronic};
246 if($aaronic eq "") { print "-W- Unable to find $elder_name in eq_elder or eq_aaronic tables\n"; }
248 $id = $hometeaching_data{$index}{'Comp ID'};
249 $district = $hometeaching_data{$index}{'HT District'};
250 $sth = $dbh->prepare("select * from eq_companionship where elder='$elder' and aaronic='$aaronic' and companionship='$id'");
251 $sth->execute or die "-E- DB error: $DBI::errstr\n";
253 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
254 my $rows = scalar @data;
256 # No existing records found for this companionship, make a new entry
257 print " Adding Elder to companionship: $elder_name -> $id\n";
258 $sth = $dbh->prepare("insert into eq_companionship values ($id,'$elder','$aaronic','$district',1)");
259 $sth->execute or die "-E- DB error: $DBI::errstr\n";
261 # An existing companionship was found for this companionship, update it
262 $sth2 = $dbh->prepare("select * from eq_companionship where district='$district' and companionship='$id'");
263 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
264 if($elder ne "NULL") {
265 print " Updating Companionship with Elder: $elder_name ($elder) -> $id\n";
266 $sth = $dbh->prepare("update eq_companionship set district='$district' where elder='$elder' and companionship='$id'");
267 $sth->execute or die "-E- DB error 'district': $DBI::errstr\n";
268 $sth = $dbh->prepare("update eq_companionship set elder='$elder' where elder='$elder' and companionship='$id'");
269 $sth->execute or die "-E- DB error 'elder': $DBI::errstr\n";
270 $sth = $dbh->prepare("update eq_companionship set valid=1 where elder='$elder' and companionship='$id'");
271 $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n";
273 print " Updating Companionship with Aaronic: $elder_name ($aaronic) -> $id\n";
274 $sth = $dbh->prepare("update eq_companionship set district='$district' where aaronic='$aaronic' and companionship='$id'");
275 $sth->execute or die "-E- DB error: $DBI::errstr\n";
276 $sth = $dbh->prepare("update eq_companionship set aaronic='$aaronic' where aaronic='$aaronic' and companionship='$id'");
277 $sth->execute or die "-E- DB error: $DBI::errstr\n";
278 $sth = $dbh->prepare("update eq_companionship set valid=1 where aaronic='$aaronic' and companionship='$id'");
279 $sth->execute or die "-E- DB error: $DBI::errstr\n";
280 $sth = $dbh->prepare("update eq_aaronic set valid=1 where aaronic='$aaronic'");
281 $sth->execute or die "-E- DB error: $DBI::errstr\n";
293 #+---------------+------------------+------+-----+---------+-------+
294 #| Field | Type | Null | Key | Default | Extra |
295 #+---------------+------------------+------+-----+---------+-------+
296 #| family | int(16) unsigned | | PRI | 0 | A |
297 #| hofh_id | int(16) unsigned | YES | | NULL | |
298 #| name | varchar(30) | YES | | NULL | |
299 #| companionship | int(16) unsigned | YES | | NULL | |
300 #| valid | tinyint(1) | YES | | NULL | |
301 #+---------------+------------------+------+-----+---------+-------+
302 sub update_eq_family_table
304 print "-> Updating eq_family table\n";
306 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
307 $sth = $dbh->prepare("update eq_family set valid=0");
308 $sth->execute or die "-E- DB error: $DBI::errstr\n";
310 foreach $index (keys %membership_data)
312 $hashref = $membership_data{$index};
313 foreach $key (keys %$hashref) {
314 if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Head of Household/i) {
315 $family_name = $membership_data{$index}{'Preferred Name'};
316 $family_name =~ s/\'/\\'/g; #'
317 $id = $membership_data{$index}{'HofH ID'};
319 # Find out how many families match this family's name
320 $sth = $dbh->prepare("select * from eq_family where name='$family_name'");
321 $sth->execute or die "-E- DB error: $DBI::errstr\n";
323 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
324 my $rows = scalar @data;
327 # No existing records found for this family, make a new entry
328 print " Adding new Family: $family_name\n";
329 $sth = $dbh->prepare("insert into eq_family values (NULL,$id,'$family_name','0',1)");
330 $sth->execute or die "-E- DB error: $DBI::errstr\n";
331 } elsif($rows == 1) {
332 # An existing record was found for this family, update it
333 print " Updating existing family: $family_name\n";
334 $sth = $dbh->prepare("update eq_family set hofh_id=$id where name='$family_name'");
335 $sth->execute or die "-E- DB error: $DBI::errstr\n";
336 $sth = $dbh->prepare("update eq_family set valid=1 where name='$family_name'");
337 $sth->execute or die "-E- DB error: $DBI::errstr\n";
339 # More than one record was found. Error! This shouldn't happen.
340 print " -E- More than one record found ($rows) for family name: $family_name\n";
342 # Now update the hometeaching field for this family
343 foreach $index (keys %hometeaching_data)
345 $hashref = $hometeaching_data{$index};
346 foreach $key (keys %$hashref) {
347 if($hometeaching_data{$index}{'Household'} =~ /(\S+)\s+(\S+),\s+(\S+)\s+(.*)/) {
348 print "I: Adjusting hometeaching match from: $hometeaching_data{$index}{'Household'} to $1, $3 $4\n";
349 $hometeaching_data{$index}{'Household'} = "$1, $3 $4";
351 if($key =~ /Quorum/i &&
352 $hometeaching_data{$index}{$key} =~ /Elders/i &&
353 $hometeaching_data{$index}{'Household'} =~ /$family_name/ &&
354 $data[0]->{companionship} != $hometeaching_data{$index}{'Comp ID'}
357 print " Updating hometeaching assignment for $family_name family\n";
358 $companionship = $hometeaching_data{$index}{'Comp ID'};
359 $sth = $dbh->prepare("update eq_family set companionship='$companionship' where name='$family_name'");
360 $sth->execute or die "-E- DB error: $DBI::errstr\n";
371 #+----------+------------------+------+-----+---------+-------+
372 #| Field | Type | Null | Key | Default | Extra |
373 #+----------+------------------+------+-----+---------+-------+
374 #| parent | int(16) unsigned | | PRI | 0 | A |
375 #| family | int(16) unsigned | YES | | NULL | |
376 #| name | varchar(30) | YES | | NULL | |
377 #| birthday | date | YES | | NULL | |
378 #| valid | tinyint(1) | YES | | NULL | |
379 #+----------+------------------+------+-----+---------+-------+
380 sub update_eq_parent_table
382 print "-> Updating eq_parent table\n";
384 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
385 $sth = $dbh->prepare("update eq_parent set valid=0");
386 $sth->execute or die "-E- DB error: $DBI::errstr\n";
388 foreach $index (keys %membership_data)
390 $hashref = $membership_data{$index};
391 foreach $key (keys %$hashref) {
392 if($key =~ /HH Position/i &&
393 $membership_data{$index}{$key} =~ /Head of Household/i ||
394 $membership_data{$index}{$key} =~ /Spouse/i
396 # Get some information from the hash about this parent
397 $parent_name = $membership_data{$index}{'Preferred Name'};
398 $parent_name =~ s/\'/\\'/g; #'
399 $birthday = $membership_data{$index}{'Birth'};
400 $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
401 $hofh_id = $membership_data{$index}{'HofH ID'};
402 $phone = $membership_data{$index}{'Phone 1'};
403 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
404 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
405 $address = $membership_data{$index}{'Street 1'};
406 if($membership_data{$index}{'Street 2'} ne "") {
407 $address .= " " . $membership_data{$index}{'Street 2'};
410 # Find the family id for this parent's HofH_ID.
411 $sth = $dbh->prepare("select * from eq_family where hofh_id='$hofh_id'");
412 $sth->execute or die "-E- DB error: $DBI::errstr\n";
413 $sqlhashref = $sth->fetchrow_hashref();
414 $family_id = $sqlhashref->{'family'};
416 # Find out how many parents match this parent's name
417 $sth = $dbh->prepare("select * from eq_parent where name='$parent_name'");
418 $sth->execute or die "-E- DB error: $DBI::errstr\n";
420 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
421 my $rows = scalar @data;
424 # No existing records found for this parent, make a new entry
425 print " Adding new Parent: $parent_name\n";
426 $sth = $dbh->prepare("insert into eq_parent values (NULL,$family_id,'$parent_name','$year-$month-$day','$phone','$address',1)");
427 $sth->execute or die "-E- DB error: $DBI::errstr\n";
428 } elsif($rows == 1) {
429 # An existing record was found for this parent, update it
430 print " Updating existing parent: $parent_name\n";
431 $sth = $dbh->prepare("update eq_parent set family='$family_id' where name='$parent_name'");
432 $sth->execute or die "-E- DB error: $DBI::errstr\n";
433 $sth = $dbh->prepare("update eq_parent set birthday='$year-$month-$day' where name='$parent_name'");
434 $sth->execute or die "-E- DB error: $DBI::errstr\n";
435 $sth = $dbh->prepare("update eq_parent set phone='$phone' where name='$parent_name'");
436 $sth->execute or die "-E- DB error: $DBI::errstr\n";
437 $sth = $dbh->prepare("update eq_parent set address='$address' where name='$parent_name'");
438 $sth->execute or die "-E- DB error: $DBI::errstr\n";
439 $sth = $dbh->prepare("update eq_parent set valid=1 where name='$parent_name'");
440 $sth->execute or die "-E- DB error: $DBI::errstr\n";
442 # More than one record was found. Error! This shouldn't happen.
443 print " -E- More than one record found with same parent name: $parent_name\n";
452 #+----------+------------------+------+-----+---------+-------+
453 #| Field | Type | Null | Key | Default | Extra |
454 #+----------+------------------+------+-----+---------+-------+
455 #| child | int(16) unsigned | | PRI | 0 | A |
456 #| family | int(16) unsigned | YES | | NULL | |
457 #| name | varchar(30) | YES | | NULL | |
458 #| birthday | date | YES | | NULL | |
459 #| valid | tinyint(1) | YES | | NULL | |
460 #+----------+------------------+------+-----+---------+-------+
461 sub update_eq_child_table
463 print "-> Updating eq_child table\n";
465 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
466 $sth = $dbh->prepare("update eq_child set valid=0");
467 $sth->execute or die "-E- DB error: $DBI::errstr\n";
469 foreach $index (keys %membership_data)
471 $hashref = $membership_data{$index};
472 foreach $key (keys %$hashref) {
473 if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Other/i ) {
474 $child_name = $membership_data{$index}{'Full Name'};
475 $child_name =~ s/\'/\\'/g; #'
476 $birthday = $membership_data{$index}{'Birth'};
477 $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
478 $id = $membership_data{$index}{'Indiv ID'};
479 $hofh_id = $membership_data{$index}{'HofH ID'};
481 # Find the family id for this child's HofH_ID.
482 $sth = $dbh->prepare("select * from eq_family where hofh_id='$hofh_id'");
483 $sth->execute or die "-E- DB error: $DBI::errstr\n";
484 $sqlhashref = $sth->fetchrow_hashref();
485 $family_id = $sqlhashref->{'family'};
487 # Find out how many children have the same name for the same family
488 $sth = $dbh->prepare("select * from eq_child where name='$child_name'");
489 $sth->execute or die "-E- DB error: $DBI::errstr\n";
491 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
492 my $rows = scalar @data;
495 # No existing records found for this child, make a new entry
496 print " Adding new Child: $child_name\n";
497 $sth = $dbh->prepare("insert into eq_child values (NULL,$family_id,'$child_name','$year-$month-$day',1)");
498 $sth->execute or die "-E- DB error: $DBI::errstr\n";
499 } elsif($rows == 1) {
500 # An existing record was found for this child, update it
501 print " Updating existing child: $child_name\n";
502 $sth = $dbh->prepare("update eq_child set family='$family_id' where name='$child_name'");
503 $sth->execute or die "-E- DB error: $DBI::errstr\n";
504 $sth = $dbh->prepare("update eq_child set birthday='$year-$month-$day' where name='$child_name'");
505 $sth->execute or die "-E- DB error: $DBI::errstr\n";
506 $sth = $dbh->prepare("update eq_child set valid=1 where name='$child_name'");
507 $sth->execute or die "-E- DB error: $DBI::errstr\n";
509 # More than one record was found. Error! This shouldn't happen.
510 print " -E- More than one record found ($rows) with same child name: $child_name\n";
518 ######################################################################
519 sub check_for_changed_ids
521 # If the Indiv ID & HofH ID has changed between data sets, we could have problems
522 my ($oldhashref, $newhashref) = @_;
523 my $found_problem = 0;
525 foreach $oldindex (keys %$oldhashref)
527 $indiv_id = $oldhashref->{$oldindex}{'Indiv ID'};
528 $hofh_id = $oldhashref->{$oldindex}{'HofH ID'};
529 $full_name = $oldhashref->{$oldindex}{'Full Name'};
530 $hh_position = $oldhashref->{$oldindex}{'HH Position'};
531 if($hh_position =~ /Other/i) { next; }
533 foreach $newindex (keys %$newhashref)
535 if($newhashref->{$newindex}{'Full Name'} eq $full_name &&
536 $indiv_id != $newhashref->{$newindex}{'Indiv ID'})
538 print "-W- Indiv ID for $full_name changed from $indiv_id to $newhashref->{$newindex}{'Indiv ID'}\n";
542 if($newhashref->{$newindex}{'Full Name'} eq $full_name &&
543 $hofh_id != $newhashref->{$newindex}{'HofH ID'})
545 print "-W- HofH ID for $full_name changed from $hofh_id to $newhashref->{$newindex}{'HofH ID'}\n";
551 return $found_problem;
554 ######################################################################
556 ######################################################################
558 ###################################################
559 # Open a connection to the database
560 $dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{
562 PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
564 ###################################################
565 # Check old directory against new directory to ensure
566 # that the Indiv ID & HofH ID have not changed between updates
568 print "-> Comparing old data files to new ones: $opt_o => $opt_n\n";
569 my %old_membership_data = ();
570 my %new_membership_data = ();
571 &csv_to_hash("$opt_o/Membership.csv",\%old_membership_data);
572 &csv_to_hash("$opt_n/Membership.csv",\%new_membership_data);
574 $changed_ids=&check_for_changed_ids(\%old_membership_data, \%new_membership_data);
578 print "-E- Some Indiv IDs and HofH IDs have changed for Head of Households between \n";
579 print " $opt_o and $opt_n data sets.\n";
580 print " This script is not currently setup to handle this properly.\n";
582 print " Exiting without updating...\n\n";
587 ###################################################
588 # Process command line options
589 if(defined $opt_n) { $datadir = $opt_n; }
590 else { $datadir = shift(@ARGV); }
591 print "-> Processing all ward data files in $datadir\n";
593 ###################################################
594 # Parse Ward Data Files
595 &csv_to_hash("$datadir/Membership.csv",\%membership_data);
596 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
599 print "-> Membership Data Dump\n\n";
600 &print_hash(\%membership_data);
601 print "-> HomeTeaching Data Dump\n\n";
602 &print_hash(\%hometeaching_data);
605 if($opt_s) { $dbh->disconnect(); exit; }
607 # Now update the various eq DB tables
608 &update_eq_elder_table();
609 &update_eq_aaronic_table();
610 &update_eq_district_table();
611 &update_eq_companionship_table();
612 &update_eq_family_table();
613 &update_eq_parent_table();
614 &update_eq_child_table();
616 ###################################################
617 # Disconnect from the database
620 ######################################################################