protected function handle(Request $request) { $uploadId = intval($request->get("upload")); if (empty($uploadId)) { throw new Exception('missing upload id'); } $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents"); $plainAgentList = MenuHook::getAgentPluginNames("Agents"); $agentList = array_merge($plainAgentList, $parmAgentList); $skipAgents = array("agent_unpack", "wget_agent"); $out = ""; $relevantAgents = array(); foreach ($agentList as $agent) { if (array_search($agent, $skipAgents) !== false) { continue; } $plugin = plugin_find($agent); if ($plugin->AgentHasResults($uploadId) != 1 && $this->jobNotYetScheduled($plugin->AgentName, $uploadId)) { $out .= "<option value='" . $agent . "'>"; $out .= htmlentities($plugin->Title); $out .= "</option>\n"; $relevantAgents[$agent] = $plugin->Title; } } $out = '<select multiple size="10" id="agents" name="agents[]">' . $out . '</select>'; return new Response($out, Response::HTTP_OK, array('Content-Type' => 'text/plain')); }
protected function postUploadAddJobs(Request $request, $fileName, $uploadId, $jobId = null, $wgetDependency = false) { $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); if ($jobId === null) { $jobId = JobAddJob($userId, $groupId, $fileName, $uploadId); } $dummy = ""; $adj2nestDependencies = array(); if ($wgetDependency) { $adj2nestDependencies = array(array('name' => 'agent_unpack', AgentPlugin::PRE_JOB_QUEUE => array('wget_agent'))); } $adj2nestplugin = \plugin_find('agent_adj2nest'); $adj2nestplugin->AgentAdd($jobId, $uploadId, $dummy, $adj2nestDependencies); $checkedAgents = checkedAgents(); AgentSchedule($jobId, $uploadId, $checkedAgents); $errorMsg = ''; $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents"); $plainAgentList = MenuHook::getAgentPluginNames("Agents"); $agentList = array_merge($plainAgentList, $parmAgentList); foreach ($parmAgentList as $parmAgent) { $agent = plugin_find($parmAgent); $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request, $agentList); } $status = GetRunnableJobList(); $message = empty($status) ? _("Is the scheduler running? ") : ""; $jobUrl = Traceback_uri() . "?mod=showjobs&upload={$uploadId}"; $message .= _("The file") . " " . $fileName . " " . _("has been uploaded. It is") . ' <a href=' . $jobUrl . '>upload #' . $uploadId . "</a>.\n"; if ($request->get('public') == self::PUBLIC_GROUPS) { $this->getObject('dao.upload.permission')->makeAccessibleToAllGroupsOf($uploadId, $userId); } return $message; }
/** * @param array $row fetched row * @param Request $request * @param $uri * @param $menuPfile * @param $menuPfileNoCompare * @param array $statusTypesAvailable * @param array $users * @param string (unique) * @return array */ private function showRow($row, Request $request, $uri, $menuPfile, $menuPfileNoCompare, $statusTypesAvailable, $users, $rowCounter) { $show = $request->get('show'); $folder = $request->get('folder'); $uploadId = intval($row['upload_pk']); $description = htmlentities($row['upload_desc']); $fileName = $row['ufile_name']; if (empty($fileName)) { $fileName = $row['upload_filename']; } $itemId = Isartifact($row['ufile_mode']) ? DirGetNonArtifact($row['uploadtree_pk']) : $row['uploadtree_pk']; $nameColumn = "<b>{$fileName}</b>"; if (IsContainer($row['ufile_mode'])) { $nameColumn = "<a href='{$uri}&upload={$uploadId}&folder={$folder}&item={$itemId}&show={$show}'>{$nameColumn}</a>"; } $nameColumn .= "<br>"; if (!empty($description)) { $nameColumn .= "<i>{$description}</i><br>"; } $Parm = "upload={$uploadId}&show={$show}&item=" . $row['uploadtree_pk']; if (Iscontainer($row['ufile_mode'])) { $nameColumn .= MenuRenderer::menuToActiveSelect($menuPfile, $Parm, $uploadId); } else { $nameColumn .= MenuRenderer::menuToActiveSelect($menuPfileNoCompare, $Parm, $uploadId); } $modsUploadMulti = MenuHook::getAgentPluginNames('UploadMulti'); if (!empty($modsUploadMulti)) { $nameColumn = '<input type="checkbox" name="uploads[]" class="browse-upload-checkbox" value="' . $uploadId . '"/>' . $nameColumn; } $dateCol = substr($row['upload_ts'], 0, 19); $pairIdPrio = array($uploadId, floatval($row[UploadBrowseProxy::PRIO_COLUMN])); if (!$this->userPerm && 4 == $row['status_fk']) { $currentStatus = $this->statusTypes[4]; } else { $statusAction = " onchange =\"changeTableEntry(this, {$uploadId},'status_fk' )\" "; $currentStatus = $this->createSelect("Status" . $this->userPerm . "Of_{$rowCounter}", $statusTypesAvailable, $row['status_fk'], $statusAction); } if ($this->userPerm) { $action = " onchange =\"changeTableEntry(this, {$uploadId}, 'assignee')\""; $currentAssignee = $this->createSelectUsers("AssignedTo_{$rowCounter}", $users, $row['assignee'], $action); } else { $currentAssignee = array_key_exists($row['assignee'], $users) ? $users[$row['assignee']] : _('Unassigned'); } $rejectableUploadId = $this->userPerm || $row['status_fk'] < 4 ? $uploadId : 0; $tripleComment = array($rejectableUploadId, $row['status_fk'], htmlspecialchars($row['status_comment'])); $sql = "SELECT rf_pk, rf_shortname FROM upload_clearing_license ucl, license_ref" . " WHERE ucl.group_fk=\$1 AND upload_fk=\$2 AND ucl.rf_fk=rf_pk"; $stmt = __METHOD__ . '.collectMainLicenses'; $this->dbManager->prepare($stmt, $sql); $res = $this->dbManager->execute($stmt, array(Auth::getGroupId(), $uploadId)); $mainLicenses = array(); while ($lic = $this->dbManager->fetchArray($res)) { $mainLicenses[] = '<a onclick="javascript:window.open(\'' . Traceback_uri() . "?mod=popup-license&rf={$lic['rf_pk']}','License text','width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes');" . '" href="javascript:;">' . $lic['rf_shortname'] . '</a>' . "<img onclick=\"removeMainLicense({$uploadId},{$lic['rf_pk']});\" class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></img>"; } $this->dbManager->freeResult($res); $output = array($nameColumn, $currentStatus, $tripleComment, implode(', ', $mainLicenses), $currentAssignee, $dateCol, $pairIdPrio); return $output; }
/** * \brief This function returns the output html */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $this->folderDao->ensureTopLevelFolder(); $folder_pk = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); // upload_pk to browse $Item = GetParm("item", PARM_INTEGER); // uploadtree_pk to browse /* check permission if $Upload is given */ if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) { $this->vars['message'] = _("Permission Denied"); return $this->render('include/base.html.twig'); } if (empty($folder_pk)) { try { $folder_pk = $this->getFolderId($Upload); } catch (Exception $exc) { return $exc->getMessage(); } } $output = $this->outputItemHtml($Item, $folder_pk, $Upload); if ($output instanceof Response) { return $output; } $this->vars['content'] = $output; $modsUploadMulti = MenuHook::getAgentPluginNames('UploadMulti'); if (!empty($modsUploadMulti)) { $multiUploadAgents = array(); foreach ($modsUploadMulti as $mod) { $multiUploadAgents[$mod] = $GLOBALS['Plugins'][$mod]->title; } $this->vars['multiUploadAgents'] = $multiUploadAgents; } $this->vars['folderId'] = $folder_pk; return $this->render('ui-browse.html.twig'); }
/** * @brief Add an upload to multiple agents. * @param int $uploadId * @param string[] $agentsToStart - list of agents * @return NULL on success, error message string on failure */ private function agentsAdd($uploadId, $agentsToStart, Request $request) { if (!is_array($agentsToStart)) { return "bad parameters"; } if (!$uploadId) { return "agent-add.php AgentsAdd(): No upload_pk specified"; } /* @var $upload Upload */ $upload = $GLOBALS['container']->get('dao.upload')->getUpload($uploadId); if ($upload === null) { return _("Upload") . " " . $uploadId . " " . _("not found"); } $agents = array(); $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents"); $plainAgentList = MenuHook::getAgentPluginNames("Agents"); $agentList = array_merge($plainAgentList, $parmAgentList); foreach ($agentList as $agentName) { if (in_array($agentName, $agentsToStart)) { $agents[$agentName] = plugin_find($agentName); } } if (count($agents) == 0) { return _("no valid agent specified"); } $jobId = JobAddJob(Auth::getUserId(), Auth::getGroupId(), $upload->getFilename(), $uploadId); $errorMsg = ''; foreach ($parmAgentList as $parmAgent) { $agent = plugin_find($parmAgent); $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request); } foreach ($agents as &$agent) { $rv = $agent->AgentAdd($jobId, $uploadId, $errorMsg, array()); if ($rv == -1) { return $errorMsg; } } return null; }