<?php

namespace App\Person;

use App\Core\AbstractRepository;


class PersonRepository extends AbstractRepository
{

  public function getTableName() {
    return "gen_member";
  }

  public function getModelName() {
    return "App\\Person\\PersonModel";
  }

  public function insertForPerson() {
      $table = $this->getTableName();
      $model = $this->getModelName();

      $member_id = test_input($_POST['member_id']);
      $gender = test_input($_POST['gender']);
      $parent_id = test_input($_POST['parent_id']);
      //if ($parent_id = 999){$parent_id = null;}
      $first_name = test_input($_POST['first_name']);
      $last_name = test_input($_POST['last_name']);
      $birth_name = test_input($_POST['birth_name']);
      $day_of_birth = test_input($_POST['day_of_birth']);
      $place_of_birth = test_input($_POST['place_of_birth']);
      $day_of_death = test_input($_POST['day_of_death']);
      $place_of_death = test_input($_POST['place_of_death']);
      $remarks = test_input($_POST['remarks']);
      $member_img = test_input($_POST['member_img']);

      if ($_POST['submit'] == "update") {
        $strSQL = "UPDATE gen_member SET
                  gender='".$gender."',
                  parent_id='".$parent_id."',
                  first_name='".$first_name."',
                  last_name='".$last_name."',
                  birth_name='".$birth_name."',
                  day_of_birth='".$day_of_birth."',
                  place_of_birth='".$place_of_birth."',
                  day_of_death='".$day_of_death."',
                  place_of_death='".$place_of_death."',
                  remarks='".$remarks."',
                  member_img='".$member_img."'
                  WHERE member_id='".$member_id."'";
      }
      if ($_POST['submit'] == "submit") {
        $strSQL = "INSERT INTO gen_member
                  (gender, parent_id, first_name, last_name, birth_name,
                  day_of_birth, place_of_birth, day_of_death, place_of_death, remarks, member_img)
                  VALUES ('".$gender."','".$parent_id."','".$first_name."', '".$last_name."', '".$birth_name."',
                          '".$day_of_birth."', '".$place_of_birth."',
                          '".$day_of_death."', '".$place_of_death."', '".$remarks."', '".$member_img."')";
      }
      //echo $strSQL; die;
      $stmt = $this->pdo->prepare($strSQL);
      $stmt->execute();
  }

// Funktion setzt male.jpg oder female.jpf wenn kein Bild vorganden
/*
  public function insertPicture($member_id, $img) {
      $table = $this->getTableName();
      $model = $this->getModelName();

      $strSQL = "UPDATE gen_member SET
                member_img='".$img."'
                WHERE member_id='".$member_id."'";

      echo $strSQL;
      //die;
      $stmt = $this->pdo->prepare($strSQL);
      $stmt->execute();
  }
*/
}

 ?>
