<?php
/*========================================================================*\
|| ###################################################################### ||
|| # vBulletin 6.2.3 - Licence Number L3138846
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2026 MH Sub I, LLC dba vBulletin. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/

class vB5_Frontend_Controller_Infraction extends vB5_Frontend_Controller
{
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Adds infraction for the specified userid and nodeid
	 *
	 */
	public function actionAdd()
	{
		// require a POST request for this action
		$this->verifyPostRequest();

		$input = [
			'infracteduserid'    => intval($_POST['infracteduserid']    ?? 0),
			'infractednodeid'    => intval($_POST['infractednodeid']    ?? 0),
			'infractionlevelid'  => intval($_POST['infractionlevelid']  ?? 0),
			'warning'            => [],
			'customreason'       => trim(strval($_POST['customreason']  ?? '')),
			'points'             => intval($_POST['points']             ?? 0),
			'reputation_penalty' => intval($_POST['reputation_penalty'] ?? 0),
			'expires'            => intval($_POST['expires']            ?? 0),
			'period'             => trim(strval($_POST['period']        ?? '')),
			'message'            => trim(strval($_POST['message']       ?? '')),
			'note'               => trim(strval($_POST['note']          ?? '')),
			'banreason'          => trim(strval($_POST['banreason']     ?? '')),
		];

		if (isset($_POST['warning']) AND $_POST['warning'] == $input['infractionlevelid'])
		{
			$input['warning'][$input['infractionlevelid']] = true;
		}

		$api = Api_InterfaceAbstract::instance();
		$result = $api->callApi('content_infraction', 'add', [$input, []]);

		$this->sendAsJson($result);
	}

	/**
	 * Reverses infraction for the specified nodeid
	 *
	 */
	public function actionReverse()
	{
		// require a POST request for this action
		$this->verifyPostRequest();

		$nodeid = isset($_POST['nodeid']) ? trim(intval($_POST['nodeid'])) : 0;
		$reason = isset($_POST['reason']) ? trim(strval($_POST['reason'])) : '';
		$userInfraction = isset($_POST['userinfraction']) ? trim(intval($_POST['userinfraction'])) : 0;

		$api = Api_InterfaceAbstract::instance();
		$nodeId = $api->callApi('content_infraction', ($userInfraction ? 'reverseInfraction' : 'reverseNodeInfraction'), array($nodeid, $reason));

		$this->sendAsJson($nodeId);
	}
}

/*=========================================================================*\
|| #######################################################################
|| # Downloaded: 13:27, Sun Aug 30th 2026
|| # CVS: $RCSfile$ - $Revision: 120115 $
|| #######################################################################
\*=========================================================================*/
