Tiny updates to the control panel

This commit is contained in:
Pinga 2023-08-28 22:19:39 +03:00
parent 29400f319f
commit 4abca19ba3
7 changed files with 229 additions and 25 deletions

View file

@ -2,7 +2,7 @@
namespace App\Controllers; namespace App\Controllers;
use App\Models\User; use App\Models\Contact;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
@ -11,9 +11,8 @@ class ContactsController extends Controller
{ {
public function view(Request $request, Response $response) public function view(Request $request, Response $response)
{ {
$userModel = new User($this->container->get('db')); $contactModel = new Contact($this->container->get('db'));
$users = $userModel->getAllUsers(); $contacts = $contactModel->getAllContact();
return view($response,'admin/contacts/index.twig', compact('users')); return view($response,'admin/contacts/index.twig', compact('contacts'));
} }
}
}

View file

@ -2,7 +2,7 @@
namespace App\Controllers; namespace App\Controllers;
use App\Models\User; use App\Models\Host;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
@ -11,9 +11,8 @@ class HostsController extends Controller
{ {
public function view(Request $request, Response $response) public function view(Request $request, Response $response)
{ {
$userModel = new User($this->container->get('db')); $hostsModel = new Host($this->container->get('db'));
$users = $userModel->getAllUsers(); $hosts = $hostsModel->getAllHost();
return view($response,'admin/hosts/index.twig', compact('users')); return view($response,'admin/hosts/index.twig', compact('hosts'));
} }
}
}

55
cp/app/Models/Contact.php Normal file
View file

@ -0,0 +1,55 @@
<?php
namespace App\Models;
use Pinga\Db\PdoDatabase;
class Contact
{
private PdoDatabase $db;
public function __construct(PdoDatabase $db)
{
$this->db = $db;
}
public function getAllContact()
{
$sql = "
SELECT
contact.*,
postalInfo.*,
status.status AS contact_status,
CASE WHEN EXISTS (
SELECT 1 FROM domain_contact_map WHERE domain_contact_map.contact_id = contact.id
) THEN 1 ELSE 0 END AS has_domain_contact_mapping
FROM contact
LEFT JOIN contact_postalInfo AS postalInfo ON contact.id = postalInfo.contact_id
LEFT JOIN contact_status AS status ON contact.id = status.contact_id
";
return $this->db->select($sql);
}
public function getContactById($id)
{
$sql = "
SELECT
contact.*,
postalInfo.*,
status.status AS contact_status
FROM contact
LEFT JOIN contact_postalInfo AS postalInfo ON contact.id = postalInfo.contact_id
LEFT JOIN contact_status AS status ON contact.id = status.contact_id
WHERE contact.id = ?
";
return $this->db->select($sql, [$id])->fetch();
}
public function deleteContact($id)
{
$this->db->delete('DELETE FROM contact WHERE id = ?', [$id]);
return true;
}
}

49
cp/app/Models/Domain.php Normal file
View file

