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  $multipleContexts = false;
53  if ($workingContexts && $workingContexts->getCount() > 1) {
54  $templateMgr = TemplateManager::getManager($request);
55  $templateMgr->assign('multipleContexts', true);
56  }
57  return parent::showTab($args, $request);
58  }
59 
60  //
61  // Public methods.
62  //
69  function showFileUploadForm($args, $request) {
70  $fileUploadForm = $this->_getFileUploadForm($request);
71  $fileUploadForm->initData($request);
72 
73  $json = new JSONMessage(true, $fileUploadForm->fetch($request));
74  return $json->getString();
75  }
76 
83  function uploadFile($args, $request) {
84  $fileUploadForm = $this->_getFileUploadForm($request);
85  $json = new JSONMessage();
86 
87  $temporaryFileId = $fileUploadForm->uploadFile($request);
88 
89  if ($temporaryFileId !== false) {
90  $json->setAdditionalAttributes(array(
91  'temporaryFileId' => $temporaryFileId
92  ));
93  } else {
94  $json->setStatus(false);
95  $json->setContent(__('common.uploadFailed'));
96  }
97 
98  return $json->getString();
99  }
100 
107  function saveFile($args, $request) {
108  $fileUploadForm = $this->_getFileUploadForm($request);
109  $fileUploadForm->readInputData();
110 
111  if ($fileUploadForm->validate()) {
112  if ($fileUploadForm->execute($request)) {
113  // Generate a JSON message with an event
114  $settingName = $request->getUserVar('fileSettingName');
115  return DAO::getDataChangedEvent($settingName);
116  }
117  }
118  $json = new JSONMessage(false, __('common.invalidFileType'));
119  return $json->getString();
120  }
121 
128  function deleteFile($args, $request) {
129  $settingName = $request->getUserVar('fileSettingName');
130 
131  $tabForm = $this->getTabForm();
132  $tabForm->initData($request);
133 
134  if ($tabForm->deleteFile($settingName, $request)) {
135  return DAO::getDataChangedEvent($settingName);
136  } else {
137  return new JSONMessage(false);
138  }
139  }
140 
148  function fetchFile($args, $request) {
149  // Get the setting name.
150  $settingName = $args['settingName'];
151 
152  // Try to fetch the file.
153  $tabForm = $this->getTabForm();
154  $tabForm->initData($request);
155 
156  $renderedElement = $tabForm->renderFileView($settingName, $request);
157 
158  $json = new JSONMessage();
159  if ($renderedElement == false) {
160  $json->setAdditionalAttributes(array('noData' => $settingName));
161  } else {
162  $json->setElementId($settingName);
163  $json->setContent($renderedElement);
164  }
165  return $json->getString();
166  }
167 
173  function reloadLocalizedDefaultSettings($args, $request) {
174  // make sure the locale is valid
175  $locale = $request->getUserVar('localeToLoad');
176  if ( !AppLocale::isLocaleValid($locale) ) {
177  $json = new JSONMessage(false);
178  return $json->getString();
179  }
180 
181  $journal = $request->getJournal();
182  $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
183  $journalSettingsDao->reloadLocalizedDefaultSettings(
184  $journal->getId(), 'registry/journalSettings.xml',
185  array(
186  'indexUrl' => $request->getIndexUrl(),
187  'journalPath' => $journal->getData('path'),
188  'primaryLocale' => $journal->getPrimaryLocale(),
189  'journalName' => $journal->getName($journal->getPrimaryLocale())
190  ),
191  $locale
192  );
193 
194  // also reload the user group localizable data
195  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
196  $userGroupDao->installLocale($locale, $journal->getId());
197 
198  return DAO::getDataChangedEvent();
199  }
200 
201 
202  //
203  // Private helper methods.
204  //
210  function _getFileUploadForm($request) {
211  $settingName = $request->getUserVar('fileSettingName');
212  $fileType = $request->getUserVar('fileType');
213 
214  switch ($fileType) {
215  case 'image':
216  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextImageFileForm');
217  $fileUploadForm = new NewContextImageFileForm($settingName);
218  break;
219  case 'css':
220  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextCssFileForm');
221  $fileUploadForm = new NewContextCssFileForm($settingName);
222  break;
223  default:
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.