Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 10-11-2015, 07:33 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help with conditional

I cannot seem to get the below conditional to work to save my life. I believe everything is correct, but I don't know what else to check.

Code:
<vb:if condition="$show['dso_slips_delete_own'] && $userinfo['userid'] == $bbuserinfo['userid']">
if I remove the userid part, it works as expected, but I want to make sure that the user viewing the page is the one who owns the data, so that only they ca edit it.

entire template:
Code:
<div id="view-dso_slips" class="<vb:if condition="$selected_tab == 'dso_slips'">selected_view_section<vb:else />view_section</vb:if><vb:if condition="$userinfo['userid'] != $bbuserinfo['userid']"> vm_other_prof</vb:if>">
<div class="blockbody">
	<table id="dso_slips_table" width="100%">
	<tr class="columnsort">
		<th class="blocksubhead">&nbsp;</th>
		<th class="blocksubhead">Date - Time</th>
		<th class="blocksubhead">Vehicle</th>
		<th class="blocksubhead">Track</th>
		<th class="blocksubhead">R/T</th>
		<th class="blocksubhead">60'</th>
		<th class="blocksubhead">330'</th>
		<th class="blocksubhead">1/8 Mile</th>
		<th class="blocksubhead">1000'</th>
		<th class="blocksubhead">1/4 Mile</th>
	</tr>
		<vb:each from="queue" value="queuelist"><tr>
			<td><a href="./slips.php?do=viewslip&id={vb:raw queuelist.id}" title="View Details"><i class="fa fa-search"></i></a><vb:if condition="$show['dso_slips_edit']">&nbsp;&nbsp;&nbsp;<a href="./slips.php?do=editslip&id={vb:raw queuelist.id}" title="Edit Slip"><i class="fa fa-pencil-square-o"></i></a></vb:if><vb:if condition="$show['dso_slips_delete_own'] && $userinfo['userid'] == $bbuserinfo['userid']">&nbsp;&nbsp;&nbsp;<a href="./slips.php?do=delslip&id={vb:raw queuelist.id}" title="Delete Slip"><i class="fa fa-eraser"></i></a></vb:if></td>
			<td>{vb:raw queuelist.date}</td>
			<td><a href="./vbrides.php?do=viewride&rideid={vb:raw queuelist.car_id}" title="View Vehicle Page">{vb:raw queuelist.car_name}</a></td>
			<td><a href="{vb:raw queuelist.track_www}" title="Visit the {vb:raw queuelist.track} Website">{vb:raw queuelist.track}</a></td>
			<td>{vb:raw queuelist.rt}</td>
			<td>{vb:raw queuelist.60ft}</td>
			<td>{vb:raw queuelist.330ft}</td>
			<td>{vb:raw queuelist.8et}</td>
			<td>{vb:raw queuelist.1000ft}</td>
			<td>{vb:raw queuelist.4et}</td>
		</tr></vb:each>
	</table>
