<?php

require_once "lib/account.php";
function submitSurvey(int $satisfaction, int $functionality, int $content, string $comment): array
{
    global $mysqli;
    $output = ["Status" => "Fail", "Opinion" => "Ignored unsuccessfully!"];
    if (isLoggedIn()
        && $satisfaction >= 1 && $satisfaction <= 5
        && $functionality >= 1 && $functionality <= 5
        && $content >= 1 && $content <= 5
        && !empty($comment)) {
        $stmtMemeAdd = $mysqli->prepare('INSERT INTO Survey (AuthorID, Satisfaction, Functionality, Content, Comment) VALUES (?, ?, ?, ?, ?)');
        $stmtMemeAdd->bind_param('iiiis', $_SESSION['ID'], $satisfaction, $functionality, $content, htmlspecialchars($comment));
        if ($stmtMemeAdd->execute() && $stmtMemeAdd->affected_rows > 0) {
            $output["Status"] = "Success";
            $output["Opinion"] = "Ignored successfully!";
        }
    }
    return $output;
}