00001 <?php
00002
00015
00016
00017 import('pages.admin.AdminHandler');
00018
00019 class AdminLanguagesHandler extends AdminHandler {
00023 function AdminLanguagesHandler() {
00024 parent::AdminHandler();
00025 }
00026
00032 function languages($args, &$request) {
00033 $this->validate();
00034 $this->setupTemplate(true);
00035
00036 $site =& $request->getSite();
00037
00038 $templateMgr =& TemplateManager::getManager();
00039 $templateMgr->assign('localeNames', AppLocale::getAllLocales());
00040 $templateMgr->assign('primaryLocale', $site->getPrimaryLocale());
00041 $templateMgr->assign('supportedLocales', $site->getSupportedLocales());
00042 $localesComplete = array();
00043 foreach (AppLocale::getAllLocales() as $key => $name) {
00044 $localesComplete[$key] = AppLocale::isLocaleComplete($key);
00045 }
00046 $templateMgr->assign('localesComplete', $localesComplete);
00047
00048 $templateMgr->assign('installedLocales', $site->getInstalledLocales());
00049 $templateMgr->assign('uninstalledLocales', array_diff(array_keys(AppLocale::getAllLocales()), $site->getInstalledLocales()));
00050 $templateMgr->assign('helpTopicId', 'site.siteManagement');
00051 $templateMgr->display('admin/languages.tpl');
00052 }
00053
00059 function saveLanguageSettings($args, &$request) {
00060 $this->validate();
00061 $site =& $request->getSite();
00062
00063 $primaryLocale = $request->getUserVar('primaryLocale');
00064 $supportedLocales = $request->getUserVar('supportedLocales');
00065
00066 if (AppLocale::isLocaleValid($primaryLocale)) {
00067 $site->setPrimaryLocale($primaryLocale);
00068 }
00069
00070 $newSupportedLocales = array();
00071 if (isset($supportedLocales) && is_array($supportedLocales)) {
00072 foreach ($supportedLocales as $locale) {
00073 if (AppLocale::isLocaleValid($locale)) {
00074 array_push($newSupportedLocales, $locale);
00075 }
00076 }
00077 }
00078 if (!in_array($primaryLocale, $newSupportedLocales)) {
00079 array_push($newSupportedLocales, $primaryLocale);
00080 }
00081 $site->setSupportedLocales($newSupportedLocales);
00082
00083 $siteDao =& DAORegistry::getDAO('SiteDAO');
00084 $siteDao->updateObject($site);
00085
00086 $this->_removeLocalesFromConferences($request);
00087
00088 import('notification.NotificationManager');
00089 $notificationManager = new NotificationManager();
00090 $notificationManager->createTrivialNotification('notification.notification', 'common.changesSaved');
00091
00092 $request->redirect(null, null, null, 'index');
00093 }
00094
00100 function installLocale($args, &$request) {
00101 $this->validate();
00102
00103 $site =& $request->getSite();
00104 $installLocale = $request->getUserVar('installLocale');
00105
00106 if (isset($installLocale) && is_array($installLocale)) {
00107 $installedLocales = $site->getInstalledLocales();
00108
00109 foreach ($installLocale as $locale) {
00110 if (AppLocale::isLocaleValid($locale) && !in_array($locale, $installedLocales)) {
00111 array_push($installedLocales, $locale);
00112 AppLocale::installLocale($locale);
00113 }
00114 }
00115
00116 $site->setInstalledLocales($installedLocales);
00117 $siteDao =& DAORegistry::getDAO('SiteDAO');
00118 $siteDao->updateObject($site);
00119 }
00120
00121 $request->redirect(null, null, null, 'languages');
00122 }
00123
00129 function uninstallLocale($args, &$request) {
00130 $this->validate();
00131
00132 $site =& $request->getSite();
00133 $locale = $request->getUserVar('locale');
00134
00135 if (isset($locale) && !empty($locale) && $locale != $site->getPrimaryLocale()) {
00136 $installedLocales = $site->getInstalledLocales();
00137
00138 if (in_array($locale, $installedLocales)) {
00139 $installedLocales = array_diff($installedLocales, array($locale));
00140 $site->setInstalledLocales($installedLocales);
00141 $supportedLocales = $site->getSupportedLocales();
00142 $supportedLocales = array_diff($supportedLocales, array($locale));
00143 $site->setSupportedLocales($supportedLocales);
00144 $siteDao =& DAORegistry::getDAO('SiteDAO');
00145 $siteDao->updateObject($site);
00146
00147 $this->_removeLocalesFromConferences($request);
00148 AppLocale::uninstallLocale($locale);
00149 }
00150 }
00151
00152 $request->redirect(null, null, null, 'languages');
00153 }
00154
00160 function reloadLocale($args, &$request) {
00161 $this->validate();
00162
00163 $site =& $request->getSite();
00164 $locale = $request->getUserVar('locale');
00165
00166 if (in_array($locale, $site->getInstalledLocales())) {
00167 AppLocale::reloadLocale($locale);
00168 }
00169
00170 $request->redirect(null, null, null, 'languages');
00171 }
00172
00177 function _removeLocalesFromConferences(&$request) {
00178 $site =& $request->getSite();
00179 $siteSupportedLocales = $site->getSupportedLocales();
00180
00181 $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00182 $settingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
00183 $conferences =& $conferenceDao->getConferences();
00184 $conferences =& $conferences->toArray();
00185 foreach ($conferences as $conference) {
00186 $primaryLocale = $conference->getPrimaryLocale();
00187 $supportedLocales = $conference->getSetting('supportedLocales');
00188
00189 if (isset($primaryLocale) && !in_array($primaryLocale, $siteSupportedLocales)) {
00190 $conference->setPrimaryLocale($site->getPrimaryLocale());
00191 $conferenceDao->updateConference($conference);
00192 }
00193
00194 if (is_array($supportedLocales)) {
00195 $supportedLocales = array_intersect($supportedLocales, $siteSupportedLocales);
00196 $settingsDao->updateSetting($conference->getId(), 'supportedLocales', $supportedLocales, 'object');
00197 }
00198 }
00199 }
00200 }
00201
00202 ?>