芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/status.pulsehost.co.uk/app/controllers/admin/AdminPlanUpdate.php
params[0]) ? $this->params[0] : null; /* Make sure it is either the trial / free plan or normal plans */ switch($plan_id) { case 'free': case 'custom': /* Get the current settings for the free plan */ $plan = settings()->{'plan_' . $plan_id}; break; default: $plan_id = (int) $plan_id; /* Check if plan exists */ if(!$plan = db()->where('plan_id', $plan_id)->getOne('plans')) { redirect('admin/plans'); } /* Parse the settings of the plan */ $plan->settings = json_decode($plan->settings ?? ''); $plan->translations = json_decode($plan->translations ?? ''); $plan->prices = json_decode($plan->prices); /* Parse codes & taxes */ $plan->taxes_ids = json_decode($plan->taxes_ids); if(in_array(settings()->license->type, ['Extended License', 'extended'])) { /* Get the available taxes from the system */ $taxes = db()->get('taxes'); } break; } $monitor_check_intervals = require APP_PATH . 'includes/monitor_check_intervals.php'; $dns_monitor_check_intervals = require APP_PATH . 'includes/dns_monitor_check_intervals.php'; $server_monitor_check_intervals = require APP_PATH . 'includes/server_monitor_check_intervals.php'; $additional_domains = db()->where('is_enabled', 1)->where('type', 1)->get('domains'); if(!empty($_POST)) { //ALTUMCODE:DEMO if(DEMO) Alerts::add_error('This command is blocked on the demo.'); if(!\Altum\Csrf::check()) { Alerts::add_error(l('global.error_message.invalid_csrf_token')); } /* Translations */ foreach($_POST['translations'] as $language_name => $array) { foreach($array as $key => $value) { $_POST['translations'][$language_name][$key] = input_clean($value); } if(!array_key_exists($language_name, \Altum\Language::$active_languages)) { unset($_POST['translations'][$language_name]); } } /* Filter variables */ $_POST['color'] = !preg_match('/#([A-Fa-f0-9]{3,4}){1,2}\b/i', $_POST['color']) ? null : $_POST['color']; $_POST['settings'] = [ 'url_minimum_characters' => (int) $_POST['url_minimum_characters'], 'url_maximum_characters' => (int) $_POST['url_maximum_characters'], 'monitors_limit' => (int) $_POST['monitors_limit'], 'monitors_check_intervals' => $_POST['monitors_check_intervals'] ?? [], 'monitors_ping_servers' => $_POST['monitors_ping_servers'] ?? [], 'heartbeats_limit' => (int) $_POST['heartbeats_limit'], 'domain_names_limit' => (int) $_POST['domain_names_limit'], 'dns_monitors_limit' => (int) $_POST['dns_monitors_limit'], 'dns_monitors_check_intervals' => $_POST['dns_monitors_check_intervals'] ?? [], 'server_monitors_limit' => (int) $_POST['server_monitors_limit'], 'server_monitors_check_intervals' => $_POST['server_monitors_check_intervals'] ?? [], 'status_pages_limit' => (int) $_POST['status_pages_limit'], 'projects_limit' => (int) $_POST['projects_limit'], 'domains_limit' => (int) $_POST['domains_limit'], 'teams_limit' => (int) $_POST['teams_limit'], 'team_members_limit' => (int) $_POST['team_members_limit'], 'active_notification_handlers_per_resource_limit' => (int) $_POST['active_notification_handlers_per_resource_limit'], 'logs_retention' => (int) $_POST['logs_retention'], 'statistics_retention' => (int) $_POST['statistics_retention'], 'additional_domains' => $_POST['additional_domains'] ?? [], 'analytics_is_enabled' => isset($_POST['analytics_is_enabled']), 'qr_is_enabled' => isset($_POST['qr_is_enabled']), 'removable_branding_is_enabled' => isset($_POST['removable_branding_is_enabled']), 'custom_url_is_enabled' => isset($_POST['custom_url_is_enabled']), 'password_protection_is_enabled' => isset($_POST['password_protection_is_enabled']), 'search_engine_block_is_enabled' => isset($_POST['search_engine_block_is_enabled']), 'custom_css_is_enabled' => isset($_POST['custom_css_is_enabled']), 'custom_js_is_enabled' => isset($_POST['custom_js_is_enabled']), 'email_reports_is_enabled' => isset($_POST['email_reports_is_enabled']), 'api_is_enabled' => isset($_POST['api_is_enabled']), 'affiliate_commission_percentage' => (int) $_POST['affiliate_commission_percentage'], 'no_ads' => isset($_POST['no_ads']) ]; foreach(array_keys(require APP_PATH . 'includes/notification_handlers.php') as $notification_handler) { $_POST['settings']['notification_handlers_' . $notification_handler . '_limit'] = (int) $_POST['notification_handlers_' . $notification_handler . '_limit']; } switch($plan_id) { case 'free': $_POST['name'] = input_clean($_POST['name']); $_POST['description'] = input_clean($_POST['description']); $_POST['price'] = input_clean($_POST['price']); $_POST['status'] = (int) $_POST['status']; /* Check for any errors */ $required_fields = ['name', 'price']; foreach($required_fields as $field) { if(!isset($_POST[$field]) || (isset($_POST[$field]) && empty($_POST[$field]) && $_POST[$field] != '0')) { Alerts::add_field_error($field, l('global.error_message.empty_field')); } } /* Make sure to not let the admin disable ALL the plans */ if(!$_POST['status']) { $enabled_plans = (int) settings()->payment->is_enabled ? database()->query("SELECT COUNT(*) AS `total` FROM `plans` WHERE `status` <> 0")->fetch_object()->total ?? 0 : 0; if(!$enabled_plans) { Alerts::add_error(l('admin_plan_update.error_message.disabled_plans')); } } $setting_key = 'plan_free'; $setting_value = json_encode([ 'plan_id' => 'free', 'name' => $_POST['name'], 'description' => $_POST['description'], 'translations' => $_POST['translations'], 'price' => $_POST['price'], 'color' => $_POST['color'], 'status' => $_POST['status'], 'settings' => $_POST['settings'] ]); break; case 'custom': $_POST['name'] = input_clean($_POST['name']); $_POST['description'] = input_clean($_POST['description']); $_POST['price'] = input_clean($_POST['price']); $_POST['custom_button_url'] = input_clean($_POST['custom_button_url']); $_POST['status'] = (int) $_POST['status']; /* Check for any errors */ $required_fields = ['name', 'price', 'custom_button_url']; foreach($required_fields as $field) { if(!isset($_POST[$field]) || (isset($_POST[$field]) && empty($_POST[$field]) && $_POST[$field] != '0')) { Alerts::add_field_error($field, l('global.error_message.empty_field')); } } $setting_key = 'plan_custom'; $setting_value = json_encode([ 'plan_id' => 'custom', 'name' => $_POST['name'], 'description' => $_POST['description'], 'translations' => $_POST['translations'], 'price' => $_POST['price'], 'custom_button_url' => $_POST['custom_button_url'], 'color' => $_POST['color'], 'status' => $_POST['status'], 'settings' => $_POST['settings'] ]); break; default: $_POST['name'] = input_clean($_POST['name']); $_POST['description'] = input_clean($_POST['description']); $_POST['trial_days'] = (int) $_POST['trial_days']; $_POST['status'] = (int) $_POST['status']; $_POST['order'] = (int) $_POST['order']; $_POST['taxes_ids'] = json_encode($_POST['taxes_ids'] ?? []); /* Prices */ $prices = [ 'monthly' => [], 'annual' => [], 'lifetime' => [], ]; foreach((array) settings()->payment->currencies as $currency => $currency_data) { $prices['monthly'][$currency] = (float) $_POST['monthly_price'][$currency]; $prices['annual'][$currency] = (float) $_POST['annual_price'][$currency]; $prices['lifetime'][$currency] = (float) $_POST['lifetime_price'][$currency]; } $prices = json_encode($prices); /* Check for any errors */ $required_fields = ['name']; foreach($required_fields as $field) { if(!isset($_POST[$field]) || (isset($_POST[$field]) && empty($_POST[$field]) && $_POST[$field] != '0')) { Alerts::add_field_error($field, l('global.error_message.empty_field')); } } /* Make sure to not let the admin disable ALL the plans */ if(!$_POST['status']) { $enabled_plans = (int) database()->query("SELECT COUNT(*) AS `total` FROM `plans` WHERE `status` <> 0")->fetch_object()->total ?? 0; if( ( !$enabled_plans || ($enabled_plans == 1 && $plan->status)) && !settings()->plan_free->status ) { Alerts::add_error(l('admin_plan_update.error_message.disabled_plans')); } } break; } if(!Alerts::has_field_errors() && !Alerts::has_errors()) { /* Update the plan in database */ switch ($plan_id) { case 'free': case 'custom': db()->where('`key`', $setting_key)->update('settings', ['value' => $setting_value]); /* Clear the cache */ cache()->deleteItem('settings'); break; default: $settings = json_encode($_POST['settings']); $translations = json_encode($_POST['translations']); db()->where('plan_id', $plan_id)->update('plans', [ 'name' => $_POST['name'], 'description' => $_POST['description'], 'translations' => $translations, 'prices' => $prices, 'trial_days' => $_POST['trial_days'], 'settings' => $settings, 'taxes_ids' => $_POST['taxes_ids'], 'color' => $_POST['color'], 'status' => $_POST['status'], 'order' => $_POST['order'], ]); /* Clear the cache */ cache()->deleteItem('plans'); break; } /* Update all users plan settings with these ones */ if(isset($_POST['submit_update_users_plan_settings'])) { $plan_settings = json_encode($_POST['settings']); db()->where('plan_id', $plan_id)->update('users', ['plan_settings' => $plan_settings]); /* Clear the cache */ cache()->clear(); } /* Set a nice success message */ Alerts::add_success(sprintf(l('global.success_message.update1'), '
' . $plan->name . '
')); /* Refresh the page */ redirect('admin/plan-update/' . $plan_id); } } /* Main View */ $data = [ 'plan_id' => $plan_id, 'plan' => $plan, 'taxes' => $taxes ?? null, 'additional_domains' => $additional_domains, 'monitor_check_intervals' => $monitor_check_intervals, 'dns_monitor_check_intervals' => $dns_monitor_check_intervals, 'server_monitor_check_intervals' => $server_monitor_check_intervals, ]; $view = new \Altum\View('admin/plan-update/index', (array) $this); $this->add_view_content('content', $view->run($data)); } }