bindValue('user_id', $userId); $addWarning->bindValue('user_ip', $userIp); $addWarning->bindValue('issuer_id', $issuerId); $addWarning->bindValue('issuer_ip', $issuerIp); $addWarning->bindValue('type', $type); $addWarning->bindValue('note', $publicNote); $addWarning->bindValue('note_private', $privateNote); if (!$addWarning->execute()) { return 0; } return (int)db_last_insert_id(); } function user_warning_count(int $userId): int { if ($userId < 1) { return 0; } $countWarnings = db_prepare(' SELECT COUNT(`warning_id`) FROM `msz_user_warnings` WHERE `user_id` = :user_id '); $countWarnings->bindValue('user_id', $userId); return (int)($countWarnings->execute() ? $countWarnings->fetchColumn() : 0); } function user_warning_remove(int $warningId): bool { if ($warningId < 1) { return false; } $removeWarning = db_prepare(' DELETE FROM `msz_user_warnings` WHERE `warning_id` = :warning_id '); $removeWarning->bindValue('warning_id', $warningId); return $removeWarning->execute(); } function user_warning_fetch( int $userId, ?int $days = null ): array { $fetchWarnings = db_prepare(sprintf( ' SELECT uw.`warning_id`, uw.`warning_created`, uw.`warning_type`, uw.`warning_note`, uw.`warning_note_private`, uw.`user_id`, uw.`issuer_id`, INET6_NTOA(uw.`user_ip`) AS `user_ip`, INET6_NTOA(uw.`issuer_ip`) AS `issuer_ip`, iu.`username` AS `issuer_username` FROM `msz_user_warnings` AS uw LEFT JOIN `msz_users` AS iu ON iu.`user_id` = uw.`issuer_id` WHERE uw.`user_id` = :user_id %s ', $days !== null ? 'AND uw.`warning_created` >= NOW() - INTERVAL :days DAY' : '' )); $fetchWarnings->bindValue('user_id', $userId); if ($days !== null) { $fetchWarnings->bindValue('days', $days); } $warnings = $fetchWarnings->execute() ? $fetchWarnings->fetchAll(PDO::FETCH_ASSOC) : false; return $warnings ? $warnings : []; }