Open Journal Systems  3.0.0
 All Classes 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($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  $json = new JSONMessage(true, $fileUploadForm->fetch($request));
80  return $json->getString();
81  }
82 
89  function uploadFile($args, $request) {
90  $fileUploadForm =& $this->_getFileUploadForm($request);
91  $json = new JSONMessage();
92 
93  $temporaryFileId = $fileUploadForm->uploadFile($request);
94 
95  if ($temporaryFileId !== false) {
96  $json->setAdditionalAttributes(array(
97  'temporaryFileId' => $temporaryFileId
98  ));
99  } else {
100  $json->setStatus(false);
101  $json->setContent(__('common.uploadFailed'));
102  }
103 
104  return $json->getString();
105  }
106 
113  function saveFile($args, $request) {
114  $fileUploadForm = $this->_getFileUploadForm($request);
115  $fileUploadForm->readInputData();
116 
117  if ($fileUploadForm->validate()) {
118  if ($fileUploadForm->execute($request)) {
119  // Generate a JSON message with an event
120  $settingName = $request->getUserVar('fileSettingName');
121  return DAO::getDataChangedEvent($settingName);
122  }
123  }
124  $json = new JSONMessage(false, __('common.invalidFileType'));
125  return $json->getString();
126  }
127 
134  function deleteFile($args, $request) {
135  $settingName = $request->getUserVar('fileSettingName');
136 
137  $tabForm = $this->getTabForm();
138  $tabForm->initData($request);
139 
140  if ($tabForm->deleteFile($settingName, $request)) {
141  return DAO::getDataChangedEvent($settingName);
142  } else {
143  return new JSONMessage(false);
144  }
145  }
146 
154  function fetchFile($args, $request) {
155  // Get the setting name.
156  $settingName = $args['settingName'];
157 
158  // Try to fetch the file.
159  $tabForm = $this->getTabForm();
160  $tabForm->initData($request);
161 
162  $renderedElement = $tabForm->renderFileView($settingName, $request);
163 
164  $json = new JSONMessage();
165  if ($renderedElement == false) {
166  $json->setAdditionalAttributes(array('noData' => $settingName));
167  } else {
168  $json->setElementId($settingName);
169  $json->setContent($renderedElement);
170  }
171  return $json->getString();
172  }
173 
174 
175  //
176  // Private helper methods.
177  //
183  function &_getFileUploadForm($request) {
184  $settingName = $request->getUserVar('fileSettingName');
185  $fileType = $request->getUserVar('fileType');
186 
187  switch ($fileType) {
188  case 'image':
189  import('lib.pkp.controllers.tab.settings.siteSetup.form.NewSiteImageFileForm');
190  $fileUploadForm = new NewSiteImageFileForm($settingName);
191  break;
192  case 'css':
193  import('lib.pkp.controllers.tab.settings.siteSetup.form.NewSiteCssFileForm');
194  $fileUploadForm = new NewSiteCssFileForm($settingName);
195  break;
196  default:
197  assert(false);
198  break;
199  }
200 
201  return $fileUploadForm;
202  }
203 }
204 
205 ?>
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:632
Handle AJAX operations for tabs on administration settings pages.