5.2 EMAIL HOOK CHANGED??

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2013-11-08 20:54

Ahmad,

Did the hooks change with the new 5.20/ I am trying to do the email changes and added this and it crashed the view.. I had to take it out and it worked fine. So I was unsuccessful using the tutorial for emailing changes to a record.

Code: Select all

function orders_insert(){
	// mm: save record change data
	$recID=mysql_insert_id();
	sql("insert into membership_user records set tableName='routes', pkValue='#recID', 
	memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()." ',
	groupID=' ".getLoggedGroupID().".", $eo);
	
	@mail(
	/*comma-separated listed of recipients */
	"[email protected], email2@oursitecom,
	
	/*message subject */
	"Database change to the Routes table notification", 
	
	
	/*message contents */
	"A new record has been added by:  ".getLoggedMemberID().
	".\n\n".
	"To view it, please go to: \n"
	"http://oursite.com/appginidatabasefilefolder/routes_view.php?SelectedID=$redID",
	
	/*sender email */
	"From: [email protected]"
	);

I put it right before this line..

Code: Select all

	return (get_magic_quotes_gpc() ? stripslashes($recID) : $recID);

}

on routes_dml.php file in the appgini database folder on my site.
I of course used my domain and proper emails but for the sake of the forum removed them here.

Please advise if this is different now or the code should be now that the program was updated.

Thanks, Tina
Tina O'Connell
Web Dev & Appgini FAN

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

Re: 5.2 EMAIL HOOK CHANGED??

Post by a.gneady » 2013-11-17 21:47

There are some syntax errors in the code .. Try this:

Code: Select all

    function orders_insert(){
       // mm: save record change data
       $recID=mysql_insert_id();
       sql("insert into membership_userrecords set tableName='routes', pkValue='$recID',
       memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()." ',
       groupID=' ".getLoggedGroupID().".", $eo);
       
       @mail(
       /*comma-separated listed of recipients */
       "[email protected], email2@oursitecom",
       
       /*message subject */
       "Database change to the Routes table notification",
       
       
       /*message contents */
       "A new record has been added by:  ".getLoggedMemberID().
       ".\n\n".
       "To view it, please go to: \n"
       "http://oursite.com/appginidatabasefilefolder/routes_view.php?SelectedID=$redID",
       
       /*sender email */
       "From: [email protected]"
       );

       return (get_magic_quotes_gpc() ? stripslashes($recID) : $recID);

}
: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.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2013-11-19 15:06

tried it, made a change and not working.. is this only for adding a record?

Where should the code be placed to send an email anytime a record is changed. I would love to see the old record content and new record content so you can see who changed what and have an email record of it.
Should it still be placed in the tablename_dml.php file or in the hooks. I had it sort of working but then I saved and uploaded a change to my file and it overwrote the content. I have to re-do it.
Would be nice to do this in the app gini file so that it uploaded each time you made changes.
I would also like to choose only certain fields to display in the email, this pulls everything. Is there a way to do that? Could not find it in the tutorials.
Tina O'Connell
Web Dev & Appgini FAN

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

Re: 5.2 EMAIL HOOK CHANGED??

Post by a.gneady » 2013-11-30 10:22

is this only for adding a record?
Yes, the above code works on insertion only.
I would love to see the old record content and new record content so you can see who changed what and have an email record of it.
Then try using the _before_insert() hook: you'll need to query the table for the original field values, then send an email listing the queried values as being the old data, and the contents of $data array as being the new data.
I would also like to choose only certain fields to display in the email, this pulls everything. Is there a way to do that? Could not find it in the tutorials.
Try something like this in place of the section labeled /* message contents */ in the hook code above:

Code: Select all

"New values:\n" . 
    "First name: {$data['first_name']}\n" .
    "Family name: {$data['family_name']}\n" .
    "Field 3: {$data['field3']}";
of course, replace the field names above with your actual field names.
: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.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-03-04 17:30

Ahmad,

How do I put the old value and the new value from a changed field into the email?

for example if I changed a driver on a route from Brittany Spears to Joe Walsh, I would like it to show both Brittany as the old value and Joe as the new value on my email..

What is the field label to pull the old value???
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-03-04 17:49

OK so in the Before insert I run the normal sql query on the routes table.. for the fields I want to capture..

then on the After insert I use the code you just mentioned for the new values.. and notification email of change.. but how to I get the old data from the before insert hook into the email generated by the after insert hook??
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-03-04 17:50

Ahmad,

I see about 50 different requests about 30 different ways to keep a log of changes. Can you just build this into your software and send out an update?

Seems like it would make allot of folks happy?? Just a thought. Are you planning this for the next update? If so when?
Tina O'Connell
Web Dev & Appgini FAN

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

Re: 5.2 EMAIL HOOK CHANGED??

Post by a.gneady » 2014-03-05 10:56

toconnell wrote:Ahmad,
I see about 50 different requests about 30 different ways to keep a log of changes. Can you just build this into your software and send out an update?
Seems like it would make allot of folks happy?? Just a thought. Are you planning this for the next update? If so when?
I have it on my backlog ... might implement it as an add-on soon.
then on the After insert I use the code you just mentioned for the new values.. and notification email of change.. but how to I get the old data from the before insert hook into the email generated by the after insert hook??
Try adding this on top of the hook file directly after <?php and outside function definitions:

Code: Select all

$old_data = array();
And in the before_insert function:

Code: Select all

global $old_data;
$old_data = $data;
And in the after_insert function:

Code: Select all

global $old_data;
Now $old_data contains, obviously, the old data before changing and you can use it in the after_insert hook.
: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.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-03-26 20:06

ahmad, Good news is not getting any errors.. but the bad news is it is not emailing anything. I emailed you the code privately for my final attempt. Would you kindly take a look for me and see if I am on target. I am most grateful once again for your assistance. Please advise when you plan on including this in the program. If soon enough I can just wait, but if not I have to figure it out soon.

Not only do I need to email the changes to this table I really need a table with them in the same database I can search.

I created a new table Historical_Log to hold the database changes. I would be most grateful if you can look at that too.. I used this code here:

Code: Select all

function routechanges_after_insert($data, $memberInfo, &$args){

$ID = $data['ID'];
$RouteNumber = $data['RouteNumber'];
$old_data = $old_data['old_data'];
$ChangedBy = $memberinfo['username'];
$ChangedDate = $data['date'];

mysql_connect("MY SERVER IP", "USER NAME", "MY PASS") or die(mysql_error()); 
mysql_select_db("school_2") or die(mysql_error()); 

if ($username <> 'al'){ //I trap to not record admin access as it is not relevant to the stats

mysql_query( "INSERT INTO Historical_Log (RouteNumber, old_data, ChangedDate, ChangedBy) VALUES ('$RouteNumber', '$old_data', '$ChangedBy', '$ChangedDate')") or die(mysql_error());
return TRUE;
}

It too crashes the routes table when I put it into the routes insert hook hooks/routes.php
after this line:

function routes_after_insert($data, $memberInfo, &$args){
Tina O'Connell
Web Dev & Appgini FAN

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

Re: 5.2 EMAIL HOOK CHANGED??

Post by a.gneady » 2014-03-27 22:31

Hmm .. didn't test the entire code you provided as I'm busy with lots of tasks currently but this line doesn't look right:

Code: Select all

$old_data = $old_data['old_data'];
You should also define $old_data first before using it:

Code: Select all

global $old_data;
I hope these are starting points that would lead you to a fix.
: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.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-03-31 14:03

I thought I did .. following your lead..

Code: Select all

<?php
$old_data = array();
at the top..

Then..

at the routes_init function..

Code: Select all

  
   
   $username=$memberInfo['username'];
   $ip=$memberInfo['IP'];
   $date=date('m/d/Y');
   $time=date('h:i:s a');
   $old_data=$data['old data'];
   
Then at the before insert fuction

Code: Select all

	function routes_before_insert(&$data, $memberInfo, &$args){

global $old_data;
$old_data = $data;


		return TRUE;

	}
Then the after insert function..

Code: Select all

function routes_after_insert($data, $memberInfo, &$args){

// 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";
}
{
global $old_data;
}



@mail(

// mail recipient

"email address here, email address here, email addresses here",



// subject

"A record was just changed in the routes table",



// message

"The record below was entered or modified by {".$memberInfo['username']."}: \n\n".
"To view it, please go to http://bigschoolbus.com/asdata2/bus_status.php?SelectedID=".$recID."\n".
"Old data was {".$old_data."}:  \n\n".
"New Data is {".$messageData."}:  \n\n".

$messageData,



// sender address

"From: [email protected]"

);

		return TRUE;

	}
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-02 16:50

OK.. at the top of the routes.php file I now have this.. I think I have it right? Any coders, please comment.. I suck at php and am just learning.

Code: Select all

$old_data = array($data['selectedID'],$data['School'], $data['RouteNumber'], $data['County'], $data['school_name'], $data['school_contact'], $data['school_contact_number'], $data['DriverAssigned'], $data['DriverAssignedpm'], $data['UnitAssigned'], $data['PMUnitAssigned'],$data['Monitor_Assigned'],$data['Lead_driver'],$data['LeadDriverBackUp'],$data['OpsMgr'],$data['Sub_assigned1'],$data['Sub_assigned2'],$data['SpareBusses'], $data['DateDriverAssigned'],$data['DateDriverUnassigned'],$data['Notes'],$data['RouteStart'], $data['RouteEnd'], $data['FirstStopOnRoute'],$data['LastStopOnRoute'],$data['MorningBellTime'],$data['AfternoonBellTime'],$data['LastUpdated'],$data['DateSubAssigned'],$data['DateSubUnassigned'],$data['TripSubAssigned'],$data['routes_start_date'],$data['route_stop_date'],$data['school_contact_ah'],$data['record_id'],$data['Created_by']);
This is all my fields in the routes table.
I think I have now done what your saying ahmad.. but still not working.. not sure why.. anyone with suggestions please pipe up.. Ahmad is so busy I hate to be a bother but really need help here.

Thank you,
Tina
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-02 19:22

Well I got the emails to show the new data entered for all fields but not the old data..

I was putting it in the function routes_after_insert in my hooks file.. when I wanted to track updates and changes to existing records not just new records.. so when I added it to routes_after_update wala it worked!!!

But still gotta get the old data to show..

Here is the working final code to get the new data to email and work now.. this code was from line 493 of: my domain.com/database folder name here/hooks/routes.php folder

Code: Select all

function routes_after_update($data, $memberInfo, &$args){

foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}

$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='routes' , pkValue='#recID', 
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);
 
@mail(
// mail recipient or recipients
"[email protected], [email protected], [email protected]",
 
// subject
"A Record in the Routes table of the database was changed - notification - ROUTE RECORD NUMBER-{$data['RouteNumber']}",
 
// message
      "The above record {$data['RouteNumber']} was just modified by: {$memberInfo['username']} Updated on, and by user id: {$data['LastUpdated']} \n To view the record please go to \n http://mydomainname.com/mydbfolder/routes_view.php?SelectedID=".$data['selectedID']."  Newly entered data shows as actual table values below:,
	  {$messageData}\n\n", 
	  
 
// sender address 
"[email protected]"
);
		return TRUE;

	}
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-03 18:10

I still cannot get the "old data" to show.. not sure how to say in php..


UPDATE Historical_Log SET old_data=???? new_data=???

I tried your insight above but just not sure it is right..

<?php
$old_data = array();

to.. These are the fields in my routes table.. is this right? (prob. not.. any help is greatly appreicated..)

$old_data = array($data['selectedID'],$data['School'], $data['RouteNumber'], $data['County'], $data['school_name'], $data['school_contact'], $data['school_contact_number'], $data['DriverAssigned'], $data['DriverAssignedpm'], $data['UnitAssigned'], $data['PMUnitAssigned'],$data['Monitor_Assigned'],$data['Lead_driver'],$data['LeadDriverBackUp'],$data['OpsMgr'],$data['Sub_assigned1'],$data['Sub_assigned2'],$data['SpareBusses'], $data['DateDriverAssigned'],$data['DateDriverUnassigned'],$data['Notes'],$data['RouteStart'], $data['RouteEnd'], $data['FirstStopOnRoute'],$data['LastStopOnRoute'],$data['MorningBellTime'],$data['AfternoonBellTime'],$data['LastUpdated'],$data['DateSubAssigned'],$data['DateSubUnassigned'],$data['TripSubAssigned'],$data['routes_start_date'],$data['route_stop_date'],$data['school_contact_ah'],$data['record_id'],$data['Created_by']);
Tina O'Connell
Web Dev & Appgini FAN

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

Re: 5.2 EMAIL HOOK CHANGED??

Post by a.gneady » 2014-04-05 08:18

not sure how to say in php..

UPDATE Historical_Log SET old_data=???? new_data=???
Try:

Code: Select all

sql("UPDATE Historical_Log SET old_data='{$old_data['fieldname']}', new_data='{$data['fieldname']}'", $eo);
where fieldname is the name of the field you want to track.
: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.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-11 20:05

Ahmad.. you are a saint!! Oh my have I been trying to mess with this for too long.. this is perfect.. thank you sooo much!! I will crack at it Monday all day and if I get it working.. I will post up my final code for others or for you.. :)

Thanks again for your help so much! I am so grateful to you. You really are a wonderful developer!!!
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-14 18:12

Well Darn.. I know I am close but now it is crashing the compliance table and the routes table.. here is my compliance table code..

I do not believe it should be UPDATE for the sql as there are no existing rows to update, should be INSERT INTO and VALUES.. so I fixed that part.. still it is emailing but not inserting the data into the log.
I know I am close. Can you look at this one more time.

This is the entire hook code for the compliance table.

Code: Select all

<?php
$old_data = $data array();
	/**

	 * @file

	 * This file contains hook functions that get called when data operations are performed on 'compliance' table. 

	 * For example, when a new record is added, when a record is edited, when a record is deleted, … etc.

	*/



	/**

	 * Called before rendering the page. This is a very powerful hook that allows you to control all aspects of how the page is rendered.

	 * 

	 * @param $options

	 * (passed by reference) a DataList object that sets options for rendering the page.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/DataList

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * True to render the page. False to cancel the operation (which could be useful for error handling to display 

	 * an error message to the user and stop displaying any data).

	*/



	function compliance_init(&$options, $memberInfo, &$args){



		return TRUE;

	}



	/**

	 * Called before displaying page content. Can be used to return a customized header template for the table.

	 * 

	 * @param $contentType

	 * specifies the type of view that will be displayed. Takes one the following values: 

	 * 'tableview', 'detailview', 'tableview+detailview', 'print-tableview', 'print-detailview', 'filters'

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * String containing the HTML header code. If empty, the default 'header.php' is used. If you want to include

	 * the default header besides your customized header, include the <%%HEADER%%> placeholder in the returned string.

	*/



	function compliance_header($contentType, $memberInfo, &$args){

		$header='';



		switch($contentType){

			case 'tableview':

				$header='';

				break;



			case 'detailview':

				$header='';

				break;



			case 'tableview+detailview':

				$header='';

				break;



			case 'print-tableview':

				$header='';

				break;



			case 'print-detailview':

				$header='';

				break;



			case 'filters':

				$header='';

				break;

		}



		return $header;

	}



	/**

	 * Called after displaying page content. Can be used to return a customized footer template for the table.

	 * 

	 * @param $contentType

	 * specifies the type of view that will be displayed. Takes one the following values: 

	 * 'tableview', 'detailview', 'tableview+detailview', 'print-tableview', 'print-detailview', 'filters'

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * String containing the HTML footer code. If empty, the default 'footer.php' is used. If you want to include 

	 * the default footer besides your customized footer, include the <%%FOOTER%%> placeholder in the returned string.

	*/



	function compliance_footer($contentType, $memberInfo, &$args){

		$footer='';



		switch($contentType){

			case 'tableview':

				$footer='';

				break;



			case 'detailview':

				$footer='';

				break;



			case 'tableview+detailview':

				$footer='';

				break;



			case 'print-tableview':

				$footer='';

				break;



			case 'print-detailview':

				$footer='';

				break;



			case 'filters':

				$footer='';

				break;

		}



		return $footer;

	}



	/**

	 * Called before executing the insert query.

	 * 

	 * @param $data

	 * An associative array where the keys are field names and the values are the field data values to be inserted into the new record.

	 * Note: if a field is set as read-only or hidden in detail view, it can't be modified through $data. You should use a direct SQL statement instead.

	 * For this table, the array items are: 

	 *     $data['Name'], $data['FirstName'], $data['LastName'], $data['MailCity'], $data['HomePhone'], $data['WorkPhone'], $data['CellPhone'], $data['Active'], $data['ApplicationforEmployement'], $data['BackgroundCheckClearance'], $data['Comments'], $data['Complaints'], $data['CopyofApprovedVendorBadge'], $data['DateInactive'], $data['DexterityExpiration'], $data['DexterityReceived'], $data['DOB'], $data['DOTStatus'], $data['DriverNotes'], $data['DrugTest_COC_Results'], $data['Email'], $data['EmployeeHandbook'], $data['Gender'], $data['HireDate'], $data['LicenseNumber'], $data['LicenseClass'], $data['LicenseEndorsements'], $data['LicenseExpiration'], $data['LicenseRestrictions'], $data['LicenseState'], $data['LocalID'], $data['Logof40HrTrainingCourse'], $data['Logof8HrRefresherCourse'], $data['MailCounty'], $data['MailState'], $data['MailStreet1'], $data['MailStreet2'], $data['MailZipCode'], $data['MI'], $data['PhoneIssued'], $data['PhoneReturned'], $data['PhysicialExamExpired'], $data['PhysicialExamRcvd'], $data['RecordofRoadTest'], $data['TurberculosisTest'], $data['UniformIssued'], $data['vendorbadge'], $data['Fieldtripformdone'], $data['ASInsurance'], $data['ClearedCounties'], $data['DriversLicenseIMAGE'], $data['light_duty'], $data['ee_id'], $data['PTO_plan'], $data['sign_on_bonus'], $data['SSN']

	 * $data array is passed by reference so that modifications to it apply to the insert query.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * A boolean TRUE to perform the insert operation, or FALSE to cancel it.

	*/



	function compliance_before_insert(&$data, $memberInfo, &$args){
{
	global $old_data;
	$old_data=$data;
	
}
		return TRUE;

	}



	/**

	 * Called after executing the insert query (but before executing the ownership insert query).

	 * 

	 * @param $data

	 * An associative array where the keys are field names and the values are the field data values that were inserted into the new record.

	 * For this table, the array items are: 

	 *     $data['Name'], $data['FirstName'], $data['LastName'], $data['MailCity'], $data['HomePhone'], $data['WorkPhone'], $data['CellPhone'], $data['Active'], $data['ApplicationforEmployement'], $data['BackgroundCheckClearance'], $data['Comments'], $data['Complaints'], $data['CopyofApprovedVendorBadge'], $data['DateInactive'], $data['DexterityExpiration'], $data['DexterityReceived'], $data['DOB'], $data['DOTStatus'], $data['DriverNotes'], $data['DrugTest_COC_Results'], $data['Email'], $data['EmployeeHandbook'], $data['Gender'], $data['HireDate'], $data['LastUpdatedby'], $data['LastUpdated'], $data['LicenseNumber'], $data['LicenseClass'], $data['LicenseEndorsements'], $data['LicenseExpiration'], $data['LicenseRestrictions'], $data['LicenseState'], $data['LocalID'], $data['Logof40HrTrainingCourse'], $data['Logof8HrRefresherCourse'], $data['MailCounty'], $data['MailState'], $data['MailStreet1'], $data['MailStreet2'], $data['MailZipCode'], $data['MI'], $data['PhoneIssued'], $data['PhoneReturned'], $data['PhysicialExamExpired'], $data['PhysicialExamRcvd'], $data['RecordofRoadTest'], $data['TurberculosisTest'], $data['UniformIssued'], $data['vendorbadge'], $data['Fieldtripformdone'], $data['ASInsurance'], $data['ClearedCounties'], $data['DriversLicenseIMAGE'], $data['light_duty'], $data['ee_id'], $data['PTO_plan'], $data['sign_on_bonus'], $data['SSN']

	 * Also includes the item $data['selectedID'] which stores the value of the primary key for the new record.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * A boolean TRUE to perform the ownership insert operation or FALSE to cancel it.

	 * Warning: if a FALSE is returned, the new record will have no ownership info.

	*/



	function compliance_after_insert($data, $memberInfo, &$args){
global $old_data;

foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}

