<?php
{
return (strnatcasecmp($rowa['name'], $rowb['name']));
}
{
return (strnatcasecmp($rowa['ufile_name'], $rowb['ufile_name']));
}
{
var $HighlightColor = '#4bfe78';
private $uploadDao;
{
$this->Name = "picker";
$this->Title = _("File Picker");
$this->Dependency = array("browse","view");
$this->LoginFlag = 0;
parent::__construct();
$this->uploadDao = $GLOBALS['container']->get('dao.upload');
}
{
return(1);
}
return(0);
}
{
$text = _("Compare this file to another.");
menu_insert(
"Browse-Pfile::Compare",0,$this->Name,$text);
return 0;
}
{
if ($this->
State != PLUGIN_STATE_INVALID) {
return (1);
}
if ($this->Name !== "") {
global $Plugins;
$this->
State = PLUGIN_STATE_VALID;
$Plugins[] = $this;
}
return($this->
State == PLUGIN_STATE_VALID);
}
{
$sql = "SELECT typlen FROM pg_type where typname='file_picker' limit 1";
if (pg_num_rows($result) > 0) {
pg_free_result($result);
return 0;
}
pg_free_result($result);
$sql = "CREATE TABLE file_picker (
file_picker_pk serial NOT NULL PRIMARY KEY,
user_fk integer NOT NULL,
uploadtree_fk1 integer NOT NULL,
uploadtree_fk2 integer NOT NULL,
last_access_date date NOT NULL
);
ALTER TABLE ONLY file_picker
ADD CONSTRAINT file_picker_user_fk_key UNIQUE (user_fk, uploadtree_fk1, uploadtree_fk2);";
pg_free_result($result);
}
function HTMLFileList($File1uploadtree_pk, $Children, $FolderContents)
{
global $Plugins;
$OutBuf="";
$OutBuf .= "<table style='text-align:left;' >";
if (!empty($FolderContents)) {
usort($FolderContents, 'picker_name_cmp');
foreach ($FolderContents as $Folder) {
if ($Folder && array_key_exists('folder_pk', $Folder)) {
$folder_pk = $Folder['folder_pk'];
$folder_name = htmlentities($Folder['name']);
$OutBuf .= "<tr>";
$OutBuf .= "<td></td>";
$OutBuf .= "<td>";
$OutBuf .= "<a href='$Uri&folder=$folder_pk&item=$File1uploadtree_pk'><b>$folder_name</b></a>/";
$OutBuf .= "</td></tr>";
} else if ($Folder && array_key_exists('uploadtree_pk', $Folder)) {
$bitem = $Folder['uploadtree_pk'];
$upload_filename = htmlentities($Folder['name']);
$OutBuf .= "<tr>";
$OutBuf .= "<td>";
$text = _("Select");
$Options = "id=filepick2 onclick='AppJump($bitem)')";
$OutBuf .= "<button type='button' $Options> $text </button>\n";
$OutBuf .= "</td>";
$OutBuf .= "<td>";
$OutBuf .= "<a href='$Uri&bitem=$bitem&item=$File1uploadtree_pk'><b>$upload_filename</b></a>/";
$OutBuf .= "</td></tr>";
}
}
} else {
if (empty($Children)) {
$text = _("No children to compare");
$OutBuf .= "<tr><td colspan=2>$text</td></tr>";
} else {
usort($Children, 'picker_ufile_name_cmp');
foreach ($Children as $Child) {
if (empty($Child)) {
continue;
}
$OutBuf .= "<tr>";
$IsDir =
Isdir($Child[
'ufile_mode']);
$LinkUri = $Uri . "&bitem=$Child[uploadtree_pk]&item=$File1uploadtree_pk";
$OutBuf .= "<td>";
$text = _("Select");
$Options = "id=filepick onclick='AppJump($Child[uploadtree_pk])')";
$OutBuf .= "<button type='button' $Options> $text </button>\n";
$OutBuf .= "</td>";
$OutBuf .= "<td>";
if ($IsContainer) {
$OutBuf .= "<a href='$LinkUri'> $Child[ufile_name]</a>";
} else {
$OutBuf .= $Child['ufile_name'];
}
if ($IsDir) {
$OutBuf .= "/";
}
$OutBuf .= "</td>";
$OutBuf .= "</tr>";
}
}
}
$OutBuf .= "</table>";
return($OutBuf);
}
function HTMLPath($File1uploadtree_pk, $FolderList, $DirectoryList)
{
if (empty($FolderList)) {
return "__FILE__ __LINE__ No folder list specified";
}
$OutBuf = "";
$OutBuf .= "<div class='alert alert-info' style='padding:5px;'>\n";
$text = _("Folder");
$OutBuf .= "<b>$text</b>: ";
foreach ($FolderList as $Folder) {
$folder_pk = $Folder['folder_pk'];
$folder_name = htmlentities($Folder['folder_name']);
$OutBuf .= "<a href='$Uri2&folder=$folder_pk&item=$File1uploadtree_pk'><b>$folder_name</b></a>/";
}
if (! empty($DirectoryList)) {
$OutBuf .= "<br>";
$First = true;
foreach ($DirectoryList as $uploadtree_rec) {
if (! $First) {
$OutBuf .= "/ ";
}
$href = "$Uri2&bitem=$uploadtree_rec[uploadtree_pk]&item=$File1uploadtree_pk";
$OutBuf .= "<a href='$href'>";
if (!$First &&
Iscontainer($uploadtree_rec[
'ufile_mode'])) {
$OutBuf .= "<br> ";
}
$OutBuf .= "<b>" . $uploadtree_rec['ufile_name'] . "</b>";
$OutBuf .= "</a>";
$First = false;
}
}
$OutBuf .= "</div>\n";
return($OutBuf);
}
{
$PickerRows = array();
$user_pk = $_SESSION['UserId'];
if (empty($user_pk)) {
return $PickerRows;
}
$sql = "select file_picker_pk, uploadtree_fk1, uploadtree_fk2 from file_picker
where user_fk= '$user_pk' and ($uploadtree_pk=uploadtree_fk1 or $uploadtree_pk=uploadtree_fk2)";
$rtncount = pg_num_rows($result);
if ($rtncount > 0) {
$PickerRows = pg_fetch_all($result);
pg_free_result($result);
} else {
pg_free_result($result);
return "";
}
$PickSelectArray = array();
foreach ($PickerRows as $PickRec) {
if ($PickRec['uploadtree_fk1'] == $uploadtree_pk) {
$item2 = $PickRec["uploadtree_fk2"];
} else {
$item2 = $PickRec["uploadtree_fk1"];
}
$PathArray =
Dir2Path($item2,
'uploadtree');
$PickSelectArray[$item2] = $Path;
}
$Options = "id=HistoryPick onchange='AppJump(this.value)')";
true, $Options);
return $SelectList;
}
{
$BaseFN = basename($FileName);
$delims= "/-.0123456789 \t\n\r\0\0xb";
$NameRoot = ltrim($BaseFN, $delims);
$NameRoot = strtok($NameRoot, $delims);
$tail = ".$ext";
if (empty($NameRoot)) {
return "";
}
$sql = "select uploadtree_pk from uploadtree
where ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)
and (ufile_name like '$NameRoot%$tail')
and (uploadtree_pk != '$uploadtree_pk') limit 100";
$SuggestionsArray = array();
while ($row = pg_fetch_assoc($result)) {
$PathArray =
Dir2Path($row[
'uploadtree_pk'],
'uploadtree');
}
pg_free_result($result);
$rtncount = count($SuggestionsArray);
if ($rtncount == 0) {
return "";
}
natsort($SuggestionsArray);
$Options = "id=SuggestPick onchange='AppJump(this.value)')";
true, true, $Options);
return $SelectList;
}
function BrowsePick($uploadtree_pk, $inBrowseuploadtree_pk, $infolder_pk, $PathArray)
{
$OutBuf = "";
if (empty($inBrowseuploadtree_pk)) {
$Browseuploadtree_pk = $uploadtree_pk;
} else {
$Browseuploadtree_pk = $inBrowseuploadtree_pk;
}
if (empty($infolder_pk)) {
} else {
$folder_pk = $infolder_pk;
}
if (empty($infolder_pk)) {
$DirectoryList =
Dir2Path($Browseuploadtree_pk,
'uploadtree');
} else {
$DirectoryList = '';
}
$OutBuf .= $this->HTMLPath($uploadtree_pk, $FolderList, $DirectoryList);
if (empty($infolder_pk)) {
$FolderContents = array();
$Children = GetNonArtifactChildren($Browseuploadtree_pk);
} else {
$Children = array();
$FolderContents = $this->GetFolderContents($folder_pk);
}
$OutBuf .= $this->
HTMLFileList($uploadtree_pk, $Children, $FolderContents);
return $OutBuf;
}
function GetFolderContents($folder_pk)
{
$FolderContents = array();
$sql = "select * from foldercontents where parent_fk='$folder_pk'";
while ($FCrow = pg_fetch_assoc($FCresult)) {
switch ($FCrow['foldercontents_mode']) {
case 1:
$sql = "select folder_pk, folder_name as name from folder where folder_pk=$FCrow[child_id]";
$FolderResult = pg_query(
$PG_CONN, $sql);
$FolderRow = pg_fetch_assoc($FolderResult);
pg_free_result($FolderResult);
$FolderContents[] = $FolderRow;
break;
case 2:
$sql = "select upload_pk, upload_filename as name from upload"
. " where upload_pk=$FCrow[child_id] and ((upload_mode & (1<<5))!=0)";
$NumRows = pg_num_rows($UpResult);
if ($NumRows) {
$UpRow = pg_fetch_assoc($UpResult);
pg_free_result($UpResult);
} else {
pg_free_result($UpResult);
break;
}
$sql = "select uploadtree_pk from uploadtree where upload_fk=$FCrow[child_id] and parent is null";
$UtreeResult = pg_query(
$PG_CONN, $sql);
$UtreeRow = pg_fetch_assoc($UtreeResult);
pg_free_result($UtreeResult);
$UpRow['uploadtree_pk'] = $UtreeRow['uploadtree_pk'];
$FolderContents[] = $UpRow;
break;
case 4:
default:
}
}
pg_free_result($FCresult);
return $FolderContents;
}
function HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray)
{
$OutBuf = '';
$OutBuf .= "<script language='javascript'>\n";
$OutBuf .= "function AppJump(val) {";
$OutBuf .= "var rtnmodelt = document.getElementById('apick');";
$OutBuf .= "var rtnmod = rtnmodelt.value;";
$OutBuf .= "var uri = '$uri' + '&rtnmod=' + rtnmod + '&item=' + $uploadtree_pk + '&item2=' + val;";
$OutBuf .= "window.location.assign(uri);";
$OutBuf .= "}";
$OutBuf .= "</script>\n";
$OutBuf .= "The purpose of the picker is to permit people to positively pick a pair of paths.";
$OutBuf .= "<br>Path pairs are used by reports that do file comparisons and "
. "differences between files (like isos, packages, directories, etc.).";
$OutBuf .= "<hr>";
$OutBuf .= "<div style=background-color:lavender>";
$OutBuf .= "<center><table style='border:5px groove red'>";
$OutBuf .= "<tr><td><b>File 1: </b></td><td> </td><td>";
$OutBuf .= "$PathStr";
$OutBuf .= "</td></tr>";
$OutBuf .= "</table></center>";
$text = _("Choose the program to run after you select the second file.");
$OutBuf .= "<b>$text</b><br>";
$OutBuf .= $this->
ApplicationPick(
"PickRtnApp", $RtnMod,
"will run after chosing a file");
$OutBuf .= "</div>";
$OutBuf .= "<br>";
$HistPick = $this->
HistoryPick($uploadtree_pk, $rtncount);
if (! empty($HistPick)) {
$text = _("Select from your pick history");
$OutBuf .= "<h3>$text ($rtncount):</h3>";
$OutBuf .= "$HistPick";
}
$text = _("Browse");
$OutBuf .= "<hr><h3>$text:</h3>";
$OutBuf .= $this->
BrowsePick($uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
return $OutBuf;
}
{
if ($this->
State != PLUGIN_STATE_READY) {
return(0);
}
if (! $uploadtree_pk) {
return "<h2>Unidentified item 1</h2>";
}
$user_pk = Auth::getUserId();
$Item1Row =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $uploadtree_pk");
if (! $this->uploadDao->isAccessible($Item1Row['upload_fk'],
Auth::getGroupId())) {
$text = _("Permission Denied");
return "<h2>$text item 1</h2>";
}
if (! empty($uploadtree_pk2)) {
$Item2Row =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $uploadtree_pk2");
if (! $this->uploadDao->isAccessible($Item2Row['upload_fk'], Auth::getGroupId())) {
$text = _("Permission Denied");
return "<h2>$text item 2</h2>";
}
}
if (!empty($user_pk) && !empty($RtnMod) && !empty($uploadtree_pk) && !empty($uploadtree_pk2)) {
$sql = "insert into file_picker (user_fk, uploadtree_fk1, uploadtree_fk2, last_access_date)
values($user_pk, $uploadtree_pk, $uploadtree_pk2, now())";
$uri =
Traceback_uri() .
"?mod=$RtnMod&item1=$uploadtree_pk&item2=$uploadtree_pk2";
echo "<script type='text/javascript'> window.location.assign('$uri');</script>";
exit();
}
$OutBuf = "";
if ($this->OutputType == 'HTML') {
if (empty($uploadtree_pk)) {
$OutBuf = "<h2>Picker URL is missing the first comparison file.</h2>";
} else {
$PathArray =
Dir2Path($uploadtree_pk,
'uploadtree');
$OutBuf .= $this->
HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
}
}
return $OutBuf;
}
{
$Path = "";
if (count($PathArray)) {
foreach ($PathArray as $PathRow) {
$Path .= "/" . $PathRow['ufile_name'];
}
}
return $Path;
}
{
$AppList = array("nomosdiff" => "License Difference",
"bucketsdiff" => "Bucket Difference");
$Options = "id=apick";
false, true, $Options);
$StrOut = "$SelectList $label";
return $StrOut;
}
}
$NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
ApplicationPick($SLName, $SelectedVal, $label)
Generate html to pick the application that will be called after the items are identified.
Install()
Create and configure database tables.
__construct()
base constructor. Most plugins will just use this
SuggestionsPick($FileName, $uploadtree_pk, &$rtncount)
Search the whole repository for containers with names similar to $FileName (based on the beggining te...
HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray)
the html format out info
Uploadtree2PathStr($PathArray)
Get string representation of uploadtree path. Use Dir2Path to get $PathArray.
RegisterMenus()
Customize submenus.
HTMLFileList($File1uploadtree_pk, $Children, $FolderContents)
Given an $File1uploadtree_pk, $Children are non artifact children of $File1uploadtree_pk.
HistoryPick($uploadtree_pk, &$rtncount)
pick history
BrowsePick($uploadtree_pk, $inBrowseuploadtree_pk, $infolder_pk, $PathArray)
file browser
Initialize()
This is called before the plugin is used.
Create_file_picker()
Create file_picker table.
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.
GetFolderFromItem($upload_pk="", $uploadtree_pk="")
Find what folder an item is in.
Folder2Path($folder_pk)
Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Array2SingleSelect($KeyValArray, $SLName="unnamed", $SelectedVal="", $FirstEmpty=false, $SelElt=true, $Options="", $ReturnKey=true)
Build a single choice select pulldown.
GetFileExt($fname)
Get File Extension (text after last period)
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
picker_ufile_name_cmp($rowa, $rowb)
Sort filenames.
picker_name_cmp($rowa, $rowb)
Sort folder and upload names.