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