00001 <?php
00002
00016 import('controllers.wizard.fileUpload.form.SubmissionFilesUploadBaseForm');
00017
00018 class SubmissionFilesUploadForm extends SubmissionFilesUploadBaseForm {
00019
00021 var $_uploaderRoles;
00022
00023
00036 function SubmissionFilesUploadForm(&$request, $monographId, $stageId, $uploaderRoles, $fileStage,
00037 $revisionOnly = false, $reviewRound = null, $revisedFileId = null, $assocType = null, $assocId = null) {
00038
00039
00040 assert(is_null($uploaderRoles) || (is_array($uploaderRoles) && count($uploaderRoles) >= 1));
00041 $this->_uploaderRoles = $uploaderRoles;
00042
00043 AppLocale::requireComponents(LOCALE_COMPONENT_OMP_MANAGER);
00044
00045 parent::SubmissionFilesUploadBaseForm(
00046 $request, 'controllers/wizard/fileUpload/form/fileUploadForm.tpl',
00047 $monographId, $stageId, $fileStage, $revisionOnly, $reviewRound, $revisedFileId, $assocType, $assocId
00048 );
00049 }
00050
00051
00052
00053
00054
00059 function getUploaderRoles() {
00060 assert(!is_null($this->_uploaderRoles));
00061 return $this->_uploaderRoles;
00062 }
00063
00064
00065
00066
00067
00071 function readInputData() {
00072 $this->readUserVars(array('genreId', 'uploaderUserGroupId'));
00073 return parent::readInputData();
00074 }
00075
00079 function validate(&$request) {
00080
00081 $revisedFileId = $this->getRevisedFileId();
00082 if ($this->getData('revisionOnly')) {
00083 assert($revisedFileId > 0);
00084 }
00085
00086
00087 $router =& $request->getRouter();
00088 $context =& $router->getContext($request);
00089
00090 if (!$revisedFileId) {
00091
00092 $this->addCheck(
00093 new FormValidatorCustom(
00094 $this, 'genreId', FORM_VALIDATOR_REQUIRED_VALUE,
00095 'submission.upload.noGenre',
00096 create_function(
00097 '$genreId,$genreDao,$context',
00098 'return is_a($genreDao->getById($genreId, $context->getId()), "Genre");'
00099 ),
00100 array(DAORegistry::getDAO('GenreDAO'), $context)
00101 )
00102 );
00103 }
00104
00105
00106 $uploaderUserGroupId = $this->getData('uploaderUserGroupId');
00107 if ($uploaderUserGroupId) {
00108 $user =& $request->getUser();
00109 $this->addCheck(
00110 new FormValidatorCustom(
00111 $this, 'uploaderUserGroupId', FORM_VALIDATOR_REQUIRED_VALUE,
00112 'submission.upload.invalidUserGroup',
00113 create_function(
00114 '$userGroupId,$userGroupDao,$userId',
00115 'return $userGroupDao->userInGroup($userId, $userGroupId);'
00116 ),
00117 array(DAORegistry::getDAO('UserGroupDAO'), $user->getId(), $context)
00118 )
00119 );
00120 }
00121
00122 return parent::validate();
00123 }
00124
00128 function fetch($request) {
00129
00130 $genreList =& $this->_retrieveGenreList($request);
00131 $this->setData('monographFileGenres', $genreList);
00132
00133
00134 $router =& $request->getRouter();
00135 $context =& $router->getContext($request);
00136 assert(is_a($context, 'Press'));
00137
00138
00139 $user =& $request->getUser();
00140 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00141 $assignedUserGroups =& $userGroupDao->getByUserId($user->getId(), $context->getId());
00142
00143
00144
00145
00146
00147
00148 $uploaderRoles = $this->getUploaderRoles();
00149 $uploaderUserGroups = array();
00150 $highestAuthorityUserGroupId = null;
00151 $highestAuthorityRoleId = null;
00152 while($userGroup =& $assignedUserGroups->next()) {
00153
00154 if (in_array($userGroup->getRoleId(), $uploaderRoles)) {
00155 $uploaderUserGroups[$userGroup->getId()] = $userGroup->getLocalizedName();
00156
00157
00158
00159
00160
00161 if (is_null($highestAuthorityUserGroupId) || $userGroup->getRoleId() <= $highestAuthorityRoleId) {
00162 $highestAuthorityRoleId = $userGroup->getRoleId();
00163 if (is_null($highestAuthorityUserGroupId) || $userGroup->getId() < $highestAuthorityUserGroupId) {
00164 $highestAuthorityUserGroupId = $userGroup->getId();
00165 }
00166 }
00167 }
00168
00169 unset($userGroup);
00170 }
00171 if (empty($uploaderUserGroups)) fatalError('Invalid uploader roles!');
00172 $this->setData('uploaderUserGroups', $uploaderUserGroups);
00173
00174
00175
00176 $defaultUserGroupId = null;
00177 if (count($uploaderUserGroups) > 1) {
00178
00179
00180 $stageAssignmentDao = & DAORegistry::getDAO('StageAssignmentDAO');
00181 $stageAssignments = $stageAssignmentDao->getBySubmissionAndStageId(
00182 $this->getData('monographId'),
00183 $this->getStageId(),
00184 null,
00185 $user->getId()
00186 );
00187
00188 while ($stageAssignment =& $stageAssignments->next()) {
00189 if (isset($uploaderUserGroups[$stageAssignment->getUserGroupId()])) {
00190 $defaultUserGroupId = $stageAssignment->getUserGroupId();
00191 break;
00192 }
00193 }
00194
00195
00196
00197 if (is_null($defaultUserGroupId)) $defaultUserGroupId = $highestAuthorityUserGroupId;
00198 }
00199 $this->setData('defaultUserGroupId', $defaultUserGroupId);
00200
00201 $settingsDao =& DAORegistry::getDAO('PressSettingsDAO');
00202 $this->setData('pressSettings', $settingsDao->getPressSettings($context->getId()));
00203
00204
00205 $this->setData('maxFileUploadSize', get_cfg_var('upload_max_filesize'));
00206
00207 return parent::fetch($request);
00208 }
00209
00215 function &execute($request) {
00216
00217 $revisedFileId = $this->getRevisedFileId();
00218 if ($revisedFileId) {
00219
00220 $fileGenre = null;
00221 } else {
00222
00223 $fileGenre = $this->getData('genreId') ? (int)$this->getData('genreId') : null;
00224 }
00225
00226
00227 $uploaderUserGroupId = $this->getData('uploaderUserGroupId');
00228 if (!$uploaderUserGroupId) fatalError('Invalid uploader user group!');
00229
00230
00231 $user =& $request->getUser();
00232 assert(is_a($user, 'User'));
00233
00234 $assocType = $this->getData('assocType') ? (int) $this->getData('assocType') : null;
00235 $assocId = $this->getData('assocId') ? (int) $this->getData('assocId') : null;
00236
00237
00238 $press =& $request->getPress();
00239 import('classes.file.MonographFileManager');
00240 $monographFileManager = new MonographFileManager($press->getId(), $this->getData('monographId'));
00241 $fileStage = $this->getData('fileStage');
00242 $monographFile = $monographFileManager->uploadMonographFile(
00243 'uploadedFile', $fileStage,
00244 $user->getId(), $uploaderUserGroupId, $revisedFileId, $fileGenre, $assocType, $assocId
00245 );
00246
00247 if ($monographFile && ($fileStage == MONOGRAPH_FILE_REVIEW_FILE || $fileStage == MONOGRAPH_FILE_REVIEW_ATTACHMENT || $fileStage == MONOGRAPH_FILE_REVIEW_REVISION)) {
00248
00249 $reviewRound =& $this->getReviewRound();
00250 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00251 $submissionFileDao->assignRevisionToReviewRound($monographFile->getFileId(), $monographFile->getRevision(), $reviewRound);
00252 }
00253
00254 if ($monographFile) {
00255
00256 import('classes.log.MonographFileLog');
00257 import('classes.log.MonographFileEventLogEntry');
00258 $localeKey = $revisedFileId ? 'submission.event.revisionUploaded' : 'submission.event.fileUploaded';
00259 $assocType = $revisedFileId ? MONOGRAPH_LOG_FILE_REVISION_UPLOAD : MONOGRAPH_LOG_FILE_UPLOAD;
00260 MonographFileLog::logEvent($request, $monographFile, $assocType, $localeKey, array('fileStage' => $fileStage, 'revisedFileId' => $revisedFileId, 'fileId' => $monographFile->getFileId(), 'fileRevision' => $monographFile->getRevision(), 'originalFileName' => $monographFile->getOriginalFileName(), 'submissionId' => $this->getData('monographId'), 'username' => $user->getUsername()));
00261 }
00262
00263 return $monographFile;
00264 }
00265
00266
00267
00268
00269
00275 function &_retrieveGenreList(&$request) {
00276 $context =& $request->getContext();
00277 $genreDao =& DAORegistry::getDAO('GenreDAO');
00278 $genres =& $genreDao->getEnabledByPressId($context->getId());
00279
00280
00281
00282 $genreList = array();
00283 while($genre =& $genres->next()){
00284 $genreId = $genre->getId();
00285 $genreList[$genreId] = $genre->getLocalizedName();
00286 unset($genre);
00287 }
00288 return $genreList;
00289 }
00290 }
00291
00292 ?>