public function execute($request)
 {
     $this->form = new sfForm();
     $this->culture = $this->context->user->getCulture();
     $this->globalForm = new SettingsGlobalForm();
     $this->siteInformationForm = new SettingsSiteInformationForm();
     $this->defaultTemplateForm = new SettingsDefaultTemplateForm();
     $this->uiLabelForm = new SettingsGenericForm(array(), array('settings' => QubitSetting::getByScope('ui_label'), 'scope' => 'ui_label', 'fieldsRequired' => false));
     $this->oaiRepositoryForm = new SettingsOaiRepositoryForm();
     $this->initializeDefaultPageElementsForm();
     // Handle POST data (form submit)
     if ($request->isMethod('post')) {
         // Clean cache
         $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings'));
         $cache->clean();
         // Global settings form submission
         if (null !== $request->global_settings) {
             // Hack to populate "version" field so it displays
             // if validation fails. By default, their values are not included in
             // $request->parameterHolder (and thus are not bound) because their
             // <input> field is disabled.
             $version = null !== ($setting = QubitSetting::getSettingByName('version')) ? $setting->getValue(array('sourceCulture' => true)) : null;
             $this->globalForm->bind(array_merge($request->global_settings, array('version' => $version)));
             if ($this->globalForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateGlobalSettings();
                 $this->redirect('settings/list');
             }
         }
         // Handle site information form submission
         if (null !== $request->site_information) {
             $this->siteInformationForm->bind($request->site_information);
             if ($this->siteInformationForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateSiteInformationSettings();
                 $this->redirect('settings/list');
             }
         }
         // Handle default template form submission
         if (null !== $request->default_template) {
             $this->defaultTemplateForm->bind($request->default_template);
             if ($this->defaultTemplateForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateDefaultTemplateSettings($this->defaultTemplateForm);
                 $this->redirect('settings/list');
             }
         }
         // Handle default template form submission
         if (null !== $request->ui_label) {
             $this->uiLabelForm->bind($request->ui_label);
             if ($this->uiLabelForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateUiLabelSettings($this->uiLabelForm);
                 $this->redirect('settings/list');
             }
         }
         // Handle OAI Repository form submission
         if (null !== $request->oai_repository) {
             $this->oaiRepositoryForm->bind($request->oai_repository);
             if ($this->oaiRepositoryForm->isValid()) {
                 // Do update and redirect to avoid repeat submit wackiness
                 $this->updateOaiRepositorySettings($this->oaiRepositoryForm);
                 $this->redirect('settings/list');
             }
         }
         if (null !== ($languageCode = $request->languageCode)) {
             try {
                 format_language($languageCode, $languageCode);
             } catch (Exception $e) {
                 $this->redirect(array('module' => 'settings', 'action' => 'list'));
             }
             $setting = new QubitSetting();
             $setting->name = $languageCode;
             $setting->scope = 'i18n_languages';
             $setting->value = $languageCode;
             $setting->deleteable = true;
             $setting->editable = true;
             $setting->getCurrentSettingI18n()->setCulture('en');
             $setting->sourceCulture = 'en';
             $setting->save();
         }
     }
     // Populate forms
     $this->populateGlobalForm();
     $this->populateSiteInformationForm();
     $this->populateDefaultTemplateForm($this->defaultTemplateForm);
     $this->populateUiLabelForm($this->uiLabelForm);
     $this->populateOaiRepositoryForm($this->oaiRepositoryForm);
     // Last symfony 1.0 forms holdout
     $this->i18nLanguages = QubitSetting::getByScope('i18n_languages');
     $this->form->setValidator('languageCode', new sfValidatorI18nChoiceLanguage());
     $this->form->setWidget('languageCode', new sfWidgetFormI18nChoiceLanguage(array('add_empty' => true, 'culture' => $this->context->user->getCulture())));
     // make vars available to template
     $this->availableLanguages = self::$availableLanguges;
 }