FOSSology  4.4.0
Open Source License Compliance by Open Source Software
bucket-diff.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011-2014 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
11 
17 {
18  var $ColumnSeparatorStyleL = "style='border:solid 0 #006600; border-left-width:2px;padding-left:1em'";
19  var $threshold = 150;
21  function __construct()
22  {
23  $this->Name = "bucketsdiff";
24  $this->Title = _("Compare Buckets Browser");
25  $this->Dependency = array("browse","view");
26  $this->DBaccess = PLUGIN_DB_READ;
27  $this->LoginFlag = 0;
28  parent::__construct();
29  }
30 
35  function Install()
36  {
37  global $PG_CONN;
38  if (empty($PG_CONN)) { return(1); } /* No DB */
39 
40  return(0);
41  } // Install()
42 
43 
54  function Initialize()
55  {
56  global $_GET;
57 
58  if ($this->State != PLUGIN_STATE_INVALID) { return(1); } // don't re-run
59  if ($this->Name !== "") // Name must be defined
60  {
61  global $Plugins;
62  $this->State=PLUGIN_STATE_VALID;
63  $Plugins[] = $this;
64  }
65 
66  return($this->State == PLUGIN_STATE_VALID);
67  } // Initialize()
68 
78  function GetTreeInfo($Uploadtree_pk)
79  {
80  global $PG_CONN;
81 
82  $TreeInfo = GetSingleRec("uploadtree", "WHERE uploadtree_pk = $Uploadtree_pk");
83  $TreeInfo['agent_pk'] = LatestAgentpk($TreeInfo['upload_fk'], "nomos_ars");
84 
85  /* Get the ars_pk of the scan to display, also the select list */
86  $ars_pk = GetArrayVal("ars", $_GET);
87  $BucketSelect = SelectBucketDataset($TreeInfo['upload_fk'], $ars_pk, "selectbdata",
88  "onchange=\"addArsGo('newds','selectbdata');\"");
89  $TreeInfo['ars_pk'] = $ars_pk;
90  if ($ars_pk == 0)
91  {
92  /* No bucket data for this upload */
93  return $BucketSelect; // $BucketSelect is error message
94  }
95 
96  /* Get scan keys */
97  $where = "where ars_pk=$ars_pk";
98  $row = GetSingleRec("bucket_ars", $where);
99  if (empty($row)) Fatal("No bucket data $where", __FILE__, __LINE__);
100  $TreeInfo['bucketagent_pk'] = $row["agent_fk"];
101  $TreeInfo['nomosagent_pk'] = $row["nomosagent_fk"];
102  $TreeInfo['bucketpool_pk'] = $row["bucketpool_fk"];
103  unset($row);
104 
105  return $TreeInfo;
106  }
107 
108 
116  function UploadHist($Uploadtree_pk, $TreeInfo, $BucketDefArray)
117  {
118  global $PG_CONN;
119 
120  $HistStr = '';
121  $lft = $TreeInfo['lft'];
122  $rgt = $TreeInfo['rgt'];
123  $upload_pk = $TreeInfo['upload_fk'];
124  $agent_pk = $TreeInfo['agent_pk'];
125  $bucketagent_pk = $TreeInfo['bucketagent_pk'];
126  $nomosagent_pk = $TreeInfo['nomosagent_pk'];
127  $bucketpool_pk = $TreeInfo['bucketpool_pk'];
128 
129  /*select all the buckets for entire tree for this bucketpool */
130  $sql = "SELECT distinct(bucket_fk) as bucket_pk,
131  count(bucket_fk) as bucketcount, bucket_reportorder
132  from bucket_file, bucket_def,
133  (SELECT distinct(pfile_fk) as PF from uploadtree
134  where upload_fk=$upload_pk
135  and ((ufile_mode & (1<<28))=0)
136  and uploadtree.lft BETWEEN $lft and $rgt) as SS
137  where PF=pfile_fk and agent_fk=$bucketagent_pk
138  and bucket_file.nomosagent_fk=$nomosagent_pk
139  and bucket_pk=bucket_fk
140  and bucketpool_fk=$bucketpool_pk
141  group by bucket_fk,bucket_reportorder
142  order by bucket_reportorder asc";
143  $result = pg_query($PG_CONN, $sql);
144  DBCheckResult($result, $sql, __FILE__, __LINE__);
145  $historows = pg_fetch_all($result);
146  pg_free_result($result);
147 
148 if (false)
149 {
150  /* Show dataset list */
151  if (!empty($BucketSelect))
152  {
153  $action = Traceback_uri() . "?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk";
154 
155  $HistStr .= "<script type='text/javascript'>
156 function addArsGo(formid, selectid )
157 {
158 var selectobj = document.getElementById(selectid);
159 var ars_pk = selectobj.options[selectobj.selectedIndex].value;
160 document.getElementById(formid).action='$action'+'&ars='+ars_pk;
161 document.getElementById(formid).submit();
162 return;
163 }
164 </script>";
165 
166  /* form to select new dataset (ars_pk) */
167  $HistStr .= "<form action='$action' id='newds' method='POST'>\n";
168  $HistStr .= $BucketSelect;
169  $HistStr .= "</form>";
170  }
171 }
172 
173  /* any rows? */
174  if (count($historows) == 0) return $HistStr;
175 
176  $sql = "select bucketpool_name from bucketpool where bucketpool_pk=$bucketpool_pk";
177  $result = pg_query($PG_CONN, $sql);
178  DBCheckResult($result, $sql, __FILE__, __LINE__);
179  $row = pg_fetch_assoc($result);
180  $bucketpool_name = $row['bucketpool_name'];
181  pg_free_result($result);
182 
183  /* Write bucket histogram to $HistStr */
184  $TotalCount = 0;
185  $NoLicFound = 0;
186  $HistStr .= "<table border=1 id='histogram'>\n";
187 
188  $text = _("Count");
189  $HistStr .= "<tr><th >$text</th>";
190 
191  $text = _("Files");
192  $HistStr .= "<th >$text</th>";
193 
194  $text = _("Bucket");
195  $HistStr .= "<th align=left>$text</th></tr>\n";
196 
197  if(empty($historows))
198  {
199  return;
200  }
201  foreach ($historows as $row)
202  {
203  $TotalCount += $row['bucketcount'];
204  $bucket_pk = $row['bucket_pk'];
205  $bucketcount = $row['bucketcount'];
206  $bucket_name = $BucketDefArray[$bucket_pk]['bucket_name'];
207  $bucket_color = $BucketDefArray[$bucket_pk]['bucket_color'];
208 
209  /* Count */
210  $HistStr .= "<tr><td align='right' style='background-color:$bucket_color'>$row[bucketcount]</td>";
211 
212  /* Show */
213  $ShowTitle = _("Click Show to list files with this license.");
214  $HistStr .= "<td align='center'><a href='";
215  $HistStr .= Traceback_uri();
216 
217  $text = _("Show");
218  $HistStr .= "?mod=list_bucket_files&bapk=$bucketagent_pk&item=$Uploadtree_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk" . "'>$text</a></td>";
219 
220  /* Bucket name */
221  $HistStr .= "<td align='left'>";
222  $HistStr .= "<a id='$bucket_pk' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filebucket&bapk=$bucketagent_pk&item=$Uploadtree_pk&bucket_pk=$bucket_pk\")'";
223  $HistStr .= ">$bucket_name </a>";
224  $HistStr .= "</td>";
225  $HistStr .= "</tr>\n";
226  }
227  $HistStr .= "</table>\n";
228  $HistStr .= "<p>\n";
229 
230  return($HistStr);
231  } // UploadHist()
232 
233 
234 
246  function ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
247  {
248  $UniqueTagArray = array();
249  $bucketstr = $Child['bucketstr'];
250 
251  /* If both $Child and $OtherChild are specified,
252  * reassemble bucketstr and highlight the differences
253  */
254  if ($Child and $OtherChild)
255  {
256  $bucketstr = "";
257  foreach ($Child['bucketarray'] as $bucket_pk)
258  {
259  $bucket_color = $BucketDefArray[$bucket_pk]['bucket_color'];
260  $BucketStyle = "style='color:#606060;background-color:$bucket_color'";
261  $DiffStyle = "style='background-color:$bucket_color;text-decoration:underline;text-transform:uppercase;border-style:outset'";
262  $bucket_name = $BucketDefArray[$bucket_pk]['bucket_name'];
263 
264  if (!empty($bucketstr)) $bucketstr .= ", ";
265  if (in_array($bucket_pk, $OtherChild['bucketarray']))
266  {
267  /* license is in both $Child and $OtherChild */
268  $Style = $BucketStyle;
269  }
270  else
271  {
272  /* license is missing from $OtherChild */
273  $Style = $DiffStyle;
274  }
275  $bucketstr .= "<span $Style>$bucket_name</span>";
276  }
277  }
278 
279  $ColStr = "<td id='$Child[uploadtree_pk]' align='left'>";
280  $ColStr .= "$Child[linkurl]";
281  /* show buckets under file name */
282  $ColStr .= "<br>";
283  $ColStr .= "<span style='position:relative;left:1em'>";
284  $ColStr .= $bucketstr;
285  $ColStr .= "</span>";
286  $ColStr .= "</td>";
287 
288  /* display file links if this is a real file */
289  $ColStr .= "<td valign='top'>";
290  $uploadtree_tablename = GetUploadtreeTableName($Child['upload_fk']);
291  $ColStr .= FileListLinks($Child['upload_fk'], $Child['uploadtree_pk'], $agent_pk, $Child['pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
292  $ColStr .= "</td>";
293  return $ColStr;
294  }
295 
296 
311  function ItemComparisonRows($Master, $agent_pk1, $agent_pk2, $BucketDefArray)
312  {
313  $TableStr = "";
314  $RowStyle1 = "style='background-color:#ecfaff'"; // pale blue
315  $RowStyle2 = "style='background-color:#ffffe3'"; // pale yellow
316  $RowNum = 0;
317 
318  foreach ($Master as $key => $Pair)
319  {
320  $RowStyle = (++$RowNum % 2) ? $RowStyle1 : $RowStyle2;
321  $TableStr .= "<tr $RowStyle>";
322 
323  $Child1 = GetArrayVal("1", $Pair);
324  $Child2 = GetArrayVal("2", $Pair);
325  if (empty($Child1))
326  {
327  $TableStr .= "<td></td><td></td>";
328  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
329  $TableStr .= $this->ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
330  }
331  else if (empty($Child2))
332  {
333  $TableStr .= $this->ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
334  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
335  $TableStr .= "<td></td><td></td>";
336  }
337  else if (!empty($Child1) and !empty($Child2))
338  {
339  $TableStr .= $this->ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
340  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
341  $TableStr .= $this->ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
342  }
343 
344  $TableStr .= "</tr>";
345  }
346 
347  return($TableStr);
348  } // ItemComparisonRows()
349 
350 
358  function AddBucketStr($TreeInfo, &$Children, $BucketDefArray)
359  {
360  if (!is_array($Children)) return;
361  $agent_pk = $TreeInfo['agent_pk'];
362  foreach($Children as &$Child)
363  {
364  $Child['bucketarray'] = GetFileBuckets($TreeInfo['nomosagent_pk'], $TreeInfo['bucketagent_pk'], $Child['uploadtree_pk'], $TreeInfo['bucketpool_pk']);
365 
366  $Child['bucketstr'] = GetFileBuckets_string($TreeInfo['nomosagent_pk'], $TreeInfo['bucketagent_pk'], $Child['uploadtree_pk'], $BucketDefArray, ",", True);
367  }
368  }
369 
370 
379  function EvalThreshold($MyArray, $Threshold, $BucketDefArray)
380  {
381  foreach($MyArray as $bucket_pk)
382  {
383  $bucket_evalorder = $BucketDefArray[$bucket_pk]['bucket_evalorder'];
384  if ($bucket_evalorder > $Threshold) return False;
385  }
386  return True;
387  }
388 
389  /* @brief remove files where all the buckets in both pairs
390  * are below a bucket_evalorder threshold.
391  function filter_evalordermin(&$Master, $BucketDefArray, $threshold)
392  {
393  foreach($Master as $Key =>&$Pair)
394  {
395  $Pair1 = GetArrayVal("1", $Pair);
396  $Pair2 = GetArrayVal("2", $Pair);
397 
398  if (empty($Pair1))
399  {
400  if ($this->EvalThreshold($Pair2['bucketarray'], $threshold, $BucketDefArray) == True)
401  unset($Master[$Key]);
402  else
403  continue;
404  }
405  else if (empty($Pair2))
406  {
407  if ($this->EvalThreshold($Pair1['bucketarray'], $threshold, $BucketDefArray) == True)
408  unset($Master[$Key]);
409  else
410  continue;
411  }
412  else
413  if (($this->EvalThreshold($Pair1['bucketarray'], $threshold, $BucketDefArray) == True)
414  and ($this->EvalThreshold($Pair2['bucketarray'], $threshold, $BucketDefArray) == True))
415  unset($Master[$Key]);
416  }
417  return;
418  } End of evalordermin */
419 
420 
425  function filter_samebucketlist(&$Master)
426  {
427  foreach($Master as $Key =>&$Pair)
428  {
429  $Pair1 = GetArrayVal("1", $Pair);
430  $Pair2 = GetArrayVal("2", $Pair);
431 
432  if (empty($Pair1) or empty($Pair2)) continue;
433  if ($Pair1['bucketstr'] == $Pair2['bucketstr'])
434  unset($Master[$Key]);
435  }
436  return;
437  } /* End of samebucketlist */
438 
446  function FilterChildren($filter, &$Master, $BucketDefArray)
447  {
448 //debugprint($Master, "Master");
449  switch($filter)
450  {
451  case 'samebucketlist':
452  $this->filter_samebucketlist($Master);
453  break;
454  default:
455  break;
456  }
457  }
458 
459 
473  function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
474  {
475  /* Initialize */
476  $FreezeText = _("Freeze Path");
477  $FrozenText = _("Frozen, Click to unfreeze");
478  $OutBuf = '';
479 
480  /******* javascript functions ********/
481  $OutBuf .= "\n<script language='javascript'>\n";
482  /* function to replace this page specifying a new filter parameter */
483  $OutBuf .= "function ChangeFilter(selectObj, utpk1, utpk2){";
484  $OutBuf .= " var selectidx = selectObj.selectedIndex;";
485  $OutBuf .= " var filter = selectObj.options[selectidx].value;";
486  $OutBuf .= ' window.location.assign("?mod=' . $this->Name .'&item1="+utpk1+"&item2="+utpk2+"&filter=" + filter); ';
487  $OutBuf .= "}\n";
488 
489  /* Freeze function (path list in banner)
490  FreezeColNo is the ID of the column to freeze: 1 or 2
491  Toggle Freeze button label: Freeze Path <-> Unfreeze Path
492  Toggle Freeze button background color: white to light blue
493  Toggle which paths are frozen: if path1 freezes, then unfreeze path2.
494  Rewrite urls: eg &item1 -> &Fitem1
495  */
496  $OutBuf .= "function Freeze(FreezeColNo) {";
497  $OutBuf .= "var FreezeElt1 = document.getElementById('Freeze1');";
498  $OutBuf .= "var FreezeElt2 = document.getElementById('Freeze2');";
499  $OutBuf .= "var AddFreezeArg = 1; "; //1 to add &freeze=, 0 to remove &freeze= from url
500  $OutBuf .= "var old_uploadtree_pk;\n";
501 
502  /* change the freeze labels to denote their new status */
503  $OutBuf .= "if (FreezeColNo == '1')";
504  $OutBuf .= "{";
505  $OutBuf .= "if (FreezeElt1.innerHTML == '$FrozenText') ";
506  $OutBuf .= "{";
507  $OutBuf .= "FreezeElt1.innerHTML = '$FreezeText';";
508  $OutBuf .= "FreezeElt1.style.backgroundColor = 'white'; ";
509  $OutBuf .= "AddFreezeArg = 0;";
510  $OutBuf .= "}";
511  $OutBuf .= "else { ";
512  $OutBuf .= "FreezeElt1.innerHTML = '$FrozenText'; ";
513  $OutBuf .= "FreezeElt1.style.backgroundColor = '#EAF7FB'; ";
514  $OutBuf .= "FreezeElt2.innerHTML = '$FreezeText';";
515  $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
516  $OutBuf .= "old_uploadtree_pk = $in_uploadtree_pk1;";
517  $OutBuf .= "}";
518  $OutBuf .= "}";
519  $OutBuf .= "else {";
520  $OutBuf .= "if (FreezeElt2.innerHTML == '$FrozenText') ";
521  $OutBuf .= "{";
522  $OutBuf .= "FreezeElt2.innerHTML = '$FreezeText';";
523  $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
524  $OutBuf .= "AddFreezeArg = 0;";
525  $OutBuf .= "}";
526  $OutBuf .= "else {";
527  $OutBuf .= "FreezeElt1.innerHTML = '$FreezeText';";
528  $OutBuf .= "FreezeElt1.style.backgroundColor = 'white';";
529  $OutBuf .= "FreezeElt2.innerHTML = '$FrozenText';";
530  $OutBuf .= "FreezeElt2.style.backgroundColor = '#EAF7FB';";
531  $OutBuf .= "old_uploadtree_pk = $in_uploadtree_pk2;";
532  $OutBuf .= "}";
533  $OutBuf .= "}";
534 
535  /* Alter the url to add or remove freeze={column number} */
536  $OutBuf .= "var i=0;\n";
537  $OutBuf .= "var linkid;\n";
538  $OutBuf .= "var linkelt;\n";
539  $OutBuf .= "var FreezeIdx;\n";
540  $OutBuf .= "var BaseURL;\n";
541  $OutBuf .= "var numlinks = document.links.length;\n";
542  $OutBuf .= "for (i=0; i < numlinks; i++)\n";
543  $OutBuf .= "{";
544  $OutBuf .= "linkelt = document.links[i];\n";
545  // freeze is the last url arg, so trim it off if it exists
546  $OutBuf .= "FreezeIdx = linkelt.href.indexOf('&freeze');\n";
547  $OutBuf .= "if (FreezeIdx > 0) \n";
548  $OutBuf .= "BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
549  $OutBuf .= "else ";
550  $OutBuf .= "BaseURL = linkelt.href; \n";
551  $OutBuf .= "if (AddFreezeArg == 1) \n ";
552  $OutBuf .= "linkelt.href = BaseURL + '&freeze=' + FreezeColNo + '&itemf=' + old_uploadtree_pk;";
553  $OutBuf .= "else \n";
554  $OutBuf .= "linkelt.href = BaseURL;";
555  $OutBuf .= "}\n";
556  $OutBuf .= "}\n";
557  $OutBuf .= "</script>\n";
558  /******* END javascript functions ********/
559 
560 
561  /* Select list for filters */
562  $SelectFilter = "<select name='diff_filter' id='diff_filter' onchange='ChangeFilter(this,$uploadtree_pk1, $uploadtree_pk2)'>";
563  $Selected = ($filter == 'none') ? "selected" : "";
564  $SelectFilter .= "<option $Selected value='none'>Remove nothing";
565 
566  $Selected = ($filter == 'samebucketlist') ? "selected" : "";
567  $SelectFilter .= "<option $Selected value='samebucketlist'>Remove unchanged bucket lists";
568  $SelectFilter .= "</select>";
569 
570  $StyleRt = "style='float:right'";
571  $OutBuf .= "<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
572 
573  /* Switch to license diff view */
574  $text = _("Switch to license view");
575  $switchURL = Traceback_uri();
576  $switchURL .= "?mod=nomosdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
577  $OutBuf .= "<a href='$switchURL' $StyleRt > $text </a> ";
578 
579 
580 // $TableStyle = "style='border-style:collapse;border:1px solid black'";
581  $TableStyle = "";
582  $OutBuf .= "<table border=0 id='dirlist' $TableStyle>";
583 
584  /* Select filter pulldown */
585  $OutBuf .= "<tr><td colspan=5 align='center'>Filter: $SelectFilter<br>&nbsp;</td></tr>";
586 
587  /* File path */
588  $OutBuf .= "<tr>";
589  $Path1 = Dir2Path($uploadtree_pk1);
590  $Path2 = Dir2Path($uploadtree_pk2);
591  $OutBuf .= "<td colspan=2>";
592  $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 1, $this);
593  $OutBuf .= "</td>";
594  $OutBuf .= "<td $this->ColumnSeparatorStyleL colspan=3>";
595  $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 2, $this);
596  $OutBuf .= "</td></tr>";
597 
598  /* File comparison table */
599  $OutBuf .= $this->ItemComparisonRows($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'], $BucketDefArray);
600 
601  /* Separator row */
602  $ColumnSeparatorStyleTop = "style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
603  $OutBuf .= "<tr>";
604  $OutBuf .= "<td colspan=5 $ColumnSeparatorStyleTop>";
605  $OutBuf .= "<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
606  $OutBuf .= "</a>";
607  $OutBuf .= "</tr>";
608 
609  /* License histogram */
610  $OutBuf .= "<tr>";
611  $Tree1Hist = $this->UploadHist($uploadtree_pk1, $TreeInfo1, $BucketDefArray);
612  $OutBuf .= "<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
613  $OutBuf .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
614  $Tree2Hist = $this->UploadHist($uploadtree_pk2, $TreeInfo2, $BucketDefArray);
615  $OutBuf .= "<td colspan=2 valign='top' align='center'>$Tree2Hist</td>";
616  $OutBuf .= "</tr></table>\n";
617 
618  $OutBuf .= "<a href='#flist' style='float:right'> Jump to top </a><p>";
619 
620  return $OutBuf;
621  }
622 
623 
634  function Output()
635  {
636  if ($this->State != PLUGIN_STATE_READY) { return(0); }
637 
638  $uTime = microtime(true);
639  $V="";
640  $UpdCache = GetParm("updcache",PARM_INTEGER);
641 
642  /* Remove "updcache" from the GET args and set $this->UpdCache
643  * This way all the url's based on the input args won't be
644  * polluted with updcache
645  * Use Traceback_parm_keep to ensure that all parameters are in order
646  */
647  $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("item1","item2", "filter", "col", "freeze", "itemf"));
648 
649  if ($UpdCache )
650  {
651  $UpdCache = $_GET['updcache'];
652  $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/","",$_SERVER['REQUEST_URI']);
653  unset($_GET['updcache']);
654  $V = ReportCachePurgeByKey($CacheKey);
655  }
656  else
657  $V = ReportCacheGet($CacheKey);
658 
659  $Cached = !empty($V);
660  if (!$Cached)
661  {
662  $V = $this->htmlContent();
663  }
664 
665  if (!$this->OutputToStdout) { return($V); }
666  print "$V";
667  $Time = microtime(true) - $uTime; // convert usecs to secs
668  $text = _("Elapsed time: %.2f seconds");
669  printf( "<small>$text</small>", $Time);
670 
671  if ($Cached)
672  {
673  $text = _("cached");
674  $text1 = _("Update");
675  echo " <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
676  }
677  else if ($Time > 0.5)
678  {
679  ReportCachePut($CacheKey, $V);
680  }
681  return;
682  }
683 
688  public function htmlContent()
689  {
690  $filter = GetParm("filter",PARM_STRING);
691  if (empty($filter)) $filter = "none";
692  $FreezeCol = GetParm("freeze",PARM_INTEGER); // which column to freeze? 1 or 2 or null
693  $ClickedCol = GetParm("col",PARM_INTEGER); // which column was clicked on? 1 or 2 or null
694  $ItemFrozen = GetParm("itemf",PARM_INTEGER); // frozen item or null
695  $in_uploadtree_pk1 = GetParm("item1",PARM_INTEGER);
696  $in_uploadtree_pk2 = GetParm("item2",PARM_INTEGER);
697 
698  if (empty($in_uploadtree_pk1) || empty($in_uploadtree_pk2))
699  Fatal("Bad input parameters. Both item1 and item2 must be specified.", __FILE__, __LINE__);
700 
701  /* If you click on a item in a frozen column, then you are a dope so ignore $ItemFrozen */
702  if ($FreezeCol == $ClickedCol)
703  {
704  $ItemFrozen= 0;
705  $FreezeCol = 0;
706  }
707 
708  /* @var $uploadDao UploadDao */
709  $uploadDao = $GLOBALS['container']->get('dao.upload');
710  /* Check item1 upload permission */
711  $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1);
712  if ( !$uploadDao->isAccessible($Item1Row['upload_fk'], Auth::getGroupId()) )
713  {
714  $text = _("Permission Denied");
715  return "<h2>$text item 1</h2>";
716  }
717 
718  /* Check item2 upload permission */
719  $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2);
720  if (!$uploadDao->isAccessible($Item2Row['upload_fk'], Auth::getGroupId()))
721  {
722  $text = _("Permission Denied");
723  return "<h2>$text item 2</h2>";
724  }
725 
726  $uploadtree_pk1 = $in_uploadtree_pk1;
727  $uploadtree_pk2 = $in_uploadtree_pk2;
728 
729  if ($FreezeCol == 1)
730  {
731  $uploadtree_pk1 = $ItemFrozen;
732  }
733  else if ($FreezeCol == 2)
734  {
735  $uploadtree_pk2 = $ItemFrozen;
736  }
737 
738 
739  $newURL = Traceback_dir() . "?mod=" . $this->Name . "&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
740  if (!empty($filter)) $newURL .= "&filter=$filter";
741 
742  // rewrite page with new uploadtree_pks */
743  if (($uploadtree_pk1 != $in_uploadtree_pk1)
744  || ($uploadtree_pk2 != $in_uploadtree_pk2))
745  {
746 print <<< JSOUT
747 <script type="text/javascript">
748  window.location.assign('$newURL');
749 </script>
750 JSOUT;
751  }
752 
753  $TreeInfo1 = $this->GetTreeInfo($uploadtree_pk1);
754  $TreeInfo2 = $this->GetTreeInfo($uploadtree_pk2);
755  $ErrText = _("No license data for tree %d. Use Jobs > Agents to schedule a license scan.");
756  $ErrMsg= '';
757  if ($TreeInfo1['agent_pk'] == 0)
758  {
759  $ErrMsg = sprintf($ErrText, 1);
760  }
761  else
762  if ($TreeInfo2['agent_pk'] == 0)
763  {
764  $ErrMsg = sprintf($ErrText, 2);
765  }
766  else
767  {
768  $BucketDefArray1 = initBucketDefArray($TreeInfo1['bucketpool_pk']);
769  $BucketDefArray2 = initBucketDefArray($TreeInfo2['bucketpool_pk']);
770  $BucketDefArray = $BucketDefArray1 + $BucketDefArray2;
771 
772  /* Get list of children */
773  $Children1 = GetNonArtifactChildren($uploadtree_pk1);
774  $Children2 = GetNonArtifactChildren($uploadtree_pk2);
775 
776  /* Add fuzzyname to children */
777  FuzzyName($Children1); // add fuzzyname to children
778  FuzzyName($Children2); // add fuzzyname to children
779 
780  /* add element licstr to children */
781  $this->AddBucketStr($TreeInfo1, $Children1, $BucketDefArray);
782  $this->AddBucketStr($TreeInfo2, $Children2, $BucketDefArray);
783 
784  /* Master array of children, aligned. */
785  $Master = MakeMaster($Children1, $Children2);
786 
787  /* add linkurl to children */
788  FileList($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'], $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
789 
790  /* Apply filter */
791  $this->FilterChildren($filter, $Master, $BucketDefArray);
792  }
793 
794  if($this->OutputType=='HTML')
795  {
796  if ($ErrMsg)
797  $V .= $ErrMsg;
798  else
799  $V .= $this->HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray);
800  }
801  return $V;
802  }
803 
804 }
805 
806 $NewPlugin = new ui_diff_buckets;
807 $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
FilterChildren($filter, &$Master, $BucketDefArray)
Filter children.
EvalThreshold($MyArray, $Threshold, $BucketDefArray)
Check all the buckets in $MyArray.
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
HTML output.
UploadHist($Uploadtree_pk, $TreeInfo, $BucketDefArray)
Given an $Uploadtree_pk, return a string with the histogram for the directory BY bucket.
ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
Return the entire <td> ... </td> for $Child file listing table differences are highlighted.
ItemComparisonRows($Master, $agent_pk1, $agent_pk2, $BucketDefArray)
Get a string with the html table rows comparing the two file lists.
filter_samebucketlist(&$Master)
remove files that contain identical bucket lists
Initialize()
This is called before the plugin is used.
Definition: bucket-diff.php:54
AddBucketStr($TreeInfo, &$Children, $BucketDefArray)
Add bucket_pk array and string to Children array.
__construct()
base constructor. Most plugins will just use this
Definition: bucket-diff.php:21
GetTreeInfo($Uploadtree_pk)
Get uploadtree info for a given uploadtree_pk.
Definition: bucket-diff.php:78
Output()
This function is called when user output is requested. This function is responsible for content....
Install()
Create and configure database tables.
Definition: bucket-diff.php:35
LatestAgentpk($upload_pk, $arsTableName, $arsSuccess=false)
Given an upload_pk, find the latest enabled agent_pk with results.
initBucketDefArray($bucketpool_pk)
Initializes array of bucket_def records.
GetFileBuckets_string($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketDefArray, $delimiter, $color)
Get string of $delimiter delimited bucket names for the given inputs. Args are same as GetFileBuckets...
SelectBucketDataset($upload_pk, &$ars_pk, $id="selectbucketdataset", $extra="")
Return a select list showing all the successful bucket runs on a particular $upload_pk.
GetFileBuckets($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketpool_pk)
Get all the unique bucket_pk's for a given uploadtree_pk and for a given nomos and bucket agent.
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]
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