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