Exemple #1
0
$router->respond('POST', '/admin/create_file/?', function ($request, $response) {
    if (!$_SESSION['admin']) {
        $response->redirect('/404')->send();
    }
    $data = ['format' => $_POST['format'], 'category' => $_POST['category'], 'producer' => $_POST['producer'], 'count' => $_POST['count']];
    $controller = new Controller_Admin();
    $result = json_encode($controller->createProductsFile($data), JSON_UNESCAPED_UNICODE);
    return $result;
});
// Скачивание файла товаров
$router->respond('GET', '/download/files/[:filename]', function ($request, $response) {
    if (!$_SESSION['admin']) {
        $response->redirect('/404')->send();
    }
    $controller = new Controller_Admin();
    $controller->downloadFile('files/' . $request->filename);
});
// Загрузка товаров
$router->respond('POST', '/admin/upload_products/?', function ($request, $response) {
    if (!$_SESSION['admin']) {
        $response->redirect('/404')->send();
    }
    $controller = new Controller_Admin();
    $result = $controller->uploadProductsFile($_FILES['file']);
    if ($result['status'] == 'success') {
        $result = $controller->uploadProducts($result['filename']);
        return json_encode($result, JSON_UNESCAPED_UNICODE);
    } else {
        return json_encode($result, JSON_UNESCAPED_UNICODE);
    }
});