<?php
    $thisPage="familientafel";
    include __DIR__ . "./../layout/header.php";
    include __DIR__ . "./../layout/navigation.php";
    include __DIR__ . "/../layout/css/navi.css";
    include __DIR__ . "/../layout/css/baum.css"; ?>
  </style>
</head> <?php
//var_dump($person);

function fill_box($pers, $left, $top, $bol_mem, $bol_fam, $but) {
  if (!empty($pers)) {
    $alter = 0;
    $id = $pers->member_id;
    if ($pers->gender == 1){ $gen = "m";$img ="male.jpg";} else{ $gen="f";$img ="female.jpg";}
    if ($pers->member_img != "") { $img = $pers->member_img;}?>
    <div class="<?php if ($bol_mem == true) {echo "mfambox_small";} else{echo "fambox_small";}?>"
        style="left:<?php echo $left;?>px;top:<?php echo $top;?>px;">
      <table>
        <tr>
          <td style="padding-left:5px">
            <a href="familienblatt?id=<?php echo $id;?>" title="Familienblatt">
              <span class="info"> <!-- hover vergrößert Bild-->
                <img src="../../photos/<?php echo $img;?>" border="0" alt="" width="40" height="52" />
              </span></a>
          </td>
          <td><a href='familientafel?<?php
            if ($bol_fam == true){echo "fam_id";}else{echo "id";}?>=<?php echo $id?>'
             title='<?php if ($bol_fam == true){echo "als Elternteil anzeigen";}else{echo "als Familie anzeigen";}?>'>
             <img src='../../img/<?php echo $gen?>.jpg' width="11" height="11" border="0" alt="" style="vertical-align: 0px;"/>
             <?php echo $pers->first_name." ".$pers->last_name;?></a><br />
             <span>
               <?php echo periode($pers)." ".alter($pers). "J.";?>
             </span>
          </td>
          </tr>
      </table><?php
      if (($but==2) AND (!$bol_fam)) { ?>
        <div class="b"><?php
      }
      if (($but==1) AND (!$bol_fam)) { ?>
        <div class="c"><?php
      } ?>
          <div class="d">
            <a href='familientafel?fam_id=<?php echo $id;?>'>
            <img src="../../img/admArrowUp.gif" width="13" height="13" border="0" alt="" title="Als eue Familie" ></a>
          </div>
        </div>
    </div><?php
  }
}

function zeichne($was, $l, $t){ // zeichnet line?>
  <div class="<?php echo $was?>" style='left:<?php echo $l;?>px;top:<?php echo $t;?>px;'></div><?php
}

function zeichne_1($was, $l, $t, $h1){  // zeichnet rect?>
  <div class="<?php echo $was?>" style='left:<?php echo $l;?>px;top:<?php echo $t;?>px;
    height:<?php echo $h1;?>px;'></div><?php
}

