| Total Complexity | 329 |
| Total Lines | 1635 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like FunctionsEdit often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FunctionsEdit, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 61 | class FunctionsEdit { |
||
| 62 | /** |
||
| 63 | * Function edit_language_checkboxes |
||
| 64 | * |
||
| 65 | * @param string $parameter_name |
||
| 66 | * @param array $accepted_languages |
||
| 67 | * |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public static function editLanguageCheckboxes($parameter_name, $accepted_languages) { |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * A list of access levels (e.g. for an edit control). |
||
| 87 | * |
||
| 88 | * @return string[] |
||
| 89 | */ |
||
| 90 | public static function optionsAccessLevels() { |
||
| 91 | return [ |
||
| 92 | Auth::PRIV_PRIVATE => I18N::translate('Show to visitors'), |
||
| 93 | Auth::PRIV_USER => I18N::translate('Show to members'), |
||
| 94 | Auth::PRIV_NONE => I18N::translate('Show to managers'), |
||
| 95 | Auth::PRIV_HIDE => I18N::translate('Hide from everyone'), |
||
| 96 | ]; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * A list of active languages (e.g. for an edit control). |
||
| 101 | * |
||
| 102 | * @return string[] |
||
| 103 | */ |
||
| 104 | public static function optionsActiveLanguages() { |
||
| 105 | $languages = []; |
||
| 106 | foreach (I18N::activeLocales() as $locale) { |
||
| 107 | $languages[$locale->languageTag()] = $locale->endonym(); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $languages; |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * A list of calendar conversions (e.g. for an edit control). |
||
| 115 | * |
||
| 116 | * @return string[] |
||
| 117 | */ |
||
| 118 | public static function optionsCalendarConversions() { |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * A list of contact methods (e.g. for an edit control). |
||
| 124 | * |
||
| 125 | * @return string[] |
||
| 126 | */ |
||
| 127 | public static function optionsContactMethods() { |
||
| 128 | return [ |
||
| 129 | 'messaging' => I18N::translate('Internal messaging'), |
||
| 130 | 'messaging2' => I18N::translate('Internal messaging with emails'), |
||
| 131 | 'messaging3' => I18N::translate('webtrees sends emails with no storage'), |
||
| 132 | 'mailto' => I18N::translate('Mailto link'), |
||
| 133 | 'none' => I18N::translate('No contact'), |
||
| 134 | ]; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * A list of hide/show options (e.g. for an edit control). |
||
| 139 | * |
||
| 140 | * @return string[] |
||
| 141 | */ |
||
| 142 | public static function optionsHideShow() { |
||
| 143 | return [ |
||
| 144 | '0' => I18N::translate('no'), |
||
| 145 | '1' => I18N::translate('yes'), |
||
| 146 | ]; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * A list of installed languages (e.g. for an edit control). |
||
| 151 | * |
||
| 152 | * @return string[] |
||
| 153 | */ |
||
| 154 | public static function optionsInstalledLanguages() { |
||
| 155 | $languages = []; |
||
| 156 | foreach (I18N::installedLocales() as $locale) { |
||
| 157 | $languages[$locale->languageTag()] = $locale->endonym(); |
||
| 158 | } |
||
| 159 | |||
| 160 | return $languages; |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * A list of integers (e.g. for an edit control). |
||
| 165 | * |
||
| 166 | * @param int[] $integers |
||
| 167 | * |
||
| 168 | * @return string[] |
||
| 169 | */ |
||
| 170 | public static function numericOptions($integers) { |
||
| 171 | $array = []; |
||
| 172 | foreach ($integers as $integer) { |
||
| 173 | if ($integer === -1) { |
||
| 174 | $array[$integer] = I18N::translate('All'); |
||
| 175 | } else { |
||
| 176 | $array[$integer] = I18N::number($integer); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | return $array; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * A list of no/yes options (e.g. for an edit control). |
||
| 185 | * |
||
| 186 | * @return string[] |
||
| 187 | */ |
||
| 188 | public static function optionsNoYes() { |
||
| 189 | return [ |
||
| 190 | '0' => I18N::translate('no'), |
||
| 191 | '1' => I18N::translate('yes'), |
||
| 192 | ]; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * A list of GEDCOM relationships (e.g. for an edit control). |
||
| 197 | * |
||
| 198 | * @param string $relationship |
||
| 199 | * |
||
| 200 | * @return string[] |
||
| 201 | */ |
||
| 202 | public static function optionsRelationships($relationship) { |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * A list of GEDCOM restrictions (e.g. for an edit control). |
||
| 214 | * |
||
| 215 | * @param bool $include_empty |
||
| 216 | * |
||
| 217 | * @return string[] |
||
| 218 | */ |
||
| 219 | public static function optionsRestrictions($include_empty) { |
||
| 220 | $options = [ |
||
| 221 | 'none' => I18N::translate('Show to visitors'), // Not valid GEDCOM, but very useful |
||
| 222 | 'privacy' => I18N::translate('Show to members'), |
||
| 223 | 'confidential' => I18N::translate('Show to managers'), |
||
| 224 | 'locked' => I18N::translate('Only managers can edit'), |
||
| 225 | ]; |
||
| 226 | |||
| 227 | if ($include_empty) { |
||
| 228 | $options = ['' => ''] + $options; |
||
| 229 | } |
||
| 230 | |||
| 231 | return $options; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * A list mail transport options (e.g. for an edit control). |
||
| 236 | * |
||
| 237 | * @return string[] |
||
| 238 | */ |
||
| 239 | public static function optionsMailTransports() { |
||
| 240 | return [ |
||
| 241 | 'internal' => I18N::translate('Use PHP mail to send messages'), |
||
| 242 | 'external' => I18N::translate('Use SMTP to send messages'), |
||
| 243 | ]; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * A list of temple options (e.g. for an edit control). |
||
| 248 | * |
||
| 249 | * @return string[] |
||
| 250 | */ |
||
| 251 | public static function optionsTemples() { |
||
| 252 | return ['' => I18N::translate('No temple - living ordinance')] + GedcomCodeTemp::templeNames(); |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * A list of user options (e.g. for an edit control). |
||
| 257 | * |
||
| 258 | * @return string[] |
||
| 259 | */ |
||
| 260 | public static function optionsUsers() { |
||
| 261 | $options = ['' => '-']; |
||
| 262 | |||
| 263 | foreach (User::all() as $user) { |
||
| 264 | $options[$user->getUserName()] = $user->getRealName() . ' - ' . $user->getUserName(); |
||
| 265 | } |
||
| 266 | |||
| 267 | return $options; |
||
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Create a form control to select a family. |
||
| 272 | * |
||
| 273 | * @param Tree $tree |
||
| 274 | * @param Family|null $family |
||
| 275 | * @param string[] $attributes |
||
| 276 | * |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | public static function formControlFamily(Tree $tree, Family $family = null, array $attributes = []) { |
||
| 280 | $value = ''; |
||
| 281 | $options = ['' => '']; |
||
| 282 | |||
| 283 | if ($family !== null) { |
||
| 284 | $value = $family->getXref(); |
||
| 285 | $options = [$value => view('selects/family', ['family' => $family])]; |
||
| 286 | } |
||
| 287 | |||
| 288 | return Bootstrap4::select($options, $value, Select2::familyConfig($tree) + $attributes); |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Create a form control to select a flag. |
||
| 293 | * |
||
| 294 | * @param string $flag |
||
| 295 | * @param string[] $attributes |
||
| 296 | * |
||
| 297 | * @return string |
||
| 298 | */ |
||
| 299 | public static function formControlFlag($flag, array $attributes = []) { |
||
| 300 | $value = ''; |
||
| 301 | $options = ['' => '']; |
||
| 302 | |||
| 303 | if ($flag !== '') { |
||
| 304 | $value = $flag; |
||
| 305 | $options = [$value => Select2::flagValue($flag)]; |
||
| 306 | } |
||
| 307 | |||
| 308 | return Bootstrap4::select($options, $value, Select2::flagConfig() + $attributes); |
||
| 309 | } |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Create a form control to select an individual. |
||
| 313 | * |
||
| 314 | * @param Tree $tree |
||
| 315 | * @param Individual|null $individual |
||
| 316 | * @param string[] $attributes |
||
| 317 | * |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | public static function formControlIndividual(Tree $tree, Individual $individual = null, array $attributes = []) { |
||
| 321 | $value = ''; |
||
| 322 | $options = ['' => '']; |
||
| 323 | |||
| 324 | if ($individual !== null) { |
||
| 325 | $value = $individual->getXref(); |
||
| 326 | $options = [$value => view('selects/individual', ['individual' => $individual])]; |
||
| 327 | } |
||
| 328 | |||
| 329 | return Bootstrap4::select($options, $value, Select2::individualConfig($tree) + $attributes); |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Create a form control to select a media object. |
||
| 334 | * |
||
| 335 | * @param Tree $tree |
||
| 336 | * @param Media|null $media |
||
| 337 | * @param string[] $attributes |
||
| 338 | * |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | public static function formControlMediaObject(Tree $tree, Media $media = null, array $attributes = []) { |
||
| 342 | $value = ''; |
||
| 343 | $options = ['' => '']; |
||
| 344 | |||
| 345 | if ($media !== null) { |
||
| 346 | $value = $media->getXref(); |
||
| 347 | $options = [$value => view('selects/media', ['media' => $media])]; |
||
| 348 | } |
||
| 349 | |||
| 350 | return Bootstrap4::select($options, $value, Select2::mediaObjectConfig($tree) + $attributes); |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Create a form control to select a note. |
||
| 355 | * |
||
| 356 | * @param Tree $tree |
||
| 357 | * @param Note|null $note |
||
| 358 | * @param string[]|null $attributes |
||
| 359 | * |
||
| 360 | * @return string |
||
| 361 | */ |
||
| 362 | public static function formControlNote(Tree $tree, Note $note = null, array $attributes = []) { |
||
| 363 | $value = ''; |
||
| 364 | $options = ['' => '']; |
||
| 365 | |||
| 366 | if ($note !== null) { |
||
| 367 | $value = $note->getXref(); |
||
| 368 | $options = [$value => view('selects/note', ['note' => $note])]; |
||
| 369 | } |
||
| 370 | |||
| 371 | return Bootstrap4::select($options, $value, Select2::noteConfig($tree) + $attributes); |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Create a form control to select a place. |
||
| 376 | * |
||
| 377 | * @param Tree $tree |
||
| 378 | * @param string $place |
||
| 379 | * @param string[] $attributes |
||
| 380 | * |
||
| 381 | * @return string |
||
| 382 | */ |
||
| 383 | public static function formControlPlace(Tree $tree, $place, array $attributes = []) { |
||
| 384 | $value = ''; |
||
| 385 | $options = ['' => '']; |
||
| 386 | |||
| 387 | if ($place !== '') { |
||
| 388 | $options = [$place => $place]; |
||
| 389 | } |
||
| 390 | |||
| 391 | return Bootstrap4::select($options, $value, Select2::placeConfig($tree) + $attributes); |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Create a form control to select a repository. |
||
| 396 | * |
||
| 397 | * @param Tree $tree |
||
| 398 | * @param Repository|null $repository |
||
| 399 | * @param string[] $attributes |
||
| 400 | * |
||
| 401 | * @return string |
||
| 402 | */ |
||
| 403 | public static function formControlRepository(Tree $tree, Repository $repository = null, array $attributes = []) { |
||
| 404 | $value = ''; |
||
| 405 | $options = ['' => '']; |
||
| 406 | |||
| 407 | if ($repository !== null) { |
||
| 408 | $value = $repository->getXref(); |
||
| 409 | $options = [$value => view('selects/repository', ['repository' => $repository])]; |
||
| 410 | } |
||
| 411 | |||
| 412 | return Bootstrap4::select($options, $value, Select2::repositoryConfig($tree) + $attributes); |
||
| 413 | } |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Create a form control to select a source. |
||
| 417 | * |
||
| 418 | * @param Tree $tree |
||
| 419 | * @param Source|null $source |
||
| 420 | * @param string[] $attributes |
||
| 421 | * |
||
| 422 | * @return string |
||
| 423 | */ |
||
| 424 | public static function formControlSource(Tree $tree, Source $source = null, array $attributes = []) { |
||
| 425 | $value = ''; |
||
| 426 | $options = ['' => '']; |
||
| 427 | |||
| 428 | if ($source !== null) { |
||
| 429 | $value = $source->getXref(); |
||
| 430 | $options = [$value => view('selects/source', ['source' => $source])]; |
||
| 431 | } |
||
| 432 | |||
| 433 | return Bootstrap4::select($options, $value, Select2::sourceConfig($tree) + $attributes); |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Create a form control to select a submitter. |
||
| 438 | * |
||
| 439 | * @param Tree $tree |
||
| 440 | * @param GedcomRecord|null $submitter |
||
| 441 | * @param string[] $attributes |
||
| 442 | * |
||
| 443 | * @return string |
||
| 444 | */ |
||
| 445 | public static function formControlSubmitter(Tree $tree, GedcomRecord $submitter = null, array $attributes = []) { |
||
| 446 | $value = ''; |
||
| 447 | $options = ['' => '']; |
||
| 448 | |||
| 449 | if ($submitter !== null) { |
||
| 450 | $value = $submitter->getXref(); |
||
| 451 | $options = [$value => view('selects/submitter', ['submitter' => $submitter])]; |
||
| 452 | } |
||
| 453 | |||
| 454 | return Bootstrap4::select($options, $value, Select2::submitterConfig($tree) + $attributes); |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Remove all links from $gedrec to $xref, and any sub-tags. |
||
| 459 | * |
||
| 460 | * @param string $gedrec |
||
| 461 | * @param string $xref |
||
| 462 | * |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | public static function removeLinks($gedrec, $xref) { |
||
| 466 | $gedrec = preg_replace('/\n1 ' . WT_REGEX_TAG . ' @' . $xref . '@(\n[2-9].*)*/', '', $gedrec); |
||
| 467 | $gedrec = preg_replace('/\n2 ' . WT_REGEX_TAG . ' @' . $xref . '@(\n[3-9].*)*/', '', $gedrec); |
||
| 468 | $gedrec = preg_replace('/\n3 ' . WT_REGEX_TAG . ' @' . $xref . '@(\n[4-9].*)*/', '', $gedrec); |
||
| 469 | $gedrec = preg_replace('/\n4 ' . WT_REGEX_TAG . ' @' . $xref . '@(\n[5-9].*)*/', '', $gedrec); |
||
| 470 | $gedrec = preg_replace('/\n5 ' . WT_REGEX_TAG . ' @' . $xref . '@(\n[6-9].*)*/', '', $gedrec); |
||
| 471 | |||
| 472 | return $gedrec; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Input addon to generate a calendar widget. |
||
| 477 | * |
||
| 478 | * @param string $id |
||
| 479 | * |
||
| 480 | * @return string |
||
| 481 | */ |
||
| 482 | public static function inputAddonCalendar($id) { |
||
| 483 | return |
||
| 484 | '<div class="input-group-append">' . |
||
| 485 | '<span class="input-group-text">' . |
||
| 486 | FontAwesome::linkIcon('calendar', I18N::translate('Select a date'), ['href' => '#', 'onclick' => 'return calendarWidget("caldiv' . $id . '", "' . $id . '");']) . |
||
| 487 | '</span>' . |
||
| 488 | '</div>'; |
||
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Input addon to select a special characterr using a virtual keyboard |
||
| 493 | * |
||
| 494 | * @param string $id |
||
| 495 | * |
||
| 496 | * @return string |
||
| 497 | */ |
||
| 498 | public static function inputAddonKeyboard($id) { |
||
| 505 | } |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Input addon to generate a help link. |
||
| 509 | * |
||
| 510 | * @param string $fact |
||
| 511 | * |
||
| 512 | * @return string |
||
| 513 | */ |
||
| 514 | public static function inputAddonHelp($fact) { |
||
| 515 | return |
||
| 516 | '<div class="input-group-append">' . |
||
| 517 | '<span class="input-group-text">' . |
||
| 518 | FunctionsPrint::helpLink($fact) . |
||
| 519 | '</span>' . |
||
| 520 | '</div>'; |
||
| 521 | } |
||
| 522 | |||
| 523 | /** |
||
| 524 | * add a new tag input field |
||
| 525 | * |
||
| 526 | * called for each fact to be edited on a form. |
||
| 527 | * Fact level=0 means a new empty form : data are POSTed by name |
||
| 528 | * else data are POSTed using arrays : |
||
| 529 | * glevels[] : tag level |
||
| 530 | * islink[] : tag is a link |
||
| 531 | * tag[] : tag name |
||
| 532 | * text[] : tag value |
||
| 533 | * |
||
| 534 | * @param string $tag fact record to edit (eg 2 DATE xxxxx) |
||
| 535 | * @param string $upperlevel optional upper level tag (eg BIRT) |
||
| 536 | * @param string $label An optional label to echo instead of the default |
||
| 537 | * @param string $extra optional text to display after the input field |
||
| 538 | * @param Individual $person For male/female translations |
||
| 539 | * |
||
| 540 | * @return string |
||
| 541 | */ |
||
| 542 | public static function addSimpleTag($tag, $upperlevel = '', $label = '', $extra = null, Individual $person = null) { |
||
| 543 | global $tags, $xref, $bdm, $action, $WT_TREE; |
||
|
|
|||
| 544 | |||
| 545 | // Some form fields need access to previous form fields. |
||
| 546 | static $previous_ids = ['SOUR' => '', 'PLAC' => '']; |
||
| 547 | |||
| 548 | preg_match('/^(?:(\d+) (' . WT_REGEX_TAG . ') ?(.*))/', $tag, $match); |
||
| 549 | list(, $level, $fact, $value) = $match; |
||
| 550 | |||
| 551 | if ($level === '0') { |
||
| 552 | if ($upperlevel) { |
||
| 553 | $name = $upperlevel . '_' . $fact; |
||
| 554 | } else { |
||
| 555 | $name = $fact; |
||
| 556 | } |
||
| 557 | } else { |
||
| 558 | $name = 'text[]'; |
||
| 559 | } |
||
| 560 | |||
| 561 | if ($level === '0') { |
||
| 562 | $id = $fact; |
||
| 563 | } else { |
||
| 564 | $id = $fact . Uuid::uuid4(); |
||
| 565 | } |
||
| 566 | if ($upperlevel) { |
||
| 567 | $id = $upperlevel . '_' . $fact . Uuid::uuid4(); |
||
| 568 | } |
||
| 569 | |||
| 570 | $previous_ids[$fact] = $id; |
||
| 571 | |||
| 572 | // field value |
||
| 573 | $islink = (substr($value, 0, 1) === '@' && substr($value, 0, 2) !== '@#'); |
||
| 574 | if ($islink) { |
||
| 575 | $value = trim($value, '@'); |
||
| 576 | } else { |
||
| 577 | $value = (string) substr($tag, strlen($fact) + 3); |
||
| 578 | } |
||
| 579 | if ($fact === 'REPO' || $fact === 'SOUR' || $fact === 'OBJE' || $fact === 'FAMC') { |
||
| 580 | $islink = true; |
||
| 581 | } |
||
| 582 | |||
| 583 | if ($fact === 'SHARED_NOTE_EDIT' || $fact === 'SHARED_NOTE') { |
||
| 584 | $islink = true; |
||
| 585 | $fact = 'NOTE'; |
||
| 586 | } |
||
| 587 | |||
| 588 | $row_class = 'form-group row'; |
||
| 589 | switch ($fact) { |
||
| 590 | case 'DATA': |
||
| 591 | case 'MAP': |
||
| 592 | // These GEDCOM tags should have no data, just child tags. |
||
| 593 | if ($value === '') { |
||
| 594 | $row_class .= ' d-none'; |
||
| 595 | } |
||
| 596 | break; |
||
| 597 | case 'LATI': |
||
| 598 | case 'LONG': |
||
| 599 | // Indicate that this row is a child of a previous row, so we can expand/collapse them. |
||
| 600 | $row_class .= ' child_of_' . $previous_ids['PLAC']; |
||
| 601 | if ($value === '') { |
||
| 602 | $row_class .= ' collapse'; |
||
| 603 | } |
||
| 604 | break; |
||
| 605 | } |
||
| 606 | |||
| 607 | $html = ''; |
||
| 608 | $html .= '<div class="' . $row_class . '">'; |
||
| 609 | $html .= '<label class="col-sm-3 col-form-label" for="' . $id . '">'; |
||
| 610 | |||
| 611 | // tag name |
||
| 612 | if ($label) { |
||
| 613 | $html .= $label; |
||
| 614 | } elseif ($upperlevel) { |
||
| 615 | $html .= GedcomTag::getLabel($upperlevel . ':' . $fact); |
||
| 616 | } else { |
||
| 617 | $html .= GedcomTag::getLabel($fact); |
||
| 618 | } |
||
| 619 | |||
| 620 | // If using GEDFact-assistant window |
||
| 621 | if ($action === 'addnewnote_assisted') { |
||
| 622 | // Do not print on GEDFact Assistant window |
||
| 623 | } else { |
||
| 624 | // Not all facts have help text. |
||
| 625 | switch ($fact) { |
||
| 626 | case 'NAME': |
||
| 627 | if ($upperlevel !== 'REPO' && $upperlevel !== 'UNKNOWN') { |
||
| 628 | $html .= FunctionsPrint::helpLink($fact); |
||
| 629 | } |
||
| 630 | break; |
||
| 631 | case 'ROMN': |
||
| 632 | case 'SURN': |
||
| 633 | case '_HEB': |
||
| 634 | $html .= FunctionsPrint::helpLink($fact); |
||
| 635 | break; |
||
| 636 | } |
||
| 637 | } |
||
| 638 | // tag level |
||
| 639 | if ($level !== '0') { |
||
| 640 | $html .= '<input type="hidden" name="glevels[]" value="' . $level . '">'; |
||
| 641 | $html .= '<input type="hidden" name="islink[]" value="' . $islink . '">'; |
||
| 642 | $html .= '<input type="hidden" name="tag[]" value="' . $fact . '">'; |
||
| 643 | } |
||
| 644 | $html .= '</label>'; |
||
| 645 | |||
| 646 | // value |
||
| 647 | $html .= '<div class="col-sm-9">'; |
||
| 648 | |||
| 649 | // Show names for spouses in MARR/HUSB/AGE and MARR/WIFE/AGE |
||
| 650 | if ($fact === 'HUSB' || $fact === 'WIFE') { |
||
| 651 | $family = Family::getInstance($xref, $WT_TREE); |
||
| 652 | if ($family) { |
||
| 653 | $spouse_link = $family->getFirstFact($fact); |
||
| 654 | if ($spouse_link) { |
||
| 655 | $spouse = $spouse_link->getTarget(); |
||
| 656 | if ($spouse) { |
||
| 657 | $html .= $spouse->getFullName(); |
||
| 658 | } |
||
| 659 | } |
||
| 660 | } |
||
| 661 | } |
||
| 662 | |||
| 663 | if (in_array($fact, Config::emptyFacts()) && ($value === '' || $value === 'Y' || $value === 'y')) { |
||
| 664 | $html .= '<input type="hidden" id="' . $id . '" name="' . $name . '" value="' . $value . '">'; |
||
| 665 | |||
| 666 | if ($fact === 'CENS' && $value === 'Y') { |
||
| 667 | $html .= self::censusDateSelector(WT_LOCALE, $xref); |
||
| 668 | |||
| 669 | /** @var CensusAssistantModule $census_assistant */ |
||
| 670 | $census_assistant = Module::getModuleByName('GEDFact_assistant'); |
||
| 671 | $record = Individual::getInstance($xref, $WT_TREE); |
||
| 672 | if ($census_assistant !== null && $record instanceof Individual) { |
||
| 673 | $html .= $census_assistant->createCensusAssistant($record); |
||
| 674 | } |
||
| 675 | } |
||
| 676 | } elseif ($fact === 'NPFX' || $fact === 'NSFX' || $fact === 'SPFX' || $fact === 'NICK') { |
||
| 677 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" oninput="updatewholename()">'; |
||
| 678 | } elseif ($fact === 'GIVN') { |
||
| 679 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" data-autocomplete-type="GIVN" oninput="updatewholename()" autofocus>'; |
||
| 680 | } elseif ($fact === 'SURN' || $fact === '_MARNM_SURN') { |
||
| 681 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" data-autocomplete-type="SURN" oninput="updatewholename()">'; |
||
| 682 | } elseif ($fact === 'ADOP') { |
||
| 683 | $html .= Bootstrap4::select(GedcomCodeAdop::getValues($person), $value, ['id' => $id, 'name' => $name]); |
||
| 684 | } elseif ($fact === 'ALIA') { |
||
| 685 | $html .= self::formControlIndividual($WT_TREE, Individual::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]); |
||
| 686 | } elseif ($fact === 'ASSO' || $fact === '_ASSO') { |
||
| 687 | $html .= |
||
| 688 | '<div class="input-group">' . |
||
| 689 | '<span class="input-group-btn"><button class="btn btn-secondary" type="button" onclick="createNewRecord(' . $id . ')" title="' . I18N::translate('Create an individual') . '"><i class="fas fa-plus"></i></button></span>' . |
||
| 690 | self::formControlIndividual($WT_TREE, Individual::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 691 | '</div>'; |
||
| 692 | if ($level === '1') { |
||
| 693 | $html .= '<p class="small text-muted">' . I18N::translate('An associate is another individual who was involved with this individual, such as a friend or an employer.') . '</p>'; |
||
| 694 | } else { |
||
| 695 | $html .= '<p class="small text-muted">' . I18N::translate('An associate is another individual who was involved with this fact or event, such as a witness or a priest.') . '</p>'; |
||
| 696 | } |
||
| 697 | } elseif ($fact === 'DATE') { |
||
| 698 | $html .= '<div class="input-group">'; |
||
| 699 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" onchange="valid_date(this)" dir="ltr">'; |
||
| 700 | $html .= self::inputAddonCalendar($id); |
||
| 701 | $html .= self::inputAddonHelp('DATE'); |
||
| 702 | $html .= '</div>'; |
||
| 703 | $html .= '<div id="caldiv' . $id . '" style="position:absolute;visibility:hidden;background-color:white;z-index:1000"></div>'; |
||
| 704 | $html .= '<p class="text-muted">' . (new Date($value))->display() . '</p>'; |
||
| 705 | } elseif ($fact === 'FAMC') { |
||
| 706 | $html .= |
||
| 707 | '<div class="input-group">' . |
||
| 708 | '<span class="input-group-btn"><button class="btn btn-secondary" type="button" data-toggle="modal" data-target="#modal-create-family" data-element-id="' . $id . '" title="' . I18N::translate('Create a family') . '"><i class="fas fa-plus"></i></button></span>' . |
||
| 709 | self::formControlFamily($WT_TREE, Family::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 710 | '</div>'; |
||
| 711 | } elseif ($fact === 'LATI') { |
||
| 712 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" oninput="valid_lati_long(this, \'N\', \'S\')">'; |
||
| 713 | } elseif ($fact === 'LONG') { |
||
| 714 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" oninput="valid_lati_long(this, \'E\', \'W\')">'; |
||
| 715 | } elseif ($fact === 'NOTE' && $islink) { |
||
| 716 | $html .= |
||
| 717 | '<div class="input-group">' . |
||
| 718 | '<span class="input-group-btn">' . |
||
| 719 | '<button class="btn btn-secondary" type="button" data-toggle="modal" data-target="#wt-ajax-modal" data-href="' . e(route('create-note-object', ['tree' => $WT_TREE->getName()])) . '" data-select-id="' . $id . '" title="' . I18N::translate('Create a shared note') . '">' . |
||
| 720 | '<i class="fas fa-plus"></i><' . |
||
| 721 | '/button>' . |
||
| 722 | '</span>' . |
||
| 723 | self::formControlNote($WT_TREE, Note::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 724 | '</div>'; |
||
| 725 | } elseif ($fact === 'OBJE') { |
||
| 726 | $html .= |
||
| 727 | '<div class="input-group">' . |
||
| 728 | '<span class="input-group-btn"><button class="btn btn-secondary" type="button" data-toggle="modal" data-href="' . e(route('create-media-object', ['tree' => $WT_TREE->getName()])) . '" data-target="#wt-ajax-modal" data-select-id="' . $id . '" title="' . I18N::translate('Create a media object') . '"><i class="fas fa-plus"></i></button></span>' . |
||
| 729 | self::formControlMediaObject($WT_TREE, Media::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 730 | '</div>'; |
||
| 731 | } elseif ($fact === 'PAGE') { |
||
| 732 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" data-autocomplete-type="PAGE" data-autocomplete-extra="#' . $previous_ids['SOUR'] . '">'; |
||
| 733 | } elseif ($fact === 'PEDI') { |
||
| 734 | $html .= Bootstrap4::select(GedcomCodePedi::getValues($person), $value, ['id' => $id, 'name' => $name]); |
||
| 735 | } elseif ($fact === 'PLAC') { |
||
| 736 | $html .= '<input ' . Html::attributes([ |
||
| 737 | 'autocomplete' => 'off', |
||
| 738 | 'class' => 'form-control', |
||
| 739 | 'id' => $id, |
||
| 740 | 'name' => $name, |
||
| 741 | 'value' => $value, |
||
| 742 | 'type' => 'text', |
||
| 743 | 'data-autocomplete-url' => route('autocomplete-place', [ |
||
| 744 | 'ged' => $WT_TREE->getName(), |
||
| 745 | 'query' => 'QUERY', |
||
| 746 | ]), |
||
| 747 | ]) . '>'; |
||
| 748 | |||
| 749 | /** @TODO - typeaheadjs.css doesn't work in an input-group */ |
||
| 750 | $html .= '<div class="input-group">'; |
||
| 751 | $html .= '<div class="input-group-append"><span class="input-group-text">' . FontAwesome::linkIcon('coordinates', I18N::translate('Latitude') . ' / ' . I18N::translate('Longitude'), ['data-toggle' => 'collapse', 'data-target' => '.child_of_' . $id]) . '</span></div>'; |
||
| 752 | $html .= self::inputAddonHelp('PLAC'); |
||
| 753 | $html .= '</div>'; |
||
| 754 | if (Module::getModuleByName('places_assistant')) { |
||
| 755 | \PlacesAssistantModule::setup_place_subfields($id); |
||
| 756 | \PlacesAssistantModule::print_place_subfields($id); |
||
| 757 | } |
||
| 758 | } elseif ($fact === 'QUAY') { |
||
| 759 | $html .= Bootstrap4::select(GedcomCodeQuay::getValues(), $value, ['id' => $id, 'name' => $name]); |
||
| 760 | } elseif ($fact === 'RELA') { |
||
| 761 | $html .= Bootstrap4::select(FunctionsEdit::optionsRelationships($value), $value, ['id' => $id, 'name' => $name]); |
||
| 762 | } elseif ($fact === 'REPO') { |
||
| 763 | $html .= |
||
| 764 | '<div class="input-group">' . |
||
| 765 | '<span class="input-group-btn"><button class="btn btn-secondary" type="button" data-toggle="modal" data-href="' . e(route('create-repository', ['tree' => $WT_TREE->getName()])) . '" data-target="#wt-ajax-modal" data-select-id="' . $id . '" title="' . I18N::translate('Create a repository') . '"><i class="fas fa-plus"></i></button></span>' . |
||
| 766 | self::formControlRepository($WT_TREE, Repository::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 767 | '</div>'; |
||
| 768 | } elseif ($fact === 'RESN') { |
||
| 769 | $html .= '<div class="input-group">'; |
||
| 770 | $html .= Bootstrap4::select(FunctionsEdit::optionsRestrictions(true), $value, ['id' => $id, 'name' => $name]); |
||
| 771 | $html .= self::inputAddonHelp('RESN'); |
||
| 772 | $html .= '</span>'; |
||
| 773 | $html .= '</div>'; |
||
| 774 | } elseif ($fact === 'SEX') { |
||
| 775 | if ($value !== 'M' && $value !== 'F') { |
||
| 776 | $value = 'U'; |
||
| 777 | } |
||
| 778 | $html .= Bootstrap4::radioButtons($name, ['M' => I18N::translate('Male'), 'F' => I18N::translate('Female'), 'U' => I18N::translateContext('unknown gender', 'Unknown')], $value, true); |
||
| 779 | } elseif ($fact === 'SOUR') { |
||
| 780 | $html .= |
||
| 781 | '<div class="input-group">' . |
||
| 782 | '<span class="input-group-btn"><button class="btn btn-secondary" type="button" data-toggle="modal" data-href="' . e(route('create-source', ['tree' => $WT_TREE->getName()])) . '" data-target="#wt-ajax-modal" data-select-id="' . $id . '" title="' . I18N::translate('Create a source') . '"><i class="fas fa-plus"></i></button></span>' . |
||
| 783 | self::formControlSource($WT_TREE, Source::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 784 | '</div>'; |
||
| 785 | } elseif ($fact === 'STAT') { |
||
| 786 | $html .= Bootstrap4::select(GedcomCodeStat::statusNames($upperlevel), $value); |
||
| 787 | } elseif ($fact === 'SUBM') { |
||
| 788 | $html .= |
||
| 789 | '<div class="input-group">' . |
||
| 790 | '<span class="input-group-btn"><button class="btn btn-secondary" type="button" data-toggle="modal" data-href="' . e(route('create-submitter', ['tree' => $WT_TREE->getName()])) . '" data-target="#wt-ajax-modal" data-select-id="' . $id . '" title="' . I18N::translate('Create a submitter') . '"><i class="fas fa-plus"></i></button></span>' . |
||
| 791 | self::formControlSubmitter($WT_TREE, GedcomRecord::getInstance($value, $WT_TREE), ['id' => $id, 'name' => $name]) . |
||
| 792 | '</div>'; |
||
| 793 | } elseif ($fact === 'TEMP') { |
||
| 794 | $html .= Bootstrap4::select(FunctionsEdit::optionsTemples(), $value, ['id' => $id, 'name' => $name]); |
||
| 795 | } elseif ($fact === 'TIME') { |
||
| 796 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" pattern="([0-1][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?" dir="ltr" placeholder="' . /* I18N: Examples of valid time formats (hours:minutes:seconds) */ I18N::translate('hh:mm or hh:mm:ss') . '">'; |
||
| 797 | } elseif ($fact === '_WT_USER') { |
||
| 798 | $html .= Bootstrap4::select(FunctionsEdit::optionsUsers(), $value, ['id' => $id, 'name' => $name]); |
||
| 799 | } elseif ($fact === '_PRIM') { |
||
| 800 | $html .= Bootstrap4::select(['' => '', 'Y' => I18N::translate('always'), 'N' => I18N::translate('never')], $value, ['id' => $id, 'name' => $name]); |
||
| 801 | $html .= '<p class="small text-muted">' . I18N::translate('Use this image for charts and on the individual’s page.') . '</p>'; |
||
| 802 | } elseif ($fact === 'TYPE' && $level === '3') { |
||
| 803 | //-- Build the selector for the Media 'TYPE' Fact |
||
| 804 | $html .= '<select name="text[]"><option selected value="" ></option>'; |
||
| 805 | $selectedValue = strtolower($value); |
||
| 806 | if (!array_key_exists($selectedValue, GedcomTag::getFileFormTypes())) { |
||
| 807 | $html .= '<option selected value="' . e($value) . '" >' . e($value) . '</option>'; |
||
| 808 | } |
||
| 809 | foreach (['' => ''] + GedcomTag::getFileFormTypes() + [] as $typeName => $typeValue) { |
||
| 810 | $html .= '<option value="' . $typeName . '" '; |
||
| 811 | if ($selectedValue === $typeName) { |
||
| 812 | $html .= 'selected'; |
||
| 813 | } |
||
| 814 | $html .= '>' . $typeValue . '</option>'; |
||
| 815 | } |
||
| 816 | $html .= '</select>'; |
||
| 817 | } elseif (($fact !== 'NAME' || $upperlevel === 'REPO' || $upperlevel === 'UNKNOWN') && $fact !== '_MARNM') { |
||
| 818 | if ($fact === 'TEXT' || $fact === 'ADDR' || ($fact === 'NOTE' && !$islink)) { |
||
| 819 | $html .= '<div class="input-group">'; |
||
| 820 | $html .= '<textarea class="form-control" id="' . $id . '" name="' . $name . '" dir="auto">' . e($value) . '</textarea>'; |
||
| 821 | $html .= '</div>'; |
||
| 822 | } else { |
||
| 823 | // If using GEDFact-assistant window |
||
| 824 | $html .= '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '">'; |
||
| 825 | } |
||
| 826 | } else { |
||
| 827 | // Populated in javascript from sub-tags |
||
| 828 | $html .= '<input type="hidden" id="' . $id . '" name="' . $name . '" oninput="updateTextName(\'' . $id . '\')" value="' . e($value) . '" class="' . $fact . '">'; |
||
| 829 | $html .= '<span id="' . $id . '_display" dir="auto">' . e($value) . '</span>'; |
||
| 830 | $html .= ' <a href="#edit_name" onclick="convertHidden(\'' . $id . '\'); return false" class="icon-edit_indi" title="' . I18N::translate('Edit the name') . '"></a>'; |
||
| 831 | } |
||
| 832 | // MARRiage TYPE : hide text field and show a selection list |
||
| 833 | if ($fact === 'TYPE' && $level === '2' && $tags[0] === 'MARR') { |
||
| 834 | $html .= '<script>'; |
||
| 835 | $html .= 'document.getElementById(\'' . $id . '\').style.display=\'none\''; |
||
| 836 | $html .= '</script>'; |
||
| 837 | $html .= '<select id="' . $id . '_sel" oninput="document.getElementById(\'' . $id . '\').value=this.value" >'; |
||
| 838 | foreach (['Unknown', 'Civil', 'Religious', 'Partners'] as $key) { |
||
| 839 | if ($key === 'Unknown') { |
||
| 840 | $html .= '<option value="" '; |
||
| 841 | } else { |
||
| 842 | $html .= '<option value="' . $key . '" '; |
||
| 843 | } |
||
| 844 | $a = strtolower($key); |
||
| 845 | $b = strtolower($value); |
||
| 846 | if ($b !== '' && strpos($a, $b) !== false || strpos($b, $a) !== false) { |
||
| 847 | $html .= 'selected'; |
||
| 848 | } |
||
| 849 | $html .= '>' . GedcomTag::getLabel('MARR_' . strtoupper($key)) . '</option>'; |
||
| 850 | } |
||
| 851 | $html .= '</select>'; |
||
| 852 | } elseif ($fact === 'TYPE' && $level === '0') { |
||
| 853 | // NAME TYPE : hide text field and show a selection list |
||
| 854 | $html .= Bootstrap4::select(GedcomCodeName::getValues($person), $value, ['id' => $id, 'name' => $name, 'oninput' => 'document.getElementById(\'' . $id . '\').value=this.value"']); |
||
| 855 | $html .= '<script>document.getElementById("' . $id . '").style.display="none";</script>'; |
||
| 856 | } |
||
| 857 | |||
| 858 | // popup links |
||
| 859 | switch ($fact) { |
||
| 860 | case 'SOUR': |
||
| 861 | //-- checkboxes to apply '1 SOUR' to BIRT/MARR/DEAT as '2 SOUR' |
||
| 862 | if ($level === '1') { |
||
| 863 | $html .= '<br>'; |
||
| 864 | switch ($WT_TREE->getPreference('PREFER_LEVEL2_SOURCES')) { |
||
| 865 | case '2': // records |
||
| 866 | $level1_checked = 'checked'; |
||
| 867 | $level2_checked = ''; |
||
| 868 | break; |
||
| 869 | case '1': // facts |
||
| 870 | $level1_checked = ''; |
||
| 871 | $level2_checked = 'checked'; |
||
| 872 | break; |
||
| 873 | case '0': // none |
||
| 874 | default: |
||
| 875 | $level1_checked = ''; |
||
| 876 | $level2_checked = ''; |
||
| 877 | break; |
||
| 878 | } |
||
| 879 | if (strpos($bdm, 'B') !== false) { |
||
| 880 | $html .= ' <label><input type="checkbox" name="SOUR_INDI" ' . $level1_checked . ' value="1">' . I18N::translate('Individual') . '</label>'; |
||
| 881 | if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $WT_TREE->getPreference('QUICK_REQUIRED_FACTS'), $matches)) { |
||
| 882 | foreach ($matches[1] as $match) { |
||
| 883 | if (!in_array($match, explode('|', WT_EVENTS_DEAT))) { |
||
| 884 | $html .= ' <label><input type="checkbox" name="SOUR_' . $match . '" ' . $level2_checked . ' value="1">' . GedcomTag::getLabel($match) . '</label>'; |
||
| 885 | } |
||
| 886 | } |
||
| 887 | } |
||
| 888 | } |
||
| 889 | if (strpos($bdm, 'D') !== false) { |
||
| 890 | if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $WT_TREE->getPreference('QUICK_REQUIRED_FACTS'), $matches)) { |
||
| 891 | foreach ($matches[1] as $match) { |
||
| 892 | if (in_array($match, explode('|', WT_EVENTS_DEAT))) { |
||
| 893 | $html .= ' <label><input type="checkbox" name="SOUR_' . $match . '"' . $level2_checked . ' value="1">' . GedcomTag::getLabel($match) . '</label>'; |
||
| 894 | } |
||
| 895 | } |
||
| 896 | } |
||
| 897 | } |
||
| 898 | if (strpos($bdm, 'M') !== false) { |
||
| 899 | $html .= ' <label><input type="checkbox" name="SOUR_FAM" ' . $level1_checked . ' value="1">' . I18N::translate('Family') . '</label>'; |
||
| 900 | if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $WT_TREE->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) { |
||
| 901 | foreach ($matches[1] as $match) { |
||
| 902 | $html .= ' <label><input type="checkbox" name="SOUR_' . $match . '"' . $level2_checked . ' value="1">' . GedcomTag::getLabel($match) . '</label>'; |
||
| 903 | } |
||
| 904 | } |
||
| 905 | } |
||
| 906 | } |
||
| 907 | break; |
||
| 908 | } |
||
| 909 | |||
| 910 | $html .= $extra . '</div></div>'; |
||
| 911 | |||
| 912 | return $html; |
||
| 913 | } |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Genearate a <select> element, with the dates/places of all known censuses |
||
| 917 | * |
||
| 918 | * |
||
| 919 | * @param string $locale Sort the censuses for this locale |
||
| 920 | * @param string $xref The individual for whom we are adding a census |
||
| 921 | * |
||
| 922 | * @return string |
||
| 923 | */ |
||
| 924 | public static function censusDateSelector($locale, $xref) { |
||
| 925 | global $controller; |
||
| 926 | |||
| 927 | // Show more likely census details at the top of the list. |
||
| 928 | switch ($locale) { |
||
| 929 | case 'cs': |
||
| 930 | $census_places = [new CensusOfCzechRepublic]; |
||
| 931 | break; |
||
| 932 | case 'en-AU': |
||
| 933 | case 'en-GB': |
||
| 934 | $census_places = [new CensusOfEngland, new CensusOfWales, new CensusOfScotland]; |
||
| 935 | break; |
||
| 936 | case 'en-US': |
||
| 937 | $census_places = [new CensusOfUnitedStates]; |
||
| 938 | break; |
||
| 939 | case 'fr': |
||
| 940 | case 'fr-CA': |
||
| 941 | $census_places = [new CensusOfFrance]; |
||
| 942 | break; |
||
| 943 | case 'da': |
||
| 944 | $census_places = [new CensusOfDenmark]; |
||
| 945 | break; |
||
| 946 | case 'de': |
||
| 947 | $census_places = [new CensusOfDeutschland]; |
||
| 948 | break; |
||
| 949 | default: |
||
| 950 | $census_places = []; |
||
| 951 | break; |
||
| 952 | } |
||
| 953 | foreach (Census::allCensusPlaces() as $census_place) { |
||
| 954 | if (!in_array($census_place, $census_places)) { |
||
| 955 | $census_places[] = $census_place; |
||
| 956 | } |
||
| 957 | } |
||
| 958 | |||
| 959 | $controller->addInlineJavascript(' |
||
| 960 | function selectCensus(el) { |
||
| 961 | var option = $(":selected", el); |
||
| 962 | $("input[id^=CENS_DATE]", $(el).closest("form")).val(option.val()); |
||
| 963 | //$("input[id^=CENS_PLAC]", $(el).closest("form")).val(option.data("place")); |
||
| 964 | var place = option.data("place"); |
||
| 965 | $("select[id^=CENS_PLAC]", $(el).closest("form")).select2().empty().append(new Option(place, place)).val(place).trigger("change"); |
||
| 966 | |||
| 967 | $("input.census-class", $(el).closest("form")).val(option.data("census")); |
||
| 968 | } |
||
| 969 | '); |
||
| 970 | |||
| 971 | $options = '<option value="">' . I18N::translate('Census date') . '</option>'; |
||
| 972 | |||
| 973 | foreach ($census_places as $census_place) { |
||
| 974 | $options .= '<option value=""></option>'; |
||
| 975 | foreach ($census_place->allCensusDates() as $census) { |
||
| 976 | $date = new Date($census->censusDate()); |
||
| 977 | $year = $date->minimumDate()->format('%Y'); |
||
| 978 | $place_hierarchy = explode(', ', $census->censusPlace()); |
||
| 979 | $options .= '<option value="' . $census->censusDate() . '" data-place="' . $census->censusPlace() . '" data-census="' . get_class($census) . '">' . $place_hierarchy[0] . ' ' . $year . '</option>'; |
||
| 980 | } |
||
| 981 | } |
||
| 982 | |||
| 983 | return |
||
| 984 | '<select id="census-selector" class="form-control" onchange="selectCensus(this)">' . $options . '</select>'; |
||
| 985 | } |
||
| 986 | |||
| 987 | /** |
||
| 988 | * Prints collapsable fields to add ASSO/RELA, SOUR, OBJE, etc. |
||
| 989 | * |
||
| 990 | * @param string $tag |
||
| 991 | * @param int $level |
||
| 992 | * @param string $parent_tag |
||
| 993 | */ |
||
| 994 | public static function printAddLayer($tag, $level = 2, $parent_tag = '') { |
||
| 995 | global $WT_TREE; |
||
| 996 | |||
| 997 | switch ($tag) { |
||
| 998 | case 'SOUR': |
||
| 999 | echo view('cards/add-source-citation', [ |
||
| 1000 | 'level' => $level, |
||
| 1001 | 'full_citations' => $WT_TREE->getPreference('FULL_SOURCES'), |
||
| 1002 | ]); |
||
| 1003 | break; |
||
| 1004 | |||
| 1005 | case 'ASSO': |
||
| 1006 | case 'ASSO2': |
||
| 1007 | echo view('cards/add-associate', [ |
||
| 1008 | 'level' => $level, |
||
| 1009 | ]); |
||
| 1010 | break; |
||
| 1011 | |||
| 1012 | case 'NOTE': |
||
| 1013 | echo view('cards/add-note', [ |
||
| 1014 | 'level' => $level, |
||
| 1015 | ]); |
||
| 1016 | break; |
||
| 1017 | |||
| 1018 | case 'SHARED_NOTE': |
||
| 1019 | echo view('cards/add-shared-note', [ |
||
| 1020 | 'level' => $level, |
||
| 1021 | 'parent_tag' => $parent_tag, |
||
| 1022 | ]); |
||
| 1023 | break; |
||
| 1024 | |||
| 1025 | case 'OBJE': |
||
| 1026 | if ($WT_TREE->getPreference('MEDIA_UPLOAD') >= Auth::accessLevel($WT_TREE)) { |
||
| 1027 | echo view('cards/add-media-object', [ |
||
| 1028 | 'level' => $level, |
||
| 1029 | ]); |
||
| 1030 | } |
||
| 1031 | break; |
||
| 1032 | |||
| 1033 | case 'RESN': |
||
| 1034 | echo view('cards/add-restriction', [ |
||
| 1035 | 'level' => $level, |
||
| 1036 | ]); |
||
| 1037 | break; |
||
| 1038 | } |
||
| 1039 | } |
||
| 1040 | |||
| 1041 | /** |
||
| 1042 | * Add some empty tags to create a new fact. |
||
| 1043 | * |
||
| 1044 | * @param string $fact |
||
| 1045 | */ |
||
| 1046 | public static function addSimpleTags($fact) { |
||
| 1072 | } |
||
| 1073 | } |
||
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Assemble the pieces of a newly created record into gedcom |
||
| 1077 | * |
||
| 1078 | * @return string |
||
| 1079 | */ |
||
| 1080 | public static function addNewName() { |
||
| 1081 | global $WT_TREE; |
||
| 1082 | |||
| 1083 | $gedrec = "\n1 NAME " . Filter::post('NAME'); |
||
| 1084 | |||
| 1085 | $tags = ['NPFX', 'GIVN', 'SPFX', 'SURN', 'NSFX']; |
||
| 1086 | |||
| 1087 | if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $WT_TREE->getPreference('ADVANCED_NAME_FACTS'), $match)) { |
||
| 1088 | $tags = array_merge($tags, $match[1]); |
||
| 1089 | } |
||
| 1090 | |||
| 1091 | // Paternal and Polish and Lithuanian surname traditions can also create a _MARNM |
||
| 1092 | $SURNAME_TRADITION = $WT_TREE->getPreference('SURNAME_TRADITION'); |
||
| 1093 | if ($SURNAME_TRADITION === 'paternal' || $SURNAME_TRADITION === 'polish' || $SURNAME_TRADITION === 'lithuanian') { |
||
| 1094 | $tags[] = '_MARNM'; |
||
| 1095 | } |
||
| 1096 | |||
| 1097 | foreach (array_unique($tags) as $tag) { |
||
| 1098 | $TAG = Filter::post($tag); |
||
| 1099 | if ($TAG) { |
||
| 1100 | $gedrec .= "\n2 {$tag} {$TAG}"; |
||
| 1101 | } |
||
| 1102 | } |
||
| 1103 | |||
| 1104 | return $gedrec; |
||
| 1105 | } |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Create a form to add a sex record. |
||
| 1109 | * |
||
| 1110 | * @return string |
||
| 1111 | */ |
||
| 1112 | public static function addNewSex() { |
||
| 1113 | switch (Filter::post('SEX', '[MF]', 'U')) { |
||
| 1114 | case 'M': |
||
| 1115 | return "\n1 SEX M"; |
||
| 1116 | case 'F': |
||
| 1117 | return "\n1 SEX F"; |
||
| 1118 | default: |
||
| 1119 | return "\n1 SEX U"; |
||
| 1120 | } |
||
| 1121 | } |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Create a form to add a new fact. |
||
| 1125 | * |
||
| 1126 | * @param string $fact |
||
| 1127 | * |
||
| 1128 | * @return string |
||
| 1129 | */ |
||
| 1130 | public static function addNewFact($fact) { |
||
| 1131 | global $WT_TREE; |
||
| 1132 | |||
| 1133 | $FACT = Filter::post($fact); |
||
| 1134 | $DATE = Filter::post($fact . '_DATE'); |
||
| 1135 | $PLAC = Filter::post($fact . '_PLAC'); |
||
| 1136 | $PLAC = Filter::post($fact . '_RELI'); |
||
| 1137 | if ($DATE || $PLAC || $FACT && $FACT !== 'Y') { |
||
| 1138 | if ($FACT && $FACT !== 'Y') { |
||
| 1139 | $gedrec = "\n1 " . $fact . ' ' . $FACT; |
||
| 1140 | } else { |
||
| 1141 | $gedrec = "\n1 " . $fact; |
||
| 1142 | } |
||
| 1143 | if ($DATE) { |
||
| 1144 | $gedrec .= "\n2 DATE " . $DATE; |
||
| 1145 | } |
||
| 1146 | if ($PLAC) { |
||
| 1147 | $gedrec .= "\n2 PLAC " . $PLAC; |
||
| 1148 | |||
| 1149 | if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $WT_TREE->getPreference('ADVANCED_PLAC_FACTS'), $match)) { |
||
| 1150 | foreach ($match[1] as $tag) { |
||
| 1151 | $TAG = Filter::post($fact . '_' . $tag); |
||
| 1152 | if ($TAG) { |
||
| 1153 | $gedrec .= "\n3 " . $tag . ' ' . $TAG; |
||
| 1154 | } |
||
| 1155 | } |
||
| 1156 | } |
||
| 1157 | $LATI = Filter::post($fact . '_LATI'); |
||
| 1158 | $LONG = Filter::post($fact . '_LONG'); |
||
| 1159 | if ($LATI || $LONG) { |
||
| 1160 | $gedrec .= "\n3 MAP\n4 LATI " . $LATI . "\n4 LONG " . $LONG; |
||
| 1161 | } |
||
| 1162 | } |
||
| 1163 | if (Filter::postBool('SOUR_' . $fact)) { |
||
| 1164 | return self::updateSource($gedrec, 2); |
||
| 1165 | } else { |
||
| 1166 | return $gedrec; |
||
| 1167 | } |
||
| 1168 | } elseif ($FACT === 'Y') { |
||
| 1169 | if (Filter::postBool('SOUR_' . $fact)) { |
||
| 1170 | return self::updateSource("\n1 " . $fact . ' Y', 2); |
||
| 1171 | } else { |
||
| 1172 | return "\n1 " . $fact . ' Y'; |
||
| 1173 | } |
||
| 1174 | } else { |
||
| 1175 | return ''; |
||
| 1176 | } |
||
| 1177 | } |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * This function splits the $glevels, $tag, $islink, and $text arrays so that the |
||
| 1181 | * entries associated with a SOUR record are separate from everything else. |
||
| 1182 | * |
||
| 1183 | * Input arrays: |
||
| 1184 | * - $glevels[] - an array of the gedcom level for each line that was edited |
||
| 1185 | * - $tag[] - an array of the tags for each gedcom line that was edited |
||
| 1186 | * - $islink[] - an array of 1 or 0 values to indicate when the text is a link element |
||
| 1187 | * - $text[] - an array of the text data for each line |
||
| 1188 | * |
||
| 1189 | * Output arrays: |
||
| 1190 | * ** For the SOUR record: |
||
| 1191 | * - $glevelsSOUR[] - an array of the gedcom level for each line that was edited |
||
| 1192 | * - $tagSOUR[] - an array of the tags for each gedcom line that was edited |
||
| 1193 | * - $islinkSOUR[] - an array of 1 or 0 values to indicate when the text is a link element |
||
| 1194 | * - $textSOUR[] - an array of the text data for each line |
||
| 1195 | * ** For the remaining records: |
||
| 1196 | * - $glevelsRest[] - an array of the gedcom level for each line that was edited |
||
| 1197 | * - $tagRest[] - an array of the tags for each gedcom line that was edited |
||
| 1198 | * - $islinkRest[] - an array of 1 or 0 values to indicate when the text is a link element |
||
| 1199 | * - $textRest[] - an array of the text data for each line |
||
| 1200 | */ |
||
| 1201 | public static function splitSource() { |
||
| 1202 | global $glevels, $tag, $islink, $text; |
||
| 1203 | global $glevelsSOUR, $tagSOUR, $islinkSOUR, $textSOUR; |
||
| 1204 | global $glevelsRest, $tagRest, $islinkRest, $textRest; |
||
| 1205 | |||
| 1206 | $glevelsSOUR = []; |
||
| 1207 | $tagSOUR = []; |
||
| 1208 | $islinkSOUR = []; |
||
| 1209 | $textSOUR = []; |
||
| 1210 | |||
| 1211 | $glevelsRest = []; |
||
| 1212 | $tagRest = []; |
||
| 1213 | $islinkRest = []; |
||
| 1214 | $textRest = []; |
||
| 1215 | |||
| 1216 | $inSOUR = false; |
||
| 1217 | |||
| 1218 | for ($i = 0; $i < count($glevels); $i++) { |
||
| 1219 | if ($inSOUR) { |
||
| 1220 | if ($levelSOUR < $glevels[$i]) { |
||
| 1221 | $dest = 'S'; |
||
| 1222 | } else { |
||
| 1223 | $inSOUR = false; |
||
| 1224 | $dest = 'R'; |
||
| 1225 | } |
||
| 1226 | } else { |
||
| 1227 | if ($tag[$i] === 'SOUR') { |
||
| 1228 | $inSOUR = true; |
||
| 1229 | $levelSOUR = $glevels[$i]; |
||
| 1230 | $dest = 'S'; |
||
| 1231 | } else { |
||
| 1232 | $dest = 'R'; |
||
| 1233 | } |
||
| 1234 | } |
||
| 1235 | if ($dest === 'S') { |
||
| 1236 | $glevelsSOUR[] = $glevels[$i]; |
||
| 1237 | $tagSOUR[] = $tag[$i]; |
||
| 1238 | $islinkSOUR[] = $islink[$i]; |
||
| 1239 | $textSOUR[] = $text[$i]; |
||
| 1240 | } else { |
||
| 1241 | $glevelsRest[] = $glevels[$i]; |
||
| 1242 | $tagRest[] = $tag[$i]; |
||
| 1243 | $islinkRest[] = $islink[$i]; |
||
| 1244 | $textRest[] = $text[$i]; |
||
| 1245 | } |
||
| 1246 | } |
||
| 1247 | } |
||
| 1248 | |||
| 1249 | /** |
||
| 1250 | * Add new GEDCOM lines from the $xxxSOUR interface update arrays, which |
||
| 1251 | * were produced by the splitSOUR() function. |
||
| 1252 | * See the FunctionsEdit::handle_updatesges() function for details. |
||
| 1253 | * |
||
| 1254 | * @param string $inputRec |
||
| 1255 | * @param string $levelOverride |
||
| 1256 | * |
||
| 1257 | * @return string |
||
| 1258 | */ |
||
| 1259 | public static function updateSource($inputRec, $levelOverride = 'no') { |
||
| 1260 | global $glevels, $tag, $islink, $text; |
||
| 1261 | global $glevelsSOUR, $tagSOUR, $islinkSOUR, $textSOUR; |
||
| 1262 | |||
| 1263 | if (count($tagSOUR) === 0) { |
||
| 1264 | return $inputRec; // No update required |
||
| 1265 | } |
||
| 1266 | |||
| 1267 | // Save original interface update arrays before replacing them with the xxxSOUR ones |
||
| 1268 | $glevelsSave = $glevels; |
||
| 1269 | $tagSave = $tag; |
||
| 1270 | $islinkSave = $islink; |
||
| 1271 | $textSave = $text; |
||
| 1272 | |||
| 1273 | $glevels = $glevelsSOUR; |
||
| 1274 | $tag = $tagSOUR; |
||
| 1275 | $islink = $islinkSOUR; |
||
| 1276 | $text = $textSOUR; |
||
| 1277 | |||
| 1278 | $myRecord = self::handleUpdates($inputRec, $levelOverride); // Now do the update |
||
| 1279 | |||
| 1280 | // Restore the original interface update arrays (just in case ...) |
||
| 1281 | $glevels = $glevelsSave; |
||
| 1282 | $tag = $tagSave; |
||
| 1283 | $islink = $islinkSave; |
||
| 1284 | $text = $textSave; |
||
| 1285 | |||
| 1286 | return $myRecord; |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * Add new GEDCOM lines from the $xxxRest interface update arrays, which |
||
| 1291 | * were produced by the splitSOUR() function. |
||
| 1292 | * See the FunctionsEdit::handle_updatesges() function for details. |
||
| 1293 | * |
||
| 1294 | * @param string $inputRec |
||
| 1295 | * @param string $levelOverride |
||
| 1296 | * |
||
| 1297 | * @return string |
||
| 1298 | */ |
||
| 1299 | public static function updateRest($inputRec, $levelOverride = 'no') { |
||
| 1300 | global $glevels, $tag, $islink, $text; |
||
| 1301 | global $glevelsRest, $tagRest, $islinkRest, $textRest; |
||
| 1302 | |||
| 1303 | if (count($tagRest) === 0) { |
||
| 1304 | return $inputRec; // No update required |
||
| 1305 | } |
||
| 1306 | |||
| 1307 | // Save original interface update arrays before replacing them with the xxxRest ones |
||
| 1308 | $glevelsSave = $glevels; |
||
| 1309 | $tagSave = $tag; |
||
| 1310 | $islinkSave = $islink; |
||
| 1311 | $textSave = $text; |
||
| 1312 | |||
| 1313 | $glevels = $glevelsRest; |
||
| 1314 | $tag = $tagRest; |
||
| 1315 | $islink = $islinkRest; |
||
| 1316 | $text = $textRest; |
||
| 1317 | |||
| 1318 | $myRecord = self::handleUpdates($inputRec, $levelOverride); // Now do the update |
||
| 1319 | |||
| 1320 | // Restore the original interface update arrays (just in case ...) |
||
| 1321 | $glevels = $glevelsSave; |
||
| 1322 | $tag = $tagSave; |
||
| 1323 | $islink = $islinkSave; |
||
| 1324 | $text = $textSave; |
||
| 1325 | |||
| 1326 | return $myRecord; |
||
| 1327 | } |
||
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Add new gedcom lines from interface update arrays |
||
| 1331 | * The edit_interface and FunctionsEdit::add_simple_tag function produce the following |
||
| 1332 | * arrays incoming from the $_POST form |
||
| 1333 | * - $glevels[] - an array of the gedcom level for each line that was edited |
||
| 1334 | * - $tag[] - an array of the tags for each gedcom line that was edited |
||
| 1335 | * - $islink[] - an array of 1 or 0 values to tell whether the text is a link element and should be surrounded by @@ |
||
| 1336 | * - $text[] - an array of the text data for each line |
||
| 1337 | * With these arrays you can recreate the gedcom lines like this |
||
| 1338 | * <code>$glevel[0].' '.$tag[0].' '.$text[0]</code> |
||
| 1339 | * There will be an index in each of these arrays for each line of the gedcom |
||
| 1340 | * fact that is being edited. |
||
| 1341 | * If the $text[] array is empty for the given line, then it means that the |
||
| 1342 | * user removed that line during editing or that the line is supposed to be |
||
| 1343 | * empty (1 DEAT, 1 BIRT) for example. To know if the line should be removed |
||
| 1344 | * there is a section of code that looks ahead to the next lines to see if there |
||
| 1345 | * are sub lines. For example we don't want to remove the 1 DEAT line if it has |
||
| 1346 | * a 2 PLAC or 2 DATE line following it. If there are no sub lines, then the line |
||
| 1347 | * can be safely removed. |
||
| 1348 | * |
||
| 1349 | * @param string $newged the new gedcom record to add the lines to |
||
| 1350 | * @param string $levelOverride Override GEDCOM level specified in $glevels[0] |
||
| 1351 | * |
||
| 1352 | * @return string The updated gedcom record |
||
| 1353 | */ |
||
| 1354 | public static function handleUpdates($newged, $levelOverride = 'no') { |
||
| 1421 | } |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * builds the form for adding new facts |
||
| 1425 | * |
||
| 1426 | * @param string $fact the new fact we are adding |
||
| 1427 | */ |
||
| 1428 | public static function createAddForm($fact) { |
||
| 1429 | global $tags, $WT_TREE; |
||
| 1430 | |||
| 1431 | $tags = []; |
||
| 1432 | |||
| 1433 | // handle MARRiage TYPE |
||
| 1434 | if (substr($fact, 0, 5) === 'MARR_') { |
||
| 1435 | $tags[0] = 'MARR'; |
||
| 1436 | echo self::addSimpleTag('1 MARR'); |
||
| 1437 | self::insertMissingSubtags($fact); |
||
| 1438 | } else { |
||
| 1439 | $tags[0] = $fact; |
||
| 1440 | if ($fact === '_UID') { |
||
| 1441 | $fact .= ' ' . GedcomTag::createUid(); |
||
| 1442 | } |
||
| 1443 | // These new level 1 tags need to be turned into links |
||
| 1444 | if (in_array($fact, ['ALIA', 'ASSO'])) { |
||
| 1445 | $fact .= ' @'; |
||
| 1446 | } |
||
| 1447 | if (in_array($fact, Config::emptyFacts())) { |
||
| 1448 | echo self::addSimpleTag('1 ' . $fact . ' Y'); |
||
| 1449 | } else { |
||
| 1450 | echo self::addSimpleTag('1 ' . $fact); |
||
| 1451 | } |
||
| 1452 | self::insertMissingSubtags($tags[0]); |
||
| 1453 | //-- handle the special SOURce case for level 1 sources [ 1759246 ] |
||
| 1454 | if ($fact === 'SOUR') { |
||
| 1455 | echo self::addSimpleTag('2 PAGE'); |
||
| 1456 | echo self::addSimpleTag('3 TEXT'); |
||
| 1457 | if ($WT_TREE->getPreference('FULL_SOURCES')) { |
||
| 1458 | echo self::addSimpleTag('3 DATE', '', GedcomTag::getLabel('DATA:DATE')); |
||
| 1459 | echo self::addSimpleTag('2 QUAY'); |
||
| 1460 | } |
||
| 1461 | } |
||
| 1462 | } |
||
| 1463 | } |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Create a form to edit a Fact object. |
||
| 1467 | * |
||
| 1468 | * @param Fact $fact |
||
| 1469 | */ |
||
| 1470 | public static function createEditForm(Fact $fact) { |
||
| 1603 | } |
||
| 1604 | } |
||
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Populates the global $tags array with any missing sub-tags. |
||
| 1608 | * |
||
| 1609 | * @param string $level1tag the type of the level 1 gedcom record |
||
| 1610 | * @param bool $add_date |
||
| 1611 | */ |
||
| 1612 | public static function insertMissingSubtags($level1tag, $add_date = false) { |
||
| 1613 | global $tags, $WT_TREE; |
||
| 1614 | |||
| 1615 | // handle MARRiage TYPE |
||
| 1616 | $type_val = ''; |
||
| 1696 | } |
||
| 1697 | } |
||
| 1698 | } |
||
| 1699 | } |
||
| 1700 | } |
||
| 1701 | } |
||
| 1702 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state