diff --git a/Web/Models/Repositories/ChandlerGroups.php b/Web/Models/Repositories/ChandlerGroups.php
new file mode 100644
index 00000000..4f895aea
--- /dev/null
+++ b/Web/Models/Repositories/ChandlerGroups.php
@@ -0,0 +1,48 @@
+context = DB::i()->getContext();
+ $this->groups = $this->context->table("chandlergroups");
+ $this->members = $this->context->table("chandleraclrelations");
+ $this->perms = $this->context->table("chandleraclgroupspermissions");
+ }
+
+ function get(string $UUID): ?ActiveRow
+ {
+ return $this->groups->where("id", $UUID)->fetch();
+ }
+
+ function getList(): \Traversable
+ {
+ foreach($this->groups as $group) yield $group;
+ }
+
+ function getMembersById(string $UUID): \Traversable
+ {
+ foreach($this->members->where("group", $UUID) as $member)
+ yield (new Users)->getByChandlerUser(
+ new ChandlerUser($this->context->table("chandlerusers")->where("id", $member->user)->fetch())
+ );
+ }
+
+ function getUsersMemberships(string $UUID): \Traversable
+ {
+ foreach($this->members->where("user", $UUID) as $member) yield $member;
+ }
+
+ function getPermissionsById(string $UUID): \Traversable
+ {
+ foreach($this->perms->where("group", $UUID) as $perm) yield $perm;
+ }
+}
diff --git a/Web/Models/Repositories/ChandlerUsers.php b/Web/Models/Repositories/ChandlerUsers.php
new file mode 100644
index 00000000..dbe0197a
--- /dev/null
+++ b/Web/Models/Repositories/ChandlerUsers.php
@@ -0,0 +1,39 @@
+context = DB::i()->getContext();
+ $this->users = $this->context->table("chandlerusers");
+ }
+
+ private function toUser(?ActiveRow $ar): ?ChandlerUser
+ {
+ return is_null($ar) ? NULL : (new User($ar))->getChandlerUser();
+ }
+
+ function get(int $id): ?ChandlerUser
+ {
+ return (new Users)->get($id)->getChandlerUser();
+ }
+
+ function getById(string $UUID): ?ChandlerUser
+ {
+ return new ChandlerUser($this->users->where("id", $UUID)->fetch());
+ }
+
+ function getList(int $page = 1): \Traversable
+ {
+ foreach($this->users as $user)
+ yield new ChandlerUser($user);
+ }
+}
diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php
index ceda6f6b..b66b651a 100644
--- a/Web/Presenters/AdminPresenter.php
+++ b/Web/Presenters/AdminPresenter.php
@@ -1,7 +1,7 @@
users = $users;
$this->clubs = $clubs;
$this->vouchers = $vouchers;
$this->gifts = $gifts;
$this->bannedLinks = $bannedLinks;
+ $this->chandlerGroups = $chandlerGroups;
parent::__construct();
}
@@ -62,7 +64,9 @@ final class AdminPresenter extends OpenVKPresenter
$this->notFound();
$this->template->user = $user;
-
+ $this->template->c_groups_list = (new ChandlerGroups)->getList();
+ $this->template->c_memberships = $this->chandlerGroups->getUsersMemberships($user->getChandlerGUID());
+
if($_SERVER["REQUEST_METHOD"] !== "POST")
return;
@@ -78,8 +82,13 @@ final class AdminPresenter extends OpenVKPresenter
$user->changeEmail($this->postParam("email"));
if($user->onlineStatus() != $this->postParam("online")) $user->setOnline(intval($this->postParam("online")));
$user->setVerified(empty($this->postParam("verify") ? 0 : 1));
+ if($this->postParam("add-to-group")) {
+ $query = "INSERT INTO `chandleraclrelations` (`user`, `group`) VALUES ('" . $user->getChandlerGUID() . "', '" . $this->postParam("add-to-group") . "')";
+ DatabaseConnection::i()->getConnection()->query($query);
+ }
$user->save();
+
break;
}
}
@@ -447,4 +456,95 @@ final class AdminPresenter extends OpenVKPresenter
$this->redirect("/admin/bannedLinks");
}
+
+ function renderChandlerGroups(): void
+ {
+ $this->template->groups = (new ChandlerGroups)->getList();
+
+ if($_SERVER["REQUEST_METHOD"] !== "POST")
+ return;
+
+ $req = "INSERT INTO `chandlergroups` (`name`) VALUES ('" . $this->postParam("name") . "')";
+ DatabaseConnection::i()->getConnection()->query($req);
+ }
+
+ function renderChandlerGroup(string $UUID): void
+ {
+ $DB = DatabaseConnection::i()->getConnection();
+
+ if(is_null($DB->query("SELECT * FROM `chandlergroups` WHERE `id` = '$UUID'")->fetch()))
+ $this->flashFail("err", tr("error"), tr("c_group_not_found"));
+
+ $this->template->group = (new ChandlerGroups)->get($UUID);
+ $this->template->mode = in_array(
+ $this->queryParam("act"),
+ [
+ "main",
+ "members",
+ "permissions",
+ "removeMember",
+ "removePermission",
+ "delete"
+ ]) ? $this->queryParam("act") : "main";
+ $this->template->members = (new ChandlerGroups)->getMembersById($UUID);
+ $this->template->perms = (new ChandlerGroups)->getPermissionsById($UUID);
+
+ if($this->template->mode == "removeMember") {
+ $where = "`user` = '" . $this->queryParam("uid") . "' AND `group` = '$UUID'";
+
+ if(is_null($DB->query("SELECT * FROM `chandleraclrelations` WHERE " . $where)->fetch()))
+ $this->flashFail("err", tr("error"), tr("c_user_is_not_in_group"));
+
+ $DB->query("DELETE FROM `chandleraclrelations` WHERE " . $where);
+ $this->flashFail("succ", tr("changes_saved"), tr("c_user_removed_from_group"));
+ } elseif($this->template->mode == "removePermission") {
+ $where = "`model` = '" . trim(addslashes($this->queryParam("model"))) . "' AND `permission` = '". $this->queryParam("perm") ."' AND `group` = '$UUID'";
+
+ if(is_null($DB->query("SELECT * FROM `chandleraclgroupspermissions WHERE $where`")))
+ $this->flashFail("err", tr("error"), tr("c_permission_not_found"));
+
+ $DB->query("DELETE FROM `chandleraclgroupspermissions` WHERE $where");
+ $this->flashFail("succ", tr("changes_saved"), tr("c_permission_removed_from_group"));
+ } elseif($this->template->mode == "delete") {
+ $DB->query("DELETE FROM `chandlergroups` WHERE `id` = '$UUID'");
+ $DB->query("DELETE FROM `chandleraclgroupspermissions` WHERE `group` = '$UUID'");
+ $DB->query("DELETE FROM `chandleraclrelations` WHERE `group` = '$UUID'");
+
+ $this->flashFail("succ", tr("changes_saved"), tr("c_group_removed"));
+ }
+
+ if ($_SERVER["REQUEST_METHOD"] !== "POST") return;
+
+ $req = "";
+
+ if($this->template->mode == "main")
+ if($this->postParam("delete"))
+ $req = "DELETE FROM `chandlergroups` WHERE `id`='$UUID'";
+ else
+ $req = "UPDATE `chandlergroups` SET `name`='". $this->postParam('name') ."' , `color`='". $this->postParam("color") ."' WHERE `id`='$UUID'";
+
+ if($this->template->mode == "members")
+ if($this->postParam("uid"))
+ if(!is_null($DB->query("SELECT * FROM `chandleraclrelations` WHERE `user` = '" . $this->postParam("uid") . "'")))
+ $this->flashFail("err", tr("error"), tr("c_user_is_already_in_group"));
+
+ $req = "INSERT INTO `chandleraclrelations` (`user`, `group`, `priority`) VALUES ('". $this->postParam("uid") ."', '$UUID', 32)";
+
+ if($this->template->mode == "permissions")
+ $req = "INSERT INTO `chandleraclgroupspermissions` (`group`, `model`, `permission`, `context`) VALUES ('$UUID', '". trim(addslashes($this->postParam("model"))) ."', '". $this->postParam("permission") ."', 0)";
+
+ $DB->query($req);
+ $this->flashFail("succ", tr("changes_saved"));
+ }
+
+ function renderChandlerUser(string $UUID): void
+ {
+ if(!$UUID) $this->notFound();
+
+ $c_user = (new ChandlerUsers())->getById($UUID);
+ $user = $this->users->getByChandlerUser($c_user);
+ if(!$user) $this->notFound();
+
+ $this->redirect("/admin/users/id" . $user->getId());
+ }
}
diff --git a/Web/Presenters/templates/Admin/@layout.xml b/Web/Presenters/templates/Admin/@layout.xml
index 8367e709..788bba8d 100644
--- a/Web/Presenters/templates/Admin/@layout.xml
+++ b/Web/Presenters/templates/Admin/@layout.xml
@@ -60,6 +60,14 @@
{_admin_banned_links}
+
+ Chandler
+
+
{_admin_services}
diff --git a/Web/Presenters/templates/Admin/ChandlerGroup.xml b/Web/Presenters/templates/Admin/ChandlerGroup.xml
new file mode 100644
index 00000000..3c9ae709
--- /dev/null
+++ b/Web/Presenters/templates/Admin/ChandlerGroup.xml
@@ -0,0 +1,177 @@
+{extends "@layout.xml"}
+
+{block title}
+ {$group->name}
+{/block}
+
+{block heading}
+ {_c_groups}
+ » {$group->name}
+{/block}
+
+{block content}
+ {var $isMain = $mode === 'main'}
+ {var $isPermissions = $mode === 'permissions'}
+ {var $isMembers = $mode === 'members'}
+
+ {if $isMain}
+
+ {elseif $isMembers}
+
+
+
+
+
+ ID |
+ UUID |
+ {_admin_name} |
+ {_gender} |
+ {_admin_shortcode} |
+ {_registration_date} |
+ {_admin_actions} |
+
+
+
+
+ {$user->getId()} |
+ {$user->getChandlerGUID()} |
+
+
+
+
+
+
+
+ {$user->getCanonicalName()}
+
+ {_admin_banned}
+ |
+ {$user->isFemale() ? tr("female") : tr("male")} |
+ {$user->getShortCode() ?? "(" . tr("none") . ")"} |
+ {$user->getRegistrationTime()} |
+
+
+ {_delete}
+
+
+ {_edit}
+
+ {if $thisUser->getChandlerUser()->can("substitute")->model('openvk\Web\Models\Entities\User')->whichBelongsTo(0)}
+
+ {_admin_loginas}
+
+ {/if}
+ |
+
+
+
+
+
+ {elseif $isPermissions}
+
+
+
+
+
+ {_c_model} |
+ {_c_permission} |
+ {_admin_actions} |
+
+
+
+
+ {$perm->model} |
+ {$perm->permission} |
+
+
+ {_edit}
+
+ |
+
+
+
+
+ {/if}
+{/block}
diff --git a/Web/Presenters/templates/Admin/ChandlerGroups.xml b/Web/Presenters/templates/Admin/ChandlerGroups.xml
new file mode 100644
index 00000000..488e7bea
--- /dev/null
+++ b/Web/Presenters/templates/Admin/ChandlerGroups.xml
@@ -0,0 +1,59 @@
+{extends "@layout.xml"}
+
+{block title}
+ {_c_groups}
+{/block}
+
+{block heading}
+ {_c_groups}
+{/block}
+
+{block content}
+
+
+{/block}
diff --git a/Web/Presenters/templates/Admin/User.xml b/Web/Presenters/templates/Admin/User.xml
index e0f4d905..46044a7a 100644
--- a/Web/Presenters/templates/Admin/User.xml
+++ b/Web/Presenters/templates/Admin/User.xml
@@ -68,6 +68,43 @@
+
+ {_c_groups}
+
+
+
+
+
+
+
+