diff --git a/cp/app/Controllers/ContactsController.php b/cp/app/Controllers/ContactsController.php index 162f2fd..1b6a230 100644 --- a/cp/app/Controllers/ContactsController.php +++ b/cp/app/Controllers/ContactsController.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use App\Models\User; +use App\Models\Contact; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Container\ContainerInterface; @@ -11,9 +11,8 @@ class ContactsController extends Controller { public function view(Request $request, Response $response) { - $userModel = new User($this->container->get('db')); - $users = $userModel->getAllUsers(); - return view($response,'admin/contacts/index.twig', compact('users')); + $contactModel = new Contact($this->container->get('db')); + $contacts = $contactModel->getAllContact(); + return view($response,'admin/contacts/index.twig', compact('contacts')); } - -} +} \ No newline at end of file diff --git a/cp/app/Controllers/HostsController.php b/cp/app/Controllers/HostsController.php index cacbec3..811a158 100644 --- a/cp/app/Controllers/HostsController.php +++ b/cp/app/Controllers/HostsController.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use App\Models\User; +use App\Models\Host; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Container\ContainerInterface; @@ -11,9 +11,8 @@ class HostsController extends Controller { public function view(Request $request, Response $response) { - $userModel = new User($this->container->get('db')); - $users = $userModel->getAllUsers(); - return view($response,'admin/hosts/index.twig', compact('users')); - } - -} + $hostsModel = new Host($this->container->get('db')); + $hosts = $hostsModel->getAllHost(); + return view($response,'admin/hosts/index.twig', compact('hosts')); + } +} \ No newline at end of file diff --git a/cp/app/Models/Contact.php b/cp/app/Models/Contact.php new file mode 100644 index 0000000..d3efddf --- /dev/null +++ b/cp/app/Models/Contact.php @@ -0,0 +1,55 @@ +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; + } +} \ No newline at end of file diff --git a/cp/app/Models/Domain.php b/cp/app/Models/Domain.php new file mode 100644 index 0000000..e653286 --- /dev/null +++ b/cp/app/Models/Domain.php @@ -0,0 +1,49 @@ +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; + } +} \ No newline at end of file diff --git a/cp/app/Models/Host.php b/cp/app/Models/Host.php new file mode 100644 index 0000000..52cd51c --- /dev/null +++ b/cp/app/Models/Host.php @@ -0,0 +1,59 @@ +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; + } +} \ No newline at end of file diff --git a/cp/resources/views/admin/contacts/index.twig b/cp/resources/views/admin/contacts/index.twig index ed41fef..330fdd8 100644 --- a/cp/resources/views/admin/contacts/index.twig +++ b/cp/resources/views/admin/contacts/index.twig @@ -45,19 +45,40 @@
- +
- - - - + + + + - + {% for contact in contacts %} + + + + + + + + + {% endfor %}
Actions
{{ contact.identifier }}{{ contact.name }}{{ contact.email }}{{ contact.contact_status }}{{ contact.has_domain_contact_mapping }} + + + + +
diff --git a/cp/resources/views/admin/hosts/index.twig b/cp/resources/views/admin/hosts/index.twig index 6da73d8..bea08e8 100644 --- a/cp/resources/views/admin/hosts/index.twig +++ b/cp/resources/views/admin/hosts/index.twig @@ -45,18 +45,40 @@
- +
- - - - + + + + + - + {% for host in hosts %} + + + + + + + + + {% endfor %}
Actions
{{ host.name }}{{ host.addr }}{{ host.crdate }}{{ host.host_status }}{{ host.has_domain_mapping }} + + + + +