</div>
</div>
plugin:
Code:
if ($show['dso_slips_view']) {
	if (isset($vbulletin->GPC['tab']))
	{
		$selected_tab = $vbulletin->GPC['tab'];
	}
	$blockinfo['title'] = "Timeslips";
	$blockid = "dso_slips";
	$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&amp;tab=dso_slips#dso_slips";

	$templater = vB_Template::create('memberinfo_tab');
	$templater->register('selected_tab', $selected_tab);
	$templater->register('relpath', $relpath);
	$templater->register('blockinfo', $blockinfo);
	$templater->register('blockid', $blockid);
	$templater->register('taburl', $taburl);
	$template_hook['profile_tabs_last'] .= $templater->render();  

	require_once('./includes/functions_dso_slips.php');
	$slipsqueue = $db->query_read("SELECT ID,Car_ID,Date,Track,RT,Sixty,ThreeThirty,Eighth_ET,Eighth_MPH,Thousand,Fourth_ET,Fourth_MPH FROM ".TABLE_PREFIX."dso_slips WHERE Owner = ".$userinfo['userid']." ORDER BY Date DESC");
		while ($row = $db->fetch_array($slipsqueue)) {
			if (isset($row['Eighth_ET']) AND isset($row['Eighth_MPH'])) { $row['Eighth_ET'] = number_format($row['Eighth_ET'],3,'.',',')." @ ".number_format($row['Eighth_MPH'],2,'.',',')." mph"; }
			if (isset($row['Fourth_ET']) AND isset($row['Fourth_MPH'])) { $row['Fourth_ET'] = number_format($row['Fourth_ET'],3,'.',',')." @ ".number_format($row['Fourth_MPH'],2,'.',',')." mph"; }
			$queue[] = array (
				'id'	=> $row['ID'],
				'car_id'	=> $row['Car_ID'],
				'car_name'	=> getVehicleName($row['Car_ID']),
				'date'		=> date("M d, Y - g:i a ",strtotime($row['Date'])),
				'track'		=> getTrackName($row['Track']),
				'track_www'	=> getTrackWeb($row['Track']),
				'rt'		=> number_format($row['RT'],3,'.',','),
				'60ft'		=> number_format($row['Sixty'],3,'.',','),
				'330ft'		=> number_format($row['ThreeThirty'],3,'.',','),
				'8et'		=> $row['Eighth_ET'],
				'1000ft'	=> number_format($row['Thousand'],3,'.',','),
				'4et'		=> $row['Fourth_ET']
				);
			}

	$templater = vB_Template::create('dso_slips_profile_tab');

	$templater->register('selected_tab', $selected_tab);
	$templater->register('queue', $queue);
	$template_hook['profile_tabs'] .= $templater->render();
}
Reply With Quote
  #2  
Old 10-11-2015, 09:16 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try replacing $userinfo['userid'] with $vbulletin->userinfo['userid'] and see what happens.
Reply With Quote
  #3  
Old 10-11-2015, 09:18 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

tried that to no affect

--------------- Added [DATE]1444605891[/DATE] at [TIME]1444605891[/TIME] ---------------

well not no affect, it actually makes the conditional always true. without the vbulletin-> the conditional is always false.
Reply With Quote
  #4  
Old 10-11-2015, 09:26 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Instead of adding the authorization check in the template, I would just move it to the script itself and redirect the user if they are not the owner. I always handle all my logic in scripts, not in the template/view.

That way it's also ten times easier to debug your code and variables.
Reply With Quote
Благодарность от:
Dragonsys
  #5  
Old 10-11-2015, 09:27 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If your plugin hook is "member_complete" then try using $prepared['userid'] instead of $bbuserinfo['userid'].

--------------- Added [DATE]1444606104[/DATE] at [TIME]1444606104[/TIME] ---------------

Quote:
Originally Posted by Dave View Post
Instead of adding the authorization check in the template, I would just move it to the script itself and redirect the user if they are not the owner. I always handle all my logic in scripts, not in the template/view.

That way it's also ten times easier to debug your code and variables.
Excellent advice...I do the same myself.
Reply With Quote
  #6  
Old 10-11-2015, 09:38 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried moving it to the php code, and I end up with the same result. It is either always true, or always false. I like ti better in the php, as you stated, so I will leave it this way, but still can't get it to work right.

I tried $prepared['userid'] and still the same.

--------------- Added [DATE]1444607425[/DATE] at [TIME]1444607425[/TIME] ---------------

