function field_type_radio($field, $name, $value)
 {
     // options
     $options = preg_split('/[;,]+/', $field['options']);
     // check
     if (count($options)) {
         // value
         $value = $this->_filtered_value($field, $name, $value);
         // return
         return mgm_make_radio_group(sprintf('%s', $this->_get_element_name($field, $name)), $options, $value, MGM_VALUE_ONLY, '', 'div');
     }
     // return default
     return $this->field_type_input($field, $name, $value);
 }
/**
 * edit custom fields
 */
function mgm_edit_custom_fields($user_ID = false, $submit_row = false, $return = false)
{
    // get user
    if (!$user_ID) {
        $user_ID = mgm_get_user_id();
    }
    // get form object
    if (is_object($user_ID)) {
        $user_ID = $user_ID->ID;
    }
    //check logged in user is super admin:
    $is_admin = is_super_admin() ? true : false;
    // system
    $system_obj = mgm_get_class('system');
    // get custom_fields
    $profile_fields = mgm_get_config('default_profile_fields', array());
    // get active custom fields on profile page
    //$cf_profile_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display'=>array('on_profile'=>true)));
    //issue #844 - get active custom fields for profile page
    $cf_profile_pg = mgm_get_class('member_custom_fields');
    $cf_profile_page = array();
    foreach (array_unique($cf_profile_pg->sort_orders) as $id) {
        foreach ($cf_profile_pg->custom_fields as $field) {
            // issue #954: show the field only if it is enabled for profile page
            if ($field['id'] == $id && ($field['display']['on_profile'] || $is_admin)) {
                $cf_profile_page[] = $field;
            }
        }
    }
    $member = mgm_get_member($user_ID);
    //this is a fix for issue#: 589, see the notes for details:
    //This is to read saved coupons as array in order to fix the fatal error on some servers.
    //This will change the object on each users profile view.
    //Also this will avoid using patch for batch update,
    $arr_coupon = array('upgrade', 'extend');
    $oldcoupon_found = 0;
    foreach ($arr_coupon as $cpn_type) {
        if (isset($member->{$cpn_type}['coupon']) && is_object($member->{$cpn_type}['coupon'])) {
            $member->{$cpn_type}['coupon'] = (array) $member->{$cpn_type}['coupon'];
            $oldcoupon_found++;
        }
    }
    if ($oldcoupon_found) {
        $member->save();
    }
    // user
    $user = get_userdata($user_ID);
    // init
    $html = '';
    // capture
    $fields = array();
    //default and readonly fields:
    $default_readonly = array();
    $arr_images = array();
    //issue #844
    $skip_fileds = array('subscription_introduction', 'coupon', 'privacy_policy', 'payment_gateways', 'terms_conditions', 'subscription_options', 'autoresponder', 'captcha', 'show_public_profile');
    // loop fields
    foreach ($cf_profile_page as $field) {
        // issue#: 255
        if (in_array($field['name'], array_keys($profile_fields))) {
            //if custom field = defualt field, is read only
            if ($field['attributes']['readonly'] && !$is_admin) {
                $default_readonly[] = $profile_fields[$field['name']]['id'];
                //email and url id is different than custom fields:
                if (in_array($field['name'], array('email', 'url'))) {
                    $default_readonly[] = $field['name'];
                }
            }
            continue;
        }
        //issue #844
        if (in_array($field['name'], $skip_fileds)) {
            continue;
        }
        // init value
        $value = '';
        //disable readonly for admin user(issue#: 515)
        $ro = $field['attributes']['readonly'] == true && !$is_admin ? 'readonly="readonly"' : false;
        // value
        if (isset($member->custom_fields->{$field}['name'])) {
            $value = $member->custom_fields->{$field}['name'];
        }
        // date
        if ($field['name'] == 'birthdate') {
            if ($value) {
                //convert saved date to input field format
                $value = mgm_get_datepicker_format('date', $value);
            } else {
                $value = '';
            }
            $element = '<input type="text" name="mgm_profile_field[' . $field['name'] . ']" value="' . $value . '" ' . $ro . ' class="text ' . ($ro ? '' : 'mgm_date') . ' mgm_custom_profile_birthdate"/>';
        } else {
            if ($field['name'] == 'country') {
                $countries = mgm_field_values(TBL_MGM_COUNTRY, 'code', 'name');
                if ($ro) {
                    $countries = !empty($value) ? array($value => $countries[$value]) : array(" " => "&nbsp;");
                }
                //issue #1782
                $value = !empty($value) ? $value : 'US';
                $options = mgm_make_combo_options($countries, $value, MGM_KEY_VALUE);
                $element = '<select name="mgm_profile_field[' . $field['name'] . ']" > ' . $options . ' </select>';
            } else {
                if ($field['type'] == 'text') {
                    $element = '<input type="text" name="mgm_profile_field[' . $field['name'] . ']" value="' . $value . '" ' . $ro . ' class="text mgm_custom_profile_password"/>';
                } else {
                    if ($field['type'] == 'password') {
                        continue;
                    } else {
                        if ($field['type'] == 'textarea') {
                            $element = '<textarea name="mgm_profile_field[' . $field['name'] . ']" cols="40" rows="5" ' . $ro . '>' . $value . '</textarea>';
                        } else {
                            if ($field['type'] == 'checkbox') {
                                $options = preg_split('/[;,]/', $field['options']);
                                //$values  = preg_split('/[;,\s]/', $value);
                                $values = @unserialize($value);
                                // pass " " as value to prevent the default value getting selected, if no option is selected
                                $values = empty($values) ? " " : $values;
                                //Issue # 694
                                $element = mgm_make_checkbox_group('mgm_profile_field[' . $field['name'] . '][]', $options, $values, MGM_VALUE_ONLY, '', 'div');
                            } else {
                                if ($field['type'] == 'checkboxg') {
                                    $options = preg_split('/[;,]/', $field['options']);
                                    if (!is_array($value)) {
                                        $values = @unserialize($value);
                                    } else {
                                        $values = $value;
                                    }
                                    $values = empty($values) ? " " : $values;
                                    $element = mgm_make_checkbox_group('mgm_profile_field[' . $field['name'] . '][]', $options, $values, MGM_VALUE_ONLY, '', 'div');
                                } else {
                                    if ($field['type'] == 'radio') {
                                        $options = preg_split('/[;,]/', $field['options']);
                                        $element = mgm_make_radio_group('mgm_profile_field[' . $field['name'] . ']', $options, $value, MGM_VALUE_ONLY);
                                    } else {
                                        if ($field['type'] == 'select') {
                                            $element = '<select name="mgm_profile_field[' . $field['name'] . ']" ' . $ro . '>';
                                            $options = preg_split('/[;,]/', $field['options']);
                                            if ($ro) {
                                                $options = !empty($value) ? array($value => $value) : array(" " => "&nbsp;");
                                            }
                                            $element .= mgm_make_combo_options($options, $value, MGM_VALUE_ONLY);
                                            $element .= '</select>';
                                        } else {
                                            if ($field['type'] == 'selectm') {
                                                $element = '<select name="mgm_profile_field[' . $field['name'] . '][]" ' . $ro . ' multiple>';
                                                $options = preg_split('/[;,]/', $field['options']);
                                                if ($ro) {
                                                    $options = !empty($value) ? array($value => $value) : array(" " => "&nbsp;");
                                                }
                                                $element .= mgm_make_combo_options($options, $value, MGM_VALUE_ONLY);
                                                $element .= '</select>';
                                            } else {
                                                if ($field['type'] == 'html') {
                                                    $element = '';
                                                    $element .= '<div class="mgm_custom_subs_introduction">' . html_entity_decode(mgm_stripslashes_deep($field['value'])) . '</div>';
                                                } else {
                                                    if ($field['type'] == 'image') {
                                                        $form_fields = new mgm_form_fields();
                                                        $element = $form_fields->get_field_element($field, 'mgm_profile_field', $value);
                                                        if (!in_array($field['name'], $arr_images)) {
                                                            $arr_images[] = $field['name'];
                                                        }
                                                        //issue #1258
                                                    } else {
                                                        if ($field['type'] == 'label') {
                                                            $form_fields = new mgm_form_fields();
                                                            $element = $form_fields->get_field_element($field, 'mgm_profile_field', $value);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // set array
        if ($element) {
            $fields[] = array('name' => $field['name'], 'label' => $field['label'], 'field' => $element);
        }
    }
    // if fields - issue #1782
    if (count($fields)) {
        $html .= '<table class="form-table">';
        foreach ($fields as $i => $row) {
            $html .= '<tr><th><label>' . mgm_stripslashes_deep($row['label']) . '</label></th>';
            $html .= '<td>' . $row['field'] . '</td></tr>';
        }
        // button
        if ($submit_row) {
            $html .= '<tr>
				<td colspan="2">
					<input class="button" type="submit" name="submit" value="' . __('Update your profile', 'mgm') . '"/>
					<input type="hidden" name="update_mgm_custom_fields_submit" value="1" />
			</td></tr>';
        }
        $html .= '</table>';
        $html .= mgm_attach_scripts(true, array());
        $yearRange = mgm_get_calendar_year_range();
        //include scripts for image upload:
        if (!empty($arr_images)) {
            $html .= mgm_upload_script_js('your-profile', $arr_images);
        }
        $html .= '<script language="javascript">jQuery(document).ready(function(){try{mgm_date_picker(".mgm_date",false,{yearRange:"' . $yearRange . '", dateFormat: "' . mgm_get_datepicker_format() . '"});}catch(x){}});</script>';
    }
    if (!empty($default_readonly)) {
        $html .= '<script language="javascript">';
        $html .= 'jQuery(document).ready(function(){try{';
        $html .= 'jQuery.each(' . json_encode($default_readonly) . ', function(){jQuery("#"+this).attr("readonly", true)})';
        $html .= '}catch(x){}})';
        $html .= '</script>';
    }
    // return
    if ($return) {
        return $html;
    } else {
        echo $html;
    }
}