14 define(
"TITLE_UI_NOMOS_DIFF", _(
"Compare License Browser"));
115 if ($this->
State != PLUGIN_STATE_INVALID) {
118 if ($this->Name !==
"") {
120 $this->
State = PLUGIN_STATE_VALID;
121 array_push($Plugins, $this);
123 return ($this->
State == PLUGIN_STATE_VALID);
137 "WHERE uploadtree_pk = $Uploadtree_pk");
138 $TreeInfo[
'agent_pk'] =
LatestAgentpk($TreeInfo[
'upload_fk'],
"nomos_ars");
141 $UploadRec =
GetSingleRec(
"upload",
"where upload_pk=$TreeInfo[upload_fk]");
142 $TreeInfo[
'uploadtree_tablename'] = $UploadRec[
'uploadtree_tablename'];
157 $lft = $TreeInfo[
'lft'];
158 $rgt = $TreeInfo[
'rgt'];
159 $upload_pk = $TreeInfo[
'upload_fk'];
160 $agent_pk = $TreeInfo[
'agent_pk'];
163 $sql =
"SELECT rf_shortname as licname,
164 count(rf_shortname) as liccount, rf_shortname
165 from ONLY license_ref,license_file,
166 (SELECT distinct(pfile_fk) as PF from $TreeInfo[uploadtree_tablename]
167 where upload_fk=$upload_pk
168 and {$TreeInfo['uploadtree_tablename']}.lft BETWEEN $lft and $rgt) as SS
169 where PF=pfile_fk and agent_fk=$agent_pk and rf_fk=rf_pk
170 group by rf_shortname
171 order by liccount desc";
179 $VLic .=
"<table border=1 id='lichistogram'>\n";
182 $VLic .=
"<tr><th >$text</th>";
185 $VLic .=
"<th >$text</th>";
187 $text = _(
"License Name");
188 $VLic .=
"<th align=left>$text</th></tr>\n";
190 while ($row = pg_fetch_assoc($result)) {
192 $LicCount += $row[
'liccount'];
195 $VLic .=
"<tr><td align='right'>$row[liccount]</td>";
198 $ShowTitle = _(
"Click Show to list files with this license.");
199 $VLic .=
"<td align='center'><a href='";
203 $VLic .=
"?mod=license_list_files&napk=$agent_pk&item=$Uploadtree_pk&lic=" .
204 urlencode($row[
'rf_shortname']) .
"' title='$ShowTitle'>$text</a></td>";
207 $VLic .=
"<td align='left'>";
208 $rf_shortname = rawurlencode($row[
'rf_shortname']);
209 $VLic .=
"<a id='$rf_shortname' onclick='FileColor_Get(\"" .
211 "?mod=ajax_filelic&napk=$agent_pk&item=$Uploadtree_pk&lic=$rf_shortname\")'";
212 $VLic .=
">$row[licname] </a>";
215 if ($row[
'licname'] ==
"No_license_found") {
216 $NoLicFound = $row[
'liccount'];
219 pg_free_result($result);
220 $VLic .=
"</table>\n";
236 $UniqueTagArray = array();
237 $licstr = $Child[
'licstr'];
243 if ($Child and $OtherChild) {
245 $DiffLicStyle =
"style='background-color:#ffa8a8'";
246 foreach ($Child[
'licarray'] as $rf_pk => $rf_shortname) {
247 if (! empty($licstr)) {
250 if (@$OtherChild[
'licarray'][$rf_pk]) {
252 $licstr .= $rf_shortname;
255 $licstr .=
"<span $DiffLicStyle>$rf_shortname</span>";
260 $ColStr =
"<td id='$Child[uploadtree_pk]' align='left'>";
261 $ColStr .=
"$Child[linkurl]";
264 $ColStr .=
"<span style='position:relative;left:1em'>";
266 $ColStr .=
"</span>";
270 $ColStr .=
"<td valign='top'>";
272 $ColStr .=
FileListLinks($Child[
'upload_fk'], $Child[
'uploadtree_pk'],
273 $agent_pk, $Child[
'pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
292 $RowStyle1 =
"style='background-color:#ecfaff'";
293 $RowStyle2 =
"style='background-color:#ffffe3'";
296 foreach ($Master as $key => $Pair) {
297 $RowStyle = (++ $RowNum % 2) ? $RowStyle1 : $RowStyle2;
298 $TableStr .=
"<tr $RowStyle>";
302 if (empty($Child1)) {
303 $TableStr .=
"<td></td><td></td>";
304 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
305 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1);
306 }
else if (empty($Child2)) {
307 $TableStr .= $this->
ChildElt($Child1, $agent_pk1, $Child2);
308 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
309 $TableStr .=
"<td></td><td></td>";
310 }
else if (! empty($Child1) and ! empty($Child2)) {
311 $TableStr .= $this->
ChildElt($Child1, $agent_pk1, $Child2);
312 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
313 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1);
316 $TableStr .=
"</tr>";
329 if (! is_array($Children)) {
332 $agent_pk = $TreeInfo[
'agent_pk'];
333 foreach ($Children as &$Child) {
337 $Child[
'licarray'] =
GetFileLicenses($agent_pk, 0, $Child[
'uploadtree_pk']);
338 $Child[
'licstr'] = implode(
", ", $Child[
'licarray']);
349 if (! is_array($Master)) {
353 foreach ($Master as $Key => &$Pair) {
354 if (empty($Pair[1]) or empty($Pair[2])) {
357 if (empty($Pair[1][
'pfile_fk'])) {
360 if (empty($Pair[2][
'pfile_fk'])) {
364 if ($Pair[1][
'pfile_fk'] == $Pair[2][
'pfile_fk']) {
365 unset($Master[$Key]);
378 foreach ($Master as $Key => &$Pair) {
379 if (empty($Pair[1]) or empty($Pair[2])) {
382 if (($Pair[1][
'ufile_name'] == $Pair[2][
'ufile_name']) &&
383 ($Pair[1][
'licstr'] == $Pair[2][
'licstr'])) {
384 unset($Master[$Key]);
397 foreach ($Master as $Key => &$Pair) {
398 if (empty($Pair[1]) or empty($Pair[2])) {
401 if (($Pair[1][
'fuzzyname'] == $Pair[2][
'fuzzyname']) &&
402 ($Pair[1][
'licstr'] == $Pair[2][
'licstr'])) {
403 unset($Master[$Key]);
420 $NoLicStr =
"No_license_found";
422 foreach ($Master as $Key => &$Pair) {
427 if ($Pair2[
'licstr'] == $NoLicStr) {
428 unset($Master[$Key]);
432 }
else if (empty($Pair2)) {
433 if ($Pair1[
'licstr'] == $NoLicStr) {
434 unset($Master[$Key]);
438 }
else if (($Pair1[
'licstr'] == $NoLicStr) and
439 ($Pair2[
'licstr'] == $NoLicStr)) {
440 unset($Master[$Key]);
482 function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1,
483 $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2)
486 $FreezeText = _(
"Freeze Path");
487 $FrozenText = _(
"Frozen, Click to unfreeze");
491 $OutBuf .=
"\n<script language='javascript'>\n";
493 $OutBuf .=
"function ChangeFilter(selectObj, utpk1, utpk2){";
494 $OutBuf .=
" var selectidx = selectObj.selectedIndex;";
495 $OutBuf .=
" var filter = selectObj.options[selectidx].value;";
496 $OutBuf .=
' window.location.assign("?mod=' . $this->Name .
497 '&item1="+utpk1+"&item2="+utpk2+"&filter=" + filter); ';
508 $OutBuf .=
"function Freeze(FreezeColNo) {";
509 $OutBuf .=
"var FreezeElt1 = document.getElementById('Freeze1');";
510 $OutBuf .=
"var FreezeElt2 = document.getElementById('Freeze2');";
511 $OutBuf .=
"var AddFreezeArg = 1; ";
513 $OutBuf .=
"var old_uploadtree_pk;\n";
516 $OutBuf .=
"if (FreezeColNo == '1')";
518 $OutBuf .=
"if (FreezeElt1.innerHTML == '$FrozenText') ";
520 $OutBuf .=
"FreezeElt1.innerHTML = '$FreezeText';";
521 $OutBuf .=
"FreezeElt1.style.backgroundColor = 'white'; ";
522 $OutBuf .=
"AddFreezeArg = 0;";
524 $OutBuf .=
"else { ";
525 $OutBuf .=
"FreezeElt1.innerHTML = '$FrozenText'; ";
526 $OutBuf .=
"FreezeElt1.style.backgroundColor = '#EAF7FB'; ";
527 $OutBuf .=
"FreezeElt2.innerHTML = '$FreezeText';";
528 $OutBuf .=
"FreezeElt2.style.backgroundColor = 'white';";
529 $OutBuf .=
"old_uploadtree_pk = $in_uploadtree_pk1;";
533 $OutBuf .=
"if (FreezeElt2.innerHTML == '$FrozenText') ";
535 $OutBuf .=
"FreezeElt2.innerHTML = '$FreezeText';";
536 $OutBuf .=
"FreezeElt2.style.backgroundColor = 'white';";
537 $OutBuf .=
"AddFreezeArg = 0;";
540 $OutBuf .=
"FreezeElt1.innerHTML = '$FreezeText';";
541 $OutBuf .=
"FreezeElt1.style.backgroundColor = 'white';";
542 $OutBuf .=
"FreezeElt2.innerHTML = '$FrozenText';";
543 $OutBuf .=
"FreezeElt2.style.backgroundColor = '#EAF7FB';";
544 $OutBuf .=
"old_uploadtree_pk = $in_uploadtree_pk2;";
549 $OutBuf .=
"var i=0;\n";
550 $OutBuf .=
"var linkid;\n";
551 $OutBuf .=
"var linkelt;\n";
552 $OutBuf .=
"var FreezeIdx;\n";
553 $OutBuf .=
"var BaseURL;\n";
554 $OutBuf .=
"var numlinks = document.links.length;\n";
555 $OutBuf .=
"for (i=0; i < numlinks; i++)\n";
557 $OutBuf .=
"linkelt = document.links[i];\n";
559 $OutBuf .=
"FreezeIdx = linkelt.href.indexOf('&freeze');\n";
560 $OutBuf .=
"if (FreezeIdx > 0) \n";
561 $OutBuf .=
"BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
563 $OutBuf .=
"BaseURL = linkelt.href; \n";
564 $OutBuf .=
"if (AddFreezeArg == 1) \n ";
565 $OutBuf .=
"linkelt.href = BaseURL + '&freeze=' + FreezeColNo + '&itemf=' + old_uploadtree_pk;";
566 $OutBuf .=
"else \n";
567 $OutBuf .=
"linkelt.href = BaseURL;";
570 $OutBuf .=
"</script>\n";
574 $SelectFilter =
"<select name='diff_filter' id='diff_filter' onchange='ChangeFilter(this,$uploadtree_pk1, $uploadtree_pk2)'>";
575 $Selected = ($filter ==
'none') ?
"selected" :
"";
576 $SelectFilter .=
"<option $Selected value='none'>0. Remove nothing";
577 $Selected = ($filter ==
'samehash') ?
"selected" :
"";
578 $SelectFilter .=
"<option $Selected value='samehash'>1. Remove duplicate (same hash) files";
579 $Selected = ($filter ==
'samelic') ?
"selected" :
"";
580 $SelectFilter .=
"<option $Selected value='samelic'>2. Remove duplicate files (different hash) with unchanged licenses";
581 $Selected = ($filter ==
'samelicfuzzy') ?
"selected" :
"";
582 $SelectFilter .=
"<option $Selected value='samelicfuzzy'>2b. Same as 2 but fuzzy match file names";
583 $Selected = ($filter ==
'nolics') ?
"selected" :
"";
584 $SelectFilter .=
"<option $Selected value='nolics'>3. Same as 2b. but also remove files with no license";
585 $SelectFilter .=
"</select>";
587 $StyleRt =
"style='float:right'";
588 $OutBuf .=
"<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
591 $text = _(
"Switch to bucket view");
593 $BucketURL .=
"?mod=bucketsdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
594 $OutBuf .=
"<a href='$BucketURL' $StyleRt > $text </a> ";
598 $OutBuf .=
"<table border=0 id='dirlist' $TableStyle>";
601 $OutBuf .=
"<tr><td colspan=5 align='center'>Filter: $SelectFilter<br> </td></tr>";
605 $Path1 =
Dir2Path($uploadtree_pk1, $TreeInfo1[
'uploadtree_tablename']);
606 $Path2 =
Dir2Path($uploadtree_pk2, $TreeInfo2[
'uploadtree_tablename']);
607 $OutBuf .=
"<td colspan=2>";
610 $OutBuf .=
"<td $this->ColumnSeparatorStyleL colspan=3>";
612 $OutBuf .=
"</td></tr>";
616 $TreeInfo2[
'agent_pk']);
619 $ColumnSeparatorStyleTop =
"style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
621 $OutBuf .=
"<td colspan=5 $ColumnSeparatorStyleTop>";
622 $OutBuf .=
"<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
628 $Tree1Hist = $this->
UploadHist($uploadtree_pk1, $TreeInfo1);
629 $OutBuf .=
"<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
630 $OutBuf .=
"<td $this->ColumnSeparatorStyleL> </td>";
631 $Tree2Hist = $this->
UploadHist($uploadtree_pk2, $TreeInfo2);
632 $OutBuf .=
"<td colspan=2 valign='top' align='center'>$Tree2Hist</td>";
633 $OutBuf .=
"</tr></table>\n";
635 $OutBuf .=
"<a href='#flist' style='float:right'> Jump to top </a><p>";
650 if ($this->
State != PLUGIN_STATE_READY) {
655 $uTime = microtime(
true);
665 $CacheKey =
"?mod=" . $this->Name .
676 $_SERVER[
'REQUEST_URI'] = preg_replace(
"/&updcache=[0-9]*/",
"",
677 $_SERVER[
'REQUEST_URI']);
678 unset($_GET[
'updcache']);
686 if (empty($filter)) {
687 $filter =
"samehash";
697 if (empty($in_uploadtree_pk1) or empty($in_uploadtree_pk2)) {
698 Fatal(
"Bad input parameters. Both item1 and item2 must be specified.",
706 if ($FreezeCol == $ClickedCol) {
712 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
714 $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1);
715 if (! $uploadDao->isAccessible($Item1Row[
'upload_fk'], Auth::getGroupId())) {
716 $text = _(
"Permission Denied");
717 return "<h2>$text item 1</h2>";
721 $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2);
722 if (! $uploadDao->isAccessible($Item2Row[
'upload_fk'], Auth::getGroupId())) {
723 $text = _(
"Permission Denied");
724 return "<h2>$text item 2</h2>";
727 $uploadtree_pk1 = $in_uploadtree_pk1;
728 $uploadtree_pk2 = $in_uploadtree_pk2;
732 if ($FreezeCol == 1) {
733 $uploadtree_pk1 = $ItemFrozen;
734 }
else if ($FreezeCol == 2) {
735 $uploadtree_pk2 = $ItemFrozen;
739 "&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
740 if (! empty($filter)) {
741 $newURL .=
"&filter=$filter";
745 if (($uploadtree_pk1 != $in_uploadtree_pk1) ||
746 ($uploadtree_pk2 != $in_uploadtree_pk2)) {
749 <script type=
"text/javascript">
750 window.location.assign(
'$newURL');
757 $ErrText = _(
"No license data for");
758 $ErrText2 = _(
"Use Jobs > Agents to schedule a license scan.");
760 if ($TreeInfo1[
'agent_pk'] == 0) {
761 $ErrMsg =
"$ErrText $TreeInfo1[ufile_name].<br>$ErrText2<p>";
762 }
else if ($TreeInfo2[
'agent_pk'] == 0) {
763 $ErrMsg =
"$ErrText $TreeInfo2[ufile_name].<br>$ErrText2<p>";
766 $Children1 = GetNonArtifactChildren($uploadtree_pk1);
767 $Children2 = GetNonArtifactChildren($uploadtree_pk2);
774 $this->
AddLicStr($TreeInfo1, $Children1);
775 $this->
AddLicStr($TreeInfo2, $Children2);
781 FileList($Master, $TreeInfo1[
'agent_pk'], $TreeInfo2[
'agent_pk'],
782 $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
788 switch ($this->OutputType) {
795 $V .= $this->
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2,
796 $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1,
809 if (! $this->OutputToStdout) {
813 $Time = microtime(
true) - $uTime;
814 $text = _(
"Elapsed time: %.2f seconds");
815 printf(
"<small>$text</small>", $Time);
819 $text1 = _(
"Update");
820 echo
" <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
833 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
Compare License Browser, list license histogram.
Install()
Create and configure database tables.
ChildElt($Child, $agent_pk, $OtherChild)
get the entire <td> ... </td> for $Child file listing table
UploadHist($Uploadtree_pk, $TreeInfo)
get history info for the directory BY LICENSE.
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2)
HTML output, returns HTML as string.
filter_nolics(&$Master)
removes pairs of "No_license_found"
filter_samelicfuzzy(&$Master)
removes files that have the same fuzzyname, and same license list.
filter_samelic(&$Master)
removes files that have the same name and license list.
AddLicStr($TreeInfo, &$Children)
Add license array to Children array.
FilterChildren($filter, &$Master)
filter children through same license, same hash, no license, same fuzzy license
filter_samehash(&$Master)
removes identical files
Initialize()
This is called before the plugin is used.
ItemComparisonRows($Master, $agent_pk1, $agent_pk2)
get a string with the html table rows comparing the two file lists.
Output()
generate output information
RegisterMenus()
Customize submenus.
GetTreeInfo($Uploadtree_pk)
get an array with uploadtree record and agent_pk
LatestAgentpk($upload_pk, $arsTableName, $arsSuccess=false)
Given an upload_pk, find the latest enabled agent_pk with results.
ReportCacheGet($CacheKey)
This function is used by Output() to see if the requested report is in the report cache.
ReportCachePut($CacheKey, $CacheValue)
This function is used to write a record to the report cache. If the record already exists,...
ReportCachePurgeByKey($CacheKey)
Purge from the report cache the record with $CacheKey.
FileList(&$Master, $agent_pk1, $agent_pk2, $filter, $plugin, $uploadtree_pk1, $uploadtree_pk2)
Adds the element linkurl to the $Master elements.
Dir2BrowseDiff($Path1, $Path2, $filter, $Column, $plugin)
Return a string which is a linked path to the file.
MakeMaster($Children1, $Children2)
Generate the master array with aligned children.
FuzzyName(&$Children)
Add fuzzyname and fuzzynameext to $Children.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
GetFileLicenses($agent, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree', $duplicate="")
get all the licenses for a single file or uploadtree
Traceback_uri()
Get the URI without query to this location.
Traceback_dir()
Get the directory of the URI without query.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
GetArrayVal($Key, $Arr)
Get the value from a array(map)
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.
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".
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN