Hooks Help

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
bescott53

Hooks Help

Post by bescott53 » 2018-08-02 15:12

hello everyone, I have a rather long script but it is not working as expected.

1) the emails are not coming out (i have highlighted this in the Bugs / annoyances, as yet no solution)
2) // Case 1 - This updates the Line Manager details fine
3) All other cases also update the Line Manager details, this is not right and I cant see why, anyone help me?

Code: Select all

                function commission_approvals_after_insert($data, $memberInfo, &$args){
                                
                                // Case 1
                                $line_manager_email=sqlValue("select LineManager from claimants where LineManager={$data['line_manager_name']}");
                                
                                mail(
                                /* comma-separated list of recipients */
                                $line_manager_email,

                                /* message subject */
                                "New commission request entered for your attention",

                                /* message contents */
                                "A new commission request has been added by ".getLoggedMemberID().
                                ".\n\n". 
                                "Please go to the link to review the request:\n".
                                "http://domain.com/dev_commissions/commission_approvals_view.php?SelectedID",

                                /* NEED TO CHECK WHO THE EMAIL IS COMMING FROM */
                                "From: [email protected]"
                                );

                                return TRUE;
                }

                function commission_approvals_before_update(&$data, $memberInfo, &$args){
                                
                                $_SESSION['U_approvedby_line_manager']=sqlValue("select approvedby_line_manager from commission_approvals where refnum='" . $data['refnum']. "'");
                                $_SESSION['U_approvedby_so']=sqlValue("select approvedby_so from commission_approvals where refnum='" . $data['refnum']. "'");;
                                $_SESSION['U_approvedby_ges_coo']=sqlValue("select approvedby_ges_coo from commission_approvals where refnum='" . $data['refnum']. "'");
                                $_SESSION['U_approvedby_ges_finance']=sqlValue("select approvedby_ges_finance from commission_approvals where refnum='" . $data['refnum']. "'");
                                
                                return TRUE;
                }

                function commission_approvals_after_update($data, $memberInfo, &$args){
                                
                                if($_SESSION['U_approvedby_line_manager'] != $data['approvedby_line_manager'])
                                
                                {
                                                if($data['approvedby_line_manager']=='Yes')
                                                    {
                                                                                
                                                    sql("UPDATE commission_approvals set LineManagerApprovalName='".getLoggedMemberID()."', date_approved_by_line_manager='".date('Y-m-d H:i:s')."' where refnum={$data['refnum']}", $eo);
                                                                
                                                                // Case 3
                                                                $Second_Approver_email=sqlValue("select SecondApprover from claimants where claimants_name={$data['claimants_name']}");
                                                                
                                                                $Finance_Approver_email=sqlValue("select FinanceApprover from claimants where claimants_name={$data['claimants_name']}");
                                
                                                                mail(
                                                                "'.$Second_Approver_email.','.$Finance_Approver_email.'",
                                                                /* message subject */
                                                                "New commission request for your attention",
                                                                /* message contents */
                                                                "Commission request being sent to Finance and Second Approver. Approved by Line Manager on ".$data['date_approved_by_line_manager'].
                                                                ".\n\n". 
                                                                "To view it, please go to:\n".
                                                                "http://domain.com/dev_commissions/commission_approvals_view.php?SelectedID",
                                
                                /* NEED TO CHECK WHO THE EMAIL IS COMMING FROM */
                                "From: [email protected]"
                                );                                                             
                                                    }
                                
                                                
                                                if($data['approvedby_line_manager']=='No - Evidence missing')
                                                {
                                                                sql("UPDATE commission_approvals set LineManagerApprovalName='".getLoggedMemberID()."', date_approved_by_line_manager='".date('Y-m-d H:i:s')."' where refnum={$data['refnum']}", $eo);
                                                                
                                                                // Case 2
                                                                $claimants_email= sqlValue("select claimants_email from claimants where claimants_uin={$data['claimants_name']}");
                                                                mail(
                                                                $claimants_email,
                                                                /* message subject */
                                                                "Commission Request Rejected by Line Manager - Needs further information",
                                                                /* message contents */
                                                                ".\n\n". 
                                                                "To update it, please go to:\n".
                                                                "http://domain.com/dev_commissions/commission_approvals_view.php?SelectedI",
                                
                                /* NEED TO CHECK WHO THE EMAIL IS COMMING FROM */
                                "From: [email protected]"
                                );
                                
                                                }
                                                
                                                
                                }
                                
                                
                                if(($_SESSION['U_approvedby_ges_finance']!=$data['approvedby_ges_finance'])||($_SESSION['U_approvedby_so']!=$data['approvedby_so']))
                                {
                                                
                                                
                                                
                                                if($data['approvedby_ges_finance']=='Yes'&&$data['approvedby_so']='Yes')
                                                {
                                                                
                                                                // Case 4
                                                                $claimants_email= sqlValue("select claimants_email from claimants where claimants_uin={$data['claimants_name']}");
                                                                mail(
                                                                $claimants_email,
                                                                /* message subject */
                                                                "Commission Request Approved",
                                                                /* message contents */
                                                                ".\n\n". 
                                                                "To view it, please go to:\n".
                                                                "http://domain.com/dev_commissions/commission_approvals_view.php?SelectedID=",
                                
                                /* NEED TO CHECK WHO THE EMAIL IS COMMING FROM */
                                "From: [email protected]"
                                );
                                                }
                                                
                                
                                
                                if($_SESSION['U_approvedby_ges_finance']!= $data['approvedby_ges_finance'])
                                {
                                                if($data['approvedby_ges_finance']=='No - EBIT to be corrected')
                                                {
                                                                sql("UPDATE commission_approvals set ApprovedByGESFinanceName='".getLoggedMemberID()."', date_approved_by_finance='".date('Y-m-d H:i:s')."' where refnum={$data['refnum']}", $eo);
                                                                // Case 5
                                                                $claimants_email= sqlValue("select claimants_email from claimants where claimants_uin={$data['claimants_name']}");
                                                                
                                                                $line_manager_email=sqlValue("select LineManager from claimants where LineManager={$data['line_manager_name']}");
                                                                
                                                                
                                                                mail(
                                                                "'.$claimants_email.','.$line_manager_email.'",
                                                                /* message subject */
                                                                "Commission request - finance require changes",
                                                                /* message contents */
                                                                "Claim has been rejected by finance, more information is required.\n".
                                                                "Line Manager will be required to approve again once the claim has been updated by the claimant.\n".
                                                                ".\n\n". 
                                                                "To view it, please go to:\n".
                                                                "http://domain.com/dev_commissions/commission_approvals_view.php?SelectedID=",
                                
                                /* NEED TO CHECK WHO THE EMAIL IS COMMING FROM */
                                "From: [email protected]"
                                );
                                
                                                }
                                                
                                
                                
                                if($_SESSION['U_approvedby_so']!=$data['approvedby_so'])
                                {
                                                if($data['approvedby_so']=='No - Evidence missing')
                                                {
                                                                // Case 6
                                                                
                                                                sql("UPDATE commission_approvals set SalesOpsApprovalName='".getLoggedMemberID()."', date_approved_by_so='".date('Y-m-d H:i:s')."' where refnum={$data['refnum']}", $eo);
                                                                
                                                                $line_manager_email=sqlValue("select LineManager from claimants where LineManager={$data['line_manager_name']}");
                                                                
                                                                $claimants_email= sqlValue("select claimants_email from claimants where claimants_uin={$data['claimants_name']}");
                                                                
                                                                mail(
                                                                "'.$claimants_email.','.$line_manager_email.'",
                                                                /* message subject */
                                                                "Commission Request Rejected by Second Approver",
                                                                /* message contents */
                                                                "Please provide requested information and update the commission request ".
                                                                ".\n\n". 
                                                                "Line managers will also need to approve the claim again. To update it, please go to:\n".
                                                                "http://domain.com/dev_commissions/commission_approvals_view.php?SelectedID=",
                                
                                /* NEED TO CHECK WHO THE EMAIL IS COMMING FROM */
                                "From: [email protected]"
                                                );             
                                                                 
                                                }
                                                                
                                }
                
                if($_SESSION['U_approvedby_so']!=$data['approvedby_so'])
                                {
                
                                if($data['approvedby_so']=='Yes')
                                                                                {
                                                                                                sql("UPDATE commission_approvals set SalesOpsApprovalName='".getLoggedMemberID()."', date_approved_by_so='".date('Y-m-d H:i:s')."' where refnum={$data['refnum']}", $eo);
                                                                                }
                                }
                                
                                
                                
                if($_SESSION['U_approvedby_ges_finance']!= $data['approvedby_ges_finance'])
                                {
                
                                if($data['approvedby_ges_finance']=='Yes')
                                                                                {
                                                                                                sql("UPDATE commission_approvals set ApprovedByGESFinanceName='".getLoggedMemberID()."', date_approved_by_finance='".date('Y-m-d H:i:s')."' where refnum={$data['refnum']}", $eo);
                                                                                }
                                }
                                
                                }
                
                
                                unset($_SESSION['U_approvedby_line_manager']);
                                unset($_SESSION['U_approvedby_so']);
                                unset($_SESSION['U_approvedby_ges_coo']);
                                unset($_SESSION['U_approvedby_ges_finance']);

                                return TRUE;
                }
                }

[Edit by moderator on 2018-08-07 to anonymize emails and domains]

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Hooks Help

Post by a.gneady » 2018-08-07 16:02

Please check this thread where sendmail() function is used instead of mail(): https://forums.appgini.com/phpbb/viewto ... 555&p=8318
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

bescott53

Re: Hooks Help

Post by bescott53 » 2018-08-08 10:18

Ahmad, thanks, i tried sendmail, but again, no joy. mails not coming out.

Also did you get a chance to look at my logic and see why only linemanager gets updated?

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Hooks Help

Post by a.gneady » 2018-08-15 12:57

Hmm ... didn't test your code, but you could try the following:
  • Using $_SESSION to pass variables across function is not safe and might not work as expected. Try $GLOBALS instead.
  • if 'refnum' is an auto-increment value, try $data['selectedID'] instead of $data['refnum']
  • For the mail sending issue, you might need to debug mail sending ... Please check my reply to this thread: https://forums.appgini.com/phpbb/viewto ... =11&t=2731
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

Post Reply