Browse Source

updated Users, Groups & Perms Controller/Views

v3-dev
REJack 6 years ago
parent
commit
0ea6c3ba4c
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 71
      app/Controllers/Admin/Groups.php
  2. 16
      app/Controllers/Admin/Perms.php
  3. 46
      app/Controllers/Admin/Users.php
  4. 84
      app/Helpers/aauth_helper.php
  5. 4
      app/Language/en/Admin.php
  6. 76
      app/Libraries/Aauth.php
  7. 12
      app/Models/Aauth/PermToGroupModel.php
  8. 13
      app/Models/Aauth/PermToUserModel.php
  9. 6
      app/Models/Aauth/UserModel.php
  10. 34
      app/Views/Admin/Groups/Delete.php
  11. 30
      app/Views/Admin/Groups/Edit.php
  12. 8
      app/Views/Admin/Groups/Home.php
  13. 30
      app/Views/Admin/Groups/New.php
  14. 32
      app/Views/Admin/Groups/Show.php
  15. 4
      app/Views/Admin/Perms/Home.php
  16. 32
      app/Views/Admin/Users/Delete.php
  17. 30
      app/Views/Admin/Users/Edit.php
  18. 12
      app/Views/Admin/Users/Home.php
  19. 30
      app/Views/Admin/Users/New.php
  20. 32
      app/Views/Admin/Users/Show.php
  21. 4
      public/assets/css/admin/groups/index.css
  22. 4
      public/assets/css/admin/perms/index.css

71
app/Controllers/Admin/Groups.php

@ -64,8 +64,10 @@ class Groups extends Controller
*/ */
public function new() public function new()
{ {
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Groups/New'); echo view('Admin/Groups/New', $data);
echo view('Templates/FooterAdmin'); echo view('Templates/FooterAdmin');
} }
@ -78,12 +80,30 @@ class Groups extends Controller
{ {
$name = $this->request->getPost('name'); $name = $this->request->getPost('name');
$definition = $this->request->getPost('definition'); $definition = $this->request->getPost('definition');
$subGroups = $this->request->getPost('sub_groups');
$perms = $this->request->getPost('perms');
if (! $this->aauth->createGroup($name, $definition)) if (! $groupId = $this->aauth->createGroup($name, $definition))
{ {
return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); return redirect()->back()->with('errors', $this->aauth->getErrorsArray());
} }
foreach ($subGroups as $subgroupId => $state)
{
if ($state === 1)
{
$this->aauth->addSubgroup($groupId, $subgroupId);
}
}
foreach ($perms as $permId => $state)
{
if ($state === 1)
{
$this->aauth->allowGroup($permId, $groupId);
}
}
return redirect()->to('/admin/groups'); return redirect()->to('/admin/groups');
} }
@ -94,7 +114,11 @@ class Groups extends Controller
*/ */
public function edit($groupId) public function edit($groupId)
{ {
$data['group'] = $this->aauth->getGroup($groupId); $data['group'] = $this->aauth->getGroup($groupId);
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
$data['activeGroups'] = $this->aauth->getSubgroups($groupId);
$data['activePerms'] = $this->aauth->getGroupPerms($groupId);
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Groups/Edit', $data); echo view('Admin/Groups/Edit', $data);
@ -110,12 +134,41 @@ class Groups extends Controller
{ {
$name = $this->request->getPost('name'); $name = $this->request->getPost('name');
$definition = $this->request->getPost('definition'); $definition = $this->request->getPost('definition');
$subGroups = $this->request->getPost('sub_groups');
$perms = $this->request->getPost('perms');
if (! $this->aauth->updateGroup($groupId, empty($name) ? null : $name, empty($definition) ? null : $definition)) if (! $this->aauth->updateGroup($groupId, empty($name) ? null : $name, empty($definition) ? null : $definition))
{ {
return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); return redirect()->back()->with('errors', $this->aauth->getErrorsArray());
} }
$activeSubGroups = $this->aauth->getSubgroups($groupId);
$activePerms = $this->aauth->getGroupPerms($groupId, 1);
foreach ($subGroups as $subgroupId => $state)
{
if (! in_array(['subgroup_id' => $subgroupId], $activeSubGroups) && $state === 1)
{
$this->aauth->addSubgroup($groupId, $subgroupId);
}
else if (in_array(['subgroup_id' => $subgroupId], $activeSubGroups) && $state === 0)
{
$this->aauth->removeSubgroup($groupId, $subgroupId);
}
}
foreach ($perms as $permId => $state)
{
if (! in_array(['perm_id' => $permId], $activePerms) && $state === 1)
{
$this->aauth->allowGroup($permId, $groupId);
}
else if (! in_array(['perm_id' => $permId], $activePerms) && $state === 0)
{
$this->aauth->denyGroup($permId, $groupId);
}
}
return redirect()->to('/admin/groups/edit/' . $groupId); return redirect()->to('/admin/groups/edit/' . $groupId);
} }
@ -126,7 +179,11 @@ class Groups extends Controller
*/ */
public function show($groupId) public function show($groupId)
{ {
$data['group'] = $this->aauth->getGroup($groupId); $data['group'] = $this->aauth->getGroup($groupId);
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
$data['activeGroups'] = $this->aauth->getSubgroups($groupId);
$data['activePerms'] = $this->aauth->getGroupPerms($groupId);
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Groups/Show', $data); echo view('Admin/Groups/Show', $data);
@ -154,7 +211,11 @@ class Groups extends Controller
} }
} }
$data['group'] = $this->aauth->getGroup($groupId); $data['group'] = $this->aauth->getGroup($groupId);
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
$data['activeGroups'] = $this->aauth->getSubgroups($groupId);
$data['activePerms'] = $this->aauth->getGroupPerms($groupId);
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Groups/Delete', $data); echo view('Admin/Groups/Delete', $data);

