home *** CD-ROM | disk | FTP | other *** search
/ 207.233.110.77 / 207.233.110.77.tar / 207.233.110.77 / vbasic / user.asp < prev    next >
Text File  |  2003-09-18  |  15KB  |  395 lines

  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <% Option Explicit %>
  3. <!-- METADATA 
  4.    TYPE="TypeLib" 
  5.    FILE="C:\Program Files\Common Files\System\ADO\msado21.tlb" 
  6. -->
  7. <!--#include file="DatabaseConnect.asp"-->
  8. <!--#include file="Crypt-DeCrypt.asp"-->
  9. <% If Session("ValidatedStudent") <> True Then
  10.     Response.Redirect "error.asp?error=denied"
  11. End If %>
  12. <HTML>
  13. <head>
  14. <title>Moorpark College Visual Basic Student Information</title>
  15. </head>
  16. <body>
  17. <%
  18.     Dim objRS              'Recordset Object
  19.     Dim sSQL              'SQL string
  20.     Dim i
  21.     Dim iContent      'Count of Files and Folders
  22.     Dim strUser          'Email of User
  23.     Dim strAbsPath    'Absolute Path of active directory -- strRoot & <folder>\<folder> etc.
  24.     Dim strRelPath    'Relative Path of active directory -- <folder>\<folder> etc.
  25.     Dim strRoot          'Root path - c:\vbstudents\<student folder>
  26.     Dim strFile          'Text file to view/delete -- includes absolute path and file name
  27.     Dim strFolder        'Name of folder to create
  28.     Dim strTmp
  29.     Dim objFSO            'FileSystemObject 
  30.     Dim objF              'Folder Object needed for CreateFolder method of the FSO
  31.     Dim objFolder        'FolderObject 
  32.     Dim objTextFile    'TextFileObject
  33.     Dim objItem          'Object variable used to loop through the contents of the folder (objFolder)
  34.  
  35.     strUser = Request.QueryString("email")
  36.     sSQL = "SELECT * FROM Students WHERE email = '" & strUser & "';"
  37.     Set objRS = Server.CreateObject("ADODB.Recordset")
  38.     objRS.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  39.     'Make sure the student's account exists
  40.     If Not (objRS.EOF And objRS.BOF) Then 
  41.       'Determine the Root directory of the account
  42.       strRoot = "c:/vbStudents/" & objRS("folder") & "/"
  43.       'Determine the relative Path of the active directory--"path" does NOT contain a preceeding '/'
  44.       strRelPath = LCase(Trim(DeCrypt(Request.QueryString("path"))))
  45.       'Determine the absolute Path of the active directory. 
  46.       strAbsPath = strRoot & strRelPath
  47.       'Create the File System Object
  48.       Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  49.       Select Case LCase(Trim(Request.QueryString("action")))
  50.           'List the folders and files of the current directory
  51. '---LIST
  52.       Case "list"
  53.           'Display the Page Heading -- Shown only with "list action"
  54.           If objRS("security") = vbStudent Then
  55.         i = Instr(objRS("name"), ",")
  56.         Response.Write ("<H2><CENTER>Student " & mid(objRS("name"), i+1) & " " & _
  57.                mid(objRS("name"), 1, i-1) & " -- Your Instructor is " & objRS("teacher") &  "</CENTER></H2>")
  58.         Response.Write ("<CENTER>Contents of  /" & strRelPath & "</CENTER>")
  59.           Else
  60.             Response.Write ("<H2><CENTER>Instructor " & objRS("name") & "</H2><BR>Contents of  /" & strRelPath & "</CENTER>")
  61.           End If          
  62.           'Display the Student's Directories and Files 
  63.           'Create the Folder object (to easily access the folder's files and subfolders)
  64.           Set objFolder = objFSO.GetFolder(strAbsPath)
  65.           'Title row of the dir/file table
  66.           %>
  67.           <BR><CENTER>
  68.           <TABLE BORDER="5" BORDERCOLOR="green" CELLSPACING="0" CELLPADDING="2">
  69.             <TR BGCOLOR="#006600">
  70.             <TD ALIGN="center"><FONT COLOR="#FFFFFF"><B>File/Dir Name</B></FONT></TD>
  71.             <TD ALIGN="center"><FONT COLOR="#FFFFFF"><B>Size (bytes)</B></FONT></TD>
  72.             <TD ALIGN="center"><FONT COLOR="#FFFFFF"><B>Created/Uploaded</B></FONT></TD>
  73.             <TD ALIGN="center"><FONT COLOR="#FFFFFF"><B>View</B></FONT></TD>
  74.             <TD ALIGN="center"><FONT COLOR="#FFFFFF"><B>DownLoad</B></FONT></TD>
  75.             <TD ALIGN="center"><FONT COLOR="#FFFFFF"><B>Delete</B></FONT></TD>
  76.           </TR>
  77.           <%
  78.           'If the Folder is a SubFolder (strRoot <> strAbsPath), display an 'Up a Level' entry
  79.           If LCase(strRoot) <> LCase(strAbsPath) Then
  80.             i = InStrRev(strRelPath, "/")
  81.             If i > 0 Then
  82.               strTmp = mid(strRelPath, 1, i - 1)
  83.             Else
  84.               strTmp = ""
  85.             End If
  86.           %>
  87.           <TR BGCOLOR="#CCFFCC">
  88.             <TD COLSPAN="6" ALIGN="left" ><%= ShowImageForType("up") %> 
  89.                 <A HREF="<%= "user.asp?email=" & strUser & "&action=list&path=" & Crypt(strTmp) %>">Up a Level</A>
  90.             </TD>
  91.           </TR>                       
  92.           <%
  93.           End If
  94.           'First list any folders
  95.           iContent = 0
  96.           For Each objItem In objFolder.SubFolders
  97.             iContent = iContent + 1
  98.             'Make sure that folders directly off the root of the account are not
  99.             '    preceded by a '/'
  100.             If Len(strRelPath) > 0 Then
  101.               strTmp = strRelPath & "/" & objItem.Name
  102.             Else
  103.               strTmp = objItem.Name
  104.             End If
  105.         %>
  106.         <TR BGCOLOR="#CCFFCC">
  107.         <TD ALIGN="left" ><%= ShowImageForType("dir") %> 
  108.           <A HREF="<%= "user.asp?email=" & strUser & "&action=list&path=" & Crypt(strTmp) %>"><%= objItem.Name %></A></TD>
  109.         <TD ALIGN="right"> </TD>
  110.         <TD ALIGN="left" ><%= objItem.DateCreated %> </TD>
  111.         <TD ALIGN="center"> </TD>
  112.         <TD ALIGN="center"> </TD>
  113.         <TD ALIGN="center">
  114.           <A HREF="<%= "user.asp?email=" & strUser & "&action=delete&file=" & objItem.Name & "&path=" & Crypt(strRelPath) & "&folder=yes" %>">Delete</A></TD>
  115.         </TR>
  116.         <%
  117.           Next 'objItem
  118.           'Now list the files
  119.           For Each objItem In objFolder.Files
  120.               iContent = iContent + 1
  121.         %>
  122.         <TR BGCOLOR="#CCFFCC">
  123.         <TD ALIGN="left" ><%= ShowImageForType(objItem.Name) %> <%= objItem.Name %></TD>
  124.         <TD ALIGN="right"><%= objItem.Size %> </TD>
  125.         <TD ALIGN="left" ><%= objItem.DateCreated %> </TD>
  126.         <% 
  127.         'Display the View link if the File is a Text file
  128.         If LCase(mid(objItem.Name, Instr(objItem.Name, ".") + 1)) = "txt" Then
  129.         %>
  130.         <TD ALIGN="center">
  131.           <A HREF="<%= "user.asp?email=" & strUser & "&action=view&file=" & objItem.Name & "&path=" & Crypt(strRelPath) %>">View</A></TD>
  132.         <%
  133.         Else
  134.         %>
  135.         <TD ALIGN="center"> </TD>
  136.         <%
  137.         End If
  138.         'Display the Download link
  139.         %>
  140.         <TD ALIGN="center">
  141.           <A HREF="<%= "startdownload.asp?file=" & Crypt(strAbsPath & "/" & objItem.Name) & "&name=" & objItem.Name & "&size=" & objItem.Size %>">Download</A></TD>
  142.         <%
  143.         'Display the Delete link
  144.         %>
  145.         <TD ALIGN="center" >
  146.           <A HREF="<%= "user.asp?email=" & strUser & "&action=delete&file=" & objItem.Name & "&path=" & Crypt(strRelPath) & "&folder=no" %>">Delete</A></TD>
  147.         </TR>
  148.         <%
  149.           Next 'objItem
  150.           'Display a Folder Empty row if no subfolders or files exist (for new accounts)
  151.           If iContent = 0 Then %>
  152.               <TR>
  153.                   <TD COLSPAN="6" ALIGN="left">
  154.                       <FONT COLOR=RED><B>Empty...</B></FONT><BR>
  155.                   </TD>
  156.               </TD>
  157.           <%
  158.           End If
  159.           Set objItem = Nothing
  160.           Set objFolder = Nothing
  161.           Set objFSO = Nothing
  162.           %>
  163.           <TR>
  164.           <TD COLSPAN="6" ALIGN="left">
  165.             <%  
  166.             strTmp = "user.asp?email=" & strUser & "&action=newfolder&path=" & Crypt(strRelPath)
  167.             %>
  168.             <FORM METHOD=POST NAME=makefolder ACTION="<%=strTmp%>">
  169.                 <%
  170.                 'Display an Error message if the folder name is invalid
  171.                 If Session("NewFolderError") = True Then    %>
  172.                       <FONT COLOR=RED>           
  173.                                     
  174.                                     
  175.                                    
  176.                       <B>Invalid New Folder Name!</B></FONT><BR>
  177.                 <%
  178.                     Session("NewFolderError") = False 
  179.                 Else %>
  180.                     <BR>
  181.                 <%
  182.                 End If
  183.                 %>
  184.                 <!--Button for Upload option-->
  185.                 <INPUT TYPE="BUTTON" VALUE="Upload a File" OnClick="document.location='user.asp?action=upload&email=<%=strUser%>&path=<%=Crypt(strRelPath)%>';">
  186.                 <!--Textbox and Button for Create Folder option-->
  187.                          
  188.                   Folder Name:<INPUT TYPE=TEXT NAME="foldername" size="20">
  189.                   <INPUT TYPE=SUBMIT VALUE="Create Folder Here">
  190.             </FORM>
  191.           </TD> 
  192.           </TR>
  193.           <TD COLSPAN="6" ALIGN="left">
  194.           <b><font color="#FF0000">Caution</font></b><font color="#FF0000"><b>:</b></font> Deleting a Folder will
  195.           <font color="#FF0000">permanently</font> delete all subfolders and files it contains.
  196.          </TD>
  197.          </TR>
  198.           </TABLE></CENTER>
  199.           <BR>
  200.           <HR>
  201.           <%
  202.           If Trim(Session("Admin")) <> "" Then
  203.           %>
  204.             <INPUT TYPE="Button" ALIGN="left" VALUE="Back To Admin Page" onClick="document.location='admin.asp';"> 
  205.           <%
  206.           Else
  207.           %>
  208.         <INPUT TYPE="Button" ALIGN="left" VALUE="Scores and Grade Status" onClick="document.location='Scores-Grade.asp?email=<%=strUser%>&path=<%=Crypt(strRelPath)%>';">
  209.         <INPUT TYPE="Button" ALIGN="right" VALUE="Change My Password" onClick="document.location='ChangePassword.asp?email=<%=strUser%>&path=<%=Crypt(strRelPath)%>';">
  210.           <%          
  211.           End If
  212.           %>
  213.           <INPUT TYPE="Button" ALIGN="left" VALUE="Logout" onClick="document.location='default.asp';"> 
  214.           <BR>
  215.           <HR>
  216.           <P>If you have questions or comments please contact me: 
  217.           <A HREF="mailto:gcampbell@moorparkcollege.net">Guy Campbell</A></P>
  218.           <%
  219. '---DELETE
  220.         'Delete the selected Folder or File
  221.         Case "delete"
  222.           strFile = strAbsPath & "/" & Request.QueryString("file")
  223.           Select Case LCase(Trim(Request.QueryString("folder")))
  224.             Case "yes"
  225.               'Delete the folder
  226.                  objFSO.DeleteFolder (strFile)
  227.             Case "no"
  228.               'Delete the file
  229.                  objFSO.DeleteFile (strFile)
  230.           End Select
  231.           Response.Redirect ("user.asp?email=" & strUser & "&action=list&path=" & Crypt(strRelPath))
  232. '---VIEW
  233.         'View the selected ("file") Text file
  234.         Case "view"
  235.           %>
  236.           <P STYLE="word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0"> 
  237.           <P STYLE="word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0">
  238.           <b>--Use your browser's back button to return to your file listing--</b>
  239.           <P>  
  240.           <%
  241.           strFile = strAbsPath & "/" & Request.QueryString("file")
  242.           'Open the file
  243.           Set objTextFile = objFSO.OpenTextFile(strFile)
  244.           'Display each line of the text file
  245.           Do While Not objTextFile.AtEndOfStream
  246.               strTmp = objTextFile.ReadLine 
  247.               For i = 1 to Len(strTmp) Step 2
  248.                 'Replace 2 spaces with 3 HTML spaces
  249.                 If Mid(strTmp, i, 2) = "  " Then
  250.                   Response.Write ("   ")
  251.                 Else
  252.                   Response.Write (Mid(strTmp, i, 2))
  253.                 End If
  254.               Next
  255.               Response.Write "<BR>" & vbCrLf
  256.           Loop
  257.           'Close the file
  258.           objTextFile.Close
  259.           Set objTextFile = Nothing
  260.           Set objFSO = Nothing
  261. '---UPLOAD
  262.         Case "upload"
  263.           'Set session variables for the ProcessUpload.asp page--which contains the code that moves the uploaded 
  264.           '        file from the default c:\vbstudents folder to the user's current folder (strAbsPath)
  265.           Session("uprelpath") = strRelPath
  266.           Session("upabspath") = strAbsPath
  267.           Session("upemail") = strUser
  268.           Response.Write ("<BR><BR><BR><BR><BR><H2><CENTER>Upload a file to  /" & strRelPath & "</CENTER></H2><BR>")
  269.           %>
  270.           <CENTER>
  271.           <TABLE BORDER="5" BORDERCOLOR="green" CELLSPACING="0" CELLPADDING="2">
  272.             <TR BGCOLOR="#CCFFCC">
  273.                 <TD ALIGN="center">
  274.                 <H3>Select the File to Upload</H3>
  275.               </TD>
  276.             </TR>
  277.             <TR BGCOLOR="#CCFFCC">
  278.               <TD ALIGN="center">
  279.                 <FONT SIZE="2" COLOR=RED><B>Note:  Please do not attempt to upload folders.  
  280.                                              This site supports file uploads only.</B></FONT>
  281.               </TD>
  282.              </TR>
  283.             <TR BGCOLOR="#CCFFCC">
  284.               <TD ALIGN="center" VALIGN="center"><BR>
  285.                 <FORM ACTION="./cgi-bin/upload.exe" ENCTYPE="multipart/form-data" METHOD="post">
  286.                     <P><INPUT NAME="filename" SIZE="30" TYPE="file">  
  287.                         <INPUT TYPE="submit" VALUE=" Upload file "></p>
  288.                 </FORM>
  289.               </TD>
  290.             </TR>
  291.           </TABLE>
  292.           </CENTER>
  293.           <BR>
  294.           <HR>
  295.           <INPUT TYPE="Button" ALIGN="center" VALUE="Cancel" onClick="document.location='<%="user.asp?email=" & strUser & "&action=list&path=" & Crypt(strRelPath)%>';"> 
  296.           <%
  297. '---NEWFOLDER
  298.         'Create the specified folder ("foldername") in the current directory
  299.         Case "newfolder"
  300.           strTmp = Trim(Request.Form("foldername"))
  301.           'Verify folder name is Valid
  302.           If strTmp = "" Or _
  303.                 Instr(strTmp, "/") > 0 Or _
  304.                 Instr(strTmp, ":") > 0 Or _
  305.                 Instr(strTmp, "?") > 0 Or _
  306.                 Instr(strTmp, ">") > 0 Or _
  307.                 Instr(strTmp, "'") > 0 Or _
  308.                 Instr(strTmp, "*") > 0 Or _
  309.                 Instr(strTmp, "\") > 0 Or _
  310.                 Instr(strTmp, """") > 0 Then
  311.                 Session("NewFolderError") = True
  312.           Else
  313.               strFolder = strAbsPath & "/" & strTmp
  314.             If objFSO.FolderExists(strFolder) = False Then
  315.                'Use the File System Object's CreateFolder method to make the folder 
  316.               Set objF = objFSO.CreateFolder(strFolder)
  317.             End If
  318.             Session("NewFolderError") = False
  319.           End If
  320.           Response.Redirect ("user.asp?email=" & strUser & "&action=list&path=" & Crypt(strRelPath))
  321.       End Select
  322.     Else
  323.     'No Records Message
  324.     Response.Write ("<H1>Account Not Found!</H1>")
  325.   End If
  326.     objRS.Close
  327.     Set objRS = Nothing
  328.     objConn.Close
  329.     Set objConn = Nothing
  330.    %>
  331.  
  332. </body>
  333. </html>
  334.  
  335. <%
  336. ' This function takes a filename and returns the appropriate image for
  337. ' that file type based on it's extension.  If you pass it "dir", it assumes
  338. ' that the corresponding item is a directory and shows the folder icon.
  339. Function ShowImageForType(strName)
  340.     Dim strTemp
  341.     'Set our working string to the one passed in
  342.     strTemp = strName
  343.     
  344.     'If it's not a directory, get the extension and set it to strTemp
  345.     ' If it is a directory, then we already have the correct value
  346.     If strTemp <> "dir" Then
  347.         strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
  348.     End If
  349.     
  350.     ' Debugging line used to perfect that above string parser
  351.     'Response.Write strTemp
  352.     
  353.     ' Set the part of the image file name that's unique to the type of file
  354.     ' to it's correct value and set this to strTemp. (yet another use of it!)
  355.     Select Case strTemp
  356.         Case "asp"
  357.             strTemp = "asp"
  358.         Case "dir"
  359.             strTemp = "dir"
  360.         Case "htm", "html"
  361.             strTemp = "htm"
  362.         Case "gif", "jpg", "bmp"
  363.             strTemp = "img"
  364.         Case "txt", "doc"
  365.             strTemp = "txt"
  366.         Case "vb"
  367.             strTemp = "vb"
  368.         Case "resx"
  369.             strTemp = "resx"
  370.         Case "user"
  371.             strTemp = "user"
  372.         Case "vbproj"
  373.             strTemp = "vbproj"
  374.         Case "vbp"
  375.             strTemp = "vbp"
  376.         Case "zip"
  377.             strTemp = "zip"
  378.         Case "up"
  379.             strTemp = "up"
  380.         Case Else
  381.             strTemp = "misc"
  382.     End Select
  383.  
  384.     'All our logic is done... build the IMG Tag for display to the browser
  385.     '     Place it into... where else... strTemp!
  386.  
  387.     'The images are all GIFs and all start with "dir_" 
  388.     '    They end with one of the values set in the select statement above.
  389.  
  390.     strTemp = "<IMG SRC="".\images\dir_" & strTemp & ".gif"" WIDTH=16 HEIGHT=16 BORDER=0>"
  391.  
  392.     ' Set return value and exit function
  393.     ShowImageForType = strTemp
  394. End Function
  395. %>