Skip to content

Commit

Permalink
Implemented #0001824: Choosing which CPFs are included in search
Browse files Browse the repository at this point in the history
  • Loading branch information
celmanabbas committed Jun 23, 2019
1 parent a07c0f6 commit b6483b9
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 74 deletions.
15 changes: 13 additions & 2 deletions adminzone/pages/modules/admin_cns_customprofilefields.php
Expand Up @@ -209,14 +209,16 @@ public function browse()
* @param LONG_TEXT $only_group The usergroups that this field is confined to (comma-separated list)
* @param BINARY $locked Whether the field is locked
* @param SHORT_TEXT $options Field options
* @param BINARY $include_in_main_search Whether to include in main keyword search
* @param BINARY $allow_template_search Whether to allow template search
* @param ID_TEXT $icon Whether it is required that every member have this field filled in
* @param ID_TEXT $section Whether it is required that every member have this field filled in
* @param LONG_TEXT $tempcode Whether it is required that every member have this field filled in
* @param ID_TEXT $autofill_type Autofill field name from https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field
* @param ID_TEXT $autofill_hint Autofill hint: '' or 'shipping' or 'billing'
* @return array A pair: the Tempcode for the visible fields, and the Tempcode for the hidden fields
*/
public function get_form_fields($name = '', $description = '', $default = '', $public_view = 1, $owner_view = 1, $owner_set = 1, $encrypted = 0, $type = 'long_text', $required = 0, $show_on_join_form = 0, $show_in_posts = 0, $show_in_post_previews = 0, $order = null, $only_group = '', $locked = 0, $options = '', $icon = '', $section = '', $tempcode = '', $autofill_type = '', $autofill_hint = '')
public function get_form_fields($name = '', $description = '', $default = '', $public_view = 1, $owner_view = 1, $owner_set = 1, $encrypted = 0, $type = 'long_text', $required = 0, $show_on_join_form = 0, $show_in_posts = 0, $show_in_post_previews = 0, $order = null, $only_group = '', $locked = 0, $options = '', $include_in_main_search = 0, $allow_template_search = 0, $icon = '', $section = '', $tempcode = '', $autofill_type = '', $autofill_hint = '')
{
$fields = new Tempcode();
$hidden = new Tempcode();
Expand Down Expand Up @@ -332,6 +334,9 @@ public function get_form_fields($name = '', $description = '', $default = '', $p
$fields->attach(form_input_tick(do_lang_tempcode('SHOW_IN_POSTS'), do_lang_tempcode('DESCRIPTION_SHOW_IN_POSTS'), 'show_in_posts', $show_in_posts == 1));
$fields->attach(form_input_tick(do_lang_tempcode('SHOW_IN_POST_PREVIEWS'), do_lang_tempcode('DESCRIPTION_SHOW_IN_POST_PREVIEWS'), 'show_in_post_previews', $show_in_post_previews == 1));

$fields->attach(form_input_tick(do_lang_tempcode('INCLUDE_IN_MAIN_SEARCH'), do_lang_tempcode('DESCRIPTION_INCLUDE_IN_MAIN_SEARCH'), 'include_in_main_search', $include_in_main_search == 1));
$fields->attach(form_input_tick(do_lang_tempcode('ALLOW_TEMPLATE_SEARCH'), do_lang_tempcode('DESCRIPTION_ALLOW_TEMPLATE_SEARCH'), 'allow_template_search', $allow_template_search == 1));

$fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('_GUID' => '7648f571ac21b86c2dbe82d3e8378a52', 'SECTION_HIDDEN' => $tempcode == '' && $section == '' && $icon == '', 'TITLE' => do_lang_tempcode('ADVANCED'))));

$rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id', 'g_name', 'g_is_super_admin'), array('g_is_private_club' => 0));
Expand Down Expand Up @@ -588,13 +593,15 @@ public function fill_in_edit_form($id)
$show_on_join_form = $myrow['cf_show_on_join_form'];
$locked = $myrow['cf_locked'];
$options = $myrow['cf_options'];
$include_in_main_search = $myrow['cf_include_in_main_search'];
$allow_template_search = $myrow['cf_allow_template_search'];
$icon = $myrow['cf_icon'];
$section = $myrow['cf_section'];
$tempcode = $myrow['cf_tempcode'];
$autofill_type = $myrow['cf_autofill_type'];
$autofill_hint = $myrow['cf_autofill_hint'];

