'; if (in_array($view, $profile_contents)){ $html .= ' '.$view; } else { $html .= ' '.$view; } $html .= ''; } return $html; } // Format tabs function format_tabs($contents) { $rows = explode("\n", $contents); $tab = '
'; $tab .= 'General'; for ($i = 0; $i < count($rows); $i++) { preg_match('/\/\*(.*?)\*\//', $rows[$i], $match); if ($match) { $tab .= '' . $match[1] . ''; } } $tab .= '
'; return $tab; } // Format form function format_form($contents) { $rows = explode("\n", $contents); $form = '
Each tab represents a profile. Each element in a profile represents a view and or API access.'; for ($i = 0; $i < count($rows); $i++) { preg_match('/\/\*(.*?)\*\//', $rows[$i], $match); if ($match) { $form .= '
'; } preg_match('/define\(\'(.*?)\', ?(.*?)\)/', $rows[$i], $match); if ($match) { $form .= format_var_html($match[1], $match[2]); } } $form .= '
'; return $form; } 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!'; } } template_header('Profiles', 'profiles'); $view .= '

Profiles

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

'.$success_msg.'

'; } $view .= format_tabs($contents); $view .= '
'; $view .= format_form($contents); $view .= '
'; //Output echo $view; template_footer(); ?>