| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id$
|
| 4 |
|
| 5 |
/**
|
| 6 |
* genealogy.module provides a Drupal-compatible database for genealogical
|
| 7 |
* research, including obituary and marriage records.
|
| 8 |
*
|
| 9 |
* Note: This is an INTERIM VERSION based on the legacy database schema.
|
| 10 |
* This version will soon be replaced with a fully normalized database schema
|
| 11 |
* containing many additional features.
|
| 12 |
*/
|
| 13 |
|
| 14 |
function _genealogy_fields() {
|
| 15 |
return array("record_number" => "Record Number",
|
| 16 |
"name" => "Decedent's Name",
|
| 17 |
"maiden_name" => "Maiden Name",
|
| 18 |
"title" => "Title",
|
| 19 |
"birthplace" => "Birthplace",
|
| 20 |
"age" => "Age at Time of Death (Years)",
|
| 21 |
"age_notes" => "Age Notes",
|
| 22 |
"birth_date" => "Date of Birth",
|
| 23 |
"death_date" => "Date of Death",
|
| 24 |
"father" => "Father",
|
| 25 |
"mother" => "Mother",
|
| 26 |
"other_parent_1" => "Other Parent Info",
|
| 27 |
"other_parent_2" => "Other Parent Info",
|
| 28 |
"mother_maiden" => "Mother's Maiden Name",
|
| 29 |
"spouse_1" => "Spouse",
|
| 30 |
"spouse_2" => "Second Spouse",
|
| 31 |
"spouse_3" => "Third Spouse",
|
| 32 |
"spouse_4" => "Fourth Spouse",
|
| 33 |
"spouse_5" => "Fifth Spouse",
|
| 34 |
"burial_site" => "Location of Burial",
|
| 35 |
"obit_date" => "Obituary Date",
|
| 36 |
"obit_source" => "Obituary Source",
|
| 37 |
"other_sources" => "Other Sources",
|
| 38 |
"notes" => "Comments");
|
| 39 |
}
|
| 40 |
|
| 41 |
#$_genealogy_fields = array("last_name","first_name","middle_name","maiden_name","title",
|
| 42 |
# "birthplace","age","age_notes","birth_date","death_date","father","mother",
|
| 43 |
# "other_parent_1","other_parent_2","mother_maiden",
|
| 44 |
# "spouse_1","spouse_2","spouse_3","spouse_4","spouse_5",
|
| 45 |
# "burial_site","obit_date","obit_source","other_sources",
|
| 46 |
# "notes");
|
| 47 |
|
| 48 |
#$_genealogy_labels = array("Last Name","First Name","Middle Name","Maiden Name (last [,first middle])","Title",
|
| 49 |
# "Birthplace","Age at Death (Years)","Age Notes","Birth Date (YYYY-MM-DD)","Death Date (YYYY-MM-DD)",
|
| 50 |
# "Father (last, first middle)","Mother (last, first middle)",
|
| 51 |
# "Other Parent 1 (last, first middle)","Other Parent 2 (last, first middle)",
|
| 52 |
# "Mother's Maiden Name (last, first middle)","Spouse 1 (last, first middle)",
|
| 53 |
# "Spouse 2 (last, first middle)","Spouse 3 (last, first middle)",
|
| 54 |
# "Spouse 4 (last, first middle)","Spouse 5 (last, first middle)",
|
| 55 |
# "Burial Site","Obit Date (YYYY-MM-DD)","Obit Source","Other Sources",
|
| 56 |
# "Notes");
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Returns help text for various aspects of this module
|
| 60 |
*/
|
| 61 |
function genealogy_help($section) {
|
| 62 |
switch($section) {
|
| 63 |
case 'admin/modules#description':
|
| 64 |
return t('Offers a database for genealogical research');
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Return a list of permissions applicable to this module
|
| 70 |
*/
|
| 71 |
function genealogy_perm() {
|
| 72 |
return array('access genealogy database','administer genealogy module','manage genealogy records');
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Adds appropriate URLs to the Drupal main menu
|
| 77 |
*/
|
| 78 |
function genealogy_menu($may_cache) {
|
| 79 |
$items = array();
|
| 80 |
if ($may_cache) {
|
| 81 |
// Nothing
|
| 82 |
} else {
|
| 83 |
$items[] = array('path'=>'genealogy','title'=>t('Genealogy Database'),
|
| 84 |
'callback'=>'genealogy_legacy_query','access'=>user_access('access genealogy database'),
|
| 85 |
'type'=>MENU_CALLBACK);
|
| 86 |
$items[] = array('path'=>'genealogy/add','title'=>t('Genealogy Database -- Add record'),
|
| 87 |
'callback'=>'genealogy_legacy_insert','access'=>user_access('manage genealogy records'),
|
| 88 |
'type'=>MENU_CALLBACK);
|
| 89 |
$items[] = array('path'=>'genealogy/delete','title'=>t('Genealogy Database -- Delete record'),
|
| 90 |
'callback'=>'genealogy_legacy_delete','access'=>user_access('manage genealogy records'),
|
| 91 |
'type'=>MENU_CALLBACK);
|
| 92 |
}
|
| 93 |
return $items;
|
| 94 |
}
|
| 95 |
|
| 96 |
/************************* LEGACY STUFF ***********************************/
|
| 97 |
|
| 98 |
/**
|
| 99 |
* Legacy query of the obit_original table
|
| 100 |
*/
|
| 101 |
function genealogy_legacy_query($id='') {
|
| 102 |
$get_fields = array('recnum','lname','fname','soundex');
|
| 103 |
foreach ($get_fields as $field) {
|
| 104 |
if (empty($_POST[$field])) {
|
| 105 |
$_POST[$field] = $_GET[$field];
|
| 106 |
}
|
| 107 |
}
|
| 108 |
$recnum = $_POST['recnum'];
|
| 109 |
if (is_numeric($recnum) && empty($id)) {
|
| 110 |
$id = $recnum;
|
| 111 |
}
|
| 112 |
$content = '';
|
| 113 |
if (!empty($_POST['submit_edit'])) {
|
| 114 |
$op = 'edit';
|
| 115 |
} else if (!empty($_POST['submit_delete'])) {
|
| 116 |
if ($_POST['areyousure'] == 'Y') {
|
| 117 |
$op = 'delete_sure';
|
| 118 |
} else {
|
| 119 |
$op = 'delete';
|
| 120 |
}
|
| 121 |
}
|
| 122 |
if (is_numeric($id)) {
|
| 123 |
switch($op) {
|
| 124 |
case 'edit':
|
| 125 |
$content .= _genealogy_legacy_edit($id);
|
| 126 |
break;
|
| 127 |
case 'delete':
|
| 128 |
$content .= _genealogy_legacy_delete($id, $op);
|
| 129 |
break;
|
| 130 |
default:
|
| 131 |
$content .= _genealogy_legacy_detail($id);
|
| 132 |
}
|
| 133 |
} else {
|
| 134 |
$content .= _genealogy_legacy_search();
|
| 135 |
}
|
| 136 |
print(theme('page',$content));
|
| 137 |
}
|
| 138 |
|
| 139 |
function _genealogy_legacy_search() {
|
| 140 |
$soundex = $_POST['soundex'];
|
| 141 |
if ($soundex) {
|
| 142 |
$soundex_s0='';
|
| 143 |
$soundex_s1=' selected';
|
| 144 |
} else {
|
| 145 |
$soundex_s0=' selected';
|
| 146 |
$soundex_s1='';
|
| 147 |
}
|
| 148 |
$html = '';
|
| 149 |
$row = db_fetch_array(db_query('select count(*) n from {obit_original}'));
|
| 150 |
if (! is_array($row)) {
|
| 151 |
drupal_set_message("Database failure on record count query");
|
| 152 |
return '';
|
| 153 |
}
|
| 154 |
$count = $row['n'];
|
| 155 |
$html .= "<p align=\"center\">As of " . date("Y-m-d") . ", there are $count records in this database.\n";
|
| 156 |
if (user_access('manage genealogy records')) {
|
| 157 |
$html .= '<br /><b>[ <a href="/genealogy/add">Add a record</a> ]</b>';
|
| 158 |
}
|
| 159 |
$html .= '<p align="left"><b>Please provide the criteria on which to search. Other fields are optional. Results are limited to 1000 records maximum. Asterisk (*) indicates a required field.</b></p><p align="left">You may use an asterisk (*) or percent sign (%) as a wildcard character in the <b>last name</b> and/or <b>first name</b> fields. For example, jo% will find "Johnson", "Jones", "Johannson", etc., that also match any other criteria you define. Note that you can also use the wildcard to match middles or endings of names, for example, "%let" to find all names ending in "let", a common French suffix. If you use this feature, the sound-alike match is disabled for the last name (but still works on the first name).</p>';
|
| 160 |
$html .= '<div align="center"><table cellspacing="5" cellpadding="5">';
|
| 161 |
$form = '<tr><td align="right">Last Name *</td><td align="left"><input name="lname" type="text" value="';
|
| 162 |
$form .= $_POST["lname"];
|
| 163 |
$form .= '"></td></tr><tr><td align="right">First Name</td><td align="left"><input name="fname" type="text" value="';
|
| 164 |
$form .= $_POST["fname"] . '"></td></tr>';
|
| 165 |
$form .= '<tr><td align="right">Year of Death On or Before</td><td align="left"><input name="yod_before" type="text" value="';
|
| 166 |
$form .= $_POST["yod_before"] . '"></td></tr>';
|
| 167 |
$form .= '<tr><td align="right">Year of Death On or After</td><td align="left"><input name="yod_after" type="text" value="';
|
| 168 |
$form .= $_POST["yod_after"] . '"></td></tr>';
|
| 169 |
$form .= '<tr><td align="right">Allow Soundalike Names?</td><td align="left"><select name="soundex"><option value="0"';
|
| 170 |
$form .= $soundex_s0 . '>No</option><option value="1"';
|
| 171 |
$form .= $soundex_s1 . '>Yes</option></select></td></tr>';
|
| 172 |
$form .= '<tr><td align="right">Record Number</td><td align="left"><input name="recnum" type="text" value=""></td></tr><tr><td colspan="2" align="center">';
|
| 173 |
$form .= form_submit(t('Search'),'submit_search');
|
| 174 |
$form .= ' ';
|
| 175 |
$form .= form_button(t('Reset Form'),'reset','reset');
|
| 176 |
$html .= form($form,'POST');
|
| 177 |
$html .= '<p><form method="GET" action="/genealogy"><input type="submit" value="Start Over"></form>';
|
| 178 |
$html .= '</td></tr></table></div>';
|
| 179 |
$lname = $_POST["lname"];
|
| 180 |
$fname = $_POST["fname"];
|
| 181 |
$yod_after = $_POST["yod_after"];
|
| 182 |
$yod_before = $_POST["yod_before"];
|
| 183 |
if ($soundex) {
|
| 184 |
$sx1 = "soundex(";
|
| 185 |
$sx2 = ")";
|
| 186 |
} else {
|
| 187 |
$sx1 = "";
|
| 188 |
$sx2 = "";
|
| 189 |
}
|
| 190 |
if (!empty($lname)) {
|
| 191 |
$lname = ereg_replace(' .*','',$lname);
|
| 192 |
$lname = ereg_replace('\?','',$lname);
|
| 193 |
$lname = ereg_replace('\*','%',$lname);
|
| 194 |
$fname = ereg_replace(' .*','',$fname);
|
| 195 |
$fname = ereg_replace('\?','',$fname);
|
| 196 |
$fname = ereg_replace('\*','%',$fname);
|
| 197 |
# Do a database query!
|
| 198 |
if (ereg('\%',$lname)) {
|
| 199 |
$where = " where last_name like '" . $lname . "'";
|
| 200 |
} else {
|
| 201 |
$where = " where " . $sx1 . "last_name" . $sx2 . " = " . $sx1 . "'" . $lname . "'" . $sx2;
|
| 202 |
}
|
| 203 |
if (!empty($fname)) {
|
| 204 |
if (ereg('\%',$fname)) {
|
| 205 |
$where .= " and first_name like '" . $fname . "'";
|
| 206 |
} else {
|
| 207 |
$where .= " and " . $sx1 . "first_name" . $sx2 . " = " . $sx1 . "'" . $fname . "'" . $sx2;
|
| 208 |
}
|
| 209 |
}
|
| 210 |
if (!empty($yod_before)) {
|
| 211 |
if (intval($yod_before) < 100) {
|
| 212 |
$yod_before += 1900;
|
| 213 |
}
|
| 214 |
$where .= " and death_date <= '" . $yod_before . "-12-31'";
|
| 215 |
}
|
| 216 |
if (!empty($yod_after)) {
|
| 217 |
if (intval($yod_after) < 100) {
|
| 218 |
$yod_after += 1900;
|
| 219 |
}
|
| 220 |
$where .= " and death_date >= '" . $yod_after . "-01-01'";
|
| 221 |
}
|
| 222 |
$sql = "select record_number, last_name, first_name, middle_name, maiden_name, birth_date, death_date from obit_original" . $where;
|
| 223 |
$sql .= " order by last_name, first_name, middle_name, maiden_name limit 1000";
|
| 224 |
if ($result = db_query($sql)) {
|
| 225 |
$html .= "\n<table width=\"100%\" cellpadding=\"2\" cellspacing=\"2\" border=\"0\">\n";
|
| 226 |
$html .= "<tr align=\"center\" valign=\"bottom\">\n";
|
| 227 |
$html .= "<th $hdrbg>Rec. Num.</th><th $hdrbg>Name of Decedent</th><th $hdrbg>Born</th><th $hdrbg>Died</th>\n";
|
| 228 |
$found = FALSE;
|
| 229 |
$script_name = '/genealogy';
|
| 230 |
$soundex = empty($_POST['soundex']) ? $_GET['soundex'] : $_POST['soundex'];
|
| 231 |
while ($row = db_fetch_array($result)) {
|
| 232 |
$found = TRUE;
|
| 233 |
$rec = $row['record_number'];
|
| 234 |
$last = $row['last_name'];
|
| 235 |
$first = $row['first_name'];
|
| 236 |
$middle = $row['middle_name'];
|
| 237 |
$maiden = $row['maiden_name'];
|
| 238 |
$born = $row['birth_date'];
|
| 239 |
$died = $row['death_date'];
|
| 240 |
$link = '<a href="' . $script_name . '/' . $rec . '?soundex=' . $soundex . '">';
|
| 241 |
if ($born == '0000-00-00') {
|
| 242 |
$born = '(unknown)';
|
| 243 |
}
|
| 244 |
if ($died == '0000-00-00') {
|
| 245 |
$died = '(unknown)';
|
| 246 |
}
|
| 247 |
# Add a hyperlink to the record number
|
| 248 |
$rec = $link . $rec . "</a>";
|
| 249 |
$name = $last;
|
| 250 |
if (! empty($first)) {
|
| 251 |
$name .= ", " . $first;
|
| 252 |
if (! empty($middle)) {
|
| 253 |
$name .= " " . $middle;
|
| 254 |
}
|
| 255 |
} else {
|
| 256 |
$name .= ", ???";
|
| 257 |
}
|
| 258 |
$name = $link . $name . "</a>";
|
| 259 |
if (! empty($maiden)) {
|
| 260 |
$mlink = "<a href=\"" . $script_name . "?soundex=" . $soundex . "&lname=" . urlencode($maiden) . "\">";
|
| 261 |
$name .= " (neé " . $mlink . $maiden . "</a>)";
|
| 262 |
}
|
| 263 |
$html .= "<tr align=\"left\" valign=\"top\">\n";
|
| 264 |
$html .= "\t<td align=\"center\">" . $rec . "</td><td><b>" . $name . "</b></td>";
|
| 265 |
$html .= "<td align=\"center\">" . $born . "</td><td align=\"center\">" . $died . "</td>";
|
| 266 |
$html .= "</tr>";
|
| 267 |
}
|
| 268 |
if (! $found) {
|
| 269 |
$html .= "<tr><td align=\"center\" colspan=\"3\" bgcolor=\"#802020\"><font color=\"#ffffff\"><b>No records matching search criteria. ";
|
| 270 |
$html .= "Please try a broader query.</b></font></td></tr>\n";
|
| 271 |
}
|
| 272 |
$html .= "</table>\n";
|
| 273 |
$html .= "<br clear=\"all\">\n";
|
| 274 |
$html .= "<p>In case you are technically inclined or curious, the SQL query executed for you was: <br><code>";
|
| 275 |
$html .= "<font size=\"-1\">" . htmlspecialchars($sql) . "</font></code><br>\n";
|
| 276 |
}
|
| 277 |
}
|
| 278 |
return $html;
|
| 279 |
}
|
| 280 |
|
| 281 |
function _genealogy_legacy_detail($recnum) {
|
| 282 |
$output = '';
|
| 283 |
$fields = _genealogy_fields();
|
| 284 |
$script_name = '/genealogy';
|
| 285 |
$soundex = $_POST['soundex'];
|
| 286 |
if ($_POST['op'] == t('Cancel')) {
|
| 287 |
drupal_set_message(t('Changed discarded'),'status');
|
| 288 |
} else if ($_POST['op'] == t('Save Changes')) {
|
| 289 |
# Update existing record
|
| 290 |
$row = db_fetch_array(db_query("select * from {obit_original} where record_number=%d",array($recnum)));
|
| 291 |
$sql = "";
|
| 292 |
$value_list = "";
|
| 293 |
$_POST['edit']['record_number']=$recnum;
|
| 294 |
// Modify the field list to match the internal database columns
|
| 295 |
$fields_x = array_merge($fields, array('first_name'=>'First name','last_name'=>'Last name','middle_name'=>'Middle name'));
|
| 296 |
unset($fields_x['name']);
|
| 297 |
reset($fields_x);
|
| 298 |
while (list($field,) = each($fields_x)) {
|
| 299 |
$value = $_POST['edit'][$field];
|
| 300 |
if ($row[$field] != $value) {
|
| 301 |
$prepared_value = "'" . $value . "'";
|
| 302 |
if ($value_list != "") {
|
| 303 |
$value_list .= ", ";
|
| 304 |
}
|
| 305 |
$value_list .= $field . "=" . $prepared_value;
|
| 306 |
}
|
| 307 |
}
|
| 308 |
if ($value_list != "") {
|
| 309 |
# At least one field was changed
|
| 310 |
$sql = "update obit_original set " . $value_list;
|
| 311 |
$sql .= " where record_number=" . $recnum;
|
| 312 |
if (db_query($sql)) {
|
| 313 |
$output .= "<p><b>Record " . $recnum . " has been updated successfully.</b></p>\n";
|
| 314 |
} else {
|
| 315 |
$output .= "<p><b>UPDATE FAILED! Please contact database administrator.</b></p>";
|
| 316 |
}
|
| 317 |
}
|
| 318 |
drupal_set_message(t('Changes saved'),'status');
|
| 319 |
} else if ($_POST['op'] == t('Add Record')) {
|
| 320 |
$sql = "";
|
| 321 |
$value_list = "";
|
| 322 |
$field_list = implode(',',$fields);
|
| 323 |
unset($_POST['edit']['record_number']);
|
| 324 |
// Modify the field list to match the internal database columns
|
| 325 |
$fields_x = array_merge($fields, array('first_name'=>'First name','last_name'=>'Last name','middle_name'=>'Middle name'));
|
| 326 |
unset($fields_x['name']);
|
| 327 |
reset($fields_x);
|
| 328 |
while (list($field,) = each($fields_x)) {
|
| 329 |
$value = $_POST['edit'][$field];
|
| 330 |
$prepared_value = empty($value) ? "NULL" : "'" . $value . "'";
|
| 331 |
if ($value_list == "") {
|
| 332 |
$value_list .= $prepared_value;
|
| 333 |
} else {
|
| 334 |
$value_list .= ", " . $prepared_value;
|
| 335 |
}
|
| 336 |
if ($sql == "") {
|
| 337 |
$sql = "insert into obit_original (";
|
| 338 |
} else {
|
| 339 |
$sql .= ", ";
|
| 340 |
}
|
| 341 |
$sql .= $field;
|
| 342 |
}
|
| 343 |
$sql .= ") values (" . $value_list . ")";
|
| 344 |
if (db_query($sql)) {
|
| 345 |
$row = db_fetch_array(db_query('select last_insert_id() id'));
|
| 346 |
$recnum = $row['id'];
|
| 347 |
$_POST['edit']['record_number'] = $recnum;
|
| 348 |
drupal_set_message('Record number '.$recnum.' was successfully added.','status');
|
| 349 |
return form(form_submit(t('View Record')),'POST','/genealogy/'.$recnum);
|
| 350 |
} else {
|
| 351 |
$recnum = 0;
|
| 352 |
drupal_set_message('INSERT FAILED! Please contact database administrator.','error');
|
| 353 |
}
|
| 354 |
return _genealogy_legacy_edit($recnum);
|
| 355 |
}
|
| 356 |
$row = db_fetch_array(db_query("select * from {obit_original} where record_number=%d",array($recnum)));
|
| 357 |
if (! is_array($row)) {
|
| 358 |
drupal_set_message($recnum . ': ' . t('Record not found'),'error');
|
| 359 |
return '';
|
| 360 |
}
|
| 361 |
$html = '';
|
| 362 |
if ($row["birth_date"] == '0000-00-00') {
|
| 363 |
$row["birth_date"] = '(unknown)';
|
| 364 |
}
|
| 365 |
if ($row["death_date"] == '0000-00-00') {
|
| 366 |
$row["death_date"] = '(unknown)';
|
| 367 |
}
|
| 368 |
$row["name"] = $row["last_name"];
|
| 369 |
if (! empty($row["first_name"])) {
|
| 370 |
$row["name"] .= ", " . $row["first_name"];
|
| 371 |
if (! empty($row["middle_name"])) {
|
| 372 |
$row["name"] .= " " . $row["middle_name"];
|
| 373 |
}
|
| 374 |
} else {
|
| 375 |
$row["name"] .= ", ???";
|
| 376 |
}
|
| 377 |
reset($fields);
|
| 378 |
$html .= "<div align=\"center\">\n";
|
| 379 |
$html .= "\n<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">\n";
|
| 380 |
while (list($field,$label) = each($fields)) {
|
| 381 |
$value = $row[$field];
|
| 382 |
if (!empty($value)) {
|
| 383 |
switch ($field) {
|
| 384 |
case "father":
|
| 385 |
case "mother":
|
| 386 |
case "other_parent_1":
|
| 387 |
case "other_parent_2":
|
| 388 |
case "spouse_1":
|
| 389 |
case "spouse_2":
|
| 390 |
case "spouse_3":
|
| 391 |
case "spouse_4":
|
| 392 |
case "spouse_5":
|
| 393 |
$name_parts = _genealogy_split_name($value);
|
| 394 |
$link = "<a href=\"" . $script_name . "?lname=" . urlencode($name_parts[0]);
|
| 395 |
$link .= "&fname=" . urlencode($name_parts[1]) . "&soundex=" . $soundex . "\">";
|
| 396 |
$elink = "</a>";
|
| 397 |
$value = $link . $value . $elink;
|
| 398 |
break;
|
| 399 |
case "maiden_name":
|
| 400 |
case "mother_maiden":
|
| 401 |
$link = "<a href=\"" . $script_name . "?lname=" . urlencode($value);
|
| 402 |
$link .= "&soundex=" . $soundex . "\">";
|
| 403 |
$elink = "</a>";
|
| 404 |
$value = $link . $value . $elink;
|
| 405 |
break;
|
| 406 |
case "notes":
|
| 407 |
if (eregi('^see *:',$value)) {
|
| 408 |
# It's a "See:" reference. Make it a link to the other name.
|
| 409 |
$val1 = trim(eregi_replace('^see *:','',$value));
|
| 410 |
$name_parts = _genealogy_split_name($val1);
|
| 411 |
$link = "<a href=\"" . $script_name . "?lname=" . urlencode($name_parts[0]);
|
| 412 |
$link .= "&fname=" . urlencode($name_parts[1]) . "&soundex=" . $soundex . "\">";
|
| 413 |
$elink = "</a>";
|
| 414 |
} else {
|
| 415 |
$link = "";
|
| 416 |
$elink = "";
|
| 417 |
}
|
| 418 |
$value = "See: " . $link . $val1 . $elink;
|
| 419 |
break;
|
| 420 |
case "name":
|
| 421 |
# Make this one boldface
|
| 422 |
$value = "<b>" . $value . "</b>";
|
| 423 |
default:
|
| 424 |
$link = "";
|
| 425 |
$elink = "";
|
| 426 |
}
|
| 427 |
$html .= "<tr valign=\"top\"><th align=\"right\"" . $hdrbg . ">" . $label . "</td><td align=\"left\">";
|
| 428 |
$html .= $value . "</td></tr>\n";
|
| 429 |
}
|
| 430 |
}
|
| 431 |
$recnum = $row["record_number"];
|
| 432 |
if (user_access('manage genealogy records') && $recnum) {
|
| 433 |
$html .= "<tr valign=\"top\"><td align=\"center\">";
|
| 434 |
$form = form_hidden('soundex',$_POST['soundex']);
|
| 435 |
$form .= form_hidden('recnum',$recnum);
|
| 436 |
$form .= form_submit(t('Edit Record'),'submit_edit');
|
| 437 |
$html .= form($form,'POST');
|
| 438 |
$html .= '</td><td align="center">';
|
| 439 |
$form = form_hidden('soundex',$_POST['soundex']);
|
| 440 |
$form .= form_hidden('recnum',$recnum);
|
| 441 |
$form .= form_submit(t('Delete Record'));
|
| 442 |
$html .= form($form,'POST','/genealogy/delete/'.$recnum);
|
| 443 |
$html .= "</td></tr>\n";
|
| 444 |
}
|
| 445 |
$html .= "</table>\n<hr>";
|
| 446 |
$html .= '<p align="center"><b><a href="/genealogy">Start New Search</a></b></p>';
|
| 447 |
$html .= "</div>\n";
|
| 448 |
return $html;
|
| 449 |
}
|
| 450 |
|
| 451 |
# Splits a name in the form "last, first middle" into its component
|
| 452 |
# parts. Returns an array where 0 is last, 1 is first, and 2 is all
|
| 453 |
# other parts (as middle).
|
| 454 |
function _genealogy_split_name($name) {
|
| 455 |
# Last name goes into element 0, rest into element 1
|
| 456 |
$parts = explode(",",$name);
|
| 457 |
$p1 = explode(" ",trim($parts[1]));
|
| 458 |
$parts[1] = $p1[0];
|
| 459 |
$parts[2] = $p1[1];
|
| 460 |
$i = 2;
|
| 461 |
while (!empty($p1[$i])) {
|
| 462 |
$parts[2] .= " " . $p1[$i++];
|
| 463 |
}
|
| 464 |
for ($i=0; $i<3; $i++) {
|
| 465 |
$parts[$i] = trim($parts[$i]);
|
| 466 |
}
|
| 467 |
return $parts;
|
| 468 |
}
|
| 469 |
|
| 470 |
function _genealogy_query_form($edit=FALSE) {
|
| 471 |
global $_POST, $SCRIPT_NAME;
|
| 472 |
$soundex = $_POST["soundex"];
|
| 473 |
$soundex_s0 = $soundex ? "" : " selected";
|
| 474 |
$soundex_s1 = $soundex ? " selected" : "";
|
| 475 |
|
| 476 |
$hdrbg = "bgcolor=\"#d0d0d0\"";
|
| 477 |
|
| 478 |
$html .= "<div align=\"center\">\n";
|
| 479 |
$html .= "<table cellspacing=\"5\" cellpadding=\"5\">\n";
|
| 480 |
$html .= "<form action=\"" . $SCRIPT_NAME . "\" method=\"POST\">\n";
|
| 481 |
$html .= "<tr><td align=\"right\">Last Name *</td><td align=\"left\"><input name=\"lname\" type=\"text\" value=\"" . $_POST["lname"] . "\"></td></tr>\n";
|
| 482 |
$html .= "<tr><td align=\"right\">First Name</td><td align=\"left\"><input name=\"fname\" type=\"text\" value=\"" . $_POST["fname"] . " \"></td></tr>\n";
|
| 483 |
$html .= "<tr><td align=\"right\">Year of Death On or Before</td><td align=\"left\"><input name=\"yod_before\" type=\"text\" value=\"" . $_POST["yod_before"] . " \"></td></tr>\n";
|
| 484 |
$html .= "<tr><td align=\"right\">Year of Death On or After</td><td align=\"left\"><input name=\"yod_after\" type=\"text\" value=\"" . $_POST["yod_after"] . " \"></td></tr>\n";
|
| 485 |
$html .= "<tr><td align=\"right\">Allow Soundalike Names?</td><td align=\"left\"><select name=\"soundex\"><option value=\"0\"" . $soundex_s0 . "\">No</option><option value=\"1\"" . $soundex_s1 . ">Yes</option></select></td></tr>\n";
|
| 486 |
$html .= "<tr><td align=\"right\">Record Number</td><td align=\"left\"><input name=\"recnum\" type=\"text\" value=\"\"></td></tr>\n";
|
| 487 |
$html .= "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Search!\"> <input type=\"reset\" value=\"Reset Form\"></form></td></tr>\n";
|
| 488 |
$html .= "<tr><td colspan=\"2\" align=\"center\"><form action=\"" . $SCRIPT_NAME . "\" method=\"POST\"> <input type=\"hidden\" name=\"soundex\" value=\"" . $soundex . "\"><input type=\"submit\" value=\"Clear Fields\"></td></tr>\n";
|
| 489 |
$html .= "</table>\n";
|
| 490 |
$html .= "</div>\n";
|
| 491 |
return $html;
|
| 492 |
}
|
| 493 |
|
| 494 |
# Return an array containing the contents of the specified record,
|
| 495 |
# or an empty array if not found.
|
| 496 |
function _genealogy_get_legacy_record($recnum) {
|
| 497 |
if ($recnum > 0) {
|
| 498 |
$old_data = db_fetch_array(db_query('select * from {obit_original} where record_number=%d', array($recnum)));
|
| 499 |
} else {
|
| 500 |
$old_data = array();
|
| 501 |
}
|
| 502 |
return $old_data;
|
| 503 |
}
|
| 504 |
|
| 505 |
function genealogy_legacy_delete($recnum) {
|
| 506 |
if (! $recnum) {
|
| 507 |
drupal_set_message(t('Cannot delete -- no record number specified'),'error');
|
| 508 |
print(theme('page',''));
|
| 509 |
return;
|
| 510 |
}
|
| 511 |
$soundex = $_POST["soundex"];
|
| 512 |
if ($_POST['op'] == t('Yes, I am sure')) {
|
| 513 |
if (db_query("delete from {obit_original} where record_number=%d",array($recnum))) {
|
| 514 |
drupal_set_message(t('Deleted record ').$recnum,'status');
|
| 515 |
} else {
|
| 516 |
drupal_set_message(t('Failed to delete record ').$recnum,'error');
|
| 517 |
}
|
| 518 |
# Just display a button to return.
|
| 519 |
$output = form(form_submit(t('Return')),'POST','/genealogy');
|
| 520 |
} else if ($_POST['op'] == t('Cancel Delete')) {
|
| 521 |
# Just display a button to return.
|
| 522 |
drupal_set_message("Delete cancelled.");
|
| 523 |
$form .= form_submit(t('Return'));
|
| 524 |
$output = form($form,'POST','/genealogy/'.$recnum);
|
| 525 |
} else {
|
| 526 |
# Just display the are-you-sure buttons, with no data.
|
| 527 |
$form = '<table border="0">';
|
| 528 |
$form .= "<tr valign=\"bottom\" align=\"center\">\n";
|
| 529 |
$form .= "<td colspan=\"2\">Are you sure you want to delete record number " . $recnum . "?\n";
|
| 530 |
$form .= "<br>There is no way to restore a deleted record.</td>\n";
|
| 531 |
$form .= "</tr>\n";
|
| 532 |
$form .= "<tr valign=\"bottom\" align=\"center\">\n";
|
| 533 |
$form .= "<td>" . form_submit(t('Yes, I am sure')) . "</td>\n";
|
| 534 |
$form .= "<td>" . form_submit(t('Cancel Delete')) . "</td>\n";
|
| 535 |
$form .= "</tr>\n";
|
| 536 |
$form .= '</table>';
|
| 537 |
$output = form($form,'POST');
|
| 538 |
}
|
| 539 |
print(theme('page',$output));
|
| 540 |
}
|
| 541 |
|
| 542 |
function genealogy_legacy_insert() {
|
| 543 |
if ($_POST['op'] == t('Add Record')) {
|
| 544 |
$content = _genealogy_legacy_detail(0);
|
| 545 |
} else {
|
| 546 |
$content = _genealogy_legacy_edit(0);
|
| 547 |
}
|
| 548 |
print(theme('page', $content));
|
| 549 |
}
|
| 550 |
|
| 551 |
function _genealogy_legacy_edit($recnum) {
|
| 552 |
$fields = _genealogy_fields();
|
| 553 |
$soundex = empty($_POST['edit']['soundex']) ? $_POST["soundex"] : $_POST['edit']['soundex'];
|
| 554 |
// Fetch the old data, if applicable
|
| 555 |
if ($recnum) {
|
| 556 |
$old_data = db_fetch_array(db_query('select * from {obit_original} where record_number=%d', array($recnum)));
|
| 557 |
} else if (is_array($_POST['edit'])) {
|
| 558 |
$old_data = $_POST['edit'];
|
| 559 |
} else {
|
| 560 |
$old_data = array();
|
| 561 |
}
|
| 562 |
if ($recnum > 0 && ! $old_data['record_number']) {
|
| 563 |
drupal_set_message(t('Record ').$recnum.t(' could not be retrieved from database.'), 'error');
|
| 564 |
return '';
|
| 565 |
}
|
| 566 |
# Display the editing form
|
| 567 |
$output .= "<div align=\"center\">\n";
|
| 568 |
$form = form_hidden('soundex',$soundex);
|
| 569 |
$form .= form_hidden('recnum',$old_data["record_number"]);
|
| 570 |
$form .= '<table border="0" class="genealogy">';
|
| 571 |
reset($fields);
|
| 572 |
while (list($field,$label) = each($fields)) {
|
| 573 |
$form .= "<tr valign=\"middle\">\n";
|
| 574 |
if ($field == "notes") {
|
| 575 |
$form .= '<td colspan="2" align="left">';
|
| 576 |
} else if ($field == "name") {
|
| 577 |
$form .= '<td align="right" class="name"><div class="form-item">';
|
| 578 |
$form .= '<label for="edit-'.$field.'">' . htmlspecialchars(t($label)) . '</label></div></td>';
|
| 579 |
$form .= '<td align="left">';
|
| 580 |
} else {
|
| 581 |
$form .= '<td align="right"><div class="form-item">';
|
| 582 |
$form .= '<label for="edit-'.$field.'">' . htmlspecialchars(t($label)) . '</label></div></td>';
|
| 583 |
$form .= '<td align="left">';
|
| 584 |
}
|
| 585 |
switch($field) {
|
| 586 |
case "record_number":
|
| 587 |
$form .= $recnum ? $recnum : '(New record)';
|
| 588 |
break;
|
| 589 |
case "name":
|
| 590 |
$form .= form_textfield(t('Last'), 'last_name', $old_data['last_name'], 20, 20, '', array(), TRUE);
|
| 591 |
$form .= form_textfield(t('First'), 'first_name', $old_data['first_name'], 20, 20, '', array(), TRUE);
|
| 592 |
$form .= form_textfield(t('Middle'), 'middle_name', $old_data['middle_name'], 20, 20, '');
|
| 593 |
break;
|
| 594 |
case "age":
|
| 595 |
$form .= form_textfield('', $field, $old_data[$field], 4, 4, '');
|
| 596 |
break;
|
| 597 |
case "birth_date":
|
| 598 |
case "death_date":
|
| 599 |
case "obit_date":
|
| 600 |
$form .= form_textfield('',$field, $old_data[$field], 15, 10, '');
|
| 601 |
break;
|
| 602 |
case "notes":
|
| 603 |
$form .= form_textarea(t($label), $field, $old_data[$field], 50, 3, '', array('wrap'=>'soft'));
|
| 604 |
break;
|
| 605 |
default:
|
| 606 |
$form .= form_textfield('', $field, $old_data[$field], 40, 50, '');
|
| 607 |
}
|
| 608 |
$form .= "</td>";
|
| 609 |
$form .= "</tr>";
|
| 610 |
}
|
| 611 |
$form .= "<tr valign=\"bottom\" align=\"center\">\n";
|
| 612 |
$form .= '<td>' . form_submit(t($recnum ? 'Save Changes' : 'Add Record')) . '</td>';
|
| 613 |
$form .= '<td>' . form_submit(t('Cancel')) . '</td>';
|
| 614 |
$form .= "</tr>\n";
|
| 615 |
$form .= "</table>\n";
|
| 616 |
$output .= form($form, 'POST');
|
| 617 |
$output .= "</div>\n";
|
| 618 |
return $output;
|
| 619 |
}
|
| 620 |
?>
|