commit b054d1a5226e7486f83b40732a25879911d3e12f from: Tracey Emery date: Thu May 12 21:27:43 2022 UTC complete add a company code commit - 25506a7ace5ab4f4f5df1d778be420b74500e607 commit + b054d1a5226e7486f83b40732a25879911d3e12f blob - 65e90492c03c2df6cb502b1aae0c6d6d9308c417 blob + aad3da897ec4aecee80ff73eab03c673bcc504ba --- module/Securitx/src/Controller/SecuritxController.php +++ module/Securitx/src/Controller/SecuritxController.php @@ -159,7 +159,132 @@ ret: ) ); } - return new ViewModel(); + if ($_GET) { + if (array_key_exists('add', $_GET)) + $action = "add"; + else if (array_key_exists('edit', $_GET)) + $action = "edit"; + else if (array_key_exists('delete', $_GET)) + $action = "delete"; + 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([ + 'member' => $member, + 'action' => $action, + 'exists' => '', + 'form' => $form, + 'completed' => false, + 'valid_domain' => '', + 'valid_phone' => '', + ]); + } + $company = new Company(); + $form->setInputFilter($company->getInputFilter()); + $form->setData($request->getPost()); + if (!$form->isValid()) { + return new ViewModel([ + 'member' => $member, + 'action' => $action, + 'exists' => '', + 'form' => $form, + 'completed' => false, + 'valid_domain' => '', + 'valid_phone' => '', + ]); + } + + $company->exchangeArray($form->getData()); + $count = $this->company_table->getShortCount( + $company->short); + + if ($count) { + return new ViewModel([ + 'member' => $member, + 'action' => $action, + 'exists' => 'Short name already exists', + 'form' => $form, + 'completed' => false, + 'valid_domain' => '', + 'valid_phone' => '', + ]); + } + + $phone_validator = new PhoneNumber([ + 'country' => 'US', + 'allow_possible' => true, + ]); + $phone_test = preg_replace('/[\-\+\(\)\s]+/i', '', + $company->phone); + if (!$phone_validator->isValid($phone_test)) { + return new ViewModel([ + 'member' => $member, + 'action' => $action, + 'exists' => '', + 'form' => $form, + 'completed' => false, + 'valid_domain' => '', + 'valid_phone' => '', + ]); + } + + $validator = new Hostname([ + 'allow' => Hostname::ALLOW_DNS, + 'useMxCheck' => true, + 'useDeepMxCheck' => true, + 'useDomainCheck' => true, + ]); + $validator->setOptions([ + 'domain' => true, + ]); + + if (!$validator->isValid($company->domain)) { + return new ViewModel([ + 'member' => $member, + 'action' => $action, + 'exists' => '', + 'form' => $form, + 'completed' => false, + 'valid_domain' => '', + 'valid_phone' => '', + ]); + } + $this->company_table->saveCompany($company); + + if ($action == "add") { + $folder = realpath(getcwd()) . "/data/uploads/" . + $company->short; + if (!is_dir($folder)) + mkdir($folder, 0755, true); + return new ViewModel([ + 'member' => $member, + 'action' => 'added', + 'completed' => true, + ]); + } + if ($action == "delete") { + /* delete folder here */ + } +ret: + return $this->redirect()->toRoute('securitx', + array( + 'action' => 'home', + 'id' => $member->u_key, + ) + ); + } else { + return $this->redirect()->toRoute('securitx', + array( + 'action' => 'home', + 'id' => $member->u_key, + ) + ); + } } public function inviteAction() { if (!$this->checkAnyAdmin()) @@ -569,13 +694,13 @@ ret: if ($member->is_admin > 0 || $member->r_admin) goto skip; $member->r_admin = 1; - } - if (array_key_exists('r_editor', $_GET)) { + } else if (array_key_exists('r_editor', $_GET)) { $type = "editor"; if ($member->is_editor > 0 || $member->r_editor) goto skip; $member->r_editor = 1; - } + } else + goto skip; $emailer = new Emailer($this->email_host); foreach ($admins as $admin) { $url1 = $this->url()->fromRoute( @@ -636,13 +761,15 @@ skip: if ($company->downloads) if ($this->downloads_table->getCCount($member->company_id)) $c_has_downloads = 1; + $count = $this->company_table->getCount(); return new ViewModel([ 'member' => $member, 'company' => $company->name, 'c_downloads' => $c_has_downloads, 'inviter' => $inviter, 'has_downloads' => $has_downloads, - 'has_domain' => $has_domain + 'has_domain' => $has_domain, + 'count' => $count, ]); } public function indexAction() { blob - e78f5a16ac37c7c03a6024a7ee29984469f50075 blob + 96d3700440caa5e8befc636e971dda74ab547be5 --- module/Securitx/src/Model/CompanyTable.php +++ module/Securitx/src/Model/CompanyTable.php @@ -26,6 +26,9 @@ class CompanyTable { } return $row; } + public function getShortCount($id) { + return $this->tableGateway->select(['short' => $id])->count(); + } public function saveCompany(Company $company) { $data = [ 'name' => $company->name, blob - 689547663575d92cc65404fe2b6e305aa732c373 blob + 44a064ee70b5f0ffa8d3cb9bca2bbc261eb9ff88 --- module/Securitx/view/securitx/companies/companies.phtml +++ module/Securitx/view/securitx/companies/companies.phtml @@ -3,8 +3,102 @@ ?>

Welcome to SecuritX

+ +

Hello, first ?>.
The company has been .

-

Congratulations! You've reached your SecuritX company editor!

+
+ + +

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

+
+get('name'); + $name->setAttribute('class', 'form-control'); + $name->setAttribute('placeholder', 'Company Name'); + + $short = $form->get('short'); + $short->setAttribute('class', 'form-control'); + $short->setAttribute('placeholder', 'Short Name'); + + $domain = $form->get('domain'); + $domain->setAttribute('class', 'form-control'); + $domain->setAttribute('placeholder', 'Email Domain'); + + $phone = $form->get('phone'); + $phone->setAttribute('class', 'form-control'); + $phone->setAttribute('placeholder', 'Phone Number'); + + $downloads = $form->get('downloads'); + $downloads->setAttribute('class', 'form-control'); + $downloads->setAttribute('placeholder', + 'Enable Browser Downloads'); + + $submit = $form->get('submit'); + $submit->setAttribute('class', 'btn btn-primary'); + + + $form->setAttribute('action', $this->url('securitx', [ + 'action' => 'companies', + 'id' => $member->u_key, + ], + [ + 'query' => [ + $action => '', + ] + ])); + $form->prepare(); + + echo $this->form()->openTag($form); +?> +
+ formLabel($name) ?> + formElement($name) ?> + formElementErrors()->render($name, + ['class' => 'help-block']) ?> +
+ +
+ formLabel($short) ?> + formElement($short) ?> + formElementErrors()->render($short, + ['class' => 'help-block']) ?> +

+
+ +
+ formLabel($phone) ?> + formElement($phone) ?> + formElementErrors()->render($phone, + ['class' => 'help-block']) ?> +

+
+ +
+ formLabel($domain) ?> + formElement($domain) ?> + formElementErrors()->render($domain, + ['class' => 'help-block']) ?> +

+
+ +
+ formLabel($downloads) ?> (if you plan to enable automatic file handling via other scripting, do not enable this) +
+ formElement($downloads) ?> + formElementErrors()->render($downloads, + ['class' => 'help-block']) ?> +
+
+ +formSubmit($form->get('submit')); + echo $this->form()->closeTag(); +done: +?> +

Go home

blob - 9167dc71ee9fc0b9ce5c6df5c0aff53fb2d4bf61 blob + ddcbd9e94688b0e3690d1932ba1863e217bd2f6a --- module/Securitx/view/securitx/home/home.phtml +++ module/Securitx/view/securitx/home/home.phtml @@ -6,14 +6,16 @@

SecuritX home of first ?> last ?>

-
+
is_admin == 1) { ?>

Add a company »

Edit a company »

+ 1) { ?>

Delete a company »

-
- -is_admin == 1 || $member->is_editor == 1) { ?> +"; + } + if ($member->is_admin == 1 || $member->is_editor == 1) { ?>

Invite a member »

is_admin == 1 || $member->is_editor == 1) { ?>