@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Pinga\Db\PdoDatabase;
class Domain
{
private PdoDatabase $db;
public function __construct(PdoDatabase $db)
{
$this->db = $db;
}
public function getAllDomain()
{
return $this->db->select('SELECT * FROM domain');
}
public function getDomainById($id)
{
return $this->db->select('SELECT * FROM domain WHERE id = ?', [$id])->fetch();
}
public function createDomain($id, $name, $tldid, $registrant, $crdate, $exdate, $update, $clid, $crid, $upid, $trdate, $trstatus, $reid, $redate, $acid, $acdate, $transfer_exdate, $idnlang, $delTime, $resTime, $rgpstatus, $rgppostData, $rgpdelTime, $rgpresTime, $rgpresReason, $rgpstatement1, $rgpstatement2, $rgpother, $addPeriod, $autoRenewPeriod, $renewPeriod, $transferPeriod, $renewedDate)
{
$id = $this->db->quote($id), $name = $this->db->quote($name), $tldid = $this->db->quote($tldid), $registrant = $this->db->quote($registrant), $crdate = $this->db->quote($crdate), $exdate = $this->db->quote($exdate), $update = $this->db->quote($update), $clid = $this->db->quote($clid), $crid = $this->db->quote($crid), $upid = $this->db->quote($upid), $trdate = $this->db->quote($trdate), $trstatus = $this->db->quote($trstatus), $reid = $this->db->quote($reid), $redate = $this->db->quote($redate), $acid = $this->db->quote($acid), $acdate = $this->db->quote($acdate), $transfer_exdate = $this->db->quote($transfer_exdate), $idnlang = $this->db->quote($idnlang), $delTime = $this->db->quote($delTime), $resTime = $this->db->quote($resTime), $rgpstatus = $this->db->quote($rgpstatus), $rgppostData = $this->db->quote($rgppostData), $rgpdelTime = $this->db->quote($rgpdelTime), $rgpresTime = $this->db->quote($rgpresTime), $rgpresReason = $this->db->quote($rgpresReason), $rgpstatement1 = $this->db->quote($rgpstatement1), $rgpstatement2 = $this->db->quote($rgpstatement2), $rgpother = $this->db->quote($rgpother), $addPeriod = $this->db->quote($addPeriod), $autoRenewPeriod = $this->db->quote($autoRenewPeriod), $renewPeriod = $this->db->quote($renewPeriod), $transferPeriod = $this->db->quote($transferPeriod), $renewedDate = $this->db->quote($renewedDate)
$this->db->insert('INSERT INTO domain (id, name, tldid, registrant, crdate, exdate, update, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, transfer_exdate, idnlang, delTime, resTime, rgpstatus, rgppostData, rgpdelTime, rgpresTime, rgpresReason, rgpstatement1, rgpstatement2, rgpother, addPeriod, autoRenewPeriod, renewPeriod, transferPeriod, renewedDate) VALUES ($id, $name, $tldid, $registrant, $crdate, $exdate, $update, $clid, $crid, $upid, $trdate, $trstatus, $reid, $redate, $acid, $acdate, $transfer_exdate, $idnlang, $delTime, $resTime, $rgpstatus, $rgppostData, $rgpdelTime, $rgpresTime, $rgpresReason, $rgpstatement1, $rgpstatement2, $rgpother, $addPeriod, $autoRenewPeriod, $renewPeriod, $transferPeriod, $renewedDate)');
return $this->db->lastInsertId();
}
public function updateDomain($id, $id, $name, $tldid, $registrant, $crdate, $exdate, $update, $clid, $crid, $upid, $trdate, $trstatus, $reid, $redate, $acid, $acdate, $transfer_exdate, $idnlang, $delTime, $resTime, $rgpstatus, $rgppostData, $rgpdelTime, $rgpresTime, $rgpresReason, $rgpstatement1, $rgpstatement2, $rgpother, $addPeriod, $autoRenewPeriod, $renewPeriod, $transferPeriod, $renewedDate)
{
$id = $this->db->quote($id), $name = $this->db->quote($name), $tldid = $this->db->quote($tldid), $registrant = $this->db->quote($registrant), $crdate = $this->db->quote($crdate), $exdate = $this->db->quote($exdate), $update = $this->db->quote($update), $clid = $this->db->quote($clid), $crid = $this->db->quote($crid), $upid = $this->db->quote($upid), $trdate = $this->db->quote($trdate), $trstatus = $this->db->quote($trstatus), $reid = $this->db->quote($reid), $redate = $this->db->quote($redate), $acid = $this->db->quote($acid), $acdate = $this->db->quote($acdate), $transfer_exdate = $this->db->quote($transfer_exdate), $idnlang = $this->db->quote($idnlang), $delTime = $this->db->quote($delTime), $resTime = $this->db->quote($resTime), $rgpstatus = $this->db->quote($rgpstatus), $rgppostData = $this->db->quote($rgppostData), $rgpdelTime = $this->db->quote($rgpdelTime), $rgpresTime = $this->db->quote($rgpresTime), $rgpresReason = $this->db->quote($rgpresReason), $rgpstatement1 = $this->db->quote($rgpstatement1), $rgpstatement2 = $this->db->quote($rgpstatement2), $rgpother = $this->db->quote($rgpother), $addPeriod = $this->db->quote($addPeriod), $autoRenewPeriod = $this->db->quote($autoRenewPeriod), $renewPeriod = $this->db->quote($renewPeriod), $transferPeriod = $this->db->quote($transferPeriod), $renewedDate = $this->db->quote($renewedDate)
$this->db->update('UPDATE domain SET id = $id, name = $name, tldid = $tldid, registrant = $registrant, crdate = $crdate, exdate = $exdate, update = $update, clid = $clid, crid = $crid, upid = $upid, trdate = $trdate, trstatus = $trstatus, reid = $reid, redate = $redate, acid = $acid, acdate = $acdate, transfer_exdate = $transfer_exdate, idnlang = $idnlang, delTime = $delTime, resTime = $resTime, rgpstatus = $rgpstatus, rgppostData = $rgppostData, rgpdelTime = $rgpdelTime, rgpresTime = $rgpresTime, rgpresReason = $rgpresReason, rgpstatement1 = $rgpstatement1, rgpstatement2 = $rgpstatement2, rgpother = $rgpother, addPeriod = $addPeriod, autoRenewPeriod = $autoRenewPeriod, renewPeriod = $renewPeriod, transferPeriod = $transferPeriod, renewedDate = $renewedDate WHERE id = ?', [$id]);
return true;
}
public function deleteDomain($id)
{
$this->db->delete('DELETE FROM domain WHERE id = ?', [$id]);
return true;
}
}

