31 use Symfony\Component\HttpFoundation\RedirectResponse;
32 use Symfony\Component\HttpFoundation\Response;
34 define(
"TITLE_CLEARINGVIEW", _(
"Change concluded License "));
49 private $highlightDao;
51 private $highlightProcessor;
53 private $highlightRenderer;
55 private $clearingDecisionEventProcessor;
57 private $clearingDecisionFilter;
59 private $invalidParm =
false;
61 private $decisionTypes;
63 private $searchChunkSize = 1048576;
65 private $searchBlockSize = 81920;
69 $this->Name =
"view-license";
70 $this->Title = TITLE_CLEARINGVIEW;
72 $this->Dependency = array(
"view");
75 parent::__construct();
78 $this->licenseDao = $container->get(
'dao.license');
79 $this->uploadDao = $container->get(
'dao.upload');
80 $this->clearingDao = $container->get(
'dao.clearing');
81 $this->agentsDao = $container->get(
'dao.agent');
82 $this->logger = $container->get(
"logger");
83 $this->highlightDao = $container->get(
"dao.highlight");
84 $this->highlightRenderer = $container->get(
"view.highlight_renderer");
85 $this->highlightProcessor = $container->get(
"view.highlight_processor");
87 $this->decisionTypes = $container->get(
'decision.types');
89 $this->clearingDecisionEventProcessor = $container->get(
90 'businessrules.clearing_decision_processor');
91 $this->clearingDecisionFilter = $container->get(
92 'businessrules.clearing_decision_filter');
107 $unmaskAgents = $selectedAgentId;
108 if (empty($selectedAgentId)) {
109 $scanJobProxy =
new ScanJobProxy($this->agentsDao,$uploadId);
110 $scanJobProxy->createAgentStatus(array_keys(AgentRef::AGENT_LIST));
111 $unmaskAgents = $scanJobProxy->getLatestSuccessfulAgentIds();
113 $highlightEntries = $this->highlightDao->getHighlightEntries($itemTreeBounds,
114 $licenseId, $unmaskAgents, $highlightId, $clearingId);
115 $groupId = Auth::getGroupId();
116 if (($selectedAgentId > 0) || ($clearingId > 0)) {
117 $this->highlightProcessor->addReferenceTexts($highlightEntries, $groupId);
119 $this->highlightProcessor->flattenHighlights($highlightEntries, array(
"K",
"K "));
121 return $highlightEntries;
124 public function execute()
127 if ($openOutput instanceof RedirectResponse) {
128 $response = $openOutput;
138 if ($this->
State != PLUGIN_STATE_READY) {
142 if (empty($uploadId)) {
147 if (empty($uploadTreeId)) {
148 $parent = $this->uploadDao->getUploadParent($uploadId);
149 if (!isset($parent)) {
150 $this->invalidParm =
true;
154 $item = $this->uploadDao->getNextItem($uploadId, $parent);
155 if ($item === UploadDao::NOT_FOUND) {
156 $this->invalidParm =
true;
159 $uploadTreeId = $item->getId();
160 return new RedirectResponse(
Traceback_uri() .
'?mod=' . $this->Name
164 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
165 $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId, $uploadTreeTableName);
166 if (
Isdir($uploadEntry[
'ufile_mode']) ||
Iscontainer($uploadEntry[
'ufile_mode'])) {
167 $parent = $this->uploadDao->getUploadParent($uploadId);
168 if (!isset($parent)) {
169 $this->invalidParm =
true;
173 $item = $this->uploadDao->getNextItem($uploadId, $parent);
174 if ($item === UploadDao::NOT_FOUND) {
175 $this->invalidParm =
true;
178 $uploadTreeId = $item->getId();
179 return new RedirectResponse(
Traceback_uri() .
'?mod=' . $this->Name
183 return parent::OutputOpen();
192 if ($this->invalidParm) {
193 $this->vars[
'content'] =
'This upload contains no files!<br><a href="'
194 .
Traceback_uri() .
'?mod=browse">Go back to browse view</a>';
195 return $this->
render(
"include/base.html.twig");
199 if (empty($uploadId)) {
200 return new Response(
"", Response::HTTP_BAD_REQUEST);
203 if (empty($uploadTreeId)) {
204 return new Response(
"", Response::HTTP_BAD_REQUEST);
207 $userId = Auth::getUserId();
208 $groupId = Auth::getGroupId();
212 if (!empty($lastItem)) {
213 $currentUploadtreeId = $lastItem;
214 if ($lastItem == $uploadTreeId) {
215 $currentUploadtreeId = $uploadTreeId;
217 $this->
updateLastItem($userId, $groupId, $lastItem, $currentUploadtreeId);
220 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
221 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
223 $this->vars[
'micromenu'] =
Dir2Browse(
'license', $uploadTreeId, NULL,
224 $showBox = 0,
"View", -1,
'',
'', $uploadTreeTableName);
228 $view = &$Plugins[plugin_find_id(
"view")];
236 $this->vars[
'searchQuery'] = $searchQuery;
237 $this->vars[
'searchMatches'] = [];
240 if ($clearingId !==
null) {
242 }
else if ($highlightId !==
null) {
247 $this->vars[
'baseuri'] = $baseUri;
248 $this->vars[
'uri'] = $baseUri .
"?mod=" . $this->Name .
Traceback_parm_keep(array(
'upload',
'folder'));
249 $this->vars[
'bulkHistoryHighlightUri'] = $this->vars[
'uri'];
250 $this->vars[
'optionName'] =
"skipFile";
251 $this->vars[
'formName'] =
"uiClearingForm";
252 $this->vars[
'ajaxAction'] =
"setNextPrev";
254 $selectedAgentId, $highlightId, $clearingId, $uploadId);
255 if (empty($searchQuery)) {
258 $searchQuery = $request->query->get(
'search',
'');
261 if (!empty($searchQuery)) {
262 $searchQuery =
trim($searchQuery);
263 if (strlen($searchQuery) < 3) {
264 $this->vars[
'searchMatches'] = [];
269 if ($filePath && file_exists($filePath)) {
270 $this->vars[
'searchMatches'] = $this->
getSearchMatches($filePath, $searchQuery, $this->searchBlockSize);
272 $this->vars[
'searchMatches'] = [];
277 $isSingleFile = !$itemTreeBounds->containsFiles();
278 $hasWritePermission = $this->uploadDao->isEditable($uploadId, $groupId);
280 $clearingDecisions =
null;
281 if ($isSingleFile || $hasWritePermission) {
282 $clearingDecisions = $this->clearingDao->getFileClearings($itemTreeBounds, $groupId,
false);
285 if ($isSingleFile && $hasWritePermission) {
286 $this->vars[
'bulkUri'] =
Traceback_uri() .
"?mod=popup-license";
287 $licenseArray = $this->licenseDao->getLicenseArray($groupId);
288 list($addedResults, $removedResults) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION);
289 if (count($addedResults)+count($removedResults)>0) {
290 array_unshift($licenseArray, array(
'id'=>0,
'fullname'=>
'',
'shortname'=>
'------'));
293 foreach ($removedResults as $result) {
294 array_unshift($licenseArray, array(
'id'=>$result->getLicenseId() ,
'fullname'=>$result->getLicenseFullName() ,
'shortname'=>$result->getLicenseShortName()));
297 foreach ($addedResults as $result) {
298 array_unshift($licenseArray, array(
'id'=>$result->getLicenseId() ,
'fullname'=>$result->getLicenseFullName() ,
'shortname'=>$result->getLicenseShortName()));
300 $this->vars[
'licenseArray'] = $licenseArray;
301 } elseif ($isSingleFile) {
302 $this->vars[
'auditDenied'] =
true;
305 $selectedClearingType =
false;
306 $selectedClearingScope =
false;
307 if (!empty($clearingDecisions)) {
308 $selectedClearingType = $clearingDecisions[0]->getType();
309 $selectedClearingScope = $clearingDecisions[0]->getScope();
311 $bulkHistory = $this->clearingDao->getBulkHistory($itemTreeBounds, $groupId);
314 list($pageMenu, $textView) = $view->getView(NULL, $ModBack, 0,
"", $highlights,
false,
true);
316 $this->vars[
'uploadId'] = $uploadId;
317 $this->vars[
'itemId'] = $uploadTreeId;
318 $this->vars[
'pageMenu'] = $pageMenu;
319 $this->vars[
'textView'] = $textView;
320 $this->vars[
'legendData'] = $this->highlightRenderer->getLegendData($selectedAgentId || $clearingId);
321 $this->vars[
'clearingTypes'] = $this->decisionTypes->getMap();
322 $this->vars[
'selectedClearingType'] = $selectedClearingType;
323 $this->vars[
'selectedClearingScope'] = $selectedClearingScope;
324 $this->vars[
'tmpClearingType'] = $this->clearingDao->isDecisionCheck($uploadTreeId, $groupId, DecisionTypes::WIP);
325 $this->vars[
'bulkHistory'] = $bulkHistory;
328 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
329 UploadTreeProxy::OPT_GROUP_ID => $groupId),
330 $uploadTreeTableName,
331 'no_license_uploadtree' . $uploadId);
332 $filesOfInterest = $noLicenseUploadTreeView->count();
335 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
336 UploadTreeProxy::OPT_GROUP_ID => $groupId),
337 $uploadTreeTableName,
338 'already_cleared_uploadtree' . $uploadId);
339 $filesToBeCleared = $nonClearedUploadTreeView->count();
341 $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared;
342 $this->vars[
'message'] = _(
"Cleared").
": $filesAlreadyCleared/$filesOfInterest";
343 if ($filesOfInterest == 0) {
346 $percentage = ($filesAlreadyCleared / $filesOfInterest) * 100;
347 $percentage = ($percentage > 11) ? $percentage : 11;
349 $this->vars[
'progressBar'] =
"width:".$percentage.
"%";
351 return $this->
render(
"ui-clearing-view.html.twig");
359 $menuText=
"Licenses";
362 $tooltipText = _(
"Set the concluded licenses for this upload");
363 $this->microMenu->insert(array(MicroMenu::VIEW, MicroMenu::VIEW_META), $menuText, $menuPosition, $this->Name, $uri, $tooltipText );
366 menu_insert(
"Browse-Pfile::$menuText", 0, $this->Name, $tooltipText);
378 public function updateLastItem($userId, $groupId, $lastItem, $currentUploadtreeId)
382 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($lastItem);
383 $itemBounds = $this->uploadDao->getItemTreeBounds($lastItem, $uploadTreeTableName);
385 $isDecisionWip = $this->clearingDao->isDecisionCheck($currentUploadtreeId, $groupId, DecisionTypes::WIP);
386 $hasChangedClearingType = $this->clearingDao->isDecisionCheck($currentUploadtreeId, $groupId,
'');
387 if ($isDecisionWip) {
388 $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
389 }
else if (empty($hasChangedClearingType[
'scope'])
390 || ($hasChangedClearingType[
'decision_type'] != $type)
392 $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
397 $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
409 $handle = fopen($filePath,
"rb");
415 $searchLen = strlen($searchQuery);
419 $pattern =
'/' . preg_quote($searchQuery,
'/') .
'/i';
421 while (!feof($handle)) {
422 $chunk = fread($handle, $this->searchChunkSize);
423 $haystack = $overlapBuffer . $chunk;
425 if (preg_match_all($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
426 foreach ($matches[0] as $match) {
427 $posInHaystack = $match[1];
428 $absolutePos = $currentFilePos - strlen($overlapBuffer) + $posInHaystack;
430 if (empty($searchMatches) || end($searchMatches)[
'position'] !== $absolutePos) {
432 'position' => $absolutePos,
433 'page' => (int)floor($absolutePos / $blockSize)
439 $overlapBuffer = ($searchLen > 1) ? substr($haystack, -($searchLen - 1)) :
'';
440 $currentFilePos += strlen($chunk);
444 return $searchMatches;
getSelectedHighlighting(ItemTreeBounds $itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId)
RegisterMenus()
While menus can be added to any time at or after the PostInitialize phase, this is the standard locat...
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
getSearchMatches($filePath, $searchQuery, $blockSize=81920)
updateLastItem($userId, $groupId, $lastItem, $currentUploadtreeId)
__construct()
base constructor. Most plugins will just use this
This is the Plugin class. All plugins should:
Output()
This function is called when user output is requested. This function is responsible for content....
render($templateName, $vars=null)
Contains the constants and helpers for authentication of user.
Various utility functions to filter ClearingDecision.
Utility functions to process ClearingDecision.
Wrapper class for license map.
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.