Пример #1
0
 /**
  * \brief This function returns the FOSSology logo and
  * Folder Navigation bar
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     global $Plugins;
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /* Load the logo image */
             $Uri = Traceback_uri();
             $V .= "<center><a href='http://fossology.org' target='_top'><img alt='FOSSology' title='FOSSology' src='{$Uri}images/fossology-logo.gif' align=absmiddle border=0></a></center><br>\n";
             $V .= FolderListScript();
             $V .= "<small><center>";
             $text = _("Expand");
             $V .= "<a href='javascript:Expand();'>{$text}</a> |";
             $text = _("Collapse");
             $V .= "<a href='javascript:Collapse();'>{$text}</a> |";
             $text = _("Refresh");
             $V .= "<a href='" . Traceback() . "'>{$text}</a>";
             $V .= "</center></small>";
             $V .= "<P>\n";
             /* Display the tree */
             $V .= "<form>\n";
             $V .= FolderListDiv(-1, 0);
             $V .= "</form>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Пример #2
0
 /**
  * \brief Given a Folder_pk, list every upload in the folder.
  */
 function ShowFolder($Folder, $Show)
 {
     global $Plugins;
     global $PG_CONN;
     $V = "";
     /* Get list of uploads in this folder */
     $sql = "SELECT * FROM upload\n        INNER JOIN uploadtree ON upload_fk = upload_pk\n        AND upload.pfile_fk = uploadtree.pfile_fk\n        AND parent IS NULL\n        AND lft IS NOT NULL \n        WHERE upload_pk IN\n        (SELECT child_id FROM foldercontents WHERE foldercontents_mode & 2 != 0 AND parent_fk = {$Folder})\n        ORDER BY upload_filename,upload_desc,upload_pk,upload_origin;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $Uri = Traceback_uri() . "?mod=" . $this->Name;
     $V .= "<table border=1 width='100%'>";
     $V .= "<tr><td valign='top' width='20%'>\n";
     $V .= FolderListScript();
     $text = _("Folder Navigation");
     $V .= "<center><H3>{$text}</H3></center>\n";
     $V .= "<center><small>";
     if ($Folder != GetUserRootFolder()) {
         $text = _("Top");
         $V .= "<a href='" . Traceback_uri() . "?mod=" . $this->Name . "'>{$text}</a> |";
     }
     $text = _("Expand");
     $V .= "<a href='javascript:Expand();'>{$text}</a> |";
     $text = _("Collapse");
     $V .= "<a href='javascript:Collapse();'>{$text}</a> |";
     $text = _("Refresh");
     $V .= "<a href='" . Traceback() . "'>{$text}</a>";
     $V .= "</small></center>";
     $V .= "<P>\n";
     $V .= "<form>\n";
     $V .= FolderListDiv($Folder, 0, $Folder, 1);
     $V .= "</form>\n";
     $V .= "</td><td valign='top'>\n";
     $text = _("Uploads");
     $V .= "<center><H3>{$text}</H3></center>\n";
     $V .= "<table class='text' id='browsetbl' border=0 width='100%' cellpadding=0>\n";
     $text = _("Upload Name and Description");
     $text1 = _("Upload Date");
     $V .= "<th>{$text}</th><th>{$text1}</th></tr>\n";
     /* Browse-Pfile menu */
     $MenuPfile = menu_find("Browse-Pfile", $MenuDepth);
     /* Browse-Pfile menu without the compare menu item */
     $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare");
     while ($Row = pg_fetch_assoc($result)) {
         if (empty($Row['upload_pk'])) {
             continue;
         }
         $Desc = htmlentities($Row['upload_desc']);
         $UploadPk = $Row['upload_pk'];
         /* check permission on upload */
         $UploadPerm = GetUploadPerm($UploadPk);
         if ($UploadPerm < PERM_READ) {
             continue;
         }
         $Name = $Row['ufile_name'];
         if (empty($Name)) {
             $Name = $Row['upload_filename'];
         }
         /* If UploadtreePk is not an artifact, then use it as the root.
            Else get the first non artifact under it.
            */
         if (Isartifact($Row['ufile_mode'])) {
             $UploadtreePk = DirGetNonArtifact($Row['uploadtree_pk'], $uploadtree_tablename);
         } else {
             $UploadtreePk = $Row['uploadtree_pk'];
         }
         $V .= "<tr><td>";
         if (IsContainer($Row['ufile_mode'])) {
             $V .= "<a href='{$Uri}&upload={$UploadPk}&folder={$Folder}&item={$UploadtreePk}&show={$Show}'>";
             $V .= "<b>" . $Name . "</b>";
             $V .= "</a>";
         } else {
             $V .= "<b>" . $Name . "</b>";
         }
         $V .= "<br>";
         if (!empty($Desc)) {
             $V .= "<i>" . $Desc . "</i><br>";
         }
         $Upload = $Row['upload_pk'];
         $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk'];
         if (Iscontainer($Row['ufile_mode'])) {
             $V .= menu_to_1list($MenuPfile, $Parm, " ", " ", 1, $UploadPk);
         } else {
             $V .= menu_to_1list($MenuPfileNoCompare, $Parm, " ", " ", 1, $UploadPk);
         }
         /* Job queue link */
         $text = _("History");
         if (plugin_find_id('showjobs') >= 0) {
             $V .= "<a href='" . Traceback_uri() . "?mod=showjobs&upload={$UploadPk}'>[{$text}]</a>";
             $V .= "</td>\n";
             $V .= "<td align='right'>" . substr($Row['upload_ts'], 0, 19) . "</td>";
         }
         $V .= "<tr><td colspan=2>&nbsp;</td></tr>\n";
     }
     pg_free_result($result);
     $V .= "</table>\n";
     $V .= "</td></tr>\n";
     $V .= "</table>\n";
     return $V;
 }
