00001 <?php
00002
00016 import('lib.pkp.classes.db.DBDataXMLParser');
00017 import('lib.pkp.classes.form.Form');
00018
00019 class PressSiteSettingsForm extends Form {
00020
00022 var $pressId;
00023
00028 function PressSiteSettingsForm($pressId = null) {
00029 parent::Form('admin/pressSettings.tpl');
00030
00031 $this->pressId = isset($pressId) ? (int) $pressId : null;
00032
00033
00034 $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'admin.presses.form.titleRequired'));
00035 $this->addCheck(new FormValidator($this, 'path', 'required', 'admin.presses.form.pathRequired'));
00036 $this->addCheck(new FormValidatorAlphaNum($this, 'path', 'required', 'admin.presses.form.pathAlphaNumeric'));
00037 $this->addCheck(new FormValidatorCustom($this, 'path', 'required', 'admin.presses.form.pathExists', create_function('$path,$form,$pressDao', 'return !$pressDao->pressExistsByPath($path) || ($form->getData(\'oldPath\') != null && $form->getData(\'oldPath\') == $path);'), array(&$this, DAORegistry::getDAO('PressDAO'))));
00038 $this->addCheck(new FormValidatorPost($this));
00039 }
00040
00044 function fetch($args, &$request) {
00045 $json = new JSONMessage();
00046
00047 $templateMgr =& TemplateManager::getManager();
00048 $templateMgr->assign('pressId', $this->pressId);
00049 $templateMgr->assign('helpTopicId', 'site.siteManagement');
00050
00051 return parent::fetch($request);
00052 }
00053
00057 function initData() {
00058 if (isset($this->pressId)) {
00059 $pressDao =& DAORegistry::getDAO('PressDAO');
00060 $press =& $pressDao->getById($this->pressId);
00061
00062 if ($press != null) {
00063 $this->_data = array(
00064 'name' => $press->getSetting('name', null),
00065 'description' => $press->getSetting('description', null),
00066 'path' => $press->getPath(),
00067 'enabled' => $press->getEnabled()
00068 );
00069
00070 } else {
00071 $this->pressId = null;
00072 }
00073 }
00074 if (!isset($this->pressId)) {
00075 $this->_data = array(
00076 'enabled' => 1
00077 );
00078 }
00079 }
00080
00084 function readInputData() {
00085 $this->readUserVars(array('name', 'description', 'path', 'enabled'));
00086 $this->setData('enabled', (int)$this->getData('enabled'));
00087
00088 if (isset($this->pressId)) {
00089 $pressDao =& DAORegistry::getDAO('PressDAO');
00090 $press =& $pressDao->getById($this->pressId);
00091 $this->setData('oldPath', $press->getPath());
00092 }
00093 }
00094
00099 function getLocaleFieldNames() {
00100 return array('name', 'description');
00101 }
00102
00107 function execute($request) {
00108 $pressDao =& DAORegistry::getDAO('PressDAO');
00109
00110 if (isset($this->pressId)) {
00111 $press =& $pressDao->getById($this->pressId);
00112
00113 import('classes.publicationFormat.PublicationFormatTombstoneManager');
00114 $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
00115 if ($press->getEnabled() && !$this->getData('enabled')) {
00116
00117
00118 $publicationFormatTombstoneMgr->insertTombstonesByPress($press);
00119 } elseif (!$press->getEnabled() && $this->getData('enabled')) {
00120
00121 $publicationFormatTombstoneMgr->deleteTombstonesByPressId($press->getId());
00122 }
00123 }
00124
00125 if (!isset($press)) {
00126 $press = $pressDao->newDataObject();
00127 }
00128
00129
00130 $pathChanged = false;
00131 $pressPath = $press->getPath();
00132 if ($pressPath != $this->getData('path')) {
00133 $pathChanged = true;
00134 }
00135 $press->setPath($this->getData('path'));
00136 $press->setEnabled($this->getData('enabled'));
00137
00138 $isNewPress = false;
00139
00140 if ($press->getId() != null) {
00141 $pressDao->updateObject($press);
00142 $series = null;
00143 } else {
00144 $isNewPress = true;
00145 $site =& $request->getSite();
00146
00147
00148 $press->setPrimaryLocale($site->getPrimaryLocale());
00149
00150 $pressId = $pressDao->insertObject($press);
00151 $pressDao->resequencePresses();
00152
00153
00154 import('classes.file.PressFileManager');
00155 $pressFileManager = new PressFileManager($pressId);
00156 $pressFileManager->mkdir($pressFileManager->getBasePath());
00157 $pressFileManager->mkdir($pressFileManager->getBasePath() . '/monographs');
00158
00159 $installedLocales =& $site->getInstalledLocales();
00160
00161
00162 $genreDao =& DAORegistry::getDAO('GenreDAO');
00163 $genreDao->installDefaults($pressId, $installedLocales);
00164
00165
00166 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00167 $userGroupDao->installSettings($pressId, 'registry/userGroups.xml');
00168
00169
00170 $sessionManager =& SessionManager::getManager();
00171 $userSession =& $sessionManager->getUserSession();
00172 if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($pressId)) {
00173
00174 $managerUserGroup =& $userGroupDao->getDefaultByRoleId($pressId, ROLE_ID_PRESS_MANAGER);
00175 $userGroupDao->assignUserToGroup($userSession->getUserId(), $managerUserGroup->getId());
00176 }
00177
00178
00179 $pressSettingsDao =& DAORegistry::getDAO('PressSettingsDAO');
00180 $titles = $this->getData('title');
00181 AppLocale::requireComponents(LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS);
00182 $pressSettingsDao->installSettings($pressId, 'registry/pressSettings.xml', array(
00183 'indexUrl' => $request->getIndexUrl(),
00184 'pressPath' => $this->getData('path'),
00185 'primaryLocale' => $site->getPrimaryLocale(),
00186 'pressName' => $titles[$site->getPrimaryLocale()]
00187 ));
00188 }
00189 $press->updateSetting('name', $this->getData('name'), 'string', true);
00190 $press->updateSetting('description', $this->getData('description'), 'string', true);
00191 $press->updateSetting('enabled', (int)$this->getData('enabled'), 0, true);
00192
00193
00194 PluginRegistry::loadAllPlugins();
00195
00196 HookRegistry::call('PressSiteSettingsForm::execute', array(&$this, &$press, &$series, &$isNewPress));
00197
00198 if ($isNewPress || $pathChanged) {
00199 return $press->getPath();
00200 }
00201 }
00202
00203 }
00204
00205 ?>