View Complete Thread | FoxWeb Forum Home
Search:
Date:    Msg ID:   
From:    Thread:   
Subject:   

<%
set defau to \\newserver\pos\portal\news\
if not used('Tree')
 use tree in 0
endif

%>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--

function OpenURL(winName, newURL) {
  window.name = "Email"
  win = window.open("", winName,"height=120,width=300,status=yes,toolbar=no,menubar=no,location=no");
  win.location.href = newURL;
  //win.moveTo(screen.availWidth/2-(300/2),screen.availHeight/2-(120/2));
//  document.Email.Receipient.value = newURL;
}

function submitconfirm()
 {
 document.confirm.submit();
 }

// -->
</SCRIPT>
<head>
 <style type="text/css">
 <!--
  <%=FILETOSTR('\\toyzportal\programs\wt\Portal.css')%>
 -->
 </style>
</head>
</head>
<%
cBranch = request.item("Branch")
cAction = request.item('Action')
cNodeId = request.item('NodeID')
if not empty(cAction)
 do case
 case cAction ='Remove' 
  %>
    <form name='confirm' method='post' action="tree.fwx?action=Delete&NodeID=<%=alltrim(cNodeId)%>&Branch=<%=alltrim(cBranch)%>">
     <br>Are you sure you want to delete<br>
     <input type="submit" name="Confirm" value="Cancel" class="nicebutton">
     <input type="submit" name="Confirm" value="Delete" class="nicebutton">
    </form>  
  <%
 case cAction = 'Delete' and Request.Form("Confirm") = "Delete"
   Sele Tree
   Set order to Node_ID
   if seek(cNodeId)
       Delete
   endif
 endcase
endif
cPath = getPath(cBranch)
nLevel = 0
%> <a href="tree.fwx">Collapse</a><br><br>
 <Table border='0'>
 <%
 DisplayTree(cBranch)
 %>
 </table>
</html>

<%
function displayTree(cBranch)

SELECT * from tree WHERE parent_id = '0' order by Rank INTO CURSOR topLevel
SELECT topLevel
if not empty(cBranch)
 RootParent = GetRootParent(cBranch)  && Manually branching @ 6
endif

SCAN 
   xKey = Node_ID
   xText = alltrim(NodeDesc)
   xParent = Parent_ID
   xLinktype = Linktype
   xNodeAction = [<a href="tree.fwx?Branch=]+alltrim(xKey)+[">]
  
   do case
   case upper(xLinktype) = 'FOLDER'
     imgIcon = "/images/folder_ico.gif"
   Case upper(xLinktype) = 'FILE'
     imgIcon = "/images/attach.gif" 
           xNodeAction = [<a href="Downloadfile.fwx?cfile=]+alltrim(NodeAction)+[">]    
   otherwise
       imgIcon = "/images/link_ico.gif"
       xNodeAction = [<a target="_blank" href="]+alltrim(NodeAction)+[">]
   endcase 
  

%>
   <tr>
      <td><a href="tree.fwx?Action=Remove&NodeID=<%=alltrim(xKey)%>&Branch=<%=alltrim(cBranch)%>"><img src="/images/deletemail.gif" border='0'></td>
      <td><img src="/images/edit.ico"></td>
      <td>
<%
    if not empty(cBranch)  && we need to branch out
     if xKey = RootParent
      do case
      case xLinktype = 'FOLDER'
       imgIcon = "/images/OpenFolder.gif"
      endcase 
     endif
    endif
%>
        <img src="<%=imgIcon%>"><%=xNodeAction%><%=xText%></a>
      </td>
   </tr>
<%
    if not empty(cBranch)  && we need to branch out
     if xKey = RootParent
      DisplayChildren(xKey,nLevel)
     endif
    endif
ENDSCAN   
endfunc


  FUNCTION GetRootParent(cKey)
  LOCAL cSel
  cSel = SELECT()
  SELECT Tree
  SET ORDER TO Node_ID
  SEEK cKey
  IF EOF()
     SELECT(cSel)
     RETURN '0'
  ENDIF
  xParent = Parent_ID
  IF xParent <> '0'
   GetRootParent(xParent) && keep going till we get to the root
  ELSE
   xParent = Node_ID  && Reached 0 which is top level
  ENDIF
  SELECT(cSel)
RETURN (xParent)