$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='compliance' , pkValue='#recID', 
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);
 
@mail(
// mail recipient
"[email protected]",
 
// subject
"A Record in the Driver Compliance table of the database was NEWLY CREATED -notification - Driver RECORD NUMBER-{$data['Record_Id']}",
 
// message
      "The above record {$data['Record_Id']} was just modified by: {$memberInfo['username']} The record was updated on and by user id: {$data['LastUpdatedby']},\n. To view the record please go to \n http://bigschoolbus.com/asdata2/compliance_view.php?SelectedID=".$data['selectedID']."  Newly entered data shows as actual table values below:,
	 {$messageData}  The user that changed this record did so from IP Address: {$memberInfo['IP']}  \n\n", 
	  
 
// sender address
"[email protected]"
);
		
sql("INSERT INTO Historical_Log (RouteNumber,old_data,new_data,ChangedDate,ChangedBy) VALUES({$data['Record_Id']}','{$old_data}','{$messageData}','{$data['LastUpdatedby']}','{$memberInfo['username']}'");

		return TRUE;

	}



	/**

	 * Called before executing the update query.

	 * 

	 * @param $data

	 * An associative array where the keys are field names and the values are the field data values.

	 * Note: if a field is set as read-only or hidden in detail view, it can't be modified through $data. You should use a direct SQL statement instead.

	 * For this table, the array items are: 

	 *     $data['Name'], $data['FirstName'], $data['LastName'], $data['MailCity'], $data['HomePhone'], $data['WorkPhone'], $data['CellPhone'], $data['Active'], $data['ApplicationforEmployement'], $data['BackgroundCheckClearance'], $data['Comments'], $data['Complaints'], $data['CopyofApprovedVendorBadge'], $data['DateInactive'], $data['DexterityExpiration'], $data['DexterityReceived'], $data['DOB'], $data['DOTStatus'], $data['DriverNotes'], $data['DrugTest_COC_Results'], $data['Email'], $data['EmployeeHandbook'], $data['Gender'], $data['HireDate'], $data['LicenseNumber'], $data['LicenseClass'], $data['LicenseEndorsements'], $data['LicenseExpiration'], $data['LicenseRestrictions'], $data['LicenseState'], $data['LocalID'], $data['Logof40HrTrainingCourse'], $data['Logof8HrRefresherCourse'], $data['MailCounty'], $data['MailState'], $data['MailStreet1'], $data['MailStreet2'], $data['MailZipCode'], $data['MI'], $data['PhoneIssued'], $data['PhoneReturned'], $data['PhysicialExamExpired'], $data['PhysicialExamRcvd'], $data['RecordofRoadTest'], $data['TurberculosisTest'], $data['UniformIssued'], $data['vendorbadge'], $data['Fieldtripformdone'], $data['ASInsurance'], $data['ClearedCounties'], $data['DriversLicenseIMAGE'], $data['light_duty'], $data['ee_id'], $data['PTO_plan'], $data['sign_on_bonus'], $data['Record_Id'], $data['SSN']

	 * Also includes the item $data['selectedID'] which stores the value of the primary key for the record to be updated.

	 * $data array is passed by reference so that modifications to it apply to the update query.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * True to perform the update operation or false to cancel it.

	*/



	function compliance_before_update(&$data, $memberInfo, &$args){

		return TRUE;

	}


	/**

	 * Called after executing the update query and before executing the ownership update query.

	 * 

	 * @param $data

	 * An associative array where the keys are field names and the values are the field data values.

	 * For this table, the array items are: 

	 *     $data['Name'], $data['FirstName'], $data['LastName'], $data['MailCity'], $data['HomePhone'], $data['WorkPhone'], $data['CellPhone'], $data['Active'], $data['ApplicationforEmployement'], $data['BackgroundCheckClearance'], $data['Comments'], $data['Complaints'], $data['CopyofApprovedVendorBadge'], $data['DateInactive'], $data['DexterityExpiration'], $data['DexterityReceived'], $data['DOB'], $data['DOTStatus'], $data['DriverNotes'], $data['DrugTest_COC_Results'], $data['Email'], $data['EmployeeHandbook'], $data['Gender'], $data['HireDate'], $data['LastUpdatedby'], $data['LastUpdated'], $data['LicenseNumber'], $data['LicenseClass'], $data['LicenseEndorsements'], $data['LicenseExpiration'], $data['LicenseRestrictions'], $data['LicenseState'], $data['LocalID'], $data['Logof40HrTrainingCourse'], $data['Logof8HrRefresherCourse'], $data['MailCounty'], $data['MailState'], $data['MailStreet1'], $data['MailStreet2'], $data['MailZipCode'], $data['MI'], $data['PhoneIssued'], $data['PhoneReturned'], $data['PhysicialExamExpired'], $data['PhysicialExamRcvd'], $data['RecordofRoadTest'], $data['TurberculosisTest'], $data['UniformIssued'], $data['vendorbadge'], $data['Fieldtripformdone'], $data['ASInsurance'], $data['ClearedCounties'], $data['DriversLicenseIMAGE'], $data['light_duty'], $data['ee_id'], $data['PTO_plan'], $data['sign_on_bonus'], $data['Record_Id'], $data['SSN']

	 * Also includes the item $data['selectedID'] which stores the value of the primary key for the record.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * True to perform the ownership update operation or false to cancel it. 

	*/



	function compliance_after_update($data, $memberInfo, &$args){

global $old_data;

foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='compliance' , pkValue='#recID', 
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);
 
