FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ui-report-conf.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2019 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
17 
19 {
20 
22  private $dbManager;
23 
27  private $uploadDao;
28 
31  private $userDao;
32 
36  private $licenseDao;
37 
41  private $clearingDao;
42 
46  private $mapDBColumns = array(
47  "reviewedBy" => "ri_reviewed",
48  "department" => "ri_department",
49  "reportRel" => "ri_report_rel",
50  "community" => "ri_community",
51  "component" => "ri_component",
52  "version" => "ri_version",
53  "relDate" => "ri_release_date",
54  "sw360Link" => "ri_sw360_link",
55  "componentType" => "ri_component_type",
56  "componentId" => "ri_component_id",
57  "footerNote" => "ri_footer",
58  "generalAssesment" => "ri_general_assesment",
59  "gaAdditional" => "ri_ga_additional",
60  "gaRisk" => "ri_ga_risk",
61  "dependencyBinarySource" => "ri_depnotes",
62  "exportRestrictionText" => "ri_exportnotes",
63  "copyrightRestrictionText" => "ri_copyrightnotes"
64  );
65 
69  private $radioListUR = array(
70  "nonCritical" => "critical",
71  "critical" => "critical",
72  "noDependency" => "dependencySourceBinary",
73  "dependencySource" => "dependencySourceBinary",
74  "dependencyBinary" => "dependencySourceBinary",
75  "noExportRestriction" => "exportRestriction",
76  "exportRestriction" => "exportRestriction",
77  "noRestriction" => "restrictionForUse",
78  "restrictionForUse" => "restrictionForUse"
79  );
80 
84  private $checkBoxListSPDX = array(
85  "spdxLicenseComment" => "spdxLicenseComment",
86  "ignoreFilesWOInfo" => "ignoreFilesWOInfo"
87  );
88 
89 
90  function __construct()
91  {
92  $this->Name = "report_conf";
93  $this->Title = _("Report Configuration");
94  $this->Dependency = array("browse");
95  $this->DBaccess = PLUGIN_DB_READ;
96  $this->LoginFlag = 0;
97  parent::__construct();
98  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
99  $this->dbManager = $GLOBALS['container']->get('db.manager');
100  $this->userDao = $GLOBALS['container']->get('dao.user');
101  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
102  $this->licenseDao = $GLOBALS['container']->get('dao.license');
103  }
104 
108  function RegisterMenus()
109  {
110  $tooltipText = _("Report Configuration");
111  menu_insert("Browse-Pfile::Conf",5,$this->Name,$tooltipText);
112  // For the Browse menu, permit switching between detail and summary.
113  $Parm = Traceback_parm_keep(array("upload","item","format"));
114  $URI = $this->Name . $Parm;
115 
116  $menuPosition = 60;
117  $menuText = "Conf";
118  if (GetParm("mod", PARM_STRING) == $this->Name) {
119  menu_insert("View::[BREAK]", 61);
120  menu_insert("View::[BREAK]", 50);
121  menu_insert("View::{$menuText}", $menuPosition);
122  menu_insert("View-Meta::[BREAK]", 61);
123  menu_insert("View-Meta::[BREAK]", 50);
124  menu_insert("View-Meta::{$menuText}", $menuPosition);
125 
126  menu_insert("Browse::Conf",-3);
127  } else {
128  $tooltipText = _("Report Configuration");
129  menu_insert("View::[BREAK]", 61);
130  menu_insert("View::[BREAK]", 50);
131  menu_insert("View::{$menuText}", $menuPosition, $URI, $tooltipText);
132  menu_insert("View-Meta::[BREAK]", 61);
133  menu_insert("View-Meta::[BREAK]", 50);
134  menu_insert("View-Meta::{$menuText}", $menuPosition, $URI, $tooltipText);
135 
136  menu_insert("Browse::Conf", -3, $URI, $tooltipText);
137  }
138  } // RegisterMenus()
139 
146  function allReportConfiguration($uploadId, $groupId)
147  {
148  $vars = [];
149  $row = $this->uploadDao->getReportInfo($uploadId);
150  foreach ($this->mapDBColumns as $key => $value) {
151  $vars[$key] = $row[$value];
152  }
153  $textAreaNoneStyle = ' style="display:none;overflow:auto;width:98%;height:80px;"';
154  $textAreaStyle = ' style="overflow:auto;width:98%;height:80px;"';
155  $vars['styleDependencyTA'] = $vars['styleExportTA'] = $vars['styleRestrictionTA'] = $textAreaStyle;
156  if ($row['ri_depnotes'] == 'NA' || empty($row['ri_depnotes'])) {
157  $vars['styleDependencyTA'] = $textAreaNoneStyle;
158  }
159 
160  if ($row['ri_exportnotes'] == 'NA' || empty($row['ri_exportnotes'])) {
161  $vars['styleExportTA'] = $textAreaNoneStyle;
162  }
163 
164  if ($row['ri_copyrightnotes'] == 'NA' || empty($row['ri_copyrightnotes'])) {
165  $vars['styleRestrictionTA'] = $textAreaNoneStyle;
166  }
167 
168  if (!empty($row['ri_ga_checkbox_selection'])) {
169  $listURCheckbox = explode(',', $row['ri_ga_checkbox_selection']);
170  foreach (array_keys($this->radioListUR) as $key => $value) {
171  $vars[$value] = $listURCheckbox[$key];
172  }
173  }
174 
175  if (!empty($row['ri_spdx_selection'])) {
176  $listSPDXCheckbox = explode(',', $row['ri_spdx_selection']);
177  foreach (array_keys($this->checkBoxListSPDX) as $key => $value) {
178  $vars[$value] = $listSPDXCheckbox[$key];
179  }
180  }
181 
182  $tableRows = "";
183  $excludedObligations = array();
184  $excludedObligations = (array) json_decode($row['ri_excluded_obligations'], true);
185  foreach ($this->getAllObligationsForGivenUploadId($uploadId, $groupId) as $obTopic => $obData) {
186  $tableRows .= '<tr><td style="width:35%">'.$obTopic.'</td>';
187  $tableRows .= '<td><textarea readonly="readonly" style="overflow:auto;width:98%;height:80px;">'.
188  $obData['text'].'</textarea></td><td>';
189  foreach ($obData['license'] as $value) {
190  if (!empty($excludedObligations[$obTopic]) && in_array($value, $excludedObligations[$obTopic])) {
191  $tableRows .= '<input class="browse-upload-checkbox view-license-rc-size" type="checkbox" name="obLicenses['.urlencode($obTopic).'][]" value="'.$value.'" checked> '.$value.'<br />';
192  } else {
193  $tableRows .= '<input class="browse-upload-checkbox view-license-rc-size" type="checkbox" name="obLicenses['.urlencode($obTopic).'][]" value="'.$value.'"> '.$value.'<br />';
194  }
195  }
196  $tableRows .= '</td></tr>';
197  }
198  $tableRowsUnifiedReport = "";
199  $unifiedColumns = array();
200  if (!empty($row['ri_unifiedcolumns'])) {
201  $unifiedColumns = (array) json_decode($row['ri_unifiedcolumns'], true);
202  } else {
203  $unifiedColumns = UploadDao::UNIFIED_REPORT_HEADINGS;
204  }
205  foreach ($unifiedColumns as $name => $unifiedReportColumns) {
206  foreach ($unifiedReportColumns as $columnName => $isenabled) {
207  $tableRowsUnifiedReport .= '<tr>';
208  $tableRowsUnifiedReport .= '<td><input class="form-control" type="text" style="width:95%" name="'.$name.'[]" value="'.$columnName.'"></td>';
209  $checked = '';
210  if ($isenabled) {
211  $checked = 'checked';
212  }
213  $tableRowsUnifiedReport .= '<td style="vertical-align:middle"><input class="browse-upload-checkbox view-license-rc-size" type="checkbox" style="width:95%" name="'.$name.'[]" '.$checked.'></td>';
214  $tableRowsUnifiedReport .= '</tr>';
215  }
216  }
217 
218  $tableRowsClixmlReport = "";
219  $clixmlColumns = array();
220  if (!empty($row['ri_clixmlcolumns'])) {
221  $clixmlColumns = (array) json_decode($row['ri_clixmlcolumns'], true);
222  } else {
223  $clixmlColumns = UploadDao::CLIXML_REPORT_HEADINGS;
224  }
225  foreach ($clixmlColumns as $name => $clixmlReportColumns) {
226  foreach ($clixmlReportColumns as $columnName => $isenabled) {
227  $tableRowsClixmlReport .= '<tr>';
228  $tableRowsClixmlReport .= '<td><input class="form-control" type="text" style="width:95%" name="'.$name.'[]" value="'.$columnName.'" readonly></td>';
229  $checked = '';
230  if ($isenabled) {
231  $checked = 'checked';
232  }
233  $tableRowsClixmlReport .= '<td style="vertical-align:middle"><input class="browse-upload-checkbox view-license-rc-size" type="checkbox" style="width:95%" name="'.$name.'[]" '.$checked.'></td>';
234  $tableRowsClixmlReport .= '</tr>';
235  }
236  }
237 
238  if (!empty($row['ri_globaldecision'])) {
239  $vars['applyGlobal'] = "checked";
240  }
241  $vars['tableRows'] = $tableRows;
242  $vars['tableRowsUnifiedReport'] = $tableRowsUnifiedReport;
243  $vars['tableRowsClixmlReport'] = $tableRowsClixmlReport;
244  $vars['scriptBlock'] = $this->createScriptBlock();
245 
246  return $vars;
247  }
248 
255  function getAllObligationsForGivenUploadId($uploadId, $groupId)
256  {
257  $allClearedLicenses = array();
258  $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
259  $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
260  $allClearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
261  $licenseMap = new LicenseMap($this->dbManager, $groupId, LicenseMap::REPORT);
262  foreach ($allClearingDecisions as $clearingDecisions) {
263  if ($clearingDecisions->getType() == DecisionTypes::IRRELEVANT) {
264  continue;
265  }
266  foreach ($clearingDecisions->getClearingLicenses() as $eachClearingLicense) {
267  if ($eachClearingLicense->isRemoved()) {
268  continue;
269  }
270  $getLicenseId = $eachClearingLicense->getLicenseId();
271  $allClearedLicenses[] = $licenseMap->getProjectedId($getLicenseId);
272  }
273  }
274  $obligationsForLicenses = $this->licenseDao->getLicenseObligations($allClearedLicenses) ?: array();
275  $obligationsForLicenseCandidates = $this->licenseDao->getLicenseObligations($allClearedLicenses, true) ?: array();
276  $allObligations = array_merge($obligationsForLicenses, $obligationsForLicenseCandidates);
277  $groupedObligations = array();
278  foreach ($allObligations as $obligations) {
279  $groupBy = $obligations['ob_topic'];
280  if (array_key_exists($groupBy, $groupedObligations)) {
281  $currentLicenses = &$groupedObligations[$groupBy]['license'];
282  if (!in_array($obligations['rf_shortname'], $currentLicenses)) {
283  $currentLicenses[] = $obligations['rf_shortname'];
284  }
285  } else {
286  $groupedObligations[$groupBy] = array(
287  "topic" => $obligations['ob_topic'],
288  "text" => $obligations['ob_text'],
289  "license" => array($obligations['rf_shortname'])
290  );
291  }
292  }
293  return $groupedObligations;
294  }
295 
300  protected function getCheckBoxSelectionList($listParams)
301  {
302  foreach ($listParams as $listkey => $listValue) {
303  $ret = GetParm($listValue, PARM_STRING);
304  if ($ret != $listkey) {
305  $cbList[] = "unchecked";
306  } else {
307  $cbList[] = "checked";
308  }
309  }
310  $cbSelectionList = implode(",", $cbList);
311 
312  return $cbSelectionList;
313  }
314 
315  public function Output()
316  {
317  $uploadId = GetParm("upload", PARM_INTEGER);
318  $groupId = Auth::getGroupId();
319  $userId = Auth::getUserId();
320  if (!$this->uploadDao->isAccessible($uploadId, $groupId)) {
321  return;
322  }
323 
324  $itemId = GetParm("item",PARM_INTEGER);
325  $this->vars['micromenu'] = Dir2Browse("browse", $itemId, NULL, $showBox=0, "View-Meta");
326  $this->vars['globalClearingAvailable'] = Auth::isClearingAdmin();
327 
328  $submitReportConf = GetParm("submitReportConf", PARM_STRING);
329 
330  if (isset($submitReportConf)) {
331  $applyGlobal = @$_POST["applyGlobal"];
332  $applyGlobal = !empty($applyGlobal) ? 1 : 0;
333  $parms = array();
334  $obLicensesEncoded = @$_POST["obLicenses"];
335  $obLicensesEncoded = !empty($obLicensesEncoded) ? $obLicensesEncoded : array();
336  $obLicenses = array();
337  array_walk($obLicensesEncoded,
338  function (&$licArray, $obTopic) use (&$obLicenses) {
339  $obLicenses[urldecode($obTopic)] = $licArray;
340  }
341  );
342  $i = 1;
343  $columns = "";
344  foreach ($this->mapDBColumns as $key => $value) {
345  $columns .= $value." = $".$i.", ";
346  $parms[] = GetParm($key, PARM_RAW);
347  $i++;
348  }
349  $parms[] = $this->getCheckBoxSelectionList($this->radioListUR);
350 
351  $unifiedReportColumnsForJson = array();
352  foreach (UploadDao::UNIFIED_REPORT_HEADINGS as $columnName => $columnValue) {
353  $columnResult = @$_POST[$columnName];
354  $unifiedReportColumnsForJson[$columnName] = array($columnResult[0] => isset($columnResult[1]) ? $columnResult[1] : null);
355  }
356  $clixmlColumnsForJson = array();
357  foreach (UploadDao::CLIXML_REPORT_HEADINGS as $columnName => $columnValue) {
358  $columnResult = @$_POST[$columnName];
359  $clixmlColumnsForJson[$columnName] = array($columnResult[0] => isset($columnResult[1]) ? $columnResult[1] : null);
360  }
361  $checkBoxUrPos = count($parms);
362  $parms[] = $this->getCheckBoxSelectionList($this->checkBoxListSPDX);
363  $checkBoxSpdxPos = count($parms);
364  $parms[] = json_encode($obLicenses);
365  $excludeObligationPos = count($parms);
366  $parms[] = json_encode($unifiedReportColumnsForJson);
367  $unifiedColumnsPos = count($parms);
368  $parms[] = json_encode($clixmlColumnsForJson);
369  $clixmlColumnsPos = count($parms);
370  $parms[] = $applyGlobal;
371  $applyGlobalPos = count($parms);
372  $parms[] = $uploadId;
373  $uploadIdPos = count($parms);
374 
375  $SQL = "UPDATE report_info SET $columns" .
376  "ri_ga_checkbox_selection = $$checkBoxUrPos, " .
377  "ri_spdx_selection = $$checkBoxSpdxPos, " .
378  "ri_excluded_obligations = $$excludeObligationPos, " .
379  "ri_unifiedcolumns = $$unifiedColumnsPos, " .
380  "ri_clixmlcolumns = $$clixmlColumnsPos, " .
381  "ri_globaldecision = $$applyGlobalPos " .
382  "WHERE upload_fk = $$uploadIdPos;";
383  $this->dbManager->getSingleRow($SQL, $parms,
384  __METHOD__ . "updateReportInfoData");
385 
386  if (@$_POST['markGlobal']) {
387  $upload = $this->uploadDao->getUpload($uploadId);
388  $uploadName = $upload->getFilename();
389  $jobId = JobAddJob($userId, $groupId, $uploadName, $uploadId);
391  $deciderPlugin = plugin_find("agent_deciderjob");
392  $conflictStrategyId = "global";
393  $errorMsg = "";
394  $deciderPlugin->AgentAdd($jobId, $uploadId, $errorMsg, array(), $conflictStrategyId);
395  $schedulerMsg = empty(GetRunnableJobList()) ? _("Is the scheduler running? ") : '';
396  $url = Traceback_uri() . "?mod=showjobs&upload=$uploadId";
397  $text = _("Your jobs have been added to job queue.");
398  $linkText = _("View Jobs");
399  $this->vars['message'] = "$schedulerMsg" . "$text <a href=\"$url\">$linkText</a>";
400  }
401  }
402  $this->vars += $this->allReportConfiguration($uploadId, $groupId);
403  $this->vars['typemap'] = [];
404  foreach (ComponentType::TYPE_MAP as $key => $name) {
405  if ($key == ComponentType::PACKAGEURL) {
406  continue;
407  }
408  $this->vars['typemap'][] = ['key' => $key, 'name' => $name];
409  }
410  }
411 
412  public function getTemplateName()
413  {
414  return "ui-report-conf.html.twig";
415  }
416 
421  protected function createScriptBlock()
422  {
423  return "
424 
425  var reportTabCookie = 'stickyReportTab';
426 
427  $(document).ready(function() {
428  $(\"#confTabs\").tabs({
429  active: ($.cookie(reportTabCookie) || 0),
430  activate: function(e, ui){
431  // Get active tab index and update cookie
432  var idString = $(e.currentTarget).attr('id');
433  idString = parseInt(idString.slice(-1)) - 1;
434  $.cookie(reportTabCookie, idString);
435  }
436  });
437  $(\"input[name='dependencySourceBinary']\").change(function(){
438  var val = $(\"input[name='dependencySourceBinary']:checked\").val();
439  if (val == 'noDependency') {
440  $('#dependencyBinarySource').hide();
441  $('#dependencyBinarySource').val('');
442  } else {
443  $('#dependencyBinarySource').css('display', 'block');
444  }
445  });
446  $(\"input[name='exportRestriction']\").change(function(){
447  var val = $(\"input[name='exportRestriction']:checked\").val();
448  if (val == 'noExportRestriction') {
449  $('#exportRestrictionText').hide();
450  $('#exportRestrictionText').val('');
451  } else {
452  $('#exportRestrictionText').css('display', 'block');
453  }
454  });
455  $(\"input[name='restrictionForUse']\").change(function(){
456  var val = $(\"input[name='restrictionForUse']:checked\").val();
457  if (val == 'noRestriction') {
458  $('#copyrightRestrictionText').hide();
459  $('#copyrightRestrictionText').val('');
460  } else {
461  $('#copyrightRestrictionText').css('display', 'block');
462  }
463  });
464  });
465  ";
466  }
467 }
468 
469 $NewPlugin = new ui_report_conf();
470 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Output()
This function is called when user output is requested. This function is responsible for content....
Definition: FO_Plugin.php:399
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
Wrapper class for license map.
Definition: LicenseMap.php:19
getAllObligationsForGivenUploadId($uploadId, $groupId)
get all the obgligations for cleared licenses
createScriptBlock()
Create Script block for conf.
allReportConfiguration($uploadId, $groupId)
list all the options for Report Configuration
RegisterMenus()
Customize submenus.
getCheckBoxSelectionList($listParams)
__construct()
base constructor. Most plugins will just use this
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.
Definition: common-dir.php:263
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item.
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
const PARM_INTEGER
Definition: common-parm.php:14
const PARM_RAW
Definition: common-parm.php:22
const PARM_STRING
Definition: common-parm.php:18
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
GetRunnableJobList()
Get runnable job list, the process is below:
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:37
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16