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

  include __DIR__ . "/../layout/css/navi.css";
  include __DIR__ . "./../inc/function_display.inc.php";
  include __DIR__ . "/../layout/css/default.css";?>

  </style> <!-- Script to print the content of a div -->
    <script>
      function printDiv() {
        var divContents = document.getElementById("Druck").innerHTML;
        var a = window.open('', '', 'height=500, width=800');
        a.document.write('<html>');
        a.document.write('<body style="margin-left:30px"><h4>Famielienblatt von:</h4>');
        a.document.write(divContents);
        a.document.write('</body></html>');
        a.document.close();
        a.print();
      }
    </script>
  </head><?php
	$font_size = "small";
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
		$font_size = "x-small";
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera'))
		$font_size = "small";
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac'))
		$font_size = "medium";
  ?>
<body style="font-size:<?php echo $font_size;?>"><?php
  global $nbm, $nbf, $nbu, $tr0, $tr1, $tr2, $ladezeit, $link,
  $link_edit_part;
  $link = "familienblatt?id=";
  $link_new = "";
  $link_edit_pers = "";
  $link_edit_part = "";
  $link_insert = "";
  $str_login = "Sie sind nicht eingelogt";
  if (isset($_SESSION['rechte'])){
    $str_login = "Sie sind eingelogt als 'user'";
    if ($_SESSION['rechte'] == "admin"){
      $link_new = "update?who=01&action=02";          // neue Person
      $link_edit_pers = "update?who=1&action=01";     // edit Person
      $link_edit_part = "update?who=2&action=01&id="; // edit Partner-Daten
      $link_insert = "update?who=2&action=02";        // neuer Partner
      $str_login = "Sie sind eingelogt als 'admin'";
    }
  }


function line_up($input,$id,$bol) {  //Darstellung in einer Zeile
  global $link, $link_edit_part;
  if (isset($input[0]->member_id)) {
    foreach ($input as $row) {?>
      <div class="child"><?php
        $gender = $row->gender;
        if ($row->gender == 01) { $gen="m";} else {$gen="f";}
        if ($row->birth_name != ""){$n_name = $row->birth_name;}else{$n_name = "";}
        //echo $row->last_name." - ".$row->birth_name." - ".$n_name;
        if ($row->member_id != $id) {?>
          <img border='0' src='./../../img/<?php echo $gen;?>.jpg' alt='sex' height='14' />
            <a href="<?php echo $link.$row->member_id?>"><?php
              echo $row->first_name." ".$row->last_name."</a>&nbsp;";
              if ($row->birth_name != ""){echo "(".$row->birth_name.")";}
              echo "&nbsp; * "
              .date_german($row->day_of_birth). "&nbsp;&nbsp;in ".$row->place_of_birth. "&nbsp;";
              if ($row->day_of_death >= 1){
                echo "&nbsp;&nbsp;&nbsp;&nbsp;† ".date_german($row->day_of_death)
                ." in ".$row->place_of_death;
              }
        }

        if ($_SESSION['rechte'] == "admin"){ // Editieren nur für admin?>
          <div id="options">
            <a href="<?php echo $link_edit_part.$row->member_id?>">edit</a>
          </div><?php
        }
        if ($bol == true){    // Heiratsdaten anzeigen, editieren zulassen
          echo "</br><strong>∞</strong> am: "
          .date_german($row->par_von) ."&nbsp; in "
          .$row->par_ort ."&nbsp;";
          if ($row->par_devorce >= 1) {
            echo " ⚮ geschieden am: ".$row->par_devorce;}
        }?>
        </div><?php
      } // end foreach
    } else {
    echo "</br>Keine Personen erfasst!";
  }
} // End function?>

<!-- ********************** main ***********************************************-->
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-4 ">
      <div id="useroptions"><?php
        $str_label = "Bitte Person wählen: "; //$id = $person->member_id;
        select_person($str_label, $person, $persons); ?>
      </div>
    </div>

    <div class="col-sm-5 ">
      <div id="useroptions">
        <ul><?php
          if (isset($_SESSION['rechte'])){                // admin rechte
            if ($_SESSION['rechte'] == "admin") {?>
              <li><a href="<?php echo $link_new;?>" title="nur für admin!">Neue Person erfassen</a></li><?php
            }
          } ?>
          <li>&nbsp;&nbsp;<?php echo $str_login;?></li>
        </ul>
      </div>
    </div>

    <div class="col-sm-3 ">
      <div id="options">
        <strong>Aktueller Stand:</strong></br>
        <p style="background-color:lightyellow;"><?php
          echo count ($persons)." Pers. (".
            "<img src='../../img/m.jpg'>".$nbm.",   ".
            "<img src='../../img/f.jpg'>".$nbf.",   ".
            "<img src='../../img/g.jpg'>".$nbu ;?>
        </p>
      </div>
    </div>
  </div>
</div>
<!-- ***************************************************************************-->

<!-- ************************* Menue *******************************************-->
<div id="options">
  <form>
    <input type="button" value=" drucken " onClick="javascript:printDiv()">
  </form>
