Page 1 of 1

Batch Actions

Posted: 2022-09-02 20:24
by selectsteel
Im trying to use the Batch Action Hook to email out some stuff to our clients. I have created a Batch action and the Javascript function to open up the corresponding php page. The problem is its not sending over the Record Id just the row id's.
I have followed this to the letter and tried many things. https://bigprof.com/appgini/help/advanc ... ch-actions.
I simply want to get the record Id into the Javascript function so I can pass it to the php script I have.

function receipts_batch_actions(&$args) {
return array(
array('title' => 'Rejected Receipts', 'function' => 'email_rejected_receipts', 'icon' => 'archive' ));
This works as expected.

I then created a receipts-tv.js
function email_rejected_receipts(table_name, ids){
alert("IDs selected from " + table_name + ": " + ids);
}

This just gives me the row numbers that I checked. So I have tried alot of different things to get the record ID but nothing works.
I have a php script already to go just need the record Id to pass to it.

Re: Batch Actions

Posted: 2022-09-05 00:32
by selectsteel
I do want to clarify this a little. The Receipts table is a child table of another called Trips when I open Receipts from a Trip the Trip record number is in the URL I just need some way to grab it and use it in my script. mycustomapp.com/receipts_view.php?filterer_job_id=635& i need the job id 635.

Re: Batch Actions

Posted: 2022-09-05 03:17
by jsetzer
I just need some way to grab it and use it in my script. mycustomapp.com/receipts_view.php?filterer_job_id=635& i need the job id 635.
Don't know if I got your point. Get URL parameter in PHP:

Code: Select all

$job_id = $_REQUEST['filterer_job_id'];
or

Code: Select all

$job_id = makeSafe((string)Request::val('filterer_job_id', ''));
Tip When using values in SQL commands, you got from user input, always use makeSafe($value); before to avoid SQL injection. Never trust user input.

Re: Batch Actions

Posted: 2022-09-05 13:25
by selectsteel
Thank you as always for your help jsetzer. Im still unsure how to pass the job_id through the javascript function used in the batch action hook?
as soon as I click the Rejected Receipts under the More button the url with the ID is gone.

function receipts_batch_actions(&$args) {
return array(
array('title' => 'Rejected Receipts',
'function' => 'email_rejected_receipts',
'icon' => 'archive'));

receips-tv.js -
function email_rejected_receipts(){
var url = 'rejected-receipts.php?';}

rejected-receipts.php-
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");
$job_id = makeSafe((string)Request::val('filterer_job_id', ''));

/* retrieve the records and display mail labels */
$res = sql( "select * from receipts " .
"where job_id = $job_id AND receipt_checked = ('Rejected')", $eo);
while($row = db_fetch_assoc($res)){
?>
<b><?php echo "Date ". $row['date']; ?></b><br>
<?php echo "City Code: ". $row['city_code']; ?></i><br>
<?php echo "Type: ". $row['type']; ?><br>
<?php echo "Description: ". $row['description']; ?><br>
<?php echo "Amount: ". $row['amount']; ?><br>
<?php echo "Why it was Rejected: ". $row['reject_notes']; ?><br>
}

Re: Batch Actions

Posted: 2022-09-05 13:30
by jsetzer
Can you please format your code. That would help us reading and understanding.

Re: Batch Actions

Posted: 2022-09-05 13:39
by jsetzer
According to the specs, you have already mentioned, your javascript function should receive the primary keys of the selected rows in 2nd parameter.

Excerpt from AppGini documentation

Code: Select all

function print_mail_labels(table_name, ids){
  alert("IDs selected from " + table_name + ": " + ids);
}
Tips

- Check parameters with console.log(ids); in javascript

- Check network traffic (payload and response) in network tab of browser's development tools

- Make use of var_dump($YOUR_VARIABLE) in PHP to see what payload arrives on server side

Re: Batch Actions

Posted: 2022-09-05 14:22
by selectsteel
yeah I get receipt ids and table name no problem but I need the parent Id as well to be passed to through the javascript file into the PHP file.
Looks like i may need to use something like URLSearchParams to get the job_id from the url ?filterer_job_id=635&

Re: Batch Actions

Posted: 2022-09-05 14:37
by selectsteel
Well I feel stupid I went back and started all over again and found I had a misspelling in my Sql table and I was using the wrong column name in my sql statement. It all works as expected now. Thanks for your help.

Re: Batch Actions

Posted: 2022-09-12 13:57
by selectsteel
Now that I have the print batch actions script working like its written Im trying to email the rows returned as one email.
The only way I can get sendmail to work is like Jsetzer displays on his site.

Code: Select all

 $mail = [
"to" => "[email protected]",
"name" => "My Name",
"subject" => "App Receipts",
"message" => $message,
"From" => "from@myemail address.com"
]; 
sendmail($mail); 
so I want to take the results from the code below and email all the rows returned.

Code: Select all

  /* retrieve the records and display mail labels */
    $res = sql( "select * from receipts " .
                "where receipt_id in ({$cs_ids})", $eo);
    while($row = db_fetch_assoc($res)){
        ?>
        <b><?php echo $row['CompanyName']; ?></b><br>
        <i>C/O <?php echo $row['city_code']; ?></i><br>
        <?php echo $row['type']; ?><br>
        <?php echo $row['description']; ?><br>
        <?php echo $row['amount']; ?>
        <?php echo $row['notes']; ?><br>
         <hr>
        <?php
    }

Re: Batch Actions

Posted: 2022-09-12 20:30
by pbottcher
Hi,

just put the message text that you create in your code into the $message variable from the code above.

Re: Batch Actions

Posted: 2022-09-12 21:36
by selectsteel
only sends one record not all them.