FOSSology  4.7.1
Open Source License Compliance by Open Source Software
ui-export-list.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2017, 2020 Siemens AG
4  SPDX-FileCopyrightText: © 2021 LG Electronics Inc.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
24 use PhpOffice\PhpSpreadsheet\Spreadsheet;
25 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
26 use Symfony\Component\HttpFoundation\Response;
27 
32 class UIExportList extends FO_Plugin
33 {
36  private $uploadDao;
37 
40  private $licenseDao;
41 
44  private $clearingDao;
45 
48  private $copyrightDao;
49 
52  private $clearingFilter;
53 
56  private $treeDao;
57 
60  protected $delimiter = ',';
61 
64  protected $enclosure = '"';
65 
66  function __construct()
67  {
68  $this->Name = "export-list";
69  $this->Title = _("Export Lists");
70  $this->Dependency = array("browse");
71  $this->DBaccess = PLUGIN_DB_READ;
72  $this->LoginFlag = 0;
73  $this->NoHeader = 0;
74  parent::__construct();
75  $this->uploadDao = $GLOBALS['container']->get('dao.upload');
76  $this->licenseDao = $GLOBALS['container']->get('dao.license');
77  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
78  $this->copyrightDao = $GLOBALS['container']->get('dao.copyright');
79  $this->treeDao = $GLOBALS['container']->get('dao.tree');
80  $this->clearingFilter = $GLOBALS['container']->get('businessrules.clearing_decision_filter');
81  }
82 
87  public function setDelimiter($delimiter=',')
88  {
89  $this->delimiter = substr($delimiter, 0, 1);
90  }
91 
96  public function setEnclosure($enclosure='"')
97  {
98  $this->enclosure = substr($enclosure, 0, 1);
99  }
100 
104  function RegisterMenus()
105  {
106  // For all other menus, permit coming back here.
107  $URI = $this->Name . Traceback_parm_keep(array(
108  "show",
109  "format",
110  "page",
111  "upload",
112  "item",
113  ));
114  $MenuDisplayString = _("Export List");
115  $Item = GetParm("item", PARM_INTEGER);
116  $Upload = GetParm("upload", PARM_INTEGER);
117  if (empty($Item) || empty($Upload)) {
118  return;
119  }
120  if (GetParm("mod", PARM_STRING) == $this->Name) {
121  menu_insert("Browse::$MenuDisplayString", 1);
122  } else {
123  menu_insert("Browse::$MenuDisplayString", 1, $URI, $MenuDisplayString);
124  /* bobg - This is to use a select list in the micro menu to replace the above List
125  and Download, but put this select list in a form
126  $LicChoices = array("Lic Download" => "Download", "Lic display" => "Display");
127  $LicChoice = Array2SingleSelect($LicChoices, $SLName="LicDL");
128  menu_insert("Browse::Nomos License List Download2", 1, $URI . "&output=dltext", NULL,NULL, $LicChoice);
129  */
130  }
131  }
132 
139  function getAgentPksFromRequest($upload_pk)
140  {
141  $agents = array_keys(AgentRef::AGENT_LIST);
142  $agent_pks = array();
143 
144  foreach ($agents as $agent) {
145  if (GetParm("agentToInclude_".$agent, PARM_STRING)) {
146  /* get last nomos agent_pk that has data for this upload */
147  $AgentRec = AgentARSList($agent."_ars", $upload_pk, 1);
148  if (!empty($AgentRec)) {
149  $agent_pks[$agent] = $AgentRec[0]["agent_fk"];
150  } else {
151  $agent_pks[$agent] = false;
152  }
153  }
154  }
155  return $agent_pks;
156  }
157 
170  public function createListOfLines($uploadtreeTablename, $uploadtree_pk,
171  $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore)
172  {
173  $licensesPerFileName = array();
175  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk,
176  $uploadtreeTablename);
177  $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
178  Auth::getGroupId());
179  $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisionsForLicenseList($allDecisions);
180  $licensesPerFileName = $this->licenseDao->getLicensesPerFileNameForAgentId($itemTreeBounds,
181  $agent_pks, $includeSubfolder, $exclude, $ignore, $editedMappedLicenses,
182  true);
183  /* how many lines of data do you want to display */
184  $currentNum = 0;
185  $lines = [];
186  foreach ($licensesPerFileName as $fileName => $licenseNames) {
187  if ($licenseNames !== false && count($licenseNames) > 0) {
188  if ($NomostListNum > -1 && ++$currentNum > $NomostListNum) {
189  $lines["warn"] = _("<br><b>Warning: Only the first $NomostListNum " .
190  "lines are displayed. To see the whole list, run " .
191  "fo_nomos_license_list from the command line.</b><br>");
192  // TODO: the following should be done using a "LIMIT" statement in the sql query
193  break;
194  }
195 
196  $row = array();
197  $row['filePath'] = $fileName;
198  if (array_key_exists('scanResults', $licenseNames)) {
199  $row['agentFindings'] = $licenseNames['scanResults'];
200  } else {
201  $row['agentFindings'] = null;
202  }
203  $row['conclusions'] = null;
204  $row['uploadtree_pk'] = $licenseNames['uploadtree_pk'][0];
205  if (array_key_exists('concludedResults', $licenseNames) && !empty($licenseNames['concludedResults'])) {
206  $row['conclusions'] = $this->consolidateConclusions($licenseNames['concludedResults']);
207  }
208  $lines[] = $row;
209  }
210  if (!$ignore && $licenseNames === false) {
211  $row = array();
212  $row['filePath'] = $fileName;
213  $row['agentFindings'] = null;
214  $row['conclusions'] = null;
215  $lines[] = $row;
216  }
217  }
218  return $lines;
219  }
220 
225  public function getTemplateName()
226  {
227  return "ui-export-list.html.twig";
228  }
229 
233  function Output()
234  {
235  global $PG_CONN;
236  global $SysConf;
237  $formVars = array();
238  if (!$PG_CONN) {
239  echo _("NO DB connection");
240  }
241 
242  if ($this->State != PLUGIN_STATE_READY) {
243  return (0);
244  }
245  $uploadtree_pk = GetParm("item", PARM_INTEGER);
246  if (empty($uploadtree_pk)) {
247  return;
248  }
249 
250  $upload_pk = GetParm("upload", PARM_INTEGER);
251  if (empty($upload_pk)) {
252  return;
253  }
254  if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
255  $text = _("Permission Denied");
256  return "<h2>$text</h2>";
257  }
258  $uploadtreeTablename = GetUploadtreeTableName($upload_pk);
259 
260  $warnings = array();
261  $exportCopyright = GetParm('export_copy', PARM_STRING);
262  if (!empty($exportCopyright) && $exportCopyright == "yes") {
263  $exportCopyright = true;
264  $copyrightType = GetParm('copyright_type', PARM_STRING);
265  $formVars["export_copy"] = "1";
266  if ($copyrightType == "all") {
267  $formVars["copy_type_all"] = 1;
268  } else {
269  $formVars["copy_type_nolic"] = 1;
270  }
271  } else {
272  $exportCopyright = false;
273  $agent_pks_dict = $this->getAgentPksFromRequest($upload_pk);
274  $agent_pks = array();
275  foreach ($agent_pks_dict as $agent_name => $agent_pk) {
276  if ($agent_pk === false) {
277  $warnings[] = _("No information for agent: $agent_name");
278  } else {
279  $agent_pks[] = $agent_pk;
280  $formVars["agentToInclude_".$agent_name] = "1";
281  }
282  }
283  }
284 
285  // Make sure all copyrights is selected in the form be default
286  if (!(array_key_exists('copy_type_all', $formVars) ||
287  array_key_exists('copy_type_nolic', $formVars))) {
288  $formVars["copy_type_all"] = 1;
289  }
290 
291  $dltext = (GetParm("output", PARM_STRING) == 'dltext');
292  $formVars["dltext"] = $dltext;
293  $dlspreadsheet = (GetParm("output", PARM_STRING) == 'dlspreadsheet');
294  $formVars["dlspreadsheet"] = $dlspreadsheet;
295  if (!$dltext&&!$dlspreadsheet) {
296  $formVars["noDownload"] = true;
297  } else {
298  $formVars["noDownload"] = false;
299  }
300 
301  $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
302  $formVars["NomostListNum"] = $NomostListNum;
303 
304  $includeSubfolder = (GetParm("doNotIncludeSubfolder", PARM_STRING) !== "yes");
305  $formVars["includeSubfolder"] = $includeSubfolder;
306 
307  $ignore = (GetParm("showContainers", PARM_STRING) !== "yes");
308  $formVars["showContainers"] = !$ignore;
309  $exclude = GetParm("exclude", PARM_STRING);
310  $formVars["exclude"] = $exclude;
311 
312  $consolidateLicenses = (GetParm("consolidate", PARM_STRING) == "perFile");
313  $formVars["perFile"] = $consolidateLicenses;
314  $consolidatePerDirectory = (GetParm("consolidate", PARM_STRING) == "perDirectory");
315  $formVars["perDirectory"] = $consolidatePerDirectory;
316  if (!$consolidateLicenses&&!$consolidatePerDirectory) {
317  $formVars["rawResult"] = true;
318  } else {
319  $formVars["rawResult"] = false;
320  }
321 
322  $this->vars = array_merge($this->vars, $formVars);
323 
324  if ($exportCopyright) {
325  $lines = $this->getCopyrights($upload_pk, $uploadtree_pk,
326  $uploadtreeTablename, $NomostListNum, $exclude, $copyrightType);
327  } else {
328  $lines = $this->createListOfLines($uploadtreeTablename, $uploadtree_pk,
329  $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore);
330  }
331 
332  $this->vars['warnings'] = array();
333  if (array_key_exists("warn",$lines)) {
334  $warnings[] = $lines["warn"];
335  unset($lines["warn"]);
336  }
337  foreach ($warnings as $warning) {
338  $this->vars['warnings'][] = "<br><b>$warning</b><br>";
339  }
340  if (empty($lines)) {
341  $this->vars['warnings'][] = "<br /><b>Result empty</b><br />";
342  }
343 
344  if ($consolidateLicenses||$consolidatePerDirectory) {
345  $lines = $this->consolidateResult($lines);
346  }
347  if ($consolidatePerDirectory) {
348  $lines = $this->consolidateFindingsPerDirectory($lines);
349  }
350 
351  if ($dltext) {
352  return $this->printCSV($lines, $uploadtreeTablename, $exportCopyright);
353  } elseif ($dlspreadsheet) {
354  return $this->printSpreadsheet($lines, $uploadtreeTablename);
355  } else {
356  $this->vars['listoutput'] = $this->printLines($lines, $exportCopyright);
357  return;
358  }
359  }
360 
374  public function getCopyrights($uploadId, $uploadtree_pk, $uploadTreeTableName,
375  $NomostListNum, $exclude, $copyrightType = "all")
376  {
377  $agentName = array('copyright', 'reso');
378  $scanJobProxy = new ScanJobProxy($GLOBALS['container']->get('dao.agent'),
379  $uploadId);
380  $scanJobProxy->createAgentStatus($agentName);
381  $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
382  if (!array_key_exists($agentName[0], $selectedScanners)) {
383  return array();
384  }
385  $latestAgentIds[] = $selectedScanners[$agentName[0]];
386  if (array_key_exists($agentName[1], $selectedScanners)) {
387  $latestAgentIds[] = $selectedScanners[$agentName[1]];
388  }
389  $ids = implode(',', $latestAgentIds);
390  $agentFilter = ' AND C.agent_fk IN ('.$ids.')';
391 
392  $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk,
393  $uploadTreeTableName);
394  $extrawhere = "UT.lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " .
395  $itemTreeBounds->getRight();
396  if (! empty($exclude)) {
397  $extrawhere .= " AND UT.ufile_name NOT LIKE '%$exclude%'";
398  }
399  $lines = [];
400  $uploadtreePkToFilePath = [];
401 
402  $copyrights = $this->copyrightDao->getScannerEntries($agentName[0],
403  $uploadTreeTableName, $uploadId, null, $extrawhere . $agentFilter);
404  $this->updateCopyrightList($lines, $uploadtreePkToFilePath, $copyrights,
405  $NomostListNum, $uploadTreeTableName, "content");
406 
407  $copyrights = $this->copyrightDao->getEditedEntries('copyright_decision',
408  $uploadTreeTableName, $uploadId, [], $extrawhere);
409  $this->updateCopyrightList($lines, $uploadtreePkToFilePath, $copyrights,
410  $NomostListNum, $uploadTreeTableName, "textfinding");
411 
412  if ($copyrightType != "all") {
413  $agentList = [];
414  foreach (AgentRef::AGENT_LIST as $agentname => $value) {
415  $AgentRec = AgentARSList($agentname."_ars", $uploadId, 1);
416  if (!empty($AgentRec)) {
417  $agentList[] = $AgentRec[0]["agent_fk"];
418  }
419  }
420  $this->removeCopyrightWithLicense($lines, $uploadtreePkToFilePath,
421  $itemTreeBounds, $agentList, $exclude);
422  }
423  return $this->reduceCopyrightLines($lines);
424  }
425 
435  private function updateCopyrightList(&$list, &$uploadtreePkToFilePath,
436  $newCopyrights, $NomostListNum, $uploadTreeTableName, $key)
437  {
438  foreach ($newCopyrights as $copyright) {
439  if ($NomostListNum > -1 && count($list) >= $NomostListNum) {
440  $list["warn"] = _("<br><b>Warning: Only the first $NomostListNum lines
441  are displayed. To see the whole list, run fo_nomos_license_list from the
442  command line.</b><br>");
443  break;
444  }
445  $row = [];
446  $row["content"] = $copyright[$key];
447  $row["filePath"] = $this->treeDao->getFullPath($copyright["uploadtree_pk"],
448  $uploadTreeTableName);
449  $uploadtreePkToFilePath[$copyright["uploadtree_pk"]] = $row["filePath"];
450  $list[$row["filePath"]][] = $row;
451  }
452  }
453 
463  private function removeCopyrightWithLicense(&$lines,
464  $uploadtreePkToFilePath, $itemTreeBounds, $agentList, $exclude)
465  {
466  $licensesPerFileName = array();
467  $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
468  Auth::getGroupId());
469  $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisionsForCopyrightList(
470  $allDecisions);
471  $licensesPerFileName = $this->licenseDao->getLicensesPerFileNameForAgentId(
472  $itemTreeBounds, $agentList, true, $exclude, true, $editedMappedLicenses,
473  true);
474  foreach ($licensesPerFileName as $licenseNames) {
475  if ($licenseNames !== false && count($licenseNames) > 0) {
476  $shouldRemove = false;
477  if (array_key_exists('concludedResults', $licenseNames)) {
478  $conclusions = $this->consolidateConclusions($licenseNames['concludedResults']);
479  if (in_array("Void", $conclusions)) {
480  // File has all licenses removed or irrelevant decision
481  continue;
482  }
483  // File has license conclusions
484  $shouldRemove = true;
485  }
486  if ((! empty($licenseNames['scanResults'])) &&
487  ! (in_array("No_license_found", $licenseNames['scanResults']) ||
488  in_array("Void", $licenseNames['scanResults']))) {
489  $shouldRemove = true;
490  }
491  if ($shouldRemove) {
492  $this->removeCopyrightByUploadtreePk($lines, $uploadtreePkToFilePath,
493  $licenseNames['uploadtree_pk']);
494  }
495  }
496  }
497  }
498 
504  private function consolidateConclusions($conclusions)
505  {
506  $consolidatedConclusions = array();
507  foreach ($conclusions as $conclusion) {
508  $consolidatedConclusions = array_merge($consolidatedConclusions,
509  $conclusion);
510  }
511  return array_unique($consolidatedConclusions);
512  }
513 
521  private function removeCopyrightByUploadtreePk(&$lines,
522  $uploadtreePkToFilePath, $uploadtreePks)
523  {
524  foreach ($uploadtreePks as $uploadtreePk) {
525  if (array_key_exists($uploadtreePk, $uploadtreePkToFilePath)) {
526  unset($lines[$uploadtreePkToFilePath[$uploadtreePk]]);
527  }
528  }
529  }
530 
537  private function printLines($lines, $copyright=false)
538  {
539  $V = '';
540  if ($copyright) {
541  foreach ($lines as $row) {
542  $V .= $row['filePath'] . ": " . htmlentities($row['content']) . "\n";
543  }
544  } else {
545  foreach ($lines as $row) {
546  $V .= $row['filePath'];
547  if ($row['agentFindings'] !== null) {
548  $V .= ": " . implode(' ', $row['agentFindings']);
549  if ($row['conclusions'] !== null) {
550  $V .= ", " . implode(' ', $row['conclusions']);
551  }
552  }
553  $V .= "\n";
554  }
555  }
556  return $V;
557  }
558 
564  private function consolidateResult($lines)
565  {
566  $newLines = [];
567  foreach ($lines as $row) {
568  $consolidatedLicenses = array();
569  if ($row['agentFindings'] == null) {
570  continue;
571  }
572  if ($row['conclusions'] !== null) {
573  $row['agentFindings'] = array();
574  foreach ($row['conclusions'] as $key => $value) {
575  $row['agentFindings'][$key] = $row['conclusions'][$key];
576  }
577  $row['conclusions'] = null;
578  } elseif ($row['agentFindings'] == null) {
579  continue;
580  } else {
581  foreach ($row['agentFindings'] as $key => $value) {
582  if ($value == "No_license_found") {
583  unset($row['agentFindings'][$key]);
584  } else {
585  $consolidatedLicenses[] = $row['agentFindings'][$key];
586  }
587  }
588  $consolidatedLicenses = array_unique($consolidatedLicenses);
589  foreach ($row['agentFindings'] as $key => $value) {
590  if (array_key_exists($key, $consolidatedLicenses) && $consolidatedLicenses[$key] !== null) {
591  $row['agentFindings'][$key] = $consolidatedLicenses[$key];
592  } else {
593  unset($row['agentFindings'][$key]);
594  }
595  }
596  }
597  $newLines[] = $row;
598  }
599 
600  return $newLines;
601  }
602 
609  private function consolidateFindingsPerDirectory($lines)
610  {
611  $newLines = [];
612  $consolidatedByDirectory = [];
613  foreach ($lines as $row) {
614  $path_parts = pathinfo($row['filePath']);
615  sort($row['agentFindings']);
616  if (array_key_exists($path_parts['dirname'], $consolidatedByDirectory)) {
617  if (in_array($row['agentFindings'], $consolidatedByDirectory[$path_parts['dirname']])) {
618  continue;
619  } else {
620  $consolidatedByDirectory[$path_parts['dirname']][] = $row['agentFindings'];
621  }
622  } else {
623  $consolidatedByDirectory[$path_parts['dirname']][] = $row['agentFindings'];
624  }
625  }
626  foreach ($consolidatedByDirectory as $key => $value) {
627  foreach ($consolidatedByDirectory[$key] as $newKey => $newValue) {
628  $newRow = [];
629  $newRow['filePath'] = $key . "/";
630  $newRow['agentFindings'] = $newValue;
631  $newRow['conclusions'] = null;
632  $newLines[] = $newRow;
633  }
634  }
635  return $newLines;
636  }
637 
638 
646  private function printCSV($lines, $uploadtreeTablename, $copyright = false)
647  {
648  $request = $this->getRequest();
649  $itemId = intval($request->get('item'));
650  $path = Dir2Path($itemId, $uploadtreeTablename);
651  $fileName = $path[count($path) - 1]['ufile_name']."-".date("Ymd");
652  if ($copyright) {
653  $fileName .= "-copyrights";
654  } else {
655  $fileName .= "-licenses";
656  }
657 
658  $out = fopen('php://output', 'w');
659  ob_start();
660  if (!$copyright) {
661  $head = array('file path', 'scan results', 'concluded results');
662  } else {
663  $head = array('file path', 'copyright');
664  }
665  fputcsv($out, $head, $this->delimiter, $this->enclosure);
666  foreach ($lines as $row) {
667  $newRow = array();
668  $newRow[] = $row['filePath'];
669  if ($copyright) {
670  $newRow[] = $row['content'];
671  } else {
672  if ($row['agentFindings'] !== null) {
673  $newRow[] = implode(' ', $row['agentFindings']);
674  } else {
675  $newRow[] = "";
676  }
677  if ($row['conclusions'] !== null) {
678  $newRow[] = implode(' ', $row['conclusions']);
679  } else {
680  $newRow[] = "";
681  }
682  }
683  fputcsv($out, $newRow, $this->delimiter, $this->enclosure);
684  }
685  $content = ob_get_contents();
686  ob_end_clean();
687 
688  $headers = array(
689  'Content-type' => 'text/csv, charset=UTF-8',
690  'Content-Disposition' => 'attachment; filename='.$fileName.'.csv',
691  'Pragma' => 'no-cache',
692  'Cache-Control' => 'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0',
693  'Expires' => 'Expires: Thu, 19 Nov 1981 08:52:00 GMT'
694  );
695 
696  return new Response($content, Response::HTTP_OK, $headers);
697  }
698 
705  private function printSpreadsheet($lines, $uploadtreeTablename)
706  {
707  $request = $this->getRequest();
708  $itemId = intval($request->get('item'));
709  $path = Dir2Path($itemId, $uploadtreeTablename);
710  $fileName = $path[count($path) - 1]['ufile_name']."-".date("Ymd");
711 
712  $spreadsheet = new Spreadsheet();
713  $sheet = $spreadsheet->getActiveSheet();
714 
715  $headRow = array(
716  'A' => array(5, 'id', 'ID'),
717  'B' => array(30, 'path', 'Source Name or Path'),
718  'C' => array(20, 'name', 'OSS Name'),
719  'D' => array(10, 'version', 'OSS Version'),
720  'E' => array(20, 'scan results', 'Scan Results'),
721  'F' => array(20, 'concluded results', 'Concluded Results'),
722  'G' => array(20, 'download', 'Download Location'),
723  'H' => array(20, 'homepage', 'Homepage'),
724  'I' => array(30, 'copyright', 'Copyright Text'),
725  'J' => array(10, 'exclude', 'Exclude'),
726  'K' => array(30, 'comment', 'Comment')
727  );
728  $styleArray = [
729  'font' => [
730  'bold' => true,
731  'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE],
732  ],
733  'alignment' => [
734  'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
735  ],
736  'borders' => [
737  'allBorders' => [
738  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
739  'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK],
740  ]
741  ],
742  'fill' => [
743  'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
744  'startColor' => ['argb' => '002060'],
745  ],
746  ];
747  $sheet->getStyle('A1:J1')->applyFromArray($styleArray);
748  foreach ($headRow as $key => $val) {
749  $cellName = $key.'1';
750 
751  $sheet->getColumnDimension($key)->setWidth($val[0]);
752 
753  $sheet->setCellValue($cellName, $val[2]);
754  }
755 
756  $styleArray = [
757  'font' => [
758  'color' => ['argb' => '808080'],
759  ],
760  'borders' => [
761  'vertical' => [
762  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
763  'color' => ['argb' => 'B2B2B2'],
764  ]
765  ],
766  'fill' => [
767  'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
768  'startColor' => ['argb' => 'FFFFCC'],
769  ],
770  ];
771  $sheet->getStyle('A2:J2')->applyFromArray($styleArray);
772  $annotationRow = array(
773  'A' => array('id', '-'),
774  'B' => array('path', '[Name of the Source File or Path]'),
775  'C' => array('name', '[Name of the OSS used]'),
776  'D' => array('version', '[Version Number of the OSS]'),
777  'E' => array('scanResults', '[Scan results. Use SPDX Identifier : https://spdx.org/licenses/]'),
778  'F' => array('concludedResults', '[Concluded results. Use SPDX Identifier : https://spdx.org/licenses/]'),
779  'G' => array('download', '[Download URL or a specific location within a VCS for the OSS]'),
780  'H' => array('homepage', '[Web site that serves as the OSSs home page]'),
781  'I' => array('copyright', '[The copyright holders of the OSS. E.g. Copyright (c) 201X Copyright Holder]'),
782  'J' => array('exclude', '[If this OSS is not included in the final version, Check exclude]'),
783  'K' => array('comment','')
784  );
785  foreach ($annotationRow as $key => $val) {
786  $cellName = $key.'2';
787 
788  $sheet->setCellValue($cellName, $val[1]);
789  }
790 
791  $styleArray = [
792  'borders' => [
793  'allBorders' => [
794  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
795  'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK],
796  ]
797  ],
798  ];
799 
800  $id = 1;
801  foreach ($lines as $row) {
802  $rowNumber = $id + 2;
803  $range = 'A'.$rowNumber.':K'.$rowNumber;
804  $sheet->getStyle($range)->applyFromArray($styleArray);
805  $sheet->setCellValue('A'.$rowNumber, "$id");
806  $sheet->setCellValue('B'.$rowNumber, $row['filePath']);
807 
808  if ($row['agentFindings'] !== null) {
809  $scannedLicenses = implode(',', $row['agentFindings']);
810  $sheet->setCellValue('E'.$rowNumber, $scannedLicenses);
811  }
812  if ($row['conclusions'] !== null) {
813  $concludedLicenses = implode(',', $row['conclusions']);
814  $sheet->setCellValue('F'.$rowNumber, $concludedLicenses);
815  }
816  $id++;
817  }
818 
819  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
820  header('Content-Disposition: attachment; filename="'.$fileName.'.xlsx"');
821  header('Cache-Control: max-age=0');
822 
823  $writer = new Xlsx($spreadsheet);
824  ob_end_clean();
825  $writer->save('php://output');
826  exit();
827  }
828 
834  private function reduceCopyrightLines($lines)
835  {
836  $reducedLines = array();
837  foreach ($lines as $line) {
838  foreach ($line as $copyright) {
839  $reducedLines[] = $copyright;
840  }
841  }
842  return $reducedLines;
843  }
844 }
845 
846 $NewPlugin = new UIExportList();
847 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
Various utility functions to filter ClearingDecision.
Definition: state.hpp:16
setEnclosure($enclosure='"')
printLines($lines, $copyright=false)
getCopyrights($uploadId, $uploadtree_pk, $uploadTreeTableName, $NomostListNum, $exclude, $copyrightType="all")
setDelimiter($delimiter=',')
getAgentPksFromRequest($upload_pk)
consolidateConclusions($conclusions)
Output()
This function returns the scheduler status.
removeCopyrightByUploadtreePk(&$lines, $uploadtreePkToFilePath, $uploadtreePks)
updateCopyrightList(&$list, &$uploadtreePkToFilePath, $newCopyrights, $NomostListNum, $uploadTreeTableName, $key)
consolidateFindingsPerDirectory($lines)
removeCopyrightWithLicense(&$lines, $uploadtreePkToFilePath, $itemTreeBounds, $agentList, $exclude)
printCSV($lines, $uploadtreeTablename, $copyright=false)
RegisterMenus()
Customize submenus.
reduceCopyrightLines($lines)
consolidateResult($lines)
printSpreadsheet($lines, $uploadtreeTablename)
__construct()
base constructor. Most plugins will just use this
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
Definition: common-dir.php:222
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.
const PARM_INTEGER
Definition: common-parm.php:14
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.
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree".
Definition: libfossagent.c:414
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:37
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN