<?php
  $thisPage="update";
  include __DIR__ . "./../layout/header.php";
  include __DIR__ . "./../layout/navigation.php";
  include __DIR__ . "/../inc/const.php"; // Konstanten

  include __DIR__ . "./../layout/css/navi.css";
?>

</head>
<body><?php
  global $ladezeit;

  include __DIR__ . "/../inc/function_display.inc.php"; // Funktionen

  $link = "<a href='update?id=";
  $update = "action=01";
  $submit = "action=02";
  $link_update = "<a href='update?id=";
  $link_submit = "<a href='submit?id=";
  $update_person = "who=1";
  $update_partner = "who=2";

  $row_m = $person;
  $m_gender = $person->gender;
  $person_id = $person->member_id;

/*
  $test = isset($_GET['something']) ? $_GET['something'] : '';
  means
  if(isset($_GET['something'])){ $test = $_GET['something'];
  } else {
    $test = '';
  }
*/
  $_SESSION['message'] = "";
  $this->is_admin();  // returns true or goto login

  // person_id wird gesetzt durch Auswaglfeld oder link (i)
  $person_id = getAndSetSession('id', 'person_id', '02');
  // who beschreibt was geändert wird (Person, Partner, ..)
  $who = getAndSetSession('who', 'who', '1');
  // action: update = 1, new = 2
  $action = getAndSetSession('action', 'action', '1');
  // p_id_p: wird gesetzt duch Selektionsfeld Partner
  $p_id = getAndSetSession('p_id', 'p_id', '0');
  // id_part_new wird gesetzt duch Selektionsfeld new Partner
  $id_part_new = getAndSetSession('id_part_new', 'id_part_new', '13');
  // id_part_update wird gesetzt duch Selektionsfeld update Partner
  $id_part_update = getAndSetSession('id_part_update', 'id_part_update', '13');
  // iss_id wird gesetzt duch Selektionsfeld update Partner
  $iss_id = getAndSetSession('iss_id', 'iss_id', '0');
    // bem_id wird gesetzt duch Selektionsfeld Bemerkungen
  $bem_id = getAndSetSession('bem_id', 'bem_id', '0');
  // wird gesetzt duch Selektionsfeld Wohnort
  $id_place = getAndSetSession('id_place', 'id_place', '0');
  // wird gesetzt duch Selektionsfeld Wohnort
  $w_ort_id = getAndSetSession('w_ort_id', 'w_ort_id', '0');
  // id_adr: wird gesetzt duch Adresseneingabe
  $id_adr = getAndSetSession('id_adr', 'id_adr', '0');
  ?>


<!-- **************************** Beginn Hauptprogramm *************************-->
<!-- ***************************** Kopfzeile ***********************************-->
<div class="container-fluid" id="myTable">
  <div class="row">
    <div class="col-sm-3 ">
      <div class="well well-sm"><?php
        $str_label = "Bitte Person wählen: ";
        if (!($who == 5)) {
          select_person($str_label, $person, $persons);
        } else {
          echo '<br><b><center>Hier findet Adressenpflege statt</b>'?></center><br> <?php
        } ?>
      </div>
    </div>
<!-- ********************************* Mittelblock *****************************-->
    <div class="col-sm-6">
      <div class="well well-sm">
        <h4 class="text-center"><?php
          switch($person->gender) {
            case 1: $icon = "<img src='../../img/m.jpg'>";break;
            case 2: $icon = "<img src='../../img/f.jpg'>";break;
            case 0: $icon = "<img src='../../img/u.jpg'>";break;
          }
          $kopf_daten =array("Personendaten ","Partnerdaten ","Ereignisse ","Wohnorte ","Adressenpflege ","Bemerkungen zu  ","User der Datenbank ");
          if ($action == 1) { ?>
            <h4 class="text-center"><strong><?php echo $kopf_daten[$who-1];
              if (!($who == 5)) {
                echo $icon." "
                .$person->first_name. " ".$person->last_name."</br>"
                .date_period($person);
              }
              echo "</strong></h4>";
          } else { ?>
            <h4 class="text-center"><strong>Neue Daten aufnehmen</strong></h4><?php
          } ?>
        </div>
      </div>
<!-- ********************************* Rechter Block ***************************-->
      <div class="col-sm-3">
        <div class="well well-sm">
          Stand <?php echo $monatsnamen[$monat]." ".$jahr;?></br>
            <p style="background-color:lightgrey;">
              <strong>Pers.:
                <span><?php
                $nbm = $nbf = $nbu = 0;
                foreach ($persons as $pers) {
                  switch($pers->gender) {
                    case 1:  $nbm++; break;   // man
                    case 2:  $nbf++; break;   // woman
                    case 0:  $nbu++; break;   // unknown
                  }
                }
                echo count ($persons)." - "
                  .$nbm." "."<img src='../../img/m.jpg'>  - "
                  .$nbf." "."<img src='../../img/f.jpg'>  - "
                  .$nbu." "."<img src='../../img/u.jpg'> " ;?>
                </span>
              </strong>
            </p>
         </div>
      </div>
   </div>
</div>
<!-- ************************* Ende Container Kopfzeile **********************************-->

