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";
87 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
88 $sth = $dbh->prepare("update eq_aaronic set valid=0");
89 $sth->execute or die "-E- DB error: $DBI::errstr\n";
91 foreach $index (keys %membership_data)
93 $hashref = $membership_data{$index};
94 foreach $key (keys %$hashref) {
95 if($key =~ /Priesthood/i &&
96 ($membership_data{$index}{$key} =~ /^Teacher\s*$/i ||
97 $membership_data{$index}{$key} =~ /^Priest\s*$/i)) {
98 $aaronic_name = $membership_data{$index}{'Preferred Name'};
99 $phone = $membership_data{$index}{'Phone 1'};
100 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
101 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
102 $sth = $dbh->prepare("select * from eq_aaronic where name='$aaronic_name'");
103 $sth->execute or die "-E- DB error: $DBI::errstr\n";
105 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
106 my $rows = scalar @data;
108 # No existing records found for this aaronic, make a new entry
109 print " Adding new Aaronic: $aaronic_name\n";
110 $sth = $dbh->prepare("insert into eq_aaronic values (NULL,'$aaronic_name','$phone',1)");
111 $sth->execute or die "-E- DB error: $DBI::errstr\n";
112 } elsif($rows == 1) {
113 # An existing record was found for this aaronic, update it, mark it valid!
114 print " Updating existing aaronic: $aaronic_name\n";
115 $sth = $dbh->prepare("update eq_aaronic set phone='$phone' where name='$aaronic_name'");
116 $sth->execute or die "-E- DB error: $DBI::errstr\n";
117 $sth = $dbh->prepare("update eq_aaronic set valid=1 where name='$aaronic_name'");
118 $sth->execute or die "-E- DB error: $DBI::errstr\n";
120 # More than one record was found. Error! This shouldn't happen.
121 print " -E- More than one record found ($rows) for aaronic name: $aaronic_name\n";
130 #+------------+------------------+------+-----+---------+-------+
131 #| Field | Type | Null | Key | Default | Extra |
132 #+------------+------------------+------+-----+---------+-------+
133 #| elder | int(16) unsigned | | PRI | 0 | A |
134 #| name | varchar(60) | YES | | NULL | |
135 #| phone | varchar(12) | YES | | NULL | |
136 #| valid | tinyint(1) | YES | | NULL | |
137 #+------------+------------------+------+-----+---------+-------+
138 sub update_eq_elder_table
140 print "-> Updating eq_elder table\n";
142 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
143 $sth = $dbh->prepare("update eq_elder set valid=0");
144 $sth->execute or die "-E- DB error: $DBI::errstr\n";
146 foreach $index (keys %membership_data)
148 $hashref = $membership_data{$index};
149 foreach $key (keys %$hashref) {
150 if($key =~ /Priesthood/i && $membership_data{$index}{$key} =~ /Elder/i) {
151 $elder_name = $membership_data{$index}{'Preferred Name'};
152 $phone = $membership_data{$index}{'Phone 1'};
153 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
154 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
155 $sth = $dbh->prepare("select * from eq_elder where name='$elder_name'");
156 $sth->execute or die "-E- DB error: $DBI::errstr\n";
158 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
159 my $rows = scalar @data;
161 # No existing records found for this elder, make a new entry
162 print " Adding new Elder: $elder_name\n";
163 $sth = $dbh->prepare("insert into eq_elder values (NULL,'$elder_name','$phone',1)");
164 $sth->execute or die "-E- DB error: $DBI::errstr\n";
165 } elsif($rows == 1) {
166 # An existing record was found for this elder, update it
167 print " Updating existing Elder: $elder_name\n";
168 $sth = $dbh->prepare("update eq_elder set valid=1 where name='$elder_name'");
169 $sth->execute or die "-E- DB error: $DBI::errstr\n";
171 $sth = $dbh->prepare("update eq_elder set phone='$phone' where name='$elder_name'");
173 $sth = $dbh->prepare("update eq_elder set phone=NULL where name='$elder_name'");
175 $sth->execute or die "-E- DB error: $DBI::errstr\n";
177 # More than one record was found. Error! This shouldn't happen.
178 print " -E- More than one record found ($rows) for Elder: $elder_name\n";
187 #+------------+------------------+------+-----+---------+-------+
188 #| Field | Type | Null | Key | Default | Extra |
189 #+------------+------------------+------+-----+---------+-------+
190 #| district | int(16) unsigned | | PRI | 0 | |
191 #| name | varchar(30) | YES | | NULL | |
192 #| supervisor | int(16) unsigned | YES | | NULL | |
193 #| valid | tinyint(1) | YES | | NULL | |
194 #+------------+------------------+------+-----+---------+-------+
195 sub update_eq_district_table
197 # Districts should be created by hand. This subroutine only
198 # updates the supervisor's ID in each district.
199 print "-> Updating eq_district table\n";
200 $sth = $dbh->prepare("select * from eq_district");
201 $sth->execute or die "-E- DB error: $DBI::errstr\n";
202 while($sqlhashref = $sth->fetchrow_hashref) {
203 $supervisor_name = $sqlhashref->{name};
204 $district = $sqlhashref->{district};
205 $sth2 = $dbh->prepare("select * from eq_elder where name='$supervisor_name'");
206 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
207 $sqlhashref2 = $sth2->fetchrow_hashref;
208 $supervisor_id = $sqlhashref2->{elder};
210 $sth2 = $dbh->prepare("update eq_district set supervisor='$supervisor_id' where district='$district'");
211 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
218 #+---------------+------------------+------+-----+---------+-------+
219 #| Field | Type | Null | Key | Default | Extra |
220 #+---------------+------------------+------+-----+---------+-------+
221 #| companionship | int(16) unsigned | | | 0 | |
222 #| elder | int(16) unsigned | YES | | NULL | |
223 #| aaronic | int(16) unsigned | YES | | NULL | |
224 #| district | int(16) unsigned | YES | | NULL | |
225 #| valid | tinyint(1) | YES | | NULL | |
226 #+---------------+------------------+------+-----+---------+-------+
227 sub update_eq_companionship_table
229 print "-> Updating eq_companionship table\n";
231 # First, mark all existing companionships as invalid in case they have been dissolved
232 $sth = $dbh->prepare("update eq_companionship set valid=0");
233 $sth->execute or die "-E- DB error: $DBI::errstr\n";
234 # Second, mark all the aaronic invalid. We'll only mark the ones as valid that are assigned to hometeach
235 $sth = $dbh->prepare("update eq_aaronic set valid=0");
236 $sth->execute or die "-E- DB error: $DBI::errstr\n";
238 foreach $index (keys %hometeaching_data)
240 $hashref = $hometeaching_data{$index};
241 foreach $key (keys %$hashref) {
242 if($key =~ /Quorum/i && $hometeaching_data{$index}{$key} =~ /Elders/i) {
243 foreach $field ("Home Teacher 1","Home Teacher 2") {
244 $elder_name = $hometeaching_data{$index}{$field};
245 if($elder_name eq "") { next; }
246 $sth2 = $dbh->prepare("select * from eq_elder where name='$elder_name'");
247 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
248 $sqlhashref2 = $sth2->fetchrow_hashref;
249 $elder = $sqlhashref2->{elder};
252 $sth2 = $dbh->prepare("select * from eq_aaronic where name='$elder_name'");
253 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
254 $sqlhashref2 = $sth2->fetchrow_hashref;
255 $aaronic = $sqlhashref2->{aaronic};
257 if($aaronic eq "") { print "-W- Unable to find $elder_name in eq_elder or eq_aaronic tables\n"; }
259 $id = $hometeaching_data{$index}{'Comp ID'};
260 $district = $hometeaching_data{$index}{'HT District'};
261 $sth = $dbh->prepare("select * from eq_companionship where elder='$elder' and aaronic='$aaronic' and companionship='$id'");
262 $sth->execute or die "-E- DB error: $DBI::errstr\n";
264 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
265 my $rows = scalar @data;
267 # No existing records found for this companionship, make a new entry
268 print " Adding Companion to companionship: $elder_name -> $id\n";
269 $sth = $dbh->prepare("insert into eq_companionship values ($id,'$elder','$aaronic','$district',1)");
270 $sth->execute or die "-E- DB error: $DBI::errstr\n";
272 # An existing companionship was found for this companionship, update it
273 $sth2 = $dbh->prepare("select * from eq_companionship where district='$district' and companionship='$id'");
274 $sth2->execute or die "-E- DB error: $DBI::errstr\n";
275 if($elder ne "NULL") {
276 print " Updating Companionship with Elder: $elder_name ($elder) -> $id\n";
277 $sth = $dbh->prepare("update eq_companionship set district='$district' where elder='$elder' and companionship='$id'");
278 $sth->execute or die "-E- DB error 'district': $DBI::errstr\n";
279 $sth = $dbh->prepare("update eq_companionship set elder='$elder' where elder='$elder' and companionship='$id'");
280 $sth->execute or die "-E- DB error 'elder': $DBI::errstr\n";
281 $sth = $dbh->prepare("update eq_companionship set valid=1 where elder='$elder' and companionship='$id'");
282 $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n";
284 print " Updating Companionship with Aaronic: $elder_name ($aaronic) -> $id\n";
285 $sth = $dbh->prepare("update eq_companionship set district='$district' where aaronic='$aaronic' and companionship='$id'");
286 $sth->execute or die "-E- DB error: $DBI::errstr\n";
287 $sth = $dbh->prepare("update eq_companionship set aaronic='$aaronic' where aaronic='$aaronic' and companionship='$id'");
288 $sth->execute or die "-E- DB error: $DBI::errstr\n";
289 $sth = $dbh->prepare("update eq_companionship set valid=1 where aaronic='$aaronic' and companionship='$id'");
290 $sth->execute or die "-E- DB error: $DBI::errstr\n";
291 $sth = $dbh->prepare("update eq_aaronic set valid=1 where aaronic='$aaronic'");
292 $sth->execute or die "-E- DB error: $DBI::errstr\n";
304 #+---------------+------------------+------+-----+---------+-------+
305 #| Field | Type | Null | Key | Default | Extra |
306 #+---------------+------------------+------+-----+---------+-------+
307 #| family | int(16) unsigned | | PRI | 0 | A |
308 #| hofh_id | int(16) unsigned | YES | | NULL | |
309 #| name | varchar(30) | YES | | NULL | |
310 #| companionship | int(16) unsigned | YES | | NULL | |
311 #| valid | tinyint(1) | YES | | NULL | |
312 #+---------------+------------------+------+-----+---------+-------+
313 sub update_eq_family_table
315 print "-> Updating eq_family table\n";
317 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
318 $sth = $dbh->prepare("update eq_family set valid=0");
319 $sth->execute or die "-E- DB error: $DBI::errstr\n";
320 $sth = $dbh->prepare("update eq_family set companionship=0");
321 $sth->execute or die "-E- DB error: $DBI::errstr\n";
323 foreach $index (keys %membership_data)
325 $hashref = $membership_data{$index};
326 foreach $key (keys %$hashref) {
327 if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Head of Household/i) {
328 $family_name = $membership_data{$index}{'Preferred Name'};
329 $family_name =~ s/\'/\\'/g; #'
330 $id = $membership_data{$index}{'HofH ID'};
332 # Find out how many families match this family's name
333 $sth = $dbh->prepare("select * from eq_family where name='$family_name'");
334 $sth->execute or die "-E- DB error: $DBI::errstr\n";
336 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
337 my $rows = scalar @data;
340 # No existing records found for this family, make a new entry
341 print " Adding new Family: $family_name\n";
342 $sth = $dbh->prepare("insert into eq_family values (NULL,$id,'$family_name','0',1)");
343 $sth->execute or die "-E- DB error: $DBI::errstr\n";
344 } elsif($rows == 1) {
345 # An existing record was found for this family, update it
346 print " Updating existing family: $family_name\n";
347 $sth = $dbh->prepare("update eq_family set hofh_id=$id where name='$family_name'");
348 $sth->execute or die "-E- DB error: $DBI::errstr\n";
349 $sth = $dbh->prepare("update eq_family set valid=1 where name='$family_name'");
350 $sth->execute or die "-E- DB error: $DBI::errstr\n";
352 # More than one record was found. Error! This shouldn't happen.
353 print " -E- More than one record found ($rows) for family name: $family_name\n";
355 # Now update the hometeaching field for this family
356 foreach $index (keys %hometeaching_data)
358 $hashref = $hometeaching_data{$index};
359 foreach $key (keys %$hashref) {
360 if($hometeaching_data{$index}{'Household'} =~ /(\S+)\s+(\S+),\s+(\S+)\s+(.*)/) {
361 print "I: Adjusting hometeaching match from: $hometeaching_data{$index}{'Household'} to $1, $3 $4\n";
362 $hometeaching_data{$index}{'Household'} = "$1, $3 $4";
364 if($key =~ /Quorum/i &&
365 $hometeaching_data{$index}{$key} =~ /Elders/i &&
366 $hometeaching_data{$index}{'Household'} =~ /$family_name/ &&
367 $data[0]->{companionship} != $hometeaching_data{$index}{'Comp ID'}
370 print " Updating hometeaching assignment for $family_name family\n";
371 $companionship = $hometeaching_data{$index}{'Comp ID'};
372 $sth = $dbh->prepare("update eq_family set companionship='$companionship' where name='$family_name'");
373 $sth->execute or die "-E- DB error: $DBI::errstr\n";
384 #+----------+------------------+------+-----+---------+-------+
385 #| Field | Type | Null | Key | Default | Extra |
386 #+----------+------------------+------+-----+---------+-------+
387 #| parent | int(16) unsigned | | PRI | 0 | A |
388 #| family | int(16) unsigned | YES | | NULL | |
389 #| name | varchar(30) | YES | | NULL | |
390 #| birthday | date | YES | | NULL | |
391 #| valid | tinyint(1) | YES | | NULL | |
392 #+----------+------------------+------+-----+---------+-------+
393 sub update_eq_parent_table
395 print "-> Updating eq_parent table\n";
397 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
398 $sth = $dbh->prepare("update eq_parent set valid=0");
399 $sth->execute or die "-E- DB error: $DBI::errstr\n";
401 foreach $index (keys %membership_data)
403 $hashref = $membership_data{$index};
404 foreach $key (keys %$hashref) {
405 if($key =~ /HH Position/i &&
406 $membership_data{$index}{$key} =~ /Head of Household/i ||
407 $membership_data{$index}{$key} =~ /Spouse/i
409 # Get some information from the hash about this parent
410 $parent_name = $membership_data{$index}{'Preferred Name'};
411 $parent_name =~ s/\'/\\'/g; #'
412 $birthday = $membership_data{$index}{'Birth'};
413 $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
414 $hofh_id = $membership_data{$index}{'HofH ID'};
415 $phone = $membership_data{$index}{'Phone 1'};
416 if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
417 if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
418 $address = $membership_data{$index}{'Street 1'};
419 if($membership_data{$index}{'Street 2'} ne "") {
420 $address .= " " . $membership_data{$index}{'Street 2'};
423 # Find the family id for this parent's HofH_ID.
424 $sth = $dbh->prepare("select * from eq_family where hofh_id='$hofh_id'");
425 $sth->execute or die "-E- DB error: $DBI::errstr\n";
426 $sqlhashref = $sth->fetchrow_hashref();
427 $family_id = $sqlhashref->{'family'};
429 # Find out how many parents match this parent's name
430 $sth = $dbh->prepare("select * from eq_parent where name='$parent_name'");
431 $sth->execute or die "-E- DB error: $DBI::errstr\n";
433 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
434 my $rows = scalar @data;
437 # No existing records found for this parent, make a new entry
438 print " Adding new Parent: $parent_name\n";
439 $sth = $dbh->prepare("insert into eq_parent values (NULL,$family_id,'$parent_name','$year-$month-$day','$phone','$address',1)");
440 $sth->execute or die "-E- DB error: $DBI::errstr\n";
441 } elsif($rows == 1) {
442 # An existing record was found for this parent, update it
443 print " Updating existing parent: $parent_name\n";
444 $sth = $dbh->prepare("update eq_parent set family='$family_id' where name='$parent_name'");
445 $sth->execute or die "-E- DB error: $DBI::errstr\n";
446 $sth = $dbh->prepare("update eq_parent set birthday='$year-$month-$day' where name='$parent_name'");
447 $sth->execute or die "-E- DB error: $DBI::errstr\n";
448 $sth = $dbh->prepare("update eq_parent set phone='$phone' where name='$parent_name'");
449 $sth->execute or die "-E- DB error: $DBI::errstr\n";
450 $sth = $dbh->prepare("update eq_parent set address='$address' where name='$parent_name'");
451 $sth->execute or die "-E- DB error: $DBI::errstr\n";
452 $sth = $dbh->prepare("update eq_parent set valid=1 where name='$parent_name'");
453 $sth->execute or die "-E- DB error: $DBI::errstr\n";
455 # More than one record was found. Error! This shouldn't happen.
456 print " -E- More than one record found with same parent name: $parent_name\n";
465 #+----------+------------------+------+-----+---------+-------+
466 #| Field | Type | Null | Key | Default | Extra |
467 #+----------+------------------+------+-----+---------+-------+
468 #| child | int(16) unsigned | | PRI | 0 | A |
469 #| family | int(16) unsigned | YES | | NULL | |
470 #| name | varchar(30) | YES | | NULL | |
471 #| birthday | date | YES | | NULL | |
472 #| valid | tinyint(1) | YES | | NULL | |
473 #+----------+------------------+------+-----+---------+-------+
474 sub update_eq_child_table
476 print "-> Updating eq_child table\n";
478 # Set all records to be invalid. Only mark them as valid if they appear on the new list.
479 $sth = $dbh->prepare("update eq_child set valid=0");
480 $sth->execute or die "-E- DB error: $DBI::errstr\n";
482 foreach $index (keys %membership_data)
484 $hashref = $membership_data{$index};
485 foreach $key (keys %$hashref) {
486 if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Other/i ) {
487 $child_name = $membership_data{$index}{'Full Name'};
488 $child_name =~ s/\'/\\'/g; #'
489 $birthday = $membership_data{$index}{'Birth'};
490 $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
491 $id = $membership_data{$index}{'Indiv ID'};
492 $hofh_id = $membership_data{$index}{'HofH ID'};
494 # Find the family id for this child's HofH_ID.
495 $sth = $dbh->prepare("select * from eq_family where hofh_id='$hofh_id'");
496 $sth->execute or die "-E- DB error: $DBI::errstr\n";
497 $sqlhashref = $sth->fetchrow_hashref();
498 $family_id = $sqlhashref->{'family'};
500 # Find out how many children have the same name for the same family
501 $sth = $dbh->prepare("select * from eq_child where name='$child_name'");
502 $sth->execute or die "-E- DB error: $DBI::errstr\n";
504 while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
505 my $rows = scalar @data;
508 # No existing records found for this child, make a new entry
509 print " Adding new Child: $child_name\n";
510 $sth = $dbh->prepare("insert into eq_child values (NULL,$family_id,'$child_name','$year-$month-$day',1)");
511 $sth->execute or die "-E- DB error: $DBI::errstr\n";
512 } elsif($rows == 1) {
513 # An existing record was found for this child, update it
514 print " Updating existing child: $child_name\n";
515 $sth = $dbh->prepare("update eq_child set family='$family_id' where name='$child_name'");
516 $sth->execute or die "-E- DB error: $DBI::errstr\n";
517 $sth = $dbh->prepare("update eq_child set birthday='$year-$month-$day' where name='$child_name'");
518 $sth->execute or die "-E- DB error: $DBI::errstr\n";
519 $sth = $dbh->prepare("update eq_child set valid=1 where name='$child_name'");
520 $sth->execute or die "-E- DB error: $DBI::errstr\n";
522 # More than one record was found. Error! This shouldn't happen.
523 print " -E- More than one record found ($rows) with same child name: $child_name\n";
531 ######################################################################
532 sub check_for_changed_ids
534 # If the Indiv ID & HofH ID has changed between data sets, we could have problems
535 my ($oldhashref, $newhashref) = @_;
536 my $found_problem = 0;
538 foreach $oldindex (keys %$oldhashref)
540 $indiv_id = $oldhashref->{$oldindex}{'Indiv ID'};
541 $hofh_id = $oldhashref->{$oldindex}{'HofH ID'};
542 $full_name = $oldhashref->{$oldindex}{'Full Name'};
543 $hh_position = $oldhashref->{$oldindex}{'HH Position'};
544 if($hh_position =~ /Other/i) { next; }
546 foreach $newindex (keys %$newhashref)
548 if($newhashref->{$newindex}{'Full Name'} eq $full_name &&
549 $indiv_id != $newhashref->{$newindex}{'Indiv ID'})
551 print "-W- Indiv ID for $full_name changed from $indiv_id to $newhashref->{$newindex}{'Indiv ID'}\n";
555 if($newhashref->{$newindex}{'Full Name'} eq $full_name &&
556 $hofh_id != $newhashref->{$newindex}{'HofH ID'})
558 print "-W- HofH ID for $full_name changed from $hofh_id to $newhashref->{$newindex}{'HofH ID'}\n";
564 return $found_problem;
567 ######################################################################
569 ######################################################################
571 ###################################################
572 # Open a connection to the database
573 $dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{
575 PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
577 ###################################################
578 # Check old directory against new directory to ensure
579 # that the Indiv ID & HofH ID have not changed between updates
581 print "-> Comparing old data files to new ones: $opt_o => $opt_n\n";
582 my %old_membership_data = ();
583 my %new_membership_data = ();
584 &csv_to_hash("$opt_o/Membership.csv",\%old_membership_data);
585 &csv_to_hash("$opt_n/Membership.csv",\%new_membership_data);
587 $changed_ids=&check_for_changed_ids(\%old_membership_data, \%new_membership_data);
591 print "-E- Some Indiv IDs and HofH IDs have changed for Head of Households between \n";
592 print " $opt_o and $opt_n data sets.\n";
593 print " This script is not currently setup to handle this properly.\n";
595 print " Exiting without updating...\n\n";
600 ###################################################
601 # Process command line options
602 if(defined $opt_n) { $datadir = $opt_n; }
603 else { $datadir = shift(@ARGV); }
604 print "-> Processing all ward data files in $datadir\n";
606 ###################################################
607 # Parse Ward Data Files
608 &csv_to_hash("$datadir/Membership.csv",\%membership_data);
609 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
612 print "-> Membership Data Dump\n\n";
613 &print_hash(\%membership_data);
614 print "-> HomeTeaching Data Dump\n\n";
615 &print_hash(\%hometeaching_data);
618 if($opt_s) { $dbh->disconnect(); exit; }
620 # Now update the various eq DB tables
621 &update_eq_elder_table();
622 &update_eq_aaronic_table();
623 &update_eq_district_table();
624 &update_eq_companionship_table();
625 &update_eq_family_table();
626 &update_eq_parent_table();
627 &update_eq_child_table();
629 ###################################################
630 # Disconnect from the database
633 ######################################################################