<?php

class OrderFileController 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 editAction() {
    // internal redirect to File::editAction
  }
  
  protected function deleteAction() {
    $id = $this->request->id;
    
    $orderfile = new OrderFile($id);
    if(!$orderfile->id || $orderfile->id != $id) {
      $this->layout()->setFlash("Dokument nicht gefunden.", "error");
      $this->redirect("Order");
    }
    
    $order_id = $orderfile->order_id;
    
    $orderfile->file->delete();
    $orderfile->delete();
    $this->redirect("Order", "edit", ["id" => $order_id]);
  }
}