18 import(
'lib.pkp.controllers.grid.languages.LanguageGridHandler');
19 import(
'lib.pkp.controllers.grid.languages.LanguageGridRow');
20 import(
'lib.pkp.controllers.grid.languages.form.InstallLanguageForm');
27 parent::__construct();
29 array(ROLE_ID_SITE_ADMIN),
31 'fetchGrid',
'fetchRow',
32 'installLocale',
'saveInstallLocale',
'uninstallLocale',
33 'disableLocale',
'enableLocale',
'setPrimaryLocale'
45 public function authorize($request, &$args, $roleAssignments) {
46 import(
'lib.pkp.classes.security.authorization.PolicySet');
47 $rolePolicy =
new PolicySet(COMBINING_PERMIT_OVERRIDES);
49 import(
'lib.pkp.classes.security.authorization.RoleBasedHandlerOperationPolicy');
50 foreach($roleAssignments as $role => $operations) {
55 return parent::authorize($request, $args, $roleAssignments);
62 parent::initialize($request, $args);
65 LOCALE_COMPONENT_PKP_ADMIN,
66 LOCALE_COMPONENT_PKP_MANAGER,
67 LOCALE_COMPONENT_APP_MANAGER,
68 LOCALE_COMPONENT_APP_ADMIN
72 $router = $request->getRouter();
74 import(
'lib.pkp.classes.linkAction.request.AjaxModal');
79 $router->url($request,
null,
null,
'installLocale',
null,
null),
80 __(
'admin.languages.installLocale'),
84 __(
'admin.languages.installLocale'),
95 'controllers/grid/common/cell/selectStatusCell.tpl',
106 $primaryId =
'contextPrimary';
108 $primaryId =
'sitePrimary';
116 $this->
setFootNote(
'admin.locale.maybeIncomplete');
127 $site = $request->getSite();
131 $installedLocales = $site->getInstalledLocales();
132 $supportedLocales = $site->getSupportedLocales();
133 $primaryLocale = $site->getPrimaryLocale();
135 foreach($installedLocales as $localeKey) {
136 $data[$localeKey] = array();
137 $data[$localeKey][
'name'] = $allLocales[$localeKey];
139 if (in_array($localeKey, $supportedLocales)) {
144 $data[$localeKey][
'supported'] = $supported;
147 $context = $request->getContext();
148 $primaryLocale = $context->getPrimaryLocale();
151 if ($localeKey == $primaryLocale) {
156 $data[$localeKey][
'primary'] = $primary;
179 $installLanguageForm->initData();
180 return new JSONMessage(
true, $installLanguageForm->fetch($request));
192 $installLanguageForm->readInputData();
194 if ($installLanguageForm->validate()) {
195 $installLanguageForm->execute();
199 $user = $request->getUser();
200 $notificationManager->createTrivialNotification(
201 $user->getId(), NOTIFICATION_TYPE_SUCCESS,
202 array(
'contents' => __(
'notification.localeInstalled'))
215 $site = $request->getSite();
216 $locale = $request->getUserVar(
'rowId');
219 if ($request->checkCSRF() && array_key_exists($locale, $gridData)) {
220 $localeData = $gridData[$locale];
221 if ($localeData[
'primary'])
return new JSONMessage(
false);
223 $installedLocales = $site->getInstalledLocales();
224 if (in_array($locale, $installedLocales)) {
225 $installedLocales = array_diff($installedLocales, array($locale));
226 $site->setInstalledLocales($installedLocales);
227 $supportedLocales = $site->getSupportedLocales();
228 $supportedLocales = array_diff($supportedLocales, array($locale));
229 $site->setSupportedLocales($supportedLocales);
231 $siteDao->updateObject($site);
237 $user = $request->getUser();
238 $notificationManager->createTrivialNotification(
239 $user->getId(), NOTIFICATION_TYPE_SUCCESS,
240 array(
'contents' => __(
'notification.localeUninstalled', array(
'locale' => $localeData[
'name'])))
256 $rowId = $request->getUserVar(
'rowId');
259 if (array_key_exists($rowId, $gridData)) {
263 $user = $request->getUser();
264 $notificationManager->createTrivialNotification(
265 $user->getId(), NOTIFICATION_TYPE_SUCCESS,
266 array(
'contents' => __(
'notification.localeEnabled'))
280 $locale = $request->getUserVar(
'rowId');
283 $user = $request->getUser();
285 if ($request->checkCSRF() && array_key_exists($locale, $gridData)) {
287 if ($gridData[$locale][
'primary']) {
288 $notificationManager->createTrivialNotification(
289 $user->getId(), NOTIFICATION_TYPE_ERROR,
290 array(
'contents' => __(
'admin.languages.cantDisable'))
294 $notificationManager->createTrivialNotification(
295 $user->getId(), NOTIFICATION_TYPE_SUCCESS,
296 array(
'contents' => __(
'notification.localeDisabled'))
313 $rowId = $request->getUserVar(
'rowId');
315 $localeData = $gridData[$rowId];
317 $user = $request->getUser();
318 $site = $request->getSite();
320 if (array_key_exists($rowId, $gridData)) {
322 $oldSitePrimaryLocale = $site->getPrimaryLocale();
324 $userDao->changeSitePrimaryLocale($oldSitePrimaryLocale, $rowId);
325 $site->setPrimaryLocale($rowId);
327 $siteDao->updateObject($site);
329 $notificationManager->createTrivialNotification(
330 $user->getId(), NOTIFICATION_TYPE_SUCCESS,
331 array(
'contents' => __(
'notification.primaryLocaleDefined', array(
'locale' => $localeData[
'name'])))
352 $newSupportedLocales = array();
355 foreach ($gridData as $locale => $data) {
356 if ($data[
'supported']) {
357 array_push($newSupportedLocales, $locale);
363 array_push($newSupportedLocales, $rowId);
365 $key = array_search($rowId, $newSupportedLocales);
366 if ($key !==
false) unset($newSupportedLocales[$key]);
370 $site = $request->getSite();
371 $site->setSupportedLocales($newSupportedLocales);
374 $siteDao->updateObject($site);
385 $site = $request->getSite();
386 $siteSupportedLocales = $site->getSupportedLocales();
390 $contexts = $contextDao->getAll();
391 while ($context = $contexts->next()) {
393 $primaryLocale = $context->getPrimaryLocale();
394 foreach (array(
'supportedLocales',
'supportedFormLocales',
'supportedSubmissionLocales') as $settingName) {
395 $localeList = $context->getData($settingName);
397 if (is_array($localeList)) {
398 $params[$settingName] = array_intersect($localeList, $siteSupportedLocales);
401 if (!in_array($primaryLocale, $siteSupportedLocales)) {
402 $params[
'primaryLocale'] = $site->getPrimaryLocale();
403 $primaryLocale = $params[
'primaryLocale'];
405 $errors = $contextService->validate(VALIDATE_ACTION_EDIT, $params, $params[
'supportedLocales'], $primaryLocale);
407 assert(empty($errors));
408 $contextService->edit($context, $params, $request);
420 $contexts = $contextDao->getAll();
422 $context = $request->getContext();
423 return ($contexts->getCount() == 1 && $context && in_array(ROLE_ID_MANAGER, $userRoles));