Open Journal Systems  3.0.0
 All Data Structures 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.AppearanceForm',
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  ));
43  }
44 
48  function showTab($args, $request) {
49  $workingContexts = $this->getWorkingContexts($request);
50 
51  if ($workingContexts && $workingContexts->getCount() > 1) {
52  $templateMgr = TemplateManager::getManager($request);
53  $templateMgr->assign('multipleContexts', true);
54  }
55  return parent::showTab($args, $request);
56  }
57 
58  //
59  // Public methods.
60  //
67  function showFileUploadForm($args, $request) {
68  $fileUploadForm = $this->_getFileUploadForm($request);
69  $fileUploadForm->initData($request);
70 
71  return new JSONMessage(true, $fileUploadForm->fetch($request));
72  }
73 
80  function uploadFile($args, $request) {
81  $fileUploadForm = $this->_getFileUploadForm($request);
82 
83  $temporaryFileId = $fileUploadForm->uploadFile($request);
84 
85  if ($temporaryFileId !== false) {
86  $json = new JSONMessage();
87  $json->setAdditionalAttributes(array(
88  'temporaryFileId' => $temporaryFileId
89  ));
90  return $json;
91  } else {
92  return new JSONMessage(false, __('common.uploadFailed'));
93  }
94  }
95 
102  function saveFile($args, $request) {
103  $fileUploadForm = $this->_getFileUploadForm($request);
104  $fileUploadForm->readInputData();
105 
106  if ($fileUploadForm->validate()) {
107  if ($fileUploadForm->execute($request)) {
108  // Generate a JSON message with an event
109  $settingName = $request->getUserVar('fileSettingName');
110  return DAO::getDataChangedEvent($settingName);
111  }
112  }
113  return new JSONMessage(false, __('common.invalidFileType'));
114  }
115 
122  function deleteFile($args, $request) {
123  $settingName = $request->getUserVar('fileSettingName');
124 
125  $tabForm = $this->getTabForm();
126  $tabForm->initData($request);
127 
128  if ($tabForm->deleteFile($settingName, $request)) {
129  return DAO::getDataChangedEvent($settingName);
130  } else {
131  return new JSONMessage(false);
132  }
133  }
134 
142  function fetchFile($args, $request) {
143  // Get the setting name.
144  $settingName = $args['settingName'];
145 
146  // Try to fetch the file.
147  $tabForm = $this->getTabForm();
148  $tabForm->initData($request);
149 
150  $renderedElement = $tabForm->renderFileView($settingName, $request);
151 
152  $json = new JSONMessage();
153  if ($renderedElement == false) {
154  $json->setAdditionalAttributes(array('noData' => $settingName));
155  } else {
156  $json->setElementId($settingName);
157  $json->setContent($renderedElement);
158  }
159  return $json;
160  }
161 
168  function reloadLocalizedDefaultSettings($args, $request) {
169  // make sure the locale is valid
170  $locale = $request->getUserVar('localeToLoad');
171  if ( !AppLocale::isLocaleValid($locale) ) {
172  return new JSONMessage(false);
173  }
174 
175  $journal = $request->getJournal();
176  $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
177  $journalSettingsDao->reloadLocalizedDefaultSettings(
178  $journal->getId(), 'registry/journalSettings.xml',
179  array(
180  'indexUrl' => $request->getIndexUrl(),
181  'journalPath' => $journal->getData('path'),
182  'primaryLocale' => $journal->getPrimaryLocale(),
183  'journalName' => $journal->getName($journal->getPrimaryLocale())
184  ),
185  $locale
186  );
187 
188  // also reload the user group localizable data
189  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
190  $userGroupDao->installLocale($locale, $journal->getId());
191 
192  return DAO::getDataChangedEvent();
193  }
194 
195 
196  //
197  // Private helper methods.
198  //
204  function _getFileUploadForm($request) {
205  $settingName = $request->getUserVar('fileSettingName');
206  $fileType = $request->getUserVar('fileType');
207 
208  switch ($fileType) {
209  case 'image':
210  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextImageFileForm');
211  $fileUploadForm = new NewContextImageFileForm($settingName);
212  break;
213  case 'css':
214  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextCssFileForm');
215  $fileUploadForm = new NewContextCssFileForm($settingName);
216  break;
217  default:
218  $fileUploadForm = null; // Suppress scrutinizer
219  assert(false);
220  break;
221  }
222 
223  return $fileUploadForm;
224  }
225 }
226 
227 ?>
static & getDAO($name, $dbconn=null)
getWorkingContexts($request)
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
Handle AJAX operations for tabs on manangement settings pages. Implements the wizard mode...
Form for upload an image.
static & getManager($request=null)
static isLocaleValid($locale)
Handle AJAX operations for tabs on Website settings page.
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:633
Form to upload an css file.