* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ACTION . "Action.php"); /** * Deletes a team. * * Reads the POST parameters looking for the following KEYS: * id: the team id. * * @category Action */ class Delete_Team_Action extends Action{ /** * Executes the action. */ function execute(){ $id = filter_input(INPUT_POST, 'id'); $statement = get_context()->get_db()->prepare(" SELECT count(team.id) AS c FROM team, player WHERE team.id = :team AND player.user = :user "); $statement->bindValue(':team', $id, SQLITE3_TEXT); $statement->bindValue(':user', get_context()->get_user()->get_id(), SQLITE3_TEXT); if ($statement->execute()->fetchArray(SQLITE3_ASSOC)["c"] == 0){ $this->code = 401; $this->message = "Unauthorized"; } else{ $statement = get_context()->get_db()->prepare("DELETE FROM team WHERE id = :id;"); $statement->bindValue(':id', $id, SQLITE3_TEXT); $statement->execute(); $statement = get_context()->get_db()->prepare("DELETE FROM team_unit WHERE team = :id;"); $statement->bindValue(':id', $id, SQLITE3_TEXT); $statement->execute(); $this->code = 204; $this->message = "No Content"; } return; } }