/** * Make a custom profile field. * * @param SHORT_TEXT Name of the field. * @param BINARY Whether the field is locked (i.e. cannot be deleted from the system). * @param SHORT_TEXT Description of the field. * @param LONG_TEXT The default value for the field. * @param BINARY Whether the field is publicly viewable. * @param BINARY Whether the field is viewable by the owner. * @param BINARY Whether the field may be set by the owner. * @param BINARY Whether the field is encrypted. * @param ID_TEXT The type of the field. * @set short_text long_text short_trans long_trans integer upload picture url list tick float * @param BINARY Whether it is required that every member have this field filled in. * @param BINARY Whether this field is shown in posts and places where member details are highlighted (such as an image in a member gallery). * @param BINARY Whether this field is shown in preview places, such as in the teaser for a member gallery. * @param ?integer The order of this field relative to other fields (NULL: next). * @param LONG_TEXT The usergroups that this field is confined to (comma-separated list). * @param boolean Whether to check that no field has this name already. * @param BINARY Whether the field is to be shown on the join form * @return AUTO_LINK The ID of the new custom profile field. */ function ocf_make_custom_field($name, $locked = 0, $description = '', $default = '', $public_view = 0, $owner_view = 0, $owner_set = 0, $encrypted = 0, $type = 'long_text', $required = 0, $show_in_posts = 0, $show_in_post_previews = 0, $order = NULL, $only_group = '', $no_name_dupe = false, $show_on_join_form = 0) { $dbs_back = $GLOBALS['NO_DB_SCOPE_CHECK']; $GLOBALS['NO_DB_SCOPE_CHECK'] = true; if ($only_group == '-1') { $only_group = ''; } // Can only encrypt things if encryption support is available require_code('encryption'); //if (!is_encryption_enabled()) $encrypted=0; // Can't have publicly-viewable encrypted fields if ($encrypted == 1) { $public_view = 0; } if ($no_name_dupe) { $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $name)); if (!is_null($test)) { $GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_back; return $test; } } if (is_null($order)) { $order = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'MAX(cf_order)'); if (is_null($order)) { $order = 0; } else { $order++; } } $map = array('cf_name' => insert_lang($name, 2, $GLOBALS['FORUM_DB']), 'cf_locked' => $locked, 'cf_description' => insert_lang($description, 2, $GLOBALS['FORUM_DB']), 'cf_default' => $default, 'cf_public_view' => $public_view, 'cf_owner_view' => $owner_view, 'cf_owner_set' => $owner_set, 'cf_type' => $type, 'cf_required' => $required, 'cf_show_in_posts' => $show_in_posts, 'cf_show_in_post_previews' => $show_in_post_previews, 'cf_order' => $order, 'cf_only_group' => $only_group, 'cf_show_on_join_form' => $show_on_join_form); $id = $GLOBALS['FORUM_DB']->query_insert('f_custom_fields', $map + array('cf_encrypted' => $encrypted), true, true); if (is_null($id)) { $id = $GLOBALS['FORUM_DB']->query_insert('f_custom_fields', $map, true); } // Still upgrading, cf_encrypted does not exist yet list($_type, $index) = get_cpf_storage_for($type); require_code('database_action'); // ($index?'#':''). $GLOBALS['FORUM_DB']->add_table_field('f_member_custom_fields', 'field_' . strval($id), $_type); // Default will be made explicit when we insert rows $indices_count = $GLOBALS['FORUM_DB']->query_value('db_meta_indices', 'COUNT(*)', array('i_table' => 'f_member_custom_fields')); if ($indices_count < 60) { if ($index) { if ($_type != 'LONG_TEXT') { $GLOBALS['FORUM_DB']->create_index('f_member_custom_fields', 'mcf' . strval($id), array('field_' . strval($id)), 'mf_member_id'); } if (strpos($_type, '_TEXT') !== false) { $GLOBALS['FORUM_DB']->create_index('f_member_custom_fields', '#mcf_ft_' . strval($id), array('field_' . strval($id)), 'mf_member_id'); } } elseif (strpos($type, 'trans') !== false || $type == 'posting_field') { $GLOBALS['FORUM_DB']->create_index('f_member_custom_fields', 'mcf' . strval($id), array('field_' . strval($id)), 'mf_member_id'); // For joins } } log_it('ADD_CUSTOM_PROFILE_FIELD', strval($id), $name); $GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_back; return $id; }
/** * Edit a custom profile field. * * @param AUTO_LINK The ID of the custom profile field. * @param SHORT_TEXT Name of the field. * @param SHORT_TEXT Description of the field. * @param LONG_TEXT The default value for the field. * @param BINARY Whether the field is publicly viewable. * @param BINARY Whether the field is viewable by the owner. * @param BINARY Whether the field may be set by the owner. * @param BINARY Whether the field should be encrypted. * @param BINARY Whether the field is to be shown on the join form * @param BINARY Whether this field is shown in posts and places where member details are highlighted (such as an image in a member gallery). * @param BINARY Whether this field is shown in preview places, such as in the teaser for a member gallery. * @param integer The order of this field relative to other fields. * @param LONG_TEXT The usergroups that this field is confined to (comma-separated list). * @param ID_TEXT The type of the field. * @set short_text long_text short_trans long_trans integer upload picture url list tick float * @param BINARY Whether it is required that every member have this field filled in. */ function ocf_edit_custom_field($id, $name, $description, $default, $public_view, $owner_view, $owner_set, $encrypted, $required, $show_in_posts, $show_in_post_previews, $order, $only_group, $type, $show_on_join_form) { $dbs_back = $GLOBALS['NO_DB_SCOPE_CHECK']; $GLOBALS['NO_DB_SCOPE_CHECK'] = true; if ($only_group == '-1') { $only_group = ''; } $info = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('cf_name', 'cf_description'), array('id' => $id), '', 1); $_name = $info[0]['cf_name']; $_description = $info[0]['cf_description']; $map = array('cf_name' => lang_remap($_name, $name, $GLOBALS['FORUM_DB']), 'cf_description' => lang_remap($_description, $description, $GLOBALS['FORUM_DB']), 'cf_default' => $default, 'cf_public_view' => $public_view, 'cf_owner_view' => $owner_view, 'cf_owner_set' => $owner_set, 'cf_required' => $required, 'cf_show_in_posts' => $show_in_posts, 'cf_show_in_post_previews' => $show_in_post_previews, 'cf_order' => $order, 'cf_only_group' => $only_group, 'cf_type' => $type, 'cf_show_on_join_form' => $show_on_join_form); $GLOBALS['FORUM_DB']->query_update('f_custom_fields', $map, array('id' => $id), '', 1); list($_type, $index) = get_cpf_storage_for($type); require_code('database_action'); $GLOBALS['FORUM_DB']->delete_index_if_exists('f_member_custom_fields', 'mcf' . strval($id)); $GLOBALS['FORUM_DB']->delete_index_if_exists('f_member_custom_fields', '#mcf_ft_' . strval($id)); $indices_count = $GLOBALS['FORUM_DB']->query_value('db_meta_indices', 'COUNT(*)', array('i_table' => 'f_member_custom_fields')); if ($indices_count < 60) { if ($index) { if ($_type != 'LONG_TEXT') { $GLOBALS['FORUM_DB']->create_index('f_member_custom_fields', 'mcf' . strval($id), array('field_' . strval($id)), 'mf_member_id'); } if (strpos($_type, '_TEXT') !== false) { $GLOBALS['FORUM_DB']->create_index('f_member_custom_fields', '#mcf_ft_' . strval($id), array('field_' . strval($id)), 'mf_member_id'); } } elseif (strpos($type, 'trans') !== false || $type == 'posting_field') { $GLOBALS['FORUM_DB']->create_index('f_member_custom_fields', 'mcf' . strval($id), array('field_' . strval($id)), 'mf_member_id'); // For joins } } log_it('EDIT_CUSTOM_PROFILE_FIELD', strval($id), $name); $GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_back; }