<!-- ************************* Auswahlfelder **********************************-->
<div class="container-fluid">
  <table width="100%">
    <tr>
      <td>
        <form>
          <strong>action: </strong>
          <input type="radio" name="action" id="action" value="01" onchange="submit()" <?php
            if ($action == 1) { echo "checked=checked"; } ?> /> <?php
            if ($action == 1) { echo "<strong><span style=\"color:red\";"."> update</strong>";
                     } else { echo " update";}?>
          <input type="radio" name="action" id="action" value="02" onchange="submit()"<?php
            if ($action == 2) { echo "checked=checked"; } ?> /><?php
            if ($action == 2) { echo "<strong><span style=\"color:red\";"."> new</strong>";
                     } else { echo " new";}?>
        </form>
      </td>
      <td>&nbsp;</td>
<!-- ************************ Choose Selections  *******************************-->
      <td>
        <form>
          <strong>select: </strong><?php
          $select = array("Person","Partner","Ereignisse","Wohnort","Adressen","Bemerkungen","User");
          for ($i=1; $i<8; $i++) { ?>
            <input type="radio" name="who" id="who" value="<?php echo $i;?>" onchange="submit()"
              <?php if ($who == $i) { echo "checked=checked"; } ?>/>
              <?php if ($who == $i) { echo "<strong><span style=\"color:red\";".">".$select[$i-1]."</strong>";}
                              else { echo $select[$i-1];}
          }  ?>
        </form>
      </td>
    </tr>
  </table>
<!-- ************************ Ende Auswahlfelder *******************************-->
  <hr>
<?php if (($who == 02)){?>
  <h3><strong>Partner von Person</strong></h3>
  <table>
    <tr style="font-weight: bold;">
      <td> </td><td>G&nbsp;</td><td>&nbsp;Vor- Nachnamen</td><td>&nbsp;&nbsp;geb.</td><td><center>&nbsp;∞<center></td><td>&nbsp;Ort</td><td><?php echo "<center>&nbsp;⚮</center>"; ?></td>
    </tr><?php
    $id_no = 0;
    if (count($partner) != 0) { ?>
      <form name="iss_id" action="update" id="iss_id" method="get"><?php
        $id_no = 0; // Zähler für array
          foreach ($partner AS $part) {
            if ($part->gender == 01) { $tr=$tr1;$gen="m";} else {$tr=$tr2;$gen="f";}
            echo $tr."<td>";?>
              <input type="radio" name="p_id" id="p_id" value="<?php echo $id_no;?>"<?php
              if ($p_id == $id_no) { echo "checked=checked";} ?> onchange="submit()" />&nbsp;</td><?php
                $id_no = $id_no + 1;
                echo "<td><strong><img src='../../img/".$gen.".jpg'>&nbsp</td>"
                ."<td>&nbsp<a href='update?id=".$part->member_id."'>"
                .$part->first_name." "
                .$part->last_name."</a></strong>&nbsp</td><td>&nbsp;&nbsp;"
                .$part->birth_name ."&nbsp;&nbsp;</td><td>"
                .$part->par_von ."&nbsp</td><td>&nbsp;"
                .$part->par_ort ."&nbsp;&nbsp;</td><td>"
                .$part->par_devorce ."</td></tr>";
          } ?>
      </form><?php
    } else { ?>
      <tr><td colspan="7" style="background-color:lightcyan";>keine Partner eingetragen!</td></tr><?php
            $_SESSION['message'] = "Kein Partner eingetragen!";
        }?>
  </table><?php
}
?>


