23 return (strnatcasecmp($rowa[
'name'], $rowb[
'name']));
32 return (strnatcasecmp($rowa[
'ufile_name'], $rowb[
'ufile_name']));
38 var $HighlightColor =
'#4bfe78';
44 $this->Name =
"picker";
45 $this->Title = _(
"File Picker");
46 $this->Dependency = array(
"browse",
"view");
49 parent::__construct();
50 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
75 $text = _(
"Compare this file to another.");
76 menu_insert(
"Browse-Pfile::Compare",0,$this->Name,$text);
92 if ($this->
State != PLUGIN_STATE_INVALID) {
95 if ($this->Name !==
"") {
98 $this->
State = PLUGIN_STATE_VALID;
101 return($this->
State == PLUGIN_STATE_VALID);
113 $sql =
"SELECT typlen FROM pg_type where typname='file_picker' limit 1";
116 if (pg_num_rows($result) > 0) {
117 pg_free_result($result);
120 pg_free_result($result);
123 $sql =
"CREATE TABLE file_picker (
124 file_picker_pk serial NOT NULL PRIMARY KEY,
125 user_fk integer NOT NULL,
126 uploadtree_fk1 integer NOT NULL,
127 uploadtree_fk2 integer NOT NULL,
128 last_access_date date NOT NULL
130 ALTER TABLE ONLY file_picker
131 ADD CONSTRAINT file_picker_user_fk_key UNIQUE (user_fk, uploadtree_fk1, uploadtree_fk2);";
135 pg_free_result($result);
154 $OutBuf .=
"<table style='text-align:left;' >";
156 if (!empty($FolderContents)) {
157 usort($FolderContents,
'picker_name_cmp');
160 foreach ($FolderContents as $Folder) {
161 if ($Folder && array_key_exists(
'folder_pk', $Folder)) {
162 $folder_pk = $Folder[
'folder_pk'];
163 $folder_name = htmlentities($Folder[
'name']);
166 $OutBuf .=
"<td></td>";
169 $OutBuf .=
"<a href='$Uri&folder=$folder_pk&item=$File1uploadtree_pk'><b>$folder_name</b></a>/";
170 $OutBuf .=
"</td></tr>";
171 }
else if ($Folder && array_key_exists(
'uploadtree_pk', $Folder)) {
172 $bitem = $Folder[
'uploadtree_pk'];
173 $upload_filename = htmlentities($Folder[
'name']);
177 $Options =
"id=filepick2 onclick='AppJump($bitem)')";
178 $OutBuf .=
"<button type='button' $Options> $text </button>\n";
182 $OutBuf .=
"<a href='$Uri&bitem=$bitem&item=$File1uploadtree_pk'><b>$upload_filename</b></a>/";
183 $OutBuf .=
"</td></tr>";
187 if (empty($Children)) {
188 $text = _(
"No children to compare");
189 $OutBuf .=
"<tr><td colspan=2>$text</td></tr>";
191 usort($Children,
'picker_ufile_name_cmp');
192 foreach ($Children as $Child) {
198 $IsDir =
Isdir($Child[
'ufile_mode']);
201 $LinkUri = $Uri .
"&bitem=$Child[uploadtree_pk]&item=$File1uploadtree_pk";
205 $Options =
"id=filepick onclick='AppJump($Child[uploadtree_pk])')";
206 $OutBuf .=
"<button type='button' $Options> $text </button>\n";
210 $OutBuf .=
"<a href='$LinkUri'> $Child[ufile_name]</a>";
212 $OutBuf .= $Child[
'ufile_name'];
222 $OutBuf .=
"</table>";
258 function HTMLPath($File1uploadtree_pk, $FolderList, $DirectoryList)
260 if (empty($FolderList)) {
261 return "__FILE__ __LINE__ No folder list specified";
268 $OutBuf .=
"<div class='alert alert-info' style='padding:5px;'>\n";
272 $OutBuf .=
"<b>$text</b>: ";
274 foreach ($FolderList as $Folder) {
275 $folder_pk = $Folder[
'folder_pk'];
276 $folder_name = htmlentities($Folder[
'folder_name']);
277 $OutBuf .=
"<a href='$Uri2&folder=$folder_pk&item=$File1uploadtree_pk'><b>$folder_name</b></a>/";
281 if (! empty($DirectoryList)) {
286 foreach ($DirectoryList as $uploadtree_rec) {
291 $href =
"$Uri2&bitem=$uploadtree_rec[uploadtree_pk]&item=$File1uploadtree_pk";
292 $OutBuf .=
"<a href='$href'>";
294 if (!$First &&
Iscontainer($uploadtree_rec[
'ufile_mode'])) {
295 $OutBuf .=
"<br> ";
298 $OutBuf .=
"<b>" . $uploadtree_rec[
'ufile_name'] .
"</b>";
304 $OutBuf .=
"</div>\n";
320 $PickerRows = array();
323 $user_pk = $_SESSION[
'UserId'];
324 if (empty($user_pk)) {
328 $sql =
"select file_picker_pk, uploadtree_fk1, uploadtree_fk2 from file_picker
329 where user_fk= '$user_pk' and ($uploadtree_pk=uploadtree_fk1 or $uploadtree_pk=uploadtree_fk2)";
332 $rtncount = pg_num_rows($result);
334 $PickerRows = pg_fetch_all($result);
335 pg_free_result($result);
338 pg_free_result($result);
343 $PickSelectArray = array();
344 foreach ($PickerRows as $PickRec) {
345 if ($PickRec[
'uploadtree_fk1'] == $uploadtree_pk) {
346 $item2 = $PickRec[
"uploadtree_fk2"];
348 $item2 = $PickRec[
"uploadtree_fk1"];
350 $PathArray =
Dir2Path($item2,
'uploadtree');
352 $PickSelectArray[$item2] = $Path;
354 $Options =
"id=HistoryPick onchange='AppJump(this.value)')";
374 $BaseFN = basename($FileName);
375 $delims=
"/-.0123456789 \t\n\r\0\0xb";
376 $NameRoot = ltrim($BaseFN, $delims);
377 $NameRoot = strtok($NameRoot, $delims);
383 if (empty($NameRoot)) {
388 $sql =
"select uploadtree_pk from uploadtree
389 where ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)
390 and (ufile_name like '$NameRoot%$tail')
391 and (uploadtree_pk != '$uploadtree_pk') limit 100";
394 $SuggestionsArray = array();
395 while ($row = pg_fetch_assoc($result)) {
396 $PathArray =
Dir2Path($row[
'uploadtree_pk'],
'uploadtree');
399 pg_free_result($result);
401 $rtncount = count($SuggestionsArray);
402 if ($rtncount == 0) {
407 natsort($SuggestionsArray);
409 $Options =
"id=SuggestPick onchange='AppJump(this.value)')";
411 true,
true, $Options);
421 function BrowsePick($uploadtree_pk, $inBrowseuploadtree_pk, $infolder_pk, $PathArray)
424 if (empty($inBrowseuploadtree_pk)) {
425 $Browseuploadtree_pk = $uploadtree_pk;
427 $Browseuploadtree_pk = $inBrowseuploadtree_pk;
430 if (empty($infolder_pk)) {
433 $folder_pk = $infolder_pk;
441 if (empty($infolder_pk)) {
442 $DirectoryList =
Dir2Path($Browseuploadtree_pk,
'uploadtree');
449 $OutBuf .= $this->HTMLPath($uploadtree_pk, $FolderList, $DirectoryList);
455 if (empty($infolder_pk)) {
456 $FolderContents = array();
457 $Children = GetNonArtifactChildren($Browseuploadtree_pk);
460 $FolderContents = $this->GetFolderContents($folder_pk);
462 $OutBuf .= $this->
HTMLFileList($uploadtree_pk, $Children, $FolderContents);
486 function GetFolderContents($folder_pk)
490 $FolderContents = array();
494 $sql =
"select * from foldercontents where parent_fk='$folder_pk'";
495 $FCresult = pg_query(
$PG_CONN, $sql);
499 while ($FCrow = pg_fetch_assoc($FCresult)) {
500 switch ($FCrow[
'foldercontents_mode']) {
502 $sql =
"select folder_pk, folder_name as name from folder where folder_pk=$FCrow[child_id]";
503 $FolderResult = pg_query(
$PG_CONN, $sql);
505 $FolderRow = pg_fetch_assoc($FolderResult);
506 pg_free_result($FolderResult);
508 $FolderContents[] = $FolderRow;
511 $sql =
"select upload_pk, upload_filename as name from upload"
512 .
" where upload_pk=$FCrow[child_id] and ((upload_mode & (1<<5))!=0)";
513 $UpResult = pg_query(
$PG_CONN, $sql);
515 $NumRows = pg_num_rows($UpResult);
517 $UpRow = pg_fetch_assoc($UpResult);
518 pg_free_result($UpResult);
520 pg_free_result($UpResult);
525 $sql =
"select uploadtree_pk from uploadtree where upload_fk=$FCrow[child_id] and parent is null";
526 $UtreeResult = pg_query(
$PG_CONN, $sql);
528 $UtreeRow = pg_fetch_assoc($UtreeResult);
529 pg_free_result($UtreeResult);
530 $UpRow[
'uploadtree_pk'] = $UtreeRow[
'uploadtree_pk'];
531 $FolderContents[] = $UpRow;
537 pg_free_result($FCresult);
538 return $FolderContents;
551 function HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray)
563 $OutBuf .=
"<script language='javascript'>\n";
564 $OutBuf .=
"function AppJump(val) {";
565 $OutBuf .=
"var rtnmodelt = document.getElementById('apick');";
566 $OutBuf .=
"var rtnmod = rtnmodelt.value;";
567 $OutBuf .=
"var uri = '$uri' + '&rtnmod=' + rtnmod + '&item=' + $uploadtree_pk + '&item2=' + val;";
568 $OutBuf .=
"window.location.assign(uri);";
570 $OutBuf .=
"</script>\n";
573 $OutBuf .=
"The purpose of the picker is to permit people to positively pick a pair of paths.";
574 $OutBuf .=
"<br>Path pairs are used by reports that do file comparisons and "
575 .
"differences between files (like isos, packages, directories, etc.).";
580 $OutBuf .=
"<div style=background-color:lavender>";
581 $OutBuf .=
"<center><table style='border:5px groove red'>";
582 $OutBuf .=
"<tr><td><b>File 1: </b></td><td> </td><td>";
584 $OutBuf .=
"$PathStr";
585 $OutBuf .=
"</td></tr>";
586 $OutBuf .=
"</table></center>";
588 $text = _(
"Choose the program to run after you select the second file.");
589 $OutBuf .=
"<b>$text</b><br>";
590 $OutBuf .= $this->
ApplicationPick(
"PickRtnApp", $RtnMod,
"will run after chosing a file");
595 $HistPick = $this->
HistoryPick($uploadtree_pk, $rtncount);
596 if (! empty($HistPick)) {
597 $text = _(
"Select from your pick history");
598 $OutBuf .=
"<h3>$text ($rtncount):</h3>";
599 $OutBuf .=
"$HistPick";
612 $OutBuf .=
"<hr><h3>$text:</h3>";
615 $OutBuf .= $this->
BrowsePick($uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
627 if ($this->
State != PLUGIN_STATE_READY) {
639 if (! $uploadtree_pk) {
640 return "<h2>Unidentified item 1</h2>";
644 $user_pk = Auth::getUserId();
650 $Item1Row =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $uploadtree_pk");
651 if (! $this->uploadDao->isAccessible($Item1Row[
'upload_fk'],
652 Auth::getGroupId())) {
653 $text = _(
"Permission Denied");
654 return "<h2>$text item 1</h2>";
657 if (! empty($uploadtree_pk2)) {
658 $Item2Row =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $uploadtree_pk2");
659 if (! $this->uploadDao->isAccessible($Item2Row[
'upload_fk'], Auth::getGroupId())) {
660 $text = _(
"Permission Denied");
661 return "<h2>$text item 2</h2>";
670 if (!empty($user_pk) && !empty($RtnMod) && !empty($uploadtree_pk) && !empty($uploadtree_pk2)) {
671 $sql =
"insert into file_picker (user_fk, uploadtree_fk1, uploadtree_fk2, last_access_date)
672 values($user_pk, $uploadtree_pk, $uploadtree_pk2, now())";
674 @$result = pg_query(
$PG_CONN, $sql);
677 $uri =
Traceback_uri() .
"?mod=$RtnMod&item1=$uploadtree_pk&item2=$uploadtree_pk2";
678 echo
"<script type='text/javascript'> window.location.assign('$uri');</script>";
684 if ($this->OutputType ==
'HTML') {
685 if (empty($uploadtree_pk)) {
686 $OutBuf =
"<h2>Picker URL is missing the first comparison file.</h2>";
688 $PathArray =
Dir2Path($uploadtree_pk,
'uploadtree');
689 $OutBuf .= $this->
HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
707 if (count($PathArray)) {
708 foreach ($PathArray as $PathRow) {
709 $Path .=
"/" . $PathRow[
'ufile_name'];
735 $AppList = array(
"nomosdiff" =>
"License Difference",
736 "bucketsdiff" =>
"Bucket Difference");
737 $Options =
"id=apick";
739 false,
true, $Options);
740 $StrOut =
"$SelectList $label";
746 $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.