commit - 25506a7ace5ab4f4f5df1d778be420b74500e607
commit + b054d1a5226e7486f83b40732a25879911d3e12f
blob - 65e90492c03c2df6cb502b1aae0c6d6d9308c417
blob + aad3da897ec4aecee80ff73eab03c673bcc504ba
--- module/Securitx/src/Controller/SecuritxController.php
+++ module/Securitx/src/Controller/SecuritxController.php
)
);
}
- 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())
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(
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
}
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
?>
<div class="jumbotron">
<h1 class="display-4">Welcome to SecuritX</h1>
+<?php if ($completed) { ?>
+ <p>Hello, <?= $member->first ?>.<br />The company has been <?= $action ?>.</p>
- <p>Congratulations! You've reached your SecuritX company editor!</p>
+ <hr class="my-4">
+
+<?php
+ goto done;
+ }
+?>
+ <p>Hello, <?= $member->first ?>.<br />Here, you can <?= $action ?> a company.</p>
+
<hr class="my-4">
+<?php
+ $name = $form->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);
+?>
+ <div class="form-group">
+ <?= $this->formLabel($name) ?>
+ <?= $this->formElement($name) ?>
+ <?= $this->formElementErrors()->render($name,
+ ['class' => 'help-block']) ?>
+ </div>
+
+ <div class="form-group">
+ <?= $this->formLabel($short) ?>
+ <?= $this->formElement($short) ?>
+ <?= $this->formElementErrors()->render($short,
+ ['class' => 'help-block']) ?>
+ <p style="color: red"><?= $exists ?></p>
+ </div>
+
+ <div class="form-group">
+ <?= $this->formLabel($phone) ?>
+ <?= $this->formElement($phone) ?>
+ <?= $this->formElementErrors()->render($phone,
+ ['class' => 'help-block']) ?>
+ <p style="color: red"><?= $valid_phone ?></p>
+ </div>
+
+ <div class="form-group">
+ <?= $this->formLabel($domain) ?>
+ <?= $this->formElement($domain) ?>
+ <?= $this->formElementErrors()->render($domain,
+ ['class' => 'help-block']) ?>
+ <p style="color: red"><?= $valid_domain ?></p>
+ </div>
+
+ <div class="form-group">
+ <?= $this->formLabel($downloads) ?> (if you plan to enable automatic file handling via other scripting, do not enable this)
+ <div class="form-group-left">
+ <?= $this->formElement($downloads) ?>
+ <?= $this->formElementErrors()->render($downloads,
+ ['class' => 'help-block']) ?>
+ </div>
+ </div>
+
+<?php
+ echo $this->formSubmit($form->get('submit'));
+ echo $this->form()->closeTag();
+done:
+?>
+ <br /><p><a class="a a-pad" href="/securitx/home/<?= $member->u_key ?>">Go home</a></p>
</div>
blob - 9167dc71ee9fc0b9ce5c6df5c0aff53fb2d4bf61
blob + ddcbd9e94688b0e3690d1932ba1863e217bd2f6a
--- module/Securitx/view/securitx/home/home.phtml
+++ module/Securitx/view/securitx/home/home.phtml
<p>SecuritX home of <?= $member->first ?> <?= $member->last ?></p>
- <hr class="my-4">
+ <hr class="my-4" \>
<?php if ($member->is_admin == 1) { ?>
<p><a class="btn btn-secondary btn-lg" href="/securitx/companies/<?= $member->u_key ?>?add">Add a company »</a></p>
<p><a class="btn btn-secondary btn-lg" href="/securitx/companies/<?= $member->u_key ?>?edit">Edit a company »</a></p>
+<?php if ($count > 1) { ?>
<p><a class="btn btn-secondary btn-lg" href="/securitx/companies/<?= $member->u_key ?>?delete">Delete a company »</a></p>
- <hr class="my-4" \>
-<?php } ?>
-<?php if ($member->is_admin == 1 || $member->is_editor == 1) { ?>
+<?php }
+ echo "<hr class='my-4' \>";
+ }
+ if ($member->is_admin == 1 || $member->is_editor == 1) { ?>
<p><a class="btn btn-secondary btn-lg" href="/securitx/invite/<?= $member->u_key ?>">Invite a member »</a></p>
<?php }
if ($member->is_admin == 1 || $member->is_editor == 1) { ?>