Bearsampp 2026.7.11
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 headers for JSON streaming
23 header('Content-Type: application/json');
24 header('X-Content-Type-Options: nosniff');
25 header('Cache-Control: no-cache');
26 header('Connection: keep-alive');
27
28// Initialize response array
29$response = array();
30
31// Check if this is a POST request
32if ($_SERVER['REQUEST_METHOD'] === 'POST') {
33 $module = isset($_POST['module']) ? $_POST['module'] : null;
34 $version = isset($_POST['version']) ? $_POST['version'] : null;
35 $filesize = isset($_POST['filesize']) ? $_POST['filesize'] : null;
36
37 if ($module && $version) {
38 // Only load the QuickPick class when needed
39 include_once __DIR__ . '/../../../classes/actions/class.action.quickPick.php';
40
41 // Ensure any output buffering is cleared and we're ready for streaming
42 while (ob_get_level() > 0) {
43 ob_end_flush();
44 }
45
46 try {
47 global $bearsamppConfig;
48 $QuickPick = new QuickPick();
49 Log::debug('QuickPick initialized for module: ' . $module . ', version: ' . $version);
50
51 // Check if enhanced mode is enabled
52 $enhancedMode = $bearsamppConfig->getEnhancedQuickPick();
53 Log::debug('Enhanced QuickPick mode: ' . ($enhancedMode ? 'enabled' : 'disabled'));
54
55 // Install the module
56 $response = $QuickPick->installModule($module, $version);
57
58 if (!isset($response['error'])) {
59 // Determine module type for appropriate messaging
60 // Use the helper method to normalize the module name consistently
61 $moduleKey = $QuickPick->normalizeModuleName($module);
62 $moduleName = strtolower($moduleKey ?? $module);
63 $moduleType = ($moduleKey && isset($QuickPick->modules[$moduleKey])) ? $QuickPick->modules[$moduleKey]['type'] : 'binary';
64
65 // Build success message based on mode and module type
66 if ($enhancedMode == 1) {
67 // Enhanced mode: config auto-updated, just need to reload
68 $successMessage = "Module $module version $version installed successfully!";
69 $successMessage .= "\n\n✓ Files extracted";
70 $successMessage .= "\n✓ Configuration updated";
71 $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>";
72 } else {
73 // Standard mode: offer to update config for all module types
74 $successMessage = "Module $module version $version has been downloaded and extracted successfully!";
75 $successMessage .= "\n\nNext steps:";
76 $successMessage .= "\n1. Click 'Apply Config' below to update bearsampp.conf";
77 $successMessage .= "\n2. Right-click the Bearsampp tray icon and select 'Reload'";
78
79 // Include module info for the apply button
80 $response['moduleType'] = $moduleType;
81 $response['moduleName'] = $moduleName;
82 $response['showApplyButton'] = true;
83 }
84
85 $response['message'] = $successMessage;
86 $response['success'] = true;
87 } else {
88 error_log('Error in QuickPick installation: ' . json_encode($response));
89 }
90
91 Log::debug('Response: ' . json_encode($response));
92 } catch (Exception $e) {
93 $response = ['error' => 'Exception: ' . $e->getMessage()];
94 error_log('Exception in QuickPick: ' . $e->getMessage());
95 }
96 } else {
97 $response = ['error' => 'Invalid module or version.'];
98 }
99} else {
100 $response = ['error' => 'Invalid request method.'];
101}
102
103// Send the final JSON response - followed by newline to be consistent with progress chunks
104echo json_encode($response) . PHP_EOL;
static debug($data, $file=null)
global $bearsamppConfig
Definition homepage.php:41