FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ui-report-conf.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2019 Siemens AG
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
27 
29 {
30 
32  private $dbManager;
33 
37  private $uploadDao;
38 
41  private $userDao;
42 
46  private $licenseDao;
47 
51  private $clearingDao;
52 
56  private $mapDBColumns = array(
57  "reviewedBy" => "ri_reviewed",
58  "department" => "ri_department",
59  "reportRel" => "ri_report_rel",
60  "community" => "ri_community",
61  "component" => "ri_component",
62  "version" => "ri_version",
63  "relDate" => "ri_release_date",
64  "sw360Link" => "ri_sw360_link",
65  "footerNote" => "ri_footer",
66  "generalAssesment" => "ri_general_assesment",
67  "gaAdditional" => "ri_ga_additional",
68  "gaRisk" => "ri_ga_risk"
69  );
70 
74  private $checkBoxListUR = array(
75  "nonCritical",
76  "critical",
77  "noDependency",
78  "dependencySource",
79  "dependencyBinary",
80  "noExportRestriction",
81  "exportRestriction",
82  "noRestriction",
83  "restrictionForUse"
84  );
85 
89  private $checkBoxListSPDX = array(
90  "spdxLicenseComment",
91  "ignoreFilesWOInfo"
92  );
93 
94 
95  function __construct()
96  {
97  $this->Name = "report_conf";
98  $this->Title = _("Report Configuration");
99  $this->Dependency = array("browse");
100  $this->DBaccess = PLUGIN_DB_READ;
101  $this->LoginFlag = 0;
102  parent::__construct();
103  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
104  $this->dbManager = $GLOBALS['container']->get('db.manager');
105  $this->userDao = $GLOBALS['container']->get('dao.user');
106  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
107  $this->licenseDao = $GLOBALS['container']->get('dao.license');
108  }
109 
113  function RegisterMenus()
114  {
115  $tooltipText = _("Report Configuration");
116  menu_insert("Browse-Pfile::Conf",5,$this->Name,$tooltipText);
117  // For the Browse menu, permit switching between detail and summary.
118  $Parm = Traceback_parm_keep(array("upload","item","format"));
119  $URI = $this->Name . $Parm;
120 
121  $menuPosition = 60;
122  $menuText = "Conf";
123  if (GetParm("mod", PARM_STRING) == $this->Name) {
124  menu_insert("View::[BREAK]", 61);
125  menu_insert("View::[BREAK]", 50);
126  menu_insert("View::{$menuText}", $menuPosition);
127  menu_insert("View-Meta::[BREAK]", 61);
128  menu_insert("View-Meta::[BREAK]", 50);
129  menu_insert("View-Meta::{$menuText}", $menuPosition);
130 
131  menu_insert("Browse::Conf",-3);
132  } else {
133  $tooltipText = _("Report Configuration");
134  menu_insert("View::[BREAK]", 61);
135  menu_insert("View::[BREAK]", 50);
136  menu_insert("View::{$menuText}", $menuPosition, $URI, $tooltipText);
137  menu_insert("View-Meta::[BREAK]", 61);
138  menu_insert("View-Meta::[BREAK]", 50);
139  menu_insert("View-Meta::{$menuText}", $menuPosition, $URI, $tooltipText);
140 
141  menu_insert("Browse::Conf", -3, $URI, $tooltipText);
142  }
143  } // RegisterMenus()
144 
151  function allReportConfiguration($uploadId, $groupId)
152  {
153  $vars = [];
154  $row = $this->uploadDao->getReportInfo($uploadId);
155  foreach ($this->mapDBColumns as $key => $value) {
156  $vars[$key] = $row[$value];
157  }
158 
159  if (!empty($row['ri_ga_checkbox_selection'])) {
160  $listURCheckbox = explode(',', $row['ri_ga_checkbox_selection']);
161  foreach ($this->checkBoxListUR as $key => $value) {
162  $vars[$value] = $listURCheckbox[$key];
163  }
164  }
165 
166  if (!empty($row['ri_spdx_selection'])) {
167  $listSPDXCheckbox = explode(',', $row['ri_spdx_selection']);
168  foreach ($this->checkBoxListSPDX as $key => $value) {
169  $vars[$value] = $listSPDXCheckbox[$key];
170  }
171  }
172 
173  $tableRows = "";
174  $excludedObligations = array();
175  $excludedObligations = (array) json_decode($row['ri_excluded_obligations'], true);
176  foreach ($this->getAllObligationsForGivenUploadId($uploadId, $groupId) as $obTopic => $obData) {
177  $tableRows .= '<tr><td style="width:35%">'.$obTopic.'</td>';
178  $tableRows .= '<td><textarea readonly="readonly" style="overflow:auto;width:98%;height:80px;">'.
179  $obData['text'].'</textarea></td><td>';
180  foreach ($obData['license'] as $value) {
181  if (!empty($excludedObligations[$obTopic]) && in_array($value, $excludedObligations[$obTopic])) {
182  $tableRows .= '<input type="checkbox" name="obLicenses['.$obTopic.'][]" value="'.$value.'" checked> '.$value.'<br />';
183  } else {
184  $tableRows .= '<input type="checkbox" name="obLicenses['.$obTopic.'][]" value="'.$value.'"> '.$value.'<br />';
185  }
186  }
187  $tableRows .= '</td></tr>';
188  }
189  $vars['tableRows'] = $tableRows;
190  $vars['scriptBlock'] = $this->createScriptBlock();
191 
192  return $vars;
193  }
194 
201  function getAllObligationsForGivenUploadId($uploadId, $groupId)
202  {
203  $allClearedLicenses = array();
204  $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
205  $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
206  $allClearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
207  $licenseMap = new LicenseMap($this->dbManager, $groupId, LicenseMap::REPORT);
208  foreach ($allClearingDecisions as $clearingDecisions) {
209  if ($clearingDecisions->getType() == DecisionTypes::IRRELEVANT) {
210  continue;
211  }
212  foreach ($clearingDecisions->getClearingLicenses() as $eachClearingLicense) {
213  if ($eachClearingLicense->isRemoved()) {
214  continue;
215  }
216  $getLicenseId = $eachClearingLicense->getLicenseId();
217  $allClearedLicenses[] = $licenseMap->getProjectedId($getLicenseId);
218  }
219  }
220  $obligationsForLicenses = $this->licenseDao->getLicenseObligations($allClearedLicenses, 'obligation_map') ?: array();
221  $obligationsForLicenseCandidates = $this->licenseDao->getLicenseObligations($allClearedLicenses, 'obligation_candidate_map') ?: array();
222  $allObligations = array_merge($obligationsForLicenses, $obligationsForLicenseCandidates);
223  $groupedObligations = array();
224  foreach ($allObligations as $obligations) {
225  $groupBy = $obligations['ob_topic'];
226  if (array_key_exists($groupBy, $groupedObligations)) {
227  $currentLicenses = &$groupedObligations[$groupBy]['license'];
228  if (!in_array($obligations['rf_shortname'], $currentLicenses)) {
229  $currentLicenses[] = $obligations['rf_shortname'];
230  }
231  } else {
232  $groupedObligations[$groupBy] = array(
233  "topic" => $obligations['ob_topic'],
234  "text" => $obligations['ob_text'],
235  "license" => array($obligations['rf_shortname'])
236  );
237  }
238  }
239  return $groupedObligations;
240  }
241 
246  protected function getCheckBoxSelectionList($checkBoxListParams)
247  {
248  foreach ($checkBoxListParams as $checkBoxListParam) {
249  $ret = GetParm($checkBoxListParam, PARM_STRING);
250  if (empty($ret)) {
251  $cbList[] = "unchecked";
252  } else {
253  $cbList[] = "checked";
254  }
255  }
256  $cbSelectionList = implode(",", $cbList);
257 
258  return $cbSelectionList;
259  }
260 
261  public function Output()
262  {
263  $uploadId = GetParm("upload", PARM_INTEGER);
264  $groupId = Auth::getGroupId();
265  $userId = Auth::getUserId();
266  if (!$this->uploadDao->isAccessible($uploadId, $groupId)) {
267  return;
268  }
269 
270  $itemId = GetParm("item",PARM_INTEGER);
271  $this->vars['micromenu'] = Dir2Browse("browse", $itemId, NULL, $showBox=0, "View-Meta");
272  $this->vars['globalClearingAvailable'] = Auth::isClearingAdmin();
273 
274  $submitReportConf = GetParm("submitReportConf", PARM_STRING);
275 
276  if (isset($submitReportConf)) {
277  $parms = array();
278  $obLicenses = @$_POST["obLicenses"];
279  $i = 1;
280  $columns = "";
281  foreach ($this->mapDBColumns as $key => $value) {
282  $columns .= $value." = $".$i.", ";
283  $parms[] = GetParm($key, PARM_TEXT);
284  $i++;
285  }
286  $parms[] = $this->getCheckBoxSelectionList($this->checkBoxListUR);
287  $checkBoxUrPos = count($parms);
288  $parms[] = $this->getCheckBoxSelectionList($this->checkBoxListSPDX);
289  $checkBoxSpdxPos = count($parms);
290  $parms[] = json_encode($obLicenses);
291  $excludeObligationPos = count($parms);
292  $parms[] = $uploadId;
293  $uploadIdPos = count($parms);
294 
295  $SQL = "UPDATE report_info SET $columns" .
296  "ri_ga_checkbox_selection = $$checkBoxUrPos, " .
297  "ri_spdx_selection = $$checkBoxSpdxPos, " .
298  "ri_excluded_obligations = $$excludeObligationPos" .
299  "WHERE upload_fk = $$uploadIdPos;";
300  $this->dbManager->getSingleRow($SQL, $parms,
301  __METHOD__ . "updateReportInfoData");
302 
303  if (@$_POST['markGlobal']) {
304  $upload = $this->uploadDao->getUpload($uploadId);
305  $uploadName = $upload->getFilename();
306  $jobId = JobAddJob($userId, $groupId, $uploadName, $uploadId);
308  $deciderPlugin = plugin_find("agent_deciderjob");
309  $conflictStrategyId = "global";
310  $errorMsg = "";
311  $deciderPlugin->AgentAdd($jobId, $uploadId, $errorMsg, array(), $conflictStrategyId);
312  $schedulerMsg = empty(GetRunnableJobList()) ? _("Is the scheduler running? ") : '';
313  $url = Traceback_uri() . "?mod=showjobs&upload=$uploadId";
314  $text = _("Your jobs have been added to job queue.");
315  $linkText = _("View Jobs");
316  $this->vars['message'] = "$schedulerMsg" . "$text <a href=\"$url\">$linkText</a>";
317  }
318  }
319  $this->vars += $this->allReportConfiguration($uploadId, $groupId);
320  }
321 
322  public function getTemplateName()
323  {
324  return "ui-report-conf.html.twig";
325  }
326 
331  protected function createScriptBlock()
332  {
333  return "
334 
335  var reportTabCookie = 'stickyReportTab';
336 
337  $(document).ready(function() {
338  $(\"#confTabs\").tabs({
339  active: ($.cookie(reportTabCookie) || 0),
340  activate: function(e, ui){
341  // Get active tab index and update cookie
342  var idString = $(e.currentTarget).attr('id');
343  idString = parseInt(idString.slice(-1)) - 1;
344  $.cookie(reportTabCookie, idString);
345  }
346  });
347  });
348  ";
349  }
350 }
351 
352 $NewPlugin = new ui_report_conf();
353 $NewPlugin->Initialize();
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:274
GetRunnableJobList()
Get runnable job list, the process is below:
Traceback_uri()
Get the URI without query to this location.
const PARM_TEXT
Definition: common-parm.php:31
getCheckBoxSelectionList($checkBoxListParams)
getAllObligationsForGivenUploadId($uploadId, $groupId)
get all the obgligations for cleared licenses
createScriptBlock()
Create Script block for conf.
RegisterMenus()
Customize submenus.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:49
Wrapper class for license map.
Definition: LicenseMap.php:29
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
const PARM_STRING
Definition: common-parm.php:29
const PARM_INTEGER
Definition: common-parm.php:25
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
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_parm_keep($List)
Create a new URI, keeping only these items.
Output()
This function is called when user output is requested. This function is responsible for content...
Definition: FO_Plugin.php:407
allReportConfiguration($uploadId, $groupId)
list all the options for Report Configuration