<!--*************************** Eingabefelder **********************************-->
<?php
  if ($who == 01) { ?>
    <h3><strong>Person bearbeiten</strong></h3>
<!--     <table width="100%">
     <tr style="font-weight: bold;">
        <td width="100%" valign="top" align="left"></td>
      </tr> -->
<!--****************************** Eingabe Person ******************************-->
      <form method="post">
        <table>
          <tr style="font-weight: bold;">
            <td>Selection (who) </td><td>Member ID</td><td>gender</td><td>&nbsp;</td><td>&nbsp;</td>
          </tr>
          <tr>
            <td><input type="text" name="who" id="who"
                  value="<?php echo $who;?>" size="4" readonly ></td>
            <td><input type="text" name="member_id" id="member_id"
                value="<?php echo $row_m->member_id; ?>" size="4" readonly ></td>
            <td><input type="radio" name="gender" id="gender" size="4"
                value="01" <?php if ($m_gender == 01) {
                  echo "checked=\"checked\""; } ?> /> male &nbsp;
              <input type="radio" name="gender" id="gender" size="4"
                value="02" <?php if ($m_gender == 02) {
                  echo "checked=\"checked\""; } ?> /> female</td>

              <td><input type="checkbox" name="parent_id" id="parent_id"
                value='999' <?php if ($row_m->parent_id == 999) {
                  echo "checked=\"checked\""; } ?>/>&nbsp;parent</td>
          </tr>


          <tr style="font-weight: bold;">
            <td>first name</td><td>last name</td><td>birth name</td><td>member image</td>
          </tr>
          <tr>
            <td><input style="background-color:lightyellow";  type="text" name="first_name" id="first_name"
                  value="<?php if ($action == 01){
                    echo $row_m->first_name;}?>" placeholder="first name" size="20%"/>&nbsp;</td>

            <td><input style="background-color:lightyellow";  type="text" name="last_name" id="last_name"
                  value="<?php if ($action == 01){
                    echo $row_m->last_name;}?>" placeholder="last name" size="20%"/>&nbsp;</td>

            <td><input style="background-color:lightyellow";  type="text" name="birth_name" id="birth_name"
                value="<?php if ($action == 01){
                  echo $row_m->birth_name;}?>" placeholder="birth name"  size="20%" />&nbsp;</td>

            <td><input style="background-color:lightyellow";  type="text" name="member_img" id="member_img"
                  value="<?php if ($action == 01) {
                    echo $row_m->member_img;}?>" placeholder="img-no"  size="40%"/>&nbsp;</td>
          </tr>
          <tr style="font-weight: bold;">
            <td> * </td><td>in </td><td> † </td><td> in </td>
          </tr>
          <tr>
            <td><input style="background-color:lightyellow";  type="date" name="day_of_birth" id="day_of_birth"
                  value="<?php if ($action == 01){
                    echo $row_m->day_of_birth;}?>" placeholder="day" /></td>
            <td><input style="background-color:lightyellow";  type="text" name="place_of_birth" id="place_of_birth"
                  value="<?php if ($action == 01){
                    echo $row_m->place_of_birth;}?>" placeholder="place" size="15%"/>&nbsp;</td>
            <td><strong> </strong>
                <input style="background-color:lightyellow";  type="date" name="day_of_death" id="day_of_death"
                  value="<?php if ($action == 01){
                    echo $row_m->day_of_death; }?>" placeholder="day of death" /></td>
            <td><input style="background-color:lightyellow";  type="text" name="place_of_death" id="place_of_death"
                  value="<?php if ($action == 01){
                    echo $row_m->place_of_death;}?>" placeholder="place" size="15%"/></td>

          </tr>
          <tr style="font-weight: bold;">
            <td colspan="3">remarks</td>
          </tr>
            <td colspan="3">
              <input style="background-color:lightyellow"; type="text" name="remarks" id="remarks"
                value="<?php if ($action == 01){
                  echo $row_m->remarks;}?>" placeholder="remarks" size="80%" /></td>
            <td>
              <strong><span style="margin-left:10px;"></strong>
                <input style="background-color:yellow;" type="submit" name="submit"
                  value="<?php if ($action == 01) { echo "update";
                                           } else { echo "submit";}?>"/></td>
          </tr>
          <!-- Ende Tabelle innerhalb Form -->
        </form><!-- ***** Ende Form Personeneingabe -->
      <tr><td>&nbsp;</td></tr>
    </table>


<!-- ********************** Eltern auswählen ********************************-->
    <div class="col-sm-12">
      <div class="row">
        <!-- links -->
        <div class="col-sm-6">
          <div class="row">
            <div class="col-sm-12">
              <div class="well well-sm">
                <p style="background-color:lightcyan;font-weight: bold;"><?php echo "Bitte Daten der Eltern von ".$person['first_name']." wählen!"?></p>
                <table>
                  <!-- Auswahl Vater und Mutter -->
                  <tr>
                    <td><?php
                      $m_f = $person->father_id;
                      if ($m_f == 0) {
                        $m_f = 13;
                        $str_label = "Vater unbekannt!";
                      } else {
                        $str_label = "<a href='update?id=".$m_f."'><strong>Link zum Vater: ID=".$m_f."</a>";
                      }
                      $str_select_name ="va_id";
                      $gender = 1;
                      $m_f = select_parents($persons, $str_label, $str_select_name, $m_f, $gender);?>
                    </td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td> <?php
                      $m_m = $person->mother_id;
                      if ($m_m == 0) {
                        $m_m = 13;
                        $str_label = "Mutter unbekannt!";
                      } else {
                        $str_label = "<a href='update?id=".$m_m."'><strong>Link zur Mutter: ID=".$m_m."</a>";
                      }
                      $str_select_name ="ma_id";
                      $gender = 2;
                      $m_m = select_parents($persons, $str_label, $str_select_name, $m_m, $gender);?>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </div>

    <!-- ****************** Partnerdaten anzeigen **********************-->
      <!-- rechts -->
        <div class="col-sm-6">
          <div class="row">
            <div class="col-sm-12">
              <div class="well well-sm">
                <p style="background-color:lightcyan;font-weight: bold;"><?php echo "Daten des Partners von ".$person['first_name'];?></p>
                <table>
                    <tr style="font-weight: bold;">
                      <td> </td><td>G&nbsp;</td><td>&nbsp;Vor- Nachnamen</td><td>&nbsp;&nbsp;geb.</td><td><center>&nbsp;∞<center></td><td>&nbsp;Ort</td><td><?php echo "<center>&nbsp;⚮</center>"; ?></td>
                    </tr><?php
                    $id_no = 0;
                    if (count($partner) != 0) { ?>
                      <form name="iss_id" action="update" id="iss_id" method="get"><?php
                        $id_no = 0; // Zähler für array
                          foreach ($partner AS $part) {
                            if ($part->gender == 01) { $tr=$tr1;$gen="m";} else {$tr=$tr2;$gen="f";}
                            echo $tr."<td>";?>
                              <input type="radio" name="p_id" id="p_id" value="<?php echo $id_no;?>"<?php
                              if ($p_id == $id_no) { echo "checked=checked";} ?> onchange="submit()" />&nbsp;</td><?php
                                $id_no = $id_no + 1;
                                echo "<td><strong><img src='../../img/".$gen.".jpg'>&nbsp</td>"
                                ."<td>&nbsp<a href='update?id=".$part->member_id."'>"
                                .$part->first_name." "
                                .$part->last_name."</a></strong>&nbsp</td><td>&nbsp;&nbsp;"
                                .$part->birth_name ."&nbsp;&nbsp;</td><td>"
                                .$part->par_von ."&nbsp</td><td>&nbsp;"
                                .$part->par_ort ."&nbsp;&nbsp;</td><td>"
                                .$part->par_devorce ."</td></tr>";
                          } ?>
                      </form><?php
                    } else { ?>
                      <tr><td colspan="7" style="background-color:lightcyan";>keine Partner eingetragen!</td></tr><?php
                            $_SESSION['message'] = "Kein Partner eingetragen!";
                        }?>
                  </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <?php
  }   // end who=1 ?>
