|
To send an email with several selected records on the list page
you need to create new button and implement two events.
Note: Change the values listed in
red to match your specific needs.
1. Proceed to the Visual
Editor page.
2. Switch to HTML mode and find the line {BEGIN delete_link}.
Add the following code right before it:
<SPAN class=buttonborder>
<INPUT class=button onclick="frmAdmin.a.value='email'; frmAdmin.submit(); return false;"
value="Email selected" type=button>
</SPAN>
|
3. Add the following code to the List page: Before process event.
response.Flush
dim arr,i
if Request.Form("a")="email" then
if Request("selection[]").Count>0 then
body=""
set rmail=CreateDictionary()
for i=1 to Request.Form("selection[]").Count
arr=split(Request.Form("selection[]").Item(i),"&")
if asp_count(arr)>=0 then
set keys=CreateDictionary()
keys("OrderID")=asp_urldecode(arr(0))
where = KeyWhere(keys,"")
set data = dal.orders.Query(where,"")
body=body & "OrderID: " & data("OrderID") & vbcrlf
body=body & "Customer: " & data("CustomerID") & vbcrlf
body=body & "Employee: " & data("EmployeeID") & vbcrlf & "-------------------" & vbcrlf & vbcrlf
data.close
set data=nothing
end if
next
' send the email
rmail("to")="test@test.com"
rmail("subject")="Sample subject"
rmail("body")=body
set arr = runner_mail(rmail)
' if error happened print a message on the web page
if arr("mailed") then
response.Write "Error happened: <br>"
response.Write "File: " & arr("source") & "<br>"
response.Write "Line: " & arr("number") & "<br>"
response.Write "Description: " & arr("description") & "<br>"
end if
end if
end if
|
4. Add the following code to the List page: Before record deleted
event. This will prevent your data from being deleted.
Function BeforeDelete(where,deleted_values)
'delete records
if Request.Form("a")="delete" then _
BeforeDelete=true
'do not delete if 'Email selected' button was clicked
if Request.Form("a")="email" then _
BeforeDelete=false
end Function
|
Sample email message:
OrderID: 10249
Customer: TRADH
Employee: 6
-------------------
OrderID: 10251
Customer: VICTE
Employee: 3
-------------------
OrderID: 10253
Customer: HANAR
Employee: 3
-------------------
Note: How to send
email to the current logged user.
Instead of hardcoded email address you can send it to the
current logged user. If you use email address as a username use the
following:
email=Session("UserID")
If email address is stored in another field of users table you
need to save it to the session variable in AfterSuccessfulLogin event:
Session("email")=data("email");
Then in BeforeProcess event
code use the following:
email=Session("email")
|