Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 01-09-2007, 12:45 AM
mistyPotato mistyPotato is offline
 
Join Date: Dec 2006
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Action based on condition

Can someone tell me how to exclude an action (or line(s)) in a vBulletin script page such as in index.php by allowing only a paricular user or administrator ?

For example......

<if $Username="Administrator">
This is the line I want to be conditionally executed
</if>

In the above example, I ONLY want the red line to be executed if the user is Administrator.
I need some way to exclude a line of the script UNLESS it's the administrator(s) or a particular members who IS the adminstrator.

What I don't know is what variables are stored in memory and how to use them in a conditional statement like this.

Thanks
Reply With Quote
  #2  
Old 01-09-2007, 12:52 AM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you using these in a PHP file or in a template?

If you're straight-up editing a PHP file, you might want to consider using vBulletin's Plugin System rather than directly modifying your Index.php file -- but, I'll show you anyway as it's the same concept in either option.

PHP Code:
if (is_member_of($vbulletin->userinfo,1,2,3)) {
// php code to execute if user is in usergroupid 1, 2, or 3

PHP Code:
if ($vbulletin->userinfo['username'] == 'JohnDoe') {
// php code to execute if the username is "JohnDoe"

Reply With Quote
  #3  
Old 01-09-2007, 02:08 AM
mistyPotato mistyPotato is offline
 
Join Date: Dec 2006
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For some reason it's not working?
I'm working inside vbulletin's admin panel.

Here's the actual code in the template....

<if ($vbulletin->userinfo['username']=='JohnDoe')>

<td class="vbmenu_control"><a href="memberlist.php$session[sessionurl_q]">$vbphrase[members_list]</a></td>

</if>


And here's what I get when I view the Source in a browser....

<if (Array['username']='JohnDoe')>

<td class="vbmenu_control"><a href="memberlist.php">Members List</a></td>

</if>


But for some reason, it still shows the code no matter what.
I'm baffled. If I comment out the code, it no longer shows (as expected).

any ideas?

Thanks
Reply With Quote
  #4  
Old 01-09-2007, 02:30 AM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In vB templates do like this:
Code:
<if condition="$bbuserinfo[username] == 'JohnDoe'">
	<td class="vbmenu_control"><a href="memberlist.php$session[sessionurl_q]">$vbphrase[members_list]</a></td>
</if>
In PHP files do as in post two.
Reply With Quote
  #5  
Old 01-09-2007, 03:17 AM
mistyPotato mistyPotato is offline
 
Join Date: Dec 2006
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank calorie !!!!
It worked !!!!!

HUG


Thanks also for your help acidburn.
For some reason I just could quite get it to work with the code you posted
Reply With Quote
  #6  
Old 01-09-2007, 08:01 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The code I posted was for use in either PHP Files or Plugins, sorry I wasn't more specific.
Reply With Quote
  #7  
Old 01-14-2007, 12:04 PM
Stifler Stifler is offline
 
Join Date: Jan 2005
Posts: 137
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by acidburn0520 View Post

PHP Code:
if (is_member_of($vbulletin->userinfo,1,2,3)) {
// php code to execute if user is in usergroupid 1, 2, or 3

would I be able to use that in a template field in vbulletin 3.5?
Reply With Quote
  #8  
Old 01-14-2007, 03:46 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're using it in a template:

Code:
<if condition="is_member_of($bbuserinfo,1,2,3)">
Code to execute if User is a Member of Usergroups 1, 2, or 3
</if>
Reply With Quote
  #9  
Old 01-28-2007, 06:07 AM
mrkhm mrkhm is offline
 
Join Date: Oct 2006
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

acidburn0520 you hit the nail right on the head!!!! thats what works!!!!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:00 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04805 seconds
  • Memory Usage 2,246KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete