Beispiel #1
0
/**
 * \brief Get an html linked string of a file browse path.
 *
 * \param $Mod - Module name (e.g. "browse")
 * \param $UploadtreePk
 * \param $LinkLast - create link (a href) for last item and use LinkLast as the module name
 * \param $ShowBox - true to draw a box around the string
 * \param $ShowMicro - true to show micro menu
 * \param $Enumerate - if >= zero number the folder/file path (the stuff in the yellow bar)
 *   starting with the value $Enumerate
 * \param $PreText - optional additional text to preceed the folder path
 * \param $PostText - optional text to follow the folder path
 * \param $uploadtree_tablename
 *
 * \return string of browse paths
 */
function Dir2Browse($Mod, $UploadtreePk, $LinkLast = NULL, $ShowBox = 1, $ShowMicro = NULL, $Enumerate = -1, $PreText = '', $PostText = '', $uploadtree_tablename = "uploadtree")
{
    $V = "";
    if ($ShowBox) {
        $V .= "<div style='border: thin dotted gray; background-color:lightyellow'>\n";
    }
    if ($Enumerate >= 0) {
        $V .= "<table border=0 width='100%'><tr><td width='5%'>";
        $V .= "<font size='+2'>" . number_format($Enumerate, 0, "", ",") . ":</font>";
        $V .= "</td><td>";
    }
    $Opt = Traceback_parm_keep(array("folder", "show"));
    $Uri = Traceback_uri() . "?mod={$Mod}";
    /* Get array of upload recs for this path, in top down order.
       This does not contain artifacts.
       */
    $Path = Dir2Path($UploadtreePk, $uploadtree_tablename);
    $Last =& $Path[count($Path) - 1];
    $V .= "<font class='text'>\n";
    /* Add in additional text */
    if (!empty($PreText)) {
        $V .= "{$PreText}<br>\n";
    }
    /* Get the FOLDER list for the upload */
    $text = _("Folder");
    $V .= "<b>{$text}</b>: ";
    if (array_key_exists(0, $Path)) {
        $List = FolderGetFromUpload($Path[0]['upload_fk']);
        $Uri2 = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array("show"));
        for ($i = 0; $i < count($List); $i++) {
            $Folder = $List[$i]['folder_pk'];
            $FolderName = htmlentities($List[$i]['folder_name']);
            $V .= "<b><a href='{$Uri2}&folder={$Folder}'>{$FolderName}</a></b>/ ";
        }
    }
    $FirstPath = 1;
    /* every firstpath belongs on a new line */
    /* Print the upload, itself (on the next line since it is not a folder) */
    if (count($Path) == -1) {
        $Upload = $Path[0]['upload_fk'];
        $UploadName = htmlentities($Path[0]['ufile_name']);
        $UploadtreePk = $Path[0]['uploadtree_pk'];
        $V .= "<br><b><a href='{$Uri2}&folder={$Folder}&upload={$Upload}&item={$UploadtreePk}'>{$UploadName}</a></b>";
        // $FirstPath=0;
    } else {
        $V .= "<br>";
    }
    /* Show the path within the upload */
    if ($FirstPath != 0) {
        for ($p = 0; !empty($Path[$p]['uploadtree_pk']); $p++) {
            $P =& $Path[$p];
            if (empty($P['ufile_name'])) {
                continue;
            }
            $UploadtreePk = $P['uploadtree_pk'];
            if (!$FirstPath) {
                $V .= "/ ";
            }
            if (!empty($LinkLast) || $P != $Last) {
                if ($P == $Last) {
                    $Uri = Traceback_uri() . "?mod={$LinkLast}";
                }
                $V .= "<a href='{$Uri}&upload=" . $P['upload_fk'] . $Opt . "&item=" . $UploadtreePk . "'>";
            }
            if (Isdir($P['ufile_mode'])) {
                $V .= $P['ufile_name'];
            } else {
                if (!$FirstPath && Iscontainer($P['ufile_mode'])) {
                    $V .= "<br>\n&nbsp;&nbsp;";
                }
                $V .= "<b>" . $P['ufile_name'] . "</b>";
            }
            if (!empty($LinkLast) || $P != $Last) {
                $V .= "</a>";
            }
            $FirstPath = 0;
        }
    }
    $V .= "</font>\n";
    if (!empty($ShowMicro)) {
        $MenuDepth = 0;
        /* unused: depth of micro menu */
        $V .= menu_to_1html(menu_find($ShowMicro, $MenuDepth), 1);
    }
    if ($Enumerate >= 0) {
        if ($PostText) {
            $V .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$PostText}";
        }
        $V .= "</td></tr></table>";
    }
    if ($ShowBox) {
        $V .= "</div>\n";
    }
    return $V;
}
/**
 * \brief DEPRECATED! Given an upload number, return the
 * folder path in an array containing folder_pk and name.
 * This is recursive!
 * NOTE: If there is a recursive loop in the folder table, then
 * this will loop INFINITELY.
 * \todo DEPRECATED!  USE Folder2Path() and GetFolderFromItem()
 */