<!-- ************************** Ende Person bearbeiten *************************-->

<!-- ******************** Begin Partner ****************************************-->
  <div> <?php
    $bol_submit = 0;
    if ($who == 02) {
      $_SESSION['message'] = "Update Partner!";
      if (($action == 01) AND (count($partner) == 0)) {
        $_SESSION['message'] = "Message: kein Partner eingetragen!";
      }
      if ($action == 2) {
        foreach ($partner as $par) {
          if (($par['man_id']==$id_part_new) OR ($par['woman_id']==$id_part_new)) {
            $bol_submit = 1;
            $_SESSION['message'] = "Partner bereits eingetragen!";

            if ($person->member_id == $id_part_new) {
              $_SESSION['message'] = "Partner muss ungleich Person sein!";
              $bol_submit = 1;
            }
          }
        }
        $_SESSION['message'] = "Insert new Partner!";
        $str_label = "PartnerIn: (new)";
        $str_get_id = "id_part_update";
      }?>
  </div>

    <hr>

    <form method="post">
      <h3><strong>Partnerdaten bearbeiten</strong></h3>
      <table>
        <tr>
          <td colspan="4" style="background-color:lightcyan;font-weight:bold;"><?php echo "Bitte Daten des Partners von ".$person['first_name']." eingeben!"?></td>
        </tr>
        <tr>
          <td>selection (who)&nbsp;</td><td>update id</td><td>member id</td><td>woman_id</td><td>married on ⚮</td><td>place</td><td>date  ∞ </td>
        </tr>
        <tr>
          <td><input type="text" name="who" id="who"
                value="<?php echo $who;?>" size="4" readonly ></td>
          <td><input type="text" name="par_id" id="par_id"
                value="<?php  if (count($partner)!=0) {if ($action == 01){echo $partner["$p_id"]["par_id"];}}?>" size="10%" readonly >&nbsp;</td>
          <td><input style="background-color:lightyellow"; type="text" name="man_id" id="man_id"
                value="<?php if (count($partner)!=0) { if ($action == 01){echo $partner["$p_id"]["man_id"];}}
                             if (($action == 02) AND ($m_gender == 1)) {echo $person_id;}
                             if (($action == 02) AND ($m_gender == 2)) {echo $id_part_new;}?>" placeholder="man_id"  size="10%" readonly />&nbsp;</td>
          <td><input style="background-color:lightyellow"; type="text" name="woman_id" id="woman_id"
                value="<?php  if (count($partner)!=0) { if ($action == 01){echo $partner["$p_id"]["woman_id"];}}
                             if (($action == 02) AND ($m_gender == 2)) {echo $person_id;}
                             if (($action == 02) AND ($m_gender == 1)) {echo $id_part_new;}?>" placeholder="wom_id"  size="10%"/>&nbsp;</td>
          <td><input style="background-color:lightyellow"; type="date" name="par_von" id="par_von"
                value="<?php if ($action == 01){echo $partner["$p_id"]["par_von"];}?>" placeholder="date"  size="20%" />&nbsp;</td>
          <td><input style="background-color:lightyellow"; type="text" name="par_ort" id="par_ort"
                value="<?php  if (count($partner)!=0) { if ($action == 01){echo $partner["$p_id"]["par_ort"];}}?>" placeholder="ort"  size="20%" />&nbsp;</td>
          <td><input style="background-color:lightyellow"; type="date" name="par_devorce" id="par_devorce"
                value="<?php if ($action == 01){echo $partner["$p_id"]["par_devorce"];}?>" placeholder="date"  size="20%" />&nbsp;</td>
        </tr>
        <tr><?php
          if ($bol_submit == 0) { ?>
            <td style="background-color:lightcyan";>
                <input style="background-color:yellow;" type="submit" name="submit"
                  value="<?php if ($action == 01) {
                                if (count($partner)!=0) {
                                  echo "update";} else { echo "no update possible";}
                                } else { echo "submit";}?>"/>

            </td>  <?php
              } else { ?>
            <td style="background-color:red";>
                  <input style="background-color:yellow;" type="text" name=""
                  value="<?php if ($action == 01) {
                             echo "update gesperrt!";
                           } else {
                             echo "submit gesperrt!";}?>"/></td>
          </tr>
          <tr>
            <td><?php
                } ?>
        </form><?php

              if ($action == 02) {
                $str_label = "new partner: ";
                $str_get_id = "id_part_new";
                select_partner($persons, $str_label, $str_get_id, $id_part_new);
              }
            } ?>
            </td>
          </tr>
        </table>
        <hr>
      </td>
