/**
  * @see Form::execute()
  * @return MonographFile if successful, otherwise null
  */
 function &execute()
 {
     // Identify the file genre.
     $revisedFileId = $this->getRevisedFileId();
     if ($revisedFileId) {
         // The file genre will be copied over from the revised file.
         $fileGenre = null;
     } else {
         // This is a new file so we need the file genre from the form.
         $fileGenre = $this->getData('genreId') ? (int) $this->getData('genreId') : null;
     }
     // Upload the file.
     import('classes.file.MonographFileManager');
     return MonographFileManager::uploadMonographFile($this->getData('monographId'), 'uploadedFile', $this->getFileStage(), $revisedFileId, $fileGenre);
 }
 /**
  * Download the monograph file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function downloadFile($args, &$request)
 {
     $monographId = $request->getUserVar('monographId');
     $fileId = $request->getUserVar('fileId');
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFile($monographId, $fileId);
 }
 /**
  * Upload a copyediting file
  * @param $args array
  * @param $request PKPRequest
  */
 function uploadFile($args, &$request)
 {
     // Get the copyediting signoff
     $signoffDao =& DAORegistry::getDAO('SignoffDAO');
     /* @var $signoffDao SignoffDAO */
     $signoff =& $signoffDao->getById($this->getSignoffId());
     assert(is_a($signoff, 'Signoff'));
     // Get the file that is being copyedited
     $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
     /* @var $submissionFileDao SubmissionFileDAO */
     $copyeditingFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
     // Get the copyedited file if it exists
     if ($signoff->getFileId()) {
         $copyeditedFile =& $submissionFileDao->getLatestRevision($signoff->getFileId());
     }
     // If we're updating a file, get its ID for the file manager
     $copyeditedFileId = isset($copyeditedFile) ? $copyeditedFile->getFileId() : null;
     $monograph =& $this->getMonograph();
     import('classes.file.MonographFileManager');
     if (MonographFileManager::uploadedFileExists('copyeditingFile')) {
         $copyeditedFileId = MonographFileManager::uploadCopyeditResponseFile($monograph->getId(), 'copyeditingFile', $copyeditedFileId);
         if (isset($copyeditedFileId)) {
             // Amend the copyediting signoff with the new file
             $signoff->setFileId($copyeditedFileId);
             $signoff->setDateCompleted(Core::getCurrentDate());
             $signoffDao->updateObject($signoff);
             $copyeditedFile =& $submissionFileDao->getLatestRevision($copyeditedFileId);
             // Transfer some of the original file's metadata over to the new file
             $copyeditedFile->setName($copyeditingFile->getLocalizedName(), Locale::getLocale());
             $copyeditedFile->setGenreId($copyeditingFile->getGenreId());
             $submissionFileDao->updateObject($copyeditedFile);
         }
     }
     return $copyeditedFileId;
 }
 /**
  * Generate a unique filename for a monograph file. Sets the filename
  * field in the monographFile to the generated value.
  * @param $monographFile MonographFile the monograph to generate a filename for
  */
 function _generateAndPopulateFileName(&$monographFile)
 {
     // If the file has a file genre set then start the
     // file name with human readable genre information.
     $genreId = $monographFile->getGenreId();
     if ($genreId) {
         $primaryLocale = Locale::getPrimaryLocale();
         $genreDao =& DAORegistry::getDAO('GenreDAO');
         /* @var $genreDao GenreDAO */
         $genre =& $genreDao->getById($genreId);
         assert(is_a($genre, 'Genre'));
         $fileName = $genre->getDesignation($primaryLocale) . '_' . date('Ymd') . '-' . $genre->getName($primaryLocale) . '-';
     }
     // Make the file name unique across all files and file revisions.
     $extension = MonographFileManager::parseFileExtension($monographFile->getOriginalFileName());
     $fileName .= $monographFile->getMonographId() . '-' . $monographFile->getFileId() . '-' . $monographFile->getRevision() . '-' . $monographFile->getFileStage() . '.' . $extension;
     // Populate the monograph file with the generated file name.
     $monographFile->setFileName($fileName);
 }
 /**
  * Save the email in the monograph email log.
  */
 function log()
 {
     import('classes.monograph.log.MonographEmailLogEntry');
     import('classes.monograph.log.MonographLog');
     $entry = new MonographEmailLogEntry();
     $monograph =& $this->monograph;
     // Log data
     $entry->setEventType($this->eventType);
     $entry->setAssocType($this->assocType);
     $entry->setAssocId($this->assocId);
     // Email data
     $entry->setSubject($this->getSubject());
     $entry->setBody($this->getBody());
     $entry->setFrom($this->getFromString(false));
     $entry->setRecipients($this->getRecipientString());
     $entry->setCcs($this->getCcString());
     $entry->setBccs($this->getBccString());
     // Add log entry
     $logEntryId = MonographLog::logEmailEntry($monograph->getId(), $entry);
     // Add attachments
     import('classes.file.MonographFileManager');
     foreach ($this->getAttachmentFiles() as $attachment) {
         MonographFileManager::temporaryFileToMonographFile($monograph->getId(), $attachment, MONOGRAPH_FILE_ATTACHMENT, $logEntryId, ASSOC_TYPE_MONOGRAPH_EMAIL_LOG_ENTRY);
     }
 }
 /**
  * Download all of the monograph files as one compressed file
  * @param $args array
  * @param $request PKPRequest
  */
 function downloadAllFiles($args, &$request)
 {
     $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
     /* @var $monograph Monograph */
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFilesArchive($monograph->getId(), $this->getData());
 }
 /**
  * @see Form::execute()
  * @param $request Request
  * @return MonographFile if successful, otherwise null
  */
 function &execute($request)
 {
     // Identify the file genre.
     $revisedFileId = $this->getRevisedFileId();
     if ($revisedFileId) {
         // The file genre will be copied over from the revised file.
         $fileGenre = null;
     } else {
         // This is a new file so we need the file genre from the form.
         $fileGenre = $this->getData('genreId') ? (int) $this->getData('genreId') : null;
     }
     // Retrieve the uploader's user group.
     $uploaderUserGroupId = $this->getData('uploaderUserGroupId');
     if (!$uploaderUserGroupId) {
         fatalError('Invalid uploader user group!');
     }
     // Identify the uploading user.
     $user =& $request->getUser();
     assert(is_a($user, 'User'));
     // Upload the file.
     import('classes.file.MonographFileManager');
     return MonographFileManager::uploadMonographFile($this->getData('monographId'), 'uploadedFile', $this->getData('fileStage'), $user->getId(), $uploaderUserGroupId, $revisedFileId, $fileGenre);
 }
 /**
  * Download the monograph file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function downloadFile($args, &$request)
 {
     $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
     $fileId = (int) $request->getUserVar('fileId');
     assert(!empty($fileId));
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFile($monograph->getId(), $fileId);
 }
 /**
  * Download the monograph file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function downloadFile($args, &$request)
 {
     $monographId = $request->getUserVar('monographId');
     $fileId = $request->getUserVar('fileId');
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $user =& $session->getUser();
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFile($monographId, $fileId);
 }
Example #10
0
 /**
  * View a file.
  * @param $args array
  * @param $request Request
  */
 function viewFile($args, &$request)
 {
     // FIXME: authorize!
     $fileId = (int) $request->getUserVar('fileId');
     $revision = (int) $request->getUserVar('fileRevision');
     $monograph =& $this->getMonograph();
     import('classes.file.MonographFileManager');
     MonographFileManager::viewFile($monograph->getId(), $fileId, $revision ? $revision : null);
 }
 /**
  * Save name for library file
  * @param $args array
  * @param $request PKPRequest
  */
 function execute($args, &$request)
 {
     $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
     $reviewAssignment =& $reviewAssignmentDao->getById($this->reviewId);
     $fileId = null;
     $monographId = $reviewAssignment->getSubmissionId();
     import('classes.file.MonographFileManager');
     if (MonographFileManager::uploadedFileExists('attachment')) {
         if ($reviewAssignment->getReviewerFileId() != null) {
             $fileId = MonographFileManager::uploadReviewFile($monographId, 'attachment', $reviewAssignment->getReviewerFileId(), $this->reviewId);
         } else {
             $fileId = MonographFileManager::uploadReviewFile($monographId, 'attachment', null, $this->reviewId);
         }
     }
     return $fileId;
 }
 /**
  * View a file
  * @param $args array
  * @param $request Request
  */
 function viewFile($args, &$request)
 {
     $monographId = (int) $request->getUserVar('monographId');
     $fileId = (int) $request->getUserVar('fileId');
     $revision = (int) $request->getUserVar('fileRevision');
     import('classes.file.MonographFileManager');
     MonographFileManager::viewFile($monographId, $fileId, $revision ? $revision : null);
 }
 /**
  * Download all of the monograph files as one compressed file.
  * @param $args array
  * @param $request Request
  */
 function downloadAllFiles($args, &$request)
 {
     // Retrieve the monograph.
     $monograph =& $this->getMonograph();
     $monographId = $monograph->getId();
     // Find out the paths of all files in this grid.
     import('classes.file.MonographFileManager');
     $filesDir = MonographFileManager::_getFilesDir($monographId);
     $filePaths = array();
     foreach ($this->getGridDataElements($request) as $submissionFileData) {
         $monographFile =& $submissionFileData['submissionFile'];
         /* @var $monographFile MonographFile */
         // Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path)
         $filePath = str_replace($filesDir, '', $monographFile->getFilePath());
         // Add files to be archived to array
         $filePaths[] = escapeshellarg($filePath);
         unset($monographFile);
     }
     // Create a temporary file.
     $archivePath = tempnam('/tmp', 'sf-');
     // Create the archive and download the file.
     exec(Config::getVar('cli', 'tar') . ' -c -z ' . '-f ' . escapeshellarg($archivePath) . ' ' . '-C ' . escapeshellarg($filesDir) . ' ' . implode(' ', array_map('escapeshellarg', $filePaths)));
     if (file_exists($archivePath)) {
         FileManager::downloadFile($archivePath);
         FileManager::deleteFile($archivePath);
     } else {
         fatalError('Creating archive with submission files failed!');
     }
 }
 /**
  * Save the email in the monograph email log.
  */
 function log($request = null)
 {
     import('classes.log.MonographLog');
     $entry = new MonographEmailLogEntry();
     $monograph =& $this->monograph;
     // Event data
     $entry->setEventType($this->logEventType);
     $entry->setAssocType(ASSOC_TYPE_MONOGRAPH);
     $entry->setAssocId($monograph->getId());
     $entry->setDateSent(Core::getCurrentDate());
     // User data
     if ($request) {
         $user =& $request->getUser();
         $entry->setSenderId($user == null ? 0 : $user->getId());
         $entry->setIPAddress($request->getRemoteAddr());
     }
     // Email data
     $entry->setSubject($this->getSubject());
     $entry->setBody($this->getBody());
     $entry->setFrom($this->getFromString(false));
     $entry->setRecipients($this->getRecipientString());
     $entry->setCcs($this->getCcString());
     $entry->setBccs($this->getBccString());
     // Add log entry
     $logDao =& DAORegistry::getDAO('MonographEmailLogDAO');
     $logDao->insertObject($entry);
     // Add attachments
     import('classes.file.MonographFileManager');
     foreach ($this->getAttachmentFiles() as $attachment) {
         MonographFileManager::temporaryFileToMonographFile($monograph->getId(), $attachment, MONOGRAPH_FILE_ATTACHMENT, $logEntryId, ASSOC_TYPE_MONOGRAPH_EMAIL_LOG_ENTRY);
     }
 }
 /**
  * Save name for library file
  * @param $args array
  * @param $request PKPRequest
  */
 function execute($args, &$request)
 {
     import('classes.file.MonographFileManager');
     if (MonographFileManager::uploadedFileExists('attachment')) {
         $fileId = MonographFileManager::uploadReviewFile($this->monographId, 'attachment');
     }
     return $fileId;
 }
 /**
  * Download the monograph file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function downloadFile($args, &$request)
 {
     $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
     $fileId = (int) $request->getUserVar('fileId');
     assert(!empty($fileId));
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $user =& $session->getUser();
     $viewsDao =& DAORegistry::getDAO('ViewsDAO');
     $viewsDao->recordView(ASSOC_TYPE_MONOGRAPH_FILE, $fileId, $user->getId());
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFile($monograph->getId(), $fileId);
 }
 /**
  * Download all of the monograph files as one compressed file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function downloadAllFiles($args, &$request)
 {
     $monographId = $request->getUserVar('monographId');
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFilesArchive($monographId, $this->getData());
 }
Example #18
0
 /**
  * @see SubmissionFile::getFilePath()
  */
 function getFilePath()
 {
     $monographDao =& DAORegistry::getDAO('MonographDAO');
     /* @var $monographDao MonographDAO */
     $monograph =& $monographDao->getMonograph($this->getMonographId());
     import('classes.file.MonographFileManager');
     return $monograph->getFilePath() . MonographFileManager::fileStageToPath($this->getFileStage()) . '/' . $this->getFileName();
 }
 /**
  * Upload the file and add it to the database.
  * @param $monographId integer
  * @param $fileName string index into the $_FILES array
  * @param $fileStage int monograph file stage (one of the MONOGRAPH_FILE_* constants)
  * @param $uploaderUserId int The id of the user that uploaded the file.
  * @param $uploaderUserGroupId int The id of the user group that the uploader acted in
  *  when uploading the file.
  * @param $revisedFileId int ID of an existing file to revise
  * @param $genreId int foreign key into genres table (e.g. manuscript, etc.)
  * @param $assocType int
  * @param $assocId int
  * @return MonographFile the uploaded monograph file or null if an error occured.
  */
 function &_handleUpload($monographId, $fileName, $fileStage, $uploaderUserId, $uploaderUserGroupId, $revisedFileId = null, $genreId = null, $assocId = null, $assocType = null)
 {
     $nullVar = null;
     // Ensure that the file has been correctly uploaded to the server.
     if (!MonographFileManager::uploadedFileExists($fileName)) {
         return $nullVar;
     }
     // Retrieve the location of the uploaded file.
     $sourceFile = MonographFileManager::getUploadedFilePath($fileName);
     // Instantiate and pre-populate a new monograph file object.
     $monographFile = MonographFileManager::_instantiateMonographFile($sourceFile, $monographId, $fileStage, $revisedFileId, $genreId, $assocId, $assocType);
     if (is_null($monographFile)) {
         return $nullVar;
     }
     // Retrieve and copy the file type of the uploaded file.
     $fileType = MonographFileManager::getUploadedFileType($fileName);
     assert($fileType !== false);
     $monographFile->setFileType($fileType);
     // Retrieve and copy the file name of the uploaded file.
     $originalFileName = MonographFileManager::getUploadedFileName($fileName);
     assert($originalFileName !== false);
     $monographFile->setOriginalFileName(MonographFileManager::truncateFileName($originalFileName));
     // Set the uploader's user and user group id.
     $monographFile->setUploaderUserId($uploaderUserId);
     $monographFile->setUserGroupId($uploaderUserGroupId);
     // Copy the uploaded file to its final destination and
     // persist its meta-data to the database.
     $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
     /* @var $submissionFileDao SubmissionFileDAO */
     return $submissionFileDao->insertObject($monographFile, $fileName, true);
 }