mirror of
https://github.com/Karaka-Management/oms-Script.git
synced 2026-02-10 10:28:41 +00:00
Fixes and drafts for reporter/helper
This commit is contained in:
parent
96981ae385
commit
cc3b997f92
|
|
@ -25,6 +25,7 @@ use Modules\Helper\Models\TemplateDataType;
|
||||||
use Modules\Helper\Models\TemplateMapper;
|
use Modules\Helper\Models\TemplateMapper;
|
||||||
|
|
||||||
use phpOMS\Account\PermissionType;
|
use phpOMS\Account\PermissionType;
|
||||||
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
use phpOMS\Message\Http\RequestStatusCode;
|
use phpOMS\Message\Http\RequestStatusCode;
|
||||||
use phpOMS\Message\NotificationLevel;
|
use phpOMS\Message\NotificationLevel;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
|
@ -66,7 +67,7 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function apiHelperSingle(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
public function apiHelperExport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||||
{
|
{
|
||||||
// todo: check permission here
|
// todo: check permission here
|
||||||
|
|
||||||
|
|
@ -80,6 +81,7 @@ final class ApiController extends Controller
|
||||||
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
|
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$view = $this->createView($template, $request, $response);
|
||||||
switch ($request->getData('type')) {
|
switch ($request->getData('type')) {
|
||||||
case 'pdf':
|
case 'pdf':
|
||||||
$response->getHeader()->set('Content-Type', MimeType::M_PDF, true);
|
$response->getHeader()->set('Content-Type', MimeType::M_PDF, true);
|
||||||
|
|
@ -90,7 +92,7 @@ final class ApiController extends Controller
|
||||||
case 'xlsx':
|
case 'xlsx':
|
||||||
$response->getHeader()->set(
|
$response->getHeader()->set(
|
||||||
'Content-disposition', 'attachment; filename="'
|
'Content-disposition', 'attachment; filename="'
|
||||||
. ((string) $request->getData('id')) . '.'
|
. $template->getName() . '.'
|
||||||
. ((string) $request->getData('type'))
|
. ((string) $request->getData('type'))
|
||||||
. '"'
|
. '"'
|
||||||
, true);
|
, true);
|
||||||
|
|
@ -102,7 +104,8 @@ final class ApiController extends Controller
|
||||||
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
|
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO handle bad request
|
$response->getHeader()->set('Content-Type', 'text/html; charset=utf-8');
|
||||||
|
$view->setTemplate('/' . \substr($view->getData('tcoll')['template']->getPath(), 0, -8));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->getData('download') !== null) {
|
if ($request->getData('download') !== null) {
|
||||||
|
|
@ -110,25 +113,80 @@ final class ApiController extends Controller
|
||||||
$response->getHeader()->set('Content-Transfer-Encoding', 'Binary', true);
|
$response->getHeader()->set('Content-Transfer-Encoding', 'Binary', true);
|
||||||
$response->getHeader()->set(
|
$response->getHeader()->set(
|
||||||
'Content-disposition', 'attachment; filename="'
|
'Content-disposition', 'attachment; filename="'
|
||||||
. ((string) $request->getData('id')) . '.'
|
. $template->getName() . '.'
|
||||||
. ((string) $request->getData('type'))
|
. ((string) $request->getData('type'))
|
||||||
. '"'
|
. '"'
|
||||||
, true);
|
, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var array $reportLanguage */
|
$response->set('export', $view);
|
||||||
/** @noinspection PhpIncludeInspection */
|
}
|
||||||
include_once __DIR__ . '/Templates/' . $request->getData('id') . '/' . $request->getData('id') . '.lang.php';
|
|
||||||
|
|
||||||
$exportView = new View($this->app, $request, $response);
|
private function createView(Template $template, RequestAbstract $request, ResponseAbstract $response) : View
|
||||||
$exportView->addData('lang', $reportLanguage[$this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->getLanguage()]);
|
{
|
||||||
$exportView->setTemplate(
|
$tcoll = [];
|
||||||
'/Modules/Helper/Templates/'
|
$files = $template->getSource()->getSources();
|
||||||
. ((string) $request->getData('id')) . '/'
|
|
||||||
. ((string) $request->getData('id')) . '.'
|
foreach ($files as $tMedia) {
|
||||||
. ((string) $request->getData('type'))
|
$lowerPath = \strtolower($tMedia->getPath());
|
||||||
);
|
|
||||||
$response->set('export', $exportView->render());
|
if (StringUtils::endsWith($lowerPath, '.lang.php')) {
|
||||||
|
$tcoll['lang'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, 'worker.php')) {
|
||||||
|
$tcoll['worker'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.xlsx.php') || StringUtils::endsWith($lowerPath, '.xls.php')) {
|
||||||
|
$tcoll['excel'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.docx.php') || StringUtils::endsWith($lowerPath, '.doc.php')) {
|
||||||
|
$tcoll['word'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.pptx.php') || StringUtils::endsWith($lowerPath, '.ppt.php')) {
|
||||||
|
$tcoll['powerpoint'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.pdf.php')) {
|
||||||
|
$tcoll['pdf'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.csv.php')) {
|
||||||
|
$tcoll['csv'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.json.php')) {
|
||||||
|
$tcoll['json'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.tpl.php')) {
|
||||||
|
$tcoll['template'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.css')) {
|
||||||
|
$tcoll['css'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.js')) {
|
||||||
|
$tcoll['js'] = $tMedia;
|
||||||
|
} elseif (StringUtils::endsWith($lowerPath, '.sqlite') || StringUtils::endsWith($lowerPath, '.db')) {
|
||||||
|
$tcoll['db'][] = $tMedia;
|
||||||
|
} else {
|
||||||
|
// Do nothing; only the creator knows how to deal with this type of file :)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$view = new View($this->app, $request, $response);
|
||||||
|
if (!$template->isStandalone()) {
|
||||||
|
$report = ReportMapper::getNewest(1,
|
||||||
|
(new Builder($this->app->dbPool->get()))->where('helper_report.helper_report_template', '=', $template->getId())
|
||||||
|
);
|
||||||
|
|
||||||
|
$rcoll = [];
|
||||||
|
$report = end($report);
|
||||||
|
$report = $report === false ? new NullReport() : $report;
|
||||||
|
|
||||||
|
if (!($report instanceof NullReport)) {
|
||||||
|
/** @var Media[] $files */
|
||||||
|
$files = $report->getSource()->getSources();
|
||||||
|
|
||||||
|
foreach ($files as $media) {
|
||||||
|
$rcoll[$media->getName() . '.' . $media->getExtension()] = $media;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$view->addData('report', $report);
|
||||||
|
$view->addData('rcoll', $rcoll);
|
||||||
|
}
|
||||||
|
|
||||||
|
$view->addData('tcoll', $tcoll);
|
||||||
|
$view->addData('lang', $request->getData('lang') ?? $request->getHeader()->getL11n()->getLanguage());
|
||||||
|
$view->addData('template', $template);
|
||||||
|
|
||||||
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -140,17 +140,7 @@ final class BackendController extends Controller
|
||||||
$view = new View($this->app, $request, $response);
|
$view = new View($this->app, $request, $response);
|
||||||
//$file = preg_replace('([^\w\s\d\-_~,;:\.\[\]\(\).])', '', $template->getName());
|
//$file = preg_replace('([^\w\s\d\-_~,;:\.\[\]\(\).])', '', $template->getName());
|
||||||
|
|
||||||
$template = TemplateMapper::get((int) $request->getData('id'));
|
$template = TemplateMapper::get((int) $request->getData('id'));
|
||||||
$accountId = $request->getHeader()->getAccount();
|
|
||||||
|
|
||||||
if ($template->getCreatedBy()->getId() !== $accountId // todo: also check if report createdBy
|
|
||||||
&& !$this->app->accountManager->get($accountId)->hasPermission(
|
|
||||||
PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::REPORT, $template->getId())
|
|
||||||
) {
|
|
||||||
$view->setTemplate('/Web/Backend/Error/403_inline');
|
|
||||||
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|
||||||
$view->setTemplate('/Modules/Helper/Theme/Backend/helper-single');
|
$view->setTemplate('/Modules/Helper/Theme/Backend/helper-single');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,19 @@ $template = $this->getData('template');
|
||||||
$report = $this->getData('report');
|
$report = $this->getData('report');
|
||||||
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
/** @noinspection PhpIncludeInspection */
|
||||||
$reportLanguage = include __DIR__ . '/../../../' . \ltrim($tcoll['lang']->getPath(), '/');
|
$reportLanguage = include __DIR__ . '/../../../../' . \ltrim($tcoll['lang']->getPath(), '/');
|
||||||
$lang = $reportLanguage[$cLang];
|
$lang = $reportLanguage[$cLang];
|
||||||
|
|
||||||
echo $this->getData('nav')->render(); ?>
|
echo $this->getData('nav')->render(); ?>
|
||||||
<div class="row">
|
<div class="row" style="height: calc(100% - 85px);">
|
||||||
<div class="col-xs-12 col-md-9">
|
<div class="col-xs-12 col-md-9">
|
||||||
<div class="wf-100">
|
<div class="wf-100" style="height: 100%;">
|
||||||
<?php /** @noinspection PhpIncludeInspection */
|
<iframe src="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/helper/report/export/?id=' . $template->getId()); ?>" allowfullscreen></iframe>
|
||||||
include __DIR__ . '/../../../' . \ltrim($tcoll['template']->getPath(), '/'); ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xs-12 col-md-3">
|
<div class="col-xs-12 col-md-3">
|
||||||
|
<?php if (count($reportLanguage) > 1) : ?>
|
||||||
<section class="box wf-100">
|
<section class="box wf-100">
|
||||||
<header><h1><?= $this->getHtml('Reports') ?></h1></header>
|
<header><h1><?= $this->getHtml('Reports') ?></h1></header>
|
||||||
|
|
||||||
|
|
@ -41,14 +41,16 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<form action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/helper/template'); ?>" method="post">
|
<form action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/helper/template'); ?>" method="post">
|
||||||
<table class="layout wf-100">
|
<table class="layout wf-100">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<?php if (count($reportLanguage) > 1) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="iLang"><?= $this->getHtml('Language'); ?></label>
|
<td><label for="iLang"><?= $this->getHtml('Language'); ?></label>
|
||||||
<tr>
|
<tr>
|
||||||
<td><select id="iLang" name="lang" data-action='[{"listener": "change", "action": [{"key": 1, "type": "redirect", "uri": "{%}&lang={#iLang}", "target": "self"}]}]'>
|
<td><select id="iLang" name="lang" data-action='[{"listener": "change", "action": [{"key": 1, "type": "redirect", "uri": "{%}&lang={#iLang}", "target": "self"}]}]'>
|
||||||
<?php foreach ($reportLanguage as $key => $langauge) : ?>
|
<?php foreach ($reportLanguage as $key => $language) : ?>
|
||||||
<option value="<?= $this->printHtml($key); ?>"<?= $this->printHtml($key === $cLang ? ' selected' : ''); ?>><?= $this->printHtml($langauge[':language'] ); ?>
|
<option value="<?= $this->printHtml($key); ?>"<?= $this->printHtml($key === $cLang ? ' selected' : ''); ?>><?= $this->printHtml($language[':language'] ); ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
|
<?php endif; ?>
|
||||||
<?php if (!$template->isStandalone()) : ?><tr>
|
<?php if (!$template->isStandalone()) : ?><tr>
|
||||||
<td><label for="iReport"><?= $this->getHtml('Report'); ?></label>
|
<td><label for="iReport"><?= $this->getHtml('Report'); ?></label>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -59,7 +61,9 @@ echo $this->getData('nav')->render(); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (isset($tcoll['excel']) || isset($tcoll['pdf']) || isset($tcoll['word']) || isset($tcoll['powerpoint']) || isset($tcoll['csv']) || isset($tcoll['json'])) : ?>
|
||||||
<section class="box wf-100">
|
<section class="box wf-100">
|
||||||
<header><h1><?= $this->getHtml('Export') ?></h1></header>
|
<header><h1><?= $this->getHtml('Export') ?></h1></header>
|
||||||
|
|
||||||
|
|
@ -87,6 +91,7 @@ echo $this->getData('nav')->render(); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<section class="box wf-100">
|
<section class="box wf-100">
|
||||||
<header><h1><?= $this->getHtml('Info') ?></h1></header>
|
<header><h1><?= $this->getHtml('Info') ?></h1></header>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user