32 function __construct()
34 $this->Name =
"bucketbrowser";
35 $this->Title = _(
"Bucket Browser");
36 $this->Dependency = array(
"browse",
"view");
39 parent::__construct();
50 if (empty($PG_CONN)) {
68 $sql =
"SELECT bucketpool_pk FROM bucketpool limit 1";
69 $result = pg_query($PG_CONN, $sql);
71 if (pg_num_rows($result) > 0)
73 pg_free_result($result);
78 $DemoPoolName =
"GPL Demo bucket pool";
79 $sql =
"INSERT INTO bucketpool (bucketpool_name, version, active, description) VALUES ('$DemoPoolName', 1, 'Y', 'Demonstration of a very simple GPL/non-gpl bucket pool')";
80 $result = pg_query($PG_CONN, $sql);
82 pg_free_result($result);
85 $sql =
"select bucketpool_pk from bucketpool 86 where bucketpool_name='$DemoPoolName' limit 1";
87 $result = pg_query($PG_CONN, $sql);
89 $row = pg_fetch_assoc($result);
90 $bucketpool_pk = $row[
'bucketpool_pk'];
91 pg_free_result($result);
94 $sql =
"INSERT INTO bucketpool (bucketpool_name, version, active, description) VALUES ('$DemoPoolName', 1, 'Y', 'Demonstration of a very simple GPL/non-gpl bucket pool')";
95 $Columns =
"bucket_name, bucket_color, bucket_reportorder, bucket_evalorder, bucketpool_fk, bucket_type, bucket_regex, stopon, applies_to";
96 $sql =
"INSERT INTO bucket_def ($Columns) VALUES ('GPL Licenses (Demo)', 'orange', 50, 50, $bucketpool_pk, 3, '(affero|gpl)', 'N', 'f'); 97 INSERT INTO bucket_def ($Columns) VALUES ('non-gpl (Demo)', 'yellow', 50, 1000, $bucketpool_pk, 99, NULL, 'N', 'f')";
98 $result = pg_query($PG_CONN, $sql);
100 pg_free_result($result);
114 if (!empty($Item) && !empty($Upload))
116 $menuText =
"Bucket";
119 $tooltipText = _(
"Browse by buckets");
120 $this->microMenu->insert(array(MicroMenu::VIEW_META, MicroMenu::VIEW), $menuText, $menuPosition, $this->
getName(), $URI, $tooltipText);
139 if ($this->
State != PLUGIN_STATE_INVALID) {
142 if ($this->Name !==
"")
145 $this->
State=PLUGIN_STATE_VALID;
146 array_push($Plugins,$this);
149 return($this->
State == PLUGIN_STATE_VALID);
168 $UniqueTagArray = array();
171 $ModLicView = &$Plugins[plugin_find_id(
"view-license")];
175 $sql =
"SELECT lft,rgt,upload_fk FROM $this->uploadtree_tablename 176 WHERE uploadtree_pk = $Uploadtree_pk";
177 $result = pg_query($PG_CONN, $sql);
179 if (pg_num_rows($result) < 1)
181 pg_free_result($result);
182 $text = _(
"Invalid URL, nonexistant item");
183 return "<h2>$text $Uploadtree_pk</h2>";
185 $row = pg_fetch_assoc($result);
188 $upload_pk = $row[
"upload_fk"];
189 pg_free_result($result);
194 "onchange=\"addArsGo('newds','selectbdata');\"");
198 return $BucketSelect;
202 $sql =
"select agent_fk, nomosagent_fk, bucketpool_fk from bucket_ars where ars_pk=$ars_pk";
203 $result = pg_query($PG_CONN, $sql);
205 $row = pg_fetch_assoc($result);
206 $bucketagent_pk = $row[
"agent_fk"];
207 $nomosagent_pk = $row[
"nomosagent_fk"];
208 $bucketpool_pk = $row[
"bucketpool_fk"];
209 pg_free_result($result);
217 $sql =
"SELECT distinct(bucket_fk) as bucket_pk, 218 count(bucket_fk) as bucketcount, bucket_reportorder 219 from bucket_file, bucket_def, 220 (SELECT distinct(pfile_fk) as PF from $this->uploadtree_tablename 221 where upload_fk=$upload_pk 222 and ((ufile_mode & (1<<28))=0) 223 and ((ufile_mode & (1<<29))=0) 224 and $this->uploadtree_tablename.lft BETWEEN $lft and $rgt) as SS 225 where PF=pfile_fk and agent_fk=$bucketagent_pk 226 and bucket_file.nomosagent_fk=$nomosagent_pk 227 and bucket_pk=bucket_fk 228 and bucketpool_fk=$bucketpool_pk 229 group by bucket_fk,bucket_reportorder 230 order by bucket_reportorder asc";
231 $result = pg_query($PG_CONN, $sql);
233 $historows = pg_fetch_all($result);
234 pg_free_result($result);
237 if (!empty($BucketSelect))
239 $action =
Traceback_uri() .
"?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk";
241 $VLic .=
"<script type='text/javascript'> 242 function addArsGo(formid, selectid ) 244 var selectobj = document.getElementById(selectid); 245 var ars_pk = selectobj.options[selectobj.selectedIndex].value; 246 document.getElementById(formid).action='$action'+'&ars='+ars_pk; 247 document.getElementById(formid).submit(); 253 $VLic .=
"<form action='$action' id='newds' method='POST'>\n";
254 $VLic .= $BucketSelect;
258 $sql =
"select bucketpool_name, version from bucketpool where bucketpool_pk=$bucketpool_pk";
259 $result = pg_query($PG_CONN, $sql);
261 $row = pg_fetch_assoc($result);
262 $bucketpool_name = $row[
'bucketpool_name'];
263 $bucketpool_version = $row[
'version'];
264 pg_free_result($result);
268 $Uniquebucketcount = 0;
270 if (is_array($historows))
272 $text = _(
"Bucket Pool");
273 $VLic .=
"$text: $bucketpool_name v$bucketpool_version<br>";
274 $VLic .=
"<table border=1 width='100%'>\n";
276 $VLic .=
"<tr><th width='10%'>$text</th>";
278 $VLic .=
"<th width='10%'>$text</th>";
280 $VLic .=
"<th align='left'>$text</th></tr>\n";
282 foreach($historows as $bucketrow)
284 $Uniquebucketcount++;
285 $bucket_pk = $bucketrow[
'bucket_pk'];
286 $bucketcount = $bucketrow[
'bucketcount'];
287 $bucket_name = $bucketDefArray[$bucket_pk][
'bucket_name'];
288 $bucket_color = $bucketDefArray[$bucket_pk][
'bucket_color'];
291 $VLic .=
"<tr><td align='right' style='background-color:$bucket_color'>$bucketcount</td>";
294 $VLic .=
"<td align='center'><a href='";
297 $VLic .=
"?mod=list_bucket_files&bapk=$bucketagent_pk&item=$Uploadtree_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk" .
"'>$text</a></td>";
300 $VLic .=
"<td align='left'>";
301 $VLic .=
"<a id='$bucket_pk' onclick='FileColor_Get(\"" .
Traceback_uri() .
"?mod=ajax_filebucket&bapk=$bucketagent_pk&item=$Uploadtree_pk&bucket_pk=$bucket_pk\")'";
302 $VLic .=
">$bucket_name </a>";
314 $VLic .=
"</table>\n";
316 $text = _(
"Unique buckets");
317 $VLic .=
"$text: $Uniquebucketcount<br>\n";
325 if (count($Children) == 0)
327 $sql =
"SELECT * FROM $this->uploadtree_tablename WHERE uploadtree_pk = '$Uploadtree_pk'";
328 $result = pg_query($PG_CONN, $sql);
330 $row = pg_fetch_assoc($result);
331 pg_free_result($result);
332 if (empty($row) || (
IsDir($row[
'ufile_mode']))) {
350 $VF .=
"<table border=0>";
351 foreach($Children as $C)
362 $IsDir =
Isdir($C[
'ufile_mode']);
366 if (!empty($C[
'pfile_fk']) && !empty($ModLicView))
369 $LinkUri .=
"?mod=view-license&napk=$nomosagent_pk&bapk=$bucketagent_pk&upload=$upload_pk&item=$C[uploadtree_pk]";
381 $LicUri =
"$tmpuri&item=" . $uploadtree_pk;
390 $VF .=
"<tr><td id='$C[uploadtree_pk]' align='left'>";
395 $VF .=
"<a href='$LicUri'>"; $HasHref=1;
396 $VF .=
"<b>"; $HasBold=1;
398 else if (!empty($LinkUri))
400 $VF .=
"<a href='$LinkUri'>"; $HasHref=1;
402 $VF .= $C[
'ufile_name'];
415 $VF .=
"<span style='position:relative;left:1em'>";
418 $bucketDefArray,
",", True);
420 $VF .=
"</td><td valign='top'>";
437 <script type=\"text/javascript\" charset=\"utf-8\"> 438 var Lastutpks=''; /* save last list of uploadtree_pk's */ 439 var Lastbupk=''; /* save last bucket_pk */ 440 var color = '#4bfe78'; 441 function FileColor_Reply() 443 if ((FileColor.readyState==4) && (FileColor.status==200)) 445 /* remove previous highlighting */ 446 var numpks = Lastutpks.length; 447 if (numpks > 0) document.getElementById(Lastbupk).style.backgroundColor='white'; 450 document.getElementById(Lastutpks[--numpks]).style.backgroundColor='white'; 453 utpklist = FileColor.responseText.split(','); 454 Lastbupk = utpklist.shift(); 455 numpks = utpklist.length; 456 Lastutpks = utpklist; 458 /* apply new highlighting */ 459 elt = document.getElementById(Lastbupk); 460 if (elt != null) elt.style.backgroundColor=color; 463 document.getElementById(utpklist[--numpks]).style.backgroundColor=color; 485 $V .=
"<table border=0 width='100%'>\n";
486 $V .=
"<tr><td valign='top' width='50%'>$VLic</td><td valign='top'>$VF</td></tr>\n";
503 function TagBucket($upload_pk, $uploadtree_pk, $bucketagent_pk, $bucket_pk, $bucketpool_pk, $nomosagent_pk)
514 $uTime = microtime(
true);
518 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
519 if ( !$uploadDao->isAccessible($Upload, Auth::getGroupId()) )
521 $text = _(
"Permission Denied");
522 return "<h2>$text</h2>";
528 return _(
'No item selected');
540 $CacheKey =
"?mod=" . $this->Name .
Traceback_parm_keep(array(
"upload",
"item",
"folder",
"ars")) ;
543 $_SERVER[
'REQUEST_URI'] = preg_replace(
"/&updcache=[0-9]*/",
"",$_SERVER[
'REQUEST_URI']);
544 unset($_GET[
'updcache']);
552 if (!empty($tagbucket))
558 $this->
TagBucket($Upload, $Item, $bucketagent_pk, $bucket_pk, $bucketpool_pk, $nomosagent_pk);
561 $Cached = !empty($V);
564 $V .=
"<font class='text'>\n";
567 if (count($Children) == 0)
574 $Uri = preg_replace(
"/&item=([0-9]*)/",
"",
Traceback());
578 $text = _(
"Loading...");
581 $Time = microtime(
true) - $uTime;
582 $text = _(
"Elapsed time: %.2f seconds");
583 $V .= sprintf(
"<p><small>$text</small>", $Time);
587 $text1 = _(
"Update");
588 echo
" <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>";
590 else if ($Time > 0.5)
600 $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"...
TagBucket($upload_pk, $uploadtree_pk, $bucketagent_pk, $bucket_pk, $bucketpool_pk, $nomosagent_pk)
Tag a bucket.
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
RegisterMenus()
Customize submenus.
Traceback_uri()
Get the URI without query to this location.
initBucketDefArray($bucketpool_pk)
Initializes array of bucket_def records.
GetPkgMimetypes()
Get package mimetype.
ShowUploadHist($Uploadtree_pk, $Uri)
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...
int IsDir(char *Fname)
Given a filename, is it a directory?
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
Install()
Create and configure database tables.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk)...
ReportCachePurgeByKey($CacheKey)
Purge from the report cache the record with $CacheKey.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
char * uploadtree_tablename
upload.uploadtree_tablename
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:
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
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Initialize()
This is called before the plugin is used. It should assume that Install() was already run one time (p...
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
GetArrayVal($Key, $Arr)
Get the value from a array(map)
Output()
This function is called when user output is requested. This function is responsible for content...
Traceback()
Get the URI + query to this location.