| 1 |
<?php |
| 2 |
/** |
| 3 |
* onWebChat Settings Page with Tabs |
| 4 |
*/ |
| 5 |
|
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
function onwebchat_settings_page() { |
| 11 |
// Note: Form submissions are handled in admin_init hook (see onwebchat.php) |
| 12 |
// This ensures redirects happen before any output is sent |
| 13 |
|
| 14 |
// Get current tab |
| 15 |
$active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'general'; |
| 16 |
|
| 17 |
// Check connection status |
| 18 |
$options = get_option('onwebchat_plugin_option'); |
| 19 |
$chatId = isset($options['text_string']) ? $options['text_string'] : ''; |
| 20 |
$isConnected = !empty($chatId); |
| 21 |
|
| 22 |
?> |
| 23 |
<div class="wrap"> |
| 24 |
<h1 style="font-weight: 400; margin-top: 34px;"> |
| 25 |
onWebChat <?php echo $isConnected ? 'Settings' : 'Activation'; ?> |
| 26 |
</h1> |
| 27 |
|
| 28 |
<?php if ($isConnected): ?> |
| 29 |
<!-- Tab Navigation (only show when connected) --> |
| 30 |
<h2 class="nav-tab-wrapper"> |
| 31 |
<a href="?page=onwebchat_settings&tab=general" |
| 32 |
class="nav-tab <?php echo $active_tab === 'general' ? 'nav-tab-active' : ''; ?>"> |
| 33 |
General |
| 34 |
</a> |
| 35 |
|
| 36 |
<a href="?page=onwebchat_settings&tab=chat" |
| 37 |
class="nav-tab <?php echo $active_tab === 'chat' ? 'nav-tab-active' : ''; ?>"> |
| 38 |
Chat Widget |
| 39 |
</a> |
| 40 |
|
| 41 |
<?php if (class_exists('WooCommerce')): ?> |
| 42 |
<a href="?page=onwebchat_settings&tab=woocommerce" |
| 43 |
class="nav-tab <?php echo $active_tab === 'woocommerce' ? 'nav-tab-active' : ''; ?>"> |
| 44 |
WooCommerce |
| 45 |
</a> |
| 46 |
<?php endif; ?> |
| 47 |
|
| 48 |
<a href="?page=onwebchat_settings&tab=advanced" |
| 49 |
class="nav-tab <?php echo $active_tab === 'advanced' ? 'nav-tab-active' : ''; ?>"> |
| 50 |
Advanced |
| 51 |
</a> |
| 52 |
</h2> |
| 53 |
<?php endif; ?> |
| 54 |
|
| 55 |
<!-- Tab Content --> |
| 56 |
<div class="tab-content" style="margin-top: 20px;"> |
| 57 |
<?php |
| 58 |
if (!$isConnected) { |
| 59 |
// Show connection tab if not connected |
| 60 |
require_once __DIR__ . '/tabs/general.php'; |
| 61 |
onwebchat_general_tab($isConnected); |
| 62 |
} else { |
| 63 |
// Show appropriate tab based on selection |
| 64 |
switch ($active_tab) { |
| 65 |
case 'chat': |
| 66 |
require_once __DIR__ . '/tabs/chat.php'; |
| 67 |
onwebchat_chat_tab(); |
| 68 |
break; |
| 69 |
|
| 70 |
case 'woocommerce': |
| 71 |
if (class_exists('WooCommerce')) { |
| 72 |
require_once __DIR__ . '/tabs/woocommerce.php'; |
| 73 |
onwebchat_woocommerce_tab(); |
| 74 |
} else { |
| 75 |
echo '<div class="notice notice-warning"><p>WooCommerce is not installed.</p></div>'; |
| 76 |
} |
| 77 |
break; |
| 78 |
|
| 79 |
case 'advanced': |
| 80 |
require_once __DIR__ . '/tabs/advanced.php'; |
| 81 |
onwebchat_advanced_tab(); |
| 82 |
break; |
| 83 |
|
| 84 |
default: |
| 85 |
require_once __DIR__ . '/tabs/general.php'; |
| 86 |
onwebchat_general_tab($isConnected); |
| 87 |
} |
| 88 |
} |
| 89 |
?> |
| 90 |
</div> |
| 91 |
</div> |
| 92 |
<?php |
| 93 |
} |
| 94 |
|
| 95 |
|