<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2017 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: ajax2.php
| Author: Virel (virel.eu)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../../../maincore.php";
require_once INFUSIONS."virel_servers_status/includes/functions.php";

$timek = $vsettings['v_sett_vote_time'];

$conf = array (
	'dvote' => "50"
); 

	$act     = intval($_REQUEST['type']);
	$id      = intval($_REQUEST['id']);
	
	$my       = dbquery('SELECT * FROM '.DB_VIREL_S_STATUS.' where v_status_id=\''.$id.'\'');
	$row_my   = dbarray($my);
	if($row_my == 0)
	{
		echo "ACCESS DENIED!!111";
		exit();
	}
	
	$row_vip = dbarray(dbquery('SELECT * FROM '.DB_VIREL_S_STATUS.' where v_status_id=\''.$id.'\''));
	$query   = dbquery('SELECT * FROM '.DB_VIREL_S_STATUS_VOTE.' where v_vote_idserv=\''.$id.'\' and v_vote_ip=\''.$_SERVER['REMOTE_ADDR'].'\'');
	while ($row_vt = dbarray($query))
	{
		$date = $row_vt['v_vote_date'];
	}
	$row_nm  = dbrows(dbquery('SELECT * FROM '.DB_VIREL_S_STATUS_VOTE.' where v_vote_idserv=\''.$id.'\' and v_vote_ip=\''.$_SERVER['REMOTE_ADDR'].'\''));
	$row_ab  = dbrows(dbquery('SELECT * FROM '.DB_VIREL_S_STATUS_VOTE.' where v_vote_idserv=\''.$id.'\''));

	if($row_nm > 0 && $date > time())
		echo 'already';
	elseif($row_ab >= $conf['dvote'])
		echo 'already2';
	else
	{
		if($act == 'up')
		{
			$updateSQL = sprintf('UPDATE '.DB_VIREL_S_STATUS.' SET v_status_vote=v_status_vote+\'1\' where v_status_id=\''.$id.'\'');
			$Result1   = dbquery($updateSQL);
			$my      = dbquery('SELECT * FROM '.DB_VIREL_S_STATUS.' where v_status_id=\''.$id.'\'');
			$row_my  = dbarray($my);
			$date    = time() + $timek;
			dbquery('INSERT INTO '.DB_VIREL_S_STATUS_VOTE.'(v_vote_idserv, v_vote_ip, v_vote_date) VALUES (\''.$id.'\',\''.$_SERVER['REMOTE_ADDR'].'\',\''.$date.'\')');
			echo 'thanks';
		}
	}


?>