Esempio n. 1
0
 /**
  * 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);
 }