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