Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
AdminSettingsTabHandler.inc.php
1 <?php
2 
16 // Import the base Handler.
17 import('lib.pkp.classes.controllers.tab.settings.SettingsTabHandler');
18 
20 
25  function AdminSettingsTabHandler($additionalTabs = array()) {
26  $role = array(ROLE_ID_SITE_ADMIN);
27 
28  $this->addRoleAssignment(ROLE_ID_MANAGER,
29  array(
30  'showFileUploadForm',
31  'uploadFile',
32  'saveFile',
33  'deleteFile',
34  'fetchFile'
35  )
36  );
37 
38  parent::SettingsTabHandler($role);
39  $this->setPageTabs(array_merge($additionalTabs, array(
40  'siteSetup' => 'lib.pkp.controllers.tab.settings.siteSetup.form.SiteSetupForm',
41  'languages' => 'controllers/tab/admin/languages/languages.tpl',
42  'plugins' => 'controllers/tab/admin/plugins/sitePlugins.tpl',
43  )));
44  }
45 
46 
47  //
48  // Extended methods from SettingsTabHandler
49  //
53  function initialize($request, $args = null) {
54  parent::initialize($request, $args);
55 
56  // Load grid-specific translations
58  LOCALE_COMPONENT_PKP_ADMIN,
59  LOCALE_COMPONENT_APP_ADMIN,
60  LOCALE_COMPONENT_PKP_MANAGER,
61  LOCALE_COMPONENT_APP_MANAGER
62  );
63  }
64 
65 
66  //
67  // Public methods.
68  //
75  function showFileUploadForm($args, $request) {
76  $fileUploadForm = $this->_getFileUploadForm($request);
77  $fileUploadForm->initData($request);
78 
79  return new JSONMessage(true, $fileUploadForm->fetch($request));
80  }
81 
88  function uploadFile($args, $request) {
89  $fileUploadForm =& $this->_getFileUploadForm($request);
90  $temporaryFileId = $fileUploadForm->uploadFile($request);
91 
92  if ($temporaryFileId !== false) {
93  $json = new JSONMessage();
94  $json->setAdditionalAttributes(array(
95  'temporaryFileId' => $temporaryFileId
96  ));
97  return $json;
98  } else {
99  return new JSONMessage(false, __('common.uploadFailed'));
100  }
101  }
102 
109  function saveFile($args, $request) {
110  $fileUploadForm = $this->_getFileUploadForm($request);
111  $fileUploadForm->readInputData();
112 
113  if ($fileUploadForm->validate()) {
114  if ($fileUploadForm->execute($request)) {
115  // Generate a JSON message with an event
116  $settingName = $request->getUserVar('fileSettingName');
117  return DAO::getDataChangedEvent($settingName);
118  }
119  }
120  return new JSONMessage(false, __('common.invalidFileType'));
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;
167  }
168 
169 
170  //
171  // Private helper methods.
172  //
178  function &_getFileUploadForm($request) {
179  $settingName = $request->getUserVar('fileSettingName');
180  $fileType = $request->getUserVar('fileType');
181 
182  switch ($fileType) {
183  case 'image':
184  import('lib.pkp.controllers.tab.settings.siteSetup.form.NewSiteImageFileForm');
185  $fileUploadForm = new NewSiteImageFileForm($settingName);
186  break;
187  case 'css':
188  import('lib.pkp.controllers.tab.settings.siteSetup.form.NewSiteCssFileForm');
189  $fileUploadForm = new NewSiteCssFileForm($settingName);
190  break;
191  default:
192  assert(false);
193  break;
194  }
195 
196  return $fileUploadForm;
197  }
198 }
199 
200 ?>
static requireComponents()
Form for upload an css file.
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
Handle AJAX operations for tabs on settings pages, under administration or management pages...
Form for upload an image.
AdminSettingsTabHandler($additionalTabs=array())
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:633
Handle AJAX operations for tabs on administration settings pages.