PMA\libraries\Util::toggleButton PHP Method

toggleButton() public static method

Creates an AJAX sliding toggle button (or and equivalent form when AJAX is disabled)
public static toggleButton ( string $action, string $select_name, array $options, string $callback ) : string
$action string The URL for the request to be executed
$select_name string The name for the dropdown box
$options array An array of options (see rte_footer.lib.php)
$callback string A JS snippet to execute when the request is successfully processed
return string HTML code for the toggle button
    public static function toggleButton($action, $select_name, $options, $callback)
    {
        // Do the logic first
        $link = "{$action}&" . urlencode($select_name) . "=";
        $link_on = $link . urlencode($options[1]['value']);
        $link_off = $link . urlencode($options[0]['value']);
        if ($options[1]['selected'] == true) {
            $state = 'on';
        } else {
            if ($options[0]['selected'] == true) {
                $state = 'off';
            } else {
                $state = 'on';
            }
        }
        return Template::get('toggle_button')->render(['pmaThemeImage' => $GLOBALS['pmaThemeImage'], 'text_dir' => $GLOBALS['text_dir'], 'link_on' => $link_on, 'toggleOn' => str_replace(' ', ' ', htmlspecialchars($options[1]['label'])), 'toggleOff' => str_replace(' ', ' ', htmlspecialchars($options[0]['label'])), 'link_off' => $link_off, 'callback' => $callback, 'state' => $state]);
    }
Util