src/UI/SettingsForm.php
public static function select($name, $default=false, $fields)
    {
        global $USER;
        if ( ! $USER ) return;
        $oldsettings = Settings::linkGetAll();
        if ( ! $USER->instructor ) {
            $configured = false;
            foreach ( $fields as $k => $v ) {
                $index = $k;
                $display = $v;
                if ( is_int($index) ) $index = $display; // No keys
                if ( ! is_string($display) ) $display = $index;
                if ( isset($oldsettings[$name]) && $k == $oldsettings[$name] ) {
                    $configured = $display;
                }
            }
            if ( $configured === false ) {
                echo('<p>'._m('Setting').' '.htmlent_utf8($name).' '._m('is not set').'</p>');
            } else {
                echo('<p>'.htmlent_utf8(ucwords($name)).' '._m('is set to').' '.htmlent_utf8($configured).'</p>');
            }
            return;
        }

        // Instructor view
        if ( $default === false ) $default = _m('Please Select');
        echo('<select name="'.$name.'">');
        echo('<option value="0">'.$default.'</option>');
        foreach ( $fields as $k => $v ) {
            $index = $k;
            $display = $v;
            if ( is_int($index) ) $index = $display; // No keys
            if ( ! is_string($display) ) $display = $index;
            echo('<option value="'.$index.'"');
            if ( isset($oldsettings[$name]) && $index == $oldsettings[$name] ) {
                echo(' selected');
            }
            echo('>'.$display.'</option>'."\n");
        }
        echo('</select>');
    }
public static function select($name, $default=false, $fields)
    {
        global $USER;
        if ( ! $USER ) return;
        $oldsettings = Settings::linkGetAll();
        if ( ! $USER->instructor ) {
            $configured = false;
            foreach ( $fields as $k => $v ) {
                $index = $k;
                $display = $v;
                if ( is_int($index) ) $index = $display; // No keys
                if ( ! is_string($display) ) $display = $index;
                if ( isset($oldsettings[$name]) && $k == $oldsettings[$name] ) {
                    $configured = $display;
                }
            }
            if ( $configured === false ) {
                echo('<p>'._m('Setting').' '.htmlent_utf8($name).' '._m('is not set').'</p>');
            } else {
                echo('<p>'.htmlent_utf8(ucwords($name)).' '._m('is set to').' '.htmlent_utf8($configured).'</p>');
            }
            return;
        }

        // Instructor view
        if ( $default === false ) $default = _m('Please Select');
        echo('<select name="'.$name.'">');
        echo('<option value="0">'.$default.'</option>');
        foreach ( $fields as $k => $v ) {
            $index = $k;
            $display = $v;
            if ( is_int($index) ) $index = $display; // No keys
            if ( ! is_string($display) ) $display = $index;
            echo('<option value="'.$index.'"');
            if ( isset($oldsettings[$name]) && $index == $oldsettings[$name] ) {
                echo(' selected');
            }
            echo('>'.$display.'</option>'."\n");
        }
        echo('</select>');
    }
public static function select ( $ name , $ default = false , $ fields ) { global $ USER ; if ( ! $ USER ) return ; $ oldsettings = Settings :: linkGetAll ( ) ; if ( ! $ USER -> instructor ) { $ configured = false ; foreach ( $ fields as $ k => $ v ) { $ index = $ k ; $ display = $ v ; if ( is_int ( $ index ) ) $ index = $ display ; // No keys if ( ! is_string ( $ display ) ) $ display = $ index ; if ( isset ( $ oldsettings [ $ name ] ) && $ k == $ oldsettings [ $ name ] ) { $ configured = $ display ; } } if ( $ configured === false ) { echo ( '<p>' . _m ( 'Setting' ) . ' ' . htmlent_utf8 ( $ name ) . ' ' . _m ( 'is not set' ) . '</p>' ) ; } else { echo ( '<p>' . htmlent_utf8 ( ucwords ( $ name ) ) . ' ' . _m ( 'is set to' ) . ' ' . htmlent_utf8 ( $ configured ) . '</p>' ) ; } return ; } // Instructor view if ( $ default === false ) $ default = _m ( 'Please Select' ) ; echo ( '<select name="' . $ name . '">' ) ; echo ( '<option value="0">' . $ default . '</option>' ) ; foreach ( $ fields as $ k => $ v ) { $ index = $ k ; $ display = $ v ; if ( is_int ( $ index ) ) $ index = $ display ; // No keys if ( ! is_string ( $ display ) ) $ display = $ index ; echo ( '<option value="' . $ index . '"' ) ; if ( isset ( $ oldsettings [ $ name ] ) && $ index == $ oldsettings [ $ name ] ) { echo ( ' selected' ) ; } echo ( '>' . $ display . '</option>' . "\n" ) ; } echo ( '</select>' ) ; }
Handle a settings selector box
Handle a settings selector box