@mail(
// mail recipient
"[email protected]",
 
// subject
"A Record in the Driver Compliance table of the database was changed - notification - Driver RECORD NUMBER-{$data['Record_Id']}",
 
// message
      "The above record {$data['Record_Id']} was just modified by:{$memberInfo['username']} The record was updated on and by:{$data['LastUpdatedby']} \n To view the record please go to \n http://bigschoolbus.com/asdata2/compliance_view.php?SelectedID=".$data['selectedID']."  Newly entered data shows as actual table values below:,
	 {$messageData} \n.  The user that changed this record did so from IP Address: {$memberInfo['IP']}  \n\n", 
	  
 
// sender address
"[email protected]"
);
	
sql("INSERT INTO Historical_Log (RouteNumber, old_data, new_data, ChangedDate, ChangedBy) VALUES({$data['Record_Id']}','{$old_data}','{$messageData}','{$data['LastUpdatedby']}','{$memberInfo['username']}'");

		return TRUE;

	}
	
	


	/**

	 * Called before deleting a record (and before performing child records check).

	 * 

	 * @param $selectedID

	 * The primary key value of the record to be deleted.

	 * 

	 * @param $skipChecks

	 * A flag passed by reference that determines whether child records check should be performed or not.

	 * If you set $skipChecks to TRUE, no child records check will be made. If you set it to FALSE, the check will be performed.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * True to perform the delete operation or false to cancel it.

	*/



	function compliance_before_delete($selectedID, &$skipChecks, $memberInfo, &$args){



		return TRUE;

	}



	/**

	 * Called after deleting a record.

	 * 

	 * @param $selectedID

	 * The primary key value of the record to be deleted.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * None.

	*/



	function compliance_after_delete($selectedID, $memberInfo, &$args){



	}



	/**

	 * Called when a user requests to view the detail view (before displaying the detail view).

	 * 

	 * @param $selectedID

	 * The primary key value of the record selected. False if no record is selected (i.e. the detail view will be 

	 * displayed to enter a new record).

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $html

	 * (passed by reference) the HTML code of the form ready to be displayed. This could be useful for manipulating 

	 * the code before displaying it using regular expressions, … etc.

	 * 

	 * @param $args

	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * None.

	*/



	function compliance_dv($selectedID, $memberInfo, &$html, &$args){



	}



	/**

	 * Called when a user requests to download table data as a CSV file (by clicking on the SAVE CSV button)

	 * 

	 * @param $query

	 * Contains the query that will be executed to return the data in the CSV file.

	 * 

	 * @param $memberInfo

	 * An array containing logged member's info.

	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo

	 * 

	 * @param $args

	 * An empty array. It's currently not used but is reserved for future uses.

	 * 

	 * @return

	 * A string containing the query to use for fetching the CSV data. If FALSE or empty is returned, the default query is used.

	*/



	function compliance_csv($query, $memberInfo, $args){



		return $query;

	}
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-14 18:12

also what is emailing is only new data.
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: 5.2 EMAIL HOOK CHANGED??

Post by toconnell » 2014-04-14 18:25

I also tried this.. no luck.. on the insert.. instead of the global $old_data..

$old_data=sql("SELECT * FROM compliance WHERE Record_Id={$data['recID']}", $eo);
Tina O'Connell
Web Dev & Appgini FAN

Post Reply