<!-- *************************** Ende td linke Seite ***************************-->
<!-- ************************** Beginn Ereignisse ******************************-->
      <div><?php
        if (($who == 03)) {
          $_SESSION['message'] = "Update issues or insert new!"; ?>
            <h3><strong>Ereignisse bearbeiten</strong></h3>
            <table>
              <tr>
              <!-- <tr style="font-weight:bold; background-color:lightgrey"> -->
              <?php  echo $tr0;?>
                <td></td><td>ID</td><td>&nbsp;Member</td><td>&nbsp;Datum</td><td>&nbsp;Ereignis</td>
              </tr><?php //felder_ereignisse();
              $id_no = 0; ?>
              <form name="iss_id" action="update" id="iss_id" method="get"><?php
                $id_no = 0; // Zähler für array
                foreach ($ereignisse AS $key => $issue) {
                  echo $tr0;?>
                    <td>
                      <input type="radio" name="iss_id" id="iss_id" value="<?php echo $id_no;?>"<?php
                        if ($iss_id == $id_no) { echo "checked=checked";} ?> onchange="submit()" />&nbsp;
                    </td><?php
                    $id_no = $id_no + 1;
                    foreach ($issue AS $key1 => $data) {
                      echo "<td>&nbsp".$data."&nbsp;</td>";
                    }
                  echo "</tr>";
                } ?>
              </form>
            </table>
          </br>

          <form method="post">
            <table>
              <tr>
                <td></td><td>ID &nbsp;</td><td>Member ID</td><td></td><td>date</td><td>issue</td>
              </tr>
              <tr>
                <td><input type="hidden" name="who" id="who"
                    value="<?php echo $who; ?>" size="10%" readonly/></td>
                <td><input type="text" name="issue_id" id="issue_id"
                    value="<?php if ($action == 01){echo $ereignisse["$iss_id"]["issue_id"];}?>" size="10%" readonly >&nbsp;</td>
                <td><input type="text" name="member_id" id="member_id"
                    value="<?php echo $row_m->member_id; ?>" size="10%" readonly/>&nbsp;</td>
                <td><input type="hidden" name="member_id_f" id="member_id_f"
                    value="<?php
                      if ($action == 01){
                            echo $ereignisse["$iss_id"]["member_id_f"];
                      } else {
                            echo $person_id;}?>" placeholder="member_id"  size="10%" readonly />&nbsp;</td>
                <td><input style="background-color:lightyellow"; type="date" name="issue_date" id="issue_date"
                    value="<?php if ($action == 01){
                      echo $ereignisse["$iss_id"]["issue_date"];}?>" placeholder="date"  size="10%"/>&nbsp;</td>
                <td><input style="background-color:lightyellow"; "width:100%"; type="text" name="issue" id="issue"
                    value="<?php if (count($ereignisse)!=0) {
                    if ($action == 01){
                      echo $ereignisse["$iss_id"]["issue"];}}?>" placeholder="issue"  size="70%"/>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="4">&nbsp;</td>
                <td><input style="background-color:yellow;" type="submit" name="submit"
                    value="<?php if ($action == 01) {
                      if (count($ereignisse)!=0) {
                            echo "update";} else { echo "no update possible";}
                          } else {
                            echo "submit";}?>"/></td>
              </tr>
              </form>
            </table>
            <hr><?php
        } // dauerhafte Anzeige ?>
      </div>
<!-- ***************************** Ende Ereignisse *****************************-->

