[FREE or $5 done today] Profile Field only Admin & Owner can see

Started by General Xbox Gaming, September 28, 2014, 11:07:40 AM

Previous topic - Next topic

General Xbox Gaming

Quote from: Kindred on September 28, 2014, 08:52:46 PM
Right... So, you check if it exists... If not, then the value is null. If so, then the value is populated.

Again, much simpler than creating a whole new field and interface for that field.
I get what your saying but I want it in smf_forummembers to make it easier to find in phpMyAdmin if I can't edit it in the forum.

Arantor

And you can still do it with a single query and return null to it in the query if it doesn't exist.

$request = $smcFunc['db_query']('', '
SELECT mem.*, th.value AS cust_field
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}themes AS th ON (th.id_member = mem.id_member AND th.id_theme = 1 AND th.variable = {string:fieldname}
WHERE mem.member_name = {string:user}',
array(
'user' => $smcFunc['htmlspecialchars']($user),
'fieldname' => 'cust_field', // or whatever this is called in the internals, cust_ plus the first 6 letters (lowercase) usually
)
);


(And no, do not ask me to debug this if you haven't got $smcFunc integrated. Doing it any other way is insecure, I have complained about this before but I haven't had the time to write a proper version. This version is at least hardened against XSS, uses the correct encoding for what's in the database and is proven against SQL injections)

General Xbox Gaming

Quote from: Arantor on September 28, 2014, 09:14:19 PM
And you can still do it with a single query and return null to it in the query if it doesn't exist.

$request = $smcFunc['db_query']('', '
SELECT mem.*, th.value AS cust_field
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}themes AS th ON (th.id_member = mem.id_member AND th.id_theme = 1 AND th.variable = {string:fieldname}
WHERE mem.member_name = {string:user}',
array(
'user' => $smcFunc['htmlspecialchars']($user),
'fieldname' => 'cust_field', // or whatever this is called in the internals, cust_ plus the first 6 letters (lowercase) usually
)
);


(And no, do not ask me to debug this if you haven't got $smcFunc integrated. Doing it any other way is insecure, I have complained about this before but I haven't had the time to write a proper version. This version is at least hardened against XSS, uses the correct encoding for what's in the database and is proven against SQL injections)
Thank you for showing me this but I simply just want a column in smf_forummembers that holds the product_key value and a way to display it in the members profile so only them and admin can see it.

margarett

That's your call and I respect that ;)
Of course now you need to wait for someone to code it :P
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Considering that you have had multiple members of the SMF team, and one of the former SMF *developers* telling you not to do this and you still want to go ahead? Best of luck to you.

Kindred

But that's just the point...   If you use the built in function, you already CAN edit it in the forum profile section...  Not here is no need to code anything else other than the tweak that you already found, or do any direct database edits...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

General Xbox Gaming

A mod would be needed either way if my php script isn't secure.

The problem with using custom_field is that I would need to add the 4 columns of information where as I can edit 1 field in smf_forummembers as the user already exists where as the row doesn't until you add the info in there profile settings.

There is no halm in adding the column as the forum still works. The add/editing would be easier, so would the mod.

All I need is a field in users profile that only the owner and admin can see which gets the value from smf_forummembers column product_key.

Kindred

You keep saying.. "All I need is..."
What you don't seem to be understanding is that, your request is not actually simple... And that it duplicates functionality that already exists..  functionality which has been tested, checked and secured.

I don't understand why you think that you would need to add 4 columns either...
It writes one row per user per customprofilefield... 
It also is alreayd built in to the forum for editing, display and validation...

Seriously... With the tweak that you already found, the custom profile field function does EXACTLY what you have asked for. The only difference is that it writes to the themes table instead of the members table.  Arantor has even given you the exact query to pull the data into a different script based on username alone, if you need it...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

General Xbox Gaming

#28
Quote from: Kindred on September 29, 2014, 06:24:15 AM
You keep saying.. "All I need is..."
What you don't seem to be understanding is that, your request is not actually simple... And that it duplicates functionality that already exists..  functionality which has been tested, checked and secured.

I don't understand why you think that you would need to add 4 columns either...
It writes one row per user per customprofilefield... 
It also is alreayd built in to the forum for editing, display and validation...

Seriously... With the tweak that you already found, the custom profile field function does EXACTLY what you have asked for. The only difference is that it writes to the themes table instead of the members table.  Arantor has even given you the exact query to pull the data into a different script based on username alone, if you need it...
What I meant was, there are 4 Columns per Row! user_id, theme_id, variable & value
My way, using smf_forummembers only uses 1 new column (I already have) to store the product_key in the same Row as the user.

It doesn't 'need' to be editable, just display in the users profile page to owner and admin. Like the e-mail does and that code looks simple enough I might try and add it myself. I was asking for a mod so I can manage it better.

What I want it to do is this but it doesn't get the 'product_key'
// Display Product Key in forum profile.
 
if ($context['user']['is_owner'] || $context['user']['is_admin'])
	
echo 
'
	
	
<dt> Product Key: </dt>
	
	
<dd>'
$context['member']['product_key'], '</dd>';

Arantor

QuoteWhat I meant was, there are 4 Columns per Row! user_id, theme_id, variable & value

Yes, and the query I gave you deals with that and returns just the one column you need.

General Xbox Gaming

Quote from: Arantor on September 29, 2014, 10:39:10 AM
QuoteWhat I meant was, there are 4 Columns per Row! user_id, theme_id, variable & value

Yes, and the query I gave you deals with that and returns just the one column you need.
To add a new Product Key I need to add the users row "user_id, theme_id, variable & value" but with smf_forummembers the Column 'product_key' is already there and I only need to add a value.

Arantor

Well, you must already have the id member and the value, the theme id will always be 1 and the variable will be related to the name of the field.

You're still making this more complicated than it needs to be and I guarantee you no-one will want to take the more complicated route for the amount of money you were offering.

I'll build what you want, and do it securely, for money but I doubt you'd want to pay the amount I'd charge to do it.

General Xbox Gaming

Quote from: Arantor on September 29, 2014, 11:10:23 AM
Well, you must already have the id member and the value, the theme id will always be 1 and the variable will be related to the name of the field.

You're still making this more complicated than it needs to be and I guarantee you no-one will want to take the more complicated route for the amount of money you were offering.

I'll build what you want, and do it securely, for money but I doubt you'd want to pay the amount I'd charge to do it.
How much? Bare in mind I have 3 young kids and I only work 24hrs a week because I have RRMS (Multiple Sclerosis). I don't therfore have much money at the moment.

Arantor

My consulting rates are currently $50/hour. I'd be estimating a minimum of 3 hours work to implement it the way you're suggesting.

Or you could just do it for free the way we've outlined.

General Xbox Gaming

Quote from: Arantor on September 29, 2014, 11:29:20 AM
My consulting rates are currently $50/hour. I'd be estimating a minimum of 3 hours work to implement it the way you're suggesting.

Or you could just do it for free the way we've outlined.
Totally out of my budget!
Is there no way I can get this to work like the rest of the fields in Profile.template.php
// Display Product Key in forum profile.
 
if ($context['user']['is_owner'] || $context['user']['is_admin'])
	
echo 
'
	
	
<dt> Product Key: </dt>
	
	
<dd>'
$context['member']['product_key'], '</dd>';

margarett

It is possible, yes. If you forget the edition part (so that you always go via phpmyadmin), some minor changes in Load.php will allow you to do that. It's not the best way to do it, but it's also clear that it's the only way you'll accept it so there's no point in continuing that discussion ;)

I'm moving this to Coding Discussion now, as it's a custom coding issue (a MOD will not happen - for free at least). If I find the time I'll post the modifications you need to perform.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

General Xbox Gaming

Quote from: margarett on September 29, 2014, 12:28:54 PM
It is possible, yes. If you forget the edition part (so that you always go via phpmyadmin), some minor changes in Load.php will allow you to do that. It's not the best way to do it, but it's also clear that it's the only way you'll accept it so there's no point in continuing that discussion ;)

I'm moving this to Coding Discussion now, as it's a custom coding issue (a MOD will not happen - for free at least). If I find the time I'll post the modifications you need to perform.
Thank you, that would be much appreciated. I will look in Load.php later when I get chance as well.

Kindred

you have now increased the complexity by having to read the value into the context array...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

General Xbox Gaming

#38
Quote from: Kindred on September 29, 2014, 03:31:28 PM
you have now increased the complexity by having to read the value into the context array...
Oh YEAH, I got it working ;D you could have done it in less then 5 minutes and made $5.



Thank you all for your support. Now all I need to do is implament a way to auto generate the key :-\ I have the script but it need editing to work the way I want it to.

Advertisement: