commit 9a2a2e446d93f4d99e18c113e55ac5fd10a23805 from: Tracey Emery date: Fri May 13 14:40:11 2022 UTC finish up delete company code commit - b054d1a5226e7486f83b40732a25879911d3e12f commit + 9a2a2e446d93f4d99e18c113e55ac5fd10a23805 blob - aad3da897ec4aecee80ff73eab03c673bcc504ba blob + 7418fa0ea05584d877bae7189fcf0f883a42ebb4 --- module/Securitx/src/Controller/SecuritxController.php +++ module/Securitx/src/Controller/SecuritxController.php @@ -12,6 +12,8 @@ use Securitx\Model\Emailer; use Securitx\Form\MemberForm; use Securitx\Form\UploaderForm; use Securitx\Form\CompanyForm; +use Securitx\Form\CompanyEditForm; +use Securitx\Form\CompanyDeleteForm; use Securitx\Form\ForgotForm; use Securitx\Form\SendForm; use Securitx\Form\TwofaForm; @@ -160,18 +162,23 @@ ret: ); } if ($_GET) { - if (array_key_exists('add', $_GET)) + $companies = ''; + if (array_key_exists('add', $_GET)) { + $form = new CompanyForm(); $action = "add"; - else if (array_key_exists('edit', $_GET)) + } else if (array_key_exists('edit', $_GET)) { + $form = new CompanyEditForm(); + $companies = $this->company_table->fetchAll(); $action = "edit"; - else if (array_key_exists('delete', $_GET)) + } else if (array_key_exists('delete', $_GET)) { + $form = new CompanyDeleteForm(); + $companies = $this->company_table->fetchAll(); $action = "delete"; - else + } else goto ret; $count = $this->company_table->getCount(); if ($count == 1 && $action == "delete") goto ret; - $form = new CompanyForm(); $request = $this->getRequest(); if (!$request->isPost()) { return new ViewModel([ @@ -182,10 +189,12 @@ ret: 'completed' => false, 'valid_domain' => '', 'valid_phone' => '', + 'companies' => $companies, ]); } $company = new Company(); - $form->setInputFilter($company->getInputFilter()); + if ($action != "delete") + $form->setInputFilter($company->getInputFilter()); $form->setData($request->getPost()); if (!$form->isValid()) { return new ViewModel([ @@ -214,7 +223,55 @@ ret: 'valid_phone' => '', ]); } - + if ($action == "delete") { + $cd = $this->company_table->getCompany( + $company->company_id + ); + if ($cd == null) + goto ret; + $members = $this->member_table->getMembersByCompany( + $cd->company_id + ); + $cfolder = realpath(getcwd()) . "/data/uploads/" . + $cd->short; + $cdls = $this->downloads_table->getCDownloads( + $cd->company_id + ); + foreach ($cdls as $cdl) { + $file = $cfolder . "/" . $cdl . ".pdf"; + if (file_exists($file)) + unlink($file); + } + if (is_dir($cfolder)) + rmdir($cfolder); + $this->company_table->deleteCompany($cd->company_id); + foreach ($members as $member) { + $folder = realpath(getcwd()) . + "/data/downloads/" . $member->u_key; + $dls = $this->downloads_table->getDownloads( + $member->u_key + ); + foreach($dls as $dl) { + $file = $folder . "/" . + $dl->id_key . ".pdf"; + if (file_exists($file)) + unlink($file); + $this->downloads_table->deleteDownload( + $dl->downloads_id + ); + } + if (is_dir($folder)) + rmdir($folder); + $this->member_table->deleteMember( + $member->id + ); + } + return new ViewModel([ + 'member' => $member, + 'action' => 'deleted', + 'completed' => true, + ]); + } $phone_validator = new PhoneNumber([ 'country' => 'US', 'allow_possible' => true, @@ -809,7 +866,8 @@ skip: ip_address TEXT, twofa INTEGER, twofa_moddate INTEGER, - phone INTEGER + phone INTEGER, + blocked INTEGER ) ', Adapter::QUERY_MODE_EXECUTE); $adapter->query(' blob - /dev/null blob + 9acc2016f02af13d01eae289bae80c1fb0694a6e (mode 644) --- /dev/null +++ module/Securitx/src/Form/CompanyDeleteForm.php @@ -0,0 +1,29 @@ +add([ + 'name' => 'company_id', + 'type' => 'select', + 'options' => [ + 'label' => 'Select Company', + 'disable_inarray_validator' => true, + ], + ]); + $this->add([ + 'name' => 'submit', + 'type' => 'submit', + 'attributes' => [ + 'value' => 'Delete Company', + 'id' => 'submitbutton', + ], + ]); + } +} blob - /dev/null blob + 1103f6b13f7976ac83ac5e2d82a74a9730a3f3de (mode 644) --- /dev/null +++ module/Securitx/src/Form/CompanyEditForm.php @@ -0,0 +1,70 @@ +add([ + 'name' => 'name', + 'type' => 'text', + 'options' => [ + 'label' => 'Company Name', + ], + ]); + $this->add([ + 'name' => 'short', + 'type' => 'text', + 'options' => [ + 'label' => 'Two Letter Short Name', + ], + ]); + $this->add([ + 'name' => 'domain', + 'type' => 'text', + 'options' => [ + 'label' => 'Company\'s Email Domain', + ], + ]); + $this->add([ + 'name' => 'phone', + 'type' => Element\Tel::class, + 'options' => [ + 'label' => 'Company\'s Primary Phone Number', + ], + ]); + $this->add([ + 'name' => 'downloads', + 'type' => 'checkbox', + 'options' => [ + 'label' => 'Enable Browser Downloads', + 'use_hidden_element' => true, + 'checked_value' => '1', + 'unchecked_value' => '0', + ], + 'attributes' => [ + 'value' => '0', + ], + ]); + $this->add([ + 'name' => 'company_id', + 'type' => 'select', + 'options' => [ + 'label' => 'Select Company', + 'disable_inarray_validator' => true, + ], + ]); + $this->add([ + 'name' => 'submit', + 'type' => 'submit', + 'attributes' => [ + 'value' => 'Edit Company', + 'id' => 'submitbutton', + ], + ]); + } +} blob - 96d3700440caa5e8befc636e971dda74ab547be5 blob + e6027752d4dce42d191004527811471dc7a6e6a5 --- module/Securitx/src/Model/CompanyTable.php +++ module/Securitx/src/Model/CompanyTable.php @@ -21,14 +21,16 @@ class CompanyTable { $rowset = $this->tableGateway->select(['company_id' => $id]); $row = $rowset->current(); if (!$row) { - throw new RuntimeException(sprintf( - 'Could not find company row with id %d', $id)); + return null; } return $row; } public function getShortCount($id) { return $this->tableGateway->select(['short' => $id])->count(); } + public function deleteCompany($id) { + return $this->tableGateway->delete(['company_id' => $id]); + } public function saveCompany(Company $company) { $data = [ 'name' => $company->name, blob - 42e103e5bba7af58d62129703c67263662742287 blob + 3b5c0b12b18be757ba05fac22f346a0a372e08dd --- module/Securitx/src/Model/DownloadsTable.php +++ module/Securitx/src/Model/DownloadsTable.php @@ -40,6 +40,9 @@ class DownloadsTable { 'company_id' =>$c_id, ]); } + public function deleteDownload($id) { + return $this->tableGateway->delete(['downloads_id' => $id]); + } public function saveDownload(Downloads $download) { $data = [ 'moddate' => $download->moddate, blob - 88004f2672ed8a2ded98511352c159f97a23f996 blob + e745f192a812b751ffef79c828bd4f2f09b97306 --- module/Securitx/src/Model/MemberTable.php +++ module/Securitx/src/Model/MemberTable.php @@ -61,6 +61,9 @@ class MemberTable { $row = $rowset->current(); return $row; } + public function getMembersByCompany($c_id) { + return $this->tableGateway->select(['company_id' => $c_id]); + } public function saveMember(Member $member) { $data = [ 'first' => $member->first, @@ -97,7 +100,7 @@ class MemberTable { $this->tableGateway->update($data, ['id' => $id]); } - public function deleteMember(SecuritX $member) { + public function deleteMember($id) { $this->tableGateway->delete(['id' => (int)$id]); } } blob - 44a064ee70b5f0ffa8d3cb9bca2bbc261eb9ff88 blob + 37c9fb7cb3108cce4a438d776c6c6a85279f3791 --- module/Securitx/view/securitx/companies/companies.phtml +++ module/Securitx/view/securitx/companies/companies.phtml @@ -13,10 +13,63 @@ goto done; } ?> -

Hello, first ?>.
Here, you can a company.

+

Hello, first ?>.
Here, you can a company.
The primary company can not be deleted.


+ $company->company_id, + 'label' => $this->escapeHtml($company->name), + ]; + array_push($co_opts, $co_opt); + } + $cnt = 1; + } + $company_id = $form->get('company_id'); + $company_id->setAttribute('class', 'form-control'); + $company_id->setAttribute('placeholder', 'Select Company'); + $company_id->setValueOptions($co_opts); + + $submit = $form->get('submit'); + $submit->setAttribute('class', 'btn btn-primary'); + + $form->setAttribute('action', $this->url('securitx', [ + 'action' => 'companies', + 'id' => $member->u_key, + ], + [ + 'query' => [ + $action => '', + ] + ])); + echo $this->form()->openTag($form); +?> +
+ formLabel($company_id) ?> + formElement($company_id) ?> + formElementErrors()->render($company_id, + ['class' => 'help-block']) ?> +
+
+ + WARNING!!! Deleting a company is not reversible!
+ WARNING!!! This action will delete the company and all of its files!
+ WARNING!!! This action will delete all company members and their files!
+ WARNING!!! Make a backup of your database and files before proceeding if you want to recover!
+ WARNING!!! Pressing the 'Delete Company' button will not ask for a confirmation!

+
+formSubmit($form->get('submit')); + echo $this->form()->closeTag(); + goto done; + } $name = $form->get('name'); $name->setAttribute('class', 'form-control'); $name->setAttribute('placeholder', 'Company Name');