Support Forums

How to get currently logged in user data at vewlisting.tpl?

This is a discussion on How to get currently logged in user data at vewlisting.tpl? within the Technical Support forums, part of the Technical Support Forums category; I want to get currently logged in user data at vewlisting.tpl Any help is appreciated. Thanks you. Peri...


Go Back   68 Classifieds Forums > Technical Support Forums > Technical Support

Reply
 
Thread Tools Display Modes
Old 12-28-2011, 03:58 AM   #1
Customer
 
Join Date: Dec 2009
Posts: 74
Rep Power: 11
user2616 has a spectacular aura about
Default How to get currently logged in user data at vewlisting.tpl?

I want to get currently logged in user data at vewlisting.tpl

Any help is appreciated.

Thanks you.
Peri
__________________
v4.1.9 Developer - Default Template (custom)
user2616 is offline   Reply With Quote
Old 12-28-2011, 06:53 AM   #2
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,538
Rep Power: 89
seymourjames is a jewel in the rough
Default

It depends upon what data?

You can use the debug functionality in smarty to see what variables are available to that template file. If you wish to restrict that information to members only (i.e. those which are logged in), you would display them in a simple test. Something like


{if $smarty.session.username<>'' || $smarty.cookies.username<>""}

The variables you wish to display

{/if}

If the variables do not exist you will need to engage in core file changes.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C
seymourjames is offline   Reply With Quote
Old 12-28-2011, 09:17 AM   #3
Customer
 
Join Date: Dec 2009
Posts: 74
Rep Power: 11
user2616 has a spectacular aura about
Default

Thanks David for your quick reply.

I want the address of logged in user.

I enabled {debug}

Found the following variables relevant to address:
{$address} - Listing user address that I do not want.
{$b_address} - Billing address of the listing user that I do not want.
{$session} - Long string
{$cookie} - Long string

I cannot find any variable related to logged in user.

Can you please give me some idea on how to access logged in user data.
__________________
v4.1.9 Developer - Default Template (custom)

Last edited by user2616; 12-28-2011 at 09:19 AM.
user2616 is offline   Reply With Quote
Old 12-28-2011, 11:20 AM   #4
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,538
Rep Power: 89
seymourjames is a jewel in the rough
Default

So let me understand. If I am logged in as Seymour-James you want my physical address to appear on my adverts or on all adverts?

Are you actually trying to prefill a contact form by any chance?
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C

Last edited by seymourjames; 12-28-2011 at 11:25 AM.
seymourjames is offline   Reply With Quote
Old 12-28-2011, 11:46 AM   #5
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,538
Rep Power: 89
seymourjames is a jewel in the rough
Default

If you want the address of the person logged in then you will need to make a core file change to viewlisting.php or make a plugin which you can call from within viewlisting.tpl. The code you will need is basically in useraccountmodify.php .


I will look at what needs to be done
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C

Last edited by seymourjames; 12-28-2011 at 12:05 PM.
seymourjames is offline   Reply With Quote
Old 12-28-2011, 12:13 PM   #6
Customer
 
Join Date: Dec 2009
Posts: 74
Rep Power: 11
user2616 has a spectacular aura about
Default

Basically, my requirement is very simple.

Firstly, I answer your questions.

Q: If I am logged in as Seymour-James you want my physical address to appear on my adverts or on all adverts?
A: No.

Q: Are you actually trying to prefill a contact form by any chance?
A: No.

Now, I tell you what I refer as address of logged in user.
Login > My Account > Modify User Account
User Registration (useraccountmodify.tpl) page appear.
Fields such as First Name, Last Name, Email Address, Address are displayed.
I am referring to the field Address above.

Let us say you (Seymour-James) logged in.
Click My Account
Click Modify User Account
User Registration (useraccountmodify.tpl) page appar.
Key in "some text" in Address field.
Click Submit.

You select a listing and and go to View Listing (viewlisting.tpl) page.
Let us say this listing is added by the user Peter.
At this point of time, I want to access the Address (value = "some text") of logged in user Seymour-James.
Not the Address of the listing user Peter.

My question: How to get the value of the field Address of logged in user in viewlisting.tpl?

Thanks.
Peri
__________________
v4.1.9 Developer - Default Template (custom)
user2616 is offline   Reply With Quote
Old 12-28-2011, 12:26 PM   #7
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,538
Rep Power: 89
seymourjames is a jewel in the rough
Default

Yes I understood. It is not so simple. I am looking at it now.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C
seymourjames is offline   Reply With Quote
Old 12-28-2011, 01:35 PM   #8
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,538
Rep Power: 89
seymourjames is a jewel in the rough
Default

Try this in viewlisting.php at line 21 - just after the closing brace and before $class_tpl->assign...


if (!empty($_SESSION['uid']))
{
$sql = "SELECT firstname, lastname, username, address, lastname, address, city, state, zip, country FROM ".PREFIX."users WHERE id=".(int)$_SESSION['uid'];
$result = $db->query($sql);
if ($result->size() > 0)
{
$user_data = $result->fetch();
$class_tpl->assign('logged_user', $user_data);
$class_tpl->assign('useraddress', $user_data[address]);
// add in more queires to pass if you wish
}
}


Then in your viewlisting.tpl file

{if $smarty.session.username<>'' || $smarty.cookies.username<>""}

{$useraddress}
// add in more if you wish

{/if}
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C
seymourjames is offline   Reply With Quote
Old 12-28-2011, 04:15 PM   #9
Customer
 
Join Date: Dec 2009
Posts: 74
Rep Power: 11
user2616 has a spectacular aura about
Default

Thank you for leading me to the solution that I already was using in showlisting2.tpl, but I never realized until you drag me to the point with your nice sample code and idea that opens my eyes and mind to understand how to solve my problem.

showlisting2.tpl is calling a plugin to get listing user's name and phone.
I just changed the plugin to add address field.

Inserted the following code in viewlisting.tpl

{if $smarty.session.uid > 0}
{get_user_field userid=$smarty.session.uid}
{elseif $smarty.cookies.uid > 0}
{get_user_field userid=$smarty.cookies.uid}
{else}
{$u_address = ''}
{/if}
{$u_address}

It simply works. It is really fantastic.

Seymour-James, I really want to thank you for your time and effort to understand my problem and provide a solution.

Now, my problem solved.

But, I have couple of small questions to you:

1. I am not defining the variable $u_address in viewlisting.tpl, but smarty is not giving error at {else} {$u_address = ''} {/if}. Why?

2. You mentioned '' (2 single quotes) and "" (2 double quotes) in {if $smarty.session.username<>'' || $smarty.cookies.username<>""}. How to know when to use '' (2 single quotes) and "" (2 double quotes)?

Thanks.
Peri
__________________
v4.1.9 Developer - Default Template (custom)
user2616 is offline   Reply With Quote
Old 12-28-2011, 05:54 PM   #10
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,538
Rep Power: 89
seymourjames is a jewel in the rough
Default

You can't generally test the output value of the plugin in the template file (do the test inside of the plugin). Same issue with the get extra fields plugin (see various other forum posts about that). I would just use the code that has been given. It works.

No real issues or rule if you use double or single quotes. Just how it was coded in the original default template.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C
seymourjames is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Products data first after personal data... lowis Site Marketing 5 02-03-2010 02:35 PM
getting the State for logged-in user business Templates, HTML, CSS, and Design Help 1 12-27-2009 05:10 PM
user info for logged in user business Technical Support 2 10-27-2009 02:45 PM
Accordion menu item if user logged in skekum TemplateCodes 2 08-20-2009 09:41 AM


All times are GMT -4. The time now is 12:47 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0