function prepare_dynamic_fields_for_display($DB, $form_name, $admin_status, $all_values, $disabled, $edit)
{
    global $field_properties, $field_types_table, $perm_admin;
    $quoted_form_name = $DB->qstr($form_name, get_magic_quotes_gpc());
    $query = "SELECT *\n\t\t\t  FROM {$field_types_table}\n\t\t\t  WHERE field_form={$quoted_form_name}\n\t\t\t  ORDER BY field_index";
    $result =& $DB->Execute($query);
    $dyn_fields = array();
    $extra = $edit ? 1 : 0;
    if (!$result) {
        return false;
    }
    while (!$result->EOF) {
        $field_id = $result->fields['field_id'];
        // disable admin fields when logged as member
        if ($admin_status != 1 && $result->fields['field_perm'] == $perm_admin) {
            $disabled[$field_id] = 'disabled';
        }
        $cur_fields =& $result->fields;
        $cur_fields['field_name'] = _T($cur_fields['field_name']);
        $properties = $field_properties[$result->fields['field_type']];
        if ($properties['multi_valued']) {
            if ($cur_fields['field_repeat'] == 0) {
                // Infinite multi-valued field
                if (isset($all_values[$cur_fields['field_id']])) {
                    $nb_values = count($all_values[$cur_fields['field_id']]);
                } else {
                    $nb_values = 0;
                }
                if (isset($all_values)) {
                    $cur_fields['field_repeat'] = $nb_values + $extra;
                } else {
                    $cur_fields['field_repeat'] = 1;
                }
            }
        } else {
            $cur_fields['field_repeat'] = 1;
            if ($properties['fixed_values']) {
                $cur_fields['choices'] = get_fixed_values($DB, $field_id);
            }
        }
        $dyn_fields[] = $cur_fields;
        $result->MoveNext();
    }
    $result->Close();
    return $dyn_fields;
}
    $query = "SELECT *\n\t\t\t  FROM {$field_types_table}\n\t\t\t  WHERE field_id={$field_id}";
    $result = db_execute($DB, $query, $error_detected);
    if ($result != false) {
        $field_name = $result->fields['field_name'];
        $field_type = $result->fields['field_name'];
        $field_perm = $result->fields['field_perm'];
        $field_pos = $result->fields['field_pos'];
        $field_required = $result->fields['field_required'];
        $field_width = $result->fields['field_width'];
        $field_height = $result->fields['field_height'];
        $field_repeat = $result->fields['field_repeat'];
        $field_size = $result->fields['field_size'];
        $result->Close();
        $fixed_values = '';
        if ($properties['fixed_values']) {
            foreach (get_fixed_values($DB, $field_id) as $val) {
                $fixed_values .= "{$val}\n";
            }
        }
    }
    // $result != false
}
$data['id'] = $field_id;
$data['name'] = htmlentities($field_name, ENT_QUOTES);
$data['perm'] = $field_perm;
$data['pos'] = $field_pos;
$data['required'] = $field_required == '1';
$data['width'] = $field_width;
$data['height'] = $field_height;
$data['repeat'] = $field_repeat;
$data['size'] = $field_size;