FOSSology  4.4.0
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 
401  $copyrights = $this->copyrightDao->getScannerEntries($agentName[0],
402  $uploadTreeTableName, $uploadId, null, $extrawhere . $agentFilter);
403  $this->updateCopyrightList($lines, $copyrights, $NomostListNum,
404  $uploadTreeTableName, "content");
405 
406  $copyrights = $this->copyrightDao->getEditedEntries('copyright_decision',
407  $uploadTreeTableName, $uploadId, [], $extrawhere);
408  $this->updateCopyrightList($lines, $copyrights, $NomostListNum,
409  $uploadTreeTableName, "textfinding");
410 
411  if ($copyrightType != "all") {
412  $agentList = [];
413  foreach (AgentRef::AGENT_LIST as $agentname => $value) {
414  $AgentRec = AgentARSList($agentname."_ars", $uploadId, 1);
415  if (!empty($AgentRec)) {
416  $agentList[] = $AgentRec[0]["agent_fk"];
417  }
418  }
419  $this->removeCopyrightWithLicense($lines, $itemTreeBounds, $agentList,
420  $exclude);
421  }
422  return $this->reduceCopyrightLines($lines);
423  }
424 
433  private function updateCopyrightList(&$list, $newCopyrights, $NomostListNum,
434  $uploadTreeTableName, $key)
435  {
436  foreach ($newCopyrights as $copyright) {
437  if ($NomostListNum > -1 && count($list) >= $NomostListNum) {
438  $lines["warn"] = _("<br><b>Warning: Only the first $NomostListNum lines
439  are displayed. To see the whole list, run fo_nomos_license_list from the
440  command line.</b><br>");
441  break;
442  }
443  $row = [];
444  $row["content"] = $copyright[$key];
445  $row["filePath"] = $this->treeDao->getFullPath($copyright["uploadtree_pk"],
446  $uploadTreeTableName);
447  $list[$row["filePath"]][] = $row;
448  }
449  }
450 
459  private function removeCopyrightWithLicense(&$lines, $itemTreeBounds,
460  $agentList, $exclude)
461  {
462  $licensesPerFileName = array();
463  $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds,
464  Auth::getGroupId());
465  $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisionsForCopyrightList(
466  $allDecisions);
467  $licensesPerFileName = $this->licenseDao->getLicensesPerFileNameForAgentId(
468  $itemTreeBounds, $agentList, true, $exclude, true, $editedMappedLicenses);
469  foreach ($licensesPerFileName as $fileName => $licenseNames) {
470  if ($licenseNames !== false && count($licenseNames) > 0) {
471  if (array_key_exists('concludedResults', $licenseNames)) {
472  $conclusions = $this->consolidateConclusions($licenseNames['concludedResults']);
473  if (in_array("Void", $conclusions)) {
474  // File has all licenses removed or irrelevant decision
475  continue;
476  }
477  // File has license conclusions
478  $this->removeIfKeyExists($lines, $fileName);
479  }
480  if ((! empty($licenseNames['scanResults'])) &&
481  ! (in_array("No_license_found", $licenseNames['scanResults']) ||
482  in_array("Void", $licenseNames['scanResults']))) {
483  $this->removeIfKeyExists($lines, $fileName);
484  }
485  }
486  }
487  }
488 
494  private function consolidateConclusions($conclusions)
495  {
496  $consolidatedConclusions = array();
497  foreach ($conclusions as $conclusion) {
498  $consolidatedConclusions = array_merge($consolidatedConclusions,
499  $conclusion);
500  }
501  return array_unique($consolidatedConclusions);
502  }
503 
511  private function removeIfKeyExists(&$lines, $key)
512  {
513  foreach (array_keys($lines) as $file) {
514  if (strpos($file, $key) !== false) {
515  unset($lines[$file]);
516  break;
517  }
518  }
519  }
520 
527  private function printLines($lines, $copyright=false)
528  {
529  $V = '';
530  if ($copyright) {
531  foreach ($lines as $row) {
532  $V .= $row['filePath'] . ": " . htmlentities($row['content']) . "\n";
533  }
534  } else {
535  foreach ($lines as $row) {
536  $V .= $row['filePath'];
537  if ($row['agentFindings'] !== null) {
538  $V .= ": " . implode(' ', $row['agentFindings']);
539  if ($row['conclusions'] !== null) {
540  $V .= ", " . implode(' ', $row['conclusions']);
541  }
542  }
543  $V .= "\n";
544  }
545  }
546  return $V;
547  }
548 
554  private function consolidateResult($lines)
555  {
556  $newLines = [];
557  foreach ($lines as $row) {
558  $consolidatedLicenses = array();
559  if ($row['agentFindings'] == null) {
560  continue;
561  }
562  if ($row['conclusions'] !== null) {
563  $row['agentFindings'] = array();
564  foreach ($row['conclusions'] as $key => $value) {
565  $row['agentFindings'][$key] = $row['conclusions'][$key];
566  }
567  $row['conclusions'] = null;
568  } elseif ($row['agentFindings'] == null) {
569  continue;
570  } else {
571  foreach ($row['agentFindings'] as $key => $value) {
572  if ($value == "No_license_found") {
573  unset($row['agentFindings'][$key]);
574  } else {
575  $consolidatedLicenses[] = $row['agentFindings'][$key];
576  }
577  }
578  $consolidatedLicenses = array_unique($consolidatedLicenses);
579  foreach ($row['agentFindings'] as $key => $value) {
580  if (array_key_exists($key, $consolidatedLicenses) && $consolidatedLicenses[$key] !== null) {
581  $row['agentFindings'][$key] = $consolidatedLicenses[$key];
582  } else {
583  unset($row['agentFindings'][$key]);
584  }
585  }
586  }
587  $newLines[] = $row;
588  }
589 
590  return $newLines;
591  }
592 
599  private function consolidateFindingsPerDirectory($lines)
600  {
601  $newLines = [];
602  $consolidatedByDirectory = [];
603  foreach ($lines as $row) {
604  $path_parts = pathinfo($row['filePath']);
605  sort($row['agentFindings']);
606  if (array_key_exists($path_parts['dirname'], $consolidatedByDirectory)) {
607  if (in_array($row['agentFindings'], $consolidatedByDirectory[$path_parts['dirname']])) {
608  continue;
609  } else {
610  $consolidatedByDirectory[$path_parts['dirname']][] = $row['agentFindings'];
611  }
612  } else {
613  $consolidatedByDirectory[$path_parts['dirname']][] = $row['agentFindings'];
614  }
615  }
616  foreach ($consolidatedByDirectory as $key => $value) {
617  foreach ($consolidatedByDirectory[$key] as $newKey => $newValue) {
618  $newRow = [];
619  $newRow['filePath'] = $key . "/";
620  $newRow['agentFindings'] = $newValue;
621  $newRow['conclusions'] = null;
622  $newLines[] = $newRow;
623  }
624  }
625  return $newLines;
626  }
627 
628 
636  private function printCSV($lines, $uploadtreeTablename, $copyright = false)
637  {
638  $request = $this->getRequest();
639  $itemId = intval($request->get('item'));
640  $path = Dir2Path($itemId, $uploadtreeTablename);
641  $fileName = $path[count($path) - 1]['ufile_name']."-".date("Ymd");
642  if ($copyright) {
643  $fileName .= "-copyrights";
644  } else {
645  $fileName .= "-licenses";
646  }
647 
648  $out = fopen('php://output', 'w');
649  ob_start();
650  if (!$copyright) {
651  $head = array('file path', 'scan results', 'concluded results');
652  } else {
653  $head = array('file path', 'copyright');
654  }
655  fputcsv($out, $head, $this->delimiter, $this->enclosure);
656  foreach ($lines as $row) {
657  $newRow = array();
658  $newRow[] = $row['filePath'];
659  if ($copyright) {
660  $newRow[] = $row['content'];
661  } else {
662  if ($row['agentFindings'] !== null) {
663  $newRow[] = implode(' ', $row['agentFindings']);
664  } else {
665  $newRow[] = "";
666  }
667  if ($row['conclusions'] !== null) {
668  $newRow[] = implode(' ', $row['conclusions']);
669  } else {
670  $newRow[] = "";
671  }
672  }
673  fputcsv($out, $newRow, $this->delimiter, $this->enclosure);
674  }
675  $content = ob_get_contents();
676  ob_end_clean();
677 
678  $headers = array(
679  'Content-type' => 'text/csv, charset=UTF-8',
680  'Content-Disposition' => 'attachment; filename='.$fileName.'.csv',
681  'Pragma' => 'no-cache',
682  'Cache-Control' => 'no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0',
683  'Expires' => 'Expires: Thu, 19 Nov 1981 08:52:00 GMT'
684  );
685 
686  return new Response($content, Response::HTTP_OK, $headers);
687  }
688 
695  private function printSpreadsheet($lines, $uploadtreeTablename)
696  {
697  $request = $this->getRequest();
698  $itemId = intval($request->get('item'));
699  $path = Dir2Path($itemId, $uploadtreeTablename);
700  $fileName = $path[count($path) - 1]['ufile_name']."-".date("Ymd");
701 
702  $spreadsheet = new Spreadsheet();
703  $sheet = $spreadsheet->getActiveSheet();
704 
705  $headRow = array(
706  'A' => array(5, 'id', 'ID'),
707  'B' => array(30, 'path', 'Source Name or Path'),
708  'C' => array(20, 'name', 'OSS Name'),
709  'D' => array(10, 'version', 'OSS Version'),
710  'E' => array(20, 'scan results', 'Scan Results'),
711  'F' => array(20, 'concluded results', 'Concluded Results'),
712  'G' => array(20, 'download', 'Download Location'),
713  'H' => array(20, 'homepage', 'Homepage'),
714  'I' => array(30, 'copyright', 'Copyright Text'),
715  'J' => array(10, 'exclude', 'Exclude'),
716  'K' => array(30, 'comment', 'Comment')
717  );
718  $styleArray = [
719  'font' => [
720  'bold' => true,
721  'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE],
722  ],
723  'alignment' => [
724  'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
725  ],
726  'borders' => [
727  'allBorders' => [
728  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
729  'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK],
730  ]
731  ],
732  'fill' => [
733  'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
734  'startColor' => ['argb' => '002060'],
735  ],
736  ];
737  $sheet->getStyle('A1:J1')->applyFromArray($styleArray);
738  foreach ($headRow as $key => $val) {
739  $cellName = $key.'1';
740 
741  $sheet->getColumnDimension($key)->setWidth($val[0]);
742 
743  $sheet->setCellValue($cellName, $val[2]);
744  }
745 
746  $styleArray = [
747  'font' => [
748  'color' => ['argb' => '808080'],
749  ],
750  'borders' => [
751  'vertical' => [
752  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
753  'color' => ['argb' => 'B2B2B2'],
754  ]
755  ],
756  'fill' => [
757  'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
758  'startColor' => ['argb' => 'FFFFCC'],
759  ],
760  ];
761  $sheet->getStyle('A2:J2')->applyFromArray($styleArray);
762  $annotationRow = array(
763  'A' => array('id', '-'),
764  'B' => array('path', '[Name of the Source File or Path]'),
765  'C' => array('name', '[Name of the OSS used]'),
766  'D' => array('version', '[Version Number of the OSS]'),
767  'E' => array('scanResults', '[Scan results. Use SPDX Identifier : https://spdx.org/licenses/]'),
768  'F' => array('concludedResults', '[Concluded results. Use SPDX Identifier : https://spdx.org/licenses/]'),
769  'G' => array('download', '[Download URL or a specific location within a VCS for the OSS]'),
770  'H' => array('homepage', '[Web site that serves as the OSSs home page]'),
771  'I' => array('copyright', '[The copyright holders of the OSS. E.g. Copyright (c) 201X Copyright Holder]'),
772  'J' => array('exclude', '[If this OSS is not included in the final version, Check exclude]'),
773  'K' => array('comment','')
774  );
775  foreach ($annotationRow as $key => $val) {
776  $cellName = $key.'2';
777 
778  $sheet->setCellValue($cellName, $val[1]);
779  }
780 
781  $styleArray = [
782  'borders' => [
783  'allBorders' => [
784  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
785  'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK],
786  ]
787  ],
788  ];
789 
790  $id = 1;
791  foreach ($lines as $row) {
792  $rowNumber = $id + 2;
793  $range = 'A'.$rowNumber.':K'.$rowNumber;
794  $sheet->getStyle($range)->applyFromArray($styleArray);
795  $sheet->setCellValue('A'.$rowNumber, "$id");
796  $sheet->setCellValue('B'.$rowNumber, $row['filePath']);
797 
798  if ($row['agentFindings'] !== null) {
799  $scannedLicenses = implode(',', $row['agentFindings']);
800  $sheet->setCellValue('E'.$rowNumber, $scannedLicenses);
801  }
802  if ($row['conclusions'] !== null) {
803  $concludedLicenses = implode(',', $row['conclusions']);
804  $sheet->setCellValue('F'.$rowNumber, $concludedLicenses);
805  }
806  $id++;
807  }
808 
809  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
810  header('Content-Disposition: attachment; filename="'.$fileName.'.xlsx"');
811  header('Cache-Control: max-age=0');
812 
813  $writer = new Xlsx($spreadsheet);
814  ob_end_clean();
815  $writer->save('php://output');
816  exit();
817  }
818 
824  private function reduceCopyrightLines($lines)
825  {
826  $reducedLines = array();
827  foreach ($lines as $line) {
828  foreach ($line as $copyright) {
829  $reducedLines[] = $copyright;
830  }
831  }
832  return $reducedLines;
833  }
834 }
835 
836 $NewPlugin = new UIExportList();
837 $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")
updateCopyrightList(&$list, $newCopyrights, $NomostListNum, $uploadTreeTableName, $key)
setDelimiter($delimiter=',')
getAgentPksFromRequest($upload_pk)
consolidateConclusions($conclusions)
Output()
This function returns the scheduler status.
consolidateFindingsPerDirectory($lines)
printCSV($lines, $uploadtreeTablename, $copyright=false)
RegisterMenus()
Customize submenus.
reduceCopyrightLines($lines)
removeIfKeyExists(&$lines, $key)
removeCopyrightWithLicense(&$lines, $itemTreeBounds, $agentList, $exclude)
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