<?php #lnk/anwesenheiten_termine/class.php

class Anwesenheiten_TermineLink extends BaseLink
{
  protected function insert($ids) {
    if ($ids["Anwesenheiten"]==null || $ids["Termine"]==null) {
      return 400;
    }
    if (!$this->man->user->HasRight($this->adminRight)) {
      return 403; // You shall not pass!
    }
    
    $qry = "INSERT INTO Anwesenheiten_Termine (Anwesenheiten, Termine) VALUES (?, ?)";
    if ($stmt = $this->db->prepare($qry)) {
      $stmt->bind_param("ii", $ids["Anwesenheiten"], $ids["Termine"]);
      $stmt->execute();
      if (1==$stmt->affected_rows) {
        $this->man->AddMessage("Termin zu Anwesenheitsliste 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["Anwesenheiten"]==null || $ids["Termine"]==null) {
      return 400;
    }
    if (!$this->man->user->HasRight($this->adminRight)) {
      return 403; // You shall not pass!
    }
    
    $qry = "DELETE FROM Anwesenheiten_Termine WHERE Anwesenheiten = ? AND Termine = ?";
    if ($stmt = $this->db->prepare($qry)) {
      $stmt->bind_param("ii", $ids["Anwesenheiten"], $ids["Termine"]);
      $stmt->execute();
      if (1==$stmt->affected_rows) {
        $this->man->AddMessage("Termin aus Anwesenheitsliste entfernt!");
        return 200;
      } else {
        return 404;
      }
    } else {
      $this->man->AddMessage("Mysql error: ".$this->db->error);
      return 500;
    }
  }
}
