<?php 
        if ($non_was_selected) {
            // no group pre-selected, display opening page
            ?>
<div class="wrap">
<dl>
<?php 
            //iterate through the available option groups. output them as a definition list.
            $option_groups = $wpdb->get_results("SELECT group_id, group_name, group_desc, group_longdesc FROM " . wp_table('optiongroups') . " ORDER BY group_id");
            foreach ($option_groups as $option_group) {
                echo "  <dt><a href=\"{$this_file}?option_group_id={$option_group->group_id}\" title=\"" . replace_constant($option_group->group_desc) . "\">{$option_group->group_name}</a></dt>\n";
                $current_long_desc = $option_group->group_longdesc;
                if ($current_long_desc == '') {
                    $current_long_desc = '<br />' . _LANG_WOP_NO_HELPS;
                }
                echo "  <dd>" . replace_constant($option_group->group_desc) . ": {$current_long_desc}</dd>\n";
            }
            // end for each group
            ?>
  <dt><a href="options-permalink.php"><?php 
            echo _LANG_WOP_PERM_LINKS;
            ?>
</a></dt>
  <dd><?php 
            echo _LANG_WOP_PERM_CONFIG;
            ?>
</dd>
</dl>
</div>
<?php 
        } else {
            echo $this_file;
            ?>
" method="post">
  <input type="hidden" name="action" value="update" />
  <input type="hidden" name="option_group_id" value="<?php 
            echo $option_group_id;
            ?>
" />
  <table width="90%" cellpadding="2" cellspacing="2" border="0">
<?php 
            //Now display all the options for the selected group.
            $options = $wpdb->get_results("SELECT {$wpdb->options[$wp_id]}.option_id, option_name, option_type, option_value, option_width, option_height, option_description, option_admin_level " . "FROM {$wpdb->options[$wp_id]} " . "LEFT JOIN {$wpdb->optiongroup_options[$wp_id]} ON {$wpdb->options[$wp_id]}.option_id = {$wpdb->optiongroup_options[$wp_id]}.option_id " . "WHERE group_id = {$option_group_id} " . "ORDER BY seq");
            if ($options) {
                foreach ($options as $option) {
                    echo '    <tr><td width="10%" valign="top">' . get_option_widget($option, $user_level >= $option->option_admin_level, '</td><td width="15%" valign="top" style="border: 1px solid #ccc">');
                    echo "    </td><td  valign='top' class='helptext'>" . replace_constant($option->option_description) . "</td></tr>\n";
                }
            }
            ?>
    <tr><td colspan="3">&nbsp;</td></tr>
    <tr><td align="center" colspan="3"><input type="submit" name="Update" value="<?php 
            echo _LANG_WOP_SUBMIT_TEXT;
            ?>
" /></td></tr>
    <tr><td colspan="3"><?php 
            echo $message;
            ?>
</td></tr>
  </table>
  </form>
</div>
        include_once 'admin-header.php';
        if ($user_level <= 3) {
            die("You have no right to edit the options for this blog.<br>Ask for a promotion to your <a href=\"mailto:" . get_settings('admin_email') . "\">blog admin</a> :)");
        }
        ?>
 <ul id="adminmenu2"> 
  <?php 
        //we need to iterate through the available option groups.
        $option_groups = $wpdb->get_results("SELECT group_id, group_name, group_desc, group_longdesc FROM {$wpdb->optiongroups[$wp_id]} ORDER BY group_id");
        foreach ($option_groups as $option_group) {
            if ($option_group->group_id == $option_group_id) {
                $current_desc = $option_group->group_desc;
                $current_long_desc = $option_group->group_longdesc;
                echo "  <li><a id=\"current2\" href=\"{$this_file}?option_group_id={$option_group->group_id}\" title=\"" . replace_constant($option_group->group_desc) . "\">{$option_group->group_name}</a></li>\n";
            } else {
                echo "  <li><a href=\"{$this_file}?option_group_id={$option_group->group_id}\" title=\"" . replace_constant($option_group->group_desc) . "\">{$option_group->group_name}</a></li>\n";
            }
        }
        // end for each group
        ?>
 
  <li class="last"><a href="options-permalink.php"><?php 
        echo _LANG_WOP_PERM_LINKS;
        ?>
</a></li> 
</ul> 
<br clear="all" /> 
<div class="wrap"> 
  <h2><?php 
        echo _LANG_WPL_EDIT_STRUCT;
        ?>
/**
** get_option_widget()
** parameters:
** option_result - result set containing option_id, option_name, option_type,
**                 option_value, option_description, option_admin_level
** editable      - flag to determine whether the returned widget will be editable
**/
function &get_option_formElement($option_result, $editable = true, $between = "")
{
    global $wpdb, $wp_id;
    $disabled = $editable ? '' : 'disabled';
    switch ($option_result->option_type) {
        case 1:
            // integer
        // integer
        case 3:
            // string
        // string
        case 8:
            // float
        // float
        case 6:
            // range -- treat same as integer for now!
            if ($option_result->option_type == 1 || $option_result->option_type == 6) {
                $width = 10;
            } elseif ($option_result->option_width < 20) {
                $width = $option_result->option_width;
            } else {
                $width = 50;
            }
            $elem = new XoopsFormText($option_result->option_name, $option_result->option_name, $width, 150, $option_result->option_value);
            break;
        case 2:
            // boolean
            $elem = new XoopsFormSelect($option_result->option_name, "{$option_result->option_name}", $option_result->option_value);
            $elem->addOption("1", "true");
            $elem->addOption("0", "false");
            break;
        case 5:
            // select
            $elem = new XoopsFormSelect($option_result->option_name, "{$option_result->option_name}", $option_result->option_value);
            $select = $wpdb->get_results("SELECT optionvalue, optionvalue_desc " . "FROM {$wpdb->optionvalues[$wp_id]} " . "WHERE option_id = {$option_result->option_id} " . "ORDER BY optionvalue_seq");
            if ($select) {
                foreach ($select as $option) {
                    $elem->addOption($option->optionvalue, $option->optionvalue_desc);
                }
            }
            break;
        case 7:
            // SQL select
            $sql = $wpdb->get_var("SELECT optionvalue FROM {$wpdb->optionvalues[$wp_id]} WHERE option_id = {$option_result->option_id}");
            if (!$sql) {
                $elem = new XoopsFormLabel($option_result->option_nam, $editable);
                break;
            }
            // now we may need to do table name substitution
            eval("include('../wp-config.php');\$sql = \"{$sql}\";");
            $elem = new XoopsFormSelect($option_result->option_name, "{$option_result->option_name}", $option_result->option_value);
            $select = $wpdb->get_results("{$sql}");
            if ($select) {
                foreach ($select as $option) {
                    $elem->addOption($option->value, $option->label);
                }
            }
            break;
        default:
            $elem = new XoopsFormLabel($option_result->option_nam, $editable);
    }
    if ($option_result->option_description) {
        $elem->setDescription(replace_constant($option_result->option_description));
    }
    $elem->setExtra($disabled);
    return $elem;
}