104 lines
3.9 KiB
PHP
104 lines
3.9 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
Route::get('/', fn () => redirect('/admin'));
|
|
|
|
Route::get('/locale/{locale}', function (string $locale) {
|
|
if (in_array($locale, config('app.available_locales', ['fa', 'en']))) {
|
|
session(['locale' => $locale]);
|
|
}
|
|
return redirect(url()->previous('/admin'));
|
|
})->name('locale.switch');
|
|
|
|
Route::middleware(['web', 'auth'])->group(function () {
|
|
Route::get('/prescription/{prescription}/print', [\App\Http\Controllers\PrescriptionPrintController::class, 'print'])
|
|
->name('prescription.print');
|
|
|
|
Route::get('/patient/{patient}/print-lab', [\App\Http\Controllers\PrescriptionPrintController::class, 'printPatientLab'])
|
|
->name('patient.print.lab');
|
|
|
|
Route::get('/prescription/{prescription}/print-admission', [\App\Http\Controllers\PrescriptionPrintController::class, 'printAdmission'])
|
|
->name('prescription.print.admission');
|
|
|
|
Route::get('/surgery-appointment/{patient}/print-admission', [\App\Http\Controllers\PrescriptionPrintController::class, 'printSurgeryAdmission'])
|
|
->name('surgery-appointment.print.admission');
|
|
|
|
Route::post('/admin/sync/run', function () {
|
|
$service = \App\Services\SyncService::fromConfig();
|
|
|
|
if (! $service->isConfigured()) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'report' => [__('navigation.sync.error_not_configured')],
|
|
], 422);
|
|
}
|
|
|
|
$result = $service->sync();
|
|
|
|
return response()->json($result);
|
|
})->name('sync.run');
|
|
|
|
Route::get('/backup/download', function () {
|
|
set_time_limit(0);
|
|
ini_set('memory_limit', '256M');
|
|
|
|
$dbPath = database_path('database.sqlite');
|
|
if (! file_exists($dbPath)) {
|
|
abort(404, 'Database not found.');
|
|
}
|
|
|
|
$zipFilename = 'matab-backup-' . now()->format('Y-m-d_H-i-s') . '.zip';
|
|
$zipPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $zipFilename;
|
|
|
|
$zip = new \ZipArchive();
|
|
if ($zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
|
|
abort(500, 'Could not create zip archive.');
|
|
}
|
|
|
|
$noCompressExts = [
|
|
'jpg', 'jpeg', 'png', 'gif', 'webp',
|
|
'mp4', 'mov', 'avi', 'mkv', 'webm',
|
|
'mp3', 'wav', 'ogg', 'opus', 'm4a',
|
|
'zip', 'gz', 'rar', '7z',
|
|
];
|
|
|
|
$addFile = function (string $realPath, string $zipEntry) use ($zip, $noCompressExts): void {
|
|
$zip->addFile($realPath, $zipEntry);
|
|
$index = $zip->locateName($zipEntry);
|
|
$ext = strtolower(pathinfo($realPath, PATHINFO_EXTENSION));
|
|
if (in_array($ext, $noCompressExts, true)) {
|
|
$zip->setCompressionIndex($index, \ZipArchive::CM_STORE);
|
|
} else {
|
|
$zip->setCompressionIndex($index, \ZipArchive::CM_DEFLATE, 1);
|
|
}
|
|
};
|
|
|
|
$addFile($dbPath, 'database/database.sqlite');
|
|
|
|
$publicPath = storage_path('app/public');
|
|
foreach (['files', 'initials'] as $folder) {
|
|
$folderPath = $publicPath . '/' . $folder;
|
|
if (! is_dir($folderPath)) {
|
|
continue;
|
|
}
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($folderPath, \RecursiveDirectoryIterator::SKIP_DOTS),
|
|
\RecursiveIteratorIterator::LEAVES_ONLY
|
|
);
|
|
foreach ($iterator as $file) {
|
|
if ($file->isFile()) {
|
|
$relativePath = str_replace('\\', '/', substr($file->getPathname(), strlen($folderPath) + 1));
|
|
$addFile($file->getPathname(), $folder . '/' . $relativePath);
|
|
}
|
|
}
|
|
}
|
|
|
|
$zip->close();
|
|
|
|
return response()->download($zipPath, $zipFilename, [
|
|
'Content-Type' => 'application/zip',
|
|
])->deleteFileAfterSend(true);
|
|
})->name('backup.download');
|
|
});
|