Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
WebsiteSettingsTabHandler.inc.php
1 <?php
2 
16 // Import the base Handler.
17 import('lib.pkp.controllers.tab.settings.ManagerSettingsTabHandler');
18 
24  $this->addRoleAssignment(ROLE_ID_MANAGER,
25  array(
26  'showFileUploadForm',
27  'uploadFile',
28  'saveFile',
29  'deleteFile',
30  'fetchFile',
31  'reloadLocalizedDefaultSettings'
32  )
33  );
34  parent::ManagerSettingsTabHandler();
35  $this->setPageTabs(array(
36  'appearance' => 'controllers.tab.settings.appearance.form.OJSAppearanceForm',
37  'information' => 'lib.pkp.controllers.tab.settings.information.form.InformationForm',
38  'archiving' => 'lib.pkp.controllers.tab.settings.archiving.form.ArchivingForm',
39  'languages' => 'controllers/tab/settings/languages/languages.tpl',
40  'plugins' => 'controllers/tab/settings/plugins/plugins.tpl',
41  'announcements' => 'lib.pkp.controllers.tab.settings.announcements.form.AnnouncementSettingsForm',
42  'navigation' => 'controllers/tab/settings/navigation/navigation.tpl',
43  ));
44  }
45 
49  function showTab($args, $request) {
50  $workingContexts = $this->getWorkingContexts($request);
51 
52  if ($workingContexts && $workingContexts->getCount() > 1) {
53  $templateMgr = TemplateManager::getManager($request);
54  $templateMgr->assign('multipleContexts', true);
55  }
56  return parent::showTab($args, $request);
57  }
58 
59  //
60  // Public methods.
61  //
68  function showFileUploadForm($args, $request) {
69  $fileUploadForm = $this->_getFileUploadForm($request);
70  $fileUploadForm->initData($request);
71 
72  $json = new JSONMessage(true, $fileUploadForm->fetch($request));
73  return $json->getString();
74  }
75 
82  function uploadFile($args, $request) {
83  $fileUploadForm = $this->_getFileUploadForm($request);
84  $json = new JSONMessage();
85 
86  $temporaryFileId = $fileUploadForm->uploadFile($request);
87 
88  if ($temporaryFileId !== false) {
89  $json->setAdditionalAttributes(array(
90  'temporaryFileId' => $temporaryFileId
91  ));
92  } else {
93  $json->setStatus(false);
94  $json->setContent(__('common.uploadFailed'));
95  }
96 
97  return $json->getString();
98  }
99 
106  function saveFile($args, $request) {
107  $fileUploadForm = $this->_getFileUploadForm($request);
108  $fileUploadForm->readInputData();
109 
110  if ($fileUploadForm->validate()) {
111  if ($fileUploadForm->execute($request)) {
112  // Generate a JSON message with an event
113  $settingName = $request->getUserVar('fileSettingName');
114  return DAO::getDataChangedEvent($settingName);
115  }
116  }
117  $json = new JSONMessage(false, __('common.invalidFileType'));
118  return $json->getString();
119  }
120 
127  function deleteFile($args, $request) {
128  $settingName = $request->getUserVar('fileSettingName');
129 
130  $tabForm = $this->getTabForm();
131  $tabForm->initData($request);
132 
133  if ($tabForm->deleteFile($settingName, $request)) {
134  return DAO::getDataChangedEvent($settingName);
135  } else {
136  return new JSONMessage(false);
137  }
138  }
139 
147  function fetchFile($args, $request) {
148  // Get the setting name.
149  $settingName = $args['settingName'];
150 
151  // Try to fetch the file.
152  $tabForm = $this->getTabForm();
153  $tabForm->initData($request);
154 
155  $renderedElement = $tabForm->renderFileView($settingName, $request);
156 
157  $json = new JSONMessage();
158  if ($renderedElement == false) {
159  $json->setAdditionalAttributes(array('noData' => $settingName));
160  } else {
161  $json->setElementId($settingName);
162  $json->setContent($renderedElement);
163  }
164  return $json->getString();
165  }
166 
172  function reloadLocalizedDefaultSettings($args, $request) {
173  // make sure the locale is valid
174  $locale = $request->getUserVar('localeToLoad');
175  if ( !AppLocale::isLocaleValid($locale) ) {
176  $json = new JSONMessage(false);
177  return $json->getString();
178  }
179 
180  $journal = $request->getJournal();
181  $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
182  $journalSettingsDao->reloadLocalizedDefaultSettings(
183  $journal->getId(), 'registry/journalSettings.xml',
184  array(
185  'indexUrl' => $request->getIndexUrl(),
186  'journalPath' => $journal->getData('path'),
187  'primaryLocale' => $journal->getPrimaryLocale(),
188  'journalName' => $journal->getName($journal->getPrimaryLocale())
189  ),
190  $locale
191  );
192 
193  // also reload the user group localizable data
194  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
195  $userGroupDao->installLocale($locale, $journal->getId());
196 
197  return DAO::getDataChangedEvent();
198  }
199 
200 
201  //
202  // Private helper methods.
203  //
209  function _getFileUploadForm($request) {
210  $settingName = $request->getUserVar('fileSettingName');
211  $fileType = $request->getUserVar('fileType');
212 
213  switch ($fileType) {
214  case 'image':
215  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextImageFileForm');
216  $fileUploadForm = new NewContextImageFileForm($settingName);
217  break;
218  case 'css':
219  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextCssFileForm');
220  $fileUploadForm = new NewContextCssFileForm($settingName);
221  break;
222  default:
223  $fileUploadForm = null; // Suppress scrutinizer
224  assert(false);
225  break;
226  }
227 
228  return $fileUploadForm;
229  }
230 }
231 
232 ?>
static & getDAO($name, $dbconn=null)
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
getWorkingContexts($request)
Definition: Handler.inc.php:29
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
Handle AJAX operations for tabs on manangement settings pages. Implements the wizard mode...
Form for upload an image.
static isLocaleValid($locale)
Handle AJAX operations for tabs on Website settings page.
Form to upload an css file.