FOSSology  4.4.0
Open Source License Compliance by Open Source Software
nomos-diff.php
Go to the documentation of this file.
1 <?php
4 /*
5  SPDX-FileCopyrightText: © 2010-2013 Hewlett-Packard Development Company, L.P.
6 
7  SPDX-License-Identifier: GPL-2.0-only
8 */
14 define("TITLE_UI_NOMOS_DIFF", _("Compare License Browser"));
15 
20 class ui_nomos_diff extends FO_Plugin
21 {
22 
27  var $Name = "nomosdiff";
28 
33  var $Title = TITLE_UI_NOMOS_DIFF;
34 
39  var $Version = "1.0";
40 
41  // var $MenuList= "Jobs::License";
46  var $Dependency = array(
47  "browse",
48  "view"
49  );
50 
56 
61  var $LoginFlag = 0;
62 
67  var $ColumnSeparatorStyleL = "style='border:solid 0 #006600; border-left-width:2px;padding-left:1em'";
68 
73  function Install()
74  {
75  global $PG_CONN;
76  if (empty($PG_CONN)) {
77  return (1);
78  } /* No DB */
79 
80  return (0);
81  }
82 
83  // Install()
84 
89  function RegisterMenus()
90  {
91  /*
92  * at this stage you have to call this plugin with a direct URL
93  * that displays both trees to compare.
94  */
95  return 0;
96  }
97 
98  // RegisterMenus()
99 
111  function Initialize()
112  {
113  global $_GET;
114 
115  if ($this->State != PLUGIN_STATE_INVALID) {
116  return (1);
117  } // don't re-run
118  if ($this->Name !== "") { // Name must be defined
119  global $Plugins;
120  $this->State = PLUGIN_STATE_VALID;
121  array_push($Plugins, $this);
122  }
123  return ($this->State == PLUGIN_STATE_VALID);
124  }
125 
126  // Initialize()
127 
134  function GetTreeInfo($Uploadtree_pk)
135  {
136  $TreeInfo = GetSingleRec("uploadtree",
137  "WHERE uploadtree_pk = $Uploadtree_pk");
138  $TreeInfo['agent_pk'] = LatestAgentpk($TreeInfo['upload_fk'], "nomos_ars");
139 
140  // Get the uploadtree table
141  $UploadRec = GetSingleRec("upload", "where upload_pk=$TreeInfo[upload_fk]");
142  $TreeInfo['uploadtree_tablename'] = $UploadRec['uploadtree_tablename'];
143  return $TreeInfo;
144  }
145 
152  function UploadHist($Uploadtree_pk, $TreeInfo)
153  {
154  global $PG_CONN;
155 
156  $VLic = '';
157  $lft = $TreeInfo['lft'];
158  $rgt = $TreeInfo['rgt'];
159  $upload_pk = $TreeInfo['upload_fk'];
160  $agent_pk = $TreeInfo['agent_pk'];
161 
162  /* Get the counts for each license under this UploadtreePk */
163  $sql = "SELECT rf_shortname as licname,
164  count(rf_shortname) as liccount, rf_shortname
165  from ONLY license_ref,license_file,
166  (SELECT distinct(pfile_fk) as PF from $TreeInfo[uploadtree_tablename]
167  where upload_fk=$upload_pk
168  and {$TreeInfo['uploadtree_tablename']}.lft BETWEEN $lft and $rgt) as SS
169  where PF=pfile_fk and agent_fk=$agent_pk and rf_fk=rf_pk
170  group by rf_shortname
171  order by liccount desc";
172  $result = pg_query($PG_CONN, $sql);
173  DBCheckResult($result, $sql, __FILE__, __LINE__);
174 
175  /* Write license histogram to $VLic */
176  $LicCount = 0;
177  $UniqueLicCount = 0;
178  $NoLicFound = 0;
179  $VLic .= "<table border=1 id='lichistogram'>\n";
180 
181  $text = _("Count");
182  $VLic .= "<tr><th >$text</th>";
183 
184  $text = _("Files");
185  $VLic .= "<th >$text</th>";
186 
187  $text = _("License Name");
188  $VLic .= "<th align=left>$text</th></tr>\n";
189 
190  while ($row = pg_fetch_assoc($result)) {
191  $UniqueLicCount ++;
192  $LicCount += $row['liccount'];
193 
194  /* Count */
195  $VLic .= "<tr><td align='right'>$row[liccount]</td>";
196 
197  /* Show */
198  $ShowTitle = _("Click Show to list files with this license.");
199  $VLic .= "<td align='center'><a href='";
200  $VLic .= Traceback_uri();
201 
202  $text = _("Show");
203  $VLic .= "?mod=license_list_files&napk=$agent_pk&item=$Uploadtree_pk&lic=" .
204  urlencode($row['rf_shortname']) . "' title='$ShowTitle'>$text</a></td>";
205 
206  /* License name */
207  $VLic .= "<td align='left'>";
208  $rf_shortname = rawurlencode($row['rf_shortname']);
209  $VLic .= "<a id='$rf_shortname' onclick='FileColor_Get(\"" .
210  Traceback_uri() .
211  "?mod=ajax_filelic&napk=$agent_pk&item=$Uploadtree_pk&lic=$rf_shortname\")'";
212  $VLic .= ">$row[licname] </a>";
213  $VLic .= "</td>";
214  $VLic .= "</tr>\n";
215  if ($row['licname'] == "No_license_found") {
216  $NoLicFound = $row['liccount'];
217  }
218  }
219  pg_free_result($result);
220  $VLic .= "</table>\n";
221  $VLic .= "<p>\n";
222 
223  return ($VLic);
224  }
225 
226  // UploadHist()
227 
234  function ChildElt($Child, $agent_pk, $OtherChild)
235  {
236  $UniqueTagArray = array();
237  $licstr = $Child['licstr'];
238 
239  /*
240  * If both $Child and $OtherChild are specified,
241  * reassemble licstr and highlight the differences
242  */
243  if ($Child and $OtherChild) {
244  $licstr = "";
245  $DiffLicStyle = "style='background-color:#ffa8a8'"; // mid red pastel
246  foreach ($Child['licarray'] as $rf_pk => $rf_shortname) {
247  if (! empty($licstr)) {
248  $licstr .= ", ";
249  }
250  if (@$OtherChild['licarray'][$rf_pk]) {
251  /* license is in both $Child and $OtherChild */
252  $licstr .= $rf_shortname;
253  } else {
254  /* license is missing from $OtherChild */
255  $licstr .= "<span $DiffLicStyle>$rf_shortname</span>";
256  }
257  }
258  }
259 
260  $ColStr = "<td id='$Child[uploadtree_pk]' align='left'>";
261  $ColStr .= "$Child[linkurl]";
262  /* show licenses under file name */
263  $ColStr .= "<br>";
264  $ColStr .= "<span style='position:relative;left:1em'>";
265  $ColStr .= $licstr;
266  $ColStr .= "</span>";
267  $ColStr .= "</td>";
268 
269  /* display item links */
270  $ColStr .= "<td valign='top'>";
271  $uploadtree_tablename = GetUploadtreeTableName($Child['upload_fk']);
272  $ColStr .= FileListLinks($Child['upload_fk'], $Child['uploadtree_pk'],
273  $agent_pk, $Child['pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
274  $ColStr .= "</td>";
275  return $ColStr;
276  }
277 
278  /* ChildElt() */
279 
289  function ItemComparisonRows($Master, $agent_pk1, $agent_pk2)
290  {
291  $TableStr = "";
292  $RowStyle1 = "style='background-color:#ecfaff'"; // pale blue
293  $RowStyle2 = "style='background-color:#ffffe3'"; // pale yellow
294  $RowNum = 0;
295 
296  foreach ($Master as $key => $Pair) {
297  $RowStyle = (++ $RowNum % 2) ? $RowStyle1 : $RowStyle2;
298  $TableStr .= "<tr $RowStyle>";
299 
300  $Child1 = GetArrayVal("1", $Pair);
301  $Child2 = GetArrayVal("2", $Pair);
302  if (empty($Child1)) {
303  $TableStr .= "<td></td><td></td>";
304  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
305  $TableStr .= $this->ChildElt($Child2, $agent_pk2, $Child1);
306  } else if (empty($Child2)) {
307  $TableStr .= $this->ChildElt($Child1, $agent_pk1, $Child2);
308  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
309  $TableStr .= "<td></td><td></td>";
310  } else if (! empty($Child1) and ! empty($Child2)) {
311  $TableStr .= $this->ChildElt($Child1, $agent_pk1, $Child2);
312  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
313  $TableStr .= $this->ChildElt($Child2, $agent_pk2, $Child1);
314  }
315 
316  $TableStr .= "</tr>";
317  }
318 
319  return ($TableStr);
320  }
321 
322  // ItemComparisonRows()
323 
327  function AddLicStr($TreeInfo, &$Children)
328  {
329  if (! is_array($Children)) {
330  return;
331  }
332  $agent_pk = $TreeInfo['agent_pk'];
333  foreach ($Children as &$Child) {
337  $Child['licarray'] = GetFileLicenses($agent_pk, 0, $Child['uploadtree_pk']);
338  $Child['licstr'] = implode(", ", $Child['licarray']);
339  }
340  }
341 
347  function filter_samehash(&$Master)
348  {
349  if (! is_array($Master)) {
350  return;
351  }
352 
353  foreach ($Master as $Key => &$Pair) {
354  if (empty($Pair[1]) or empty($Pair[2])) {
355  continue;
356  }
357  if (empty($Pair[1]['pfile_fk'])) {
358  continue;
359  }
360  if (empty($Pair[2]['pfile_fk'])) {
361  continue;
362  }
363 
364  if ($Pair[1]['pfile_fk'] == $Pair[2]['pfile_fk']) {
365  unset($Master[$Key]);
366  }
367  }
368  return;
369  }
370 
371  /* End of samehash */
372 
376  function filter_samelic(&$Master)
377  {
378  foreach ($Master as $Key => &$Pair) {
379  if (empty($Pair[1]) or empty($Pair[2])) {
380  continue;
381  }
382  if (($Pair[1]['ufile_name'] == $Pair[2]['ufile_name']) &&
383  ($Pair[1]['licstr'] == $Pair[2]['licstr'])) {
384  unset($Master[$Key]);
385  }
386  }
387  return;
388  }
389 
390  /* End of samelic */
391 
395  function filter_samelicfuzzy(&$Master)
396  {
397  foreach ($Master as $Key => &$Pair) {
398  if (empty($Pair[1]) or empty($Pair[2])) {
399  continue;
400  }
401  if (($Pair[1]['fuzzyname'] == $Pair[2]['fuzzyname']) &&
402  ($Pair[1]['licstr'] == $Pair[2]['licstr'])) {
403  unset($Master[$Key]);
404  }
405  }
406  return;
407  }
408 
409  /* End of samelic */
410 
418  function filter_nolics(&$Master)
419  {
420  $NoLicStr = "No_license_found";
421 
422  foreach ($Master as $Key => &$Pair) {
423  $Pair1 = GetArrayVal("1", $Pair);
424  $Pair2 = GetArrayVal("2", $Pair);
425 
426  if (empty($Pair1)) {
427  if ($Pair2['licstr'] == $NoLicStr) {
428  unset($Master[$Key]);
429  } else {
430  continue;
431  }
432  } else if (empty($Pair2)) {
433  if ($Pair1['licstr'] == $NoLicStr) {
434  unset($Master[$Key]);
435  } else {
436  continue;
437  }
438  } else if (($Pair1['licstr'] == $NoLicStr) and
439  ($Pair2['licstr'] == $NoLicStr)) {
440  unset($Master[$Key]);
441  }
442  }
443  return;
444  }
445 
446  /* End of nolics */
447 
455  function FilterChildren($filter, &$Master)
456  {
457  switch ($filter) {
458  case 'samehash':
459  $this->filter_samehash($Master);
460  break;
461  case 'samelic':
462  $this->filter_samehash($Master);
463  $this->filter_samelic($Master);
464  break;
465  case 'samelicfuzzy':
466  $this->filter_samehash($Master);
467  $this->filter_samelicfuzzy($Master);
468  break;
469  case 'nolics':
470  $this->filter_samehash($Master);
471  $this->filter_nolics($Master);
472  $this->filter_samelicfuzzy($Master);
473  break;
474  default:
475  break;
476  }
477  }
478 
482  function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1,
483  $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2)
484  {
485  /* Initialize */
486  $FreezeText = _("Freeze Path");
487  $FrozenText = _("Frozen, Click to unfreeze");
488  $OutBuf = '';
489 
490  /******* javascript functions ********/
491  $OutBuf .= "\n<script language='javascript'>\n";
492  /* function to replace this page specifying a new filter parameter */
493  $OutBuf .= "function ChangeFilter(selectObj, utpk1, utpk2){";
494  $OutBuf .= " var selectidx = selectObj.selectedIndex;";
495  $OutBuf .= " var filter = selectObj.options[selectidx].value;";
496  $OutBuf .= ' window.location.assign("?mod=' . $this->Name .
497  '&item1="+utpk1+"&item2="+utpk2+"&filter=" + filter); ';
498  $OutBuf .= "}\n";
499 
500  /*
501  * Freeze function (path list in banner)
502  * FreezeColNo is the ID of the column to freeze: 1 or 2
503  * Toggle Freeze button label: Freeze Path <-> Unfreeze Path
504  * Toggle Freeze button background color: white to light blue
505  * Toggle which paths are frozen: if path1 freezes, then unfreeze path2.
506  * Rewrite urls: eg &item1 -> &Fitem1
507  */
508  $OutBuf .= "function Freeze(FreezeColNo) {";
509  $OutBuf .= "var FreezeElt1 = document.getElementById('Freeze1');";
510  $OutBuf .= "var FreezeElt2 = document.getElementById('Freeze2');";
511  $OutBuf .= "var AddFreezeArg = 1; "; // 1 to add &freeze=, 0 to remove
512  // &freeze= from url
513  $OutBuf .= "var old_uploadtree_pk;\n";
514 
515  /* change the freeze labels to denote their new status */
516  $OutBuf .= "if (FreezeColNo == '1')";
517  $OutBuf .= "{";
518  $OutBuf .= "if (FreezeElt1.innerHTML == '$FrozenText') ";
519  $OutBuf .= "{";
520  $OutBuf .= "FreezeElt1.innerHTML = '$FreezeText';";
521  $OutBuf .= "FreezeElt1.style.backgroundColor = 'white'; ";
522  $OutBuf .= "AddFreezeArg = 0;";
523  $OutBuf .= "}";
524  $OutBuf .= "else { ";
525  $OutBuf .= "FreezeElt1.innerHTML = '$FrozenText'; ";
526  $OutBuf .= "FreezeElt1.style.backgroundColor = '#EAF7FB'; ";
527  $OutBuf .= "FreezeElt2.innerHTML = '$FreezeText';";
528  $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
529  $OutBuf .= "old_uploadtree_pk = $in_uploadtree_pk1;";
530  $OutBuf .= "}";
531  $OutBuf .= "}";
532  $OutBuf .= "else {";
533  $OutBuf .= "if (FreezeElt2.innerHTML == '$FrozenText') ";
534  $OutBuf .= "{";
535  $OutBuf .= "FreezeElt2.innerHTML = '$FreezeText';";
536  $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
537  $OutBuf .= "AddFreezeArg = 0;";
538  $OutBuf .= "}";
539  $OutBuf .= "else {";
540  $OutBuf .= "FreezeElt1.innerHTML = '$FreezeText';";
541  $OutBuf .= "FreezeElt1.style.backgroundColor = 'white';";
542  $OutBuf .= "FreezeElt2.innerHTML = '$FrozenText';";
543  $OutBuf .= "FreezeElt2.style.backgroundColor = '#EAF7FB';";
544  $OutBuf .= "old_uploadtree_pk = $in_uploadtree_pk2;";
545  $OutBuf .= "}";
546  $OutBuf .= "}";
547 
548  /* Alter the url to add or remove freeze={column number} */
549  $OutBuf .= "var i=0;\n";
550  $OutBuf .= "var linkid;\n";
551  $OutBuf .= "var linkelt;\n";
552  $OutBuf .= "var FreezeIdx;\n";
553  $OutBuf .= "var BaseURL;\n";
554  $OutBuf .= "var numlinks = document.links.length;\n";
555  $OutBuf .= "for (i=0; i < numlinks; i++)\n";
556  $OutBuf .= "{";
557  $OutBuf .= "linkelt = document.links[i];\n";
558  // freeze is the last url arg, so trim it off if it exists
559  $OutBuf .= "FreezeIdx = linkelt.href.indexOf('&freeze');\n";
560  $OutBuf .= "if (FreezeIdx > 0) \n";
561  $OutBuf .= "BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
562  $OutBuf .= "else ";
563  $OutBuf .= "BaseURL = linkelt.href; \n";
564  $OutBuf .= "if (AddFreezeArg == 1) \n ";
565  $OutBuf .= "linkelt.href = BaseURL + '&freeze=' + FreezeColNo + '&itemf=' + old_uploadtree_pk;";
566  $OutBuf .= "else \n";
567  $OutBuf .= "linkelt.href = BaseURL;";
568  $OutBuf .= "}\n";
569  $OutBuf .= "}\n";
570  $OutBuf .= "</script>\n";
571  /******* END javascript functions ********/
572 
573  /* Select list for filters */
574  $SelectFilter = "<select name='diff_filter' id='diff_filter' onchange='ChangeFilter(this,$uploadtree_pk1, $uploadtree_pk2)'>";
575  $Selected = ($filter == 'none') ? "selected" : "";
576  $SelectFilter .= "<option $Selected value='none'>0. Remove nothing";
577  $Selected = ($filter == 'samehash') ? "selected" : "";
578  $SelectFilter .= "<option $Selected value='samehash'>1. Remove duplicate (same hash) files";
579  $Selected = ($filter == 'samelic') ? "selected" : "";
580  $SelectFilter .= "<option $Selected value='samelic'>2. Remove duplicate files (different hash) with unchanged licenses";
581  $Selected = ($filter == 'samelicfuzzy') ? "selected" : "";
582  $SelectFilter .= "<option $Selected value='samelicfuzzy'>2b. Same as 2 but fuzzy match file names";
583  $Selected = ($filter == 'nolics') ? "selected" : "";
584  $SelectFilter .= "<option $Selected value='nolics'>3. Same as 2b. but also remove files with no license";
585  $SelectFilter .= "</select>";
586 
587  $StyleRt = "style='float:right'";
588  $OutBuf .= "<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
589 
590  /* Switch to bucket diff view */
591  $text = _("Switch to bucket view");
592  $BucketURL = Traceback_uri();
593  $BucketURL .= "?mod=bucketsdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
594  $OutBuf .= "<a href='$BucketURL' $StyleRt > $text </a> ";
595 
596  // $TableStyle = "style='border-style:collapse;border:1px solid black'";
597  $TableStyle = "";
598  $OutBuf .= "<table border=0 id='dirlist' $TableStyle>";
599 
600  /* Select filter pulldown */
601  $OutBuf .= "<tr><td colspan=5 align='center'>Filter: $SelectFilter<br>&nbsp;</td></tr>";
602 
603  /* File path */
604  $OutBuf .= "<tr>";
605  $Path1 = Dir2Path($uploadtree_pk1, $TreeInfo1['uploadtree_tablename']);
606  $Path2 = Dir2Path($uploadtree_pk2, $TreeInfo2['uploadtree_tablename']);
607  $OutBuf .= "<td colspan=2>";
608  $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 1, $this);
609  $OutBuf .= "</td>";
610  $OutBuf .= "<td $this->ColumnSeparatorStyleL colspan=3>";
611  $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 2, $this);
612  $OutBuf .= "</td></tr>";
613 
614  /* File comparison table */
615  $OutBuf .= $this->ItemComparisonRows($Master, $TreeInfo1['agent_pk'],
616  $TreeInfo2['agent_pk']);
617 
618  /* Separator row */
619  $ColumnSeparatorStyleTop = "style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
620  $OutBuf .= "<tr>";
621  $OutBuf .= "<td colspan=5 $ColumnSeparatorStyleTop>";
622  $OutBuf .= "<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
623  $OutBuf .= "</a>";
624  $OutBuf .= "</tr>";
625 
626  /* License histogram */
627  $OutBuf .= "<tr>";
628  $Tree1Hist = $this->UploadHist($uploadtree_pk1, $TreeInfo1);
629  $OutBuf .= "<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
630  $OutBuf .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
631  $Tree2Hist = $this->UploadHist($uploadtree_pk2, $TreeInfo2);
632  $OutBuf .= "<td colspan=2 valign='top' align='center'>$Tree2Hist</td>";
633  $OutBuf .= "</tr></table>\n";
634 
635  $OutBuf .= "<a href='#flist' style='float:right'> Jump to top </a><p>";
636 
637  return $OutBuf;
638  }
639 
648  function Output()
649  {
650  if ($this->State != PLUGIN_STATE_READY) {
651  return (0);
652  }
653  $V = "";
654 
655  $uTime = microtime(true);
656  /* */
657  $updcache = GetParm("updcache", PARM_INTEGER);
658 
659  /*
660  * Remove "updcache" from the GET args.
661  * This way all the url's based on the input args won't be
662  * polluted with updcache
663  * Use Traceback_parm_keep to ensure that all parameters are in order
664  */
665  $CacheKey = "?mod=" . $this->Name .
667  array(
668  "item1",
669  "item2",
670  "filter",
671  "col",
672  "freeze",
673  "itemf"
674  ));
675  if ($updcache) {
676  $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/", "",
677  $_SERVER['REQUEST_URI']);
678  unset($_GET['updcache']);
679  $V = ReportCachePurgeByKey($CacheKey);
680  } else {
681  $V = ReportCacheGet($CacheKey);
682  }
683 
684  if (empty($V)) { // no cache exists
685  $filter = GetParm("filter", PARM_STRING);
686  if (empty($filter)) {
687  $filter = "samehash";
688  }
689  $FreezeCol = GetParm("freeze", PARM_INTEGER); // which column to freeze? 1
690  // or 2 or null
691  $ClickedCol = GetParm("col", PARM_INTEGER); // which column was clicked
692  // on? 1 or 2 or null
693  $ItemFrozen = GetParm("itemf", PARM_INTEGER); // frozen item or null
694  $in_uploadtree_pk1 = GetParm("item1", PARM_INTEGER);
695  $in_uploadtree_pk2 = GetParm("item2", PARM_INTEGER);
696 
697  if (empty($in_uploadtree_pk1) or empty($in_uploadtree_pk2)) {
698  Fatal("Bad input parameters. Both item1 and item2 must be specified.",
699  __FILE__, __LINE__);
700  }
701 
702  /*
703  * If you click on a item in a frozen column, then you are a dope so
704  * ignore $ItemFrozen
705  */
706  if ($FreezeCol == $ClickedCol) {
707  $ItemFrozen = 0;
708  $FreezeCol = 0;
709  }
710 
711  /* @var UploadDao $uploadDao */
712  $uploadDao = $GLOBALS['container']->get('dao.upload');
713  /* Check item1 upload permissions */
714  $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1);
715  if (! $uploadDao->isAccessible($Item1Row['upload_fk'], Auth::getGroupId())) {
716  $text = _("Permission Denied");
717  return "<h2>$text item 1</h2>";
718  }
719 
720  /* Check item2 upload permissions */
721  $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2);
722  if (! $uploadDao->isAccessible($Item2Row['upload_fk'], Auth::getGroupId())) {
723  $text = _("Permission Denied");
724  return "<h2>$text item 2</h2>";
725  }
726 
727  $uploadtree_pk1 = $in_uploadtree_pk1;
728  $uploadtree_pk2 = $in_uploadtree_pk2;
729 
730  // if someone is going to freeze a column, let them manually select in the
731  // other column (don't try to do matching)
732  if ($FreezeCol == 1) {
733  $uploadtree_pk1 = $ItemFrozen;
734  } else if ($FreezeCol == 2) {
735  $uploadtree_pk2 = $ItemFrozen;
736  }
737 
738  $newURL = Traceback_dir() . "?mod=" . $this->Name .
739  "&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
740  if (! empty($filter)) {
741  $newURL .= "&filter=$filter";
742  }
743 
744  // rewrite page with new uploadtree_pks */
745  if (($uploadtree_pk1 != $in_uploadtree_pk1) ||
746  ($uploadtree_pk2 != $in_uploadtree_pk2)) {
747  print
748  <<< JSOUT
749 <script type="text/javascript">
750  window.location.assign('$newURL');
751 </script>
752 JSOUT;
753  }
754 
755  $TreeInfo1 = $this->GetTreeInfo($uploadtree_pk1);
756  $TreeInfo2 = $this->GetTreeInfo($uploadtree_pk2);
757  $ErrText = _("No license data for");
758  $ErrText2 = _("Use Jobs > Agents to schedule a license scan.");
759  $ErrMsg = '';
760  if ($TreeInfo1['agent_pk'] == 0) {
761  $ErrMsg = "$ErrText $TreeInfo1[ufile_name].<br>$ErrText2<p>";
762  } else if ($TreeInfo2['agent_pk'] == 0) {
763  $ErrMsg = "$ErrText $TreeInfo2[ufile_name].<br>$ErrText2<p>";
764  } else {
765  /* Get list of children */
766  $Children1 = GetNonArtifactChildren($uploadtree_pk1);
767  $Children2 = GetNonArtifactChildren($uploadtree_pk2);
768 
769  /* Add fuzzyname to children */
770  FuzzyName($Children1); // add fuzzyname to children
771  FuzzyName($Children2); // add fuzzyname to children
772 
773  /* add element licstr to children */
774  $this->AddLicStr($TreeInfo1, $Children1);
775  $this->AddLicStr($TreeInfo2, $Children2);
776 
777  /* Master array of children, aligned. */
778  $Master = MakeMaster($Children1, $Children2);
779 
780  /* add linkurl to children */
781  FileList($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'],
782  $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
783 
784  /* Apply filter */
785  $this->FilterChildren($filter, $Master);
786  }
787 
788  switch ($this->OutputType) {
789  case "XML":
790  break;
791  case "HTML":
792  if ($ErrMsg) {
793  $V .= $ErrMsg;
794  } else {
795  $V .= $this->HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2,
796  $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1,
797  $TreeInfo2);
798  }
799  break;
800  case "Text":
801  break;
802  default:
803  }
804  $Cached = false;
805  } else {
806  $Cached = true;
807  }
808 
809  if (! $this->OutputToStdout) {
810  return ($V);
811  }
812  print "$V";
813  $Time = microtime(true) - $uTime; // convert usecs to secs
814  $text = _("Elapsed time: %.2f seconds");
815  printf("<small>$text</small>", $Time);
816 
817  if ($Cached) {
818  $text = _("cached");
819  $text1 = _("Update");
820  echo " <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
821  } else {
822  // Cache Report if this took longer than 1/2 second
823  if ($Time > 0.5) {
824  ReportCachePut($CacheKey, $V);
825  }
826  }
827  /* */
828  return;
829  } /* End Output() */
830 }
831 
832 $NewPlugin = new ui_nomos_diff();
833 $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
Definition: state.hpp:16
Compare License Browser, list license histogram.
Definition: nomos-diff.php:21
Install()
Create and configure database tables.
Definition: nomos-diff.php:73
ChildElt($Child, $agent_pk, $OtherChild)
get the entire <td> ... </td> for $Child file listing table
Definition: nomos-diff.php:234
UploadHist($Uploadtree_pk, $TreeInfo)
get history info for the directory BY LICENSE.
Definition: nomos-diff.php:152
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2)
HTML output, returns HTML as string.
Definition: nomos-diff.php:482
filter_nolics(&$Master)
removes pairs of "No_license_found"
Definition: nomos-diff.php:418
filter_samelicfuzzy(&$Master)
removes files that have the same fuzzyname, and same license list.
Definition: nomos-diff.php:395
filter_samelic(&$Master)
removes files that have the same name and license list.
Definition: nomos-diff.php:376
AddLicStr($TreeInfo, &$Children)
Add license array to Children array.
Definition: nomos-diff.php:327
FilterChildren($filter, &$Master)
filter children through same license, same hash, no license, same fuzzy license
Definition: nomos-diff.php:455
filter_samehash(&$Master)
removes identical files
Definition: nomos-diff.php:347
Initialize()
This is called before the plugin is used.
Definition: nomos-diff.php:111
ItemComparisonRows($Master, $agent_pk1, $agent_pk2)
get a string with the html table rows comparing the two file lists.
Definition: nomos-diff.php:289
Output()
generate output information
Definition: nomos-diff.php:648
RegisterMenus()
Customize submenus.
Definition: nomos-diff.php:89
GetTreeInfo($Uploadtree_pk)
get an array with uploadtree record and agent_pk
Definition: nomos-diff.php:134
LatestAgentpk($upload_pk, $arsTableName, $arsSuccess=false)
Given an upload_pk, find the latest enabled agent_pk with results.
ReportCacheGet($CacheKey)
This function is used by Output() to see if the requested report is in the report cache.
ReportCachePut($CacheKey, $CacheValue)
This function is used to write a record to the report cache. If the record already exists,...
ReportCachePurgeByKey($CacheKey)
Purge from the report cache the record with $CacheKey.
FileList(&$Master, $agent_pk1, $agent_pk2, $filter, $plugin, $uploadtree_pk1, $uploadtree_pk2)
Adds the element linkurl to the $Master elements.
Dir2BrowseDiff($Path1, $Path2, $filter, $Column, $plugin)
Return a string which is a linked path to the file.
MakeMaster($Children1, $Children2)
Generate the master array with aligned children.
FuzzyName(&$Children)
Add fuzzyname and fuzzynameext to $Children.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
GetSingleRec($Table, $Where="")
Retrieve a single database record.
Definition: common-db.php:91
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
Definition: common-dir.php:222
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
GetFileLicenses($agent, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree', $duplicate="")
get all the licenses for a single file or uploadtree
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
const PARM_INTEGER
Definition: common-parm.php:14
Traceback_dir()
Get the directory of the URI without query.
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.
GetArrayVal($Key, $Arr)
Get the value from a array(map)
Definition: common-ui.php:157
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.
Definition: common-ui.php:66
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