00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class LanguageSettingsForm extends Form {
00021
00023 var $settings;
00024
00026 var $availableLocales;
00027
00031 function LanguageSettingsForm() {
00032 parent::Form('manager/languageSettings.tpl');
00033
00034 $this->settings = array(
00035 'supportedLocales' => 'object'
00036 );
00037
00038 $site = &Request::getSite();
00039 $this->availableLocales = $site->getSupportedLocales();
00040
00041 $localeCheck = create_function('$locale,$availableLocales', 'return in_array($locale,$availableLocales);');
00042
00043
00044 $this->addCheck(new FormValidator($this, 'primaryLocale', 'required', 'manager.languages.form.primaryLocaleRequired'), array('Locale', 'isLocaleValid'));
00045 $this->addCheck(new FormValidator($this, 'primaryLocale', 'required', 'manager.languages.form.primaryLocaleRequired'), $localeCheck, array(&$this->availableLocales));
00046 $this->addCheck(new FormValidatorPost($this));
00047 }
00048
00052 function display() {
00053 $templateMgr = &TemplateManager::getManager();
00054 $site = &Request::getSite();
00055 $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00056 $templateMgr->assign('helpTopicId','journal.managementPages.languages');
00057 parent::display();
00058 }
00059
00063 function initData() {
00064 $journal = &Request::getJournal();
00065 foreach ($this->settings as $settingName => $settingType) {
00066 $this->_data[$settingName] = $journal->getSetting($settingName);
00067 }
00068
00069 $this->setData('primaryLocale', $journal->getPrimaryLocale());
00070
00071 if ($this->getData('supportedLocales') == null || !is_array($this->getData('supportedLocales'))) {
00072 $this->setData('supportedLocales', array());
00073 }
00074 }
00075
00079 function readInputData() {
00080 $vars = array_keys($this->settings);
00081 $vars[] = 'primaryLocale';
00082 $this->readUserVars($vars);
00083
00084 if ($this->getData('supportedLocales') == null || !is_array($this->getData('supportedLocales'))) {
00085 $this->setData('supportedLocales', array());
00086 }
00087 }
00088
00092 function execute() {
00093 $journal = &Request::getJournal();
00094 $settingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00095
00096
00097 $supportedLocales = array();
00098 foreach ($this->getData('supportedLocales') as $locale) {
00099 if (Locale::isLocaleValid($locale) && in_array($locale, $this->availableLocales)) {
00100 array_push($supportedLocales, $locale);
00101 }
00102 }
00103
00104 $primaryLocale = $this->getData('primaryLocale');
00105
00106 if ($primaryLocale != null && !empty($primaryLocale) && !in_array($primaryLocale, $supportedLocales)) {
00107 array_push($supportedLocales, $primaryLocale);
00108 }
00109 $this->setData('supportedLocales', $supportedLocales);
00110
00111 foreach ($this->_data as $name => $value) {
00112 if (!in_array($name, array_keys($this->settings))) continue;
00113 $settingsDao->updateSetting(
00114 $journal->getJournalId(),
00115 $name,
00116 $value,
00117 $this->settings[$name]
00118 );
00119 }
00120
00121 $journalDao =& DAORegistry::getDAO('JournalDAO');
00122 $journal->setPrimaryLocale($this->getData('primaryLocale'));
00123 $journalDao->updateJournal($journal);
00124 }
00125
00126 }
00127
00128 ?>