00001 <?php
00002
00015 import('classes.handler.Handler');
00016 import('lib.pkp.classes.core.JSONMessage');
00017
00018 class SignoffInformationCenterHandler extends Handler {
00020 var $signoff;
00021
00023 var $monograph;
00024
00026 var $stageId;
00027
00031 function SignoffInformationCenterHandler() {
00032 parent::Handler();
00033
00034 $this->addRoleAssignment(
00035 array(
00036 ROLE_ID_AUTHOR,
00037 ROLE_ID_SERIES_EDITOR,
00038 ROLE_ID_PRESS_MANAGER,
00039 ROLE_ID_PRESS_ASSISTANT
00040 ),
00041 array('viewSignoffHistory', 'viewNotes', 'getUserSignoffs', 'fetchNotesForm', 'saveNote', 'listNotes', 'uploadFile')
00042 );
00043 }
00044
00048 function initialize(&$request, $args = null) {
00049 parent::initialize($request, $args);
00050
00051
00052 $this->monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00053 $this->signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00054 $this->stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00055 }
00056
00060 function authorize($request, $args, $roleAssignments) {
00061
00062 import('classes.security.authorization.OmpSubmissionAccessPolicy');
00063 $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00064
00065 import('classes.security.authorization.OmpSignoffAccessPolicy');
00066 $router =& $request->getRouter();
00067 $mode = SIGNOFF_ACCESS_READ;
00068 if ($router->getRequestedOp($request) == 'saveNote') {
00069 $mode = SIGNOFF_ACCESS_MODIFY;
00070 }
00071
00072 $router =& $request->getRouter();
00073 $requestedOp = $router->getRequestedOp($request);
00074 $stageId = $request->getUserVar('stageId');
00075 if ($request->getUserVar('signoffId')) {
00076 $this->addPolicy(new OmpSignoffAccessPolicy($request, $args, $roleAssignments, $mode, $stageId));
00077 } else if ($requestedOp == 'viewNotes' || $requestedOp == 'getUserSignoffs') {
00078 import('classes.security.authorization.internal.WorkflowStageRequiredPolicy');
00079 $this->addPolicy(new WorkflowStageRequiredPolicy($stageId));
00080 } else {
00081 return AUTHORIZATION_DENY;
00082 }
00083
00084 return parent::authorize($request, $args, $roleAssignments);
00085 }
00086
00090 function setupTemplate() {
00091 AppLocale::requireComponents(LOCALE_COMPONENT_OMP_SUBMISSION);
00092 parent::setupTemplate();
00093 }
00094
00101 function viewSignoffHistory($args, &$request) {
00102 $this->setupTemplate();
00103 $user =& $request->getUser();
00104
00105 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00106
00107 $templateMgr =& TemplateManager::getManager();
00108 $templateMgr->assign_by_ref('signoff', $signoff);
00109
00110 return $templateMgr->fetchJson('controllers/informationCenter/signoffHistory.tpl');
00111 }
00112
00119 function viewNotes($args, &$request) {
00120 $this->setupTemplate($request);
00121 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00122 $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00123 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00124
00125 $templateMgr =& TemplateManager::getManager();
00126 $templateMgr->assign('monographId', $monograph->getId());
00127 $templateMgr->assign('stageId', $stageId);
00128 $templateMgr->assign('symbolic', (string) $request->getUserVar('symbolic'));
00129 if ($signoff) {
00130 $templateMgr->assign('signoffId', $signoff->getId());
00131 }
00132 return $templateMgr->fetchJson('controllers/informationCenter/signoffNotes.tpl');
00133 }
00134
00141 function getUserSignoffs($args, &$request) {
00142 $user =& $request->getUser();
00143 $signoffDao =& DAORegistry::getDAO('SignoffDAO');
00144 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00145 $symbolic = (string) $request->getUserVar('symbolic');
00146
00147 $monographFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00148 $signoffsFactory =& $signoffDao->getAllBySymbolic($symbolic, ASSOC_TYPE_MONOGRAPH_FILE, null, $user->getId());
00149
00150 $signoffs = array();
00151 while ($signoff =& $signoffsFactory->next()) {
00152 if (!$signoff->getDateCompleted() && $signoff->getAssocType() == ASSOC_TYPE_MONOGRAPH_FILE) {
00153 $monographFile =& $monographFileDao->getLatestRevision($signoff->getAssocId());
00154 if (is_a($monographFile, 'MonographFile')) {
00155 if ($monographFile->getMonographId() == $monograph->getId()) {
00156 $signoffs[$signoff->getId()] = $monographFile->getLocalizedName();
00157 }
00158 } else {
00159 assert(false);
00160 }
00161 }
00162 }
00163
00164 $json = new JSONMessage(true, $signoffs);
00165 return $json->getString();
00166 }
00167
00174 function fetchNotesForm($args, &$request) {
00175 $this->setupTemplate($request);
00176 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00177 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00178
00179 import('controllers.grid.files.fileSignoff.form.NewSignoffNoteForm');
00180 $notesForm = new NewSignoffNoteForm($signoff->getId(), $monograph->getId(), $signoff->getSymbolic(), $this->stageId);
00181 $notesForm->initData();
00182
00183 $json = new JSONMessage(true, $notesForm->fetch($request));
00184 return $json->getString();
00185 }
00186
00192 function saveNote($args, &$request) {
00193 $this->setupTemplate($request);
00194 $signoff =& $this->signoff;
00195 $monograph =& $this->monograph;
00196 $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
00197
00198 import('controllers.grid.files.fileSignoff.form.NewSignoffNoteForm');
00199 $notesForm = new NewSignoffNoteForm($signoff->getId(), $monograph->getId(), $signoff->getSymbolic(), $this->stageId);
00200 $notesForm->readInputData();
00201
00202 if ($notesForm->validate()) {
00203 $notesForm->execute($request, $userRoles);
00204 $json = new JSONMessage(true);
00205 } else {
00206
00207 $json = new JSONMessage(false);
00208 }
00209
00210 return $json->getString();
00211 }
00212
00219 function listNotes($args, &$request) {
00220 $this->setupTemplate($request);
00221 $signoff =& $this->signoff;
00222 $monograph =& $this->monograph;
00223
00224 $templateMgr =& TemplateManager::getManager();
00225 $noteDao =& DAORegistry::getDAO('NoteDAO');
00226 $notesFactory =& $noteDao->getByAssoc(ASSOC_TYPE_SIGNOFF, $signoff->getId());
00227 $notes = $notesFactory->toAssociativeArray();
00228
00229 $noteFilesDownloadLink = array();
00230 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00231 import('controllers.api.file.linkAction.DownloadFileLinkAction');
00232 foreach ($notes as $noteId => $note) {
00233 $file =& $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_NOTE, $noteId, $monograph->getId(), MONOGRAPH_FILE_NOTE);
00234
00235 $file = current($file);
00236
00237
00238 if ($file) {
00239 $noteFilesDownloadLink[$noteId] = new DownloadFileLinkAction($request, $file, $this->stageId);
00240 }
00241 }
00242
00243 $user =& $request->getUser();
00244
00245 import('lib.pkp.classes.core.ArrayItemIterator');
00246 $templateMgr->assign('notes', new ArrayItemIterator($notes));
00247 $templateMgr->assign('noteFilesDownloadLink', $noteFilesDownloadLink);
00248 $templateMgr->assign('notesListId', 'notesList');
00249 $templateMgr->assign('currentUserId', $user->getId());
00250 $templateMgr->assign('notesDeletable', false);
00251
00252 $json = new JSONMessage(true, $templateMgr->fetch('controllers/informationCenter/notesList.tpl'));
00253 $json->setEvent('dataChanged');
00254 return $json->getString();
00255 }
00256
00263 function uploadFile($args, &$request) {
00264 $user =& $request->getUser();
00265
00266 import('classes.file.TemporaryFileManager');
00267 $temporaryFileManager = new TemporaryFileManager();
00268 $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
00269 if ($temporaryFile) {
00270 $json = new JSONMessage(true);
00271 $json->setAdditionalAttributes(array(
00272 'temporaryFileId' => $temporaryFile->getId()
00273 ));
00274 } else {
00275 $json = new JSONMessage(false, __('common.uploadFailed'));
00276 }
00277
00278 return $json->getString();
00279 }
00280 }
00281
00282 ?>