コード例 #1
0
function bbconnect_rows($args = null)
{
    global $wpdb;
    global $totalValues, $fieldInfos;
    $positionInarray = 0;
    //determine which position we have in array
    $blog_prefix = $wpdb->get_blog_prefix(get_current_blog_id());
    // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED
    $defaults = array('user_id' => false, 'action_search' => false, 'action_array' => false, 'post_vars' => false, 'table_body' => false, 'action' => 'view', 'bbconnect_address_count' => 0, 'return' => false, 'tdw' => false, 'thiskey' => '', 'return_def' => true);
    // PARSE THE INCOMING ARGS
    $args = wp_parse_args($args, $defaults);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    // SET A LOOKUP ARRAY FOR THE INITIAL QUERY
    $post_matches = array();
    if (isset($post_vars['search'])) {
        foreach ($post_vars['search'] as $k => $v) {
            if (isset($v['type']) && 'user' == $v['type'] && isset($v['field']) && isset($v['query'])) {
                $post_matches[$v['field']] = $v['query'];
            }
        }
    }
    // GET THE USER DATA
    $current_member = get_userdata($user_id);
    if (!$current_member) {
        return false;
    }
    // CHANGE DISPLAY BASED ON ACTION
    if ('edit' == $action) {
        $display = ' style="display: block;"';
    } else {
        $display = ' disabled="disabled"';
    }
    // RETRIEVE THE USER ROW
    if (false == $return) {
        // RETRIEVE THE AVATAR
        $user_avatar = apply_filters('bbconnect_reports_user_avatar', get_avatar($current_member->user_email, 32), $current_member);
        // RETRIEVE THE PROFILE FIELDS
        $user_fields = array($current_member->first_name . ' ' . $current_member->last_name);
        $user_fields = apply_filters('bbconnect_reports_user_fields', $user_fields, $current_member);
        // RETRIEVE THE ACTIONS
        $user_actions = array();
        if (is_admin()) {
            $user_actions['edit'] = '<a href="' . admin_url('/users.php?page=bbconnect_edit_user&user_id=' . $current_member->ID) . '">' . __('edit') . '</a>';
            $user_actions['edit in new tab'] = '<a href="' . admin_url('/users.php?page=bbconnect_edit_user&user_id=' . $current_member->ID) . '" target="_blank">' . __('edit in new tab') . '</a>';
            $user_actions['email'] = '<a href="mailto:' . $current_member->user_email . '">' . __('email') . '</a>';
        } else {
            $user_actions['view'] = '<a href="' . home_url('/bbconnect/?rel=viewprofile&amp;uid=' . $current_member->ID) . '" class="bbconnectpanels-toggle" title="profile-' . $current_member->ID . '">' . __('view', 'bbconnect') . '</a>';
        }
        $user_actions = apply_filters('bbconnect_reports_user_actions', $user_actions, $current_member);
        // USER SETUP
        $return_html = '<tr>';
        // if ( is_admin() ) {
        //     $return_html .= '<td class="gredit-column" width="3%">';
        //     $return_html .= '<input type="checkbox" name="gredit_users[]" value="'.$current_member->ID.'" class="gredit-user subgredit"'.$display.' />';
        //     $return_html .= '<input type="hidden" value="'.$current_member->user_email.'" disabled="disabled" />';
        //     $return_html .= '</td>';
        // }
        $return_html .= '<td style="text-align:left;" class="bbconnect-column-default" width="' . $tdw . '%">';
        $return_html .= '<div class="username column-username">';
        // USER AVATAR
        $return_html .= '<div class="bbconnect-reports-user-avatar">' . $user_avatar . '</div>';
        // USER INFO - OPEN
        $return_html .= '<div class="bbconnect-reports-user-info">';
        // USER FIELDS
        $return_html .= '<div class="bbconnect-reports-user-fields">';
        $return_html .= implode('<br />', $user_fields);
        $return_html .= '</span>';
        $return_html .= '<br />';
        // USER ACTIONS
        $return_html .= '<div class="bbconnect-reports-user-actions">';
        $return_html .= implode(' | ', $user_actions);
        $return_html .= '</span>';
        // USER INFO - CLOSE
        $return_html .= '</div>';
        // USER CLOSEOUT
        $return_html .= '</div>';
        $return_html .= '</td>';
        // RESOURCE CLEANUP
        unset($user_avatar);
        unset($user_fields);
        unset($user_actions);
    } else {
        $return_val = array();
        if (false != $return_def) {
            $return_val['ID'] = $current_member->ID;
            $return_val['email'] = $current_member->user_email;
            $return_val['first_name'] = $current_member->first_name;
            $return_val['last_name'] = $current_member->last_name;
            //$return_val['organization'] = $current_member->bbconnect_organization;
        }
    }
    if (!empty($table_body)) {
        $tempTotals = array();
        foreach ($table_body as $key => $value) {
            //declare an empty array to hold temporal total values
            $positionInarray++;
            // HORRIBLY HACKISH MANIPULATIONS FOR ADDRESSES...
            if (false != strstr($key, 'address')) {
                // THE KEY WITH THE NUMERIC IDENTIFIER
                $origkey = $key;
                // THE NUMERIC IDENTIFIER
                $thiskey = str_replace('_', '', substr($key, -2));
                // THE KEY WITH THE NUMERIC IDENTIFIER REMOVED
                if (is_numeric($thiskey)) {
                    $key = substr($key, 0, -2);
                }
            }
            // SET THE ARRAY KEY
            //if ( isset( $post_vars['search'] ) )
            //$thiskey = in_array_r($value, $post_vars['search'], true);
            if (false == $return) {
                $align = is_numeric($current_member->{$key}) ? 'right' : 'right';
                $return_html .= '<td width="' . $tdw . '%" style="text-align: ' . $align . ';">';
                //$return_html .= $key . ' ' . $value;
            }
            // TAXONOMIES
            if (is_array($value)) {
                // KEYS USED AS OBJECT VARS CANNOT HAVE DASHES
                $alt_key = str_replace('-', '', $key);
                if (!empty($current_member->{$key})) {
                    foreach ($current_member->{$key} as $subkey => $subvalue) {
                        if ('bbconnect' == substr($key, 0, 9)) {
                            $key = substr($key, 10);
                        }
                        $term_name = get_term_by('id', $subvalue, $key);
                        if (in_array_r($subvalue, $value)) {
                            $ret_arr[] = '<span class="highlight">' . $term_name->name . '</span>';
                        } else {
                            $ret_arr[] = $term_name->name;
                        }
                    }
                } else {
                    if (!empty($current_member->{$alt_key})) {
                        foreach ($current_member->{$alt_key} as $subkey => $subvalue) {
                            $term_name = get_term_by('id', $subvalue, substr($key, 10));
                            if (in_array_r($subvalue, $value)) {
                                $ret_arr[] = '<span class="highlight">' . $term_name->name . '</span>';
                            } else {
                                $ret_arr[] = $term_name->name;
                            }
                        }
                    } else {
                        $ret_arr = '';
                        //bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => $current_member->$key ) );
                    }
                }
                if (false == $return) {
                    if (!is_array($ret_arr)) {
                        $return_html .= '';
                        //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => $current_member->$key ) );
                    } else {
                        $return_html .= implode(', ', $ret_arr);
                        //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => strip_tags( implode( '|', $ret_arr ) ) ) );
                    }
                } else {
                    if (!is_array($ret_arr)) {
                        $return_val[$key] = $current_member->{$key};
                    } else {
                        $return_val[$key] = strip_tags(implode(',', $ret_arr));
                    }
                }
                unset($ret_arr);
                // META
            } else {
                if (is_array($current_member->{$key})) {
                    $marray_out = array();
                    foreach ($current_member->{$key} as $meta_key => $meta_value) {
                        if (is_array($meta_value)) {
                            if (is_assoc($meta_value)) {
                                if (!empty($meta_value['value'])) {
                                    $hlpre = '';
                                    $hlpos = '';
                                    $meta_type = '';
                                    if (isset($post_matches[$key]) && !empty($post_matches[$key])) {
                                        if (false !== strpos($meta_value['value'], $post_matches[$key])) {
                                            $hlpre = '<span class="highlight">';
                                            $hlpos = '</span>';
                                        }
                                    }
                                    if (isset($meta_value['type']) && !empty($meta_value['type'])) {
                                        $meta_type = $meta_value['type'] . ': ';
                                    }
                                    $marray_out[] = $hlpre . $meta_type . $meta_value['value'] . $hlpos;
                                }
                            }
                        } else {
                            if ($blog_prefix . 'capabilities' == $key) {
                                if (in_array($meta_key, $current_member->roles)) {
                                    $marray_out[] = $meta_key;
                                }
                            } elseif (1 == $meta_value || 'true' == $meta_value) {
                                $marray_out[] = 'yes';
                            } elseif (0 == $meta_value || 'false' == $meta_value) {
                                $marray_out[] = 'no';
                            } else {
                                $marray_out[] = $meta_value;
                            }
                        }
                    }
                    if (false == $return) {
                        $return_html .= implode('<br />', $marray_out);
                        //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => implode( '|', $marray_out ) ) );
                    } else {
                        $return_val[$key] = implode('|', $marray_out);
                    }
                    unset($marray_out);
                } else {
                    // IF THIS IS AN ADDRESS FIELD, LOOP THROUGH AND PRESENT ALL RESULTS
                    if (false != strstr($key, 'address') && is_numeric($thiskey)) {
                        // PRE-PROCESS THE META KEY FOR THE GENERAL CHARACTERISTIC
                        // UPON-WHICH THE INDIVIDUAL ADDRESSES CAN BE APPENDED...
                        $pre_add_base = strrchr($key, '_');
                        $pro_add_base = 0 - strlen($pre_add_base);
                        $add_base = substr($key, 0, $pro_add_base);
                        // IF THERE ARE POST-OPS INVOLVED, LIMIT THE DISPLAY TO THE INTERESECT
                        if (isset($post_vars['search'][$thiskey]['post_ops']) && !empty($post_vars['search'][$thiskey]['post_ops'])) {
                            $post_op_arr = $post_vars['search'][$thiskey]['post_ops'];
                            $po_s = array();
                            // GET THE SUFFIX
                            foreach ($post_op_arr as $pkey => $pval) {
                                $cur_po_preval = 'bbconnect_' . $pval;
                                $origkey = substr($key, 0, -2) . substr($pval, 2);
                                $cur_po_val = $current_member->{$cur_po_preval};
                                $pre_po_s = strrchr($cur_po_val, '_');
                                $po_s[] = substr($pre_po_s, 1);
                            }
                            $po_s_array = array_unique($po_s);
                            if (count($po_s_array) == 1) {
                                $po_add = $po_s_array[0];
                            }
                        }
                        // SET THE VARS
                        $cur_address = array();
                        for ($i = 1; $i <= $bbconnect_address_count; $i++) {
                            $cur_ite = $add_base . '_' . $i;
                            if (isset($po_add)) {
                                if ($i != $po_add) {
                                    continue;
                                } else {
                                    $sub_ite = $add_base . '_' . $po_add;
                                    $cur_address[$cur_ite] = $current_member->{$cur_ite};
                                    $cur_grex_key = $cur_ite;
                                }
                            } else {
                                if (isset($post_vars['search'][$thiskey]['query']) && !empty($post_vars['search'][$thiskey]['query'])) {
                                    if (is_array($post_vars['search'][$thiskey]['query'])) {
                                        foreach ($post_vars['search'][$thiskey]['query'] as $val) {
                                            if (false !== stripos($current_member->{$cur_ite}, $val)) {
                                                $cur_address[$cur_ite] = $current_member->{$cur_ite};
                                                $cur_grex_key = $cur_ite;
                                                break;
                                            }
                                        }
                                    } else {
                                        if (false !== stripos($current_member->{$cur_ite}, $post_vars['search'][$thiskey]['query'])) {
                                            $cur_address[$cur_ite] = $current_member->{$cur_ite};
                                            $cur_grex_key = $cur_ite;
                                            break;
                                        }
                                    }
                                } else {
                                    if ($current_member->{$cur_ite}) {
                                        $cur_address[$cur_ite] = $current_member->{$cur_ite};
                                        $cur_grex_key[] = $cur_ite;
                                    } else {
                                        $cur_address[$cur_ite] = false;
                                        $cur_grex_key[] = $cur_ite;
                                    }
                                }
                            }
                        }
                        if (false == $return) {
                            // EXCEPTIONS FOR STATES
                            $cur_address_filtered = array();
                            if (false !== strpos($key, 'address_state')) {
                                array_filter($cur_address);
                                foreach ($cur_address as $ck => $cv) {
                                    $cur_address_filtered[$ck] = bbconnect_state_lookdown($cur_ite, $cv);
                                }
                                $cur_address = $cur_address_filtered;
                            } elseif (false !== strpos($key, 'address_country')) {
                                $bbconnect_helper_country = bbconnect_helper_country();
                                array_filter($cur_address);
                                foreach ($cur_address as $ck => $cv) {
                                    if (array_key_exists($cv, $bbconnect_helper_country)) {
                                        $cur_address_filtered[$ck] = $bbconnect_helper_country[$cv];
                                    } else {
                                        $cur_address_filtered[$ck] = $cv;
                                    }
                                }
                                $cur_address = $cur_address_filtered;
                            }
                            $return_html .= implode('<br />', array_filter($cur_address));
                            if (isset($cur_grex_key) && is_array($cur_grex_key)) {
                                $cur_grex_val = $cur_address;
                            } else {
                                $cur_grex_val = urlencode(serialize($cur_address));
                                $cur_grex_key = array();
                                //if ( !isset( $cur_grex_key ) ) $return_html .= ''; //<p>'.$value.'</p>
                            }
                            //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $cur_grex_key, 'g_val' => $cur_grex_val ) );
                        } else {
                            if (false === $post_vars) {
                                if (false !== strpos($origkey, 'address_state')) {
                                    $return_val[$origkey] = bbconnect_state_lookdown($origkey, $current_member->{$origkey});
                                } else {
                                    $return_val[$origkey] = $current_member->{$origkey};
                                }
                            } else {
                                foreach ($cur_address as $ka => $va) {
                                    // EXCEPTIONS FOR STATES
                                    if (false !== strpos($ka, 'address_state')) {
                                        $return_val[$ka] = bbconnect_state_lookdown($ka, $va);
                                    } else {
                                        $return_val[$ka] = $va;
                                    }
                                }
                                //$return_val[$origkey] = implode( '|', $cur_address );
                            }
                        }
                        unset($cur_address);
                        unset($cur_grex_key);
                    } else {
                        if (false == $return) {
                            $fieldInfo = get_option('bbconnect_' . $key);
                            $fieldInfos[$positionInarray] = $fieldInfo;
                            if ($key == 'bbconnect_bb_work_queue' && function_exists('bbconnect_workqueues_get_action_items')) {
                                $args = array('author' => $current_member->ID);
                                $notes = bbconnect_workqueues_get_action_items($args);
                                $type_list = array();
                                foreach ($notes as $note) {
                                    $note_types = wp_get_post_terms($note->ID, 'bb_note_type');
                                    foreach ($note_types as $note_type) {
                                        if ($note_type->parent > 0) {
                                            $type_list[$note_type->name] = $note_type->name;
                                            break;
                                        }
                                    }
                                }
                                $return_html .= implode(', ', $type_list);
                            } elseif ($key == 'bbconnect_category_id' || $key == 'bbconnect_segment_id') {
                                if (!empty($current_member->{$key})) {
                                    $return_html .= get_the_title($current_member->{$key});
                                }
                            } elseif ($fieldInfo['options']['field_type'] == 'date' && is_real_date($current_member->{$key})) {
                                $new_date_string = date('d F Y', strtotime($current_member->{$key}));
                                $return_html .= $new_date_string;
                            } elseif ($fieldInfo['options']['field_type'] == 'number' && $fieldInfo['options']['is_currency'] && $current_member->{$key} != '') {
                                $return_html .= '$' . number_format($current_member->{$key}, 2);
                            } else {
                                if (is_string($current_member->{$key})) {
                                    $return_html .= $current_member->{$key};
                                }
                            }
                            //check if value is numeric and find total
                            if ($fieldInfo['options']['field_type'] == 'number' && is_numeric($current_member->{$key}) && $current_member->{$key} > 0) {
                                $tempTotals[$positionInarray] = !empty($totalValues[$positionInarray]) ? $totalValues[$positionInarray] + $current_member->{$key} : $current_member->{$key};
                            } else {
                                $tempTotals[$positionInarray] = !empty($totalValues[$positionInarray]) ? $totalValues[$positionInarray] : 0;
                            }
                            //$positionInarray++;
                            //if reached the max position in array, then go back to zero
                            if ($positionInarray == count($table_body)) {
                                foreach ($tempTotals as $keytemp => $valuetemp) {
                                    if ($valuetemp) {
                                        $totalValues = $tempTotals;
                                        break;
                                    }
                                }
                                $positionInarray = 0;
                                $tempTotals = array();
                            }
                            //insert into totals array if tempvalues not empty
                            //$return_html .= bbconnect_grex_input( array( 'u_key' => $current_member->ID, 'g_key' => $key, 'g_val' => $current_member->$key ) );
                        } else {
                            $return_val[$key] = $current_member->{$key};
                        }
                    }
                }
            }
            if (false == $return) {
                $return_html .= '</td>';
            }
        }
    }
    //global $action_array;
    if (is_array($action_array)) {
        if (false == $return) {
            $return_html .= '<td width="' . $tdw * 2 . '%"><table width="100%">';
        }
        if (isset($action_array[$current_member->ID])) {
            foreach ($action_array[$current_member->ID] as $key => $value) {
                if (false == $return) {
                    $return_html .= '<tr>';
                    if (is_admin()) {
                        $return_html .= '<td class="gredit-column" width="3%"><input type="checkbox" name="gredit_actions[' . $current_member->ID . '][]" value="' . $value['ID'] . '" class="gredit-action subgredit"' . $display . ' /></td>';
                    }
                    $return_html .= '<td width="' . round($tdw * 2 - 7, 2) . '%" class="action-detail ' . $value['post_type'] . '">';
                    $inner_return_hmtl = '';
                    if (is_admin()) {
                        $return_html .= apply_filters('bbconnect_action_detail_html', $inner_return_hmtl, $value);
                    } else {
                        $return_html .= apply_filters('bbconnect_action_detail_html_public', $inner_return_hmtl, $value);
                    }
                    $return_html .= '</td></tr>';
                } else {
                    $return_val = apply_filters('bbconnect_action_detail_val', $return_val, $value);
                }
            }
        }
        if (false == $return) {
            $return_html .= '</table></td>';
        }
    }
    unset($current_member);
    if (false == $return) {
        $return_html .= '</tr>';
    }
    if (false == $return) {
        return $return_html;
    } else {
        return $return_val;
    }
}
コード例 #2
0
function bbconnect_field($meta, $args = array())
{
    // CORNERSHOP CREATIVE CUSTOMIZATION
    $meta = apply_filters('bbconnect_field_prepare', $meta, $args);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    // FOR CONVENIENCE
    $key = $meta['meta_key'];
    $disabled = bbconnect_field_disabled($key);
    // SETUP THE LOGIC
    switch ($meta['options']['field_type']) {
        case 'title':
            // BUMP
            echo '<h3 class="bbconnect-section">' . stripslashes($meta['name']) . '</h3>';
            if (isset($meta['description']) && !empty($meta['description'])) {
                echo '<p>' . $meta['description'] . '</p>';
            }
            break;
        case 'taxonomy':
            $tax = $key;
            $taxonomy = get_taxonomy($tax);
            // DETERMINE WHETHER OR NOT CHILDREN ARE DISPLAYED
            if (isset($meta['options']['children']) && false == $meta['options']['children']) {
                $children = '&parent=0';
            } else {
                $children = '';
            }
            // SET THE DISPLAY OPTIONS
            if (isset($meta['options']['sort_by']) && false == $meta['options']['sort_by']) {
                $sort = '&orderby=name';
            } else {
                $sort = '&orderby=id';
            }
            $terms = get_terms($tax, 'hide_empty=0' . $sort . $children);
            if ('-view' == $action) {
                foreach ($terms as $term) {
                    if (!empty($value) && in_array_r($term->term_id, $value)) {
                        $output_arr[] = $term->name;
                    }
                }
                if (!empty($output_arr)) {
                    echo '<div> ' . implode(', ', $output_arr) . '</div>';
                }
            } else {
                $display = get_option('_bbconnect_taxonomy_display');
                // LET THE API OVERRIDE THIS
                if (isset($meta['options']['display'])) {
                    $display = $meta['options']['display'];
                }
                if ('select' == $display || '-search' == $action) {
                    echo '<select class="chzn-select" multiple="multiple" name="' . $name . '[]" style="width: 200px">';
                    $child_terms = array();
                    if ('' == $children) {
                        foreach ($terms as $term) {
                            $selected = '';
                            if (false != $term->parent) {
                                if (!empty($value) && in_array_r($term->term_id, $value)) {
                                    $selected = ' selected';
                                }
                                $child_terms[$term->parent][] = '<option value="' . $term->term_id . '"' . $selected . '>&nbsp;&nbsp;&nbsp;' . $term->name . '</option>';
                            }
                        }
                    }
                    foreach ($terms as $term) {
                        $selected = '';
                        if (false != $term->parent) {
                            continue;
                        }
                        if (!empty($value) && in_array_r($term->term_id, $value)) {
                            $selected = ' selected';
                        }
                        echo '<option value="' . $term->term_id . '"' . $selected . '>' . $term->name . '</option>';
                        if (isset($child_terms[$term->term_id])) {
                            foreach ($child_terms[$term->term_id] as $pk => $pv) {
                                echo $pv;
                            }
                        }
                    }
                    echo '</select>';
                } else {
                    echo '<div class="taxonomy-panel">';
                    if ('' == $children) {
                        foreach ($terms as $term) {
                            $checked = '';
                            if (false != $term->parent) {
                                if (!empty($value) && in_array_r($term->term_id, $value)) {
                                    $checked = ' checked';
                                }
                                $child_terms[$term->parent][] = '<span class="float-checkbox">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="' . $name . '[]"  value="' . $term->term_id . '"' . $checked . ' />&nbsp;' . $term->name . '</span>';
                            }
                        }
                    }
                    foreach ($terms as $term) {
                        $checked = '';
                        if (false != $term->parent) {
                            continue;
                        }
                        if (!empty($value) && in_array_r($term->term_id, $value)) {
                            $checked = ' checked';
                        }
                        echo '<span class="float-checkbox"><input type="checkbox" name="' . $name . '[]"  value="' . $term->term_id . '"' . $checked . ' />&nbsp;' . $term->name;
                        if (isset($child_terms[$term->term_id])) {
                            foreach ($child_terms[$term->term_id] as $pk => $pv) {
                                echo $pv;
                            }
                        }
                        echo '</span>';
                    }
                    echo '</div>';
                }
                if ('-edit' == $action) {
                    echo '<input type="hidden" name="' . $name . '[]"  value="" />';
                }
                // SPECIAL CASES
                if ('-bulk-edit' == $action) {
                    echo '<div style="clear: both; padding: 7px;"><input type="radio" name="bbconnect_user_taxonomy_options[' . $key . ']" value="append" checked="checked" /> ' . __('Append', 'bbconnect') . '<input type="radio" name="bbconnect_user_taxonomy_options[' . $key . ']" value="overwrite" /> ' . __('Overwrite', 'bbconnect') . '<input type="radio" name="bbconnect_user_taxonomy_options[' . $key . ']" value="remove" /> ' . __('Remove', 'bbconnect') . '</div>';
                }
                if ('-edit' == $action && current_user_can('list_users')) {
                    echo '<div class="end-of-float"><a href="' . get_bloginfo('wpurl') . '/wp-admin/edit-tags.php?taxonomy=' . $tax . '&TB_iframe=true&height=450&width=920" class="thickbox button-primary">' . __('Add terms', 'bbconnect') . '</a></div>';
                }
            }
            break;
        case 'section':
            if ('-view' != $action || 'true' == get_option('bbconnectpanels_public_labels')) {
                echo '<h3>' . stripslashes($meta['name']) . '</h3>';
            }
            echo '<ul>';
            if (!empty($meta['options']['choices'])) {
                // THIS IS A PASS THROUGH FOR ANY SANITIZED POST VALS
                $child_vals = array();
                if (isset($value) && is_array($value) && !empty($value)) {
                    $child_vals = $value;
                }
                foreach ($meta['options']['choices'] as $skey => $sval) {
                    // GET THE OPTION
                    $smeta = bbconnect_get_option($sval);
                    // CHECK TO SEE IF ANY FIELDS HAVE BEEN REMOVED FROM DISPLAY
                    $grouped_hide = bbconnect_hide_meta(array('meta' => $smeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                    if ($grouped_hide) {
                        continue;
                    }
                    $post_val = false;
                    if (in_array($smeta['options']['field_type'], array('group'))) {
                        $post_val = $child_vals;
                    } else {
                        if (isset($child_vals[$smeta['meta_key']])) {
                            $post_val = $child_vals[$smeta['meta_key']];
                        }
                    }
                    // ECHO OUT THE FIELDS!
                    bbconnect_get_field(array('meta' => $smeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                }
            }
            echo '</ul>';
            break;
        case 'textarea':
            // ALLOW OPTIONS TO HAVE SOME PRESETS
            if (empty($value) && !empty($meta['options']['choices'])) {
                $value = $meta['options']['choices'];
            }
            if ('-view' == $action) {
                echo wpautop($value);
            } else {
                if ('-edit' == $action) {
                    // ONLY DISPLAY THE TEXT AREA IF WE KNOW FOR SURE WE HAVE THE RIGHT RESOURCES
                    if (isset($meta['options']['wp_editor']) && false != $meta['options']['wp_editor']) {
                        // CORNERSHOP CREATIVE CUSTOMIZATION
                        $html_value = utf8_encode(html_entity_decode($value));
                        wp_editor($html_value, $key, array('textarea_name' => $name));
                    } else {
                        echo '<textarea ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="' . $class . '">' . $value . '</textarea>';
                    }
                } else {
                    echo '<textarea ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="' . $class . '">' . $value . '</textarea>';
                }
            }
            break;
        case 'select':
        case 'multiselect':
            if ('-view' == $action) {
                if ('wpr' == $meta['source'] && 'display_name' == $key) {
                    echo $value->display_name;
                } else {
                    echo $value;
                }
            } else {
                // OPTIONALLY ADD LOOKUPS
                if ('-search' == $action) {
                    $autocomp = ' chzn-select';
                    $multiple = ' multiple="multiple" data-placeholder="' . __('All Options', 'bbconnect') . '" style="width: 150px"';
                    $name = $name . '[]';
                } else {
                    if ('multiselect' == $meta['options']['field_type']) {
                        $autocomp = ' chzn-select';
                        $multiple = ' multiple="multiple"';
                        $name = $name . '[]';
                    } else {
                        if ('address' == substr($key, 0, 7)) {
                            if (false !== strpos($key, 'country')) {
                                $multiple = '';
                                $autocomp = ' country-field';
                            } else {
                                if (false !== strpos($key, 'state')) {
                                    $multiple = '';
                                    $autocomp = ' state-province-field';
                                } else {
                                    $autocomp = '';
                                    $multiple = '';
                                }
                            }
                        } else {
                            $autocomp = '';
                            $multiple = '';
                        }
                    }
                }
                if ('wpr' == $meta['source']) {
                    if ('-search' == $action) {
                    } else {
                        if (isset($flag) && 'normalize' == $flag) {
                        } else {
                            $name = $key;
                        }
                    }
                }
                // LET'S HANDLE ROLES
                if ('wpr' == $meta['source'] && 'role' == $key) {
                    echo '<select ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="regular-text' . $class . $autocomp . '"' . $multiple . '>';
                    if (is_array($value)) {
                        $user_role = $value;
                    } else {
                        //$user_roles = array_keys( $value->wp_capabilities );
                        //$user_role = array_shift( $user_roles );
                        $user_roles = array_intersect(array_values($value->roles), array_keys(get_editable_roles()));
                        $user_role = array_shift($user_roles);
                    }
                    // print the full list of roles with the primary one selected.
                    bbconnect_dropdown_roles($user_role);
                    // print the 'no role' option. Make it selected if the user has no role yet.
                    if ('-search' == $action) {
                        echo '<option value="no_role">' . __('No role for this site') . '</option>';
                    } else {
                        if ($user_role) {
                            echo '<option value="">' . __('&mdash; No role for this site &mdash;') . '</option>';
                        } else {
                            echo '<option value="" selected="selected">' . __('&mdash; No role for this site &mdash;') . '</option>';
                        }
                    }
                    echo '</select>';
                    // AND DISPLAY NAMES (ADDING A FEW OPTIONS ALONG THE WAY)
                } else {
                    if ('wpr' == $meta['source'] && 'display_name' == $key) {
                        if (is_user_logged_in() && !empty($value)) {
                            $cuser = $value;
                            echo '<select ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="regular-text' . $class . $autocomp . '"' . $multiple . '>';
                            $public_display = array();
                            if (!empty($cuser->nickname)) {
                                $public_display['display_nickname'] = $cuser->nickname;
                            }
                            if (!empty($cuser->user_login)) {
                                $public_display['display_username'] = $cuser->user_login;
                            }
                            if (!empty($cuser->first_name)) {
                                $public_display['display_firstname'] = $cuser->first_name;
                            }
                            if (!empty($cuser->last_name)) {
                                $public_display['display_lastname'] = $cuser->last_name;
                            }
                            // FOR ORGS
                            if (!empty($cuser->bbconnect_organization)) {
                                $public_display['display_organization'] = $cuser->bbconnect_organization;
                            }
                            if (!empty($cuser->first_name) && !empty($cuser->last_name)) {
                                // SETUP FORMAL VARS
                                if (!empty($cuser->bbconnect_prefix)) {
                                    $m_pre = $cuser->bbconnect_prefix . ' ';
                                }
                                if (!empty($cuser->bbconnect_suffix)) {
                                    $m_suf = ' ' . $cuser->bbconnect_suffix;
                                }
                                if (!empty($cuser->bbconnect_middle_name)) {
                                    $m_mid = ' ' . $cuser->bbconnect_middle_name . ' ';
                                } else {
                                    $m_mid = ' ';
                                }
                                $public_display['display_formal'] = $m_pre . $cuser->first_name . $m_mid . $cuser->last_name . $m_suf;
                                $public_display['display_firstlast'] = $cuser->first_name . ' ' . $cuser->last_name;
                                $public_display['display_lastfirst'] = $cuser->last_name . ' ' . $cuser->first_name;
                            }
                            if (!empty($cuser->display_name)) {
                                if (!in_array($cuser->display_name, $public_display)) {
                                    // Only add this if it isn't duplicated elsewhere
                                    $public_display = array('display_displayname' => $cuser->display_name) + $public_display;
                                }
                            }
                            $public_display = array_map('trim', $public_display);
                            $public_display = array_unique($public_display);
                            foreach ($public_display as $id => $item) {
                                echo '<option id="' . $id . '"' . selected($cuser->display_name, $item) . '>' . $item . '</option>';
                            }
                            echo '</select>';
                        }
                        // EVERYTHING ELSE
                    } else {
                        if (!is_array($value)) {
                            $value = html_entity_decode($value);
                            // Hack to fix issue with "Mr & Mrs"
                        }
                        echo '<select ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="regular-text' . $class . $autocomp . '"' . $multiple . '>';
                        if (empty($value) && isset($meta['options']['default'])) {
                            $value = $meta['options']['default'];
                        }
                        $setext = '';
                        echo '<option value="">' . $setext . '</option>';
                        // IF THIS IS A REFERENCE TO A HELPER, PICK IT UP
                        if (!is_array($meta['options']['choices'])) {
                            $option_arr = call_user_func($meta['options']['choices']);
                        } else {
                            $option_arr = $meta['options']['choices'];
                        }
                        // IF THIS IS AN ASSOCIATIVE ARRAY, CREATE OPTION GROUPS
                        foreach ($option_arr as $choices => $choice) {
                            if (is_array($choice)) {
                                $true_match = true;
                                if (false !== strpos($meta['meta_key'], 'address_state_')) {
                                    $true_match = false;
                                    $address_number = substr($meta['meta_key'], -1);
                                    $user_country = get_user_meta($_GET['user_id'], 'bbconnect_address_country_' . $address_number, true);
                                    $countries = bbconnect_helper_country();
                                    $country = array_key_exists($user_country, $countries) ? $countries[$user_country] : $user_country;
                                    if ($choices == $country) {
                                        $true_match = true;
                                    }
                                }
                                foreach ($choice as $topkey => $topvalue) {
                                    if (is_array($topvalue)) {
                                        echo '<optgroup label="' . $topkey . '">';
                                        foreach ($topvalue as $subkey => $subvalue) {
                                            echo '<option value="' . $subkey . '"';
                                            if (is_array($value)) {
                                                if (in_array($subkey, $value) && $true_match) {
                                                    echo ' selected="selected"';
                                                }
                                            } elseif ($true_match) {
                                                echo selected($value, $subkey);
                                            }
                                            echo '>' . $subvalue . '</option>';
                                        }
                                        echo '</optgroup>';
                                    } else {
                                        echo '<option value="' . $topkey . '"';
                                        if (is_array($value)) {
                                            if (in_array($topkey, $value) && $true_match) {
                                                echo ' selected="selected"';
                                            }
                                        } elseif ($true_match) {
                                            echo selected($value, $topkey);
                                        }
                                        echo '>' . $topvalue . '</option>';
                                    }
                                }
                            } else {
                                echo '<option value="' . $choices . '"';
                                if (is_array($value)) {
                                    if (in_array($choices, $value)) {
                                        echo ' selected="selected"';
                                    }
                                } else {
                                    echo selected($value, $choices);
                                }
                                echo '>' . $choice . '</option>';
                            }
                        }
                        echo '</select>';
                    }
                }
            }
            break;
        case 'checkbox':
            if ('-bulk-edit' == $action) {
                echo '<select ' . $disabled . ' name="' . $name . '">';
                echo '<option value="true">' . __('yes', 'bbconnect') . '</option>';
                echo '<option value="false">' . __('no', 'bbconnect') . '</option>';
                echo '</select>';
            } else {
                if ('-search' === $action) {
                    echo '<select ' . $disabled . ' name="' . $name . '">';
                    echo '<option value=""' . selected($value, '') . '>' . __('empty', 'bbconnect') . '</option>';
                    echo '<option value="true"' . selected($value, 'true') . '>' . __('yes', 'bbconnect') . '</option>';
                    echo '<option value="false"' . selected($value, 'false') . '>' . __('no', 'bbconnect') . '</option>';
                    echo '</select>';
                } else {
                    if ('wp' == $meta['source']) {
                        // SET THE DEFAULTS
                        if ('true' === $meta['options']['choices']) {
                            $chk = 'on';
                            $val = 'true';
                        } else {
                            $chk = 'off';
                            $val = 'false';
                        }
                        // LET THE USER SAVED VALUE OVERRIDE THE DEFAULTS
                        if (!empty($value)) {
                            if ('true' === $value) {
                                $chk = 'on';
                                $val = 'true';
                            } else {
                                $chk = 'off';
                                $val = 'false';
                            }
                        }
                        // SPECIAL CASE FOR THE ADMIN BARS AND SSL PREFERENCES
                        if ('rich_editing' == $key || 'comment_shortcuts' == $key) {
                            $wp_class = 'upt ';
                            $wp_key = $key;
                            $field_name = ' name="' . $key . '"';
                        } else {
                            if ('show_admin_bar_front' == $key || 'show_admin_bar_admin' == $key || 'admin_bar_front' == $key) {
                                $wp_key = 'admin_bar_front';
                                $wp_class = 'uwpt ';
                                if ('on' == $chk) {
                                    $field_name = ' name="admin_bar_front"';
                                } else {
                                    $field_name = '';
                                }
                                $val = 'true';
                            } else {
                                $wp_key = $key;
                                $wp_class = 'umt ';
                                $field_name = ' name="' . $key . '"';
                            }
                        }
                        echo '<a class="' . $wp_class . $chk . $class . '" title="' . $wp_key . '"><input type="hidden" id="' . $wp_key . '"' . $field_name . ' value="' . $val . '" /> ' . $meta['name'] . '</a> ';
                    } else {
                        // SET THE DEFAULTS
                        if ('true' === $meta['options']['choices']) {
                            $chk = 'on';
                            $val = 'true';
                        } else {
                            $chk = 'off';
                            $val = 'false';
                        }
                        // LET THE USER SAVED VALUE OVERRIDE THE DEFAULTS
                        if (!empty($value)) {
                            if ('true' === $value) {
                                $chk = 'on';
                                $val = 'true';
                            } else {
                                $chk = 'off';
                                $val = 'false';
                            }
                        }
                        echo '<a class="upt ' . $chk . '" title="' . $title . '"><input type="hidden" id="' . $title . '"  name="' . $name . '" value="' . $val . '" /> ' . $meta['name'] . '</a> ';
                    }
                }
            }
            break;
        case 'radio':
            if ('-view' == $action) {
                echo $value;
            } else {
                // IF THIS IS A REFERENCE TO A HELPER, PICK IT UP
                if (!is_array($meta['options']['choices'])) {
                    $option_arr = call_user_func($meta['options']['choices']);
                } else {
                    $option_arr = $meta['options']['choices'];
                }
                echo '<ul>';
                // IF THIS IS AN ASSOCIATIVE ARRAY, CREATE OPTION GROUPS
                foreach ($option_arr as $subkey => $subvalue) {
                    if ('' != $value) {
                        if ($subkey == $value) {
                            $checked = ' checked';
                        } else {
                            $checked = '';
                        }
                    } else {
                        $checked = '';
                    }
                    echo '<li><input ' . $disabled . ' type="radio" name="' . $name . '" value="' . $subkey . '"' . $checked . ' /> ' . $subvalue . '</li>';
                }
                echo '</ul>';
            }
            break;
        case 'group':
            // THIS IS A PASS THROUGH FOR ANY SANITIZED POST VALS
            $child_vals = array();
            if (isset($value) && is_array($value) && !empty($value)) {
                $child_vals = $value;
            }
            if ('-view' == $action) {
                foreach ($meta['options']['choices'] as $gkey => $gvalue) {
                    // GET THE OPTION
                    $gmeta = get_option($gvalue);
                    $grouped_hide = bbconnect_hide_meta(array('meta' => $gmeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                    if ($grouped_hide) {
                        continue;
                    }
                    $post_val = false;
                    if (isset($child_vals[$gmeta['meta_key']])) {
                        $post_val = $child_vals[$gmeta['meta_key']];
                    }
                    bbconnect_get_field(array('meta' => $gmeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                }
            } else {
                $group_hide = bbconnect_hide_meta(array('meta' => $meta, 'group_override' => true, 'bbconnect_cap' => $capabilities, 'action' => $action));
                if (false == $group_hide) {
                    ?>
                    <li>
                        <div class="t-wrapper group">
                            <p class="t-trigger-wrapper group">
                                <span class="bbconnect-label group">
                                    <span class="t-trigger group" title="<?php 
                    echo $id . $action;
                    ?>
">
                                        <?php 
                    echo $meta['name'];
                    ?>
                                    </span>
                                </span>
                                <span class="bbconnect-field">
                                <?php 
                    // LET PLUGINS EXTEND GROUPS
                    do_action('bbconnect_group_markers', $meta, $cid, $action);
                    ?>
                                </span>
                            </p>
                            <div id="<?php 
                    echo $id . $action;
                    ?>
" class="t-panel">
                                <ul class="group-panel">
                                <?php 
                    foreach ($meta['options']['choices'] as $gkey => $gvalue) {
                        // GET THE OPTION
                        $gmeta = bbconnect_get_option($gvalue);
                        $grouped_hide = bbconnect_hide_meta(array('meta' => $gmeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                        if ($grouped_hide) {
                            continue;
                        }
                        $post_val = false;
                        if (isset($child_vals[$gmeta['meta_key']])) {
                            $post_val = $child_vals[$gmeta['meta_key']];
                        }
                        bbconnect_get_field(array('meta' => $gmeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                    }
                    ?>
                                </ul>
                            </div>
                        </div>
                    </li>
                <?php 
                } else {
                    foreach ($meta['options']['choices'] as $gkey => $gvalue) {
                        // GET THE OPTION
                        $gmeta = bbconnect_get_option($gvalue);
                        $grouped_hide = bbconnect_hide_meta(array('meta' => $gmeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                        if ($grouped_hide) {
                            continue;
                        }
                        $post_val = false;
                        if (isset($child_vals[$gmeta['meta_key']])) {
                            $post_val = $child_vals[$gmeta['meta_key']];
                        }
                        bbconnect_get_field(array('meta' => $gmeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                    }
                }
            }
            break;
        case 'multitext':
            if ('-view' == $action) {
                $fdisplay = array();
                if (is_array($value)) {
                    foreach ($value as $fkey => $fval) {
                        if (is_array($fval)) {
                            $fdisplay[] = '<strong>' . $fval['type'] . ':</strong> ' . $fval['value'];
                        }
                    }
                }
                echo implode(', ', $fdisplay);
            } else {
                echo '<ul id="' . $id . '">';
                //if ( is_array( $value ) && count( $value ) > 1 ) {
                // IF WE'RE JUST STARTING OUT WITH DATA, PREFILL THE VALUE ARRAY WITH NULLITY
                if (!is_array($value) || empty($value)) {
                    $value = array();
                    // GO WITH OVERRIDES FIRST
                    if (isset($meta['options']['add_fields']) && is_array($meta['options']['add_fields'])) {
                        foreach ($meta['options']['add_fields'] as $k => $v) {
                            $value[0][$k] = '';
                        }
                    }
                    $value[0]['value'] = '';
                    if (is_array($meta['options']['choices']) && !empty($meta['options']['choices'])) {
                        $value[0]['type'] = '';
                    }
                }
                /*
                $single_val = '';
                foreach( $value as $fkey => $fval ) {
                    $single_val .= $value[$fkey]['value'];
                }
                */
                $arrcount = count($value);
                $nfkey = 0;
                $key_type = '';
                // COUNT THE FIELDS AVAILABLE
                $add_fields = false;
                $field_ct = 1;
                if (isset($meta['options']['add_fields']) && is_array($meta['options']['add_fields'])) {
                    $add_fields = true;
                    $field_ct = 1 + count($meta['options']['add_fields']);
                }
                $fper = round(52 / $field_ct);
                foreach ($value as $fkey => $fval) {
                    // CREATE THE TYPE FROM THE OPTION
                    // OPTIONALLY BYPASS THIS
                    if (is_array($meta['options']['choices'])) {
                        $arr_choices = array_filter($meta['options']['choices']);
                        if (!empty($arr_choices)) {
                            $key_type = '<select name="' . $name . '[' . $nfkey . '][type]" id="' . $id . '-' . $fkey . '-select">';
                            $key_type .= '<option value="">...</option>';
                            foreach ($meta['options']['choices'] as $typekey => $typeval) {
                                $key_type .= '<option value="' . $typekey . '"';
                                if (isset($value[$fkey]['type'])) {
                                    $key_type .= selected($value[$fkey]['type'], $typekey, false);
                                }
                                $key_type .= '>' . $typeval . '</option>';
                            }
                            $key_type .= '</select>';
                        }
                    }
                    if (false != $add_fields) {
                        $add_fields = '';
                        foreach ($meta['options']['add_fields'] as $k => $v) {
                            if (isset($value[$fkey][$k])) {
                                $ctv = $value[$fkey][$k];
                            } else {
                                $ctv = '';
                            }
                            $add_name = $v['name'];
                            if ('text' == $v['type']) {
                                if (isset($v['class'])) {
                                    $tempclass = $class . ' ' . implode(' ', $v['class']);
                                }
                                $add_fields .= '<input type="text" name="' . $name . '[' . $nfkey . '][' . $k . ']" class="regular-text regular-multi' . $tempclass . '" style="width: ' . $fper . '%;" value="' . $ctv . '" placeholder="' . $add_name . '" /> ';
                            } else {
                                if ('checkbox' == $v['type']) {
                                    $chk = '';
                                    if ('true' == $ctv) {
                                        $chk = 'on';
                                    }
                                    $add_fields .= '<a class="upt ' . $chk . '" title="' . $k . '-' . $nfkey . '"><input type="hidden" id="' . $k . '-' . $nfkey . '"  name="' . $name . '[' . $nfkey . '][' . $k . ']" value="' . $ctv . '" /> ' . $add_name . '</a> ';
                                }
                            }
                        }
                    }
                    ?>
                        <li id="<?php 
                    echo $id . '' . $fkey;
                    ?>
" class="multilist">
                            <?php 
                    /*<span class="handle"></span>*/
                    ?>
                            <span>
                                <?php 
                    echo $add_fields;
                    ?>
                                <input type="text" name="<?php 
                    echo $name . '[' . $nfkey . '][value]';
                    ?>
" class="regular-text regular-multi<?php 
                    echo $class;
                    ?>
" style="width: <?php 
                    echo $fper;
                    ?>
%;" value="<?php 
                    echo $value[$fkey]['value'];
                    ?>
" placeholder="<?php 
                    _e('Value', 'bbconnect');
                    ?>
" />
                                <?php 
                    echo $key_type;
                    ?>
                            </span>
                            <?php 
                    if ($arrcount == 1) {
                        ?>
                                <a id="<?php 
                        echo $id . '' . $nfkey;
                        ?>
-sub" class="sub" title="<?php 
                        echo $nfkey;
                        ?>
" style="display:none;">&nbsp;</a>
                                <a id="<?php 
                        echo $id . '' . $nfkey;
                        ?>
-add" class="add" title="<?php 
                        echo $nfkey;
                        ?>
">&nbsp;</a>
                            <?php 
                    } else {
                        if ($nfkey == $arrcount - 1) {
                            ?>
                                <a id="<?php 
                            echo $id . '' . $nfkey;
                            ?>
-sub" class="sub" title="<?php 
                            echo $nfkey;
                            ?>
">&nbsp;</a>
                                <a id="<?php 
                            echo $id . '' . $nfkey;
                            ?>
-add" class="add" title="<?php 
                            echo $nfkey;
                            ?>
">&nbsp;</a>
                            <?php 
                        } elseif ($nfkey == 0) {
                            ?>
                                <a id="<?php 
                            echo $id . '' . $nfkey;
                            ?>
-sub" class="sub" title="<?php 
                            echo $nfkey;
                            ?>
" style="display:none;">&nbsp;</a>
                            <?php 
                        } else {
                            ?>
                                <a class="sub" title="<?php 
                            echo $nfkey;
                            ?>
">&nbsp;</a>
                            <?php 
                        }
                    }
                    ?>
                        </li>
                    <?php 
                    $nfkey++;
                }
                /*
                } else {
                    if ( !is_array( $value ) ) {
                        $value = array();
                    }
                    $single_val = '';
                    foreach( $value as $fkey => $fval ) {
                        $single_val .= $value[$fkey]['value'];
                    }
                    if ( !isset( $fkey ) ) {
                        $fkey = 0;
                    }
                
                
                    // CREATE THE TYPE FROM THE OPTION
                    // OPTIONALLY BYPASS THIS
                    if ( isset( $meta['options']['single_value'] ) ) {
                        $key_type = '';
                    } else {
                        $key_type = '<select name="'.$name.'[0][type]">';
                        $key_type .= '<option value="">...</option>';
                        foreach ( $meta['options']['choices'] as $typekey => $typeval ) {
                            if ( is_array( $value ) && array_key_exists( $fkey, $value ) && isset( $value[$fkey]['type'] ) ) {
                                $key_type .= '<option value="'.$typekey.'"'. selected( $value[$fkey]['type'], $typekey, false ) . '>'.$typeval.'</option>';
                            } else {
                                $key_type .= '<option value="'.$typekey.'">'.$typeval.'</option>';
                            }
                        }
                        $key_type .= '</select>';
                    }
                
                    if ( isset( $meta['options']['double_value'] ) ) {
                        $dbl = '<input type="text" name="' . $name . '[0][label]" class="regular-text regular-multi' . $class . '" value="' . $value[$fkey]['label'] . '" /> ';
                    } else {
                        $dbl = false;
                    }
                    ?>
                    <li id="<?php echo $id .''. $fkey; ?>" class="multilist"><span><?php echo $dbl; ?><input type="text" name="<?php echo $name . '[0][value]'; ?>" class="regular-text regular-multi<?php echo $class; ?>" value="<?php echo $single_val; ?>" /> <?php echo $key_type; ?></span> <a id="<?php echo $id .''. $fkey; ?>-sub" class="sub" title="<?php echo $fkey; ?>" style="display:none;">&nbsp;</a> <a id="<?php echo $id .''. $fkey; ?>-add" class="add" title="0">&nbsp;</a></li>
                    <?php
                }
                */
                echo '</ul>';
            }
            break;
        case 'password':
            if ('-view' != $action) {
                echo '<ul>';
                $choices = $meta['options']['choices'];
                if ('wpr' == $meta['source']) {
                    ?>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $key . $choices[0];
                    ?>
" id="<?php 
                    echo $key . $choices[0] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('type password', 'bbconnect');
                    ?>
</li>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $key . $choices[1];
                    ?>
" id="<?php 
                    echo $key . $choices[1] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('re-type password', 'bbconnect');
                    ?>
</li>
                    <?php 
                } else {
                    ?>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $name;
                    ?>
[<?php 
                    echo $choices[0];
                    ?>
]" id="<?php 
                    echo $key . $choices[0] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('type password', 'bbconnect');
                    ?>
</li>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $name;
                    ?>
[<?php 
                    echo $choices[1];
                    ?>
]" id="<?php 
                    echo $key . $choices[1] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('re-type password', 'bbconnect');
                    ?>
</li>
                    <?php 
                }
                echo '</ul>';
            }
            break;
        case 'date':
            if ('wpr' == $meta['source']) {
                if ('-search' == $action) {
                } else {
                    if (isset($flag) && 'normalize' == $flag) {
                    } else {
                        $name = $key;
                    }
                }
            }
            if (is_array($value)) {
                $vds = $value[0];
                $vde = $value[1];
            } else {
                $vds = false;
                $vde = false;
                if ($disabled && !empty($value)) {
                    $value = date('d F Y', strtotime($value));
                }
            }
            if (!empty($vds) && is_real_date($vds) && $disabled) {
                $vds = date('d F Y', strtotime($vds));
            }
            if (!empty($vde) && is_real_date($vde) && $disabled) {
                $vde = date('d F Y', strtotime($vde));
            }
            if ('-search' == $action) {
                echo '<input ' . $disabled . ' type="text" name="' . $name . '[]" id="' . $id . '_start" placeholder="' . __('start', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $vds . '" />';
                echo '<input ' . $disabled . ' type="text" name="' . $name . '[]" id="' . $id . '_end" placeholder="' . __('end', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $vde . '" />';
            } else {
                echo '<input ' . $disabled . ' type="text" name="' . $name . '" id="' . $id . '" class="regular-text bbconnect-date' . $class . '" value="' . $value . '" />';
            }
            break;
        case 'plugin':
            $args = array();
            if ('user' == $type) {
                $args['fdata'] = get_userdata($cid);
            } else {
                if ('option' == $type) {
                    $args['fdata'] = $meta;
                } else {
                    if ('post' == $type) {
                        $args['fdata'] = array('id' => $id, 'name' => $name, 'class' => $class);
                    }
                }
            }
            $args['fvalue'] = $value;
            $args['faction'] = $action;
            $args['ftype'] = $type;
            $func = $meta['options']['choices'];
            call_user_func($func, $args);
            break;
        case 'number':
        case 'text':
        case 'hidden':
            // IF THIS IS A WORDPRESS USER FIELD, MAKE SOME SMALL MODIFICATIONS
            if ('wpr' == $meta['source']) {
                if (!empty($value) && is_object($value)) {
                    if ('email' == $key || 'url' == $key) {
                        $user_key = 'user_' . $key;
                    } else {
                        $user_key = $key;
                    }
                    $value = $value->{$user_key};
                    if ('user_registered' == $key && !empty($value)) {
                        $value = date(get_option('date_format'), strtotime($value));
                    }
                }
                if ('-search' == $action) {
                } else {
                    if (isset($flag) && 'normalize' == $flag) {
                    } else {
                        $name = $key;
                    }
                }
                if ('-search' != $action) {
                    if ('user_login' == $key && !empty($value)) {
                        $disabled = ' disabled';
                    }
                    if ('ID' == $key && !empty($value)) {
                        $disabled = ' disabled';
                    }
                    if ('user_registered' == $key && !empty($value)) {
                        $disabled = ' disabled';
                    }
                }
            }
            // ALLOW OPTIONS TO HAVE SOME PRESETS
            if (empty($value) && !empty($meta['options']['choices'])) {
                $value = $meta['options']['choices'];
            }
            $field_type = $meta['options']['field_type'];
            $attr = '';
            if ($field_type == 'number') {
                $align = 'right';
                if ($meta['options']['is_currency'] && $value != '' && $disabled) {
                    $field_type = 'text';
                    $value = '$' . number_format($value, 2);
                }
                $step = $meta['options']['is_currency'] ? '0.01' : '1';
                $attr = ' step="' . $step . '"';
            } else {
                $align = 'left';
            }
            if ('-view' == $action) {
                if ('email' == $key) {
                    echo '<a href="mailto:' . $value . '">' . $value . '</a>';
                } else {
                    if ('url' == $key) {
                        echo '<a href="' . $value . '">' . $value . '</a>';
                    } else {
                        echo $value;
                    }
                }
            } else {
                if ($meta['options']['field_type'] != 'text') {
                    echo '<input type="' . $field_type . '" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value="' . $value . '" style="text-align: ' . $align . ';" ' . $disabled . ' ' . $attr . '>';
                } else {
                    if ('-search' == $action && 'user_registered' == $key) {
                        if (is_array($value)) {
                            $vs = $value[0];
                            $ve = $value[1];
                        } else {
                            $vs = false;
                            $ve = false;
                        }
                        echo '<input type="text" name="' . $name . '[]" id="' . $id . '_start" placeholder="' . __('start', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $vs . '" />';
                        echo '<input type="text" name="' . $name . '[]" id="' . $id . '_end" placeholder="' . __('end', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $ve . '" />';
                    } else {
                        if ('-search' == $action && 'ID' == $key) {
                            echo '<input type="text" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value="' . $value . '"' . $disabled . ' />';
                        } else {
                            if ('user_registered' == $key || 'ID' == $key) {
                                echo $value . '<br />';
                                if ('ID' == $key) {
                                    echo implode('<br />', apply_filters('bbconnect_user_id_assets', array(), $value, $action));
                                }
                            } else {
                                if ('-search' == $action && is_array($value)) {
                                    echo '<input type="text" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value=""' . $disabled . ' />';
                                } else {
                                    echo '<input type="text" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value="' . $value . '"' . $disabled . ' />';
                                }
                            }
                        }
                    }
                }
            }
            break;
            // EXTEND THE FIELD SYSTEM
        // EXTEND THE FIELD SYSTEM
        default:
            do_action('bbconnect_field_switch', $meta, $args);
            break;
    }
}