Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 10-18-2006, 11:44 AM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried to add

Quote:
fetch_object('button').innerHTML = <a
href="predictions.php?do=remove&eventid=$eventinfo[eventid]">Remove</a>;
but of course that gives me a javascript error
Reply With Quote
  #12  
Old 10-18-2006, 12:43 PM
nico_swd's Avatar
nico_swd nico_swd is offline
 
Join Date: Dec 2005
Location: Spain
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Give this a try.

Code:
<script type="text/javascript">
function create_req_object()
{
	var req = false;
	
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		var msp = new Array('Microsoft', 'Msxml2');
		
		for (var i in msp)
		{
			try
			{
				req = eval('ne' + 'w Act' + 'iveXObj'+ 'ect(msp[i] + ".XMLH'+ 'TTP");');
			}
			catch(e)
			{
				continue;
			}
		}
	}
	
	return req;
}

function submit_form(form)
{
	var http = create_req_object();
	
	if (!http)
	{
		return true;
	}

	if (isNaN(form.Home.value) || isNaN(form.Away.value) || !form.Home.value || !form.Away.value)
	{
		alert("Invalid prediction. Please use numbers only.");
		return false;
	}

	http.open('POST', form.action);
	http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function()
	{
		if (http.readyState == 4 && http.status == 200)
		{
			var eventid = parseInt(http.responseText);
			
			if (!isNaN(eventid))
			{			
				toggle_predictions();
				fetch_object('predction_home1').innerHTML = form.Home.value;
				fetch_object('predction_away1').innerHTML = form.Away.value;
				
				fetch_object('remove').innerHTML = '<a href="predictions.php?do=remove&eventid='+ eventid +'" onclick="return remove_prediction('+ eventid +');">Remove</a>';
				
				alert("Predictions successfully submitted.");
			}
		}
	}
	http.send('do=addpredict&Home='+ form.Home.value +'&Away='+ form.Away.value +'&eventid='+ form.eventid.value +'&1Home='+ form.Home1.value +'&1Away='+ form.Away1.value);
	return false;
}


function remove_prediction(eventid)
{
	var http = create_req_object();
	
	if (!http)
	{
		return true;
	}
	
	http.open('GET', 'predictions.php?do=remove&eventid='+ eventid);
	http.onreadystatechange = function()
	{
		if (http.readyState == 4 && http.status == 200)
		{
			toggle_predictions();
			
			var form = document.predictions;
			form.Home.value = '';
			form.Away.value = '';
			
			alert("Sucessfully removed.");
		}
	}
	http.send(null);
	return false;
}


function toggle_predictions()
{
	var objects = new Array(
		'Home1',
		'Away1',
		'predction_home1',
		'predction_away1',
		'predict',
		'remove'
	);
	
	for (var i in objects)
	{
		var style = fetch_object(objects[i]).style;
		
		style.display = style.display == 'none' ? 'block' : 'none';
	}
}

</script>
<form action="predictions.php" method="post" onsubmit="return submit_form(this);" name="predictions">
<input type="hidden" name="do" value="addpredict">
<input type="hidden" name="eventid" value="32">
<table class="tborder" cellspacing="1" cellpadding="4" border="0">
<tr>
	<td class="tcat" colspan="5">Interactive game details</td>
</tr>
<tr>
	<td class="thead">Your predictions</td>
	<td class="thead">Actual</td>
	<td colspan="2" align="center" class="thead">Teams</td>
	<td class="thead">Colors</td>
</tr>

<tr>
	<td align="center">
		<div id="Home1">
			<input type="hidden" name="Home1" value="RDG">
			<input name="Home" type="text" size="1" value="">
		</div>
		<div id="predction_home1" style="display: none;"></div>
	</td>
	<td class="alt2" align="center"></td>
	<td nowrap><strong>Home</strong>:</td>
	<td>RDG</td>
	<td><img src="images/calendarteams/RDG.gif"></td>
</tr>

<tr>
	<td align="center">
		<div id="Away1">
			<input type="hidden" name="Away1" value="Victory">
			<input name="Away" type="text" size="1" value="" id="Away1">
		</div>		
		<div id="predction_away1" style="display: none;"></div>
	</td>
	<td class="alt2" align="center"></td>
	<td nowrap><strong>Away</strong>:</td>
	<td>Victory</td>
	<td><img src="images/calendarteams/Victory.gif"></td>
</tr>

<div class="smallfont">
	<strong>Venue</strong>: Gonaives - Parc Vincent
</div>


<div class="smallfont">
	<strong>Competition</strong>: Digicel Cloture
</div>


<div class="smallfont">
	<strong>Round</strong>: 9
</div>

<tr>
	<td align="center">
			<input type="image" src="/forums/images/kirsch/buttons/predict.gif" id="predict">
		<div id="remove" style="display: none;">
		</div>
	</td>
	<td class="alt2" style="border-top:0px solid #c0c0c0;" align="center" colspan="4">insert link to leaderboard here</td>
</tr>
</table>
</form>
You have to change this as well.
PHP Code:
if ($_REQUEST['do'] == 'addpredict')
{
 
// get input data
 
$vbulletin->input->clean_array_gpc('r', array('eventid' => TYPE_UINT'Home' => TYPE_UINT'Away' => TYPE_UINT'1Home' => TYPE_STR'1Away' => TYPE_STR));
 
 
$eventid =& $vbulletin->GPC['eventid'];
 
$home   =& $vbulletin->GPC['Home'];
 
$away   =& $vbulletin->GPC['Away'];
 
$hometeam   =& $vbulletin->GPC['1Home'];
 
$awayteam   =& $vbulletin->GPC['1Away'];
 
$player=$vbulletin->userinfo['userid'];
$db->query("INSERT into new_predictions(id,eventid,userid,homepred,awaypred,hometeam,awayteam) VALUES ('','$eventid','$player','$home','$away','$hometeam','$awayteam')");

echo 
$db->insert_id();

(echo'ing the insert_id() so we can use it for the remove link)

You should also do an error check in your PHP script. Javascript runs on the client side and can't be trusted.
Reply With Quote
  #13  
Old 10-18-2006, 11:05 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nico, once again thanks for the help. Everything but the ajax remove is fine, but I will live with that. I simply put a front end redirect in predictions.php that brings back to the previous page.

It's a pity I had to edit calendar.php as there was no hook at the desired location.

My predictions is heavily customized. I am going to try to simplify it and release it, giving you 100% credits for the ajax code (not a line was from me). I only had to add the eventid to the <div> <div id="$customtitle$eventinfo[eventid]"> to make it unique, because sometimes there are multiple games in the same day.
Reply With Quote
  #14  
Old 10-19-2006, 01:56 AM
Cap'n Steve's Avatar
Cap'n Steve Cap'n Steve is offline
 
Join Date: Feb 2004
Location: Kalamazoo, MI, USA
Posts: 745
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="showthread.php?t=93249" title="vBulletin.org Forum - Thread 93249">Here's a nice tutorial.</a>
Reply With Quote
  #15  
Old 10-19-2006, 12:14 PM
nico_swd's Avatar
nico_swd nico_swd is offline
 
Join Date: Dec 2005
Location: Spain
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

^^ Thank you for that. I'll have a look at it.

Lionel, I just downloaded your script. Thanks for the credit.

I saw you modified it a bit... don't use getElementById, cause it's not cross browser safe. Use vB's fetch_object() function instead.

Code:
fetch_object('button'+ form.eventid.value).innerHTML = '<a href="predictions.php?do=remove&eventid='+ form.eventid.value +'">Remove</a>';
Also, I'll have a look on how to make it compatible with vB's AJAX system and post an updated version later.


EDIT:

Give this a try.
Code:
function submit_form(form)
{
	if (isNaN(form.Home.value) || isNaN(form.Away.value) || !form.Home.value || !form.Away.value)
	{
		alert("Invalid prediction. Please use numbers only.");
		return false;
	}
	
	http = new vB_AJAX_Handler(true);
	
	if (!http)
	{
		return true;
	}

	http.onreadystatechange(handle_prediction);
	http.send('predictions.php', 'do=addpredict&Home='+ form.Home.value +'&Away='+ form.Away.value +'&eventid='+ form.eventid.value +'&1Home='+ form.Home1.value +'&1Away='+ form.Away1.value);
	return false;
}


function handle_prediction()
{
	if (http.handler.readyState == 4 && http.handler.status == 200)
	{
		var form = document.predictions;
		
		fetch_object('Home'+ form.eventid.value).innerHTML = form.Home.value;
		fetch_object('Away'+ form.eventid.value).innerHTML = form.Away.value;
		fetch_object('button'+ form.eventid.value).innerHTML = '<a href="predictions.php?do=remove&eventid='+ form.eventid.value +'">Remove</a>'
		
	}
}
You have to change the form name to "predictions", or change predictions to something else in the second function.
Reply With Quote
  #16  
Old 10-19-2006, 12:16 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

cool. Thanks Nico. Feel free to modify all you want.
Reply With Quote
  #17  
Old 10-19-2006, 12:28 PM
nico_swd's Avatar
nico_swd nico_swd is offline
 
Join Date: Dec 2005
Location: Spain
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I edited the post above. I didn't fully test it though.
Reply With Quote
Reply


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 11:38 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04096 seconds
  • Memory Usage 2,264KB
  • Queries Executed 14 (?)
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
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete