18 var $ColumnSeparatorStyleL =
"style='border:solid 0 #006600; border-left-width:2px;padding-left:1em'";
23 $this->Name =
"bucketsdiff";
24 $this->Title = _(
"Compare Buckets Browser");
25 $this->Dependency = array(
"browse",
"view");
28 parent::__construct();
58 if ($this->
State != PLUGIN_STATE_INVALID) {
return(1); }
59 if ($this->Name !==
"")
62 $this->
State=PLUGIN_STATE_VALID;
66 return($this->
State == PLUGIN_STATE_VALID);
82 $TreeInfo =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $Uploadtree_pk");
83 $TreeInfo[
'agent_pk'] =
LatestAgentpk($TreeInfo[
'upload_fk'],
"nomos_ars");
88 "onchange=\"addArsGo('newds','selectbdata');\"");
89 $TreeInfo[
'ars_pk'] = $ars_pk;
97 $where =
"where ars_pk=$ars_pk";
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"];
116 function UploadHist($Uploadtree_pk, $TreeInfo, $BucketDefArray)
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'];
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";
145 $historows = pg_fetch_all($result);
146 pg_free_result($result);
151 if (!empty($BucketSelect))
153 $action =
Traceback_uri() .
"?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk";
155 $HistStr .=
"<script type='text/javascript'>
156 function addArsGo(formid, selectid )
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();
167 $HistStr .=
"<form action='$action' id='newds' method='POST'>\n";
168 $HistStr .= $BucketSelect;
169 $HistStr .=
"</form>";
174 if (count($historows) == 0)
return $HistStr;
176 $sql =
"select bucketpool_name from bucketpool where bucketpool_pk=$bucketpool_pk";
179 $row = pg_fetch_assoc($result);
180 $bucketpool_name = $row[
'bucketpool_name'];
181 pg_free_result($result);
186 $HistStr .=
"<table border=1 id='histogram'>\n";
189 $HistStr .=
"<tr><th >$text</th>";
192 $HistStr .=
"<th >$text</th>";
195 $HistStr .=
"<th align=left>$text</th></tr>\n";
197 if(empty($historows))
201 foreach ($historows as $row)
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'];
210 $HistStr .=
"<tr><td align='right' style='background-color:$bucket_color'>$row[bucketcount]</td>";
213 $ShowTitle = _(
"Click Show to list files with this license.");
214 $HistStr .=
"<td align='center'><a href='";
218 $HistStr .=
"?mod=list_bucket_files&bapk=$bucketagent_pk&item=$Uploadtree_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk" .
"'>$text</a></td>";
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>";
225 $HistStr .=
"</tr>\n";
227 $HistStr .=
"</table>\n";
246 function ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
248 $UniqueTagArray = array();
249 $bucketstr = $Child[
'bucketstr'];
254 if ($Child and $OtherChild)
257 foreach ($Child[
'bucketarray'] as $bucket_pk)
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'];
264 if (!empty($bucketstr)) $bucketstr .=
", ";
265 if (in_array($bucket_pk, $OtherChild[
'bucketarray']))
268 $Style = $BucketStyle;
275 $bucketstr .=
"<span $Style>$bucket_name</span>";
279 $ColStr =
"<td id='$Child[uploadtree_pk]' align='left'>";
280 $ColStr .=
"$Child[linkurl]";
283 $ColStr .=
"<span style='position:relative;left:1em'>";
284 $ColStr .= $bucketstr;
285 $ColStr .=
"</span>";
289 $ColStr .=
"<td valign='top'>";
291 $ColStr .=
FileListLinks($Child[
'upload_fk'], $Child[
'uploadtree_pk'], $agent_pk, $Child[
'pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
314 $RowStyle1 =
"style='background-color:#ecfaff'";
315 $RowStyle2 =
"style='background-color:#ffffe3'";
318 foreach ($Master as $key => $Pair)
320 $RowStyle = (++$RowNum % 2) ? $RowStyle1 : $RowStyle2;
321 $TableStr .=
"<tr $RowStyle>";
327 $TableStr .=
"<td></td><td></td>";
328 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
329 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
331 else if (empty($Child2))
333 $TableStr .= $this->
ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
334 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
335 $TableStr .=
"<td></td><td></td>";
337 else if (!empty($Child1) and !empty($Child2))
339 $TableStr .= $this->
ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
340 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
341 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
344 $TableStr .=
"</tr>";
360 if (!is_array($Children))
return;
361 $agent_pk = $TreeInfo[
'agent_pk'];
362 foreach($Children as &$Child)
364 $Child[
'bucketarray'] =
GetFileBuckets($TreeInfo[
'nomosagent_pk'], $TreeInfo[
'bucketagent_pk'], $Child[
'uploadtree_pk'], $TreeInfo[
'bucketpool_pk']);
366 $Child[
'bucketstr'] =
GetFileBuckets_string($TreeInfo[
'nomosagent_pk'], $TreeInfo[
'bucketagent_pk'], $Child[
'uploadtree_pk'], $BucketDefArray,
",", True);
381 foreach($MyArray as $bucket_pk)
383 $bucket_evalorder = $BucketDefArray[$bucket_pk][
'bucket_evalorder'];
384 if ($bucket_evalorder > $Threshold)
return False;
427 foreach($Master as $Key =>&$Pair)
432 if (empty($Pair1) or empty($Pair2))
continue;
433 if ($Pair1[
'bucketstr'] == $Pair2[
'bucketstr'])
434 unset($Master[$Key]);
451 case 'samebucketlist':
473 function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
476 $FreezeText = _(
"Freeze Path");
477 $FrozenText = _(
"Frozen, Click to unfreeze");
481 $OutBuf .=
"\n<script language='javascript'>\n";
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); ';
496 $OutBuf .=
"function Freeze(FreezeColNo) {";
497 $OutBuf .=
"var FreezeElt1 = document.getElementById('Freeze1');";
498 $OutBuf .=
"var FreezeElt2 = document.getElementById('Freeze2');";
499 $OutBuf .=
"var AddFreezeArg = 1; ";
500 $OutBuf .=
"var old_uploadtree_pk;\n";
503 $OutBuf .=
"if (FreezeColNo == '1')";
505 $OutBuf .=
"if (FreezeElt1.innerHTML == '$FrozenText') ";
507 $OutBuf .=
"FreezeElt1.innerHTML = '$FreezeText';";
508 $OutBuf .=
"FreezeElt1.style.backgroundColor = 'white'; ";
509 $OutBuf .=
"AddFreezeArg = 0;";
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;";
520 $OutBuf .=
"if (FreezeElt2.innerHTML == '$FrozenText') ";
522 $OutBuf .=
"FreezeElt2.innerHTML = '$FreezeText';";
523 $OutBuf .=
"FreezeElt2.style.backgroundColor = 'white';";
524 $OutBuf .=
"AddFreezeArg = 0;";
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;";
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";
544 $OutBuf .=
"linkelt = document.links[i];\n";
546 $OutBuf .=
"FreezeIdx = linkelt.href.indexOf('&freeze');\n";
547 $OutBuf .=
"if (FreezeIdx > 0) \n";
548 $OutBuf .=
"BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
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;";
557 $OutBuf .=
"</script>\n";
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";
566 $Selected = ($filter ==
'samebucketlist') ?
"selected" :
"";
567 $SelectFilter .=
"<option $Selected value='samebucketlist'>Remove unchanged bucket lists";
568 $SelectFilter .=
"</select>";
570 $StyleRt =
"style='float:right'";
571 $OutBuf .=
"<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
574 $text = _(
"Switch to license view");
576 $switchURL .=
"?mod=nomosdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
577 $OutBuf .=
"<a href='$switchURL' $StyleRt > $text </a> ";
582 $OutBuf .=
"<table border=0 id='dirlist' $TableStyle>";
585 $OutBuf .=
"<tr><td colspan=5 align='center'>Filter: $SelectFilter<br> </td></tr>";
591 $OutBuf .=
"<td colspan=2>";
594 $OutBuf .=
"<td $this->ColumnSeparatorStyleL colspan=3>";
596 $OutBuf .=
"</td></tr>";
599 $OutBuf .= $this->
ItemComparisonRows($Master, $TreeInfo1[
'agent_pk'], $TreeInfo2[
'agent_pk'], $BucketDefArray);
602 $ColumnSeparatorStyleTop =
"style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
604 $OutBuf .=
"<td colspan=5 $ColumnSeparatorStyleTop>";
605 $OutBuf .=
"<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
611 $Tree1Hist = $this->
UploadHist($uploadtree_pk1, $TreeInfo1, $BucketDefArray);
612 $OutBuf .=
"<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
613 $OutBuf .=
"<td $this->ColumnSeparatorStyleL> </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";
618 $OutBuf .=
"<a href='#flist' style='float:right'> Jump to top </a><p>";
636 if ($this->
State != PLUGIN_STATE_READY) {
return(0); }
638 $uTime = microtime(
true);
647 $CacheKey =
"?mod=" . $this->Name .
Traceback_parm_keep(array(
"item1",
"item2",
"filter",
"col",
"freeze",
"itemf"));
651 $UpdCache = $_GET[
'updcache'];
652 $_SERVER[
'REQUEST_URI'] = preg_replace(
"/&updcache=[0-9]*/",
"",$_SERVER[
'REQUEST_URI']);
653 unset($_GET[
'updcache']);
659 $Cached = !empty($V);
665 if (!$this->OutputToStdout) {
return($V); }
667 $Time = microtime(
true) - $uTime;
668 $text = _(
"Elapsed time: %.2f seconds");
669 printf(
"<small>$text</small>", $Time);
674 $text1 = _(
"Update");
675 echo
" <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
677 else if ($Time > 0.5)
691 if (empty($filter)) $filter =
"none";
698 if (empty($in_uploadtree_pk1) || empty($in_uploadtree_pk2))
699 Fatal(
"Bad input parameters. Both item1 and item2 must be specified.", __FILE__, __LINE__);
702 if ($FreezeCol == $ClickedCol)
709 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
711 $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1);
712 if ( !$uploadDao->isAccessible($Item1Row[
'upload_fk'], Auth::getGroupId()) )
714 $text = _(
"Permission Denied");
715 return "<h2>$text item 1</h2>";
719 $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2);
720 if (!$uploadDao->isAccessible($Item2Row[
'upload_fk'], Auth::getGroupId()))
722 $text = _(
"Permission Denied");
723 return "<h2>$text item 2</h2>";
726 $uploadtree_pk1 = $in_uploadtree_pk1;
727 $uploadtree_pk2 = $in_uploadtree_pk2;
731 $uploadtree_pk1 = $ItemFrozen;
733 else if ($FreezeCol == 2)
735 $uploadtree_pk2 = $ItemFrozen;
739 $newURL =
Traceback_dir() .
"?mod=" . $this->Name .
"&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
740 if (!empty($filter)) $newURL .=
"&filter=$filter";
743 if (($uploadtree_pk1 != $in_uploadtree_pk1)
744 || ($uploadtree_pk2 != $in_uploadtree_pk2))
747 <script type=
"text/javascript">
748 window.location.assign(
'$newURL');
755 $ErrText = _(
"No license data for tree %d. Use Jobs > Agents to schedule a license scan.");
757 if ($TreeInfo1[
'agent_pk'] == 0)
759 $ErrMsg = sprintf($ErrText, 1);
762 if ($TreeInfo2[
'agent_pk'] == 0)
764 $ErrMsg = sprintf($ErrText, 2);
770 $BucketDefArray = $BucketDefArray1 + $BucketDefArray2;
773 $Children1 = GetNonArtifactChildren($uploadtree_pk1);
774 $Children2 = GetNonArtifactChildren($uploadtree_pk2);
781 $this->
AddBucketStr($TreeInfo1, $Children1, $BucketDefArray);
782 $this->
AddBucketStr($TreeInfo2, $Children2, $BucketDefArray);
788 FileList($Master, $TreeInfo1[
'agent_pk'], $TreeInfo2[
'agent_pk'], $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
794 if($this->OutputType==
'HTML')
799 $V .= $this->
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray);
807 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
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.
AddBucketStr($TreeInfo, &$Children, $BucketDefArray)
Add bucket_pk array and string to Children array.
__construct()
base constructor. Most plugins will just use this
GetTreeInfo($Uploadtree_pk)
Get uploadtree info for a given uploadtree_pk.
Output()
This function is called when user output is requested. This function is responsible for content....
Install()
Create and configure database tables.
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.
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]
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