16
app/Controllers/Admin/Perms.php

@ -49,7 +49,7 @@ class Perms extends Controller
$data = $this->aauth->listPermsPaginated(); $data = $this->aauth->listPermsPaginated();
$data['cssFiles'] = [ $data['cssFiles'] = [
'/assets/css/admin/groups/index.css' '/assets/css/admin/perms/index.css'
]; ];
echo view('Templates/HeaderAdmin', $data); echo view('Templates/HeaderAdmin', $data);
@ -84,7 +84,7 @@ class Perms extends Controller
return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); return redirect()->back()->with('errors', $this->aauth->getErrorsArray());
} }
return redirect()->to('/admin/groups'); return redirect()->to('/admin/perms');
} }
/** /**
@ -94,7 +94,7 @@ class Perms extends Controller
*/ */
public function edit($permId) public function edit($permId)
{ {
$data['group'] = $this->aauth->getPerm($permId); $data['perm'] = $this->aauth->getPerm($permId);
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Perms/Edit', $data); echo view('Admin/Perms/Edit', $data);
@ -116,7 +116,7 @@ class Perms extends Controller
return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); return redirect()->back()->with('errors', $this->aauth->getErrorsArray());
} }
return redirect()->to('/admin/groups/edit/' . $permId); return redirect()->to('/admin/perms/edit/' . $permId);
} }
/** /**
@ -126,7 +126,7 @@ class Perms extends Controller
*/ */
public function show($permId) public function show($permId)
{ {
$data['group'] = $this->aauth->getPerm($permId); $data['perm'] = $this->aauth->getPerm($permId);
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Perms/Show', $data); echo view('Admin/Perms/Show', $data);
@ -142,7 +142,7 @@ class Perms extends Controller
{ {
if (! $this->aauth->getPerm($permId)) if (! $this->aauth->getPerm($permId))
{ {
return redirect()->to('/admin/groups'); return redirect()->to('/admin/perms');
} }
$id = $this->request->getPost('id'); $id = $this->request->getPost('id');
@ -150,11 +150,11 @@ class Perms extends Controller
{ {
if ($this->aauth->deletePerm($permId)) if ($this->aauth->deletePerm($permId))
{ {
return redirect()->to('/admin/groups'); return redirect()->to('/admin/perms');
} }
} }
$data['group'] = $this->aauth->getPerm($permId); $data['perm'] = $this->aauth->getPerm($permId);
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Perms/Delete', $data); echo view('Admin/Perms/Delete', $data);

46
app/Controllers/Admin/Users.php

@ -67,6 +67,8 @@ class Users extends Controller
public function new() public function new()
{ {
$data['useUsername'] = $this->config->loginUseUsername; $data['useUsername'] = $this->config->loginUseUsername;
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Users/New', $data); echo view('Admin/Users/New', $data);
@ -101,6 +103,8 @@ class Users extends Controller
{ {
$data['useUsername'] = $this->config->loginUseUsername; $data['useUsername'] = $this->config->loginUseUsername;
$data['user'] = $this->aauth->getUser($userId); $data['user'] = $this->aauth->getUser($userId);
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Users/Edit', $data); echo view('Admin/Users/Edit', $data);
@ -117,12 +121,46 @@ class Users extends Controller
$email = $this->request->getPost('email'); $email = $this->request->getPost('email');
$username = $this->request->getPost('username'); $username = $this->request->getPost('username');
$password = $this->request->getPost('password'); $password = $this->request->getPost('password');
$groups = $this->request->getPost('groups');
$perms = $this->request->getPost('perms');
if (! $this->aauth->updateUser($userId, empty($email) ? null : $email, empty($password) ? null : $password, empty($username) ? null : $username)) if (! $this->aauth->updateUser($userId, empty($email) ? null : $email, empty($password) ? null : $password, empty($username) ? null : $username))
{ {
return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); return redirect()->back()->with('errors', $this->aauth->getErrorsArray());
} }
$activeGroups = $this->aauth->getUserGroups($userId);
$activePerms = $this->aauth->getUserPerms($userId, 1);
foreach ($groups as $groupId => $state)
{
if ($groupId === 2)
{
continue;
}
if (! in_array(['group_id' => $groupId], $activeGroups) && $state === 1)
{
$this->aauth->addMember($groupId, $userId);
}
else if (in_array(['group_id' => $groupId], $activeGroups) && $state === 0)
{
$this->aauth->removeMember($groupId, $userId);
}
}
foreach ($perms as $permId => $state)
{
if (! in_array(['perm_id' => $permId], $activePerms) && $state === 1)
{
$this->aauth->allowUser($permId, $userId);
}
else if (in_array(['perm_id' => $permId], $activePerms) && $state === 0)
{
$this->aauth->denyUser($permId, $userId);
}
}
return redirect()->to('/admin/users/edit/' . $userId); return redirect()->to('/admin/users/edit/' . $userId);
} }
@ -133,7 +171,9 @@ class Users extends Controller
*/ */
public function show($userId) public function show($userId)
{ {
$data['user'] = $this->aauth->getUser($userId); $data['user'] = $this->aauth->getUser($userId);
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Users/Show', $data); echo view('Admin/Users/Show', $data);
@ -161,7 +201,9 @@ class Users extends Controller
} }
} }
$data['user'] = $this->aauth->getUser($userId); $data['user'] = $this->aauth->getUser($userId);
$data['groups'] = $this->aauth->listGroups();
$data['perms'] = $this->aauth->listPerms();
echo view('Templates/HeaderAdmin'); echo view('Templates/HeaderAdmin');
echo view('Admin/Users/Delete', $data); echo view('Admin/Users/Delete', $data);

84
app/Helpers/aauth_helper.php

@ -35,3 +35,87 @@ if (! function_exists('is_loggedin'))
return $aauth->isLoggedIn(); return $aauth->isLoggedIn();
} }
} }
if (! function_exists('is_member'))
{
/**
* Is member
*
* @return boolean
*/
function is_member($groupPar, $userId)
{
$aauth = new Aauth();
return $aauth->isMember($groupPar, $userId);
}
}
if (! function_exists('is_allowed'))
{
/**
* Is allowed
*
* @return boolean
*/
function is_allowed($permPar, $userId)
{
$aauth = new Aauth();
return $aauth->isAllowed($permPar, $userId);
}
}
if (! function_exists('get_subgroups'))
{
/**
* Get Sub-Groups by Group Name/Id
*
* @return array
*/
function get_subgroups($groupPar)
{
$aauth = new Aauth();
return $aauth->getSubgroups($groupPar);
}
}
if (! function_exists('get_user_perms'))
{
/**
* Get User Groups
*
* @return array
*/
function get_user_groups($userId)
{
$aauth = new Aauth();
return $aauth->getUserGroups($userId);
}
}
if (! function_exists('get_user_perms'))
{
/**
* Get Group Perms by Group Name/Id
*
* @return array
*/
function get_user_perms($userId, $state = null)
{
$aauth = new Aauth();
return $aauth->getUserPerms($userId, $state);
}
}
if (! function_exists('get_group_perms'))
{
/**
* Get Group Perms by Group Name/Id
*
* @return array
*/
function get_group_perms($groupPar, $state = null)
{
$aauth = new Aauth();
return $aauth->getGroupPerms($groupPar, $state);
}
}

