/** * 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"); } $Account = AbstractAccountType::loadFromSession($SessionRequest); $AccountEntry = AccountEntry::get($Account->getID()); $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-info inline', new HTMLElement('legend', 'legend-info', self::TITLE), new MapRenderer($AccountEntry)), new HTMLElement('fieldset', 'fieldset-manage inline', new HTMLElement('legend', 'legend-manage', "Manage Account"), $Account->getFieldSet($Request)->addClass('inline'), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update')), 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'))); $AffiliateQuery->addRowCallback(function (AccountAffiliationEntry $Affiliation) use($Account, $ApproveSelect) { if ($Affiliation->isAwaitingApproval()) { $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(AccountHome::getRequestURL(), "Account updated successfully. Redirecting...", 5); case 'approve': $affiliateID = $Form->validateField($Request, self::PARAM_APPROVE_AFFILIATE_ID); AccountAffiliationEntry::approveAffiliation($Request, $Account->getID(), $affiliateID); return new RedirectResponse(AccountHome::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, $Account->getID(), $affiliateID, $type); return new RedirectResponse(AccountHome::getRequestURL(), "Affiliation requested successfully. Redirecting...", 5); } throw new \InvalidArgumentException($submit); }
function getConfigFieldSet() { $FieldSet = new HTMLElement('fieldset', self::CLS_FIELDSET_CONFIG . ' inline', new Attributes('data-' . static::PARAM_PRODUCT_TYPE, $this->getTypeName()), new HTMLElement('legend', 'legend-shipping', "Configure Product"), new HTMLElement('label', 'label-' . self::PARAM_PRODUCT_TITLE, "Product Title<br/>", new HTMLInputField(self::PARAM_PRODUCT_TITLE, $this->title, new Attributes('placeholder', '"My Product - $9.99"'), new RequiredValidation())), "<br/><br/>", new HTMLElement('label', 'label-' . self::PARAM_PRODUCT_TOTAL_COST, "Total Cost<br/>", new HTMLInputField(self::PARAM_PRODUCT_TOTAL_COST, $this->total, new Attributes('placeholder', '"9.99"'), new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Choose Wallet Types(s)<br/>", $SourceSelect = new HTMLSelectField(self::PARAM_PAYMENT_WALLET_TYPES . '[]', new Attributes('multiple', 'multiple')))); foreach (AbstractWallet::loadAllWalletTypes() as $WalletType) { $SourceSelect->addOption($WalletType::ID_FLAG, $WalletType->getDescription()); if ($WalletType::ID_FLAG & $this->wallet_flags) { $SourceSelect->select($WalletType::ID_FLAG); } } return $FieldSet; }