require_once plugin_dir_path( __FILE__ ) . '../includes/models/ExcellenceClub.php';
class Arvea_Admin {
private $plugin_name;
private $version;
private $calculations;
public function __construct($plugin_name, $version) {
$this->plugin_name = $plugin_name;
$this->version = $version;
if (class_exists('Arvea_Calculations')) {
$this->calculations = new Arvea_Calculations();
} else {
error_log('Arvea Plugin: Calculations class not found');
add_action('admin_notices', [$this, 'show_missing_calculations_notice']);
}
add_action('wp_ajax_arvea_send_telegram_test', array($this, 'ajax_send_telegram_test'));
add_action('wp_ajax_arvea_send_email_test', array($this, 'ajax_send_email_test'));
add_action('admin_post_arvea_add_sequence', [$this, 'handle_add_sequence']);
add_action('admin_post_arvea_delete_sequence', [$this, 'handle_delete_sequence']);
add_action('admin_post_arvea_delete_step', [$this, 'handle_delete_step']);
add_action('admin_post_arvea_manual_ac_update', [$this, 'handle_manual_ac_update']);
add_action('admin_post_arvea_add_partner', [$this, 'handle_add_partner_form']);
add_action('admin_post_arvea_import_partners_csv', [$this, 'handle_import_partners_csv']);
add_action('admin_post_arvea_update_user_tags', [$this, 'handle_update_user_tags']);
add_action('wp_ajax_arvea_validate_partner', [$this, 'ajax_validate_partner']);
// Growth strategies handlers
add_action('admin_post_arvea_enroll_strategy', [$this, 'handle_enroll_strategy']);
add_action('admin_post_arvea_update_strategy_progress', [$this, 'handle_update_strategy_progress']);
add_action('admin_post_arvea_create_custom_strategy', [$this, 'handle_create_custom_strategy']);
add_action('admin_post_arvea_pause_strategy', [$this, 'handle_pause_strategy']);
add_action('admin_post_arvea_resume_strategy', [$this, 'handle_resume_strategy']);
// Include database repair utility
require_once plugin_dir_path(__FILE__) . 'class-arvea-database-repair-utility.php';
// Include automation management
require_once plugin_dir_path(__FILE__) . 'class-arvea-automation.php';
add_action('wp_ajax_arvea_get_partner_details', [$this, 'ajax_get_partner_details']);
add_action('wp_ajax_arvea_update_partner', [$this, 'ajax_update_partner']);
// Include compensation admin handler
require_once plugin_dir_path(__FILE__) . 'class-arvea-compensation-admin-handler.php';
// Handle the calculations form submission
add_action('admin_init', [$this, 'handle_calculations_form']);
// Handle capability transfer when the Super Upline is changed
add_action('update_option_arvea_super_upline_user_id', [$this, 'handle_super_upline_change'], 10, 3);
// Load common components
$this->load_common_components();
// Initialize modern navigation
$this->init_navigation_hooks();
// Load access fix admin page
require_once plugin_dir_path(__FILE__) . 'fix-access-admin-page.php';
}
/**
* Load common components used across admin pages
*/
private function load_common_components() {
// Include breadcrumb component
require_once plugin_dir_path(__FILE__) . 'views/components/breadcrumb.php';
// Include page header component
require_once plugin_dir_path(__FILE__) . 'views/components/page-header.php';
// Include quick actions component
require_once plugin_dir_path(__FILE__) . 'views/components/quick-actions.php';
// Include sidebar navigation component (if it exists)
$sidebar_file = plugin_dir_path(__FILE__) . 'views/components/sidebar-navigation.php';
if (file_exists($sidebar_file)) {
require_once $sidebar_file;
}
}
public function show_missing_calculations_notice() {
echo '
';
echo '
Arvea Plugin: Critical error - Calculations class not found. Please reinstall the plugin.
';
echo '
';
}
public function enqueue_styles() {
// Only enqueue on ARVEA admin pages
if (!$this->is_arvea_admin_page()) {
return;
}
wp_enqueue_style(
$this->plugin_name,
plugin_dir_url(__FILE__) . 'css/arvea-admin.css',
array(),
$this->version,
'all'
);
// Enqueue modern design system
wp_enqueue_style(
$this->plugin_name . '-modern',
plugin_dir_url(__FILE__) . 'css/arvea-modern-design-system.css',
array(),
$this->version,
'all'
);
// Enqueue modern navigation
wp_enqueue_style(
$this->plugin_name . '-navigation',
plugin_dir_url(__FILE__) . 'css/arvea-modern-navigation.css',
array(),
$this->version,
'all'
);
// Enqueue Google Fonts
wp_enqueue_style(
'arvea-fonts',
'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap',
array(),
null
);
// Add modern navigation wrapper styles
$this->add_navigation_wrapper_styles();
}
public function enqueue_scripts() {
wp_enqueue_script(
$this->plugin_name,
plugin_dir_url(__FILE__) . 'js/arvea-admin.js',
array('jquery'),
$this->version,
false
);
// Enqueue modern components
wp_enqueue_script(
$this->plugin_name . '-modern',
plugin_dir_url(__FILE__) . 'js/arvea-modern-components.js',
array('jquery'),
$this->version,
true
);
// Localize script for AJAX
wp_localize_script(
$this->plugin_name,
'arvea_ajax',
[
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('arvea_ajax_nonce'),
'strings' => [
'confirm_delete' => __('Are you sure you want to delete this item?', 'arvea-super-upline'),
'loading' => __('Loading...', 'arvea-super-upline'),
'error' => __('An error occurred. Please try again.', 'arvea-super-upline'),
'success' => __('Operation completed successfully.', 'arvea-super-upline')
]
]
);
}
public function setup_admin_menu() {
// Add capability to admin role - this is still needed for the unified system
if (function_exists('get_role')) {
$admin_role = get_role('administrator');
if ($admin_role && !$admin_role->has_cap('manage_arvea_crm')) {
$admin_role->add_cap('manage_arvea_crm');
}
} else if (function_exists('wp_roles')) {
// Fallback to wp_roles() if get_role is not available
$wp_roles = wp_roles();
$admin_role = $wp_roles->get_role('administrator');
if ($admin_role && !$admin_role->has_cap('manage_arvea_crm')) {
$admin_role->add_cap('manage_arvea_crm');
}
}
// The old menu system has been completely replaced by the unified
// Elite Command Center. All menu registration is now handled by the
// Arvea_Elite_Command_Center class which provides a comprehensive
// admin interface with all MLM CRM functionality organized properly.
// No menu registration needed here - the unified system handles everything
return;
}
// Display methods for all admin pages
public function display_dashboard_page() {
require_once plugin_dir_path(__FILE__) . 'views/dashboard-page.php';
}
public function display_partners_page() {
require_once plugin_dir_path(__FILE__) . 'views/partners-page.php';
}
public function display_add_partner_page() {
require_once plugin_dir_path(__FILE__) . 'views/add-user-page.php';
}
public function display_manage_partners_page() {
require_once plugin_dir_path(__FILE__) . 'views/manage-partners-page.php';
}
public function display_user_management_page() {
require_once plugin_dir_path(__FILE__) . 'views/user-management-page.php';
}
public function display_tags_page() {
require_once plugin_dir_path(__FILE__) . 'views/tags-page.php';
}
public function display_countries_page() {
require_once plugin_dir_path(__FILE__) . 'views/countries-page.php';
}
public function display_ranks_page() {
require_once plugin_dir_path(__FILE__) . 'views/ranks-page.php';
}
public function display_automation_page() {
require_once plugin_dir_path(__FILE__) . 'views/automation-page.php';
}
public function display_growth_strategies_page() {
require_once plugin_dir_path(__FILE__) . 'views/growth-strategies-page.php';
}
public function display_excellence_club_page() {
require_once plugin_dir_path(__FILE__) . 'views/excellence-club-page.php';
}
public function display_database_repair_page() {
require_once plugin_dir_path(__FILE__) . 'views/database-repair-page.php';
}
public function display_settings_page() {
require_once plugin_dir_path(__FILE__) . 'views/settings-page.php';
}
public function display_calculations_page() {
require_once plugin_dir_path(__FILE__) . 'views/calculations-page.php';
}
public function display_sequence_steps_page() {
require_once plugin_dir_path(__FILE__) . 'views/sequence-steps-page.php';
}
public function display_navigation_test_page() {
$test_file = plugin_dir_path(__FILE__) . 'views/navigation-test-page.php';
if (file_exists($test_file)) {
require_once $test_file;
} else {
echo '
';
echo '
Navigation test page template is missing.
';
echo '
';
}
}
public function display_test_dashboard_page() {
$dashboard_file = plugin_dir_path(__FILE__) . 'views/test-dashboard-page.php';
if (file_exists($dashboard_file)) {
require_once $dashboard_file;
} else {
echo '
';
echo '
Test dashboard page template is missing.
';
echo '
';
}
}
public function display_integration_test_page() {
$test_file = plugin_dir_path(__FILE__) . 'views/integration-test.php';
if (file_exists($test_file)) {
require_once $test_file;
} else {
echo '
';
echo '
Integration test page template is missing.
';
echo '
';
}
}
public function display_integration_status_page() {
$status_file = plugin_dir_path(__FILE__) . 'views/integration-status.php';
if (file_exists($status_file)) {
require_once $status_file;
} else {
echo '
';
echo '
Integration status page template is missing.
';
echo '
';
}
}
// Modern navigation integration methods
/**
* Check if current page is an ARVEA admin page
*/
private function is_arvea_admin_page() {
$screen = get_current_screen();
if (!$screen) {
return false;
}
// Check if we're on an ARVEA admin page
return strpos($screen->id, 'arvea') !== false ||
strpos($screen->base, 'arvea') !== false ||
(isset($_GET['page']) && strpos($_GET['page'], 'arvea') !== false);
}
/**
* Initialize navigation hooks
*/
private function init_navigation_hooks() {
// Add admin body classes for styling
add_filter('admin_body_class', [$this, 'add_admin_body_classes']);
// Enqueue navigation scripts and styles
add_action('admin_enqueue_scripts', [$this, 'enqueue_navigation_assets']);
}
/**
* Add navigation wrapper styles
*/
private function add_navigation_wrapper_styles() {
if (!$this->is_arvea_admin_page()) {
return;
}
echo '';
}
/**
* Add admin body classes
*/
public function add_admin_body_classes($classes) {
if ($this->is_arvea_admin_page()) {
$classes .= ' arvea-admin-page';
// Add specific page class
if (isset($_GET['page'])) {
$page_class = 'arvea-page-' . str_replace(['arvea-', '_'], ['', '-'], $_GET['page']);
$classes .= ' ' . $page_class;
}
}
return $classes;
}
/**
* Enqueue navigation assets
*/
public function enqueue_navigation_assets() {
if (!$this->is_arvea_admin_page()) {
return;
}
// Enqueue modern navigation JavaScript
wp_enqueue_script(
$this->plugin_name . '-navigation',
plugin_dir_url(__FILE__) . 'js/arvea-modern-navigation.js',
array('jquery'),
$this->version,
true
);
// Localize script with navigation data
wp_localize_script(
$this->plugin_name . '-navigation',
'arvea_navigation',
[
'current_page' => isset($_GET['page']) ? $_GET['page'] : 'arvea-elite',
'admin_url' => admin_url('admin.php'),
'nonce' => wp_create_nonce('arvea_navigation_nonce'),
'strings' => [
'search_placeholder' => __('Search...', 'arvea-super-upline'),
'loading' => __('Loading...', 'arvea-super-upline'),
'error' => __('An error occurred', 'arvea-super-upline')
]
]
);
}
// Placeholder methods for missing functionality - these would need to be implemented
public function handle_add_sequence() {
// Implementation needed
}
public function handle_delete_sequence() {
// Implementation needed
}
public function handle_delete_step() {
// Implementation needed
}
public function handle_manual_ac_update() {
// Implementation needed
}
public function handle_add_partner_form() {
// Security check
if (!isset($_POST['arvea_add_partner_nonce']) || !wp_verify_nonce($_POST['arvea_add_partner_nonce'], 'arvea_add_partner_action')) {
wp_die('Security check failed.');
}
// Permission check - be more permissive for administrators and super uplines
$current_user = wp_get_current_user();
$super_upline_id = get_option('arvea_super_upline_user_id');
$has_access = false;
// Super Upline always has access
if ($super_upline_id && $current_user->ID == $super_upline_id) {
$has_access = true;
}
// Administrator role has access
else if (in_array('administrator', $current_user->roles)) {
$has_access = true;
}
// Check for the base capability
else if (current_user_can('manage_arvea_crm')) {
$has_access = true;
}
if (!$has_access) {
wp_die('You do not have permission to perform this action.');
}
global $wpdb;
$users_table = $wpdb->prefix . 'arvea_users';
// Sanitize input data
$first_name = sanitize_text_field($_POST['first_name']);
$last_name = sanitize_text_field($_POST['last_name']);
$email = sanitize_email($_POST['email']);
$arvea_id = sanitize_text_field($_POST['arvea_id']);
$country_code = sanitize_text_field($_POST['country']);
$referrer_id = !empty($_POST['sponsor']) ? intval($_POST['sponsor']) : 0;
$rank_id = intval($_POST['rank']);
// Basic validation
if (empty($first_name) || empty($last_name) || empty($email) || empty($arvea_id) || empty($country_code) || empty($rank_id)) {
wp_redirect(add_query_arg('arvea_message', 'error', wp_get_referer()));
exit;
}
// Check if email already exists
$existing_user = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM $users_table WHERE email = %s",
$email
));
if ($existing_user) {
wp_redirect(add_query_arg('arvea_message', 'email_exists', wp_get_referer()));
exit;
}
// Check if ARVEA ID already exists
$existing_arvea_id = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM $users_table WHERE arvea_official_id = %s",
$arvea_id
));
if ($existing_arvea_id) {
wp_redirect(add_query_arg('arvea_message', 'arvea_id_exists', wp_get_referer()));
exit;
}
// If no sponsor is selected, assign the Super Upline by default
if (empty($referrer_id)) {
$super_upline_id = get_option('arvea_super_upline_user_id');
if ($super_upline_id) {
$referrer_id = $super_upline_id;
}
}
// Check if table exists
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$users_table'") == $users_table;
if (!$table_exists) {
wp_redirect(add_query_arg('arvea_message', 'database_error', wp_get_referer()));
exit;
}
// Insert new partner
$result = $wpdb->insert(
$users_table,
[
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'arvea_official_id' => $arvea_id,
'country_code' => $country_code,
'referrer_id' => $referrer_id,
'rank_id' => $rank_id,
'status' => 'partner',
'registration_date' => current_time('mysql', 1),
'telegram_chat_id' => 0, // Default value for required field
'personal_ac' => 0.00,
'team_ac' => 0.00
]
);
if ($result === false) {
error_log('ARVEA: Failed to insert partner - ' . $wpdb->last_error);
wp_redirect(add_query_arg('arvea_message', 'database_error', wp_get_referer()));
exit;
}
// Get the new partner ID
$new_partner_id = $wpdb->insert_id;
// Log the action
error_log("ARVEA: New partner added - ID: $new_partner_id, Name: $first_name $last_name, Email: $email");
// Redirect with success message
wp_redirect(add_query_arg([
'arvea_message' => 'success',
'partner_id' => $new_partner_id
], wp_get_referer()));
exit;
}
public function handle_import_partners_csv() {
// Implementation needed
}
public function handle_update_user_tags() {
// Implementation needed
}
public function ajax_validate_partner() {
// Implementation needed
}
public function ajax_get_partner_details() {
// Implementation needed
}
public function ajax_update_partner() {
// Implementation needed
}
public function handle_enroll_strategy() {
// Verify nonce
if (!isset($_POST['arvea_enroll_nonce']) || !wp_verify_nonce($_POST['arvea_enroll_nonce'], 'arvea_enroll_strategy')) {
wp_die('Security check failed.');
}
// Permission check - be more permissive for administrators and super uplines
$current_user = wp_get_current_user();
$super_upline_id = get_option('arvea_super_upline_user_id');
$has_access = false;
// Super Upline always has access
if ($super_upline_id && $current_user->ID == $super_upline_id) {
$has_access = true;
}
// Administrator role has access
else if (in_array('administrator', $current_user->roles)) {
$has_access = true;
}
// Check for the base capability
else if (current_user_can('manage_arvea_crm')) {
$has_access = true;
}
if (!$has_access) {
wp_die('Permission denied.');
}
global $wpdb;
$user_automations_table = $wpdb->prefix . 'arvea_user_automations';
$users_table = $wpdb->prefix . 'arvea_users';
$sequences_table = $wpdb->prefix . 'arvea_automation_sequences';
// Check if tables exist
$automations_table_exists = $wpdb->get_var("SHOW TABLES LIKE '$user_automations_table'") == $user_automations_table;
$users_table_exists = $wpdb->get_var("SHOW TABLES LIKE '$users_table'") == $users_table;
$sequences_table_exists = $wpdb->get_var("SHOW TABLES LIKE '$sequences_table'") == $sequences_table;
if (!$automations_table_exists || !$users_table_exists || !$sequences_table_exists) {
wp_redirect(add_query_arg('message', 'database_error', wp_get_referer()));
exit;
}
// Sanitize input
$partner_id = intval($_POST['partner_id']);
$strategy_id = intval($_POST['strategy_id_select']);
$send_welcome = isset($_POST['send_welcome']) ? 1 : 0;
if (!$partner_id || !$strategy_id) {
wp_redirect(add_query_arg('message', 'invalid_data', wp_get_referer()));
exit;
}
// Check if partner exists
$partner = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM $users_table WHERE id = %d",
$partner_id
));
if (!$partner) {
wp_redirect(add_query_arg('message', 'partner_not_found', wp_get_referer()));
exit;
}
// Check if strategy exists
$strategy = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM $sequences_table WHERE id = %d",
$strategy_id
));
if (!$strategy) {
wp_redirect(add_query_arg('message', 'strategy_not_found', wp_get_referer()));
exit;
}
// Check if already enrolled in this strategy
$existing_enrollment = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM $user_automations_table WHERE user_id = %d AND automation_id = %d",
$partner_id,
$strategy_id
));
if ($existing_enrollment) {
wp_redirect(add_query_arg('message', 'already_enrolled', wp_get_referer()));
exit;
}
// Enroll the partner
$result = $wpdb->insert(
$user_automations_table,
[
'user_id' => $partner_id,
'automation_id' => $strategy_id,
'status' => 'active',
'current_step' => 1,
'start_date' => current_time('mysql', 1),
'next_run_time' => current_time('mysql', 1),
'last_run_time' => null,
'completed_at' => null
]
);
if ($result === false) {
error_log('ARVEA: Failed to enroll partner in strategy - ' . $wpdb->last_error);
wp_redirect(add_query_arg('message', 'enrollment_failed', wp_get_referer()));
exit;
}
// Log the enrollment
$enrollment_id = $wpdb->insert_id;
error_log("ARVEA: Partner enrolled in strategy - Partner: {$partner->first_name} {$partner->last_name} (ID: $partner_id), Strategy: {$strategy->name} (ID: $strategy_id), Enrollment ID: $enrollment_id");
// Send welcome message if requested and Telegram is available
if ($send_welcome && class_exists('Arvea_Telegram_Bot') && !empty($partner->telegram_chat_id)) {
try {
$telegram_bot = Arvea_Telegram_Bot::get_instance();
$welcome_message = $this->build_welcome_message($partner, $strategy);
$telegram_bot->send_message_to_user($partner_id, $welcome_message);
} catch (Exception $e) {
error_log('ARVEA: Failed to send welcome message - ' . $e->getMessage());
// Don't fail the enrollment if message sending fails
}
}
// Redirect with success message
wp_redirect(add_query_arg([
'message' => 'enrolled_success',
'partner_name' => urlencode($partner->first_name . ' ' . $partner->last_name),
'strategy_name' => urlencode($strategy->name)
], wp_get_referer()));
exit;
}
/**
* Build welcome message for strategy enrollment
*/
private function build_welcome_message($partner, $strategy) {
$message = "🎉 Welcome to {$strategy->name}!\n\n";
$message .= "Hi {$partner->first_name}! You've been enrolled in our proven growth strategy.\n\n";
if (strpos($strategy->name, 'Manager') !== false) {
$message .= "🎯 Your Goal: Achieve Manager rank\n";
$message .= "📈 Your Path: Follow our step-by-step monthly plan\n";
$message .= "💪 Your Support: We'll guide you every step of the way\n\n";
} elseif (strpos($strategy->name, 'Sapphire') !== false) {
$message .= "👑 Your Goal: Build 18 qualified managers\n";
$message .= "🏗️ Your Focus: Leadership development and duplication\n";
$message .= "🎖️ Your Reward: Sapphire Manager status\n\n";
} elseif (strpos($strategy->name, 'Excellence') !== false) {
$message .= "💎 Your Goal: Excellence Club Golden Bonus\n";
$message .= "💰 Your Focus: Maximize TF and FEM earnings\n";
$message .= "🏆 Your Reward: Maximum commission potential\n\n";
}
$message .= "📱 Next Steps:\n";
$message .= "• Check your dashboard for your personalized action plan\n";
$message .= "• Follow the monthly milestones\n";
$message .= "• Stay connected for updates and support\n\n";
$message .= "🚀 Let's achieve greatness together!";
return $message;
}
public function handle_update_strategy_progress() {
if (!isset($_POST['arvea_progress_nonce']) || !wp_verify_nonce($_POST['arvea_progress_nonce'], 'arvea_update_progress')) {
wp_die('Security check failed');
}
// Permission check - be more permissive for administrators and super uplines
$current_user = wp_get_current_user();
$super_upline_id = get_option('arvea_super_upline_user_id');
$has_access = false;
// Super Upline always has access
if ($super_upline_id && $current_user->ID == $super_upline_id) {
$has_access = true;
}
// Administrator role has access
else if (in_array('administrator', $current_user->roles)) {
$has_access = true;
}
// Check for the base capability
else if (current_user_can('manage_arvea_crm')) {
$has_access = true;
}
if (!$has_access) {
wp_die('Permission denied');
}
$enrollment_id = intval($_POST['enrollment_id']);
$new_step = intval($_POST['new_step']);
$notes = sanitize_textarea_field($_POST['notes']);
global $wpdb;
$user_automations_table = $wpdb->prefix . 'arvea_user_automations';
$result = $wpdb->update($user_automations_table, [
'current_step' => $new_step,
'last_run_time' => current_time('mysql')
], ['id' => $enrollment_id]);
// Log progress update
if ($result && !empty($notes)) {
$tracking_table = $wpdb->prefix . 'arvea_tracking';
$enrollment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $user_automations_table WHERE id = %d", $enrollment_id));
if ($enrollment) {
$wpdb->insert($tracking_table, [
'user_id' => $enrollment->user_id,
'activity_type' => 'strategy_progress',
'activity_value' => $new_step,
'activity_date' => current_time('mysql'),
'notes' => $notes
]);
}
}
wp_redirect(admin_url('admin.php?page=arvea-growth-strategies&message=progress_updated'));
exit;
}
public function handle_create_custom_strategy() {
if (!isset($_POST['arvea_custom_strategy_nonce']) || !wp_verify_nonce($_POST['arvea_custom_strategy_nonce'], 'arvea_create_custom_strategy')) {
wp_die('Security check failed');
}
// Permission check - be more permissive for administrators and super uplines
$current_user = wp_get_current_user();
$super_upline_id = get_option('arvea_super_upline_user_id');
$has_access = false;
// Super Upline always has access
if ($super_upline_id && $current_user->ID == $super_upline_id) {
$has_access = true;
}
// Administrator role has access
else if (in_array('administrator', $current_user->roles)) {
$has_access = true;
}
// Check for the base capability
else if (current_user_can('manage_arvea_crm')) {
$has_access = true;
}
if (!$has_access) {
wp_die('Permission denied');
}
$name = sanitize_text_field($_POST['strategy_name']);
$description = sanitize_textarea_field($_POST['strategy_description']);
$duration_months = intval($_POST['duration_months']);
$target_rank = sanitize_text_field($_POST['target_rank']);
global $wpdb;
$sequences_table = $wpdb->prefix . 'arvea_automation_sequences';
$result = $wpdb->insert($sequences_table, [
'name' => $name,
'description' => $description,
'trigger_type' => 'manual_enrollment',
'created_at' => current_time('mysql')
]);
if ($result) {
$sequence_id = $wpdb->insert_id;
// Create basic steps for custom strategy
$this->create_default_strategy_steps($sequence_id, $duration_months);
wp_redirect(admin_url('admin.php?page=arvea-growth-strategies&message=custom_strategy_created'));
} else {
wp_redirect(admin_url('admin.php?page=arvea-growth-strategies&error=custom_strategy_failed'));
}
exit;
}
public function handle_pause_strategy() {
if (!isset($_GET['arvea_pause_nonce']) || !wp_verify_nonce($_GET['arvea_pause_nonce'], 'arvea_pause_strategy')) {
wp_die('Security check failed');
}
// Permission check - be more permissive for administrators and super uplines
$current_user = wp_get_current_user();
$super_upline_id = get_option('arvea_super_upline_user_id');
$has_access = false;
// Super Upline always has access
if ($super_upline_id && $current_user->ID == $super_upline_id) {
$has_access = true;
}
// Administrator role has access
else if (in_array('administrator', $current_user->roles)) {
$has_access = true;
}
// Check for the base capability
else if (current_user_can('manage_arvea_crm')) {
$has_access = true;
}
if (!$has_access) {
wp_die('Permission denied');
}
$enrollment_id = intval($_GET['enrollment_id']);
global $wpdb;
$user_automations_table = $wpdb->prefix . 'arvea_user_automations';
$wpdb->update($user_automations_table, [
'status' => 'paused'
], ['id' => $enrollment_id]);
wp_redirect(admin_url('admin.php?page=arvea-growth-strategies&message=strategy_paused'));
exit;
}
public function handle_resume_strategy() {
if (!isset($_GET['arvea_resume_nonce']) || !wp_verify_nonce($_GET['arvea_resume_nonce'], 'arvea_resume_strategy')) {
wp_die('Security check failed');
}
// Permission check - be more permissive for administrators and super uplines
$current_user = wp_get_current_user();
$super_upline_id = get_option('arvea_super_upline_user_id');
$has_access = false;
// Super Upline always has access
if ($super_upline_id && $current_user->ID == $super_upline_id) {
$has_access = true;
}
// Administrator role has access
else if (in_array('administrator', $current_user->roles)) {
$has_access = true;
}
// Check for the base capability
else if (current_user_can('manage_arvea_crm')) {
$has_access = true;
}
if (!$has_access) {
wp_die('Permission denied');
}
$enrollment_id = intval($_GET['enrollment_id']);
global $wpdb;
$user_automations_table = $wpdb->prefix . 'arvea_user_automations';
$wpdb->update($user_automations_table, [
'status' => 'active',
'next_run_time' => current_time('mysql')
], ['id' => $enrollment_id]);
wp_redirect(admin_url('admin.php?page=arvea-growth-strategies&message=strategy_resumed'));
exit;
}
private function create_default_strategy_steps($sequence_id, $duration_months) {
global $wpdb;
$steps_table = $wpdb->prefix . 'arvea_automation_steps';
$steps_per_month = 4; // Weekly check-ins
$total_steps = $duration_months * $steps_per_month;
$delay_days = 7; // Weekly intervals
for ($i = 1; $i <= $total_steps; $i++) {
$week_number = ceil($i / $steps_per_month);
$wpdb->insert($steps_table, [
'sequence_id' => $sequence_id,
'step_order' => $i,
'delay_days' => $delay_days,
'action_type' => 'telegram_message',
'subject_template' => "Week {$week_number} Check-in",
'body_template' => "Hello {first_name}! This is your week {$week_number} progress check-in. How are you progressing towards your goals?"
]);
}
}
public function handle_calculations_form() {
// Implementation needed
}
public function handle_super_upline_change($old_value, $new_value, $option) {
// Remove capability from the old user
if (!empty($old_value)) {
$old_user = get_user_by('ID', $old_value);
if ($old_user && !user_can($old_user, 'administrator')) {
// Only remove if not administrator (admins keep their capabilities)
$old_user->remove_cap('manage_arvea_crm');
$old_user->remove_cap('manage_arvea_elite');
$old_user->remove_cap('view_arvea_dashboard');
$old_user->remove_cap('manage_arvea_partners');
$old_user->remove_cap('manage_arvea_settings');
$old_user->remove_cap('manage_arvea_automation');
$old_user->remove_cap('manage_arvea_integrations');
}
}
// Add capability to the new user
if (!empty($new_value)) {
$new_user = get_user_by('ID', $new_value);
if ($new_user && $new_user->exists()) {
$new_user->add_cap('manage_arvea_crm', true);
$new_user->add_cap('manage_arvea_elite', true);
$new_user->add_cap('view_arvea_dashboard', true);
$new_user->add_cap('manage_arvea_partners', true);
$new_user->add_cap('manage_arvea_settings', true);
$new_user->add_cap('manage_arvea_automation', true);
$new_user->add_cap('manage_arvea_integrations', true);
// Clear user capability cache
wp_cache_delete($new_user->ID, 'user_meta');
wp_cache_delete($new_user->ID, 'users');
}
}
}
public function ajax_send_telegram_test() {
// Implementation needed
}
public function ajax_send_email_test() {
// Implementation needed
}
public function display_analytics_page() {
require_once plugin_dir_path(__FILE__) . 'views/analytics-dashboard-page.php';
}
public function display_security_page() {
require_once plugin_dir_path(__FILE__) . 'views/security-dashboard-page.php';
}
public function display_performance_page() {
require_once plugin_dir_path(__FILE__) . 'views/performance-dashboard-page.php';
}
}
❇️ Domptez vos envies et renforcez votre volonté avec le coupe faim ARVEA. 🥰 Disponible de suite ! 😉 #arvea #ARVEA_NATURE #arvea... – TopArvea
❇️ Domptez vos envies et renforcez votre volonté avec le coupe faim ARVEA. 🥰
Disponible de suite ! 😉
#arvea #ARVEA_NATURE #arvea_algérie #sahalina #أرفيا #صحة_لينا #أرفيا_الجزائر
#coupe_faim #retour #retour_en_stock
Si vous aussi voulez profité des remises (20 à 30 %) sur les promos des produits Arvea Nature Algérie ou profitez de Business Opportunity Arvea Algérie avec un kit de démarrage, système de recrutement et duplication venez nous rejoindre en cliquant ci dessous.
L’inscription gratuite Vous permet d’être directement lié au fournisseur Arvea nature c-a-d en première main, ce qui vous permet de bénéficier de remises de 20% à 30% prix catalogue sur tous les produits Arvea.
يتيح لك التسجيل المجاني الارتباط مباشرة بالمورد ارفيا ، أي بشكل مباشر ، مما يتيح لك الاستفادة من خصومات تتراوح بين 20٪ إلى 30٪ من قائمة الأسعار على جميع منتجات ارفيا.
Gagner des primes mensuel sur le chiffre de votre groupes sur cinq niveaux de partenaires.
…اربح مكافآت شهرية على عدد مجموعاتك على خمسة مستويات من الشركاء
Inscrivez vous !!! ET OBTENEZ UN LIEN D’INSCRIPTION :