Jump to content
  • 0

Feefty vote for points addon (FLUX)


Profile

Question


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  77
  • Reputation:   1
  • Joined:  04/15/17
  • Last Seen:  

Hi all, I have installed the Flux addon by Feetly (Vote for points) and everything is working fine... Until I vote.

https://github.com/Feefty/FluxCP_Addons-VoteForPoints

The votes are not being updated on the SQL tables when I try to vote, it gives me this error:

"Unable to vote for the server. Err no. 3"

Went to index.php on modules and tried to figure out the error, but could't.
All my SQL tables are there, it's just the "votepoints" that are not being updated when voting.

This is the code on index.php (Which I think handles the SQL part for adding points).

<?php if (!defined('FLUX_ROOT')) exit;

$this->loginRequired();

require_once("function.php");
$vfp_sites		= Flux::config('FluxTables.vfp_sites');
$vfp_logs		= Flux::config('FluxTables.vfp_logs');
$cp_tbl			= Flux::config('FluxTables.cashpoints');
$errorMessage	= NULL;

if (isset($_POST['id']))
{
	$id 		= (int) $params->get('id');
	$ip 		= $_SERVER['REMOTE_ADDR'];
	$account_id = (int) $session->account->account_id;

	$sql = "SELECT * FROM $server->loginDatabase.$vfp_sites WHERE id = ?";
	$sth = $server->connection->getStatement($sql);
	$sth->execute(array($id));
	$res = $sth->fetch();

	// voting site doesn't exists
	if ( ! $sth->rowCount())
	{
		$errorMessage = Flux::message("VoteDontExists");
	} else

	// voter is using invalid ip
	if (Flux::config('EnableIPVoteCheck') && !empty($_SERVER["HTTP_X_FORWARDED_FOR"]) || 
		Flux::config('EnableIPVoteCheck') && !empty($_SERVER['HTTP_CLIENT_IP']) || 
		Flux::config('EnableIPVoteCheck') && !empty($_SERVER['HTTP_X_FORWARDED']))
	{
		$errorMessage = sprintf(Flux::message("UnableToVote"), 1);
	} else {
		// validate for ip address
		if (Flux::config('EnableIPVoteCheck'))
		{
			$sql = "SELECT timestamp_expire FROM $server->loginDatabase.$vfp_logs WHERE ipaddress = ? AND sites_id = ? AND UNIX_TIMESTAMP(timestamp_expire) > ? LIMIT 1";
			$sth = $server->connection->getStatement($sql);
			$bind = array($ip, $id, time());
			$sth->execute($bind);

			if ($sth->rowCount())
				$errorMessage = Flux::message("AlreadyVoted");
		}

		// validate for account_id
		if (is_null($errorMessage))
		{
			$sql = "SELECT timestamp_expire FROM $server->loginDatabase.$vfp_logs WHERE account_id = ? AND sites_id = ? AND UNIX_TIMESTAMP(timestamp_expire) > ? LIMIT 1";
			$sth = $server->connection->getStatement($sql);
			$bind = array($account_id, $id, time());
			$sth->execute($bind);

			if ($sth->rowCount()) 
			{
				$errorMessage = Flux::message("AlreadyVoted");
			} else {
				// update the existing row
				$sql = "UPDATE $server->loginDatabase.$vfp_logs SET timestamp_expire = ?, timestamp_voted = ?, ipaddress = ? WHERE account_id = ? AND sites_id = ?";
				$sth = $server->connection->getStatement($sql);
				$bind = array(
					date(Flux::config("DateTimeFormat"), strtotime("+".$res->voteinterval." hours")),
					date(Flux::config("DateTimeFormat")),
					$ip,
					$account_id,
					$id
				);
				$sth->execute($bind);

				if ( ! $sth->rowCount())
				{
					// insert new row
					$sql = "INSERT INTO $server->loginDatabase.$vfp_logs VALUES (NULL, ?, ?, ?, ?, ?)";
					$sth = $server->connection->getStatement($sql);
					$bind = array(
						$id,
						date(Flux::config("DateTimeFormat"), strtotime("+".$res->voteinterval." hours")),
						date(Flux::config("DateTimeFormat")),
						$ip,
						$account_id
					);
					$sth->execute($bind);

					if ( ! $sth->rowCount())
					{
						$errorMessage = sprintf(Flux::message("UnableToVote"), 2);
					} else {

						switch (Flux::config('PointsType'))
						{
							case "vote":
								// update votepoints
								$sql = "UPDATE $server->loginDatabase.cp_createlog SET votepoints = votepoints + ? WHERE account_id = ?";
								$sth = $server->connection->getStatement($sql);
								$sth->execute(array((int) $res->votepoints, $account_id));

								if ( ! $sth->rowCount())
									$errorMessage = sprintf(Flux::message("UnableToVote"), 3);
							break;

							case "cash":
								// insert or update cashpoints
								$cashpoints_var = "#CASHPOINTS";
								$sql = "UPDATE $cp_tbl SET value = value + ? WHERE key = ? AND account_id = ?";
								$sth = $server->connection->getStatement($sql);
								$sth->execute(array((int) $res->votepoints, $cashpoints_var, $account_id));

								// account doesn't have a record for cashpoints
								// so we will add a row
								if ( ! $sth->rowCount())
								{
									$sql = "INSERT INTO $cp_tbl (`account_id`, `key`, `index`, `value`) VALUES (?, ?, 0, ?)";
									$sth = $server->connection->getStatement($sql);
									$bind = array($account_id, $cashpoints_var, $res->votepoints);
									$sth->execute($bind);

									if ( ! $sth->rowCount())
										$errorMessage = sprintf(Flux::message("UnableToVote"), 4);
								}
							break;

							default:
								// update credits row
								$sql = "UPDATE $server->loginDatabase.cp_credits SET balance = balance + ? WHERE account_id = ?";
								$sth = $server->connection->getStatement($sql);
								$sth->execute(array((int) $res->votepoints, $account_id));

								if ( ! $sth->rowCount())
								{
									// insert new credits row
									$sql = "INSERT INTO $server->loginDatabase.cp_credits VALUES (?, ?, NULL, NULL)";
									$sth = $server->connection->getStatement($sql);
									$sth->execute(array($account, $res->votepoints));

									if ( ! $sth->rowCount())
										$errorMessage = sprintf(Flux::message("UnableToVote"), 6);
								}
							break;
						}
					}
				}
			}
		}
	}
}

// fetch all voting sites
$sql = "SELECT * FROM $server->loginDatabase.$vfp_sites";
$sth = $server->connection->getStatement($sql);
$sth->execute();
$votesites_res = $sth->fetchAll();

?>

Could anyone give me some assistance?

THANK YOU!

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  77
  • Reputation:   1
  • Joined:  04/15/17
  • Last Seen:  

Isnt it possible to add something to the code, so that if the rows are empty it will create them?

Wouldn't that work?

UPDATE: I changed the code the to following and is now working fine!

case "vote":
// update votepoints
$sql = "UPDATE $server->loginDatabase.cp_v4p_voters SET votepoints = votepoints + ? WHERE account_id = ?";
$sth = $server->connection->getStatement($sql);
$sth->execute(array((int) $res->votepoints, $accoun
	if ( ! $sth->rowCount())
{
	$sql = "INSERT INTO $server->loginDatabase.cp_v4p_voters VALUES (?, ?)";
	$sth = $server->connection->getStatement($sql);
	$bind = array($account_id, $res->votepoints);
	$sth->execute(
	if ( ! $sth->rowCount())
		$errorMessage = sprintf(Flux::message("UnableToVote"), 3);

Also, created a new table called cp_v4p_voters

Edited by Profile
update
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  283
  • Reputation:   76
  • Joined:  06/13/13
  • Last Seen:  

the error message tell you it failed to execute sql query, which is updating table cp_createlog

it seem there is no existing record found so it failed the task

case "vote":
	// update votepoints
	$sql = "UPDATE $server->loginDatabase.cp_createlog SET votepoints = votepoints + ? WHERE account_id = ?";
	$sth = $server->connection->getStatement($sql);
	$sth->execute(array((int) $res->votepoints, $account_id));

	if ( ! $sth->rowCount())
		$errorMessage = sprintf(Flux::message("UnableToVote"), 3);
	break;

you may want to try the query insert if not exist else update, but imho it will be best to create separate table since i check the table cp_createlog purpose is to log creating account proccess... CMIW

Edited by Litro Endemic
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  77
  • Reputation:   1
  • Joined:  04/15/17
  • Last Seen:  

I see, if in this case I created a new table called "votepoints", how would I change the code in the index.php?

I'm not very familiar with web side.

Could you give an example? thanks

Link to comment
Share on other sites

×
×
  • Create New...