<?php

if (isset($user)) {
    if (@$_GET['rating'] == "up") {
        $q = $db->super_query("SELECT COUNT(*) as count FROM loads_rating WHERE id_user = '$user[id]' AND `name` = '$file' AND `path` = '$path' LIMIT 1");
        if ($q['count'] != 0) {
            $err = 'Вы уже голосовали за этот файл';
        } else {
            if ($db->query("UPDATE loads_list SET rating = rating +1 WHERE name = '$file' AND `path` = '$path' LIMIT 1")) {
                if ($db->query("UPDATE loads_list SET kol = kol +1 WHERE name = '$file' AND `path` = '$path' LIMIT 1")) {
                    if ($db->query("UPDATE loads_list SET `user` = '" . $user['nick'] . "' WHERE `name` = '$file' AND `path` = '$path' LIMIT 1")) {
                        if ($db->query("INSERT INTO `loads_rating` (`id_user`, `name`, `path`) values('" . $user['id'] . "', '$file', '$path')")) {
                            msg("Ваш + успешно принят");
                        } else {
                            $err = 'Ошыбка';
                        }
                    }
                }
            }
        }
    }

    if (@$_GET['rating'] == "down") {
        $q = $db->super_query("SELECT COUNT(*) as count FROM loads_rating WHERE id_user = '$user[id]' AND `name` = '$file' AND `path` = '$path' LIMIT 1");
        if ($q['count'] != 0) {
            $err = 'Вы уже голосовали за этот файл';
        } else {
            if ($db->query("UPDATE loads_list SET rating = rating -1 WHERE name = '$file' AND `path` = '$path' LIMIT 1")) {
                if ($db->query("UPDATE loads_list SET kol = kol +1 WHERE name = '$file' AND `path` = '$path' LIMIT 1")) {
                    if ($db->query("UPDATE loads_list SET `user` = '" . $user['nick'] . "' WHERE `name` = '$file' AND `path` = '$path' LIMIT 1")) {
                        if ($db->query("INSERT INTO `loads_rating` (`id_user`, `name`, `path`) values('" . $user['id'] . "', '$file', '$path')")) {
                            msg("Ваш - успешно принят");
                        } else {
                            $err = 'Ошыбка';
                        }
                    }
                }
            }
        }
    }
}
?>