<!-- ***************************** Beginn Wohnorte *****************************-->
      <div><?php
        $person_id = $person->member_id;
        if (($who == 04)) {
          $_SESSION['message'] = "Update place or insert new!"; ?>
          <h3><strong>Wohnorte bearbeiten</strong></h3>
          <table>
            <tr style="font-weight: bold; background-color:lightgrey">
              <td>s &nbsp;</td><td>&nbsp;ort</td><td>&nbsp;von</td><td>&nbsp;bis</td><td>&nbsp;m</td><td>&nbsp;adr</td>
              <td>&nbsp;PLZ</td><td>&nbsp;Ort</td><td>&nbsp;Strasse</td>
            </tr><?php
            $id_o_no = 0; ?>
            <form name="w_ort_id" action="update" id="w_ort_id" method="get"><?php
              //$id_o_no = 0; // Zähler für array
              $felder_wohnort = "";
              $anzahl = count($wohnorte);   // Anzahl Wohnorte
              echo "Anzahl Wohnorte: ".$anzahl ."<br";
              $felder_wohnorte = "";
              $orte = array();
              $wohnort = array();
              if ($anzahl != 0) {  // Anzahl > 0 dann
                foreach ($wohnorte as $mem) {
                  $bis = $mem->ort_bis;
                  if ($bis==0) {$bis = "heute"; }
                  $wohnort = [
                    'ort_id' => $mem->ort_id,
                    'ort_von' => $mem->ort_von,
                    'ort_bis' => $bis,  //$mem->ort_bis,
                    'member_id_f' => $mem->member_id_f,
                    'adr_id_f' => $mem->adr_id_f,
                    'adr_plz' => $mem->adr_plz,
                    'adr_ort' => $mem->adr_ort,
                    'adr_strasse' => $mem->adr_strasse];
                  $orte[] = $wohnort;
                }
              }

              $id_o_no = 0; ?>
              <form name="w_ort_id" action="update" id="w_ort_id" method="get"><?php
                $id_o_no = 0; // Zähler für array
                if ($anzahl != 0) {  // Anzahl > 0 dann auslesen
                  foreach ($orte AS $key => $ort) {
                    echo $tr0;?>
                      <td>
                        <input type="radio" name="w_ort_id" id="w_ort_id" value="<?php echo $id_o_no;?>"<?php
                          if ($w_ort_id == $id_o_no) {
                            echo "checked=checked";} ?> onchange="submit()" />
                      </td><?php
                      $id_o_no = $id_o_no +1;
                      foreach ($ort AS $key1 => $data) {
                        echo "<td>&nbsp;".$data."&nbsp;</td>";
                      }
                    echo "</tr>";
                  }
                } else {
                  echo $tr0 . "<td colspan=\"4\"> Keine Wohnorte erfasst!</td></tr>";
                } ?>
              </form>
          </table>
        </br>
          <table>
            <tr><?php
            if ($action == 2) {
              $str_label="neuer Ort: ";
              select_adress($adressen, $id_place, $str_label);
            } ?>
            <form method="post">
              <td>Select (who)&nbsp;</td><td>id</td><td>member_id_f</td><td>adr_id</td><td>von</td><td>bis</td>
            <tr>
              <td><input type="text" name="who" id="who"
                value="<?php echo $who; ?>" size="5%" readonly/></td>
              <td><input type="text" name="ort_id" id="ort_id"
                  value="<?php if ($action == 01){echo $orte["$w_ort_id"]["ort_id"];}?>" size="5%" readonly >&nbsp;</td>
              <td><input type="text" name="member_id_f" id="member_id_f"
                  value="<?php
                    if ($action == 01){
                      echo $orte["$w_ort_id"]["member_id_f"];}
                              else {
                      echo $person_id;}?>" placeholder="member_id"  size="10%" readonly />&nbsp;</td>
              <td><input type="number" name="adr_id_f" id="adr_id_f" type="number" min="1" max="999"
                  value="<?php if ($action == 01){
                    echo $orte["$w_ort_id"]["adr_id_f"];}
                        else{
                    echo $id_place;}?>" placeholder="adr"  size="10%"/>&nbsp;</td>

              <td><input style="background-color:lightyellow"; type="date" name="ort_von" id="ort_von"
                  value="<?php if ($action == 01){
                    echo $orte["$w_ort_id"]["ort_von"];}?>" placeholder="date"  size="10%"/>&nbsp;</td>

              <td><input style="background-color:lightyellow"; type="date" name="ort_bis" id="ort_bis"
                  value="<?php if ($action == 01){
                    echo $orte["$w_ort_id"]["ort_bis"];}?>" placeholder="date"  size="10%"/>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="4">&nbsp;</td>
                <td><input style="background-color:yellow;" type="submit" name="submit"
                    value="<?php if ($action == 01) {
                      if (count($orte) != 0 ){echo "update";}}
                      else {echo "submit";}?>"/></td>
              </tr>
            </table>
          </form>
          <hr><?php
        }     // Ende  $felder_wohnorte ?>
      </div>
<!-- ***************************** Ende Wohnorte *******************************-->

