00001 <?php
00002
00015
00016 import('classes.handler.Handler');
00017 import('lib.pkp.classes.core.JSONMessage');
00018
00019 class SettingsTabHandler extends Handler {
00020
00022 var $_currentTab;
00023
00025 var $_pageTabs;
00026
00027
00032 function SettingsTabHandler($role) {
00033 parent::Handler();
00034 $this->addRoleAssignment(
00035 $role,
00036 array('saveFormData', 'showTab')
00037 );
00038 }
00039
00040
00041
00042
00043
00048 function getCurrentTab() {
00049 return $this->_currentTab;
00050 }
00051
00056 function setCurrentTab($currentTab) {
00057 $this->_currentTab = $currentTab;
00058 }
00059
00064 function getPageTabs() {
00065 return $this->_pageTabs;
00066 }
00067
00072 function setPageTabs($pageTabs) {
00073 $this->_pageTabs = $pageTabs;
00074 }
00075
00076
00077
00078
00082 function initialize(&$request) {
00083 $this->setCurrentTab($request->getUserVar('tab'));
00084 }
00085
00089 function authorize(&$request, $args, $roleAssignments) {
00090 import('classes.security.authorization.OmpPressAccessPolicy');
00091 $this->addPolicy(new OmpPressAccessPolicy($request, $roleAssignments));
00092 return parent::authorize($request, $args, $roleAssignments);
00093 }
00094
00095
00096
00097
00101 function showTab($args, &$request) {
00102 $this->setupTemplate();
00103 if ($this->_isValidTab()) {
00104 if ($this->_isTabTemplate()) {
00105 $this->setupTemplate(true);
00106 $templateMgr =& TemplateManager::getManager();
00107 if ($this->_isManagementHandler()) {
00108
00109 $templateMgr->assign('wizardMode', $this->getWizardMode());
00110 }
00111 $templateMgr->assign('canEdit', true);
00112 return $templateMgr->fetchJson($this->_getTabTemplate());
00113 } else {
00114 $tabForm = $this->getTabForm();
00115 $tabForm->initData($request);
00116 $json = new JSONMessage(true, $tabForm->fetch($request));
00117 return $json->getString();
00118 }
00119 }
00120 }
00121
00126 function saveFormData($args, &$request) {
00127 $json = new JSONMessage();
00128
00129 if ($this->_isValidTab()) {
00130 $tabForm = $this->getTabForm();
00131
00132
00133 $tabForm->readInputData($request);
00134 if($tabForm->validate()) {
00135 $result = $tabForm->execute($request);
00136 if ($result !== false) {
00137 $notificationManager = new NotificationManager();
00138 $user =& $request->getUser();
00139 $notificationManager->createTrivialNotification($user->getId());
00140 }
00141 } else {
00142 $json->setStatus(false);
00143 }
00144 }
00145
00146 return $json->getString();
00147 }
00148
00153 function getTabForm() {
00154 $currentTab = $this->getCurrentTab();
00155 $pageTabs = $this->getPageTabs();
00156
00157
00158 import($pageTabs[$currentTab]);
00159 $tabFormClassName = $this->_getFormClassName($pageTabs[$currentTab]);
00160
00161 if ($this->_isManagementHandler()) {
00162 $tabForm = new $tabFormClassName($this->getWizardMode());
00163 } else {
00164 $tabForm = new $tabFormClassName();
00165 }
00166
00167 assert(is_a($tabForm, 'Form'));
00168
00169 return $tabForm;
00170 }
00171
00172
00173
00174
00175
00180 function _getTabTemplate() {
00181 $currentTab = $this->getCurrentTab();
00182 $pageTabs = $this->getPageTabs();
00183
00184 return $pageTabs[$currentTab];
00185 }
00186
00191 function _isValidTab() {
00192 if (array_key_exists($this->getCurrentTab(), $this->getPageTabs())) {
00193 return true;
00194 } else {
00195 assert(false);
00196 return false;
00197 }
00198 }
00199
00204 function _isTabTemplate() {
00205 $currentTab = $this->getCurrentTab();
00206 $pageTabs = $this->getPageTabs();
00207
00208 return (strstr($pageTabs[$currentTab], '.tpl'));
00209 }
00210
00216 function _getFormClassName($classPath) {
00217 $needle = '.form.';
00218 $formClassName = strstr($classPath, $needle);
00219 $formClassName = trim(str_replace($needle, ' ', $formClassName));
00220 return $formClassName;
00221 }
00222
00227 function _isManagementHandler() {
00228 return is_subclass_of($this, 'ManagerSettingsTabHandler');
00229 }
00230 }
00231
00232 ?>