59
cp/app/Models/Host.php Normal file
View file

@ -0,0 +1,59 @@
<?php
namespace App\Models;
use Pinga\Db\PdoDatabase;
class Host
{
private PdoDatabase $db;
public function __construct(PdoDatabase $db)
{
$this->db = $db;
}
public function getAllHost()
{
$sql = "
SELECT
host.*,
addr.addr,
addr.ip,
status.status AS host_status,
CASE WHEN EXISTS (
SELECT 1 FROM domain_host_map WHERE domain_host_map.host_id = host.id
) THEN 1 ELSE 0 END AS has_domain_mapping
FROM host
LEFT JOIN host_addr AS addr ON host.id = addr.host_id
LEFT JOIN host_status AS status ON host.id = status.host_id
";
return $this->db->select($sql);
}
public function getHostById($id)
{
$sql = "
SELECT
host.*,
addr.addr,
addr.ip,
status.status AS host_status,
domainMap.domain_id
FROM host
LEFT JOIN host_addr AS addr ON host.id = addr.host_id
LEFT JOIN host_status AS status ON host.id = status.host_id
LEFT JOIN domain_host_map AS domainMap ON host.id = domainMap.host_id
WHERE host.id = ?
";
return $this->db->select($sql, [$id])->fetch();
}
public function deleteHost($id)
{
$this->db->delete('DELETE FROM host WHERE id = ?', [$id]);
return true;
}
}

View file

@ -45,19 +45,40 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div id="table-default" class="table-responsive"> <div id="table-default" class="table-responsive">
<table id="contactTable" class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th><button class="table-sort" data-sort="sort-id">ID</button></th> <th><button class="table-sort" data-sort="sort-email">Identifier</button></th>
<th><button class="table-sort" data-sort="sort-email">Email</button></th> <th><button class="table-sort" data-sort="sort-crdate">Name</button></th>
<th><button class="table-sort" data-sort="sort-crdate">Creation Date</button></th> <th><button class="table-sort" data-sort="sort-registrar">Email</button></th>
<th><button class="table-sort" data-sort="sort-registrar">Registrar</button></th>
<th><button class="table-sort" data-sort="sort-status">Status</button></th> <th><button class="table-sort" data-sort="sort-status">Status</button></th>
<th><button class="table-sort" data-sort="sort-status">Associated</button></th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody class="table-tbody"> <tbody class="table-tbody">
<!-- Rows will be added here dynamically --> {% for contact in contacts %}
<tr>
<td>{{ contact.identifier }}</td>
<td>{{ contact.name }}</td>
<td>{{ contact.email }}</td>
<td>{{ contact.contact_status }}</td>
<td>{{ contact.has_domain_contact_mapping }}</td>
<td class="text-end">
<span class="dropdown">
<button class="btn dropdown-toggle align-text-top" data-bs-boundary="viewport" data-bs-toggle="dropdown">Actions</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item" href="#">
Action
</a>
<a class="dropdown-item" href="#">
Another action
</a>
</div>
</span>
</td>
</tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>

View file

@ -45,18 +45,40 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div id="table-default" class="table-responsive"> <div id="table-default" class="table-responsive">
<table id="hostTable" class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th><button class="table-sort" data-sort="sort-id">ID</button></th> <th><button class="table-sort" data-sort="sort-id">Host Name</button></th>
<th><button class="table-sort" data-sort="sort-name">Name</button></th> <th><button class="table-sort" data-sort="sort-name">IP Addresses</button></th>
<th><button class="table-sort" data-sort="sort-crdate">Creation Date</button></th> <th><button class="table-sort" data-sort="sort-name">Creation Date</button></th>
<th><button class="table-sort" data-sort="sort-status">Status</button></th> <th><button class="table-sort" data-sort="sort-crdate">Status</button></th>
<th><button class="table-sort" data-sort="sort-status">Associated</button></th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody class="table-tbody"> <tbody class="table-tbody">
<!-- Rows will be added here dynamically --> {% for host in hosts %}
<tr>
<td><strong>{{ host.name }}</strong></td>
<td>{{ host.addr }}</td>
<td>{{ host.crdate }}</td>
<td>{{ host.host_status }}</td>
<td>{{ host.has_domain_mapping }}</td>
<td class="text-end">
<span class="dropdown">
<button class="btn dropdown-toggle align-text-top" data-bs-boundary="viewport" data-bs-toggle="dropdown">Actions</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item" href="#">
Action
</a>
<a class="dropdown-item" href="#">
Another action
</a>
</div>
</span>
</td>
</tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>