Пример #3
0
/**
 * \brief Create the folder tree, using DIVs.
 * This is recursive!
 * NOTE: If there is a recursive loop in the folder table, then
 * this will loop INFINITELY.
 *
 * \param $ParentFolder  parent folder_pk
 * \param $Depth         folder depth to display, -1 to use users root folder
 * \param $HighLight     Optional, folder_pk of folder to highlight.
 * \param $ShowParent    Optional default is false. true if parent should be in shown in the tree.
 *
 * \return HTML of the folder tree
 */
function FolderListDiv($ParentFolder, $Depth, $Highlight = 0, $ShowParent = 0)
{
    global $Plugins;
    global $PG_CONN;
    if (empty($PG_CONN)) {
        return;
    }
    if (empty($ParentFolder)) {
        return;
    }
    if ($ParentFolder == "-1") {
        return FolderListDiv(GetUserRootFolder(), 0);
    }
    $Browse =& $Plugins[plugin_find_id("browse")];
    $Uri = Traceback_uri();
    $V = "";
    if ($Depth != 0) {
        $V .= "<font class='treehide1' color='white'>";
        $V .= "+&nbsp;";
        $V .= "</font>";
        if ($Depth > 1) {
            for ($i = 1; $i < $Depth; $i++) {
                $V .= "<font class='treehide'>";
                $V .= "+&nbsp;";
                $V .= "</font>";
            }
        }
    }
    /* Load this folder's parent */
    if ($ShowParent && $ParentFolder != GetUserRootFolder()) {
        $sql = "SELECT parent_fk FROM foldercontents WHERE foldercontents_mode = 1 AND child_id = '{$ParentFolder}' LIMIT 1;";
        $result = pg_query($PG_CONN, $sql);
        DBCheckResult($result, $sql, __FILE__, __LINE__);
        if (pg_num_rows($result) > 0) {
            $row = pg_fetch_assoc($result);
            $P = $row['parent_fk'];
            if (!empty($P) && $P != 0) {
                $ParentFolder = $P;
            }
            pg_free_result($result);
        } else {
            pg_free_result($result);
            // No parent
            return "";
        }
    }
    /* Load this folder's name */
    $sql = "SELECT folder_name,folder_desc FROM folder WHERE folder_pk={$ParentFolder} LIMIT 1;";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    $Name = trim($row['folder_name']);
    $Desc = trim($row['folder_desc']);
    if ($Name == "") {
        $Name = "[default]";
    }
    $Desc = str_replace('"', "&quot;", $Desc);
    pg_free_result($result);
    /* Load any subfolders */
    $sql = "SELECT folder.folder_pk, folder.folder_name AS name,\n                                 folder.folder_desc AS description, \n                                 foldercontents.parent_fk AS parent, \n                                 foldercontents.foldercontents_mode, \n                                 NULL AS ts, NULL AS upload_pk, NULL AS pfile_fk, NULL AS ufile_mode\n                          FROM folder, foldercontents\n                          WHERE foldercontents.foldercontents_mode = 1\n                                AND foldercontents.parent_fk ={$ParentFolder}\n                                AND foldercontents.child_id = folder.folder_pk\n                                AND folder.folder_pk is not null\n                          ORDER BY name";
    /* Now create the HTML */
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    if (pg_num_rows($result) > 0) {
        $V .= '<a href="javascript:ShowHide(' . "'TreeDiv-{$ParentFolder}'" . ')"><font class="treebranch">+</font></a>';
    } else {
        $V .= "<font class='treearm'>&ndash;</font>";
    }
    $V .= "&nbsp;";
    if (!empty($Desc)) {
        $Title = 'title="' . $Desc . '"';
    } else {
        $Title = "";
    }
    if (plugin_find_id("basenav") >= 0) {
        $Target = "target='basenav'";
    } else {
        $Target = "";
    }
    if (!empty($Browse)) {
        $V .= "<a {$Title} {$Target} class='treetext' href='{$Uri}?mod=browse&folder={$ParentFolder}'>";
    }
    if (!empty($Highlight) && $Highlight == $ParentFolder) {
        $V .= "<font style='border: 1pt solid; color:red; font-weight:bold;'>";
    }
    $V .= htmlentities($Name);
    if (!empty($Highlight) && $Highlight == $ParentFolder) {
        $V .= "</font>";
    }
    if (!empty($Browse)) {
        $V .= "</a>";
    }
    $V .= "<br>\n";
    if (pg_num_rows($result) > 0) {
        $Hide = "";
        if ($Depth > 0) {
            $Hide = "style='display:none;'";
        }
        $V .= "<div id='TreeDiv-{$ParentFolder}' {$Hide}>\n";
        while ($row = pg_fetch_assoc($result)) {
            $V .= FolderListDiv($row['folder_pk'], $Depth + 1, $Highlight);
        }
        $V .= "</div>\n";
    }
    pg_free_result($result);
    return $V;
}