"; file_put_contents($views_file, $new_content); return count($views_to_add); } return 0; } // Handle view scanning if (isset($_POST['scan_views'])) { $added_count = scan_and_update_views(); header('Location: index.php?page=profiles&views_added=' . $added_count); exit; } // Format key function function format_key($key) { $key = str_replace( ['_', 'url', 'db ', ' pass', ' user', 'ipn', 'paypal'], [' ', 'URL', 'Database ', ' Password', ' Username', 'IPN', 'PayPal'], strtolower($key) ); return ucwords($key); } // Format HTML output function function format_var_html($key, $value) { global $all_views; // Ensure all_views is loaded if (!isset($all_views) || !is_array($all_views)) { include dirname(__FILE__).'/settings/settingsviews.php'; } $html = ''; $value = htmlspecialchars(trim($value, '\''), ENT_QUOTES); $profile_contents = explode(',',$value); // Add profile header with bulk select options $checked_count = count(array_intersect($profile_contents, $all_views)); $total_count = count($all_views); $html .= '
'; $html .= '

Profile: ' . ucwords(str_replace('_', ' ', $key)) . ' (' . $checked_count . '/' . $total_count . ' selected)

'; $html .= '
'; $html .= ' '; $html .= ''; $html .= '
'; // Create a container for the checkboxes with data attributes for filtering $html .= '
'; // Group views by category for better organization $grouped_views = []; foreach ($all_views as $view) { $category = 'Other'; if (strpos($view, 'equipment') === 0) $category = 'Equipment'; elseif (strpos($view, 'product') === 0) $category = 'Products'; elseif (strpos($view, 'account') === 0) $category = 'Accounts'; elseif (strpos($view, 'user') === 0) $category = 'Users'; elseif (strpos($view, 'report') === 0) $category = 'Reports'; elseif (strpos($view, 'contract') === 0) $category = 'Contracts'; elseif (strpos($view, 'dealer') === 0) $category = 'Dealers'; elseif (strpos($view, 'rma') === 0) $category = 'RMA'; elseif (in_array($view, ['dashboard', 'profile', 'admin', 'settings', 'config'])) $category = 'Core'; $grouped_views[$category][] = $view; } // Output grouped checkboxes foreach ($grouped_views as $category => $views) { $html .= '
'; $html .= '
' . $category . '
'; foreach ($views as $view) { $checked = in_array($view, $profile_contents) ? 'checked' : ''; $html .= '
'; $html .= ''; $html .= '
'; } $html .= '
'; } $html .= '
'; return $html; } // Format tabs and content together (interleaved for collapsible functionality) function format_tabs_and_content($contents) { global $all_views; // Ensure all_views is loaded if (!isset($all_views) || !is_array($all_views)) { include dirname(__FILE__).'/settings/settingsviews.php'; } $rows = explode("\n", $contents); $output = ''; $profile_count = 0; // Count profiles for performance warning foreach ($rows as $row) { if (preg_match('/\/\*(.*?)\*\//', $row)) { $profile_count++; } } // Add performance notice for large numbers of profiles if ($profile_count > 10) { $output .= '
'; $output .= ''; $output .= '

Managing ' . $profile_count . ' profiles.

'; $output .= ''; $output .= '
'; } // Start with General tab and its content $output .= '
General
'; $output .= ''; $current_profile = strtolower(str_replace(' ', '_', $tab_match[1])); $output .= '
' . $tab_match[1] . '
'; $output .= ''; return $output; } if (isset($_POST['submit']) && !empty($_POST)) { //remove submit from POST unset($_POST['submit']); //Make POST ready for save into definition foreach($_POST as $profile_name => $profile_views){ $view_input = ''; foreach($profile_views as $profile_view){ $view_input .= $profile_view.','; } $view_input = "'".substr($view_input,0,-1)."'"; // Update the configuration file with the new keys and values $contents = preg_replace('/define\(\'' . $profile_name . '\'\, ?(.*?)\)/s', 'define(\'' . $profile_name . '\',' . $view_input . ')', $contents); } //SAVE TO FILE file_put_contents($file, $contents); //Return succesmessage header('Location: index.php?page=profiles&success_msg=1'); exit; } // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { $success_msg = 'Profiles updated successfully!'; } } // Handle views added message if (isset($_GET['views_added'])) { $added_count = (int)$_GET['views_added']; if ($added_count > 0) { $success_msg = $added_count . ' new views added!'; } else { $success_msg = 'No new views found. All views are up to date.'; } } template_header('Profiles', 'profiles'); $view .= '

Profiles

'; if (isset($success_msg)){ $view .= '

'.$success_msg.'

'; } $view .= format_tabs_and_content($contents); $view .= '
'; // Add basic JavaScript functionality $view .= ' '; //Output echo $view; template_footer(); ?>