Open Monograph Press  1.1
 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 
20 
21 
26  $this->addRoleAssignment(ROLE_ID_MANAGER,
27  array(
28  'showFileUploadForm',
29  'uploadFile',
30  'saveFile',
31  'deleteFile',
32  'fetchFile',
33  'reloadLocalizedDefaultSettings'
34  )
35  );
36  parent::ManagerSettingsTabHandler();
37  $this->setPageTabs(array(
38  'appearance' => 'lib.pkp.controllers.tab.settings.appearance.form.AppearanceForm',
39  'information' => 'lib.pkp.controllers.tab.settings.information.form.InformationForm',
40  'languages' => 'controllers/tab/settings/languages/languages.tpl',
41  'plugins' => 'controllers/tab/settings/plugins/plugins.tpl',
42  'announcements' => 'lib.pkp.controllers.tab.settings.announcements.form.AnnouncementSettingsForm',
43  'navigation' => 'controllers/tab/settings/navigation/navigation.tpl',
44  ));
45  }
46 
50  function showTab($args, $request) {
51  $workingContexts = $this->getWorkingContexts($request);
52 
53  $multipleContexts = false;
54  if ($workingContexts && $workingContexts->getCount() > 1) {
55  $templateMgr = TemplateManager::getManager($request);
56  $templateMgr->assign('multipleContexts', true);
57  }
58  return parent::showTab($args, $request);
59  }
60 
61  //
62  // Public methods.
63  //
70  function showFileUploadForm($args, $request) {
71  $fileUploadForm = $this->_getFileUploadForm($request);
72  $fileUploadForm->initData($request);
73 
74  $json = new JSONMessage(true, $fileUploadForm->fetch($request));
75  return $json->getString();
76  }
77 
84  function uploadFile($args, $request) {
85  $fileUploadForm = $this->_getFileUploadForm($request);
86  $json = new JSONMessage();
87 
88  $temporaryFileId = $fileUploadForm->uploadFile($request);
89 
90  if ($temporaryFileId !== false) {
91  $json->setAdditionalAttributes(array(
92  'temporaryFileId' => $temporaryFileId
93  ));
94  } else {
95  $json->setStatus(false);
96  $json->setContent(__('common.uploadFailed'));
97  }
98 
99  return $json->getString();
100  }
101 
108  function saveFile($args, $request) {
109  $fileUploadForm = $this->_getFileUploadForm($request);
110  $fileUploadForm->readInputData();
111 
112  if ($fileUploadForm->validate()) {
113  if ($fileUploadForm->execute($request)) {
114  // Generate a JSON message with an event
115  $settingName = $request->getUserVar('fileSettingName');
116  return DAO::getDataChangedEvent($settingName);
117  }
118  }
119  $json = new JSONMessage(false, __('common.invalidFileType'));
120  return $json->getString();
121  }
122 
129  function deleteFile($args, $request) {
130  $settingName = $request->getUserVar('fileSettingName');
131 
132  $tabForm = $this->getTabForm();
133  $tabForm->initData($request);
134 
135  if ($tabForm->deleteFile($settingName, $request)) {
136  return DAO::getDataChangedEvent($settingName);
137  } else {
138  return new JSONMessage(false);
139  }
140  }
141 
149  function fetchFile($args, $request) {
150  // Get the setting name.
151  $settingName = $args['settingName'];
152 
153  // Try to fetch the file.
154  $tabForm = $this->getTabForm();
155  $tabForm->initData($request);
156 
157  $renderedElement = $tabForm->renderFileView($settingName, $request);
158 
159  $json = new JSONMessage();
160  if ($renderedElement == false) {
161  $json->setAdditionalAttributes(array('noData' => $settingName));
162  } else {
163  $json->setElementId($settingName);
164  $json->setContent($renderedElement);
165  }
166  return $json->getString();
167  }
168 
174  function reloadLocalizedDefaultSettings($args, $request) {
175  // make sure the locale is valid
176  $locale = $request->getUserVar('localeToLoad');
177  if ( !AppLocale::isLocaleValid($locale) ) {
178  $json = new JSONMessage(false);
179  return $json->getString();
180  }
181 
182  $press = $request->getPress();
183  $pressSettingsDao = DAORegistry::getDAO('PressSettingsDAO');
184  $pressSettingsDao->reloadLocalizedDefaultSettings(
185  $press->getId(), 'registry/pressSettings.xml',
186  array(
187  'indexUrl' => $request->getIndexUrl(),
188  'pressPath' => $press->getData('path'),
189  'primaryLocale' => $press->getPrimaryLocale(),
190  'pressName' => $press->getName($press->getPrimaryLocale())
191  ),
192  $locale
193  );
194 
195  // also reload the user group localizable data
196  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
197  $userGroupDao->installLocale($locale, $press->getId());
198 
199  return DAO::getDataChangedEvent();
200  }
201 
202 
203  //
204  // Private helper methods.
205  //
211  function &_getFileUploadForm($request) {
212  $settingName = $request->getUserVar('fileSettingName');
213  $fileType = $request->getUserVar('fileType');
214 
215  switch ($fileType) {
216  case 'image':
217  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextImageFileForm');
218  $fileUploadForm = new NewContextImageFileForm($settingName);
219  break;
220  case 'css':
221  import('lib.pkp.controllers.tab.settings.appearance.form.NewContextCssFileForm');
222  $fileUploadForm = new NewContextCssFileForm($settingName);
223  break;
224  default:
225  assert(false);
226  break;
227  }
228 
229  return $fileUploadForm;
230  }
231 }
232 
233 ?>
static & getDAO($name, $dbconn=null)
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
getWorkingContexts($request)
Definition: Handler.inc.php:33
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.