<%
    function getNameParent(con,id)
	dim rez
	rez=""
	set rs=server.createObject("adodb.recordset")
	rs.open "select name from cat where id=" & id,con
	while not rs.eof
	    if rs.bof then break
	    rez=rs("name").value
	    rs.moveNext
	wend
	rs.close
	set rs=nothing
	if rez="" then rez="Main"
	getNameParent=rez
    end function
    '-----------------------------
    function getIdParent(con,id)
	dim rez
	rez=""
	set rs=server.createObject("adodb.recordset")
	rs.open "select parent from cat where id=" & id,con
	while not rs.eof
	    if rs.bof then break
	    rez=rs("parent").value
	    rs.moveNext
	wend
	rs.close
	set rs=nothing
	if rez="" then rez=0
	getIdParent=rez
    end function
    '--------------------------
    set con=server.createObject("adodb.connection")
    con.open Application("Product")
%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="../../stil.css">
</head>
<body>
<h1 align=center>Administration menu page</h1>
<br>
<p align=center>
<a href="upload.asp"><font size=2 face=monospaced color=black>Upload image product</font></a>
</p>
<hr>
<%
	id=request("id")
	if id="" then id=0
	'da-mi toti copii pentru id
	
%>
<table align=center cols=4>
<tr>
<td colspan=2 align=center><font size=2><b><%=getNameParent(con,id)%></b></font></td>
<td align=center><a href="add.asp?id=<%=id%>"><img src="../images/add.gif"></a></td>
<td align=center>
<%
    if id<>0 then
%>
<a href="admin.asp?id=<%=getIdParent(con,id)%>"><img src="../images/up.gif"></a></td>
<%
    end if
%>
</tr>
<%
	set rs= server.createObject("adodb.recordset")		
	rs.open "select * from cat where parent=" & id & " order by id",con
	while not rs.eof
	    if rs.bof then break
%>
<tr>
    <td><font color=blue><b><%=rs("name")%></b></font></td>
    <td align=center width=20><a href="alterCategory.asp?id=<%=rs("id")%>"><img src="../images/alter.gif" border=1></a></td>
    <td align=center width=20><a href="askDeleteCategory.asp?id=<%=rs("id")%>"><img src="../images/delete.gif" border=1></a></td>
    <td align=center width=20>    
    <a href="admin.asp?id=<%=rs("id") %>"><img src="../images/down.gif" border=1></a>
    </td>
</tr>
<%
	    rs.moveNext
	wend
	rs.close
	set rs=nothing
	set rs=server.createObject("adodb.recordset")	
	
	rs.open "select * from items where cat_id=" & id & " order by shop_id",con
	
	while not rs.eof 
	    if rs.bof then break
%>
<tr>
    <td><font color=blue><b><%=rs("name")%></b></font></td>
    <td align=center width=20><a href="alterProduct.asp?id=<%=rs("id")%>"><img src="../images/alter.gif" border=1></a></td>
    <td align=center width=20><a href="askDeleteProduct.asp?id=<%=rs("id")%>"><img src="../images/delete.gif" border=1></a></td>
    <td align=center width=20></td>
</tr>
<%
	    rs.moveNext
	wend 
	rs.close
	set rs=nothing
	con.close
	set con=nothing
%>
</table>
<hr>
</body>
</html>