Bearsampp 2026.3.26
API documentation
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 global $bearsamppConfig;
43 $QuickPick = new QuickPick();
44 Util::logDebug('QuickPick initialized for module: ' . $module . ', version: ' . $version);
45
46 // Check if enhanced mode is enabled
47 $enhancedMode = $bearsamppConfig->getEnhancedQuickPick();
48 Util::logDebug('Enhanced QuickPick mode: ' . ($enhancedMode ? 'enabled' : 'disabled'));
49
50 // Install the module
51 $response = $QuickPick->installModule($module, $version);
52
53 if (!isset($response['error'])) {
54 // Determine module type for appropriate messaging
55 // Use the helper method to normalize the module name consistently
56 $moduleKey = $QuickPick->normalizeModuleName($module);
57 $moduleName = strtolower($moduleKey ?? $module);
58 $moduleType = ($moduleKey && isset($QuickPick->modules[$moduleKey])) ? $QuickPick->modules[$moduleKey]['type'] : 'binary';
59
60 // Build success message based on mode and module type
61 if ($enhancedMode == 1) {
62 // Enhanced mode: config auto-updated, just need to reload
63 $successMessage = "Module $module version $version installed successfully!";
64 $successMessage .= "\n\n✓ Files extracted";
65 $successMessage .= "\n✓ Configuration updated";
66 $successMessage .= "\n\n<span class='text-warning'><i class='fas fa-exclamation-triangle'></i> IMPORTANT: Right-click the Bearsampp tray icon and select 'Reload' to activate the new version.</span>";
67 } else {
68 // Standard mode: offer to update config for all module types
69 $successMessage = "Module $module version $version has been downloaded and extracted successfully!";
70 $successMessage .= "\n\nNext steps:";
71 $successMessage .= "\n1. Click 'Apply Config' below to update bearsampp.conf";
72 $successMessage .= "\n2. Right-click the Bearsampp tray icon and select 'Reload'";
73
74 // Include module info for the apply button
75 $response['moduleType'] = $moduleType;
76 $response['moduleName'] = $moduleName;
77 $response['showApplyButton'] = true;
78 }
79
80 $response['message'] = $successMessage;
81 $response['success'] = true;
82 } else {
83 error_log('Error in QuickPick installation: ' . json_encode($response));
84 }
85
86 Util::logDebug('Response: ' . json_encode($response));
87 } catch (Exception $e) {
88 $response = ['error' => 'Exception: ' . $e->getMessage()];
89 error_log('Exception in QuickPick: ' . $e->getMessage());
90 }
91
92 // End output buffering and discard any remaining output
93 ob_end_clean();
94 } else {
95 $response = ['error' => 'Invalid module or version.'];
96 }
97} else {
98 $response = ['error' => 'Invalid request method.'];
99}
100
101// Send the JSON response
102echo json_encode($response);
static logDebug($data, $file=null)
global $bearsamppConfig
Definition homepage.php:41
$enhancedMode
Definition homepage.php:169