00001 <?php
00002
00020
00021
00022
00023 import('form.Form');
00024 import('issue.Issue');
00025
00026 class IssueForm extends Form {
00027
00031 function IssueForm($template) {
00032 parent::Form($template);
00033 $this->addCheck(new FormValidatorPost($this));
00034 }
00035
00040 function getLocaleFieldNames() {
00041 $issueDao =& DAORegistry::getDAO('IssueDAO');
00042 return $issueDao->getLocaleFieldNames();
00043 }
00044
00048 function display() {
00049 $templateMgr =& TemplateManager::getManager();
00050 $journal =& Request::getJournal();
00051
00052
00053 $templateMgr->assign('enableSubscriptions', $journal->getSetting('enableSubscriptions'));
00054 $templateMgr->assign('enableDelayedOpenAccess', $journal->getSetting('enableDelayedOpenAccess'));
00055
00056 $accessOptions = array();
00057 $accessOptions[OPEN_ACCESS] = Locale::Translate('editor.issues.openAccess');
00058 $accessOptions[SUBSCRIPTION] = Locale::Translate('editor.issues.subscription');
00059 $templateMgr->assign('accessOptions', $accessOptions);
00060
00061 $templateMgr->assign('enablePublicIssueId', $journal->getSetting('enablePublicIssueId'));
00062
00063 parent::display();
00064 }
00065
00069 function validate($issueId = 0) {
00070 if ($this->getData('showVolume')) {
00071 $this->addCheck(new FormValidatorCustom($this, 'volume', 'required', 'editor.issues.volumeRequired', create_function('$volume', 'return ($volume > 0);')));
00072 }
00073
00074 if ($this->getData('showNumber')) {
00075 $this->addCheck(new FormValidatorCustom($this, 'number', 'required', 'editor.issues.numberRequired', create_function('$number', 'return ($number > 0);')));
00076 }
00077
00078 if ($this->getData('showYear')) {
00079 $this->addCheck(new FormValidatorCustom($this, 'year', 'required', 'editor.issues.yearRequired', create_function('$year', 'return ($year > 0);')));
00080 }
00081
00082 if ($this->getData('showTitle')) {
00083 $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'editor.issues.titleRequired'));
00084 }
00085
00086
00087 $journal =& Request::getJournal();
00088 $issueDao =& DAORegistry::getDAO('IssueDAO');
00089
00090 $publicIssueId = $this->getData('publicIssueId');
00091 if ($publicIssueId && $issueDao->publicIssueIdExists($publicIssueId, $issueId, $journal->getJournalId())) {
00092 $this->addError('publicIssueId', Locale::translate('editor.issues.issuePublicIdentificationExists'));
00093 $this->addErrorField('publicIssueId');
00094 }
00095
00096
00097
00098 $subscription = $journal->getSetting('enableSubscriptions');
00099 $delayedOpenAccess = $journal->getSetting('enableDelayedOpenAccess');
00100 if (!empty($issueId)) {
00101 $issue =& $issueDao->getIssueById($issueId);
00102 $issuePublished = $issue->getPublished();
00103 } else {
00104 $issuePublished = 0;
00105 }
00106
00107 if (($subscription && !$delayedOpenAccess) || ($subscription && $delayedOpenAccess && $issuePublished)) {
00108 $month = $this->getData('Date_Month');
00109 $day = $this->getData('Date_Day');
00110 $year = $this->getData('Date_Year');
00111 if (!checkdate($month,$day,$year)) {
00112 $this->addError('openAccessDate', Locale::translate('editor.issues.invalidAccessDate'));
00113 $this->addErrorField('openAccessDate');
00114 }
00115 }
00116
00117 import('file.PublicFileManager');
00118 $publicFileManager =& new PublicFileManager();
00119
00120 if ($publicFileManager->uploadedFileExists('coverPage')) {
00121 $type = $publicFileManager->getUploadedFileType('coverPage');
00122 if (!$publicFileManager->getImageExtension($type)) {
00123 $this->addError('coverPage', Locale::translate('editor.issues.invalidCoverPageFormat'));
00124 $this->addErrorField('coverPage');
00125 }
00126 }
00127
00128 if ($publicFileManager->uploadedFileExists('styleFile')) {
00129 $type = $publicFileManager->getUploadedFileType('styleFile');
00130 if ($type != 'text/plain' && $type != 'text/css') {
00131 $this->addError('styleFile', Locale::translate('editor.issues.invalidStyleFormat'));
00132 }
00133 }
00134
00135 return parent::validate();
00136 }
00137
00142 function initData($issueId = null) {
00143 $issueDao =& DAORegistry::getDAO('IssueDAO');
00144
00145
00146 if (isset($issueId)) {
00147 $issue =& $issueDao->getIssueById($issueId);
00148 }
00149
00150 if (isset($issue)) {
00151 $openAccessDate = $issue->getOpenAccessDate();
00152 if (isset($openAccessDate)) $openAccessDate = getdate(strtotime($openAccessDate));
00153
00154 $this->_data = array(
00155 'title' => $issue->getTitle(null),
00156 'volume' => $issue->getVolume(),
00157 'number' => $issue->getNumber(),
00158 'year' => $issue->getYear(),
00159 'datePublished' => $issue->getDatePublished(),
00160 'description' => $issue->getDescription(null),
00161 'publicIssueId' => $issue->getPublicIssueId(),
00162 'accessStatus' => $issue->getAccessStatus(),
00163 'Date_Month' => $openAccessDate['mon'],
00164 'Date_Day' => $openAccessDate['mday'],
00165 'Date_Year' => $openAccessDate['year'],
00166 'showVolume' => $issue->getShowVolume(),
00167 'showNumber' => $issue->getShowNumber(),
00168 'showYear' => $issue->getShowYear(),
00169 'showTitle' => $issue->getShowTitle(),
00170 'fileName' => $issue->getFileName(null),
00171 'originalFileName' => $issue->getOriginalFileName(null),
00172 'coverPageDescription' => $issue->getCoverPageDescription(null),
00173 'coverPageAltText' => $issue->getCoverPageAltText(null),
00174 'showCoverPage' => $issue->getShowCoverPage(null),
00175 'hideCoverPageArchives' => $issue->getHideCoverPageArchives(null),
00176 'hideCoverPageCover' => $issue->getHideCoverPageCover(null),
00177 'styleFileName' => $issue->getStyleFileName(),
00178 'originalStyleFileName' => $issue->getOriginalStyleFileName()
00179 );
00180 return $issue->getIssueId();
00181
00182 } else {
00183 $journal =& Request::getJournal();
00184 $showVolume = $journal->getSetting('publicationFormatVolume');
00185 $showNumber = $journal->getSetting('publicationFormatNumber');
00186 $showYear = $journal->getSetting('publicationFormatYear');
00187 $showTitle = $journal->getSetting('publicationFormatTitle');
00188
00189 $this->setData('showVolume', $showVolume);
00190 $this->setData('showNumber', $showNumber);
00191 $this->setData('showYear', $showYear);
00192 $this->setData('showTitle', $showTitle);
00193
00194
00195 $issueDao =& DAORegistry::getDAO('IssueDAO');
00196 $issue = $issueDao->getLastCreatedIssue($journal->getJournalId());
00197
00198 if (isset($issue)) {
00199 $volumePerYear = $journal->getSetting('volumePerYear');
00200 $issuePerVolume = $journal->getSetting('issuePerVolume');
00201 $number = $issue->getNumber();
00202 $volume = $issue->getVolume();
00203 $year = $issue->getYear();
00204
00205 if ($showVolume && $showNumber && $showYear) {
00206 $number++;
00207 if ($issuePerVolume && $number > $issuePerVolume) {
00208 $number = 1;
00209 $volume++;
00210 if ($volumePerYear && $volume > $volumePerYear) {
00211 $volume = 1;
00212 $year++;
00213 }
00214 }
00215 } elseif ($showVolume && $showNumber) {
00216 $number++;
00217 if ($issuePerVolume && $number > $issuePerVolume) {
00218 $number = 1;
00219 $volume++;
00220 }
00221 } elseif ($showVolume && $showYear) {
00222 $number = 0;
00223 $volume++;
00224 if ($volumePerYear && $volume > $volumePerYear) {
00225 $volume = 1;
00226 $year++;
00227 }
00228 } elseif ($showYear) {
00229 $volume = $number = 0;
00230 $year++;
00231 } else {
00232 $year = $volume = $number = 0;
00233 }
00234
00235
00236 } else {
00237 $volume = $journal->getSetting('initialVolume');
00238 $number = $journal->getSetting('initialNumber');
00239 $year = $journal->getSetting('initialYear');
00240 }
00241
00242
00243 if ($journal->getSetting('enableSubscriptions')) {
00244 $accessStatus = SUBSCRIPTION;
00245 } else {
00246 $accessStatus = OPEN_ACCESS;
00247 }
00248
00249
00250 $this->_data = array(
00251 'showVolume' => $showVolume,
00252 'showNumber' => $showNumber,
00253 'showYear' => $showYear,
00254 'showTitle' => $showTitle,
00255 'volume' => $volume,
00256 'number' => $number,
00257 'year' => $year,
00258 'accessStatus' => $accessStatus
00259 );
00260
00261 }
00262 }
00263
00267 function readInputData() {
00268 $this->readUserVars(array(
00269 'title',
00270 'volume',
00271 'number',
00272 'year',
00273 'description',
00274 'publicIssueId',
00275 'accessStatus',
00276 'Date_Month',
00277 'Date_Day',
00278 'Date_Year',
00279 'showVolume',
00280 'showNumber',
00281 'showYear',
00282 'showTitle',
00283 'fileName',
00284 'originalFileName',
00285 'coverPageDescription',
00286 'coverPageAltText',
00287 'showCoverPage',
00288 'hideCoverPageArchives',
00289 'hideCoverPageCover',
00290 'articles',
00291 'styleFileName',
00292 'originalStyleFileName'
00293 ));
00294
00295 $this->readUserDateVars(array('datePublished'));
00296
00297 $this->addCheck(new FormValidatorCustom($this, 'showVolume', 'required', 'editor.issues.issueIdentificationRequired', create_function('$showVolume, $showNumber, $showYear, $showTitle', 'return $showVolume || $showNumber || $showYear || $showTitle ? true : false;'), array($this->getData('showNumber'), $this->getData('showYear'), $this->getData('showTitle'))));
00298
00299 }
00300
00304 function execute($issueId = 0) {
00305 $journal =& Request::getJournal();
00306 $issueDao =& DAORegistry::getDAO('IssueDAO');
00307
00308 if ($issueId) {
00309 $issue = $issueDao->getIssueById($issueId);
00310 $isNewIssue = false;
00311 } else {
00312 $issue =& new Issue();
00313 $isNewIssue = true;
00314 }
00315 $volume = $this->getData('volume');
00316 $number = $this->getData('number');
00317 $year = $this->getData('year');
00318
00319 $showVolume = $this->getData('showVolume');
00320 $showNumber = $this->getData('showNumber');
00321 $showYear = $this->getData('showYear');
00322 $showTitle = $this->getData('showTitle');
00323
00324 $issue->setJournalId($journal->getJournalId());
00325 $issue->setTitle($this->getData('title'), null);
00326 $issue->setVolume(empty($volume) ? 0 : $volume);
00327 $issue->setNumber(empty($number) ? 0 : $number);
00328 $issue->setYear(empty($year) ? 0 : $year);
00329 if (!$isNewIssue) {
00330 $issue->setDatePublished($this->getData('datePublished'));
00331 }
00332 $issue->setDescription($this->getData('description'), null);
00333 $issue->setPublicIssueId($this->getData('publicIssueId'));
00334 $issue->setShowVolume(empty($showVolume) ? 0 : $showVolume);
00335 $issue->setShowNumber(empty($showNumber) ? 0 : $showNumber);
00336 $issue->setShowYear(empty($showYear) ? 0 : $showYear);
00337 $issue->setShowTitle(empty($showTitle) ? 0 : $showTitle);
00338 $issue->setCoverPageDescription($this->getData('coverPageDescription'), null);
00339 $issue->setCoverPageAltText($this->getData('coverPageAltText'), null);
00340 $showCoverPage = array_map(create_function('$arrayElement', 'return (int)$arrayElement;'), (array) $this->getData('showCoverPage'));
00341 foreach (array_keys($this->getData('coverPageDescription')) as $locale) {
00342 if (!array_key_exists($locale, $showCoverPage)) {
00343 $showCoverPage[$locale] = 0;
00344 }
00345 }
00346 $issue->setShowCoverPage($showCoverPage, null);
00347
00348 $hideCoverPageArchives = array_map(create_function('$arrayElement', 'return (int)$arrayElement;'), (array) $this->getData('hideCoverPageArchives'));
00349 foreach (array_keys($this->getData('coverPageDescription')) as $locale) {
00350 if (!array_key_exists($locale, $hideCoverPageArchives)) {
00351 $hideCoverPageArchives[$locale] = 0;
00352 }
00353 }
00354 $issue->setHideCoverPageArchives($hideCoverPageArchives, null);
00355
00356 $hideCoverPageCover = array_map(create_function('$arrayElement', 'return (int)$arrayElement;'), (array) $this->getData('hideCoverPageCover'));
00357 foreach (array_keys($this->getData('coverPageDescription')) as $locale) {
00358 if (!array_key_exists($locale, $hideCoverPageCover)) {
00359 $hideCoverPageCover[$locale] = 0;
00360 }
00361 }
00362 $issue->setHideCoverPageCover($hideCoverPageCover, null);
00363
00364 $month = $this->getData('Date_Month');
00365 $day = $this->getData('Date_Day');
00366 $year = $this->getData('Date_Year');
00367
00368 if ($this->getData('accessStatus')) {
00369 $issue->setAccessStatus($this->getData('accessStatus'));
00370 $issue->setOpenAccessDate(date('Y-m-d H:i:s',mktime(0,0,0,$month,$day,$year)));
00371 } else {
00372 $issue->setAccessStatus(1);
00373 $issue->setOpenAccessDate(Core::getCurrentDate());
00374 }
00375
00376
00377 if ($issueId) {
00378 $issue->setIssueId($issueId);
00379 $issueDao->updateIssue($issue);
00380 } else {
00381 $issue->setPublished(0);
00382 $issue->setCurrent(0);
00383
00384 $issueId = $issueDao->insertIssue($issue);
00385 $issue->setIssueId($issueId);
00386 }
00387
00388 import('file.PublicFileManager');
00389 $publicFileManager =& new PublicFileManager();
00390 if ($publicFileManager->uploadedFileExists('coverPage')) {
00391 $journal = Request::getJournal();
00392 $originalFileName = $publicFileManager->getUploadedFileName('coverPage');
00393 $newFileName = 'cover_issue_' . $issueId . '_' . $this->getFormLocale() . '.' . $publicFileManager->getExtension($originalFileName);
00394 $publicFileManager->uploadJournalFile($journal->getJournalId(), 'coverPage', $newFileName);
00395 $issue->setOriginalFileName($publicFileManager->truncateFileName($originalFileName, 127), $this->getFormLocale());
00396 $issue->setFileName($newFileName, $this->getFormLocale());
00397
00398
00399 list($width, $height) = getimagesize($publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/' . $newFileName);
00400 $issue->setWidth($width, $this->getFormLocale());
00401 $issue->setHeight($height, $this->getFormLocale());
00402
00403 $issueDao->updateIssue($issue);
00404 }
00405
00406 if ($publicFileManager->uploadedFileExists('styleFile')) {
00407 $journal = Request::getJournal();
00408 $originalFileName = $publicFileManager->getUploadedFileName('styleFile');
00409 $newFileName = 'style_' . $issueId . '.css';
00410 $publicFileManager->uploadJournalFile($journal->getJournalId(), 'styleFile', $newFileName);
00411 $issue->setStyleFileName($newFileName);
00412 $issue->setOriginalStyleFileName($publicFileManager->truncateFileName($originalFileName, 127));
00413 $issueDao->updateIssue($issue);
00414 }
00415
00416 return $issueId;
00417 }
00418 }
00419
00420 ?>