29 define(
"TITLE_UI_BROWSE", _(
"Browse"));
    38   function __construct()
    40     $this->Name = 
"browse";
    41     $this->Title = TITLE_UI_BROWSE;
    42     $this->MenuList = 
"Browse";
    43     $this->MenuOrder = 80; 
    44     $this->MenuTarget = 
"";
    49     $this->uploadDao = $container->get(
'dao.upload');
    50     $this->folderDao = $container->get(
'dao.folder');
    52     parent::__construct();
    60     menu_insert(
"Main::" . $this->MenuList, $this->MenuOrder, $this->Name, $this->Name);
    73     return ($this->
State == PLUGIN_STATE_READY);
    80   function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename)
    84     $dbManager = $container->get(
'db.manager');
    85     $RowStyle1 = 
"style='background-color:#ecfaff'";  
    86     $RowStyle2 = 
"style='background-color:#ffffe3'";  
    92     $Uri = 
Traceback_uri() . 
"?mod=" . $this->Name . 
"&folder=$Folder";
    96     $MenuPfile = 
menu_find(
"Browse-Pfile", $MenuDepth);
    98     $MenuPfileNoCompare = 
menu_remove($MenuPfile, 
"Compare");
   101     foreach ($MenuPfile as $value) {
   102       if (($value->Name == 
'Tag') || ($value->Name == 
'Compare')) {
   107     $Results = GetNonArtifactChildren($Item, $uploadtree_tablename);
   109     $V .= 
"<table class='text' style='border-collapse: collapse' border=0 padding=0>\n";
   110     $stmtGetFirstChild = __METHOD__.
'.getFirstChild';
   111     $dbManager->prepare($stmtGetFirstChild,
"SELECT uploadtree_pk FROM $uploadtree_tablename WHERE parent=$1 limit 1");
   112     foreach ($Results as $Row) {
   113       if (empty($Row[
'uploadtree_pk'])) {
   117       $Name = $Row[
'ufile_name'];
   120       $RowStyle = (($RowNum++ % (2 * $ColorSpanRows)) < $ColorSpanRows) ? $RowStyle1 : $RowStyle2;
   121       $V .= 
"<tr $RowStyle>";
   124       $result = $dbManager->execute($stmtGetFirstChild,array($Row[
'uploadtree_pk']));
   125       $HasChildren = $dbManager->fetchArray($result);
   126       $dbManager->freeResult($result);
   128       $Parm = 
"upload=$Upload&show=$Show&item=" . $Row[
'uploadtree_pk'];
   129       $Link = $HasChildren ? 
"$Uri&show=$Show&upload=$Upload&item=$Row[uploadtree_pk]" : NULL;
   131       if ($Show == 
'detail') {
   132         $V .= 
"<td class='mono'>" . 
DirMode2String($Row[
'ufile_mode']) . 
"</td>";
   133         if (!
Isdir($Row[
'ufile_mode'])) {
   134           $V .= 
"<td align='right'>  " . number_format($Row[
'pfile_size'], 0, 
"", 
",") . 
"  </td>";
   136           $V .= 
"<td> </td>";
   140       $displayItem = 
Isdir($Row[
'ufile_mode']) ? 
"$Name/" : 
$Name;
   142         $displayItem = 
"<a href=\"$Link\">$displayItem</a>";
   145         $displayItem = 
"<b>$displayItem</b>";
   147       $V .= 
"<td>$displayItem</td>\n";
   150         $V .= 
menu_to_1list($MenuPfileNoCompare, $Parm, 
"<td>", 
"</td>\n", 1, $Upload);
   151       } 
else if (!
Isdir($Row[
'ufile_mode'])) {
   152         $V .= 
menu_to_1list($MenuPfile, $Parm, 
"<td>", 
"</td>\n", 1, $Upload);
   154         $V .= 
menu_to_1list($MenuTag, $Parm, 
"<td>", 
"</td>\n", 1, $Upload);
   158     if (! $ShowSomething) {
   159       $text = _(
"No files");
   160       $V .= 
"<b>$text</b>\n";
   163       if (count($Results) == 1) {
   168         $V .= count($Results) . 
" $text\n";
   180     $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
   182     $uiFolderNav = $GLOBALS[
'container']->get(
'ui.folder.nav');
   184     $folderNav = 
'<div id="sidetree">';
   185     if ($folderId != $rootFolder->getId()) {
   186       $folderNav .= 
'<div class="treeheader" style="display:inline;"><a href="' .
   187           Traceback_uri() . 
'?mod=' . $this->Name . 
'">Top</a> | </div>';
   189     $folderNav .= 
'<div id="sidetreecontrol" class="treeheader" style="display:inline;"><a href="?#">Collapse All</a> | <a href="?#">Expand All</a></div>';
   190     $folderNav .= $uiFolderNav->showFolderTree($folderId).
'</div>';
   192     $this->vars[
'folderNav'] = $folderNav;
   194     $assigneeArray = $this->getAssigneeArray();
   195     $this->vars[
'assigneeOptions'] = $assigneeArray;
   196     $this->vars[
'statusOptions'] = $this->uploadDao->getStatusTypeMap();
   197     $this->vars[
'folder'] = $folderId;
   198     $this->vars[
'folderName'] = $rootFolder->getName();
   206     if ($this->
State != PLUGIN_STATE_READY) {
   209     $this->folderDao->ensureTopLevelFolder();
   216     if (!empty($folder_pk) && !$this->folderDao->isFolderAccessible($folder_pk)) {
   217       $this->vars[
'message'] = _(
"Permission Denied");
   218       return $this->
render(
'include/base.html.twig');
   222     if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
   223       $this->vars[
'message'] = _(
"Permission Denied");
   224       return $this->
render(
'include/base.html.twig');
   227     if (empty($folder_pk)) {
   230       } 
catch (Exception $exc) {
   231         return $exc->getMessage();
   236     if ($output instanceof Response) {
   240     $this->vars[
'content'] = $output;
   241     $modsUploadMulti = MenuHook::getAgentPluginNames(
'UploadMulti');
   242     if (!empty($modsUploadMulti)) {
   243       $multiUploadAgents = array();
   244       foreach ($modsUploadMulti as $mod) {
   245         $multiUploadAgents[$mod] = $GLOBALS[
'Plugins'][$mod]->title;
   247       $this->vars[
'multiUploadAgents'] = $multiUploadAgents;
   249     $this->vars[
'folderId'] = $folder_pk;
   251     return $this->
render(
'ui-browse.html.twig');
   260     $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
   261     if (empty($uploadId)) {
   262       return $rootFolder->getId();
   267     $dbManager = $container->get(
'db.manager');
   268     $uploadExists = $dbManager->getSingleRow(
   269       "SELECT count(*) cnt FROM upload WHERE upload_pk=$1 " .
   270       "AND (expire_action IS NULL OR expire_action!='d') AND pfile_fk IS NOT NULL", array($uploadId));
   271     if ($uploadExists[
'cnt']< 1) {
   272       throw new Exception(
"This upload no longer exists on this system.");
   275     $folderTreeCte = $this->folderDao->getFolderTreeCte($rootFolder);
   277     $parent = $dbManager->getSingleRow(
   279         " SELECT ft.folder_pk FROM foldercontents fc LEFT JOIN folder_tree ft ON fc.parent_fk=ft.folder_pk "   280         . 
"WHERE child_id=$2 AND foldercontents_mode=$3 ORDER BY depth LIMIT 1",
   281         array($rootFolder->getId(), $uploadId, FolderDao::MODE_UPLOAD),
   282         __METHOD__.
'.parent');
   284       throw new Exception(
"Upload $uploadId missing from foldercontents in your foldertree.");
   286     return $parent[
'folder_pk'];
   298     $dbManager = $container->get(
'db.manager');
   301     $uploadtree_tablename = 
"";
   302     if (! empty($uploadTreeId)) {
   303       $sql = 
"SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = $1";
   304       $row = $dbManager->getSingleRow($sql, array($uploadTreeId));
   305       $Upload = $row[
'upload_fk'];
   306       if (! $this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
   307         $this->vars[
'message'] = _(
"Permission Denied");
   308         return $this->
render(
'include/base.html.twig');
   313         $View = &$Plugins[plugin_find_id(
"view")];
   314         if (! empty($View)) {
   315           $this->vars[
'content'] = $View->ShowView(NULL, 
"browse");
   316           return $this->
render(
'include/base.html.twig');
   319       $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row[
'upload_fk']);
   320       $html .= 
Dir2Browse($this->Name, $uploadTreeId, NULL, 1, 
"Browse", -1, 
'', 
'', $uploadtree_tablename) . 
"\n";
   321     } 
else if (!empty($Upload)) {
   322       $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
   324         $uploadtree_tablename) . 
"\n";
   327     if (empty($Upload)) {
   328       $this->vars[
'show'] = $show;
   333     if (empty($uploadTreeId)) {
   335         $uploadTreeId = $this->uploadDao->getUploadParent($Upload);
   336       } 
catch(Exception $e) {
   337         $this->vars[
'message'] = $e->getMessage();
   338         return $this->
render(
'include/base.html.twig');
   341     $html .= $this->ShowItem($Upload, $uploadTreeId, $show, $Folder, $uploadtree_tablename);
   342     $this->vars[
'content'] = $html;
   343     return $this->
render(
'include/base.html.twig');
   349   private function getAssigneeArray()
   353     $userDao = $container->get(
'dao.user');
   354     $assigneeArray = $userDao->getUserChoices();
   355     $assigneeArray[Auth::getUserId()] = _(
'-- Me --');
   356     $assigneeArray[1] = _(
'Unassigned');
   357     $assigneeArray[0] = 
'';
   358     return $assigneeArray;
   363 $NewPlugin->Install();
 
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. 
Traceback_uri()
Get the URI without query to this location. 
DirMode2String($Mode)
Convert a file mode to string values. 
ShowFolder($folderId)
Given a folderId, list every item in it. If it is an individual file, then list the file contents...
#define PLUGIN_DB_READ
Plugin requires read permission on DB. 
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types. 
This is the Plugin class. All plugins should: 
RegisterMenus()
Customize submenus. 
Output()
This function returns the output html. 
Traceback_parm_keep($List)
Create a new URI, keeping only these items. 
outputItemHtml($uploadTreeId, $Folder, $Upload)
getFolderId($uploadId)
kludge for plugins not supplying a folder parameter. Find what folder this upload is in...
Dir2BrowseUpload($Mod, $UploadPk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $uploadtree_tablename='uploadtree')
Get an html links string of a file browse path. 
render($templateName, $vars=null)