Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions core/components/com_courses/site/controllers/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
*/
class Form extends SiteController
{
/**
* Viewing without being enrolled (admins and course managers)
*
* @var boolean
*/
protected $unenrolled = false;

/**
* Execute a task
*
Expand All @@ -44,10 +51,21 @@ public function execute()
if (!$this->member || !is_numeric($this->member))
{
$this->member = $this->course->offering()->member(User::get('id'))->get('id');
if (!$this->member || !is_numeric($this->member))
}

if (!$this->member || !is_numeric($this->member))
{
// authorize() already exempts super admins and course managers, but
// it runs inside the task and execute() gets here first. Let them
// through without a member id rather than turning them away, and
// flag it so the view can say so.
if (User::get('usertype') != 'Super Administrator' && !$this->course->access('manage'))
{
App::abort(422, Lang::txt('No user found'));
}

$this->member = null;
$this->unenrolled = true;
}

// Set the base path
Expand Down Expand Up @@ -198,11 +216,12 @@ public function layoutTask()
$this->_buildTitle();
$this->_buildPathway();

$this->view->pdf = new PdfForm($this->assertFormId());
$this->view->title = $this->view->pdf->getTitle();
$this->view->readonly = Request::getInt('readonly', false);
$this->view->base = $this->base;
$this->view->course = $this->course;
$this->view->pdf = new PdfForm($this->assertFormId());
$this->view->title = $this->view->pdf->getTitle();
$this->view->readonly = Request::getInt('readonly', false);
$this->view->unenrolled = $this->unenrolled;
$this->view->base = $this->base;
$this->view->course = $this->course;
$this->view->display();
}

Expand Down Expand Up @@ -353,6 +372,12 @@ public function updateDeploymentTask()
*/
public function showDeploymentTask($dep=null)
{
// These need a real member record; viewing as an admin is not enough
if (!$this->member)
{
App::abort(422, Lang::txt('No user found'));
}

if (!$id = Request::getInt('id', false))
{
App::abort(422, Lang::txt('COM_COURSES_ERROR_MISSING_IDENTIFIER'));
Expand All @@ -379,6 +404,12 @@ public function showDeploymentTask($dep=null)
*/
public function completeTask()
{
// These need a real member record; viewing as an admin is not enough
if (!$this->member)
{
App::abort(422, Lang::txt('No user found'));
}

if (!$crumb = Request::getString('crumb', false))
{
App::abort(422);
Expand Down Expand Up @@ -475,6 +506,12 @@ public function completeTask()
*/
public function startWorkTask()
{
// These need a real member record; viewing as an admin is not enough
if (!$this->member)
{
App::abort(422, Lang::txt('No user found'));
}

if (!$crumb = Request::getString('crumb', false))
{
App::abort(422);
Expand All @@ -500,6 +537,12 @@ public function startWorkTask()
*/
public function saveProgressTask()
{
// These need a real member record; viewing as an admin is not enough
if (!$this->member)
{
App::abort(422, Lang::txt('No user found'));
}

if (!isset($_POST['crumb']) || !isset($_POST['question']) || !isset($_POST['answer']))
{
echo Lang::txt('COM_COURSES_ERROR_MISSING_CRUMB_QUESTION_OR_ANSWER');
Expand All @@ -526,6 +569,12 @@ public function saveProgressTask()
*/
public function submitTask()
{
// These need a real member record; viewing as an admin is not enough
if (!$this->member)
{
App::abort(422, Lang::txt('No user found'));
}

if (!$crumb = Request::getString('crumb', false))
{
App::abort(422);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ COM_COURSES_HEADER_END_DATE="End date"
COM_COURSES_SELECT_PREVIOUS_PDF="Select a previous PDF"
COM_COURSES_DEPLOY="Deploy"
COM_COURSES_ERROR_MISSING_DEPLOYMENT="No deployment provided"
COM_COURSES_FORM_NOT_ENROLLED="You are viewing this form as an administrator. You are not enrolled in this course, so you cannot deploy it or respond to it."
COM_COURSES_ERROR_MISSING_DEPLOYMENT_ID="No deployment ID provided"
COM_COURSES_ERROR_UNKNOWN_IDENTIFIER="No form matches identifier"
COM_COURSES_ERROR_MISSING_IDENTIFIER="No form identifier supplied"
Expand Down
5 changes: 5 additions & 0 deletions core/components/com_courses/site/views/form/tmpl/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

?>
<section class="main section courses-form">
<?php if (!empty($this->unenrolled)) : ?>
<div class="warning">
<?php echo Lang::txt('COM_COURSES_FORM_NOT_ENROLLED'); ?>
</div>
<?php endif; ?>
<noscript>
<div class="error">You must enable JavaScript to annotate PDFs for deployment as forms, sorry.</div>
</noscript>
Expand Down