|
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.
|
if(@$_REQUEST["a"]=="email")
{
if(@$_REQUEST["selection"])
{
$body="";
foreach(@$_REQUEST["selection"]
as $keyblock)
{
$arr=split("&",refine($keyblock));
if(count($arr)<1)
continue;
$keys=array();
$keys["OrderID"]=urldecode(@$arr[0]);
$where =
KeyWhere($keys);
$rs =
CustomQuery("select
* from orders where $where");
$data=db_fetch_array($rs);
$body .=
"OrderID:
" .
$data['OrderID']
.
"\n";
$body .=
"Customer:
" .
$data['CustomerID']
. "\n";
$body .=
"Employee:
" .
$data['EmployeeID']
.
"\n-------------------\n\n";
}
// send the email
$email="test@test.com";
$subject="Sample
subject";
$arr =
runner_mail(array('to'
=>
$email,
'subject' =>
$subject,
'body' =>
$body));
// if error happened print a message on the web page
if (!$arr["mailed"])
{
echo
"Error happened: <br>";
echo
"File: " .
$arr["errors"][0]["file"]
.
"<br>";
echo
"Line: "
. $arr["errors"][0]["line"]
.
"<br>";
echo
"Description: " .
$arr["errors"][0]["description"]
.
"<br>";
}
}
}
|
4. Add the following code to the List page: Before record deleted
event. This will prevent your data from being deleted.
//delete records
if(@$_POST["a"]=="delete")
return true;
//do not delete if 'Email selected' button was clicked
if(@$_POST["a"]=="email")
return false;
|
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"];
|