18 import(
'classes.handler.Handler');
21 import(
'lib.pkp.classes.core.JSONMessage');
50 parent::__construct();
52 array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_AUTHOR, ROLE_ID_REVIEWER, ROLE_ID_ASSISTANT),
54 'startWizard',
'displayFileUploadForm',
55 'uploadFile',
'confirmRevision',
57 'finishFileSubmission'
70 parent::initialize($request);
73 $this->_fileStage = (int)$request->getUserVar(
'fileStage');
76 $uploaderRoles = $request->getUserVar(
'uploaderRoles');
77 if (!empty($uploaderRoles)) {
78 $this->_uploaderRoles = array();
79 $uploaderRoles = explode(
'-', $uploaderRoles);
80 foreach($uploaderRoles as $uploaderRole) {
81 if (!is_numeric($uploaderRole))
fatalError(
'Invalid uploader role!');
82 $this->_uploaderRoles[] = (int)$uploaderRole;
87 $this->_revisionOnly = (boolean)$request->getUserVar(
'revisionOnly');
89 $this->_assocType = $request->getUserVar(
'assocType') ? (int)$request->getUserVar(
'assocType') :
null;
90 $this->_assocId = $request->getUserVar(
'assocId') ? (int)$request->getUserVar(
'assocId') :
null;
93 if ($this->
getRevisionOnly() && $request->getUserVar(
'revisedFileId')) {
95 $this->_revisedFileId = (int)$request->getUserVar(
'revisedFileId');
100 LOCALE_COMPONENT_APP_SUBMISSION,
101 LOCALE_COMPONENT_PKP_SUBMISSION,
102 LOCALE_COMPONENT_PKP_COMMON,
103 LOCALE_COMPONENT_APP_COMMON
198 $templateMgr->assign(array(
203 'isReviewer' => $request->getUserVar(
'isReviewer'),
204 'revisionOnly' => $this->getRevisionOnly(),
205 'reviewRoundId' => is_a($reviewRound,
'ReviewRound')?$reviewRound->getId():
null,
206 'revisedFileId' => $this->getRevisedFileId(),
207 'assocType' => $this->getAssocType(),
208 'assocId' => $this->getAssocId(),
209 'dependentFilesOnly' => $request->getUserVar(
'dependentFilesOnly'),
211 return $templateMgr->fetchJson(
'controllers/wizard/fileUpload/fileUploadWizard.tpl');
222 import(
'lib.pkp.controllers.wizard.fileUpload.form.SubmissionFilesUploadForm');
225 $request, $submission->getId(), $this->getStageId(), $this->getUploaderRoles(), $this->getFileStage(),
226 $this->getRevisionOnly(), $this->getReviewRound(), $this->getRevisedFileId(),
227 $this->getAssocType(), $this->getAssocId()
229 $fileForm->initData();
232 return new JSONMessage(
true, $fileForm->fetch($request));
244 import(
'lib.pkp.controllers.wizard.fileUpload.form.SubmissionFilesUploadForm');
246 $request, $submission->getId(), $this->getStageId(),
null, $this->getFileStage(),
247 $this->getRevisionOnly(), $this->getReviewRound(),
null, $this->getAssocType(), $this->getAssocId()
249 $uploadForm->readInputData();
252 if (!$uploadForm->validate()) {
253 return new JSONMessage(
true, $uploadForm->fetch($request));
256 $uploadedFile = $uploadForm->execute();
257 if (!is_a($uploadedFile,
'SubmissionFile')) {
258 return new JSONMessage(
false, __(
'common.uploadFailed'));
269 if (!$uploadForm->getRevisedFileId()) {
270 $user = $request->getUser();
271 $revisionSubmissionFilesSelection = $uploadForm->getRevisionSubmissionFilesSelection($user, $uploadedFile);
272 $revisedFileId = $this->
_checkForRevision($uploadedFile, $revisionSubmissionFilesSelection);
273 if ($revisedFileId) {
275 import(
'lib.pkp.controllers.wizard.fileUpload.form.SubmissionFilesUploadConfirmationForm');
276 $confirmationForm =
new SubmissionFilesUploadConfirmationForm($request, $submission->getId(), $this->getStageId(), $this->getFileStage(), $reviewRound, $revisedFileId, $this->getAssocType(), $this->getAssocId(), $uploadedFile);
277 $confirmationForm->initData();
280 return new JSONMessage(
true, $confirmationForm->fetch($request),
'0', $uploadedFileInfo);
285 return new JSONMessage(
true,
'',
'0', $uploadedFileInfo);
293 switch ($submissionFile->getFileStage()) {
294 case SUBMISSION_FILE_ATTACHMENT:
299 $submissionFileDao->assignRevisionToReviewRound($submissionFile->getFileId(), $submissionFile->getRevision(), $reviewRound);
302 case SUBMISSION_FILE_REVIEW_FILE:
303 case SUBMISSION_FILE_REVIEW_ATTACHMENT:
304 case SUBMISSION_FILE_REVIEW_REVISION:
308 $submissionFileDao->assignRevisionToReviewRound($submissionFile->getFileId(), $submissionFile->getRevision(), $reviewRound);
310 if ($submissionFile->getFileStage() == SUBMISSION_FILE_REVIEW_REVISION) {
312 $authorUserIds = array();
314 $submitterAssignments = $stageAssignmentDao->getBySubmissionAndRoleId($reviewRound->getSubmissionId(), ROLE_ID_AUTHOR);
315 while ($assignment = $submitterAssignments->next()) {
316 $authorUserIds[] = $assignment->getUserId();
321 $notificationMgr->updateNotification(
323 array(NOTIFICATION_TYPE_PENDING_INTERNAL_REVISIONS, NOTIFICATION_TYPE_PENDING_EXTERNAL_REVISIONS),
325 ASSOC_TYPE_SUBMISSION,
326 $reviewRound->getSubmissionId()
330 import(
'lib.pkp.classes.submission.reviewRound.ReviewRoundDAO');
332 $reviewRoundDao->updateStatus($reviewRound);
337 $router = $request->getRouter();
338 $dispatcher = $router->getDispatcher();
339 $context = $request->getContext();
340 $uploader = $request->getUser();
342 if (in_array($uploader->getId(), $authorUserIds)) {
345 import(
'lib.pkp.classes.log.SubmissionEmailLogEntry');
347 $submissionEmails = $submissionEmailLogDao->getByEventType($submission->getId(), SUBMISSION_EMAIL_AUTHOR_NOTIFY_REVISED_VERSION);
348 $lastNotification =
null;
349 $sentDates = array();
350 if ($submissionEmails){
351 while ($email = $submissionEmails->next()) {
352 if ($email->getDateSent()){
353 $sentDates[] = $email->getDateSent();
356 if (!empty($sentDates)){
357 $lastNotification = max(array_map(
'strtotime', $sentDates));
361 import(
'lib.pkp.classes.mail.SubmissionMailTemplate');
363 $mail->setEventType(SUBMISSION_EMAIL_AUTHOR_NOTIFY_REVISED_VERSION);
364 $mail->setReplyTo($context->getData(
'contactEmail'), $context->getData(
'contactName'));
367 $editorsStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submission->getId(), $this->getStageId());
368 foreach ($editorsStageAssignments as $editorsStageAssignment) {
369 $editor = $userDao->getById($editorsStageAssignment->getUserId());
371 if (is_null($lastNotification) || strtotime($editor->getDateLastLogin()) > $lastNotification || strtotime(
'-1 day') > $lastNotification){
372 $mail->addRecipient($editor->getEmail(), $editor->getFullName());
376 $submissionUrl = $dispatcher->url($request, ROUTE_PAGE,
null,
'workflow',
'index', array($submission->getId(), $this->getStageId()));
377 $mail->assignParams(array(
378 'authorName' => $uploader->getFullName(),
379 'editorialContactSignature' => $context->getData(
'contactName'),
380 'submissionUrl' => $submissionUrl,
383 if ($mail->getRecipients()){
384 if (!$mail->send($request)) {
385 import(
'classes.notification.NotificationManager');
387 $notificationMgr->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_ERROR, array(
'contents' => __(
'email.compose.error')));
407 import(
'lib.pkp.controllers.wizard.fileUpload.form.SubmissionFilesUploadConfirmationForm');
411 $request, $submission->getId(), $this->getStageId(), $this->getFileStage(), $reviewRound
413 $confirmationForm->readInputData();
416 if ($confirmationForm->validate()) {
417 if (is_a($uploadedFile = $confirmationForm->execute(),
'SubmissionFile')) {
428 return new JSONMessage(
true, $confirmationForm->fetch($request));
441 $metadataForm->initData();
442 return new JSONMessage(
true, $metadataForm->fetch($request));
455 $fileId = (int)$request->getUserVar(
'fileId');
458 $templateMgr->assign(
'submissionId', $submission->getId());
459 $templateMgr->assign(
'fileId', $fileId);
460 if (isset($args[
'fileStage'])) {
461 $templateMgr->assign(
'fileStage', $args[
'fileStage']);
464 return $templateMgr->fetchJson(
'controllers/wizard/fileUpload/form/fileSubmissionComplete.tpl');
492 $uploadedFileName = $uploadedFile->getOriginalFileName();
495 $minPercentage =
Config::getVar(
'files',
'filename_revision_match', 70);
499 $possibleRevisedFileId =
null;
500 $matchedPercentage = 0;
501 foreach ((array) $submissionFiles as $submissionFile) {
506 $a = Stringy\Stringy::create($uploadedFileName)->toAscii(),
507 $b = Stringy\Stringy::create($submissionFile->getOriginalFileName())->toAscii(),
512 $possibleRevisedFileId = $submissionFile->getFileId();
516 $minPercentage = $matchedPercentage;
521 return $possibleRevisedFileId;
533 if ($a == $b)
return false;
535 $pattern =
'/([^0-9]*)([0-9]*)([^0-9]*)/';
536 $aMatchCount = preg_match_all($pattern, $a, $aMatches, PREG_SET_ORDER);
537 $bMatchCount = preg_match_all($pattern, $b, $bMatches, PREG_SET_ORDER);
538 if ($aMatchCount != $bMatchCount || $aMatchCount == 0)
return false;
542 for ($i=0; $i<
count($aMatches); $i++) {
543 if ($aMatches[$i][1] != $bMatches[$i][1])
return false;
544 if ($aMatches[$i][3] != $bMatches[$i][3])
return false;
559 'uploadedFile' => array(
560 'fileId' => $uploadedFile->getFileId(),
561 'revision' => $uploadedFile->getRevision(),
562 'name' => $uploadedFile->getLocalizedName(),
563 'fileLabel' => $uploadedFile->getFileLabel(),
564 'type' => $uploadedFile->getDocumentType(),
565 'genreId' => $uploadedFile->getGenreId(),