29 var $ColumnSeparatorStyleL =
"style='border:solid 0 #006600; border-left-width:2px;padding-left:1em'";
32 function __construct()
34 $this->Name =
"bucketsdiff";
35 $this->Title = _(
"Compare Buckets Browser");
36 $this->Dependency = array(
"browse",
"view");
39 parent::__construct();
49 if (empty($PG_CONN)) {
return(1); }
69 if ($this->
State != PLUGIN_STATE_INVALID) {
return(1); }
70 if ($this->Name !==
"")
73 $this->
State=PLUGIN_STATE_VALID;
74 array_push($Plugins,$this);
77 return($this->
State == PLUGIN_STATE_VALID);
93 $TreeInfo =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $Uploadtree_pk");
94 $TreeInfo[
'agent_pk'] =
LatestAgentpk($TreeInfo[
'upload_fk'],
"nomos_ars");
99 "onchange=\"addArsGo('newds','selectbdata');\"");
100 $TreeInfo[
'ars_pk'] = $ars_pk;
104 return $BucketSelect;
108 $where =
"where ars_pk=$ars_pk";
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"];
127 function UploadHist($Uploadtree_pk, $TreeInfo, $BucketDefArray)
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'];
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);
156 $historows = pg_fetch_all($result);
157 pg_free_result($result);
162 if (!empty($BucketSelect))
164 $action =
Traceback_uri() .
"?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk";
166 $HistStr .=
"<script type='text/javascript'> 167 function addArsGo(formid, selectid ) 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(); 178 $HistStr .=
"<form action='$action' id='newds' method='POST'>\n";
179 $HistStr .= $BucketSelect;
180 $HistStr .=
"</form>";
185 if (count($historows) == 0)
return $HistStr;
187 $sql =
"select bucketpool_name from bucketpool where bucketpool_pk=$bucketpool_pk";
188 $result = pg_query($PG_CONN, $sql);
190 $row = pg_fetch_assoc($result);
191 $bucketpool_name = $row[
'bucketpool_name'];
192 pg_free_result($result);
197 $HistStr .=
"<table border=1 id='histogram'>\n";
200 $HistStr .=
"<tr><th >$text</th>";
203 $HistStr .=
"<th >$text</th>";
206 $HistStr .=
"<th align=left>$text</th></tr>\n";
208 if(empty($historows))
212 foreach ($historows as $row)
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'];
221 $HistStr .=
"<tr><td align='right' style='background-color:$bucket_color'>$row[bucketcount]</td>";
224 $ShowTitle = _(
"Click Show to list files with this license.");
225 $HistStr .=
"<td align='center'><a href='";
229 $HistStr .=
"?mod=list_bucket_files&bapk=$bucketagent_pk&item=$Uploadtree_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk" .
"'>$text</a></td>";
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>";
236 $HistStr .=
"</tr>\n";
238 $HistStr .=
"</table>\n";
257 function ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
259 $UniqueTagArray = array();
260 $bucketstr = $Child[
'bucketstr'];
265 if ($OtherChild and $OtherChild)
268 foreach ($Child[
'bucketarray'] as $bucket_pk)
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'];
275 if (!empty($bucketstr)) $bucketstr .=
", ";
276 if (in_array($bucket_pk, $OtherChild[
'bucketarray']))
279 $Style = $BucketStyle;
286 $bucketstr .=
"<span $Style>$bucket_name</span>";
290 $ColStr =
"<td id='$Child[uploadtree_pk]' align='left'>";
291 $ColStr .=
"$Child[linkurl]";
294 $ColStr .=
"<span style='position:relative;left:1em'>";
295 $ColStr .= $bucketstr;
296 $ColStr .=
"</span>";
300 $ColStr .=
"<td valign='top'>";
302 $ColStr .=
FileListLinks($Child[
'upload_fk'], $Child[
'uploadtree_pk'], $agent_pk, $Child[
'pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
325 $RowStyle1 =
"style='background-color:#ecfaff'";
326 $RowStyle2 =
"style='background-color:#ffffe3'";
329 foreach ($Master as $key => $Pair)
331 $RowStyle = (++$RowNum % 2) ? $RowStyle1 : $RowStyle2;
332 $TableStr .=
"<tr $RowStyle>";
338 $TableStr .=
"<td></td><td></td>";
339 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
340 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
342 else if (empty($Child2))
344 $TableStr .= $this->
ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
345 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
346 $TableStr .=
"<td></td><td></td>";
348 else if (!empty($Child1) and !empty($Child2))
350 $TableStr .= $this->
ChildElt($Child1, $agent_pk1, $Child2, $BucketDefArray);
351 $TableStr .=
"<td $this->ColumnSeparatorStyleL> </td>";
352 $TableStr .= $this->
ChildElt($Child2, $agent_pk2, $Child1, $BucketDefArray);
355 $TableStr .=
"</tr>";
371 if (!is_array($Children))
return;
372 $agent_pk = $TreeInfo[
'agent_pk'];
373 foreach($Children as &$Child)
375 $Child[
'bucketarray'] =
GetFileBuckets($TreeInfo[
'nomosagent_pk'], $TreeInfo[
'bucketagent_pk'], $Child[
'uploadtree_pk'], $TreeInfo[
'bucketpool_pk']);
377 $Child[
'bucketstr'] =
GetFileBuckets_string($TreeInfo[
'nomosagent_pk'], $TreeInfo[
'bucketagent_pk'], $Child[
'uploadtree_pk'], $BucketDefArray,
",", True);
392 foreach($MyArray as $bucket_pk)
394 $bucket_evalorder = $BucketDefArray[$bucket_pk][
'bucket_evalorder'];
395 if ($bucket_evalorder > $Threshold)
return False;
438 foreach($Master as $Key =>&$Pair)
443 if (empty($Pair1) or empty($Pair2))
continue;
444 if ($Pair1[
'bucketstr'] == $Pair2[
'bucketstr'])
445 unset($Master[$Key]);
462 case 'samebucketlist':
484 function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
487 $FreezeText = _(
"Freeze Path");
488 $FrozenText = _(
"Frozen, Click to unfreeze");
492 $OutBuf .=
"\n<script language='javascript'>\n";
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); ';
507 $OutBuf .=
"function Freeze(FreezeColNo) {";
508 $OutBuf .=
"var FreezeElt1 = document.getElementById('Freeze1');";
509 $OutBuf .=
"var FreezeElt2 = document.getElementById('Freeze2');";
510 $OutBuf .=
"var AddFreezeArg = 1; ";
511 $OutBuf .=
"var old_uploadtree_pk;\n";
514 $OutBuf .=
"if (FreezeColNo == '1')";
516 $OutBuf .=
"if (FreezeElt1.innerHTML == '$FrozenText') ";
518 $OutBuf .=
"FreezeElt1.innerHTML = '$FreezeText';";
519 $OutBuf .=
"FreezeElt1.style.backgroundColor = 'white'; ";
520 $OutBuf .=
"AddFreezeArg = 0;";
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;";
531 $OutBuf .=
"if (FreezeElt2.innerHTML == '$FrozenText') ";
533 $OutBuf .=
"FreezeElt2.innerHTML = '$FreezeText';";
534 $OutBuf .=
"FreezeElt2.style.backgroundColor = 'white';";
535 $OutBuf .=
"AddFreezeArg = 0;";
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;";
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";
555 $OutBuf .=
"linkelt = document.links[i];\n";
557 $OutBuf .=
"FreezeIdx = linkelt.href.indexOf('&freeze');\n";
558 $OutBuf .=
"if (FreezeIdx > 0) \n";
559 $OutBuf .=
"BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
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;";
568 $OutBuf .=
"</script>\n";
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";
577 $Selected = ($filter ==
'samebucketlist') ?
"selected" :
"";
578 $SelectFilter .=
"<option $Selected value='samebucketlist'>Remove unchanged bucket lists";
579 $SelectFilter .=
"</select>";
581 $StyleRt =
"style='float:right'";
582 $OutBuf .=
"<a name='flist' href='#histo' $StyleRt > Jump to histogram </a><br>";
585 $text = _(
"Switch to license view");
587 $switchURL .=
"?mod=nomosdiff&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
588 $OutBuf .=
"<a href='$switchURL' $StyleRt > $text </a> ";
593 $OutBuf .=
"<table border=0 id='dirlist' $TableStyle>";
596 $OutBuf .=
"<tr><td colspan=5 align='center'>Filter: $SelectFilter<br> </td></tr>";
602 $OutBuf .=
"<td colspan=2>";
605 $OutBuf .=
"<td $this->ColumnSeparatorStyleL colspan=3>";
607 $OutBuf .=
"</td></tr>";
610 $OutBuf .= $this->
ItemComparisonRows($Master, $TreeInfo1[
'agent_pk'], $TreeInfo2[
'agent_pk'], $BucketDefArray);
613 $ColumnSeparatorStyleTop =
"style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
615 $OutBuf .=
"<td colspan=5 $ColumnSeparatorStyleTop>";
616 $OutBuf .=
"<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
622 $Tree1Hist = $this->
UploadHist($uploadtree_pk1, $TreeInfo1, $BucketDefArray);
623 $OutBuf .=
"<td colspan=2 valign='top' align='center'>$Tree1Hist</td>";
624 $OutBuf .=
"<td $this->ColumnSeparatorStyleL> </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";
629 $OutBuf .=
"<a href='#flist' style='float:right'> Jump to top </a><p>";
647 if ($this->
State != PLUGIN_STATE_READY) {
return(0); }
649 $uTime = microtime(
true);
658 $CacheKey =
"?mod=" . $this->Name .
Traceback_parm_keep(array(
"item1",
"item2",
"filter",
"col",
"freeze",
"itemf"));
662 $UpdCache = $_GET[
'updcache'];
663 $_SERVER[
'REQUEST_URI'] = preg_replace(
"/&updcache=[0-9]*/",
"",$_SERVER[
'REQUEST_URI']);
664 unset($_GET[
'updcache']);
670 $Cached = !empty($V);
676 if (!$this->OutputToStdout) {
return($V); }
678 $Time = microtime(
true) - $uTime;
679 $text = _(
"Elapsed time: %.2f seconds");
680 printf(
"<small>$text</small>", $Time);
685 $text1 = _(
"Update");
686 echo
" <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
688 else if ($Time > 0.5)
702 if (empty($filter)) $filter =
"none";
709 if (empty($in_uploadtree_pk1) || empty($in_uploadtree_pk2))
710 Fatal(
"Bad input parameters. Both item1 and item2 must be specified.", __FILE__, __LINE__);
713 if ($FreezeCol == $ClickedCol)
720 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
722 $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1);
723 if ( !$uploadDao->isAccessible($Item1Row[
'upload_fk'], Auth::getGroupId()) )
725 $text = _(
"Permission Denied");
726 return "<h2>$text item 1</h2>";
730 $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2);
731 if (!$uploadDao->isAccessible($Item2Row[
'upload_fk'], Auth::getGroupId()))
733 $text = _(
"Permission Denied");
734 return "<h2>$text item 2</h2>";
737 $uploadtree_pk1 = $in_uploadtree_pk1;
738 $uploadtree_pk2 = $in_uploadtree_pk2;
742 $uploadtree_pk1 = $ItemFrozen;
744 else if ($FreezeCol == 2)
746 $uploadtree_pk2 = $ItemFrozen;
750 $newURL =
Traceback_dir() .
"?mod=" . $this->Name .
"&item1=$uploadtree_pk1&item2=$uploadtree_pk2";
751 if (!empty($filter)) $newURL .=
"&filter=$filter";
754 if (($uploadtree_pk1 != $in_uploadtree_pk1)
755 || ($uploadtree_pk2 != $in_uploadtree_pk2))
758 <script type=
"text/javascript">
759 window.location.assign(
'$newURL');
766 $ErrText = _(
"No license data for tree %d. Use Jobs > Agents to schedule a license scan.");
768 if ($TreeInfo1[
'agent_pk'] == 0)
770 $ErrMsg = sprintf($ErrText, 1);
773 if ($TreeInfo2[
'agent_pk'] == 0)
775 $ErrMsg = sprintf($ErrText, 2);
781 $BucketDefArray = $BucketDefArray1 + $BucketDefArray2;
784 $Children1 = GetNonArtifactChildren($uploadtree_pk1);
785 $Children2 = GetNonArtifactChildren($uploadtree_pk2);
792 $this->
AddBucketStr($TreeInfo1, $Children1, $BucketDefArray);
793 $this->
AddBucketStr($TreeInfo2, $Children2, $BucketDefArray);
799 FileList($Master, $TreeInfo1[
'agent_pk'], $TreeInfo2[
'agent_pk'], $filter, $this, $uploadtree_pk1, $uploadtree_pk2);
805 if($this->OutputType==
'HTML')
810 $V .= $this->
HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray);
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"...
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.
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.
Install()
Create and configure database tables.
GetTreeInfo($Uploadtree_pk)
Get uploadtree info for a given uploadtree_pk.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
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.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
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.
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:
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'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.
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)
Initialize()
This is called before the plugin is used.
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.