1: <?php
2:
3:
4: 5: 6: 7: 8:
9:
10: namespace app\views\search;
11:
12:
13: use \mako\utility\HTML;
14: include '/var/www/hbrutvikling/hbr/app/views/search/family.php';
15:
16: class HTMLWrapper {
17:
18:
19:
20:
21: private $parentsKey = 'Parents';
22: private $urlprefix = 'http://156.116.18.160/mako/index.php/';
23: private $urlshow = 'http://156.116.18.160/mako/index.php/showmergedperson?frkmst=';
24: private $urlshowmerged = 'http://156.116.18.160/mako/index.php/showmergedperson?res=';
25: private $daurl = 'http://digitalarkivet.arkivverket.no/';
26:
27: private $livsloptable = array('Dato', 'Kilde', 'Rolle', 'Navn', 'F.dato', 'F.sted', 'Bosted', 'Stilling og stand', 'Fam.st', 'Siv.st.', 'Yrke', 'PKID', 'Far/Brudgom', 'Mor/Brud', 'Partner', 'Barn/Andre');
28: protected $html;
29:
30: public function __construct() {
31: $this->html = new HTML();
32: }
33:
34:
35: public function formatTable($table, $tblid = NULL, $trclass = NULL)
36: {
37: $trclassval = '';
38: $tblidval = '';
39: $tbbody = '';
40: $tdbodyend = '';
41: if ($tblid != NULL)
42: {
43: $tbbody = '<tbody id="'.$tblid.'">';
44: $tdbodyend = '</tbody>';
45: }
46: $res = '';
47: $blue = '#93F0FE';
48: $offwhite = '#FFFCFC';
49: $grey = '#E4E0E0';
50: $bgcolor = $grey;
51: if (count($table) > 0)
52: {
53: $res ='<table border="1" align="left">';
54: $i = 0;
55: foreach ($table as $row)
56: {
57:
58: if ($i == 1)
59: {
60:
61: }
62: if (count($row) > 0)
63: {
64: $res .='<tr align="left" bgcolor="'.$bgcolor.$trclassval.'">';
65: if ($i == 0)
66: {
67: foreach ($row as $cell)
68: {
69:
70: $res .='<th> '.$cell.' </th>';
71: }
72: }
73: else
74: {
75: foreach ($row as $cell)
76: {
77:
78: $res .='<td> '.$cell.' </td>';
79: }
80: }
81: $res .='</tr>';
82: $i++;
83: if ($bgcolor == $offwhite)
84: $bgcolor = $grey;
85: else
86: $bgcolor = $offwhite;
87: }
88: }
89:
90: $res .='</table>';
91: }
92: return $res;
93: }
94:
95: public function createLabelElement($name, $label)
96: {
97:
98: $res = '<label for="'.$label.'">'.$name.'</label>';
99: return $res;
100: }
101:
102: public function createBoxElement($name, $value, $boxtype, $id, $checked = '')
103: {
104: if ($id === '')
105: $idtext = $id;
106: else
107: $idtext = ' id="'.$id.'" ';
108: if ($value === '')
109: $valuetxt = $value;
110: else
111: $valuetxt = '" value="'.$value.'" ';
112: $res = '<input type="'.$boxtype.'" name="'.$name.'"'.$valuetxt.$idtext.$checked.'> </input>';
113: return $res;
114: }
115:
116: public function createButtonElement($name, $value, $class = NULL)
117: {
118:
119:
120: $classpart = '';
121: if ($class != NULL)
122: {
123: $classpart = ' class="'.$class.'"';
124: }
125: $res = '<input type= "submit" name="'.$name.'" value="'.$value.'" '.$classpart.'/> ';
126: return $res;
127: }
128:
129:
130: public function createHiddenElement( $name, $value, $class = NULL)
131: {
132: $res = '<input type= "hidden" name="'.$name.'" value="'.$value.'">';
133: return $res;
134: }
135:
136:
137:
138: public function createTextElement( $name, $value, $id, $size, $class = NULL)
139: {
140: $res = '<input type= "text" name="'.$name.'" value="'.$value.'" id="'.$id.'" size="'.$size.'"/>';
141: return $res;
142: }
143:
144:
145: public function createDivElement($class)
146: {
147: $res = '<div class="'.$class.'">';
148: return $res;
149: }
150:
151: public function createPlaceLine($place)
152: {
153:
154: $res = '';
155:
156: $res .= '<h2> Steder </h2>';
157: $id = $place['id'];
158:
159: if (strlen ($id)> 2)
160: $type = '&type='.substr($id, 0, 2);
161:
162: $res .= '<a href="'.$this->urlprefix.'showplace?id='.$place['autoid'].$type.'">';
163: if (strlen ($id) > 2 && substr($id, 0, 2) == 'gf')
164: {
165:
166:
167: $res .= $place['bydel'].', ';
168: $res .= $place['gatenavn_og_nummer_i_gata'].', ';
169: $res .= $place['gaardens_nummer'];
170: }
171: else if (strlen ($id)> 2 && substr($id, 0, 2) == 'bf')
172: {
173:
174: $res .= $place['bostedets_navn'];
175: }
176: else
177: {}
178: $res .= '</a>';
179: return $res;
180: }
181:
182: private function getKildeurlsfx($person)
183: {
184:
185: $res = '';
186: if ($person['kildekategori'] == 'kb')
187: {
188: if ($person['listetype'] != NULL)
189: $res = 'kb/'.$person['listetype'];
190:
191: }
192: elseif ($person['kildekategori'] == 'ft')
193: $res = 'ft';
194: else
195: {}
196: return $res;
197: }
198:
199: public function createHendelseLine($person, $fmlfields = NULL)
200: {
201: $emptyField = '';
202: $res = ' <th> ';
203:
204: if ($person['hendelsesdato'] != 'null')
205: $res .= $person['hendelsesdato'];
206: else
207: $res.=$emptyField;
208:
209: $res .= '</th> <th>';
210:
211: if ($person['kildeid'] != 'null')
212: $res .= $person['kildeid'];
213: else
214: $res .= $emptyField;
215: $res .= '</th> <th>';
216:
217: if ($person['rolle'] != 'null' )
218: $res .= $person['rolle'];
219: else
220: $res .= $emptyField;
221: $res .= '</th> <th>';
222:
223: $fulNavn = '';
224: if ($person['fornavn'] != 'null' && $person['etternavn'] != 'null')
225: $fulNavn = $person['fornavn'].' '.$person['etternavn'];
226: else if ($person['fornavn'] != 'null')
227: $fulNavn = $person['fornavn'];
228: else if ($person['etternavn'] != 'null')
229: $fulNavn = $person['etternavn'];
230: else
231: $fulNavn = $emptyField;
232: $res .= $fulNavn;
233: $res .= '</th> <th>';
234:
235: if ($person['fodselsaar'] != 'null')
236: $res .= $person['fodselsaar'];
237: else
238: $res .= $emptyField;
239: $res .= '</th> <th>';
240:
241: if ($person['fodested'] != 'null')
242: $res .= $person['fodested'];
243: else
244: $res .= $emptyField;
245: $res .= '</th> <th>';
246: if ($person['bosted']!= 'null')
247: $res .= $person['bosted'];
248: else
249: $res .= $emptyField;
250: $res .= '</th> ';
251:
252: $stogst = $emptyField;
253: if ($person['stilling_stand'] != NULL)
254: $stogst = $person['stilling_stand'];
255: $res .= '<th>'.$stogst.' </th>';
256:
257: $f = $emptyField;
258: if (array_key_exists('familiestilling', $person) && isset($person['familiestilling']))
259: $f = $person['familiestilling'];
260: $res .= '<th>'.$f.' </th>';
261:
262: $f = $emptyField;
263: if (array_key_exists('sivilstand', $person) && isset($person['sivilstand']))
264: $f = $person['sivilstand'];
265: $res .= '<th>'.$f.' </th>';
266:
267: $f = $emptyField;
268: if (array_key_exists('yrke', $person) && isset($person['yrke']))
269: $f = $person['yrke'];
270: $res .= '<th>'.$f.' </th>';
271:
272:
273: $pkid = $this->daurl.$this->getKildeurlsfx($person).'/person/'.$person['pfid'];
274: $dahref = '<a href="'.$pkid.'">DA</a>';
275: $res .= '<th>'.$dahref.' </th>';
276:
277: if ($fmlfields != NULL)
278: $res .= '<th>'.$fmlfields['Far'].' </th>';
279:
280: if ($fmlfields != NULL)
281: $res .= '<th>'.$fmlfields['Mor'].' </th>';
282:
283: if ($fmlfields != NULL)
284: $res .= '<th>'.$fmlfields['Partner'].' </th>';
285:
286: if ($fmlfields != NULL)
287: $res .= '<th>'.$fmlfields['Barn'].' </th>';
288: return $res;
289: }
290:
291:
292: private function makeTableHeader()
293: {
294: $res = '';
295: $res .= '<tr style="background:#80BFFF"> ';
296: foreach ($this->livsloptable as $item)
297: {
298: $res .= '<th> '.$item.' </th>';
299: }
300: $res .= '</tr> ';
301: return $res;
302:
303: }
304:
305: public function makehref($url, $txt)
306: {
307:
308: $res = '<a href="'.$url.'">'.$txt.'</a>';
309: return $res;
310: }
311: private function getFmlFields($inx,$familier)
312: {
313: $res = array("Far" => " ",
314: "Mor" => "",
315: "Partner" => "",
316: "Barn" => "",
317: );
318: if ($familier != NULL && count($familier) > $inx)
319: {
320:
321: $f = $familier[$inx][0];
322: if ($f["isFamilyMember"] == 'true')
323: {
324: foreach ($f["family"] as $key => $value)
325: {
326: switch ($key) {
327: case "Far":
328: $res["Far"] = $this->makehref($this->urlshow.$value['url'], $value["name"]);
329: break;
330: case "Mor":
331: $res["Mor"] = $this->makehref($this->urlshow.$value['url'], $value["name"]);
332: break;
333: case "Partner":
334: $res["Partner"] = $this->makehref($this->urlshow.$value['url'], $value["name"]);
335: break;
336: case "Barn":
337: $res["Barn"] = $this->makehref($this->urlshow.$value['url'], $value["name"]);
338: break;
339: }
340: }
341: }
342: else
343: {
344: $main = $f["MainPersons"];
345: foreach ($main as $m)
346: {
347: $res["Barn"] .= $this->makehref($this->urlshow.$f["family"][$m]['url'],$f["family"][$m]["name"]);
348: }
349: }
350: }
351:
352: return $res;
353: }
354:
355: public function createLivsLoepTable($forekomster, $familier)
356: {
357: $res = '';
358: $class = 'mergingWindow';
359: $res .= '<h1> Livsløp </h1>';
360: $res .= '<div class="'.$class.'"> ';
361:
362: if ($forekomster != NULL)
363: {
364: $res .= '<table>';
365: $res .= $this->makeTableHeader();
366: $ii = 0;
367:
368: foreach ($forekomster as $forekomst)
369: {
370:
371: $fmlfields = $this->getFmlFields($ii,$familier);
372: $res .= '<tr>';
373: $res .= $this->createHendelseLine($forekomst, $fmlfields);
374: $res .= '</tr>';
375: $ii = $ii +1;
376: }
377: $res .= '</table>';
378: }
379: $res .= ' </div>';
380: return $res;
381:
382: }
383:
384: public function getNameLine($person)
385: {
386: $fulNavn = '';
387: if ($person['forenamn'] != 'null' && $person['etternamn'] != 'null')
388: $fulNavn = $person['forenamn'].' '.$person['etternamn'];
389: else if ($person['forenamn'] != 'null')
390: $fulNavn = $person['forenamn'];
391: else if ($person['etternamn']!= 'null')
392: $fulNavn = $person['etternamn'];
393: else
394: $fulNavn = $emptyField;
395: return $fulNavn;
396: }
397:
398: public function getFamilySectionMerged($allfamilies)
399: {
400: $res = '';
401: $mother = '';
402: $child = '';
403: $father = '';
404: $other = '';
405: $class = 'familySection';
406: $hendelse = new Hendelse();
407: $familyhtml = '';
408: $otherhtml = '';
409:
410: if ($allfamilies != NULL)
411: {
412: $hasParentsFmly = false;
413: if (array_key_exists($this->parentsKey, $allfamilies) && isset($allfamilies[$this->parentsKey]) && (count($allfamilies[$this->parentsKey]) > 0))
414: {
415: $hasParentsFmly = true;
416: $prents = $allfamilies[$this->parentsKey];
417: $res .= '<div class="'.$class.'"> ';
418: $res .= '<h3> Foreldre og søsken </h3>';
419: if (array_key_exists('far', $prents))
420: {
421: $res .= 'Far: <a href="'.$this->urlshowmerged.$prents["far"]["autoid"].'" target="_blank">'.$prents["far"]["fornavn"].' '.$prents["far"]["etternavn"].'</a> <br>';
422: }
423: if (array_key_exists('mor', $prents))
424: {
425: $res .= 'Mor: <a href="'.$this->urlshowmerged.$prents["mor"]["autoid"].'" target="_blank">'.$prents["mor"]["fornavn"].' '.$prents["mor"]["etternavn"].'</a> <br>';
426: }
427: if (array_key_exists('sosken', $prents))
428: {
429: $res .= 'Søsken: <br>';
430: $sosken = $prents['sosken'];
431: foreach ($sosken as $s)
432: {
433: $res .= '<a href="'.$this->urlshowmerged.$s["autoid"].'" target="_blank">'.$s["fornavn"].' '.$s["etternavn"].'</a> <br>';
434: }
435: }
436: $res .= ' </div>';
437: }
438: foreach ($allfamilies as $key =>$f)
439: {
440: if ($key !== $this->parentsKey)
441: {
442:
443:
444: foreach ($f as $family)
445: {
446: if(array_key_exists ("familyMember" , $family ))
447: {
448: if($hasParentsFmly !== true && $family["familyMember"] !== "Barn")
449: {
450: $res .= '<div class="'.$class.'"> ';
451: if ($family["isFamilyMember"] == 'true')
452: {
453:
454: $familyhtml = '<h3> Familie </h3>';
455: if (array_key_exists ('other' ,$family))
456: {
457: $otherhtml = '<h3> Andre </h3>';
458: }
459: foreach ($family as $key =>$item)
460: {
461: if ($key == 'other')
462: {
463: foreach ($item as $othermember)
464: {
465: if (is_array($othermember))
466: {
467: $otherhtml .= $item["type"].': '.'<a href="'.$this->urlshow.$othermember["url"].'" target="_blank">'.
468: $othermember["name"].'</a> <br>';
469: }
470: }
471: }
472: elseif ($key == 'family')
473: {
474: foreach($item as $mkey =>$member)
475: {
476: $familyhtml .= $mkey.': '.'<a href="'.$this->urlshow.$member["url"].'" target="_blank">'.$member["name"].'</a> <br>';
477: }
478: }
479: else{}
480: }
481: }
482:
483: else
484: {
485: $familyhtml .= '<h3>'. $family["hendelse"]. '</h3>';
486: if (array_key_exists ( "MainPersons", $family))
487: {
488: foreach ($family["MainPersons"] as $p)
489: {
490: $familyhtml .= $p.': '.'<a href="'.$this->urlshow.$family["family"][$p]["url"].'" target="_blank">'.$family["family"][$p]["name"].'</a> <br>';
491: }
492: }
493: }
494: $res .= $familyhtml.$otherhtml;
495: $res .= ' </div>';
496: }
497: }
498: else
499: {
500:
501: }
502: }
503: }
504: else
505: {
506:
507:
508: }
509: }
510: }
511:
512: return $res;
513: }
514:
515: public function getFamilySection($family, $person)
516: {
517: $res = '';
518: $mother = '';
519: $child = '';
520: $father = '';
521: $other = '';
522: $class = 'familySection';
523: $hendelse = new Family();
524: $familyhtml = '';
525: $otherhtml = '';
526: $linkprefix = '<a href="http://156.116.18.160/mako/index.php/showperson?frkmst=';
527:
528: if ($family != NULL)
529: {
530:
531: $res = '<div class="'.$class.'"> ';
532:
533: $families = $hendelse->processFamily($family, $person);
534: $res .= '<br>'.json_encode($families);
535: if ($families != NULL)
536: {
537: foreach ($families as $familyset)
538: {
539: if ($familyset != NULL)
540: {
541: if ($familyset["isFamilyMember"] == 'true')
542: {
543:
544: $familyhtml = '<h3> Familie </h3>';
545: if (array_key_exists ('other' ,$familyset))
546: {
547: $otherhtml = '<h3> Andre </h3>';
548: }
549: foreach ($familyset as $key =>$item)
550: {
551: if ($key == 'other')
552: {
553: foreach ($item as $othermember)
554: {
555: if (is_array($othermember))
556: {
557: $otherhtml .= $item["type"].': '.$linkprefix.$othermember["url"].'" target="_blank">'.
558: $othermember["name"].'</a> <br>';
559: }
560: }
561: }
562: elseif ($key == 'family')
563: {
564:
565:
566:
567: foreach($item as $mkey =>$member)
568: {
569: $familyhtml .= $mkey.': '.$linkprefix.$member["url"].'" target="_blank">'.$member["name"].'</a> <br>';
570: }
571: }
572:
573: }
574: }
575: else
576: {
577:
578: $familyhtml .= '<h3>'. $familyset["hendelse"]. '</h3>';
579: if (array_key_exists ( "MainPersons", $familyset))
580: {
581: foreach ($familyset["MainPersons"] as $p)
582: {
583: $familyhtml .= $p.': '.$linkprefix.$familyset["family"][$p]["url"].'" target="_blank">'.$familyset["family"][$p]["name"].'</a> <br>';
584: }
585: }
586: }
587:
588:
589:
590: $res .= $familyhtml.$otherhtml;
591: }
592: }
593: }
594: $res .= ' </div>';
595: }
596: return $res;
597: }
598:
599: public function createForekomstDetails($person)
600: {
601: $emptyField = '';
602: $res = '<h2>';
603: if ($person['fornavn'] != 'null' && $person['etternavn'] != 'null')
604: $res .= $person['fornavn'].' '.$person['etternavn'];
605: else if ($person['fornavn'] != 'null')
606: $res .= $person['fornavn'];
607: else if ($person['etternavn']!= 'null')
608: $res .= $person['etternavn'];
609: else
610: $res .= $emptyField;
611: if($person['kjonn'] == 'k')
612: $res .= ', kvinne';
613: elseif ($person['kjonn'] == 'm')
614: $res .= ', mann';
615: $res .= '</h2>';
616: return $res;
617: }
618:
619: public function createPersonDetails($opplysning, $edit)
620: {
621: $res = '';
622:
623:
624:
625: if ($edit === true)
626: {
627: $buttenresponce = 'savepersondata';
628: $buttenname = 'Save';
629: }
630: else
631: {
632: $buttenresponce = 'openeditpersondetails';
633: $buttenname = 'Edit';
634: }
635:
636: if ($edit == 'true')
637: {
638: $name = $this->createLabelElement('Fornavn: ', 'fornavnlabel');
639: $name .= $this->createTextElement( 'fornavn',$opplysning['fornavn'],'fornavn' ,30 );
640: $name .= $this->createLabelElement('Etternavn: ', 'etternavnlabel');
641: $name .= $this->createTextElement( 'etternavn',$opplysning['etternavn'],'etternavn' ,30 );
642: }
643: else
644: {
645: $name = $opplysning['fornavn'].' '.$opplysning['etternavn'];
646: $kjonn = '';
647: if ($opplysning['kjonn'] == 'm')
648: $name .= ', mann';
649: elseif ($opplysning['kjonn']== 'k')
650: $name .= ', kvinne';
651: }
652: $f = '';
653: if ($edit == 'true')
654: {
655: $f = $this->createLabelElement('Dato', 'personbdatolabel');
656: $f .= $this->createTextElement( 'fodselsdato',$opplysning['fodselsdato'],'fodselsdato' ,30 );
657: $f .= $this->createLabelElement('Sted', 'personbplacelabel' );
658: $f .= $this->createTextElement( 'fodested',$opplysning['fodested'],'fodested' ,30 );
659: }
660: else
661: {
662: if ($opplysning['fodselsdato'] == '')
663: $f = 'Ukjent dato, ';
664: else
665: $f = $opplysning['fodselsdato'].', ';
666: if ($opplysning['fodested'] == '')
667: $f .= 'Ukjent sted';
668: else
669: $f .= $opplysning['fodested'];
670: }
671: $d = '';
672: if ($edit == 'true')
673: {
674: $d = $this->createLabelElement('Dato', 'personddatolabel');
675: $d .= $this->createTextElement( 'dodsdato',$opplysning['dodsdato'],'dodsdato' ,30 );
676: $d .= $this->createLabelElement('Sted', 'persondplacelabel' );
677: $d .= $this->createTextElement( 'dodssted',$opplysning['dodssted'],'dodssted' ,30 );
678: }
679: else
680: {
681: if ($opplysning['dodsdato'] == '')
682: $d = 'Ukjent dato, ';
683: else
684: $d = $opplysning['dodsdato'].', ';
685: if ($opplysning['dodssted'] == '')
686: $d .= 'Ukjent sted';
687: else
688: $d .= $opplysning['dodssted'];
689: }
690: $res .= '<div>';
691: $res .= '<form action="" method="get">';
692: if ($edit == 'true')
693: {
694: $res .= '<table>';
695: $res .= '<tr>';
696: $res .= '<th>';
697: $res .= $name;
698: $res .= '</th>';
699: $res .= '</tr>';
700: }
701: else
702: {
703: $res .= '<h2>'.$name.'</h2>';
704: $res .= '<table>';
705: }
706:
707: $res .= '<tr>';
708: $res .= '<th>';
709: $res .= 'Født: '.$f;
710: $res .= '</th>';
711: $res .= '</tr>';
712: $res .= '<tr>';
713: $res .= '<th>';
714: $res .= 'Død: '.$d;
715: $res .= '</th>';
716: $res .= '</tr>';
717: $res .= '</table>';
718: $res .= $this->html->tag('button', array('type' => 'submit', 'name' => $buttenresponce), $buttenname);
719: $res .= '</form>';
720: $res .= '</div>';
721: return $res;
722: }
723: }