00001 <?php
00002
00016 import('lib.pkp.classes.form.Form');
00017
00018 class SignoffFileUploadForm extends Form {
00019 var $_monographId;
00020 var $_stageId;
00021 var $_symbolic;
00022 var $_signoffId;
00023
00034 function SignoffFileUploadForm($monographId, $stageId, $symbolic, $signoffId = null) {
00035 $this->_monographId = $monographId;
00036 $this->_stageId = $stageId;
00037 $this->_symbolic = $symbolic;
00038 $this->_signoffId = $signoffId;
00039
00040 parent::Form('controllers/modals/signoff/form/signoffFileUploadForm.tpl');
00041 }
00042
00043
00044
00045
00049 function getMonographId() {
00050 return $this->_monographId;
00051 }
00052
00057 function getStageId() {
00058 return $this->_stageId;
00059 }
00060
00065 function getSymbolic() {
00066 return $this->_symbolic;
00067 }
00068
00069
00070
00071
00072 function getSignoffId() {
00073 return $this->_signoffId;
00074 }
00075
00076
00077
00078
00082 function initData(&$request) {
00083 $this->setData('monographId', $this->getMonographId());
00084 $this->setData('stageId', $this->getStageId());
00085 }
00086
00087
00091 function fetch($request) {
00092 $templateMgr =& TemplateManager::getManager();
00093 $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00094 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00095
00096 $signoffId = $this->getSignoffId();
00097 if ($signoffId) {
00098 $signoff =& $signoffDao->getById($signoffId);
00099 }
00100
00101
00102 if (isset($signoff)) {
00103 $templateMgr->assign('signoffId', $signoff->getId());
00104
00105 $submissionFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
00106 assert(is_a($submissionFile, 'MonographFile'));
00107
00108 $templateMgr->assign('signoffFileName', $submissionFile->getLocalizedName());
00109 } else {
00110
00111 $user =& $request->getUser();
00112 $signoffs =& $signoffDao->getAllByMonograph($this->getMonographId(), $this->getSymbolic(), $user->getId(), null, true);
00113 $availableSignoffs = array();
00114 while ($signoff =& $signoffs->next()) {
00115 $submissionFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
00116 assert(is_a($submissionFile, 'MonographFile'));
00117
00118 $availableSignoffs[$signoff->getId()] = $submissionFile->getLocalizedName();
00119 unset($signoff);
00120 }
00121
00122
00123 if (count($availableSignoffs) == 1) {
00124
00125 foreach ($availableSignoffs as $signoffId => $fileName) {
00126 $templateMgr->assign('signoffId', $signoffId);
00127 $templateMgr->assign('signoffFileName', $fileName);
00128 }
00129 } else {
00130
00131 $templateMgr->assign('availableSignoffs', $availableSignoffs);
00132 }
00133 }
00134
00135 return parent::fetch($request);
00136 }
00137
00141 function readInputData() {
00142 $this->readUserVars(array('signoffId', 'newNote', 'temporaryFileId'));
00143 }
00144
00148 function validate(&$request) {
00149
00150 $signoffId = $this->getSignoffId();
00151 return (is_numeric($signoffId) && $signoffId > 0);
00152 }
00153
00154
00155
00156
00162 function execute($request) {
00163 $user =& $request->getUser();
00164
00165
00166 $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00167 $signoff =& $signoffDao->getById($this->getData('signoffId'));
00168 assert(is_a($signoff, 'Signoff'));
00169
00170
00171 $temporaryFileId = $this->getData('temporaryFileId');
00172 if ($temporaryFileId || $this->getData('newNote')) {
00173 $user =& $request->getUser();
00174
00175 $noteDao =& DAORegistry::getDAO('NoteDAO');
00176 $note = $noteDao->newDataObject();
00177
00178 $note->setUserId($user->getId());
00179 $note->setContents($this->getData('newNote'));
00180 $note->setAssocType(ASSOC_TYPE_SIGNOFF);
00181 $note->setAssocId($signoff->getId());
00182 $noteId = $noteDao->insertObject($note);
00183 $note->setId($noteId);
00184
00185
00186 if ($temporaryFileId) {
00187
00188 $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
00189 $temporaryFile =& $temporaryFileDao->getTemporaryFile(
00190 $temporaryFileId,
00191 $user->getId()
00192 );
00193
00194
00195
00196 import('classes.monograph.MonographFile');
00197
00198 $press =& $request->getPress();
00199 import('classes.file.MonographFileManager');
00200 $monographFileManager = new MonographFileManager($press->getId(), $this->getMonographId());
00201 $signoffFileId = $monographFileManager->temporaryFileToMonographFile(
00202 $temporaryFile,
00203 MONOGRAPH_FILE_NOTE, $signoff->getUserId(),
00204 $signoff->getUserGroupId(), $signoff->getAssocId(), null,
00205 ASSOC_TYPE_NOTE, $noteId
00206 );
00207
00208
00209
00210
00211
00212
00213
00214
00215 if ($signoffFileId) {
00216 $signoff->setFileId($signoffFileId);
00217 $signoff->setFileRevision(1);
00218 }
00219 }
00220
00221
00222
00223 $signoff->setDateCompleted(Core::getCurrentDate());
00224 $signoffDao->updateObject($signoff);
00225
00226
00227 $notificationMgr = new NotificationManager();
00228 $notificationMgr->updateAuditorRequestNotification($signoff, $request);
00229
00230
00231 $notificationMgr->updateSignoffNotification($signoff, $request);
00232
00233
00234 import('classes.log.MonographFileLog');
00235 import('classes.log.MonographFileEventLogEntry');
00236 $monographDao =& DAORegistry::getDAO('MonographDAO');
00237 $monograph =& $monographDao->getById($this->getMonographId());
00238 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00239 $monographFile =& $submissionFileDao->getLatestRevision($signoff->getFileId());
00240
00241 if (isset($monographFile)) {
00242 MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_AUDIT_UPLOAD, 'submission.event.fileAuditUploaded', array('file' => $monographFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername()));
00243 }
00244 return $signoff->getId();
00245 }
00246 }
00247 }
00248
00249 ?>