25 define(
"TITLE_UI_NOMOS_DIFF", _(
"Compare License Browser"));
87 if (empty($PG_CONN)) {
126 if ($this->
State != PLUGIN_STATE_INVALID) {
129 if ($this->Name !==
"") {
131 $this->
State = PLUGIN_STATE_VALID;
132 array_push($Plugins, $this);
134 return ($this->
State == PLUGIN_STATE_VALID);
148 "WHERE uploadtree_pk = $Uploadtree_pk");
149 $TreeInfo[
'agent_pk'] =
LatestAgentpk($TreeInfo[
'upload_fk'],
"nomos_ars");
152 $UploadRec =
GetSingleRec(
"upload",
"where upload_pk=$TreeInfo[upload_fk]");
153 $TreeInfo[
'uploadtree_tablename'] = $UploadRec[
'uploadtree_tablename'];
168 $lft = $TreeInfo[
'lft'];
169 $rgt = $TreeInfo[
'rgt'];
170 $upload_pk = $TreeInfo[
'upload_fk'];
171 $agent_pk = $TreeInfo[
'agent_pk'];
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);
190 $VLic .=
"<table border=1 id='lichistogram'>\n";
193 $VLic .=
"<tr><th >$text</th>";
196 $VLic .=
"<th >$text</th>";
198 $text = _(
"License Name");
199 $VLic .=
"<th align=left>$text</th></tr>\n";
201 while ($row = pg_fetch_assoc($result)) {
203 $LicCount += $row[
'liccount'];
206 $VLic .=
"<tr><td align='right'>$row[liccount]</td>";
209 $ShowTitle = _(
"Click Show to list files with this license.");
210 $VLic .=
"<td align='center'><a href='";
214 $VLic .=
"?mod=license_list_files&napk=$agent_pk&item=$Uploadtree_pk&lic=" .
215 urlencode($row[
'rf_shortname']) .
"' title='$ShowTitle'>$text</a></td>";
218 $VLic .=
"<td align='left'>";
219 $rf_shortname = rawurlencode($row[
'rf_shortname']);
220 $VLic .=
"<a id='$rf_shortname' onclick='FileColor_Get(\"" .
222 "?mod=ajax_filelic&napk=$agent_pk&item=$Uploadtree_pk&lic=$rf_shortname\")'";
223 $VLic .=
">$row[licname] </a>";
226 if ($row[
'licname'] ==
"No_license_found") {
227 $NoLicFound = $row[
'liccount'];
230 pg_free_result($result);
231 $VLic .=
"</table>\n";
247 $UniqueTagArray = array();
248 $licstr = $Child[
'licstr'];
254 if ($OtherChild and $OtherChild) {
256 $DiffLicStyle =
"style='background-color:#ffa8a8'";
257 foreach ($Child[
'licarray'] as $rf_pk => $rf_shortname) {
258 if (! empty($licstr)) {
261 if (@$OtherChild[
'licarray'][$rf_pk]) {
263 $licstr .= $rf_shortname;
266 $licstr .=
"<span $DiffLicStyle>$rf_shortname</span>";
271 $ColStr =
"<td id='$Child[uploadtree_pk]' align='left'>";
272 $ColStr .=
"$Child[linkurl]";
275 $ColStr .=
"<span style='position:relative;left:1em'>";
277 $ColStr .=
"</span>";
281 $ColStr .=
"<td valign='top'>";
283 $ColStr .=
FileListLinks($Child[
'upload_fk'], $Child[
'uploadtree_pk'],
284 $agent_pk, $Child[
'pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
303 $RowStyle1 =
"style='background-color:#ecfaff'";
304 $RowStyle2 =
"style='background-color:#ffffe3'";
307 foreach ($Master as $key => $Pair) {
308 $RowStyle = (++ $RowNum % 2) ? $RowStyle1 : $RowStyle2;
309 $TableStr .=
"<tr $RowStyle>";
313 if (empty($Child1)) {
314 $TableStr .=
"<td></td><td></td>";
315 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </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> </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> </td>";
324 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1);
327 $TableStr .=
"</tr>";
340 if (! is_array($Children)) {
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']);
360 if (! is_array($Master)) {
364 foreach ($Master as $Key => &$Pair) {
365 if (empty($Pair[1]) or empty($Pair[2])) {
368 if (empty($Pair[1][
'pfile_fk'])) {
371 if (empty($Pair[2][
'pfile_fk'])) {
375 if ($Pair[1][
'pfile_fk'] == $Pair[2][
'pfile_fk']) {
376 unset($Master[$Key]);
389 foreach ($Master as $Key => &$Pair) {
390 if (empty($Pair[1]) or empty($Pair[2])) {
393 if (($Pair[1][
'ufile_name'] == $Pair[2][
'ufile_name']) &&
394 ($Pair[1][
'licstr'] == $Pair[2][
'licstr'])) {
395 unset($Master[$Key]);
408 foreach ($Master as $Key => &$Pair) {
409 if (empty($Pair[1]) or empty($Pair[2])) {
412 if (($Pair[1][
'fuzzyname'] == $Pair[2][
'fuzzyname']) &&
413 ($Pair[1][
'licstr'] == $Pair[2][
'licstr'])) {
414 unset($Master[$Key]);
431 $NoLicStr =
"No_license_found";
433 foreach ($Master as $Key => &$Pair) {
438 if ($Pair2[
'licstr'] == $NoLicStr) {
439 unset($Master[$Key]);
443 }
else if (empty($Pair2)) {
444 if ($Pair1[
'licstr'] == $NoLicStr) {
445 unset($Master[$Key]);
449 }
else if (($Pair1[
'licstr'] == $NoLicStr) and
450 ($Pair2[
'licstr'] == $NoLicStr)) {
451 unset($Master[$Key]);
493 function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1,
494 $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2)
497 $FreezeText = _(
"Freeze Path");
498 $FrozenText = _(
"Frozen, Click to unfreeze");
502 $OutBuf .=
"\n<script language='javascript'>\n";
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); ';
519 $OutBuf .=
"function Freeze(FreezeColNo) {";
520 $OutBuf .=
"var FreezeElt1 = document.getElementById('Freeze1');";
521 $OutBuf .=
"var FreezeElt2 = document.getElementById('Freeze2');";
522 $OutBuf .=
"var AddFreezeArg = 1; ";
524 $OutBuf .=
"var old_uploadtree_pk;\n";
527 $OutBuf .=
"if (FreezeColNo == '1')";
529 $OutBuf .=
"if (FreezeElt1.innerHTML == '$FrozenText') ";
531 $OutBuf .=
"FreezeElt1.innerHTML = '$FreezeText';";
532 $OutBuf .=
"FreezeElt1.style.backgroundColor = 'white'; ";
533 $OutBuf .=
"AddFreezeArg = 0;";
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;";
544 $OutBuf .=
"if (FreezeElt2.innerHTML == '$FrozenText') ";
546 $OutBuf .=
"FreezeElt2.innerHTML = '$FreezeText';";
547 $OutBuf .=
"FreezeElt2.style.backgroundColor = 'white';";
548 $OutBuf .=
"AddFreezeArg = 0;";
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;";
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";
568 $OutBuf .=
"linkelt = document.links[i];\n";
570 $OutBuf .=
"FreezeIdx = linkelt.href.indexOf('&freeze');\n";
571 $OutBuf .=
"if (FreezeIdx > 0) \n";
572 $OutBuf .=
"BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
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;";
581 $OutBuf .=
"</script>\n";
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>";
598 $StyleRt =
"style='float:right'";
599 $OutBuf .=
"<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
602 $text = _(
"Switch to bucket view");
604 $BucketURL .=
"?mod=bucketsdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
605 $OutBuf .=
"<a href='$BucketURL' $StyleRt > $text </a> ";
609 $OutBuf .=
"<table border=0 id='dirlist' $TableStyle>";
612 $OutBuf .=
"<tr><td colspan=5 align='center'>Filter: $SelectFilter<br> </td></tr>";
616 $Path1 =
Dir2Path($uploadtree_pk1, $TreeInfo1[
'uploadtree_tablename']);
617 $Path2 =
Dir2Path($uploadtree_pk2, $TreeInfo2[
'uploadtree_tablename']);
618 $OutBuf .=
"<td colspan=2>";
621 $OutBuf .=
"<td $this->ColumnSeparatorStyleL colspan=3>";
623 $OutBuf .=
"</td></tr>";
627 $TreeInfo2[
'agent_pk']);
630 $ColumnSeparatorStyleTop =
"style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
632 $OutBuf .=
"<td colspan=5 $ColumnSeparatorStyleTop>";
633 $OutBuf .=
"<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
639 $Tree1Hist = $this->
UploadHist($uploadtree_pk1, $TreeInfo1);
640 $OutBuf .=
"<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
641 $OutBuf .=
"<td $this->ColumnSeparatorStyleL> </td>";
642 $Tree2Hist = $this->
UploadHist($uploadtree_pk2, $TreeInfo2);
643 $OutBuf .=
"<td colspan=2 valign='top' align='center'>$Tree2Hist</td>";
644 $OutBuf .=
"</tr></table>\n";
646 $OutBuf .=
"<a href='#flist' style='float:right'> Jump to top </a><p>";
661 if ($this->
State != PLUGIN_STATE_READY) {
666 $uTime = microtime(
true);
676 $CacheKey =
"?mod=" . $this->Name .
687 $_SERVER[
'REQUEST_URI'] = preg_replace(
"/&updcache=[0-9]*/",
"",
688 $_SERVER[
'REQUEST_URI']);
689 unset($_GET[
'updcache']);
697 if (empty($filter)) {
698 $filter =
"samehash";
708 if (empty($in_uploadtree_pk1) or empty($in_uploadtree_pk2)) {
709 Fatal(
"Bad input parameters. Both item1 and item2 must be specified.",
717 if ($FreezeCol == $ClickedCol) {
723 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
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>";
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>";
738 $uploadtree_pk1 = $in_uploadtree_pk1;
739 $uploadtree_pk2 = $in_uploadtree_pk2;
743 if ($FreezeCol == 1) {
744 $uploadtree_pk1 = $ItemFrozen;
745 }
else if ($FreezeCol == 2) {
746 $uploadtree_pk2 = $ItemFrozen;
750 "&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
751 if (! empty($filter)) {
752 $newURL .=
"&filter=$filter";
756 if (($uploadtree_pk1 != $in_uploadtree_pk1) ||
757 ($uploadtree_pk2 != $in_uploadtree_pk2)) {
760 <script type=
"text/javascript">
761 window.location.assign(
'$newURL');
768 $ErrText = _(
"No license data for");
769 $ErrText2 = _(
"Use Jobs > Agents to schedule a license scan.");
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>";
777 $Children1 = GetNonArtifactChildren($uploadtree_pk1);
778 $Children2 = GetNonArtifactChildren($uploadtree_pk2);
785 $this->
AddLicStr($TreeInfo1, $Children1);
786 $this->
AddLicStr($TreeInfo2, $Children2);
792 FileList($Master, $TreeInfo1[
'agent_pk'], $TreeInfo2[
'agent_pk'],
793 $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
799 switch ($this->OutputType) {
806 $V .= $this->
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2,
807 $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1,
820 if (! $this->OutputToStdout) {
824 $Time = microtime(
true) - $uTime;
825 $text = _(
"Elapsed time: %.2f seconds");
826 printf(
"<small>$text</small>", $Time);
830 $text1 = _(
"Update");
831 echo
" <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
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"...
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.
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.
ItemComparisonRows($Master, $agent_pk1, $agent_pk2)
get a string with the html table rows comparing the two file lists.
FilterChildren($filter, &$Master)
filter children through same license, same hash, no license, same fuzzy license
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
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.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
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.
RegisterMenus()
Customize submenus.
filter_samehash(&$Master)
removes identical files
FileList(&$Master, $agent_pk1, $agent_pk2, $filter, $plugin, $uploadtree_pk1, $uploadtree_pk2)
Adds the element linkurl to the $Master elements.
GetTreeInfo($Uploadtree_pk)
get an array with uploadtree record and agent_pk
Output()
generate output information
AddLicStr($TreeInfo, &$Children)
Add license array to Children array.
filter_nolics(&$Master)
removes pairs of "No_license_found"
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:
ChildElt($Child, $agent_pk, $OtherChild)
get the entire <td> ... </td> for $Child file listing table
Traceback_dir()
Get the directory of the URI without query.
filter_samelicfuzzy(&$Master)
removes files that have the same fuzzyname, and same license list.
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.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
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)
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.
Install()
Create and configure database tables.
Initialize()
This is called before the plugin is used.
filter_samelic(&$Master)
removes files that have the same name and license list.
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.