function zeichne_2($was, $l, $t, $text){  // zeichnet rect with text?>
  <div class="<?php echo $was?>" style='left:<?php echo $l;?>px;top:<?php echo $t;?>px;'><?php
    echo $text; ?>
  </div><?php
}
// ****************************** end functions *********************************
?>
<body><?php
  global $ladezeit;
    // Konstanten zur Festlegung der Boxes
    $box_hight = 56;              // hight of a box
    $box_width = 190;             // width of a box
    $delta_top = 67;              // vertical from box to box
    $top = 85;

    $left = 200;
    $t_footer = 800;
    $top_max = 200;

    $gff_left = $left;       $gff_top = $top + 20; // grandfather of father
    $gmf_left = $left + 222; $gmf_top = $top + 20; // grandmother of father +212
    $gfm_left = $left + 520; $gfm_top = $top + 20; // grandfather of father +298=212+86
    $gmm_left = $left + 742; $gmm_top = $top + 20; // grandmother of father +212

    $f_left = $left + 106;   $f_top = $top + 126;    // father
    $c_left = $left + 356;   $c_top = $top + 182;    // Child +260
    $m_left = $left + 626;   $m_top = $top + 126;    // mother +260

    $left_bg_l = $left + 96;             // linker background
    $left_bg_r = $left + 616;             // rechter background
    $left_r = $left + 462;                        // rechte Boxes
    $left_fname = $left + 340;                    // linke Seite Name

    $top_rect   = $top + 76;              //
    $top_line_h = $top + 101;             // horizontrale Linie Eltern
    $top_famname = $top + 105;
    $top_sibs = $top + 116 + 70 + 15;
    $top_p = $top_boxes = $top + 154;      // top der boxes left and right

    $bol_fam = false;     // link to Parents ($fam_id) or to member ($id)
    $bol_mem = false;     // highlight the box
    $but = 0;     // no triangle-button
    $but_m = 1;   // triangle-button male-siblings viewable
    $but_f = 2;   // triangle-button female-siblings viewable
    ?>

    <div class="container-fluid">
      <div class="container-fluid">
        <div style='margin-left:20px;margin-top:0px;'><?php
          $l = $left_fname;
          $t = 60;    // position des Auswahl-Button
          // spezieller Part: ohne ausgewählte Person kein $_GET
          if (empty($person->member_id)){ ?>
            <form  action="<?php echo "familientafel?id=2";?>"><?php
          } else { ?>
            <form  action="<?php echo "familientafel?id=".$person->member_id;?>"><?php
          }?>
          <div style="position:absolute;width:240px;left:<?php echo $l;?>px;top:<?php echo $t;?>px;height:30px;">
            <select name="id" onchange="submit()" style="bg-color:lightyellow;">
              <option value="null"><?php
              foreach ($persons as $pers) { // Auswahl anzeigen
                if ($pers->member_id == $_SESSION['id']) { ?>">
                  <option selected value="<?php echo $pers->member_id;?>"><?php
                } else { ?>
                  <option value="<?php echo $pers->member_id;?>"><?php
                }
                  echo jahr($pers->day_of_birth).":&nbsp;&nbsp;".$pers->last_name.", ".$pers->first_name;?>
                </option><?php
              } ?>
            </select>
          </div>
        </form>

        <div class="box" style='left:310px; width:200px;'>
          <strong><?php echo "Kind als Ausgangspunkt:</strong>"; ?>
        </div><?php
        if (!empty($mother)){  // nur wenn Mutter #0, kann es Kinder geben?>
          <div class="box" style='left:555px; width:200px; top:160px;'>
            <strong><?php echo "Ausgangspunkt</strong>"; ?>
          </div><?php
        } ?>
<!-- ********** Hinweise zur Website **************-->
        <div class="box" style='left:0px; width:250px; top:110px;'>
          <strong><font color=blue>Hinweise zu dieser Webseite <br></font></strong>
          <li>Neue Person kann im Seitenkopf<br><span style="background-color:lightyellow;
            border:1px; border-style:solid; border-color:lightgrey;">
            Dropdown-Liste </span>ausgewählt werden;<br>
            Kind wird zum <strong>Ausgangspunkt</strong></li>	            	            <br>
          <li>Ein Click auf den <span style="color:blue;"> Namen</span> einer Person,
            erzeugt einen neuen Ausgangspunkt:
          <ul>
            <li><strong>Kind (Mitte)</strong> wird zum Elternteil<br></li>
            <li><strong>Andere Personen (Vater oder Mutter) </strong> werden zu Kindern<br></li>
          </ul>
          <li>Click auf <b><img src="../../img/admArrowUp.gif" width="15" height="15" border="0" alt="" ></b>
            Zeichen, die entsprechende Familie mit Kindern </br>wird angezeigt.</li><br>
          <li>Click auf das <strong>Bild</strong> einer Person,
            <br>ruft sein Familienblatt auf
          </li>
        </div><?php

        // ******** display grand parents paternal *********************
        if (!empty($gffather)) {
          fill_box($gffather,$gff_left,$gff_top, $bol_mem, $bol_fam, $but);
          $was = 'rect_1';
          $l = $left_bg_l;
          $t = $top_rect;     //$top_rect;
          zeichne($was, $l, $t);
          $was = 'line_h';
          $l = $left + 212;
          $t = $top_line_h;   //$top + 101;
          zeichne($was, $l, $t);
        }
        if (!empty($gmfather)) {
          fill_box($gmfather,$gmf_left,$gmf_top, $bol_mem, $bol_fam, $but);
        }

        // ********* display grand parents maternal ******************
        if (!empty($gfmother)) {
          fill_box($gfmother,$gfm_left,$gfm_top, $bol_mem, $bol_fam, $but);
          $was = 'rect_1';
          $l = $left_bg_r; //$left + 625;
          $t = $top_rect;    //$top_rect;
          zeichne($was, $l, $t);
          $was = 'line_h';
          $l = $left + 731.5;
          $t = $top_line_h;   //$top + 101;
          zeichne($was, $l, $t);
        }
        if (!empty($gmmother)) {
          fill_box($gmmother,$gmm_left,$gmm_top, $bol_mem, $bol_fam, $but);
        }
        // display father
        $bol_mem = true;     // member = father or mother
        if (!empty($father)) {
          fill_box($father, $f_left, $f_top, $bol_mem, $bol_fam, $but);
        }
        // dispaly mother
        if (!empty($mother)) {
          fill_box($mother, $m_left, $m_top, $bol_mem, $bol_fam, $but);
        }
        $bol_mem = false;    // background color

        // waagerechte Verbindungslinie zwischen Eltern (links)
        if (!empty($mother)) { // wenn vorhanden; Mutter nicht ohne Vater!
          $was = 'line_v2';
          $l = $left + 302;
          $t = $top_p;
          zeichne($was, $l, $t);  //nach links
          $was = 'line_v2';
          $l = $left_r;
          $t = $top_p;
          zeichne($was, $l, $t);  // nach rechts
        }
        if (!empty($siblings_f)) {  // display siblings of father
          $f_top = $f_top + 15;
          foreach ($siblings_f as $sib):
            $but = 2;               // female triangle-button next to the box
            $f_left = $f_left;
            $f_top = $f_top + $delta_top;    // next
            fill_box($sib,$f_left, $f_top, $bol_mem, $bol_fam, $but);
            $but = 0;               // no triangle-button
          endforeach;
          $anz = count($siblings_f) + 0;  // +1 (Vater mit einschließen)
          $h1 = ($delta_top * $anz) + 9; // hight of background
          $was = 'fambackground';
          $l = $left_bg_l;
          $t = $top_sibs;
          zeichne_1($was, $l, $t, $h1);
          if ($t_footer <= $h1) { $t_footer = $h1;} // höhe des footers
        }

        if (!empty($siblings_m)) {  // display siblings of mother
          $m_top = $m_top + 15;
          foreach ($siblings_m as $sib):
            $but = 1;               // male triangle-button
            $m_left = $m_left;
            $m_top = $m_top + $delta_top;    // next Child die();
            fill_box($sib,$m_left,$m_top, $bol_mem, $bol_fam, $but);
            $but = 0;
          endforeach;
          $anz = count($siblings_m) + 0;  // +1 wegen Vater
          $h2 = ($delta_top * $anz) + 9;  + 9;
          $was = 'fambackground';
          $l = $left_bg_r;  //$left + 626;
          $t = $top_sibs;   //
          zeichne_1($was, $l, $t, $h2);
          if ($t_footer <= $h2) { $t_footer = $h2;} // höhe des footers
        }

        // display name of family (nur wenn es eine Mutter gibt!)
        if (!empty($mother)) {
          $text = "<center><b>Fam. ".$father->first_name." ".$father->last_name."</center></b>";
        } else {
          $text = "<center><b>Keine Auswahl möglich!</b></center> ";}
        $was = 'famname';
        $l = $left_fname;
        $t = $top_famname;
        zeichne_2($was, $l, $t, $text); // es wir $text ausgegeben

        // display person
        $bol_fam = true;
        if (!empty($person)) { //echo "Person not empty";
          $was = 'line_h';
          $l = $left_r;   //$left + 472;     // left_r
          $t = $top_boxes;      //top_line
          zeichne($was, $l, $t);
          $bol_mem = true;
          fill_box($person,$c_left,$c_top,$bol_mem,$bol_fam, $but);
          $bol_mem = false;
          $c_top = $c_top + $delta_top;    // next box below
        }

        if (!empty($siblings)) {  // display children (siblings of $person)
        // kleine Sekrechte zu Kinder
        $was = 'line_h';
        $l = $left_r;   //$left + 472;
        $t = $top_boxes;    //$top + 154;    //top_boxes
        zeichne($was, $l, $t);
        $l = $left_r;   //Mitte Seite = $left + 472;
        $t = $top_boxes;    //$top + 154;  //top_line
        $anz = count($siblings);
        $bol_mem = true;
        foreach ($siblings as $sib){
          fill_box($sib,$c_left,$c_top, $bol_mem, $bol_fam, $but);
          $c_top = $c_top + $delta_top;    // next box below
        }
        $bol_mem = false;
        $anz = count($siblings) + 0;  // +1 wegen Vater
        $h1 = (($delta_top * $anz) + 9);
        if ($t_footer <= $h1) { $t_footer = $h1;} // höhe des footers
        } ?>
      </div>
    </div><?php
    if ($f_top <= $m_top){ $t_footer = $m_top;} else {$t_footer = $f_top;}
    if ($t_footer <= $c_top){ $t_footer = $c_top;}
    $hint_1 = $t_footer + $delta_top  + 20;
    $t_footer = $hint_1 + 20 ?>
  </div><?php
  if ($t_footer <= 780){$t_footer = 780;}       // minimale Höhe

  include __DIR__ . "/../js/hochschieben.js";   // Navigation nach oben schieben
  include __DIR__ . "/../layout/footer_e.php"; ?>

  </body>
</html>