Function DisplayChildren(uid,nLevel)
  local xKey,xText,xParent,cCursor
  nlevel = nlevel + 1
  cCursor = sys(2015)
  SELECT Node_ID, NodeDesc, Parent_ID,Linktype,NodeAction FROM Tree;
  WHERE Parent_ID = uid ORDER BY RANK Into Cursor &cCursor
  Sele &cCursor
  Scan
     xKey = Node_ID
     xText = alltrim(NodeDesc)
     xParent = Parent_ID
     xLinktype = Linktype
     xNodeAction = [<a href="tree.fwx?Branch=]+alltrim(xKey)+[">]
     do case
     case upper(xLinktype) = 'FOLDER'
      imgIcon = "/images/folder_ico.gif"
     Case upper(xLinktype) = 'FILE'
      imgIcon = "/images/attach.gif"      
           xNodeAction = [<a href="Downloadfile.fwx?cfile=]+alltrim(NodeAction)+[">]
     otherwise
           imgIcon = "/images/link_ico.gif"
       xNodeAction = [<a target="_blank" href="]+alltrim(NodeAction)+[">]          
     endcase 
%> 
  <tr>
   <table border='0'>
    <tr>
     <% if Inlist(alltrim(xKey),&cPath)
      do case
      case upper(xLinktype) = 'FOLDER'
       imgIcon = "/images/OpenFolder.gif"
      Case upper(xLinktype) = 'FILE'
       imgIcon = "/images/attach.gif"      
      otherwise
       imgIcon = "/images/link_ico.gif"
      endcase 
      endif
     %>
     <%Indent(nLevel)%>
     <td><a href="tree.fwx?Action=Remove&NodeID=<%=alltrim(xKey)%>&Branch=<%=alltrim(cBranch)%>"><img src="/images/deletemail.gif" border='0'></a></td>
     <td><img src="/images/edit.ico"></td>
     <td><img src="<%=imgIcon%>"><%=xNodeAction%><%=xText%></a></td>
    </tr>
   </table>
  </tr>
<%
     onlevel = nLevel
     if Inlist(alltrim(xKey),&cPath)
          nlevel = nLevel + 1
          DisplayChildren(xKey,nLevel)
        nLevel = nlevel -1
     endif
  endscan
  if used(cCursor)
   use in (cCursor)
  endif  
  return
ENDFUNC

FUNCTION GetParent(cChild)
SELECT Tree
SET ORDER TO Node_ID
SEEK cChild
IF NOT EOF()
 RETURN Parent_ID
ELSE
 RETURN ""
ENDIF
**************
FUNCTION GetPath(cChild)
oParent = GetParent(cChild)
cPathStr = [']+alltrim(cChild)+[']+','+[']+alltrim(oParent)+[']+','
DO WHILE NOT EMPTY(oParent)
 oParent = GetParent(oParent)
 cPathStr = cPathStr+[']+alltrim(oParent)+[']+','
ENDDO
return substr(cPathStr,1,len(cPathStr)-4)
ENDFUNC
*****
function Indent(nLevel)

for x = 1 to nLevel
  %>
  <td width='5'></td>
  <%
endfor   
**********

Sent by Larry Zhang on 03/23/2006 12:43:16 PM:
How did you achieve this? Could you show us your script?
Thanks.
 
Sent by Ali Koumaiha on 02/21/2006 06:42:21 AM:
Thank you.  I ended up doing that and I wrote a nice script to display 'tree like' from a table.  tested it on:
 
1000 Record (Parents)
  100 Children
    each child having 300 records.
 
And it was really fast :)
 
I love Foxweb
 
 
Sent by FoxWeb Support on 02/20/2006 05:31:45 PM:
Are you asking for help on the structure of the table that will hold this information?  A fairly popular method is to have a parent id field in your table, indicating the parent id of the current document.  At the very minimum, your table will contain a document id, the parent document id, a title and the content.  It would be fairly easy to write a recursive function that can return all descendants of a particular document.
 
In addition to this, you could add a RootID field, representing the top level document for a particular child.  This would allow you to quickly get a list of all descendants of a root, with a single select statement (as opposed to having to call the recursive function I mentioned above).

FoxWeb Support Team
support@foxweb.com email

Sent by Ali Koumaiha on 02/19/2006 07:37:04 PM:
I am currently using Foxweb and i have developed an internal portal/ordering system for my company.  I am currently stuck on a design issue for our File-Library section.
 
Basically, Our corporate staff will be placing files and links and news articles on the portal section and it is appearing to me that it will look like a tree in a sense.
 
I have spent a week so far to come up with a nice design to handle this.  I am stuck.  Any thoughts would be greatly appreciated.
 
I have created a Tree table similar to the table of the Treeview of FoxPro, but i haven't been  successful.
 
This is what i would like to have:
 
- Root 1
   - Child 1.1
   - Child 1.2
   ----- Child 1.2.1
- Root 2
- Root 3
  - Child 3.1
 
Etc.  I am thinking, when the script loads the page, i only display the parents (root 0) Root 1,2 & 3.  Then, depending on which link (fwx will track the root by something like this DisplayRoot.fwx?NodeID="<%=root%>". 
But, the expand function is killing me.  Any thoughts?  Has anyone coded a catalog/tree type similar to my concept and were succesful?
Please help.
 
Thanks