4
app/Language/en/Admin.php

@ -50,6 +50,8 @@ return [
'usersLabelUsernameCurrent' => 'Current username', 'usersLabelUsernameCurrent' => 'Current username',
'usersLabelPassword' => 'Password', 'usersLabelPassword' => 'Password',
'usersLabelBanned' => 'Banned', 'usersLabelBanned' => 'Banned',
'usersLabelGroups' => 'Groups',
'usersLabelPerms' => 'Perms',
'usersLabelCreatedAt' => 'Created at', 'usersLabelCreatedAt' => 'Created at',
'usersLabelUpdatedAt' => 'Updated at', 'usersLabelUpdatedAt' => 'Updated at',
'usersLabelLastIPAddress' => 'Last IP-Address', 'usersLabelLastIPAddress' => 'Last IP-Address',
@ -70,6 +72,8 @@ return [
'groupsLabelId' => 'Id', 'groupsLabelId' => 'Id',
'groupsLabelName' => 'Name', 'groupsLabelName' => 'Name',
'groupsLabelDefinition' => 'Definition', 'groupsLabelDefinition' => 'Definition',
'groupsLabelSubGroups' => 'Sub-Groups',
'groupsLabelPerms' => 'Perms',
'groupsLabelNameCurrent' => 'Current Name', 'groupsLabelNameCurrent' => 'Current Name',
'groupsLabelDefinitionCurrent' => 'Current Definition', 'groupsLabelDefinitionCurrent' => 'Current Definition',
'groupsLabelCreatedAt' => 'Created at', 'groupsLabelCreatedAt' => 'Created at',

76
app/Libraries/Aauth.php

@ -669,7 +669,7 @@ class Aauth
} }
else if (is_null($email) && is_null($password) && is_null($username)) else if (is_null($email) && is_null($password) && is_null($username))
{ {
return false; return true;
} }
$data['id'] = $userId; $data['id'] = $userId;
@ -1317,7 +1317,7 @@ class Aauth
if (is_null($name) && is_null($definition)) if (is_null($name) && is_null($definition))
{ {
return false; return true;
} }
else if (! $groupId = $this->getGroupId($groupPar)) else if (! $groupId = $this->getGroupId($groupPar))
{ {
@ -1444,11 +1444,53 @@ class Aauth
return $groupToUserModel->delete($groupId, $userId); return $groupToUserModel->delete($groupId, $userId);
} }
/**
* Get User Groups
*
* @param integer|string $userId User id
*
* @return object Array of group_id's
*/
public function getUserGroups($userId)
{
$userModel = new UserModel();
if (! $userModel->existsById($userId))
{
return false;
}
$groupToUserModel = new GroupToUserModel();
return $groupToUserModel->findAllByUserId($userId);
}
/**
* Get User Perms
*
* @param integer|string $userId User id
*
* @return object Array of perm_id's
*/
public function getUserPerms($userId, $state = null)
{
$userModel = new UserModel();
if (! $userModel->existsById($userId))
{
return false;
}
$permToUserModel = new PermToUserModel();
return $permToUserModel->findAllByUserId($userId, $state);
}
/** /**
* Add subgroup to group * Add subgroup to group
* *
* @param integer $userId User id to add to group * @param integer|string $groupPar Group id
* @param integer|string $groupPar Group id or name to add user to * @param integer|string $subgroupPar Subgroup id or name to add to group
* *
* @return boolean Add success/failure * @return boolean Add success/failure
*/ */
@ -1469,6 +1511,10 @@ class Aauth
return false; return false;
} }
else if (! $groupId = $subgroupId)
{
return false;
}
else if ($groupToGroupModel->exists($groupId, $subgroupId)) else if ($groupToGroupModel->exists($groupId, $subgroupId))
{ {
$this->info(lang('Aauth.alreadyMemberSubgroup')); $this->info(lang('Aauth.alreadyMemberSubgroup'));
@ -1539,6 +1585,26 @@ class Aauth
return $groupToGroupModel->findAllByGroupId($groupId); return $groupToGroupModel->findAllByGroupId($groupId);
} }
/**
* Get group perms
*
* @param integer|string $groupPar Group id or name to get
* @param integer $state State (1 = allowed, 0 = denied)
*
* @return object Array of subgroup_id's
*/
public function getGroupPerms($groupPar, int $state = null)
{
if (! $groupId = $this->getGroupId($groupPar))
{
return false;
}
$permToGroupModel = new PermToGroupModel();
return $permToGroupModel->findAllByGroupId($groupId, $state);
}
/** /**
* Remove member from all groups * Remove member from all groups
* *
@ -1907,7 +1973,7 @@ class Aauth
if (is_null($name) && is_null($definition)) if (is_null($name) && is_null($definition))
{ {
return false; return true;
} }
else if (! $permId = $this->getPermId($permPar)) else if (! $permId = $this->getPermId($permPar))
{ {

12
app/Models/Aauth/PermToGroupModel.php

@ -97,12 +97,20 @@ class PermToGroupModel
* *
* @return array|null * @return array|null
*/ */
public function findAllByGroupId(int $groupId) public function findAllByGroupId(int $groupId, int $state = null)
{ {
$builder = $this->builder(); $builder = $this->builder();
$builder->select('perm_id, state');
$builder->where('group_id', $groupId); $builder->where('group_id', $groupId);
if (! $state)
{
$builder->select('perm_id, state');
}
else if ($state)
{
$builder->select('perm_id');
$builder->where('state', $state);
}
return $builder->get()->getResult('array'); return $builder->get()->getResult('array');
} }

