/** * Save an entry version * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming instance ID $fields = Request::getVar('fields', array(), 'post'); // Do we have an ID? if (!$fields['version']) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TOOLS_ERROR_MISSING_ID'), 'error'); return; } $row = Version::getInstance(intval($fields['version'])); if (!$row) { Request::setVar('id', $fields['id']); Request::setVar('version', $fields['version']); Notify::error(Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND')); return $this->editTask(); } $row->vnc_command = trim($fields['vnc_command']); $row->vnc_timeout = $fields['vnc_timeout'] != 0 ? intval(trim($fields['vnc_timeout'])) : NULL; $row->hostreq = trim($fields['hostreq']); $row->mw = trim($fields['mw']); $row->params = trim($fields['params']); if (!$row->vnc_command) { Notify::error(Lang::txt('COM_TOOLS_ERROR_MISSING_COMMAND')); return $this->editTask($row); } $row->hostreq = is_array($row->hostreq) ? explode(',', $row->hostreq[0]) : explode(',', $row->hostreq); $hostreq = array(); foreach ($row->hostreq as $req) { if (!empty($req)) { $hostreq[] = trim($req); } } $row->hostreq = $hostreq; $row->update(); if ($this->getTask() == 'apply') { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit&id=' . $fields['id'] . '&version=' . $fields['version'], false)); return; } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TOOLS_ITEM_SAVED')); }
/** * Display the primary child * For most resources, this will be the first child of a standalone resource * Tools are the only exception in which case the button launches a tool session * * @param string $option Component name * @param object $resource Resource * @param object $firstChild First resource child * @param string $xact Extra parameters to add * @return string */ public static function primary_child($option, $resource, $firstChild, $xact = '') { $database = \App::get('db'); $html = ''; switch ($resource->type) { case 7: $authorized = User::authorise('core.manage', 'com_tools.' . $resource->id); $mconfig = Component::params('com_tools'); // Ensure we have a connection to the middleware if (!$mconfig->get('mw_on') || $mconfig->get('mw_on') > 1 && !$authorized) { $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_SESSION_INVOKE_DISABLED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); return $html; } //get tool params $params = Component::params('com_tools'); $launchOnIpad = $params->get('launch_ipad', 0); // Generate the URL that launches a tool session $lurl = ''; $database = \App::get('db'); $tables = $database->getTableList(); $table = $database->getPrefix() . 'tool_version'; if (in_array($table, $tables)) { if (isset($resource->revision) && $resource->toolpublished) { $sess = $resource->tool ? $resource->tool : $resource->alias . '_r' . $resource->revision; $v = (!isset($resource->revision) or $resource->revision == 'dev') ? 'test' : $resource->revision; $lurl = 'index.php?option=com_tools&app=' . $resource->alias . '&task=invoke&version=' . $v; } elseif (!isset($resource->revision) or $resource->revision == 'dev') { // serve dev version $lurl = 'index.php?option=com_tools&app=' . $resource->alias . '&task=invoke&version=dev'; } } else { $lurl = 'index.php?option=com_tools&task=invoke&app=' . $resource->alias; } require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php'; // Create some tool objects $hztv = \Components\Tools\Models\Version::getInstance($resource->tool); $ht = \Components\Tools\Models\Tool::getInstance($hztv->toolid); if ($ht) { // @FIXME: this only seems to fail on hubbub VMs where workspace resource is incomplete/incorrect (bad data in DB?) $toolgroups = $ht->getToolGroupsRestriction($hztv->toolid, $resource->tool); } // Get current users groups $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members'); $ingroup = false; $groups = array(); if ($xgroups) { foreach ($xgroups as $xgroup) { $groups[] = $xgroup->cn; } // Check if they're in the admin tool group $admingroup = Component::params('com_tools')->get('admingroup'); if ($admingroup && in_array($admingroup, $groups)) { $ingroup = true; } else { if ($toolgroups) { foreach ($toolgroups as $toolgroup) { if (in_array($toolgroup->cn, $groups)) { $ingroup = true; } } } } } if (!User::isGuest() && !$ingroup && $toolgroups) { // see if tool is restricted to a group and if current user is in that group $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_IS_RESTRICTED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); } else { if (isset($resource->revision) && $resource->toolpublished or !isset($resource->revision)) { // dev or published tool //if (User::isGuest()) { // Not logged-in = show message //$html .= self::primaryButton('launchtool disabled', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL')); //$html .= self::warning('You must <a href="'.Route::url('index.php?option=com_users&view=login').'">log in</a> before you can run this tool.')."\n"; //} 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); //} } else { // tool unpublished $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNPUBLISHED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); } } break; case 4: // write primary button and downloads for a Learning Module $html .= self::primaryButton('', Route::url('index.php?option=com_resources&id=' . $resource->id . '&task=play'), 'Start learning module'); break; case 6: case 8: case 31: case 2: // do nothing $mesg = Lang::txt('COM_RESOURCES_VIEW') . ' '; $mesg .= $resource->type == 6 ? 'Course Lectures' : ''; $mesg .= $resource->type == 2 ? 'Workshop ' : ''; $mesg .= $resource->type == 6 ? '' : 'Series'; $html .= self::primaryButton('download', Route::url('index.php?option=com_resources&id=' . $resource->id) . '#series', $mesg, '', $mesg, ''); break; default: $firstChild->title = str_replace('"', '"', $firstChild->title); $firstChild->title = str_replace('&', '&', $firstChild->title); $firstChild->title = str_replace('&', '&', $firstChild->title); $mesg = ''; $class = ''; $action = ''; $xtra = ''; //$lt = new \Components\Resources\Tables\Type($database); //$lt->load($firstChild->logicaltype); $lt = \Components\Resources\Tables\Type::getRecordInstance($firstChild->logicaltype); $ltparams = new \Hubzero\Config\Registry($lt->params); //$rt = new \Components\Resources\Tables\Type($database); //$rt->load($firstChild->type); $rt = \Components\Resources\Tables\Type::getRecordInstance($firstChild->type); $tparams = new \Hubzero\Config\Registry($rt->params); if ($firstChild->logicaltype) { $rtLinkAction = $ltparams->get('linkAction', 'extension'); } else { $rtLinkAction = $tparams->get('linkAction', 'extension'); } switch ($rtLinkAction) { case 'download': $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; //$action = 'rel="download"'; $linkAction = 3; break; case 'lightbox': $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = 'play'; //$action = 'rel="internal"'; $linkAction = 2; break; case 'newwindow': case 'external': $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); //$class = 'popup'; $action = 'rel="external"'; $linkAction = 1; break; case 'extension': default: $linkAction = 0; $mediatypes = array('elink', 'quicktime', 'presentation', 'presentation_audio', 'breeze', 'quiz', 'player', 'video_stream', 'video', 'hubpresenter'); $downtypes = array('thesis', 'handout', 'manual', 'software_download'); if (in_array($lt->alias, $downtypes)) { $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; } elseif (in_array($rt->alias, $mediatypes)) { $mesg = Lang::txt('COM_RESOURCES_VIEW_PRESENTATION'); $mediatypes = array('flash_paper', 'breeze', '32', '26'); if (in_array($firstChild->type, $mediatypes)) { $class = 'play'; } } else { $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; } if ($firstChild->standalone == 1) { $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = ''; //'play'; } if (substr($firstChild->path, 0, 7) == 'http://' || substr($firstChild->path, 0, 8) == 'https://' || substr($firstChild->path, 0, 6) == 'ftp://' || substr($firstChild->path, 0, 9) == 'mainto://' || substr($firstChild->path, 0, 9) == 'gopher://' || substr($firstChild->path, 0, 7) == 'file://' || substr($firstChild->path, 0, 7) == 'news://' || substr($firstChild->path, 0, 7) == 'feed://' || substr($firstChild->path, 0, 6) == 'mms://') { $mesg = Lang::txt('COM_RESOURCES_VIEW_LINK'); } break; } // IF (not a simulator) THEN show the first child as the primary button if ($firstChild->access == 1 && User::isGuest()) { // first child is for registered users only and the visitor is not logged in $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_LOGIN_REQUIRED_TO_DOWNLOAD') . '</p>' . "\n"; $html .= self::primaryButton($class . ' disabled', Route::url('index.php?option=com_users&view=login'), $mesg, '', '', '', '', $pop); } else { $childParams = new \Hubzero\Config\Registry($firstChild->params); $linkAction = intval($childParams->get('link_action', $linkAction)); $url = self::processPath($option, $firstChild, $resource->id, $linkAction); switch ($linkAction) { case 3: $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; break; case 2: $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = 'play'; break; case 1: $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); //$class = 'popup'; $action = 'rel="external"'; break; case 0: default: // Do nothing break; } $attribs = new \Hubzero\Config\Registry($firstChild->attribs); $width = intval($attribs->get('width', 640)); $height = intval($attribs->get('height', 360)); if ($width > 0 && $height > 0) { $class .= ' ' . $width . 'x' . $height; } //$xtra = ''; //if ($firstChild->type == 13 || $firstChild->type == 15 || $firstChild->type == 33) { //$xtra = ' '. self::getFileAttribs($firstChild->path); //} //load a resouce type object on child resource type //$rt = new \Components\Resources\Tables\Type($database); //$rt->load($firstChild->type); //if we are a hubpresenter resource type, do not show file type in button if ($rt->alias == 'hubpresenter') { //$xtra = ""; //$class = "play 1000x600"; $class = 'hubpresenter'; } else { $mesg .= ' ' . self::getFileAttribs($firstChild->path); } if ($rt->alias == 'video') { $class = 'video'; } $pt = \Components\Resources\Tables\Type::getRecordInstance($resource->type); if ($pt->alias == 'databases') { $mesg = "Dataview"; } if ($xact) { $action = $xact; } $html .= self::primaryButton($class, $url, $mesg, $xtra, $firstChild->title, $action); } break; } return $html; }
/** * Short description for 'unpublishAllVersions' * * Long description (if any) ... * * @return boolean Return description (if any) ... */ public function unpublishAllVersions() { $db = \App::get('db'); if (empty($this->toolname)) { return false; } $query = "SELECT id FROM `#__tool_version` AS v WHERE v.toolname=" . $db->Quote($this->toolname) . " v.state=1 ORDER BY v.revision DESC LIMIT 1"; $db->setQuery($query); $result = $db->loadResult(); if (empty($result)) { return false; } foreach ((array) $result as $v) { $hzvt = Version::getInstance($v); if (empty($hzvt)) { continue; } $hzvt->state = 0; $hzvt->update(); } return true; }
/** * Short description for 'getToolRevision' * * Long description (if any) ... * * @param unknown $toolid Parameter description (if any) ... * @param string $revision Parameter description (if any) ... * @return boolean Return description (if any) ... */ public static function getToolRevision($toolid, $revision) { $db = \App::get('db'); if ($revision == 'dev' || $revision == 'development') { if (is_numeric($toolid)) { $query = "SELECT instance FROM #__tool_version AS v WHERE v.toolid=" . $db->Quote($toolid) . " AND v.state=3 ORDER BY v.revision DESC LIMIT 1"; } else { $query = "SELECT instance FROM #__tool_version AS v, #__tool AS t WHERE t.toolname=" . $db->Quote($toolid) . " AND v.toolid=t.id AND v.state=3 ORDER BY v.revision " . " DESC LIMIT 1"; } } else { if ($revision == 'current') { if (is_numeric($toolid)) { $query = "SELECT instance FROM #__tool_version AS v WHERE v.toolid=" . $db->Quote($toolid) . " AND v.state=1 ORDER BY v.revision DESC LIMIT 1"; } else { $query = "SELECT instance FROM #__tool_version AS v, #__tool AS t WHERE t.toolname=" . $db->Quote($toolid) . " AND v.toolid=t.id AND v.state=1 ORDER BY v.revision " . " DESC LIMIT 1"; } } else { if (is_numeric($toolid)) { $query = "SELECT instance FROM #__tool_version AS v WHERE v.toolid=" . $db->Quote($toolid) . " AND v.state<>'3' AND v.revision=" . $db->Quote($revision) . " LIMIT 1"; } else { $query = "SELECT instance FROM #__tool_version AS v, #__tool AS t WHERE t.toolname=" . $db->Quote($toolid) . " AND v.toolid=" . $db->Quote($toolid) . " AND v.state<>'3' AND " . " v.revision=" . $db->Quote($revision) . " LIMIT 1"; } } } $db->setQuery($query); $result = $db->loadResult(); if (empty($result)) { return false; } return \Components\Tools\Models\Version::getInstance($result); }