00001 <?php
00002
00015
00016
00017
00018 import('db.DBDataXMLParser');
00019 import('form.Form');
00020
00021 class JournalSiteSettingsForm extends Form {
00022
00024 var $journalId;
00025
00030 function JournalSiteSettingsForm($journalId = null) {
00031 parent::Form('admin/journalSettings.tpl');
00032
00033 $this->journalId = isset($journalId) ? (int) $journalId : null;
00034
00035
00036 $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'admin.journals.form.titleRequired'));
00037 $this->addCheck(new FormValidator($this, 'path', 'required', 'admin.journals.form.pathRequired'));
00038 $this->addCheck(new FormValidatorAlphaNum($this, 'path', 'required', 'admin.journals.form.pathAlphaNumeric'));
00039 $this->addCheck(new FormValidatorCustom($this, 'path', 'required', 'admin.journals.form.pathExists', create_function('$path,$form,$journalDao', 'return !$journalDao->journalExistsByPath($path) || ($form->getData(\'oldPath\') != null && $form->getData(\'oldPath\') == $path);'), array(&$this, DAORegistry::getDAO('JournalDAO'))));
00040 $this->addCheck(new FormValidatorPost($this));
00041 }
00042
00046 function display() {
00047 $templateMgr = &TemplateManager::getManager();
00048 $templateMgr->assign('journalId', $this->journalId);
00049 $templateMgr->assign('helpTopicId', 'site.siteManagement');
00050 parent::display();
00051 }
00052
00056 function initData() {
00057 if (isset($this->journalId)) {
00058 $journalDao = &DAORegistry::getDAO('JournalDAO');
00059 $journal = &$journalDao->getJournal($this->journalId);
00060
00061 if ($journal != null) {
00062 $this->_data = array(
00063 'title' => $journal->getSetting('title', null),
00064 'description' => $journal->getSetting('description', null),
00065 'path' => $journal->getPath(),
00066 'enabled' => $journal->getEnabled()
00067 );
00068
00069 } else {
00070 $this->journalId = null;
00071 }
00072 }
00073 if (!isset($this->journalId)) {
00074 $this->_data = array(
00075 'enabled' => 1
00076 );
00077 }
00078 }
00079
00083 function readInputData() {
00084 $this->readUserVars(array('title', 'description', 'path', 'enabled'));
00085 $this->setData('enabled', (int)$this->getData('enabled'));
00086
00087 if (isset($this->journalId)) {
00088 $journalDao = &DAORegistry::getDAO('JournalDAO');
00089 $journal = &$journalDao->getJournal($this->journalId);
00090 $this->setData('oldPath', $journal->getPath());
00091 }
00092 }
00093
00098 function getLocaleFieldNames() {
00099 return array('title', 'description');
00100 }
00101
00105 function execute() {
00106 $journalDao = &DAORegistry::getDAO('JournalDAO');
00107
00108 if (isset($this->journalId)) {
00109 $journal = &$journalDao->getJournal($this->journalId);
00110 }
00111
00112 if (!isset($journal)) {
00113 $journal = &new Journal();
00114 }
00115
00116 $journal->setPath($this->getData('path'));
00117 $journal->setEnabled($this->getData('enabled'));
00118
00119 if ($journal->getJournalId() != null) {
00120 $isNewJournal = false;
00121 $journalDao->updateJournal($journal);
00122 $section = null;
00123 } else {
00124 $isNewJournal = true;
00125 $site =& Request::getSite();
00126
00127
00128 $journal->setPrimaryLocale ($site->getPrimaryLocale());
00129
00130 $journalId = $journalDao->insertJournal($journal);
00131 $journalDao->resequenceJournals();
00132
00133
00134 $sessionManager = &SessionManager::getManager();
00135 $userSession = &$sessionManager->getUserSession();
00136 if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
00137 $role = &new Role();
00138 $role->setJournalId($journalId);
00139 $role->setUserId($userSession->getUserId());
00140 $role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
00141
00142 $roleDao = &DAORegistry::getDAO('RoleDAO');
00143 $roleDao->insertRole($role);
00144 }
00145
00146
00147 import('file.FileManager');
00148 FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
00149 FileManager::mkdir(Config::getVar('files', 'files_dir'). '/journals/' . $journalId . '/articles');
00150 FileManager::mkdir(Config::getVar('files', 'files_dir'). '/journals/' . $journalId . '/issues');
00151 FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
00152
00153
00154 $journalSettingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00155 $titles = $this->getData('title');
00156 $journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array(
00157 'indexUrl' => Request::getIndexUrl(),
00158 'journalPath' => $this->getData('path'),
00159 'primaryLocale' => $site->getPrimaryLocale(),
00160 'journalName' => $titles[$site->getPrimaryLocale()]
00161 ));
00162
00163
00164 import('rt.ojs.JournalRTAdmin');
00165 $journalRtAdmin = &new JournalRTAdmin($journalId);
00166 $journalRtAdmin->restoreVersions(false);
00167
00168
00169 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00170 $section = &new Section();
00171 $section->setJournalId($journal->getJournalId());
00172 $section->setTitle(Locale::translate('section.default.title'), $journal->getPrimaryLocale());
00173 $section->setAbbrev(Locale::translate('section.default.abbrev'), $journal->getPrimaryLocale());
00174 $section->setMetaIndexed(true);
00175 $section->setMetaReviewed(true);
00176 $section->setPolicy(Locale::translate('section.default.policy'), $journal->getPrimaryLocale());
00177 $section->setEditorRestricted(false);
00178 $section->setHideTitle(false);
00179 $sectionDao->insertSection($section);
00180
00181 }
00182 $journal->updateSetting('title', $this->getData('title'), 'string', true);
00183 $journal->updateSetting('description', $this->getData('description'), 'string', true);
00184 HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
00185 }
00186
00187 }
00188
00189 ?>