13
app/Models/Aauth/PermToUserModel.php

@ -97,12 +97,21 @@ class PermToUserModel
* *
* @return array|null * @return array|null
*/ */
public function findAllByUserId(int $userId) public function findAllByUserId(int $userId, int $state = null)
{ {
$builder = $this->builder(); $builder = $this->builder();
$builder->select('perm_id, state');
$builder->where('user_id', $userId); $builder->where('user_id', $userId);
if (! $state)
{
$builder->select('perm_id, state');
}
else if ($state)
{
$builder->select('perm_id');
$builder->where('state', $state);
}
return $builder->get()->getResult('array'); return $builder->get()->getResult('array');
} }

6
app/Models/Aauth/UserModel.php

@ -143,9 +143,11 @@ class UserModel extends Model
public function updateLastLogin(int $userId) public function updateLastLogin(int $userId)
{ {
$builder = $this->builder(); $builder = $this->builder();
$request = \Config\Services::request();
$data['last_login'] = $this->setDate(); $data['last_login'] = $this->setDate();
$data['last_activity'] = $this->setDate(); $data['last_activity'] = $this->setDate();
$data['last_ip_address'] = $request->getIPAddress();
return $builder->update($data, [$this->primaryKey => $userId]); return $builder->update($data, [$this->primaryKey => $userId]);
} }