<!-- ***************************** Beginn Adressen *****************************-->
      <div><?php
        if (($who == 05)) {
          $_SESSION['message'] = "Update adress or insert new!"; ?>
          <h3><strong>Adressen bearbeiten</strong></h3>
          <form method="post">
            <table>
              <tr>
                <td>Select (who)&nbsp;</td><td>adr id</td><td>PLZ</td><td>Ort</td><td>Land</td><td>Str</td><td>&nbsp; </td>
              </tr>
              <tr>
                <td><input type="text" name="who" id="who"
                  value="<?php echo $who; ?>" size="5%" readonly/></td>
                <td><!--<strong>id = </strong></td> -->
                    <input type="text" name="adr_id" id="adr_id"
                      value="<?php if ($action == 01){echo $adressen["$id_adr"]["adr_id"];}?>" size="5%" readonly >&nbsp;</td>
                <td><input style="background-color:lightyellow"; type="text" name="adr_plz"  id="adr_plz"
                      value="<?php if ($action == 01){echo $adressen["$id_adr"]["adr_plz"];}?>" placeholder="plz"  size="5%"/>&nbsp;</td>
                <td><input style="background-color:lightyellow"; type="text" name="adr_ort" id="adr_ort"
                      value="<?php if ($action == 01){echo $adressen["$id_adr"]["adr_ort"];}?>" placeholder="ort"  size="20%"/>&nbsp;</td>
                <td><input style="background-color:lightyellow"; type="text" name="adr_land" id="adr_land"
                      value="<?php if ($action == 01){echo $adressen["$id_adr"]["adr_land"];}?>" placeholder="country"  size="20%"/>&nbsp;</td>
                <td><input style="background-color:lightyellow"; type="text" name="adr_strasse" id="adr_strasse"
                      value="<?php if ($action == 01){echo $adressen["$id_adr"]["adr_strasse"];}?>" placeholder="str"  size="30%" />&nbsp;</td>
              </tr>
              <tr>
                <td colspan = "4"></td>
                <td><input style="background-color:yellow";  type="submit" name="submit"
                    value="<?php if ($action == 01) { echo "update";} else { echo "submit";}?>"/></td>
              </tr>
            </table>
          </form>
          </br>
          <table>
            <tr style="font-weight: bold; background-color:lightgrey;">
              <td>&nbsp; </td><td>&nbsp;id &nbsp;</td><td>PLZ&nbsp;</td><td>Ort&nbsp;</td><td>Strasse&nbsp;</td><td>Land&nbsp;</td><td>phone</td>
            </tr><?php
            //  adressen();
            $id_a_no = 0; ?>
            <form name="id_adr" action="update" id="id_adr" method="get"><?php
              $id_a_no = 0; // Zähler für array
              foreach ($adressen AS $key => $adr) { ?>
                <tr>
                  <td><input type="radio" name="id_adr" id="id_adr" value="<?php echo $id_a_no;?>"<?php
                    if ($id_adr == $id_a_no) { echo "checked=checked";} ?>  onchange="submit()" />
                  </td><?php
                  $id_a_no = $id_a_no + 1;
                  foreach ($adr AS $key1 => $data) {
                    echo "<td>&nbsp;".$data."&nbsp;</td>";
                  } ?>
                </tr><?php
              } ?>
            </form>
          </table>
          <hr><?php
        }?>
      </div>
<!-- ************************** Ende Adressen bearbeiten ***********************-->

<!-- ************************** Beginn Bemerkungen bearbeiten ******************-->
      <div><?php
        if ($who == 06) {
          if ($action == 1) {$_SESSION['message'] = "Update remarks";} else {
            $_SESSION['message'] = "insert new remark";} ?>
              <h3><strong>Bemerkungen zu Person bearbeiten</strong></h3>
              <form method="post">
              <table>
                <tr>
                  <td>Select (who)&nbsp;</td><td>id</td><td>rem id</td><td>id_f</td><td>date</td><td>remark</td><td>erledigt</td>
                </tr>
                <tr>
                  <td><input type="text" name="who" id="who"
                    value="<?php echo $who; ?>" size="5%" readonly/></td>
                  <td><input type="text" name="member_id" id="member_id"
                      value="<?php echo $row_m->member_id; ?>" size="5%" readonly />&nbsp;</td>
                  <td><input type="text" name="rem_id" id="rem_id"
                      value="<?php if ($action == 01){
                        echo $bemerkungen["$bem_id"]["rem_id"];}?>" size="5%" readonly >&nbsp;</td>
                  <td><input type="text" name="member_id_f" id="member_id_f" value="<?php
                    if ($action == 01){
                      echo $bemerkungen["$bem_id"]["member_id_f"];
                    } else {
                      echo $person_id;}?>" placeholder="member_id_f"  size="5%" readonly />&nbsp;</td>
                  <td><input style="background-color:lightyellow"; type="date" name="rem_date" id="rem_date"
                      value="<?php if ($action == 01){echo $bemerkungen["$bem_id"]["rem_date"];}?>" placeholder="date"  size="15%" />&nbsp;</td>
                  <td><input style="background-color:lightyellow"; style="width:100%" type="text" name="rem_remark" id="rem_remark"
                      value="<?php
                      if ($action == 01){
                        if (count($bemerkungen)!=0) {
                          echo $bemerkungen["$bem_id"]["rem_remark"];}}?>" placeholder="remark"  size="70%" />&nbsp;</td>
                  <td><input style="background-color:lightyellow"; style="width:100%" type="text" name="rem_erl" id="rem_erl"
                      value="<?php
                      if ($action == 01){
                        if (count($bemerkungen)!=0) {
                          echo $bemerkungen["$bem_id"]["rem_erl"];}}?>" placeholder="erl"  size="5%" />&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="4"></td>
                  <td><input style="background-color:yellow;" type="submit" name="submit"
                      value="<?php if ($action == 01) {
                                    if (count($bemerkungen)!=0) {
                                      echo "update";}else {echo "update not possible";}
                                    } else { echo "submit";}?>"/></td>
                </tr>
                </form>
              </table>
              </br>

              <table>
                <tr style="font-weight:bold; background-color:lightgrey">
                  <td>&nbsp;</td><td>&nbsp;ID</td><td>&nbsp;Datum</td><td>&nbsp;Bemerkung</td>
                  <td>&nbsp;id_f</td><td>&nbsp;erl</td>
                </tr><?php
                //felder_ereignisse();
                $id_no = 0;
                $person_id = $person->member_id; ?>
                <form name="bem_id" action="update" id="bem_id" method="get"><?php
                  $id_no = 0; // Zähler für array
                  foreach ($bemerkungen AS $key => $issue) {
                    echo $tr0; ?>
                      <td><input type="radio" name="bem_id" id="bem_id" value="<?php echo $id_no;?>"<?php
                         if ($bem_id == $id_no) { echo "checked=checked";} ?> onchange="submit()" /></td><?php
                      $id_no = $id_no +1;
                      foreach ($issue AS $key1 => $data) {
                        echo "<td>&nbsp;".$data."&nbsp;</td>";
                      }
                    echo "</tr>";
                  } ?>
                </form>
            </table><?php
          } ?>
      </div>
      </td> <!-- Ende rechte Seite -->
    </tr>
  </table><!-- Ende Tabelle Eingabefelder Haupt-Tabelle-->
  <?php

  if ($who == 7) {?>
    <hr>
    <div>
      <h3><strong>User bearbeiten (nur für admin)</strong></h3>
    </div><?php
  }?>
