News:

Wondering if this will always be free?  See why free is better.

Main Menu

defining value in context

Started by brion, September 21, 2009, 02:15:04 PM

Previous topic - Next topic

brion

I added two fields in the smf_members table of the database, I want to display them in the value field of a text box.

I tried doing

Quote', $context['mdetect'] ,'

But that didn't do anything, I am guessing I need to find where $context is defined at and add the two fields to it? But I don't know which file that is in. It might be easier to just use a query, and I tried and couldn't get that to work either.

Theme: Classic(Custom)
Version: 1.1.9

Please help  :'(

sAce

where are you trying to display the result ??

Tyrsson

Check

Sources/Load.php

*I think that is where its at in 2.0... Not sure about 1.1.x

You should upgrade to the 1.1.10 as soon as possible.
PM at your own risk, some I answer, if they are interesting, some I ignore.

brion

I see this code? would this be the correct one?

Quote// Set up the contextual user array.
   $context['user'] = array(
      'id' => &$ID_MEMBER,
      'is_logged' => !$user_info['is_guest'],
      'is_guest' => &$user_info['is_guest'],
      'is_admin' => &$user_info['is_admin'],
      'is_mod' => false,
      'username' => &$user_info['username'],
      'language' => &$user_info['language'],
      'email' => &$user_info['email']
   );

If so would this work?

Quote// Set up the contextual user array.
   $context['user'] = array(
      'id' => &$ID_MEMBER,
      'is_logged' => !$user_info['is_guest'],
      'is_guest' => &$user_info['is_guest'],
      'is_admin' => &$user_info['is_admin'],
      'is_mod' => false,
      'username' => &$user_info['username'],
      'language' => &$user_info['language'],
      'email' => &$user_info['email'],
                'mdetect; => &$user_info['mdetect']
   );

So then in the script could I use ', $context['mdetect'] ,'?

brion

Hi, never finished receiving help, thanks.

Arantor

You have to add them into loadMemberData first as that's where $user_info gets them from.

Moving to SMF Coding Discussion as that's the best place to discuss this.
Holder of controversial views, all of which my own.


brion

Here is the changes I made to add mdetect and odetect, and still doesn't work.

Load.php

Quoteif ($set == 'normal')
   {
      $select_columns = "
         IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
         mem.signature, mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName,
         mem.realName, mem.emailAddress, mem.hideEmail, mem.dateRegistered, mem.websiteTitle, mem.websiteUrl,
         mem.birthdate, mem.memberIP, mem.memberIP2, mem.ICQ, mem.AIM, mem.YIM, mem.MSN, mem.mdetect, mem.odetect, mem.posts, mem.lastLogin,
         mem.karmaGood, mem.ID_POST_GROUP, mem.karmaBad, mem.lngfile, mem.ID_GROUP, mem.timeOffset, mem.showOnline,
         mem.buddy_list, mg.onlineColor AS member_group_color, IFNULL(mg.groupName, '') AS member_group,
         pg.onlineColor AS post_group_color, IFNULL(pg.groupName, '') AS post_group, mem.is_activated,
         IF(mem.ID_GROUP = 0 OR mg.stars = '', pg.stars, mg.stars) AS stars" . (!empty($modSettings['titlesEnable']) ? ',
         mem.usertitle' : '');
      $select_tables = "
         LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
         LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
         LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
         LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP)";
   }

Quoteelseif ($set == 'profile')
   {
      $select_columns = "
         IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
         mem.signature, mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName,
         mem.realName, mem.emailAddress, mem.hideEmail, mem.dateRegistered, mem.websiteTitle, mem.websiteUrl,
         mem.birthdate, mem.ICQ, mem.AIM, mem.YIM, mem.MSN, mem.mdetect, mem.odetect, mem.posts, mem.lastLogin, mem.karmaGood,
         mem.karmaBad, mem.memberIP, mem.memberIP2, mem.lngfile, mem.ID_GROUP, mem.ID_THEME, mem.buddy_list, mem.pm_ignore_list,
         mem.pm_email_notify, mem.timeOffset" . (!empty($modSettings['titlesEnable']) ? ', mem.usertitle' : '') . ",
         mem.timeFormat, mem.secretQuestion, mem.is_activated, mem.additionalGroups, mem.smileySet, mem.showOnline,
         mem.totalTimeLoggedIn, mem.ID_POST_GROUP, mem.notifyAnnouncements, mem.notifyOnce, mem.notifySendBody,
         mem.notifyTypes, lo.url, mg.onlineColor AS member_group_color, IFNULL(mg.groupName, '') AS member_group,
         pg.onlineColor AS post_group_color, IFNULL(pg.groupName, '') AS post_group,
         IF(mem.ID_GROUP = 0 OR mg.stars = '', pg.stars, mg.stars) AS stars, mem.passwordSalt";
      $select_tables = "
         LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
         LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
         LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
         LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP)";
   }

