00001 <?php
00019
00020 import('classes.file.FileManagementHandler');
00021
00022
00023 import('lib.pkp.classes.core.JSONMessage');
00024
00025
00026 class FileSignoffHandler extends FileManagementHandler {
00027
00029 var $_symbolic;
00030
00032 var $_signoffId;
00033
00034
00038 function FileSignoffHandler() {
00039 parent::FileManagementHandler();
00040
00041 $this->addRoleAssignment(
00042 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT, ROLE_ID_AUTHOR),
00043 array('displayFileUploadForm', 'uploadFile', 'signoff', 'readSignoff', 'signoffRead')
00044 );
00045 }
00046
00047
00048
00049
00050
00054 function initialize(&$request, $args) {
00055 parent::initialize($request, $args);
00056
00057
00058 $this->_signoffId = $request->getUserVar('signoffId') ? (int) $request->getUserVar('signoffId') : null;
00059 $this->_symbolic = $request->getUserVar('symbolic')?$request->getUserVar('symbolic') : null;
00060
00061
00062 AppLocale::requireComponents(
00063 LOCALE_COMPONENT_OMP_SUBMISSION,
00064 LOCALE_COMPONENT_PKP_SUBMISSION,
00065 LOCALE_COMPONENT_PKP_COMMON,
00066 LOCALE_COMPONENT_APPLICATION_COMMON,
00067 LOCALE_COMPONENT_PKP_GRID
00068 );
00069 }
00070
00071
00075 function authorize(&$request, $args, $roleAssignments) {
00076 import('classes.security.authorization.OmpSignoffAccessPolicy');
00077
00078
00079 $router =& $request->getRouter();
00080 $operation = $router->getRequestedOp($request);
00081
00082 $mode = SIGNOFF_ACCESS_MODIFY;
00083 switch ($operation) {
00084 case 'readSignoff':
00085 case 'signoffRead':
00086 $mode = SIGNOFF_ACCESS_READ;
00087 break;
00088 default:
00089 break;
00090 }
00091
00092
00093 if ($request->getUserVar('signoffId')) {
00094
00095 $stageId = (int) $request->getUserVar('stageId');
00096 $this->addPolicy(new OmpSignoffAccessPolicy($request, $args, $roleAssignments, $mode, $stageId));
00097 }
00098 $symbolic = $request->getUserVar('symbolic');
00099 if ($symbolic) {
00100 $signoffDao =& DAORegistry::getDAO('SignoffDAO');
00101 $symbolics = $signoffDao->getAllSymbolics();
00102 if (!in_array($symbolic, $symbolics)) {
00103 return false;
00104 }
00105 }
00106
00107 return parent::authorize($request, $args, $roleAssignments);
00108 }
00109
00110
00111
00112
00113
00118 function getSymbolic() {
00119 return $this->_symbolic;
00120 }
00121
00122
00123 function getSignoffId() {
00124 return $this->_signoffId;
00125 }
00126
00127
00128
00129
00130
00137 function readSignoff($args, &$request) {
00138 $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00139 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00140 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00141
00142
00143 if (!$signoff) {
00144 $json = new JSONMessage(false);
00145 return $json->getString();
00146 }
00147
00148
00149 $monograph =& $this->getMonograph();
00150 $stageId = $this->getStageId();
00151 if ($signoff->getAssocType() != ASSOC_TYPE_MONOGRAPH_FILE) assert(false);
00152 $signoffFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
00153
00154
00155 $templateMgr =& TemplateManager::getManager();
00156 $templateMgr->assign('monographId', $monograph->getId());
00157 $templateMgr->assign('stageId', $stageId);
00158 $templateMgr->assign('signoffId', $signoff->getId());
00159 $templateMgr->assign('signoffFileName', $signoffFile->getLocalizedName());
00160
00161
00162 $noteDao =& DAORegistry::getDAO('NoteDAO');
00163 $notes =& $noteDao->getByAssoc(ASSOC_TYPE_SIGNOFF, $signoff->getId());
00164 if (!$notes->wasEmpty()) {
00165 $lastNote =& $notes->next();
00166 $templateMgr->assign('noteText', $lastNote->getContents());
00167 } else {
00168 $templateMgr->assign('noteText', '');
00169 }
00170
00171
00172 if ($signoff->getFileId() && $signoff->getFileRevision()) {
00173 $responseFile =& $submissionFileDao->getRevision($signoff->getFileId(), $signoff->getFileRevision());
00174 assert(is_a($responseFile, 'MonographFile'));
00175
00176 import('controllers.api.file.linkAction.DownloadFileLinkAction');
00177 $downloadFileAction = new DownloadFileLinkAction($request, $responseFile, $stageId);
00178 $templateMgr->assign('downloadSignoffResponseFileAction', $downloadFileAction);
00179 } else {
00180 $templateMgr->assign('downloadSignoffResponseFileAction', false);
00181 }
00182
00183 return $templateMgr->fetchJson('controllers/modals/signoff/readSignoff.tpl');
00184 }
00185
00186
00191 function signoffRead($args, &$request) {
00192 $json = new JSONMessage(true);
00193 return $json->getString();
00194 }
00195
00196
00203 function displayFileUploadForm($args, &$request) {
00204 $monograph =& $this->getMonograph();
00205
00206 import('controllers.modals.signoff.form.SignoffFileUploadForm');
00207 $fileForm = new SignoffFileUploadForm(
00208 $monograph->getId(), $this->getStageId(),
00209 $this->getSymbolic(), $this->getSignoffId()
00210 );
00211
00212 $fileForm->initData($args, $request);
00213
00214
00215 $json = new JSONMessage(true, $fileForm->fetch($request));
00216 return $json->getString();
00217 }
00218
00219
00226 function uploadFile($args, &$request) {
00227 $user =& $request->getUser();
00228
00229 import('classes.file.TemporaryFileManager');
00230 $temporaryFileManager = new TemporaryFileManager();
00231 $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
00232 if ($temporaryFile) {
00233 $json = new JSONMessage(true);
00234 $json->setAdditionalAttributes(array(
00235 'temporaryFileId' => $temporaryFile->getId()
00236 ));
00237 } else {
00238 $json = new JSONMessage(false, __('common.uploadFailed'));
00239 }
00240
00241 return $json->getString();
00242 }
00243
00244
00251 function signoff($args, &$request) {
00252
00253 if ($request->getUserVar('noSignoffs')) {
00254 $json = new JSONMessage(true);
00255 return $json->getString();
00256 }
00257 $monograph =& $this->getMonograph();
00258
00259
00260 import('controllers.modals.signoff.form.SignoffFileUploadForm');
00261 $uploadForm = new SignoffFileUploadForm(
00262 $monograph->getId(), $this->getStageId(),
00263 $this->getSymbolic(), $this->getSignoffId()
00264 );
00265 $uploadForm->readInputData();
00266
00267
00268 if ($uploadForm->validate($request)) {
00269 $signoffId = $uploadForm->execute($request);
00270
00271
00272 $user =& $request->getUser();
00273 $notificationMgr = new NotificationManager();
00274 $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.uploadedResponse')));
00275
00276
00277
00278
00279 return DAO::getDataChangedEvent();
00280 } else {
00281 $json = new JSONMessage(false, array_pop($uploadForm->getErrorsArray()));
00282 }
00283 return $json->getString();
00284 }
00285
00286
00287
00288
00289
00296 function &_getUploadedFileInfo(&$uploadedFile) {
00297 $uploadedFileInfo = array(
00298 'uploadedFile' => array(
00299 'fileId' => $uploadedFile->getFileId(),
00300 'revision' => $uploadedFile->getRevision()
00301 )
00302 );
00303 return $uploadedFileInfo;
00304 }
00305 }
00306
00307 ?>