</div>
<!-- ****************************** Ende Eingaben *******************************-->
<!-- ***************************************************************************-->
<!-- ******************************* Kinder und Geschwister ********************-->

<!-- *********************** Beginn Block *******************************-->
<div class="col-sm-12">
  <div class="row">
    <!-- links -->
    <div class="col-sm-6">
      <div class="row">
        <div class="col-sm-12">
          <div class="well well-sm">
            <p style="background-color:lightcyan;font-weight: bold;"><?php echo "Kinder von ".$person['first_name']." (Person)"?></p>
            <table>
              <tr style="font-weight: bold;">
                <td>G&nbsp;</td><td>Vor- Nachname&nbsp;</td><td>geb.&nbsp;</td>
                <td><center>*</center></td><td>&nbsp;Ort&nbsp;</td><td><center>†</center></td>
              </tr><?php
                if (count($children) != 0) {
                    $id = $person->member_id;
                    fill_line($children,$id,$link);
                } else { ?>
                    <tr><td colspan="5" style="background-color:lightcyan";>kein Kind eingetragen!</td></tr><?php
                }?>
            </table>
          </div>
        </div>
      </div>
    </div>

<!-- ****************** Partnerdaten anzeigen **********************-->
  <!-- rechts -->
    <div class="col-sm-6">
      <div class="row">
        <div class="col-sm-12">
          <div class="well well-sm">
            <p style="background-color:lightcyan;font-weight: bold;"><?php echo "Geschwister von ".$person['first_name']." (Person)"?></p>
            <table>
                <tr style="font-weight: bold;">
                  <td>G&nbsp</td><td>Vor- Nachname</td><td>geb.</td>
                  <td><center>*</center></td><td>Ort</td><td><center>†</center></td>
                </tr><?php
                  if (count($siblings) != 0) {
                    $id = $person->member_id;
                    fill_line($siblings,$id,$link);
                  } else { ?>
                    <tr><td colspan="3" style="background-color:lightcyan";>keine Ereignisse eingetragen!</td></tr><?php
                  } ?>
              </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- *********************** Blockende ***********************************************-->


    <!-- *********************** A D M I N *****************************************-->
    <!-- *** D E B U G wird nur angezeigt wenn $bol_debug = true ( in const.php)****-->
<div class="col-sm-12">
  <div class="row">
    <div class="col-sm-6">
      <div class="row">
        <div class="col-sm-12">
          <div class="well well-sm">
            <p style="background-color:lightcyan";><?php echo "SESSION: ".$_SESSION['message']; ?></p><?php
            echo "Person: ".$person_id.";  who: ".$who."; action ".$action."; Partner-No: ".$p_id
            ."; Neuer Partner: ".$id_part_new."; Update Partner: ".$id_part_update."; Tab-Pos.: ".$iss_id
            ."; Bemerkungen ".$bem_id."; Adresse: ".$id_place."; Wohnorte-Tab.: ".$w_ort_id."; Adresse: ".$id_adr."; ";?>
          </div>
        </div>
      </div>
    </div>

<!-- *** D E B U G wird nur angezeigt wenn $bol_debug = true ( in const.php)****-->
    <div class="col-sm-6">
      <div class="row">
        <div class="col-sm-12">
          <div class="well well-sm"><?php
            if ($bol_debug == true) { ?>
              <p style="background-color:lightcyan";><?php echo "Debug Info: "; ?></p><?php
              echo "GET: "; var_dump($_GET);
              echo "SESSION: "; var_dump($_SESSION);
              if ($who == 2) {
                echo "id_part_new: ".$id_part_new." - &nbsp;"
                ."person_id: ".$person->member_id." - &nbsp;"
                ."person_gender: ".$person->gender."</br>";
                echo "bol_submit: ".$bol_submit. "</br>";
              }
            }?>
          </div>
        </div>
      </div>
    </div>

  </div>
</div><?php

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