Bearsampp 2025.8.29
Loading...
Searching...
No Matches
ajax.quickpick.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2022-2025 Bearsampp
5 * * License: GNU General Public License version 3 or later; see LICENSE.txt
6 * * Website: https://bearsampp.com
7 * * Github: https://github.com/Bearsampp
8 *
9 */
10
21
22// Set appropriate headers for AJAX response
23header('Content-Type: application/json');
24
25// Initialize response array
26$response = array();
27
28// Check if this is a POST request
29if ($_SERVER['REQUEST_METHOD'] === 'POST') {
30 $module = isset($_POST['module']) ? $_POST['module'] : null;
31 $version = isset($_POST['version']) ? $_POST['version'] : null;
32 $filesize = isset($_POST['filesize']) ? $_POST['filesize'] : null;
33
34 if ($module && $version) {
35 // Only load the QuickPick class when needed
36 include_once __DIR__ . '/../../../classes/actions/class.action.quickPick.php';
37
38 // Start output buffering to capture any unwanted output
39 ob_start();
40
41 try {
42 $QuickPick = new QuickPick();
43 Util::logDebug('QuickPick initialized for module: ' . $module . ', version: ' . $version);
44
45 // Install the module
46 $response = $QuickPick->installModule($module, $version);
47
48 if (!isset($response['error'])) {
49 // Build success message
50 $successMessage = "Module $module version $version installed successfully.";
51
52 // Add appropriate instructions based on module type
53 if (isset($QuickPick->modules[$module]) && $QuickPick->modules[$module]['type'] === "binary") {
54 $successMessage .= "\nReload needed...\nWhen you are done installing modules then\nRight click on menu and choose reload.";
55 } else {
56 $successMessage .= "\nEdit Bearsampp.conf to use new version(s) then\nWhen you are done installing modules\nRight click on menu and choose reload.";
57 }
58
59 $response['message'] = $successMessage;
60 $response['success'] = true;
61 } else {
62 error_log('Error in QuickPick installation: ' . json_encode($response));
63 }
64
65 Util::logDebug('Response: ' . json_encode($response));
66 } catch (Exception $e) {
67 $response = ['error' => 'Exception: ' . $e->getMessage()];
68 error_log('Exception in QuickPick: ' . $e->getMessage());
69 }
70
71 // End output buffering and discard any remaining output
72 ob_end_clean();
73 } else {
74 $response = ['error' => 'Invalid module or version.'];
75 }
76} else {
77 $response = ['error' => 'Invalid request method.'];
78}
79
80// Send the JSON response
81echo json_encode($response);
$response
static logDebug($data, $file=null)