Subversion Repositories DevTools

Rev

Rev 5958 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
29 jtweddle 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
' 			 	   NEW Upload	PDF
5
'               --- PROCESS FORM ---
6
'=====================================================
7
%>
8
<%
9
Option explicit
10
' Good idea to set when using redirect
11
Response.Expires = 0	' always load the page, dont store
12
%>
13
 
14
<!--#include file="common/config.asp"-->
15
<!--#include file="common/globals.asp"-->
16
<!--#include file="common/formating.asp"-->
17
<!--#include file="common/qstr.asp"-->
18
<!--#include file="common/common_subs.asp"-->
19
<!--#include file="common/common_dbedit.asp"-->
20
<!--#include file="upload/clsUpload.asp"-->
21
<%
22
' Set rfile parameter. This is a return page after Login
23
Call objPMod.StoreParameter ( "rfile", "Bom_Home.asp" )
24
'------------ ACCESS CONTROL ------------------
25
%>
26
<!--#include file="_access_control_general.asp"-->
27
<%
28
'------------ Variable Definition -------------
29
Dim objUpload
30
Dim sFileName
31
'------------ Constants Declaration -----------
32
'------------ Variable Init -------------------
33
Set objUpload = New clsUpload
34
'parPv_id = objUpload.Fields("pv_id").Value
35
'----------------------------------------------
36
%>
37
<%
38
'-----------------------  MAIN LINE  ---------------------------
39
 
40
'--- Process submition ---
41
 
42
If (objUpload.Fields("bom_id").Value <> "") Then
43
 
44
	' Compile path to save file to
45
	If instr(Request.ServerVariables("HTTP_USER_AGENT"), "MSIE") > 0 Then
46
		sFileName = objUpload.Fields("results_file").FileName
47
	Else
48
		sFileName = objUpload.Fields("results_file").FilePath
49
	End If
50
 
4807 dpurdie 51
    '
52
    ' Save file name into the BOMS table for backward compatability
53
    '
29 jtweddle 54
	OraSession.BeginTrans
55
	OraDatabase.ExecuteSQL "UPDATE BOMS SET PDF_ATTACHMENT_PATH='"& sFileName &"' WHERE BOM_ID ="& objUpload.Fields("bom_id").Value
56
	OraSession.CommitTrans
57
 
4807 dpurdie 58
    '
59
    '   Save the binary file into the Database as a blob
60
    '
61
    Dim OraParameters
62
    Dim OraBlob 
63
    Dim PartImage
64
    Dim amount_written
65
 
66
    Set OraParameters = OraDatabase.Parameters
67
    OraParameters.Add "PartImage", Empty,ORAPARM_OUTPUT, ORATYPE_BLOB 
68
 
69
    'BeginTrans needs to be called since LOB locators become invalid after the ExecuteSQL call 
70
    On Error Resume Next
71
    OraSession.BeginTrans
72
 
73
    '   Only retain one entry, so delete any that exist
74
	OraDatabase.ExecuteSQL "DELETE FROM BOM_ATTACHMENTS WHERE BOM_ID="& objUpload.Fields("bom_id").Value
75
 
76
    '   Create the entry with an empty blob
77
    OraDatabase.ExecuteSQL ("insert into BOM_ATTACHMENTS (BOM_ID, LENGTH, CONTENTTYPE, NAME, DATA) values ("&_
78
            objUpload.Fields("bom_id").Value &","&_
79
            objUpload("results_file").Length &",'"&_
80
            objUpload("results_file").ContentType &"','"&_
81
            sFileName & "', EMPTY_BLOB()) RETURNING DATA INTO :PartImage") 
82
    Set PartImage = OraDatabase.Parameters("PARTIMAGE").Value 
83
 
84
    '
85
    '   Need to send the data in chuncks
86
    '       Not sure what the chunk limit is, but we will try 1Meg lumps
87
    Dim data
88
    Dim dataLen
89
    Dim dataIndex
90
    Dim sendSize
91
    Dim sendType
92
 
93
    data = objUpload("results_file").BLOB
94
    dataLen = objUpload("results_file").Length
95
    dataIndex = 0
96
    sendSize = 1048576
97
    sendSize = 1024
98
    sendType = ORALOB_FIRST_PIECE
99
 
100
    Set OraBlob = OraDatabase.Parameters("PartImage").Value
101
    Do While dataLen > 0
102
 
103
        If Err.number <> 0 Then Exit Do
104
 
105
        If  dataIndex = 0 Then
106
            If sendSize > dataLen  Then
107
                sendSize = dataLen
108
                sendType = ORALOB_ONE_PIECE
109
            Else
110
                sendType = ORALOB_FIRST_PIECE
111
            End If
112
        Else
113
            If sendSize > dataLen  Then
114
                sendSize = dataLen
115
                sendType = ORALOB_LAST_PIECE
116
            End If
117
        End If
118
 
119
        amount_written = OraBlob.Write(MidB( data, 1+dataIndex, sendSize), sendSize , sendType)
120
 
121
        dataLen   = dataLen - sendSize
122
        dataIndex = dataIndex + sendSize
123
        sendType = ORALOB_NEXT_PIECE
124
    Loop
125
 
126
 
127
    ' Rollback or commit the transaction
29 jtweddle 128
	If Err.number <> 0 Then
4807 dpurdie 129
        OraSession.Rollback 
130
    Else
131
        OraSession.CommitTrans 
132
    End If
133
 
134
	'   Either update the parent display or display an error message
135
	If Err.number <> 0 Then
136
		Call RaiseMsgInParent ( enum_MSG_ERROR, "Upload is not completed.<br>" & Err.description  )
29 jtweddle 137
	Else
138
		Call OpenInParentWindow ("Bom_Home.asp?bom_id="& objUpload.Fields("bom_id").Value)
139
	End If
140
 
141
	Set objUpload = Nothing
142
	Call CloseWindow
143
 
144
Else
6029 dpurdie 145
	Response.write "Some mandatory parameters are missing!" & "<br>" 'TODO
29 jtweddle 146
	Response.write QSTR_All 
147
 
148
End If
5958 dpurdie 149
Call Destroy_All_Objects
29 jtweddle 150
%>
151