/** * Handle processing the form when it's posted, such as saving and handling errors. */ protected function processPost() { // Process data as usual parent::processPost(); // ### Now manipulate the interface // Get currently saved account details $settings = TidySettings_getSettings($this->settingPrefix); // Only do check if we have access ID and secret ID. Code will handle hiding pro features // automatically if we can't get the account details. $accountDetails = false; if (isset($settings['stwwt_access_id']) && isset($settings['stwwt_secret_id'])) { $accountDetails = $this->checkAccountType($settings['stwwt_access_id'], $settings['stwwt_secret_id']); } // Check account level $accountLevel = 'invalid'; if (isset($accountDetails['account_type'])) { $accountLevel = $accountDetails['account_type']; } // Save the account details to the database for use later. TidySettings_saveSettings($accountDetails, STWWT_SETTINGS_KEY_ACCOUNT); // Set the account level in the interface if ($accountLevel == 'invalid') { $this->formObj->setElementHTML('stwwt_account_level', sprintf('<span class="stwwt_account_invalid"><span class="stwwt_account_level">Invalid</span> - please provide valid account details.</span>')); } else { $displayAcctName = ucwords($accountLevel); if ('Plus' == $displayAcctName) { $displayAcctName = 'PLUS'; } $this->formObj->setElementHTML('stwwt_account_level', sprintf('<span class="stwwt_account_level stwwt_account_%s">%s</span>', $accountLevel, $displayAcctName)); } if (!empty($this->paramList)) { // Look for any elements that have an account_level value. If that account level doesn't match the // desired account level, then that field doesn't get rendered. For all other fields, assume they // have account. foreach ($this->paramList as $fieldName => $fieldDetails) { // ### Check 1 - Account level required if (isset($fieldDetails['account_level']) && $fieldDetails['account_level']) { // Got a list of account levels? Copy them all over if (is_array($fieldDetails['account_level'])) { if (!in_array($accountLevel, $fieldDetails['account_level'])) { $this->removeElementDueToAccountLevel($fieldName, $fieldDetails); } } else { if ($fieldDetails['account_level'] != $accountLevel) { $this->removeElementDueToAccountLevel($fieldName, $fieldDetails); } } } // end if account level required // ### Check 2 - Check for account feature (independent of account level) if (isset($fieldDetails['account_feature']) && $fieldDetails['account_feature']) { $featureName = $fieldDetails['account_feature']; if (isset($accountDetails[$featureName]) && $accountDetails[$featureName] != 1 || $accountLevel == 'invalid') { $this->removeElementDueToAccountLevel($fieldName, $fieldDetails); } } } // end foreach } // end if (!empty($paramList)) }