Email Membership Group

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Email Membership Group

Post by kbarrett » 2019-04-04 19:54

Hello,

I am trying to figure out a couple of more things to customize my project. One of them is I would like to email a subset of a group based on their $memberInfo['custom'][1] which is 'Position' once a record is changed in the table that pertains to their 'Position' I have tried a few different permutations in the table hook in the after insert section and only have ended up with errors. I am assuming I would have to start with some sort of SQL query to get the group emails but am lost on how to get there. Any thoughts?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Email Membership Group

Post by pbottcher » 2019-04-04 20:12

Hi,
if you want to send an email after a record has been created, use the after_insert function, if you want to send the mail after a record has been updated, use the after_update function.

In your SQL you just need to retrieve the e-mail address for the users with the $memberInfo['custom'][1] = YOURSEARCHSTRING

something like

Code: Select all

SQL("SELECT email FROM `membership_users` where custom2='YOURSEARCHSTRING'",$eo);
this should give you all e-mail addresses.

Note $memberInfo['custom'][1] should map to the DB field custom2, $memberInfo['custom'][0] to custom1
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Email Membership Group

Post by kbarrett » 2019-04-04 20:43

Hi, Thanks, I am a little slow at, well lots, anyway I tried to create a variable from the SQL query and name it Group for this code:
// to compose a message containing the submitted data,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}

sendmail(array(
'to' => '[email protected]', <--- tried adding Group here, no luck.
'name' => 'Recipient Name',

'subject' => 'A new record needs your attention',

'message' => "The following new record was submitted by {$memberInfo['username']}: \n\n" . $messageData
);

return TRUE;
}

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Email Membership Group- Still stuck

Post by kbarrett » 2019-04-09 19:59

I borrowed some code and have been trying to get it to work in place of my previous failed attempts. I can get the email to work from my last post above, it emails me fine. However I would like to email a group or the Position which is defined in $memberInfo['custom'][1] which is "Position". I have tried numerous iterations of the code and either end up with errors or nothing. I would be fine with emailing the $memberInfo['group'] if that was all I could do.
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='MyTableName' , pkValue='#recID',
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);

@mail(
// mail recipient
" I need to email the group or ideally the Position here. The sql would be - SQL("SELECT email FROM `membership_users` where custom2='Position'",$eo);",

// subject
"A record in the MyTable table of the database was changed - notification - This Record-{$data['Table_Id']}",

// message
"The above record {$data['Table_Id']} was just modified by:{$memberInfo['username']} The record was updated on and by:{$data['RevisedBy']} \n To view the record please go to \n http://mydomain.com/project/MyTable_vie ... ID=".$data['selectedID']." Newly entered data shows as actual table values below:,
{$messageData} \n. Please review or make any changes or corrections as required. \n\n",


// sender address
"[email protected]"
);
return TRUE;

}

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Still stuck

Post by kbarrett » 2019-04-12 18:45

No solutions ?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Email Membership Group

Post by pbottcher » 2019-04-12 20:53

Hi,

can you try

$res=SQL("SELECT email FROM `membership_users` where where custom2='Position'",$eo);
$name="";
while($row = db_fetch_assoc($res)) {
$name=$name.";".$row['email'];
}
$name=ltrim($name, ';');

sendmail(array(
'to' => $name,
'name' => "[email protected]",
'subject' => "A record in the MyTable table of the database was changed - notification - This Record-{$data['Table_Id']}",,
'message' => "The above record {$data['Table_Id']} was just modified by:{$memberInfo['username']} The record was updated on and by:{$data['RevisedBy']} \n To view the record please go to \n http://mydomain.com/project/MyTable_vie ... ID=".$data['selectedID']." Newly entered data shows as actual table values below:,
{$messageData} \n. Please review or make any changes or corrections as required. \n\n", HTML allowed'
));
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Email Membership Group

Post by kbarrett » 2019-04-13 02:54

Hi,

I changed the appropriate values and it doesn't work. The pages doesn't load.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Email Membership Group

Post by kbarrett » 2019-04-13 03:37

Here is the latest code I tried:
$res=SQL("SELECT email FROM `membership_users` where custom2='Position'",$eo);
$name="";
while($row = db_fetch_assoc($res)) {
$name=$name.";".$row['email'];
}
$name=ltrim($name, ';');

sendmail(array(
'to' => $name,
'name' => "myemail@mysite",
'subject' => "A record in the My_table table of the database was changed - notification - This Record-{$data['Table_Id']}",,
'message' => "The above record {$data['Table_Id']} was just modified by:{$memberInfo['username']} The record was updated on and by:{$data['RevisedBy']} \n To view the record please go to \n https://mysite.com/myproject/MyTable_vi ... ID=".$data['selectedID']." Newly entered data shows as actual table values below:,
{$messageData} \n. Please review or make any changes or corrections as required. \n\n", 'HTML allowed'
));

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Email Membership Group - Solved

Post by kbarrett » 2019-04-17 18:53

To close this string. With a lot of incredible assistance from PBoettcher the following code will work in both the after_insert and after_update sections of the hook file:
function My_Table_after_insert($data, $memberInfo, &$args){

$res=SQL("SELECT email FROM `membership_users` where custom2='{$data['Name_of_field']}'",$eo);

while($row = db_fetch_assoc($res)) {

$send_rc=sendmail(array(

'to' => $row['email'],

'name' => "Some Name",

'subject' => "A new record has been added to the My Table. This record pertains to your position - Notification - This Record-{$data['ID']}",

'message' => "The above record id:{$data['ID']} [{$data['A_Field']}] was just modified by:{$memberInfo['username']} The record was updated on {$data['Another_Field']} \n To view the record please go to \n https://yoursite.com/yourdb/My-Table_vi ... dID={$data['selectedID']}

\nPlease review or make any changes or corrections as required. \n\n"

));



}

return TRUE;


}

Post Reply