34
app/Views/Admin/Groups/Delete.php

@ -25,6 +25,40 @@
<label><?= lang('Admin.groupsLabelDefinition') ?></label> <label><?= lang('Admin.groupsLabelDefinition') ?></label>
<p><?= $group['definition'] ?></p> <p><?= $group['definition'] ?></p>
</div> </div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputSubGroups"><?= lang('Admin.groupsLabelSubGroups') ?></label>
<?php foreach ($groups as $group): ?>
<?php if (! in_array(['subgroup_id' => $group['id']], $activeGroups)): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.groupsLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<?php if (! in_array(['perm_id' => $perm['id'], 'state' => 1], $activePerms)): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary float-right"><?= lang('Admin.groupsDeleteSubmit') ?></button> <button type="submit" class="btn btn-primary float-right"><?= lang('Admin.groupsDeleteSubmit') ?></button>

30
app/Views/Admin/Groups/Edit.php

@ -42,6 +42,36 @@
<label for="inputDefinition"><?= lang('Admin.groupsLabelDefinition') ?></label> <label for="inputDefinition"><?= lang('Admin.groupsLabelDefinition') ?></label>
<input type="text" class="form-control" name="definition" id="inputDefinition" placeholder="<?= lang('Admin.groupsLabelDefinition') ?>"> <input type="text" class="form-control" name="definition" id="inputDefinition" placeholder="<?= lang('Admin.groupsLabelDefinition') ?>">
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputSubGroups"><?= lang('Admin.groupsLabelSubGroups') ?></label>
<?php foreach ($groups as $subgroup): ?>
<input type="hidden" name="sub_groups[<?= $subgroup['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="sub_groups[<?= $subgroup['id'] ?>]" value="1" <?= in_array(['subgroup_id' => $subgroup['id']], $activeGroups) ? 'checked' : ($subgroup['id'] === 2 ? 'disabled' : ($subgroup['id'] === 3 ? 'disabled' : ($subgroup['id'] === $group['id'] ? 'disabled' : ''))) ?>>
<?= $subgroup['definition'] ?> (<?= $subgroup['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.groupsLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<input type="hidden" name="perms[<?= $perm['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="perms[<?= $perm['id'] ?>]" value="1" <?= in_array(['perm_id' => $perm['id'], 'state' => 1], $activePerms) ? 'checked' : '' ?>>
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary float-right"><?= lang('Admin.groupsEditSubmit') ?></button> <button type="submit" class="btn btn-primary float-right"><?= lang('Admin.groupsEditSubmit') ?></button>

8
app/Views/Admin/Groups/Home.php

@ -21,9 +21,11 @@
<table class="table mb-0"> <table class="table mb-0">
<thead> <thead>
<tr> <tr>
<th scope="col"><?= lang('Admin.groupsLabelId') ?></th> <th scope="col" class="text-center"><?= lang('Admin.groupsLabelId') ?></th>
<th scope="col"><?= lang('Admin.groupsLabelName') ?></th> <th scope="col"><?= lang('Admin.groupsLabelName') ?></th>
<th scope="col"><?= lang('Admin.groupsLabelDefinition') ?></th> <th scope="col"><?= lang('Admin.groupsLabelDefinition') ?></th>
<th scope="col" class="text-center"><?= lang('Admin.groupsLabelSubGroups') ?></th>
<th scope="col" class="text-center"><?= lang('Admin.groupsLabelPerms') ?></th>
<th scope="col"><?= lang('Admin.groupsLabelCreatedAt') ?></th> <th scope="col"><?= lang('Admin.groupsLabelCreatedAt') ?></th>
<th scope="col"><?= lang('Admin.groupsLabelUpdatedAt') ?></th> <th scope="col"><?= lang('Admin.groupsLabelUpdatedAt') ?></th>
<th scope="col"></th> <th scope="col"></th>
@ -32,9 +34,11 @@
<tbody> <tbody>
<?php foreach ($groups as $group): ?> <?php foreach ($groups as $group): ?>
<tr> <tr>
<th scope="row"><?= $group['id'] ?></th> <th scope="row" class="text-center"><?= $group['id'] ?></th>
<td><?= $group['name'] ?></td> <td><?= $group['name'] ?></td>
<td><?= $group['definition'] ?></td> <td><?= $group['definition'] ?></td>
<td class="text-center"><?= count(get_subgroups($group['id'])) ?></td>
<td class="text-center"><?= count(get_group_perms($group['id'], 1)) ?></td>
<td><?= $group['created_at'] ?></td> <td><?= $group['created_at'] ?></td>
<td><?= $group['updated_at'] ?></td> <td><?= $group['updated_at'] ?></td>
<td class="text-right p-1"> <td class="text-right p-1">

30
app/Views/Admin/Groups/New.php

@ -28,6 +28,36 @@
<label for="inputDefinition"><?= lang('Admin.groupsLabelDefinition') ?></label> <label for="inputDefinition"><?= lang('Admin.groupsLabelDefinition') ?></label>
<input type="text" class="form-control" name="definition" id="inputDefinition" placeholder="<?= lang('Admin.groupsLabelDefinition') ?>"> <input type="text" class="form-control" name="definition" id="inputDefinition" placeholder="<?= lang('Admin.groupsLabelDefinition') ?>">
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputSubGroups"><?= lang('Admin.groupsLabelSubGroups') ?></label>
<?php foreach ($groups as $group): ?>
<input type="hidden" name="sub_groups[<?= $group['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="sub_groups[<?= $group['id'] ?>]" value="1" <?= ($group['id'] === 2 ? 'disabled' : ($group['id'] === 3 ? 'disabled' : '')) ?>>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.groupsLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<input type="hidden" name="perms[<?= $perm['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="perms[<?= $perm['id'] ?>]" value="1">
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary float-right"><?= lang('Admin.groupsNewSubmit') ?></button> <button type="submit" class="btn btn-primary float-right"><?= lang('Admin.groupsNewSubmit') ?></button>

32
app/Views/Admin/Groups/Show.php

@ -24,6 +24,38 @@
<label><?= lang('Admin.groupsLabelDefinition') ?></label> <label><?= lang('Admin.groupsLabelDefinition') ?></label>
<p><?= $group['definition'] ?></p> <p><?= $group['definition'] ?></p>
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputSubGroups"><?= lang('Admin.groupsLabelSubGroups') ?></label>
<?php foreach ($groups as $group): ?>
<?php if (! in_array(['subgroup_id' => $group['id']], $activeGroups)): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.groupsLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<?php if (! in_array(['perm_id' => $perm['id'], 'state' => 1], $activePerms)): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<a href="<?= site_url('admin/groups') ?>" class="btn btn-warning"><?= lang('Admin.groupsLinkBack') ?></a> <a href="<?= site_url('admin/groups') ?>" class="btn btn-warning"><?= lang('Admin.groupsLinkBack') ?></a>

4
app/Views/Admin/Perms/Home.php

@ -21,7 +21,7 @@
<table class="table mb-0"> <table class="table mb-0">
<thead> <thead>
<tr> <tr>
<th scope="col"><?= lang('Admin.permsLabelId') ?></th> <th scope="col" class="text-center"><?= lang('Admin.permsLabelId') ?></th>
<th scope="col"><?= lang('Admin.permsLabelName') ?></th> <th scope="col"><?= lang('Admin.permsLabelName') ?></th>
<th scope="col"><?= lang('Admin.permsLabelDefinition') ?></th> <th scope="col"><?= lang('Admin.permsLabelDefinition') ?></th>
<th scope="col"><?= lang('Admin.permsLabelCreatedAt') ?></th> <th scope="col"><?= lang('Admin.permsLabelCreatedAt') ?></th>
@ -32,7 +32,7 @@
<tbody> <tbody>
<?php foreach ($perms as $perm): ?> <?php foreach ($perms as $perm): ?>
<tr> <tr>
<th scope="row"><?= $perm['id'] ?></th> <th scope="row" class="text-center"><?= $perm['id'] ?></th>
<td><?= $perm['name'] ?></td> <td><?= $perm['name'] ?></td>
<td><?= $perm['definition'] ?></td> <td><?= $perm['definition'] ?></td>
<td><?= $perm['created_at'] ?></td> <td><?= $perm['created_at'] ?></td>

32
app/Views/Admin/Users/Delete.php

@ -25,6 +25,38 @@
<label><?= lang('Admin.usersLabelUsername') ?></label> <label><?= lang('Admin.usersLabelUsername') ?></label>
<p><?= $user['username'] ?></p> <p><?= $user['username'] ?></p>
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputSubGroups"><?= lang('Admin.usersLabelGroups') ?></label>
<?php foreach ($groups as $group): ?>
<?php if (! is_member($group['id'], $user['id'])): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.usersLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<?php if (! is_allowed($perm['id'], $user['id'])): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary float-right"><?= lang('Admin.usersDeleteSubmit') ?></button> <button type="submit" class="btn btn-primary float-right"><?= lang('Admin.usersDeleteSubmit') ?></button>

30
app/Views/Admin/Users/Edit.php

@ -46,6 +46,36 @@
<label for="inputPassword"><?= lang('Admin.usersLabelPassword') ?></label> <label for="inputPassword"><?= lang('Admin.usersLabelPassword') ?></label>
<input type="password" class="form-control" name="password" id="inputPassword" placeholder="<?= lang('Admin.usersLabelPassword') ?>"> <input type="password" class="form-control" name="password" id="inputPassword" placeholder="<?= lang('Admin.usersLabelPassword') ?>">
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputGroups"><?= lang('Admin.usersLabelGroups') ?></label>
<?php foreach ($groups as $group): ?>
<input type="hidden" name="groups[<?= $group['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="groups[<?= $group['id'] ?>]" value="1" <?= ($group['id'] === 2 ? 'checked disabled' : ($group['id'] === 3 ? 'disabled' : (is_member($group['id'], $user['id']) ? 'checked' : ''))) ?>>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.usersLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<input type="hidden" name="perms[<?= $perm['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="perms[<?= $perm['id'] ?>]" value="1" <?= (is_allowed($perm['id'], $user['id']) ? 'checked' : '') ?>>
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary float-right"><?= lang('Admin.usersEditSubmit') ?></button> <button type="submit" class="btn btn-primary float-right"><?= lang('Admin.usersEditSubmit') ?></button>

12
app/Views/Admin/Users/Home.php

@ -21,10 +21,12 @@
<table class="table mb-0"> <table class="table mb-0">
<thead> <thead>
<tr> <tr>
<th scope="col"><?= lang('Admin.usersLabelId') ?></th> <th scope="col" class="text-center"><?= lang('Admin.usersLabelId') ?></th>
<th scope="col"><?= lang('Admin.usersLabelEmail') ?></th> <th scope="col"><?= lang('Admin.usersLabelEmail') ?></th>
<th scope="col"><?= lang('Admin.usersLabelUsername') ?></th> <th scope="col"><?= lang('Admin.usersLabelUsername') ?></th>
<th scope="col"><?= lang('Admin.usersLabelBanned') ?></th> <th scope="col" class="text-center"><?= lang('Admin.usersLabelGroups') ?></th>
<th scope="col" class="text-center"><?= lang('Admin.usersLabelPerms') ?></th>
<th scope="col" class="text-center"><?= lang('Admin.usersLabelBanned') ?></th>
<th scope="col"><?= lang('Admin.usersLabelCreatedAt') ?></th> <th scope="col"><?= lang('Admin.usersLabelCreatedAt') ?></th>
<th scope="col"><?= lang('Admin.usersLabelUpdatedAt') ?></th> <th scope="col"><?= lang('Admin.usersLabelUpdatedAt') ?></th>
<th scope="col"><?= lang('Admin.usersLabelLastIPAddress') ?></th> <th scope="col"><?= lang('Admin.usersLabelLastIPAddress') ?></th>
@ -36,10 +38,12 @@
<tbody> <tbody>
<?php foreach ($users as $user): ?> <?php foreach ($users as $user): ?>
<tr> <tr>
<th scope="row"><?= $user['id'] ?></th> <th scope="row" class="text-center"><?= $user['id'] ?></th>
<td><?= $user['email'] ?></td> <td><?= $user['email'] ?></td>
<td><?= $user['username'] ?></td> <td><?= $user['username'] ?></td>
<td><?= $user['banned'] === 1 ? 'Yes' : 'No' ?></td> <td class="text-center"><?= count(get_user_groups($user['id'])) ?></td>
<td class="text-center"><?= count(get_user_perms($user['id'], 1)) ?></td>
<td class="text-center"><?= $user['banned'] === 1 ? 'Yes' : 'No' ?></td>
<td><?= $user['created_at'] ?></td> <td><?= $user['created_at'] ?></td>
<td><?= $user['updated_at'] ?></td> <td><?= $user['updated_at'] ?></td>
<td><?= $user['last_ip_address'] ?></td> <td><?= $user['last_ip_address'] ?></td>

30
app/Views/Admin/Users/New.php

@ -32,6 +32,36 @@
<label for="inputPassword"><?= lang('Admin.usersLabelPassword') ?></label> <label for="inputPassword"><?= lang('Admin.usersLabelPassword') ?></label>
<input type="password" class="form-control" name="password" id="inputPassword" placeholder="<?= lang('Admin.usersLabelPassword') ?>" required> <input type="password" class="form-control" name="password" id="inputPassword" placeholder="<?= lang('Admin.usersLabelPassword') ?>" required>
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputGroups"><?= lang('Admin.usersLabelGroups') ?></label>
<?php foreach ($groups as $group): ?>
<input type="hidden" name="groups[<?= $group['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="groups[<?= $group['id'] ?>]" value="1" <?= ($group['id'] === 2 ? 'checked disabled' : ($group['id'] === 3 ? 'disabled' : '')) ?>>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.usersLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<input type="hidden" name="perms[<?= $perm['id'] ?>]" value="0">
<div class="form-check">
<label>
<input type="checkbox" name="perms[<?= $perm['id'] ?>]" value="1">
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary float-right"><?= lang('Admin.usersNewSubmit') ?></button> <button type="submit" class="btn btn-primary float-right"><?= lang('Admin.usersNewSubmit') ?></button>

32
app/Views/Admin/Users/Show.php

@ -24,6 +24,38 @@
<label><?= lang('Admin.usersLabelUsername') ?></label> <label><?= lang('Admin.usersLabelUsername') ?></label>
<p><?= $user['username'] ?></p> <p><?= $user['username'] ?></p>
</div> </div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputSubGroups"><?= lang('Admin.usersLabelGroups') ?></label>
<?php foreach ($groups as $group): ?>
<?php if (! is_member($group['id'], $user['id'])): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $group['definition'] ?> (<?= $group['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPerms"><?= lang('Admin.usersLabelPerms') ?></label>
<?php foreach ($perms as $perm): ?>
<?php if (! is_allowed($perm['id'], $user['id'])): ?>
<?php continue; ?>
<?php endif; ?>
<div class="form-check">
<label>
<?= $perm['definition'] ?> (<?= $perm['name'] ?>)
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<a href="<?= site_url('admin/users') ?>" class="btn btn-warning"><?= lang('Admin.usersLinkBack') ?></a> <a href="<?= site_url('admin/users') ?>" class="btn btn-warning"><?= lang('Admin.usersLinkBack') ?></a>

4
public/assets/css/admin/groups/index.css

@ -0,0 +1,4 @@
.table thead td,
.table thead th {
border-top: none;
}

4
public/assets/css/admin/perms/index.css

@ -0,0 +1,4 @@
.table thead td,
.table thead th {
border-top: none;
}
Loading…
Cancel
Save