Quote// Set up the contextual user array.
   $context['user'] = array(
      'id' => &$ID_MEMBER,
      'is_logged' => !$user_info['is_guest'],
      'is_guest' => &$user_info['is_guest'],
      'is_admin' => &$user_info['is_admin'],
      'is_mod' => false,
      'username' => &$user_info['username'],
      'language' => &$user_info['language'],
      'email' => &$user_info['email'],
      'mdetect' => &$user_info['mdetect'],
      'odetect' => &$user_info['odetect']
   );

Profile.template.php

Quoteecho '
                                                           <tr>
                        <td width="40%"><b>Main Detector: </b></td>
                        <td><input type="text" name="mdetect" maxlength="35" size="24" value="',$context['mdetect'],'" /></td>
                     </tr>
                     <tr>
                        <td width="40%"><b>Other Detectors: </b></td>
                        <td><input type="text" name="odetect" maxlength="35" size="24" value="',$context['odetect'],'" /></td>
                     </tr>
                                                        <tr>
                        <td colspan="2"><hr width="100%" size="1" class="hrcolor" /></td>
                     </tr>';


Arantor

You also need to add a matching entry in loadMemberContext.
Holder of controversial views, all of which my own.


brion

Still doesn't work, here is what I have.

Quoteecho '
                                                           <tr>
                        <td width="40%"><b>Main Detector: </b></td>
                        <td><input type="text" name="mdetect" maxlength="35" size="24" value="',$context['member']['mdetect'],'" /></td>
                     </tr>
                     <tr>
                        <td width="40%"><b>Other Detectors: </b></td>
                        <td><input type="text" name="odetect" maxlength="35" size="24" value="',$context['member']['odetect'],'" /></td>
                     </tr>
                                                        <tr>
                        <td colspan="2"><hr width="100%" size="1" class="hrcolor" /></td>
                     </tr>';

