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
84 changes: 83 additions & 1 deletion core/components/com_resources/helpers/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,24 @@ public static function primary_child($option, $resource, $firstChild, $xact='')
//} else {
$pop = (User::isGuest()) ? '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_LOGIN_REQUIRED_TO_RUN') . '</p>' : '';
$pop = ($resource->revision =='dev') ? '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNDER_DEVELOPMENT') . '</p>' : $pop;
$html .= self::primaryButton('launchtool', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 0, $pop);

$existingSession = self::findExistingToolSession($resource);
if ($existingSession)
{
$resumeUrl = Route::url(
'index.php?option=com_tools&task=session'
. '&app=' . $existingSession->appname
. '&sess=' . $existingSession->sessnum
);
$routedLurl = Route::url($lurl);
$newUrl = $routedLurl . (strpos($routedLurl, '?') !== false ? '&newinstance=1' : '?newinstance=1');
$html .= self::primaryButton('resumetool', $resumeUrl, Lang::txt('COM_RESOURCES_RESUME_TOOL'), '', Lang::txt('COM_RESOURCES_RESUME_TOOL_TITLE'), '', 0, $pop);
$html .= '<p class="launch-new-instance"><a class="btn btn-secondary" href="' . $newUrl . '">' . Lang::txt('COM_RESOURCES_LAUNCH_NEW_INSTANCE') . '</a></p>';
}
else
{
$html .= self::primaryButton('launchtool', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 0, $pop);
}
//}
}
else
Expand Down Expand Up @@ -1095,6 +1112,71 @@ public static function primary_child($option, $resource, $firstChild, $xact='')
return $html;
}

/**
* Look for an existing middleware session for the current user that matches
* this tool resource (any version). Returns the most recently accessed one,
* or null when none exist / middleware is unavailable.
*
* @param object $resource Tool resource
* @return object|null
*/
protected static function findExistingToolSession($resource)
{
if (User::isGuest())
{
return null;
}

if (!$resource->alias)
{
return null;
}

// The session appname is the attached revision: alias_r<rev>, or "_dev" for the dev version.
$appname = (!isset($resource->revision) || $resource->revision == 'dev')
? $resource->alias . '_dev'
: $resource->alias . '_r' . $resource->revision;

try
{
require_once \Component::path('com_tools') . DS . 'helpers' . DS . 'utils.php';

$mwdb = \Components\Tools\Helpers\Utils::getMWDBO();
if (!$mwdb)
{
return null;
}

$toolsTables = \Component::path('com_tools') . DS . 'tables';
require_once $toolsTables . DS . 'viewperm.php';
require_once $toolsTables . DS . 'session.php';

$ms = new \Components\Tools\Tables\Session($mwdb);
$records = $ms->getRecords(User::get('username'), $appname, false);
}
catch (\Exception $e)
{
return null;
}

if (!$records)
{
return null;
}

// Records are already filtered to this appname; pick the most recently accessed.
$match = null;
foreach ($records as $row)
{
if (!$match || strtotime($row->accesstime) > strtotime($match->accesstime))
{
$match = $row;
}
}

return $match;
}

/**
* Generate the primary resources button
*
Expand Down
8 changes: 8 additions & 0 deletions core/components/com_resources/site/assets/css/resources.css
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@
display: block;
}

.launch-new-instance {
margin: -1em 0 1.5em 0;
}
.launch-new-instance .btn {
display: block;
text-align: center;
}

#primary-document_pop {
display: none;
position: absolute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ COM_RESOURCES_LICENSE="License"
COM_RESOURCES_AVAILABLE_VERSIONS="Available Versions"
COM_RESOURCES_TOOL_IS_CLOSED_SOURCE="This tool is closed source."
COM_RESOURCES_LAUNCH_TOOL="Launch Tool"
COM_RESOURCES_RESUME_TOOL="Resume Tool"
COM_RESOURCES_RESUME_TOOL_TITLE="Resume your existing session for this tool"
COM_RESOURCES_LAUNCH_NEW_INSTANCE="launch a new instance"
COM_RESOURCES_TOOL_IS_RESTRICTED="WARNING: This tool is currently restricted to authorized members of the hub. If you need access, please submit a ticket to that effect and include the reason for your request."
COM_RESOURCES_TOOL_VERSION_UNDER_DEVELOPMENT="Warning: This tool version is under development and may not be run until it is installed."
COM_RESOURCES_TOOL_LOGIN_REQUIRED_TO_RUN="You must login before you can run this tool."
Expand Down