return $this->get_form_fields($name, $description, $default, $public_view, $owner_view, $owner_set, $encrypted, $type, $required, $show_on_join_form, $show_in_posts, $show_in_post_previews, $order, $only_group, $locked, $options, $icon, $section, $tempcode, $autofill_type, $autofill_hint);
return $this->get_form_fields($name, $description, $default, $public_view, $owner_view, $owner_set, $encrypted, $type, $required, $show_on_join_form, $show_in_posts, $show_in_post_previews, $order, $only_group, $locked, $options, $include_in_main_search, $allow_template_search, $icon, $section, $tempcode, $autofill_type, $autofill_hint);
}

/**
Expand Down Expand Up @@ -622,6 +629,8 @@ public function add_actualisation()
$only_group,
post_param_integer('show_on_join_form', 0),
post_param_string('options'),
post_param_integer('include_in_main_search', 0),
post_param_integer('allow_template_search', 0),
post_param_string('icon'),
post_param_string('section'),
post_param_string('tempcode'),
Expand Down Expand Up @@ -657,6 +666,8 @@ public function edit_actualisation($id)
post_param_string('type'),
post_param_integer('show_on_join_form', 0),
post_param_string('options'),
post_param_integer('include_in_main_search', 0),
post_param_integer('allow_template_search', 0),
post_param_string('icon'),
post_param_string('section'),
post_param_string('tempcode'),
Expand Down
12 changes: 6 additions & 6 deletions adminzone/pages/modules_custom/admin_customers.php
Expand Up @@ -107,12 +107,12 @@ public function install($upgrade_from = null, $upgrade_from_hack = null)
if ($cur_id !== null) {
$GLOBALS['FORUM_DB']->query_update('f_custom_fields', array('cf_owner_view' => 1, 'cf_owner_set' => 1), array('id' => $cur_id), '', 1);
}
cns_make_custom_field('cms_support_credits', 1, '', '', 0, 1, 0, 0, 'integer', 0, 0, 0, null, '', 0, '', '', '', '', true);
cns_make_custom_field('cms_ftp_host', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'short_text', 0, 0, 0, null, '', 0, '', '', '', '', true);
cns_make_custom_field('cms_ftp_path', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'short_text', 0, 0, 0, null, '', 0, '', '', '', '', true);
cns_make_custom_field('cms_ftp_username', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'short_text', 0, 0, 0, null, '', 0, '', '', '', '', true);
cns_make_custom_field('cms_ftp_password', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'password', 0, 0, 0, null, '', 0, '', '', '', '', true);
cns_make_custom_field('cms_profession', 0, '', do_lang('CUSTOMER_PROFESSION_CPF_LIST'), 0, 1, 1, 0, 'list', 0, 0, 0, null, '', 0, '', '', '', '', true);
cns_make_custom_field('cms_support_credits', 1, '', '', 0, 1, 0, 0, 'integer', 0, 0, 0, null, '', 0, '', 0, 0, '', '', '', true);
cns_make_custom_field('cms_ftp_host', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'short_text', 0, 0, 0, null, '', 0, '', 0, 0, '', '', '', true);
cns_make_custom_field('cms_ftp_path', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'short_text', 0, 0, 0, null, '', 0, '', 0, 0, '', '', '', true);
cns_make_custom_field('cms_ftp_username', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'short_text', 0, 0, 0, null, '', 0, '', 0, 0, '', '', '', true);
cns_make_custom_field('cms_ftp_password', 0, do_lang('ENCRYPTED_TO_WEBSITE'), '', 0, 1, 1, 1, 'password', 0, 0, 0, null, '', 0, '', 0, 0, '', '', '', true);
cns_make_custom_field('cms_profession', 0, '', do_lang('CUSTOMER_PROFESSION_CPF_LIST'), 0, 1, 1, 0, 'list', 0, 0, 0, null, '', 0, '', 0, 0, '', '', '', true);

// Credit logging...

Expand Down
4 changes: 4 additions & 0 deletions lang/EN/cns.ini
Expand Up @@ -265,6 +265,10 @@ SHOW_ON_JOIN_FORM=Show on the join form
DESCRIPTION_SHOW_ON_JOIN_FORM=Whether to show this setting on the join form.
SHOW_IN_POST_PREVIEWS=Show with summaries of content
DESCRIPTION_SHOW_IN_POST_PREVIEWS=Whether the value of this field will be shown with certain kinds of member content summary (currently just personal-gallery links in the galleries module).
INCLUDE_IN_MAIN_SEARCH=Include in main search
DESCRIPTION_INCLUDE_IN_MAIN_SEARCH=Whether the value of this field will be searched through the main search input.
ALLOW_TEMPLATE_SEARCH=Allow template search
DESCRIPTION_ALLOW_TEMPLATE_SEARCH=Whether to have a designated input box for this field in template search.
SHOW_IN_POSTS=Show with content
DESCRIPTION_SHOW_IN_POSTS=Whether the value of this field will be shown with member content (currently next to posts on the forum [under the username tooltip], and also from within personal-galleries).
PUBLIC_VIEW=Publicly viewable
Expand Down
10 changes: 5 additions & 5 deletions site/pages/modules/purchase.php
Expand Up @@ -133,12 +133,12 @@ public function install($upgrade_from = null, $upgrade_from_hack = null)

require_code('currency');

$GLOBALS['FORUM_DRIVER']->install_create_custom_field('currency', 3, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'list', 0, '', 'default=CURRENCY', '', '', '', /*autofill_type=*/'transaction-currency');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_cardholder_name', 100, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'short_text', 1, '', '', '', '', '', /*autofill_type=*/'cc-name');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_type', 26, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'list', 1, 'American Express|Delta|Diners Card|JCB|Master Card|Solo|Switch|Visa', '', '', '', '', /*autofill_type=*/'cc-type');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_number', 20, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'integer', 1, '', '', '', '', '', /*autofill_type=*/'cc-number');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('currency', 3, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'list', 0, '', 'default=CURRENCY', 0, 0, '', '', '', /*autofill_type=*/'transaction-currency');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_cardholder_name', 100, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'short_text', 1, '', '', 0, 0, '', '', '', /*autofill_type=*/'cc-name');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_type', 26, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'list', 1, 'American Express|Delta|Diners Card|JCB|Master Card|Solo|Switch|Visa', '', 0, 0, '', '', '', /*autofill_type=*/'cc-type');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_number', 20, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'integer', 1, '', '', 0, 0, '', '', '', /*autofill_type=*/'cc-number');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_start_date', 5, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'year_month', 1, 'mm/yy');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_expiry_date', 5, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'year_month', 1, 'mm/yy', '', '', '', '', /*autofill_type=*/'cc-exp');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_expiry_date', 5, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'year_month', 1, 'mm/yy', '', 0, 0, '', '', '', /*autofill_type=*/'cc-exp');
$GLOBALS['FORUM_DRIVER']->install_create_custom_field('payment_card_issue_number', 2, /*locked=*/0, /*viewable=*/0, /*settable=*/1, /*required=*/0, '', 'integer', 1, '');

$GLOBALS['SITE_DB']->create_table('ecom_transactions', array(
Expand Down
6 changes: 4 additions & 2 deletions sources/cns_forum_driver_helper_install.php
Expand Up @@ -35,6 +35,8 @@
* @param BINARY $encrypted Whether the field is encrypted
* @param ?string $default Default field value (null: standard for field type)
* @param SHORT_TEXT $options Field options
* @param BINARY $include_in_main_search Whether to include in main keyword search
* @param BINARY $allow_template_search Whether to allow template search
* @param ID_TEXT $icon Whether it is required that every member have this field filled in
* @param ID_TEXT $section Whether it is required that every member have this field filled in
* @param LONG_TEXT $tempcode Whether it is required that every member have this field filled in
Expand All @@ -44,7 +46,7 @@
*
* @ignore
*/
function _helper_install_create_custom_field($this_ref, $name, $length, $locked = 1, $viewable = 0, $settable = 0, $required = 0, $description = '', $type = 'long_text', $encrypted = 0, $default = null, $options = '', $icon = '', $section = '', $tempcode = '', $autofill_type = '', $autofill_hint = '')
function _helper_install_create_custom_field($this_ref, $name, $length, $locked = 1, $viewable = 0, $settable = 0, $required = 0, $description = '', $type = 'long_text', $encrypted = 0, $default = null, $options = '', $include_in_main_search = 0, $allow_template_search = 0, $icon = '', $section = '', $tempcode = '', $autofill_type = '', $autofill_hint = '')
{
cns_require_all_forum_stuff();
require_code('cns_members_action');
Expand All @@ -55,7 +57,7 @@ function _helper_install_create_custom_field($this_ref, $name, $length, $locked
if ($default === null) {
$default = (strpos($name, 'points') !== false) ? '0' : '';
}
$id = cns_make_custom_field($name, $locked, $description, $default, $viewable, $viewable, $settable, $encrypted, $type, $required, 0, 0, null, '', 0, $options, $icon, $section, $tempcode, true, $autofill_type, $autofill_hint);
$id = cns_make_custom_field($name, $locked, $description, $default, $viewable, $viewable, $settable, $encrypted, $type, $required, 0, 0, null, '', 0, $options, $include_in_main_search, $allow_template_search, $icon, $section, $tempcode, true, $autofill_type, $autofill_hint);
}
return $id !== null;
}
Expand Down
5 changes: 5 additions & 0 deletions sources/cns_install.php
Expand Up @@ -227,6 +227,9 @@ function install_cns($upgrade_from = null)
$GLOBALS['FORUM_DB']->query_update('f_custom_fields', array('cf_type' => 'date'), array('cf_type' => 'just_date'));
$GLOBALS['FORUM_DB']->query_update('f_custom_fields', array('cf_type' => 'time'), array('cf_type' => 'just_time'));

$GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_include_in_main_search', 'BINARY');
$GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_allow_template_search', 'BINARY');

$GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_icon', 'ID_TEXT');
$GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_section', 'ID_TEXT');
$GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_tempcode', 'LONG_TEXT');
Expand Down Expand Up @@ -438,6 +441,8 @@ function install_cns($upgrade_from = null)
'cf_encrypted' => 'BINARY',
'cf_show_on_join_form' => 'BINARY',
'cf_options' => 'SHORT_TEXT',
'cf_include_in_main_search' => 'BINARY',
'cf_allow_template_search' => 'BINARY',
'cf_icon' => 'ID_TEXT',
'cf_section' => 'ID_TEXT',
'cf_tempcode' => 'LONG_TEXT',
Expand Down
10 changes: 8 additions & 2 deletions sources/cns_members_action.php
Expand Up @@ -815,6 +815,8 @@ function cns_make_predefined_content_field($type)
$required = 0;
$show_in_posts = 0;
$show_in_post_previews = 0;
$include_in_main_search = 0;
$allow_template_search = 0;

if ($type == 'staff_notes') {
$public_view = 0;
Expand All @@ -837,7 +839,7 @@ function cns_make_predefined_content_field($type)
$description = do_lang('DEFAULT_CPF_' . $type . '_DESCRIPTION');
}

return cns_make_custom_field($title, 0, $description, '', $public_view, $owner_view, $owner_set, 0, $_type, $required, $show_in_posts, $show_in_post_previews, null, '', 0, '', $icon, $section, $tempcode, true);
return cns_make_custom_field($title, 0, $description, '', $public_view, $owner_view, $owner_set, 0, $_type, $required, $show_in_posts, $show_in_post_previews, null, '', 0, '', $include_in_main_search, $allow_template_search, $icon, $section, $tempcode, true);
}

/**
Expand Down Expand Up @@ -926,6 +928,8 @@ function get_cpf_storage_for($type, $encrypted = 0, $__default = '')
* @param LONG_TEXT $only_group The usergroups that this field is confined to (comma-separated list)
* @param BINARY $show_on_join_form Whether the field is to be shown on the join form
* @param SHORT_TEXT $options Field options
* @param BINARY $include_in_main_search Whether to include in main keyword search
* @param BINARY $allow_template_search Whether to allow template search
* @param ID_TEXT $icon Whether it is required that every member have this field filled in
* @param ID_TEXT $section Whether it is required that every member have this field filled in
* @param LONG_TEXT $tempcode Whether it is required that every member have this field filled in
Expand All @@ -934,7 +938,7 @@ function get_cpf_storage_for($type, $encrypted = 0, $__default = '')
* @param ID_TEXT $autofill_hint Autofill hint: '' or 'shipping' or 'billing'
* @return AUTO_LINK The ID of the new Custom Profile Field
*/
function cns_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 = '', $show_on_join_form = 0, $options = '', $icon = '', $section = '', $tempcode = '', $no_name_dupe = false, $autofill_type = '', $autofill_hint = '')
function cns_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 = '', $show_on_join_form = 0, $options = '', $include_in_main_search = 0, $allow_template_search = 0, $icon = '', $section = '', $tempcode = '', $no_name_dupe = false, $autofill_type = '', $autofill_hint = '')
{
require_code('global4');
prevent_double_submit('ADD_CUSTOM_PROFILE_FIELD', null, $name);
Expand Down Expand Up @@ -979,6 +983,8 @@ function cns_make_custom_field($name, $locked = 0, $description = '', $default =
'cf_order' => $order,
'cf_only_group' => $only_group,
'cf_show_on_join_form' => $show_on_join_form,
'cf_include_in_main_search' => $include_in_main_search,
'cf_allow_template_search' => $allow_template_search,
'cf_icon' => $icon,
'cf_section' => $section,
'cf_tempcode' => $tempcode,
Expand Down

0 comments on commit b6483b9

Please sign in to comment.