false, "Description" => false, "Entry" => false, "Emblem" => false, "General" => false ]; $Fields = (object) [ "Name" => "", "Description" => "", "Entry" => "Anyone" ]; // bit of a clunky way to do this but eh $Ranks = (object) [ (object) [ "Name" => "Guest", "Description" => "A non-group member.", "Rank" => 0, "Permissions" => json_encode([ "CanViewGroupWall" => true, "CanViewGroupStatus" => true, "CanPostOnGroupWall" => true, "CanPostGroupStatus" => false, "CanDeleteGroupWallPosts" => false, "CanAcceptJoinRequests" => false, "CanKickLowerRankedMembers" => false, "CanRoleLowerRankedMembers" => false, "CanManageRelationships" => false, "CanCreateAssets" => false, "CanConfigureAssets" => false, "CanSpendFunds" => false, "CanManageGames" => false, "CanManageGroupAdmin" => false, "CanViewAuditLog" => false ]) ], (object) [ "Name" => "Member", "Description" => "A regular group member.", "Rank" => 25, "Permissions" => json_encode([ "CanViewGroupWall" => true, "CanViewGroupStatus" => true, "CanPostOnGroupWall" => true, "CanPostGroupStatus" => false, "CanDeleteGroupWallPosts" => false, "CanAcceptJoinRequests" => false, "CanKickLowerRankedMembers" => false, "CanRoleLowerRankedMembers" => false, "CanManageRelationships" => false, "CanCreateAssets" => false, "CanConfigureAssets" => false, "CanSpendFunds" => false, "CanManageGames" => false, "CanManageGroupAdmin" => false, "CanViewAuditLog" => false ]) ], (object) [ "Name" => "Admin", "Description" => "A group administrator.", "Rank" => 100, "Permissions" => json_encode([ "CanViewGroupWall" => true, "CanViewGroupStatus" => true, "CanPostOnGroupWall" => true, "CanPostGroupStatus" => true, "CanDeleteGroupWallPosts" => true, "CanAcceptJoinRequests" => false, "CanKickLowerRankedMembers" => true, "CanRoleLowerRankedMembers" => true, "CanManageRelationships" => false, "CanCreateAssets" => true, "CanConfigureAssets" => true, "CanSpendFunds" => false, "CanManageGames" => false, "CanManageGroupAdmin" => true, "CanViewAuditLog" => true ]) ], (object) [ "Name" => "Owner", "Description" => "The group's owner.", "Rank" => 255, "Permissions" => json_encode([ "CanViewGroupWall" => true, "CanViewGroupStatus" => true, "CanPostOnGroupWall" => true, "CanPostGroupStatus" => true, "CanDeleteGroupWallPosts" => true, "CanAcceptJoinRequests" => true, "CanKickLowerRankedMembers" => true, "CanRoleLowerRankedMembers" => true, "CanManageRelationships" => true, "CanCreateAssets" => true, "CanConfigureAssets" => true, "CanSpendFunds" => true, "CanManageGames" => false, "CanManageGroupAdmin" => true, "CanViewAuditLog" => true ]) ], ]; if($_SERVER["REQUEST_METHOD"] == "POST") { $Fields->Name = $_POST["Name"] ?? ""; $Fields->Description = $_POST["Description"] ?? ""; // $Fields->Entry = $_POST["Entry"] ?? ""; $Emblem = $_FILES["Emblem"] ?? false; if(!strlen($Fields->Name)) $Errors->Name = "Group name cannot be empty"; else if(strlen($Fields->Name) < 3) $Errors->Name = "Group name must be at least 3 characters long"; else if(strlen($Fields->Name) > 48) $Errors->Name = "Group name cannot be longer than 48 characters"; else if(Polygon::IsExplicitlyFiltered($Fields->Name)) $Errors->Name = "Group name contains inappropriate text"; if(strlen($Fields->Description) > 1000) $Errors->Description = "Group description cannot be longer than 1,000 characters"; else if(Polygon::IsExplicitlyFiltered($Fields->Description)) $Errors->Description = "Group description contains inappropriate text"; // if(!in_array($Fields->Entry, ["Anyone", "Manual"])) $Errors->Entry = "Group entry setting is invalid"; if(!$Emblem || !$Emblem["size"]) $Errors->Emblem = "You must upload a group emblem"; // if(SESSION["user"]["currency"] < 500) $Errors->General = "You do not have the sufficient funds to create a group"; $GroupExists = Database::singleton()->run("SELECT COUNT(*) FROM groups WHERE name = :Name", [":Name" => $Fields->Name])->fetchColumn(); if($GroupExists) $Errors->Name = "A group with that name already exists"; $CreatedGroups = Database::singleton()->run("SELECT COUNT(*) FROM groups WHERE owner = :UserID", [":UserID" => SESSION["user"]["id"]])->fetchColumn(); if($CreatedGroups >= 3) $Errors->General = "You can only create a maximum of three groups"; if(Groups::GetUserGroups(SESSION["user"]["id"])->rowCount() >= 20) $Errors->General = "You have reached the maximum number of groups"; if(!$Errors->Name && !$Errors->Description && !$Errors->Entry && !$Errors->Emblem && !$Errors->General) { // the group emblem is uploaded as an image on the creator's account $Image = new Upload($Emblem); if(!$Image->uploaded) throw new Exception("Failed to upload image"); $Image->allowed = ['image/png', 'image/jpg', 'image/jpeg']; $Image->image_convert = 'png'; $EmblemID = Catalog::CreateAsset(["type" => 22, "creator" => SESSION["user"]["id"], "name" => $Fields->Name, "description" => "Group Emblem"]); $Processor = Image::Process($Image, ["name" => "$EmblemID", "resize" => false, "dir" => "assets/"]); if($Processor !== true) $Errors->Emblem = $Processor; if(!$Errors->Emblem) { Thumbnails::UploadAsset($Image, $EmblemID, 60, 62, ["keepRatio" => true, "align" => "C"]); Thumbnails::UploadAsset($Image, $EmblemID, 420, 420, ["keepRatio" => true, "align" => "C"]); // remove 500 pizzas from creator // Database::singleton()->run( // "UPDATE users SET currency = currency - 500 WHERE id = :UserID", // [":UserID" => SESSION["user"]["id"]] // ); // create group Database::singleton()->run( "INSERT INTO groups (creator, owner, emblem, name, description, entry, created) VALUES (:UserID, :UserID, :EmblemID, :Name, :Description, :Entry, UNIX_TIMESTAMP())", [":UserID" => SESSION["user"]["id"], ":EmblemID" => $EmblemID, ":Name" => $Fields->Name, ":Description" => $Fields->Description, ":Entry" => $Fields->Entry] ); $GroupID = Database::singleton()->lastInsertId(); // create initial ranks foreach ($Ranks as $Rank) { Database::singleton()->run( "INSERT INTO groups_ranks (GroupID, Name, Description, Rank, Permissions, Created) VALUES (:GroupID, :Name, :Description, :Rank, :Permissions, UNIX_TIMESTAMP())", [":GroupID" => $GroupID, "Name" => $Rank->Name, ":Description" => $Rank->Description, ":Rank" => $Rank->Rank, ":Permissions" => $Rank->Permissions] ); } // instantiate creator as owner Database::singleton()->run( "INSERT INTO groups_members (GroupID, UserID, Rank, Joined) VALUES (:GroupID, :UserID, 255, UNIX_TIMESTAMP())", [":GroupID" => $GroupID, ":UserID" => SESSION["user"]["id"]] ); redirect("/groups?gid=$GroupID"); } } } $pageBuilder = new PageBuilder(); $pageBuilder->buildHeader(); ?>

Create A Group

Name?>
Description?>
Emblem?>

General?>

General?>
buildFooter();