here is the updated php code:
Code:
if ($show['dso_slips_view']) {
	if (isset($vbulletin->GPC['tab']))
	{
		$selected_tab = $vbulletin->GPC['tab'];
	}
	$blockinfo['title'] = "Timeslips";
	$blockid = "dso_slips";
	$taburl = $memberurl = fetch_seo_url('member', $prepared) . "&amp;tab=dso_slips#dso_slips";

	$templater = vB_Template::create('memberinfo_tab');
	$templater->register('selected_tab', $selected_tab);
	$templater->register('relpath', $relpath);
	$templater->register('blockinfo', $blockinfo);
	$templater->register('blockid', $blockid);
	$templater->register('taburl', $taburl);
	$template_hook['profile_tabs_last'] .= $templater->render();  

	require_once('./includes/functions_dso_slips.php');
	$slipsqueue = $db->query_read("SELECT ID,Car_ID,Date,Track,RT,Sixty,ThreeThirty,Eighth_ET,Eighth_MPH,Thousand,Fourth_ET,Fourth_MPH FROM ".TABLE_PREFIX."dso_slips WHERE Owner = ".$userinfo['userid']." ORDER BY Date DESC");
		while ($row = $db->fetch_array($slipsqueue)) {
			if (isset($row['Eighth_ET']) AND isset($row['Eighth_MPH'])) { $row['Eighth_ET'] = number_format($row['Eighth_ET'],3,'.',',')." @ ".number_format($row['Eighth_MPH'],2,'.',',')." mph"; }
			if (isset($row['Fourth_ET']) AND isset($row['Fourth_MPH'])) { $row['Fourth_ET'] = number_format($row['Fourth_ET'],3,'.',',')." @ ".number_format($row['Fourth_MPH'],2,'.',',')." mph"; }
			if ($show['dso_slips_edit_own'] && $userinfo['userid'] == $prepared['userid']) { $dso_slip_edit_own_link = 'true'; } else { $dso_slip_edit_own_link = 'false'; }
			if ($show['dso_slips_delete_own'] && $userinfo['userid'] == $prepared['userid']) { $dso_slip_delete_own_link = 'true'; } else { $dso_slip_delete_own_link = 'false'; }
			$queue[] = array (
				'id'	=> $row['ID'],
				'car_id'	=> $row['Car_ID'],
				'car_name'	=> getVehicleName($row['Car_ID']),
				'date'		=> date("M d, Y - g:i a ",strtotime($row['Date'])),
				'track'		=> getTrackName($row['Track']),
				'track_www'	=> getTrackWeb($row['Track']),
				'rt'		=> number_format($row['RT'],3,'.',','),
				'60ft'		=> number_format($row['Sixty'],3,'.',','),
				'330ft'		=> number_format($row['ThreeThirty'],3,'.',','),
				'8et'		=> $row['Eighth_ET'],
				'1000ft'	=> number_format($row['Thousand'],3,'.',','),
				'4et'		=> $row['Fourth_ET']
				);
		}
	
	$templater = vB_Template::create('dso_slips_profile_tab');
	$templater->register('dso_slip_edit_own_link', $dso_slip_edit_own_link);
	$templater->register('dso_slip_delete_own_link', $dso_slip_delete_own_link);
	$templater->register('selected_tab', $selected_tab);
	$templater->register('queue', $queue);
	$template_hook['profile_tabs'] .= $templater->render();
}
this always equals true:
Code:
if ($show['dso_slips_delete_own'] && $userinfo['userid'] == $prepared['userid']) { $dso_slip_delete_own_link = 'true'; } else { $dso_slip_delete_own_link = 'false'; }
even when I view another user's profile (in which case I need it to be false).
If I change it to bbuserinfo (instead of prepared) then it is always false (but should be true when viewing my profile)




EDIT: Finally got it, thank you for the help. When I added vbulletin-> to userinfo and used prepared instead of bbuserinfo it works.
Reply With Quote
  #7  
Old 10-11-2015, 11:41 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I should have been more clear. I meant for you to try:

$vbulletin->userinfo['userid'] == $prepared['userid']
Reply With Quote
Благодарность от:
Dragonsys
  #8  
Old 10-12-2015, 01:05 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
Sorry, I should have been more clear. I meant for you to try:

$vbulletin->userinfo['userid'] == $prepared['userid']
I did in the template, and it didn't work for me, but in the php it did. Though I probably had something else wrong in there, I'm sure.

Thanks again
Reply With Quote
Благодарность от:
MarkFL
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 02:04 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.04371 seconds
  • Memory Usage 2,255KB
  • 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
  • (5)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (3)post_thanks_box_bit
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete