Advertisement:

Author Topic: Include reason for joining in profile.  (Read 1287 times)

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Include reason for joining in profile.
« on: March 02, 2018, 01:02:08 PM »
I've used the reason for joining mod for many many years, and it has been most helpful. I realize I could use custom profile fields to do this now, but we have all those years of data in the join_reason field I want to keep and be able to refer back to.  Problem is, unless you go into phpmyadmin there is really no way to view it.  We like the way it displays now when approving members, so that is the reason for keeping the mod.

Anyhow, can someone help me with some code to include it in a user profile, so only admins can see it?  This is what I tried innitially, but the reason does not show up. I am guessing I need to define it somewhere?

Code: [Select]
echo '
<dt>', $txt['join_reason'], ': </dt>
<dd>', $context['member']['join_reason'], '</dd>';

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 56,969
  • Gender: Male
    • Kindred-999 on GitHub
Re: Include reason for joining in profile.
« Reply #1 on: March 02, 2018, 05:02:49 PM »
Why not just move the data from the reason field to a custom field?    That would basically take a single sql statement in phpmyadmin...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #2 on: March 02, 2018, 05:13:47 PM »
If you add a custom profile field that is required on registration, does that then appear on the approve members page so it can be looked at like the mod does?  Or would you have to actually go to the profile and look at it? I was assuming not.   That is what I am trying to avoid. If we get multiple registration requests before they can be addressed, we can easily look at them all in one spot without having to go to each profile.  Its a large forum and all registrations are screened.  I think we've had almost 800 approved new members this year

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #3 on: March 02, 2018, 06:38:33 PM »
I did run a test and added a custom profile field for registration. As I suspected, the data does not show up on the members waiting for approval. I think that what I seek is the best solution for me.  So with that... :)

I can fix an old truck but this is mostly beyond me.  :)

Offline Virginiaz

  • Semi-Newbie
  • *
  • Posts: 40
Re: Include reason for joining in profile.
« Reply #4 on: March 02, 2018, 06:42:51 PM »
Edit: Sorry, I forgot to mention, this is for adding a custom field. I know you were asking about something else before, but this was more straight-forward in my opinion, and it does what you were asking about after the first post, with the approval page and what not.
-

I have to admit, I thought this would be a quick one, but I am realizing now how much more complicated even generating just the member list is in SMF 2.0 (I've just done a bunch of SMF 1.1.21 coding in my spare time).


This is what I was able to do. Bare in mind that this is just what I was able to slap together in about 30 minutes:


1. Find this code in Sources/ManageMembers.php :

Code: [Select]
'ip' => array(
'header' => array(
'value' => $txt['ip_address'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=trackip;searchip=%1$s">%1$s</a>',
'params' => array(
'member_ip' => false,
),
),
),
'sort' => array(
'default' => 'INET_ATON(member_ip)',
'reverse' => 'INET_ATON(member_ip) DESC',
),
),


Add this as another entry in the array after it (you can add it somewhere else, but where you add it in this array determines where it will appear on the approve users list):

Important Note: You need to change the name of "cust_join_r" to whatever the custom col name of your custom profile field is. Otherwise it won't work.

Code: [Select]
// mod - add Reason for join custom profile field to approve list
'reason' => array(
'header' => array(
'value' => 'Reason for joining',
),
'data' => array(
'function' => create_function('$rowData', '
global $user_profile;

loadMemberData($rowData[\'id_member\'], false, \'profile\');

return $user_profile[$rowData[\'id_member\']][\'options\'][\'cust_join_r\'];
'),
'class' => 'windowbg',
),
'sort' => array(
'default' => 'join_reason',
'reverse' => 'join_reason DESC',
),
),
// end - end custom code

If you want to find the column name of your custom profile field, it's in the database table "custom_fields" (or rather: {$db_prefix}custom_fields). It would the text in the table column "col_name"


Attached is a screenshot of what the result looks like

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #5 on: March 02, 2018, 07:04:35 PM »
That looks like it would work nicely!  Two more questions.  First, how would the sql statement be formed to copy the existing data from the the join_reason in the smf_members table to the new column in custom_fields table

and

How would you make the field required on registration?  It appears there are no options in the custom fields creation to require a field

Offline Virginiaz

  • Semi-Newbie
  • *
  • Posts: 40
Re: Include reason for joining in profile.
« Reply #6 on: March 02, 2018, 07:34:16 PM »
Well thinking about it more, you could move to the custom fields like talked about before, I could put together a quickie php script to copy the data from members.join_reason to the custom field

This is the page to add a custom field. There are a ton of options to customize it, including only letting an admin see. It should be plainly visible on this page: [your forum.com]index.php?action=admin;area=featuresettings;sa=profileedit

-

or you could just add the data to the profile field like in your first post. The reason it's not working, probably, is because the join_reason column is not actually be fetched from the db and put into the $context array. I'm not sure what mod you are using, so I can't be sure if it's actually fetching that data or not, but I presume not.

Offline Virginiaz

  • Semi-Newbie
  • *
  • Posts: 40
Re: Include reason for joining in profile.
« Reply #7 on: March 02, 2018, 08:13:00 PM »
If the join_reason column is indeed not being plucked from the database, then the fix would be to add it to the query in loadMemberData, which is in Sources/Load.php:

Find:

Code: [Select]
function loadMemberData($users, $is_name = false, $set = 'normal')

A couple dozen lines inside the loadMemberData function, you should find this:

Code: [Select]
elseif ($set == 'profile')
{
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
mem.openid_uri, mem.birthdate, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login, mem.karma_good,
mem.karma_bad, mem.member_ip, mem.member_ip2, mem.lngfile, mem.id_group, mem.id_theme, mem.buddy_list,
mem.pm_ignore_list, mem.pm_email_notify, mem.pm_receive_from, mem.time_offset' . (!empty($modSettings['titlesEnable']) ? ', mem.usertitle' : '') . ',
mem.time_format, mem.secret_question, mem.is_activated, mem.additional_groups, mem.smiley_set, mem.show_online,
mem.total_time_logged_in, mem.id_post_group, mem.notify_announcements, mem.notify_regularity, mem.notify_send_body,
mem.notify_types, lo.url, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.ignore_boards, mem.warning,
CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars, mem.password_salt, mem.pm_prefs';

So maybe add it to the line that begins with mem.signature, like this:

Code: [Select]
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name, mem.join_reason,

^(again, assuming, join_reason is the name of the db column. You need to be careful about this when editing sql queries)


It's my assumption that once you make the above modification, the join_reason column should be available to you in the $context code you provided in your very first post in this thread. If so, you can wrap a conditional statement around it that checks for admin privileges, so it only shows up for Administrators:

Code: [Select]
if ( allowedTo('admin_forum') ) {
echo '
<dt>', $txt['join_reason'], ': </dt>
<dd>', $context['member']['join_reason'], '</dd>';
}

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 56,969
  • Gender: Male
    • Kindred-999 on GitHub
Re: Include reason for joining in profile.
« Reply #8 on: March 02, 2018, 09:05:14 PM »
Custom fields are stored in the smf_themes table
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #9 on: March 02, 2018, 09:40:06 PM »
join_reason is definitely in smf_members  in my database.

Offline Virginiaz

  • Semi-Newbie
  • *
  • Posts: 40
Re: Include reason for joining in profile.
« Reply #10 on: March 02, 2018, 10:08:45 PM »
join_reason is definitely in smf_members  in my database.

I wasn't asking if it was in the db table but rather if the loadMemberData was actually pulling it from the db. If you have a mod that adds their own columns to it, they usually have to add it to that function if they want it to be available to basic things like profiles and message view.

Check the db queries from loadMemberData like I was referring to in my last post, and add if it necessary as described.

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #11 on: March 02, 2018, 11:27:43 PM »
I tried the edit to load.php and the data would still not propagate into the profile edits

Offline Virginiaz

  • Semi-Newbie
  • *
  • Posts: 40
Re: Include reason for joining in profile.
« Reply #12 on: March 02, 2018, 11:40:40 PM »
I tried the edit to load.php and the data would still not propagate into the profile edits

Ok, I found out why. The loadMemberContext function in Load.php also needs to be modified. So in addition to adding "join_reason" to the sql query in loadMemberData, you need to do this in Load.php:

Find:

Code: [Select]
// What a monstrous array...
$memberContext[$user] = array(
'username' => $profile['member_name'],

Replace it with this:

Code: [Select]
// What a monstrous array...
$memberContext[$user] = array(
'username' => $profile['member_name'],
'join_reason' => !empty($profile['join_reason']) ? $profile['join_reason'] : '',


I added a test column to the members table called join_reason then followed all my own steps and I was able to successfully implement what you are trying to do. $context['member']['join_reason'] contained the data you are after.

Let me know how it goes.

Offline aegersz

  • Sophist Member
  • *****
  • Posts: 1,394
  • Gender: Male
  • "mods" junkie
    • dopetalk
Re: Include reason for joining in profile.
« Reply #13 on: March 03, 2018, 03:00:35 AM »
i came up with a batch solution to copy all join reasons from the mod to my new profile field via the DB.

it is documented in the mod comments and linked to my method.

it might help in someway.
Linux CentOS VPS running SMF 2.0 with 140+ mods installed (the full h/w and s/w can be seen at http://forum.drugs-and-users.org/index.php/topic,3301)

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #14 on: March 03, 2018, 10:41:02 AM »
EUREKA!

One thing though to make it work,  I had to also add  mem.join_reason here as well, perhaps because I am using smfpack's socialprofile?:

Code: [Select]
if ($set == 'normal')
{
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name, mem.join_reason,

Thanks a ton!   However...  Can we go a step further?  My forum has been around 18 years.  The first couple thousand members did not have to give a reason for joining, so their column is empty. Is there an if statement we could include to assign text to appear if the field is empty?

Offline Virginiaz

  • Semi-Newbie
  • *
  • Posts: 40
Re: Include reason for joining in profile.
« Reply #15 on: March 03, 2018, 12:43:51 PM »
Re-modify Load.php:loadMemberContext

Code: [Select]
// What a monstrous array...
$memberContext[$user] = array(
'username' => $profile['member_name'],
'join_reason' => !empty($profile['join_reason']) ? $profile['join_reason'] : 'N/A',

If you wanted to be fancy about it, I suppose you could change N/A to <i>N/A</i> so you can differentiate between a rare instance where a user themselves inputs N/A and when the reason is actually not available.

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #16 on: March 03, 2018, 01:13:42 PM »
Thank you!

  Now, if I wanted to get cute, and provide some random text via a random text script, can I put an include in there to direct to the script instead of the N/A?   If my php script was named randomtext.php for example...


Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #17 on: March 03, 2018, 01:24:14 PM »
I was able to accomplish that script part by myself.  THANK YOU!!

Offline Jeff B

  • Full Member
  • ***
  • Posts: 405
Re: Include reason for joining in profile.
« Reply #18 on: March 04, 2018, 01:12:04 PM »
I'm going to mark this as solved.  I decided to use the new function publicly. Members can go in and see what members back to 2010 and see what the reasons were for joining. Members that joined prior to that, back to 2000, we are having fun with that. The member reason function if empty, returns a random text script with made up reasons for joining. I came up with about 75 bogus reasons that people joined and each time that part of the profile is viewed, a random reason is displayed with a disclaimer that is it is a random reason generated by the Forum.  Pretty fun and the members like it.

Example:
 I have been around the forum since before they required a reason starting April 11th, 2010.
The Forestry Forum has generously generated a random reason for me!

I heard if I joined I could get Free Health care.
 
Example:

I have been around the forum since before they required a reason starting April 11th, 2010.
The Forestry Forum has generously generated a random reason for me!

I made a bet and I need someone to prove I'm right even if I'm not.

Example:

I have been around the forum since before they required a reason starting April 11th, 2010.
The Forestry Forum has generously generated a random reason for me!

I need someone to help me look for ticks.