<?php #lnk/xx_fahrzeuge_einweisungen/class.php

class Fahrzeuge_EinweisungenLink extends BaseLink
{
  public function __construct($database, $keyvaluestore, $manager, $info, $page) {
    parent::__construct($database, $keyvaluestore, $manager, $info, $page);
  }
  
  protected function insert($ids) {
    if ($ids["Fahrzeuge"]==null || $ids["Personal"]==null) {
      return 400;
    }
    if (!$this->man->user->HasRight($this->adminRight)) {
      return 403; // You shall not pass!
    }
    
    $qry = "INSERT INTO Fahrzeuge_Einweisungen (Personal, Fahrzeuge) VALUES (?, ?)";
    if ($stmt = $this->db->prepare($qry)) {
      $stmt->bind_param("ii", $ids["Personal"], $ids["Fahrzeuge"]);
      $stmt->execute();
      if (1==$stmt->affected_rows) {
        $this->man->AddMessage("Fahrzeugeinweisung hinzugefügt!");
        return 201;
      } else {
        return 200;
      }
    } else {
      $this->man->AddMessage("Mysql error: ".$this->db->error);
    }
    return 500; // Should not reach this stage
  }
  
  protected function remove($ids) {
    if ($ids["Fahrzeuge"]==null || $ids["Personal"]==null) {
      return 400;
    }
    if (!$this->man->user->HasRight($this->adminRight)) {
      return 403; // You shall not pass!
    }
    
    $qry = "DELETE FROM Fahrzeuge_Einweisungen WHERE Fahrzeuge = ? AND Personal = ?";
    if ($stmt = $this->db->prepare($qry)) {
      $stmt->bind_param("ii", $ids["Fahrzeuge"], $ids["Personal"]);
      $stmt->execute();
      if (1==$stmt->affected_rows) {
        $this->man->AddMessage("Fahrzeugeinweisung entfernt!");
        return 200;
      } else {
        return 404;
      }
    } else {
      $this->man->AddMessage("Mysql error: ".$this->db->error);
      return 500;
    }
  }
}
