public function runUpload(TBGRequest $request) { $apc_exists = TBGRequest::CanGetUploadStatus(); if ($apc_exists && !$request['APC_UPLOAD_PROGRESS']) { $request->setParameter('APC_UPLOAD_PROGRESS', $request['upload_id']); } $this->getResponse()->setDecoration(TBGResponse::DECORATE_NONE); $canupload = false; if ($request['mode'] == 'issue') { $issue = TBGContext::factory()->TBGIssue($request['issue_id']); $canupload = (bool) ($issue instanceof TBGIssue && $issue->hasAccess() && $issue->canAttachFiles()); } elseif ($request['mode'] == 'article') { $article = TBGWikiArticle::getByName($request['article_name']); $canupload = (bool) ($article instanceof TBGWikiArticle && $article->canEdit()); } else { $event = TBGEvent::createNew('core', 'upload', $request['mode']); $event->triggerUntilProcessed(); $canupload = $event->isProcessed() ? (bool) $event->getReturnValue() : true; } if ($canupload) { try { $file = TBGContext::getRequest()->handleUpload('uploader_file'); if ($file instanceof TBGFile) { switch ($request['mode']) { case 'issue': if (!$issue instanceof TBGIssue) { break; } $issue->attachFile($file, $request->getRawParameter('comment'), $request['uploader_file_description']); $issue->save(); break; case 'article': if (!$article instanceof TBGWikiArticle) { break; } $article->attachFile($file); break; } if ($apc_exists) { return $this->renderText('ok'); } } $this->error = TBGContext::getI18n()->__('An unhandled error occured with the upload'); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); $this->error = $e->getMessage(); } } else { // $this->getResponse()->setHttpStatus(401); $this->error = TBGContext::getI18n()->__('You are not allowed to attach files here'); } if (!$apc_exists) { switch ($request['mode']) { case 'issue': if (!$issue instanceof TBGIssue) { break; } $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo()))); break; case 'article': if (!$article instanceof TBGWikiArticle) { break; } $this->forward(TBGContext::getRouting()->generate('publish_article_attachments', array('article_name' => $article->getName()))); break; } } TBGLogging::log('marking upload ' . $request['APC_UPLOAD_PROGRESS'] . ' as completed with error ' . $this->error); $request->markUploadAsFinishedWithError($request['APC_UPLOAD_PROGRESS'], $this->error); return $this->renderText($request['APC_UPLOAD_PROGRESS'] . ': ' . $this->error); }
<?php $apc_enabled = TBGRequest::CanGetUploadStatus(); ?> <div id="attach_file" style="display: none;"> <div class="rounded_box white borderless shadowed backdrop_box medium"> <div class="backdrop_detail_header"> <?php if ($mode == 'issue') { ?> <?php echo __('Attach one or more file(s) to this issue'); ?> <?php } elseif ($mode == 'article') { ?> <?php echo __('Attach one or more file(s) to this article'); ?> <?php } ?> </div> <div id="backdrop_detail_content"> <div id="upload_forms"> <form method="post" action="<?php echo $form_action; ?> " enctype="multipart/form-data" id="uploader_upload_form" style="margin: 10px 0 0 5px;<?php if ($apc_enabled) { ?>