<%@ LANGUAGE="VBSCRIPT" %> <% Option Explicit %> <% If Session("ValidatedStudent") <> True Then Response.Redirect "error.asp?error=denied" End If %> Moorpark College Visual Basic Student Information <% Dim objRS 'Recordset Object Dim sSQL 'SQL string Dim i Dim iContent 'Count of Files and Folders Dim strUser 'Email of User Dim strAbsPath 'Absolute Path of active directory -- strRoot & \ etc. Dim strRelPath 'Relative Path of active directory -- \ etc. Dim strRoot 'Root path - c:\vbstudents\ Dim strFile 'Text file to view/delete -- includes absolute path and file name Dim strFolder 'Name of folder to create Dim strTmp Dim objFSO 'FileSystemObject Dim objF 'Folder Object needed for CreateFolder method of the FSO Dim objFolder 'FolderObject Dim objTextFile 'TextFileObject Dim objItem 'Object variable used to loop through the contents of the folder (objFolder) strUser = Request.QueryString("email") sSQL = "SELECT * FROM Students WHERE email = '" & strUser & "';" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText 'Make sure the student's account exists If Not (objRS.EOF And objRS.BOF) Then 'Determine the Root directory of the account strRoot = "c:/vbStudents/" & objRS("folder") & "/" 'Determine the relative Path of the active directory--"path" does NOT contain a preceeding '/' strRelPath = LCase(Trim(DeCrypt(Request.QueryString("path")))) 'Determine the absolute Path of the active directory. strAbsPath = strRoot & strRelPath 'Create the File System Object Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Select Case LCase(Trim(Request.QueryString("action"))) 'List the folders and files of the current directory '---LIST Case "list" 'Display the Page Heading -- Shown only with "list action" If objRS("security") = vbStudent Then i = Instr(objRS("name"), ",") Response.Write ("

Student " & mid(objRS("name"), i+1) & " " & _ mid(objRS("name"), 1, i-1) & " -- Your Instructor is " & objRS("teacher") & "

") Response.Write ("
Contents of  /" & strRelPath & "
") Else Response.Write ("

Instructor " & objRS("name") & "


Contents of  /" & strRelPath & "") End If 'Display the Student's Directories and Files 'Create the Folder object (to easily access the folder's files and subfolders) Set objFolder = objFSO.GetFolder(strAbsPath) 'Title row of the dir/file table %>
<% 'If the Folder is a SubFolder (strRoot <> strAbsPath), display an 'Up a Level' entry If LCase(strRoot) <> LCase(strAbsPath) Then i = InStrRev(strRelPath, "/") If i > 0 Then strTmp = mid(strRelPath, 1, i - 1) Else strTmp = "" End If %> <% End If 'First list any folders iContent = 0 For Each objItem In objFolder.SubFolders iContent = iContent + 1 'Make sure that folders directly off the root of the account are not ' preceded by a '/' If Len(strRelPath) > 0 Then strTmp = strRelPath & "/" & objItem.Name Else strTmp = objItem.Name End If %> <% Next 'objItem 'Now list the files For Each objItem In objFolder.Files iContent = iContent + 1 %> <% 'Display the View link if the File is a Text file If LCase(mid(objItem.Name, Instr(objItem.Name, ".") + 1)) = "txt" Then %> <% Else %> <% End If 'Display the Download link %> <% 'Display the Delete link %> <% Next 'objItem 'Display a Folder Empty row if no subfolders or files exist (for new accounts) If iContent = 0 Then %> <% End If Set objItem = Nothing Set objFolder = Nothing Set objFSO = Nothing %>
File/Dir Name Size (bytes) Created/Uploaded View DownLoad Delete
<%= ShowImageForType("up") %>  ">Up a Level
<%= ShowImageForType("dir") %>  "><%= objItem.Name %>   <%= objItem.DateCreated %>      ">Delete
<%= ShowImageForType(objItem.Name) %> <%= objItem.Name %> <%= objItem.Size %>  <%= objItem.DateCreated %>  View  Download ">Delete
Empty...
<% strTmp = "user.asp?email=" & strUser & "&action=newfolder&path=" & Crypt(strRelPath) %>
<% 'Display an Error message if the folder name is invalid If Session("NewFolderError") = True Then %>                                                         Invalid New Folder Name!
<% Session("NewFolderError") = False Else %>
<% End If %>         Folder Name:
Caution: Deleting a Folder will permanently delete all subfolders and files it contains.


