This topic is locked
[SOLVED]

 How To send an email with several selected records

10/14/2010 10:59:15 AM
PHPRunner General questions
G
gchable author

How To send an email with several selected records + GRAN TOTAL:
OrderID: 10249

Customer: TRADH

Total: $1,000.00

-------------------

OrderID: 10251

Customer: VICTE

Total: $1,000.00

-------------------

OrderID: 10253

Customer: HANAR

Total: $1,000.00

-------------------

Gran total: $3,000.00

G
gchable author 10/15/2010

any help?

ideas?

T
tedwilder 10/16/2010



any help?

ideas?


I'm quite sure there is a code for doing that in the help file under advanced topic, programming , email.

T
tedwilder 10/16/2010

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="var form = $('#frmAdmin1')[0];

    form.a.value='email'; form.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:
    ";
    echo "File: " . $arr["errors"][0]["file"] . "
    ";
    echo "Line: " . $arr["errors"][0]["line"] . "
    ";
    echo "Description: " . $arr["errors"][0]["description"] . "
    ";
    }
    }
    }
  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"];

G
gchable author 10/16/2010

Ok, tks:
where is "gran total" on this code? i need sum
1,000.00

1,000.00

1,000.00

--------

3,000.00
Anyone know of a way I can make this work?
Thank you in advance for help.

Sergey Kornilov admin 10/18/2010

It really depends on what kind of code you end up using. Here is an example, see my additions in bold:

$body="";

$total=0;

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 .= "Total: " . $data['Total'] . "\n-------------------\n\n";
$total+=$data['Total'];
}
$body .= "-------------------\nGrand total: " . $total . "\n-------------------";

G
gchable author 10/19/2010

Thank you, work fine