34 return (strnatcasecmp($rowa[
'name'], $rowb[
'name']));
43 return (strnatcasecmp($rowa[
'ufile_name'], $rowb[
'ufile_name']));
49 var $HighlightColor =
'#4bfe78';
53 function __construct()
55 $this->Name =
"picker";
56 $this->Title = _(
"File Picker");
57 $this->Dependency = array(
"browse",
"view");
60 parent::__construct();
61 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
71 if (empty($PG_CONN)) {
86 $text = _(
"Compare this file to another.");
87 menu_insert(
"Browse-Pfile::Compare",0,$this->Name,$text);
103 if ($this->
State != PLUGIN_STATE_INVALID) {
106 if ($this->Name !==
"") {
109 $this->
State = PLUGIN_STATE_VALID;
110 array_push($Plugins,$this);
112 return($this->
State == PLUGIN_STATE_VALID);
124 $sql =
"SELECT typlen FROM pg_type where typname='file_picker' limit 1";
125 $result = pg_query($PG_CONN, $sql);
127 if (pg_num_rows($result) > 0) {
128 pg_free_result($result);
131 pg_free_result($result);
134 $sql =
"CREATE TABLE file_picker ( 135 file_picker_pk serial NOT NULL PRIMARY KEY, 136 user_fk integer NOT NULL, 137 uploadtree_fk1 integer NOT NULL, 138 uploadtree_fk2 integer NOT NULL, 139 last_access_date date NOT NULL 141 ALTER TABLE ONLY file_picker 142 ADD CONSTRAINT file_picker_user_fk_key UNIQUE (user_fk, uploadtree_fk1, uploadtree_fk2);";
144 $result = pg_query($PG_CONN, $sql);
146 pg_free_result($result);
165 $OutBuf .=
"<table style='text-align:left;' >";
167 if (!empty($FolderContents)) {
168 usort($FolderContents,
'picker_name_cmp');
171 foreach ($FolderContents as $Folder) {
172 if ($Folder && array_key_exists(
'folder_pk', $Folder)) {
173 $folder_pk = $Folder[
'folder_pk'];
174 $folder_name = htmlentities($Folder[
'name']);
177 $OutBuf .=
"<td></td>";
180 $OutBuf .=
"<a href='$Uri&folder=$folder_pk&item=$File1uploadtree_pk'><b>$folder_name</b></a>/";
181 $OutBuf .=
"</td></tr>";
182 }
else if ($Folder && array_key_exists(
'uploadtree_pk', $Folder)) {
183 $bitem = $Folder[
'uploadtree_pk'];
184 $upload_filename = htmlentities($Folder[
'name']);
188 $Options =
"id=filepick2 onclick='AppJump($bitem)')";
189 $OutBuf .=
"<button type='button' $Options> $text </button>\n";
193 $OutBuf .=
"<a href='$Uri&bitem=$bitem&item=$File1uploadtree_pk'><b>$upload_filename</b></a>/";
194 $OutBuf .=
"</td></tr>";
198 if (empty($Children)) {
199 $text = _(
"No children to compare");
200 $OutBuf .=
"<tr><td colspan=2>$text</td></tr>";
202 usort($Children,
'picker_ufile_name_cmp');
203 foreach ($Children as $Child) {
209 $IsDir =
Isdir($Child[
'ufile_mode']);
212 $LinkUri = $Uri .
"&bitem=$Child[uploadtree_pk]&item=$File1uploadtree_pk";
216 $Options =
"id=filepick onclick='AppJump($Child[uploadtree_pk])')";
217 $OutBuf .=
"<button type='button' $Options> $text </button>\n";
221 $OutBuf .=
"<a href='$LinkUri'> $Child[ufile_name]</a>";
223 $OutBuf .= $Child[
'ufile_name'];
233 $OutBuf .=
"</table>";
269 function HTMLPath($File1uploadtree_pk, $FolderList, $DirectoryList)
271 if (empty($FolderList)) {
272 return "__FILE__ __LINE__ No folder list specified";
279 $OutBuf .=
"<div style='border: thin dotted gray; background-color:lightyellow'>\n";
283 $OutBuf .=
"<b>$text</b>: ";
285 foreach ($FolderList as $Folder) {
286 $folder_pk = $Folder[
'folder_pk'];
287 $folder_name = htmlentities($Folder[
'folder_name']);
288 $OutBuf .=
"<a href='$Uri2&folder=$folder_pk&item=$File1uploadtree_pk'><b>$folder_name</b></a>/";
292 if (! empty($DirectoryList)) {
297 foreach ($DirectoryList as $uploadtree_rec) {
302 $href =
"$Uri2&bitem=$uploadtree_rec[uploadtree_pk]&item=$File1uploadtree_pk";
303 $OutBuf .=
"<a href='$href'>";
305 if (!$First &&
Iscontainer($uploadtree_rec[
'ufile_mode'])) {
306 $OutBuf .=
"<br> ";
309 $OutBuf .=
"<b>" . $uploadtree_rec[
'ufile_name'] .
"</b>";
315 $OutBuf .=
"</div>\n";
331 $PickerRows = array();
334 $user_pk = $_SESSION[
'UserId'];
335 if (empty($user_pk)) {
339 $sql =
"select file_picker_pk, uploadtree_fk1, uploadtree_fk2 from file_picker 340 where user_fk= '$user_pk' and ($uploadtree_pk=uploadtree_fk1 or $uploadtree_pk=uploadtree_fk2)";
341 $result = pg_query($PG_CONN, $sql);
343 $rtncount = pg_num_rows($result);
345 $PickerRows = pg_fetch_all($result);
346 pg_free_result($result);
349 pg_free_result($result);
354 $PickSelectArray = array();
355 foreach ($PickerRows as $PickRec) {
356 if ($PickRec[
'uploadtree_fk1'] == $uploadtree_pk) {
357 $item2 = $PickRec[
"uploadtree_fk2"];
359 $item2 = $PickRec[
"uploadtree_fk1"];
361 $PathArray =
Dir2Path($item2,
'uploadtree');
363 $PickSelectArray[$item2] = $Path;
365 $Options =
"id=HistoryPick onchange='AppJump(this.value)')";
385 $BaseFN = basename($FileName);
386 $delims=
"/-.0123456789 \t\n\r\0\0xb";
387 $NameRoot = ltrim($BaseFN, $delims);
388 $NameRoot = strtok($NameRoot, $delims);
394 if (empty($NameRoot)) {
399 $sql =
"select uploadtree_pk from uploadtree 400 where ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) 401 and (ufile_name like '$NameRoot%$tail') 402 and (uploadtree_pk != '$uploadtree_pk') limit 100";
403 $result = pg_query($PG_CONN, $sql);
405 $SuggestionsArray = array();
406 while ($row = pg_fetch_assoc($result)) {
407 $PathArray =
Dir2Path($row[
'uploadtree_pk'],
'uploadtree');
410 pg_free_result($result);
412 $rtncount = count($SuggestionsArray);
413 if ($rtncount == 0) {
418 natsort($SuggestionsArray);
420 $Options =
"id=SuggestPick onchange='AppJump(this.value)')";
422 true,
true, $Options);
432 function BrowsePick($uploadtree_pk, $inBrowseuploadtree_pk, $infolder_pk, $PathArray)
435 if (empty($inBrowseuploadtree_pk)) {
436 $Browseuploadtree_pk = $uploadtree_pk;
438 $Browseuploadtree_pk = $inBrowseuploadtree_pk;
441 if (empty($infolder_pk)) {
444 $folder_pk = $infolder_pk;
452 if (empty($infolder_pk)) {
453 $DirectoryList =
Dir2Path($Browseuploadtree_pk,
'uploadtree');
460 $OutBuf .= $this->HTMLPath($uploadtree_pk, $FolderList, $DirectoryList);
466 if (empty($infolder_pk)) {
467 $FolderContents = array();
468 $Children = GetNonArtifactChildren($Browseuploadtree_pk);
471 $FolderContents = $this->GetFolderContents($folder_pk);
473 $OutBuf .= $this->
HTMLFileList($uploadtree_pk, $Children, $FolderContents);
497 function GetFolderContents($folder_pk)
501 $FolderContents = array();
505 $sql =
"select * from foldercontents where parent_fk='$folder_pk'";
506 $FCresult = pg_query($PG_CONN, $sql);
510 while ($FCrow = pg_fetch_assoc($FCresult)) {
511 switch ($FCrow[
'foldercontents_mode']) {
513 $sql =
"select folder_pk, folder_name as name from folder where folder_pk=$FCrow[child_id]";
514 $FolderResult = pg_query($PG_CONN, $sql);
516 $FolderRow = pg_fetch_assoc($FolderResult);
517 pg_free_result($FolderResult);
519 $FolderContents[] = $FolderRow;
522 $sql =
"select upload_pk, upload_filename as name from upload" 523 .
" where upload_pk=$FCrow[child_id] and ((upload_mode & (1<<5))!=0)";
524 $UpResult = pg_query($PG_CONN, $sql);
526 $NumRows = pg_num_rows($UpResult);
528 $UpRow = pg_fetch_assoc($UpResult);
529 pg_free_result($UpResult);
531 pg_free_result($UpResult);
536 $sql =
"select uploadtree_pk from uploadtree where upload_fk=$FCrow[child_id] and parent is null";
537 $UtreeResult = pg_query($PG_CONN, $sql);
539 $UtreeRow = pg_fetch_assoc($UtreeResult);
540 pg_free_result($UtreeResult);
541 $UpRow[
'uploadtree_pk'] = $UtreeRow[
'uploadtree_pk'];
542 $FolderContents[] = $UpRow;
548 pg_free_result($FCresult);
549 return $FolderContents;
562 function HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray)
574 $OutBuf .=
"<script language='javascript'>\n";
575 $OutBuf .=
"function AppJump(val) {";
576 $OutBuf .=
"var rtnmodelt = document.getElementById('apick');";
577 $OutBuf .=
"var rtnmod = rtnmodelt.value;";
578 $OutBuf .=
"var uri = '$uri' + '&rtnmod=' + rtnmod + '&item=' + $uploadtree_pk + '&item2=' + val;";
579 $OutBuf .=
"window.location.assign(uri);";
581 $OutBuf .=
"</script>\n";
584 $OutBuf .=
"The purpose of the picker is to permit people to positively pick a pair of paths.";
585 $OutBuf .=
"<br>Path pairs are used by reports that do file comparisons and " 586 .
"differences between files (like isos, packages, directories, etc.).";
591 $OutBuf .=
"<div style=background-color:lavender>";
592 $OutBuf .=
"<center><table style='border:5px groove red'>";
593 $OutBuf .=
"<tr><td><b>File 1: </b></td><td> </td><td>";
595 $OutBuf .=
"$PathStr";
596 $OutBuf .=
"</td></tr>";
597 $OutBuf .=
"</table></center>";
599 $text = _(
"Choose the program to run after you select the second file.");
600 $OutBuf .=
"<b>$text</b><br>";
601 $OutBuf .= $this->
ApplicationPick(
"PickRtnApp", $RtnMod,
"will run after chosing a file");
606 $HistPick = $this->
HistoryPick($uploadtree_pk, $rtncount);
607 if (! empty($HistPick)) {
608 $text = _(
"Select from your pick history");
609 $OutBuf .=
"<h3>$text ($rtncount):</h3>";
610 $OutBuf .=
"$HistPick";
623 $OutBuf .=
"<hr><h3>$text:</h3>";
626 $OutBuf .= $this->
BrowsePick($uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
638 if ($this->
State != PLUGIN_STATE_READY) {
650 if (! $uploadtree_pk) {
651 return "<h2>Unidentified item 1</h2>";
655 $user_pk = Auth::getUserId();
661 $Item1Row =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $uploadtree_pk");
662 if (! $this->uploadDao->isAccessible($Item1Row[
'upload_fk'],
663 Auth::getGroupId())) {
664 $text = _(
"Permission Denied");
665 return "<h2>$text item 1</h2>";
668 if (! empty($uploadtree_pk2)) {
669 $Item2Row =
GetSingleRec(
"uploadtree",
"WHERE uploadtree_pk = $uploadtree_pk2");
670 if (! $this->uploadDao->isAccessible($Item2Row[
'upload_fk'], Auth::getGroupId())) {
671 $text = _(
"Permission Denied");
672 return "<h2>$text item 2</h2>";
681 if (!empty($user_pk) && !empty($RtnMod) && !empty($uploadtree_pk) && !empty($uploadtree_pk2)) {
682 $sql =
"insert into file_picker (user_fk, uploadtree_fk1, uploadtree_fk2, last_access_date) 683 values($user_pk, $uploadtree_pk, $uploadtree_pk2, now())";
685 @$result = pg_query($PG_CONN, $sql);
688 $uri =
Traceback_uri() .
"?mod=$RtnMod&item1=$uploadtree_pk&item2=$uploadtree_pk2";
689 echo
"<script type='text/javascript'> window.location.assign('$uri');</script>";
695 if ($this->OutputType ==
'HTML') {
696 if (empty($uploadtree_pk)) {
697 $OutBuf =
"<h2>Picker URL is missing the first comparison file.</h2>";
699 $PathArray =
Dir2Path($uploadtree_pk,
'uploadtree');
700 $OutBuf .= $this->
HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
718 if (count($PathArray)) {
719 foreach ($PathArray as $PathRow) {
720 $Path .=
"/" . $PathRow[
'ufile_name'];
746 $AppList = array(
"nomosdiff" =>
"License Difference",
747 "bucketsdiff" =>
"Bucket Difference");
748 $Options =
"id=apick";
750 false,
true, $Options);
751 $StrOut =
"$SelectList $label";
757 $NewPlugin->Initialize();
Traceback_uri()
Get the URI without query to this location.
picker_ufile_name_cmp($rowa, $rowb)
Sort filenames.
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
Initialize()
This is called before the plugin is used.
Create_file_picker()
Create file_picker table.
Uploadtree2PathStr($PathArray)
Get string representation of uploadtree path. Use Dir2Path to get $PathArray.
SuggestionsPick($FileName, $uploadtree_pk, &$rtncount)
Search the whole repository for containers with names similar to $FileName (based on the beggining te...
Folder2Path($folder_pk)
Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
ApplicationPick($SLName, $SelectedVal, $label)
Generate html to pick the application that will be called after the items are identified.
picker_name_cmp($rowa, $rowb)
Sort folder and upload names.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
BrowsePick($uploadtree_pk, $inBrowseuploadtree_pk, $infolder_pk, $PathArray)
file browser
HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray)
the html format out info
GetFileExt($fname)
Get File Extension (text after last period)
HTMLFileList($File1uploadtree_pk, $Children, $FolderContents)
Given an $File1uploadtree_pk, $Children are non artifact children of $File1uploadtree_pk.
This is the Plugin class. All plugins should:
HistoryPick($uploadtree_pk, &$rtncount)
pick history
GetFolderFromItem($upload_pk="", $uploadtree_pk="")
Find what folder an item is in.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
RegisterMenus()
Customize submenus.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Install()
Create and configure database tables.
Array2SingleSelect($KeyValArray, $SLName="unnamed", $SelectedVal="", $FirstEmpty=false, $SelElt=true, $Options="", $ReturnKey=true)
Build a single choice select pulldown.