<?php

class ProducttechAttributeController extends mfBaseController {
  
  protected function init() {
    $this->needlogin=true;
    $me = new User();
    $me->loadMe();
    $this->me = $me;
    $this->layout()->set("me",$me);
    
    if(!$me->isAdmin()) {
      $this->redirect("Dashboard");
    }
  }
  
  protected function deleteAction() {
    $id = $this->request->id;
    
    $ta = new ProducttechAttribute($id);
    if(!$ta->id || $ta->id != $id) {
      $this->layout()->setFlash("Attribut nicht gefunden.", "error");
      $this->redirect("Producttech");
    }
    
    /*if(ProductModel::search(["producttech_id" => $tech->id])) {
      $this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error");
      $this->redirect("Producttech");
    }*/
    
    $producttech_id = $ta->producttech_id;
    
    // check if Product is unused
    $ta->delete();
    $this->redirect("Producttech", "edit", ['id' => $producttech_id]);
  }
}