Quote// What a monstrous array...
   $memberContext[$user] = array(
      'username' => &$profile['memberName'],
      'name' => &$profile['realName'],
      'id' => &$profile['ID_MEMBER'],
      'is_guest' => $profile['ID_MEMBER'] == 0,
      'is_buddy' => $profile['buddy'],
      'is_reverse_buddy' => in_array($ID_MEMBER, $buddy_list),
      'buddies' => $buddy_list,
      'title' => !empty($modSettings['titlesEnable']) ? $profile['usertitle'] : '',
      'href' => $scripturl . '?action=profile;u=' . $profile['ID_MEMBER'],
      'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $profile['realName'] . '">' . $profile['realName'] . '</a>',
      'email' => &$profile['emailAddress'],
      'hide_email' => $profile['emailAddress'] == '' || (!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']) || (!empty($profile['hideEmail']) && !empty($modSettings['allow_hideEmail']) && !allowedTo('moderate_forum') && $ID_MEMBER != $profile['ID_MEMBER']),
      'email_public' => (empty($profile['hideEmail']) || empty($modSettings['allow_hideEmail'])) && (empty($modSettings['guest_hideContacts']) || !$user_info['is_guest']),
      'registered' => empty($profile['dateRegistered']) ? $txt[470] : timeformat($profile['dateRegistered']),
      'registered_timestamp' => empty($profile['dateRegistered']) ? 0 : forum_time(true, $profile['dateRegistered']),
      'blurb' => &$profile['personalText'],
      'gender' => array(
         'name' => $gendertxt,
         'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : 'Female') . '.gif" alt="' . $gendertxt . '" border="0" />' : ''
      ),
      'website' => array(
         'title' => &$profile['websiteTitle'],
         'url' => &$profile['websiteUrl'],
      ),
      'birth_date' => empty($profile['birthdate']) || $profile['birthdate'] === '0001-01-01' ? '0000-00-00' : (substr($profile['birthdate'], 0, 4) === '0004' ? '0000' . substr($profile['birthdate'], 4) : $profile['birthdate']),
      'signature' => &$profile['signature'],
      'location' => &$profile['location'],
      'mdetect' => &$profile['mdetect'],
      'odetect' => &$profile['odetect'],

Arantor

And what exactly do you get in terms of errors, and where are you in the forum when you do get them?

Oh, and please use [code] instead of [quote], it's a whole lot easier to read.
Holder of controversial views, all of which my own.


brion

No errors are produced. Below is the screen shots when editing a profile where nothing is happening. In the textbox it should say None (the database default) until changed, and the same on the actual profile.

Arantor

So is that value actually being read from the database?

I should note that you could have saved yourself a ton of effort with the Custom Profile Fields mod (for 1.1) or the Advanced Profile Fields core feature (in 2.0.)
Holder of controversial views, all of which my own.


brion

I am worried about installing mods, I read about how they can screw your entire forum up, because some mods don't work with other ones. So I'd rather hard code this myself.

Well I don't know if it is reading from the database because I don't know which variable to use? Would it be this?

$context['member']['mdetect']

Arantor

If it wasn't reading it from the database correctly you'd have errors in your loadMemberContext function being added to the error log.

Looks like it would be that value since you're getting it from the DB correctly as far as I can see.
Holder of controversial views, all of which my own.


Tyrsson

Uhm, just a thought....

Have you tried adding this in the profile.php file and then passed it into the template file?

Not sure the exact area but I added something to the profile template awhile back in a private mod and it seems I had to add something like: (in your case it would be something like)


$context['member']['mdetect'] = $user_profile[$memID]['mdetect'];

If I am not mistaken (which is very possible) the context is going to be defined within the Source file and then loaded in the template. If the var is not defined in the source it most likely will not be available in the template.

It looks like it should be in the $user_info, but your using $context.
PM at your own risk, some I answer, if they are interesting, some I ignore.

brion

Quote from: Tyrsson on September 24, 2009, 06:58:33 AM
Uhm, just a thought....

Have you tried adding this in the profile.php file and then passed it into the template file?

Not sure the exact area but I added something to the profile template awhile back in a private mod and it seems I had to add something like: (in your case it would be something like)


$context['member']['mdetect'] = $user_profile[$memID]['mdetect'];

If I am not mistaken (which is very possible) the context is going to be defined within the Source file and then loaded in the template. If the var is not defined in the source it most likely will not be available in the template.

It looks like it should be in the $user_info, but your using $context.

I haven't tried it that way. I am a SMF noob but not a noob to PHP. Can you help me step by step? I won't ask any more questions for a long while when this is fixed.

brion

Alright one part is fixed it's now reading from the database when viewing the profile. It is being read by this.

".$context['member']['mdetect']."

However it won't read the database in the text box or update it, never will change when submitted.

Tyrsson

Well, unless you have coded it but not posted it here... I have not heard mention of where you are actually updating that column in the members table...

My best suggestion will be to look over the Source/Profile.php files and see how the information is update from the profile.

You will have to update the information with a query in the profile source file or something similar.
PM at your own risk, some I answer, if they are interesting, some I ignore.

brion

The updating part should be in Profile.template.php right? That is where the profile specs are at. This is my code in the text boxes, but it won't work.

echo "
                                                           <tr>
<td width='40%'><b>Main Detector: </b></td>
<td><input type='text' name='mdetect' maxlength='35' size='24' value=\"".$context['member']['mdetect']."\" /></td>
</tr>
<tr>
<td width='40%'><b>Other Detectors: </b></td>
<td><input type='text' name='odetect' maxlength='35' size='24' value=\"".$context['member']['odetect']."\" /></td>
</tr>
                                                        <tr>
<td colspan='2'><hr width='100%' size='1' class='hrcolor' /></td>
</tr>";

Arantor

No, the templates ONLY cover how it appears on the page.

Profile.php is where the updating action is. Look out for the UPDATE query.
Holder of controversial views, all of which my own.


Advertisement: