Trouble Creating Small App

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
camhabib
Forum Commoner
Posts: 37
Joined: Tue Aug 16, 2005 8:36 pm
Location: Boston, MA

Trouble Creating Small App

Post by camhabib »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm trying to create an app to utilize an existing framework and pull data from a database.  I have tried contacting the site owner and they have been of no assistance with the technical aspects of my goal.  The site is a online forum (http://honestforum.com).  Users previously had the ability to see the names of the various people that rated their post (with either +/- 1).  Following scheduled site maintenance, the feature was lost and unable to be retrieved (webmaster unavailable).  I have been been trying to create a small online system where users can access the list based on the post id#.  The problem I'm having is trying to identify where the database is and how to accesses the information.  I have isolated the section of code for the rating system.  From this thread (first post, original poster): http://www.honestforum.com/hf-chat/146520-tribute.html the http code pertaining to the rating system is:


[syntax="html"]	<script type="text/javascript">
		<!--
		var g_rating_post_1457917 = false;
		function rate_post_1457917(vote)
		{
			if (g_rating_post_1457917)
				return;
			g_rating_post_1457917 = true;	
			nr_rate_post( rate_post_done_1457917, 1457917, 146520, vote, 9659 );
		}
		
		function rate_post_done_1457917()
		{
			g_rating_post_1457917 = false;
			nr_rate_post_done( 'nr_rating_p1457917', 'thumbs_up_1457917', 'thumbs_dn_1457917' );
		}
		//-->
		</script>
	

<div class="nr-right">
<a rel="nofollow" href="http://www.honestforum.com/showthread.php?do=ratepost&p=1457917&t=146520&v=1&tui=9659" class="nr-thumbs-up" onclick="rate_post_1457917(1); return false;"><img id="thumbs_up_1457917" src="http://www.honestforum.com/NuRatings/thumbs_up_d.gif" border="0" title="Thumbs Up!" /></a>  
<a rel="nofollow" href="http://www.honestforum.com/showthread.php?do=ratepost&t=146520&t=1457917&v=-1&tui=9659" class="nr-thumbs-down" onclick="rate_post_1457917(-1); return false;" ><img id="thumbs_dn_1457917" src="http://www.honestforum.com/NuRatings/thumbs_dn.gif" border="0" title="Thumbs Down!" /></a>
<span><a href="/hf-chat/146520-tribute.html#nr-who-rated" id="nr_rating_p1457917" title="29 votes" onclick="nr_who_rated('post', 1457917, 'nr-wrp1457917'); return false;" >-23</a></span>
</div>
<div id="nr-wrp1457917" class="nr-who-rated">&nbsp;</div>

I have been able to retrieve the javascript used for the rating system:

Code: Select all

 /************************************************************************\
 *
 * NuRatings 
 * 
 * Copyright ©2006 NuHit, LLC. All Rights Reserved.
 * This file may not be redistributed in whole or significant part.
 * http://www.nuhit.com | http://www.nuhit.com/license.html
 *
\************************************************************************/


function nr_threshold_changed( selector, targeturl )
{
	if (!selector)
		return;
	for (i=0;i<selector.length;i++)
    {
		if (selector.options[i] && selector.options[i].selected)
		{
			window.location = targeturl + selector.options[i].value;
			return;
		}
    }
}

function nr_rate_thread( callback, threadid, dir )
{
	vote_ajax_handler = new vB_AJAX_Handler(true);
	vote_ajax_handler.onreadystatechange( callback );
	vote_ajax_handler.send('forumdisplay.php?do=ratethread_ajax&t=' + threadid + '&v=' + dir);
}

function nr_rate_thread_done( rating_id, thumbs_up_id, thumbs_dn_id )
{
	if (vote_ajax_handler.handler.readyState == 4 && vote_ajax_handler.handler.status == 200)
	{
		response = nr_process_response( vote_ajax_handler.handler.responseText );
		if (!response || !response.action)
			return;
		if (response.action == 1)
		{	// update display
			link = fetch_object( rating_id );
			if (link)
			{
				link.innerHTML = response.ratingtext ? response.ratingtext : response.rating;
				link.title = response.votestext;
			}
			up = fetch_object( thumbs_up_id );
			if (up)
				up.src = response.rating >= 0 ? g_nr_thumbs_up_src : g_nr_thumbs_up_d_src;
			dn = fetch_object( thumbs_dn_id );
			if (dn)
				dn.src = response.rating <= 0 ? g_nr_thumbs_dn_src : g_nr_thumbs_dn_d_src;
		}
	}
}

function nr_rate_post( callback, postid, threadid, vote, theuserid )
{
	vote_ajax_handler = new vB_AJAX_Handler(true);
	vote_ajax_handler.onreadystatechange( callback );
	vote_ajax_handler.send('showthread.php?do=ratepost_ajax&p=' + postid + '&t=' + threadid + '&v=' + vote + '&tui=' + theuserid );
}

function nr_rate_post_done( rating_id, thumbs_up_id, thumbs_dn_id )
{
	if (vote_ajax_handler.handler.readyState == 4 && vote_ajax_handler.handler.status == 200)
	{
		response = nr_process_response( vote_ajax_handler.handler.responseText );
		if (!response || !response.action)
			return;
		if (response.action == 1)
		{	// update display
			link = fetch_object( rating_id );
			if (link)
			{
				link.innerHTML = response.ratingtext ? response.ratingtext : response.rating;
				link.title = response.votestext;
			}
			up = fetch_object( thumbs_up_id );
			if (up)
				up.src = response.rating >= 0 ? g_nr_thumbs_up_src : g_nr_thumbs_up_d_src;
			dn = fetch_object( thumbs_dn_id );
			if (dn)
				dn.src = response.rating <= 0 ? g_nr_thumbs_dn_src : g_nr_thumbs_dn_d_src;
		}
	}
}

function nr_rate_user( vote, clicked_on_id, option_count )
{
	// update checkboxes
	for (i=0; i<option_count; i++)
	{
		check_id = "nr-check-" + i;
		checkbox = fetch_object( check_id );
		if (checkbox)
			checkbox.checked = check_id == clicked_on_id;
	}

	theuserid = g_nr_userid;
	vote_ajax_handler = new vB_AJAX_Handler(true);
	vote_ajax_handler.onreadystatechange( nr_rate_user_done );
	vote_ajax_handler.send('member.php?do=rateuser_ajax&u=' + theuserid + '&v=' + vote);
}

function nr_rate_user_done( rating_id )
{
	if (vote_ajax_handler.handler.readyState == 4 && vote_ajax_handler.handler.status == 200)
	{
		response = nr_process_response( vote_ajax_handler.handler.responseText );
		if (!response || !response.action)
			return;
		if (response.action == 1)
		{	// update display

			rating_label = fetch_object( 'nr-user-rating' );
			if (rating_label)
				rating_label.innerHTML = response.ratingtext ? response.ratingtext : response.rating;
			votes_label = fetch_object( 'nr-user-votes' );
			if (votes_label)
				votes_label.innerHTML = response.votestext;
		}
	}
}

function nr_process_response( response_txt )
{
	// unencode commas
	response_txt = response_txt.replace( ',,', ',' );

	response = new Object();
	response.action = 0;
	response.fullresponse = response_txt;
	parts = response_txt.split(',');

	for (var i=0; i<parts.length; i++)
	{
		var p2 = parts[i].split('=');
		if (p2.length == 2)
			response[ p2[0].toString() ] = p2[1];
		else
		{
			var label = p2.shift();
			response[ label.toString() ] = p2.join('=');
		}
			
	}

	if (response.action == 2)
		window.alert( response.message );

	return response;
}

var g_nr_who_rated_ref = null;
function nr_who_rated( what, id, where )
{
	if (g_nr_who_rated_ref)
	{
		bClose = g_nr_who_rated_ref == where;
		nr_hide_who_voted();
		if (bClose)
			return;
	}
	g_nr_who_rated_ref = where;
	vote_ajax_handler = new vB_AJAX_Handler(true);
	vote_ajax_handler.onreadystatechange( nr_who_rated_done );
	vote_ajax_handler.send('/index.php?do=whorated_ajax&nr_w=' + what + '&nr_id=' + id);
}

function nr_who_rated_done()
{
	if (vote_ajax_handler.handler.readyState == 4 && vote_ajax_handler.handler.status == 200)
	{
		response = nr_process_response( vote_ajax_handler.handler.responseText );
		if (!response || !response.action)
			return;
		if (response.action == 3)	// html sent, show it.
		{	// update display
			obj = g_nr_who_rated_ref ? fetch_object(g_nr_who_rated_ref) : fetch_object('nr-who-rated');
			if (obj)
			{
				// change object's content
				obj.innerHTML = response.html;

				// show it
				obj.style.display = 'block';
			}
		}
	}
}

function nr_hide_who_voted()
{
	elem = g_nr_who_rated_ref ? fetch_object(g_nr_who_rated_ref) : null;
	if (elem)
		elem.style.display = 'none';
	g_nr_who_rated_ref = null;
}

function nr_toggle_post( post_id )
{
	var post_ctr_id = "post" + post_id;
	var post_ctr = fetch_object( post_ctr_id );
	
	if (!post_ctr)
		return;

	if (post_ctr.style.display == 'none')
		post_ctr.style.display = '';
	else
		post_ctr.style.display = 'none';
}
I am unable to access the root directory for a index of files, chance any existing files, or access any existing PHP scrips, which is the main difficulty I am facing. I would love to be able to output in a simple table form a list of names and what they rated each post. Any help at all would be greatly appreciated.


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The solution is likely in the nr_who_rated_* JavaScript functions. First, make sure that they are even being called when you expect them to be (i.e. upon clicking whatever button should display the users who voted). Secondly, make sure that AJAX is getting the correct response from the page it is calling on this line:

Code: Select all

vote_ajax_handler.send('/index.php?do=whorated_ajax&nr_w=' + what + '&nr_id=' + id);
Post Reply