Exemplo n.º 1
0
 /**
  * Set the file to use as the default editing file.
  * @param $trackDirectorSubmission object
  * @param $fileId int
  * @param $revision int
  * @param $createGalley boolean
  * TODO: SECURITY!
  */
 function setEditingFile($trackDirectorSubmission, $fileId, $revision, $createGalley = false)
 {
     import('file.PaperFileManager');
     $paperFileManager = new PaperFileManager($trackDirectorSubmission->getPaperId());
     $trackDirectorSubmissionDao =& DAORegistry::getDAO('TrackDirectorSubmissionDAO');
     $paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
     $user =& Request::getUser();
     if (!HookRegistry::call('TrackDirectorAction::setEditingFile', array(&$trackDirectorSubmission, &$fileId, &$revision))) {
         // Copy the file from the director decision file folder to the layout folder
         $newFileId = $paperFileManager->copyToLayoutFile($fileId, $revision);
         $trackDirectorSubmission->setLayoutFileId($newFileId);
         $trackDirectorSubmissionDao->updateTrackDirectorSubmission($trackDirectorSubmission);
         if ($createGalley) {
             $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
             $galleys =& $paperGalleyDao->getGalleysByPaper($trackDirectorSubmission->getPaperId());
             if (empty($galleys)) {
                 $layoutFile =& $paperFileDao->getPaperFile($newFileId, $revision);
                 $fileType = $layoutFile->getFileType();
                 $fileId = $paperFileManager->copyPublicFile($layoutFile->getFilePath(), $fileType);
                 if (strstr($fileType, 'html')) {
                     $galley = new PaperHTMLGalley();
                 } else {
                     $galley = new PaperGalley();
                 }
                 $galley->setPaperId($trackDirectorSubmission->getPaperId());
                 $galley->setLocale(Locale::getLocale());
                 $galley->setFileId($fileId);
                 if ($galley->isHTMLGalley()) {
                     $galley->setLabel('HTML');
                 } elseif (strstr($fileType, 'pdf')) {
                     $galley->setLabel('PDF');
                 } else {
                     if (strstr($fileType, 'postscript')) {
                         $galley->setLabel('Postscript');
                     } else {
                         if (strstr($fileType, 'xml')) {
                             $galley->setLabel('XML');
                         } else {
                             $galley->setLabel(Locale::translate('common.untitled'));
                         }
                     }
                 }
                 $paperGalleyDao->insertGalley($galley);
             }
         }
         // Add log
         import('paper.log.PaperLog');
         import('paper.log.PaperEventLogEntry');
         PaperLog::logEvent($trackDirectorSubmission->getPaperId(), PAPER_LOG_LAYOUT_SET_FILE, LOG_TYPE_FILE, $trackDirectorSubmission->getLayoutFileId(), 'log.layout.layoutFileSet', array('directorName' => $user->getFullName(), 'paperId' => $trackDirectorSubmission->getPaperId()));
     }
 }
Exemplo n.º 2
0
 /**
  * Save changes to the galley.
  * @return int the galley ID
  */
 function execute($fileName = null)
 {
     import('classes.file.PaperFileManager');
     $paperFileManager = new PaperFileManager($this->paperId);
     $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
     $fileName = isset($fileName) ? $fileName : 'galleyFile';
     if (isset($this->galley)) {
         $galley =& $this->galley;
         // Upload galley file
         if ($paperFileManager->uploadedFileExists($fileName)) {
             if ($galley->getFileId()) {
                 $paperFileManager->uploadPublicFile($fileName, $galley->getFileId());
             } else {
                 $fileId = $paperFileManager->uploadPublicFile($fileName);
                 $galley->setFileId($fileId);
             }
             // Update file search index
             import('classes.search.PaperSearchIndex');
             PaperSearchIndex::updateFileIndex($this->paperId, PAPER_SEARCH_GALLEY_FILE, $galley->getFileId());
         }
         if ($paperFileManager->uploadedFileExists('styleFile')) {
             // Upload stylesheet file
             $styleFileId = $paperFileManager->uploadPublicFile('styleFile', $galley->getStyleFileId());
             $galley->setStyleFileId($styleFileId);
         } else {
             if ($this->getData('deleteStyleFile')) {
                 // Delete stylesheet file
                 $styleFile =& $galley->getStyleFile();
                 if (isset($styleFile)) {
                     $paperFileManager->deleteFile($styleFile->getFileId());
                 }
             }
         }
         // Update existing galley
         $galley->setLabel($this->getData('label'));
         $galley->setLocale($this->getData('galleyLocale'));
         $galleyDao->updateGalley($galley);
     } else {
         // Upload galley file
         if ($paperFileManager->uploadedFileExists($fileName)) {
             $fileType = $paperFileManager->getUploadedFileType($fileName);
             $fileId = $paperFileManager->uploadPublicFile($fileName);
             // Update file search index
             import('classes.search.PaperSearchIndex');
             PaperSearchIndex::updateFileIndex($this->paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
         } else {
             $fileId = 0;
         }
         if (isset($fileType) && strstr($fileType, 'html')) {
             // Assume HTML galley
             $galley = new PaperHTMLGalley();
         } else {
             $galley = new PaperGalley();
         }
         $galley->setPaperId($this->paperId);
         $galley->setFileId($fileId);
         if ($this->getData('label') == null) {
             // Generate initial label based on file type
             if ($galley->isHTMLGalley()) {
                 $galley->setLabel('HTML');
             } else {
                 if (isset($fileType)) {
                     if (strstr($fileType, 'pdf')) {
                         $galley->setLabel('PDF');
                     } else {
                         if (strstr($fileType, 'postscript')) {
                             $galley->setLabel('PostScript');
                         } else {
                             if (strstr($fileType, 'xml')) {
                                 $galley->setLabel('XML');
                             } else {
                                 if (strstr($fileType, 'audio')) {
                                     $galley->setLabel('Audio');
                                 } else {
                                     if (strstr($fileType, 'powerpoint')) {
                                         $galley->setLabel('Slideshow');
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($galley->getLabel() == null) {
                 $galley->setLabel(Locale::translate('common.untitled'));
             }
         } else {
             $galley->setLabel($this->getData('label'));
         }
         $galley->setLocale($this->getData('galleyLocale'));
         // Insert new galley
         $galleyDao->insertGalley($galley);
         $this->galleyId = $galley->getId();
     }
     return $this->galleyId;
 }