<?php
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}

    if(isset($_POST['id_image']) && isset($_POST['id_user']) && isset($_POST['user_ip']))
    {
        $id_user = $_POST['id_user'];
        $id_image = $_POST['id_image'];
        $user_ip = $_POST['user_ip'];
        
        //print_r($_POST);
       
        // Checking if this user has allready voted for this image
        if(voteCheck($id_image, $id_user))
        {
            if(vote($id_image, $id_user, $user_ip))
            {
                //vote($id_image, $id_user, $user_ip);
                echo "Uspešno ste glasali.";
            }
            else
            {
                echo "Greška prilikom upisa glasa.";
            }
        }
        else
        {
            echo "Već ste glasali za ovaj predlog.";
        }
    }
    else
    {
        $error = "Ajax problem";
        echo $error;
    }
?>