FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
bucket-diff.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2011-2014 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2015 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ***********************************************************/
19 
22 
28 {
29  var $ColumnSeparatorStyleL = "style='border:solid 0 #006600; border-left-width:2px;padding-left:1em'";
30  var $threshold = 150;
32  function __construct()
33  {
34  $this->Name = "bucketsdiff";
35  $this->Title = _("Compare Buckets Browser");
36  $this->Dependency = array("browse","view");
37  $this->DBaccess = PLUGIN_DB_READ;
38  $this->LoginFlag = 0;
39  parent::__construct();
40  }
41 
46  function Install()
47  {
48  global $PG_CONN;
49  if (empty($PG_CONN)) { return(1); } /* No DB */
50 
51  return(0);
52  } // Install()
53 
54 
65  function Initialize()
66  {
67  global $_GET;
68 
69  if ($this->State != PLUGIN_STATE_INVALID) { return(1); } // don't re-run
70  if ($this->Name !== "") // Name must be defined
71  {
72  global $Plugins;
73  $this->State=PLUGIN_STATE_VALID;
74  array_push($Plugins,$this);
75  }
76 
77  return($this->State == PLUGIN_STATE_VALID);
78  } // Initialize()
79 
89  function GetTreeInfo($Uploadtree_pk)
90  {
91  global $PG_CONN;
92 
93  $TreeInfo = GetSingleRec("uploadtree", "WHERE uploadtree_pk = $Uploadtree_pk");
94  $TreeInfo['agent_pk'] = LatestAgentpk($TreeInfo['upload_fk'], "nomos_ars");
95 
96  /* Get the ars_pk of the scan to display, also the select list */
97  $ars_pk = GetArrayVal("ars", $_GET);
98  $BucketSelect = SelectBucketDataset($TreeInfo['upload_fk'], $ars_pk, "selectbdata",
99  "onchange=\"addArsGo('newds','selectbdata');\"");
100  $TreeInfo['ars_pk'] = $ars_pk;
101  if ($ars_pk == 0)
102  {
103  /* No bucket data for this upload */
104  return $BucketSelect; // $BucketSelect is error message
105  }
106 
107  /* Get scan keys */
108  $where = "where ars_pk=$ars_pk";
109  $row = GetSingleRec("bucket_ars", $where);
110  if (empty($row)) Fatal("No bucket data $where", __FILE__, __LINE__);
111  $TreeInfo['bucketagent_pk'] = $row["agent_fk"];
112  $TreeInfo['nomosagent_pk'] = $row["nomosagent_fk"];
113  $TreeInfo['bucketpool_pk'] = $row["bucketpool_fk"];
114  unset($row);
115 
116  return $TreeInfo;
117  }
118 
119 
127  function UploadHist($Uploadtree_pk, $TreeInfo, $BucketDefArray)
128  {
129  global $PG_CONN;
130 
131  $HistStr = '';
132  $lft = $TreeInfo['lft'];
133  $rgt = $TreeInfo['rgt'];
134  $upload_pk = $TreeInfo['upload_fk'];
135  $agent_pk = $TreeInfo['agent_pk'];
136  $bucketagent_pk = $TreeInfo['bucketagent_pk'];
137  $nomosagent_pk = $TreeInfo['nomosagent_pk'];
138  $bucketpool_pk = $TreeInfo['bucketpool_pk'];
139 
140  /*select all the buckets for entire tree for this bucketpool */
141  $sql = "SELECT distinct(bucket_fk) as bucket_pk,
142  count(bucket_fk) as bucketcount, bucket_reportorder
143  from bucket_file, bucket_def,
144  (SELECT distinct(pfile_fk) as PF from uploadtree
145  where upload_fk=$upload_pk
146  and ((ufile_mode & (1<<28))=0)
147  and uploadtree.lft BETWEEN $lft and $rgt) as SS
148  where PF=pfile_fk and agent_fk=$bucketagent_pk
149  and bucket_file.nomosagent_fk=$nomosagent_pk
150  and bucket_pk=bucket_fk
151  and bucketpool_fk=$bucketpool_pk
152  group by bucket_fk,bucket_reportorder
153  order by bucket_reportorder asc";
154  $result = pg_query($PG_CONN, $sql);
155  DBCheckResult($result, $sql, __FILE__, __LINE__);
156  $historows = pg_fetch_all($result);
157  pg_free_result($result);
158 
159 if (false)
160 {
161  /* Show dataset list */
162  if (!empty($BucketSelect))
163  {
164  $action = Traceback_uri() . "?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk";
165 
166  $HistStr .= "<script type='text/javascript'>
167 function addArsGo(formid, selectid )
168 {
169 var selectobj = document.getElementById(selectid);
170 var ars_pk = selectobj.options[selectobj.selectedIndex].value;
171 document.getElementById(formid).action='$action'+'&ars='+ars_pk;
172 document.getElementById(formid).submit();
173 return;
174 }
175 </script>";
176 
177  /* form to select new dataset (ars_pk) */
178  $HistStr .= "<form action='$action' id='newds' method='POST'>\n";
179  $HistStr .= $BucketSelect;
180  $HistStr .= "</form>";
181  }
182 }
183 
184  /* any rows? */
185  if (count($historows) == 0) return $HistStr;
186 
187  $sql = "select bucketpool_name from bucketpool where bucketpool_pk=$bucketpool_pk";
188  $result = pg_query($PG_CONN, $sql);
189  DBCheckResult($result, $sql, __FILE__, __LINE__);
190  $row = pg_fetch_assoc($result);
191  $bucketpool_name = $row['bucketpool_name'];
192  pg_free_result($result);
193 
194  /* Write bucket histogram to $HistStr */
195  $TotalCount = 0;
196  $NoLicFound = 0;
197  $HistStr .= "<table border=1 id='histogram'>\n";
198 
199  $text = _("Count");
200  $HistStr .= "<tr><th >$text</th>";
201 
202  $text = _("Files");
203  $HistStr .= "<th >$text</th>";
204 
205  $text = _("Bucket");
206  $HistStr .= "<th align=left>$text</th></tr>\n";
207 
208  if(empty($historows))
209  {
210  return;
211  }
212  foreach ($historows as $row)
213  {
214  $TotalCount += $row['bucketcount'];
215  $bucket_pk = $row['bucket_pk'];
216  $bucketcount = $row['bucketcount'];
217  $bucket_name = $BucketDefArray[$bucket_pk]['bucket_name'];
218  $bucket_color = $BucketDefArray[$bucket_pk]['bucket_color'];
219 
220  /* Count */
221  $HistStr .= "<tr><td align='right' style='background-color:$bucket_color'>$row[bucketcount]</td>";
222 
223  /* Show */
224  $ShowTitle = _("Click Show to list files with this license.");
225  $HistStr .= "<td align='center'><a href='";
226  $HistStr .= Traceback_uri();
227 
228  $text = _("Show");
229  $HistStr .= "?mod=list_bucket_files&bapk=$bucketagent_pk&item=$Uploadtree_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk" . "'>$text</a></td>";
230 
231  /* Bucket name */
232  $HistStr .= "<td align='left'>";
233  $HistStr .= "<a id='$bucket_pk' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filebucket&bapk=$bucketagent_pk&item=$Uploadtree_pk&bucket_pk=$bucket_pk\")'";
234  $HistStr .= ">$bucket_name </a>";
235  $HistStr .= "</td>";
236  $HistStr .= "</tr>\n";
237  }
238  $HistStr .= "</table>\n";
239  $HistStr .= "<p>\n";
240 
241  return($HistStr);
242  } // UploadHist()
243 
244 
245 
257  function ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
258  {
259  $UniqueTagArray = array();
260  $bucketstr = $Child['bucketstr'];
261 
262  /* If both $Child and $OtherChild are specified,
263  * reassemble bucketstr and highlight the differences
264  */
265  if ($OtherChild and $OtherChild)
266  {
267  $bucketstr = "";
268  foreach ($Child['bucketarray'] as $bucket_pk)
269  {
270  $bucket_color = $BucketDefArray[$bucket_pk]['bucket_color'];
271  $BucketStyle = "style='color:#606060;background-color:$bucket_color'";
272  $DiffStyle = "style='background-color:$bucket_color;text-decoration:underline;text-transform:uppercase;border-style:outset'";
273  $bucket_name = $BucketDefArray[$bucket_pk]['bucket_name'];
274 
275  if (!empty($bucketstr)) $bucketstr .= ", ";
276  if (in_array($bucket_pk, $OtherChild['bucketarray']))
277  {
278  /* license is in both $Child and $OtherChild */
279  $Style = $BucketStyle;
280  }
281  else
282  {
283  /* license is missing from $OtherChild */
284  $Style = $DiffStyle;
285  }
286  $bucketstr .= "<span $Style>$bucket_name</span>";
287  }
288  }
289 
290  $ColStr = "<td id='$Child[uploadtree_pk]' align='left'>";
291  $ColStr .= "$Child[linkurl]";
292  /* show buckets under file name */
293  $ColStr .= "<br>";
294  $ColStr .= "<span style='position:relative;left:1em'>";
295  $ColStr .= $bucketstr;
296  $ColStr .= "</span>";
297  $ColStr .= "</td>";
298 
299  /* display file links if this is a real file */
300  $ColStr .= "<td valign='top'>";
301  $uploadtree_tablename = GetUploadtreeTableName($Child['upload_fk']);
302  $ColStr .= FileListLinks($Child['upload_fk'], $Child['uploadtree_pk'], $agent_pk, $Child['pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
303  $ColStr .= "</td>";
304  return $ColStr;
305  }
306 
307 
322  function ItemComparisonRows($Master, $agent_pk1, $agent_pk2, $BucketDefArray)
323  {
324  $TableStr = "";
325  $RowStyle1 = "style='background-color:#ecfaff'"; // pale blue
326  $RowStyle2 = "style='background-color:#ffffe3'"; // pale yellow
327  $RowNum = 0;
328 
329  foreach ($Master as $key => $Pair)
330  {
331  $RowStyle = (++$RowNum % 2) ? $RowStyle1 : $RowStyle2;
332  $TableStr .= "<tr $RowStyle>";
333 
334  $Child1 = GetArrayVal("1", $Pair);
335  $Child2 = GetArrayVal("2", $Pair);
336  if (empty($Child1))
337  {
338  $TableStr .= "<td></td><td></td>";
339  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
340  $TableStr .= $this->ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
341  }
342  else if (empty($Child2))
343  {
344  $TableStr .= $this->ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
345  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
346  $TableStr .= "<td></td><td></td>";
347  }
348  else if (!empty($Child1) and !empty($Child2))
349  {
350  $TableStr .= $this->ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
351  $TableStr .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
352  $TableStr .= $this->ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
353  }
354 
355  $TableStr .= "</tr>";
356  }
357 
358  return($TableStr);
359  } // ItemComparisonRows()
360 
361 
369  function AddBucketStr($TreeInfo, &$Children, $BucketDefArray)
370  {
371  if (!is_array($Children)) return;
372  $agent_pk = $TreeInfo['agent_pk'];
373  foreach($Children as &$Child)
374  {
375  $Child['bucketarray'] = GetFileBuckets($TreeInfo['nomosagent_pk'], $TreeInfo['bucketagent_pk'], $Child['uploadtree_pk'], $TreeInfo['bucketpool_pk']);
376 
377  $Child['bucketstr'] = GetFileBuckets_string($TreeInfo['nomosagent_pk'], $TreeInfo['bucketagent_pk'], $Child['uploadtree_pk'], $BucketDefArray, ",", True);
378  }
379  }
380 
381 
390  function EvalThreshold($MyArray, $Threshold, $BucketDefArray)
391  {
392  foreach($MyArray as $bucket_pk)
393  {
394  $bucket_evalorder = $BucketDefArray[$bucket_pk]['bucket_evalorder'];
395  if ($bucket_evalorder > $Threshold) return False;
396  }
397  return True;
398  }
399 
400  /* @brief remove files where all the buckets in both pairs
401  * are below a bucket_evalorder threshold.
402  function filter_evalordermin(&$Master, $BucketDefArray, $threshold)
403  {
404  foreach($Master as $Key =>&$Pair)
405  {
406  $Pair1 = GetArrayVal("1", $Pair);
407  $Pair2 = GetArrayVal("2", $Pair);
408 
409  if (empty($Pair1))
410  {
411  if ($this->EvalThreshold($Pair2['bucketarray'], $threshold, $BucketDefArray) == True)
412  unset($Master[$Key]);
413  else
414  continue;
415  }
416  else if (empty($Pair2))
417  {
418  if ($this->EvalThreshold($Pair1['bucketarray'], $threshold, $BucketDefArray) == True)
419  unset($Master[$Key]);
420  else
421  continue;
422  }
423  else
424  if (($this->EvalThreshold($Pair1['bucketarray'], $threshold, $BucketDefArray) == True)
425  and ($this->EvalThreshold($Pair2['bucketarray'], $threshold, $BucketDefArray) == True))
426  unset($Master[$Key]);
427  }
428  return;
429  } End of evalordermin */
430 
431 
436  function filter_samebucketlist(&$Master)
437  {
438  foreach($Master as $Key =>&$Pair)
439  {
440  $Pair1 = GetArrayVal("1", $Pair);
441  $Pair2 = GetArrayVal("2", $Pair);
442 
443  if (empty($Pair1) or empty($Pair2)) continue;
444  if ($Pair1['bucketstr'] == $Pair2['bucketstr'])
445  unset($Master[$Key]);
446  }
447  return;
448  } /* End of samebucketlist */
449 
457  function FilterChildren($filter, &$Master, $BucketDefArray)
458  {
459 //debugprint($Master, "Master");
460  switch($filter)
461  {
462  case 'samebucketlist':
463  $this->filter_samebucketlist($Master);
464  break;
465  default:
466  break;
467  }
468  }
469 
470 
484  function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
485  {
486  /* Initialize */
487  $FreezeText = _("Freeze Path");
488  $FrozenText = _("Frozen, Click to unfreeze");
489  $OutBuf = '';
490 
491  /******* javascript functions ********/
492  $OutBuf .= "\n<script language='javascript'>\n";
493  /* function to replace this page specifying a new filter parameter */
494  $OutBuf .= "function ChangeFilter(selectObj, utpk1, utpk2){";
495  $OutBuf .= " var selectidx = selectObj.selectedIndex;";
496  $OutBuf .= " var filter = selectObj.options[selectidx].value;";
497  $OutBuf .= ' window.location.assign("?mod=' . $this->Name .'&item1="+utpk1+"&item2="+utpk2+"&filter=" + filter); ';
498  $OutBuf .= "}\n";
499 
500  /* Freeze function (path list in banner)
501  FreezeColNo is the ID of the column to freeze: 1 or 2
502  Toggle Freeze button label: Freeze Path <-> Unfreeze Path
503  Toggle Freeze button background color: white to light blue
504  Toggle which paths are frozen: if path1 freezes, then unfreeze path2.
505  Rewrite urls: eg &item1 -> &Fitem1
506  */
507  $OutBuf .= "function Freeze(FreezeColNo) {";
508  $OutBuf .= "var FreezeElt1 = document.getElementById('Freeze1');";
509  $OutBuf .= "var FreezeElt2 = document.getElementById('Freeze2');";
510  $OutBuf .= "var AddFreezeArg = 1; "; //1 to add &freeze=, 0 to remove &freeze= from url
511  $OutBuf .= "var old_uploadtree_pk;\n";
512 
513  /* change the freeze labels to denote their new status */
514  $OutBuf .= "if (FreezeColNo == '1')";
515  $OutBuf .= "{";
516  $OutBuf .= "if (FreezeElt1.innerHTML == '$FrozenText') ";
517  $OutBuf .= "{";
518  $OutBuf .= "FreezeElt1.innerHTML = '$FreezeText';";
519  $OutBuf .= "FreezeElt1.style.backgroundColor = 'white'; ";
520  $OutBuf .= "AddFreezeArg = 0;";
521  $OutBuf .= "}";
522  $OutBuf .= "else { ";
523  $OutBuf .= "FreezeElt1.innerHTML = '$FrozenText'; ";
524  $OutBuf .= "FreezeElt1.style.backgroundColor = '#EAF7FB'; ";
525  $OutBuf .= "FreezeElt2.innerHTML = '$FreezeText';";
526  $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
527  $OutBuf .= "old_uploadtree_pk = $in_uploadtree_pk1;";
528  $OutBuf .= "}";
529  $OutBuf .= "}";
530  $OutBuf .= "else {";
531  $OutBuf .= "if (FreezeElt2.innerHTML == '$FrozenText') ";
532  $OutBuf .= "{";
533  $OutBuf .= "FreezeElt2.innerHTML = '$FreezeText';";
534  $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
535  $OutBuf .= "AddFreezeArg = 0;";
536  $OutBuf .= "}";
537  $OutBuf .= "else {";
538  $OutBuf .= "FreezeElt1.innerHTML = '$FreezeText';";
539  $OutBuf .= "FreezeElt1.style.backgroundColor = 'white';";
540  $OutBuf .= "FreezeElt2.innerHTML = '$FrozenText';";
541  $OutBuf .= "FreezeElt2.style.backgroundColor = '#EAF7FB';";
542  $OutBuf .= "old_uploadtree_pk = $in_uploadtree_pk2;";
543  $OutBuf .= "}";
544  $OutBuf .= "}";
545 
546  /* Alter the url to add or remove freeze={column number} */
547  $OutBuf .= "var i=0;\n";
548  $OutBuf .= "var linkid;\n";
549  $OutBuf .= "var linkelt;\n";
550  $OutBuf .= "var FreezeIdx;\n";
551  $OutBuf .= "var BaseURL;\n";
552  $OutBuf .= "var numlinks = document.links.length;\n";
553  $OutBuf .= "for (i=0; i < numlinks; i++)\n";
554  $OutBuf .= "{";
555  $OutBuf .= "linkelt = document.links[i];\n";
556  // freeze is the last url arg, so trim it off if it exists
557  $OutBuf .= "FreezeIdx = linkelt.href.indexOf('&freeze');\n";
558  $OutBuf .= "if (FreezeIdx > 0) \n";
559  $OutBuf .= "BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
560  $OutBuf .= "else ";
561  $OutBuf .= "BaseURL = linkelt.href; \n";
562  $OutBuf .= "if (AddFreezeArg == 1) \n ";
563  $OutBuf .= "linkelt.href = BaseURL + '&freeze=' + FreezeColNo + '&itemf=' + old_uploadtree_pk;";
564  $OutBuf .= "else \n";
565  $OutBuf .= "linkelt.href = BaseURL;";
566  $OutBuf .= "}\n";
567  $OutBuf .= "}\n";
568  $OutBuf .= "</script>\n";
569  /******* END javascript functions ********/
570 
571 
572  /* Select list for filters */
573  $SelectFilter = "<select name='diff_filter' id='diff_filter' onchange='ChangeFilter(this,$uploadtree_pk1, $uploadtree_pk2)'>";
574  $Selected = ($filter == 'none') ? "selected" : "";
575  $SelectFilter .= "<option $Selected value='none'>Remove nothing";
576 
577  $Selected = ($filter == 'samebucketlist') ? "selected" : "";
578  $SelectFilter .= "<option $Selected value='samebucketlist'>Remove unchanged bucket lists";
579  $SelectFilter .= "</select>";
580 
581  $StyleRt = "style='float:right'";
582  $OutBuf .= "<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
583 
584  /* Switch to license diff view */
585  $text = _("Switch to license view");
586  $switchURL = Traceback_uri();
587  $switchURL .= "?mod=nomosdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
588  $OutBuf .= "<a href='$switchURL' $StyleRt > $text </a> ";
589 
590 
591 // $TableStyle = "style='border-style:collapse;border:1px solid black'";
592  $TableStyle = "";
593  $OutBuf .= "<table border=0 id='dirlist' $TableStyle>";
594 
595  /* Select filter pulldown */
596  $OutBuf .= "<tr><td colspan=5 align='center'>Filter: $SelectFilter<br>&nbsp;</td></tr>";
597 
598  /* File path */
599  $OutBuf .= "<tr>";
600  $Path1 = Dir2Path($uploadtree_pk1);
601  $Path2 = Dir2Path($uploadtree_pk2);
602  $OutBuf .= "<td colspan=2>";
603  $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 1, $this);
604  $OutBuf .= "</td>";
605  $OutBuf .= "<td $this->ColumnSeparatorStyleL colspan=3>";
606  $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 2, $this);
607  $OutBuf .= "</td></tr>";
608 
609  /* File comparison table */
610  $OutBuf .= $this->ItemComparisonRows($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'], $BucketDefArray);
611 
612  /* Separator row */
613  $ColumnSeparatorStyleTop = "style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
614  $OutBuf .= "<tr>";
615  $OutBuf .= "<td colspan=5 $ColumnSeparatorStyleTop>";
616  $OutBuf .= "<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
617  $OutBuf .= "</a>";
618  $OutBuf .= "</tr>";
619 
620  /* License histogram */
621  $OutBuf .= "<tr>";
622  $Tree1Hist = $this->UploadHist($uploadtree_pk1, $TreeInfo1, $BucketDefArray);
623  $OutBuf .= "<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
624  $OutBuf .= "<td $this->ColumnSeparatorStyleL>&nbsp;</td>";
625  $Tree2Hist = $this->UploadHist($uploadtree_pk2, $TreeInfo2, $BucketDefArray);
626  $OutBuf .= "<td colspan=2 valign='top' align='center'>$Tree2Hist</td>";
627  $OutBuf .= "</tr></table>\n";
628 
629  $OutBuf .= "<a href='#flist' style='float:right'> Jump to top </a><p>";
630 
631  return $OutBuf;
632  }
633 
634 
645  function Output()
646  {
647  if ($this->State != PLUGIN_STATE_READY) { return(0); }
648 
649  $uTime = microtime(true);
650  $V="";
651  $UpdCache = GetParm("updcache",PARM_INTEGER);
652 
653  /* Remove "updcache" from the GET args and set $this->UpdCache
654  * This way all the url's based on the input args won't be
655  * polluted with updcache
656  * Use Traceback_parm_keep to ensure that all parameters are in order
657  */
658  $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("item1","item2", "filter", "col", "freeze", "itemf"));
659 
660  if ($UpdCache )
661  {
662  $UpdCache = $_GET['updcache'];
663  $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/","",$_SERVER['REQUEST_URI']);
664  unset($_GET['updcache']);
665  $V = ReportCachePurgeByKey($CacheKey);
666  }
667  else
668  $V = ReportCacheGet($CacheKey);
669 
670  $Cached = !empty($V);
671  if (!$Cached)
672  {
673  $V = $this->htmlContent();
674  }
675 
676  if (!$this->OutputToStdout) { return($V); }
677  print "$V";
678  $Time = microtime(true) - $uTime; // convert usecs to secs
679  $text = _("Elapsed time: %.2f seconds");
680  printf( "<small>$text</small>", $Time);
681 
682  if ($Cached)
683  {
684  $text = _("cached");
685  $text1 = _("Update");
686  echo " <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
687  }
688  else if ($Time > 0.5)
689  {
690  ReportCachePut($CacheKey, $V);
691  }
692  return;
693  }
694 
699  public function htmlContent()
700  {
701  $filter = GetParm("filter",PARM_STRING);
702  if (empty($filter)) $filter = "none";
703  $FreezeCol = GetParm("freeze",PARM_INTEGER); // which column to freeze? 1 or 2 or null
704  $ClickedCol = GetParm("col",PARM_INTEGER); // which column was clicked on? 1 or 2 or null
705  $ItemFrozen = GetParm("itemf",PARM_INTEGER); // frozen item or null
706  $in_uploadtree_pk1 = GetParm("item1",PARM_INTEGER);
707  $in_uploadtree_pk2 = GetParm("item2",PARM_INTEGER);
708 
709  if (empty($in_uploadtree_pk1) || empty($in_uploadtree_pk2))
710  Fatal("Bad input parameters. Both item1 and item2 must be specified.", __FILE__, __LINE__);
711 
712  /* If you click on a item in a frozen column, then you are a dope so ignore $ItemFrozen */
713  if ($FreezeCol == $ClickedCol)
714  {
715  $ItemFrozen= 0;
716  $FreezeCol = 0;
717  }
718 
719  /* @var $uploadDao UploadDao */
720  $uploadDao = $GLOBALS['container']->get('dao.upload');
721  /* Check item1 upload permission */
722  $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1);
723  if ( !$uploadDao->isAccessible($Item1Row['upload_fk'], Auth::getGroupId()) )
724  {
725  $text = _("Permission Denied");
726  return "<h2>$text item 1</h2>";
727  }
728 
729  /* Check item2 upload permission */
730  $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2);
731  if (!$uploadDao->isAccessible($Item2Row['upload_fk'], Auth::getGroupId()))
732  {
733  $text = _("Permission Denied");
734  return "<h2>$text item 2</h2>";
735  }
736 
737  $uploadtree_pk1 = $in_uploadtree_pk1;
738  $uploadtree_pk2 = $in_uploadtree_pk2;
739 
740  if ($FreezeCol == 1)
741  {
742  $uploadtree_pk1 = $ItemFrozen;
743  }
744  else if ($FreezeCol == 2)
745  {
746  $uploadtree_pk2 = $ItemFrozen;
747  }
748 
749 
750  $newURL = Traceback_dir() . "?mod=" . $this->Name . "&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
751  if (!empty($filter)) $newURL .= "&filter=$filter";
752 
753  // rewrite page with new uploadtree_pks */
754  if (($uploadtree_pk1 != $in_uploadtree_pk1)
755  || ($uploadtree_pk2 != $in_uploadtree_pk2))
756  {
757 print <<< JSOUT
758 <script type="text/javascript">
759  window.location.assign('$newURL');
760 </script>
761 JSOUT;
762  }
763 
764  $TreeInfo1 = $this->GetTreeInfo($uploadtree_pk1);
765  $TreeInfo2 = $this->GetTreeInfo($uploadtree_pk2);
766  $ErrText = _("No license data for tree %d. Use Jobs > Agents to schedule a license scan.");
767  $ErrMsg= '';
768  if ($TreeInfo1['agent_pk'] == 0)
769  {
770  $ErrMsg = sprintf($ErrText, 1);
771  }
772  else
773  if ($TreeInfo2['agent_pk'] == 0)
774  {
775  $ErrMsg = sprintf($ErrText, 2);
776  }
777  else
778  {
779  $BucketDefArray1 = initBucketDefArray($TreeInfo1['bucketpool_pk']);
780  $BucketDefArray2 = initBucketDefArray($TreeInfo2['bucketpool_pk']);
781  $BucketDefArray = $BucketDefArray1 + $BucketDefArray2;
782 
783  /* Get list of children */
784  $Children1 = GetNonArtifactChildren($uploadtree_pk1);
785  $Children2 = GetNonArtifactChildren($uploadtree_pk2);
786 
787  /* Add fuzzyname to children */
788  FuzzyName($Children1); // add fuzzyname to children
789  FuzzyName($Children2); // add fuzzyname to children
790 
791  /* add element licstr to children */
792  $this->AddBucketStr($TreeInfo1, $Children1, $BucketDefArray);
793  $this->AddBucketStr($TreeInfo2, $Children2, $BucketDefArray);
794 
795  /* Master array of children, aligned. */
796  $Master = MakeMaster($Children1, $Children2);
797 
798  /* add linkurl to children */
799  FileList($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'], $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
800 
801  /* Apply filter */
802  $this->FilterChildren($filter, $Master, $BucketDefArray);
803  }
804 
805  if($this->OutputType=='HTML')
806  {
807  if ($ErrMsg)
808  $V .= $ErrMsg;
809  else
810  $V .= $this->HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray);
811  }
812  return $V;
813  }
814 
815 }
816 
817 $NewPlugin = new ui_diff_buckets;
818 $NewPlugin->Initialize();
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:421
FuzzyName(&$Children)
Add fuzzyname and fuzzynameext to $Children.
Traceback_uri()
Get the URI without query to this location.
initBucketDefArray($bucketpool_pk)
Initializes array of bucket_def records.
UploadHist($Uploadtree_pk, $TreeInfo, $BucketDefArray)
Given an $Uploadtree_pk, return a string with the histogram for the directory BY bucket.
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
Definition: common-dir.php:233
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...
ReportCachePut($CacheKey, $CacheValue)
This function is used to write a record to the report cache. If the record already exists...
GetSingleRec($Table, $Where="")
Retrieve a single database record.
Definition: common-db.php:102
Install()
Create and configure database tables.
Definition: bucket-diff.php:46
GetTreeInfo($Uploadtree_pk)
Get uploadtree info for a given uploadtree_pk.
Definition: bucket-diff.php:89
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:49
MakeMaster($Children1, $Children2)
Generate the master array with aligned children.
ItemComparisonRows($Master, $agent_pk1, $agent_pk2, $BucketDefArray)
Get a string with the html table rows comparing the two file lists.
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
AddBucketStr($TreeInfo, &$Children, $BucketDefArray)
Add bucket_pk array and string to Children array.
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
HTML output.
ReportCachePurgeByKey($CacheKey)
Purge from the report cache the record with $CacheKey.
Definition: state.hpp:26
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
FilterChildren($filter, &$Master, $BucketDefArray)
Filter children.
LatestAgentpk($upload_pk, $arsTableName, $arsSuccess=false)
Given an upload_pk, find the latest enabled agent_pk with results.
FileList(&$Master, $agent_pk1, $agent_pk2, $filter, $plugin, $uploadtree_pk1, $uploadtree_pk2)
Adds the element linkurl to the $Master elements.
const PARM_STRING
Definition: common-parm.php:29
const PARM_INTEGER
Definition: common-parm.php:25
filter_samebucketlist(&$Master)
remove files that contain identical bucket lists
Output()
This function is called when user output is requested. This function is responsible for content...
ReportCacheGet($CacheKey)
This function is used by Output() to see if the requested report is in the report cache...
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
Traceback_dir()
Get the directory of the URI without query.
EvalThreshold($MyArray, $Threshold, $BucketDefArray)
Check all the buckets in $MyArray.
SelectBucketDataset($upload_pk, &$ars_pk, $id="selectbucketdataset", $extra="")
Return a select list showing all the successful bucket runs on a particular $upload_pk.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
GetFileBuckets($nomosagent_pk, $bucketagent_pk, $uploadtree_pk, $bucketpool_pk)
Get all the unique bucket_pk&#39;s for a given uploadtree_pk and for a given nomos and bucket agent...
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198
Dir2BrowseDiff($Path1, $Path2, $filter, $Column, $plugin)
Return a string which is a linked path to the file.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
Return the entire <td> ... </td> for $Child file listing table differences are highlighted.
GetArrayVal($Key, $Arr)
Get the value from a array(map)
Definition: common-ui.php:143
Initialize()
This is called before the plugin is used.
Definition: bucket-diff.php:65
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.
Definition: common-ui.php:75