function FolderGetFromUpload($Uploadpk, $Folder = -1, $Stop = -1)
{
    global $PG_CONN;
    if (empty($PG_CONN)) {
        return;
    }
    if (empty($Uploadpk)) {
        return;
    }
    if ($Stop == -1) {
        $Stop = FolderGetTop();
    }
    if ($Folder == $Stop) {
        return;
    }
    $sql = "";
    $Parm = "";
    if ($Folder < 0) {
        /* Mode 2 means child_id is an upload_pk */
        $Parm = $Uploadpk;
        $sql = "SELECT foldercontents.parent_fk,folder_name FROM foldercontents\n              INNER JOIN folder ON foldercontents.parent_fk = folder.folder_pk\n\t\t\t  AND foldercontents.foldercontents_mode = " . FolderDao::MODE_UPLOAD . "\n\t\t\t  WHERE foldercontents.child_id = {$Parm} LIMIT 1;";
    } else {
        /* Mode 1 means child_id is a folder_pk */
        $Parm = $Folder;
        $sql = "SELECT foldercontents.parent_fk,folder_name FROM foldercontents\n\t\t\t  INNER JOIN folder ON foldercontents.parent_fk = folder.folder_pk\n\t\t\t  AND foldercontents.foldercontents_mode = 1\n\t\t\t  WHERE foldercontents.child_id = {$Parm} LIMIT 1;";
    }
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $R = pg_fetch_assoc($result);
    if (empty($R['parent_fk'])) {
        pg_free_result($result);
        return;
    }
    $V = array();
    $V['folder_pk'] = $R['parent_fk'];
    $V['folder_name'] = $R['folder_name'];
    if ($R['parent_fk'] != 0) {
        $List = FolderGetFromUpload($Uploadpk, $R['parent_fk'], $Stop);
    }
    if (empty($List)) {
        $List = array();
    }
    array_push($List, $V);
    pg_free_result($result);
    return $List;
}
/**
 * \brief Return a string which is a linked path to the file.
 *  This is a modified Dir2Browse() to support browsediff links.
 *  \param $Path1 - path array for tree 1
 *  \param $Path2 - path array for tree 2
 *  \param $filter - filter portion of URL, optional
 *  \param $Column - which path is being emitted, column 1 or 2
 *  \param $plugin - plugin pointer of the caller ($this)
 ************************************************************/
function Dir2BrowseDiff($Path1, $Path2, $filter, $Column, $plugin)
{
    if (count($Path1) < 1 || count($Path2) < 1) {
        return "No path specified";
    }
    $filter_clause = empty($filter) ? "" : "&filter={$filter}";
    $Path = $Column == 1 ? $Path1 : $Path2;
    $Last = $Path[count($Path) - 1];
    /* Banner Box decorations */
    $V = "<div style='border: double gray; background-color:lightyellow'>\n";
    /* Get/write the FOLDER list (in banner) */
    $text = _("Folder");
    $V .= "<b>{$text}</b>: ";
    $List = FolderGetFromUpload($Path[0]['upload_fk']);
    $Uri2 = Traceback_uri() . "?mod={$plugin->Name}";
    /* Define Freeze button */
    $text = _("Freeze path");
    $id = "Freeze{$Column}";
    $alt = _("Freeze this path so that selecting a new directory in the other path will not change this one.");
    $Options = "id='{$id}' onclick='Freeze(\"{$Column}\")' title='{$alt}'";
    $FreezeBtn = "<button type='button' {$Options}> {$text} </button>\n";
    for ($i = 0; $i < count($List); $i++) {
        $Folder = $List[$i]['folder_pk'];
        $FolderName = htmlentities($List[$i]['folder_name']);
        $V .= "<b>{$FolderName}/</b> ";
    }
    $FirstPath = true;
    /* If firstpath is true, print FreezeBtn and starts a new line */
    $V .= "&nbsp;&nbsp;&nbsp;{$FreezeBtn}";
    $V .= "<br>";
    /* Show the path within the upload */
    for ($PathLev = 0; $PathLev < count($Path); $PathLev++) {
        $PathElt1 = @$Path1[$PathLev];
        $PathElt2 = @$Path2[$PathLev];
        // temporarily ignore notice of missing Path2[PathLev]
        $PathElt = $Column == 1 ? $PathElt1 : $PathElt2;
        /* Prevent a malformed href if any path information is missing */
        $UseHref = (!empty($PathElt1) and !empty($PathElt2));
        if ($UseHref and $PathElt != $Last) {
            $href = "{$Uri2}&item1={$PathElt1['uploadtree_pk']}&item2={$PathElt2['uploadtree_pk']}{$filter_clause}&col={$Column}";
            $V .= "<a href='{$href}'>";
        }
        if (!$FirstPath) {
            $V .= "<br>";
        }
        $V .= "&nbsp;&nbsp;<b>" . $PathElt['ufile_name'] . "/</b>";
        if ($UseHref and $PathElt != $Last) {
            $V .= "</a>";
        }
        $FirstPath = false;
    }
    $V .= "</div>\n";
    // for box
    return $V;
}