2024.8.23
Loading...
Searching...
No Matches
ajax.quickpick.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * This script handles AJAX requests for installing modules in the Bearsampp application.
12 * It expects a POST request with 'module', 'version', and optionally 'filesize' parameters.
13 *
14 * The script performs the following actions:
15 * - Includes the QuickPick class.
16 * - Logs the file access.
17 * - Creates an instance of the QuickPick class.
18 * - Sets the response header to JSON.
19 * - Initializes an empty response array.
20 * - Checks if the request method is POST.
21 * - Validates the 'module' and 'version' parameters.
22 * - Calls the installModule method of the QuickPick class.
23 * - Constructs a response message based on the installation result.
24 * - Returns the response as a JSON object.
25 *
26 * @package Bearsampp
27 * @subpackage Core
28 * @category AJAX
29 * @license GNU General Public License version 3 or later; see LICENSE.txt
30 * @link https://bearsampp.com
31 */
32include __DIR__ . '/../../../classes/actions/class.action.quickPick.php';
33Util::logDebug('File accessed successfully.');
35
36header('Content-Type: application/json');
37
38$response = array();
39
40if ($_SERVER['REQUEST_METHOD'] === 'POST') {
41 $module = isset($_POST['module']) ? $_POST['module'] : null;
42 $version = isset($_POST['version']) ? $_POST['version'] : null;
43 $filesize = isset($_POST['filesize']) ? $_POST['filesize'] : null;
44
45 if ($module && $version) {
46 $response = $QuickPick->installModule($module, $version);
47 if (!isset($response['error'])) {
48 $response['message'] = "Module $module version $version installed successfully.";
49 if (isset($QuickPick->modules[$module]) && $QuickPick->modules[$module]['type'] === "binary") {
50 $response['message'] .= "\nReload needed...";
51 $response['message'] .= "\nWhen you are done installing modules then";
52 $response['message'] .= "\nRight click on menu and choose reload.";
53 } else {
54 $response['message'] .= "\nEdit Bearsampp.conf to use new version(s) then";
55 $response['message'] .= "\nWhen you are done installing modules";
56 $response['message'] .= "\nRight click on menu and choose reload.";
57 }
58 } else {
59 error_log('Error in response: ' . json_encode($response));
60 }
61 Util::logDebug('Response: ' . json_encode($response));
62 } else {
63 $response = ['error' => 'Invalid module or version.'];
64 }
65} else {
66 $response = ['error' => 'Invalid request method.'];
67}
68
69echo json_encode($response);
$QuickPick
$response
static logDebug($data, $file=null)