<% If Trim(Session("Admin")) <> "" Then %> <% Else %> <% End If %>

If you have questions or comments please contact me: Guy Campbell

<% '---DELETE 'Delete the selected Folder or File Case "delete" strFile = strAbsPath & "/" & Request.QueryString("file") Select Case LCase(Trim(Request.QueryString("folder"))) Case "yes" 'Delete the folder objFSO.DeleteFolder (strFile) Case "no" 'Delete the file objFSO.DeleteFile (strFile) End Select Response.Redirect ("user.asp?email=" & strUser & "&action=list&path=" & Crypt(strRelPath)) '---VIEW 'View the selected ("file") Text file Case "view" %>

 

--Use your browser's back button to return to your file listing--

<% strFile = strAbsPath & "/" & Request.QueryString("file") 'Open the file Set objTextFile = objFSO.OpenTextFile(strFile) 'Display each line of the text file Do While Not objTextFile.AtEndOfStream strTmp = objTextFile.ReadLine For i = 1 to Len(strTmp) Step 2 'Replace 2 spaces with 3 HTML spaces If Mid(strTmp, i, 2) = " " Then Response.Write ("   ") Else Response.Write (Mid(strTmp, i, 2)) End If Next Response.Write "
" & vbCrLf Loop 'Close the file objTextFile.Close Set objTextFile = Nothing Set objFSO = Nothing '---UPLOAD Case "upload" 'Set session variables for the ProcessUpload.asp page--which contains the code that moves the uploaded ' file from the default c:\vbstudents folder to the user's current folder (strAbsPath) Session("uprelpath") = strRelPath Session("upabspath") = strAbsPath Session("upemail") = strUser Response.Write ("




Upload a file to  /" & strRelPath & "


") %>

Select the File to Upload

Note:  Please do not attempt to upload folders.  This site supports file uploads only.

  



';"> <% '---NEWFOLDER 'Create the specified folder ("foldername") in the current directory Case "newfolder" strTmp = Trim(Request.Form("foldername")) 'Verify folder name is Valid If strTmp = "" Or _ Instr(strTmp, "/") > 0 Or _ Instr(strTmp, ":") > 0 Or _ Instr(strTmp, "?") > 0 Or _ Instr(strTmp, ">") > 0 Or _ Instr(strTmp, "'") > 0 Or _ Instr(strTmp, "*") > 0 Or _ Instr(strTmp, "\") > 0 Or _ Instr(strTmp, """") > 0 Then Session("NewFolderError") = True Else strFolder = strAbsPath & "/" & strTmp If objFSO.FolderExists(strFolder) = False Then 'Use the File System Object's CreateFolder method to make the folder Set objF = objFSO.CreateFolder(strFolder) End If Session("NewFolderError") = False End If Response.Redirect ("user.asp?email=" & strUser & "&action=list&path=" & Crypt(strRelPath)) End Select Else 'No Records Message Response.Write ("

Account Not Found!

") End If objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %> <% ' This function takes a filename and returns the appropriate image for ' that file type based on it's extension. If you pass it "dir", it assumes ' that the corresponding item is a directory and shows the folder icon. Function ShowImageForType(strName) Dim strTemp 'Set our working string to the one passed in strTemp = strName 'If it's not a directory, get the extension and set it to strTemp ' If it is a directory, then we already have the correct value If strTemp <> "dir" Then strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1))) End If ' Debugging line used to perfect that above string parser 'Response.Write strTemp ' Set the part of the image file name that's unique to the type of file ' to it's correct value and set this to strTemp. (yet another use of it!) Select Case strTemp Case "asp" strTemp = "asp" Case "dir" strTemp = "dir" Case "htm", "html" strTemp = "htm" Case "gif", "jpg", "bmp" strTemp = "img" Case "txt", "doc" strTemp = "txt" Case "vb" strTemp = "vb" Case "resx" strTemp = "resx" Case "user" strTemp = "user" Case "vbproj" strTemp = "vbproj" Case "vbp" strTemp = "vbp" Case "zip" strTemp = "zip" Case "up" strTemp = "up" Case Else strTemp = "misc" End Select 'All our logic is done... build the IMG Tag for display to the browser ' Place it into... where else... strTemp! 'The images are all GIFs and all start with "dir_" ' They end with one of the values set in the select statement above. strTemp = "" ' Set return value and exit function ShowImageForType = strTemp End Function %>