</div>
<!--********************************** Person **********************************-->
<div  id="Druck">   <!-- Beginn des Druckbereichs -->
  <div id="name">
    <h2 class="text-center"><strong><?php
    if ($person->gender == 01) { $gen="m";} else { $gen="f";}?>
    <img border='0' src='./../../img/<?php echo $gen;?>.jpg' alt='M' height='20' /><?php
      echo $person->first_name." ".$person->last_name;
      if ($person->birth_name <> "") {
        echo ", geb. ".$person->birth_name;}?></strong><?php echo " - ID:".$person->member_id;?></h2>
  </div>
  <div id="bd">
    <div class="birth"><?php
      echo "geboren am ".date_ged($person->day_of_birth)." in ".$person->place_of_birth;?>
    </div>
    <div class="death"><?php
      if ($person->day_of_death != 0) {
      echo "gestorben am ".date_ged($person->day_of_death)." in ".$person->place_of_death;}?>
    </div>
  </div>
  </br><hr>

<!--********************************* Eltern ***********************************-->
  <div class="children"><strong>Eltern von <?php echo $person->first_name;?></strong><?php
    $id = $person->member_id;
    $parents = array();
    $parents[]=$father;
    $parents[]=$mother;
    $bol = false;                 // keine Hochzeitsdaten
    line_up($parents, $id, $bol); ?>
  </div>
<!--******************************** Kinder ************************************-->
  <div id="children"><strong>Kinder von <?php echo $person->first_name;?></strong><?php
    $id = $person->member_id;
    $bol = false;                 // keine Hochzeitsdaten
    line_up($children, $id, $bol); ?>
  </div>
  <!--****************************** Geschwister *******************************-->
  <div id="siblings"><strong>Geschwister von <?php echo $person->first_name;?></strong><?php
    $id = $person->member_id;
    $bol = false;                 // keine Hochzeitsdaten anzeigen
    line_up($siblings, $id, $bol); ?>
  </div>
  <div id="siblings"><strong>Ehe(partner) von <?php echo $person->first_name;?></strong><?php
    $id = $person->member_id;
    $bol = true;                 // keine Hochzeitsdaten
    line_up($partner, $id, $bol); ?>
  </div>
</div> <!-- Ende des Druckbereichs -->
<hr>
<!--******************************** Ehepartner ********************************-->

<!-- ************************ Ende Kopfzeile ***********************************-->
<!-- div id="GFG" style="background-color: green;" -->
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <div class="well well-sm">
        <strong>Ereignisse</strong></br>
        <table style="width:100%;">
          <tr style="font-weight:bold; background-color:lightgrey;">
            <td>ID&nbsp;</td><td>Datum</td><td>Ereignis</td>
          </tr><?php
          if (count($ereignisse) != 0) {
            foreach ($ereignisse as $issue) {
              echo $tr0."<td>"
              .$issue->issue_id ."&nbsp;</td><td>&nbsp;"
              .$issue->issue_date ."&nbsp;</td><td>&nbsp;"
              .$issue->issue ."</td></tr>";
            }
          } else { ?>
            <tr><td colspan="3" style="background-color:lightcyan;">keine Ereignisse eingetragen!</td></tr><?php
          } ?>
          </table>
        </div><?php
        ?>
      </div>
<!-- **************************** Rechte Seite *********************************-->
      <div class="col-sm-6">
        <div class="well well-sm">
          <strong>Wohnorte</strong></br>
          <table style="width: 100%;">
            <tr style="font-weight:bold; background-color:lightgrey;">
              <td>bis&nbsp</td><td>PLZ&nbsp</td><td>Ort&nbsp</td><td>Strasse</td></tr><?php
                if (count($wohnorte) != 0) {
                  foreach ($wohnorte as $ort) {
                    echo $tr0."<td>";
                    $bis = $ort->ort_bis;
                    if ($bis==0) {$bis = "heute"; }
                    echo $bis."&nbsp</td><td>"
                    .$ort->adr_plz ."&nbsp</td><td>"
                    .$ort->adr_ort ."&nbsp</td><td>"
                    .$ort->adr_strasse ."</td></tr>";
                  }
                } else { ?>
                  <tr><td colspan="4" style="background-color:lightcyan;">keine Wohnorte eingetragen!</td></tr><?php
            } ?>
          </table>
        </div>
      </div>
      <div class="col-sm-12 "><?php
        if (isset($_SESSION['rechte'])){                // admin rechte
          if ($_SESSION['rechte'] == "admin") {?>
            <div class="well well-sm">
              <strong>Bemerkungen</strong></br>
              <table style="width: 100%;">
                <tr style="font-weight: bold; background-color:lightgrey;">
                  <td>ID&nbsp;</td><td>Datum&nbsp;&nbsp;</td><td>Bemerkung</td>
                </tr><?php
                  if (count($bemerkungen) != 0) {
                    foreach ($bemerkungen as $bem) {
                      echo $tr0."<td>"
                        .$bem->rem_id ."&nbsp;</td><td>&nbsp;"
                        .$bem->rem_date ."&nbsp;</td><td>&nbsp;"
                        .$bem->rem_remark ."</td></tr>";
                    }
                  } else { ?>
                    <tr><td colspan="3" style="background-color:lightcyan;">keine Bemerkung eingetragen!</td></tr><?php
                  } ?>
                </table>
              </div><?php
            }
          } ?>
      </div>
    </div>
  </div>
  <?php

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