67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
class RimoWorkorderController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
}
|
|
|
|
protected function downloadAhaAction() {
|
|
$workorder_id = $this->request->id;
|
|
$inline = !empty($this->request->inline);
|
|
|
|
if(!$workorder_id || $workorder_id < 1) {
|
|
header("HTTP/1.1 400 Bad Request");
|
|
echo "Invalid workorder id.";
|
|
exit;
|
|
}
|
|
|
|
$workorder = new RimoWorkorder($workorder_id);
|
|
if(!$workorder->id) {
|
|
header("HTTP/1.1 404 Not Found");
|
|
echo "Workorder nicht gefunden.";
|
|
exit;
|
|
}
|
|
|
|
$return = $workorder->getAha();
|
|
if($return === false) {
|
|
header("HTTP/1.1 500 Not Found");
|
|
echo "Fehler beim Herunterladen des AHA-Reports aus Rimo.";
|
|
exit;
|
|
}
|
|
|
|
$filename = $workorder->rimo_name.'_AHA.pdf';
|
|
$disposition = $inline ? 'inline' : 'attachment';
|
|
|
|
header("Content-type: application/pdf");
|
|
header('Content-disposition: '.$disposition.'; filename="'.$filename.'"');
|
|
echo $return;
|
|
exit;
|
|
}
|
|
|
|
protected function parseAhaAction() {
|
|
header('Content-Type: application/json');
|
|
$post = json_decode(file_get_contents('php://input'), true);
|
|
$id = $post['id'] ?? $this->request->id ?? null;
|
|
|
|
if (!$id || $id < 1) {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid workorder id.']);
|
|
exit;
|
|
}
|
|
|
|
$wo = new RimoWorkorder($id);
|
|
if (!$wo->id) {
|
|
echo json_encode(['success' => false, 'message' => 'RimoWorkorder nicht gefunden.']);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode($wo->parseAha());
|
|
exit;
|
|
}
|
|
|
|
} |