/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-create-account', new HTMLElement('legend', 'legend-account', self::TITLE), new HTMLElement('label', null, "Choose a Account Type<br/>", new HTMLInputField(self::PARAM_ACCOUNT_NAME, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Status<br/>", new HTMLInputField(self::PARAM_ACCOUNT_PASSWORD, null, 'password', new RequiredValidation())), "<br/><br/>Login:<br/>", new HTMLButton('submit', 'Login', 'submit')), "<br/>"); $Form->setFormValues($Request); if (!$Request instanceof IFormRequest) { return $Form; } $Form->validateRequest($Request); $AccountEntry = AccountEntry::search($Request[self::PARAM_ACCOUNT_NAME]); $Account = $AccountEntry->getAccount(); $Account->assertPassword($Request[self::PARAM_ACCOUNT_PASSWORD]); $Account->startSession($SessionRequest); return new RedirectResponse(ManageAccount::getRequestURL($AccountEntry->getID()), "Logged in successfully. Redirecting...", 5); }
/** * @param $key * @param $value * @param null $arg1 * @return bool if true, the value has been rendered, otherwise false */ function renderNamedValue($key, $value, $arg1 = null) { switch ($key) { case 'created': if ($value) { echo DateUtil::ago($value) . ' ago'; } return true; case 'status': echo "<span class='status'>", $arg1 ?: $value, "</span>"; return true; case 'amount': if ($value) { echo "<span class='amount'>", $value, "</span>"; } return true; case 'payment-source': case 'payment-source-id': $href = $this->domain . ltrim(ManagePaymentSource::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'transaction': case 'transaction-id': $href = $this->domain . ltrim(ManageTransaction::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'product': case 'product-id': $href = $this->domain . ltrim(ManageProduct::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'test-url': $href = $this->domain . ltrim($value, '/'); echo "<a href='{$href}'>Test</a>"; return true; case 'order-page-url': $href = $this->domain . ltrim($value, '/'); echo "<a href='{$href}'>Order Page</a>"; return true; case 'account': case 'affiliate': case 'account-id': $href = $this->domain . ltrim(ManageAccount::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'wallet-id': $href = $this->domain . ltrim(ManageWallet::getRequestURL($value), '/'); echo "<a href='{$href}'>", $value, "</a>"; return true; } return false; }
function getFeesFieldSet() { $Table = new AccountTable(); $Query = $Table->select(AccountTable::COLUMN_ID)->select(AccountTable::COLUMN_NAME)->select(AccountAffiliationTable::COLUMN_TYPE)->join(AccountAffiliationTable::TABLE_NAME, $Table::COLUMN_ID, AccountAffiliationTable::COLUMN_AFFILIATE_ID)->where(AccountAffiliationTable::COLUMN_ACCOUNT_ID, $this->getAccountID()); $FieldsetFees = new HTMLElement('fieldset', 'fieldset-fees inline', new HTMLElement('legend', 'legend-fees', "Product Rates and Fees"), new HTMLAnchor(ManageAccount::getRequestURL($this->getAccountID()), "Add Affiliates"), "<br/><br/>"); while ($row = $Query->fetch()) { list($accountID, $accountName, $accountType) = array_values($row); $accountTypeText = array_search($accountType, AccountAffiliationEntry::$TypeOptions); $FieldsetFees->addAll(new HTMLElement('label', 'label-' . self::PARAM_PRODUCT_FEE, "{$accountName} - {$accountTypeText}<br/>", new HTMLInputField(self::PARAM_PRODUCT_FEE . '[' . $accountID . ']', $this->fees[$accountID], new Attributes('placeholder', 'Set fee "9.99" or rate "%1.50"'), new RequiredValidation())), "<br/><br/>"); } return $FieldsetFees; }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $Account = AbstractAccountType::loadFromSession($SessionRequest); if ($Account instanceof ResellerAccount) { } else { if ($Account instanceof AdministratorAccount) { } else { throw new RequestException("Only resellers may create a new Account"); } } $accountOptions = array("Choose a Account Type" => null); /** @var AbstractAccountType[] $AccountTypes */ $AccountTypes = array(); $AccountForms = array(); foreach (Types\AbstractAccountType::loadAllAccountTypes() as $AccountType) { $AccountTypes[$AccountType->getTypeName()] = $AccountType; $FieldSet = $AccountType->getFieldSet($Request); $FieldSet->addClass($AccountType::CLS_FIELDSET_CHOOSE_ACCOUNT); $FieldSet->setAttribute('disabled', 'disabled'); $AccountForms[] = $FieldSet; $accountOptions[ucfirst($AccountType->getTypeName())] = $AccountType->getTypeName(); } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-create-account', new HTMLElement('legend', 'legend-account', self::TITLE), new HTMLElement('label', null, "Choose a Account Type<br/>", new HTMLSelectField(self::PARAM_ACCOUNT_TYPE, $accountOptions, new RequiredValidation())), "<br/><br/>", $AccountForms, "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>"); if (!$Request instanceof IFormRequest) { return $Form; } // $status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS); $accountType = $Form->validateField($Request, self::PARAM_ACCOUNT_TYPE); $ChosenAccount = $AccountTypes[$accountType]; $ChosenAccount->validateRequest($Request, $Form); $id = AccountEntry::create($Request, $ChosenAccount); AccountAffiliationEntry::setAffiliate($Request, $Account->getID(), $id, AccountAffiliationEntry::TYPE_RESELLER); return new RedirectResponse(ManageAccount::getRequestURL($id), "Account created successfully. Redirecting...", 5); }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws RequestException * @throws \CPath\Request\Validation\Exceptions\ValidationException * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $AccountEntry = AccountEntry::get($this->id); $Account = $AccountEntry->getAccount(); $AffiliateQuery = AccountAffiliationEntry::queryAccountAffiliates($Account->getID()); $AffiliateListTable = new HTMLPDOQueryTable($AffiliateQuery); $AffiliateListTable->addColumn('affiliate'); $AffiliateListTable->addColumn('type'); $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-manage inline', new HTMLElement('legend', 'legend-manage', self::TITLE), new HTMLInputField(self::PARAM_ID, $this->id, 'hidden'), new HTMLInputField(self::PARAM_ACCOUNT_TYPE, $Account->getTypeName(), 'hidden'), new HTMLElement('label', null, "Status<br/>", $SelectStatus = new HTMLSelectField(self::PARAM_ACCOUNT_STATUS, AccountEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", $Account->getFieldSet($Request), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update'), new HTMLButton(self::PARAM_SUBMIT, 'Delete', 'delete')), new HTMLElement('fieldset', 'fieldset-affiliates inline', new HTMLElement('legend', 'legend-affiliates', "Add affiliation"), "Account ID:<br/>", new HTMLInputField(self::PARAM_AFFILIATE_ID), "<br/><br/>Affiliation Type:<br/>", $TypeSelect = new HTMLSelectField(self::PARAM_AFFILIATE_TYPE, array("Request New Affiliate" => AccountAffiliationEntry::TYPE_REQUEST_AFFILIATE, "Request New Reseller" => AccountAffiliationEntry::TYPE_REQUEST_RESELLER, "Request New Processor" => AccountAffiliationEntry::TYPE_REQUEST_PROCESSOR)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Request', 'request')), new HTMLElement('fieldset', 'fieldset-affiliate-list inline', new HTMLElement('legend', 'legend-affiliate-list', "Affiliates"), $AffiliateListTable), new HTMLElement('fieldset', 'fieldset-affiliate-approve inline', new HTMLElement('legend', 'legend-affiliate-approve', "Approve Affiliates"), $ApproveSelect = new HTMLSelectField(self::PARAM_APPROVE_AFFILIATE_ID, array('Pending affiliate approvals' => null)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Approve', 'approve'))); $SelectStatus->setInputValue($AccountEntry->getStatus()); $Account = AbstractAccountType::loadFromSession($SessionRequest); if ($Account instanceof AdministratorAccount) { $TypeSelect->setOptions(AccountAffiliationEntry::$TypeOptions); } $AffiliateQuery->addRowCallback(function (AccountAffiliationEntry $Affiliation) use($Account, $ApproveSelect) { if ($Affiliation->getType() & $Affiliation::TYPE_REQUEST_RESELLER && $Affiliation->getAffiliateID() === $Account->getID()) { $ApproveSelect->addOption($Affiliation->getAffiliateID(), "Approve '" . $Affiliation->getTypeText() . "' - " . $Affiliation->getAffiliateID()); } }); if (!$Request instanceof IFormRequest) { return $Form; } $submit = $Request[self::PARAM_SUBMIT]; switch ($submit) { case 'update': $status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS); $AccountEntry->update($Request, $Account, $status); return new RedirectResponse(ManageAccount::getRequestURL($this->getAccountID()), "Account updated successfully. Redirecting...", 5); case 'delete': AccountEntry::delete($Request, $this->getAccountID()); return new RedirectResponse(SearchAccounts::getRequestURL(), "Account deleted successfully. Redirecting...", 5); case 'approve': $affiliateID = $Form->validateField($Request, self::PARAM_APPROVE_AFFILIATE_ID); AccountAffiliationEntry::approveAffiliation($Request, $this->getAccountID(), $affiliateID); return new RedirectResponse(SearchAccounts::getRequestURL(), "Account deleted successfully. Redirecting...", 5); case 'request': $affiliateID = $Form->validateField($Request, self::PARAM_AFFILIATE_ID); $type = $Form->validateField($Request, self::PARAM_AFFILIATE_TYPE); AccountAffiliationEntry::setAffiliate($Request, $this->getAccountID(), $affiliateID, $type); return new RedirectResponse(ManageAccount::getRequestURL($this->getAccountID()), "Affiliation requested successfully. Redirecting...", 5); } throw new \InvalidArgumentException($submit); }